summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-04-24 13:34:15 +0200
committeraxis <qt-info@nokia.com>2009-04-24 13:34:15 +0200
commit8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch)
treea17e1a767a89542ab59907462206d7dcf2e504b2 /examples
Long live Qt for S60!
Diffstat (limited to 'examples')
-rw-r--r--examples/README39
-rw-r--r--examples/activeqt/README39
-rw-r--r--examples/activeqt/activeqt.pro22
-rw-r--r--examples/activeqt/comapp/comapp.pro15
-rw-r--r--examples/activeqt/comapp/comapp.rc1
-rw-r--r--examples/activeqt/comapp/main.cpp272
-rw-r--r--examples/activeqt/dotnet/walkthrough/Form1.cs127
-rw-r--r--examples/activeqt/dotnet/walkthrough/Form1.resx131
-rw-r--r--examples/activeqt/dotnet/walkthrough/Form1.vb88
-rw-r--r--examples/activeqt/dotnet/walkthrough/csharp.csproj143
-rw-r--r--examples/activeqt/dotnet/walkthrough/vb.vbproj147
-rw-r--r--examples/activeqt/dotnet/wrapper/app.csproj93
-rw-r--r--examples/activeqt/dotnet/wrapper/lib/lib.vcproj149
-rw-r--r--examples/activeqt/dotnet/wrapper/lib/networker.cpp70
-rw-r--r--examples/activeqt/dotnet/wrapper/lib/networker.h67
-rw-r--r--examples/activeqt/dotnet/wrapper/lib/tools.cpp61
-rw-r--r--examples/activeqt/dotnet/wrapper/lib/tools.h54
-rw-r--r--examples/activeqt/dotnet/wrapper/lib/worker.cpp59
-rw-r--r--examples/activeqt/dotnet/wrapper/lib/worker.h69
-rw-r--r--examples/activeqt/dotnet/wrapper/main.cs40
-rw-r--r--examples/activeqt/dotnet/wrapper/wrapper.sln28
-rw-r--r--examples/activeqt/hierarchy/hierarchy.inf9
-rw-r--r--examples/activeqt/hierarchy/hierarchy.pro18
-rw-r--r--examples/activeqt/hierarchy/main.cpp50
-rw-r--r--examples/activeqt/hierarchy/objects.cpp108
-rw-r--r--examples/activeqt/hierarchy/objects.h100
-rw-r--r--examples/activeqt/menus/fileopen.xpm22
-rw-r--r--examples/activeqt/menus/filesave.xpm22
-rw-r--r--examples/activeqt/menus/main.cpp64
-rw-r--r--examples/activeqt/menus/menus.cpp178
-rw-r--r--examples/activeqt/menus/menus.h76
-rw-r--r--examples/activeqt/menus/menus.inf9
-rw-r--r--examples/activeqt/menus/menus.pro16
-rw-r--r--examples/activeqt/multiple/ax1.h87
-rw-r--r--examples/activeqt/multiple/ax2.h94
-rw-r--r--examples/activeqt/multiple/main.cpp53
-rw-r--r--examples/activeqt/multiple/multiple.inf9
-rw-r--r--examples/activeqt/multiple/multiple.pro18
-rw-r--r--examples/activeqt/multiple/multipleax.rc32
-rw-r--r--examples/activeqt/opengl/glbox.cpp250
-rw-r--r--examples/activeqt/opengl/glbox.h90
-rw-r--r--examples/activeqt/opengl/globjwin.cpp111
-rw-r--r--examples/activeqt/opengl/globjwin.h62
-rw-r--r--examples/activeqt/opengl/main.cpp91
-rw-r--r--examples/activeqt/opengl/opengl.inf9
-rw-r--r--examples/activeqt/opengl/opengl.pro21
-rw-r--r--examples/activeqt/qutlook/addressview.cpp289
-rw-r--r--examples/activeqt/qutlook/addressview.h79
-rw-r--r--examples/activeqt/qutlook/fileopen.xpm22
-rw-r--r--examples/activeqt/qutlook/fileprint.xpm24
-rw-r--r--examples/activeqt/qutlook/filesave.xpm22
-rw-r--r--examples/activeqt/qutlook/main.cpp56
-rw-r--r--examples/activeqt/qutlook/qutlook.pro25
-rw-r--r--examples/activeqt/simple/main.cpp137
-rw-r--r--examples/activeqt/simple/simple.inf11
-rw-r--r--examples/activeqt/simple/simple.pro15
-rw-r--r--examples/activeqt/webbrowser/main.cpp189
-rw-r--r--examples/activeqt/webbrowser/mainwindow.ui306
-rw-r--r--examples/activeqt/webbrowser/webaxwidget.h67
-rw-r--r--examples/activeqt/webbrowser/webbrowser.pro19
-rw-r--r--examples/activeqt/webbrowser/wincemainwindow.ui299
-rw-r--r--examples/activeqt/wrapper/main.cpp161
-rw-r--r--examples/activeqt/wrapper/wrapper.inf9
-rw-r--r--examples/activeqt/wrapper/wrapper.pro17
-rw-r--r--examples/activeqt/wrapper/wrapperax.rc32
-rw-r--r--examples/assistant/README38
-rw-r--r--examples/assistant/assistant.pro10
-rw-r--r--examples/assistant/simpletextviewer/documentation/about.txt9
-rw-r--r--examples/assistant/simpletextviewer/documentation/browse.html34
-rw-r--r--examples/assistant/simpletextviewer/documentation/filedialog.html48
-rw-r--r--examples/assistant/simpletextviewer/documentation/findfile.html32
-rw-r--r--examples/assistant/simpletextviewer/documentation/images/browse.pngbin0 -> 21553 bytes
-rw-r--r--examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.pngbin0 -> 9589 bytes
-rw-r--r--examples/assistant/simpletextviewer/documentation/images/filedialog.pngbin0 -> 12318 bytes
-rw-r--r--examples/assistant/simpletextviewer/documentation/images/handbook.pngbin0 -> 1060 bytes
-rw-r--r--examples/assistant/simpletextviewer/documentation/images/mainwindow.pngbin0 -> 12769 bytes
-rw-r--r--examples/assistant/simpletextviewer/documentation/images/open.pngbin0 -> 11697 bytes
-rw-r--r--examples/assistant/simpletextviewer/documentation/images/wildcard.pngbin0 -> 11266 bytes
-rw-r--r--examples/assistant/simpletextviewer/documentation/index.html41
-rw-r--r--examples/assistant/simpletextviewer/documentation/intro.html28
-rw-r--r--examples/assistant/simpletextviewer/documentation/openfile.html36
-rw-r--r--examples/assistant/simpletextviewer/documentation/simpletextviewer.adp40
-rw-r--r--examples/assistant/simpletextviewer/documentation/wildcardmatching.html57
-rw-r--r--examples/assistant/simpletextviewer/findfiledialog.cpp221
-rw-r--r--examples/assistant/simpletextviewer/findfiledialog.h99
-rw-r--r--examples/assistant/simpletextviewer/main.cpp52
-rw-r--r--examples/assistant/simpletextviewer/mainwindow.cpp154
-rw-r--r--examples/assistant/simpletextviewer/mainwindow.h91
-rw-r--r--examples/assistant/simpletextviewer/simpletextviewer.pro18
-rw-r--r--examples/dbus/complexpingpong/complexping.cpp118
-rw-r--r--examples/dbus/complexpingpong/complexping.h59
-rw-r--r--examples/dbus/complexpingpong/complexping.pro18
-rw-r--r--examples/dbus/complexpingpong/complexpingpong.pro4
-rw-r--r--examples/dbus/complexpingpong/complexpong.cpp105
-rw-r--r--examples/dbus/complexpingpong/complexpong.h68
-rw-r--r--examples/dbus/complexpingpong/complexpong.pro18
-rw-r--r--examples/dbus/complexpingpong/ping-common.h42
-rw-r--r--examples/dbus/dbus-chat/chat.cpp164
-rw-r--r--examples/dbus/dbus-chat/chat.h82
-rw-r--r--examples/dbus/dbus-chat/chat_adaptor.cpp35
-rw-r--r--examples/dbus/dbus-chat/chat_adaptor.h57
-rw-r--r--examples/dbus/dbus-chat/chat_interface.cpp25
-rw-r--r--examples/dbus/dbus-chat/chat_interface.h49
-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.pro14
-rw-r--r--examples/dbus/listnames/listnames.cpp92
-rw-r--r--examples/dbus/listnames/listnames.pro19
-rw-r--r--examples/dbus/pingpong/ping-common.h42
-rw-r--r--examples/dbus/pingpong/ping.cpp75
-rw-r--r--examples/dbus/pingpong/ping.pro18
-rw-r--r--examples/dbus/pingpong/pingpong.pro4
-rw-r--r--examples/dbus/pingpong/pong.cpp80
-rw-r--r--examples/dbus/pingpong/pong.h54
-rw-r--r--examples/dbus/pingpong/pong.pro18
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.cpp138
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.h76
-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.cpp59
-rw-r--r--examples/dbus/remotecontrolledcar/car/car_adaptor_p.h57
-rw-r--r--examples/dbus/remotecontrolledcar/car/main.cpp73
-rw-r--r--examples/dbus/remotecontrolledcar/controller/car.xml11
-rw-r--r--examples/dbus/remotecontrolledcar/controller/car_interface.cpp26
-rw-r--r--examples/dbus/remotecontrolledcar/controller/car_interface_p.h74
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.cpp83
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.h71
-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.cpp53
-rw-r--r--examples/dbus/remotecontrolledcar/remotecontrolledcar.pro10
-rw-r--r--examples/designer/README37
-rw-r--r--examples/designer/calculatorbuilder/calculatorbuilder.pro16
-rw-r--r--examples/designer/calculatorbuilder/calculatorbuilder.qrc5
-rw-r--r--examples/designer/calculatorbuilder/calculatorform.cpp92
-rw-r--r--examples/designer/calculatorbuilder/calculatorform.h71
-rw-r--r--examples/designer/calculatorbuilder/calculatorform.ui303
-rw-r--r--examples/designer/calculatorbuilder/main.cpp54
-rw-r--r--examples/designer/calculatorform/calculatorform.cpp66
-rw-r--r--examples/designer/calculatorform/calculatorform.h66
-rw-r--r--examples/designer/calculatorform/calculatorform.pro15
-rw-r--r--examples/designer/calculatorform/calculatorform.ui284
-rw-r--r--examples/designer/calculatorform/main.cpp53
-rw-r--r--examples/designer/containerextension/containerextension.pro28
-rw-r--r--examples/designer/containerextension/multipagewidget.cpp131
-rw-r--r--examples/designer/containerextension/multipagewidget.h88
-rw-r--r--examples/designer/containerextension/multipagewidgetcontainerextension.cpp101
-rw-r--r--examples/designer/containerextension/multipagewidgetcontainerextension.h75
-rw-r--r--examples/designer/containerextension/multipagewidgetextensionfactory.cpp65
-rw-r--r--examples/designer/containerextension/multipagewidgetextensionfactory.h64
-rw-r--r--examples/designer/containerextension/multipagewidgetplugin.cpp197
-rw-r--r--examples/designer/containerextension/multipagewidgetplugin.h81
-rw-r--r--examples/designer/customwidgetplugin/analogclock.cpp111
-rw-r--r--examples/designer/customwidgetplugin/analogclock.h59
-rw-r--r--examples/designer/customwidgetplugin/customwidgetplugin.cpp156
-rw-r--r--examples/designer/customwidgetplugin/customwidgetplugin.h73
-rw-r--r--examples/designer/customwidgetplugin/customwidgetplugin.pro23
-rw-r--r--examples/designer/designer.pro21
-rw-r--r--examples/designer/taskmenuextension/taskmenuextension.pro27
-rw-r--r--examples/designer/taskmenuextension/tictactoe.cpp176
-rw-r--r--examples/designer/taskmenuextension/tictactoe.h83
-rw-r--r--examples/designer/taskmenuextension/tictactoedialog.cpp99
-rw-r--r--examples/designer/taskmenuextension/tictactoedialog.h73
-rw-r--r--examples/designer/taskmenuextension/tictactoeplugin.cpp134
-rw-r--r--examples/designer/taskmenuextension/tictactoeplugin.h78
-rw-r--r--examples/designer/taskmenuextension/tictactoetaskmenu.cpp104
-rw-r--r--examples/designer/taskmenuextension/tictactoetaskmenu.h88
-rw-r--r--examples/designer/worldtimeclockbuilder/form.ui162
-rw-r--r--examples/designer/worldtimeclockbuilder/main.cpp70
-rw-r--r--examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro13
-rw-r--r--examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc5
-rw-r--r--examples/designer/worldtimeclockplugin/worldtimeclock.cpp122
-rw-r--r--examples/designer/worldtimeclockplugin/worldtimeclock.h73
-rw-r--r--examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp124
-rw-r--r--examples/designer/worldtimeclockplugin/worldtimeclockplugin.h74
-rw-r--r--examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro23
-rw-r--r--examples/desktop/README41
-rw-r--r--examples/desktop/desktop.pro13
-rw-r--r--examples/desktop/screenshot/main.cpp52
-rw-r--r--examples/desktop/screenshot/screenshot.cpp198
-rw-r--r--examples/desktop/screenshot/screenshot.h100
-rw-r--r--examples/desktop/screenshot/screenshot.pro11
-rw-r--r--examples/desktop/systray/images/bad.svg64
-rw-r--r--examples/desktop/systray/images/heart.svg55
-rw-r--r--examples/desktop/systray/images/trash.svg58
-rw-r--r--examples/desktop/systray/main.cpp63
-rw-r--r--examples/desktop/systray/systray.pro24
-rw-r--r--examples/desktop/systray/systray.qrc7
-rw-r--r--examples/desktop/systray/window.cpp259
-rw-r--r--examples/desktop/systray/window.h113
-rw-r--r--examples/dialogs/README40
-rw-r--r--examples/dialogs/classwizard/classwizard.cpp431
-rw-r--r--examples/dialogs/classwizard/classwizard.h157
-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.cpp64
-rw-r--r--examples/dialogs/configdialog/configdialog.cpp117
-rw-r--r--examples/dialogs/configdialog/configdialog.h70
-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.cpp53
-rw-r--r--examples/dialogs/configdialog/pages.cpp152
-rw-r--r--examples/dialogs/configdialog/pages.h65
-rw-r--r--examples/dialogs/dialogs.pro19
-rw-r--r--examples/dialogs/extension/extension.pro11
-rw-r--r--examples/dialogs/extension/finddialog.cpp113
-rw-r--r--examples/dialogs/extension/finddialog.h79
-rw-r--r--examples/dialogs/extension/main.cpp51
-rw-r--r--examples/dialogs/findfiles/findfiles.pro11
-rw-r--r--examples/dialogs/findfiles/main.cpp52
-rw-r--r--examples/dialogs/findfiles/window.cpp250
-rw-r--r--examples/dialogs/findfiles/window.h91
-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.cpp360
-rw-r--r--examples/dialogs/licensewizard/licensewizard.h164
-rw-r--r--examples/dialogs/licensewizard/licensewizard.pro12
-rw-r--r--examples/dialogs/licensewizard/licensewizard.qrc6
-rw-r--r--examples/dialogs/licensewizard/main.cpp64
-rw-r--r--examples/dialogs/sipdialog/dialog.cpp124
-rw-r--r--examples/dialogs/sipdialog/dialog.h64
-rw-r--r--examples/dialogs/sipdialog/main.cpp53
-rw-r--r--examples/dialogs/sipdialog/sipdialog.pro14
-rw-r--r--examples/dialogs/standarddialogs/dialog.cpp390
-rw-r--r--examples/dialogs/standarddialogs/dialog.h99
-rw-r--r--examples/dialogs/standarddialogs/main.cpp61
-rw-r--r--examples/dialogs/standarddialogs/standarddialogs.pro13
-rw-r--r--examples/dialogs/tabdialog/main.cpp58
-rw-r--r--examples/dialogs/tabdialog/tabdialog.cpp196
-rw-r--r--examples/dialogs/tabdialog/tabdialog.h100
-rw-r--r--examples/dialogs/tabdialog/tabdialog.pro12
-rw-r--r--examples/dialogs/trivialwizard/trivialwizard.cpp136
-rw-r--r--examples/dialogs/trivialwizard/trivialwizard.pro9
-rw-r--r--examples/draganddrop/README40
-rw-r--r--examples/draganddrop/delayedencoding/delayedencoding.pro14
-rw-r--r--examples/draganddrop/delayedencoding/delayedencoding.qrc6
-rw-r--r--examples/draganddrop/delayedencoding/images/drag.pngbin0 -> 977 bytes
-rw-r--r--examples/draganddrop/delayedencoding/images/example.svg59
-rw-r--r--examples/draganddrop/delayedencoding/main.cpp52
-rw-r--r--examples/draganddrop/delayedencoding/mimedata.cpp66
-rw-r--r--examples/draganddrop/delayedencoding/mimedata.h64
-rw-r--r--examples/draganddrop/delayedencoding/sourcewidget.cpp115
-rw-r--r--examples/draganddrop/delayedencoding/sourcewidget.h71
-rw-r--r--examples/draganddrop/draganddrop.pro15
-rw-r--r--examples/draganddrop/draggableicons/draggableicons.pro12
-rw-r--r--examples/draganddrop/draggableicons/draggableicons.qrc7
-rw-r--r--examples/draganddrop/draggableicons/dragwidget.cpp169
-rw-r--r--examples/draganddrop/draggableicons/dragwidget.h66
-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.cpp62
-rw-r--r--examples/draganddrop/draggabletext/draggabletext.pro14
-rw-r--r--examples/draganddrop/draggabletext/draggabletext.qrc5
-rw-r--r--examples/draganddrop/draggabletext/draglabel.cpp52
-rw-r--r--examples/draganddrop/draggabletext/draglabel.h59
-rw-r--r--examples/draganddrop/draggabletext/dragwidget.cpp164
-rw-r--r--examples/draganddrop/draggabletext/dragwidget.h63
-rw-r--r--examples/draganddrop/draggabletext/main.cpp53
-rw-r--r--examples/draganddrop/draggabletext/words.txt41
-rw-r--r--examples/draganddrop/dropsite/droparea.cpp127
-rw-r--r--examples/draganddrop/dropsite/droparea.h78
-rw-r--r--examples/draganddrop/dropsite/dropsite.pro14
-rw-r--r--examples/draganddrop/dropsite/dropsitewindow.cpp146
-rw-r--r--examples/draganddrop/dropsite/dropsitewindow.h78
-rw-r--r--examples/draganddrop/dropsite/main.cpp54
-rw-r--r--examples/draganddrop/fridgemagnets/draglabel.cpp90
-rw-r--r--examples/draganddrop/fridgemagnets/draglabel.h65
-rw-r--r--examples/draganddrop/fridgemagnets/dragwidget.cpp215
-rw-r--r--examples/draganddrop/fridgemagnets/dragwidget.h66
-rw-r--r--examples/draganddrop/fridgemagnets/fridgemagnets.pro15
-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.cpp55
-rw-r--r--examples/draganddrop/puzzle/mainwindow.cpp151
-rw-r--r--examples/draganddrop/puzzle/mainwindow.h77
-rw-r--r--examples/draganddrop/puzzle/pieceslist.cpp122
-rw-r--r--examples/draganddrop/puzzle/pieceslist.h62
-rw-r--r--examples/draganddrop/puzzle/puzzle.pro27
-rw-r--r--examples/draganddrop/puzzle/puzzle.qrc5
-rw-r--r--examples/draganddrop/puzzle/puzzlewidget.cpp205
-rw-r--r--examples/draganddrop/puzzle/puzzlewidget.h86
-rw-r--r--examples/examplebase.pri1
-rw-r--r--examples/examples.pro57
-rw-r--r--examples/graphicsview/README40
-rw-r--r--examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro16
-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.cpp99
-rw-r--r--examples/graphicsview/basicgraphicslayouts/layoutitem.h62
-rw-r--r--examples/graphicsview/basicgraphicslayouts/main.cpp59
-rw-r--r--examples/graphicsview/basicgraphicslayouts/window.cpp91
-rw-r--r--examples/graphicsview/basicgraphicslayouts/window.h58
-rw-r--r--examples/graphicsview/collidingmice/collidingmice.pro18
-rw-r--r--examples/graphicsview/collidingmice/images/cheese.jpgbin0 -> 3029 bytes
-rw-r--r--examples/graphicsview/collidingmice/main.cpp88
-rw-r--r--examples/graphicsview/collidingmice/mice.qrc5
-rw-r--r--examples/graphicsview/collidingmice/mouse.cpp200
-rw-r--r--examples/graphicsview/collidingmice/mouse.h72
-rw-r--r--examples/graphicsview/diagramscene/arrow.cpp147
-rw-r--r--examples/graphicsview/diagramscene/arrow.h94
-rw-r--r--examples/graphicsview/diagramscene/diagramitem.cpp152
-rw-r--r--examples/graphicsview/diagramscene/diagramitem.h97
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.cpp241
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.h113
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.pro22
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.qrc20
-rw-r--r--examples/graphicsview/diagramscene/diagramtextitem.cpp82
-rw-r--r--examples/graphicsview/diagramscene/diagramtextitem.h79
-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.cpp56
-rw-r--r--examples/graphicsview/diagramscene/mainwindow.cpp651
-rw-r--r--examples/graphicsview/diagramscene/mainwindow.h151
-rw-r--r--examples/graphicsview/dragdroprobot/coloritem.cpp129
-rw-r--r--examples/graphicsview/dragdroprobot/coloritem.h64
-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.cpp78
-rw-r--r--examples/graphicsview/dragdroprobot/robot.cpp273
-rw-r--r--examples/graphicsview/dragdroprobot/robot.h110
-rw-r--r--examples/graphicsview/dragdroprobot/robot.qrc5
-rw-r--r--examples/graphicsview/elasticnodes/edge.cpp144
-rw-r--r--examples/graphicsview/elasticnodes/edge.h78
-rw-r--r--examples/graphicsview/elasticnodes/elasticnodes.pro22
-rw-r--r--examples/graphicsview/elasticnodes/graphwidget.cpp224
-rw-r--r--examples/graphicsview/elasticnodes/graphwidget.h71
-rw-r--r--examples/graphicsview/elasticnodes/main.cpp54
-rw-r--r--examples/graphicsview/elasticnodes/node.cpp185
-rw-r--r--examples/graphicsview/elasticnodes/node.h84
-rw-r--r--examples/graphicsview/graphicsview.pro22
-rw-r--r--examples/graphicsview/padnavigator/backside.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.cpp59
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.pro29
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.qrc14
-rw-r--r--examples/graphicsview/padnavigator/panel.cpp238
-rw-r--r--examples/graphicsview/padnavigator/panel.h92
-rw-r--r--examples/graphicsview/padnavigator/roundrectitem.cpp164
-rw-r--r--examples/graphicsview/padnavigator/roundrectitem.h83
-rw-r--r--examples/graphicsview/padnavigator/splashitem.cpp92
-rw-r--r--examples/graphicsview/padnavigator/splashitem.h63
-rw-r--r--examples/graphicsview/portedasteroids/animateditem.cpp95
-rw-r--r--examples/graphicsview/portedasteroids/animateditem.h84
-rw-r--r--examples/graphicsview/portedasteroids/bg.pngbin0 -> 3793 bytes
-rw-r--r--examples/graphicsview/portedasteroids/ledmeter.cpp161
-rw-r--r--examples/graphicsview/portedasteroids/ledmeter.h96
-rw-r--r--examples/graphicsview/portedasteroids/main.cpp60
-rw-r--r--examples/graphicsview/portedasteroids/portedasteroids.pro21
-rw-r--r--examples/graphicsview/portedasteroids/portedasteroids.qrc163
-rw-r--r--examples/graphicsview/portedasteroids/sounds/Explosion.wavbin0 -> 18427 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites.h170
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits.ini9
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits.pov31
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0000.pngbin0 -> 215 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0001.pngbin0 -> 236 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0002.pngbin0 -> 244 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0003.pngbin0 -> 277 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0004.pngbin0 -> 259 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0005.pngbin0 -> 251 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0006.pngbin0 -> 214 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0007.pngbin0 -> 177 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0008.pngbin0 -> 175 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0009.pngbin0 -> 221 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0010.pngbin0 -> 243 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0011.pngbin0 -> 272 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0012.pngbin0 -> 265 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0013.pngbin0 -> 253 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0014.pngbin0 -> 214 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/bits/bits0015.pngbin0 -> 196 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/exhaust/exhaust.pngbin0 -> 92 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/missile/missile.pngbin0 -> 89 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/powerups/brake.pngbin0 -> 151 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/powerups/energy.pngbin0 -> 134 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/powerups/shield.pngbin0 -> 171 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/powerups/shoot.pngbin0 -> 181 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/powerups/teleport.pngbin0 -> 160 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock1.ini9
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock1.pov26
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10000.pngbin0 -> 2502 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10001.pngbin0 -> 2483 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10002.pngbin0 -> 2519 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10003.pngbin0 -> 2460 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10004.pngbin0 -> 2486 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10005.pngbin0 -> 2416 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10006.pngbin0 -> 2419 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10007.pngbin0 -> 2374 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10008.pngbin0 -> 2329 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10009.pngbin0 -> 2227 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10010.pngbin0 -> 2218 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10011.pngbin0 -> 2178 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10012.pngbin0 -> 2172 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10013.pngbin0 -> 2229 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10014.pngbin0 -> 2270 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10015.pngbin0 -> 2348 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10016.pngbin0 -> 2402 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10017.pngbin0 -> 2489 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10018.pngbin0 -> 2530 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10019.pngbin0 -> 2591 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10020.pngbin0 -> 2540 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10021.pngbin0 -> 2606 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10022.pngbin0 -> 2591 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10023.pngbin0 -> 2566 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10024.pngbin0 -> 2512 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10025.pngbin0 -> 2456 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10026.pngbin0 -> 2420 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10027.pngbin0 -> 2557 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10028.pngbin0 -> 2567 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10029.pngbin0 -> 2572 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10030.pngbin0 -> 2620 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock1/rock10031.pngbin0 -> 2558 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock2.ini9
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock2.pov26
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20000.pngbin0 -> 1338 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20001.pngbin0 -> 1363 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20002.pngbin0 -> 1385 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20003.pngbin0 -> 1389 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20004.pngbin0 -> 1361 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20005.pngbin0 -> 1393 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20006.pngbin0 -> 1361 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20007.pngbin0 -> 1369 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20008.pngbin0 -> 1368 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20009.pngbin0 -> 1311 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20010.pngbin0 -> 1340 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20011.pngbin0 -> 1322 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20012.pngbin0 -> 1350 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20013.pngbin0 -> 1337 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20014.pngbin0 -> 1341 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20015.pngbin0 -> 1373 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20016.pngbin0 -> 1357 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20017.pngbin0 -> 1354 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20018.pngbin0 -> 1320 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20019.pngbin0 -> 1356 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20020.pngbin0 -> 1379 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20021.pngbin0 -> 1401 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20022.pngbin0 -> 1418 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20023.pngbin0 -> 1401 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20024.pngbin0 -> 1383 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20025.pngbin0 -> 1360 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20026.pngbin0 -> 1376 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20027.pngbin0 -> 1331 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20028.pngbin0 -> 1353 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20029.pngbin0 -> 1376 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20030.pngbin0 -> 1290 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock2/rock20031.pngbin0 -> 1313 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock3.ini9
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock3.pov26
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30000.pngbin0 -> 738 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30001.pngbin0 -> 730 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30002.pngbin0 -> 769 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30003.pngbin0 -> 766 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30004.pngbin0 -> 770 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30005.pngbin0 -> 756 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30006.pngbin0 -> 760 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30007.pngbin0 -> 750 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30008.pngbin0 -> 747 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30009.pngbin0 -> 752 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30010.pngbin0 -> 727 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30011.pngbin0 -> 737 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30012.pngbin0 -> 724 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30013.pngbin0 -> 751 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30014.pngbin0 -> 720 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30015.pngbin0 -> 741 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30016.pngbin0 -> 723 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30017.pngbin0 -> 722 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30018.pngbin0 -> 716 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30019.pngbin0 -> 735 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30020.pngbin0 -> 735 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30021.pngbin0 -> 731 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30022.pngbin0 -> 735 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30023.pngbin0 -> 732 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30024.pngbin0 -> 727 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30025.pngbin0 -> 721 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30026.pngbin0 -> 716 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30027.pngbin0 -> 721 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30028.pngbin0 -> 739 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30029.pngbin0 -> 740 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30030.pngbin0 -> 725 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/rock3/rock30031.pngbin0 -> 715 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/shield/shield0000.pngbin0 -> 1702 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/shield/shield0001.pngbin0 -> 1690 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/shield/shield0002.pngbin0 -> 1849 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/shield/shield0003.pngbin0 -> 1858 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/shield/shield0004.pngbin0 -> 1725 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/shield/shield0005.pngbin0 -> 1876 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/shield/shield0006.pngbin0 -> 1848 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship.ini9
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship.pov128
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0000.pngbin0 -> 1772 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0001.pngbin0 -> 1893 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0002.pngbin0 -> 1899 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0003.pngbin0 -> 1878 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0004.pngbin0 -> 1979 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0005.pngbin0 -> 2054 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0006.pngbin0 -> 1956 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0007.pngbin0 -> 1929 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0008.pngbin0 -> 1790 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0009.pngbin0 -> 1913 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0010.pngbin0 -> 1954 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0011.pngbin0 -> 1975 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0012.pngbin0 -> 1953 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0013.pngbin0 -> 1924 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0014.pngbin0 -> 1900 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0015.pngbin0 -> 1799 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0016.pngbin0 -> 1738 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0017.pngbin0 -> 1868 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0018.pngbin0 -> 1945 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0019.pngbin0 -> 1972 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0020.pngbin0 -> 2014 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0021.pngbin0 -> 2002 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0022.pngbin0 -> 1920 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0023.pngbin0 -> 1840 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0024.pngbin0 -> 1733 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0025.pngbin0 -> 1880 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0026.pngbin0 -> 1951 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0027.pngbin0 -> 2014 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0028.pngbin0 -> 2019 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0029.pngbin0 -> 2022 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0030.pngbin0 -> 1969 bytes
-rw-r--r--examples/graphicsview/portedasteroids/sprites/ship/ship0031.pngbin0 -> 1880 bytes
-rw-r--r--examples/graphicsview/portedasteroids/toplevel.cpp543
-rw-r--r--examples/graphicsview/portedasteroids/toplevel.h126
-rw-r--r--examples/graphicsview/portedasteroids/view.cpp967
-rw-r--r--examples/graphicsview/portedasteroids/view.h184
-rw-r--r--examples/graphicsview/portedcanvas/blendshadow.cpp94
-rw-r--r--examples/graphicsview/portedcanvas/butterfly.pngbin0 -> 36868 bytes
-rw-r--r--examples/graphicsview/portedcanvas/canvas.cpp733
-rw-r--r--examples/graphicsview/portedcanvas/canvas.doc29
-rw-r--r--examples/graphicsview/portedcanvas/canvas.h131
-rw-r--r--examples/graphicsview/portedcanvas/main.cpp92
-rw-r--r--examples/graphicsview/portedcanvas/makeimg.cpp133
-rw-r--r--examples/graphicsview/portedcanvas/portedcanvas.pro18
-rw-r--r--examples/graphicsview/portedcanvas/portedcanvas.qrc7
-rw-r--r--examples/graphicsview/portedcanvas/qt-trans.xpm54
-rw-r--r--examples/graphicsview/portedcanvas/qtlogo.pngbin0 -> 21921 bytes
-rw-r--r--examples/help/README38
-rw-r--r--examples/help/contextsensitivehelp/contextsensitivehelp.pro20
-rw-r--r--examples/help/contextsensitivehelp/doc/amount.html11
-rw-r--r--examples/help/contextsensitivehelp/doc/filter.html12
-rw-r--r--examples/help/contextsensitivehelp/doc/plants.html44
-rw-r--r--examples/help/contextsensitivehelp/doc/rain.html11
-rw-r--r--examples/help/contextsensitivehelp/doc/source.html33
-rw-r--r--examples/help/contextsensitivehelp/doc/temperature.html13
-rw-r--r--examples/help/contextsensitivehelp/doc/time.html11
-rw-r--r--examples/help/contextsensitivehelp/doc/wateringmachine.qchbin0 -> 27648 bytes
-rw-r--r--examples/help/contextsensitivehelp/doc/wateringmachine.qhcbin0 -> 10240 bytes
-rw-r--r--examples/help/contextsensitivehelp/doc/wateringmachine.qhcp14
-rw-r--r--examples/help/contextsensitivehelp/doc/wateringmachine.qhp25
-rw-r--r--examples/help/contextsensitivehelp/helpbrowser.cpp81
-rw-r--r--examples/help/contextsensitivehelp/helpbrowser.h65
-rw-r--r--examples/help/contextsensitivehelp/main.cpp51
-rw-r--r--examples/help/contextsensitivehelp/wateringconfigdialog.cpp69
-rw-r--r--examples/help/contextsensitivehelp/wateringconfigdialog.h62
-rw-r--r--examples/help/contextsensitivehelp/wateringconfigdialog.ui446
-rw-r--r--examples/help/help.pro13
-rw-r--r--examples/help/remotecontrol/enter.pngbin0 -> 315 bytes
-rw-r--r--examples/help/remotecontrol/main.cpp54
-rw-r--r--examples/help/remotecontrol/remotecontrol.cpp175
-rw-r--r--examples/help/remotecontrol/remotecontrol.h79
-rw-r--r--examples/help/remotecontrol/remotecontrol.pro15
-rw-r--r--examples/help/remotecontrol/remotecontrol.qrc5
-rw-r--r--examples/help/remotecontrol/remotecontrol.ui228
-rw-r--r--examples/help/simpletextviewer/assistant.cpp110
-rw-r--r--examples/help/simpletextviewer/assistant.h63
-rw-r--r--examples/help/simpletextviewer/documentation/about.txt9
-rw-r--r--examples/help/simpletextviewer/documentation/browse.html34
-rw-r--r--examples/help/simpletextviewer/documentation/filedialog.html48
-rw-r--r--examples/help/simpletextviewer/documentation/findfile.html32
-rw-r--r--examples/help/simpletextviewer/documentation/images/browse.pngbin0 -> 21553 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/images/fadedfilemenu.pngbin0 -> 9589 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/images/filedialog.pngbin0 -> 12318 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/images/handbook.pngbin0 -> 1060 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/images/icon.pngbin0 -> 5513 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/images/mainwindow.pngbin0 -> 12769 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/images/open.pngbin0 -> 11697 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/images/wildcard.pngbin0 -> 11266 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/index.html41
-rw-r--r--examples/help/simpletextviewer/documentation/intro.html28
-rw-r--r--examples/help/simpletextviewer/documentation/openfile.html36
-rw-r--r--examples/help/simpletextviewer/documentation/simpletextviewer.qchbin0 -> 108544 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/simpletextviewer.qhcbin0 -> 18432 bytes
-rw-r--r--examples/help/simpletextviewer/documentation/simpletextviewer.qhcp30
-rw-r--r--examples/help/simpletextviewer/documentation/simpletextviewer.qhp49
-rw-r--r--examples/help/simpletextviewer/documentation/wildcardmatching.html57
-rw-r--r--examples/help/simpletextviewer/findfiledialog.cpp222
-rw-r--r--examples/help/simpletextviewer/findfiledialog.h99
-rw-r--r--examples/help/simpletextviewer/main.cpp52
-rw-r--r--examples/help/simpletextviewer/mainwindow.cpp147
-rw-r--r--examples/help/simpletextviewer/mainwindow.h84
-rw-r--r--examples/help/simpletextviewer/simpletextviewer.pro18
-rw-r--r--examples/help/simpletextviewer/textedit.cpp75
-rw-r--r--examples/help/simpletextviewer/textedit.h61
-rw-r--r--examples/ipc/README35
-rw-r--r--examples/ipc/ipc.pro10
-rw-r--r--examples/ipc/localfortuneclient/client.cpp153
-rw-r--r--examples/ipc/localfortuneclient/client.h82
-rw-r--r--examples/ipc/localfortuneclient/localfortuneclient.pro14
-rw-r--r--examples/ipc/localfortuneclient/main.cpp52
-rw-r--r--examples/ipc/localfortuneserver/localfortuneserver.pro14
-rw-r--r--examples/ipc/localfortuneserver/main.cpp56
-rw-r--r--examples/ipc/localfortuneserver/server.cpp111
-rw-r--r--examples/ipc/localfortuneserver/server.h70
-rw-r--r--examples/ipc/sharedmemory/dialog.cpp189
-rw-r--r--examples/ipc/sharedmemory/dialog.h71
-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.cpp54
-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.cpp83
-rw-r--r--examples/itemviews/addressbook/adddialog.h72
-rw-r--r--examples/itemviews/addressbook/addressbook.pro21
-rw-r--r--examples/itemviews/addressbook/addresswidget.cpp238
-rw-r--r--examples/itemviews/addressbook/addresswidget.h83
-rw-r--r--examples/itemviews/addressbook/main.cpp53
-rw-r--r--examples/itemviews/addressbook/mainwindow.cpp138
-rw-r--r--examples/itemviews/addressbook/mainwindow.h76
-rw-r--r--examples/itemviews/addressbook/newaddresstab.cpp78
-rw-r--r--examples/itemviews/addressbook/newaddresstab.h75
-rw-r--r--examples/itemviews/addressbook/tablemodel.cpp185
-rw-r--r--examples/itemviews/addressbook/tablemodel.h73
-rw-r--r--examples/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro12
-rw-r--r--examples/itemviews/basicsortfiltermodel/main.cpp94
-rw-r--r--examples/itemviews/basicsortfiltermodel/window.cpp157
-rw-r--r--examples/itemviews/basicsortfiltermodel/window.h89
-rw-r--r--examples/itemviews/chart/chart.pro19
-rw-r--r--examples/itemviews/chart/chart.qrc5
-rw-r--r--examples/itemviews/chart/main.cpp54
-rw-r--r--examples/itemviews/chart/mainwindow.cpp173
-rw-r--r--examples/itemviews/chart/mainwindow.h73
-rw-r--r--examples/itemviews/chart/mydata.cht8
-rw-r--r--examples/itemviews/chart/pieview.cpp562
-rw-r--r--examples/itemviews/chart/pieview.h115
-rw-r--r--examples/itemviews/chart/qtdata.cht14
-rw-r--r--examples/itemviews/coloreditorfactory/coloreditorfactory.pro13
-rw-r--r--examples/itemviews/coloreditorfactory/colorlisteditor.cpp77
-rw-r--r--examples/itemviews/coloreditorfactory/colorlisteditor.h70
-rw-r--r--examples/itemviews/coloreditorfactory/main.cpp54
-rw-r--r--examples/itemviews/coloreditorfactory/window.cpp95
-rw-r--r--examples/itemviews/coloreditorfactory/window.h58
-rw-r--r--examples/itemviews/combowidgetmapper/combowidgetmapper.pro9
-rw-r--r--examples/itemviews/combowidgetmapper/main.cpp52
-rw-r--r--examples/itemviews/combowidgetmapper/window.cpp137
-rw-r--r--examples/itemviews/combowidgetmapper/window.h87
-rw-r--r--examples/itemviews/customsortfiltermodel/customsortfiltermodel.pro14
-rw-r--r--examples/itemviews/customsortfiltermodel/main.cpp96
-rw-r--r--examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp116
-rw-r--r--examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.h74
-rw-r--r--examples/itemviews/customsortfiltermodel/window.cpp168
-rw-r--r--examples/itemviews/customsortfiltermodel/window.h91
-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.cpp54
-rw-r--r--examples/itemviews/editabletreemodel/mainwindow.cpp181
-rw-r--r--examples/itemviews/editabletreemodel/mainwindow.h72
-rw-r--r--examples/itemviews/editabletreemodel/mainwindow.ui128
-rw-r--r--examples/itemviews/editabletreemodel/treeitem.cpp180
-rw-r--r--examples/itemviews/editabletreemodel/treeitem.h75
-rw-r--r--examples/itemviews/editabletreemodel/treemodel.cpp289
-rw-r--r--examples/itemviews/editabletreemodel/treemodel.h98
-rw-r--r--examples/itemviews/fetchmore/fetchmore.pro12
-rw-r--r--examples/itemviews/fetchmore/filelistmodel.cpp116
-rw-r--r--examples/itemviews/fetchmore/filelistmodel.h76
-rw-r--r--examples/itemviews/fetchmore/main.cpp51
-rw-r--r--examples/itemviews/fetchmore/window.cpp82
-rw-r--r--examples/itemviews/fetchmore/window.h65
-rw-r--r--examples/itemviews/itemviews.pro28
-rw-r--r--examples/itemviews/pixelator/imagemodel.cpp92
-rw-r--r--examples/itemviews/pixelator/imagemodel.h69
-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.cpp55
-rw-r--r--examples/itemviews/pixelator/mainwindow.cpp245
-rw-r--r--examples/itemviews/pixelator/mainwindow.h75
-rw-r--r--examples/itemviews/pixelator/pixelator.pro16
-rw-r--r--examples/itemviews/pixelator/pixeldelegate.cpp108
-rw-r--r--examples/itemviews/pixelator/pixeldelegate.h80
-rw-r--r--examples/itemviews/puzzle/example.jpgbin0 -> 42654 bytes
-rw-r--r--examples/itemviews/puzzle/main.cpp55
-rw-r--r--examples/itemviews/puzzle/mainwindow.cpp150
-rw-r--r--examples/itemviews/puzzle/mainwindow.h78
-rw-r--r--examples/itemviews/puzzle/piecesmodel.cpp204
-rw-r--r--examples/itemviews/puzzle/piecesmodel.h81
-rw-r--r--examples/itemviews/puzzle/puzzle.pro16
-rw-r--r--examples/itemviews/puzzle/puzzle.qrc5
-rw-r--r--examples/itemviews/puzzle/puzzlewidget.cpp205
-rw-r--r--examples/itemviews/puzzle/puzzlewidget.h86
-rw-r--r--examples/itemviews/simpledommodel/domitem.cpp102
-rw-r--r--examples/itemviews/simpledommodel/domitem.h67
-rw-r--r--examples/itemviews/simpledommodel/dommodel.cpp190
-rw-r--r--examples/itemviews/simpledommodel/dommodel.h77
-rw-r--r--examples/itemviews/simpledommodel/main.cpp53
-rw-r--r--examples/itemviews/simpledommodel/mainwindow.cpp85
-rw-r--r--examples/itemviews/simpledommodel/mainwindow.h71
-rw-r--r--examples/itemviews/simpledommodel/simpledommodel.pro17
-rw-r--r--examples/itemviews/simpletreemodel/default.txt40
-rw-r--r--examples/itemviews/simpletreemodel/main.cpp62
-rw-r--r--examples/itemviews/simpletreemodel/simpletreemodel.pro15
-rw-r--r--examples/itemviews/simpletreemodel/simpletreemodel.qrc5
-rw-r--r--examples/itemviews/simpletreemodel/treeitem.cpp117
-rw-r--r--examples/itemviews/simpletreemodel/treeitem.h71
-rw-r--r--examples/itemviews/simpletreemodel/treemodel.cpp219
-rw-r--r--examples/itemviews/simpletreemodel/treemodel.h77
-rw-r--r--examples/itemviews/simplewidgetmapper/main.cpp52
-rw-r--r--examples/itemviews/simplewidgetmapper/simplewidgetmapper.pro11
-rw-r--r--examples/itemviews/simplewidgetmapper/window.cpp134
-rw-r--r--examples/itemviews/simplewidgetmapper/window.h85
-rw-r--r--examples/itemviews/spinboxdelegate/delegate.cpp103
-rw-r--r--examples/itemviews/spinboxdelegate/delegate.h71
-rw-r--r--examples/itemviews/spinboxdelegate/main.cpp87
-rw-r--r--examples/itemviews/spinboxdelegate/spinboxdelegate.pro11
-rw-r--r--examples/itemviews/stardelegate/main.cpp108
-rw-r--r--examples/itemviews/stardelegate/stardelegate.cpp130
-rw-r--r--examples/itemviews/stardelegate/stardelegate.h70
-rw-r--r--examples/itemviews/stardelegate/stardelegate.pro16
-rw-r--r--examples/itemviews/stardelegate/stareditor.cpp99
-rw-r--r--examples/itemviews/stardelegate/stareditor.h78
-rw-r--r--examples/itemviews/stardelegate/starrating.cpp103
-rw-r--r--examples/itemviews/stardelegate/starrating.h77
-rw-r--r--examples/layouts/README41
-rw-r--r--examples/layouts/basiclayouts/basiclayouts.pro11
-rw-r--r--examples/layouts/basiclayouts/dialog.cpp150
-rw-r--r--examples/layouts/basiclayouts/dialog.h91
-rw-r--r--examples/layouts/basiclayouts/main.cpp51
-rw-r--r--examples/layouts/borderlayout/borderlayout.cpp214
-rw-r--r--examples/layouts/borderlayout/borderlayout.h89
-rw-r--r--examples/layouts/borderlayout/borderlayout.pro13
-rw-r--r--examples/layouts/borderlayout/main.cpp52
-rw-r--r--examples/layouts/borderlayout/window.cpp69
-rw-r--r--examples/layouts/borderlayout/window.h62
-rw-r--r--examples/layouts/dynamiclayouts/dialog.cpp170
-rw-r--r--examples/layouts/dynamiclayouts/dialog.h91
-rw-r--r--examples/layouts/dynamiclayouts/dynamiclayouts.pro11
-rw-r--r--examples/layouts/dynamiclayouts/main.cpp51
-rw-r--r--examples/layouts/flowlayout/flowlayout.cpp154
-rw-r--r--examples/layouts/flowlayout/flowlayout.h73
-rw-r--r--examples/layouts/flowlayout/flowlayout.pro13
-rw-r--r--examples/layouts/flowlayout/main.cpp52
-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.cpp65
-rw-r--r--examples/linguist/arrowpad/arrowpad.h69
-rw-r--r--examples/linguist/arrowpad/arrowpad.pro18
-rw-r--r--examples/linguist/arrowpad/main.cpp64
-rw-r--r--examples/linguist/arrowpad/mainwindow.cpp62
-rw-r--r--examples/linguist/arrowpad/mainwindow.h69
-rw-r--r--examples/linguist/hellotr/hellotr.pro13
-rw-r--r--examples/linguist/hellotr/main.cpp71
-rw-r--r--examples/linguist/linguist.pro11
-rw-r--r--examples/linguist/trollprint/main.cpp61
-rw-r--r--examples/linguist/trollprint/mainwindow.cpp96
-rw-r--r--examples/linguist/trollprint/mainwindow.h75
-rw-r--r--examples/linguist/trollprint/printpanel.cpp86
-rw-r--r--examples/linguist/trollprint/printpanel.h70
-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.cpp56
-rw-r--r--examples/mainwindows/application/mainwindow.cpp396
-rw-r--r--examples/mainwindows/application/mainwindow.h106
-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.cpp53
-rw-r--r--examples/mainwindows/dockwidgets/mainwindow.cpp343
-rw-r--r--examples/mainwindows/dockwidgets/mainwindow.h98
-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.cpp54
-rw-r--r--examples/mainwindows/mdi/mainwindow.cpp399
-rw-r--r--examples/mainwindows/mdi/mainwindow.h119
-rw-r--r--examples/mainwindows/mdi/mdi.pro14
-rw-r--r--examples/mainwindows/mdi/mdi.qrc10
-rw-r--r--examples/mainwindows/mdi/mdichild.cpp176
-rw-r--r--examples/mainwindows/mdi/mdichild.h77
-rw-r--r--examples/mainwindows/menus/main.cpp52
-rw-r--r--examples/mainwindows/menus/mainwindow.cpp371
-rw-r--r--examples/mainwindows/menus/mainwindow.h125
-rw-r--r--examples/mainwindows/menus/menus.pro11
-rw-r--r--examples/mainwindows/recentfiles/main.cpp52
-rw-r--r--examples/mainwindows/recentfiles/mainwindow.cpp256
-rw-r--r--examples/mainwindows/recentfiles/mainwindow.h97
-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.cpp53
-rw-r--r--examples/mainwindows/sdi/mainwindow.cpp375
-rw-r--r--examples/mainwindows/sdi/mainwindow.h109
-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/blockingfortuneclient/blockingclient.cpp154
-rw-r--r--examples/network/blockingfortuneclient/blockingclient.h85
-rw-r--r--examples/network/blockingfortuneclient/blockingfortuneclient.pro14
-rw-r--r--examples/network/blockingfortuneclient/fortunethread.cpp138
-rw-r--r--examples/network/blockingfortuneclient/fortunethread.h74
-rw-r--r--examples/network/blockingfortuneclient/main.cpp52
-rw-r--r--examples/network/broadcastreceiver/broadcastreceiver.pro12
-rw-r--r--examples/network/broadcastreceiver/main.cpp52
-rw-r--r--examples/network/broadcastreceiver/receiver.cpp88
-rw-r--r--examples/network/broadcastreceiver/receiver.h69
-rw-r--r--examples/network/broadcastsender/broadcastsender.pro12
-rw-r--r--examples/network/broadcastsender/main.cpp52
-rw-r--r--examples/network/broadcastsender/sender.cpp92
-rw-r--r--examples/network/broadcastsender/sender.h76
-rw-r--r--examples/network/download/download.pro21
-rw-r--r--examples/network/download/main.cpp176
-rw-r--r--examples/network/downloadmanager/downloadmanager.cpp173
-rw-r--r--examples/network/downloadmanager/downloadmanager.h85
-rw-r--r--examples/network/downloadmanager/downloadmanager.pro22
-rw-r--r--examples/network/downloadmanager/main.cpp68
-rw-r--r--examples/network/downloadmanager/textprogressbar.cpp99
-rw-r--r--examples/network/downloadmanager/textprogressbar.h64
-rw-r--r--examples/network/fortuneclient/client.cpp191
-rw-r--r--examples/network/fortuneclient/client.h86
-rw-r--r--examples/network/fortuneclient/fortuneclient.pro12
-rw-r--r--examples/network/fortuneclient/main.cpp52
-rw-r--r--examples/network/fortuneserver/fortuneserver.pro12
-rw-r--r--examples/network/fortuneserver/main.cpp56
-rw-r--r--examples/network/fortuneserver/server.cpp123
-rw-r--r--examples/network/fortuneserver/server.h72
-rw-r--r--examples/network/ftp/ftp.pro21
-rw-r--r--examples/network/ftp/ftp.qrc7
-rw-r--r--examples/network/ftp/ftpwindow.cpp364
-rw-r--r--examples/network/ftp/ftpwindow.h104
-rw-r--r--examples/network/ftp/images/cdtoparent.pngbin0 -> 139 bytes
-rw-r--r--examples/network/ftp/images/dir.pngbin0 -> 154 bytes
-rw-r--r--examples/network/ftp/images/file.pngbin0 -> 129 bytes
-rw-r--r--examples/network/ftp/main.cpp106
-rw-r--r--examples/network/http/authenticationdialog.ui129
-rw-r--r--examples/network/http/http.pro13
-rw-r--r--examples/network/http/httpwindow.cpp262
-rw-r--r--examples/network/http/httpwindow.h94
-rw-r--r--examples/network/http/main.cpp52
-rw-r--r--examples/network/loopback/dialog.cpp187
-rw-r--r--examples/network/loopback/dialog.h90
-rw-r--r--examples/network/loopback/loopback.pro12
-rw-r--r--examples/network/loopback/main.cpp52
-rw-r--r--examples/network/network-chat/chatdialog.cpp141
-rw-r--r--examples/network/network-chat/chatdialog.h70
-rw-r--r--examples/network/network-chat/chatdialog.ui79
-rw-r--r--examples/network/network-chat/client.cpp140
-rw-r--r--examples/network/network-chat/client.h83
-rw-r--r--examples/network/network-chat/connection.cpp276
-rw-r--r--examples/network/network-chat/connection.h108
-rw-r--r--examples/network/network-chat/main.cpp52
-rw-r--r--examples/network/network-chat/network-chat.pro21
-rw-r--r--examples/network/network-chat/peermanager.cpp170
-rw-r--r--examples/network/network-chat/peermanager.h85
-rw-r--r--examples/network/network-chat/server.cpp58
-rw-r--r--examples/network/network-chat/server.h63
-rw-r--r--examples/network/network.pro25
-rw-r--r--examples/network/securesocketclient/certificateinfo.cpp100
-rw-r--r--examples/network/securesocketclient/certificateinfo.h69
-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.cpp63
-rw-r--r--examples/network/securesocketclient/securesocketclient.pro18
-rw-r--r--examples/network/securesocketclient/securesocketclient.qrc5
-rw-r--r--examples/network/securesocketclient/sslclient.cpp218
-rw-r--r--examples/network/securesocketclient/sslclient.h81
-rw-r--r--examples/network/securesocketclient/sslclient.ui190
-rw-r--r--examples/network/securesocketclient/sslerrors.ui110
-rw-r--r--examples/network/threadedfortuneserver/dialog.cpp82
-rw-r--r--examples/network/threadedfortuneserver/dialog.h66
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.cpp69
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.h64
-rw-r--r--examples/network/threadedfortuneserver/fortunethread.cpp77
-rw-r--r--examples/network/threadedfortuneserver/fortunethread.h67
-rw-r--r--examples/network/threadedfortuneserver/main.cpp56
-rw-r--r--examples/network/threadedfortuneserver/threadedfortuneserver.pro16
-rw-r--r--examples/network/torrent/addtorrentdialog.cpp170
-rw-r--r--examples/network/torrent/addtorrentdialog.h74
-rw-r--r--examples/network/torrent/bencodeparser.cpp235
-rw-r--r--examples/network/torrent/bencodeparser.h81
-rw-r--r--examples/network/torrent/connectionmanager.cpp89
-rw-r--r--examples/network/torrent/connectionmanager.h66
-rw-r--r--examples/network/torrent/filemanager.cpp447
-rw-r--r--examples/network/torrent/filemanager.h144
-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.cpp713
-rw-r--r--examples/network/torrent/mainwindow.h132
-rw-r--r--examples/network/torrent/metainfo.cpp218
-rw-r--r--examples/network/torrent/metainfo.h122
-rw-r--r--examples/network/torrent/peerwireclient.cpp665
-rw-r--r--examples/network/torrent/peerwireclient.h210
-rw-r--r--examples/network/torrent/ratecontroller.cpp156
-rw-r--r--examples/network/torrent/ratecontroller.h80
-rw-r--r--examples/network/torrent/torrent.pro39
-rw-r--r--examples/network/torrent/torrentclient.cpp1529
-rw-r--r--examples/network/torrent/torrentclient.h205
-rw-r--r--examples/network/torrent/torrentserver.cpp104
-rw-r--r--examples/network/torrent/torrentserver.h72
-rw-r--r--examples/network/torrent/trackerclient.cpp237
-rw-r--r--examples/network/torrent/trackerclient.h104
-rw-r--r--examples/opengl/2dpainting/2dpainting.pro19
-rw-r--r--examples/opengl/2dpainting/glwidget.cpp73
-rw-r--r--examples/opengl/2dpainting/glwidget.h73
-rw-r--r--examples/opengl/2dpainting/helper.cpp91
-rw-r--r--examples/opengl/2dpainting/helper.h72
-rw-r--r--examples/opengl/2dpainting/main.cpp51
-rw-r--r--examples/opengl/2dpainting/widget.cpp73
-rw-r--r--examples/opengl/2dpainting/widget.h72
-rw-r--r--examples/opengl/2dpainting/window.cpp72
-rw-r--r--examples/opengl/2dpainting/window.h67
-rw-r--r--examples/opengl/README41
-rw-r--r--examples/opengl/framebufferobject/bubbles.svg202
-rw-r--r--examples/opengl/framebufferobject/designer.pngbin0 -> 2810 bytes
-rw-r--r--examples/opengl/framebufferobject/framebufferobject.pro24
-rw-r--r--examples/opengl/framebufferobject/framebufferobject.qrc6
-rw-r--r--examples/opengl/framebufferobject/glwidget.cpp309
-rw-r--r--examples/opengl/framebufferobject/glwidget.h82
-rw-r--r--examples/opengl/framebufferobject/main.cpp62
-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.cpp249
-rw-r--r--examples/opengl/framebufferobject2/glwidget.h66
-rw-r--r--examples/opengl/framebufferobject2/main.cpp62
-rw-r--r--examples/opengl/grabber/glwidget.cpp284
-rw-r--r--examples/opengl/grabber/glwidget.h98
-rw-r--r--examples/opengl/grabber/grabber.pro14
-rw-r--r--examples/opengl/grabber/main.cpp52
-rw-r--r--examples/opengl/grabber/mainwindow.cpp207
-rw-r--r--examples/opengl/grabber/mainwindow.h95
-rw-r--r--examples/opengl/hellogl/glwidget.cpp250
-rw-r--r--examples/opengl/hellogl/glwidget.h99
-rw-r--r--examples/opengl/hellogl/hellogl.pro14
-rw-r--r--examples/opengl/hellogl/main.cpp52
-rw-r--r--examples/opengl/hellogl/window.cpp90
-rw-r--r--examples/opengl/hellogl/window.h70
-rw-r--r--examples/opengl/hellogl_es/bubble.cpp140
-rw-r--r--examples/opengl/hellogl_es/bubble.h77
-rw-r--r--examples/opengl/hellogl_es/cl_helper.h133
-rw-r--r--examples/opengl/hellogl_es/glwidget.cpp457
-rw-r--r--examples/opengl/hellogl_es/glwidget.h87
-rw-r--r--examples/opengl/hellogl_es/hellogl_es.pro34
-rw-r--r--examples/opengl/hellogl_es/main.cpp53
-rw-r--r--examples/opengl/hellogl_es/mainwindow.cpp108
-rw-r--r--examples/opengl/hellogl_es/mainwindow.h60
-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.cpp140
-rw-r--r--examples/opengl/hellogl_es2/bubble.h77
-rw-r--r--examples/opengl/hellogl_es2/glwidget.cpp642
-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.cpp53
-rw-r--r--examples/opengl/hellogl_es2/mainwindow.cpp108
-rw-r--r--examples/opengl/hellogl_es2/mainwindow.h60
-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.pro31
-rw-r--r--examples/opengl/overpainting/bubble.cpp113
-rw-r--r--examples/opengl/overpainting/bubble.h76
-rw-r--r--examples/opengl/overpainting/glwidget.cpp360
-rw-r--r--examples/opengl/overpainting/glwidget.h114
-rw-r--r--examples/opengl/overpainting/main.cpp51
-rw-r--r--examples/opengl/overpainting/overpainting.pro15
-rw-r--r--examples/opengl/pbuffers/cubelogo.pngbin0 -> 5920 bytes
-rw-r--r--examples/opengl/pbuffers/glwidget.cpp260
-rw-r--r--examples/opengl/pbuffers/glwidget.h70
-rw-r--r--examples/opengl/pbuffers/main.cpp62
-rw-r--r--examples/opengl/pbuffers/pbuffers.pro13
-rw-r--r--examples/opengl/pbuffers/pbuffers.qrc5
-rw-r--r--examples/opengl/pbuffers2/bubbles.svg202
-rw-r--r--examples/opengl/pbuffers2/designer.pngbin0 -> 2810 bytes
-rw-r--r--examples/opengl/pbuffers2/glwidget.cpp326
-rw-r--r--examples/opengl/pbuffers2/glwidget.h85
-rw-r--r--examples/opengl/pbuffers2/main.cpp62
-rw-r--r--examples/opengl/pbuffers2/pbuffers2.pro23
-rw-r--r--examples/opengl/pbuffers2/pbuffers2.qrc6
-rw-r--r--examples/opengl/samplebuffers/glwidget.cpp149
-rw-r--r--examples/opengl/samplebuffers/glwidget.h62
-rw-r--r--examples/opengl/samplebuffers/main.cpp72
-rw-r--r--examples/opengl/samplebuffers/samplebuffers.pro12
-rw-r--r--examples/opengl/textures/glwidget.cpp182
-rw-r--r--examples/opengl/textures/glwidget.h84
-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.cpp54
-rw-r--r--examples/opengl/textures/textures.pro15
-rw-r--r--examples/opengl/textures/textures.qrc10
-rw-r--r--examples/opengl/textures/window.cpp89
-rw-r--r--examples/opengl/textures/window.h67
-rw-r--r--examples/painting/README42
-rw-r--r--examples/painting/basicdrawing/basicdrawing.pro16
-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.cpp54
-rw-r--r--examples/painting/basicdrawing/renderarea.cpp209
-rw-r--r--examples/painting/basicdrawing/renderarea.h84
-rw-r--r--examples/painting/basicdrawing/window.cpp262
-rw-r--r--examples/painting/basicdrawing/window.h88
-rw-r--r--examples/painting/concentriccircles/circlewidget.cpp125
-rw-r--r--examples/painting/concentriccircles/circlewidget.h74
-rw-r--r--examples/painting/concentriccircles/concentriccircles.pro15
-rw-r--r--examples/painting/concentriccircles/main.cpp52
-rw-r--r--examples/painting/concentriccircles/window.cpp94
-rw-r--r--examples/painting/concentriccircles/window.h71
-rw-r--r--examples/painting/fontsampler/fontsampler.pro12
-rw-r--r--examples/painting/fontsampler/main.cpp52
-rw-r--r--examples/painting/fontsampler/mainwindow.cpp373
-rw-r--r--examples/painting/fontsampler/mainwindow.h83
-rw-r--r--examples/painting/fontsampler/mainwindowbase.ui140
-rw-r--r--examples/painting/imagecomposition/imagecomposer.cpp209
-rw-r--r--examples/painting/imagecomposition/imagecomposer.h88
-rw-r--r--examples/painting/imagecomposition/imagecomposition.pro14
-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.cpp56
-rw-r--r--examples/painting/painterpaths/main.cpp52
-rw-r--r--examples/painting/painterpaths/painterpaths.pro16
-rw-r--r--examples/painting/painterpaths/renderarea.cpp131
-rw-r--r--examples/painting/painterpaths/renderarea.h81
-rw-r--r--examples/painting/painterpaths/window.cpp289
-rw-r--r--examples/painting/painterpaths/window.h93
-rw-r--r--examples/painting/painting.pro18
-rw-r--r--examples/painting/svgviewer/files/bubbles.svg202
-rw-r--r--examples/painting/svgviewer/files/cubic.svg77
-rw-r--r--examples/painting/svgviewer/files/spheres.svg72
-rw-r--r--examples/painting/svgviewer/main.cpp63
-rw-r--r--examples/painting/svgviewer/mainwindow.cpp164
-rw-r--r--examples/painting/svgviewer/mainwindow.h81
-rw-r--r--examples/painting/svgviewer/svgview.cpp188
-rw-r--r--examples/painting/svgviewer/svgview.h84
-rw-r--r--examples/painting/svgviewer/svgviewer.pro32
-rw-r--r--examples/painting/svgviewer/svgviewer.qrc6
-rw-r--r--examples/painting/transformations/main.cpp52
-rw-r--r--examples/painting/transformations/renderarea.cpp173
-rw-r--r--examples/painting/transformations/renderarea.h91
-rw-r--r--examples/painting/transformations/transformations.pro15
-rw-r--r--examples/painting/transformations/window.cpp181
-rw-r--r--examples/painting/transformations/window.h81
-rw-r--r--examples/phonon/README39
-rw-r--r--examples/phonon/capabilities/capabilities.pro11
-rw-r--r--examples/phonon/capabilities/main.cpp58
-rw-r--r--examples/phonon/capabilities/window.cpp166
-rw-r--r--examples/phonon/capabilities/window.h97
-rw-r--r--examples/phonon/musicplayer/main.cpp57
-rw-r--r--examples/phonon/musicplayer/mainwindow.cpp352
-rw-r--r--examples/phonon/musicplayer/mainwindow.h112
-rw-r--r--examples/phonon/musicplayer/musicplayer.pro16
-rw-r--r--examples/phonon/phonon.pro12
-rw-r--r--examples/qmake/precompile/main.cpp61
-rw-r--r--examples/qmake/precompile/mydialog.cpp48
-rw-r--r--examples/qmake/precompile/mydialog.h55
-rw-r--r--examples/qmake/precompile/mydialog.ui47
-rw-r--r--examples/qmake/precompile/myobject.cpp58
-rw-r--r--examples/qmake/precompile/myobject.h56
-rw-r--r--examples/qmake/precompile/precompile.pro22
-rw-r--r--examples/qmake/precompile/stable.h53
-rw-r--r--examples/qmake/precompile/util.cpp50
-rw-r--r--examples/qmake/tutorial/hello.cpp50
-rw-r--r--examples/qmake/tutorial/hello.h48
-rw-r--r--examples/qmake/tutorial/hellounix.cpp43
-rw-r--r--examples/qmake/tutorial/hellowin.cpp43
-rw-r--r--examples/qmake/tutorial/main.cpp54
-rw-r--r--examples/qtconcurrent/README38
-rw-r--r--examples/qtconcurrent/imagescaling/imagescaling.cpp147
-rw-r--r--examples/qtconcurrent/imagescaling/imagescaling.h82
-rw-r--r--examples/qtconcurrent/imagescaling/imagescaling.pro15
-rw-r--r--examples/qtconcurrent/imagescaling/main.cpp64
-rw-r--r--examples/qtconcurrent/map/main.cpp82
-rw-r--r--examples/qtconcurrent/map/map.pro16
-rw-r--r--examples/qtconcurrent/progressdialog/main.cpp100
-rw-r--r--examples/qtconcurrent/progressdialog/progressdialog.pro16
-rw-r--r--examples/qtconcurrent/qtconcurrent.pro14
-rw-r--r--examples/qtconcurrent/runfunction/main.cpp73
-rw-r--r--examples/qtconcurrent/runfunction/runfunction.pro16
-rw-r--r--examples/qtconcurrent/wordcount/main.cpp167
-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.cpp65
-rw-r--r--examples/qtestlib/tutorial1/tutorial1.pro12
-rw-r--r--examples/qtestlib/tutorial2/testqstring.cpp81
-rw-r--r--examples/qtestlib/tutorial2/tutorial2.pro12
-rw-r--r--examples/qtestlib/tutorial3/testgui.cpp71
-rw-r--r--examples/qtestlib/tutorial3/tutorial3.pro12
-rw-r--r--examples/qtestlib/tutorial4/testgui.cpp91
-rw-r--r--examples/qtestlib/tutorial4/tutorial4.pro12
-rw-r--r--examples/qtestlib/tutorial5/benchmarking.cpp135
-rw-r--r--examples/qtestlib/tutorial5/tutorial5.pro12
-rw-r--r--examples/qws/README38
-rw-r--r--examples/qws/ahigl/ahigl.pro18
-rw-r--r--examples/qws/ahigl/qscreenahigl_qws.cpp963
-rw-r--r--examples/qws/ahigl/qscreenahigl_qws.h91
-rw-r--r--examples/qws/ahigl/qscreenahiglplugin.cpp97
-rw-r--r--examples/qws/ahigl/qwindowsurface_ahigl.cpp349
-rw-r--r--examples/qws/ahigl/qwindowsurface_ahigl_p.h92
-rw-r--r--examples/qws/dbscreen/dbscreen.cpp99
-rw-r--r--examples/qws/dbscreen/dbscreen.h70
-rw-r--r--examples/qws/dbscreen/dbscreen.pro13
-rw-r--r--examples/qws/dbscreen/dbscreendriverplugin.cpp80
-rw-r--r--examples/qws/framebuffer/framebuffer.pro13
-rw-r--r--examples/qws/framebuffer/main.c586
-rw-r--r--examples/qws/mousecalibration/calibration.cpp145
-rw-r--r--examples/qws/mousecalibration/calibration.h68
-rw-r--r--examples/qws/mousecalibration/main.cpp93
-rw-r--r--examples/qws/mousecalibration/mousecalibration.pro13
-rw-r--r--examples/qws/mousecalibration/scribblewidget.cpp93
-rw-r--r--examples/qws/mousecalibration/scribblewidget.h71
-rw-r--r--examples/qws/qws.pro9
-rw-r--r--examples/qws/simpledecoration/analogclock.cpp111
-rw-r--r--examples/qws/simpledecoration/analogclock.h58
-rw-r--r--examples/qws/simpledecoration/main.cpp60
-rw-r--r--examples/qws/simpledecoration/mydecoration.cpp375
-rw-r--r--examples/qws/simpledecoration/mydecoration.h73
-rw-r--r--examples/qws/simpledecoration/simpledecoration.pro12
-rw-r--r--examples/qws/svgalib/README5
-rw-r--r--examples/qws/svgalib/svgalib.pro21
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.cpp67
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.h66
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.cpp192
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.h79
-rw-r--r--examples/qws/svgalib/svgalibplugin.cpp75
-rw-r--r--examples/qws/svgalib/svgalibscreen.cpp354
-rw-r--r--examples/qws/svgalib/svgalibscreen.h84
-rw-r--r--examples/qws/svgalib/svgalibsurface.cpp87
-rw-r--r--examples/qws/svgalib/svgalibsurface.h76
-rw-r--r--examples/richtext/README42
-rw-r--r--examples/richtext/calendar/calendar.pro11
-rw-r--r--examples/richtext/calendar/main.cpp53
-rw-r--r--examples/richtext/calendar/mainwindow.cpp215
-rw-r--r--examples/richtext/calendar/mainwindow.h74
-rw-r--r--examples/richtext/orderform/detailsdialog.cpp157
-rw-r--r--examples/richtext/orderform/detailsdialog.h91
-rw-r--r--examples/richtext/orderform/main.cpp56
-rw-r--r--examples/richtext/orderform/mainwindow.cpp250
-rw-r--r--examples/richtext/orderform/mainwindow.h77
-rw-r--r--examples/richtext/orderform/orderform.pro13
-rw-r--r--examples/richtext/richtext.pro14
-rw-r--r--examples/richtext/syntaxhighlighter/highlighter.cpp148
-rw-r--r--examples/richtext/syntaxhighlighter/highlighter.h85
-rw-r--r--examples/richtext/syntaxhighlighter/main.cpp53
-rw-r--r--examples/richtext/syntaxhighlighter/mainwindow.cpp130
-rw-r--r--examples/richtext/syntaxhighlighter/mainwindow.h76
-rw-r--r--examples/richtext/syntaxhighlighter/syntaxhighlighter.pro19
-rw-r--r--examples/richtext/textobject/files/heart.svg55
-rw-r--r--examples/richtext/textobject/main.cpp55
-rw-r--r--examples/richtext/textobject/svgtextobject.cpp72
-rw-r--r--examples/richtext/textobject/svgtextobject.h70
-rw-r--r--examples/richtext/textobject/textobject.pro14
-rw-r--r--examples/richtext/textobject/window.cpp117
-rw-r--r--examples/richtext/textobject/window.h81
-rw-r--r--examples/script/README40
-rw-r--r--examples/script/calculator/calculator.js264
-rw-r--r--examples/script/calculator/calculator.pro14
-rw-r--r--examples/script/calculator/calculator.qrc6
-rw-r--r--examples/script/calculator/calculator.ui406
-rw-r--r--examples/script/calculator/main.cpp101
-rw-r--r--examples/script/context2d/context2d.cpp825
-rw-r--r--examples/script/context2d/context2d.h261
-rw-r--r--examples/script/context2d/context2d.pro32
-rw-r--r--examples/script/context2d/context2d.qrc5
-rw-r--r--examples/script/context2d/domimage.cpp157
-rw-r--r--examples/script/context2d/domimage.h87
-rw-r--r--examples/script/context2d/environment.cpp561
-rw-r--r--examples/script/context2d/environment.h145
-rw-r--r--examples/script/context2d/main.cpp54
-rw-r--r--examples/script/context2d/qcontext2dcanvas.cpp143
-rw-r--r--examples/script/context2d/qcontext2dcanvas.h98
-rw-r--r--examples/script/context2d/scripts/alpha.js21
-rw-r--r--examples/script/context2d/scripts/arc.js30
-rw-r--r--examples/script/context2d/scripts/bezier.js26
-rw-r--r--examples/script/context2d/scripts/clock.js99
-rw-r--r--examples/script/context2d/scripts/fill1.js8
-rw-r--r--examples/script/context2d/scripts/grad.js20
-rw-r--r--examples/script/context2d/scripts/linecap.js24
-rw-r--r--examples/script/context2d/scripts/linestye.js10
-rw-r--r--examples/script/context2d/scripts/moveto.js20
-rw-r--r--examples/script/context2d/scripts/moveto2.js24
-rw-r--r--examples/script/context2d/scripts/pacman.js83
-rw-r--r--examples/script/context2d/scripts/plasma.js58
-rw-r--r--examples/script/context2d/scripts/pong.js235
-rw-r--r--examples/script/context2d/scripts/quad.js21
-rw-r--r--examples/script/context2d/scripts/rgba.js19
-rw-r--r--examples/script/context2d/scripts/rotate.js16
-rw-r--r--examples/script/context2d/scripts/scale.js67
-rw-r--r--examples/script/context2d/scripts/stroke1.js10
-rw-r--r--examples/script/context2d/scripts/translate.js29
-rw-r--r--examples/script/context2d/window.cpp174
-rw-r--r--examples/script/context2d/window.h81
-rw-r--r--examples/script/customclass/bytearrayclass.cpp304
-rw-r--r--examples/script/customclass/bytearrayclass.h90
-rw-r--r--examples/script/customclass/bytearrayclass.pri6
-rw-r--r--examples/script/customclass/bytearrayprototype.cpp136
-rw-r--r--examples/script/customclass/bytearrayprototype.h80
-rw-r--r--examples/script/customclass/customclass.pro15
-rw-r--r--examples/script/customclass/main.cpp70
-rw-r--r--examples/script/defaultprototypes/code.js20
-rw-r--r--examples/script/defaultprototypes/defaultprototypes.pro12
-rw-r--r--examples/script/defaultprototypes/defaultprototypes.qrc5
-rw-r--r--examples/script/defaultprototypes/main.cpp84
-rw-r--r--examples/script/defaultprototypes/prototypes.cpp110
-rw-r--r--examples/script/defaultprototypes/prototypes.h78
-rw-r--r--examples/script/helloscript/helloscript.pro11
-rw-r--r--examples/script/helloscript/helloscript.qrc5
-rw-r--r--examples/script/helloscript/helloscript.qs5
-rw-r--r--examples/script/helloscript/main.cpp97
-rw-r--r--examples/script/marshal/main.cpp106
-rw-r--r--examples/script/marshal/marshal.pro11
-rw-r--r--examples/script/qscript/main.cpp221
-rw-r--r--examples/script/qscript/qscript.pro16
-rw-r--r--examples/script/qsdbg/example.qs17
-rw-r--r--examples/script/qsdbg/main.cpp74
-rw-r--r--examples/script/qsdbg/qsdbg.pri9
-rw-r--r--examples/script/qsdbg/qsdbg.pro21
-rw-r--r--examples/script/qsdbg/scriptbreakpointmanager.cpp159
-rw-r--r--examples/script/qsdbg/scriptbreakpointmanager.h122
-rw-r--r--examples/script/qsdbg/scriptdebugger.cpp737
-rw-r--r--examples/script/qsdbg/scriptdebugger.h85
-rw-r--r--examples/script/qstetrix/main.cpp142
-rw-r--r--examples/script/qstetrix/qstetrix.pro17
-rw-r--r--examples/script/qstetrix/tetrix.qrc8
-rw-r--r--examples/script/qstetrix/tetrixboard.cpp139
-rw-r--r--examples/script/qstetrix/tetrixboard.h102
-rw-r--r--examples/script/qstetrix/tetrixboard.js261
-rw-r--r--examples/script/qstetrix/tetrixpiece.js131
-rw-r--r--examples/script/qstetrix/tetrixwindow.js16
-rw-r--r--examples/script/qstetrix/tetrixwindow.ui175
-rw-r--r--examples/script/script.pro15
-rw-r--r--examples/sql/README40
-rw-r--r--examples/sql/cachedtable/cachedtable.pro13
-rw-r--r--examples/sql/cachedtable/main.cpp58
-rw-r--r--examples/sql/cachedtable/tableeditor.cpp106
-rw-r--r--examples/sql/cachedtable/tableeditor.h73
-rw-r--r--examples/sql/connection.h136
-rw-r--r--examples/sql/drilldown/drilldown.pro20
-rw-r--r--examples/sql/drilldown/drilldown.qrc11
-rw-r--r--examples/sql/drilldown/imageitem.cpp124
-rw-r--r--examples/sql/drilldown/imageitem.h75
-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.cpp172
-rw-r--r--examples/sql/drilldown/informationwindow.h91
-rw-r--r--examples/sql/drilldown/logo.pngbin0 -> 13378 bytes
-rw-r--r--examples/sql/drilldown/main.cpp63
-rw-r--r--examples/sql/drilldown/view.cpp192
-rw-r--r--examples/sql/drilldown/view.h81
-rw-r--r--examples/sql/masterdetail/albumdetails.xml98
-rw-r--r--examples/sql/masterdetail/database.h97
-rw-r--r--examples/sql/masterdetail/dialog.cpp283
-rw-r--r--examples/sql/masterdetail/dialog.h83
-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.cpp60
-rw-r--r--examples/sql/masterdetail/mainwindow.cpp430
-rw-r--r--examples/sql/masterdetail/mainwindow.h104
-rw-r--r--examples/sql/masterdetail/masterdetail.pro18
-rw-r--r--examples/sql/masterdetail/masterdetail.qrc6
-rw-r--r--examples/sql/querymodel/customsqlmodel.cpp65
-rw-r--r--examples/sql/querymodel/customsqlmodel.h59
-rw-r--r--examples/sql/querymodel/editablesqlmodel.cpp110
-rw-r--r--examples/sql/querymodel/editablesqlmodel.h63
-rw-r--r--examples/sql/querymodel/main.cpp87
-rw-r--r--examples/sql/querymodel/querymodel.pro15
-rw-r--r--examples/sql/relationaltablemodel/relationaltablemodel.cpp115
-rw-r--r--examples/sql/relationaltablemodel/relationaltablemodel.pro11
-rw-r--r--examples/sql/sql.pro18
-rw-r--r--examples/sql/sqlwidgetmapper/main.cpp52
-rw-r--r--examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro10
-rw-r--r--examples/sql/sqlwidgetmapper/window.cpp159
-rw-r--r--examples/sql/sqlwidgetmapper/window.h90
-rw-r--r--examples/sql/tablemodel/tablemodel.cpp84
-rw-r--r--examples/sql/tablemodel/tablemodel.pro11
-rw-r--r--examples/threads/README40
-rw-r--r--examples/threads/mandelbrot/main.cpp54
-rw-r--r--examples/threads/mandelbrot/mandelbrot.pro15
-rw-r--r--examples/threads/mandelbrot/mandelbrotwidget.cpp240
-rw-r--r--examples/threads/mandelbrot/mandelbrotwidget.h85
-rw-r--r--examples/threads/mandelbrot/renderthread.cpp216
-rw-r--r--examples/threads/mandelbrot/renderthread.h89
-rw-r--r--examples/threads/queuedcustomtype/block.cpp74
-rw-r--r--examples/threads/queuedcustomtype/block.h71
-rw-r--r--examples/threads/queuedcustomtype/main.cpp129
-rw-r--r--examples/threads/queuedcustomtype/queuedcustomtype.pro7
-rw-r--r--examples/threads/queuedcustomtype/renderthread.cpp110
-rw-r--r--examples/threads/queuedcustomtype/renderthread.h77
-rw-r--r--examples/threads/queuedcustomtype/window.cpp137
-rw-r--r--examples/threads/queuedcustomtype/window.h77
-rw-r--r--examples/threads/semaphores/semaphores.cpp107
-rw-r--r--examples/threads/semaphores/semaphores.pro12
-rw-r--r--examples/threads/threads.pro12
-rw-r--r--examples/threads/waitconditions/waitconditions.cpp126
-rw-r--r--examples/threads/waitconditions/waitconditions.pro22
-rw-r--r--examples/tools/README40
-rw-r--r--examples/tools/codecs/codecs.pro13
-rw-r--r--examples/tools/codecs/encodedfiles/.gitattributes2
-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.cpp52
-rw-r--r--examples/tools/codecs/mainwindow.cpp203
-rw-r--r--examples/tools/codecs/mainwindow.h88
-rw-r--r--examples/tools/codecs/previewform.cpp102
-rw-r--r--examples/tools/codecs/previewform.h80
-rw-r--r--examples/tools/completer/completer.pro14
-rw-r--r--examples/tools/completer/completer.qrc6
-rw-r--r--examples/tools/completer/dirmodel.cpp63
-rw-r--r--examples/tools/completer/dirmodel.h61
-rw-r--r--examples/tools/completer/main.cpp55
-rw-r--r--examples/tools/completer/mainwindow.cpp264
-rw-r--r--examples/tools/completer/mainwindow.h87
-rw-r--r--examples/tools/completer/resources/countries.txt241
-rw-r--r--examples/tools/completer/resources/wordlist.txt1486
-rw-r--r--examples/tools/customcompleter/customcompleter.pro14
-rw-r--r--examples/tools/customcompleter/customcompleter.qrc5
-rw-r--r--examples/tools/customcompleter/main.cpp55
-rw-r--r--examples/tools/customcompleter/mainwindow.cpp118
-rw-r--r--examples/tools/customcompleter/mainwindow.h77
-rw-r--r--examples/tools/customcompleter/resources/wordlist.txt1455
-rw-r--r--examples/tools/customcompleter/textedit.cpp174
-rw-r--r--examples/tools/customcompleter/textedit.h79
-rw-r--r--examples/tools/customtype/customtype.pro3
-rw-r--r--examples/tools/customtype/main.cpp74
-rw-r--r--examples/tools/customtype/message.cpp90
-rw-r--r--examples/tools/customtype/message.h76
-rw-r--r--examples/tools/customtypesending/customtypesending.pro5
-rw-r--r--examples/tools/customtypesending/main.cpp68
-rw-r--r--examples/tools/customtypesending/message.cpp72
-rw-r--r--examples/tools/customtypesending/message.h72
-rw-r--r--examples/tools/customtypesending/window.cpp80
-rw-r--r--examples/tools/customtypesending/window.h73
-rw-r--r--examples/tools/echoplugin/echoplugin.pro13
-rw-r--r--examples/tools/echoplugin/echowindow/echointerface.h62
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.cpp119
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.h80
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.pro20
-rw-r--r--examples/tools/echoplugin/echowindow/main.cpp57
-rw-r--r--examples/tools/echoplugin/plugin/echoplugin.cpp55
-rw-r--r--examples/tools/echoplugin/plugin/echoplugin.h60
-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.cpp167
-rw-r--r--examples/tools/i18n/languagechooser.h86
-rw-r--r--examples/tools/i18n/main.cpp55
-rw-r--r--examples/tools/i18n/mainwindow.cpp96
-rw-r--r--examples/tools/i18n/mainwindow.h77
-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/plugandpaint/interfaces.h111
-rw-r--r--examples/tools/plugandpaint/main.cpp58
-rw-r--r--examples/tools/plugandpaint/mainwindow.cpp310
-rw-r--r--examples/tools/plugandpaint/mainwindow.h104
-rw-r--r--examples/tools/plugandpaint/paintarea.cpp196
-rw-r--r--examples/tools/plugandpaint/paintarea.h92
-rw-r--r--examples/tools/plugandpaint/plugandpaint.pro28
-rw-r--r--examples/tools/plugandpaint/plugindialog.cpp157
-rw-r--r--examples/tools/plugandpaint/plugindialog.h77
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictools.pro17
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp198
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h88
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro19
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp125
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h64
-rw-r--r--examples/tools/plugandpaintplugins/plugandpaintplugins.pro11
-rw-r--r--examples/tools/regexp/main.cpp52
-rw-r--r--examples/tools/regexp/regexp.pro11
-rw-r--r--examples/tools/regexp/regexpdialog.cpp188
-rw-r--r--examples/tools/regexp/regexpdialog.h86
-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.cpp217
-rw-r--r--examples/tools/settingseditor/locationdialog.h85
-rw-r--r--examples/tools/settingseditor/main.cpp52
-rw-r--r--examples/tools/settingseditor/mainwindow.cpp223
-rw-r--r--examples/tools/settingseditor/mainwindow.h92
-rw-r--r--examples/tools/settingseditor/settingseditor.pro17
-rw-r--r--examples/tools/settingseditor/settingstree.cpp263
-rw-r--r--examples/tools/settingseditor/settingstree.h91
-rw-r--r--examples/tools/settingseditor/variantdelegate.cpp317
-rw-r--r--examples/tools/settingseditor/variantdelegate.h82
-rw-r--r--examples/tools/styleplugin/plugin/plugin.pro25
-rw-r--r--examples/tools/styleplugin/plugin/simplestyle.cpp49
-rw-r--r--examples/tools/styleplugin/plugin/simplestyle.h61
-rw-r--r--examples/tools/styleplugin/plugin/simplestyleplugin.cpp65
-rw-r--r--examples/tools/styleplugin/plugin/simplestyleplugin.h65
-rw-r--r--examples/tools/styleplugin/styleplugin.pro11
-rw-r--r--examples/tools/styleplugin/stylewindow/main.cpp58
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.cpp61
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.h55
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.pro19
-rw-r--r--examples/tools/tools.pro24
-rw-r--r--examples/tools/treemodelcompleter/main.cpp55
-rw-r--r--examples/tools/treemodelcompleter/mainwindow.cpp247
-rw-r--r--examples/tools/treemodelcompleter/mainwindow.h89
-rw-r--r--examples/tools/treemodelcompleter/resources/treemodel.txt20
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.cpp98
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.h71
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.pro14
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.qrc5
-rw-r--r--examples/tools/undoframework/commands.cpp163
-rw-r--r--examples/tools/undoframework/commands.h104
-rw-r--r--examples/tools/undoframework/diagramitem.cpp66
-rw-r--r--examples/tools/undoframework/diagramitem.h73
-rw-r--r--examples/tools/undoframework/diagramscene.cpp76
-rw-r--r--examples/tools/undoframework/diagramscene.h75
-rw-r--r--examples/tools/undoframework/images/cross.pngbin0 -> 114 bytes
-rw-r--r--examples/tools/undoframework/main.cpp58
-rw-r--r--examples/tools/undoframework/mainwindow.cpp209
-rw-r--r--examples/tools/undoframework/mainwindow.h100
-rw-r--r--examples/tools/undoframework/undoframework.pro18
-rw-r--r--examples/tools/undoframework/undoframework.qrc6
-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.cpp68
-rw-r--r--examples/tutorials/addressbook-fr/part1/addressbook.h67
-rw-r--r--examples/tutorials/addressbook-fr/part1/main.cpp55
-rw-r--r--examples/tutorials/addressbook-fr/part1/part1.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part2/addressbook.cpp158
-rw-r--r--examples/tutorials/addressbook-fr/part2/addressbook.h85
-rw-r--r--examples/tutorials/addressbook-fr/part2/main.cpp55
-rw-r--r--examples/tutorials/addressbook-fr/part2/part2.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part3/addressbook.cpp217
-rw-r--r--examples/tutorials/addressbook-fr/part3/addressbook.h87
-rw-r--r--examples/tutorials/addressbook-fr/part3/main.cpp53
-rw-r--r--examples/tutorials/addressbook-fr/part3/part3.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part4/addressbook.cpp291
-rw-r--r--examples/tutorials/addressbook-fr/part4/addressbook.h100
-rw-r--r--examples/tutorials/addressbook-fr/part4/main.cpp53
-rw-r--r--examples/tutorials/addressbook-fr/part4/part4.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part5/addressbook.cpp315
-rw-r--r--examples/tutorials/addressbook-fr/part5/addressbook.h103
-rw-r--r--examples/tutorials/addressbook-fr/part5/finddialog.cpp87
-rw-r--r--examples/tutorials/addressbook-fr/part5/finddialog.h69
-rw-r--r--examples/tutorials/addressbook-fr/part5/main.cpp53
-rw-r--r--examples/tutorials/addressbook-fr/part5/part5.pro11
-rw-r--r--examples/tutorials/addressbook-fr/part6/addressbook.cpp396
-rw-r--r--examples/tutorials/addressbook-fr/part6/addressbook.h104
-rw-r--r--examples/tutorials/addressbook-fr/part6/finddialog.cpp83
-rw-r--r--examples/tutorials/addressbook-fr/part6/finddialog.h69
-rw-r--r--examples/tutorials/addressbook-fr/part6/main.cpp53
-rw-r--r--examples/tutorials/addressbook-fr/part6/part6.pro11
-rw-r--r--examples/tutorials/addressbook-fr/part7/addressbook.cpp449
-rw-r--r--examples/tutorials/addressbook-fr/part7/addressbook.h106
-rw-r--r--examples/tutorials/addressbook-fr/part7/finddialog.cpp83
-rw-r--r--examples/tutorials/addressbook-fr/part7/finddialog.h69
-rw-r--r--examples/tutorials/addressbook-fr/part7/main.cpp53
-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.cpp68
-rw-r--r--examples/tutorials/addressbook/part1/addressbook.h67
-rw-r--r--examples/tutorials/addressbook/part1/main.cpp55
-rw-r--r--examples/tutorials/addressbook/part1/part1.pro11
-rw-r--r--examples/tutorials/addressbook/part2/addressbook.cpp158
-rw-r--r--examples/tutorials/addressbook/part2/addressbook.h85
-rw-r--r--examples/tutorials/addressbook/part2/main.cpp55
-rw-r--r--examples/tutorials/addressbook/part2/part2.pro11
-rw-r--r--examples/tutorials/addressbook/part3/addressbook.cpp217
-rw-r--r--examples/tutorials/addressbook/part3/addressbook.h87
-rw-r--r--examples/tutorials/addressbook/part3/main.cpp53
-rw-r--r--examples/tutorials/addressbook/part3/part3.pro11
-rw-r--r--examples/tutorials/addressbook/part4/addressbook.cpp291
-rw-r--r--examples/tutorials/addressbook/part4/addressbook.h100
-rw-r--r--examples/tutorials/addressbook/part4/main.cpp53
-rw-r--r--examples/tutorials/addressbook/part4/part4.pro11
-rw-r--r--examples/tutorials/addressbook/part5/addressbook.cpp315
-rw-r--r--examples/tutorials/addressbook/part5/addressbook.h103
-rw-r--r--examples/tutorials/addressbook/part5/finddialog.cpp87
-rw-r--r--examples/tutorials/addressbook/part5/finddialog.h69
-rw-r--r--examples/tutorials/addressbook/part5/main.cpp53
-rw-r--r--examples/tutorials/addressbook/part5/part5.pro13
-rw-r--r--examples/tutorials/addressbook/part6/addressbook.cpp396
-rw-r--r--examples/tutorials/addressbook/part6/addressbook.h104
-rw-r--r--examples/tutorials/addressbook/part6/finddialog.cpp83
-rw-r--r--examples/tutorials/addressbook/part6/finddialog.h69
-rw-r--r--examples/tutorials/addressbook/part6/main.cpp53
-rw-r--r--examples/tutorials/addressbook/part6/part6.pro13
-rw-r--r--examples/tutorials/addressbook/part7/addressbook.cpp449
-rw-r--r--examples/tutorials/addressbook/part7/addressbook.h106
-rw-r--r--examples/tutorials/addressbook/part7/finddialog.cpp83
-rw-r--r--examples/tutorials/addressbook/part7/finddialog.h69
-rw-r--r--examples/tutorials/addressbook/part7/main.cpp53
-rw-r--r--examples/tutorials/addressbook/part7/part7.pro13
-rw-r--r--examples/tutorials/tutorials.pro10
-rw-r--r--examples/uitools/multipleinheritance/calculatorform.cpp66
-rw-r--r--examples/uitools/multipleinheritance/calculatorform.h63
-rw-r--r--examples/uitools/multipleinheritance/calculatorform.ui303
-rw-r--r--examples/uitools/multipleinheritance/main.cpp53
-rw-r--r--examples/uitools/multipleinheritance/multipleinheritance.pro13
-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.cpp56
-rw-r--r--examples/uitools/textfinder/textfinder.cpp156
-rw-r--r--examples/uitools/textfinder/textfinder.h75
-rw-r--r--examples/uitools/textfinder/textfinder.pro12
-rw-r--r--examples/uitools/textfinder/textfinder.qrc6
-rw-r--r--examples/uitools/uitools.pro12
-rwxr-xr-xexamples/webkit/formextractor/form.html64
-rw-r--r--examples/webkit/formextractor/formextractor.cpp74
-rw-r--r--examples/webkit/formextractor/formextractor.h67
-rw-r--r--examples/webkit/formextractor/formextractor.pro18
-rw-r--r--examples/webkit/formextractor/formextractor.qrc5
-rw-r--r--examples/webkit/formextractor/formextractor.ui159
-rw-r--r--examples/webkit/formextractor/main.cpp53
-rw-r--r--examples/webkit/formextractor/mainwindow.cpp87
-rw-r--r--examples/webkit/formextractor/mainwindow.h75
-rw-r--r--examples/webkit/previewer/main.cpp53
-rw-r--r--examples/webkit/previewer/mainwindow.cpp197
-rw-r--r--examples/webkit/previewer/mainwindow.h87
-rw-r--r--examples/webkit/previewer/previewer.cpp65
-rw-r--r--examples/webkit/previewer/previewer.h65
-rw-r--r--examples/webkit/previewer/previewer.pro15
-rw-r--r--examples/webkit/previewer/previewer.ui99
-rw-r--r--examples/webkit/webkit.pro11
-rw-r--r--examples/widgets/README44
-rw-r--r--examples/widgets/analogclock/analogclock.cpp146
-rw-r--r--examples/widgets/analogclock/analogclock.h60
-rw-r--r--examples/widgets/analogclock/analogclock.pro13
-rw-r--r--examples/widgets/analogclock/main.cpp52
-rw-r--r--examples/widgets/calculator/button.cpp64
-rw-r--r--examples/widgets/calculator/button.h59
-rw-r--r--examples/widgets/calculator/calculator.cpp398
-rw-r--r--examples/widgets/calculator/calculator.h108
-rw-r--r--examples/widgets/calculator/calculator.pro15
-rw-r--r--examples/widgets/calculator/main.cpp52
-rw-r--r--examples/widgets/calendarwidget/calendarwidget.pro13
-rw-r--r--examples/widgets/calendarwidget/main.cpp52
-rw-r--r--examples/widgets/calendarwidget/window.cpp462
-rw-r--r--examples/widgets/calendarwidget/window.h128
-rw-r--r--examples/widgets/charactermap/charactermap.pro13
-rw-r--r--examples/widgets/charactermap/characterwidget.cpp178
-rw-r--r--examples/widgets/charactermap/characterwidget.h87
-rw-r--r--examples/widgets/charactermap/main.cpp52
-rw-r--r--examples/widgets/charactermap/mainwindow.cpp196
-rw-r--r--examples/widgets/charactermap/mainwindow.h84
-rw-r--r--examples/widgets/codeeditor/codeeditor.cpp171
-rw-r--r--examples/widgets/codeeditor/codeeditor.h106
-rw-r--r--examples/widgets/codeeditor/codeeditor.pro9
-rw-r--r--examples/widgets/codeeditor/main.cpp56
-rw-r--r--examples/widgets/digitalclock/digitalclock.cpp73
-rw-r--r--examples/widgets/digitalclock/digitalclock.h60
-rw-r--r--examples/widgets/digitalclock/digitalclock.pro11
-rw-r--r--examples/widgets/digitalclock/main.cpp52
-rw-r--r--examples/widgets/groupbox/groupbox.pro11
-rw-r--r--examples/widgets/groupbox/main.cpp52
-rw-r--r--examples/widgets/groupbox/window.cpp190
-rw-r--r--examples/widgets/groupbox/window.h67
-rw-r--r--examples/widgets/icons/iconpreviewarea.cpp142
-rw-r--r--examples/widgets/icons/iconpreviewarea.h78
-rw-r--r--examples/widgets/icons/icons.pro27
-rw-r--r--examples/widgets/icons/iconsizespinbox.cpp71
-rw-r--r--examples/widgets/icons/iconsizespinbox.h60
-rw-r--r--examples/widgets/icons/imagedelegate.cpp106
-rw-r--r--examples/widgets/icons/imagedelegate.h69
-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.cpp52
-rw-r--r--examples/widgets/icons/mainwindow.cpp443
-rw-r--r--examples/widgets/icons/mainwindow.h117
-rw-r--r--examples/widgets/imageviewer/imageviewer.cpp278
-rw-r--r--examples/widgets/imageviewer/imageviewer.h104
-rw-r--r--examples/widgets/imageviewer/imageviewer.pro15
-rw-r--r--examples/widgets/imageviewer/main.cpp52
-rw-r--r--examples/widgets/lineedits/lineedits.pro13
-rw-r--r--examples/widgets/lineedits/main.cpp52
-rw-r--r--examples/widgets/lineedits/window.cpp257
-rw-r--r--examples/widgets/lineedits/window.h76
-rw-r--r--examples/widgets/movie/animation.mngbin0 -> 5464 bytes
-rw-r--r--examples/widgets/movie/main.cpp52
-rw-r--r--examples/widgets/movie/movie.pro11
-rw-r--r--examples/widgets/movie/movieplayer.cpp211
-rw-r--r--examples/widgets/movie/movieplayer.h97
-rw-r--r--examples/widgets/scribble/main.cpp52
-rw-r--r--examples/widgets/scribble/mainwindow.cpp251
-rw-r--r--examples/widgets/scribble/mainwindow.h93
-rw-r--r--examples/widgets/scribble/scribble.pro13
-rw-r--r--examples/widgets/scribble/scribblearea.cpp215
-rw-r--r--examples/widgets/scribble/scribblearea.h91
-rw-r--r--examples/widgets/shapedclock/main.cpp52
-rw-r--r--examples/widgets/shapedclock/shapedclock.cpp159
-rw-r--r--examples/widgets/shapedclock/shapedclock.h67
-rw-r--r--examples/widgets/shapedclock/shapedclock.pro13
-rw-r--r--examples/widgets/sliders/main.cpp52
-rw-r--r--examples/widgets/sliders/sliders.pro13
-rw-r--r--examples/widgets/sliders/slidersgroup.cpp133
-rw-r--r--examples/widgets/sliders/slidersgroup.h79
-rw-r--r--examples/widgets/sliders/window.cpp146
-rw-r--r--examples/widgets/sliders/window.h85
-rw-r--r--examples/widgets/spinboxes/main.cpp52
-rw-r--r--examples/widgets/spinboxes/spinboxes.pro11
-rw-r--r--examples/widgets/spinboxes/window.cpp252
-rw-r--r--examples/widgets/spinboxes/window.h82
-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.cpp54
-rw-r--r--examples/widgets/styles/norwegianwoodstyle.cpp331
-rw-r--r--examples/widgets/styles/norwegianwoodstyle.h79
-rw-r--r--examples/widgets/styles/styles.pro16
-rw-r--r--examples/widgets/styles/styles.qrc6
-rw-r--r--examples/widgets/styles/widgetgallery.cpp276
-rw-r--r--examples/widgets/styles/widgetgallery.h122
-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.cpp54
-rw-r--r--examples/widgets/stylesheet/mainwindow.cpp75
-rw-r--r--examples/widgets/stylesheet/mainwindow.h67
-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.cpp94
-rw-r--r--examples/widgets/stylesheet/stylesheeteditor.h68
-rw-r--r--examples/widgets/stylesheet/stylesheeteditor.ui171
-rw-r--r--examples/widgets/tablet/main.cpp61
-rw-r--r--examples/widgets/tablet/mainwindow.cpp275
-rw-r--r--examples/widgets/tablet/mainwindow.h114
-rw-r--r--examples/widgets/tablet/tablet.pro15
-rw-r--r--examples/widgets/tablet/tabletapplication.cpp57
-rw-r--r--examples/widgets/tablet/tabletapplication.h67
-rw-r--r--examples/widgets/tablet/tabletcanvas.cpp257
-rw-r--r--examples/widgets/tablet/tabletcanvas.h115
-rw-r--r--examples/widgets/tetrix/main.cpp55
-rw-r--r--examples/widgets/tetrix/tetrix.pro17
-rw-r--r--examples/widgets/tetrix/tetrixboard.cpp409
-rw-r--r--examples/widgets/tetrix/tetrixboard.h117
-rw-r--r--examples/widgets/tetrix/tetrixpiece.cpp146
-rw-r--r--examples/widgets/tetrix/tetrixpiece.h76
-rw-r--r--examples/widgets/tetrix/tetrixwindow.cpp116
-rw-r--r--examples/widgets/tetrix/tetrixwindow.h77
-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.cpp55
-rw-r--r--examples/widgets/tooltips/shapeitem.cpp100
-rw-r--r--examples/widgets/tooltips/shapeitem.h71
-rw-r--r--examples/widgets/tooltips/sortingbox.cpp302
-rw-r--r--examples/widgets/tooltips/sortingbox.h107
-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.cpp63
-rw-r--r--examples/widgets/validators/ledwidget.h65
-rw-r--r--examples/widgets/validators/localeselector.cpp313
-rw-r--r--examples/widgets/validators/localeselector.h61
-rw-r--r--examples/widgets/validators/main.cpp137
-rw-r--r--examples/widgets/validators/validators.pro23
-rw-r--r--examples/widgets/validators/validators.qrc6
-rw-r--r--examples/widgets/validators/validators.ui467
-rw-r--r--examples/widgets/widgets.pro42
-rw-r--r--examples/widgets/wiggly/dialog.cpp70
-rw-r--r--examples/widgets/wiggly/dialog.h57
-rw-r--r--examples/widgets/wiggly/main.cpp61
-rw-r--r--examples/widgets/wiggly/wiggly.pro15
-rw-r--r--examples/widgets/wiggly/wigglywidget.cpp101
-rw-r--r--examples/widgets/wiggly/wigglywidget.h70
-rw-r--r--examples/widgets/windowflags/controllerwindow.cpp221
-rw-r--r--examples/widgets/windowflags/controllerwindow.h105
-rw-r--r--examples/widgets/windowflags/main.cpp52
-rw-r--r--examples/widgets/windowflags/previewwindow.cpp119
-rw-r--r--examples/widgets/windowflags/previewwindow.h68
-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.cpp53
-rw-r--r--examples/xml/dombookmarks/mainwindow.cpp146
-rw-r--r--examples/xml/dombookmarks/mainwindow.h76
-rw-r--r--examples/xml/dombookmarks/xbeltree.cpp187
-rw-r--r--examples/xml/dombookmarks/xbeltree.h75
-rw-r--r--examples/xml/htmlinfo/apache_org.html281
-rw-r--r--examples/xml/htmlinfo/htmlinfo.pro18
-rw-r--r--examples/xml/htmlinfo/main.cpp89
-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.cpp64
-rw-r--r--examples/xml/rsslisting/rsslisting.cpp239
-rw-r--r--examples/xml/rsslisting/rsslisting.h87
-rw-r--r--examples/xml/rsslisting/rsslisting.pro12
-rw-r--r--examples/xml/saxbookmarks/frank.xbel230
-rw-r--r--examples/xml/saxbookmarks/frankf.xbel230
-rw-r--r--examples/xml/saxbookmarks/jennifer.xbel93
-rw-r--r--examples/xml/saxbookmarks/jenniferf.xbel93
-rw-r--r--examples/xml/saxbookmarks/main.cpp57
-rw-r--r--examples/xml/saxbookmarks/mainwindow.cpp164
-rw-r--r--examples/xml/saxbookmarks/mainwindow.h78
-rw-r--r--examples/xml/saxbookmarks/saxbookmarks.pro29
-rw-r--r--examples/xml/saxbookmarks/xbelgenerator.cpp115
-rw-r--r--examples/xml/saxbookmarks/xbelgenerator.h69
-rw-r--r--examples/xml/saxbookmarks/xbelhandler.cpp147
-rw-r--r--examples/xml/saxbookmarks/xbelhandler.h79
-rw-r--r--examples/xml/streambookmarks/frank.xbel230
-rw-r--r--examples/xml/streambookmarks/jennifer.xbel93
-rw-r--r--examples/xml/streambookmarks/main.cpp55
-rw-r--r--examples/xml/streambookmarks/mainwindow.cpp177
-rw-r--r--examples/xml/streambookmarks/mainwindow.h80
-rw-r--r--examples/xml/streambookmarks/streambookmarks.pro16
-rw-r--r--examples/xml/streambookmarks/xbelreader.cpp205
-rw-r--r--examples/xml/streambookmarks/xbelreader.h82
-rw-r--r--examples/xml/streambookmarks/xbelwriter.cpp93
-rw-r--r--examples/xml/streambookmarks/xbelwriter.h65
-rw-r--r--examples/xml/xml.pro17
-rw-r--r--examples/xml/xmlstreamlint/main.cpp128
-rw-r--r--examples/xml/xmlstreamlint/xmlstreamlint.pro12
-rw-r--r--examples/xmlpatterns/README38
-rw-r--r--examples/xmlpatterns/filetree/filetree.cpp372
-rw-r--r--examples/xmlpatterns/filetree/filetree.h103
-rw-r--r--examples/xmlpatterns/filetree/filetree.pro15
-rw-r--r--examples/xmlpatterns/filetree/forms/mainwindow.ui200
-rw-r--r--examples/xmlpatterns/filetree/main.cpp54
-rw-r--r--examples/xmlpatterns/filetree/mainwindow.cpp166
-rw-r--r--examples/xmlpatterns/filetree/mainwindow.h73
-rw-r--r--examples/xmlpatterns/filetree/queries.qrc7
-rw-r--r--examples/xmlpatterns/filetree/queries/listCPPFiles.xq19
-rw-r--r--examples/xmlpatterns/filetree/queries/wholeTree.xq1
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui196
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/main.cpp53
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp135
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/mainwindow.h64
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp459
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h139
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro13
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/queries.qrc7
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq58
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq3
-rw-r--r--examples/xmlpatterns/recipes/files/allRecipes.xq4
-rw-r--r--examples/xmlpatterns/recipes/files/cookbook.xml62
-rw-r--r--examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq5
-rw-r--r--examples/xmlpatterns/recipes/files/mushroomSoup.xq5
-rw-r--r--examples/xmlpatterns/recipes/files/preparationLessThan30.xq9
-rw-r--r--examples/xmlpatterns/recipes/files/preparationTimes.xq5
-rw-r--r--examples/xmlpatterns/recipes/forms/querywidget.ui151
-rw-r--r--examples/xmlpatterns/recipes/main.cpp54
-rw-r--r--examples/xmlpatterns/recipes/querymainwindow.cpp124
-rw-r--r--examples/xmlpatterns/recipes/querymainwindow.h72
-rw-r--r--examples/xmlpatterns/recipes/recipes.pro13
-rw-r--r--examples/xmlpatterns/recipes/recipes.qrc11
-rw-r--r--examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp106
-rw-r--r--examples/xmlpatterns/shared/xmlsyntaxhighlighter.h72
-rw-r--r--examples/xmlpatterns/trafficinfo/main.cpp54
-rw-r--r--examples/xmlpatterns/trafficinfo/mainwindow.cpp181
-rw-r--r--examples/xmlpatterns/trafficinfo/mainwindow.h77
-rw-r--r--examples/xmlpatterns/trafficinfo/station_example.wml31
-rw-r--r--examples/xmlpatterns/trafficinfo/stationdialog.cpp164
-rw-r--r--examples/xmlpatterns/trafficinfo/stationdialog.h70
-rw-r--r--examples/xmlpatterns/trafficinfo/stationdialog.ui104
-rw-r--r--examples/xmlpatterns/trafficinfo/stationquery.cpp94
-rw-r--r--examples/xmlpatterns/trafficinfo/stationquery.h74
-rw-r--r--examples/xmlpatterns/trafficinfo/time_example.wml56
-rw-r--r--examples/xmlpatterns/trafficinfo/timequery.cpp116
-rw-r--r--examples/xmlpatterns/trafficinfo/timequery.h74
-rw-r--r--examples/xmlpatterns/trafficinfo/trafficinfo.pro9
-rw-r--r--examples/xmlpatterns/xmlpatterns.pro16
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globalVariables.pro11
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globals.cpp67
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globals.gccxml33
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globals.html40
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq110
-rw-r--r--examples/xmlpatterns/xquery/xquery.pro10
1918 files changed, 146862 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/activeqt/README b/examples/activeqt/README
new file mode 100644
index 0000000000..24be2de827
--- /dev/null
+++ b/examples/activeqt/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 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/activeqt/activeqt.pro b/examples/activeqt/activeqt.pro
new file mode 100644
index 0000000000..1cd05f61d6
--- /dev/null
+++ b/examples/activeqt/activeqt.pro
@@ -0,0 +1,22 @@
+TEMPLATE = subdirs
+SUBDIRS += comapp \
+ hierarchy \
+ menus \
+ multiple \
+ simple \
+ webbrowser \
+ wrapper
+
+contains(QT_CONFIG, opengl):SUBDIRS += opengl
+
+# For now only the contain examples with mingw, for the others you need
+# an IDL compiler
+win32-g++|wince*:SUBDIRS = webbrowser
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS activeqt.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/comapp/comapp.pro b/examples/activeqt/comapp/comapp.pro
new file mode 100644
index 0000000000..29aebae58e
--- /dev/null
+++ b/examples/activeqt/comapp/comapp.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+CONFIG += qaxserver
+
+# Input
+SOURCES += main.cpp
+
+RC_FILE = comapp.rc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/comapp
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS comapp.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/comapp
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/comapp/comapp.rc b/examples/activeqt/comapp/comapp.rc
new file mode 100644
index 0000000000..24e339ae41
--- /dev/null
+++ b/examples/activeqt/comapp/comapp.rc
@@ -0,0 +1 @@
+1 TYPELIB "comapp.rc"
diff --git a/examples/activeqt/comapp/main.cpp b/examples/activeqt/comapp/main.cpp
new file mode 100644
index 0000000000..95caaa3db4
--- /dev/null
+++ b/examples/activeqt/comapp/main.cpp
@@ -0,0 +1,272 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QAxFactory>
+#include <QTabWidget>
+#include <QTimer>
+
+class Application;
+class DocumentList;
+
+//! [0]
+class Document : public QObject
+{
+ Q_OBJECT
+
+ Q_CLASSINFO("ClassID", "{2b5775cd-72c2-43da-bc3b-b0e8d1e1c4f7}")
+ Q_CLASSINFO("InterfaceID", "{2ce1761e-07a3-415c-bd11-0eab2c7283de}")
+
+ Q_PROPERTY(Application *application READ application)
+ Q_PROPERTY(QString title READ title WRITE setTitle)
+
+public:
+ Document(DocumentList *list);
+ ~Document();
+
+ Application *application() const;
+
+ QString title() const;
+ void setTitle(const QString &title);
+
+private:
+ QWidget *page;
+};
+//! [0]
+
+//! [1]
+class DocumentList : public QObject
+{
+ Q_OBJECT
+
+ Q_CLASSINFO("ClassID", "{496b761d-924b-4554-a18a-8f3704d2a9a6}")
+ Q_CLASSINFO("InterfaceID", "{6c9e30e8-3ff6-4e6a-9edc-d219d074a148}")
+
+ Q_PROPERTY(Application* application READ application)
+ Q_PROPERTY(int count READ count)
+
+public:
+ DocumentList(Application *application);
+
+ int count() const;
+ Application *application() const;
+
+public slots:
+ Document *addDocument();
+ Document *item(int index) const;
+
+private:
+ QList<Document*> list;
+};
+//! [1]
+
+//! [2]
+class Application : public QObject
+{
+ Q_OBJECT
+
+ Q_CLASSINFO("ClassID", "{b50a71db-c4a7-4551-8d14-49983566afee}")
+ Q_CLASSINFO("InterfaceID", "{4a427759-16ef-4ed8-be79-59ffe5789042}")
+ Q_CLASSINFO("RegisterObject", "yes")
+
+ Q_PROPERTY(DocumentList* documents READ documents)
+ Q_PROPERTY(QString id READ id)
+ Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
+
+public:
+ Application(QObject *parent = 0);
+ DocumentList *documents() const;
+
+ QString id() const { return objectName(); }
+
+ void setVisible(bool on);
+ bool isVisible() const;
+
+ QTabWidget *window() const { return ui; }
+
+public slots:
+ void quit();
+
+private:
+ DocumentList *docs;
+
+ QTabWidget *ui;
+};
+//! [2]
+
+//! [3]
+Document::Document(DocumentList *list)
+: QObject(list)
+{
+ QTabWidget *tabs = list->application()->window();
+ page = new QWidget(tabs);
+ page->setWindowTitle("Unnamed");
+ tabs->addTab(page, page->windowTitle());
+
+ page->show();
+}
+
+Document::~Document()
+{
+ delete page;
+}
+
+Application *Document::application() const
+{
+ return qobject_cast<DocumentList*>(parent())->application();
+}
+
+QString Document::title() const
+{
+ return page->windowTitle();
+}
+
+void Document::setTitle(const QString &t)
+{
+ page->setWindowTitle(t);
+
+ QTabWidget *tabs = application()->window();
+ int index = tabs->indexOf(page);
+ tabs->setTabText(index, page->windowTitle());
+}
+
+//! [3] //! [4]
+DocumentList::DocumentList(Application *application)
+: QObject(application)
+{
+}
+
+Application *DocumentList::application() const
+{
+ return qobject_cast<Application*>(parent());
+}
+
+int DocumentList::count() const
+{
+ return list.count();
+}
+
+Document *DocumentList::item(int index) const
+{
+ if (index >= list.count())
+ return 0;
+
+ return list.at(index);
+}
+
+Document *DocumentList::addDocument()
+{
+ Document *document = new Document(this);
+ list.append(document);
+
+ return document;
+}
+
+
+//! [4] //! [5]
+Application::Application(QObject *parent)
+: QObject(parent), ui(0)
+{
+ ui = new QTabWidget;
+
+ setObjectName("From QAxFactory");
+ docs = new DocumentList(this);
+}
+
+DocumentList *Application::documents() const
+{
+ return docs;
+}
+
+void Application::setVisible(bool on)
+{
+ ui->setShown(on);
+}
+
+bool Application::isVisible() const
+{
+ return ui->isVisible();
+}
+
+void Application::quit()
+{
+ delete docs;
+ docs = 0;
+
+ delete ui;
+ ui = 0;
+ QTimer::singleShot(0, qApp, SLOT(quit()));
+}
+
+#include "main.moc"
+//! [5] //! [6]
+
+
+QAXFACTORY_BEGIN("{edd3e836-f537-4c6f-be7d-6014c155cc7a}", "{b7da3de8-83bb-4bbe-9ab7-99a05819e201}")
+ QAXCLASS(Application)
+ QAXTYPE(Document)
+ QAXTYPE(DocumentList)
+QAXFACTORY_END()
+
+//! [6] //! [7]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ app.setQuitOnLastWindowClosed(false);
+
+ // started by COM - don't do anything
+ if (QAxFactory::isServer())
+ return app.exec();
+
+ // started by user
+ Application appobject(0);
+ appobject.setObjectName("From Application");
+
+ QAxFactory::startServer();
+ QAxFactory::registerActiveObject(&appobject);
+
+ appobject.setVisible(true);
+
+ QObject::connect(qApp, SIGNAL(lastWindowClosed()), &appobject, SLOT(quit()));
+
+ return app.exec();
+}
+//! [7]
diff --git a/examples/activeqt/dotnet/walkthrough/Form1.cs b/examples/activeqt/dotnet/walkthrough/Form1.cs
new file mode 100644
index 0000000000..9fb572afeb
--- /dev/null
+++ b/examples/activeqt/dotnet/walkthrough/Form1.cs
@@ -0,0 +1,127 @@
+using System;
+using System.Drawing;
+using System.Collections;
+using System.ComponentModel;
+using System.Windows.Forms;
+using System.Data;
+
+namespace csharp
+{
+ /// <summary>
+ /// Summary description for Form1.
+ /// </summary>
+ public class Form1 : System.Windows.Forms.Form
+ {
+ private AxwrapperaxLib.AxQPushButton resetButton;
+ private AxmultipleaxLib.AxQAxWidget2 circleWidget;
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.Container components = null;
+
+ public Form1()
+ {
+ //
+ // Required for Windows Form Designer support
+ //
+ InitializeComponent();
+
+ //
+ // TODO: Add any constructor code after InitializeComponent call
+ //
+ }
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ protected override void Dispose( bool disposing )
+ {
+ if( disposing )
+ {
+ if (components != null)
+ {
+ components.Dispose();
+ }
+ }
+ base.Dispose( disposing );
+ }
+
+ #region Windows Form Designer generated code
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
+ this.resetButton = new AxwrapperaxLib.AxQPushButton();
+ this.circleWidget = new AxmultipleaxLib.AxQAxWidget2();
+ ((System.ComponentModel.ISupportInitialize)(this.resetButton)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.circleWidget)).BeginInit();
+ this.SuspendLayout();
+ //
+ // resetButton
+ //
+ this.resetButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
+ this.resetButton.Enabled = true;
+ this.resetButton.Location = new System.Drawing.Point(160, 296);
+ this.resetButton.Name = "resetButton";
+ this.resetButton.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("resetButton.OcxState")));
+ this.resetButton.Size = new System.Drawing.Size(168, 32);
+ this.resetButton.TabIndex = 1;
+ this.resetButton.clicked += new System.EventHandler(this.resetLineWidth);
+ //
+ // circleWidget
+ //
+ this.circleWidget.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right);
+ this.circleWidget.Enabled = true;
+ this.circleWidget.Location = new System.Drawing.Point(8, 8);
+ this.circleWidget.Name = "circleWidget";
+ this.circleWidget.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("circleWidget.OcxState")));
+ this.circleWidget.Size = new System.Drawing.Size(320, 264);
+ this.circleWidget.TabIndex = 2;
+ this.circleWidget.ClickEvent += new System.EventHandler(this.circleClicked);
+ //
+ // Form1
+ //
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
+ this.ClientSize = new System.Drawing.Size(336, 333);
+ this.Controls.AddRange(new System.Windows.Forms.Control[] {
+ this.circleWidget,
+ this.resetButton});
+ this.Name = "Form1";
+ this.Text = "Form1";
+ ((System.ComponentModel.ISupportInitialize)(this.resetButton)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.circleWidget)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+ #endregion
+
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main()
+ {
+ Application.Run(new Form1());
+ }
+
+//! [0]
+ private void circleClicked(object sender, System.EventArgs e)
+ {
+ this.circleWidget.lineWidth++;
+ }
+//! [0]
+
+//! [1]
+ private void resetLineWidth(object sender, System.EventArgs e)
+ {
+ this.circleWidget.lineWidth = 1;
+ this.resetButton.setFocus();
+ }
+//! [1]
+ }
+}
diff --git a/examples/activeqt/dotnet/walkthrough/Form1.resx b/examples/activeqt/dotnet/walkthrough/Form1.resx
new file mode 100644
index 0000000000..6353f829fe
--- /dev/null
+++ b/examples/activeqt/dotnet/walkthrough/Form1.resx
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 1.3
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">1.3</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1">this is my long string</data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ [base64 mime encoded serialized .NET Framework object]
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ [base64 mime encoded string representing a byte array form of the .NET Framework object]
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>1.3</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="resetButton.OcxState" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>
+ AAEAAAD/////AQAAAAAAAAAMAgAAAFpTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0xLjAuMzMw
+ MC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACFT
+ eXN0ZW0uV2luZG93cy5Gb3Jtcy5BeEhvc3QrU3RhdGUBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAGwMA
+ AAIBAAAAAQAAAAAAAAAAAAAAAAYDAAAAAAAFAAAACGVuYWJsZWQAAAAAEgEAAAACeAAAAAAQAAAAAAAA
+ AAJ5AAAAABAAAAAAAAAABndpZHRoAAAAABAAAACoAAAAB2hlaWdodAAAAAAQAAAAGgAAAA1taW5pbXVt
+ V2lkdGgAAAAAEAAAAAAAAAAObWluaW11bUhlaWdodAAAAAAQAAAAAAAAAA1tYXhpbXVtV2lkdGgAAAAA
+ EAAAf/8AAAAObWF4aW11bUhlaWdodAAAAAAQAAB//wAAAA9iYWNrZ3JvdW5kTW9kZQAAAAAQAAAABAAA
+ ABdwYWxldHRlRm9yZWdyb3VuZENvbG9yAAAAAAr/AAAAAAAAF3BhbGV0dGVCYWNrZ3JvdW5kQ29sb3IA
+ AAAACv/U0MgAAAARYmFja2dyb3VuZE9yaWdpbgAAAAAQAAAAAAAAAAVmb250AAAAAAUAAAAYAE0AUwAg
+ AFMAaABlAGwAbAAgAEQAbABnAFP//wUBADIAAAAACGNhcHRpb24AAAAAA/////8AAAAJaWNvblRleHQA
+ AAAAA/////8AAAAObW91c2VUcmFja2luZwAAAAASAAAAAAxmb2N1c1BvbGljeQAAAAAQAAAAAQAAAA91
+ cGRhdGVzRW5hYmxlZAAAAAASAQAAAAptYXhpbWl6ZWQAAAAAEgAAAAALZnVsbFNjcmVlbgAAAAASAAAA
+ AAxhY2NlcHREcm9wcwAAAAASAAAAABNpbnB1dE1ldGhvZEVuYWJsZWQAAAAAEgAAAAAFdGV4dAAAAAAD
+ AAAADAAmAFIAZQBzAGUAdAAAAAt0b2dnbGVUeXBlAAAAABAAAAAAAAAABWRvd24AAAAAEgAAAAAMdG9n
+ Z2xlU3RhdGUAAAAAEAAAAAAAAAALYXV0b1Jlc2l6ZQAAAAASAAAAAAthdXRvUmVwZWF0AAAAABIAAAAA
+ EGV4Y2x1c2l2ZVRvZ2dsZQAAAAASAAAAAAxhdXRvRGVmYXVsdAAAAAASAQAAAAttZW51QnV0dG9uAAAA
+ ABIAAAAABWZsYXQAAAAAEgAL
+</value>
+ </data>
+ <data name="circleWidget.OcxState" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>
+ AAEAAAD/////AQAAAAAAAAAMAgAAAFpTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0xLjAuMzMw
+ MC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACFT
+ eXN0ZW0uV2luZG93cy5Gb3Jtcy5BeEhvc3QrU3RhdGUBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAALwAA
+ AAIBAAAAAQAAAAAAAAAAAAAAABoAAAAAAAAFAAAACmxpbmVXaWR0aAAAAAAQAAAAAAs=
+</value>
+ </data>
+ <data name="$this.Name">
+ <value>Form1</value>
+ </data>
+</root> \ No newline at end of file
diff --git a/examples/activeqt/dotnet/walkthrough/Form1.vb b/examples/activeqt/dotnet/walkthrough/Form1.vb
new file mode 100644
index 0000000000..f5f241bd97
--- /dev/null
+++ b/examples/activeqt/dotnet/walkthrough/Form1.vb
@@ -0,0 +1,88 @@
+Public Class Form1
+ Inherits System.Windows.Forms.Form
+
+#Region " Windows Form Designer generated code "
+
+ Public Sub New()
+ MyBase.New()
+
+ 'This call is required by the Windows Form Designer.
+ InitializeComponent()
+
+ 'Add any initialization after the InitializeComponent() call
+
+ End Sub
+
+ 'Form overrides dispose to clean up the component list.
+ Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
+ If disposing Then
+ If Not (components Is Nothing) Then
+ components.Dispose()
+ End If
+ End If
+ MyBase.Dispose(disposing)
+ End Sub
+
+ 'Required by the Windows Form Designer
+ Private components As System.ComponentModel.IContainer
+
+ 'NOTE: The following procedure is required by the Windows Form Designer
+ 'It can be modified using the Windows Form Designer.
+ 'Do not modify it using the code editor.
+ Friend WithEvents circleWidget As AxmultipleaxLib.AxQAxWidget2
+ Friend WithEvents resetButton As AxwrapperaxLib.AxQPushButton
+ <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
+ Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
+ Me.circleWidget = New AxmultipleaxLib.AxQAxWidget2()
+ Me.resetButton = New AxwrapperaxLib.AxQPushButton()
+ CType(Me.circleWidget, System.ComponentModel.ISupportInitialize).BeginInit()
+ CType(Me.resetButton, System.ComponentModel.ISupportInitialize).BeginInit()
+ Me.SuspendLayout()
+ '
+ 'circleWidget
+ '
+ Me.circleWidget.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
+ Or System.Windows.Forms.AnchorStyles.Left) _
+ Or System.Windows.Forms.AnchorStyles.Right)
+ Me.circleWidget.Enabled = True
+ Me.circleWidget.Location = New System.Drawing.Point(8, 8)
+ Me.circleWidget.Name = "circleWidget"
+ Me.circleWidget.OcxState = CType(resources.GetObject("circleWidget.OcxState"), System.Windows.Forms.AxHost.State)
+ Me.circleWidget.Size = New System.Drawing.Size(280, 216)
+ Me.circleWidget.TabIndex = 0
+ '
+ 'resetButton
+ '
+ Me.resetButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
+ ' VB is case insensitive, but our C++ controls are not.
+ ' Me.resetButton.enabled = True
+ Me.resetButton.Location = New System.Drawing.Point(184, 240)
+ Me.resetButton.Name = "resetButton"
+ Me.resetButton.OcxState = CType(resources.GetObject("resetButton.OcxState"), System.Windows.Forms.AxHost.State)
+ Me.resetButton.Size = New System.Drawing.Size(104, 24)
+ Me.resetButton.TabIndex = 1
+ '
+ 'Form1
+ '
+ Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
+ Me.ClientSize = New System.Drawing.Size(292, 273)
+ Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.resetButton, Me.circleWidget})
+ Me.Name = "Form1"
+ Me.Text = "Form1"
+ CType(Me.circleWidget, System.ComponentModel.ISupportInitialize).EndInit()
+ CType(Me.resetButton, System.ComponentModel.ISupportInitialize).EndInit()
+ Me.ResumeLayout(False)
+
+ End Sub
+
+#End Region
+
+ Private Sub circleWidget_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles circleWidget.ClickEvent
+ Me.circleWidget.lineWidth = Me.circleWidget.lineWidth + 1
+ End Sub
+
+ Private Sub resetButton_clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetButton.clicked
+ Me.circleWidget.lineWidth = 1
+ Me.resetButton.setFocus()
+ End Sub
+End Class
diff --git a/examples/activeqt/dotnet/walkthrough/csharp.csproj b/examples/activeqt/dotnet/walkthrough/csharp.csproj
new file mode 100644
index 0000000000..4c5502b8aa
--- /dev/null
+++ b/examples/activeqt/dotnet/walkthrough/csharp.csproj
@@ -0,0 +1,143 @@
+<VisualStudioProject>
+ <CSHARP
+ ProjectType = "Local"
+ ProductVersion = "7.0.9466"
+ SchemaVersion = "1.0"
+ ProjectGuid = "{F15600FD-7677-4C01-B98A-6776CE500617}"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = ""
+ AssemblyKeyContainerName = ""
+ AssemblyName = "csharp"
+ AssemblyOriginatorKeyFile = ""
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Grid"
+ DefaultTargetSchema = "IE50"
+ DelaySign = "false"
+ OutputType = "WinExe"
+ RootNamespace = "csharp"
+ StartupObject = ""
+ >
+ <Config
+ Name = "Debug"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "DEBUG;TRACE"
+ DocumentationFile = ""
+ DebugSymbols = "true"
+ FileAlignment = "4096"
+ IncrementalBuild = "true"
+ Optimize = "false"
+ OutputPath = "bin\Debug\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ <Config
+ Name = "Release"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "TRACE"
+ DocumentationFile = ""
+ DebugSymbols = "false"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ Optimize = "true"
+ OutputPath = "bin\Release\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.dll"
+ />
+ <Reference
+ Name = "System.Data"
+ AssemblyName = "System.Data"
+ HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
+ />
+ <Reference
+ Name = "System.Drawing"
+ AssemblyName = "System.Drawing"
+ HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Drawing.dll"
+ />
+ <Reference
+ Name = "System.Windows.Forms"
+ AssemblyName = "System.Windows.Forms"
+ HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Windows.Forms.dll"
+ />
+ <Reference
+ Name = "System.XML"
+ AssemblyName = "System.Xml"
+ HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
+ />
+ <Reference
+ Name = "stdole"
+ Guid = "{00020430-0000-0000-C000-000000000046}"
+ VersionMajor = "2"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "primary"
+ />
+ <Reference
+ Name = "wrapperaxLib"
+ Guid = "{3B756301-0075-4E40-8BE8-5A81DE2426B7}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "tlbimp"
+ />
+ <Reference
+ Name = "AxwrapperaxLib"
+ Guid = "{3B756301-0075-4E40-8BE8-5A81DE2426B7}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "aximp"
+ />
+ <Reference
+ Name = "multipleaxLib"
+ Guid = "{05828915-AD1C-47AB-AB96-D6AD1E25F0E2}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "tlbimp"
+ />
+ <Reference
+ Name = "AxmultipleaxLib"
+ Guid = "{05828915-AD1C-47AB-AB96-D6AD1E25F0E2}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "aximp"
+ />
+ </References>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "Form1.cs"
+ SubType = "Form"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Form1.resx"
+ DependentUpon = "Form1.cs"
+ BuildAction = "EmbeddedResource"
+ />
+ </Include>
+ </Files>
+ </CSHARP>
+</VisualStudioProject>
+
diff --git a/examples/activeqt/dotnet/walkthrough/vb.vbproj b/examples/activeqt/dotnet/walkthrough/vb.vbproj
new file mode 100644
index 0000000000..eb0a9d63d8
--- /dev/null
+++ b/examples/activeqt/dotnet/walkthrough/vb.vbproj
@@ -0,0 +1,147 @@
+<VisualStudioProject>
+ <VisualBasic
+ ProjectType = "Local"
+ ProductVersion = "7.0.9466"
+ SchemaVersion = "1.0"
+ ProjectGuid = "{BFF242A6-967C-4F73-BEBE-DED2D9C395C6}"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = ""
+ AssemblyKeyContainerName = ""
+ AssemblyName = "vb"
+ AssemblyOriginatorKeyFile = ""
+ AssemblyOriginatorKeyMode = "None"
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Grid"
+ DefaultTargetSchema = "IE50"
+ DelaySign = "false"
+ OutputType = "WinExe"
+ OptionCompare = "Binary"
+ OptionExplicit = "On"
+ OptionStrict = "Off"
+ RootNamespace = "vb"
+ StartupObject = "vb.Form1"
+ >
+ <Config
+ Name = "Debug"
+ BaseAddress = "285212672"
+ ConfigurationOverrideFile = ""
+ DefineConstants = ""
+ DefineDebug = "true"
+ DefineTrace = "true"
+ DebugSymbols = "true"
+ IncrementalBuild = "true"
+ Optimize = "false"
+ OutputPath = "bin\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "1"
+ />
+ <Config
+ Name = "Release"
+ BaseAddress = "285212672"
+ ConfigurationOverrideFile = ""
+ DefineConstants = ""
+ DefineDebug = "false"
+ DefineTrace = "true"
+ DebugSymbols = "false"
+ IncrementalBuild = "false"
+ Optimize = "true"
+ OutputPath = "bin\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "1"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ />
+ <Reference
+ Name = "System.Data"
+ AssemblyName = "System.Data"
+ />
+ <Reference
+ Name = "System.Drawing"
+ AssemblyName = "System.Drawing"
+ />
+ <Reference
+ Name = "System.Windows.Forms"
+ AssemblyName = "System.Windows.Forms"
+ />
+ <Reference
+ Name = "System.XML"
+ AssemblyName = "System.Xml"
+ />
+ <Reference
+ Name = "stdole"
+ Guid = "{00020430-0000-0000-C000-000000000046}"
+ VersionMajor = "2"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "primary"
+ />
+ <Reference
+ Name = "wrapperaxLib"
+ Guid = "{3B756301-0075-4E40-8BE8-5A81DE2426B7}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "tlbimp"
+ />
+ <Reference
+ Name = "multipleaxLib"
+ Guid = "{05828915-AD1C-47AB-AB96-D6AD1E25F0E2}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "tlbimp"
+ />
+ <Reference
+ Name = "AxwrapperaxLib"
+ Guid = "{3B756301-0075-4E40-8BE8-5A81DE2426B7}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "aximp"
+ />
+ <Reference
+ Name = "AxmultipleaxLib"
+ Guid = "{05828915-AD1C-47AB-AB96-D6AD1E25F0E2}"
+ VersionMajor = "1"
+ VersionMinor = "0"
+ Lcid = "0"
+ WrapperTool = "aximp"
+ />
+ </References>
+ <Imports>
+ <Import Namespace = "Microsoft.VisualBasic" />
+ <Import Namespace = "System" />
+ <Import Namespace = "System.Collections" />
+ <Import Namespace = "System.Data" />
+ <Import Namespace = "System.Drawing" />
+ <Import Namespace = "System.Diagnostics" />
+ <Import Namespace = "System.Windows.Forms" />
+ </Imports>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "Form1.vb"
+ SubType = "Form"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Form1.resx"
+ DependentUpon = "Form1.vb"
+ BuildAction = "EmbeddedResource"
+ />
+ </Include>
+ </Files>
+ </VisualBasic>
+</VisualStudioProject>
+
diff --git a/examples/activeqt/dotnet/wrapper/app.csproj b/examples/activeqt/dotnet/wrapper/app.csproj
new file mode 100644
index 0000000000..dce4bf0b81
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/app.csproj
@@ -0,0 +1,93 @@
+<VisualStudioProject>
+ <CSHARP
+ ProjectType = "Local"
+ ProductVersion = "7.0.9466"
+ SchemaVersion = "1.0"
+ ProjectGuid = "{334C8F04-E034-4082-9380-43906DDE71AB}"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = ""
+ AssemblyKeyContainerName = ""
+ AssemblyName = "wrapper"
+ AssemblyOriginatorKeyFile = ""
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Grid"
+ DefaultTargetSchema = "IE50"
+ DelaySign = "false"
+ OutputType = "Exe"
+ RootNamespace = "wrapper"
+ StartupObject = ""
+ >
+ <Config
+ Name = "Debug"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "DEBUG;TRACE"
+ DocumentationFile = ""
+ DebugSymbols = "true"
+ FileAlignment = "4096"
+ IncrementalBuild = "true"
+ Optimize = "false"
+ OutputPath = "bin\Debug\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ <Config
+ Name = "Release"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "TRACE"
+ DocumentationFile = ""
+ DebugSymbols = "false"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ Optimize = "true"
+ OutputPath = "bin\Release\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ HintPath = "D:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.dll"
+ />
+ <Reference
+ Name = "System.Data"
+ AssemblyName = "System.Data"
+ HintPath = "D:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
+ />
+ <Reference
+ Name = "System.XML"
+ AssemblyName = "System.Xml"
+ HintPath = "D:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
+ />
+ <Reference
+ Name = "lib"
+ AssemblyName = "lib"
+ HintPath = "lib\lib.dll"
+ />
+ </References>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "main.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ </Include>
+ </Files>
+ </CSHARP>
+</VisualStudioProject>
+
diff --git a/examples/activeqt/dotnet/wrapper/lib/lib.vcproj b/examples/activeqt/dotnet/wrapper/lib/lib.vcproj
new file mode 100644
index 0000000000..f49c35d52c
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/lib/lib.vcproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="lib"
+ ProjectGUID="{2E94A303-45A2-47AC-B87A-7C3519E9D6D8}"
+ Keyword="ManagedCProj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="2"
+ CharacterSet="2"
+ ManagedExtensions="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtCore&quot;"
+ PreprocessorDefinitions="WIN32;_DEBUG"
+ IgnoreStandardIncludePath="FALSE"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="0"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="QtCored4.lib"
+ OutputFile="lib.dll"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories="$(QTDIR)/lib"
+ GenerateDebugInformation="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="2"
+ CharacterSet="2"
+ ManagedExtensions="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ AdditionalIncludeDirectories="&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtCore&quot;"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="WIN32;NDEBUG"
+ MinimalRebuild="FALSE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="QtCore4.lib"
+ OutputFile="$(OutDir)/lib.dll"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories="$(QTDIR)/lib"
+ GenerateDebugInformation="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="networker.cpp">
+ </File>
+ <File
+ RelativePath="tools.cpp">
+ </File>
+ <File
+ RelativePath="worker.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="networker.h">
+ </File>
+ <File
+ RelativePath="tools.h">
+ </File>
+ <File
+ RelativePath="worker.h">
+ <FileConfiguration
+ Name="Debug|Win32">
+ <Tool
+ Name="VCCustomBuildTool"
+ CommandLine="$(QTDIR)\bin\moc.exe $(InputName).h -o moc_$(InputName).cpp"
+ Outputs="moc_$(InputName).cpp"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32">
+ <Tool
+ Name="VCCustomBuildTool"
+ CommandLine="$(QTDIR)\bin\moc.exe $(InputName).h -o moc_$(InputName).cpp"
+ Outputs="moc_$(InputName).cpp"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Generated MOC"
+ Filter="">
+ <File
+ RelativePath="moc_worker.cpp">
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/activeqt/dotnet/wrapper/lib/networker.cpp b/examples/activeqt/dotnet/wrapper/lib/networker.cpp
new file mode 100644
index 0000000000..54e862b460
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/lib/networker.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include "networker.h"
+#include "worker.h"
+#include "tools.h"
+
+netWorker::netWorker()
+{
+ workerObject = new Worker();
+}
+//! [0] //! [1]
+
+netWorker::~netWorker()
+{
+ delete workerObject;
+}
+//! [1] //! [2]
+
+String *netWorker::get_StatusString()
+{
+ return QStringToString(workerObject->statusString());
+}
+//! [2] //! [3]
+
+void netWorker::set_StatusString(String *string)
+{
+ workerObject->setStatusString(StringToQString(string));
+ __raise statusStringChanged(string);
+}
+//! [3]
diff --git a/examples/activeqt/dotnet/wrapper/lib/networker.h b/examples/activeqt/dotnet/wrapper/lib/networker.h
new file mode 100644
index 0000000000..583c6c4ae3
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/lib/networker.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// lib.h
+
+#pragma once
+
+#using <mscorlib.dll>
+using namespace System;
+
+//! [0]
+class Worker;
+
+// .NET class
+public __gc class netWorker
+{
+public:
+ netWorker();
+ ~netWorker();
+
+ __property String *get_StatusString();
+ __property void set_StatusString(String *string);
+
+ __event void statusStringChanged(String *args);
+
+private:
+ Worker *workerObject;
+};
+//! [0]
diff --git a/examples/activeqt/dotnet/wrapper/lib/tools.cpp b/examples/activeqt/dotnet/wrapper/lib/tools.cpp
new file mode 100644
index 0000000000..aa67aea46a
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/lib/tools.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QString>
+
+#using <mscorlib.dll>
+#include <vcclr.h>
+
+using namespace System;
+
+String *QStringToString(const QString &qstring)
+{
+ return new String((const wchar_t *)qstring.utf16());
+}
+//! [0] //! [1]
+
+QString StringToQString(String *string)
+{
+ const wchar_t __pin *chars = PtrToStringChars(string);
+ return QString::fromUtf16((const ushort *)chars);
+}
+//! [1]
diff --git a/examples/activeqt/dotnet/wrapper/lib/tools.h b/examples/activeqt/dotnet/wrapper/lib/tools.h
new file mode 100644
index 0000000000..8569eca5dc
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/lib/tools.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TOOLS_H
+#define TOOLS_H
+
+#using <mscorlib.dll>
+
+QT_BEGIN_NAMESPACE
+class QString;
+QT_END_NAMESPACE
+
+System::String *QStringToString(const QString &qstring);
+QString StringToQString(System::String *string);
+
+#endif // TOOLS_H
diff --git a/examples/activeqt/dotnet/wrapper/lib/worker.cpp b/examples/activeqt/dotnet/wrapper/lib/worker.cpp
new file mode 100644
index 0000000000..695db57284
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/lib/worker.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "worker.h"
+#include "tools.h"
+
+Worker::Worker()
+{
+ status = "Idle";
+}
+
+void Worker::setStatusString(const QString &string)
+{
+ status = string;
+ emit statusStringChanged(status);
+}
+
+QString Worker::statusString() const
+{
+ return status;
+}
diff --git a/examples/activeqt/dotnet/wrapper/lib/worker.h b/examples/activeqt/dotnet/wrapper/lib/worker.h
new file mode 100644
index 0000000000..8bab9ed8ee
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/lib/worker.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WORKER_H
+#define WORKER_H
+
+#include <QObject>
+
+// native Qt/C++ class
+//! [0]
+class Worker : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString statusString READ statusString WRITE setStatusString)
+public:
+ Worker();
+
+ QString statusString() const;
+
+public slots:
+ void setStatusString(const QString &string);
+
+signals:
+ void statusStringChanged(const QString &string);
+
+private:
+ QString status;
+};
+//! [0]
+
+#endif // WORKER_H
diff --git a/examples/activeqt/dotnet/wrapper/main.cs b/examples/activeqt/dotnet/wrapper/main.cs
new file mode 100644
index 0000000000..1d430298c0
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/main.cs
@@ -0,0 +1,40 @@
+//! [0]
+using System;
+
+namespace WrapperApp
+{
+ class App
+ {
+ void Run()
+ {
+ netWorker worker = new netWorker();
+
+ worker.statusStringChanged += new netWorker.__Delegate_statusStringChanged(onStatusStringChanged);
+
+ System.Console.Out.WriteLine(worker.StatusString);
+
+ System.Console.Out.WriteLine("Working cycle begins...");
+ worker.StatusString = "Working";
+ worker.StatusString = "Lunch Break";
+ worker.StatusString = "Working";
+ worker.StatusString = "Idle";
+ System.Console.Out.WriteLine("Working cycle ends...");
+ }
+
+ private void onStatusStringChanged(string str)
+ {
+ System.Console.Out.WriteLine(str);
+ }
+
+ [STAThread]
+//! [0] //! [1]
+ static void Main(string[] args)
+ {
+ App app = new App();
+ app.Run();
+ }
+//! [1] //! [2]
+ }
+//! [2] //! [3]
+}
+//! [3]
diff --git a/examples/activeqt/dotnet/wrapper/wrapper.sln b/examples/activeqt/dotnet/wrapper/wrapper.sln
new file mode 100644
index 0000000000..e25e6bdfb2
--- /dev/null
+++ b/examples/activeqt/dotnet/wrapper/wrapper.sln
@@ -0,0 +1,28 @@
+Microsoft Visual Studio Solution File, Format Version 7.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "app", "app.csproj", "{334C8F04-E034-4082-9380-43906DDE71AB}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib", "lib\lib.vcproj", "{2E94A303-45A2-47AC-B87A-7C3519E9D6D8}"
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ ConfigName.0 = Debug
+ ConfigName.1 = Release
+ EndGlobalSection
+ GlobalSection(ProjectDependencies) = postSolution
+ {334C8F04-E034-4082-9380-43906DDE71AB}.0 = {2E94A303-45A2-47AC-B87A-7C3519E9D6D8}
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {334C8F04-E034-4082-9380-43906DDE71AB}.Debug.ActiveCfg = Debug|.NET
+ {334C8F04-E034-4082-9380-43906DDE71AB}.Debug.Build.0 = Debug|.NET
+ {334C8F04-E034-4082-9380-43906DDE71AB}.Release.ActiveCfg = Release|.NET
+ {334C8F04-E034-4082-9380-43906DDE71AB}.Release.Build.0 = Release|.NET
+ {2E94A303-45A2-47AC-B87A-7C3519E9D6D8}.Debug.ActiveCfg = Debug|Win32
+ {2E94A303-45A2-47AC-B87A-7C3519E9D6D8}.Debug.Build.0 = Debug|Win32
+ {2E94A303-45A2-47AC-B87A-7C3519E9D6D8}.Release.ActiveCfg = Release|Win32
+ {2E94A303-45A2-47AC-B87A-7C3519E9D6D8}.Release.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/examples/activeqt/hierarchy/hierarchy.inf b/examples/activeqt/hierarchy/hierarchy.inf
new file mode 100644
index 0000000000..cb7e90f021
--- /dev/null
+++ b/examples/activeqt/hierarchy/hierarchy.inf
@@ -0,0 +1,9 @@
+[version]
+ signature="$CHICAGO$"
+ AdvancedINF=2.0
+ [Add.Code]
+ hierarchyax.dll=hierarchyax.dll
+ [hierarchyax.dll]
+ file-win32-x86=thiscab
+ clsid={d574a747-8016-46db-a07c-b2b4854ee75c}
+ RegisterServer=yes
diff --git a/examples/activeqt/hierarchy/hierarchy.pro b/examples/activeqt/hierarchy/hierarchy.pro
new file mode 100644
index 0000000000..d0ebbcd206
--- /dev/null
+++ b/examples/activeqt/hierarchy/hierarchy.pro
@@ -0,0 +1,18 @@
+TEMPLATE = lib
+TARGET = hierarchyax
+
+CONFIG += qt warn_off qaxserver dll
+contains(CONFIG, static):DEFINES += QT_NODLL
+
+SOURCES = objects.cpp main.cpp
+HEADERS = objects.h
+RC_FILE = $$QT_SOURCE_TREE/src/activeqt/control/qaxserver.rc
+DEF_FILE = $$QT_SOURCE_TREE/src/activeqt/control/qaxserver.def
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/hierarchy
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hierarchy.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/hierarchy
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/hierarchy/main.cpp b/examples/activeqt/hierarchy/main.cpp
new file mode 100644
index 0000000000..e817635241
--- /dev/null
+++ b/examples/activeqt/hierarchy/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include "objects.h"
+#include <QAxFactory>
+
+QAXFACTORY_BEGIN("{9e626211-be62-4d18-9483-9419358fbb03}", "{75c276de-1df5-451f-a004-e4fa1a587df1}")
+ QAXCLASS(QParentWidget)
+ QAXTYPE(QSubWidget)
+QAXFACTORY_END()
+//! [0]
diff --git a/examples/activeqt/hierarchy/objects.cpp b/examples/activeqt/hierarchy/objects.cpp
new file mode 100644
index 0000000000..c3928b5b15
--- /dev/null
+++ b/examples/activeqt/hierarchy/objects.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "objects.h"
+#include <QLayout>
+#include <QPainter>
+
+/* Implementation of QParentWidget */
+//! [0]
+QParentWidget::QParentWidget(QWidget *parent)
+: QWidget(parent)
+{
+ vbox = new QVBoxLayout(this);
+}
+
+//! [0] //! [1]
+void QParentWidget::createSubWidget(const QString &name)
+{
+ QSubWidget *sw = new QSubWidget(this, name);
+ vbox->addWidget(sw);
+ sw->setLabel(name);
+ sw->show();
+}
+
+//! [1] //! [2]
+QSubWidget *QParentWidget::subWidget(const QString &name)
+{
+ return qFindChild<QSubWidget*>(this, name);
+}
+
+//! [2]
+QSize QParentWidget::sizeHint() const
+{
+ return QWidget::sizeHint().expandedTo(QSize(100, 100));
+}
+
+/* Implementation of QSubWidget */
+//! [3]
+QSubWidget::QSubWidget(QWidget *parent, const QString &name)
+: QWidget(parent)
+{
+ setObjectName(name);
+}
+
+void QSubWidget::setLabel(const QString &text)
+{
+ lbl = text;
+ setObjectName(text);
+ update();
+}
+
+QString QSubWidget::label() const
+{
+ return lbl;
+}
+
+QSize QSubWidget::sizeHint() const
+{
+ QFontMetrics fm(font());
+ return QSize(fm.width(lbl), fm.height());
+}
+
+void QSubWidget::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.setPen(palette().text().color());
+ painter.drawText(rect(), Qt::AlignCenter, lbl);
+//! [3] //! [4]
+}
+//! [4]
diff --git a/examples/activeqt/hierarchy/objects.h b/examples/activeqt/hierarchy/objects.h
new file mode 100644
index 0000000000..e719e6d687
--- /dev/null
+++ b/examples/activeqt/hierarchy/objects.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OBJECTS_H
+#define OBJECTS_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QVBoxLayout;
+QT_END_NAMESPACE
+class QSubWidget;
+
+//! [0]
+class QParentWidget : public QWidget
+{
+ Q_OBJECT
+ Q_CLASSINFO("ClassID", "{d574a747-8016-46db-a07c-b2b4854ee75c}");
+ Q_CLASSINFO("InterfaceID", "{4a30719d-d9c2-4659-9d16-67378209f822}");
+ Q_CLASSINFO("EventsID", "{4a30719d-d9c2-4659-9d16-67378209f823}");
+public:
+ QParentWidget(QWidget *parent = 0);
+
+ QSize sizeHint() const;
+
+public slots:
+ void createSubWidget( const QString &name );
+
+ QSubWidget *subWidget( const QString &name );
+
+private:
+ QVBoxLayout *vbox;
+};
+//! [0]
+
+//! [1]
+class QSubWidget : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY( QString label READ label WRITE setLabel )
+
+ Q_CLASSINFO("ClassID", "{850652f4-8f71-4f69-b745-bce241ccdc30}");
+ Q_CLASSINFO("InterfaceID", "{2d76cc2f-3488-417a-83d6-debff88b3c3f}");
+ Q_CLASSINFO("ToSuperClass", "QSubWidget");
+
+public:
+ QSubWidget(QWidget *parent = 0, const QString &name = QString());
+
+ void setLabel( const QString &text );
+ QString label() const;
+
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent( QPaintEvent *e );
+
+private:
+ QString lbl;
+};
+//! [1]
+
+#endif // OBJECTS_H
diff --git a/examples/activeqt/menus/fileopen.xpm b/examples/activeqt/menus/fileopen.xpm
new file mode 100644
index 0000000000..880417eeeb
--- /dev/null
+++ b/examples/activeqt/menus/fileopen.xpm
@@ -0,0 +1,22 @@
+/* XPM */
+static const char *fileopen[] = {
+" 16 13 5 1",
+". c #040404",
+"# c #808304",
+"a c None",
+"b c #f3f704",
+"c c #f3f7f3",
+"aaaaaaaaa...aaaa",
+"aaaaaaaa.aaa.a.a",
+"aaaaaaaaaaaaa..a",
+"a...aaaaaaaa...a",
+".bcb.......aaaaa",
+".cbcbcbcbc.aaaaa",
+".bcbcbcbcb.aaaaa",
+".cbcb...........",
+".bcb.#########.a",
+".cb.#########.aa",
+".b.#########.aaa",
+"..#########.aaaa",
+"...........aaaaa"
+};
diff --git a/examples/activeqt/menus/filesave.xpm b/examples/activeqt/menus/filesave.xpm
new file mode 100644
index 0000000000..bd6870f475
--- /dev/null
+++ b/examples/activeqt/menus/filesave.xpm
@@ -0,0 +1,22 @@
+/* XPM */
+static const char *filesave[] = {
+" 14 14 4 1",
+". c #040404",
+"# c #808304",
+"a c #bfc2bf",
+"b c None",
+"..............",
+".#.aaaaaaaa.a.",
+".#.aaaaaaaa...",
+".#.aaaaaaaa.#.",
+".#.aaaaaaaa.#.",
+".#.aaaaaaaa.#.",
+".#.aaaaaaaa.#.",
+".##........##.",
+".############.",
+".##.........#.",
+".##......aa.#.",
+".##......aa.#.",
+".##......aa.#.",
+"b............."
+};
diff --git a/examples/activeqt/menus/main.cpp b/examples/activeqt/menus/main.cpp
new file mode 100644
index 0000000000..56f8a9fc16
--- /dev/null
+++ b/examples/activeqt/menus/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "menus.h"
+#include <QApplication>
+#include <QAxFactory>
+
+QAXFACTORY_DEFAULT(QMenus,
+ "{4dc3f340-a6f7-44e4-a79b-3e9217695fbd}",
+ "{9ee49617-7d5c-441a-b833-4b068d40d751}",
+ "{13eca64b-ee2a-4f3c-aa04-5d9d975979a7}",
+ "{ce947ee3-0403-4fdc-895a-4fe779394b46}",
+ "{8de435ce-8d2a-46ac-b3b3-cb800d0847c7}");
+
+int main( int argc, char **argv )
+{
+ QApplication a( argc, argv );
+
+ QWidget *window = 0;
+ if ( !QAxFactory::isServer() ) {
+ window = new QMenus();
+ window->show();
+ }
+
+ return a.exec();
+}
diff --git a/examples/activeqt/menus/menus.cpp b/examples/activeqt/menus/menus.cpp
new file mode 100644
index 0000000000..27f064e862
--- /dev/null
+++ b/examples/activeqt/menus/menus.cpp
@@ -0,0 +1,178 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "menus.h"
+#include <QAction>
+#include <QAxFactory>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QTextEdit>
+#include <QPixmap>
+
+#include "fileopen.xpm"
+#include "filesave.xpm"
+
+QMenus::QMenus(QWidget *parent)
+ : QMainWindow(parent, 0) // QMainWindow's default flag is WType_TopLevel
+{
+ QAction *action;
+
+ QMenu *file = new QMenu(this);
+
+ action = new QAction(QPixmap((const char**)fileopen), "&Open", this);
+ action->setShortcut(tr("CTRL+O"));
+ connect(action, SIGNAL(triggered()), this, SLOT(fileOpen()));
+ file->addAction(action);
+
+ action = new QAction(QPixmap((const char**)filesave),"&Save", this);
+ action->setShortcut(tr("CTRL+S"));
+ connect(action, SIGNAL(triggered()), this, SLOT(fileSave()));
+ file->addAction(action);
+
+ QMenu *edit = new QMenu(this);
+
+ action = new QAction("&Normal", this);
+ action->setShortcut(tr("CTRL+N"));
+ action->setToolTip("Normal");
+ action->setStatusTip("Toggles Normal");
+ action->setCheckable(true);
+ connect(action, SIGNAL(triggered()), this, SLOT(editNormal()));
+ edit->addAction(action);
+
+ action = new QAction("&Bold", this);
+ action->setShortcut(tr("CTRL+B"));
+ action->setCheckable(true);
+ connect(action, SIGNAL(triggered()), this, SLOT(editBold()));
+ edit->addAction(action);
+
+ action = new QAction("&Underline", this);
+ action->setShortcut(tr("CTRL+U"));
+ action->setCheckable(true);
+ connect(action, SIGNAL(triggered()), this, SLOT(editUnderline()));
+ edit->addAction(action);
+
+ QMenu *advanced = new QMenu(this);
+ action = new QAction("&Font...", this);
+ connect(action, SIGNAL(triggered()), this, SLOT(editAdvancedFont()));
+ advanced->addAction(action);
+
+ action = new QAction("&Style...", this);
+ connect(action, SIGNAL(triggered()), this, SLOT(editAdvancedStyle()));
+ advanced->addAction(action);
+
+ edit->addMenu(advanced)->setText("&Advanced");
+
+ edit->addSeparator();
+
+ action = new QAction("Una&vailable", this);
+ action->setShortcut(tr("CTRL+V"));
+ action->setCheckable(true);
+ action->setEnabled(false);
+ connect(action, SIGNAL(triggered()), this, SLOT(editUnderline()));
+ edit->addAction(action);
+
+ QMenu *help = new QMenu(this);
+
+ action = new QAction("&About...", this);
+ action->setShortcut(tr("F1"));
+ connect(action, SIGNAL(triggered()), this, SLOT(helpAbout()));
+ help->addAction(action);
+
+ action = new QAction("&About Qt...", this);
+ connect(action, SIGNAL(triggered()), this, SLOT(helpAboutQt()));
+ help->addAction(action);
+
+ if (!QAxFactory::isServer())
+ menuBar()->addMenu(file)->setText("&File");
+ menuBar()->addMenu(edit)->setText("&Edit");
+ menuBar()->addMenu(help)->setText("&Help");
+
+ editor = new QTextEdit(this);
+ setCentralWidget(editor);
+
+ statusBar();
+}
+
+void QMenus::fileOpen()
+{
+ editor->append("File Open selected.");
+}
+
+void QMenus::fileSave()
+{
+ editor->append("File Save selected.");
+}
+
+void QMenus::editNormal()
+{
+ editor->append("Edit Normal selected.");
+}
+
+void QMenus::editBold()
+{
+ editor->append("Edit Bold selected.");
+}
+
+void QMenus::editUnderline()
+{
+ editor->append("Edit Underline selected.");
+}
+
+void QMenus::editAdvancedFont()
+{
+ editor->append("Edit Advanced Font selected.");
+}
+
+void QMenus::editAdvancedStyle()
+{
+ editor->append("Edit Advanced Style selected.");
+}
+
+void QMenus::helpAbout()
+{
+ QMessageBox::about(this, "About QMenus",
+ "This example implements an in-place ActiveX control with menus and status messages.");
+}
+
+void QMenus::helpAboutQt()
+{
+ QMessageBox::aboutQt(this);
+}
diff --git a/examples/activeqt/menus/menus.h b/examples/activeqt/menus/menus.h
new file mode 100644
index 0000000000..c961cd5cc0
--- /dev/null
+++ b/examples/activeqt/menus/menus.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MENUS_H
+#define MENUS_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QTextEdit;
+QT_END_NAMESPACE
+
+class QMenus : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ QMenus(QWidget *parent = 0);
+
+public slots:
+ void fileOpen();
+ void fileSave();
+
+ void editNormal();
+ void editBold();
+ void editUnderline();
+
+ void editAdvancedFont();
+ void editAdvancedStyle();
+
+ void helpAbout();
+ void helpAboutQt();
+
+private:
+ QTextEdit *editor;
+};
+
+#endif // MENUS_H
diff --git a/examples/activeqt/menus/menus.inf b/examples/activeqt/menus/menus.inf
new file mode 100644
index 0000000000..f97efe86d8
--- /dev/null
+++ b/examples/activeqt/menus/menus.inf
@@ -0,0 +1,9 @@
+[version]
+ signature="$CHICAGO$"
+ AdvancedINF=2.0
+ [Add.Code]
+ menusax.exe=menusax.exe
+ [menusax.exe]
+ file-win32-x86=thiscab
+ clsid={4dc3f340-a6f7-44e4-a79b-3e9217695fbd}
+ RegisterServer=yes
diff --git a/examples/activeqt/menus/menus.pro b/examples/activeqt/menus/menus.pro
new file mode 100644
index 0000000000..8963bad405
--- /dev/null
+++ b/examples/activeqt/menus/menus.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET = menusax
+
+CONFIG += qt warn_off qaxserver
+
+SOURCES = main.cpp menus.cpp
+HEADERS = menus.h
+RC_FILE = $$QT_SOURCE_TREE/src/activeqt/control/qaxserver.rc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/menus
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS menus.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/menus
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/multiple/ax1.h b/examples/activeqt/multiple/ax1.h
new file mode 100644
index 0000000000..a53e4f457a
--- /dev/null
+++ b/examples/activeqt/multiple/ax1.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef AX1_H
+#define AX1_H
+
+#include <QWidget>
+#include <QPainter>
+
+//! [0]
+class QAxWidget1 : public QWidget
+{
+ Q_OBJECT
+ Q_CLASSINFO("ClassID", "{1D9928BD-4453-4bdd-903D-E525ED17FDE5}")
+ Q_CLASSINFO("InterfaceID", "{99F6860E-2C5A-42ec-87F2-43396F4BE389}")
+ Q_CLASSINFO("EventsID", "{0A3E9F27-E4F1-45bb-9E47-63099BCCD0E3}")
+
+ Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor)
+public:
+ QAxWidget1(QWidget *parent = 0)
+ : QWidget(parent), fill_color(Qt::red)
+ {
+ }
+
+ QColor fillColor() const
+ {
+ return fill_color;
+ }
+ void setFillColor(const QColor &fc)
+ {
+ fill_color = fc;
+ repaint();
+ }
+
+protected:
+ void paintEvent(QPaintEvent *e)
+ {
+ QPainter paint(this);
+ QRect r = rect();
+ r.adjust(10, 10, -10, -10);
+ paint.fillRect(r, fill_color);
+ }
+
+private:
+ QColor fill_color;
+};
+//! [0]
+
+#endif // AX1_H
diff --git a/examples/activeqt/multiple/ax2.h b/examples/activeqt/multiple/ax2.h
new file mode 100644
index 0000000000..b6b50f3e6a
--- /dev/null
+++ b/examples/activeqt/multiple/ax2.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef AX2_H
+#define AX2_H
+
+#include <QWidget>
+#include <QPainter>
+
+//! [0]
+class QAxWidget2 : public QWidget
+{
+ Q_OBJECT
+ Q_CLASSINFO("ClassID", "{58139D56-6BE9-4b17-937D-1B1EDEDD5B71}")
+ Q_CLASSINFO("InterfaceID", "{B66280AB-08CC-4dcc-924F-58E6D7975B7D}")
+ Q_CLASSINFO("EventsID", "{D72BACBA-03C4-4480-B4BB-DE4FE3AA14A0}")
+ Q_CLASSINFO("ToSuperClass", "QAxWidget2")
+ Q_CLASSINFO("StockEvents", "yes")
+ Q_CLASSINFO("Insertable", "yes")
+
+ Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
+public:
+ QAxWidget2(QWidget *parent = 0)
+ : QWidget(parent), line_width( 1 )
+ {
+ }
+
+ int lineWidth() const
+ {
+ return line_width;
+ }
+ void setLineWidth( int lw )
+ {
+ line_width = lw;
+ repaint();
+ }
+
+protected:
+ void paintEvent( QPaintEvent *e )
+ {
+ QPainter paint( this );
+ QPen pen = paint.pen();
+ pen.setWidth( line_width );
+ paint.setPen( pen );
+
+ QRect r = rect();
+ r.adjust( 10, 10, -10, -10 );
+ paint.drawEllipse( r );
+ }
+
+private:
+ int line_width;
+};
+//! [0]
+
+#endif // AX2_H
diff --git a/examples/activeqt/multiple/main.cpp b/examples/activeqt/multiple/main.cpp
new file mode 100644
index 0000000000..612292eeec
--- /dev/null
+++ b/examples/activeqt/multiple/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include "ax1.h"
+#include "ax2.h"
+#include <QAxFactory>
+
+QT_USE_NAMESPACE
+
+QAXFACTORY_BEGIN("{98DE28B6-6CD3-4e08-B9FA-3D1DB43F1D2F}", "{05828915-AD1C-47ab-AB96-D6AD1E25F0E2}")
+ QAXCLASS(QAxWidget1)
+ QAXCLASS(QAxWidget2)
+QAXFACTORY_END()
+//! [0]
diff --git a/examples/activeqt/multiple/multiple.inf b/examples/activeqt/multiple/multiple.inf
new file mode 100644
index 0000000000..7f6be769c7
--- /dev/null
+++ b/examples/activeqt/multiple/multiple.inf
@@ -0,0 +1,9 @@
+[version]
+ signature="$CHICAGO$"
+ AdvancedINF=2.0
+ [Add.Code]
+ multipleax.dll=multipleax.dll
+ [multipleax.dll]
+ file-win32-x86=thiscab
+ clsid={1D9928BD-4453-4bdd-903D-E525ED17FDE5}
+ RegisterServer=yes
diff --git a/examples/activeqt/multiple/multiple.pro b/examples/activeqt/multiple/multiple.pro
new file mode 100644
index 0000000000..97acc9a4aa
--- /dev/null
+++ b/examples/activeqt/multiple/multiple.pro
@@ -0,0 +1,18 @@
+TEMPLATE = lib
+TARGET = multipleax
+
+CONFIG += qt warn_off qaxserver dll
+contains(CONFIG, static):DEFINES += QT_NODLL
+
+SOURCES = main.cpp
+HEADERS = ax1.h ax2.h
+RC_FILE = multipleax.rc
+DEF_FILE = $$QT_SOURCE_TREE/src/activeqt/control/qaxserver.def
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/multiple
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS multiple.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/multiple
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/multiple/multipleax.rc b/examples/activeqt/multiple/multipleax.rc
new file mode 100644
index 0000000000..1809e0d550
--- /dev/null
+++ b/examples/activeqt/multiple/multipleax.rc
@@ -0,0 +1,32 @@
+#include "winver.h"
+
+1 TYPELIB "multipleax.rc"
+1 ICON DISCARDABLE "..\\..\\..\\src\\activeqt\\control\\qaxserver.ico"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x3fL
+ FILEOS 0x00040000L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904e4"
+ BEGIN
+ VALUE "CompanyName", "Nokia Corporation and/or its subsidiary(-ies)"
+ VALUE "FileDescription", "Multiple Example (ActiveQt)"
+ VALUE "FileVersion", "1.0.0.0"
+ VALUE "LegalCopyright", "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)."
+ VALUE "InternalName", "multipleax.dll"
+ VALUE "OriginalFilename", "multipleax.dll"
+ VALUE "ProductName", "Multiple Example (ActiveQt)"
+ VALUE "ProductVersion", "1.0.0.0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1252
+ END
+END
diff --git a/examples/activeqt/opengl/glbox.cpp b/examples/activeqt/opengl/glbox.cpp
new file mode 100644
index 0000000000..4cb015b7b4
--- /dev/null
+++ b/examples/activeqt/opengl/glbox.cpp
@@ -0,0 +1,250 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/****************************************************************************
+**
+** This is a simple QGLWidget displaying an openGL wireframe box
+**
+** The OpenGL code is mostly borrowed from Brian Pauls "spin" example
+** in the Mesa distribution
+**
+****************************************************************************/
+
+#include "glbox.h"
+#include <QAxAggregated>
+#include <QUuid>
+//! [0]
+#include <objsafe.h>
+//! [0]
+
+#if defined(Q_CC_MSVC)
+#pragma warning(disable:4305) // init: truncation from const double to float
+#endif
+
+/*!
+ Create a GLBox widget
+*/
+
+GLBox::GLBox( QWidget* parent, const char* name )
+ : QGLWidget( parent )
+{
+ xRot = yRot = zRot = 0.0; // default object rotation
+ scale = 1.25; // default object scale
+ object = 0;
+}
+
+
+/*!
+ Release allocated resources
+*/
+
+GLBox::~GLBox()
+{
+ makeCurrent();
+ glDeleteLists( object, 1 );
+}
+
+
+/*!
+ Paint the box. The actual openGL commands for drawing the box are
+ performed here.
+*/
+
+void GLBox::paintGL()
+{
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ glLoadIdentity();
+ glTranslatef( 0.0, 0.0, -10.0 );
+ glScalef( scale, scale, scale );
+
+ glRotatef( xRot, 1.0, 0.0, 0.0 );
+ glRotatef( yRot, 0.0, 1.0, 0.0 );
+ glRotatef( zRot, 0.0, 0.0, 1.0 );
+
+ glCallList( object );
+}
+
+
+/*!
+ Set up the OpenGL rendering state, and define display list
+*/
+
+void GLBox::initializeGL()
+{
+ qglClearColor(Qt::black); // Let OpenGL clear to black
+ object = makeObject(); // Generate an OpenGL display list
+ glShadeModel( GL_FLAT );
+}
+
+
+
+/*!
+ Set up the OpenGL view port, matrix mode, etc.
+*/
+
+void GLBox::resizeGL( int w, int h )
+{
+ glViewport( 0, 0, (GLint)w, (GLint)h );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
+ glMatrixMode( GL_MODELVIEW );
+}
+
+
+/*!
+ Generate an OpenGL display list for the object to be shown, i.e. the box
+*/
+
+GLuint GLBox::makeObject()
+{
+ GLuint list;
+
+ list = glGenLists( 1 );
+
+ glNewList( list, GL_COMPILE );
+
+ qglColor(Qt::white); // Shorthand for glColor3f or glIndex
+
+ glLineWidth( 2.0 );
+
+ glBegin( GL_LINE_LOOP );
+ glVertex3f( 1.0, 0.5, -0.4 );
+ glVertex3f( 1.0, -0.5, -0.4 );
+ glVertex3f( -1.0, -0.5, -0.4 );
+ glVertex3f( -1.0, 0.5, -0.4 );
+ glEnd();
+
+ glBegin( GL_LINE_LOOP );
+ glVertex3f( 1.0, 0.5, 0.4 );
+ glVertex3f( 1.0, -0.5, 0.4 );
+ glVertex3f( -1.0, -0.5, 0.4 );
+ glVertex3f( -1.0, 0.5, 0.4 );
+ glEnd();
+
+ glBegin( GL_LINES );
+ glVertex3f( 1.0, 0.5, -0.4 ); glVertex3f( 1.0, 0.5, 0.4 );
+ glVertex3f( 1.0, -0.5, -0.4 ); glVertex3f( 1.0, -0.5, 0.4 );
+ glVertex3f( -1.0, -0.5, -0.4 ); glVertex3f( -1.0, -0.5, 0.4 );
+ glVertex3f( -1.0, 0.5, -0.4 ); glVertex3f( -1.0, 0.5, 0.4 );
+ glEnd();
+
+ glEndList();
+
+ return list;
+}
+
+
+/*!
+ Set the rotation angle of the object to \e degrees around the X axis.
+*/
+
+void GLBox::setXRotation( int degrees )
+{
+ xRot = (GLfloat)(degrees % 360);
+ updateGL();
+}
+
+
+/*!
+ Set the rotation angle of the object to \e degrees around the Y axis.
+*/
+
+void GLBox::setYRotation( int degrees )
+{
+ yRot = (GLfloat)(degrees % 360);
+ updateGL();
+}
+
+
+/*!
+ Set the rotation angle of the object to \e degrees around the Z axis.
+*/
+
+void GLBox::setZRotation( int degrees )
+{
+ zRot = (GLfloat)(degrees % 360);
+ updateGL();
+}
+
+//! [1]
+class ObjectSafetyImpl : public QAxAggregated,
+ public IObjectSafety
+{
+public:
+//! [1] //! [2]
+ ObjectSafetyImpl() {}
+
+ long queryInterface( const QUuid &iid, void **iface )
+ {
+ *iface = 0;
+ if ( iid == IID_IObjectSafety )
+ *iface = (IObjectSafety*)this;
+ else
+ return E_NOINTERFACE;
+
+ AddRef();
+ return S_OK;
+ }
+
+//! [2] //! [3]
+ QAXAGG_IUNKNOWN;
+
+//! [3] //! [4]
+ HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions )
+ {
+ *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
+ *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
+ return S_OK;
+ }
+ HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions )
+ {
+ return S_OK;
+ }
+};
+//! [4] //! [5]
+
+QAxAggregated *GLBox::createAggregate()
+{
+ return new ObjectSafetyImpl();
+}
+//! [5]
diff --git a/examples/activeqt/opengl/glbox.h b/examples/activeqt/opengl/glbox.h
new file mode 100644
index 0000000000..3ebf818e9f
--- /dev/null
+++ b/examples/activeqt/opengl/glbox.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/****************************************************************************
+**
+** This is a simple QGLWidget displaying an openGL wireframe box
+**
+****************************************************************************/
+
+#ifndef GLBOX_H
+#define GLBOX_H
+
+#include <QtOpenGL>
+//! [0]
+#include <QAxBindable>
+
+class GLBox : public QGLWidget,
+ public QAxBindable
+{
+ Q_OBJECT
+//! [0] //! [1]
+
+public:
+
+ GLBox( QWidget* parent, const char* name = 0 );
+ ~GLBox();
+
+ QAxAggregated *createAggregate();
+
+public slots:
+
+ void setXRotation( int degrees );
+//! [1]
+ void setYRotation( int degrees );
+ void setZRotation( int degrees );
+
+protected:
+
+ void initializeGL();
+ void paintGL();
+ void resizeGL( int w, int h );
+
+ virtual GLuint makeObject();
+
+private:
+
+ GLuint object;
+ GLfloat xRot, yRot, zRot, scale;
+
+};
+
+#endif // GLBOX_H
diff --git a/examples/activeqt/opengl/globjwin.cpp b/examples/activeqt/opengl/globjwin.cpp
new file mode 100644
index 0000000000..3ac5d78621
--- /dev/null
+++ b/examples/activeqt/opengl/globjwin.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "globjwin.h"
+#include "glbox.h"
+#include <QPushButton>
+#include <QSlider>
+#include <QLayout>
+#include <QFrame>
+#include <QMenuBar>
+#include <QMenu>
+#include <QApplication>
+
+
+GLObjectWindow::GLObjectWindow(QWidget* parent)
+ : QWidget(parent)
+{
+
+ // Create a menu
+ QMenu *file = new QMenu( this );
+ file->addAction( "Exit", qApp, SLOT(quit())/*, CTRL+Key_Q*/);
+
+ // Create a menu bar
+ QMenuBar *m = new QMenuBar( this );
+ m->addMenu(file)->setText("&File");
+
+ // Create a nice frame to put around the OpenGL widget
+ QFrame* f = new QFrame(this);
+ f->setFrameStyle( QFrame::Sunken | QFrame::Panel );
+ f->setLineWidth( 2 );
+
+ // Create our OpenGL widget
+ GLBox* c = new GLBox( f, "glbox");
+
+ // Create the three sliders; one for each rotation axis
+ QSlider* x = new QSlider(Qt::Vertical, this);
+ x->setMaximum(360);
+ x->setPageStep(60);
+ x->setTickPosition( QSlider::TicksLeft );
+ QObject::connect( x, SIGNAL(valueChanged(int)),c,SLOT(setXRotation(int)) );
+
+ QSlider* y = new QSlider(Qt::Vertical, this);
+ y->setMaximum(360);
+ y->setPageStep(60);
+ y->setTickPosition( QSlider::TicksLeft );
+ QObject::connect( y, SIGNAL(valueChanged(int)),c,SLOT(setYRotation(int)) );
+
+ QSlider* z = new QSlider(Qt::Vertical, this);
+ z->setMaximum(360);
+ z->setPageStep(60);
+ z->setTickPosition( QSlider::TicksLeft );
+ QObject::connect( z, SIGNAL(valueChanged(int)),c,SLOT(setZRotation(int)) );
+
+ // Now that we have all the widgets, put them into a nice layout
+
+ // Top level layout, puts the sliders to the left of the frame/GL widget
+ QHBoxLayout* hlayout = new QHBoxLayout(this);
+
+ // Put the sliders on top of each other
+ QVBoxLayout* vlayout = new QVBoxLayout();
+ vlayout->addWidget( x );
+ vlayout->addWidget( y );
+ vlayout->addWidget( z );
+
+ // Put the GL widget inside the frame
+ QHBoxLayout* flayout = new QHBoxLayout(f);
+ flayout->setMargin(0);
+ flayout->addWidget( c, 1 );
+
+ hlayout->setMenuBar( m );
+ hlayout->addLayout( vlayout );
+ hlayout->addWidget( f, 1 );
+}
diff --git a/examples/activeqt/opengl/globjwin.h b/examples/activeqt/opengl/globjwin.h
new file mode 100644
index 0000000000..d707aa63f3
--- /dev/null
+++ b/examples/activeqt/opengl/globjwin.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/****************************************************************************
+**
+** The GLObjectWindow contains a GLBox and three sliders connected to
+** the GLBox's rotation slots.
+**
+****************************************************************************/
+
+#ifndef GLOBJWIN_H
+#define GLOBJWIN_H
+
+#include <qwidget.h>
+
+class GLObjectWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ GLObjectWindow(QWidget *parent = 0);
+};
+
+#endif
diff --git a/examples/activeqt/opengl/main.cpp b/examples/activeqt/opengl/main.cpp
new file mode 100644
index 0000000000..469bdfb29d
--- /dev/null
+++ b/examples/activeqt/opengl/main.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//
+// Qt OpenGL example: Box
+//
+// A small example showing how a GLWidget can be used just as any Qt widget
+//
+// File: main.cpp
+//
+// The main() function
+//
+
+#include "globjwin.h"
+#include "glbox.h"
+#include <QApplication>
+#include <QtOpenGL>
+//! [0]
+#include <QAxFactory>
+
+QAXFACTORY_DEFAULT( GLBox,
+ "{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}",
+ "{33b051af-bb25-47cf-a390-5cfd2987d26a}",
+ "{8c996c29-eafa-46ac-a6f9-901951e765b5}",
+ "{2c3c183a-eeda-41a4-896e-3d9c12c3577d}",
+ "{83e16271-6480-45d5-aaf1-3f40b7661ae4}"
+ )
+
+//! [0] //! [1]
+/*
+ The main program is here.
+*/
+
+int main( int argc, char **argv )
+{
+ QApplication::setColorSpec( QApplication::CustomColor );
+ QApplication a(argc,argv);
+
+ if ( !QGLFormat::hasOpenGL() ) {
+ qWarning( "This system has no OpenGL support. Exiting." );
+ return -1;
+ }
+
+ if ( !QAxFactory::isServer() ) {
+ GLObjectWindow w;
+ w.resize( 400, 350 );
+ w.show();
+ return a.exec();
+//! [1] //! [2]
+ }
+ return a.exec();
+//! [2] //! [3]
+}
+//! [3]
diff --git a/examples/activeqt/opengl/opengl.inf b/examples/activeqt/opengl/opengl.inf
new file mode 100644
index 0000000000..4a79e67d01
--- /dev/null
+++ b/examples/activeqt/opengl/opengl.inf
@@ -0,0 +1,9 @@
+[version]
+ signature="$CHICAGO$"
+ AdvancedINF=2.0
+ [Add.Code]
+ openglax.exe=openglax.exe
+ [openglax.exe]
+ file-win32-x86=thiscab
+ clsid={5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}
+ RegisterServer=yes
diff --git a/examples/activeqt/opengl/opengl.pro b/examples/activeqt/opengl/opengl.pro
new file mode 100644
index 0000000000..4979dc09cb
--- /dev/null
+++ b/examples/activeqt/opengl/opengl.pro
@@ -0,0 +1,21 @@
+TEMPLATE = app
+TARGET = openglax
+
+CONFIG += qt warn_off qaxserver
+
+QT += opengl
+
+HEADERS = glbox.h \
+ globjwin.h
+SOURCES = glbox.cpp \
+ globjwin.cpp \
+ main.cpp
+RC_FILE = $$QT_SOURCE_TREE/src/activeqt/control/qaxserver.rc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/opengl
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS opengl.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/opengl
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/qutlook/addressview.cpp b/examples/activeqt/qutlook/addressview.cpp
new file mode 100644
index 0000000000..281fe6a07f
--- /dev/null
+++ b/examples/activeqt/qutlook/addressview.cpp
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include "addressview.h"
+#include "msoutl.h"
+#include <QtGui>
+
+class AddressBookModel : public QAbstractListModel
+{
+public:
+ AddressBookModel(AddressView *parent);
+ ~AddressBookModel();
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ QVariant data(const QModelIndex &index, int role) const;
+
+ void changeItem(const QModelIndex &index, const QString &firstName, const QString &lastName, const QString &address, const QString &email);
+ void addItem(const QString &firstName, const QString &lastName, const QString &address, const QString &email);
+ void update();
+
+private:
+ Outlook::Application outlook;
+ Outlook::Items * contactItems;
+
+ mutable QHash<QModelIndex, QStringList> cache;
+};
+//! [0] //! [1]
+
+AddressBookModel::AddressBookModel(AddressView *parent)
+: QAbstractListModel(parent)
+{
+ if (!outlook.isNull()) {
+ Outlook::NameSpace session(outlook.Session());
+ session.Logon();
+ Outlook::MAPIFolder *folder = session.GetDefaultFolder(Outlook::olFolderContacts);
+ contactItems = new Outlook::Items(folder->Items());
+ connect(contactItems, SIGNAL(ItemAdd(IDispatch*)), parent, SLOT(updateOutlook()));
+ connect(contactItems, SIGNAL(ItemChange(IDispatch*)), parent, SLOT(updateOutlook()));
+ connect(contactItems, SIGNAL(ItemRemove()), parent, SLOT(updateOutlook()));
+
+ delete folder;
+ }
+}
+
+//! [1] //! [2]
+AddressBookModel::~AddressBookModel()
+{
+ delete contactItems;
+
+ if (!outlook.isNull())
+ Outlook::NameSpace(outlook.Session()).Logoff();
+}
+
+//! [2] //! [3]
+int AddressBookModel::rowCount(const QModelIndex &) const
+{
+ return contactItems ? contactItems->Count() : 0;
+}
+
+int AddressBookModel::columnCount(const QModelIndex &parent) const
+{
+ return 4;
+}
+
+//! [3] //! [4]
+QVariant AddressBookModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ switch (section) {
+ case 0:
+ return tr("First Name");
+ case 1:
+ return tr("Last Name");
+ case 2:
+ return tr("Address");
+ case 3:
+ return tr("Email");
+ default:
+ break;
+ }
+
+ return QVariant();
+}
+
+//! [4] //! [5]
+QVariant AddressBookModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid() || role != Qt::DisplayRole)
+ return QVariant();
+
+ QStringList data;
+ if (cache.contains(index)) {
+ data = cache.value(index);
+ } else {
+ Outlook::ContactItem contact(contactItems->Item(index.row() + 1));
+ data << contact.FirstName() << contact.LastName() << contact.HomeAddress() << contact.Email1Address();
+ cache.insert(index, data);
+ }
+
+ if (index.column() < data.count())
+ return data.at(index.column());
+
+ return QVariant();
+}
+
+//! [5] //! [6]
+void AddressBookModel::changeItem(const QModelIndex &index, const QString &firstName, const QString &lastName, const QString &address, const QString &email)
+{
+ Outlook::ContactItem item(contactItems->Item(index.row() + 1));
+
+ item.SetFirstName(firstName);
+ item.SetLastName(lastName);
+ item.SetHomeAddress(address);
+ item.SetEmail1Address(email);
+
+ item.Save();
+
+ cache.take(index);
+}
+
+//! [6] //! [7]
+void AddressBookModel::addItem(const QString &firstName, const QString &lastName, const QString &address, const QString &email)
+{
+ Outlook::ContactItem item(outlook.CreateItem(Outlook::olContactItem));
+ if (!item.isNull()) {
+ item.SetFirstName(firstName);
+ item.SetLastName(lastName);
+ item.SetHomeAddress(address);
+ item.SetEmail1Address(email);
+
+ item.Save();
+ }
+}
+
+//! [7] //! [8]
+void AddressBookModel::update()
+{
+ cache.clear();
+
+ emit reset();
+}
+
+
+//! [8] //! [9]
+AddressView::AddressView(QWidget *parent)
+: QWidget(parent)
+{
+ QGridLayout *mainGrid = new QGridLayout(this);
+
+ QLabel *liFirstName = new QLabel("First &Name", this);
+ liFirstName->resize(liFirstName->sizeHint());
+ mainGrid->addWidget(liFirstName, 0, 0);
+
+ QLabel *liLastName = new QLabel("&Last Name", this);
+ liLastName->resize(liLastName->sizeHint());
+ mainGrid->addWidget(liLastName, 0, 1);
+
+ QLabel *liAddress = new QLabel("Add&ress", this);
+ liAddress->resize(liAddress->sizeHint());
+ mainGrid->addWidget(liAddress, 0, 2);
+
+ QLabel *liEMail = new QLabel("&E-Mail", this);
+ liEMail->resize(liEMail->sizeHint());
+ mainGrid->addWidget(liEMail, 0, 3);
+
+ add = new QPushButton("A&dd", this);
+ add->resize(add->sizeHint());
+ mainGrid->addWidget(add, 0, 4);
+ connect(add, SIGNAL(clicked()), this, SLOT(addEntry()));
+
+ iFirstName = new QLineEdit(this);
+ iFirstName->resize(iFirstName->sizeHint());
+ mainGrid->addWidget(iFirstName, 1, 0);
+ liFirstName->setBuddy(iFirstName);
+
+ iLastName = new QLineEdit(this);
+ iLastName->resize(iLastName->sizeHint());
+ mainGrid->addWidget(iLastName, 1, 1);
+ liLastName->setBuddy(iLastName);
+
+ iAddress = new QLineEdit(this);
+ iAddress->resize(iAddress->sizeHint());
+ mainGrid->addWidget(iAddress, 1, 2);
+ liAddress->setBuddy(iAddress);
+
+ iEMail = new QLineEdit(this);
+ iEMail->resize(iEMail->sizeHint());
+ mainGrid->addWidget(iEMail, 1, 3);
+ liEMail->setBuddy(iEMail);
+
+ change = new QPushButton("&Change", this);
+ change->resize(change->sizeHint());
+ mainGrid->addWidget(change, 1, 4);
+ connect(change, SIGNAL(clicked()), this, SLOT(changeEntry()));
+
+ treeView = new QTreeView(this);
+ treeView->setSelectionMode(QTreeView::SingleSelection);
+ treeView->setRootIsDecorated(false);
+
+ model = new AddressBookModel(this);
+ treeView->setModel(model);
+
+ connect(treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(itemSelected(QModelIndex)));
+
+ mainGrid->addWidget(treeView, 2, 0, 1, 5);
+}
+
+void AddressView::updateOutlook()
+{
+ model->update();
+}
+
+void AddressView::addEntry()
+{
+ if (!iFirstName->text().isEmpty() || !iLastName->text().isEmpty() ||
+ !iAddress->text().isEmpty() || !iEMail->text().isEmpty()) {
+ model->addItem(iFirstName->text(), iFirstName->text(), iAddress->text(), iEMail->text());
+ }
+
+ iFirstName->setText("");
+ iLastName->setText("");
+ iAddress->setText("");
+ iEMail->setText("");
+}
+
+void AddressView::changeEntry()
+{
+ QModelIndex current = treeView->currentIndex();
+
+ if (current.isValid())
+ model->changeItem(current, iFirstName->text(), iLastName->text(), iAddress->text(), iEMail->text());
+}
+
+//! [9] //! [10]
+void AddressView::itemSelected(const QModelIndex &index)
+{
+ if (!index.isValid())
+ return;
+
+ QAbstractItemModel *model = treeView->model();
+ iFirstName->setText(model->data(model->index(index.row(), 0)).toString());
+ iLastName->setText(model->data(model->index(index.row(), 1)).toString());
+ iAddress->setText(model->data(model->index(index.row(), 2)).toString());
+ iEMail->setText(model->data(model->index(index.row(), 3)).toString());
+}
+//! [10]
diff --git a/examples/activeqt/qutlook/addressview.h b/examples/activeqt/qutlook/addressview.h
new file mode 100644
index 0000000000..5363cc1f15
--- /dev/null
+++ b/examples/activeqt/qutlook/addressview.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSVIEW_H
+#define ADDRESSVIEW_H
+
+#include <QWidget>
+
+class AddressBookModel;
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QModelIndex;
+class QPushButton;
+class QTreeView;
+QT_END_NAMESPACE
+
+//! [0]
+class AddressView : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressView(QWidget *parent = 0);
+
+protected slots:
+ void addEntry();
+ void changeEntry();
+ void itemSelected(const QModelIndex &index);
+
+ void updateOutlook();
+
+protected:
+ AddressBookModel *model;
+
+ QTreeView *treeView;
+ QPushButton *add, *change;
+ QLineEdit *iFirstName, *iLastName, *iAddress, *iEMail;
+};
+//! [0]
+
+#endif // ADDRESSVIEW_H
diff --git a/examples/activeqt/qutlook/fileopen.xpm b/examples/activeqt/qutlook/fileopen.xpm
new file mode 100644
index 0000000000..880417eeeb
--- /dev/null
+++ b/examples/activeqt/qutlook/fileopen.xpm
@@ -0,0 +1,22 @@
+/* XPM */
+static const char *fileopen[] = {
+" 16 13 5 1",
+". c #040404",
+"# c #808304",
+"a c None",
+"b c #f3f704",
+"c c #f3f7f3",
+"aaaaaaaaa...aaaa",
+"aaaaaaaa.aaa.a.a",
+"aaaaaaaaaaaaa..a",
+"a...aaaaaaaa...a",
+".bcb.......aaaaa",
+".cbcbcbcbc.aaaaa",
+".bcbcbcbcb.aaaaa",
+".cbcb...........",
+".bcb.#########.a",
+".cb.#########.aa",
+".b.#########.aaa",
+"..#########.aaaa",
+"...........aaaaa"
+};
diff --git a/examples/activeqt/qutlook/fileprint.xpm b/examples/activeqt/qutlook/fileprint.xpm
new file mode 100644
index 0000000000..6ada912fa0
--- /dev/null
+++ b/examples/activeqt/qutlook/fileprint.xpm
@@ -0,0 +1,24 @@
+/* XPM */
+static const char *fileprint[] = {
+" 16 14 6 1",
+". c #000000",
+"# c #848284",
+"a c #c6c3c6",
+"b c #ffff00",
+"c c #ffffff",
+"d c None",
+"ddddd.........dd",
+"dddd.cccccccc.dd",
+"dddd.c.....c.ddd",
+"ddd.cccccccc.ddd",
+"ddd.c.....c....d",
+"dd.cccccccc.a.a.",
+"d..........a.a..",
+".aaaaaaaaaa.a.a.",
+".............aa.",
+".aaaaaa###aa.a.d",
+".aaaaaabbbaa...d",
+".............a.d",
+"d.aaaaaaaaa.a.dd",
+"dd...........ddd"
+};
diff --git a/examples/activeqt/qutlook/filesave.xpm b/examples/activeqt/qutlook/filesave.xpm
new file mode 100644
index 0000000000..bd6870f475
--- /dev/null
+++ b/examples/activeqt/qutlook/filesave.xpm
@@ -0,0 +1,22 @@
+/* XPM */
+static const char *filesave[] = {
+" 14 14 4 1",
+". c #040404",
+"# c #808304",
+"a c #bfc2bf",
+"b c None",
+"..............",
+".#.aaaaaaaa.a.",
+".#.aaaaaaaa...",
+".#.aaaaaaaa.#.",
+".#.aaaaaaaa.#.",
+".#.aaaaaaaa.#.",
+".#.aaaaaaaa.#.",
+".##........##.",
+".############.",
+".##.........#.",
+".##......aa.#.",
+".##......aa.#.",
+".##......aa.#.",
+"b............."
+};
diff --git a/examples/activeqt/qutlook/main.cpp b/examples/activeqt/qutlook/main.cpp
new file mode 100644
index 0000000000..b015d8af17
--- /dev/null
+++ b/examples/activeqt/qutlook/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include "addressview.h"
+#include <QApplication>
+
+int main(int argc, char ** argv)
+{
+ QApplication a(argc, argv);
+
+ AddressView view;
+ view.setWindowTitle("Qt Example - Looking at Outlook");
+ view.show();
+
+ return a.exec();
+}
+//! [0]
diff --git a/examples/activeqt/qutlook/qutlook.pro b/examples/activeqt/qutlook/qutlook.pro
new file mode 100644
index 0000000000..0387735e8c
--- /dev/null
+++ b/examples/activeqt/qutlook/qutlook.pro
@@ -0,0 +1,25 @@
+#! [0] #! [1]
+TEMPLATE = app
+TARGET = qutlook
+CONFIG += qaxcontainer
+
+TYPELIBS = $$system(dumpcpp -getfile {00062FFF-0000-0000-C000-000000000046})
+#! [0]
+
+isEmpty(TYPELIBS) {
+ message("Microsoft Outlook type library not found!")
+ REQUIRES += Outlook
+} else {
+#! [1] #! [2]
+ HEADERS = addressview.h
+ SOURCES = addressview.cpp main.cpp
+}
+#! [2]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/qutlook
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qutlook.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/qutlook
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/simple/main.cpp b/examples/activeqt/simple/main.cpp
new file mode 100644
index 0000000000..7f939e4290
--- /dev/null
+++ b/examples/activeqt/simple/main.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QAxBindable>
+#include <QAxFactory>
+#include <QApplication>
+#include <QLayout>
+#include <QSlider>
+#include <QLCDNumber>
+#include <QLineEdit>
+#include <QMessageBox>
+
+//! [0]
+class QSimpleAX : public QWidget, public QAxBindable
+{
+ Q_OBJECT
+ Q_PROPERTY( QString text READ text WRITE setText )
+ Q_PROPERTY( int value READ value WRITE setValue )
+public:
+ QSimpleAX(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QVBoxLayout *vbox = new QVBoxLayout( this );
+
+ slider = new QSlider( Qt::Horizontal, this );
+ LCD = new QLCDNumber( 3, this );
+ edit = new QLineEdit( this );
+
+ connect( slider, SIGNAL( valueChanged( int ) ), this, SLOT( setValue(int) ) );
+ connect( edit, SIGNAL(textChanged(const QString&)), this, SLOT(setText(const QString&)) );
+
+ vbox->addWidget( slider );
+ vbox->addWidget( LCD );
+ vbox->addWidget( edit );
+ }
+
+ QString text() const
+ {
+ return edit->text();
+ }
+ int value() const
+ {
+ return slider->value();
+ }
+
+signals:
+ void someSignal();
+ void valueChanged(int);
+ void textChanged(const QString&);
+
+public slots:
+ void setText( const QString &string )
+ {
+ if ( !requestPropertyChange( "text" ) )
+ return;
+
+ edit->blockSignals( true );
+ edit->setText( string );
+ edit->blockSignals( false );
+ emit someSignal();
+ emit textChanged( string );
+
+ propertyChanged( "text" );
+ }
+ void about()
+ {
+ QMessageBox::information( this, "About QSimpleAX", "This is a Qt widget, and this slot has been\n"
+ "called through ActiveX/OLE automation!" );
+ }
+ void setValue( int i )
+ {
+ if ( !requestPropertyChange( "value" ) )
+ return;
+ slider->blockSignals( true );
+ slider->setValue( i );
+ slider->blockSignals( false );
+ LCD->display( i );
+ emit valueChanged( i );
+
+ propertyChanged( "value" );
+ }
+
+private:
+ QSlider *slider;
+ QLCDNumber *LCD;
+ QLineEdit *edit;
+};
+
+//! [0]
+#include "main.moc"
+
+//! [1]
+QAXFACTORY_DEFAULT(QSimpleAX,
+ "{DF16845C-92CD-4AAB-A982-EB9840E74669}",
+ "{616F620B-91C5-4410-A74E-6B81C76FFFE0}",
+ "{E1816BBA-BF5D-4A31-9855-D6BA432055FF}",
+ "{EC08F8FC-2754-47AB-8EFE-56A54057F34E}",
+ "{A095BA0C-224F-4933-A458-2DD7F6B85D8F}")
+//! [1]
diff --git a/examples/activeqt/simple/simple.inf b/examples/activeqt/simple/simple.inf
new file mode 100644
index 0000000000..3657e9fb87
--- /dev/null
+++ b/examples/activeqt/simple/simple.inf
@@ -0,0 +1,11 @@
+//! [0]
+[version]
+ signature="$CHICAGO$"
+ AdvancedINF=2.0
+ [Add.Code]
+ simpleax.exe=simpleax.exe
+ [simpleax.exe]
+ file-win32-x86=thiscab
+ clsid={DF16845C-92CD-4AAB-A982-EB9840E74669}
+ RegisterServer=yes
+//! [0]
diff --git a/examples/activeqt/simple/simple.pro b/examples/activeqt/simple/simple.pro
new file mode 100644
index 0000000000..4d8480eebc
--- /dev/null
+++ b/examples/activeqt/simple/simple.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+TARGET = simpleax
+
+CONFIG += qt warn_off qaxserver
+
+SOURCES = main.cpp
+RC_FILE = $$QT_SOURCE_TREE/src/activeqt/control/qaxserver.rc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/simple
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS simple.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/simple
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/webbrowser/main.cpp b/examples/activeqt/webbrowser/main.cpp
new file mode 100644
index 0000000000..fe93eab8fa
--- /dev/null
+++ b/examples/activeqt/webbrowser/main.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMessageBox>
+#include <QProgressBar>
+#include <QStatusBar>
+#include <QMainWindow>
+#include <QAbstractEventDispatcher>
+
+#if defined(Q_OS_WINCE)
+#include "ui_wincemainwindow.h"
+#include <windows.h>
+#else
+#include "ui_mainwindow.h"
+#endif
+
+//! [0]
+class MainWindow : public QMainWindow, public Ui::MainWindow
+{
+ Q_OBJECT
+public:
+ MainWindow();
+
+public slots:
+ void on_WebBrowser_TitleChange(const QString &title);
+ void on_WebBrowser_ProgressChange(int a, int b);
+ void on_WebBrowser_CommandStateChange(int cmd, bool on);
+ void on_WebBrowser_BeforeNavigate();
+ void on_WebBrowser_NavigateComplete(QString);
+
+ void on_actionGo_triggered();
+ void on_actionNewWindow_triggered();
+ void on_actionAbout_triggered();
+ void on_actionAboutQt_triggered();
+ void on_actionFileClose_triggered();
+
+private:
+ QProgressBar *pb;
+};
+//! [0] //! [1]
+
+MainWindow::MainWindow()
+{
+ setupUi(this);
+
+ connect(addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger()));
+ connect(actionBack, SIGNAL(triggered()), WebBrowser, SLOT(GoBack()));
+ connect(actionForward, SIGNAL(triggered()), WebBrowser, SLOT(GoForward()));
+ connect(actionStop, SIGNAL(triggered()), WebBrowser, SLOT(Stop()));
+ connect(actionRefresh, SIGNAL(triggered()), WebBrowser, SLOT(Refresh()));
+ connect(actionHome, SIGNAL(triggered()), WebBrowser, SLOT(GoHome()));
+ connect(actionSearch, SIGNAL(triggered()), WebBrowser, SLOT(GoSearch()));
+
+ pb = new QProgressBar(statusBar());
+ pb->setTextVisible(false);
+ pb->hide();
+ statusBar()->addPermanentWidget(pb);
+
+ WebBrowser->dynamicCall("GoHome()");
+}
+
+//! [1] //! [2]
+void MainWindow::on_WebBrowser_TitleChange(const QString &title)
+{
+ setWindowTitle("Qt WebBrowser - " + title);
+}
+
+void MainWindow::on_WebBrowser_ProgressChange(int a, int b)
+{
+ if (a <= 0 || b <= 0) {
+ pb->hide();
+ return;
+ }
+ pb->show();
+ pb->setRange(0, b);
+ pb->setValue(a);
+}
+
+void MainWindow::on_WebBrowser_CommandStateChange(int cmd, bool on)
+{
+ switch (cmd) {
+ case 1:
+ actionForward->setEnabled(on);
+ break;
+ case 2:
+ actionBack->setEnabled(on);
+ break;
+ }
+}
+
+void MainWindow::on_WebBrowser_BeforeNavigate()
+{
+ actionStop->setEnabled(true);
+}
+
+void MainWindow::on_WebBrowser_NavigateComplete(QString)
+{
+ actionStop->setEnabled(false);
+}
+
+//! [2] //! [3]
+void MainWindow::on_actionGo_triggered()
+{
+ WebBrowser->dynamicCall("Navigate(const QString&)", addressEdit->text());
+}
+
+void MainWindow::on_actionNewWindow_triggered()
+{
+ MainWindow *window = new MainWindow;
+ window->show();
+ if (addressEdit->text().isEmpty())
+ return;
+ window->addressEdit->setText(addressEdit->text());
+ window->actionStop->setEnabled(true);
+ window->on_actionGo_triggered();
+}
+
+void MainWindow::on_actionAbout_triggered()
+{
+ QMessageBox::about(this, tr("About WebBrowser"),
+ tr("This Example has been created using the ActiveQt integration into Qt Designer.\n"
+ "It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX\n"
+ "control into a Qt application."));
+}
+
+void MainWindow::on_actionAboutQt_triggered()
+{
+ QMessageBox::aboutQt(this, tr("About Qt"));
+}
+
+void MainWindow::on_actionFileClose_triggered()
+{
+ close();
+}
+
+#include "main.moc"
+
+//! [3] //! [4]
+int main(int argc, char ** argv)
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+#if defined(Q_OS_WINCE)
+ w.showMaximized();
+#else
+ w.show();
+#endif
+ return a.exec();
+}
+//! [4]
diff --git a/examples/activeqt/webbrowser/mainwindow.ui b/examples/activeqt/webbrowser/mainwindow.ui
new file mode 100644
index 0000000000..12a0a328e6
--- /dev/null
+++ b/examples/activeqt/webbrowser/mainwindow.ui
@@ -0,0 +1,306 @@
+<ui version="4.0" stdsetdef="1" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="objectName" >
+ <string notr="true" >MainWindow</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>812</width>
+ <height>605</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Qt WebBrowser</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QHBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" >unnamed</string>
+ </property>
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QFrame" name="Frame3" >
+ <property name="objectName" >
+ <string notr="true" >Frame3</string>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" >unnamed</string>
+ </property>
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="WebAxWidget" name="WebBrowser" >
+ <property name="objectName" >
+ <string notr="true" >WebBrowser</string>
+ </property>
+ <property name="focusPolicy" >
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ <property name="control" >
+ <string>{8856F961-340A-11D0-A96B-00C04FD705A2}</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QToolBar" name="tbNavigate" >
+ <property name="objectName" >
+ <string notr="true" >tbNavigate</string>
+ </property>
+ <property name="windowTitle" >
+ <string>Navigation</string>
+ </property>
+ <addaction name="actionBack" />
+ <addaction name="actionForward" />
+ <addaction name="actionStop" />
+ <addaction name="actionRefresh" />
+ <addaction name="actionHome" />
+ <addaction name="separator" />
+ <addaction name="actionSearch" />
+ </widget>
+ <widget class="QToolBar" name="tbAddress" >
+ <property name="objectName" >
+ <string notr="true" >tbAddress</string>
+ </property>
+ <property name="windowTitle" >
+ <string>Address</string>
+ </property>
+ <widget class="QLabel" name="lblAddress" >
+ <property name="objectName" >
+ <string notr="true" >lblAddress</string>
+ </property>
+ <property name="text" >
+ <string>Address</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="addressEdit" >
+ <property name="objectName" >
+ <string notr="true" >addressEdit</string>
+ </property>
+ </widget>
+ <addaction name="actionGo" />
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="objectName" >
+ <string notr="true" >menubar</string>
+ </property>
+ <widget class="QMenu" name="PopupMenu" >
+ <property name="objectName" >
+ <string notr="true" >PopupMenu</string>
+ </property>
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <widget class="QMenu" name="FileNewGroup_2" >
+ <property name="objectName" >
+ <string notr="true" >FileNewGroup_2</string>
+ </property>
+ <property name="title" >
+ <string>New</string>
+ </property>
+ <addaction name="actionNewWindow" />
+ </widget>
+ <addaction name="FileNewGroup" />
+ <addaction name="FileNewGroup_2" />
+ <addaction name="separator" />
+ <addaction name="actionFileClose" />
+ </widget>
+ <widget class="QMenu" name="unnamed" >
+ <property name="objectName" >
+ <string notr="true" >unnamed</string>
+ </property>
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="actionAbout" />
+ <addaction name="actionAboutQt" />
+ </widget>
+ <addaction name="PopupMenu" />
+ <addaction name="unnamed" />
+ </widget>
+ <action name="actionGo" >
+ <property name="objectName" >
+ <string>actionGo</string>
+ </property>
+ <property name="icon" >
+ <iconset>image0</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Go</string>
+ </property>
+ </action>
+ <action name="actionBack" >
+ <property name="objectName" >
+ <string>actionBack</string>
+ </property>
+ <property name="icon" >
+ <iconset>image1</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Back</string>
+ </property>
+ <property name="shortcut" >
+ <string>Backspace</string>
+ </property>
+ </action>
+ <action name="actionForward" >
+ <property name="objectName" >
+ <string>actionForward</string>
+ </property>
+ <property name="icon" >
+ <iconset>image2</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Forward</string>
+ </property>
+ </action>
+ <action name="actionStop" >
+ <property name="objectName" >
+ <string>actionStop</string>
+ </property>
+ <property name="icon" >
+ <iconset>image3</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Stop</string>
+ </property>
+ </action>
+ <action name="actionRefresh" >
+ <property name="objectName" >
+ <string>actionRefresh</string>
+ </property>
+ <property name="icon" >
+ <iconset>image4</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Refresh</string>
+ </property>
+ </action>
+ <action name="actionHome" >
+ <property name="objectName" >
+ <string>actionHome</string>
+ </property>
+ <property name="icon" >
+ <iconset>image5</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Home</string>
+ </property>
+ </action>
+ <action name="actionFileClose" >
+ <property name="objectName" >
+ <string>actionFileClose</string>
+ </property>
+ <property name="iconText" >
+ <string>Close</string>
+ </property>
+ <property name="text" >
+ <string>C&amp;lose</string>
+ </property>
+ </action>
+ <action name="actionSearch" >
+ <property name="objectName" >
+ <string>actionSearch</string>
+ </property>
+ <property name="icon" >
+ <iconset>image6</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Search</string>
+ </property>
+ </action>
+ <action name="actionAbout" >
+ <property name="objectName" >
+ <string>actionAbout</string>
+ </property>
+ <property name="iconText" >
+ <string>About</string>
+ </property>
+ </action>
+ <action name="actionAboutQt" >
+ <property name="objectName" >
+ <string>actionAboutQt</string>
+ </property>
+ <property name="iconText" >
+ <string>About Qt</string>
+ </property>
+ </action>
+ <actiongroup name="FileNewGroup" >
+ <action name="actionNewWindow" >
+ <property name="objectName" >
+ <string>actionNewWindow</string>
+ </property>
+ <property name="iconText" >
+ <string>Window</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+N</string>
+ </property>
+ </action>
+ <property name="objectName" >
+ <string>FileNewGroup</string>
+ </property>
+ </actiongroup>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>WebAxWidget</class>
+ <extends>QAxWidget</extends>
+ <header>webaxwidget.h</header>
+ </customwidget>
+ </customwidgets>
+ <connections>
+ <connection>
+ <sender>addressEdit</sender>
+ <signal>returnPressed()</signal>
+ <receiver>actionGo</receiver>
+ <slot>trigger()</slot>
+ </connection>
+ </connections>
+ <layoutdefault spacing="6" margin="11" />
+ <images>
+ <image name="image0" >
+ <data format="XPM.GZ" length="1241" >789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232365200210543251d2e253d856405bffcbc54103b11c8563600020b03105719c4b530b08072f50880513560a09c080338d5209420294a4451a38c90426621ab5146d10de524a2aa417505445122861a547722bb0c971a3d2aa921c2ae446c6a9431fc85a9064551220e354009653dec00294e712a1ac4e97078a9a9b5e6020013b3f563</data>
+ </image>
+ <image name="image1" >
+ <data format="XPM.GZ" length="4494" >789ce596497332470c86effe15947573a5f4c1cc30cc542a07ef60bc808dd7540e3d9b6df006186c93ca7f8fba2535ce57be98dc9292313c487a2575f7ccf063a376d53baa6dfc589bbe9ad7fbbc96df99496da3983d3e7efcfec76f7faead87418dfe1a51500bd67f595befbfd6f2daf1f35369014e08a05e6fd4ab96e31e73d0282bc7a7cae23ff3ccfe8170ca6cee9843f51f3b4ec8cff9efccdebf2d2cf9b06bb9417a25c74f98bdff99390a84fb8e49af70f39891b2e40bfbf8b6b0917e87968346a8f5a6cc51c07ab02f2cf1983237552f709c86691e3bbd5be5821998a32067bd1765d13f67563d530a4b3df8b01c523d8ec74059faed086bfc82390e851b8ed3c86485e34365a9bfc5ece3df8433e10bcb5140f5dd3cf0e099f32f99e350cecb5858f2b1c1dc52fda663d334a277c0ecfd5d61c9373973120967969b548fd71b079e797d8e985b21eb63aecceb85e7c299f4ffaa2ce7739359ebc195631387c6ad1f5e302791ccbba72cf173e15cfa2d2cc7619cf1fa63c9dccaa4ff4bcfdc7fa82cfdf7999348f6bf299c4bfd4c59ea0f99535dafca71d60a65ffebca52ff8c3989e47cce98351fb785759e7bcbad65bf0be624ca9a8e87caac0fb1702ef191b2cc9731a7b9ec4f87d934659e27e142f8c671e6eb9d0ae7b2be07cc6924ccf999698a7e4f58f572e64cebb9f393444994e68e4365d9ff7be15caef70766ad678cb0f8f18359ebe109b3af27f199fadd794cf254eb196599774758e77d5496f5dd64a67959af122ef87c639b59eb81d34ba97fe3f4215196f3922acbbc28acf527cc792c7a857029ecf63bcded05efb8a52cf3cc9833ed2f66563dac0b8b1ebe3317ea77f73352173db8f6ccf54a66df0f30fb7c777d9bc214d2cf88d9cf73cfece3ddf3296b66da7fe199d7a32b5cc8feef31fbfe8f99bdde96b0faddf3272bac390665b99e90d9e7ef33972de9d73d7ff3d873255c49fc1b73257ee4f8d2eb5d336b3e8e8535ff86d9e7bbf35f2cf51366ef77cfeb6299df62563f3c0a8b1fdcf3d3569778773f756e66f7fcac967e175f797ffff5dfd9ff4103010d6698a35955030b2cb1c25bbcc3fbd5344861882352b8c5077c5c45836678c267ca7fc1314ebeaf81537cc599eb608e6ff88e1f2b682c705314b6486182dbb8f31d0ddca529f644619ff2db641d3cf82a8bfa9d62d7da670d3cc4233c760a63eaa08d2734478fac8f87ffc833788a6738c073bc20ebe3255eb1069d863e5e3b851bacfb7c6b0d0c30c488f24a3a2d4ddaf1986a3d600b13179be280ef597809e876e206000c69d8ec0e590f32c8a18012b7a0825b9799e018eee0de4e0b4318c103ff2ea2985b78c47d28a487ce276b634cca40356d1655801c3bf044af2136e0195ef8b711be4045ab50ff42e16bdbb6463d8e610253fe3d4855ec3ed80abd9f62397ef9c9e6cee835249bc31bbc731ff0010beacbcdbfaca29f2836a3e839fd1f3acb5cb6fd6e13b6605b34766097d6664cdf0d7faad9813dd827df08daf4de812ddaa7061c4017baf43ea6daef70c8fb0247704c932dc897b94e67da09553a811ef4a94a0f4ee10c069435216b630ae7a43b800b7fc6164ea543ea73ea75663b22a50e5cc215ec50956beaf606ead08080147b64c76403d20ebdc6142268528d3655ee3a1db6f88b535ee015b42081d4205ee1f4f335878501ea7644331dc81acecdb7ef63b86b32eae59956cff63237f92af7319c9a82669c989256bd0b6fa6fabe86bbfe0ecdadb9a399ce61b49a86355adfbedd45736756bc27b30afd161a9a9179585de33bf69fd2f8ebd7b5bf014644b906</data>
+ </image>
+ <image name="image2" >
+ <data format="XPM.GZ" length="4494" >789ce5965b4f23471085dff915d6d6db2aaac5e3b92aca037703cbc55c8c21ca43cf8c8d0dd85c6c307694ff9eeaaed3bd68771f968d14298a0a109fabebd4e99a9ef17cfad8e81d1f343e7e5a99cecc6c5435aaa1796a7cac9fc7e3c5ef7ffcf6e7ca8756d4909f661c35a20fbfac7ce8cc1a55e3f07ed2b7409702b4badaccfb996563020f5c7ecbf340b9a31c3591dff7ac7943e002cc8e73cf74acdcc27a8a2d37a5be4e1d9f04567f9fc105f25dcfea9726caad62a07c1158f58f94e3087e868ea57fa5fa0be590bfb11c3525affd4e03ebfa25b8507fbcaa1c47ca66e459fdf10c6c30af4dcfda8f5f9513dfffce71e1f5a956967adddfaeb25f4f7b60e8d199e596f42f6bc787ca213f554e5be06dc7a28ffdee282791cedb5c83d19fd795a55ecf4b3fb0ee07ebd312fae796e3283665e238524e2265de031bcc774d396d61be25b8c4fe1f02abfeab67f49f2867decfbd6393b6a03f03438f3bca19fa51cb33fc6f80fd7eae2c27e257e7cb4de5b4045f78d679f24960ddcfb172e6f73357ce63e88fc115ce43e558fcabbeb905fb7e47cae24ff5daca41af007bbd81e5b425f53aff6160d52f95f318f37d01a39ee7ca05f4790a469e0e1c97590bfa1b81f53c3e2bfbf5ecf697b532efe754398f31af437085eb65948b18e723f70cbf9e2bcc633db0f65b533609fcbafb372bf318fdcfc015e65b281731ee0ff6acf70767ca5e8f7be01abcab5cfa7e89e53cce2ba3fd1681b5df8172013f44e00acfbf4a39e8ef287b7dbe02234feefce795d727a36c12ccf75239d4b7c1bede9def42fcc0ef7960d5cbc05ebf543635aed752b94aa1ff02ee83ddf3b6a87c3d3f2b9b047a4fcaa17e0cf6f5eef928ab13f5476960d5eb7ac6f5dd07d7e04839e83d29d7be9ffbfe31b50dc723cfa87f08acf947e51a7ad457ee6760773ecaa4f47e36036bfd96673c3fb6c13578a01cf41f9505d5af3b2f655dc28fa93da33e550ef523e5e06f08861eb9e7b94cdfe7ddf753d50feb6f94437e00f67edcf3aa4e831ed8afe73bb05fefe655f7c37edcfd62bb81ddfb82935776cfeb41c87766ff2cfe7f1a4c6cb8e48ae91f68d4dce7015ff390473fad71c3b77cc7639ef03d3ffcb48f013ff293a84c79c6d54f693c8bc28b28589539bff2e2ed647e586389184bacf13a6ff0e6d71a32f92dde96bfdf9dbccc6387dba2d086caae4c668ff7bf68f0673ee0433ee263eef0099ff2199f8b62d0e32e5f704fea2fe5b70d3f57729556b91b349a1c718b634e64faa9fc7fc919e772220a91213254ca273b884bf72b4a54f1846ad925e93b1af56940d734a4110fe4efb5c40dddda907311734c7752d10b3a1ae289c634a17b7dafe331e995b3b124fbdfd25d85471763596fab7aa2a4f53d444653ded3773bb96e8faeae1de2ea8dff9da0b0ebfcd858e3357aa667bb1f68b4a5e7d256853559e8f56d64aefe85e6f44a0b5aea3bac5c2bebf74b8775fb6bfbb858771e7a6f1df09c36f89a36698bb6f53d5c4ef08ee4e6a2dd269b9d488729ed4a171b7bd40ece3228cce5d305edd3673ed7773139bd133a14d5233a96cff7a9237142a77446e7125dba900e70681564f5a6acdc1285ae9e0feaf150d675e8d2d59dd315ad52931fec2973d1a5489c6698e29c5a508829797bd629a52665bcf9fdd32ed95c1d50217b5c18b67390f34befb8e78873a9b6b39ad285216328a2de3bef5b32a59db5ccec42a6b565aaf7dffba6e663d3972b211ea86b065f3cbccbc7b53890399a21a55f677f5863e4f670c337df667f58e3d6dc99dbef3dd5ff6bdf73ff82c65fbfaefc0d4fb5b868</data>
+ </image>
+ <image name="image3" >
+ <data format="XPM.GZ" length="802" >789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232325500210543251d2e25658564056503300071f540dc3430007371012a492a830156496538c094848922c9c2259134c099304914e3604c8424aa5e6449b0044216ca824ba2da8b4512218b4d122e8b55520fee5974072164511da487ea490c7f22cba249e20d3efc018f3fcae0d2702eb5d2106992b5d65c00b9a48974</data>
+ </image>
+ <image name="image4" >
+ <data format="XPM.GZ" length="1241" >789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232365200210543251d2e253d856405bffcbc54105b19c8563600020b03103711c4b530b08072f50880513524ab518681443435ca984ae08ae06a94114a10ac443435ca3043904d4c4453a38ca604ae11590d9a0ab80bd0d46078914c35c4d885a608871a547f61f81d5d117a1862018930e5b8d5c0950c741a1b1e6a6aadb90086a9d853</data>
+ </image>
+ <image name="image5" >
+ <data format="XPM.GZ" length="5598" >789ca5985973db480ec7dff3295cc15b6a0b2351a428d6d63ef83e255bbe647b6a1fd02465dd872d9f53f3dd076c005dc926ce6a32eed8553f37fadf7fa0c1a69cdfbe6cdc9cb537befcf6e97145ab61be910fe861e34bf1349dbefdfedffffcf1e97323dae07f51bdbe117dfed7a7cfddd546bed199cfca0ae888016afeab62e8796ef110ee545caf05be16ae5bfc6ee096e7b6e756983f51b6f53b81257ecfb8eee7e9b162f66af1c78125fe48987f23f3fb81657e691cd5bddecc7316d555efd058f7eb2867aa771058f4de8c55cffb6dd4a34cf5b68d357e681c6515634db81a7e3ef59c35cccf5560bf9ef6953389c77660af074f15c751e05c38a6d81f2ef9f3a848f4e9d658f2c36b635dbfa54cc2383556bd33e12492fc70df38f1f3f8ae4cc2745a711285fda7caa4f95e06967a2d8c63f27a8fc2a60fa4acfa980a371b898f0767dc6cf8fdbc9f84c27e4de124d2fabe186b3dee8c75ff1365dbef2db0ccef0987fd2f2a6632fd576552fd2b63d57b08ecd7d39d70b321fd0560acfb6d1a4b7e3050764de7d79f08a70de937ea7b7689e68f4de1e0776e2c7ab8abecb47eb170aa7ee822b0e89f1b4b7fd24dc529abe9794f02cbf99e2b3badc7a5b1ee97089b3e0e8d253f3c364e253e5576120ff7c63a9f7966d2e771d358e75bca4ef3bb0e2cf9758db5fe47c6b21eeb81bd3f07c2ad58ebd130d67e6a194b3cf97e62b2fa24c67a1f5d2aab3f8781a53e17c6eaa7082cfa3de156acf9d5034b7e3563f1eb96c6eaf7c0b815fbf8d2739e3aedefb1b1de9723618b77a49cebf946c6e20f5f8d251e753e8b5bb9e74c980a4afc7a7fbf66b1ed8fb7c67a9ec7c2ad5cfd74038bdfa6b1f6cbd458fd2e84b358efbb0363f5b71358fccd8c33596f9c4bfddcc458fac78d8cf5797b3296f5f82c4c49e6f5c9bf9fb23ce41307967e3935d6f36c0b67b1ce3f188b5f3757367f5363b98fdc38b0cc0f8cf5f90bf3ea97028bfe50981289777d63edcf81b1c4439897f3c52d615738cfe0df371c1deb7db265acf98d8d253f7a50d67a60c758cfcbf4cc7f2fb0f8bf1736bfae30d6f35f1a4b3ce6c6e2df95ca85f6f7dc58f3db0e5c783e14e6ebc533e87e963fbe0873f9fd3cc97c91693fd028b0d4e3c558f3eb0b9b5f972bab3fe78c353f3056bfabc0e2371636bfe4cf9b29d1e76b69acfdb863accfd33cb0dc2fa7c6e2179e03cb79ae940b7dffbf1b6bfd1363f53b12367f581a6b3d1bca56df6e60a9bfc6e765def4ecef6bc7eafaf9e8d558fbb7a15ce87d7263acf7ffbdb1e40f33e1e0cf29ebfea8eb6d7ff29f17f8f4137dfe51d8fa0117ca65ee3fbfe3bd705116b2de9f775e3af50313e1a229f1f0682cf1b052e6e1d9dfbf1cddd4fd2363cdcfef5fb05b7d1f0c944bed4f67ac9f5f27c265bf4c3d9f07eefb787f1f96695eaa1e0a174d7d7f81b1ee4f81a5fe75e552d9bf1fca7e617e9e8d556f33b0c4fbcf5ffdb44c956bc6a2d75dfd6c2020fd3ce2ff69a0c31c0b2cff91461fef71804374bfaa81231ce3044b9ce2ecd734380fc2392e70890ff888bfa6f184cff8c24e5ef10ddf71f3a37c3ed6c015afdec26dfeb983bbb887fb78f0f734380fe031c7437f3247788c27d8fe713e1f6a1076f014cfb08be7ac7481977885d75c951fe4f3630dcea3c3eb7b9cc70d6b9ce12d9fee26de610debeb69b0fb578cb89a0d8c399711e794609373d9c39455f2b53466d8c20c17809c45cc7a3c00f011081cffccff379fef35388f1d0428a0c401f459e58c3d45700f0003cee71d8678fc730d7430e2557d3c8331f7568c37308129cc7006733e9d262c6008cb6ff3f94ea3c72bc678ca3f1fb80a637884154c71c974c55d72c91a4feca4fdf553f8ad46554d8e9ee30a9eb1efab31611f2ff0ca346427bb9c11e114debe7e7ebed328318702e7f0ce9dbee47a1c724655b745b0c94ea6b0c55519f059b98f73d19a6cc30eecc21eecfb7100877004c770026de8e070bdfe805338832e9cc3055cc2955f7b0d3de8f0cfebb5356ee016eea0c6a30e11342086049a907aadcd35355a90111250f5e5288706bfdb4bea572a78b49e06ddd3a0d2807a2502110d6944639ad09466ebf9e8ae684e0bf5b1a4075ab28f11ffa1df678dc7f57cb0c68a9ee899355e7c2ddbf40a31bdb1c63bcdfe86c6803669cb9f4555c76b38a76dcee57d5d1f5c8f1d5af0b9745581bb029a5c8f3eedd21eed73b70ebe56fa91061dd061f05139e9d1116b1cfb9aee55c4fcf6330d5cd289d778a6b65fdd831dea702e256b9cf2b974a84367d4fd580347744e17744957acc13e7cfc095d538f356ed8cd2ddd518dea147da4c1956890ffcf295ed5e4c83b4a59f182b9455935e3b801ab791c7fa4e188d7a4bcbee66353feaef9df8852ca2f3e9ee3ef73840f359cabfec22979f4ddbd1bf018ba118f318f899bf298b9b95bb8e537cffe9ffffef4171c39a0bf</data>
+ </image>
+ <image name="image6" >
+ <data format="XPM.GZ" length="3742" >789c8d96c9521c490c86ef3c458775734cc8ddd5b5c6c41c303b180cc60b66620eaacc2c9aa5599b7562de7da45fc5180c8e98fa39f091522e4a49c9bbb783bdedcdc1db77735733991d864198c8e5e06dbc9e4eeffffceb8fbfe7de64d9407f466531c8defc36f76667360883adb3d364c013051ae2039f8147266359068f4dc6740a2e4db05f05d726f0253898c017c6a3cc04ffafce79aa3af0143c36c17e055caa0aacbf06aeb2203e5f09ae4d185f75ce472de6e7737063c2fcb57356b702fed673e32c473d4bcf3760198f02e69325706b022f3a676df0f567e05035d1ed273dc79883e7c1d1045e70ae2456d84fd9738a589f0b703261bc72ae25e17ee4b0e7d8f3b5733374e603e32c37c11ff36970db12f193f7e07c1c6bec87c6e0c604ff0e1c4db03f36cec7e3a6f4fd2e38e779eee7bd05e7e350fa7e4fc0455ee6b84fb9eab913bfdf1c5ce5758efba54fffb1e75302d726f8af3817a5f8f922584cf06fc0211f951ebfd0b30afe07ce4510dfdf1e38e665e9f9f1e01c32cf1fda06a73c2f7c7eac5f8c8b61eef582f315b909dc82f1c17e07dc1459e5f1c77d953abb787e0ab832611cf957366dd9c707f556762a3fcf8673ddd6d8afdc1957b909fe98af2a65d4c787c08d09e3c8bfaad504f378de83a309e35fc049d9d747bda19c7dbe8f602d88d6fd11af3a33c1ffde398e02ec69178c0b04bb7fa12be03e08e7ab4b895e2f74ec1ca2e73f6d811b2d37df1feaa9969082f71ff4a73a98c01f9cdb3678fde27eea58f7f9cdc8bfba33c11efda2199ac01bcead048fd72678a4e9e3f6a86f6d172acc87fc69f290f9386f3d72f478a1bf348509fea8b7a66c9b80fec1a8b7a66a53f47cc2fe9b5ae77346fe35ad09e761703081d12f9b68c2fc57ce6d0c1e6fe463934ce0efc63234c11ffd5b4a13c66f9cb53d79fded832bcd27f47f5aeb59055e744eb1df3fe2251aeee4e7453f9264c27aa847b44f7f4f909fda3efb7ae30c5c84b65f1fef435b9a608ff7a4ad4c981ffb6b6b13d8fda5edfb37eff4dcb65e2f787f5a7cb0f7fd0413ecf13eb49d09f6783ff07cf97d8ec0a3f8d8df516f483faf07c45b1f27e9f30ff989e9fdbe11ff1034fd3c9eebe068c238fa9f6677f2fb27ac1f475dd3f97da25fc6c204be755673ef3f8db3360c1f1f824b13c651df2877c44fd0df511efe5ea39f44318151cf9a4e2ab0af870d63fee4dc55fdfe109f880ff3fb788a8ff98df733762630fa471aa6febda2839e5b3f0fe1bef4f18bc9fb01fa7dca4ce0bb9e5b671ef69c3cff18f99cc626d853cf551f3fe453ca531bbdde979cbb2c793e207f536102a39fa5ca0446bf4279f97b89feaabb5181511f38bedf2ffa47373461bdcfe0dc8471d46387860fc6fbaad155c11ef7a5d953747ede69cf2a30fe3fd06c5121fe88572726f8a37f68720ffbfdadf7ac02fb7e82098c7e85ebf2fde37dea92098cf7acc367bc33fbff7a6ecfc4c22d078eaac41d1ff0e4d7f66a7df84293e71ecfec858f9ee8d1fef8a9c733fb139ef2299ff1395ff0255fc167c233befee1f1cc3ef10ddff21ddff303cfabe77bd584177891971e3d7ed8db4e7b2df30aaff29a7aac3ff9ebe4a9bdf2067fe04ddee28ffafb36eff027de558fcfbaab2ffc95bf3db5578b3dfecefb3ce411673c56ceb9e0b23f47a5fbac7fb26f889988742f2a129e504b81a246e0c8ec293cb7a7441d0b1dd0840ee9883486744253bea4533a7bd5fe9c2ed4feb29fff4aff32a36b8dd5e92fe6bfa15bddcf1dddd303cd93c6911668aa2b5cbc363f3c16799f9630fbb2d20aadd21aadeb3d547a8617f6f0d8a00fb4495bfadb47daa61dfa84f977e933c597f64f6e6c9fbed057fa467bf49df669c8bb34a2eca53d8d35576ef88e722aa8a48a6a6a448320a20fd36bf3eb7f407c2c89efb5500f6422877224c77222533915e6b397fbd117f54ccee54275295732936bb9915bb9937b797869ff34e7649ecfe4bd2ce81a8bbc2a4bb2fc5a3dfe2c59915559fb75fdfe8f7affe7f7b97f011cdd9635</data>
+ </image>
+ </images>
+</ui>
diff --git a/examples/activeqt/webbrowser/webaxwidget.h b/examples/activeqt/webbrowser/webaxwidget.h
new file mode 100644
index 0000000000..0e82311f33
--- /dev/null
+++ b/examples/activeqt/webbrowser/webaxwidget.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WEBAXWIDGET_H
+#define WEBAXWIDGET_H
+
+#include <ActiveQt/QAxWidget>
+#include "windows.h"
+
+class WebAxWidget : public QAxWidget
+{
+public:
+
+ WebAxWidget(QWidget* parent = 0, Qt::WindowFlags f = 0)
+ : QAxWidget(parent, f)
+ {
+ }
+protected:
+ virtual bool translateKeyEvent(int message, int keycode) const
+ {
+ if (message >= WM_KEYFIRST && message <= WM_KEYLAST)
+ return true;
+ else
+ return QAxWidget::translateKeyEvent(message, keycode);
+ }
+
+};
+
+#endif // WEBAXWIDGET_H
diff --git a/examples/activeqt/webbrowser/webbrowser.pro b/examples/activeqt/webbrowser/webbrowser.pro
new file mode 100644
index 0000000000..d6566cb64c
--- /dev/null
+++ b/examples/activeqt/webbrowser/webbrowser.pro
@@ -0,0 +1,19 @@
+TEMPLATE = app
+
+CONFIG += qaxcontainer
+
+QTDIR_build:REQUIRES = shared
+
+HEADERS = webaxwidget.h
+SOURCES = main.cpp
+FORMS = mainwindow.ui
+wince*: FORMS = wincemainwindow.ui
+
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/webbrowser
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS webbrowser.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/webbrowser
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/webbrowser/wincemainwindow.ui b/examples/activeqt/webbrowser/wincemainwindow.ui
new file mode 100644
index 0000000000..98a9ddb715
--- /dev/null
+++ b/examples/activeqt/webbrowser/wincemainwindow.ui
@@ -0,0 +1,299 @@
+<ui version="4.0" stdsetdef="1" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="objectName" >
+ <string notr="true" >MainWindow</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>812</width>
+ <height>605</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Qt WebBrowser</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QHBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" >unnamed</string>
+ </property>
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QFrame" name="Frame3" >
+ <property name="objectName" >
+ <string notr="true" >Frame3</string>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" >unnamed</string>
+ </property>
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QAxWidget" name="WebBrowser" >
+ <property name="objectName" >
+ <string notr="true" >WebBrowser</string>
+ </property>
+ <property name="focusPolicy" >
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ <property name="control" >
+ <string>{F5AFC7EF-1571-48B6-A69C-F1833F4C3A44}</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QToolBar" name="tbNavigate" >
+ <property name="objectName" >
+ <string notr="true" >tbNavigate</string>
+ </property>
+ <property name="windowTitle" >
+ <string>Navigation</string>
+ </property>
+ <addaction name="actionBack" />
+ <addaction name="actionForward" />
+ <addaction name="actionStop" />
+ <addaction name="actionRefresh" />
+ <addaction name="actionHome" />
+ <addaction name="separator" />
+ <addaction name="actionSearch" />
+ </widget>
+ <widget class="QToolBar" name="tbAddress" >
+ <property name="objectName" >
+ <string notr="true" >tbAddress</string>
+ </property>
+ <property name="windowTitle" >
+ <string>Address</string>
+ </property>
+ <widget class="QLabel" name="lblAddress" >
+ <property name="objectName" >
+ <string notr="true" >lblAddress</string>
+ </property>
+ <property name="text" >
+ <string>Address</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="addressEdit" >
+ <property name="objectName" >
+ <string notr="true" >addressEdit</string>
+ </property>
+ </widget>
+ <addaction name="actionGo" />
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="objectName" >
+ <string notr="true" >menubar</string>
+ </property>
+ <widget class="QMenu" name="PopupMenu" >
+ <property name="objectName" >
+ <string notr="true" >PopupMenu</string>
+ </property>
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <widget class="QMenu" name="FileNewGroup_2" >
+ <property name="objectName" >
+ <string notr="true" >FileNewGroup_2</string>
+ </property>
+ <property name="title" >
+ <string>New</string>
+ </property>
+ <addaction name="actionNewWindow" />
+ </widget>
+ <addaction name="FileNewGroup" />
+ <addaction name="FileNewGroup_2" />
+ <addaction name="separator" />
+ <addaction name="actionFileClose" />
+ </widget>
+ <widget class="QMenu" name="unnamed" >
+ <property name="objectName" >
+ <string notr="true" >unnamed</string>
+ </property>
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="actionAbout" />
+ <addaction name="actionAboutQt" />
+ </widget>
+ <addaction name="PopupMenu" />
+ <addaction name="unnamed" />
+ </widget>
+ <action name="actionGo" >
+ <property name="objectName" >
+ <string>actionGo</string>
+ </property>
+ <property name="icon" >
+ <iconset>image0</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Go</string>
+ </property>
+ </action>
+ <action name="actionBack" >
+ <property name="objectName" >
+ <string>actionBack</string>
+ </property>
+ <property name="icon" >
+ <iconset>image1</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Back</string>
+ </property>
+ <property name="shortcut" >
+ <string>Backspace</string>
+ </property>
+ </action>
+ <action name="actionForward" >
+ <property name="objectName" >
+ <string>actionForward</string>
+ </property>
+ <property name="icon" >
+ <iconset>image2</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Forward</string>
+ </property>
+ </action>
+ <action name="actionStop" >
+ <property name="objectName" >
+ <string>actionStop</string>
+ </property>
+ <property name="icon" >
+ <iconset>image3</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Stop</string>
+ </property>
+ </action>
+ <action name="actionRefresh" >
+ <property name="objectName" >
+ <string>actionRefresh</string>
+ </property>
+ <property name="icon" >
+ <iconset>image4</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Refresh</string>
+ </property>
+ </action>
+ <action name="actionHome" >
+ <property name="objectName" >
+ <string>actionHome</string>
+ </property>
+ <property name="icon" >
+ <iconset>image5</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Home</string>
+ </property>
+ </action>
+ <action name="actionFileClose" >
+ <property name="objectName" >
+ <string>actionFileClose</string>
+ </property>
+ <property name="iconText" >
+ <string>Close</string>
+ </property>
+ <property name="text" >
+ <string>C&amp;lose</string>
+ </property>
+ </action>
+ <action name="actionSearch" >
+ <property name="objectName" >
+ <string>actionSearch</string>
+ </property>
+ <property name="icon" >
+ <iconset>image6</iconset>
+ </property>
+ <property name="iconText" >
+ <string>Search</string>
+ </property>
+ </action>
+ <action name="actionAbout" >
+ <property name="objectName" >
+ <string>actionAbout</string>
+ </property>
+ <property name="iconText" >
+ <string>About</string>
+ </property>
+ </action>
+ <action name="actionAboutQt" >
+ <property name="objectName" >
+ <string>actionAboutQt</string>
+ </property>
+ <property name="iconText" >
+ <string>About Qt</string>
+ </property>
+ </action>
+ <actiongroup name="FileNewGroup" >
+ <action name="actionNewWindow" >
+ <property name="objectName" >
+ <string>actionNewWindow</string>
+ </property>
+ <property name="iconText" >
+ <string>Window</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+N</string>
+ </property>
+ </action>
+ <property name="objectName" >
+ <string>FileNewGroup</string>
+ </property>
+ </actiongroup>
+ </widget>
+ <connections>
+ <connection>
+ <sender>addressEdit</sender>
+ <signal>returnPressed()</signal>
+ <receiver>actionGo</receiver>
+ <slot>trigger()</slot>
+ </connection>
+ </connections>
+ <layoutdefault spacing="6" margin="11" />
+ <images>
+ <image name="image0" >
+ <data format="XPM.GZ" length="1241" >789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232365200210543251d2e253d856405bffcbc54103b11c8563600020b03105719c4b530b08072f50880513560a09c080338d5209420294a4451a38c90426621ab5146d10de524a2aa417505445122861a547722bb0c971a3d2aa921c2ae446c6a9431fc85a9064551220e354009653dec00294e712a1ac4e97078a9a9b5e6020013b3f563</data>
+ </image>
+ <image name="image1" >
+ <data format="XPM.GZ" length="4494" >789ce596497332470c86effe15947573a5f4c1cc30cc542a07ef60bc808dd7540e3d9b6df006186c93ca7f8fba2535ce57be98dc9292313c487a2575f7ccf063a376d53baa6dfc589bbe9ad7fbbc96df99496da3983d3e7efcfec76f7faead87418dfe1a51500bd67f595befbfd6f2daf1f35369014e08a05e6fd4ab96e31e73d0282bc7a7cae23ff3ccfe8170ca6cee9843f51f3b4ec8cff9efccdebf2d2cf9b06bb9417a25c74f98bdff99390a84fb8e49af70f39891b2e40bfbf8b6b0917e87968346a8f5a6cc51c07ab02f2cf1983237552f709c86691e3bbd5be5821998a32067bd1765d13f67563d530a4b3df8b01c523d8ec74059faed086bfc82390e851b8ed3c86485e34365a9bfc5ece3df8433e10bcb5140f5dd3cf0e099f32f99e350cecb5858f2b1c1dc52fda663d334a277c0ecfd5d61c9373973120967969b548fd71b079e797d8e985b21eb63aecceb85e7c299f4ffaa2ce7739359ebc195631387c6ad1f5e302791ccbba72cf173e15cfa2d2cc7619cf1fa63c9dccaa4ff4bcfdc7fa82cfdf7999348f6bf299c4bfd4c59ea0f99535dafca71d60a65ffebca52ff8c3989e47cce98351fb785759e7bcbad65bf0be624ca9a8e87caac0fb1702ef191b2cc9731a7b9ec4f87d934659e27e142f8c671e6eb9d0ae7b2be07cc6924ccf999698a7e4f58f572e64cebb9f393444994e68e4365d9ff7be15caef70766ad678cb0f8f18359ebe109b3af27f199fadd794cf254eb196599774758e77d5496f5dd64a67959af122ef87c639b59eb81d34ba97fe3f4215196f3922acbbc28acf527cc792c7a857029ecf63bcded05efb8a52cf3cc9833ed2f66563dac0b8b1ebe3317ea77f73352173db8f6ccf54a66df0f30fb7c777d9bc214d2cf88d9cf73cfece3ddf3296b66da7fe199d7a32b5cc8feef31fbfe8f99bdde96b0faddf3272bac390665b99e90d9e7ef33972de9d73d7ff3d873255c49fc1b73257ee4f8d2eb5d336b3e8e8535ff86d9e7bbf35f2cf51366ef77cfeb6299df62563f3c0a8b1fdcf3d3569778773f756e66f7fcac967e175f797ffff5dfd9ff4103010d6698a35955030b2cb1c25bbcc3fbd5344861882352b8c5077c5c45836678c267ca7fc1314ebeaf81537cc599eb608e6ff88e1f2b682c705314b6486182dbb8f31d0ddca529f644619ff2db641d3cf82a8bfa9d62d7da670d3cc4233c760a63eaa08d2734478fac8f87ffc833788a6738c073bc20ebe3255eb1069d863e5e3b851bacfb7c6b0d0c30c488f24a3a2d4ddaf1986a3d600b13179be280ef597809e876e206000c69d8ec0e590f32c8a18012b7a0825b9799e018eee0de4e0b4318c103ff2ea2985b78c47d28a487ce276b634cca40356d1655801c3bf044af2136e0195ef8b711be4045ab50ff42e16bdbb6463d8e610253fe3d4855ec3ed80abd9f62397ef9c9e6cee835249bc31bbc731ff0010beacbcdbfaca29f2836a3e839fd1f3acb5cb6fd6e13b6605b34766097d6664cdf0d7faad9813dd827df08daf4de812ddaa7061c4017baf43ea6daef70c8fb0247704c932dc897b94e67da09553a811ef4a94a0f4ee10c069435216b630ae7a43b800b7fc6164ea543ea73ea75663b22a50e5cc215ec50956beaf606ead08080147b64c76403d20ebdc6142268528d3655ee3a1db6f88b535ee015b42081d4205ee1f4f335878501ea7644331dc81acecdb7ef63b86b32eae59956cff63237f92af7319c9a82669c989256bd0b6fa6fabe86bbfe0ecdadb9a399ce61b49a86355adfbedd45736756bc27b30afd161a9a9179585de33bf69fd2f8ebd7b5bf014644b906</data>
+ </image>
+ <image name="image2" >
+ <data format="XPM.GZ" length="4494" >789ce5965b4f23471085dff915d6d6db2aaac5e3b92aca037703cbc55c8c21ca43cf8c8d0dd85c6c307694ff9eeaaed3bd68771f968d14298a0a109fabebd4e99a9ef17cfad8e81d1f343e7e5a99cecc6c5435aaa1796a7cac9fc7e3c5ef7ffcf6e7ca8756d4909f661c35a20fbfac7ce8cc1a55e3f07ed2b7409702b4badaccfb996563020f5c7ecbf340b9a31c3591dff7ac7943e002cc8e73cf74acdcc27a8a2d37a5be4e1d9f04567f9fc105f25dcfea9726caad62a07c1158f58f94e3087e868ea57fa5fa0be590bfb11c3525affd4e03ebfa25b8507fbcaa1c47ca66e459fdf10c6c30af4dcfda8f5f9513dfffce71e1f5a956967adddfaeb25f4f7b60e8d199e596f42f6bc787ca213f554e5be06dc7a28ffdee282791cedb5c83d19fd795a55ecf4b3fb0ee07ebd312fae796e3283665e238524e2265de031bcc774d396d61be25b8c4fe1f02abfeab67f49f2867decfbd6393b6a03f03438f3bca19fa51cb33fc6f80fd7eae2c27e257e7cb4de5b4045f78d679f24960ddcfb172e6f73357ce63e88fc115ce43e558fcabbeb905fb7e47cae24ff5daca41af007bbd81e5b425f53aff6160d52f95f318f37d01a39ee7ca05f4790a469e0e1c97590bfa1b81f53c3e2bfbf5ecf697b532efe754398f31af437085eb65948b18e723f70cbf9e2bcc633db0f65b533609fcbafb372bf318fdcfc015e65b281731ee0ff6acf70767ca5e8f7be01abcab5cfa7e89e53cce2ba3fd1681b5df8172013f44e00acfbf4a39e8ef287b7dbe02234feefce795d727a36c12ccf75239d4b7c1bede9def42fcc0ef7960d5cbc05ebf543635aed752b94aa1ff02ee83ddf3b6a87c3d3f2b9b047a4fcaa17e0cf6f5eef928ab13f5476960d5eb7ac6f5dd07d7e04839e83d29d7be9ffbfe31b50dc723cfa87f08acf947e51a7ad457ee6760773ecaa4f47e36036bfd96673c3fb6c13578a01cf41f9505d5af3b2f655dc28fa93da33e550ef523e5e06f08861eb9e7b94cdfe7ddf753d50feb6f94437e00f67edcf3aa4e831ed8afe73bb05fefe655f7c37edcfd62bb81ddfb82935776cfeb41c87766ff2cfe7f1a4c6cb8e48ae91f68d4dce7015ff390473fad71c3b77cc7639ef03d3ffcb48f013ff293a84c79c6d54f693c8bc28b28589539bff2e2ed647e586389184bacf13a6ff0e6d71a32f92dde96bfdf9dbccc6387dba2d086caae4c668ff7bf68f0673ee0433ee263eef0099ff2199f8b62d0e32e5f704fea2fe5b70d3f57729556b91b349a1c718b634e64faa9fc7fc919e772220a91213254ca273b884bf72b4a54f1846ad925e93b1af56940d734a4110fe4efb5c40dddda907311734c7752d10b3a1ae289c634a17b7dafe331e995b3b124fbdfd25d85471763596fab7aa2a4f53d444653ded3773bb96e8faeae1de2ea8dff9da0b0ebfcd858e3357aa667bb1f68b4a5e7d256853559e8f56d64aefe85e6f44a0b5aea3bac5c2bebf74b8775fb6bfbb858771e7a6f1df09c36f89a36698bb6f53d5c4ef08ee4e6a2dd269b9d488729ed4a171b7bd40ece3228cce5d305edd3673ed7773139bd133a14d5233a96cff7a9237142a77446e7125dba900e70681564f5a6acdc1285ae9e0feaf150d675e8d2d59dd315ad52931fec2973d1a5489c6698e29c5a508829797bd629a52665bcf9fdd32ed95c1d50217b5c18b67390f34befb8e78873a9b6b39ad285216328a2de3bef5b32a59db5ccec42a6b565aaf7dffba6e663d3972b211ea86b065f3cbccbc7b53890399a21a55f677f5863e4f670c337df667f58e3d6dc99dbef3dd5ff6bdf73ff82c65fbfaefc0d4fb5b868</data>
+ </image>
+ <image name="image3" >
+ <data format="XPM.GZ" length="802" >789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232325500210543251d2e25658564056503300071f540dc3430007371012a492a830156496538c094848922c9c2259134c099304914e3604c8424aa5e6449b0044216ca824ba2da8b4512218b4d122e8b55520fee5974072164511da487ea490c7f22cba249e20d3efc018f3fcae0d2702eb5d2106992b5d65c00b9a48974</data>
+ </image>
+ <image name="image4" >
+ <data format="XPM.GZ" length="1241" >789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232365200210543251d2e253d856405bffcbc54105b19c8563600020b03103711c4b530b08072f50880513524ab518681443435ca984ae08ae06a94114a10ac443435ca3043904d4c4453a38ca604ae11590d9a0ab80bd0d46078914c35c4d885a608871a547f61f81d5d117a1862018930e5b8d5c0950c741a1b1e6a6aadb90086a9d853</data>
+ </image>
+ <image name="image5" >
+ <data format="XPM.GZ" length="5598" >789ca5985973db480ec7dff3295cc15b6a0b2351a428d6d63ef83e255bbe647b6a1fd02465dd872d9f53f3dd076c005dc926ce6a32eed8553f37fadf7fa0c1a69cdfbe6cdc9cb537befcf6e97145ab61be910fe861e34bf1349dbefdfedffffcf1e97323dae07f51bdbe117dfed7a7cfddd546bed199cfca0ae888016afeab62e8796ef110ee545caf05be16ae5bfc6ee096e7b6e756983f51b6f53b81257ecfb8eee7e9b162f66af1c78125fe48987f23f3fb81657e691cd5bddecc7316d555efd058f7eb2867aa771058f4de8c55cffb6dd4a34cf5b68d357e681c6515634db81a7e3ef59c35cccf5560bf9ef6953389c77660af074f15c751e05c38a6d81f2ef9f3a848f4e9d658f2c36b635dbfa54cc2383556bd33e12492fc70df38f1f3f8ae4cc2745a711285fda7caa4f95e06967a2d8c63f27a8fc2a60fa4acfa980a371b898f0767dc6cf8fdbc9f84c27e4de124d2fabe186b3dee8c75ff1365dbef2db0ccef0987fd2f2a6632fd576552fd2b63d57b08ecd7d39d70b321fd0560acfb6d1a4b7e3050764de7d79f08a70de937ea7b7689e68f4de1e0776e2c7ab8abecb47eb170aa7ee822b0e89f1b4b7fd24dc529abe9794f02cbf99e2b3badc7a5b1ee97089b3e0e8d253f3c364e253e5576120ff7c63a9f7966d2e771d358e75bca4ef3bb0e2cf9758db5fe47c6b21eeb81bd3f07c2ad58ebd130d67e6a194b3cf97e62b2fa24c67a1f5d2aab3f8781a53e17c6eaa7082cfa3de156acf9d5034b7e3563f1eb96c6eaf7c0b815fbf8d2739e3aedefb1b1de9723618b77a49cebf946c6e20f5f8d251e753e8b5bb9e74c980a4afc7a7fbf66b1ed8fb7c67a9ec7c2ad5cfd74038bdfa6b1f6cbd458fd2e84b358efbb0363f5b71358fccd8c33596f9c4bfddcc458fac78d8cf5797b3296f5f82c4c49e6f5c9bf9fb23ce41307967e3935d6f36c0b67b1ce3f188b5f3757367f5363b98fdc38b0cc0f8cf5f90bf3ea97028bfe50981289777d63edcf81b1c4439897f3c52d615738cfe0df371c1deb7db265acf98d8d253f7a50d67a60c758cfcbf4cc7f2fb0f8bf1736bfae30d6f35f1a4b3ce6c6e2df95ca85f6f7dc58f3db0e5c783e14e6ebc533e87e963fbe0873f9fd3cc97c91693fd028b0d4e3c558f3eb0b9b5f972bab3fe78c353f3056bfabc0e2371636bfe4cf9b29d1e76b69acfdb863accfd33cb0dc2fa7c6e2179e03cb79ae940b7dffbf1b6bfd1363f53b12367f581a6b3d1bca56df6e60a9bfc6e765def4ecef6bc7eafaf9e8d558fbb7a15ce87d7263acf7ffbdb1e40f33e1e0cf29ebfea8eb6d7ff29f17f8f4137dfe51d8fa0117ca65ee3fbfe3bd705116b2de9f775e3af50313e1a229f1f0682cf1b052e6e1d9dfbf1cddd4fd2363cdcfef5fb05b7d1f0c944bed4f67ac9f5f27c265bf4c3d9f07eefb787f1f96695eaa1e0a174d7d7f81b1ee4f81a5fe75e552d9bf1fca7e617e9e8d556f33b0c4fbcf5ffdb44c956bc6a2d75dfd6c2020fd3ce2ff69a0c31c0b2cff91461fef71804374bfaa81231ce3044b9ce2ecd734380fc2392e70890ff888bfa6f184cff8c24e5ef10ddf71f3a37c3ed6c015afdec26dfeb983bbb887fb78f0f734380fe031c7437f3247788c27d8fe713e1f6a1076f014cfb08be7ac7481977885d75c951fe4f3630dcea3c3eb7b9cc70d6b9ce12d9fee26de610debeb69b0fb578cb89a0d8c399711e794609373d9c39455f2b53466d8c20c17809c45cc7a3c00f011081cffccff379fef35388f1d0428a0c401f459e58c3d45700f0003cee71d8678fc730d7430e2557d3c8331f7568c37308129cc7006733e9d262c6008cb6ff3f94ea3c72bc678ca3f1fb80a637884154c71c974c55d72c91a4feca4fdf553f8ad46554d8e9ee30a9eb1efab31611f2ff0ca346427bb9c11e114debe7e7ebed328318702e7f0ce9dbee47a1c724655b745b0c94ea6b0c55519f059b98f73d19a6cc30eecc21eecfb7100877004c770026de8e070bdfe805338832e9cc3055cc2955f7b0d3de8f0cfebb5356ee016eea0c6a30e11342086049a907aadcd35355a90111250f5e5288706bfdb4bea572a78b49e06ddd3a0d2807a2502110d6944639ad09466ebf9e8ae684e0bf5b1a4075ab28f11ffa1df678dc7f57cb0c68a9ee899355e7c2ddbf40a31bdb1c63bcdfe86c6803669cb9f4555c76b38a76dcee57d5d1f5c8f1d5af0b9745581bb029a5c8f3eedd21eed73b70ebe56fa91061dd061f05139e9d1116b1cfb9aee55c4fcf6330d5cd289d778a6b65fdd831dea702e256b9cf2b974a84367d4fd580347744e17744957acc13e7cfc095d538f356ed8cd2ddd518dea147da4c1956890ffcf295ed5e4c83b4a59f182b9455935e3b801ab791c7fa4e188d7a4bcbee66353feaef9df8852ca2f3e9ee3ef73840f359cabfec22979f4ddbd1bf018ba118f318f899bf298b9b95bb8e537cffe9ffffef4171c39a0bf</data>
+ </image>
+ <image name="image6" >
+ <data format="XPM.GZ" length="3742" >789c8d96c9521c490c86ef3c458775734cc8ddd5b5c6c41c303b180cc60b66620eaacc2c9aa5599b7562de7da45fc5180c8e98fa39f091522e4a49c9bbb783bdedcdc1db77735733991d864198c8e5e06dbc9e4eeffffceb8fbfe7de64d9407f466531c8defc36f76667360883adb3d364c013051ae2039f8147266359068f4dc6740a2e4db05f05d726f0253898c017c6a3cc04ffafce79aa3af0143c36c17e055caa0aacbf06aeb2203e5f09ae4d185f75ce472de6e7737063c2fcb57356b702fed673e32c473d4bcf3760198f02e69325706b022f3a676df0f567e05035d1ed273dc79883e7c1d1045e70ae2456d84fd9738a589f0b703261bc72ae25e17ee4b0e7d8f3b5733374e603e32c37c11ff36970db12f193f7e07c1c6bec87c6e0c604ff0e1c4db03f36cec7e3a6f4fd2e38e779eee7bd05e7e350fa7e4fc0455ee6b84fb9eab913bfdf1c5ce5758efba54fffb1e75302d726f8af3817a5f8f922584cf06fc0211f951ebfd0b30afe07ce4510dfdf1e38e665e9f9f1e01c32cf1fda06a73c2f7c7eac5f8c8b61eef582f315b909dc82f1c17e07dc1459e5f1c77d953abb787e0ab832611cf957366dd9c707f556762a3fcf8673ddd6d8afdc1957b909fe98af2a65d4c787c08d09e3c8bfaad504f378de83a309e35fc049d9d747bda19c7dbe8f602d88d6fd11af3a33c1ffde398e02ec69178c0b04bb7fa12be03e08e7ab4b895e2f74ec1ca2e73f6d811b2d37df1feaa9969082f71ff4a73a98c01f9cdb3678fde27eea58f7f9cdc8bfba33c11efda2199ac01bcead048fd72678a4e9e3f6a86f6d172acc87fc69f290f9386f3d72f478a1bf348509fea8b7a66c9b80fec1a8b7a66a53f47cc2fe9b5ae77346fe35ad09e761703081d12f9b68c2fc57ce6d0c1e6fe463934ce0efc63234c11ffd5b4a13c66f9cb53d79fded832bcd27f47f5aeb59055e744eb1df3fe2251aeee4e7453f9264c27aa847b44f7f4f909fda3efb7ae30c5c84b65f1fef435b9a608ff7a4ad4c981ffb6b6b13d8fda5edfb37eff4dcb65e2f787f5a7cb0f7fd0413ecf13eb49d09f6783ff07cf97d8ec0a3f8d8df516f483faf07c45b1f27e9f30ff989e9fdbe11ff1034fd3c9eebe068c238fa9f6677f2fb27ac1f475dd3f97da25fc6c204be755673ef3f8db3360c1f1f824b13c651df2877c44fd0df511efe5ea39f44318151cf9a4e2ab0af870d63fee4dc55fdfe109f880ff3fb788a8ff98df733762630fa471aa6febda2839e5b3f0fe1bef4f18bc9fb01fa7dca4ce0bb9e5b671ef69c3cff18f99cc626d853cf551f3fe453ca531bbdde979cbb2c793e207f536102a39fa5ca0446bf4279f97b89feaabb5181511f38bedf2ffa47373461bdcfe0dc8471d46387860fc6fbaad155c11ef7a5d953747ede69cf2a30fe3fd06c5121fe88572726f8a37f68720ffbfdadf7ac02fb7e82098c7e85ebf2fde37dea92098cf7acc367bc33fbff7a6ecfc4c22d078eaac41d1ff0e4d7f66a7df84293e71ecfec858f9ee8d1fef8a9c733fb139ef2299ff1395ff0255fc167c233befee1f1cc3ef10ddff21ddff303cfabe77bd584177891971e3d7ed8db4e7b2df30aaff29a7aac3ff9ebe4a9bdf2067fe04ddee28ffafb36eff027de558fcfbaab2ffc95bf3db5578b3dfecefb3ce411673c56ceb9e0b23f47a5fbac7fb26f889988742f2a129e504b81a246e0c8ec293cb7a7441d0b1dd0840ee9883486744253bea4533a7bd5fe9c2ed4feb29fff4aff32a36b8dd5e92fe6bfa15bddcf1dddd303cd93c6911668aa2b5cbc363f3c16799f9630fbb2d20aadd21aadeb3d547a8617f6f0d8a00fb4495bfadb47daa61dfa84f977e933c597f64f6e6c9fbed057fa467bf49df669c8bb34a2eca53d8d35576ef88e722aa8a48a6a6a448320a20fd36bf3eb7f407c2c89efb5500f6422877224c77222533915e6b397fbd117f54ccee54275295732936bb9915bb9937b797869ff34e7649ecfe4bd2ce81a8bbc2a4bb2fc5a3dfe2c59915559fb75fdfe8f7affe7f7b97f011cdd9635</data>
+ </image>
+ </images>
+</ui>
diff --git a/examples/activeqt/wrapper/main.cpp b/examples/activeqt/wrapper/main.cpp
new file mode 100644
index 0000000000..a403084afa
--- /dev/null
+++ b/examples/activeqt/wrapper/main.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QAxFactory>
+#include <QCheckBox>
+#include <QRadioButton>
+#include <QPushButton>
+#include <QToolButton>
+#include <QPixmap>
+
+/* XPM */
+static const char *fileopen[] = {
+" 16 13 5 1",
+". c #040404",
+"# c #808304",
+"a c None",
+"b c #f3f704",
+"c c #f3f7f3",
+"aaaaaaaaa...aaaa",
+"aaaaaaaa.aaa.a.a",
+"aaaaaaaaaaaaa..a",
+"a...aaaaaaaa...a",
+".bcb.......aaaaa",
+".cbcbcbcbc.aaaaa",
+".bcbcbcbcb.aaaaa",
+".cbcb...........",
+".bcb.#########.a",
+".cb.#########.aa",
+".b.#########.aaa",
+"..#########.aaaa",
+"...........aaaaa"
+};
+
+
+//! [0]
+class ActiveQtFactory : public QAxFactory
+{
+public:
+ ActiveQtFactory( const QUuid &lib, const QUuid &app )
+ : QAxFactory( lib, app )
+ {}
+ QStringList featureList() const
+ {
+ QStringList list;
+ list << "QCheckBox";
+ list << "QRadioButton";
+ list << "QPushButton";
+ list << "QToolButton";
+ return list;
+ }
+ QObject *createObject(const QString &key)
+ {
+ if ( key == "QCheckBox" )
+ return new QCheckBox(0);
+ if ( key == "QRadioButton" )
+ return new QRadioButton(0);
+ if ( key == "QPushButton" )
+ return new QPushButton(0 );
+ if ( key == "QToolButton" ) {
+ QToolButton *tb = new QToolButton(0);
+// tb->setIcon( QPixmap(fileopen) );
+ return tb;
+ }
+
+ return 0;
+ }
+ const QMetaObject *metaObject( const QString &key ) const
+ {
+ if ( key == "QCheckBox" )
+ return &QCheckBox::staticMetaObject;
+ if ( key == "QRadioButton" )
+ return &QRadioButton::staticMetaObject;
+ if ( key == "QPushButton" )
+ return &QPushButton::staticMetaObject;
+ if ( key == "QToolButton" )
+ return &QToolButton::staticMetaObject;
+
+ return 0;
+ }
+ QUuid classID( const QString &key ) const
+ {
+ if ( key == "QCheckBox" )
+ return "{6E795DE9-872D-43CF-A831-496EF9D86C68}";
+ if ( key == "QRadioButton" )
+ return "{AFCF78C8-446C-409A-93B3-BA2959039189}";
+ if ( key == "QPushButton" )
+ return "{2B262458-A4B6-468B-B7D4-CF5FEE0A7092}";
+ if ( key == "QToolButton" )
+ return "{7c0ffe7a-60c3-4666-bde2-5cf2b54390a1}";
+
+ return QUuid();
+ }
+ QUuid interfaceID( const QString &key ) const
+ {
+ if ( key == "QCheckBox" )
+ return "{4FD39DD7-2DE0-43C1-A8C2-27C51A052810}";
+ if ( key == "QRadioButton" )
+ return "{7CC8AE30-206C-48A3-A009-B0A088026C2F}";
+ if ( key == "QPushButton" )
+ return "{06831CC9-59B6-436A-9578-6D53E5AD03D3}";
+ if ( key == "QToolButton" )
+ return "{6726080f-d63d-4950-a366-9bf33e5cdf84}";
+
+ return QUuid();
+ }
+ QUuid eventsID( const QString &key ) const
+ {
+ if ( key == "QCheckBox" )
+ return "{FDB6FFBE-56A3-4E90-8F4D-198488418B3A}";
+ if ( key == "QRadioButton" )
+ return "{73EE4860-684C-4A66-BF63-9B9EFFA0CBE5}";
+ if ( key == "QPushButton" )
+ return "{3CC3F17F-EA59-4B58-BBD3-842D467131DD}";
+ if ( key == "QToolButton" )
+ return "{f4d421fd-4ead-4fd9-8a25-440766939639}";
+
+ return QUuid();
+ }
+};
+//! [0] //! [1]
+
+QAXFACTORY_EXPORT( ActiveQtFactory, "{3B756301-0075-4E40-8BE8-5A81DE2426B7}", "{AB068077-4924-406a-BBAF-42D91C8727DD}" )
+//! [1]
diff --git a/examples/activeqt/wrapper/wrapper.inf b/examples/activeqt/wrapper/wrapper.inf
new file mode 100644
index 0000000000..fc17a3de03
--- /dev/null
+++ b/examples/activeqt/wrapper/wrapper.inf
@@ -0,0 +1,9 @@
+[version]
+ signature="$CHICAGO$"
+ AdvancedINF=2.0
+ [Add.Code]
+ wrapperax.dll=wrapperax.dll
+ [wrapperax.dll]
+ file-win32-x86=thiscab
+ clsid={23F5012A-7333-43D3-BCA8-836AABC61B4A}
+ RegisterServer=yes
diff --git a/examples/activeqt/wrapper/wrapper.pro b/examples/activeqt/wrapper/wrapper.pro
new file mode 100644
index 0000000000..e109dba93c
--- /dev/null
+++ b/examples/activeqt/wrapper/wrapper.pro
@@ -0,0 +1,17 @@
+TEMPLATE = lib
+TARGET = wrapperax
+
+CONFIG += qt warn_off qaxserver dll
+contains(CONFIG, static):DEFINES += QT_NODLL
+
+SOURCES = main.cpp
+RC_FILE = wrapperax.rc
+DEF_FILE = $$QT_SOURCE_TREE/src/activeqt/control/qaxserver.def
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/wrapper
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS wrapper.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/wrapper
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/activeqt/wrapper/wrapperax.rc b/examples/activeqt/wrapper/wrapperax.rc
new file mode 100644
index 0000000000..453688d90a
--- /dev/null
+++ b/examples/activeqt/wrapper/wrapperax.rc
@@ -0,0 +1,32 @@
+#include "winver.h"
+
+1 TYPELIB "wrapperax.rc"
+1 ICON DISCARDABLE "..\\..\\..\\src\\activeqt\\control\\qaxserver.ico"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x3fL
+ FILEOS 0x00040000L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904e4"
+ BEGIN
+ VALUE "CompanyName", "Nokia Corporation and/or its subsidiary(-ies)"
+ VALUE "FileDescription", "Wrapper Example (ActiveQt)"
+ VALUE "FileVersion", "1.0.0.0"
+ VALUE "LegalCopyright", "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)."
+ VALUE "InternalName", "wrapperax.dll"
+ VALUE "OriginalFilename", "wrapperax.dll"
+ VALUE "ProductName", "Wrapper Example (ActiveQt)"
+ VALUE "ProductVersion", "1.0.0.0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1252
+ END
+END
diff --git a/examples/assistant/README b/examples/assistant/README
new file mode 100644
index 0000000000..85f5a4373d
--- /dev/null
+++ b/examples/assistant/README
@@ -0,0 +1,38 @@
+Support for interactive help is provided by the Qt Assistant application.
+Developers can take advantages of the facilities it offers to display
+specially-prepared documentation to users of their 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/assistant/assistant.pro b/examples/assistant/assistant.pro
new file mode 100644
index 0000000000..b724bcb6f5
--- /dev/null
+++ b/examples/assistant/assistant.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = simpletextviewer
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/assistant
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS assistant.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/assistant
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/assistant/simpletextviewer/documentation/about.txt b/examples/assistant/simpletextviewer/documentation/about.txt
new file mode 100644
index 0000000000..eeab35f4a6
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/about.txt
@@ -0,0 +1,9 @@
+The Simple Text Viewer enables the user to select and view existing
+files.
+
+HTML files is displayed using rich text, while other files are
+presented as plain text. The application provides a file dialog
+allowing the user to search for files using wildcard matching. The
+search is performed within in the specified directory, and the user is
+given an option to browse the existing file system to find the
+relevant directory.
diff --git a/examples/assistant/simpletextviewer/documentation/browse.html b/examples/assistant/simpletextviewer/documentation/browse.html
new file mode 100644
index 0000000000..987abf31f6
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/browse.html
@@ -0,0 +1,34 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Browse</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Browse</h2></center></p>
+
+ <p>
+ The file dialog let you browse the current file system to
+ specify the directory in which the file you want to open
+ resides.
+ Note that only the specified directory will be searched, any
+ subdirectories will simply be ignored.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/browse.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="filedialog.html">File Dialog</a>, <a href="wildcardmatching.html">Wildcard Matching</a>,
+ <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
+
diff --git a/examples/assistant/simpletextviewer/documentation/filedialog.html b/examples/assistant/simpletextviewer/documentation/filedialog.html
new file mode 100644
index 0000000000..afa65ed577
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/filedialog.html
@@ -0,0 +1,48 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>File Dialog</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>File Dialog</h2></center></p>
+
+ <p>
+ In the file dialog you can name a particular file name, or
+ search for files using wildcard matching, i.e. specify a
+ file name containing wildcards. In addition you must specify
+ the directory in which the file you search for resides.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/filedialog.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ By default the dialog will search for all files (*) in the
+ current directory (the directory the application is run from).
+ </p>
+
+ <p>
+ When editing the file name and directory parameters, an
+ overview of the matching files are displayed in the
+ dialog. The overview is updated whenever the parameters
+ change.
+ </p>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="browse.html">Browse</a>, <a href="wildcardmatching.html">Wildcard Matching</a>,
+ <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
+
+
diff --git a/examples/assistant/simpletextviewer/documentation/findfile.html b/examples/assistant/simpletextviewer/documentation/findfile.html
new file mode 100644
index 0000000000..32e0147181
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/findfile.html
@@ -0,0 +1,32 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Find File</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Find File</h2></center></p>
+
+ <p>
+ To open and view a file in the Simple Text Viewer, select the
+ 'Open...' option in the 'File' menu. The application will then
+ provide you with a file dialog that you can use to search for
+ any existing file.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/fadedfilemenu.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="openfile.html">Open File</a>, <a href="filedialog.html">File Dialog</a>
+ </p>
+ </body>
+</html>
+
diff --git a/examples/assistant/simpletextviewer/documentation/images/browse.png b/examples/assistant/simpletextviewer/documentation/images/browse.png
new file mode 100644
index 0000000000..86db6b19eb
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/images/browse.png
Binary files differ
diff --git a/examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.png b/examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.png
new file mode 100644
index 0000000000..fde0e43f67
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.png
Binary files differ
diff --git a/examples/assistant/simpletextviewer/documentation/images/filedialog.png b/examples/assistant/simpletextviewer/documentation/images/filedialog.png
new file mode 100644
index 0000000000..883a33a269
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/images/filedialog.png
Binary files differ
diff --git a/examples/assistant/simpletextviewer/documentation/images/handbook.png b/examples/assistant/simpletextviewer/documentation/images/handbook.png
new file mode 100644
index 0000000000..3bd2b928b0
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/images/handbook.png
Binary files differ
diff --git a/examples/assistant/simpletextviewer/documentation/images/mainwindow.png b/examples/assistant/simpletextviewer/documentation/images/mainwindow.png
new file mode 100644
index 0000000000..c28d5e9ffe
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/images/mainwindow.png
Binary files differ
diff --git a/examples/assistant/simpletextviewer/documentation/images/open.png b/examples/assistant/simpletextviewer/documentation/images/open.png
new file mode 100644
index 0000000000..1e5bba3c8c
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/images/open.png
Binary files differ
diff --git a/examples/assistant/simpletextviewer/documentation/images/wildcard.png b/examples/assistant/simpletextviewer/documentation/images/wildcard.png
new file mode 100644
index 0000000000..6e83a56cc4
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/images/wildcard.png
Binary files differ
diff --git a/examples/assistant/simpletextviewer/documentation/index.html b/examples/assistant/simpletextviewer/documentation/index.html
new file mode 100644
index 0000000000..5a7b1d5fac
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/index.html
@@ -0,0 +1,41 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Manual</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Simple Text Viewer</h2></center></p>
+
+ <p>
+ The Simple Text Viewer enables the user to select and view
+ existing files.
+ </p>
+
+ <p><center>
+ <img src="images/mainwindow.png" />
+ </center></p>
+
+ <p>
+ HTML files is displayed using rich text, while
+ other files are presented as plain text. The application
+ provides a file dialog allowing the user to search for files
+ using wildcard matching. The search is performed within in the
+ specified directory, and the user is given an option to browse
+ the existing file system to find the relevant directory.
+ </p>
+
+ <ul>
+ <li><a href="findfile.html">Find File</a></li>
+ <ul>
+ <li><a href="filedialog.html">File Dialog</a></li>
+ <li><a href="wildcardmatching.html">WildCard Matching</a></li>
+ <li><a href="browse.html">Browse</a></li>
+ </ul>
+ <li><a href="openfile.html">Open File</a></li>
+ </ul>
+ </body>
+</html>
+
+
+
diff --git a/examples/assistant/simpletextviewer/documentation/intro.html b/examples/assistant/simpletextviewer/documentation/intro.html
new file mode 100644
index 0000000000..2e2aa40de7
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/intro.html
@@ -0,0 +1,28 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Manual</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Simple Text Viewer</h2></center></p>
+
+ <p>
+ The Simple Text Viewer enables the user to select and view
+ existing files.
+ </p>
+
+ <p><center>
+ <img src="images/mainwindow.png" />
+ </center></p>
+
+ <p>
+ The application provides its own custom documentation that is
+ available through the <b>Help</b> menu in the main window's menubar
+ and through the <b>Help</b> button in the application's find file
+ dialog.
+ </p>
+
+ </body>
+</html>
+
diff --git a/examples/assistant/simpletextviewer/documentation/openfile.html b/examples/assistant/simpletextviewer/documentation/openfile.html
new file mode 100644
index 0000000000..e172de95ea
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/openfile.html
@@ -0,0 +1,36 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Open File</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Open File</h2></center></p>
+
+ <p>
+ Once the file you want to view appears in the dialog's
+ display, you can open it in two different ways.
+ </p>
+
+ <p>
+ By pressing the 'Open' button the currently selected file will
+ be opened. By default, the first file in the list of matching
+ files is selected. Another way of opening a file is to simply
+ double click the displayed file name.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/open.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
diff --git a/examples/assistant/simpletextviewer/documentation/simpletextviewer.adp b/examples/assistant/simpletextviewer/documentation/simpletextviewer.adp
new file mode 100644
index 0000000000..660df4f382
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/simpletextviewer.adp
@@ -0,0 +1,40 @@
+<!DOCTYPE DCF>
+
+<assistantconfig version="3.2.0">
+
+<profile>
+ <property name="name">simpletextviewer</property>
+ <property name="title">Simple Text Viewer</property>
+ <property name="applicationicon">images/handbook.png</property>
+ <property name="startpage">index.html</property>
+ <property name="aboutmenutext">About Simple Text Viewer</property>
+ <property name="abouturl">about.txt</property>
+ <property name="assistantdocs">.</property>
+</profile>
+
+<DCF ref="index.html" icon="images/handbook.png" title="Simple Text Viewer">
+ <section ref="./findfile.html" title="Find File">
+ <keyword ref="./index.html">Display</keyword>
+ <keyword ref="./index.html">Rich text</keyword>
+ <keyword ref="./index.html">Plain text</keyword>
+ <keyword ref="./findfile.html">Find</keyword>
+ <keyword ref="./findfile.html">File menu</keyword>
+ <keyword ref="./filedialog.html">File name</keyword>
+ <keyword ref="./filedialog.html">File dialog</keyword>
+ <keyword ref="./wildcardmatching.html">File globbing</keyword>
+ <keyword ref="./wildcardmatching.html">Wildcard matching</keyword>
+ <keyword ref="./wildcardmatching.html">Wildcard syntax</keyword>
+ <keyword ref="./browse.html">Browse</keyword>
+ <keyword ref="./browse.html">Directory</keyword>
+ <keyword ref="./openfile.html">Open</keyword>
+ <keyword ref="./openfile.html">Select</keyword>
+
+ <section ref="./filedialog.html" title="File Dialog" />
+ <section ref="./wildcardmatching.html" title="Wildcard Matching" />
+ <section ref="./browse.html" title="Browse" />
+ </section>
+ <section ref="./openfile.html" title="Open File" />
+</DCF>
+
+</assistantconfig>
+
diff --git a/examples/assistant/simpletextviewer/documentation/wildcardmatching.html b/examples/assistant/simpletextviewer/documentation/wildcardmatching.html
new file mode 100644
index 0000000000..eb1839a068
--- /dev/null
+++ b/examples/assistant/simpletextviewer/documentation/wildcardmatching.html
@@ -0,0 +1,57 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Wildcard Matching</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Wildcard Matching</h2></center></p>
+
+ <p>
+ Most command shells such as bash or cmd.exe support "file
+ globbing", the ability to identify a group of files by using
+ wildcards.
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/wildcard.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ Wildcard matching provides four features:
+ </p>
+
+ <ul>
+ <li>Any character represents itself apart from those
+ mentioned below. Thus 'c' matches the character 'c'.
+ </li>
+ <li>The '?' character matches any single character.</li>
+ <li>The '*' matches zero or more of any characters.</li>
+ <li>Sets of characters can be represented in square brackets.
+ Within the character class, like outside, backslash
+ has no special meaning.
+ </li>
+ </ul>
+
+ <p>
+ For example we could identify HTML files with
+ <code>*.html</code>. This will match zero or more characters
+ followed by a dot followed by 'h', 't', 'm' and 'l'.
+ </p>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="browse.html">Browse</a>, <a href="filedialog.html">File Dialog</a>,
+ <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
+
+
+
diff --git a/examples/assistant/simpletextviewer/findfiledialog.cpp b/examples/assistant/simpletextviewer/findfiledialog.cpp
new file mode 100644
index 0000000000..f73657e0d4
--- /dev/null
+++ b/examples/assistant/simpletextviewer/findfiledialog.cpp
@@ -0,0 +1,221 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "findfiledialog.h"
+
+//! [0]
+FindFileDialog::FindFileDialog(QTextEdit *editor, QAssistantClient *assistant,
+ QWidget *parent)
+ : QDialog(parent)
+{
+ currentAssistantClient = assistant;
+ currentEditor = editor;
+//! [0]
+
+ createButtons();
+ createComboBoxes();
+ createFilesTree();
+ createLabels();
+ createLayout();
+
+ directoryComboBox->addItem(QDir::toNativeSeparators(QDir::currentPath()));
+ fileNameComboBox->addItem("*");
+ findFiles();
+
+ setWindowTitle(tr("Find File"));
+//! [1]
+}
+//! [1]
+
+void FindFileDialog::browse()
+{
+ QString currentDirectory = directoryComboBox->currentText();
+ QString newDirectory = QFileDialog::getExistingDirectory(this,
+ tr("Select Directory"), currentDirectory);
+ if (!newDirectory.isEmpty()) {
+ directoryComboBox->addItem(QDir::toNativeSeparators(newDirectory));
+ directoryComboBox->setCurrentIndex(directoryComboBox->count() - 1);
+ update();
+ }
+}
+
+//! [2]
+void FindFileDialog::help()
+{
+ currentAssistantClient->showPage(QLibraryInfo::location(QLibraryInfo::ExamplesPath) +
+ QDir::separator() + "assistant/simpletextviewer/documentation/filedialog.html");
+}
+//! [2]
+
+void FindFileDialog::openFile(QTreeWidgetItem *item)
+{
+ if (!item) {
+ item = foundFilesTree->currentItem();
+ if (!item)
+ return;
+ }
+
+ QString fileName = item->text(0);
+ QString path = directoryComboBox->currentText() + QDir::separator();
+
+ QFile file(path + fileName);
+ if (file.open(QIODevice::ReadOnly)) {
+ QString data(file.readAll());
+
+ if (fileName.endsWith(".html"))
+ currentEditor->setHtml(data);
+ else
+ currentEditor->setPlainText(data);
+ }
+ close();
+}
+
+void FindFileDialog::update()
+{
+ findFiles();
+ buttonBox->button(QDialogButtonBox::Open)->setEnabled(
+ foundFilesTree->topLevelItemCount() > 0);
+}
+
+void FindFileDialog::findFiles()
+{
+ QRegExp filePattern(fileNameComboBox->currentText() + "*");
+ filePattern.setPatternSyntax(QRegExp::Wildcard);
+
+ QDir directory(directoryComboBox->currentText());
+
+ QStringList allFiles = directory.entryList(QDir::Files | QDir::NoSymLinks);
+ QStringList matchingFiles;
+
+ foreach (QString file, allFiles) {
+ if (filePattern.exactMatch(file))
+ matchingFiles << file;
+ }
+ showFiles(matchingFiles);
+}
+
+void FindFileDialog::showFiles(const QStringList &files)
+{
+ foundFilesTree->clear();
+
+ for (int i = 0; i < files.count(); ++i) {
+ QTreeWidgetItem *item = new QTreeWidgetItem(foundFilesTree);
+ item->setText(0, files[i]);
+ }
+
+ if (files.count() > 0)
+ foundFilesTree->setCurrentItem(foundFilesTree->topLevelItem(0));
+}
+
+void FindFileDialog::createButtons()
+{
+ browseButton = new QToolButton;
+ browseButton->setText(tr("..."));
+ connect(browseButton, SIGNAL(clicked()), this, SLOT(browse()));
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Open
+ | QDialogButtonBox::Cancel
+ | QDialogButtonBox::Help);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(openFile()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(help()));
+}
+
+void FindFileDialog::createComboBoxes()
+{
+ directoryComboBox = new QComboBox;
+ fileNameComboBox = new QComboBox;
+
+ fileNameComboBox->setEditable(true);
+ fileNameComboBox->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Preferred);
+
+ directoryComboBox->setMinimumContentsLength(30);
+ directoryComboBox->setSizeAdjustPolicy(
+ QComboBox::AdjustToMinimumContentsLength);
+ directoryComboBox->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Preferred);
+
+ connect(fileNameComboBox, SIGNAL(editTextChanged(const QString &)),
+ this, SLOT(update()));
+ connect(directoryComboBox, SIGNAL(currentIndexChanged(const QString &)),
+ this, SLOT(update()));
+}
+
+void FindFileDialog::createFilesTree()
+{
+ foundFilesTree = new QTreeWidget;
+ foundFilesTree->setColumnCount(1);
+ foundFilesTree->setHeaderLabels(QStringList(tr("Matching Files")));
+ foundFilesTree->setRootIsDecorated(false);
+ foundFilesTree->setSelectionMode(QAbstractItemView::SingleSelection);
+
+ connect(foundFilesTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
+ this, SLOT(openFile(QTreeWidgetItem *)));
+}
+
+void FindFileDialog::createLabels()
+{
+ directoryLabel = new QLabel(tr("Search in:"));
+ fileNameLabel = new QLabel(tr("File name (including wildcards):"));
+}
+
+void FindFileDialog::createLayout()
+{
+ QHBoxLayout *fileLayout = new QHBoxLayout;
+ fileLayout->addWidget(fileNameLabel);
+ fileLayout->addWidget(fileNameComboBox);
+
+ QHBoxLayout *directoryLayout = new QHBoxLayout;
+ directoryLayout->addWidget(directoryLabel);
+ directoryLayout->addWidget(directoryComboBox);
+ directoryLayout->addWidget(browseButton);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(fileLayout);
+ mainLayout->addLayout(directoryLayout);
+ mainLayout->addWidget(foundFilesTree);
+ mainLayout->addStretch();
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+}
diff --git a/examples/assistant/simpletextviewer/findfiledialog.h b/examples/assistant/simpletextviewer/findfiledialog.h
new file mode 100644
index 0000000000..0c89fda950
--- /dev/null
+++ b/examples/assistant/simpletextviewer/findfiledialog.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDFILEDIALOG_H
+#define FINDFILEDIALOG_H
+
+#include <QAssistantClient>
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QLabel;
+class QTextEdit;
+class QToolButton;
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+//! [0]
+class FindFileDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindFileDialog(QTextEdit *editor, QAssistantClient *assistant,
+ QWidget *parent = 0);
+
+private slots:
+ void browse();
+ void help();
+ void openFile(QTreeWidgetItem *item = 0);
+ void update();
+
+private:
+ void findFiles();
+ void showFiles(const QStringList &files);
+
+ void createButtons();
+ void createComboBoxes();
+ void createFilesTree();
+ void createLabels();
+ void createLayout();
+
+ QAssistantClient *currentAssistantClient;
+ QTextEdit *currentEditor;
+ QTreeWidget *foundFilesTree;
+
+ QComboBox *directoryComboBox;
+ QComboBox *fileNameComboBox;
+
+ QLabel *directoryLabel;
+ QLabel *fileNameLabel;
+
+ QDialogButtonBox *buttonBox;
+
+ QToolButton *browseButton;
+};
+//! [0]
+
+#endif
diff --git a/examples/assistant/simpletextviewer/main.cpp b/examples/assistant/simpletextviewer/main.cpp
new file mode 100644
index 0000000000..1d51376c06
--- /dev/null
+++ b/examples/assistant/simpletextviewer/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/assistant/simpletextviewer/mainwindow.cpp b/examples/assistant/simpletextviewer/mainwindow.cpp
new file mode 100644
index 0000000000..cc2f3c0486
--- /dev/null
+++ b/examples/assistant/simpletextviewer/mainwindow.cpp
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "findfiledialog.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ textViewer = new QTextEdit;
+ textViewer->setReadOnly(true);
+ QFile file("documentation/intro.html");
+ if (file.open(QIODevice::ReadOnly))
+ textViewer->setHtml(file.readAll());
+
+ setCentralWidget(textViewer);
+
+ createActions();
+ createMenus();
+
+ initializeAssistant();
+
+ setWindowTitle(tr("Simple Text Viewer"));
+ resize(750, 400);
+}
+//! [0]
+
+//! [1]
+void MainWindow::closeEvent(QCloseEvent *)
+{
+ if (assistantClient)
+ assistantClient->closeAssistant();
+}
+//! [1]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Simple Text Viewer"),
+ tr("This example demonstrates how to use\n" \
+ "Qt Assistant as help system for your\n" \
+ "own application."));
+}
+
+//! [2]
+void MainWindow::assistant()
+{
+ assistantClient->showPage(QLibraryInfo::location(QLibraryInfo::ExamplesPath) +
+ QDir::separator() +
+ "assistant/simpletextviewer/documentation/index.html");
+}
+//! [2]
+
+//! [3]
+void MainWindow::open()
+{
+ FindFileDialog dialog(textViewer, assistantClient);
+ dialog.exec();
+}
+//! [3]
+
+void MainWindow::createActions()
+{
+ assistantAct = new QAction(tr("Help Contents"), this);
+ assistantAct->setShortcut(tr("F1"));
+ connect(assistantAct, SIGNAL(triggered()), this, SLOT(assistant()));
+
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ clearAct = new QAction(tr("&Clear"), this);
+ clearAct->setShortcut(tr("Ctrl+C"));
+ connect(clearAct, SIGNAL(triggered()), textViewer, SLOT(clear()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ 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 = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(clearAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(assistantAct);
+ helpMenu->addSeparator();
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(helpMenu);
+}
+
+//! [4]
+void MainWindow::initializeAssistant()
+{
+ assistantClient = new QAssistantClient(QLibraryInfo::location(QLibraryInfo::BinariesPath), this);
+
+ QStringList arguments;
+ arguments << "-profile" << QString("documentation") + QDir::separator() + QString("simpletextviewer.adp");
+ assistantClient->setArguments(arguments);
+}
+//! [4]
diff --git a/examples/assistant/simpletextviewer/mainwindow.h b/examples/assistant/simpletextviewer/mainwindow.h
new file mode 100644
index 0000000000..b56d2017fa
--- /dev/null
+++ b/examples/assistant/simpletextviewer/mainwindow.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QAssistantClient>
+#include <QMainWindow>
+#include <QTextEdit>
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void about();
+//! [0]
+ void assistant();
+//! [0]
+ void open();
+
+protected:
+//! [1]
+ void closeEvent(QCloseEvent *event);
+//! [1]
+
+private:
+ void createActions();
+ void createMenus();
+//! [2]
+ void initializeAssistant();
+//! [2]
+
+//! [3]
+ QAssistantClient *assistantClient;
+//! [3]
+ QTextEdit *textViewer;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+
+ QAction *assistantAct;
+ QAction *clearAct;
+ QAction *openAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/assistant/simpletextviewer/simpletextviewer.pro b/examples/assistant/simpletextviewer/simpletextviewer.pro
new file mode 100644
index 0000000000..4bbdaf1a9d
--- /dev/null
+++ b/examples/assistant/simpletextviewer/simpletextviewer.pro
@@ -0,0 +1,18 @@
+CONFIG += assistant
+
+QT += network
+
+HEADERS = mainwindow.h \
+ findfiledialog.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ findfiledialog.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/assistant/simpletextviewer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES documentation *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/assistant/simpletextviewer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
diff --git a/examples/dbus/complexpingpong/complexping.cpp b/examples/dbus/complexpingpong/complexping.cpp
new file mode 100644
index 0000000000..18fa66dcaa
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexping.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4c2a473244
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexping.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7c46533f9a
--- /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]/dbus/complexpingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/complexpingpong
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..283e440d3e
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexpong.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..5682e99c6f
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexpong.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b4d4d1aa9e
--- /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]/dbus/complexpingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/complexpingpong
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/dbus/complexpingpong/ping-common.h b/examples/dbus/complexpingpong/ping-common.h
new file mode 100644
index 0000000000..06228a9819
--- /dev/null
+++ b/examples/dbus/complexpingpong/ping-common.h
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..1dbc7647b6
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..48b549e2d7
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4292a58d46
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_adaptor.cpp
@@ -0,0 +1,35 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -i chat_adaptor.h -a :chat_adaptor.cpp com.trolltech.chat.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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..9d8e7a6d27
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_adaptor.h
@@ -0,0 +1,57 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -a chat_adaptor.h: com.trolltech.chat.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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_142741156243605
+#define CHAT_ADAPTOR_H_142741156243605
+
+#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..5e2d2a72e9
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_interface.cpp
@@ -0,0 +1,25 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -i chat_interface.h -p :chat_interface.cpp chat/com.trolltech.chat.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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..75140cc24e
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_interface.h
@@ -0,0 +1,49 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -p chat_interface.h: com.trolltech.chat.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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_143021156243606
+#define CHAT_INTERFACE_H_143021156243606
+
+#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..e04c641c5a
--- /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]/dbus/chat
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xml
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/chat
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/dbus/dbus.pro b/examples/dbus/dbus.pro
new file mode 100644
index 0000000000..e4a4f70f88
--- /dev/null
+++ b/examples/dbus/dbus.pro
@@ -0,0 +1,14 @@
+TEMPLATE = subdirs
+SUBDIRS = listnames \
+ pingpong \
+ complexpingpong \
+ dbus-chat \
+ remotecontrolledcar
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/dbus
+sources.files = *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/dbus/listnames/listnames.cpp b/examples/dbus/listnames/listnames.cpp
new file mode 100644
index 0000000000..dca32e6abf
--- /dev/null
+++ b/examples/dbus/listnames/listnames.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b8a648ee3d
--- /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]/dbus/listnames
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/listnames
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
diff --git a/examples/dbus/pingpong/ping-common.h b/examples/dbus/pingpong/ping-common.h
new file mode 100644
index 0000000000..06228a9819
--- /dev/null
+++ b/examples/dbus/pingpong/ping-common.h
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..d773be4453
--- /dev/null
+++ b/examples/dbus/pingpong/ping.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e28060f6f2
--- /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]/dbus/pingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/pingpong
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..fc7800ce15
--- /dev/null
+++ b/examples/dbus/pingpong/pong.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4bc45d8683
--- /dev/null
+++ b/examples/dbus/pingpong/pong.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ed06d222e2
--- /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]/dbus/pingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/pingpong
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/dbus/remotecontrolledcar/car/car.cpp b/examples/dbus/remotecontrolledcar/car/car.cpp
new file mode 100644
index 0000000000..5f3bef9a1a
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..609bc03a44
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CAR_H
+#define CAR_H
+
+#include <QGraphicsItem>
+#include <QObject>
+#include <QBrush>
+
+class Car : public QObject, public QGraphicsItem
+{
+ 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..600c3f2e8b
--- /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_p.h
+SOURCES += car.cpp main.cpp car_adaptor.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/dbus/remotecontrolledcar/car
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.xml
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/remotecontrolledcar/car
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..f0c9aa0c50
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car_adaptor.cpp
@@ -0,0 +1,59 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -c CarAdaptor -a car_adaptor_p.h:car_adaptor.cpp car.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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_p.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 CarAdaptor
+ */
+
+CarAdaptor::CarAdaptor(QObject *parent)
+ : QDBusAbstractAdaptor(parent)
+{
+ // constructor
+ setAutoRelaySignals(true);
+}
+
+CarAdaptor::~CarAdaptor()
+{
+ // destructor
+}
+
+void CarAdaptor::accelerate()
+{
+ // handle method call com.trolltech.Examples.CarInterface.accelerate
+ QMetaObject::invokeMethod(parent(), "accelerate");
+}
+
+void CarAdaptor::decelerate()
+{
+ // handle method call com.trolltech.Examples.CarInterface.decelerate
+ QMetaObject::invokeMethod(parent(), "decelerate");
+}
+
+void CarAdaptor::turnLeft()
+{
+ // handle method call com.trolltech.Examples.CarInterface.turnLeft
+ QMetaObject::invokeMethod(parent(), "turnLeft");
+}
+
+void CarAdaptor::turnRight()
+{
+ // handle method call com.trolltech.Examples.CarInterface.turnRight
+ QMetaObject::invokeMethod(parent(), "turnRight");
+}
+
diff --git a/examples/dbus/remotecontrolledcar/car/car_adaptor_p.h b/examples/dbus/remotecontrolledcar/car/car_adaptor_p.h
new file mode 100644
index 0000000000..39782f5f7f
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car_adaptor_p.h
@@ -0,0 +1,57 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -c CarAdaptor -a car_adaptor_p.h:car_adaptor.cpp car.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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_P_H_1157030132
+#define CAR_ADAPTOR_P_H_1157030132
+
+#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 CarAdaptor: 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:
+ CarAdaptor(QObject *parent);
+ virtual ~CarAdaptor();
+
+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..13a191a63b
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/main.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "car.h"
+#include "car_adaptor_p.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 CarAdaptor(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..daa946745e
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/car_interface.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -c CarInterface -p car_interface_p.h:car_interface.cpp car.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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_p.h"
+
+/*
+ * Implementation of interface class CarInterface
+ */
+
+CarInterface::CarInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+CarInterface::~CarInterface()
+{
+}
+
diff --git a/examples/dbus/remotecontrolledcar/controller/car_interface_p.h b/examples/dbus/remotecontrolledcar/controller/car_interface_p.h
new file mode 100644
index 0000000000..33733124f2
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/car_interface_p.h
@@ -0,0 +1,74 @@
+/*
+ * This file was generated by dbusxml2cpp version 0.6
+ * Command line was: dbusxml2cpp -c CarInterface -p car_interface_p.h:car_interface.cpp car.xml
+ *
+ * dbusxml2cpp is Copyright (C) 2009 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_P_H_1156853585
+#define CAR_INTERFACE_P_H_1156853585
+
+#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 CarInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "com.trolltech.Examples.CarInterface"; }
+
+public:
+ CarInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~CarInterface();
+
+public Q_SLOTS: // METHODS
+ inline QDBusReply<void> accelerate()
+ {
+ QList<QVariant> argumentList;
+ return callWithArgumentList(QDBus::Block, QLatin1String("accelerate"), argumentList);
+ }
+
+ inline QDBusReply<void> decelerate()
+ {
+ QList<QVariant> argumentList;
+ return callWithArgumentList(QDBus::Block, QLatin1String("decelerate"), argumentList);
+ }
+
+ inline QDBusReply<void> turnLeft()
+ {
+ QList<QVariant> argumentList;
+ return callWithArgumentList(QDBus::Block, QLatin1String("turnLeft"), argumentList);
+ }
+
+ inline QDBusReply<void> turnRight()
+ {
+ QList<QVariant> argumentList;
+ return callWithArgumentList(QDBus::Block, QLatin1String("turnRight"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+ void crashed();
+};
+
+namespace com {
+ namespace trolltech {
+ namespace Examples {
+ typedef ::CarInterface CarInterface;
+ }
+ }
+}
+#endif
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.cpp b/examples/dbus/remotecontrolledcar/controller/controller.cpp
new file mode 100644
index 0000000000..7d27bd37a2
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/controller.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "controller.h"
+#include "car_interface_p.h"
+
+Controller::Controller(QWidget *parent)
+ : QWidget(parent)
+{
+ ui.setupUi(this);
+ car = new 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..200ef3c471
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/controller.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONTROLLER_H
+#define CONTROLLER_H
+
+#include "ui_controller.h"
+
+class CarInterface;
+
+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;
+ 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..b31d418421
--- /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_p.h controller.h
+SOURCES += main.cpp car_interface.cpp controller.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/dbus/remotecontrolledcar/controller
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xml
+sources.path = $$[QT_INSTALL_EXAMPLES]/dbus/remotecontrolledcar/controller
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..f28661ef82
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..0df8e1ff2d
--- /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]/dbus/remotecontrolledcar
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/README b/examples/designer/README
new file mode 100644
index 0000000000..fb9443caed
--- /dev/null
+++ b/examples/designer/README
@@ -0,0 +1,37 @@
+Qt Designer is a capable graphical user interface designer that lets you
+create and configure forms without writing code. GUIs created with
+Qt Designer can be compiled into an application or created at run-time.
+
+
+Some of the examples in this directory can be run from the example launcher;
+others can only be used from within Qt Designer.
+
+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/designer/calculatorbuilder/calculatorbuilder.pro b/examples/designer/calculatorbuilder/calculatorbuilder.pro
new file mode 100644
index 0000000000..e08220a0a3
--- /dev/null
+++ b/examples/designer/calculatorbuilder/calculatorbuilder.pro
@@ -0,0 +1,16 @@
+#! [0]
+CONFIG += uitools
+
+HEADERS = calculatorform.h
+RESOURCES = calculatorbuilder.qrc
+SOURCES = calculatorform.cpp \
+ main.cpp
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorbuilder
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.ui *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorbuilder
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/calculatorbuilder/calculatorbuilder.qrc b/examples/designer/calculatorbuilder/calculatorbuilder.qrc
new file mode 100644
index 0000000000..19b39059e7
--- /dev/null
+++ b/examples/designer/calculatorbuilder/calculatorbuilder.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/forms">
+ <file>calculatorform.ui</file>
+</qresource>
+</RCC>
diff --git a/examples/designer/calculatorbuilder/calculatorform.cpp b/examples/designer/calculatorbuilder/calculatorform.cpp
new file mode 100644
index 0000000000..92d75c5d45
--- /dev/null
+++ b/examples/designer/calculatorbuilder/calculatorform.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtUiTools>
+//! [0]
+#include <QtGui>
+
+#include "calculatorform.h"
+
+//! [1]
+CalculatorForm::CalculatorForm(QWidget *parent)
+ : QWidget(parent)
+{
+ QUiLoader loader;
+
+ QFile file(":/forms/calculatorform.ui");
+ file.open(QFile::ReadOnly);
+ QWidget *formWidget = loader.load(&file, this);
+ file.close();
+//! [1]
+
+//! [2]
+ ui_inputSpinBox1 = qFindChild<QSpinBox*>(this, "inputSpinBox1");
+ ui_inputSpinBox2 = qFindChild<QSpinBox*>(this, "inputSpinBox2");
+ ui_outputWidget = qFindChild<QLabel*>(this, "outputWidget");
+//! [2]
+
+//! [3]
+ QMetaObject::connectSlotsByName(this);
+//! [3]
+
+//! [4]
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(formWidget);
+ setLayout(layout);
+
+ setWindowTitle(tr("Calculator Builder"));
+}
+//! [4]
+
+//! [5]
+void CalculatorForm::on_inputSpinBox1_valueChanged(int value)
+{
+ ui_outputWidget->setText(QString::number(value + ui_inputSpinBox2->value()));
+}
+//! [5] //! [6]
+
+//! [6] //! [7]
+void CalculatorForm::on_inputSpinBox2_valueChanged(int value)
+{
+ ui_outputWidget->setText(QString::number(value + ui_inputSpinBox1->value()));
+}
+//! [7]
diff --git a/examples/designer/calculatorbuilder/calculatorform.h b/examples/designer/calculatorbuilder/calculatorform.h
new file mode 100644
index 0000000000..8b322b707e
--- /dev/null
+++ b/examples/designer/calculatorbuilder/calculatorform.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CALCULATORFORM_H
+#define CALCULATORFORM_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QSpinBox;
+QT_END_NAMESPACE
+
+//! [0]
+class CalculatorForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CalculatorForm(QWidget *parent = 0);
+
+private slots:
+ void on_inputSpinBox1_valueChanged(int value);
+ void on_inputSpinBox2_valueChanged(int value);
+
+private:
+ QSpinBox *ui_inputSpinBox1;
+ QSpinBox *ui_inputSpinBox2;
+ QLabel *ui_outputWidget;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/calculatorbuilder/calculatorform.ui b/examples/designer/calculatorbuilder/calculatorform.ui
new file mode 100644
index 0000000000..dda0e62ddd
--- /dev/null
+++ b/examples/designer/calculatorbuilder/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/designer/calculatorbuilder/main.cpp b/examples/designer/calculatorbuilder/main.cpp
new file mode 100644
index 0000000000..56358b8845
--- /dev/null
+++ b/examples/designer/calculatorbuilder/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "calculatorform.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(calculatorbuilder);
+
+ QApplication app(argc, argv);
+ CalculatorForm calculator;
+ calculator.show();
+ return app.exec();
+}
diff --git a/examples/designer/calculatorform/calculatorform.cpp b/examples/designer/calculatorform/calculatorform.cpp
new file mode 100644
index 0000000000..3de2852db8
--- /dev/null
+++ b/examples/designer/calculatorform/calculatorform.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "calculatorform.h"
+
+//! [0]
+CalculatorForm::CalculatorForm(QWidget *parent)
+ : QWidget(parent)
+{
+ ui.setupUi(this);
+}
+//! [0]
+
+//! [1]
+void CalculatorForm::on_inputSpinBox1_valueChanged(int value)
+{
+ ui.outputWidget->setText(QString::number(value + ui.inputSpinBox2->value()));
+}
+//! [1]
+
+//! [2]
+void CalculatorForm::on_inputSpinBox2_valueChanged(int value)
+{
+ ui.outputWidget->setText(QString::number(value + ui.inputSpinBox1->value()));
+}
+//! [2]
diff --git a/examples/designer/calculatorform/calculatorform.h b/examples/designer/calculatorform/calculatorform.h
new file mode 100644
index 0000000000..37f0a18774
--- /dev/null
+++ b/examples/designer/calculatorform/calculatorform.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CALCULATORFORM_H
+#define CALCULATORFORM_H
+
+//! [0]
+#include "ui_calculatorform.h"
+//! [0]
+
+//! [1]
+class CalculatorForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CalculatorForm(QWidget *parent = 0);
+
+private slots:
+ void on_inputSpinBox1_valueChanged(int value);
+ void on_inputSpinBox2_valueChanged(int value);
+
+private:
+ Ui::CalculatorForm ui;
+};
+//! [1]
+
+#endif
diff --git a/examples/designer/calculatorform/calculatorform.pro b/examples/designer/calculatorform/calculatorform.pro
new file mode 100644
index 0000000000..5a133a9cce
--- /dev/null
+++ b/examples/designer/calculatorform/calculatorform.pro
@@ -0,0 +1,15 @@
+#! [0]
+HEADERS = calculatorform.h
+#! [0] #! [1]
+FORMS = calculatorform.ui
+#! [1]
+SOURCES = calculatorform.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorform
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorform
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/calculatorform/calculatorform.ui b/examples/designer/calculatorform/calculatorform.ui
new file mode 100644
index 0000000000..3a956399ae
--- /dev/null
+++ b/examples/designer/calculatorform/calculatorform.ui
@@ -0,0 +1,284 @@
+<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>400</width>
+ <height>300</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 Form</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="6" >
+ <spacer>
+ <property name="objectName" >
+ <string notr="true" >horizontalSpacer</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>239</x>
+ <y>9</y>
+ <width>152</width>
+ <height>52</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>
+ <item row="0" column="4" >
+ <widget class="QLabel" name="label_3_2" >
+ <property name="objectName" >
+ <string notr="true" >label_3_2</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>169</x>
+ <y>9</y>
+ <width>20</width>
+ <height>52</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>=</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="5" >
+ <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>36</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>36</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>
+ <item row="1" column="2" >
+ <spacer>
+ <property name="objectName" >
+ <string notr="true" >verticalSpacer</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>89</x>
+ <y>67</y>
+ <width>20</width>
+ <height>224</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="3" >
+ <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>46</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>46</width>
+ <height>25</height>
+ </rect>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLabel" name="label_3" >
+ <property name="objectName" >
+ <string notr="true" >label_3</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>63</x>
+ <y>9</y>
+ <width>20</width>
+ <height>52</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>+</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <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>46</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>46</width>
+ <height>25</height>
+ </rect>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/designer/calculatorform/main.cpp b/examples/designer/calculatorform/main.cpp
new file mode 100644
index 0000000000..dcb7366cb9
--- /dev/null
+++ b/examples/designer/calculatorform/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "calculatorform.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ CalculatorForm calculator;
+ calculator.show();
+ return app.exec();
+}
+
diff --git a/examples/designer/containerextension/containerextension.pro b/examples/designer/containerextension/containerextension.pro
new file mode 100644
index 0000000000..9b2b8bc959
--- /dev/null
+++ b/examples/designer/containerextension/containerextension.pro
@@ -0,0 +1,28 @@
+#! [0]
+TEMPLATE = lib
+#! [0]
+TARGET = $$qtLibraryTarget($$TARGET)
+#! [1]
+CONFIG += designer plugin
+#! [1]
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
+
+#! [2]
+HEADERS += multipagewidget.h \
+ multipagewidgetplugin.h \
+ multipagewidgetcontainerextension.h \
+ multipagewidgetextensionfactory.h
+
+SOURCES += multipagewidget.cpp \
+ multipagewidgetplugin.cpp \
+ multipagewidgetcontainerextension.cpp \
+ multipagewidgetextensionfactory.cpp
+#! [2]
+
+# install
+target.path = $$[QT_INSTALL_PLUGINS]/designer
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer/containerextension
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/containerextension/multipagewidget.cpp b/examples/designer/containerextension/multipagewidget.cpp
new file mode 100644
index 0000000000..5a3697b358
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidget.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "multipagewidget.h"
+
+MultiPageWidget::MultiPageWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ comboBox = new QComboBox();
+ comboBox->setObjectName("__qt__passive_comboBox");
+ stackWidget = new QStackedWidget();
+
+ connect(comboBox, SIGNAL(activated(int)),
+ this, SLOT(setCurrentIndex(int)));
+
+ layout = new QVBoxLayout();
+ layout->addWidget(comboBox);
+ layout->addWidget(stackWidget);
+ setLayout(layout);
+}
+
+QSize MultiPageWidget::sizeHint() const
+{
+ return QSize(200, 150);
+}
+
+void MultiPageWidget::addPage(QWidget *page)
+{
+ insertPage(count(), page);
+}
+
+void MultiPageWidget::removePage(int index)
+{
+ QWidget *widget = stackWidget->widget(index);
+ stackWidget->removeWidget(widget);
+
+ comboBox->removeItem(index);
+}
+
+int MultiPageWidget::count() const
+{
+ return stackWidget->count();
+}
+
+int MultiPageWidget::currentIndex() const
+{
+ return stackWidget->currentIndex();
+}
+
+void MultiPageWidget::insertPage(int index, QWidget *page)
+{
+ page->setParent(stackWidget);
+
+ stackWidget->insertWidget(index, page);
+
+ QString title = page->windowTitle();
+ if (title.isEmpty()) {
+ title = tr("Page %1").arg(comboBox->count() + 1);
+ page->setWindowTitle(title);
+ }
+ comboBox->insertItem(index, title);
+}
+
+void MultiPageWidget::setCurrentIndex(int index)
+{
+ if (index != currentIndex()) {
+ stackWidget->setCurrentIndex(index);
+ comboBox->setCurrentIndex(index);
+ emit currentIndexChanged(index);
+ }
+}
+
+QWidget* MultiPageWidget::widget(int index)
+{
+ return stackWidget->widget(index);
+}
+
+QString MultiPageWidget::pageTitle() const
+{
+ if (const QWidget *currentWidget = stackWidget->currentWidget())
+ return currentWidget->windowTitle();
+ return QString();
+}
+
+void MultiPageWidget::setPageTitle(QString const &newTitle)
+{
+ comboBox->setItemText(currentIndex(), newTitle);
+ if (QWidget *currentWidget = stackWidget->currentWidget())
+ currentWidget->setWindowTitle(newTitle);
+ emit pageTitleChanged(newTitle);
+}
diff --git a/examples/designer/containerextension/multipagewidget.h b/examples/designer/containerextension/multipagewidget.h
new file mode 100644
index 0000000000..77a09c5ff4
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidget.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MULTIPAGEWIDGET_H
+#define MULTIPAGEWIDGET_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QStackedWidget;
+class QVBoxLayout;
+QT_END_NAMESPACE
+
+//! [0]
+class MultiPageWidget : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex)
+ Q_PROPERTY(QString pageTitle READ pageTitle WRITE setPageTitle STORED false)
+
+public:
+ MultiPageWidget(QWidget *parent = 0);
+
+ QSize sizeHint() const;
+
+ int count() const;
+ int currentIndex() const;
+ QWidget *widget(int index);
+ QString pageTitle() const;
+
+public slots:
+ void addPage(QWidget *page);
+ void insertPage(int index, QWidget *page);
+ void removePage(int index);
+ void setPageTitle(QString const &newTitle);
+ void setCurrentIndex(int index);
+
+signals:
+ void currentIndexChanged(int index);
+ void pageTitleChanged(const QString &title);
+
+private:
+ QStackedWidget *stackWidget;
+ QComboBox *comboBox;
+ QVBoxLayout *layout;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/containerextension/multipagewidgetcontainerextension.cpp b/examples/designer/containerextension/multipagewidgetcontainerextension.cpp
new file mode 100644
index 0000000000..b61da3daf5
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidgetcontainerextension.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "multipagewidgetcontainerextension.h"
+#include "multipagewidget.h"
+
+//! [0]
+MultiPageWidgetContainerExtension::MultiPageWidgetContainerExtension(MultiPageWidget *widget,
+ QObject *parent)
+ :QObject(parent)
+{
+ myWidget = widget;
+}
+//! [0]
+
+//! [1]
+void MultiPageWidgetContainerExtension::addWidget(QWidget *widget)
+{
+ myWidget->addPage(widget);
+}
+//! [1]
+
+//! [2]
+int MultiPageWidgetContainerExtension::count() const
+{
+ return myWidget->count();
+}
+//! [2]
+
+//! [3]
+int MultiPageWidgetContainerExtension::currentIndex() const
+{
+ return myWidget->currentIndex();
+}
+//! [3]
+
+//! [4]
+void MultiPageWidgetContainerExtension::insertWidget(int index, QWidget *widget)
+{
+ myWidget->insertPage(index, widget);
+}
+//! [4]
+
+//! [5]
+void MultiPageWidgetContainerExtension::remove(int index)
+{
+ myWidget->removePage(index);
+}
+//! [5]
+
+//! [6]
+void MultiPageWidgetContainerExtension::setCurrentIndex(int index)
+{
+ myWidget->setCurrentIndex(index);
+}
+//! [6]
+
+//! [7]
+QWidget* MultiPageWidgetContainerExtension::widget(int index) const
+{
+ return myWidget->widget(index);
+}
+//! [7]
diff --git a/examples/designer/containerextension/multipagewidgetcontainerextension.h b/examples/designer/containerextension/multipagewidgetcontainerextension.h
new file mode 100644
index 0000000000..661146e0d1
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidgetcontainerextension.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MULTIPAGEWIDGETCONTAINEREXTENSION_H
+#define MULTIPAGEWIDGETCONTAINEREXTENSION_H
+
+#include <QtDesigner/QDesignerContainerExtension>
+
+QT_BEGIN_NAMESPACE
+class QExtensionManager;
+QT_END_NAMESPACE
+class MultiPageWidget;
+
+//! [0]
+class MultiPageWidgetContainerExtension: public QObject,
+ public QDesignerContainerExtension
+{
+ Q_OBJECT
+ Q_INTERFACES(QDesignerContainerExtension)
+
+public:
+ MultiPageWidgetContainerExtension(MultiPageWidget *widget, QObject *parent);
+
+ void addWidget(QWidget *widget);
+ int count() const;
+ int currentIndex() const;
+ void insertWidget(int index, QWidget *widget);
+ void remove(int index);
+ void setCurrentIndex(int index);
+ QWidget *widget(int index) const;
+
+private:
+ MultiPageWidget *myWidget;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/containerextension/multipagewidgetextensionfactory.cpp b/examples/designer/containerextension/multipagewidgetextensionfactory.cpp
new file mode 100644
index 0000000000..4a1e81b3d8
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidgetextensionfactory.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "multipagewidgetextensionfactory.h"
+#include "multipagewidgetcontainerextension.h"
+#include "multipagewidget.h"
+
+//! [0]
+MultiPageWidgetExtensionFactory::MultiPageWidgetExtensionFactory(QExtensionManager *parent)
+ : QExtensionFactory(parent)
+{}
+//! [0]
+
+//! [1]
+QObject *MultiPageWidgetExtensionFactory::createExtension(QObject *object,
+ const QString &iid,
+ QObject *parent) const
+{
+ MultiPageWidget *widget = qobject_cast<MultiPageWidget*>(object);
+
+ if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
+ return new MultiPageWidgetContainerExtension(widget, parent);
+ } else {
+ return 0;
+ }
+}
+//! [1]
diff --git a/examples/designer/containerextension/multipagewidgetextensionfactory.h b/examples/designer/containerextension/multipagewidgetextensionfactory.h
new file mode 100644
index 0000000000..9a96b37023
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidgetextensionfactory.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MULTIPAGEWIDGETEXTENSIONFACTORY_H
+#define MULTIPAGEWIDGETEXTENSIONFACTORY_H
+
+#include <QtDesigner/QExtensionFactory>
+
+QT_BEGIN_NAMESPACE
+class QExtensionManager;
+QT_END_NAMESPACE
+
+//! [0]
+class MultiPageWidgetExtensionFactory: public QExtensionFactory
+{
+ Q_OBJECT
+
+public:
+ MultiPageWidgetExtensionFactory(QExtensionManager *parent = 0);
+
+protected:
+ QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/containerextension/multipagewidgetplugin.cpp b/examples/designer/containerextension/multipagewidgetplugin.cpp
new file mode 100644
index 0000000000..c09ed3afab
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidgetplugin.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDesigner/QExtensionFactory>
+#include <QtDesigner/QExtensionManager>
+#include <QtDesigner/QDesignerFormEditorInterface>
+#include <QtDesigner/QDesignerFormWindowInterface>
+#include <QtDesigner/QDesignerContainerExtension>
+#include <QtDesigner/QDesignerPropertySheetExtension>
+
+#include <QIcon>
+#include <QtPlugin>
+
+#include "multipagewidget.h"
+#include "multipagewidgetplugin.h"
+#include "multipagewidgetextensionfactory.h"
+
+//! [0]
+MultiPageWidgetPlugin::MultiPageWidgetPlugin(QObject *parent)
+ :QObject(parent)
+{
+ initialized = false;
+}
+
+QString MultiPageWidgetPlugin::name() const
+{
+ return QLatin1String("MultiPageWidget");
+}
+
+QString MultiPageWidgetPlugin::group() const
+{
+ return QLatin1String("Display Widgets [Examples]");
+}
+
+QString MultiPageWidgetPlugin::toolTip() const
+{
+ return QString();
+}
+
+QString MultiPageWidgetPlugin::whatsThis() const
+{
+ return QString();
+}
+
+QString MultiPageWidgetPlugin::includeFile() const
+{
+ return QLatin1String("multipagewidget.h");
+}
+
+QIcon MultiPageWidgetPlugin::icon() const
+{
+ return QIcon();
+}
+
+//! [0] //! [1]
+bool MultiPageWidgetPlugin::isContainer() const
+{
+ return true;
+}
+
+//! [1] //! [2]
+QWidget *MultiPageWidgetPlugin::createWidget(QWidget *parent)
+{
+ MultiPageWidget *widget = new MultiPageWidget(parent);
+ connect(widget, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(currentIndexChanged(int)));
+ connect(widget, SIGNAL(pageTitleChanged(const QString &)),
+ this, SLOT(pageTitleChanged(const QString &)));
+ return widget;
+}
+
+//! [2] //! [3]
+bool MultiPageWidgetPlugin::isInitialized() const
+{
+ return initialized;
+}
+//! [3]
+
+//! [4]
+void MultiPageWidgetPlugin::initialize(QDesignerFormEditorInterface *formEditor)
+{
+ if (initialized)
+ return;
+//! [4]
+
+//! [5]
+ QExtensionManager *manager = formEditor->extensionManager();
+//! [5] //! [6]
+ QExtensionFactory *factory = new MultiPageWidgetExtensionFactory(manager);
+
+ Q_ASSERT(manager != 0);
+ manager->registerExtensions(factory, Q_TYPEID(QDesignerContainerExtension));
+
+ initialized = true;
+}
+//! [6]
+
+//! [7]
+QString MultiPageWidgetPlugin::domXml() const
+{
+ return QLatin1String("\
+<ui language=\"c++\">\
+ <widget class=\"MultiPageWidget\" name=\"multipagewidget\">\
+ <widget class=\"QWidget\" name=\"page\" />\
+ </widget>\
+ <customwidgets>\
+ <customwidget>\
+ <class>MultiPageWidget</class>\
+ <extends>QWidget</extends>\
+ <addpagemethod>addPage</addpagemethod>\
+ </customwidget>\
+ </customwidgets>\
+</ui>");
+}
+//! [7]
+
+//! [8]
+void MultiPageWidgetPlugin::currentIndexChanged(int index)
+{
+ Q_UNUSED(index);
+ MultiPageWidget *widget = qobject_cast<MultiPageWidget*>(sender());
+//! [8] //! [9]
+ if (widget) {
+ QDesignerFormWindowInterface *form = QDesignerFormWindowInterface::findFormWindow(widget);
+ if (form)
+ form->emitSelectionChanged();
+ }
+}
+//! [9]
+
+//! [10]
+void MultiPageWidgetPlugin::pageTitleChanged(const QString &title)
+{
+ Q_UNUSED(title);
+ MultiPageWidget *widget = qobject_cast<MultiPageWidget*>(sender());
+//! [10] //! [11]
+ if (widget) {
+ QWidget *page = widget->widget(widget->currentIndex());
+ QDesignerFormWindowInterface *form;
+ form = QDesignerFormWindowInterface::findFormWindow(widget);
+//! [11]
+ if (form) {
+//! [12]
+ QDesignerFormEditorInterface *editor = form->core();
+ QExtensionManager *manager = editor->extensionManager();
+//! [12] //! [13]
+ QDesignerPropertySheetExtension *sheet;
+ sheet = qt_extension<QDesignerPropertySheetExtension*>(manager, page);
+ const int propertyIndex = sheet->indexOf(QLatin1String("windowTitle"));
+ sheet->setChanged(propertyIndex, true);
+ }
+ }
+}
+
+//! [13]
+
+//! [14]
+Q_EXPORT_PLUGIN2(containerextension, MultiPageWidgetPlugin)
+//! [14]
diff --git a/examples/designer/containerextension/multipagewidgetplugin.h b/examples/designer/containerextension/multipagewidgetplugin.h
new file mode 100644
index 0000000000..1431c8a3ef
--- /dev/null
+++ b/examples/designer/containerextension/multipagewidgetplugin.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#ifndef MULTIPAGEWIDGETPLUGIN_H
+#define MULTIPAGEWIDGETPLUGIN_H
+
+#include <QtDesigner/QDesignerCustomWidgetInterface>
+
+QT_BEGIN_NAMESPACE
+class QIcon;
+class QWidget;
+QT_END_NAMESPACE
+
+class MultiPageWidgetPlugin: public QObject, public QDesignerCustomWidgetInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QDesignerCustomWidgetInterface)
+public:
+ MultiPageWidgetPlugin(QObject *parent = 0);
+
+ QString name() const;
+ QString group() const;
+ QString toolTip() const;
+ QString whatsThis() const;
+ QString includeFile() const;
+ QIcon icon() const;
+ bool isContainer() const;
+ QWidget *createWidget(QWidget *parent);
+ bool isInitialized() const;
+ void initialize(QDesignerFormEditorInterface *formEditor);
+ QString domXml() const;
+
+private slots:
+ void currentIndexChanged(int index);
+ void pageTitleChanged(const QString &title);
+
+private:
+ bool initialized;
+};
+
+#endif
+//! [0]
diff --git a/examples/designer/customwidgetplugin/analogclock.cpp b/examples/designer/customwidgetplugin/analogclock.cpp
new file mode 100644
index 0000000000..28155ba0e7
--- /dev/null
+++ b/examples/designer/customwidgetplugin/analogclock.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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/designer/customwidgetplugin/analogclock.h b/examples/designer/customwidgetplugin/analogclock.h
new file mode 100644
index 0000000000..4d843ad6dd
--- /dev/null
+++ b/examples/designer/customwidgetplugin/analogclock.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANALOGCLOCK_H
+#define ANALOGCLOCK_H
+
+#include <QWidget>
+#include <QtDesigner/QDesignerExportWidget>
+
+class QDESIGNER_WIDGET_EXPORT AnalogClock : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AnalogClock(QWidget *parent = 0);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+};
+
+#endif
diff --git a/examples/designer/customwidgetplugin/customwidgetplugin.cpp b/examples/designer/customwidgetplugin/customwidgetplugin.cpp
new file mode 100644
index 0000000000..bcea3b84a1
--- /dev/null
+++ b/examples/designer/customwidgetplugin/customwidgetplugin.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "analogclock.h"
+#include "customwidgetplugin.h"
+
+#include <QtPlugin>
+
+//! [0]
+AnalogClockPlugin::AnalogClockPlugin(QObject *parent)
+ : QObject(parent)
+{
+ initialized = false;
+}
+//! [0]
+
+//! [1]
+void AnalogClockPlugin::initialize(QDesignerFormEditorInterface * /* core */)
+{
+ if (initialized)
+ return;
+
+ initialized = true;
+}
+//! [1]
+
+//! [2]
+bool AnalogClockPlugin::isInitialized() const
+{
+ return initialized;
+}
+//! [2]
+
+//! [3]
+QWidget *AnalogClockPlugin::createWidget(QWidget *parent)
+{
+ return new AnalogClock(parent);
+}
+//! [3]
+
+//! [4]
+QString AnalogClockPlugin::name() const
+{
+ return "AnalogClock";
+}
+//! [4]
+
+//! [5]
+QString AnalogClockPlugin::group() const
+{
+ return "Display Widgets [Examples]";
+}
+//! [5]
+
+//! [6]
+QIcon AnalogClockPlugin::icon() const
+{
+ return QIcon();
+}
+//! [6]
+
+//! [7]
+QString AnalogClockPlugin::toolTip() const
+{
+ return "";
+}
+//! [7]
+
+//! [8]
+QString AnalogClockPlugin::whatsThis() const
+{
+ return "";
+}
+//! [8]
+
+//! [9]
+bool AnalogClockPlugin::isContainer() const
+{
+ return false;
+}
+//! [9]
+
+//! [10]
+QString AnalogClockPlugin::domXml() const
+{
+ return "<ui language=\"c++\">\n"
+ " <widget class=\"AnalogClock\" name=\"analogClock\">\n"
+//! [11]
+ " <property name=\"geometry\">\n"
+ " <rect>\n"
+ " <x>0</x>\n"
+ " <y>0</y>\n"
+ " <width>100</width>\n"
+ " <height>100</height>\n"
+ " </rect>\n"
+ " </property>\n"
+//! [11]
+ " <property name=\"toolTip\" >\n"
+ " <string>The current time</string>\n"
+ " </property>\n"
+ " <property name=\"whatsThis\" >\n"
+ " <string>The analog clock widget displays the current time.</string>\n"
+ " </property>\n"
+ " </widget>\n"
+ "</ui>\n";
+}
+//! [10]
+
+//! [12]
+QString AnalogClockPlugin::includeFile() const
+{
+ return "analogclock.h";
+}
+//! [12]
+
+//! [13]
+Q_EXPORT_PLUGIN2(customwidgetplugin, AnalogClockPlugin)
+//! [13]
diff --git a/examples/designer/customwidgetplugin/customwidgetplugin.h b/examples/designer/customwidgetplugin/customwidgetplugin.h
new file mode 100644
index 0000000000..4438690bce
--- /dev/null
+++ b/examples/designer/customwidgetplugin/customwidgetplugin.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CUSTOMWIDGETPLUGIN_H
+#define CUSTOMWIDGETPLUGIN_H
+
+#include <QDesignerCustomWidgetInterface>
+
+//! [0]
+class AnalogClockPlugin : public QObject, public QDesignerCustomWidgetInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QDesignerCustomWidgetInterface)
+
+public:
+ AnalogClockPlugin(QObject *parent = 0);
+
+ bool isContainer() const;
+ bool isInitialized() const;
+ QIcon icon() const;
+ QString domXml() const;
+ QString group() const;
+ QString includeFile() const;
+ QString name() const;
+ QString toolTip() const;
+ QString whatsThis() const;
+ QWidget *createWidget(QWidget *parent);
+ void initialize(QDesignerFormEditorInterface *core);
+
+private:
+ bool initialized;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/customwidgetplugin/customwidgetplugin.pro b/examples/designer/customwidgetplugin/customwidgetplugin.pro
new file mode 100644
index 0000000000..6cc376f0c7
--- /dev/null
+++ b/examples/designer/customwidgetplugin/customwidgetplugin.pro
@@ -0,0 +1,23 @@
+#! [0] #! [1]
+CONFIG += designer plugin
+#! [0]
+TARGET = $$qtLibraryTarget($$TARGET)
+#! [2]
+TEMPLATE = lib
+#! [1] #! [2]
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
+
+#! [3]
+HEADERS = analogclock.h \
+ customwidgetplugin.h
+SOURCES = analogclock.cpp \
+ customwidgetplugin.cpp
+#! [3]
+
+# install
+target.path = $$[QT_INSTALL_PLUGINS]/designer
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer/customwidgetplugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/designer.pro b/examples/designer/designer.pro
new file mode 100644
index 0000000000..b7eacc086a
--- /dev/null
+++ b/examples/designer/designer.pro
@@ -0,0 +1,21 @@
+TEMPLATE = subdirs
+SUBDIRS = calculatorform
+
+!static:SUBDIRS += calculatorbuilder \
+ containerextension \
+ customwidgetplugin \
+ taskmenuextension \
+ worldtimeclockbuilder \
+ worldtimeclockplugin
+
+# the sun cc compiler has a problem with the include lines for the form.prf
+solaris-cc*:SUBDIRS -= calculatorbuilder \
+ worldtimeclockbuilder
+
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/taskmenuextension/taskmenuextension.pro b/examples/designer/taskmenuextension/taskmenuextension.pro
new file mode 100644
index 0000000000..89c0c44f2c
--- /dev/null
+++ b/examples/designer/taskmenuextension/taskmenuextension.pro
@@ -0,0 +1,27 @@
+#! [0]
+TEMPLATE = lib
+#! [0]
+TARGET = $$qtLibraryTarget($$TARGET)
+#! [1]
+CONFIG += designer plugin
+#! [1]
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
+
+#! [2]
+HEADERS += tictactoe.h \
+ tictactoedialog.h \
+ tictactoeplugin.h \
+ tictactoetaskmenu.h
+SOURCES += tictactoe.cpp \
+ tictactoedialog.cpp \
+ tictactoeplugin.cpp \
+ tictactoetaskmenu.cpp
+#! [2]
+
+# install
+target.path = $$[QT_INSTALL_PLUGINS]/designer
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer/taskmenuextension
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/taskmenuextension/tictactoe.cpp b/examples/designer/taskmenuextension/tictactoe.cpp
new file mode 100644
index 0000000000..ba766ccd36
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoe.cpp
@@ -0,0 +1,176 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "tictactoe.h"
+
+TicTacToe::TicTacToe(QWidget *parent)
+ : QWidget(parent)
+{
+}
+
+QSize TicTacToe::minimumSizeHint() const
+{
+ return QSize(200, 200);
+}
+
+QSize TicTacToe::sizeHint() const
+{
+ return QSize(200, 200);
+}
+
+void TicTacToe::setState(const QString &newState)
+{
+ turnNumber = 0;
+ myState = "---------";
+ int position = 0;
+ while (position < 9 && position < newState.length()) {
+ QChar mark = newState.at(position);
+ if (mark == Cross || mark == Nought) {
+ ++turnNumber;
+ myState.replace(position, 1, mark);
+ }
+ position++;
+ }
+ update();
+}
+
+QString TicTacToe::state() const
+{
+ return myState;
+}
+
+void TicTacToe::clearBoard()
+{
+ myState = "---------";
+ turnNumber = 0;
+ update();
+}
+
+void TicTacToe::mousePressEvent(QMouseEvent *event)
+{
+ if (turnNumber == 9) {
+ clearBoard();
+ update();
+ } else {
+ for (int position = 0; position < 9; ++position) {
+ QRect cell = cellRect(position / 3, position % 3);
+ if (cell.contains(event->pos())) {
+ if (myState.at(position) == Empty) {
+ if (turnNumber % 2 == 0)
+ myState.replace(position, 1, Cross);
+ else
+ myState.replace(position, 1, Nought);
+ ++turnNumber;
+ update();
+ }
+ }
+ }
+ }
+}
+
+void TicTacToe::paintEvent(QPaintEvent * /* event */)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ painter.setPen(QPen(Qt::darkGreen, 1));
+ painter.drawLine(cellWidth(), 0, cellWidth(), height());
+ painter.drawLine(2 * cellWidth(), 0, 2 * cellWidth(), height());
+ painter.drawLine(0, cellHeight(), width(), cellHeight());
+ painter.drawLine(0, 2 * cellHeight(), width(), 2 * cellHeight());
+
+ painter.setPen(QPen(Qt::darkBlue, 2));
+
+ for (int position = 0; position < 9; ++position) {
+ QRect cell = cellRect(position / 3, position % 3);
+
+ if (myState.at(position) == Cross) {
+ painter.drawLine(cell.topLeft(), cell.bottomRight());
+ painter.drawLine(cell.topRight(), cell.bottomLeft());
+ } else if (myState.at(position) == Nought) {
+ painter.drawEllipse(cell);
+ }
+ }
+
+ painter.setPen(QPen(Qt::yellow, 3));
+
+ for (int position = 0; position < 9; position = position + 3) {
+ if (myState.at(position) != Empty
+ && myState.at(position + 1) == myState.at(position)
+ && myState.at(position + 2) == myState.at(position)) {
+ int y = cellRect((position / 3), 0).center().y();
+ painter.drawLine(0, y, width(), y);
+ turnNumber = 9;
+ }
+ }
+
+ for (int position = 0; position < 3; ++position) {
+ if (myState.at(position) != Empty
+ && myState.at(position + 3) == myState.at(position)
+ && myState.at(position + 6) == myState.at(position)) {
+ int x = cellRect(0, position).center().x();
+ painter.drawLine(x, 0, x, height());
+ turnNumber = 9;
+ }
+ }
+ if (myState.at(0) != Empty && myState.at(4) == myState.at(0)
+ && myState.at(8) == myState.at(0)) {
+ painter.drawLine(0, 0, width(), height());
+ turnNumber = 9;
+ }
+ if (myState.at(2) != Empty && myState.at(4) == myState.at(2)
+ && myState.at(6) == myState.at(2)) {
+ painter.drawLine(0, height(), width(), 0);
+ turnNumber = 9;
+ }
+}
+
+QRect TicTacToe::cellRect(int row, int column) const
+{
+ const int HMargin = width() / 30;
+ const int VMargin = height() / 30;
+ return QRect(column * cellWidth() + HMargin,
+ row * cellHeight() + VMargin,
+ cellWidth() - 2 * HMargin,
+ cellHeight() - 2 * VMargin);
+}
diff --git a/examples/designer/taskmenuextension/tictactoe.h b/examples/designer/taskmenuextension/tictactoe.h
new file mode 100644
index 0000000000..ef3c533e57
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoe.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TICTACTOE_H
+#define TICTACTOE_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QRect;
+class QSize;
+QT_END_NAMESPACE
+
+//! [0]
+class TicTacToe : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(QString state READ state WRITE setState)
+
+public:
+ TicTacToe(QWidget *parent = 0);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+ void setState(const QString &newState);
+ QString state() const;
+ void clearBoard();
+
+protected:
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+private:
+ enum { Empty = '-', Cross = 'X', Nought = 'O' };
+
+ QRect cellRect(int row, int col) const;
+ int cellWidth() const { return width() / 3; }
+ int cellHeight() const { return height() / 3; }
+
+ QString myState;
+ int turnNumber;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/taskmenuextension/tictactoedialog.cpp b/examples/designer/taskmenuextension/tictactoedialog.cpp
new file mode 100644
index 0000000000..a9bd16a084
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoedialog.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtDesigner>
+
+#include "tictactoe.h"
+#include "tictactoedialog.h"
+
+//! [0]
+TicTacToeDialog::TicTacToeDialog(TicTacToe *tic, QWidget *parent)
+ : QDialog(parent)
+{
+ ticTacToe = tic;
+ editor = new TicTacToe;
+ editor->setState(ticTacToe->state());
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel
+ | QDialogButtonBox::Reset);
+
+ connect(buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
+ this, SLOT(resetState()));
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(saveState()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(editor);
+ mainLayout->addWidget(buttonBox);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Edit State"));
+}
+//! [0]
+
+//! [1]
+QSize TicTacToeDialog::sizeHint() const
+{
+ return QSize(250, 250);
+}
+//! [1]
+
+//! [2]
+void TicTacToeDialog::resetState()
+{
+ editor->clearBoard();
+}
+//! [2]
+
+//! [3]
+void TicTacToeDialog::saveState()
+{
+//! [3] //! [4]
+ if (QDesignerFormWindowInterface *formWindow
+ = QDesignerFormWindowInterface::findFormWindow(ticTacToe)) {
+ formWindow->cursor()->setProperty("state", editor->state());
+ }
+//! [4] //! [5]
+ accept();
+}
+//! [5]
diff --git a/examples/designer/taskmenuextension/tictactoedialog.h b/examples/designer/taskmenuextension/tictactoedialog.h
new file mode 100644
index 0000000000..55b25d29b5
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoedialog.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TICTACTOEDIALOG_H
+#define TICTACTOEDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+QT_END_NAMESPACE
+class TicTacToe;
+
+//! [0]
+class TicTacToeDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ TicTacToeDialog(TicTacToe *plugin = 0, QWidget *parent = 0);
+
+ QSize sizeHint() const;
+
+private slots:
+ void resetState();
+ void saveState();
+
+private:
+ TicTacToe *editor;
+ TicTacToe *ticTacToe;
+ QDialogButtonBox *buttonBox;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/taskmenuextension/tictactoeplugin.cpp b/examples/designer/taskmenuextension/tictactoeplugin.cpp
new file mode 100644
index 0000000000..1333090406
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoeplugin.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDesigner>
+#include <QtGui>
+#include <QtPlugin>
+
+#include "tictactoe.h"
+#include "tictactoeplugin.h"
+#include "tictactoetaskmenu.h"
+
+//! [0]
+TicTacToePlugin::TicTacToePlugin(QObject *parent)
+ : QObject(parent)
+{
+ initialized = false;
+}
+
+QString TicTacToePlugin::name() const
+{
+ return "TicTacToe";
+}
+
+QString TicTacToePlugin::group() const
+{
+ return "Display Widgets [Examples]";
+}
+
+QString TicTacToePlugin::toolTip() const
+{
+ return "";
+}
+
+QString TicTacToePlugin::whatsThis() const
+{
+ return "";
+}
+
+QString TicTacToePlugin::includeFile() const
+{
+ return "tictactoe.h";
+}
+
+QIcon TicTacToePlugin::icon() const
+{
+ return QIcon();
+}
+
+bool TicTacToePlugin::isContainer() const
+{
+ return false;
+}
+
+QWidget *TicTacToePlugin::createWidget(QWidget *parent)
+{
+ TicTacToe *ticTacToe = new TicTacToe(parent);
+ ticTacToe->setState("-X-XO----");
+ return ticTacToe;
+}
+
+bool TicTacToePlugin::isInitialized() const
+{
+ return initialized;
+}
+
+//! [0] //! [1]
+void TicTacToePlugin::initialize(QDesignerFormEditorInterface *formEditor)
+{
+//! [1] //! [2]
+ if (initialized)
+ return;
+
+ QExtensionManager *manager = formEditor->extensionManager();
+ Q_ASSERT(manager != 0);
+//! [2]
+
+//! [3]
+ manager->registerExtensions(new TicTacToeTaskMenuFactory(manager),
+ Q_TYPEID(QDesignerTaskMenuExtension));
+
+ initialized = true;
+}
+
+QString TicTacToePlugin::domXml() const
+{
+ return QLatin1String("\
+<ui language=\"c++\">\
+ <widget class=\"TicTacToe\" name=\"ticTacToe\"/>\
+</ui>");
+}
+
+//! [3]
+
+//! [4]
+Q_EXPORT_PLUGIN2(taskmenuextension, TicTacToePlugin)
+//! [4]
diff --git a/examples/designer/taskmenuextension/tictactoeplugin.h b/examples/designer/taskmenuextension/tictactoeplugin.h
new file mode 100644
index 0000000000..b51540ef63
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoeplugin.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#ifndef TICTACTOEPLUGIN_H
+#define TICTACTOEPLUGIN_H
+
+#include <QDesignerCustomWidgetInterface>
+
+QT_BEGIN_NAMESPACE
+class QIcon;
+class QWidget;
+QT_END_NAMESPACE
+
+class TicTacToePlugin : public QObject, public QDesignerCustomWidgetInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QDesignerCustomWidgetInterface)
+
+public:
+ TicTacToePlugin(QObject *parent = 0);
+
+ QString name() const;
+ QString group() const;
+ QString toolTip() const;
+ QString whatsThis() const;
+ QString includeFile() const;
+ QIcon icon() const;
+ bool isContainer() const;
+ QWidget *createWidget(QWidget *parent);
+ bool isInitialized() const;
+ void initialize(QDesignerFormEditorInterface *formEditor);
+ QString domXml() const;
+
+private:
+ bool initialized;
+};
+
+#endif
+//! [0]
diff --git a/examples/designer/taskmenuextension/tictactoetaskmenu.cpp b/examples/designer/taskmenuextension/tictactoetaskmenu.cpp
new file mode 100644
index 0000000000..af5401a899
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoetaskmenu.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDesigner>
+#include <QtGui>
+
+#include "tictactoe.h"
+#include "tictactoedialog.h"
+#include "tictactoetaskmenu.h"
+
+//! [0]
+TicTacToeTaskMenu::TicTacToeTaskMenu(TicTacToe *tic, QObject *parent)
+ : QObject(parent)
+{
+ ticTacToe = tic;
+
+ editStateAction = new QAction(tr("Edit State..."), this);
+ connect(editStateAction, SIGNAL(triggered()), this, SLOT(editState()));
+}
+//! [0]
+
+//! [1]
+void TicTacToeTaskMenu::editState()
+{
+ TicTacToeDialog dialog(ticTacToe);
+ dialog.exec();
+}
+//! [1]
+
+//! [2]
+QAction *TicTacToeTaskMenu::preferredEditAction() const
+{
+ return editStateAction;
+}
+//! [2]
+
+//! [3]
+QList<QAction *> TicTacToeTaskMenu::taskActions() const
+{
+ QList<QAction *> list;
+ list.append(editStateAction);
+ return list;
+}
+//! [3]
+
+//! [4]
+TicTacToeTaskMenuFactory::TicTacToeTaskMenuFactory(QExtensionManager *parent)
+ : QExtensionFactory(parent)
+{
+}
+//! [4]
+
+//! [5]
+QObject *TicTacToeTaskMenuFactory::createExtension(QObject *object,
+ const QString &iid,
+ QObject *parent) const
+{
+ if (iid != Q_TYPEID(QDesignerTaskMenuExtension))
+ return 0;
+
+ if (TicTacToe *tic = qobject_cast<TicTacToe*>(object))
+ return new TicTacToeTaskMenu(tic, parent);
+
+ return 0;
+}
+//! [5]
diff --git a/examples/designer/taskmenuextension/tictactoetaskmenu.h b/examples/designer/taskmenuextension/tictactoetaskmenu.h
new file mode 100644
index 0000000000..4bd317022f
--- /dev/null
+++ b/examples/designer/taskmenuextension/tictactoetaskmenu.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TICTACTOETASKMENU_H
+#define TICTACTOETASKMENU_H
+
+#include <QDesignerTaskMenuExtension>
+#include <QExtensionFactory>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QExtensionManager;
+QT_END_NAMESPACE
+class TicTacToe;
+
+//! [0]
+class TicTacToeTaskMenu : public QObject, public QDesignerTaskMenuExtension
+{
+ Q_OBJECT
+ Q_INTERFACES(QDesignerTaskMenuExtension)
+
+public:
+ TicTacToeTaskMenu(TicTacToe *tic, QObject *parent);
+
+ QAction *preferredEditAction() const;
+ QList<QAction *> taskActions() const;
+
+private slots:
+ void editState();
+
+private:
+ QAction *editStateAction;
+ TicTacToe *ticTacToe;
+};
+//! [0]
+
+//! [1]
+class TicTacToeTaskMenuFactory : public QExtensionFactory
+{
+ Q_OBJECT
+
+public:
+ TicTacToeTaskMenuFactory(QExtensionManager *parent = 0);
+
+protected:
+ QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
+};
+//! [1]
+
+#endif
diff --git a/examples/designer/worldtimeclockbuilder/form.ui b/examples/designer/worldtimeclockbuilder/form.ui
new file mode 100644
index 0000000000..e5be1d911f
--- /dev/null
+++ b/examples/designer/worldtimeclockbuilder/form.ui
@@ -0,0 +1,162 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>WorldTimeForm</class>
+ <widget class="QWidget" name="WorldTimeForm" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>World Time Clock</string>
+ </property>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="WorldTimeClock" name="worldTimeClock" />
+ </item>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Current time:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTimeEdit" name="timeEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Set time zone:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="spinBox" >
+ <property name="maximum" >
+ <number>12</number>
+ </property>
+ <property name="minimum" >
+ <number>-12</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <pixmapfunction></pixmapfunction>
+ <customwidgets>
+ <customwidget>
+ <class>WorldTimeClock</class>
+ <extends></extends>
+ <header>worldtimeclock.h</header>
+ <container>0</container>
+ <pixmap></pixmap>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>spinBox</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>worldTimeClock</receiver>
+ <slot>setTimeZone(int)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>339</x>
+ <y>166</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>230</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>worldTimeClock</sender>
+ <signal>updated(QTime)</signal>
+ <receiver>timeEdit</receiver>
+ <slot>setTime(QTime)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>141</x>
+ <y>59</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>291</x>
+ <y>133</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/designer/worldtimeclockbuilder/main.cpp b/examples/designer/worldtimeclockbuilder/main.cpp
new file mode 100644
index 0000000000..35f7dc05d0
--- /dev/null
+++ b/examples/designer/worldtimeclockbuilder/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtUiTools>
+//! [0]
+#include <QtGui>
+
+//! [1]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(worldtimeclockbuilder);
+
+ QApplication app(argc, argv);
+
+ QUiLoader loader;
+//! [1]
+
+//! [2]
+ QFile file(":/forms/form.ui");
+ file.open(QFile::ReadOnly);
+
+ QWidget *widget = loader.load(&file);
+
+ file.close();
+ widget->show();
+//! [2]
+
+//! [3]
+ return app.exec();
+}
+//! [3]
diff --git a/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro
new file mode 100644
index 0000000000..0123fd13b3
--- /dev/null
+++ b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro
@@ -0,0 +1,13 @@
+#! [0]
+CONFIG += uitools
+SOURCES = main.cpp
+RESOURCES = worldtimeclockbuilder.qrc
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockbuilder
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.ui *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockbuilder
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc
new file mode 100644
index 0000000000..89d5ac3c22
--- /dev/null
+++ b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/forms">
+ <file>form.ui</file>
+</qresource>
+</RCC>
diff --git a/examples/designer/worldtimeclockplugin/worldtimeclock.cpp b/examples/designer/worldtimeclockplugin/worldtimeclock.cpp
new file mode 100644
index 0000000000..77eff54765
--- /dev/null
+++ b/examples/designer/worldtimeclockplugin/worldtimeclock.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "worldtimeclock.h"
+
+WorldTimeClock::WorldTimeClock(QWidget *parent)
+ : QWidget(parent)
+{
+ timeZoneOffset = 0;
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(update()));
+ timer->start(1000);
+
+ setWindowTitle(tr("World Time Clock"));
+ resize(200, 200);
+}
+
+void WorldTimeClock::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();
+ time = time.addSecs(timeZoneOffset);
+
+ 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);
+ }
+
+ emit updated(time);
+}
+
+void WorldTimeClock::setTimeZone(int hourOffset)
+{
+ timeZoneOffset = qMin(qMax(-12, hourOffset), 12) * 3600;
+ update();
+}
diff --git a/examples/designer/worldtimeclockplugin/worldtimeclock.h b/examples/designer/worldtimeclockplugin/worldtimeclock.h
new file mode 100644
index 0000000000..7bfe8c5fab
--- /dev/null
+++ b/examples/designer/worldtimeclockplugin/worldtimeclock.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WORLDTIMECLOCK_H
+#define WORLDTIMECLOCK_H
+
+#include <QTime>
+#include <QWidget>
+#include <QtDesigner/QDesignerExportWidget>
+
+//! [0] //! [1]
+class QDESIGNER_WIDGET_EXPORT WorldTimeClock : public QWidget
+{
+ Q_OBJECT
+//! [0]
+
+public:
+ WorldTimeClock(QWidget *parent = 0);
+
+public slots:
+ void setTimeZone(int hourOffset);
+
+signals:
+ void updated(QTime currentTime);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ int timeZoneOffset;
+//! [2]
+};
+//! [1] //! [2]
+
+#endif
diff --git a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp
new file mode 100644
index 0000000000..e73c45bc34
--- /dev/null
+++ b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "worldtimeclock.h"
+#include "worldtimeclockplugin.h"
+
+#include <QtPlugin>
+
+WorldTimeClockPlugin::WorldTimeClockPlugin(QObject *parent)
+ : QObject(parent)
+{
+ initialized = false;
+}
+
+void WorldTimeClockPlugin::initialize(QDesignerFormEditorInterface * /* core */)
+{
+ if (initialized)
+ return;
+
+ initialized = true;
+}
+
+bool WorldTimeClockPlugin::isInitialized() const
+{
+ return initialized;
+}
+
+QWidget *WorldTimeClockPlugin::createWidget(QWidget *parent)
+{
+ return new WorldTimeClock(parent);
+}
+
+QString WorldTimeClockPlugin::name() const
+{
+ return "WorldTimeClock";
+}
+
+QString WorldTimeClockPlugin::group() const
+{
+ return "Display Widgets [Examples]";
+}
+
+QIcon WorldTimeClockPlugin::icon() const
+{
+ return QIcon();
+}
+
+QString WorldTimeClockPlugin::toolTip() const
+{
+ return "";
+}
+
+QString WorldTimeClockPlugin::whatsThis() const
+{
+ return "";
+}
+
+bool WorldTimeClockPlugin::isContainer() const
+{
+ return false;
+}
+
+QString WorldTimeClockPlugin::domXml() const
+{
+ return "<ui language=\"c++\">\n"
+ " <widget class=\"WorldTimeClock\" name=\"worldTimeClock\">\n"
+ " <property name=\"geometry\">\n"
+ " <rect>\n"
+ " <x>0</x>\n"
+ " <y>0</y>\n"
+ " <width>100</width>\n"
+ " <height>100</height>\n"
+ " </rect>\n"
+ " </property>\n"
+ " </widget>\n"
+ "</ui>";
+}
+
+QString WorldTimeClockPlugin::includeFile() const
+{
+ return "worldtimeclock.h";
+}
+
+//! [0]
+Q_EXPORT_PLUGIN2(worldtimeclockplugin, WorldTimeClockPlugin)
+//! [0]
diff --git a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.h b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.h
new file mode 100644
index 0000000000..87d797a9bd
--- /dev/null
+++ b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WORLDTIMECLOCKPLUGIN_H
+#define WORLDTIMECLOCKPLUGIN_H
+
+#include <QDesignerCustomWidgetInterface>
+
+//! [0]
+class WorldTimeClockPlugin : public QObject,
+ public QDesignerCustomWidgetInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QDesignerCustomWidgetInterface)
+
+public:
+ WorldTimeClockPlugin(QObject *parent = 0);
+
+ bool isContainer() const;
+ bool isInitialized() const;
+ QIcon icon() const;
+ QString domXml() const;
+ QString group() const;
+ QString includeFile() const;
+ QString name() const;
+ QString toolTip() const;
+ QString whatsThis() const;
+ QWidget *createWidget(QWidget *parent);
+ void initialize(QDesignerFormEditorInterface *core);
+
+private:
+ bool initialized;
+};
+//! [0]
+
+#endif
diff --git a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro
new file mode 100644
index 0000000000..5eb133f1fa
--- /dev/null
+++ b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro
@@ -0,0 +1,23 @@
+#! [0]
+CONFIG += designer plugin
+#! [0]
+TARGET = $$qtLibraryTarget($$TARGET)
+#! [1]
+TEMPLATE = lib
+#! [1]
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
+
+#! [2]
+HEADERS = worldtimeclock.h \
+ worldtimeclockplugin.h
+SOURCES = worldtimeclock.cpp \
+ worldtimeclockplugin.cpp
+#! [2]
+
+# install
+target.path = $$[QT_INSTALL_PLUGINS]/designer
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockplugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..61108e509c
--- /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]/desktop
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS desktop.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/desktop
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/desktop/screenshot/main.cpp b/examples/desktop/screenshot/main.cpp
new file mode 100644
index 0000000000..59e86744bf
--- /dev/null
+++ b/examples/desktop/screenshot/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..7d9545e387
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.cpp
@@ -0,0 +1,198 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..ecc7724472
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b610812c82
--- /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]/desktop/screenshot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS screenshot.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/desktop/screenshot
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/desktop/systray/images/bad.svg b/examples/desktop/systray/images/bad.svg
new file mode 100644
index 0000000000..186dba9cc8
--- /dev/null
+++ b/examples/desktop/systray/images/bad.svg
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
+"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg viewBox="-10 -10 178 178" height="177.523" id="svg1" inkscape:version="0.40" sodipodi:docbase="/mnt/donnees/09-Mes_images/Travaux/Travaux vectoriel/pictogrammes/sécu SVG/produits chimiques" sodipodi:docname="XiIrritant.svg" sodipodi:version="0.32" width="155.932" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xlink="http://www.w3.org/1999/xlink">
+<metadata>
+<rdf:RDF xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<cc:Work rdf:about="">
+<dc:title>Irritant</dc:title>
+<dc:description>produit chimique</dc:description>
+<dc:subject>
+<rdf:Bag>
+<rdf:li></rdf:li>
+<rdf:li>symbol</rdf:li>
+<rdf:li>signs_and_symbols</rdf:li>
+</rdf:Bag>
+</dc:subject>
+<dc:publisher>
+<cc:Agent rdf:about="http://www.openclipart.org">
+<dc:title>yves GUILLOU</dc:title>
+</cc:Agent>
+</dc:publisher>
+<dc:creator>
+<cc:Agent>
+<dc:title>yves GUILLOU</dc:title>
+</cc:Agent>
+</dc:creator>
+<dc:rights>
+<cc:Agent>
+<dc:title>yves GUILLOU</dc:title>
+</cc:Agent>
+</dc:rights>
+<dc:date></dc:date>
+<dc:format>image/svg+xml</dc:format>
+<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+<cc:license rdf:resource="http://web.resource.org/cc/PublicDomain"/>
+<dc:language>en</dc:language>
+</cc:Work>
+<cc:License rdf:about="http://web.resource.org/cc/PublicDomain">
+<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
+</cc:License>
+</rdf:RDF>
+</metadata>
+<sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="svg1" inkscape:cx="62.372805" inkscape:cy="34.864537" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="1121" inkscape:window-width="1590" inkscape:window-x="200" inkscape:window-y="0" inkscape:zoom="6.6399849" pagecolor="#ffffff"/>
+<defs id="defs2">
+<marker id="ArrowEnd" markerHeight="3" markerUnits="strokeWidth" markerWidth="4" orient="auto" refX="0" refY="5" viewBox="0 0 10 10">
+<path d="M 0 0 L 10 5 L 0 10 z" id="path4"/>
+</marker>
+<marker id="ArrowStart" markerHeight="3" markerUnits="strokeWidth" markerWidth="4" orient="auto" refX="10" refY="5" viewBox="0 0 10 10">
+<path d="M 10 0 L 0 5 L 10 10 z" id="path6"/>
+</marker>
+</defs>
+<g id="g7">
+<g id="g8">
+<path d="M 155.932 155.932L 155.932 0L 0 0L 0 155.932L 155.932 155.932z" id="path9" style="stroke:none; fill:#000000"/>
+<path d="M 150.83 150.83L 150.83 5.1011L 5.1011 5.1011L 5.1011 150.83L 150.83 150.83z" id="path10" style="stroke:none; fill:#ff9900"/>
+</g>
+<g id="g11">
+<path d="M 140.823 111.783L 44.3677 14.0771L 15.1084 44.1489L 111.564 141.854L 140.823 111.783z" id="path12" style="stroke:none; fill:#000000"/>
+<path d="M 111.783 15.1084L 14.0771 111.564L 44.1489 140.823L 141.855 44.3677L 111.783 15.1084z" id="path13" style="stroke:none; fill:#000000"/>
+</g>
+</g>
+</svg>
diff --git a/examples/desktop/systray/images/heart.svg b/examples/desktop/systray/images/heart.svg
new file mode 100644
index 0000000000..ba5f050b00
--- /dev/null
+++ b/examples/desktop/systray/images/heart.svg
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) --><svg viewBox="100 200 550 500" height="595.27559pt" id="svg1" inkscape:version="0.40+cvs" sodipodi:docbase="C:\Documents and Settings\Jon Phillips\My Documents\projects\clipart-project\submissions" sodipodi:docname="heart-left-highlight.svg" sodipodi:version="0.32" width="595.27559pt" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg">
+<metadata>
+<rdf:RDF xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<cc:Work rdf:about="">
+<dc:title>Heart Left-Highlight</dc:title>
+<dc:description>This is a normal valentines day heart.</dc:description>
+<dc:subject>
+<rdf:Bag>
+<rdf:li>holiday</rdf:li>
+<rdf:li>valentines</rdf:li>
+<rdf:li></rdf:li>
+<rdf:li>valentine</rdf:li>
+<rdf:li>hash(0x8a091c0)</rdf:li>
+<rdf:li>hash(0x8a0916c)</rdf:li>
+<rdf:li>signs_and_symbols</rdf:li>
+<rdf:li>hash(0x8a091f0)</rdf:li>
+<rdf:li>day</rdf:li>
+</rdf:Bag>
+</dc:subject>
+<dc:publisher>
+<cc:Agent rdf:about="http://www.openclipart.org">
+<dc:title>Jon Phillips</dc:title>
+</cc:Agent>
+</dc:publisher>
+<dc:creator>
+<cc:Agent>
+<dc:title>Jon Phillips</dc:title>
+</cc:Agent>
+</dc:creator>
+<dc:rights>
+<cc:Agent>
+<dc:title>Jon Phillips</dc:title>
+</cc:Agent>
+</dc:rights>
+<dc:date></dc:date>
+<dc:format>image/svg+xml</dc:format>
+<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+<cc:license rdf:resource="http://web.resource.org/cc/PublicDomain"/>
+<dc:language>en</dc:language>
+</cc:Work>
+<cc:License rdf:about="http://web.resource.org/cc/PublicDomain">
+<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
+</cc:License>
+</rdf:RDF>
+</metadata>
+<defs id="defs3"/>
+<sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="549.40674" inkscape:cy="596.00159" inkscape:document-units="px" inkscape:guide-bbox="true" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="615" inkscape:window-width="866" inkscape:window-x="88" inkscape:window-y="116" inkscape:zoom="0.35000000" pagecolor="#ffffff" showguides="true"/>
+<g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1">
+<path d="M 263.41570,235.14588 C 197.17570,235.14588 143.41575,288.90587 143.41575,355.14588 C 143.41575,489.90139 279.34890,525.23318 371.97820,658.45392 C 459.55244,526.05056 600.54070,485.59932 600.54070,355.14588 C 600.54070,288.90588 546.78080,235.14587 480.54070,235.14588 C 432.49280,235.14588 391.13910,263.51631 371.97820,304.33338 C 352.81740,263.51630 311.46370,235.14587 263.41570,235.14588 z " id="path7" sodipodi:nodetypes="ccccccc" style="fill:#e60000;fill-opacity:1.0000000;stroke:#000000;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/>
+<path d="M 265.00000,253.59375 C 207.04033,253.59375 160.00000,300.63407 160.00000,358.59375 C 160.00000,476.50415 278.91857,507.43251 359.96875,624.00000 C 366.52868,614.08205 220.00000,478.47309 220.00000,378.59375 C 220.00000,320.63407 267.04033,273.59375 325.00000,273.59375 C 325.50453,273.59375 325.99718,273.64912 326.50000,273.65625 C 309.22436,261.07286 288.00557,253.59374 265.00000,253.59375 z " id="path220" sodipodi:nodetypes="ccccccc" style="fill:#e6e6e6;fill-opacity:0.64556962;stroke:none;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/>
+</g>
+</svg>
diff --git a/examples/desktop/systray/images/trash.svg b/examples/desktop/systray/images/trash.svg
new file mode 100644
index 0000000000..c44e4c75a2
--- /dev/null
+++ b/examples/desktop/systray/images/trash.svg
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 10, SVG Export Plug-In . SVG Version: 3.0.0 Build 76) --><svg enable-background="new 0 0 347 348" height="348" i:pageBounds="0 792 612 0" i:rulerOrigin="0 0" i:viewOrigin="131 567" overflow="visible" space="preserve" viewBox="-20 -20 387 388" width="347" xmlns="http://www.w3.org/2000/svg" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" xmlns:graph="http://ns.adobe.com/Graphs/1.0/" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:x="http://ns.adobe.com/Extensibility/1.0/" xmlns:xlink="http://www.w3.org/1999/xlink">
+<metadata>
+<rdf:RDF xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<cc:Work rdf:about="">
+<dc:title>Keep Tidy Inside</dc:title>
+<dc:description></dc:description>
+<dc:subject>
+<rdf:Bag>
+<rdf:li></rdf:li>
+<rdf:li>symbol</rdf:li>
+<rdf:li>bin</rdf:li>
+<rdf:li>signs_and_symbols</rdf:li>
+<rdf:li>clean</rdf:li>
+<rdf:li>rubish</rdf:li>
+<rdf:li>trash</rdf:li>
+<rdf:li>inside</rdf:li>
+<rdf:li>garbage</rdf:li>
+<rdf:li>sign</rdf:li>
+</rdf:Bag>
+</dc:subject>
+<dc:publisher>
+<cc:Agent rdf:about="http://www.openclipart.org">
+<dc:title>Martin Owens</dc:title>
+</cc:Agent>
+</dc:publisher>
+<dc:creator>
+<cc:Agent>
+<dc:title>Martin Owens</dc:title>
+</cc:Agent>
+</dc:creator>
+<dc:rights>
+<cc:Agent>
+<dc:title>Martin Owens</dc:title>
+</cc:Agent>
+</dc:rights>
+<dc:date></dc:date>
+<dc:format>image/svg+xml</dc:format>
+<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+<cc:license rdf:resource="http://web.resource.org/cc/PublicDomain"/>
+<dc:language>en</dc:language>
+</cc:Work>
+<cc:License rdf:about="http://web.resource.org/cc/PublicDomain">
+<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
+</cc:License>
+</rdf:RDF>
+</metadata>
+<g i:dimmedPercent="50" i:knockout="Off" i:layer="yes" i:rgbTrio="#4F008000FFFF" id="Layer_1">
+<path d="M347,174c0,96.098-77.679,174-173.5,174C77.679,348,0,270.098,0,174 C0,77.902,77.679,0,173.5,0C269.321,0,347,77.902,347,174z" fill="#10A040" i:knockout="Off"/>
+<path d="M238,53c0,13.807-11.864,25-26.5,25S185,66.807,185,53s11.864-25,26.5-25 S238,39.193,238,53z" fill="#FFFFFF" i:knockout="Off"/>
+<path d="M66,175c1.055,6.355,19.333,126.417,19.333,126.417h68.333 c0,0,14.105-122.524,14.333-126.417c6.224-0.622,6.667-13-2-13c-12.164,0-89.205-0.059-98,0S61.167,174.487,66,175z" fill="#FFFFFF" i:knockout="Off"/>
+<path d="M78,141c17.292-5.325,24.179-23.532,27-31c14.513,6.596,40.333,12.265,59,8 c3.683,19.419-28.043,19.31-23,37C132.577,145.705,89.404,167.292,78,141z" fill="#FFFFFF" i:knockout="Off"/>
+<path d="M103,82l139-1c-0.6,3.421,33.633,57.497,29,67c-4.089,0.418-67,5-67,5 c6.109-9.379-13-43-13-43L103,82z" fill="#FFFFFF" i:knockout="Off"/>
+<path d="M270,156l-66-3c0,0-23.565,143.355-24,145s1.855,2.536,3,1s51-82,51-82 s19.754,80.701,20,82s3.721,1.209,4,0S270,156,270,156z" fill="#FFFFFF" i:knockout="Off"/>
+</g>
+</svg>
diff --git a/examples/desktop/systray/main.cpp b/examples/desktop/systray/main.cpp
new file mode 100644
index 0000000000..d406d16d9e
--- /dev/null
+++ b/examples/desktop/systray/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(systray);
+
+ QApplication app(argc, argv);
+
+ if (!QSystemTrayIcon::isSystemTrayAvailable()) {
+ QMessageBox::critical(0, QObject::tr("Systray"),
+ QObject::tr("I couldn't detect any system tray "
+ "on this system."));
+ return 1;
+ }
+ QApplication::setQuitOnLastWindowClosed(false);
+
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/desktop/systray/systray.pro b/examples/desktop/systray/systray.pro
new file mode 100644
index 0000000000..3c0862636a
--- /dev/null
+++ b/examples/desktop/systray/systray.pro
@@ -0,0 +1,24 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+RESOURCES = systray.qrc
+QT += xml svg
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/desktop/systray
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS systray.pro resources images
+sources.path = $$[QT_INSTALL_EXAMPLES]/desktop/systray
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+wince* {
+ CONFIG(debug, release|debug) {
+ addPlugins.sources = $$QT_BUILD_TREE/plugins/imageformats/qsvgd4.dll
+ }
+ CONFIG(release, release|debug) {
+ addPlugins.sources = $$QT_BUILD_TREE/plugins/imageformats/qsvg4.dll
+ }
+ addPlugins.path = imageformats
+ DEPLOYMENT += addPlugins
+}
diff --git a/examples/desktop/systray/systray.qrc b/examples/desktop/systray/systray.qrc
new file mode 100644
index 0000000000..b0d5e0cb7c
--- /dev/null
+++ b/examples/desktop/systray/systray.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>images/bad.svg</file>
+ <file>images/heart.svg</file>
+ <file>images/trash.svg</file>
+</qresource>
+</RCC>
diff --git a/examples/desktop/systray/window.cpp b/examples/desktop/systray/window.cpp
new file mode 100644
index 0000000000..052ecdd5b2
--- /dev/null
+++ b/examples/desktop/systray/window.cpp
@@ -0,0 +1,259 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ createIconGroupBox();
+ createMessageGroupBox();
+
+ iconLabel->setMinimumWidth(durationLabel->sizeHint().width());
+
+ createActions();
+ createTrayIcon();
+
+ connect(showMessageButton, SIGNAL(clicked()), this, SLOT(showMessage()));
+ connect(showIconCheckBox, SIGNAL(toggled(bool)),
+ trayIcon, SLOT(setVisible(bool)));
+ connect(iconComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(setIcon(int)));
+ connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
+ connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+ this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(iconGroupBox);
+ mainLayout->addWidget(messageGroupBox);
+ setLayout(mainLayout);
+
+ iconComboBox->setCurrentIndex(1);
+ trayIcon->show();
+
+ setWindowTitle(tr("Systray"));
+ resize(400, 300);
+}
+//! [0]
+
+//! [1]
+void Window::setVisible(bool visible)
+{
+ minimizeAction->setEnabled(visible);
+ maximizeAction->setEnabled(!isMaximized());
+ restoreAction->setEnabled(isMaximized() || !visible);
+ QDialog::setVisible(visible);
+}
+//! [1]
+
+//! [2]
+void Window::closeEvent(QCloseEvent *event)
+{
+ if (trayIcon->isVisible()) {
+ QMessageBox::information(this, tr("Systray"),
+ tr("The program will keep running in the "
+ "system tray. To terminate the program, "
+ "choose <b>Quit</b> in the context menu "
+ "of the system tray entry."));
+ hide();
+ event->ignore();
+ }
+}
+//! [2]
+
+//! [3]
+void Window::setIcon(int index)
+{
+ QIcon icon = iconComboBox->itemIcon(index);
+ trayIcon->setIcon(icon);
+ setWindowIcon(icon);
+
+ trayIcon->setToolTip(iconComboBox->itemText(index));
+}
+//! [3]
+
+//! [4]
+void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
+{
+ switch (reason) {
+ case QSystemTrayIcon::Trigger:
+ case QSystemTrayIcon::DoubleClick:
+ iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1)
+ % iconComboBox->count());
+ break;
+ case QSystemTrayIcon::MiddleClick:
+ showMessage();
+ break;
+ default:
+ ;
+ }
+}
+//! [4]
+
+//! [5]
+void Window::showMessage()
+{
+ QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(
+ typeComboBox->itemData(typeComboBox->currentIndex()).toInt());
+ trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon,
+ durationSpinBox->value() * 1000);
+}
+//! [5]
+
+//! [6]
+void Window::messageClicked()
+{
+ QMessageBox::information(0, tr("Systray"),
+ tr("Sorry, I already gave what help I could.\n"
+ "Maybe you should try asking a human?"));
+}
+//! [6]
+
+void Window::createIconGroupBox()
+{
+ iconGroupBox = new QGroupBox(tr("Tray Icon"));
+
+ iconLabel = new QLabel("Icon:");
+
+ iconComboBox = new QComboBox;
+ iconComboBox->addItem(QIcon(":/images/bad.svg"), tr("Bad"));
+ iconComboBox->addItem(QIcon(":/images/heart.svg"), tr("Heart"));
+ iconComboBox->addItem(QIcon(":/images/trash.svg"), tr("Trash"));
+
+ showIconCheckBox = new QCheckBox(tr("Show icon"));
+ showIconCheckBox->setChecked(true);
+
+ QHBoxLayout *iconLayout = new QHBoxLayout;
+ iconLayout->addWidget(iconLabel);
+ iconLayout->addWidget(iconComboBox);
+ iconLayout->addStretch();
+ iconLayout->addWidget(showIconCheckBox);
+ iconGroupBox->setLayout(iconLayout);
+}
+
+void Window::createMessageGroupBox()
+{
+ messageGroupBox = new QGroupBox(tr("Balloon Message"));
+
+ typeLabel = new QLabel(tr("Type:"));
+
+ typeComboBox = new QComboBox;
+ typeComboBox->addItem(tr("None"), QSystemTrayIcon::NoIcon);
+ typeComboBox->addItem(style()->standardIcon(
+ QStyle::SP_MessageBoxInformation), tr("Information"),
+ QSystemTrayIcon::Information);
+ typeComboBox->addItem(style()->standardIcon(
+ QStyle::SP_MessageBoxWarning), tr("Warning"),
+ QSystemTrayIcon::Warning);
+ typeComboBox->addItem(style()->standardIcon(
+ QStyle::SP_MessageBoxCritical), tr("Critical"),
+ QSystemTrayIcon::Critical);
+ typeComboBox->setCurrentIndex(1);
+
+ durationLabel = new QLabel(tr("Duration:"));
+
+ durationSpinBox = new QSpinBox;
+ durationSpinBox->setRange(5, 60);
+ durationSpinBox->setSuffix(" s");
+ durationSpinBox->setValue(15);
+
+ durationWarningLabel = new QLabel(tr("(some systems might ignore this "
+ "hint)"));
+ durationWarningLabel->setIndent(10);
+
+ titleLabel = new QLabel(tr("Title:"));
+
+ titleEdit = new QLineEdit(tr("Cannot connect to network"));
+
+ bodyLabel = new QLabel(tr("Body:"));
+
+ bodyEdit = new QTextEdit;
+ bodyEdit->setPlainText(tr("Don't believe me. Honestly, I don't have a "
+ "clue.\nClick this balloon for details."));
+
+ showMessageButton = new QPushButton(tr("Show Message"));
+ showMessageButton->setDefault(true);
+
+ QGridLayout *messageLayout = new QGridLayout;
+ messageLayout->addWidget(typeLabel, 0, 0);
+ messageLayout->addWidget(typeComboBox, 0, 1, 1, 2);
+ messageLayout->addWidget(durationLabel, 1, 0);
+ messageLayout->addWidget(durationSpinBox, 1, 1);
+ messageLayout->addWidget(durationWarningLabel, 1, 2, 1, 3);
+ messageLayout->addWidget(titleLabel, 2, 0);
+ messageLayout->addWidget(titleEdit, 2, 1, 1, 4);
+ messageLayout->addWidget(bodyLabel, 3, 0);
+ messageLayout->addWidget(bodyEdit, 3, 1, 2, 4);
+ messageLayout->addWidget(showMessageButton, 5, 4);
+ messageLayout->setColumnStretch(3, 1);
+ messageLayout->setRowStretch(4, 1);
+ messageGroupBox->setLayout(messageLayout);
+}
+
+void Window::createActions()
+{
+ minimizeAction = new QAction(tr("Mi&nimize"), this);
+ connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
+
+ maximizeAction = new QAction(tr("Ma&ximize"), this);
+ connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
+
+ restoreAction = new QAction(tr("&Restore"), this);
+ connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
+
+ quitAction = new QAction(tr("&Quit"), this);
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+}
+
+void Window::createTrayIcon()
+{
+ trayIconMenu = new QMenu(this);
+ trayIconMenu->addAction(minimizeAction);
+ trayIconMenu->addAction(maximizeAction);
+ trayIconMenu->addAction(restoreAction);
+ trayIconMenu->addSeparator();
+ trayIconMenu->addAction(quitAction);
+
+ trayIcon = new QSystemTrayIcon(this);
+ trayIcon->setContextMenu(trayIconMenu);
+}
diff --git a/examples/desktop/systray/window.h b/examples/desktop/systray/window.h
new file mode 100644
index 0000000000..d9bfd520eb
--- /dev/null
+++ b/examples/desktop/systray/window.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QSystemTrayIcon>
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QCheckBox;
+class QComboBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QMenu;
+class QPushButton;
+class QSpinBox;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+ void setVisible(bool visible);
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void setIcon(int index);
+ void iconActivated(QSystemTrayIcon::ActivationReason reason);
+ void showMessage();
+ void messageClicked();
+
+private:
+ void createIconGroupBox();
+ void createMessageGroupBox();
+ void createActions();
+ void createTrayIcon();
+
+ QGroupBox *iconGroupBox;
+ QLabel *iconLabel;
+ QComboBox *iconComboBox;
+ QCheckBox *showIconCheckBox;
+
+ QGroupBox *messageGroupBox;
+ QLabel *typeLabel;
+ QLabel *durationLabel;
+ QLabel *durationWarningLabel;
+ QLabel *titleLabel;
+ QLabel *bodyLabel;
+ QComboBox *typeComboBox;
+ QSpinBox *durationSpinBox;
+ QLineEdit *titleEdit;
+ QTextEdit *bodyEdit;
+ QPushButton *showMessageButton;
+
+ QAction *minimizeAction;
+ QAction *maximizeAction;
+ QAction *restoreAction;
+ QAction *quitAction;
+
+ QSystemTrayIcon *trayIcon;
+ QMenu *trayIconMenu;
+};
+//! [0]
+
+#endif
diff --git a/examples/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..200d7acee1
--- /dev/null
+++ b/examples/dialogs/classwizard/classwizard.cpp
@@ -0,0 +1,431 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4808629fce
--- /dev/null
+++ b/examples/dialogs/classwizard/classwizard.h
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..0515a8a9f1
--- /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]/dialogs/classwizard
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/classwizard
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..8230695f5c
--- /dev/null
+++ b/examples/dialogs/classwizard/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..f442e10194
--- /dev/null
+++ b/examples/dialogs/configdialog/configdialog.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b09771c59f
--- /dev/null
+++ b/examples/dialogs/configdialog/configdialog.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..5ef381049c
--- /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]/dialogs/configdialog
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/configdialog
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..afc5467881
--- /dev/null
+++ b/examples/dialogs/configdialog/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..27c322a15f
--- /dev/null
+++ b/examples/dialogs/configdialog/pages.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 Software (Australia)"));
+ serverCombo->addItem(tr("Qt Software (Germany)"));
+ serverCombo->addItem(tr("Qt Software (Norway)"));
+ serverCombo->addItem(tr("Qt Software (People's Republic of China)"));
+ serverCombo->addItem(tr("Qt Software (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..534798f3b1
--- /dev/null
+++ b/examples/dialogs/configdialog/pages.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..6d0ed8dc6e
--- /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]/dialogs
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/dialogs/extension/extension.pro b/examples/dialogs/extension/extension.pro
new file mode 100644
index 0000000000..7f80f9c0a9
--- /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]/dialogs/extension
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/extension
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/dialogs/extension/finddialog.cpp b/examples/dialogs/extension/finddialog.cpp
new file mode 100644
index 0000000000..80c2868caa
--- /dev/null
+++ b/examples/dialogs/extension/finddialog.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4fc7ee589a
--- /dev/null
+++ b/examples/dialogs/extension/finddialog.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..fa70a55be4
--- /dev/null
+++ b/examples/dialogs/extension/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..6820c173ea
--- /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]/dialogs/findfiles
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/findfiles
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/dialogs/findfiles/main.cpp b/examples/dialogs/findfiles/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/dialogs/findfiles/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..7620a68c29
--- /dev/null
+++ b/examples/dialogs/findfiles/window.cpp
@@ -0,0 +1,250 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+ 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(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..8cd4813823
--- /dev/null
+++ b/examples/dialogs/findfiles/window.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..30b41659a3
--- /dev/null
+++ b/examples/dialogs/licensewizard/licensewizard.cpp
@@ -0,0 +1,360 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..bcf22a2a2b
--- /dev/null
+++ b/examples/dialogs/licensewizard/licensewizard.h
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..789dae0462
--- /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]/dialogs/licensewizard
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/licensewizard
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..9d100324dd
--- /dev/null
+++ b/examples/dialogs/licensewizard/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..9f1b9adc22
--- /dev/null
+++ b/examples/dialogs/sipdialog/dialog.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(pressed()),
+ 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.width() == availableGeometry.width()) {
+ if (desktopGeometry.height() > availableGeometry.height()) {
+ setWindowState(windowState() & ~Qt::WindowMaximized);
+ setGeometry(availableGeometry);
+ } else {
+ setWindowState(windowState() | Qt::WindowMaximized);
+ }
+ }
+ desktopGeometry = availableGeometry;
+}
+//! [reactToSIP() function]
diff --git a/examples/dialogs/sipdialog/dialog.h b/examples/dialogs/sipdialog/dialog.h
new file mode 100644
index 0000000000..ffcc926409
--- /dev/null
+++ b/examples/dialogs/sipdialog/dialog.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..5fcbfd806e
--- /dev/null
+++ b/examples/dialogs/sipdialog/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "dialog.h"
+
+//! [main() function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ dialog.exec();
+}
+//! [main() function]
diff --git a/examples/dialogs/sipdialog/sipdialog.pro b/examples/dialogs/sipdialog/sipdialog.pro
new file mode 100644
index 0000000000..3d5503f616
--- /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]/dialogs/sipdialog
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/sipdialog
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..0fe1f7e3fd
--- /dev/null
+++ b/examples/dialogs/standarddialogs/dialog.cpp
@@ -0,0 +1,390 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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&Integer()"));
+
+ 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::show&M&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);
+#ifndef Q_WS_WIN
+#ifndef Q_OS_MAC
+ native->hide();
+#endif
+#endif
+ 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::getInteger(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 = QColorDialog::getColor(Qt::green, this);
+ 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..35f0b051f5
--- /dev/null
+++ b/examples/dialogs/standarddialogs/dialog.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..3b7ed8b982
--- /dev/null
+++ b/examples/dialogs/standarddialogs/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..9b06e5cf3e
--- /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]/dialogs/standarddialogs
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/standarddialogs
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..04f3b33410
--- /dev/null
+++ b/examples/dialogs/tabdialog/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..189d085597
--- /dev/null
+++ b/examples/dialogs/tabdialog/tabdialog.cpp
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b22997d511
--- /dev/null
+++ b/examples/dialogs/tabdialog/tabdialog.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f3fa95df4b
--- /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]/dialogs/tabdialog
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/tabdialog
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..128bce76cd
--- /dev/null
+++ b/examples/dialogs/trivialwizard/trivialwizard.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..27bb8d9a7a
--- /dev/null
+++ b/examples/dialogs/trivialwizard/trivialwizard.pro
@@ -0,0 +1,9 @@
+SOURCES = trivialwizard.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/dialogs/trivialwizard
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/dialogs/trivialwizard
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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/delayedencoding/delayedencoding.pro b/examples/draganddrop/delayedencoding/delayedencoding.pro
new file mode 100644
index 0000000000..c7b95b6ed5
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/delayedencoding.pro
@@ -0,0 +1,14 @@
+QT += svg
+
+HEADERS = mimedata.h \
+ sourcewidget.h
+RESOURCES = delayedencoding.qrc
+SOURCES = main.cpp \
+ mimedata.cpp \
+ sourcewidget.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/delayedencoding
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/delayedencoding
+INSTALLS += target sources
diff --git a/examples/draganddrop/delayedencoding/delayedencoding.qrc b/examples/draganddrop/delayedencoding/delayedencoding.qrc
new file mode 100644
index 0000000000..374f21147d
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/delayedencoding.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="">
+ <file>images/drag.png</file>
+ <file>images/example.svg</file>
+</qresource>
+</RCC>
diff --git a/examples/draganddrop/delayedencoding/images/drag.png b/examples/draganddrop/delayedencoding/images/drag.png
new file mode 100644
index 0000000000..dd795cfffc
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/images/drag.png
Binary files differ
diff --git a/examples/draganddrop/delayedencoding/images/example.svg b/examples/draganddrop/delayedencoding/images/example.svg
new file mode 100644
index 0000000000..4707cf891e
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/images/example.svg
@@ -0,0 +1,59 @@
+<?xml version="1.0" standalone="no"?>
+<!-- ***********************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+************************************************************************ -->
+<svg width="8cm" height="8cm" viewBox="0 0 400 400"
+ xmlns="http://www.w3.org/2000/svg" baseProfile="tiny" version="1.1">
+ <title>Sphere</title>
+ <desc>A gradient filled sphere.</desc>
+ <g>
+ <defs>
+ <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse"
+ cx="200" cy="200" r="100" fx="150" fy="150">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="blue" />
+ <stop offset="100%" stop-color="black" />
+ </radialGradient>
+ </defs>
+ <rect fill="lightblue" x="0" y="0" width="400" height="400" />
+ <circle fill="url(#blueSphere)" stroke="black" stroke-width="2"
+ cx="200" cy="200" r="100"/>
+ </g>
+</svg>
diff --git a/examples/draganddrop/delayedencoding/main.cpp b/examples/draganddrop/delayedencoding/main.cpp
new file mode 100644
index 0000000000..801e474fae
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "sourcewidget.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ SourceWidget window;
+ window.show();
+ return app.exec();
+}
+
diff --git a/examples/draganddrop/delayedencoding/mimedata.cpp b/examples/draganddrop/delayedencoding/mimedata.cpp
new file mode 100644
index 0000000000..5c7c23c9d5
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/mimedata.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "mimedata.h"
+
+MimeData::MimeData()
+ : QMimeData()
+{
+}
+
+//![0]
+QStringList MimeData::formats() const
+{
+ return QMimeData::formats() << "image/png";
+}
+//![0]
+
+//![1]
+QVariant MimeData::retrieveData(const QString &mimeType, QVariant::Type type)
+ const
+{
+ emit dataRequested(mimeType);
+
+ return QMimeData::retrieveData(mimeType, type);
+}
+//![1]
+
diff --git a/examples/draganddrop/delayedencoding/mimedata.h b/examples/draganddrop/delayedencoding/mimedata.h
new file mode 100644
index 0000000000..13e834dae7
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/mimedata.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MIMEDATA_H
+#define MIMEDATA_H
+
+#include <QMimeData>
+
+//![0]
+class MimeData : public QMimeData
+{
+ Q_OBJECT
+
+public:
+ MimeData();
+ QStringList formats() const;
+
+signals:
+ void dataRequested(const QString &mimeType) const;
+
+protected:
+ QVariant retrieveData(const QString &mimetype, QVariant::Type type) const;
+};
+//![0]
+
+#endif
diff --git a/examples/draganddrop/delayedencoding/sourcewidget.cpp b/examples/draganddrop/delayedencoding/sourcewidget.cpp
new file mode 100644
index 0000000000..f5aed89cff
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/sourcewidget.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtSvg>
+#include "mimedata.h"
+#include "sourcewidget.h"
+
+SourceWidget::SourceWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QFile imageFile(":/images/example.svg");
+ imageFile.open(QIODevice::ReadOnly);
+ imageData = imageFile.readAll();
+ imageFile.close();
+
+ QScrollArea *imageArea = new QScrollArea;
+ imageLabel = new QSvgWidget;
+ imageLabel->renderer()->load(imageData);
+ imageArea->setWidget(imageLabel);
+ //imageLabel->setMinimumSize(imageLabel->renderer()->viewBox().size());
+
+ QLabel *instructTopLabel = new QLabel(tr("This is an SVG drawing:"));
+ QLabel *instructBottomLabel = new QLabel(
+ tr("Drag the icon to copy the drawing as a PNG file:"));
+ QPushButton *dragIcon = new QPushButton(tr("Export"));
+ dragIcon->setIcon(QIcon(":/images/drag.png"));
+
+ connect(dragIcon, SIGNAL(pressed()), this, SLOT(startDrag()));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(instructTopLabel, 0, 0, 1, 2);
+ layout->addWidget(imageArea, 1, 0, 2, 2);
+ layout->addWidget(instructBottomLabel, 3, 0);
+ layout->addWidget(dragIcon, 3, 1);
+ setLayout(layout);
+ setWindowTitle(tr("Delayed Encoding"));
+}
+
+//![1]
+void SourceWidget::createData(const QString &mimeType)
+{
+ if (mimeType != "image/png")
+ return;
+
+ QImage image(imageLabel->size(), QImage::Format_RGB32);
+ QPainter painter;
+ painter.begin(&image);
+ imageLabel->renderer()->render(&painter);
+ painter.end();
+
+ QByteArray data;
+ QBuffer buffer(&data);
+ buffer.open(QIODevice::WriteOnly);
+ image.save(&buffer, "PNG");
+ buffer.close();
+
+ mimeData->setData("image/png", data);
+}
+//![1]
+
+//![0]
+void SourceWidget::startDrag()
+{
+ mimeData = new MimeData;
+
+ connect(mimeData, SIGNAL(dataRequested(const QString &)),
+ this, SLOT(createData(const QString &)), Qt::DirectConnection);
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setPixmap(QPixmap(":/images/drag.png"));
+
+ drag->exec(Qt::CopyAction);
+}
+//![0]
+
diff --git a/examples/draganddrop/delayedencoding/sourcewidget.h b/examples/draganddrop/delayedencoding/sourcewidget.h
new file mode 100644
index 0000000000..8d6a6901cd
--- /dev/null
+++ b/examples/draganddrop/delayedencoding/sourcewidget.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SOURCEWIDGET_H
+#define SOURCEWIDGET_H
+
+#include <QByteArray>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QSvgWidget;
+QT_END_NAMESPACE
+class MimeData;
+
+class SourceWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ SourceWidget(QWidget *parent = 0);
+//![0]
+public slots:
+ void createData(const QString &mimetype);
+ void startDrag();
+
+private:
+ QByteArray imageData;
+ QSvgWidget *imageLabel;
+ MimeData *mimeData;
+//![0]
+};
+
+#endif
diff --git a/examples/draganddrop/draganddrop.pro b/examples/draganddrop/draganddrop.pro
new file mode 100644
index 0000000000..fa857db14c
--- /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]/draganddrop
+INSTALLS += sources
diff --git a/examples/draganddrop/draggableicons/draggableicons.pro b/examples/draganddrop/draggableicons/draggableicons.pro
new file mode 100644
index 0000000000..5212abc800
--- /dev/null
+++ b/examples/draganddrop/draggableicons/draggableicons.pro
@@ -0,0 +1,12 @@
+HEADERS = dragwidget.h
+RESOURCES = draggableicons.qrc
+SOURCES = dragwidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/draggableicons
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/draggableicons
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..021f816737
--- /dev/null
+++ b/examples/draganddrop/draggableicons/dragwidget.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..201adf83a4
--- /dev/null
+++ b/examples/draganddrop/draggableicons/dragwidget.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..cd945370cc
--- /dev/null
+++ b/examples/draganddrop/draggableicons/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..109be5dd00
--- /dev/null
+++ b/examples/draganddrop/draggabletext/draggabletext.pro
@@ -0,0 +1,14 @@
+HEADERS = draglabel.h \
+ dragwidget.h
+RESOURCES = draggabletext.qrc
+SOURCES = draglabel.cpp \
+ dragwidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/draggabletext
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.txt *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/draggabletext
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..4dfa099bb6
--- /dev/null
+++ b/examples/draganddrop/draggabletext/draglabel.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..8ba2778e77
--- /dev/null
+++ b/examples/draganddrop/draggabletext/draglabel.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..2af7b295de
--- /dev/null
+++ b/examples/draganddrop/draggabletext/dragwidget.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 (children().contains(event->source())) {
+ 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..b51f05b2a4
--- /dev/null
+++ b/examples/draganddrop/draggabletext/dragwidget.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e66c8b71d5
--- /dev/null
+++ b/examples/draganddrop/draggabletext/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..495e2bfe3e
--- /dev/null
+++ b/examples/draganddrop/dropsite/droparea.cpp
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..8a40acccda
--- /dev/null
+++ b/examples/draganddrop/dropsite/droparea.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..268e2478b0
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsite.pro
@@ -0,0 +1,14 @@
+HEADERS = droparea.h \
+ dropsitewindow.h
+SOURCES = droparea.cpp \
+ dropsitewindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/dropsite
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/dropsite
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
diff --git a/examples/draganddrop/dropsite/dropsitewindow.cpp b/examples/draganddrop/dropsite/dropsitewindow.cpp
new file mode 100644
index 0000000000..6e7055b8b6
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsitewindow.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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) {
+ QString url = urlList.at(i).path();
+ text.append(url + " ");
+ }
+ } 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..bbdc687ed3
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsitewindow.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..62589ad98c
--- /dev/null
+++ b/examples/draganddrop/dropsite/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..1bec024e2d
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/draglabel.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5d2fd5281b
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/draglabel.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..2f96a58670
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/dragwidget.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4722917615
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/dragwidget.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b452746dfd
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/fridgemagnets.pro
@@ -0,0 +1,15 @@
+HEADERS = draglabel.h \
+ dragwidget.h
+RESOURCES = fridgemagnets.qrc
+SOURCES = draglabel.cpp \
+ dragwidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/fridgemagnets
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.txt
+sources.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/fridgemagnets
+INSTALLS += target sources
+TARGET.UID3 = 0xA000C610
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..23dfe79a0f
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "dragwidget.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(fridgemagnets);
+ bool smallScreen = false;
+ for (int i=0; i<argc; i++)
+ if (QString(argv[i]) == "-small-screen")
+ smallScreen = true;
+
+ QApplication app(argc, argv);
+ DragWidget window;
+ 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..e0e5cc1907
--- /dev/null
+++ b/examples/draganddrop/puzzle/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ 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..f998882e9e
--- /dev/null
+++ b/examples/draganddrop/puzzle/mainwindow.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(QKeySequence(tr("Ctrl+O")));
+
+ QAction *exitAction = fileMenu->addAction(tr("E&xit"));
+ exitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
+
+ 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..edfbb12e03
--- /dev/null
+++ b/examples/draganddrop/puzzle/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..77d06fb6ed
--- /dev/null
+++ b/examples/draganddrop/puzzle/pieceslist.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 = qVariantValue<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..26685e3311
--- /dev/null
+++ b/examples/draganddrop/puzzle/pieceslist.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e51eb78bdf
--- /dev/null
+++ b/examples/draganddrop/puzzle/puzzle.pro
@@ -0,0 +1,27 @@
+HEADERS = mainwindow.h \
+ pieceslist.h \
+ puzzlewidget.h
+RESOURCES = puzzle.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ pieceslist.cpp \
+ puzzlewidget.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/puzzle
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.jpg
+sources.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/puzzle
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:{
+ addFile.sources = example.jpg
+ addFile.path = .
+ DEPLOYMENT += addFile
+}
+wince*: {
+ addFile.sources = 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..8548db521c
--- /dev/null
+++ b/examples/draganddrop/puzzle/puzzlewidget.cpp
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..312e25fc77
--- /dev/null
+++ b/examples/draganddrop/puzzle/puzzlewidget.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/examplebase.pri b/examples/examplebase.pri
new file mode 100644
index 0000000000..eff6588df6
--- /dev/null
+++ b/examples/examplebase.pri
@@ -0,0 +1 @@
+symbian:RSS_RULES ="group_name=\"QtExamples\";" \ No newline at end of file
diff --git a/examples/examples.pro b/examples/examples.pro
new file mode 100644
index 0000000000..8892f2af57
--- /dev/null
+++ b/examples/examples.pro
@@ -0,0 +1,57 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ desktop \
+ dialogs \
+ draganddrop \
+ graphicsview \
+ ipc \
+ itemviews \
+ layouts \
+ linguist \
+ mainwindows \
+ network \
+ painting \
+ qtconcurrent \
+ richtext \
+ sql \
+ threads \
+ tools \
+ tutorials \
+ widgets \
+ uitools \
+ xml \
+ script
+
+symbian: SUBDIRS = \
+ graphicsview \
+ itemviews \
+ network \
+ painting \
+ widgets \
+ draganddrop \
+ mainwindows \
+ script \
+ sql \
+ xml
+
+contains(QT_CONFIG, phonon):!static: SUBDIRS += phonon
+contains(QT_CONFIG, webkit): SUBDIRS += webkit
+embedded:SUBDIRS += qws
+!wince*:!symbian: {
+ !contains(QT_EDITION, Console):contains(QT_BUILD_PARTS, tools):SUBDIRS += designer
+ contains(QT_BUILD_PARTS, tools):SUBDIRS += assistant qtestlib help
+} else {
+ contains(QT_BUILD_PARTS, tools):SUBDIRS += qtestlib
+}
+contains(QT_CONFIG, opengl): SUBDIRS += opengl
+contains(QT_CONFIG, dbus): SUBDIRS += dbus
+win32:!contains(QT_EDITION, OpenSource|Console):SUBDIRS += activeqt
+contains(QT_CONFIG, xmlpatterns): SUBDIRS += xmlpatterns
+contains(DEFINES, QT_NO_CURSOR): SUBDIRS -= mainwindows
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
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/basicgraphicslayouts/basicgraphicslayouts.pro b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro
new file mode 100644
index 0000000000..956f5c27ac
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro
@@ -0,0 +1,16 @@
+HEADERS = layoutitem.h \
+ window.h
+SOURCES = layoutitem.cpp \
+ main.cpp \
+ window.cpp
+RESOURCES = basicgraphicslayouts.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/basicgraphicslayouts
+sources.files = $$SOURCES $$HEADERS $$RESOURCES basicgraphicslayouts.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/basicgraphicslayouts
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A645 \ No newline at end of file
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..8216b6e97b
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "layoutitem.h"
+
+//! [0]
+LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
+ : QGraphicsWidget(parent)
+{
+ pix = new QPixmap(QLatin1String(":/images/block.png"));
+ // Do not allow a size smaller than the pixmap with two frames around it.
+ setMinimumSize(pix->size() + QSize(12, 12));
+}
+//! [0]
+
+LayoutItem::~LayoutItem()
+{
+ delete 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 = pix->width();
+ qreal h = 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, *pix);
+}
+//! [2]
diff --git a/examples/graphicsview/basicgraphicslayouts/layoutitem.h b/examples/graphicsview/basicgraphicslayouts/layoutitem.h
new file mode 100644
index 0000000000..cbda636d19
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/layoutitem.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LAYOUTITEM_H
+#define LAYOUTITEM_H
+#include <QtGui>
+
+//! [0]
+class LayoutItem : public QGraphicsWidget
+{
+ Q_OBJECT
+
+public:
+ LayoutItem(QGraphicsItem *parent = 0);
+ ~LayoutItem();
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget = 0);
+
+private:
+ QPixmap *pix;
+};
+//! [0]
+
+#endif
diff --git a/examples/graphicsview/basicgraphicslayouts/main.cpp b/examples/graphicsview/basicgraphicslayouts/main.cpp
new file mode 100644
index 0000000000..720f6ff491
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..afa98ebb14
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/window.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..0ecde8ae02
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/window.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a434efcf34
--- /dev/null
+++ b/examples/graphicsview/collidingmice/collidingmice.pro
@@ -0,0 +1,18 @@
+HEADERS += \
+ mouse.h
+SOURCES += \
+ main.cpp \
+ mouse.cpp
+
+RESOURCES += \
+ mice.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/collidingmice
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS collidingmice.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/collidingmice
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A643 \ No newline at end of file
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..4a44481b90
--- /dev/null
+++ b/examples/graphicsview/collidingmice/main.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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();
+
+ 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..1d10574631
--- /dev/null
+++ b/examples/graphicsview/collidingmice/mouse.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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/graphicsview/collidingmice/mouse.h b/examples/graphicsview/collidingmice/mouse.h
new file mode 100644
index 0000000000..832ea53704
--- /dev/null
+++ b/examples/graphicsview/collidingmice/mouse.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOUSE_H
+#define MOUSE_H
+
+#include <QGraphicsItem>
+#include <QObject>
+
+//! [0]
+class Mouse : public QObject, public QGraphicsItem
+{
+ 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/graphicsview/diagramscene/arrow.cpp b/examples/graphicsview/diagramscene/arrow.cpp
new file mode 100644
index 0000000000..0bc2ca8a70
--- /dev/null
+++ b/examples/graphicsview/diagramscene/arrow.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f624eb1c0b
--- /dev/null
+++ b/examples/graphicsview/diagramscene/arrow.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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; }
+
+
+public slots:
+ 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..b31f6b5c91
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramitem.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+}
+//! [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..5409f20cc9
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramitem.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..8065ec551c
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramscene.cpp
@@ -0,0 +1,241 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e33ee4f075
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramscene.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..9e90e0d534
--- /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]/graphicsview/diagramscene
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS diagramscene.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..008b70fd46
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramtextitem.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..6f0ddcbf0c
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramtextitem.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4e0307484d
--- /dev/null
+++ b/examples/graphicsview/diagramscene/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b536a7af85
--- /dev/null
+++ b/examples/graphicsview/diagramscene/mainwindow.cpp
@@ -0,0 +1,651 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QLabel>
+
+#include "mainwindow.h"
+#include "diagramitem.h"
+#include "diagramscene.h"
+#include "diagramtextitem.h"
+
+const int InsertTextButton = 10;
+
+//! [0]
+MainWindow::MainWindow()
+{
+ createActions();
+ createToolBox();
+ createMenus();
+
+ scene = new DiagramScene(itemMenu);
+ 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"));
+}
+//! [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() == DiagramItem::Type) {
+ qgraphicsitem_cast<DiagramItem *>(item)->removeArrows();
+ }
+ scene->removeItem(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",
+ qVariantValue<QColor>(textAction->data())));
+ textButtonTriggered();
+}
+//! [12]
+
+//! [13]
+void MainWindow::itemColorChanged()
+{
+ fillAction = qobject_cast<QAction *>(sender());
+ fillColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/floodfill.png",
+ qVariantValue<QColor>(fillAction->data())));
+ fillButtonTriggered();
+}
+//! [13]
+
+//! [14]
+void MainWindow::lineColorChanged()
+{
+ lineAction = qobject_cast<QAction *>(sender());
+ lineColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/linecolor.png",
+ qVariantValue<QColor>(lineAction->data())));
+ lineButtonTriggered();
+}
+//! [14]
+
+//! [15]
+void MainWindow::textButtonTriggered()
+{
+ scene->setTextColor(qVariantValue<QColor>(textAction->data()));
+}
+//! [15]
+
+//! [16]
+void MainWindow::fillButtonTriggered()
+{
+ scene->setItemColor(qVariantValue<QColor>(fillAction->data()));
+}
+//! [16]
+
+//! [17]
+void MainWindow::lineButtonTriggered()
+{
+ scene->setLineColor(qVariantValue<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;
+ 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;
+ 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->setShortcut(tr("Ctrl+X"));
+ 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();
+ fontSizeCombo = new QComboBox();
+ connect(fontCombo, SIGNAL(currentFontChanged(const QFont &)),
+ this, SLOT(currentFontChanged(const 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(const QString &)),
+ this, SLOT(fontSizeChanged(const 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;
+ 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(const QString &)),
+ this, SLOT(sceneScaleChanged(const 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;
+ 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..e4dae4ff02
--- /dev/null
+++ b/examples/graphicsview/diagramscene/mainwindow.h
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "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..2d6b145e5b
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/coloritem.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "coloritem.h"
+
+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);
+}
+
+QRectF ColorItem::boundingRect() const
+{
+ return QRectF(-15.5, -15.5, 34, 34);
+}
+
+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);
+}
+
+void ColorItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (event->button() != Qt::LeftButton) {
+ event->ignore();
+ return;
+ }
+
+ setCursor(Qt::ClosedHandCursor);
+}
+
+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);
+
+ 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));
+ } 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));
+ }
+
+ drag->exec();
+ setCursor(Qt::OpenHandCursor);
+}
+
+void ColorItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+{
+ setCursor(Qt::OpenHandCursor);
+}
diff --git a/examples/graphicsview/dragdroprobot/coloritem.h b/examples/graphicsview/dragdroprobot/coloritem.h
new file mode 100644
index 0000000000..67b2c70dec
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/coloritem.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COLORITEM_H
+#define COLORITEM_H
+
+#include <QGraphicsItem>
+
+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;
+};
+
+#endif
diff --git a/examples/graphicsview/dragdroprobot/dragdroprobot.pro b/examples/graphicsview/dragdroprobot/dragdroprobot.pro
new file mode 100644
index 0000000000..756a9c8d42
--- /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]/graphicsview/dragdroprobot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS dragdroprobot.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/dragdroprobot
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..204305efaf
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/main.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "coloritem.h"
+#include "robot.h"
+
+#include <math.h>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ 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);
+
+ 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();
+}
diff --git a/examples/graphicsview/dragdroprobot/robot.cpp b/examples/graphicsview/dragdroprobot/robot.cpp
new file mode 100644
index 0000000000..c6d8c44250
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/robot.cpp
@@ -0,0 +1,273 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "robot.h"
+
+RobotPart::RobotPart(QGraphicsItem *parent)
+ : QGraphicsItem(parent), color(Qt::lightGray), dragOver(false)
+{
+ setAcceptDrops(true);
+}
+
+void RobotPart::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+{
+ if (event->mimeData()->hasColor()
+ || (qgraphicsitem_cast<RobotHead *>(this) && event->mimeData()->hasImage())) {
+ event->setAccepted(true);
+ dragOver = true;
+ update();
+ } else {
+ event->setAccepted(false);
+ }
+}
+
+void RobotPart::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+{
+ Q_UNUSED(event);
+ dragOver = false;
+ update();
+}
+
+void RobotPart::dropEvent(QGraphicsSceneDragDropEvent *event)
+{
+ dragOver = false;
+ if (event->mimeData()->hasColor())
+ color = qVariantValue<QColor>(event->mimeData()->colorData());
+ else if (event->mimeData()->hasImage())
+ pixmap = qVariantValue<QPixmap>(event->mimeData()->imageData());
+ update();
+}
+
+RobotHead::RobotHead(QGraphicsItem *parent)
+ : RobotPart(parent)
+{
+}
+
+QRectF RobotHead::boundingRect() const
+{
+ return QRectF(-15, -50, 30, 50);
+}
+
+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);
+ }
+}
+
+int RobotHead::type() const
+{
+ return Type;
+}
+
+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);
+}
+
+Robot::Robot()
+{
+ QGraphicsItem *torsoItem = new RobotTorso(this);
+ QGraphicsItem *headItem = new RobotHead(torsoItem);
+ QGraphicsItem *upperLeftArmItem = new RobotLimb(torsoItem);
+ QGraphicsItem *lowerLeftArmItem = new RobotLimb(upperLeftArmItem);
+ QGraphicsItem *upperRightArmItem = new RobotLimb(torsoItem);
+ QGraphicsItem *lowerRightArmItem = new RobotLimb(upperRightArmItem);
+ QGraphicsItem *upperRightLegItem = new RobotLimb(torsoItem);
+ QGraphicsItem *lowerRightLegItem = new RobotLimb(upperRightLegItem);
+ QGraphicsItem *upperLeftLegItem = new RobotLimb(torsoItem);
+ QGraphicsItem *lowerLeftLegItem = new RobotLimb(upperLeftLegItem);
+
+ 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);
+
+ timeLine = new QTimeLine;
+
+ QGraphicsItemAnimation *headAnimation = new QGraphicsItemAnimation;
+ headAnimation->setItem(headItem);
+ headAnimation->setTimeLine(timeLine);
+ headAnimation->setRotationAt(0, 20);
+ headAnimation->setRotationAt(1, -20);
+ headAnimation->setScaleAt(1, 1.1, 1.1);
+
+ QGraphicsItemAnimation *upperLeftArmAnimation = new QGraphicsItemAnimation;
+ upperLeftArmAnimation->setItem(upperLeftArmItem);
+ upperLeftArmAnimation->setTimeLine(timeLine);
+ upperLeftArmAnimation->setRotationAt(0, 190);
+ upperLeftArmAnimation->setRotationAt(1, 180);
+
+ QGraphicsItemAnimation *lowerLeftArmAnimation = new QGraphicsItemAnimation;
+ lowerLeftArmAnimation->setItem(lowerLeftArmItem);
+ lowerLeftArmAnimation->setTimeLine(timeLine);
+ lowerLeftArmAnimation->setRotationAt(0, 50);
+ lowerLeftArmAnimation->setRotationAt(1, 10);
+
+ QGraphicsItemAnimation *upperRightArmAnimation = new QGraphicsItemAnimation;
+ upperRightArmAnimation->setItem(upperRightArmItem);
+ upperRightArmAnimation->setTimeLine(timeLine);
+ upperRightArmAnimation->setRotationAt(0, 300);
+ upperRightArmAnimation->setRotationAt(1, 310);
+
+ QGraphicsItemAnimation *lowerRightArmAnimation = new QGraphicsItemAnimation;
+ lowerRightArmAnimation->setItem(lowerRightArmItem);
+ lowerRightArmAnimation->setTimeLine(timeLine);
+ lowerRightArmAnimation->setRotationAt(0, 0);
+ lowerRightArmAnimation->setRotationAt(1, -70);
+
+ QGraphicsItemAnimation *upperLeftLegAnimation = new QGraphicsItemAnimation;
+ upperLeftLegAnimation->setItem(upperLeftLegItem);
+ upperLeftLegAnimation->setTimeLine(timeLine);
+ upperLeftLegAnimation->setRotationAt(0, 150);
+ upperLeftLegAnimation->setRotationAt(1, 80);
+
+ QGraphicsItemAnimation *lowerLeftLegAnimation = new QGraphicsItemAnimation;
+ lowerLeftLegAnimation->setItem(lowerLeftLegItem);
+ lowerLeftLegAnimation->setTimeLine(timeLine);
+ lowerLeftLegAnimation->setRotationAt(0, 70);
+ lowerLeftLegAnimation->setRotationAt(1, 10);
+
+ QGraphicsItemAnimation *upperRightLegAnimation = new QGraphicsItemAnimation;
+ upperRightLegAnimation->setItem(upperRightLegItem);
+ upperRightLegAnimation->setTimeLine(timeLine);
+ upperRightLegAnimation->setRotationAt(0, 40);
+ upperRightLegAnimation->setRotationAt(1, 120);
+
+ QGraphicsItemAnimation *lowerRightLegAnimation = new QGraphicsItemAnimation;
+ lowerRightLegAnimation->setItem(lowerRightLegItem);
+ lowerRightLegAnimation->setTimeLine(timeLine);
+ lowerRightLegAnimation->setRotationAt(0, 10);
+ lowerRightLegAnimation->setRotationAt(1, 50);
+
+ QGraphicsItemAnimation *torsoAnimation = new QGraphicsItemAnimation;
+ torsoAnimation->setItem(torsoItem);
+ torsoAnimation->setTimeLine(timeLine);
+ torsoAnimation->setRotationAt(0, 5);
+ torsoAnimation->setRotationAt(1, -20);
+
+ timeLine->setUpdateInterval(1000 / 25);
+ timeLine->setCurveShape(QTimeLine::SineCurve);
+ timeLine->setLoopCount(0);
+ timeLine->setDuration(2000);
+ timeLine->start();
+}
+
+Robot::~Robot()
+{
+ delete timeLine;
+}
+
+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);
+}
diff --git a/examples/graphicsview/dragdroprobot/robot.h b/examples/graphicsview/dragdroprobot/robot.h
new file mode 100644
index 0000000000..c0b6d14610
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/robot.h
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ROBOT_H
+#define ROBOT_H
+
+#include <QGraphicsItem>
+
+QT_BEGIN_NAMESPACE
+class QGraphicsSceneMouseEvent;
+class QTimeLine;
+QT_END_NAMESPACE
+
+class RobotPart : public QGraphicsItem
+{
+public:
+ RobotPart(QGraphicsItem *parent = 0);
+
+protected:
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
+ void dropEvent(QGraphicsSceneDragDropEvent *event);
+
+ QPixmap pixmap;
+ QColor color;
+ bool dragOver;
+};
+
+class RobotHead : public RobotPart
+{
+public:
+ RobotHead(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+ enum { Type = UserType + 1 };
+ int type() const;
+};
+
+class RobotTorso : public RobotPart
+{
+public:
+ RobotTorso(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+};
+
+class RobotLimb : public RobotPart
+{
+public:
+ RobotLimb(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+};
+
+class Robot : public RobotPart
+{
+public:
+ Robot();
+ ~Robot();
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+private:
+ QTimeLine *timeLine;
+};
+
+#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..4018c25aed
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/edge.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QPainter>
+
+#include "edge.h"
+#include "node.h"
+
+#include <math.h>
+
+static const double Pi = 3.14159265358979323846264338327950288419717;
+static double TwoPi = 2.0 * Pi;
+
+Edge::Edge(Node *sourceNode, Node *destNode)
+ : arrowSize(10)
+{
+ setAcceptedMouseButtons(0);
+ source = sourceNode;
+ dest = destNode;
+ source->addEdge(this);
+ dest->addEdge(this);
+ adjust();
+}
+
+Edge::~Edge()
+{
+}
+
+Node *Edge::sourceNode() const
+{
+ return source;
+}
+
+void Edge::setSourceNode(Node *node)
+{
+ source = node;
+ adjust();
+}
+
+Node *Edge::destNode() const
+{
+ return dest;
+}
+
+void Edge::setDestNode(Node *node)
+{
+ dest = node;
+ adjust();
+}
+
+void Edge::adjust()
+{
+ if (!source || !dest)
+ return;
+
+ QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
+ qreal length = line.length();
+ QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
+
+ prepareGeometryChange();
+ sourcePoint = line.p1() + edgeOffset;
+ destPoint = line.p2() - edgeOffset;
+}
+
+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);
+}
+
+void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ if (!source || !dest)
+ return;
+
+ // Draw the line itself
+ QLineF line(sourcePoint, destPoint);
+ painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+ painter->drawLine(line);
+
+ // Draw the arrows if there's enough room
+ 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);
+}
diff --git a/examples/graphicsview/elasticnodes/edge.h b/examples/graphicsview/elasticnodes/edge.h
new file mode 100644
index 0000000000..9078870e2a
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/edge.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EDGE_H
+#define EDGE_H
+
+#include <QGraphicsItem>
+
+class Node;
+
+class Edge : public QGraphicsItem
+{
+public:
+ Edge(Node *sourceNode, Node *destNode);
+ ~Edge();
+
+ Node *sourceNode() const;
+ void setSourceNode(Node *node);
+
+ Node *destNode() const;
+ void setDestNode(Node *node);
+
+ 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;
+};
+
+#endif
diff --git a/examples/graphicsview/elasticnodes/elasticnodes.pro b/examples/graphicsview/elasticnodes/elasticnodes.pro
new file mode 100644
index 0000000000..800eaae7b7
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/elasticnodes.pro
@@ -0,0 +1,22 @@
+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]/graphicsview/elasticnodes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS elasticnodes.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/elasticnodes
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A642 \ No newline at end of file
diff --git a/examples/graphicsview/elasticnodes/graphwidget.cpp b/examples/graphicsview/elasticnodes/graphwidget.cpp
new file mode 100644
index 0000000000..5c5029c720
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/graphwidget.cpp
@@ -0,0 +1,224 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "graphwidget.h"
+#include "edge.h"
+#include "node.h"
+
+#include <QDebug>
+#include <QGraphicsScene>
+#include <QWheelEvent>
+
+#include <math.h>
+
+GraphWidget::GraphWidget()
+ : 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);
+ setResizeAnchor(AnchorViewCenter);
+
+ 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);
+
+ scale(qreal(0.8), qreal(0.8));
+ setMinimumSize(400, 400);
+ setWindowTitle(tr("Elastic Nodes"));
+}
+
+void GraphWidget::itemMoved()
+{
+ if (!timerId)
+ timerId = startTimer(1000 / 25);
+}
+
+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);
+ }
+}
+
+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;
+ }
+}
+
+void GraphWidget::wheelEvent(QWheelEvent *event)
+{
+ scaleView(pow((double)2, -event->delta() / 240.0));
+}
+
+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);
+}
+
+void GraphWidget::scaleView(qreal scaleFactor)
+{
+ qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
+ if (factor < 0.07 || factor > 100)
+ return;
+
+ scale(scaleFactor, scaleFactor);
+}
diff --git a/examples/graphicsview/elasticnodes/graphwidget.h b/examples/graphicsview/elasticnodes/graphwidget.h
new file mode 100644
index 0000000000..2c86c7615c
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/graphwidget.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GRAPHWIDGET_H
+#define GRAPHWIDGET_H
+
+#include <QtGui/QGraphicsView>
+
+class Node;
+
+class GraphWidget : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ GraphWidget();
+
+ 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;
+};
+
+#endif
diff --git a/examples/graphicsview/elasticnodes/main.cpp b/examples/graphicsview/elasticnodes/main.cpp
new file mode 100644
index 0000000000..8043d58450
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..6942fa007d
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/node.cpp
@@ -0,0 +1,185 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGraphicsScene>
+#include <QGraphicsSceneMouseEvent>
+#include <QPainter>
+#include <QStyleOption>
+
+#include "edge.h"
+#include "node.h"
+#include "graphwidget.h"
+
+Node::Node(GraphWidget *graphWidget)
+ : graph(graphWidget)
+{
+ setFlag(ItemIsMovable);
+ setCacheMode(DeviceCoordinateCache);
+ setZValue(1);
+}
+
+void Node::addEdge(Edge *edge)
+{
+ edgeList << edge;
+ edge->adjust();
+}
+
+QList<Edge *> Node::edges() const
+{
+ return edgeList;
+}
+
+void Node::calculateForces()
+{
+ if (!scene() || scene()->mouseGrabberItem() == this) {
+ newPos = pos();
+ return;
+ }
+
+ // 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;
+
+ QLineF line(mapFromItem(node, 0, 0), QPointF(0, 0));
+ qreal dx = line.dx();
+ qreal dy = line.dy();
+ double l = 2.0 * (dx * dx + dy * dy);
+ if (l > 0) {
+ xvel += (dx * 150.0) / l;
+ yvel += (dy * 150.0) / l;
+ }
+ }
+
+ // Now subtract all forces pulling items together
+ double weight = (edgeList.size() + 1) * 10;
+ foreach (Edge *edge, edgeList) {
+ QPointF pos;
+ if (edge->sourceNode() == this)
+ pos = mapFromItem(edge->destNode(), 0, 0);
+ else
+ pos = mapFromItem(edge->sourceNode(), 0, 0);
+ xvel += pos.x() / weight;
+ yvel += pos.y() / weight;
+ }
+
+ if (qAbs(xvel) < 0.1 && qAbs(yvel) < 0.1)
+ xvel = yvel = 0;
+
+ 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));
+}
+
+bool Node::advance()
+{
+ if (newPos == pos())
+ return false;
+
+ setPos(newPos);
+ return true;
+}
+
+QRectF Node::boundingRect() const
+{
+ qreal adjust = 2;
+ return QRectF(-10 - adjust, -10 - adjust,
+ 23 + adjust, 23 + adjust);
+}
+
+QPainterPath Node::shape() const
+{
+ QPainterPath path;
+ path.addEllipse(-10, -10, 20, 20);
+ return path;
+}
+
+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);
+}
+
+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);
+}
+
+void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ update();
+ QGraphicsItem::mousePressEvent(event);
+}
+
+void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ update();
+ QGraphicsItem::mouseReleaseEvent(event);
+}
diff --git a/examples/graphicsview/elasticnodes/node.h b/examples/graphicsview/elasticnodes/node.h
new file mode 100644
index 0000000000..42309c4538
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/node.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef NODE_H
+#define NODE_H
+
+#include <QGraphicsItem>
+#include <QList>
+
+class Edge;
+class GraphWidget;
+QT_BEGIN_NAMESPACE
+class QGraphicsSceneMouseEvent;
+QT_END_NAMESPACE
+
+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;
+};
+
+#endif
diff --git a/examples/graphicsview/graphicsview.pro b/examples/graphicsview/graphicsview.pro
new file mode 100644
index 0000000000..e955725b15
--- /dev/null
+++ b/examples/graphicsview/graphicsview.pro
@@ -0,0 +1,22 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ elasticnodes \
+ collidingmice \
+ padnavigator \
+ basicgraphicslayouts
+
+!symbian: SUBDIRS += \
+ diagramscene \
+ dragdroprobot \
+ basicgraphicslayouts
+
+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]/graphicsview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS graphicsview.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/graphicsview/padnavigator/backside.ui b/examples/graphicsview/padnavigator/backside.ui
new file mode 100644
index 0000000000..afa488c6f4
--- /dev/null
+++ b/examples/graphicsview/padnavigator/backside.ui
@@ -0,0 +1,208 @@
+<ui version="4.0" >
+ <class>BackSide</class>
+ <widget class="QWidget" name="BackSide" >
+ <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..a7d00c8448
--- /dev/null
+++ b/examples/graphicsview/padnavigator/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#ifndef QT_NO_OPENGL
+# include <QtOpenGL>
+#endif
+
+#include "panel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Q_INIT_RESOURCE(padnavigator);
+
+ Panel panel(3, 3);
+ panel.setFocus();
+ panel.showFullScreen();
+
+ return app.exec();
+}
diff --git a/examples/graphicsview/padnavigator/padnavigator.pro b/examples/graphicsview/padnavigator/padnavigator.pro
new file mode 100644
index 0000000000..7fa85072c3
--- /dev/null
+++ b/examples/graphicsview/padnavigator/padnavigator.pro
@@ -0,0 +1,29 @@
+HEADERS += \
+ panel.h \
+ roundrectitem.h \
+ splashitem.h
+
+SOURCES += \
+ panel.cpp \
+ roundrectitem.cpp \
+ splashitem.cpp \
+ main.cpp
+
+RESOURCES += \
+ padnavigator.qrc
+
+FORMS += \
+ backside.ui
+
+contains(QT_CONFIG, opengl):QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/padnavigator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS padnavigator.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/padnavigator
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+CONFIG += console
+
+symbian:TARGET.UID3 = 0xA000A644 \ No newline at end of file
diff --git a/examples/graphicsview/padnavigator/padnavigator.qrc b/examples/graphicsview/padnavigator/padnavigator.qrc
new file mode 100644
index 0000000000..30ee8e1a08
--- /dev/null
+++ b/examples/graphicsview/padnavigator/padnavigator.qrc
@@ -0,0 +1,14 @@
+<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>
+ <file>images/blue_angle_swirl.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/graphicsview/padnavigator/panel.cpp b/examples/graphicsview/padnavigator/panel.cpp
new file mode 100644
index 0000000000..28a3cb4eb8
--- /dev/null
+++ b/examples/graphicsview/padnavigator/panel.cpp
@@ -0,0 +1,238 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "panel.h"
+#include "roundrectitem.h"
+#include "splashitem.h"
+#include "ui_backside.h"
+
+#ifndef QT_NO_OPENGL
+#include <QtOpenGL/QtOpenGL>
+#else
+#endif
+#include <QtGui/QtGui>
+
+#include <math.h>
+
+Panel::Panel(int width, int height)
+ : selectedX(0),
+ selectedY(0),
+ width(width),
+ height(height),
+ flipped(false),
+ flipLeft(true)
+{
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setCacheMode(CacheBackground);
+ setViewportUpdateMode(FullViewportUpdate);
+ setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform
+ | QPainter::TextAntialiasing);
+ setBackgroundBrush(QPixmap(":/images/blue_angle_swirl.jpg"));
+#ifndef QT_NO_OPENGL
+ setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+#endif
+ setMinimumSize(50, 50);
+
+ selectionTimeLine = new QTimeLine(150, this);
+ flipTimeLine = new QTimeLine(500, this);
+
+ QRectF bounds((-width / 2.0) * 150, (-height / 2.0) * 150, width * 150, height * 150);
+
+ scene = new QGraphicsScene(bounds, this);
+ scene->setItemIndexMethod(QGraphicsScene::NoIndex);
+ setScene(scene);
+
+ baseItem = new RoundRectItem(bounds, QColor(226, 255, 92, 64));
+ scene->addItem(baseItem);
+
+ QWidget *embed = new QWidget;
+ ui = new Ui_BackSide;
+ ui->setupUi(embed);
+ ui->hostName->setFocus();
+
+ backItem = new RoundRectItem(bounds, embed->palette().window(), embed);
+ backItem->setTransform(QTransform().rotate(180, Qt::YAxis));
+ backItem->setParentItem(baseItem);
+
+ selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray);
+ selectionItem->setParentItem(baseItem);
+ selectionItem->setZValue(-1);
+ selectionItem->setPos(posForLocation(0, 0));
+ startPos = selectionItem->pos();
+
+ grid = new QGraphicsItem **[height];
+
+ for (int y = 0; y < height; ++y) {
+ grid[y] = new QGraphicsItem *[width];
+
+ for (int x = 0; x < width; ++x) {
+ RoundRectItem *item = new RoundRectItem(QRectF(-54, -54, 108, 108),
+ QColor(214, 240, 110, 128));
+ item->setPos(posForLocation(x, y));
+
+ item->setParentItem(baseItem);
+ item->setFlag(QGraphicsItem::ItemIsFocusable);
+ grid[y][x] = item;
+
+ switch (qrand() % 9) {
+ case 0: item->setPixmap(QPixmap(":/images/kontact_contacts.png")); break;
+ case 1: item->setPixmap(QPixmap(":/images/kontact_journal.png")); break;
+ case 2: item->setPixmap(QPixmap(":/images/kontact_notes.png")); break;
+ case 3: item->setPixmap(QPixmap(":/images/kopeteavailable.png")); break;
+ case 4: item->setPixmap(QPixmap(":/images/metacontact_online.png")); break;
+ case 5: item->setPixmap(QPixmap(":/images/minitools.png")); break;
+ case 6: item->setPixmap(QPixmap(":/images/kontact_journal.png")); break;
+ case 7: item->setPixmap(QPixmap(":/images/kontact_contacts.png")); break;
+ case 8: item->setPixmap(QPixmap(":/images/kopeteavailable.png")); break;
+ default:
+ break;
+ }
+
+ connect(item, SIGNAL(activated()), this, SLOT(flip()));
+ }
+ }
+
+ grid[0][0]->setFocus();
+
+ connect(backItem, SIGNAL(activated()),
+ this, SLOT(flip()));
+ connect(selectionTimeLine, SIGNAL(valueChanged(qreal)),
+ this, SLOT(updateSelectionStep(qreal)));
+ connect(flipTimeLine, SIGNAL(valueChanged(qreal)),
+ this, SLOT(updateFlipStep(qreal)));
+
+ splash = new SplashItem;
+ splash->setZValue(5);
+ splash->setPos(-splash->rect().width() / 2, scene->sceneRect().top());
+ scene->addItem(splash);
+
+ splash->grabKeyboard();
+
+ updateSelectionStep(0);
+
+ setWindowTitle(tr("Pad Navigator Example"));
+}
+
+Panel::~Panel()
+{
+ for (int y = 0; y < height; ++y)
+ delete [] grid[y];
+ delete [] grid;
+}
+
+void Panel::keyPressEvent(QKeyEvent *event)
+{
+ if (splash->isVisible() || event->key() == Qt::Key_Return || flipped) {
+ QGraphicsView::keyPressEvent(event);
+ return;
+ }
+
+ selectedX = (selectedX + width + (event->key() == Qt::Key_Right) - (event->key() == Qt::Key_Left)) % width;
+ selectedY = (selectedY + height + (event->key() == Qt::Key_Down) - (event->key() == Qt::Key_Up)) % height;
+ grid[selectedY][selectedX]->setFocus();
+
+ selectionTimeLine->stop();
+ startPos = selectionItem->pos();
+ endPos = posForLocation(selectedX, selectedY);
+ selectionTimeLine->start();
+}
+
+void Panel::resizeEvent(QResizeEvent *event)
+{
+ QGraphicsView::resizeEvent(event);
+ fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
+}
+
+void Panel::updateSelectionStep(qreal val)
+{
+ QPointF newPos(startPos.x() + (endPos - startPos).x() * val,
+ startPos.y() + (endPos - startPos).y() * val);
+ selectionItem->setPos(newPos);
+
+ QTransform transform;
+ yrot = newPos.x() / 6.0;
+ xrot = newPos.y() / 6.0;
+ transform.rotate(newPos.x() / 6.0, Qt::YAxis);
+ transform.rotate(newPos.y() / 6.0, Qt::XAxis);
+ baseItem->setTransform(transform);
+}
+
+void Panel::updateFlipStep(qreal val)
+{
+ qreal finalxrot = xrot - xrot * val;
+ qreal finalyrot;
+ if (flipLeft)
+ finalyrot = yrot - yrot * val - 180 * val;
+ else
+ finalyrot = yrot - yrot * val + 180 * val;
+ QTransform transform;
+ transform.rotate(finalyrot, Qt::YAxis);
+ transform.rotate(finalxrot, Qt::XAxis);
+ qreal scale = 1 - sin(3.14 * val) * 0.3;
+ transform.scale(scale, scale);
+ baseItem->setTransform(transform);
+ if (val == 0)
+ grid[selectedY][selectedX]->setFocus();
+}
+
+void Panel::flip()
+{
+ if (flipTimeLine->state() == QTimeLine::Running)
+ return;
+
+ if (flipTimeLine->currentValue() == 0) {
+ flipTimeLine->setDirection(QTimeLine::Forward);
+ flipTimeLine->start();
+ flipped = true;
+ flipLeft = selectionItem->pos().x() < 0;
+ } else {
+ flipTimeLine->setDirection(QTimeLine::Backward);
+ flipTimeLine->start();
+ flipped = false;
+ }
+}
+
+QPointF Panel::posForLocation(int x, int y) const
+{
+ return QPointF(x * 150, y * 150)
+ - QPointF((width - 1) * 75, (height - 1) * 75);
+}
diff --git a/examples/graphicsview/padnavigator/panel.h b/examples/graphicsview/padnavigator/panel.h
new file mode 100644
index 0000000000..03876b778d
--- /dev/null
+++ b/examples/graphicsview/padnavigator/panel.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/qgraphicsview.h>
+
+QT_BEGIN_NAMESPACE
+class QTimeLine;
+class Ui_BackSide;
+QT_END_NAMESPACE;
+
+class RoundRectItem;
+
+class Panel : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ Panel(int width, int height);
+ ~Panel();
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+private Q_SLOTS:
+ void updateSelectionStep(qreal val);
+ void updateFlipStep(qreal val);
+ void flip();
+
+private:
+ QPointF posForLocation(int x, int y) const;
+
+ QGraphicsScene *scene;
+ RoundRectItem *selectionItem;
+ RoundRectItem *baseItem;
+ RoundRectItem *backItem;
+ QGraphicsWidget *splash;
+ QTimeLine *selectionTimeLine;
+ QTimeLine *flipTimeLine;
+ int selectedX, selectedY;
+
+ QGraphicsItem ***grid;
+
+ QPointF startPos;
+ QPointF endPos;
+ qreal xrot, yrot;
+ qreal xrot2, yrot2;
+
+ int width;
+ int height;
+ bool flipped;
+ bool flipLeft;
+
+ Ui_BackSide *ui;
+};
diff --git a/examples/graphicsview/padnavigator/roundrectitem.cpp b/examples/graphicsview/padnavigator/roundrectitem.cpp
new file mode 100644
index 0000000000..c5dc35d490
--- /dev/null
+++ b/examples/graphicsview/padnavigator/roundrectitem.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "roundrectitem.h"
+
+#include <QtGui/QtGui>
+
+RoundRectItem::RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget)
+ : QGraphicsRectItem(rect),
+ brush(brush),
+ timeLine(75),
+ lastVal(0),
+ opa(1),
+ proxyWidget(0)
+{
+ connect(&timeLine, SIGNAL(valueChanged(qreal)),
+ this, SLOT(updateValue(qreal)));
+
+ if (embeddedWidget) {
+ proxyWidget = new QGraphicsProxyWidget(this);
+ proxyWidget->setFocusPolicy(Qt::StrongFocus);
+ proxyWidget->setWidget(embeddedWidget);
+ proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25));
+ }
+}
+
+void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QTransform x = painter->worldTransform();
+
+ QLineF unit = x.map(QLineF(0, 0, 1, 1));
+ if (unit.p1().x() > unit.p2().x() || unit.p1().y() > unit.p2().y()) {
+ if (proxyWidget && proxyWidget->isVisible()) {
+ proxyWidget->hide();
+ proxyWidget->setGeometry(rect());
+ }
+ return;
+ }
+
+ if (proxyWidget && !proxyWidget->isVisible()) {
+ proxyWidget->show();
+ proxyWidget->setFocus();
+ }
+ if (proxyWidget && proxyWidget->pos() != QPoint())
+ proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25));
+
+ painter->setOpacity(opacity());
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(0, 0, 0, 64));
+ painter->drawRoundRect(rect().translated(2, 2));
+
+ if (!proxyWidget) {
+ QLinearGradient gradient(rect().topLeft(), rect().bottomRight());
+ const QColor col = brush.color();
+ gradient.setColorAt(0, col);
+ gradient.setColorAt(1, col.dark(int(200 + lastVal * 50)));
+ painter->setBrush(gradient);
+ } else {
+ painter->setBrush(brush);
+ }
+
+ painter->setPen(QPen(Qt::black, 1));
+ painter->drawRoundRect(rect());
+ if (!pix.isNull()) {
+ painter->scale(1.95, 1.95);
+ painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix);;
+ }
+}
+
+QRectF RoundRectItem::boundingRect() const
+{
+ qreal penW = 0.5;
+ qreal shadowW = 2.0;
+ return rect().adjusted(-penW, -penW, penW + shadowW, penW + shadowW);
+}
+
+void RoundRectItem::setPixmap(const QPixmap &pixmap)
+{
+ pix = pixmap;
+ if (scene() && isVisible())
+ update();
+}
+
+qreal RoundRectItem::opacity() const
+{
+ RoundRectItem *parent = parentItem() ? (RoundRectItem *)parentItem() : 0;
+ return opa + (parent ? parent->opacity() : 0);
+}
+
+void RoundRectItem::setOpacity(qreal opacity)
+{
+ opa = opacity;
+ update();
+}
+
+void RoundRectItem::keyPressEvent(QKeyEvent *event)
+{
+ if (event->isAutoRepeat() || event->key() != Qt::Key_Return
+ || (timeLine.state() == QTimeLine::Running && timeLine.direction() == QTimeLine::Forward)) {
+ QGraphicsRectItem::keyPressEvent(event);
+ return;
+ }
+
+ timeLine.stop();
+ timeLine.setDirection(QTimeLine::Forward);
+ timeLine.start();
+ emit activated();
+}
+
+void RoundRectItem::keyReleaseEvent(QKeyEvent *event)
+{
+ if (event->key() != Qt::Key_Return) {
+ QGraphicsRectItem::keyReleaseEvent(event);
+ return;
+ }
+ timeLine.stop();
+ timeLine.setDirection(QTimeLine::Backward);
+ timeLine.start();
+}
+
+void RoundRectItem::updateValue(qreal value)
+{
+ lastVal = value;
+ if (!proxyWidget)
+ setTransform(QTransform().scale(1 - value / 10.0, 1 - value / 10.0));
+}
diff --git a/examples/graphicsview/padnavigator/roundrectitem.h b/examples/graphicsview/padnavigator/roundrectitem.h
new file mode 100644
index 0000000000..33e33d7ec0
--- /dev/null
+++ b/examples/graphicsview/padnavigator/roundrectitem.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qobject.h>
+#include <QtCore/qtimeline.h>
+#include <QtGui/qgraphicsitem.h>
+#include <QtGui/qbrush.h>
+
+QT_BEGIN_NAMESPACE
+class QGraphicsProxyWidget;
+QT_END_NAMESPACE;
+
+class RoundRectItem : public QObject, public QGraphicsRectItem
+{
+ Q_OBJECT
+public:
+ RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget = 0);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
+ QRectF boundingRect() const;
+
+ void setPixmap(const QPixmap &pixmap);
+
+ qreal opacity() const;
+ void setOpacity(qreal opacity);
+
+Q_SIGNALS:
+ void activated();
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+ void keyReleaseEvent(QKeyEvent *event);
+
+private slots:
+ void updateValue(qreal value);
+
+private:
+ QBrush brush;
+ QPixmap pix;
+ QTimeLine timeLine;
+ qreal lastVal;
+ qreal opa;
+
+ QGraphicsProxyWidget *proxyWidget;
+};
diff --git a/examples/graphicsview/padnavigator/splashitem.cpp b/examples/graphicsview/padnavigator/splashitem.cpp
new file mode 100644
index 0000000000..2a374bf0a5
--- /dev/null
+++ b/examples/graphicsview/padnavigator/splashitem.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "splashitem.h"
+
+#include <QtGui/QtGui>
+
+SplashItem::SplashItem(QGraphicsItem *parent)
+ : QGraphicsWidget(parent)
+{
+ opacity = 1.0;
+
+
+ timeLine = new QTimeLine(350);
+ timeLine->setCurveShape(QTimeLine::EaseInCurve);
+ connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(setValue(qreal)));
+
+ 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. Please press any key to continue.");
+ resize(400, 175);
+}
+
+void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ painter->setOpacity(opacity);
+ painter->setPen(QPen(Qt::black, 2));
+ painter->setBrush(QColor(245, 245, 255, 220));
+ painter->setClipRect(rect());
+ painter->drawRoundRect(3, -100 + 3, 400 - 6, 250 - 6);
+
+ QRectF textRect = rect().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);
+}
+
+void SplashItem::keyPressEvent(QKeyEvent * /* event */)
+{
+ if (timeLine->state() == QTimeLine::NotRunning)
+ timeLine->start();
+}
+
+void SplashItem::setValue(qreal value)
+{
+ opacity = 1 - value;
+ setPos(x(), scene()->sceneRect().top() - rect().height() * value);
+ if (value == 1)
+ hide();
+}
diff --git a/examples/graphicsview/padnavigator/splashitem.h b/examples/graphicsview/padnavigator/splashitem.h
new file mode 100644
index 0000000000..982bbe293d
--- /dev/null
+++ b/examples/graphicsview/padnavigator/splashitem.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qobject.h>
+#include <QtCore/qtimeline.h>
+#include <QtGui/qgraphicswidget.h>
+
+class SplashItem : public QGraphicsWidget
+{
+ Q_OBJECT
+public:
+ SplashItem(QGraphicsItem *parent = 0);
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+
+private Q_SLOTS:
+ void setValue(qreal value);
+
+private:
+ QTimeLine *timeLine;
+ QString text;
+ qreal opacity;
+};
diff --git a/examples/graphicsview/portedasteroids/animateditem.cpp b/examples/graphicsview/portedasteroids/animateditem.cpp
new file mode 100644
index 0000000000..ac41fb5244
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/animateditem.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "animateditem.h"
+
+#include <QtGui/qbitmap.h>
+#include <QtGui/qpainter.h>
+
+AnimatedPixmapItem::AnimatedPixmapItem(const QList<QPixmap> &animation,
+ QGraphicsScene *scene)
+ : QGraphicsItem(0, scene), currentFrame(0), vx(0), vy(0)
+{
+ for (int i = 0; i < animation.size(); ++i) {
+ QPixmap pixmap = animation.at(i);
+ Frame frame;
+ frame.pixmap = pixmap;
+ frame.shape = QPainterPath();
+ frame.boundingRect = pixmap.rect();
+ frames << frame;
+ }
+}
+
+void AnimatedPixmapItem::setFrame(int frame)
+{
+ if (!frames.isEmpty()) {
+ prepareGeometryChange();
+ currentFrame = frame % frames.size();
+ }
+}
+
+void AnimatedPixmapItem::advance(int phase)
+{
+ if (phase == 1)
+ moveBy(vx, vy);
+}
+
+QRectF AnimatedPixmapItem::boundingRect() const
+{
+ return frames.at(currentFrame).boundingRect;
+}
+
+QPainterPath AnimatedPixmapItem::shape() const
+{
+ const Frame &f = frames.at(currentFrame);
+ if (f.shape.isEmpty()) {
+ QPainterPath path;
+ path.addRegion(f.pixmap.createHeuristicMask());
+ const_cast<Frame &>(f).shape = path;
+ }
+ return f.shape;
+}
+
+void AnimatedPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/,
+ QWidget * /*widget*/)
+{
+ painter->drawPixmap(0, 0, frames.at(currentFrame).pixmap);
+}
diff --git a/examples/graphicsview/portedasteroids/animateditem.h b/examples/graphicsview/portedasteroids/animateditem.h
new file mode 100644
index 0000000000..54e8e563c1
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/animateditem.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANIMATEDPIXMAPITEM_H
+#define ANIMATEDPIXMAPITEM_H
+
+#include <QGraphicsItem>
+
+class AnimatedPixmapItem : public QGraphicsItem
+{
+public:
+ AnimatedPixmapItem(const QList<QPixmap> &animation, QGraphicsScene *scene = 0);
+
+ void setFrame(int frame);
+ inline int frame() const
+ { return currentFrame; }
+ inline int frameCount() const
+ { return frames.size(); }
+ inline QPixmap image(int frame) const
+ { return frames.isEmpty() ? QPixmap() : frames.at(frame % frames.size()).pixmap; }
+ inline void setVelocity(qreal xvel, qreal yvel)
+ { vx = xvel; vy = yvel; }
+ inline qreal xVelocity() const
+ { return vx; }
+ inline qreal yVelocity() const
+ { return vy; }
+
+ QRectF boundingRect() const;
+ QPainterPath shape() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+ void advance(int phase);
+
+private:
+ struct Frame {
+ QPixmap pixmap;
+ QPainterPath shape;
+ QRectF boundingRect;
+ };
+
+ int currentFrame;
+ QList<Frame> frames;
+ qreal vx, vy;
+};
+
+#endif
diff --git a/examples/graphicsview/portedasteroids/bg.png b/examples/graphicsview/portedasteroids/bg.png
new file mode 100644
index 0000000000..1201172f24
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/bg.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/ledmeter.cpp b/examples/graphicsview/portedasteroids/ledmeter.cpp
new file mode 100644
index 0000000000..37aee269cb
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/ledmeter.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * KAsteroids - Copyright (c) Martin R. Jones 1997
+ *
+ * Part of the KDE project
+ */
+
+#include <qpainter.h>
+//Added by qt3to4:
+#include <QResizeEvent>
+#include <Q3Frame>
+#include "ledmeter.h"
+
+KALedMeter::KALedMeter( QWidget *parent ) : Q3Frame( parent )
+{
+ mCRanges.setAutoDelete( TRUE );
+ mRange = 100;
+ mCount = 20;
+ mCurrentCount = 0;
+ mValue = 0;
+ setMinimumWidth( mCount * 2 + frameWidth() );
+}
+
+void KALedMeter::setRange( int r )
+{
+ mRange = r;
+ if ( mRange < 1 )
+ mRange = 1;
+ setValue( mValue );
+ update();
+}
+
+void KALedMeter::setCount( int c )
+{
+ mCount = c;
+ if ( mCount < 1 )
+ mCount = 1;
+ setMinimumWidth( mCount * 2 + frameWidth() );
+ calcColorRanges();
+ setValue( mValue );
+ update();
+}
+
+void KALedMeter::setValue( int v )
+{
+ mValue = v;
+ if ( mValue > mRange )
+ mValue = mRange;
+ else if ( mValue < 0 )
+ mValue = 0;
+ int c = ( mValue + mRange / mCount - 1 ) * mCount / mRange;
+ if ( c != mCurrentCount )
+ {
+ mCurrentCount = c;
+ update();
+ }
+}
+
+void KALedMeter::addColorRange( int pc, const QColor &c )
+{
+ ColorRange *cr = new ColorRange;
+ cr->mPc = pc;
+ cr->mColor = c;
+ mCRanges.append( cr );
+ calcColorRanges();
+}
+
+void KALedMeter::resizeEvent( QResizeEvent *e )
+{
+ Q3Frame::resizeEvent( e );
+ int w = ( width() - frameWidth() - 2 ) / mCount * mCount;
+ w += frameWidth() + 2;
+ setFrameRect( QRect( 0, 0, w, height() ) );
+}
+
+void KALedMeter::drawContents( QPainter *p )
+{
+ QRect b = contentsRect();
+
+ unsigned cidx = 0;
+ int ncol = mCount;
+ QColor col = colorGroup().foreground();
+
+ if ( !mCRanges.isEmpty() )
+ {
+ col = mCRanges.at( cidx )->mColor;
+ ncol = mCRanges.at( cidx )->mValue;
+ }
+ p->setBrush( col );
+ p->setPen( col );
+
+ int lw = b.width() / mCount;
+ int lx = b.left() + 1;
+ for ( int i = 0; i < mCurrentCount; i++, lx += lw )
+ {
+ if ( i > ncol )
+ {
+ if ( ++cidx < mCRanges.count() )
+ {
+ col = mCRanges.at( cidx )->mColor;
+ ncol = mCRanges.at( cidx )->mValue;
+ p->setBrush( col );
+ p->setPen( col );
+ }
+ }
+
+ p->drawRect( lx, b.top() + 1, lw - 1, b.height() - 2 );
+ }
+}
+
+void KALedMeter::calcColorRanges()
+{
+ int prev = 0;
+ ColorRange *cr;
+ for ( cr = mCRanges.first(); cr; cr = mCRanges.next() )
+ {
+ cr->mValue = prev + cr->mPc * mCount / 100;
+ prev = cr->mValue;
+ }
+}
+
diff --git a/examples/graphicsview/portedasteroids/ledmeter.h b/examples/graphicsview/portedasteroids/ledmeter.h
new file mode 100644
index 0000000000..117b113d9c
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/ledmeter.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * KAsteroids - Copyright (c) Martin R. Jones 1997
+ *
+ * Part of the KDE project
+ */
+
+#ifndef __LEDMETER_H__
+#define __LEDMETER_H__
+
+#include <q3frame.h>
+#include <q3ptrlist.h>
+//Added by qt3to4:
+#include <QResizeEvent>
+
+
+class KALedMeter : public Q3Frame
+{
+ Q_OBJECT
+public:
+ KALedMeter( QWidget *parent );
+
+ int range() const { return mRange; }
+ void setRange( int r );
+
+ int count() const { return mCount; }
+ void setCount( int c );
+
+ int value () const { return mValue; }
+
+ void addColorRange( int pc, const QColor &c );
+
+public slots:
+ void setValue( int v );
+
+protected:
+ virtual void resizeEvent( QResizeEvent * );
+ virtual void drawContents( QPainter * );
+ void calcColorRanges();
+
+protected:
+ struct ColorRange
+ {
+ int mPc;
+ int mValue;
+ QColor mColor;
+ };
+
+ int mRange;
+ int mCount;
+ int mCurrentCount;
+ int mValue;
+ Q3PtrList<ColorRange> mCRanges;
+};
+
+#endif
diff --git a/examples/graphicsview/portedasteroids/main.cpp b/examples/graphicsview/portedasteroids/main.cpp
new file mode 100644
index 0000000000..69b5fd514a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "toplevel.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(portedasteroids);
+
+ QApplication app(argc, argv);
+
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ KAstTopLevel topLevel;
+ topLevel.setWindowTitle("Ported Asteroids Game");
+ topLevel.show();
+
+ app.setQuitOnLastWindowClosed(true);
+ return app.exec();
+}
diff --git a/examples/graphicsview/portedasteroids/portedasteroids.pro b/examples/graphicsview/portedasteroids/portedasteroids.pro
new file mode 100644
index 0000000000..99dc042657
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/portedasteroids.pro
@@ -0,0 +1,21 @@
+TEMPLATE = app
+INCLUDEPATH += .
+
+# Input
+HEADERS += ledmeter.h sprites.h toplevel.h view.h
+SOURCES += ledmeter.cpp main.cpp toplevel.cpp view.cpp
+#The following line was inserted by qt3to4
+QT += qt3support
+
+HEADERS += animateditem.h
+SOURCES += animateditem.cpp
+
+RESOURCES += portedasteroids.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/portedasteroids
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS portedasteroids.pro bg.png sounds sprites
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/portedasteroids
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/graphicsview/portedasteroids/portedasteroids.qrc b/examples/graphicsview/portedasteroids/portedasteroids.qrc
new file mode 100644
index 0000000000..178082812a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/portedasteroids.qrc
@@ -0,0 +1,163 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/trolltech/examples/graphicsview/portedasteroids">
+<file>bg.png</file>
+<file>sprites/bits/bits0000.png</file>
+<file>sprites/bits/bits0001.png</file>
+<file>sprites/bits/bits0002.png</file>
+<file>sprites/bits/bits0003.png</file>
+<file>sprites/bits/bits0004.png</file>
+<file>sprites/bits/bits0005.png</file>
+<file>sprites/bits/bits0006.png</file>
+<file>sprites/bits/bits0007.png</file>
+<file>sprites/bits/bits0008.png</file>
+<file>sprites/bits/bits0009.png</file>
+<file>sprites/bits/bits0010.png</file>
+<file>sprites/bits/bits0011.png</file>
+<file>sprites/bits/bits0012.png</file>
+<file>sprites/bits/bits0013.png</file>
+<file>sprites/bits/bits0014.png</file>
+<file>sprites/bits/bits0015.png</file>
+<file>sprites/ship/ship0000.png</file>
+<file>sprites/ship/ship0001.png</file>
+<file>sprites/ship/ship0002.png</file>
+<file>sprites/ship/ship0003.png</file>
+<file>sprites/ship/ship0004.png</file>
+<file>sprites/ship/ship0005.png</file>
+<file>sprites/ship/ship0006.png</file>
+<file>sprites/ship/ship0007.png</file>
+<file>sprites/ship/ship0008.png</file>
+<file>sprites/ship/ship0009.png</file>
+<file>sprites/ship/ship0010.png</file>
+<file>sprites/ship/ship0011.png</file>
+<file>sprites/ship/ship0012.png</file>
+<file>sprites/ship/ship0013.png</file>
+<file>sprites/ship/ship0014.png</file>
+<file>sprites/ship/ship0015.png</file>
+<file>sprites/ship/ship0016.png</file>
+<file>sprites/ship/ship0017.png</file>
+<file>sprites/ship/ship0018.png</file>
+<file>sprites/ship/ship0019.png</file>
+<file>sprites/ship/ship0020.png</file>
+<file>sprites/ship/ship0021.png</file>
+<file>sprites/ship/ship0022.png</file>
+<file>sprites/ship/ship0023.png</file>
+<file>sprites/ship/ship0024.png</file>
+<file>sprites/ship/ship0025.png</file>
+<file>sprites/ship/ship0026.png</file>
+<file>sprites/ship/ship0027.png</file>
+<file>sprites/ship/ship0028.png</file>
+<file>sprites/ship/ship0029.png</file>
+<file>sprites/ship/ship0030.png</file>
+<file>sprites/ship/ship0031.png</file>
+<file>sprites/rock1/rock10016.png</file>
+<file>sprites/rock1/rock10017.png</file>
+<file>sprites/rock1/rock10018.png</file>
+<file>sprites/rock1/rock10019.png</file>
+<file>sprites/rock1/rock10020.png</file>
+<file>sprites/rock1/rock10021.png</file>
+<file>sprites/rock1/rock10022.png</file>
+<file>sprites/rock1/rock10023.png</file>
+<file>sprites/rock1/rock10024.png</file>
+<file>sprites/rock1/rock10025.png</file>
+<file>sprites/rock1/rock10026.png</file>
+<file>sprites/rock1/rock10027.png</file>
+<file>sprites/rock1/rock10028.png</file>
+<file>sprites/rock1/rock10029.png</file>
+<file>sprites/rock1/rock10030.png</file>
+<file>sprites/rock1/rock10031.png</file>
+<file>sprites/rock1/rock10000.png</file>
+<file>sprites/rock1/rock10001.png</file>
+<file>sprites/rock1/rock10002.png</file>
+<file>sprites/rock1/rock10003.png</file>
+<file>sprites/rock1/rock10004.png</file>
+<file>sprites/rock1/rock10005.png</file>
+<file>sprites/rock1/rock10006.png</file>
+<file>sprites/rock1/rock10007.png</file>
+<file>sprites/rock1/rock10008.png</file>
+<file>sprites/rock1/rock10009.png</file>
+<file>sprites/rock1/rock10010.png</file>
+<file>sprites/rock1/rock10011.png</file>
+<file>sprites/rock1/rock10012.png</file>
+<file>sprites/rock1/rock10013.png</file>
+<file>sprites/rock1/rock10014.png</file>
+<file>sprites/rock1/rock10015.png</file>
+<file>sprites/rock2/rock20000.png</file>
+<file>sprites/rock2/rock20001.png</file>
+<file>sprites/rock2/rock20002.png</file>
+<file>sprites/rock2/rock20003.png</file>
+<file>sprites/rock2/rock20004.png</file>
+<file>sprites/rock2/rock20005.png</file>
+<file>sprites/rock2/rock20006.png</file>
+<file>sprites/rock2/rock20007.png</file>
+<file>sprites/rock2/rock20008.png</file>
+<file>sprites/rock2/rock20009.png</file>
+<file>sprites/rock2/rock20010.png</file>
+<file>sprites/rock2/rock20011.png</file>
+<file>sprites/rock2/rock20012.png</file>
+<file>sprites/rock2/rock20013.png</file>
+<file>sprites/rock2/rock20014.png</file>
+<file>sprites/rock2/rock20015.png</file>
+<file>sprites/rock2/rock20016.png</file>
+<file>sprites/rock2/rock20017.png</file>
+<file>sprites/rock2/rock20018.png</file>
+<file>sprites/rock2/rock20019.png</file>
+<file>sprites/rock2/rock20020.png</file>
+<file>sprites/rock2/rock20021.png</file>
+<file>sprites/rock2/rock20022.png</file>
+<file>sprites/rock2/rock20023.png</file>
+<file>sprites/rock2/rock20024.png</file>
+<file>sprites/rock2/rock20025.png</file>
+<file>sprites/rock2/rock20026.png</file>
+<file>sprites/rock2/rock20027.png</file>
+<file>sprites/rock2/rock20028.png</file>
+<file>sprites/rock2/rock20029.png</file>
+<file>sprites/rock2/rock20030.png</file>
+<file>sprites/rock2/rock20031.png</file>
+<file>sprites/rock3/rock30000.png</file>
+<file>sprites/rock3/rock30001.png</file>
+<file>sprites/rock3/rock30002.png</file>
+<file>sprites/rock3/rock30003.png</file>
+<file>sprites/rock3/rock30004.png</file>
+<file>sprites/rock3/rock30005.png</file>
+<file>sprites/rock3/rock30006.png</file>
+<file>sprites/rock3/rock30007.png</file>
+<file>sprites/rock3/rock30008.png</file>
+<file>sprites/rock3/rock30009.png</file>
+<file>sprites/rock3/rock30010.png</file>
+<file>sprites/rock3/rock30011.png</file>
+<file>sprites/rock3/rock30012.png</file>
+<file>sprites/rock3/rock30013.png</file>
+<file>sprites/rock3/rock30014.png</file>
+<file>sprites/rock3/rock30015.png</file>
+<file>sprites/rock3/rock30016.png</file>
+<file>sprites/rock3/rock30017.png</file>
+<file>sprites/rock3/rock30018.png</file>
+<file>sprites/rock3/rock30019.png</file>
+<file>sprites/rock3/rock30020.png</file>
+<file>sprites/rock3/rock30021.png</file>
+<file>sprites/rock3/rock30022.png</file>
+<file>sprites/rock3/rock30023.png</file>
+<file>sprites/rock3/rock30024.png</file>
+<file>sprites/rock3/rock30025.png</file>
+<file>sprites/rock3/rock30026.png</file>
+<file>sprites/rock3/rock30027.png</file>
+<file>sprites/rock3/rock30028.png</file>
+<file>sprites/rock3/rock30029.png</file>
+<file>sprites/rock3/rock30030.png</file>
+<file>sprites/rock3/rock30031.png</file>
+<file>sprites/missile/missile.png</file>
+<file>sprites/exhaust/exhaust.png</file>
+<file>sprites/powerups/shield.png</file>
+<file>sprites/powerups/shoot.png</file>
+<file>sprites/powerups/teleport.png</file>
+<file>sprites/powerups/brake.png</file>
+<file>sprites/powerups/energy.png</file>
+<file>sprites/shield/shield0000.png</file>
+<file>sprites/shield/shield0001.png</file>
+<file>sprites/shield/shield0002.png</file>
+<file>sprites/shield/shield0003.png</file>
+<file>sprites/shield/shield0004.png</file>
+<file>sprites/shield/shield0005.png</file>
+<file>sprites/shield/shield0006.png</file>
+</qresource>
+</RCC>
diff --git a/examples/graphicsview/portedasteroids/sounds/Explosion.wav b/examples/graphicsview/portedasteroids/sounds/Explosion.wav
new file mode 100644
index 0000000000..7b140b1c69
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sounds/Explosion.wav
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites.h b/examples/graphicsview/portedasteroids/sprites.h
new file mode 100644
index 0000000000..1483d68525
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * KAsteroids - Copyright (c) Martin R. Jones 1997
+ *
+ * Part of the KDE project
+ */
+
+#ifndef __SPRITES_H__
+#define __SPRITES_H__
+
+#include "animateditem.h"
+
+#define ID_ROCK_LARGE 1024
+#define ID_ROCK_MEDIUM 1025
+#define ID_ROCK_SMALL 1026
+
+#define ID_MISSILE 1030
+
+#define ID_BIT 1040
+#define ID_EXHAUST 1041
+
+#define ID_ENERGY_POWERUP 1310
+#define ID_TELEPORT_POWERUP 1311
+#define ID_BRAKE_POWERUP 1312
+#define ID_SHIELD_POWERUP 1313
+#define ID_SHOOT_POWERUP 1314
+
+#define ID_SHIP 1350
+#define ID_SHIELD 1351
+
+#define MAX_SHIELD_AGE 350
+#define MAX_POWERUP_AGE 500
+#define MAX_MISSILE_AGE 40
+
+class KMissile : public AnimatedPixmapItem
+{
+public:
+ KMissile( const QList<QPixmap> &s, QGraphicsScene *c ) : AnimatedPixmapItem( s, c )
+ { myAge = 0; }
+
+ virtual int type() const { return ID_MISSILE; }
+
+ void growOlder() { myAge++; }
+ bool expired() { return myAge > MAX_MISSILE_AGE; }
+
+private:
+ int myAge;
+};
+
+class KBit : public AnimatedPixmapItem
+{
+public:
+ KBit( const QList<QPixmap> &s, QGraphicsScene *c ) : AnimatedPixmapItem( s, c )
+ { death = 7; }
+
+ virtual int type() const { return ID_BIT; }
+
+ void setDeath( int d ) { death = d; }
+ void growOlder() { death--; }
+ bool expired() { return death <= 0; }
+
+private:
+ int death;
+};
+
+class KExhaust : public AnimatedPixmapItem
+{
+public:
+ KExhaust( const QList<QPixmap> &s, QGraphicsScene *c ) : AnimatedPixmapItem( s, c )
+ { death = 1; }
+
+ virtual int type() const { return ID_EXHAUST; }
+
+ void setDeath( int d ) { death = d; }
+ void growOlder() { death--; }
+ bool expired() { return death <= 0; }
+
+private:
+ int death;
+};
+
+class KPowerup : public AnimatedPixmapItem
+{
+public:
+ KPowerup( const QList<QPixmap> &s, QGraphicsScene *c, int t ) : AnimatedPixmapItem( s, c ),
+ myAge( 0 ), _type(t) { }
+
+ virtual int type() const { return _type; }
+
+ void growOlder() { myAge++; }
+ bool expired() const { return myAge > MAX_POWERUP_AGE; }
+
+protected:
+ int myAge;
+ int _type;
+};
+
+class KRock : public AnimatedPixmapItem
+{
+public:
+ KRock (const QList<QPixmap> &s, QGraphicsScene *c, int t, int sk, int st) : AnimatedPixmapItem( s, c )
+ { _type = t; skip = cskip = sk; step = st; }
+
+ void nextFrame()
+ {
+ if (cskip-- <= 0) {
+ setFrame( (frame()+step+frameCount())%frameCount() );
+ cskip = QABS(skip);
+ }
+ }
+
+ virtual int type() const { return _type; }
+
+private:
+ int _type;
+ int skip;
+ int cskip;
+ int step;
+};
+
+class KShield : public AnimatedPixmapItem
+{
+public:
+ KShield( QList<QPixmap> &s, QGraphicsScene *c )
+ : AnimatedPixmapItem( s, c ) {}
+
+ virtual int type() const { return ID_SHIELD; }
+};
+
+#endif
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits.ini b/examples/graphicsview/portedasteroids/sprites/bits/bits.ini
new file mode 100644
index 0000000000..cb2976f88f
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits.ini
@@ -0,0 +1,9 @@
+Cyclic_Animation=On
+Width=12
+Height=12
+Final_frame=16 ;; NR_ROTS
+Antialias=On
+Output_Alpha=On
+Output_to_File=On
+Output_File_Type=n
+Input_File_Name=bits.pov
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits.pov b/examples/graphicsview/portedasteroids/sprites/bits/bits.pov
new file mode 100644
index 0000000000..9be7ccb67b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits.pov
@@ -0,0 +1,31 @@
+
+#version 3.0
+global_settings { assumed_gamma 2.0 }
+
+#include "colors.inc"
+#include "textures.inc"
+#include "metals.inc"
+
+camera {
+ location <15, -15, -100>
+ look_at <0, 0, 0>
+}
+
+light_source { <50, 50, -50> colour White }
+light_source { <0, 0, -50> colour White }
+
+prism {
+ linear_sweep
+ linear_spline
+ 0,
+ 0.2,
+ 5,
+ <2, 0>, <0, 2>, <-1, 1>, <0, -3>, <2, 0>
+ texture { T_Silver_2A }
+
+ rotate <360*clock, 50, 30>
+ scale <20, 20, 20>
+}
+
+
+
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0000.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0000.png
new file mode 100644
index 0000000000..5ec9d02940
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0000.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0001.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0001.png
new file mode 100644
index 0000000000..07b4012337
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0001.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0002.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0002.png
new file mode 100644
index 0000000000..833379229c
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0002.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0003.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0003.png
new file mode 100644
index 0000000000..9f1fc02836
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0003.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0004.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0004.png
new file mode 100644
index 0000000000..eb1cc090c9
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0004.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0005.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0005.png
new file mode 100644
index 0000000000..149be63c1a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0005.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0006.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0006.png
new file mode 100644
index 0000000000..4ac75c8ed1
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0006.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0007.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0007.png
new file mode 100644
index 0000000000..907241dd7a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0007.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0008.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0008.png
new file mode 100644
index 0000000000..15332684fe
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0008.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0009.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0009.png
new file mode 100644
index 0000000000..05402ba9eb
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0009.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0010.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0010.png
new file mode 100644
index 0000000000..ca4f2297a9
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0010.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0011.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0011.png
new file mode 100644
index 0000000000..91913c032f
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0011.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0012.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0012.png
new file mode 100644
index 0000000000..e55d4399a4
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0012.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0013.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0013.png
new file mode 100644
index 0000000000..9c7343600d
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0013.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0014.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0014.png
new file mode 100644
index 0000000000..f0463a2a9b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0014.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/bits/bits0015.png b/examples/graphicsview/portedasteroids/sprites/bits/bits0015.png
new file mode 100644
index 0000000000..bce35aac53
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/bits/bits0015.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/exhaust/exhaust.png b/examples/graphicsview/portedasteroids/sprites/exhaust/exhaust.png
new file mode 100644
index 0000000000..1d9bc33679
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/exhaust/exhaust.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/missile/missile.png b/examples/graphicsview/portedasteroids/sprites/missile/missile.png
new file mode 100644
index 0000000000..f1a83b2fc3
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/missile/missile.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/powerups/brake.png b/examples/graphicsview/portedasteroids/sprites/powerups/brake.png
new file mode 100644
index 0000000000..5f65a115fb
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/powerups/brake.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/powerups/energy.png b/examples/graphicsview/portedasteroids/sprites/powerups/energy.png
new file mode 100644
index 0000000000..4b40074873
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/powerups/energy.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/powerups/shield.png b/examples/graphicsview/portedasteroids/sprites/powerups/shield.png
new file mode 100644
index 0000000000..6ac686896e
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/powerups/shield.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/powerups/shoot.png b/examples/graphicsview/portedasteroids/sprites/powerups/shoot.png
new file mode 100644
index 0000000000..5e5bf08d32
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/powerups/shoot.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/powerups/teleport.png b/examples/graphicsview/portedasteroids/sprites/powerups/teleport.png
new file mode 100644
index 0000000000..009c229eda
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/powerups/teleport.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock1.ini b/examples/graphicsview/portedasteroids/sprites/rock1/rock1.ini
new file mode 100644
index 0000000000..e42fc76624
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock1.ini
@@ -0,0 +1,9 @@
+Cyclic_Animation=On
+Width=48
+Height=48
+Final_frame=32 ;; NR_ROTS
+Antialias=On
+Output_Alpha=On
+Output_to_File=On
+Output_File_Type=n
+Input_File_Name=rock1.pov
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock1.pov b/examples/graphicsview/portedasteroids/sprites/rock1/rock1.pov
new file mode 100644
index 0000000000..58298c0505
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock1.pov
@@ -0,0 +1,26 @@
+#include "colors.inc"
+#include "shapes.inc"
+#include "textures.inc"
+// #include "stones.inc"
+
+camera {
+ location <2,2,-6>
+ up <0, 1, 0>
+// right <4/3, 0, 0>
+ look_at <0,0,0>
+}
+
+object { light_source { <10, 5, -5> color red 1.1 green 1.1 blue 1.0 } }
+
+#declare Rock =
+mesh {
+ #include "rock.inc" /* collection of triangle or smooth_triangle data */
+}
+
+object {
+ Rock
+ texture { pigment {White} }
+ scale 1.9
+ rotate <60, 45, 360*clock>
+}
+
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10000.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10000.png
new file mode 100644
index 0000000000..5fe70ef29a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10000.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10001.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10001.png
new file mode 100644
index 0000000000..ea66dacd1c
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10001.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10002.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10002.png
new file mode 100644
index 0000000000..cb55ed0829
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10002.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10003.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10003.png
new file mode 100644
index 0000000000..f82934c3c4
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10003.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10004.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10004.png
new file mode 100644
index 0000000000..04efc2baac
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10004.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10005.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10005.png
new file mode 100644
index 0000000000..b9c0d03e96
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10005.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10006.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10006.png
new file mode 100644
index 0000000000..7f9126728d
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10006.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10007.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10007.png
new file mode 100644
index 0000000000..b28f219dab
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10007.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10008.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10008.png
new file mode 100644
index 0000000000..0153d4aee0
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10008.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10009.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10009.png
new file mode 100644
index 0000000000..c04d82720f
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10009.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10010.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10010.png
new file mode 100644
index 0000000000..c7d3c40d21
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10010.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10011.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10011.png
new file mode 100644
index 0000000000..233dfcecbc
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10011.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10012.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10012.png
new file mode 100644
index 0000000000..ec7b5ba308
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10012.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10013.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10013.png
new file mode 100644
index 0000000000..22eac3ad63
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10013.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10014.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10014.png
new file mode 100644
index 0000000000..ad1503d13f
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10014.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10015.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10015.png
new file mode 100644
index 0000000000..cec22e2773
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10015.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10016.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10016.png
new file mode 100644
index 0000000000..c7a96cb2e9
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10016.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10017.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10017.png
new file mode 100644
index 0000000000..c8310bd645
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10017.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10018.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10018.png
new file mode 100644
index 0000000000..b8d436b0d2
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10018.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10019.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10019.png
new file mode 100644
index 0000000000..e5d07997e6
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10019.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10020.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10020.png
new file mode 100644
index 0000000000..440f8d00c9
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10020.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10021.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10021.png
new file mode 100644
index 0000000000..de3d54df7f
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10021.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10022.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10022.png
new file mode 100644
index 0000000000..698056d5cb
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10022.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10023.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10023.png
new file mode 100644
index 0000000000..4e6ba042a8
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10023.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10024.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10024.png
new file mode 100644
index 0000000000..3b428509a1
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10024.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10025.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10025.png
new file mode 100644
index 0000000000..68139364f0
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10025.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10026.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10026.png
new file mode 100644
index 0000000000..4a2b171119
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10026.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10027.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10027.png
new file mode 100644
index 0000000000..30448fb693
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10027.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10028.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10028.png
new file mode 100644
index 0000000000..43ca1a91db
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10028.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10029.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10029.png
new file mode 100644
index 0000000000..9d7e88857e
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10029.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10030.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10030.png
new file mode 100644
index 0000000000..39b2ad2def
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10030.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock1/rock10031.png b/examples/graphicsview/portedasteroids/sprites/rock1/rock10031.png
new file mode 100644
index 0000000000..257ec7bf32
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock1/rock10031.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock2.ini b/examples/graphicsview/portedasteroids/sprites/rock2/rock2.ini
new file mode 100644
index 0000000000..d50e6fada7
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock2.ini
@@ -0,0 +1,9 @@
+Cyclic_Animation=On
+Width=32
+Height=32
+Final_frame=32 ;; NR_ROTS
+Antialias=On
+Output_Alpha=On
+Output_to_File=On
+Output_File_Type=n
+Input_File_Name=rock2.pov
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock2.pov b/examples/graphicsview/portedasteroids/sprites/rock2/rock2.pov
new file mode 100644
index 0000000000..2f37a20620
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock2.pov
@@ -0,0 +1,26 @@
+#include "colors.inc"
+#include "shapes.inc"
+#include "textures.inc"
+// #include "stones.inc"
+
+camera {
+ location <2,2,-6>
+ up <0, 1, 0>
+// right <4/3, 0, 0>
+ look_at <0,0,0>
+}
+
+object { light_source { <10, 5, -5> color red 1.1 green 1.1 blue 1.0 } }
+
+#declare Rock =
+mesh {
+ #include "rock.inc" /* collection of triangle or smooth_triangle data */
+}
+
+object {
+ Rock
+ texture { pigment {White} }
+ scale 1.9
+ rotate <60, 30, 360*clock>
+}
+
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20000.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20000.png
new file mode 100644
index 0000000000..5cb52bb813
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20000.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20001.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20001.png
new file mode 100644
index 0000000000..d765be1bd9
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20001.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20002.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20002.png
new file mode 100644
index 0000000000..84e2380cc2
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20002.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20003.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20003.png
new file mode 100644
index 0000000000..39772b8aad
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20003.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20004.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20004.png
new file mode 100644
index 0000000000..b983079186
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20004.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20005.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20005.png
new file mode 100644
index 0000000000..70bb4d829e
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20005.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20006.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20006.png
new file mode 100644
index 0000000000..cf5c2f4c47
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20006.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20007.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20007.png
new file mode 100644
index 0000000000..479c21d277
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20007.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20008.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20008.png
new file mode 100644
index 0000000000..871abca06a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20008.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20009.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20009.png
new file mode 100644
index 0000000000..bc31fbb526
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20009.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20010.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20010.png
new file mode 100644
index 0000000000..1da9953348
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20010.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20011.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20011.png
new file mode 100644
index 0000000000..d542c6edaa
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20011.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20012.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20012.png
new file mode 100644
index 0000000000..d104ff954b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20012.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20013.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20013.png
new file mode 100644
index 0000000000..e12943df91
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20013.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20014.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20014.png
new file mode 100644
index 0000000000..dc7529cfdf
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20014.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20015.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20015.png
new file mode 100644
index 0000000000..0b49c2cde5
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20015.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20016.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20016.png
new file mode 100644
index 0000000000..adbad98698
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20016.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20017.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20017.png
new file mode 100644
index 0000000000..5a8aeef218
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20017.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20018.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20018.png
new file mode 100644
index 0000000000..11c6af47c4
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20018.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20019.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20019.png
new file mode 100644
index 0000000000..026b72b54a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20019.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20020.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20020.png
new file mode 100644
index 0000000000..8bc7e20fe1
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20020.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20021.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20021.png
new file mode 100644
index 0000000000..e0a7626f97
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20021.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20022.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20022.png
new file mode 100644
index 0000000000..5796e12cd4
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20022.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20023.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20023.png
new file mode 100644
index 0000000000..d2cf0c6870
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20023.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20024.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20024.png
new file mode 100644
index 0000000000..071ce210fa
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20024.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20025.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20025.png
new file mode 100644
index 0000000000..ae8101d77f
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20025.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20026.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20026.png
new file mode 100644
index 0000000000..f2681d46f4
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20026.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20027.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20027.png
new file mode 100644
index 0000000000..e83fd41000
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20027.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20028.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20028.png
new file mode 100644
index 0000000000..5621b4d6d7
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20028.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20029.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20029.png
new file mode 100644
index 0000000000..aec4a34746
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20029.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20030.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20030.png
new file mode 100644
index 0000000000..89a8f5fa6d
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20030.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock2/rock20031.png b/examples/graphicsview/portedasteroids/sprites/rock2/rock20031.png
new file mode 100644
index 0000000000..69f537589b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock2/rock20031.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock3.ini b/examples/graphicsview/portedasteroids/sprites/rock3/rock3.ini
new file mode 100644
index 0000000000..26a3cf9694
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock3.ini
@@ -0,0 +1,9 @@
+Cyclic_Animation=On
+Width=20
+Height=20
+Final_frame=32 ;; NR_ROTS
+Antialias=On
+Output_Alpha=On
+Output_to_File=On
+Output_File_Type=n
+Input_File_Name=rock3.pov
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock3.pov b/examples/graphicsview/portedasteroids/sprites/rock3/rock3.pov
new file mode 100644
index 0000000000..2f37a20620
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock3.pov
@@ -0,0 +1,26 @@
+#include "colors.inc"
+#include "shapes.inc"
+#include "textures.inc"
+// #include "stones.inc"
+
+camera {
+ location <2,2,-6>
+ up <0, 1, 0>
+// right <4/3, 0, 0>
+ look_at <0,0,0>
+}
+
+object { light_source { <10, 5, -5> color red 1.1 green 1.1 blue 1.0 } }
+
+#declare Rock =
+mesh {
+ #include "rock.inc" /* collection of triangle or smooth_triangle data */
+}
+
+object {
+ Rock
+ texture { pigment {White} }
+ scale 1.9
+ rotate <60, 30, 360*clock>
+}
+
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30000.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30000.png
new file mode 100644
index 0000000000..de1205a888
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30000.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30001.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30001.png
new file mode 100644
index 0000000000..12ebc00313
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30001.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30002.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30002.png
new file mode 100644
index 0000000000..ebb899e334
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30002.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30003.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30003.png
new file mode 100644
index 0000000000..1ff7a0675d
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30003.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30004.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30004.png
new file mode 100644
index 0000000000..5b505bf10b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30004.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30005.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30005.png
new file mode 100644
index 0000000000..f9680dcbaa
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30005.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30006.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30006.png
new file mode 100644
index 0000000000..e29746afca
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30006.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30007.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30007.png
new file mode 100644
index 0000000000..f01baa6b37
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30007.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30008.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30008.png
new file mode 100644
index 0000000000..cd10711322
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30008.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30009.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30009.png
new file mode 100644
index 0000000000..4f32955a10
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30009.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30010.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30010.png
new file mode 100644
index 0000000000..bb61d549b9
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30010.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30011.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30011.png
new file mode 100644
index 0000000000..8486e5a457
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30011.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30012.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30012.png
new file mode 100644
index 0000000000..d9ae4191e1
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30012.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30013.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30013.png
new file mode 100644
index 0000000000..ce694002ab
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30013.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30014.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30014.png
new file mode 100644
index 0000000000..981e92c130
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30014.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30015.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30015.png
new file mode 100644
index 0000000000..b8fb00c84e
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30015.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30016.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30016.png
new file mode 100644
index 0000000000..72bc42fc75
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30016.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30017.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30017.png
new file mode 100644
index 0000000000..c89f358cee
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30017.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30018.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30018.png
new file mode 100644
index 0000000000..e1ba724d4b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30018.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30019.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30019.png
new file mode 100644
index 0000000000..5f004a7668
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30019.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30020.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30020.png
new file mode 100644
index 0000000000..58009bf92a
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30020.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30021.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30021.png
new file mode 100644
index 0000000000..8d9549c856
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30021.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30022.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30022.png
new file mode 100644
index 0000000000..1e8a1c2336
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30022.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30023.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30023.png
new file mode 100644
index 0000000000..9b960d6695
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30023.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30024.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30024.png
new file mode 100644
index 0000000000..6c15f2b897
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30024.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30025.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30025.png
new file mode 100644
index 0000000000..12b05da545
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30025.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30026.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30026.png
new file mode 100644
index 0000000000..16190e9442
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30026.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30027.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30027.png
new file mode 100644
index 0000000000..a8625015d9
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30027.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30028.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30028.png
new file mode 100644
index 0000000000..e3e0c18067
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30028.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30029.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30029.png
new file mode 100644
index 0000000000..ec70b84437
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30029.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30030.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30030.png
new file mode 100644
index 0000000000..da48df145e
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30030.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/rock3/rock30031.png b/examples/graphicsview/portedasteroids/sprites/rock3/rock30031.png
new file mode 100644
index 0000000000..c1dc1b92fc
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/rock3/rock30031.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/shield/shield0000.png b/examples/graphicsview/portedasteroids/sprites/shield/shield0000.png
new file mode 100644
index 0000000000..72332544af
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/shield/shield0000.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/shield/shield0001.png b/examples/graphicsview/portedasteroids/sprites/shield/shield0001.png
new file mode 100644
index 0000000000..2b0bc9d0d1
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/shield/shield0001.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/shield/shield0002.png b/examples/graphicsview/portedasteroids/sprites/shield/shield0002.png
new file mode 100644
index 0000000000..cdc0fe37ce
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/shield/shield0002.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/shield/shield0003.png b/examples/graphicsview/portedasteroids/sprites/shield/shield0003.png
new file mode 100644
index 0000000000..979ed5ad77
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/shield/shield0003.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/shield/shield0004.png b/examples/graphicsview/portedasteroids/sprites/shield/shield0004.png
new file mode 100644
index 0000000000..0bb93a22d8
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/shield/shield0004.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/shield/shield0005.png b/examples/graphicsview/portedasteroids/sprites/shield/shield0005.png
new file mode 100644
index 0000000000..32210bdd24
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/shield/shield0005.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/shield/shield0006.png b/examples/graphicsview/portedasteroids/sprites/shield/shield0006.png
new file mode 100644
index 0000000000..76c9920394
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/shield/shield0006.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship.ini b/examples/graphicsview/portedasteroids/sprites/ship/ship.ini
new file mode 100644
index 0000000000..479cc20ea8
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship.ini
@@ -0,0 +1,9 @@
+Cyclic_Animation=On
+Width=42
+Height=42
+Final_frame=32 ;; NR_ROTS
+Antialias=On
+Output_Alpha=On
+Output_to_File=On
+Output_File_Type=n
+Input_File_Name=ship.pov
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship.pov b/examples/graphicsview/portedasteroids/sprites/ship/ship.pov
new file mode 100644
index 0000000000..8f185cd7b5
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship.pov
@@ -0,0 +1,128 @@
+
+#version 3.0
+global_settings { assumed_gamma 2.0 }
+
+#include "colors.inc"
+#include "textures.inc"
+#include "metals.inc"
+
+camera {
+ orthographic
+ up <0, 130, 0>
+ right <130, 0, 0>
+ location <0, 0, -130>
+ look_at <0, 0, 0>
+}
+
+light_source { <50, 25, -25> colour White }
+light_source { <0, 0, -100> colour Gray80 }
+
+#declare ShipColor = color red 1.0 green 1.0 blue 0.9
+
+#declare BaseTexture =
+texture {
+ pigment { ShipColor }
+}
+
+#declare Grubby =
+texture {
+ pigment {
+ bozo
+ color_map {
+ [0.0 color rgbt <1, 1, 1, 1>]
+ [0.8 color rgbt <0.9, 0.9, 0.9, 0.5>]
+ [1.0 color rgbt <0.8, 0.8, 0.8, 0.5>]
+ }
+ turbulence 2.0
+ scale 3
+ }
+}
+
+#declare ShipTexture =
+texture { BaseTexture }
+texture { Grubby }
+
+union {
+ cone {
+ <12, 0, 0>, 0.5
+ <11, 0, 0>, 1.0
+ texture { ShipTexture }
+ }
+ cone {
+ <11, 0, 0>, 1.0
+ <8, 0, 0>, 2.0
+ texture { ShipTexture }
+ }
+ cone {
+ <8, 0, 0>, 2.0
+ <3.5, 0, 0>, 3.8
+ texture { ShipTexture }
+ }
+ difference {
+ cone {
+ <8, 0, -0.01>, 2.0
+ <3.5, 0, -0.01>, 3.8
+ pigment { color Gray20 }
+ }
+ box {
+ <9, -4.0, -3.7>,
+ <2, 4.0, 10>
+ rotate <0, -18, 0>
+ }
+ box {
+ <6.5, -4.0, -8>,
+ <10, 4.0, 8>
+ }
+ box {
+ <2, -4.0, -8>,
+ <4.5, 4.0, 8>
+ }
+ }
+ cone {
+ <3.5, 0, 0>, 3.8
+ <2, 0, 0>, 4.0
+ texture { ShipTexture }
+ }
+ cylinder {
+ <2, 0, 0>,
+ <-9, 0, 0>,
+ 4.0
+ texture { ShipTexture }
+ }
+ cone {
+ <-9, 0, 0>, 4.0
+ <-10, 0, 0>, 3.5
+ texture { ShipTexture }
+ }
+ prism {
+ linear_sweep
+ linear_spline
+ 0,
+ 0.5,
+ 4,
+ <7.5, 0>, <-7.5, 10>, <-7.5, -10>, <7.5, 0>
+ rotate <90, 0, 0>
+ texture { T_Silver_2A }
+ texture { ShipTexture }
+ }
+ prism {
+ linear_sweep
+ linear_spline
+ -0.5,
+ 0.5,
+ 4,
+ <4, 0>, <-7.5, 5>, <-7.5, -5>, <4, 0>
+ pigment { color White }
+ }
+ cone {
+ <-12, 0, 0>, 3.0
+ <-10, 0, 0>, 2.0
+ texture { T_Silver_2A }
+ pigment { color Gray60 }
+ }
+
+ rotate <0, 0,-360*clock>
+ scale <5, 5, 5>
+}
+
+
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0000.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0000.png
new file mode 100644
index 0000000000..a8f1bb37b7
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0000.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0001.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0001.png
new file mode 100644
index 0000000000..861f1301ee
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0001.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0002.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0002.png
new file mode 100644
index 0000000000..418ced1372
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0002.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0003.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0003.png
new file mode 100644
index 0000000000..50a386bb24
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0003.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0004.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0004.png
new file mode 100644
index 0000000000..f2bc0bc417
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0004.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0005.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0005.png
new file mode 100644
index 0000000000..7280485fcb
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0005.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0006.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0006.png
new file mode 100644
index 0000000000..51d26e9b57
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0006.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0007.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0007.png
new file mode 100644
index 0000000000..682c0428f4
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0007.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0008.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0008.png
new file mode 100644
index 0000000000..003d7fa2e8
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0008.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0009.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0009.png
new file mode 100644
index 0000000000..538b879967
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0009.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0010.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0010.png
new file mode 100644
index 0000000000..17999cd408
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0010.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0011.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0011.png
new file mode 100644
index 0000000000..1a4bbe9dee
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0011.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0012.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0012.png
new file mode 100644
index 0000000000..2523d85332
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0012.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0013.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0013.png
new file mode 100644
index 0000000000..8bd5971719
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0013.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0014.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0014.png
new file mode 100644
index 0000000000..a164ab7b9b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0014.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0015.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0015.png
new file mode 100644
index 0000000000..ca8e0b9db7
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0015.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0016.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0016.png
new file mode 100644
index 0000000000..cfaf8c4b58
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0016.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0017.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0017.png
new file mode 100644
index 0000000000..8049617220
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0017.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0018.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0018.png
new file mode 100644
index 0000000000..4a3421bac4
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0018.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0019.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0019.png
new file mode 100644
index 0000000000..786d37550b
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0019.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0020.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0020.png
new file mode 100644
index 0000000000..bd4365cde0
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0020.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0021.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0021.png
new file mode 100644
index 0000000000..eb358c1299
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0021.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0022.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0022.png
new file mode 100644
index 0000000000..eb865e1331
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0022.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0023.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0023.png
new file mode 100644
index 0000000000..3738ce2c16
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0023.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0024.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0024.png
new file mode 100644
index 0000000000..a7c1adc92d
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0024.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0025.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0025.png
new file mode 100644
index 0000000000..2ca3aaebdf
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0025.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0026.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0026.png
new file mode 100644
index 0000000000..4661ca58aa
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0026.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0027.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0027.png
new file mode 100644
index 0000000000..f5c9203807
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0027.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0028.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0028.png
new file mode 100644
index 0000000000..08353d4283
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0028.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0029.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0029.png
new file mode 100644
index 0000000000..8685d31332
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0029.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0030.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0030.png
new file mode 100644
index 0000000000..78dd469536
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0030.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/sprites/ship/ship0031.png b/examples/graphicsview/portedasteroids/sprites/ship/ship0031.png
new file mode 100644
index 0000000000..6cd06439ff
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/sprites/ship/ship0031.png
Binary files differ
diff --git a/examples/graphicsview/portedasteroids/toplevel.cpp b/examples/graphicsview/portedasteroids/toplevel.cpp
new file mode 100644
index 0000000000..1aecc842c8
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/toplevel.cpp
@@ -0,0 +1,543 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * KAsteroids - Copyright (c) Martin R. Jones 1997
+ *
+ * Part of the KDE project
+ */
+// --- toplevel.cpp ---
+#include <q3accel.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlcdnumber.h>
+#include <qpushbutton.h>
+
+#include <qapplication.h>
+//Added by qt3to4:
+#include <Q3HBoxLayout>
+#include <QShowEvent>
+#include <Q3Frame>
+#include <QPixmap>
+#include <QHideEvent>
+#include <QKeyEvent>
+#include <Q3VBoxLayout>
+
+#include "toplevel.h"
+#include "ledmeter.h"
+
+
+#define SB_SCORE 1
+#define SB_LEVEL 2
+#define SB_SHIPS 3
+
+struct SLevel
+{
+ int nrocks;
+ double rockSpeed;
+};
+
+#define MAX_LEVELS 16
+
+SLevel levels[MAX_LEVELS] =
+{
+ { 1, 0.4 },
+ { 1, 0.6 },
+ { 2, 0.5 },
+ { 2, 0.7 },
+ { 2, 0.8 },
+ { 3, 0.6 },
+ { 3, 0.7 },
+ { 3, 0.8 },
+ { 4, 0.6 },
+ { 4, 0.7 },
+ { 4, 0.8 },
+ { 5, 0.7 },
+ { 5, 0.8 },
+ { 5, 0.9 },
+ { 5, 1.0 }
+};
+
+const char *soundEvents[] =
+{
+ "ShipDestroyed",
+ "RockDestroyed",
+ 0
+};
+
+const char *soundDefaults[] =
+{
+ "Explosion.wav",
+ "ploop.wav",
+ 0
+};
+
+
+KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name )
+ : Q3MainWindow( parent, name, 0 )
+{
+ QWidget *border = new QWidget( this );
+ border->setBackgroundColor( Qt::black );
+ setCentralWidget( border );
+
+ Q3VBoxLayout *borderLayout = new Q3VBoxLayout( border );
+ borderLayout->addStretch( 1 );
+
+ QWidget *mainWin = new QWidget( border );
+ mainWin->setFixedSize(640, 480);
+ borderLayout->addWidget( mainWin, 0, Qt::AlignHCenter );
+
+ borderLayout->addStretch( 1 );
+
+ view = new KAsteroidsView( mainWin );
+ view->setFocusPolicy( Qt::StrongFocus );
+ connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) );
+ connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) );
+ connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) );
+ connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) );
+
+ Q3VBoxLayout *vb = new Q3VBoxLayout( mainWin );
+ Q3HBoxLayout *hb = new Q3HBoxLayout;
+ Q3HBoxLayout *hbd = new Q3HBoxLayout;
+ vb->addLayout( hb );
+
+ QFont labelFont( "helvetica", 24 );
+ QColorGroup grp( Qt::darkGreen, Qt::black, QColor( 128, 128, 128 ),
+ QColor( 64, 64, 64 ), Qt::black, Qt::darkGreen, Qt::black );
+ QPalette pal( grp, grp, grp );
+
+ mainWin->setPalette( pal );
+
+ hb->addSpacing( 10 );
+
+ QLabel *label;
+ label = new QLabel( tr("Score"), mainWin );
+ label->setFont( labelFont );
+ label->setPalette( pal );
+ label->setFixedWidth( label->sizeHint().width() );
+ hb->addWidget( label );
+
+ scoreLCD = new QLCDNumber( 6, mainWin );
+ scoreLCD->setFrameStyle( Q3Frame::NoFrame );
+ scoreLCD->setSegmentStyle( QLCDNumber::Flat );
+ scoreLCD->setFixedWidth( 150 );
+ scoreLCD->setPalette( pal );
+ hb->addWidget( scoreLCD );
+ hb->addStretch( 10 );
+
+ label = new QLabel( tr("Level"), mainWin );
+ label->setFont( labelFont );
+ label->setPalette( pal );
+ label->setFixedWidth( label->sizeHint().width() );
+ hb->addWidget( label );
+
+ levelLCD = new QLCDNumber( 2, mainWin );
+ levelLCD->setFrameStyle( Q3Frame::NoFrame );
+ levelLCD->setSegmentStyle( QLCDNumber::Flat );
+ levelLCD->setFixedWidth( 70 );
+ levelLCD->setPalette( pal );
+ hb->addWidget( levelLCD );
+ hb->addStretch( 10 );
+
+ label = new QLabel( tr("Ships"), mainWin );
+ label->setFont( labelFont );
+ label->setFixedWidth( label->sizeHint().width() );
+ label->setPalette( pal );
+ hb->addWidget( label );
+
+ shipsLCD = new QLCDNumber( 1, mainWin );
+ shipsLCD->setFrameStyle( Q3Frame::NoFrame );
+ shipsLCD->setSegmentStyle( QLCDNumber::Flat );
+ shipsLCD->setFixedWidth( 40 );
+ shipsLCD->setPalette( pal );
+ hb->addWidget( shipsLCD );
+
+ hb->addStrut( 30 );
+
+ vb->addWidget( view, 10 );
+
+// -- bottom layout:
+ vb->addLayout( hbd );
+
+ QFont smallFont( "helvetica", 14 );
+ hbd->addSpacing( 10 );
+
+ QString sprites_prefix = ":/trolltech/examples/graphicsview/portedasteroids/sprites/";
+/*
+ label = new QLabel( tr( "T" ), mainWin );
+ label->setFont( smallFont );
+ label->setFixedWidth( label->sizeHint().width() );
+ label->setPalette( pal );
+ hbd->addWidget( label );
+
+ teleportsLCD = new QLCDNumber( 1, mainWin );
+ teleportsLCD->setFrameStyle( QFrame::NoFrame );
+ teleportsLCD->setSegmentStyle( QLCDNumber::Flat );
+ teleportsLCD->setPalette( pal );
+ teleportsLCD->setFixedHeight( 20 );
+ hbd->addWidget( teleportsLCD );
+
+ hbd->addSpacing( 10 );
+*/
+ QPixmap pm( sprites_prefix + "powerups/brake.png" );
+ label = new QLabel( mainWin );
+ label->setPixmap( pm );
+ label->setFixedWidth( label->sizeHint().width() );
+ label->setPalette( pal );
+ hbd->addWidget( label );
+
+ brakesLCD = new QLCDNumber( 1, mainWin );
+ brakesLCD->setFrameStyle( Q3Frame::NoFrame );
+ brakesLCD->setSegmentStyle( QLCDNumber::Flat );
+ brakesLCD->setPalette( pal );
+ brakesLCD->setFixedHeight( 20 );
+ hbd->addWidget( brakesLCD );
+
+ hbd->addSpacing( 10 );
+
+ pm.load( sprites_prefix + "powerups/shield.png" );
+ label = new QLabel( mainWin );
+ label->setPixmap( pm );
+ label->setFixedWidth( label->sizeHint().width() );
+ label->setPalette( pal );
+ hbd->addWidget( label );
+
+ shieldLCD = new QLCDNumber( 1, mainWin );
+ shieldLCD->setFrameStyle( Q3Frame::NoFrame );
+ shieldLCD->setSegmentStyle( QLCDNumber::Flat );
+ shieldLCD->setPalette( pal );
+ shieldLCD->setFixedHeight( 20 );
+ hbd->addWidget( shieldLCD );
+
+ hbd->addSpacing( 10 );
+
+ pm.load( sprites_prefix + "powerups/shoot.png" );
+ label = new QLabel( mainWin );
+ label->setPixmap( pm );
+ label->setFixedWidth( label->sizeHint().width() );
+ label->setPalette( pal );
+ hbd->addWidget( label );
+
+ shootLCD = new QLCDNumber( 1, mainWin );
+ shootLCD->setFrameStyle( Q3Frame::NoFrame );
+ shootLCD->setSegmentStyle( QLCDNumber::Flat );
+ shootLCD->setPalette( pal );
+ shootLCD->setFixedHeight( 20 );
+ hbd->addWidget( shootLCD );
+
+ hbd->addStretch( 1 );
+
+ label = new QLabel( tr( "Fuel" ), mainWin );
+ label->setFont( smallFont );
+ label->setFixedWidth( label->sizeHint().width() + 10 );
+ label->setPalette( pal );
+ hbd->addWidget( label );
+
+ powerMeter = new KALedMeter( mainWin );
+ powerMeter->setFrameStyle( Q3Frame::Box | Q3Frame::Plain );
+ powerMeter->setRange( MAX_POWER_LEVEL );
+ powerMeter->addColorRange( 10, Qt::darkRed );
+ powerMeter->addColorRange( 20, QColor(160, 96, 0) );
+ powerMeter->addColorRange( 70, Qt::darkGreen );
+ powerMeter->setCount( 40 );
+ powerMeter->setPalette( pal );
+ powerMeter->setFixedSize( 200, 12 );
+ hbd->addWidget( powerMeter );
+
+ shipsRemain = 3;
+ showHiscores = FALSE;
+
+ actions.insert( Qt::Key_Up, Thrust );
+ actions.insert( Qt::Key_Left, RotateLeft );
+ actions.insert( Qt::Key_Right, RotateRight );
+ actions.insert( Qt::Key_Space, Shoot );
+ actions.insert( Qt::Key_Z, Teleport );
+ actions.insert( Qt::Key_X, Brake );
+ actions.insert( Qt::Key_S, Shield );
+ actions.insert( Qt::Key_P, Pause );
+ actions.insert( Qt::Key_L, Launch );
+ actions.insert( Qt::Key_N, NewGame );
+
+ view->showText( tr( "Press N to start playing" ), Qt::yellow );
+}
+
+KAstTopLevel::~KAstTopLevel()
+{
+}
+
+void KAstTopLevel::playSound( const char * )
+{
+}
+
+void KAstTopLevel::keyPressEvent( QKeyEvent *event )
+{
+ if ( event->isAutoRepeat() || !actions.contains( event->key() ) )
+ {
+ event->ignore();
+ return;
+ }
+
+ Action a = actions[ event->key() ];
+
+ switch ( a )
+ {
+ case RotateLeft:
+ view->rotateLeft( TRUE );
+ break;
+
+ case RotateRight:
+ view->rotateRight( TRUE );
+ break;
+
+ case Thrust:
+ view->thrust( TRUE );
+ break;
+
+ case Shoot:
+ view->shoot( TRUE );
+ break;
+
+ case Shield:
+ view->setShield( TRUE );
+ break;
+
+ case Teleport:
+ view->teleport( TRUE );
+ break;
+
+ case Brake:
+ view->brake( TRUE );
+ break;
+
+ default:
+ event->ignore();
+ return;
+ }
+ event->accept();
+}
+
+void KAstTopLevel::keyReleaseEvent( QKeyEvent *event )
+{
+ if ( event->isAutoRepeat() || !actions.contains( event->key() ) )
+ {
+ event->ignore();
+ return;
+ }
+
+ Action a = actions[ event->key() ];
+
+ switch ( a )
+ {
+ case RotateLeft:
+ view->rotateLeft( FALSE );
+ break;
+
+ case RotateRight:
+ view->rotateRight( FALSE );
+ break;
+
+ case Thrust:
+ view->thrust( FALSE );
+ break;
+
+ case Shoot:
+ view->shoot( FALSE );
+ break;
+
+ case Brake:
+ view->brake( FALSE );
+ break;
+
+ case Shield:
+ view->setShield( FALSE );
+ break;
+
+ case Teleport:
+ view->teleport( FALSE );
+ break;
+
+ case Launch:
+ if ( waitShip )
+ {
+ view->newShip();
+ waitShip = FALSE;
+ view->hideText();
+ }
+ else
+ {
+ event->ignore();
+ return;
+ }
+ break;
+
+ case NewGame:
+ slotNewGame();
+ break;
+/*
+ case Pause:
+ {
+ view->pause( TRUE );
+ QMessageBox::information( this,
+ tr("KAsteroids is paused"),
+ tr("Paused") );
+ view->pause( FALSE );
+ }
+ break;
+*/
+ default:
+ event->ignore();
+ return;
+ }
+
+ event->accept();
+}
+
+void KAstTopLevel::showEvent( QShowEvent *e )
+{
+ Q3MainWindow::showEvent( e );
+ view->pause( FALSE );
+ view->setFocus();
+}
+
+void KAstTopLevel::hideEvent( QHideEvent *e )
+{
+ Q3MainWindow::hideEvent( e );
+ view->pause( TRUE );
+}
+
+void KAstTopLevel::slotNewGame()
+{
+ score = 0;
+ shipsRemain = SB_SHIPS;
+ scoreLCD->display( 0 );
+ level = 0;
+ levelLCD->display( level+1 );
+ shipsLCD->display( shipsRemain-1 );
+ view->newGame();
+ view->setRockSpeed( levels[0].rockSpeed );
+ view->addRocks( levels[0].nrocks );
+// view->showText( tr( "Press L to launch." ), yellow );
+ view->newShip();
+ waitShip = FALSE;
+ view->hideText();
+ isPaused = FALSE;
+}
+
+void KAstTopLevel::slotShipKilled()
+{
+ shipsRemain--;
+ shipsLCD->display( shipsRemain-1 );
+
+ playSound( "ShipDestroyed" );
+
+ if ( shipsRemain )
+ {
+ waitShip = TRUE;
+ view->showText( tr( "Ship Destroyed. Press L to launch."), Qt::yellow );
+ }
+ else
+ {
+ view->showText( tr("Game Over!"), Qt::red );
+ view->endGame();
+ doStats();
+// highscore->addEntry( score, level, showHiscores );
+ }
+}
+
+void KAstTopLevel::slotRockHit( int size )
+{
+ switch ( size )
+ {
+ case 0:
+ score += 10;
+ break;
+
+ case 1:
+ score += 20;
+ break;
+
+ default:
+ score += 40;
+ }
+
+ playSound( "RockDestroyed" );
+
+ scoreLCD->display( score );
+}
+
+void KAstTopLevel::slotRocksRemoved()
+{
+ level++;
+
+ if ( level >= MAX_LEVELS )
+ level = MAX_LEVELS - 1;
+
+ view->setRockSpeed( levels[level-1].rockSpeed );
+ view->addRocks( levels[level-1].nrocks );
+
+ levelLCD->display( level+1 );
+}
+
+void KAstTopLevel::doStats()
+{
+ QString r( "0.00" );
+ if ( view->shots() )
+ r = QString::number( (double)view->hits() / view->shots() * 100.0,
+ 'g', 2 );
+
+/* multi-line text broken in Qt 3
+ QString s = tr( "Game Over\n\nShots fired:\t%1\n Hit:\t%2\n Missed:\t%3\nHit ratio:\t%4 %\n\nPress N for a new game" )
+ .arg(view->shots()).arg(view->hits())
+ .arg(view->shots() - view->hits())
+ .arg(r);
+*/
+
+ view->showText( "Game Over. Press N for a new game.", Qt::yellow, FALSE );
+}
+
+void KAstTopLevel::slotUpdateVitals()
+{
+ brakesLCD->display( view->brakeCount() );
+ shieldLCD->display( view->shieldCount() );
+ shootLCD->display( view->shootCount() );
+// teleportsLCD->display( view->teleportCount() );
+ powerMeter->setValue( view->power() );
+}
diff --git a/examples/graphicsview/portedasteroids/toplevel.h b/examples/graphicsview/portedasteroids/toplevel.h
new file mode 100644
index 0000000000..67781da427
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/toplevel.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * KAsteroids - Copyright (c) Martin R. Jones 1997
+ *
+ * Part of the KDE project
+ */
+
+#ifndef __KAST_TOPLEVEL_H__
+#define __KAST_TOPLEVEL_H__
+
+#include <q3mainwindow.h>
+#include <q3dict.h>
+#include <qmap.h>
+//Added by qt3to4:
+#include <QShowEvent>
+#include <QHideEvent>
+#include <QKeyEvent>
+
+#include "view.h"
+
+
+class KALedMeter;
+QT_BEGIN_NAMESPACE
+class QLCDNumber;
+QT_END_NAMESPACE
+
+class KAstTopLevel : public Q3MainWindow
+{
+ Q_OBJECT
+public:
+ KAstTopLevel( QWidget *parent=0, const char *name=0 );
+ virtual ~KAstTopLevel();
+
+private:
+ void playSound( const char *snd );
+ void readSoundMapping();
+ void doStats();
+
+protected:
+ virtual void showEvent( QShowEvent * );
+ virtual void hideEvent( QHideEvent * );
+ virtual void keyPressEvent( QKeyEvent *event );
+ virtual void keyReleaseEvent( QKeyEvent *event );
+
+private slots:
+ void slotNewGame();
+
+ void slotShipKilled();
+ void slotRockHit( int size );
+ void slotRocksRemoved();
+
+ void slotUpdateVitals();
+
+private:
+ KAsteroidsView *view;
+ QLCDNumber *scoreLCD;
+ QLCDNumber *levelLCD;
+ QLCDNumber *shipsLCD;
+
+ QLCDNumber *teleportsLCD;
+// QLCDNumber *bombsLCD;
+ QLCDNumber *brakesLCD;
+ QLCDNumber *shieldLCD;
+ QLCDNumber *shootLCD;
+ KALedMeter *powerMeter;
+
+ bool sound;
+ Q3Dict<QString> soundDict;
+
+ // waiting for user to press Enter to launch a ship
+ bool waitShip;
+ bool isPaused;
+
+ int shipsRemain;
+ int score;
+ int level;
+ bool showHiscores;
+
+ enum Action { Launch, Thrust, RotateLeft, RotateRight, Shoot, Teleport,
+ Brake, Shield, Pause, NewGame };
+
+ QMap<int,Action> actions;
+};
+
+#endif
+
diff --git a/examples/graphicsview/portedasteroids/view.cpp b/examples/graphicsview/portedasteroids/view.cpp
new file mode 100644
index 0000000000..fc6956b83f
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/view.cpp
@@ -0,0 +1,967 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * KAsteroids - Copyright (c) Martin R. Jones 1997
+ *
+ * Part of the KDE project
+ */
+
+#include <stdlib.h>
+#include <math.h>
+#include <qapplication.h>
+#include <qnamespace.h>
+#include <q3accel.h>
+#include <qmessagebox.h>
+#include <q3scrollview.h>
+#include <qdir.h>
+#include <QGraphicsItem>
+//Added by qt3to4:
+#include <QTimerEvent>
+#include <QPixmap>
+#include <QResizeEvent>
+#include <QShowEvent>
+
+#include "view.h"
+
+#define IMG_BACKGROUND ":/trolltech/examples/graphicsview/portedasteroids/bg.png"
+
+#define REFRESH_DELAY 33
+#define SHIP_SPEED 0.3
+#define MISSILE_SPEED 10.0
+#define SHIP_STEPS 64
+#define ROTATE_RATE 2
+#define SHIELD_ON_COST 1
+#define SHIELD_HIT_COST 30
+#define BRAKE_ON_COST 4
+
+#define MAX_ROCK_SPEED 2.5
+#define MAX_POWERUP_SPEED 1.5
+#define MAX_SHIP_SPEED 12
+#define MAX_BRAKES 5
+#define MAX_SHIELDS 5
+#define MAX_FIREPOWER 5
+
+#define TEXT_SPEED 4
+
+#define PI_X_2 6.283185307
+#ifndef M_PI
+#define M_PI 3.141592654
+#endif
+
+static struct
+{
+ int id;
+ const char *path;
+ int frames;
+}
+kas_animations [] =
+{
+ { ID_ROCK_LARGE, "rock1/rock1%1.png", 32 },
+ { ID_ROCK_MEDIUM, "rock2/rock2%1.png", 32 },
+ { ID_ROCK_SMALL, "rock3/rock3%1.png", 32 },
+ { ID_SHIP, "ship/ship%1.png", 32 },
+ { ID_MISSILE, "missile/missile.png", 1 },
+ { ID_BIT, "bits/bits%1.png", 16 },
+ { ID_EXHAUST, "exhaust/exhaust.png", 1 },
+ { ID_ENERGY_POWERUP, "powerups/energy.png", 1 },
+// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 },
+ { ID_BRAKE_POWERUP, "powerups/brake.png", 1 },
+ { ID_SHIELD_POWERUP, "powerups/shield.png", 1 },
+ { ID_SHOOT_POWERUP, "powerups/shoot.png", 1 },
+ { ID_SHIELD, "shield/shield%1.png", 6 },
+ { 0, 0, 0 }
+};
+
+KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name )
+ : QWidget( parent, name ),
+ field(0, 0, 640, 440),
+ view(&field,this)
+{
+ view.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+ view.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+ view.setCacheMode(QGraphicsView::CacheBackground);
+ view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ view.setOptimizationFlags(QGraphicsView::DontClipPainter
+ | QGraphicsView::DontSavePainterState
+ | QGraphicsView::DontAdjustForAntialiasing);
+ view.viewport()->setFocusProxy( this );
+ rocks.setAutoDelete( TRUE );
+ missiles.setAutoDelete( TRUE );
+ bits.setAutoDelete( TRUE );
+ powerups.setAutoDelete( TRUE );
+ exhaust.setAutoDelete( TRUE );
+
+ QPixmap pm( IMG_BACKGROUND );
+ field.setBackgroundBrush( pm );
+
+ textSprite = new QGraphicsTextItem( 0, &field );
+ QFont font( "helvetica", 18 );
+ textSprite->setFont( font );
+ textSprite->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+
+ shield = 0;
+ shieldOn = FALSE;
+ refreshRate = REFRESH_DELAY;
+
+ initialized = readSprites();
+
+ shieldTimer = new QTimer( this );
+ connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) );
+ mTimerId = -1;
+
+ shipPower = MAX_POWER_LEVEL;
+ vitalsChanged = TRUE;
+ can_destroy_powerups = FALSE;
+
+ mPaused = TRUE;
+
+ if ( !initialized ) {
+ textSprite->setHtml( tr("<font color=red>Error: Cannot read sprite images</font>") );
+ textSprite->setPos( (field.width()-textSprite->boundingRect().width()) / 2,
+ (field.height()-textSprite->boundingRect().height()) / 2 );
+ }
+}
+
+// - - -
+
+KAsteroidsView::~KAsteroidsView()
+{
+}
+
+// - - -
+
+void KAsteroidsView::reset()
+{
+ if ( !initialized )
+ return;
+ rocks.clear();
+ missiles.clear();
+ bits.clear();
+ powerups.clear();
+ exhaust.clear();
+
+ shotsFired = 0;
+ shotsHit = 0;
+
+ rockSpeed = 1.0;
+ powerupSpeed = 1.0;
+ mFrameNum = 0;
+ mPaused = FALSE;
+
+ ship->hide();
+ shield->hide();
+/*
+ if ( mTimerId >= 0 ) {
+ killTimer( mTimerId );
+ mTimerId = -1;
+ }
+*/
+}
+
+// - --
+
+void KAsteroidsView::newGame()
+{
+ if ( !initialized )
+ return;
+ if ( shieldOn )
+ {
+ shield->hide();
+ shieldOn = FALSE;
+ }
+ reset();
+ if ( mTimerId < 0 )
+ mTimerId = startTimer( REFRESH_DELAY );
+ emit updateVitals();
+}
+
+// - - -
+
+void KAsteroidsView::endGame()
+{
+}
+
+void KAsteroidsView::pause( bool p )
+{
+ if ( !initialized )
+ return;
+ if ( !mPaused && p ) {
+ if ( mTimerId >= 0 ) {
+ killTimer( mTimerId );
+ mTimerId = -1;
+ }
+ } else if ( mPaused && !p )
+ mTimerId = startTimer( REFRESH_DELAY );
+ mPaused = p;
+}
+
+// - - -
+
+void KAsteroidsView::newShip()
+{
+ if ( !initialized )
+ return;
+ ship->setPos( width()/2, height()/2 );
+ ship->setFrame( 0 );
+ shield->setPos( width()/2, height()/2 );
+ shield->setFrame( 0 );
+ ship->setVelocity( 0.0, 0.0 );
+ shipDx = 0;
+ shipDy = 0;
+ shipAngle = 0;
+ rotateL = FALSE;
+ rotateR = FALSE;
+ thrustShip = FALSE;
+ shootShip = FALSE;
+ brakeShip = FALSE;
+ teleportShip = FALSE;
+ shieldOn = TRUE;
+ shootDelay = 0;
+ shipPower = MAX_POWER_LEVEL;
+ rotateRate = ROTATE_RATE;
+ rotateSlow = 0;
+
+ mBrakeCount = 0;
+ mTeleportCount = 0;
+ mShootCount = 0;
+
+ ship->show();
+ shield->show();
+ mShieldCount = 1; // just in case the ship appears on a rock.
+ shieldTimer->start( 1000, TRUE );
+}
+
+void KAsteroidsView::setShield( bool s )
+{
+ if ( !initialized )
+ return;
+ if ( shieldTimer->isActive() && !s ) {
+ shieldTimer->stop();
+ hideShield();
+ } else {
+ shieldOn = s && mShieldCount;
+ }
+}
+
+void KAsteroidsView::brake( bool b )
+{
+ if ( !initialized )
+ return;
+ if ( mBrakeCount )
+ {
+ if ( brakeShip && !b )
+ {
+ rotateL = FALSE;
+ rotateR = FALSE;
+ thrustShip = FALSE;
+ rotateRate = ROTATE_RATE;
+ }
+
+ brakeShip = b;
+ }
+}
+
+// - - -
+
+bool KAsteroidsView::readSprites()
+{
+ QString sprites_prefix = ":/trolltech/examples/graphicsview/portedasteroids/sprites/";
+
+ int i = 0;
+ while ( kas_animations[i].id )
+ {
+ QList<QPixmap> anim;
+ QString wildcard = sprites_prefix + kas_animations[i].path;
+ wildcard.replace("%1", "*");
+ QFileInfo fi(wildcard);
+ foreach (QString entry, QDir(fi.path(), fi.fileName()).entryList())
+ anim << QPixmap(fi.path() + "/" + entry);
+ animation.insert( kas_animations[i].id, anim );
+ i++;
+ }
+
+ ship = new AnimatedPixmapItem( animation[ID_SHIP], &field );
+ ship->hide();
+
+ shield = new KShield( animation[ID_SHIELD], &field );
+ shield->hide();
+
+ return (!ship->image(0).isNull() && !shield->image(0).isNull());
+}
+
+// - - -
+
+void KAsteroidsView::addRocks( int num )
+{
+ if ( !initialized )
+ return;
+ for ( int i = 0; i < num; i++ )
+ {
+ KRock *rock = new KRock( animation[ID_ROCK_LARGE], &field,
+ ID_ROCK_LARGE, randInt(2), randInt(2) ? -1 : 1 );
+ double dx = (2.0 - randDouble()*4.0) * rockSpeed;
+ double dy = (2.0 - randDouble()*4.0) * rockSpeed;
+ rock->setVelocity( dx, dy );
+ rock->setFrame( randInt( rock->frameCount() ) );
+ if ( dx > 0 )
+ {
+ if ( dy > 0 )
+ rock->setPos( 5, 5 );
+ else
+ rock->setPos( 5, field.height() - 25 );
+ rock->setFrame( 0 );
+ }
+ else
+ {
+ if ( dy > 0 )
+ rock->setPos( field.width() - 25, 5 );
+ else
+ rock->setPos( field.width() - 25, field.height() - 25 );
+ rock->setFrame( 0 );
+ }
+ rock->show();
+ rocks.append( rock );
+ }
+}
+
+// - - -
+
+void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll )
+{
+ if ( !initialized )
+ return;
+ textSprite->setHtml( QString("<font color=#%1%2%3>%4</font>")
+ .arg(color.red(), 2, 16, QLatin1Char('0'))
+ .arg(color.green(), 2, 16, QLatin1Char('0'))
+ .arg(color.blue(), 2, 16, QLatin1Char('0'))
+ .arg(text) );
+ Q_UNUSED(color);
+ // ### Porting: no such thing textSprite->setColor( color );
+
+ if ( scroll ) {
+ textSprite->setPos( (field.width()-textSprite->boundingRect().width()) / 2,
+ -textSprite->boundingRect().height() );
+ textDy = TEXT_SPEED;
+ } else {
+ textSprite->setPos( (field.width()-textSprite->boundingRect().width()) / 2,
+ (field.height()-textSprite->boundingRect().height()) / 2 );
+ textDy = 0;
+ }
+ textSprite->show();
+}
+
+// - - -
+
+void KAsteroidsView::hideText()
+{
+ textDy = -TEXT_SPEED;
+}
+
+// - - -
+
+void KAsteroidsView::resizeEvent(QResizeEvent* event)
+{
+ QWidget::resizeEvent(event);
+ field.setSceneRect(0, 0, width()-4, height()-4);
+ view.resize(width(),height());
+}
+
+// - - -
+
+void KAsteroidsView::timerEvent( QTimerEvent * )
+{
+ field.advance();
+
+ AnimatedPixmapItem *rock;
+
+ // move rocks forward
+ for ( rock = rocks.first(); rock; rock = rocks.next() ) {
+ ((KRock *)rock)->nextFrame();
+ wrapSprite( rock );
+ }
+
+ wrapSprite( ship );
+
+ // check for missile collision with rocks.
+ processMissiles();
+
+ // these are generated when a ship explodes
+ for ( KBit *bit = bits.first(); bit; bit = bits.next() )
+ {
+ if ( bit->expired() )
+ {
+ bits.removeRef( bit );
+ }
+ else
+ {
+ bit->growOlder();
+ bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() );
+ }
+ }
+
+ for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() )
+ exhaust.removeRef( e );
+
+ // move / rotate ship.
+ // check for collision with a rock.
+ processShip();
+
+ // move powerups and check for collision with player and missiles
+ processPowerups();
+
+ if ( textSprite->isVisible() )
+ {
+ if ( textDy < 0 &&
+ textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) {
+ textSprite->hide();
+ } else {
+ textSprite->moveBy( 0, textDy );
+ }
+
+ if ( textSprite->sceneBoundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 )
+ textDy = 0;
+ }
+
+ if ( vitalsChanged && !(mFrameNum % 10) ) {
+ emit updateVitals();
+ vitalsChanged = FALSE;
+ }
+
+ mFrameNum++;
+}
+
+void KAsteroidsView::wrapSprite( QGraphicsItem *s )
+{
+ int x = int(s->x() + s->boundingRect().width() / 2);
+ int y = int(s->y() + s->boundingRect().height() / 2);
+
+ if ( x > field.width() )
+ s->setPos( s->x() - field.width(), s->y() );
+ else if ( x < 0 )
+ s->setPos( field.width() + s->x(), s->y() );
+
+ if ( y > field.height() )
+ s->setPos( s->x(), s->y() - field.height() );
+ else if ( y < 0 )
+ s->setPos( s->x(), field.height() + s->y() );
+}
+
+// - - -
+
+void KAsteroidsView::rockHit( AnimatedPixmapItem *hit )
+{
+ KPowerup *nPup = 0;
+ int rnd = int(randDouble()*30.0) % 30;
+ switch( rnd )
+ {
+ case 4:
+ case 5:
+ nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field,
+ ID_ENERGY_POWERUP );
+ break;
+ case 10:
+// nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field,
+// ID_TELEPORT_POWERUP );
+ break;
+ case 15:
+ nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field,
+ ID_BRAKE_POWERUP );
+ break;
+ case 20:
+ nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field,
+ ID_SHIELD_POWERUP );
+ break;
+ case 24:
+ case 25:
+ nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field,
+ ID_SHOOT_POWERUP );
+ break;
+ }
+ if ( nPup )
+ {
+ double r = 0.5 - randDouble();
+ nPup->setPos( hit->x(), hit->y() );
+ nPup->setFrame( 0 );
+ nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r );
+ powerups.append( nPup );
+ }
+
+ if ( hit->type() == ID_ROCK_LARGE || hit->type() == ID_ROCK_MEDIUM )
+ {
+ // break into smaller rocks
+ double addx[4] = { 1.0, 1.0, -1.0, -1.0 };
+ double addy[4] = { -1.0, 1.0, -1.0, 1.0 };
+
+ double dx = hit->xVelocity();
+ double dy = hit->yVelocity();
+
+ double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed;
+ if ( dx > maxRockSpeed )
+ dx = maxRockSpeed;
+ else if ( dx < -maxRockSpeed )
+ dx = -maxRockSpeed;
+ if ( dy > maxRockSpeed )
+ dy = maxRockSpeed;
+ else if ( dy < -maxRockSpeed )
+ dy = -maxRockSpeed;
+
+ AnimatedPixmapItem *nrock;
+
+ for ( int i = 0; i < 4; i++ )
+ {
+ double r = rockSpeed/2 - randDouble()*rockSpeed;
+ if ( hit->type() == ID_ROCK_LARGE )
+ {
+ nrock = new KRock( animation[ID_ROCK_MEDIUM], &field,
+ ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
+ emit rockHit( 0 );
+ }
+ else
+ {
+ nrock = new KRock( animation[ID_ROCK_SMALL], &field,
+ ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 );
+ emit rockHit( 1 );
+ }
+
+ nrock->setPos( hit->x(), hit->y() );
+ nrock->setFrame( 0 );
+ nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r );
+ nrock->setFrame( randInt( nrock->frameCount() ) );
+ rocks.append( nrock );
+ }
+ }
+ else if ( hit->type() == ID_ROCK_SMALL )
+ emit rockHit( 2 );
+ rocks.removeRef( hit );
+ if ( rocks.count() == 0 )
+ emit rocksRemoved();
+}
+
+void KAsteroidsView::reducePower( int val )
+{
+ shipPower -= val;
+ if ( shipPower <= 0 )
+ {
+ shipPower = 0;
+ thrustShip = FALSE;
+ if ( shieldOn )
+ {
+ shieldOn = FALSE;
+ shield->hide();
+ }
+ }
+ vitalsChanged = TRUE;
+}
+
+void KAsteroidsView::addExhaust( double x, double y, double dx,
+ double dy, int count )
+{
+ for ( int i = 0; i < count; i++ )
+ {
+ KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field );
+ e->setPos( x + 2 - randDouble()*4, y + 2 - randDouble()*4 );
+ e->setVelocity( dx, dy );
+ exhaust.append( e );
+ }
+}
+
+void KAsteroidsView::processMissiles()
+{
+ KMissile *missile;
+
+ // if a missile has hit a rock, remove missile and break rock into smaller
+ // rocks or remove completely.
+ Q3PtrListIterator<KMissile> it(missiles);
+
+ for ( ; it.current(); ++it )
+ {
+ missile = it.current();
+ missile->growOlder();
+
+ if ( missile->expired() )
+ {
+ missiles.removeRef( missile );
+ continue;
+ }
+
+ wrapSprite( missile );
+
+ QList<QGraphicsItem *> hits = missile->collidingItems(Qt::IntersectsItemBoundingRect);
+ QList<QGraphicsItem *>::Iterator hit;
+ for ( hit = hits.begin(); hit != hits.end(); ++hit )
+ {
+ if ( (*hit)->type() >= ID_ROCK_LARGE &&
+ (*hit)->type() <= ID_ROCK_SMALL && (*hit)->collidesWithItem(missile) )
+ {
+ shotsHit++;
+ rockHit( static_cast<AnimatedPixmapItem *>(*hit) );
+ missiles.removeRef( missile );
+ break;
+ }
+ }
+ }
+}
+
+// - - -
+
+void KAsteroidsView::processShip()
+{
+ if ( ship->isVisible() )
+ {
+ if ( shieldOn )
+ {
+ shield->show();
+ reducePower( SHIELD_ON_COST );
+ static int sf = 0;
+ sf++;
+
+ if ( sf % 2 )
+ shield->setFrame( (shield->frame()+1) % shield->frameCount() );
+ shield->setPos( ship->x() - 9, ship->y() - 9 );
+
+ QList<QGraphicsItem *> hits = shield->collidingItems(Qt::IntersectsItemBoundingRect);
+ QList<QGraphicsItem *>::Iterator it;
+ for ( it = hits.begin(); it != hits.end(); ++it )
+ {
+ if ( (*it)->type() >= ID_ROCK_LARGE &&
+ (*it)->type() <= ID_ROCK_SMALL && (*it)->collidesWithItem(shield) )
+ {
+ int factor;
+ switch ( (*it)->type() )
+ {
+ case ID_ROCK_LARGE:
+ factor = 3;
+ break;
+
+ case ID_ROCK_MEDIUM:
+ factor = 2;
+ break;
+
+ default:
+ factor = 1;
+ }
+
+ if ( factor > mShieldCount )
+ {
+ // shield not strong enough
+ shieldOn = FALSE;
+ break;
+ }
+ rockHit( static_cast<AnimatedPixmapItem *>(*it) );
+ // the more shields we have the less costly
+ reducePower( factor * (SHIELD_HIT_COST - mShieldCount*2) );
+ }
+ }
+ }
+
+ if ( !shieldOn )
+ {
+ shield->hide();
+ QList<QGraphicsItem *> hits = ship->collidingItems(Qt::IntersectsItemBoundingRect);
+ QList<QGraphicsItem *>::Iterator it;
+ for ( it = hits.begin(); it != hits.end(); ++it )
+ {
+ if ( (*it)->type() >= ID_ROCK_LARGE &&
+ (*it)->type() <= ID_ROCK_SMALL && (*it)->collidesWithItem(ship))
+ {
+ KBit *bit;
+ for ( int i = 0; i < 12; i++ )
+ {
+ bit = new KBit( animation[ID_BIT], &field );
+ bit->setPos( ship->x() + 5 - randDouble() * 10,
+ ship->y() + 5 - randDouble() * 10 );
+ bit->setFrame( randInt(bit->frameCount()) );
+ bit->setVelocity( 1-randDouble()*2,
+ 1-randDouble()*2 );
+ bit->setDeath( 60 + randInt(60) );
+ bits.append( bit );
+ }
+ ship->hide();
+ shield->hide();
+ emit shipKilled();
+ break;
+ }
+ }
+ }
+
+
+ if ( rotateSlow )
+ rotateSlow--;
+
+ if ( rotateL )
+ {
+ shipAngle -= rotateSlow ? 1 : rotateRate;
+ if ( shipAngle < 0 )
+ shipAngle += SHIP_STEPS;
+ }
+
+ if ( rotateR )
+ {
+ shipAngle += rotateSlow ? 1 : rotateRate;
+ if ( shipAngle >= SHIP_STEPS )
+ shipAngle -= SHIP_STEPS;
+ }
+
+ double angle = shipAngle * PI_X_2 / SHIP_STEPS;
+ double cosangle = cos( angle );
+ double sinangle = sin( angle );
+
+ if ( brakeShip )
+ {
+ thrustShip = FALSE;
+ rotateL = FALSE;
+ rotateR = FALSE;
+ rotateRate = ROTATE_RATE;
+ if ( fabs(shipDx) < 2.5 && fabs(shipDy) < 2.5 )
+ {
+ shipDx = 0.0;
+ shipDy = 0.0;
+ ship->setVelocity( shipDx, shipDy );
+ brakeShip = FALSE;
+ }
+ else
+ {
+ double motionAngle = atan2( -shipDy, -shipDx );
+ if ( angle > M_PI )
+ angle -= PI_X_2;
+ double angleDiff = angle - motionAngle;
+ if ( angleDiff > M_PI )
+ angleDiff = PI_X_2 - angleDiff;
+ else if ( angleDiff < -M_PI )
+ angleDiff = PI_X_2 + angleDiff;
+ double fdiff = fabs( angleDiff );
+ if ( fdiff > 0.08 )
+ {
+ if ( angleDiff > 0 )
+ rotateL = TRUE;
+ else if ( angleDiff < 0 )
+ rotateR = TRUE;
+ if ( fdiff > 0.6 )
+ rotateRate = mBrakeCount + 1;
+ else if ( fdiff > 0.4 )
+ rotateRate = 2;
+ else
+ rotateRate = 1;
+
+ if ( rotateRate > 5 )
+ rotateRate = 5;
+ }
+ else if ( fabs(shipDx) > 1 || fabs(shipDy) > 1 )
+ {
+ thrustShip = TRUE;
+ // we'll make braking a bit faster
+ shipDx += cosangle/6 * (mBrakeCount - 1);
+ shipDy += sinangle/6 * (mBrakeCount - 1);
+ reducePower( BRAKE_ON_COST );
+ addExhaust( ship->x() + 20 - cosangle*22,
+ ship->y() + 20 - sinangle*22,
+ shipDx-cosangle, shipDy-sinangle,
+ mBrakeCount+1 );
+ }
+ }
+ }
+
+ if ( thrustShip )
+ {
+ // The ship has a terminal velocity, but trying to go faster
+ // still uses fuel (can go faster diagonally - don't care).
+ double thrustx = cosangle/4;
+ double thrusty = sinangle/4;
+ if ( fabs(shipDx + thrustx) < MAX_SHIP_SPEED )
+ shipDx += thrustx;
+ if ( fabs(shipDy + thrusty) < MAX_SHIP_SPEED )
+ shipDy += thrusty;
+ ship->setVelocity( shipDx, shipDy );
+ reducePower( 1 );
+ addExhaust( ship->x() + 20 - cosangle*20,
+ ship->y() + 20 - sinangle*20,
+ shipDx-cosangle, shipDy-sinangle, 3 );
+ }
+
+ ship->setFrame( shipAngle >> 1 );
+
+ if ( shootShip )
+ {
+ if ( !shootDelay && (int)missiles.count() < mShootCount + 2 )
+ {
+ KMissile *missile = new KMissile( animation[ID_MISSILE], &field );
+ missile->setPos( 21+ship->x()+cosangle*21,
+ 21+ship->y()+sinangle*21 );
+ missile->setFrame( 0 );
+ missile->setVelocity( shipDx + cosangle*MISSILE_SPEED,
+ shipDy + sinangle*MISSILE_SPEED );
+ missiles.append( missile );
+ shotsFired++;
+ reducePower( 1 );
+
+ shootDelay = 5;
+ }
+
+ if ( shootDelay )
+ shootDelay--;
+ }
+
+ if ( teleportShip )
+ {
+ int ra = qrand() % 10;
+ if( ra == 0 )
+ ra += qrand() % 20;
+ int xra = ra * 60 + ( (qrand() % 20) * (qrand() % 20) );
+ int yra = ra * 50 - ( (qrand() % 20) * (qrand() % 20) );
+ ship->setPos( xra, yra );
+ }
+
+ vitalsChanged = TRUE;
+ }
+}
+
+// - - -
+
+void KAsteroidsView::processPowerups()
+{
+ if ( !powerups.isEmpty() )
+ {
+ // if player gets the powerup remove it from the screen, if option
+ // "Can destroy powerups" is enabled and a missile hits the powerup
+ // destroy it
+
+ KPowerup *pup;
+ Q3PtrListIterator<KPowerup> it( powerups );
+
+ for( ; it.current(); ++it )
+ {
+ pup = it.current();
+ pup->growOlder();
+
+ if( pup->expired() )
+ {
+ powerups.removeRef( pup );
+ continue;
+ }
+
+ wrapSprite( pup );
+
+ QList<QGraphicsItem *> hits = pup->collidingItems();
+ QList<QGraphicsItem *>::Iterator it;
+ for ( it = hits.begin(); it != hits.end(); ++it )
+ {
+ if ( (*it) == ship )
+ {
+ switch( pup->type() )
+ {
+ case ID_ENERGY_POWERUP:
+ shipPower += 150;
+ if ( shipPower > MAX_POWER_LEVEL )
+ shipPower = MAX_POWER_LEVEL;
+ break;
+ case ID_TELEPORT_POWERUP:
+ mTeleportCount++;
+ break;
+ case ID_BRAKE_POWERUP:
+ if ( mBrakeCount < MAX_BRAKES )
+ mBrakeCount++;
+ break;
+ case ID_SHIELD_POWERUP:
+ if ( mShieldCount < MAX_SHIELDS )
+ mShieldCount++;
+ break;
+ case ID_SHOOT_POWERUP:
+ if ( mShootCount < MAX_FIREPOWER )
+ mShootCount++;
+ break;
+ }
+
+ powerups.removeRef( pup );
+ vitalsChanged = TRUE;
+ }
+ else if ( (*it) == shield )
+ {
+ powerups.removeRef( pup );
+ }
+ else if ( (*it)->type() == ID_MISSILE )
+ {
+ if ( can_destroy_powerups )
+ {
+ powerups.removeRef( pup );
+ }
+ }
+ }
+ }
+ } // -- if( powerups.isEmpty() )
+}
+
+// - - -
+
+void KAsteroidsView::hideShield()
+{
+ shield->hide();
+ mShieldCount = 0;
+ shieldOn = FALSE;
+}
+
+double KAsteroidsView::randDouble()
+{
+ int v = qrand();
+ return (double)v / (double)RAND_MAX;
+}
+
+int KAsteroidsView::randInt( int range )
+{
+ return qrand() % range;
+}
+
+void KAsteroidsView::showEvent( QShowEvent *e )
+{
+#if defined( QT_LICENSE_PROFESSIONAL )
+ static bool wasThere = FALSE;
+
+ if ( !wasThere ) {
+ wasThere = TRUE;
+ QMessageBox::information( this, tr("QGraphicsView demo"),
+ tr("This game has been implemented using the QGraphicsView class.\n"
+ "The QGraphicsView class is not part of the Light Platform Edition. Please \n"
+ "contact Qt Software if you want to upgrade to the Full Platform Edition.") );
+ }
+#endif
+
+ QWidget::showEvent( e );
+}
diff --git a/examples/graphicsview/portedasteroids/view.h b/examples/graphicsview/portedasteroids/view.h
new file mode 100644
index 0000000000..d055f29a2c
--- /dev/null
+++ b/examples/graphicsview/portedasteroids/view.h
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * KAsteroids - Copyright (c) Martin R. Jones 1997
+ *
+ * Part of the KDE project
+ */
+
+#ifndef __AST_VIEW_H__
+#define __AST_VIEW_H__
+
+#include <qwidget.h>
+#include <q3ptrlist.h>
+#include <q3intdict.h>
+#include <qtimer.h>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+//Added by qt3to4:
+#include <QTimerEvent>
+#include <QShowEvent>
+#include <QResizeEvent>
+#include "sprites.h"
+
+#define MAX_POWER_LEVEL 1000
+
+class KAsteroidsView : public QWidget
+{
+ Q_OBJECT
+public:
+ KAsteroidsView( QWidget *parent = 0, const char *name = 0 );
+ virtual ~KAsteroidsView();
+
+ int refreshRate;
+
+ void reset();
+ void setRockSpeed( double rs ) { rockSpeed = rs; }
+ void addRocks( int num );
+ void newGame();
+ void endGame();
+ void newShip();
+
+ void rotateLeft( bool r ) { rotateL = r; rotateSlow = 5; }
+ void rotateRight( bool r ) { rotateR = r; rotateSlow = 5; }
+ void thrust( bool t ) { thrustShip = t && shipPower > 0; }
+ void shoot( bool s ) { shootShip = s; shootDelay = 0; }
+ void setShield( bool s );
+ void teleport( bool te) { teleportShip = te && mTeleportCount; }
+ void brake( bool b );
+ void pause( bool p);
+
+ void showText( const QString &text, const QColor &color, bool scroll=TRUE );
+ void hideText();
+
+ int shots() const { return shotsFired; }
+ int hits() const { return shotsHit; }
+ int power() const { return shipPower; }
+
+ int teleportCount() const { return mTeleportCount; }
+ int brakeCount() const { return mBrakeCount; }
+ int shieldCount() const { return mShieldCount; }
+ int shootCount() const { return mShootCount; }
+
+signals:
+ void shipKilled();
+ void rockHit( int size );
+ void rocksRemoved();
+ void updateVitals();
+
+private slots:
+ void hideShield();
+
+protected:
+ bool readSprites();
+ void wrapSprite( QGraphicsItem * );
+ void rockHit( AnimatedPixmapItem * );
+ void reducePower( int val );
+ void addExhaust( double x, double y, double dx, double dy, int count );
+ void processMissiles();
+ void processShip();
+ void processPowerups();
+ void processShield();
+ double randDouble();
+ int randInt( int range );
+
+ virtual void resizeEvent( QResizeEvent *event );
+ virtual void timerEvent( QTimerEvent * );
+
+ void showEvent( QShowEvent * );
+
+private:
+ QGraphicsScene field;
+ QGraphicsView view;
+ QMap<int, QList<QPixmap> > animation;
+ Q3PtrList<AnimatedPixmapItem> rocks;
+ Q3PtrList<KMissile> missiles;
+ Q3PtrList<KBit> bits;
+ Q3PtrList<KExhaust> exhaust;
+ Q3PtrList<KPowerup> powerups;
+ KShield *shield;
+ AnimatedPixmapItem *ship;
+ QGraphicsTextItem *textSprite;
+
+ bool rotateL;
+ bool rotateR;
+ bool thrustShip;
+ bool shootShip;
+ bool teleportShip;
+ bool brakeShip;
+ bool pauseShip;
+ bool shieldOn;
+
+ bool vitalsChanged;
+
+ int shipAngle;
+ int rotateSlow;
+ int rotateRate;
+ int shipPower;
+
+ int shotsFired;
+ int shotsHit;
+ int shootDelay;
+
+ int mBrakeCount;
+ int mShieldCount;
+ int mTeleportCount;
+ int mShootCount;
+
+ double shipDx;
+ double shipDy;
+
+ int textDy;
+ int mFrameNum;
+ bool mPaused;
+ int mTimerId;
+
+ double rockSpeed;
+ double powerupSpeed;
+
+ bool can_destroy_powerups;
+
+ QTimer *shieldTimer;
+ bool initialized;
+};
+
+#endif
diff --git a/examples/graphicsview/portedcanvas/blendshadow.cpp b/examples/graphicsview/portedcanvas/blendshadow.cpp
new file mode 100644
index 0000000000..42cd0e366d
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/blendshadow.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qimage.h>
+#include <qcolor.h>
+
+static inline int blendComponent( int v, int av, int s, int as )
+{
+ return as*s + av*v -(av*as*s)/255;
+}
+
+static inline QRgb blendShade( QRgb v, QRgb s )
+{
+ //shadow image is already reduced and blurred
+ int as = qAlpha(s);
+ int av = qAlpha(v);
+ if ( as == 0 || av == 255 )
+ return v;
+
+ int a = as + av -(as*av)/255;
+
+ int r = blendComponent( qRed(v),av, qRed(s), as)/a;
+ int g = blendComponent( qGreen(v),av, qGreen(s), as)/a;
+ int b = blendComponent( qBlue(v),av, qBlue(s), as)/a;
+
+ return qRgba(r,g,b,a);
+}
+
+
+
+int main( int*, char**)
+{
+ QImage image( "out.png" );
+ image.convertDepth( 32 );
+ QImage shade( "outshade.png" );
+ shade.convertDepth( 32 );
+ int dx = 10;
+ int dy = 5;
+
+ int w = image.width();
+ int h = image.height();
+
+ QImage img( w+dx, h+dy, 32 );
+ img.setAlphaBuffer( TRUE );
+
+ for ( int y = 0; y < h+dy; y++ ) {
+ for ( int x = 0; x < w+dx; x++ ) {
+ QRgb sh = (x<dx||y<dy) ? 0 : shade.pixel( x-dx, y-dy );
+ QRgb pixel = (x<w&y<h) ? image.pixel( x, y ) : 0;
+ img.setPixel( x, y, blendShade( pixel, sh ) );
+ }
+ }
+ img.save("blend.png", "PNG" );
+}
+
+
diff --git a/examples/graphicsview/portedcanvas/butterfly.png b/examples/graphicsview/portedcanvas/butterfly.png
new file mode 100644
index 0000000000..f3e050eca2
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/butterfly.png
Binary files differ
diff --git a/examples/graphicsview/portedcanvas/canvas.cpp b/examples/graphicsview/portedcanvas/canvas.cpp
new file mode 100644
index 0000000000..c8718dc607
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/canvas.cpp
@@ -0,0 +1,733 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qdatetime.h>
+#include <qmainwindow.h>
+#include <qstatusbar.h>
+#include <qmessagebox.h>
+#include <qmenubar.h>
+#include <qapplication.h>
+#include <qpainter.h>
+#include <qprinter.h>
+#include <qlabel.h>
+#include <qimage.h>
+#include <q3progressdialog.h>
+#include <Q3PointArray>
+#include <Q3PtrList>
+#include <QPixmap>
+#include <Q3PopupMenu>
+#include <QMouseEvent>
+#include <Q3MemArray>
+#include "canvas.h"
+#include <QStyleOptionGraphicsItem>
+#include <qdebug.h>
+#include <stdlib.h>
+
+// We use a global variable to save memory - all the brushes and pens in
+// the mesh are shared.
+static QBrush *tb = 0;
+static QPen *tp = 0;
+
+class EdgeItem;
+class NodeItem;
+
+class EdgeItem: public QGraphicsLineItem
+{
+public:
+ EdgeItem( NodeItem*, NodeItem* );
+ void setFromPoint( int x, int y ) ;
+ void setToPoint( int x, int y );
+ static int count() { return c; }
+private:
+ static int c;
+};
+
+static const int imageRTTI = 984376;
+
+
+class ImageItem: public QGraphicsRectItem
+{
+public:
+ ImageItem( QImage img );
+ int rtti () const { return imageRTTI; }
+protected:
+ void paint( QPainter *, const QStyleOptionGraphicsItem *option, QWidget *widget );
+private:
+ QImage image;
+ QPixmap pixmap;
+};
+
+
+ImageItem::ImageItem( QImage img )
+ : image(img)
+{
+ setRect(0, 0, image.width(), image.height());
+ setFlag(ItemIsMovable);
+#if !defined(Q_WS_QWS)
+ pixmap.convertFromImage(image, Qt::OrderedAlphaDither);
+#endif
+}
+
+void ImageItem::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget * )
+{
+// On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
+// but on other platforms, we need to use a QPixmap.
+#if defined(Q_WS_QWS)
+ p->drawImage( option->exposedRect, image, option->exposedRect, Qt::OrderedAlphaDither );
+#else
+ p->drawPixmap( option->exposedRect, pixmap, option->exposedRect );
+#endif
+}
+
+class NodeItem: public QGraphicsEllipseItem
+{
+public:
+ NodeItem();
+ ~NodeItem() {}
+
+ void addInEdge( EdgeItem *edge ) { inList.append( edge ); }
+ void addOutEdge( EdgeItem *edge ) { outList.append( edge ); }
+
+protected:
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+
+
+ // QPoint center() { return boundingRect().center(); }
+private:
+ Q3PtrList<EdgeItem> inList;
+ Q3PtrList<EdgeItem> outList;
+};
+
+
+int EdgeItem::c = 0;
+
+EdgeItem::EdgeItem( NodeItem *from, NodeItem *to )
+ : QGraphicsLineItem( )
+{
+ c++;
+ setPen( *tp );
+ from->addOutEdge( this );
+ to->addInEdge( this );
+ setLine( QLineF(int(from->x()), int(from->y()), int(to->x()), int(to->y()) ));
+ setZValue( 127 );
+ setBoundingRegionGranularity(0.05);
+}
+
+void EdgeItem::setFromPoint( int x, int y )
+{
+ setLine(QLineF( x,y, line().p2().x(), line().p2().y() ));
+}
+
+void EdgeItem::setToPoint( int x, int y )
+{
+ setLine(QLineF( line().p1().x(), line().p1().y(), x, y ));
+}
+
+QVariant NodeItem::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ if (change == ItemPositionHasChanged) {
+ Q3PtrListIterator<EdgeItem> it1( inList );
+ EdgeItem *edge;
+ while (( edge = it1.current() )) {
+ ++it1;
+ edge->setToPoint( int(x()), int(y()) );
+ }
+ Q3PtrListIterator<EdgeItem> it2( outList );
+ while (( edge = it2.current() )) {
+ ++it2;
+ edge->setFromPoint( int(x()), int(y()) );
+ }
+ }
+
+ return QGraphicsEllipseItem::itemChange(change, value);
+}
+
+NodeItem::NodeItem( )
+ : QGraphicsEllipseItem( QRectF(-3, -3, 6, 6) )
+{
+ setPen( *tp );
+ setBrush( *tb );
+ setZValue( 128 );
+ setFlag(ItemIsMovable);
+}
+
+FigureEditor::FigureEditor(
+ QGraphicsScene& c, QWidget* parent,
+ const char* name, Qt::WindowFlags f) :
+ QGraphicsView(&c,parent)
+{
+ setObjectName(name);
+ setWindowFlags(f);
+ setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+}
+
+void FigureEditor::clear()
+{
+ scene()->clear();
+}
+
+BouncyLogo::BouncyLogo() :
+ xvel(0), yvel(0)
+{
+ setPixmap(QPixmap(":/trolltech/examples/graphicsview/portedcanvas/qt-trans.xpm"));
+}
+
+const int logo_rtti = 1234;
+
+int BouncyLogo::type() const
+{
+ return logo_rtti;
+}
+
+QPainterPath BouncyLogo::shape() const
+{
+ QPainterPath path;
+ path.addRect(boundingRect());
+ return path;
+}
+
+void BouncyLogo::initPos()
+{
+ initSpeed();
+ int trial=1000;
+ do {
+ setPos(qrand()%int(scene()->width()),qrand()%int(scene()->height()));
+ advance(0);
+ } while (trial-- && xvel==0.0 && yvel==0.0);
+}
+
+void BouncyLogo::initSpeed()
+{
+ const double speed = 4.0;
+ double d = (double)(qrand()%1024) / 1024.0;
+ xvel = d*speed*2-speed;
+ yvel = (1-d)*speed*2-speed;
+}
+
+void BouncyLogo::advance(int stage)
+{
+ switch ( stage ) {
+ case 0: {
+ double vx = xvel;
+ double vy = yvel;
+
+ if ( vx == 0.0 && vy == 0.0 ) {
+ // stopped last turn
+ initSpeed();
+ vx = xvel;
+ vy = yvel;
+ }
+
+ double nx = x() + vx;
+ double ny = y() + vy;
+
+ if ( nx < 0 || nx >= scene()->width() )
+ vx = -vx;
+ if ( ny < 0 || ny >= scene()->height() )
+ vy = -vy;
+
+ for (int bounce=0; bounce<4; bounce++) {
+ QList<QGraphicsItem *> l=scene()->collidingItems(this);
+ for (QList<QGraphicsItem *>::Iterator it=l.begin(); it!=l.end(); ++it) {
+ QGraphicsItem *hit = *it;
+ QPainterPath advancedShape = QMatrix().translate(xvel, yvel).map(shape());
+ if ( hit->type()==logo_rtti && hit->collidesWithPath(mapToItem(hit, advancedShape)) ) {
+ switch ( bounce ) {
+ case 0:
+ vx = -vx;
+ break;
+ case 1:
+ vy = -vy;
+ vx = -vx;
+ break;
+ case 2:
+ vx = -vx;
+ break;
+ case 3:
+ // Stop for this turn
+ vx = 0;
+ vy = 0;
+ break;
+ }
+ xvel = vx;
+ yvel = vy;
+ break;
+ }
+ }
+ }
+
+ if ( x()+vx < 0 || x()+vx >= scene()->width() )
+ vx = 0;
+ if ( y()+vy < 0 || y()+vy >= scene()->height() )
+ vy = 0;
+
+ xvel = vx;
+ yvel = vy;
+ } break;
+ case 1:
+ moveBy(xvel, yvel);
+ break;
+ }
+}
+
+static uint mainCount = 0;
+static QImage *butterflyimg;
+static QImage *logoimg;
+
+Main::Main(QGraphicsScene& c, QWidget* parent, const char* name, Qt::WindowFlags f) :
+ Q3MainWindow(parent,name,f),
+ canvas(c)
+{
+ editor = new FigureEditor(canvas,this);
+ QMenuBar* menu = menuBar();
+
+ Q3PopupMenu* file = new Q3PopupMenu( menu );
+ file->insertItem("&Fill canvas", this, SLOT(init()), Qt::CTRL+Qt::Key_F);
+ file->insertItem("&Erase canvas", this, SLOT(clear()), Qt::CTRL+Qt::Key_E);
+ file->insertItem("&New view", this, SLOT(newView()), Qt::CTRL+Qt::Key_N);
+ file->insertSeparator();
+ file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P);
+ file->insertSeparator();
+ file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q);
+ menu->insertItem("&File", file);
+
+ Q3PopupMenu* edit = new Q3PopupMenu( menu );
+ edit->insertItem("Add &Circle", this, SLOT(addCircle()), Qt::ALT+Qt::Key_C);
+ edit->insertItem("Add &Hexagon", this, SLOT(addHexagon()), Qt::ALT+Qt::Key_H);
+ edit->insertItem("Add &Polygon", this, SLOT(addPolygon()), Qt::ALT+Qt::Key_P);
+ edit->insertItem("Add Spl&ine", this, SLOT(addSpline()), Qt::ALT+Qt::Key_I);
+ edit->insertItem("Add &Text", this, SLOT(addText()), Qt::ALT+Qt::Key_T);
+ edit->insertItem("Add &Line", this, SLOT(addLine()), Qt::ALT+Qt::Key_L);
+ edit->insertItem("Add &Rectangle", this, SLOT(addRectangle()), Qt::ALT+Qt::Key_R);
+ edit->insertItem("Add &Sprite", this, SLOT(addSprite()), Qt::ALT+Qt::Key_S);
+ edit->insertItem("Create &Mesh", this, SLOT(addMesh()), Qt::ALT+Qt::Key_M );
+ edit->insertItem("Add &Alpha-blended image", this, SLOT(addButterfly()), Qt::ALT+Qt::Key_A);
+ menu->insertItem("&Edit", edit);
+
+ Q3PopupMenu* view = new Q3PopupMenu( menu );
+ view->insertItem("&Enlarge", this, SLOT(enlarge()), Qt::SHIFT+Qt::CTRL+Qt::Key_Plus);
+ view->insertItem("Shr&ink", this, SLOT(shrink()), Qt::SHIFT+Qt::CTRL+Qt::Key_Minus);
+ view->insertSeparator();
+ view->insertItem("&Rotate clockwise", this, SLOT(rotateClockwise()), Qt::CTRL+Qt::Key_PageDown);
+ view->insertItem("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), Qt::CTRL+Qt::Key_PageUp);
+ view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Plus);
+ view->insertItem("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus);
+ view->insertItem("Translate left", this, SLOT(moveL()), Qt::CTRL+Qt::Key_Left);
+ view->insertItem("Translate right", this, SLOT(moveR()), Qt::CTRL+Qt::Key_Right);
+ view->insertItem("Translate up", this, SLOT(moveU()), Qt::CTRL+Qt::Key_Up);
+ view->insertItem("Translate down", this, SLOT(moveD()), Qt::CTRL+Qt::Key_Down);
+ view->insertItem("&Mirror", this, SLOT(mirror()), Qt::CTRL+Qt::Key_Home);
+ menu->insertItem("&View", view);
+
+ menu->insertSeparator();
+
+ Q3PopupMenu* help = new Q3PopupMenu( menu );
+ help->insertItem("&About", this, SLOT(help()), Qt::Key_F1);
+ help->setItemChecked(dbf_id, TRUE);
+ menu->insertItem("&Help",help);
+
+ statusBar();
+
+ setCentralWidget(editor);
+
+ printer = 0;
+
+ init();
+}
+
+void Main::init()
+{
+ clear();
+
+ static int r=24;
+ qsrand(++r);
+
+ mainCount++;
+ butterflyimg = 0;
+ logoimg = 0;
+
+ int i;
+ for ( i=0; i < int(canvas.width()) / 56; i++) {
+ addButterfly();
+ }
+ for ( i=0; i < int(canvas.width()) / 85; i++) {
+ addHexagon();
+ }
+ for ( i=0; i < int(canvas.width()) / 128; i++) {
+ addLogo();
+ }
+}
+
+Main::~Main()
+{
+ delete printer;
+ if ( !--mainCount ) {
+ delete[] butterflyimg;
+ butterflyimg = 0;
+ delete[] logoimg;
+ logoimg = 0;
+ }
+}
+
+void Main::newView()
+{
+ // Open a new view... have it delete when closed.
+ Main *m = new Main(canvas, 0, 0, Qt::WDestructiveClose);
+ m->show();
+}
+
+void Main::clear()
+{
+ editor->clear();
+}
+
+void Main::help()
+{
+ static QMessageBox* about = new QMessageBox( "Qt Canvas Example",
+ "<h3>The QCanvas classes example</h3>"
+ "<ul>"
+ "<li> Press ALT-S for some sprites."
+ "<li> Press ALT-C for some circles."
+ "<li> Press ALT-L for some lines."
+ "<li> Drag the objects around."
+ "<li> Read the code!"
+ "</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
+ about->setButtonText( 1, "Dismiss" );
+ about->show();
+}
+
+void Main::aboutQt()
+{
+ QMessageBox::aboutQt( this, "Qt Canvas Example" );
+}
+
+void Main::enlarge()
+{
+ canvas.setSceneRect(0, 0, canvas.width()*4/3, canvas.height()*4/3);
+}
+
+void Main::shrink()
+{
+ canvas.setSceneRect(0, 0, qMax(canvas.width()*3/4, qreal(1.0)), qMax(canvas.height()*3/4, qreal(1.0)));
+}
+
+void Main::rotateClockwise()
+{
+ editor->rotate( 22.5 );
+}
+
+void Main::rotateCounterClockwise()
+{
+ editor->rotate( -22.5 );
+}
+
+void Main::zoomIn()
+{
+ editor->scale( 2.0, 2.0 );
+}
+
+void Main::zoomOut()
+{
+ editor->scale( 0.5, 0.5 );
+}
+
+void Main::mirror()
+{
+ editor->scale( -1, 1 );
+}
+
+void Main::moveL()
+{
+ editor->translate( -16, 0 );
+}
+
+void Main::moveR()
+{
+ editor->translate( +16, 0 );
+}
+
+void Main::moveU()
+{
+ editor->translate( 0, -16 );
+}
+
+void Main::moveD()
+{
+ editor->translate( 0, +16 );
+}
+
+void Main::print()
+{
+ if ( !printer ) printer = new QPrinter;
+ if ( printer->setup(this) ) {
+ QPainter pp(printer);
+ canvas.render(&pp);
+ }
+}
+
+
+void Main::addSprite()
+{
+ BouncyLogo* i = new BouncyLogo;
+ canvas.addItem(i);
+ i->initPos();
+ i->setZValue(qrand()%256);
+}
+
+QString butterfly_fn;
+QString logo_fn;
+
+
+void Main::addButterfly()
+{
+ if ( butterfly_fn.isEmpty() )
+ return;
+ if ( !butterflyimg ) {
+ butterflyimg = new QImage[4];
+ butterflyimg[0].load( butterfly_fn );
+ butterflyimg[1] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.75),
+ int(butterflyimg[0].height()*0.75) );
+ butterflyimg[2] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.5),
+ int(butterflyimg[0].height()*0.5) );
+ butterflyimg[3] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.25),
+ int(butterflyimg[0].height()*0.25) );
+ }
+ QAbstractGraphicsShapeItem* i = new ImageItem(butterflyimg[qrand()%4]);
+ canvas.addItem(i);
+ i->setPos(qrand()%int(canvas.width()-butterflyimg->width()),
+ qrand()%int(canvas.height()-butterflyimg->height()));
+ i->setZValue(qrand()%256+250);
+}
+
+void Main::addLogo()
+{
+ if ( logo_fn.isEmpty() )
+ return;
+ if ( !logoimg ) {
+ logoimg = new QImage[4];
+ logoimg[0].load( logo_fn );
+ logoimg[1] = logoimg[0].smoothScale( int(logoimg[0].width()*0.75),
+ int(logoimg[0].height()*0.75) );
+ logoimg[2] = logoimg[0].smoothScale( int(logoimg[0].width()*0.5),
+ int(logoimg[0].height()*0.5) );
+ logoimg[3] = logoimg[0].smoothScale( int(logoimg[0].width()*0.25),
+ int(logoimg[0].height()*0.25) );
+ }
+ QAbstractGraphicsShapeItem* i = new ImageItem(logoimg[qrand()%4]);
+ canvas.addItem(i);
+ i->setPos(qrand()%int(canvas.width()-logoimg->width()),
+ qrand()%int(canvas.height()-logoimg->width()));
+ i->setZValue(qrand()%256+256);
+}
+
+
+
+void Main::addCircle()
+{
+ QAbstractGraphicsShapeItem* i = canvas.addEllipse(QRectF(0,0,50,50));
+ i->setFlag(QGraphicsItem::ItemIsMovable);
+ i->setPen(Qt::NoPen);
+ i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
+ i->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
+ i->setZValue(qrand()%256);
+}
+
+void Main::addHexagon()
+{
+ const int size = int(canvas.width() / 25);
+ Q3PointArray pa(6);
+ pa[0] = QPoint(2*size,0);
+ pa[1] = QPoint(size,-size*173/100);
+ pa[2] = QPoint(-size,-size*173/100);
+ pa[3] = QPoint(-2*size,0);
+ pa[4] = QPoint(-size,size*173/100);
+ pa[5] = QPoint(size,size*173/100);
+ QGraphicsPolygonItem* i = canvas.addPolygon(pa);
+ i->setFlag(QGraphicsItem::ItemIsMovable);
+ i->setPen(Qt::NoPen);
+ i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
+ i->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
+ i->setZValue(qrand()%256);
+}
+
+void Main::addPolygon()
+{
+ const int size = int(canvas.width()/2);
+ Q3PointArray pa(6);
+ pa[0] = QPoint(0,0);
+ pa[1] = QPoint(size,size/5);
+ pa[2] = QPoint(size*4/5,size);
+ pa[3] = QPoint(size/6,size*5/4);
+ pa[4] = QPoint(size*3/4,size*3/4);
+ pa[5] = QPoint(size*3/4,size/4);
+ QGraphicsPolygonItem* i = canvas.addPolygon(pa);
+ i->setFlag(QGraphicsItem::ItemIsMovable);
+ i->setPen(Qt::NoPen);
+ i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
+ i->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
+ i->setZValue(qrand()%256);
+}
+
+void Main::addSpline()
+{
+ const int size = int(canvas.width()/6);
+
+ Q3PointArray pa(12);
+ pa[0] = QPoint(0,0);
+ pa[1] = QPoint(size/2,0);
+ pa[2] = QPoint(size,size/2);
+ pa[3] = QPoint(size,size);
+ pa[4] = QPoint(size,size*3/2);
+ pa[5] = QPoint(size/2,size*2);
+ pa[6] = QPoint(0,size*2);
+ pa[7] = QPoint(-size/2,size*2);
+ pa[8] = QPoint(size/4,size*3/2);
+ pa[9] = QPoint(0,size);
+ pa[10]= QPoint(-size/4,size/2);
+ pa[11]= QPoint(-size/2,0);
+
+ QPainterPath path;
+ path.moveTo(pa[0]);
+ for (int i = 1; i < pa.size(); i += 3)
+ path.cubicTo(pa[i], pa[(i + 1) % pa.size()], pa[(i + 2) % pa.size()]);
+
+ QGraphicsPathItem* item = canvas.addPath(path);
+ item->setFlag(QGraphicsItem::ItemIsMovable);
+ item->setPen(Qt::NoPen);
+ item->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
+ item->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
+ item->setZValue(qrand()%256);
+}
+
+void Main::addText()
+{
+ QGraphicsTextItem* i = canvas.addText("QCanvasText");
+ i->setFlag(QGraphicsItem::ItemIsMovable);
+ i->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
+ i->setZValue(qrand()%256);
+}
+
+void Main::addLine()
+{
+ QGraphicsLineItem* i = canvas.addLine(QLineF( qrand()%int(canvas.width()), qrand()%int(canvas.height()),
+ qrand()%int(canvas.width()), qrand()%int(canvas.height()) ));
+ i->setFlag(QGraphicsItem::ItemIsMovable);
+ i->setPen( QPen(QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8), 6) );
+ i->setZValue(qrand()%256);
+}
+
+void Main::addMesh()
+{
+ int x0 = 0;
+ int y0 = 0;
+
+ if ( !tb ) tb = new QBrush( Qt::red );
+ if ( !tp ) tp = new QPen( Qt::black );
+
+ int nodecount = 0;
+
+ int w = int(canvas.width());
+ int h = int(canvas.height());
+
+ const int dist = 30;
+ int rows = h / dist;
+ int cols = w / dist;
+
+#ifndef QT_NO_PROGRESSDIALOG
+ Q3ProgressDialog progress( "Creating mesh...", "Abort", rows,
+ this, "progress", TRUE );
+#endif
+
+ canvas.update();
+
+ Q3MemArray<NodeItem*> lastRow(cols);
+ for ( int j = 0; j < rows; j++ ) {
+ int n = j%2 ? cols-1 : cols;
+ NodeItem *prev = 0;
+ for ( int i = 0; i < n; i++ ) {
+ NodeItem *el = new NodeItem;
+ canvas.addItem(el);
+ nodecount++;
+ int r = qrand();
+ int xrand = r %20;
+ int yrand = (r/20) %20;
+ el->setPos( xrand + x0 + i*dist + (j%2 ? dist/2 : 0 ),
+ yrand + y0 + j*dist );
+
+ if ( j > 0 ) {
+ if ( i < cols-1 )
+ canvas.addItem(new EdgeItem( lastRow[i], el));
+ if ( j%2 )
+ canvas.addItem(new EdgeItem( lastRow[i+1], el));
+ else if ( i > 0 )
+ canvas.addItem(new EdgeItem( lastRow[i-1], el));
+ }
+ if ( prev ) {
+ canvas.addItem(new EdgeItem( prev, el));
+ }
+ if ( i > 0 ) lastRow[i-1] = prev;
+ prev = el;
+ }
+ lastRow[n-1]=prev;
+#ifndef QT_NO_PROGRESSDIALOG
+ progress.setProgress( j );
+ if ( progress.wasCancelled() )
+ break;
+#endif
+ }
+#ifndef QT_NO_PROGRESSDIALOG
+ progress.setProgress( rows );
+#endif
+ // qDebug( "%d nodes, %d edges", nodecount, EdgeItem::count() );
+}
+
+void Main::addRectangle()
+{
+ QAbstractGraphicsShapeItem *i = canvas.addRect( QRectF(qrand()%int(canvas.width()),
+ qrand()%int(canvas.height()),
+ canvas.width()/5,
+ canvas.width()/5) );
+ i->setFlag(QGraphicsItem::ItemIsMovable);
+ int z = qrand()%256;
+ i->setBrush( QColor(z,z,z) );
+ i->setPen( QPen(QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8), 6) );
+ i->setZValue(z);
+}
diff --git a/examples/graphicsview/portedcanvas/canvas.doc b/examples/graphicsview/portedcanvas/canvas.doc
new file mode 100644
index 0000000000..f6d77ad685
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/canvas.doc
@@ -0,0 +1,29 @@
+/*! \page canvas-example.html
+
+ \ingroup examples
+ \title Canvas Example
+
+ This example shows a QCanvas and some \l{QCanvasItem}s in action.
+ You can do a lot more with QCanvas than we show here, but the
+ example provides a taste of what can be done.
+
+ <hr>
+
+ Header file:
+
+ \include canvas/canvas.h
+
+ <hr>
+
+ Implementation:
+
+ \include canvas/canvas.cpp
+
+ <hr>
+
+ Main:
+
+ \include canvas/main.cpp
+*/
+
+
diff --git a/examples/graphicsview/portedcanvas/canvas.h b/examples/graphicsview/portedcanvas/canvas.h
new file mode 100644
index 0000000000..769edbf134
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/canvas.h
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EXAMPLE_H
+#define EXAMPLE_H
+
+#include <q3popupmenu.h>
+#include <q3mainwindow.h>
+#include <q3intdict.h>
+#include <QMouseEvent>
+#include <QGraphicsView>
+#include <QGraphicsScene>
+#include <QGraphicsItem>
+
+class BouncyLogo : public QGraphicsPixmapItem {
+ void initSpeed();
+public:
+ BouncyLogo();
+ void advance(int);
+ int type() const;
+
+ QPainterPath shape() const;
+
+ void initPos();
+private:
+ qreal xvel;
+ qreal yvel;
+};
+
+
+class FigureEditor : public QGraphicsView {
+ Q_OBJECT
+
+public:
+ FigureEditor(QGraphicsScene&, QWidget* parent=0, const char* name=0, Qt::WindowFlags f=0);
+ void clear();
+
+signals:
+ void status(const QString&);
+};
+
+class Main : public Q3MainWindow {
+ Q_OBJECT
+
+public:
+ Main(QGraphicsScene&, QWidget* parent=0, const char* name=0, Qt::WindowFlags f=0);
+ ~Main();
+
+public slots:
+ void help();
+
+private slots:
+ void aboutQt();
+ void newView();
+ void clear();
+ void init();
+
+ void addSprite();
+ void addCircle();
+ void addHexagon();
+ void addPolygon();
+ void addSpline();
+ void addText();
+ void addLine();
+ void addRectangle();
+ void addMesh();
+ void addLogo();
+ void addButterfly();
+
+ void enlarge();
+ void shrink();
+ void rotateClockwise();
+ void rotateCounterClockwise();
+ void zoomIn();
+ void zoomOut();
+ void mirror();
+ void moveL();
+ void moveR();
+ void moveU();
+ void moveD();
+
+ void print();
+
+private:
+ QGraphicsScene& canvas;
+ FigureEditor *editor;
+
+ Q3PopupMenu* options;
+ QPrinter* printer;
+ int dbf_id;
+};
+
+#endif
diff --git a/examples/graphicsview/portedcanvas/main.cpp b/examples/graphicsview/portedcanvas/main.cpp
new file mode 100644
index 0000000000..b68c4cb225
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/main.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qstatusbar.h>
+#include <qmessagebox.h>
+#include <qmenubar.h>
+#include <qapplication.h>
+#include <qdesktopwidget.h>
+#include <qimage.h>
+#include <qtimer.h>
+
+#include "canvas.h"
+
+#include <stdlib.h>
+
+extern QString butterfly_fn;
+extern QString logo_fn;
+
+int main(int argc, char** argv)
+{
+ Q_INIT_RESOURCE(portedcanvas);
+
+ QApplication app(argc,argv);
+
+ if ( argc > 1 )
+ butterfly_fn = argv[1];
+ else
+ butterfly_fn = ":/trolltech/examples/graphicsview/portedcanvas/butterfly.png";
+
+ if ( argc > 2 )
+ logo_fn = argv[2];
+ else
+ logo_fn = ":/trolltech/examples/graphicsview/portedcanvas/qtlogo.png";
+
+ QGraphicsScene canvas;
+ canvas.setSceneRect(0, 0, 800, 600);
+ Main m(canvas);
+ m.resize(m.sizeHint());
+ m.setCaption("Ported Canvas Example");
+ if ( QApplication::desktop()->width() > m.width() + 10
+ && QApplication::desktop()->height() > m.height() +30 )
+ m.show();
+ else
+ m.showMaximized();
+
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), &canvas, SLOT(advance()));
+ timer.start(30);
+
+ QObject::connect( qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()) );
+
+ return app.exec();
+}
+
diff --git a/examples/graphicsview/portedcanvas/makeimg.cpp b/examples/graphicsview/portedcanvas/makeimg.cpp
new file mode 100644
index 0000000000..93a8efefbe
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/makeimg.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qimage.h>
+#include <qcolor.h>
+
+static inline int blendComponent( int v, int av, int s, int as )
+{
+ //shadow gets a color inversely proportional to the
+ //alpha value
+ s = (s*(255-as))/255;
+ //then do standard blending
+ return as*s + av*v -(av*as*s)/255;
+}
+
+static inline QRgb blendShade( QRgb v, QRgb s )
+{
+ //pick a number: shadow is 1/3 of object
+ int as = qAlpha(s)/3;
+ int av = qAlpha(v);
+ if ( as == 0 || av == 255 )
+ return v;
+
+ int a = as + av -(as*av)/255;
+
+
+ int r = blendComponent( qRed(v),av, qRed(s), as)/a;
+ int g = blendComponent( qGreen(v),av, qGreen(s), as)/a;
+ int b = blendComponent( qBlue(v),av, qBlue(s), as)/a;
+
+ return qRgba(r,g,b,a);
+}
+
+int main( int*, char**)
+{
+ QImage *img;
+
+ img = new QImage( "in.png" );
+ int w,h;
+ int y;
+ img->setAlphaBuffer( TRUE );
+ *img = img->convertDepth( 32 );
+ w = img->width();
+ h = img->height();
+#if 0
+ for ( y = 0; y < h; y ++ ) {
+ uint *line = (uint*)img->scanLine( y );
+ for ( int x = 0; x < w; x++ ) {
+ uint pixel = line[x];
+ int r = qRed(pixel);
+ int g = qGreen(pixel);
+ int b = qBlue(pixel);
+ int min = QMIN( r, QMIN( g, b ) );
+ int max = QMAX( r, QMAX( g, b ) );
+ r -= min;
+ g -= min;
+ b -= min;
+ if ( max !=min ) {
+ r = (r*255)/(max-min);
+ g = (g*255)/(max-min);
+ b = (b*255)/(max-min);
+ }
+ int a = 255-min;
+ a -= (max-min)/3; //hack more transparency for colors.
+ line[x] = qRgba( r, g, b, a );
+ }
+ }
+#endif
+ *img = img->smoothScale( w/2, h/2 );
+
+ qDebug( "saving out.png");
+ img->save( "out.png", "PNG" );
+
+ w = img->width();
+ h = img->height();
+
+ QImage *img2 = new QImage( w, h, 32 );
+ img2->setAlphaBuffer( TRUE );
+ for ( y = 0; y < h; y++ ) {
+ for ( int x = 0; x < w; x++ ) {
+ QRgb shader = img->pixel( x, y );
+
+ int as = qAlpha(shader)/3;
+
+ int r = (qRed(shader)*(255-as))/255;
+ int g = (qGreen(shader)*(255-as))/255;
+ int b = (qBlue(shader)*(255-as))/255;
+
+ img2->setPixel( x, y, qRgba(r,g,b,as) );
+ }
+ }
+
+ img2->save( "outshade.png", "PNG" );
+
+}
diff --git a/examples/graphicsview/portedcanvas/portedcanvas.pro b/examples/graphicsview/portedcanvas/portedcanvas.pro
new file mode 100644
index 0000000000..7c3946bc0d
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/portedcanvas.pro
@@ -0,0 +1,18 @@
+TEMPLATE = app
+TARGET = portedcanvas
+
+CONFIG += qt warn_on
+
+HEADERS = canvas.h
+SOURCES = canvas.cpp main.cpp
+QT += qt3support
+
+RESOURCES += portedcanvas.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/portedcanvas
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS portedcanvas.pro *.png *.xpm *.doc
+sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/portedcanvas
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/graphicsview/portedcanvas/portedcanvas.qrc b/examples/graphicsview/portedcanvas/portedcanvas.qrc
new file mode 100644
index 0000000000..cf2e02464c
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/portedcanvas.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/trolltech/examples/graphicsview/portedcanvas">
+<file>qt-trans.xpm</file>
+<file>butterfly.png</file>
+<file>qtlogo.png</file>
+</qresource>
+</RCC>
diff --git a/examples/graphicsview/portedcanvas/qt-trans.xpm b/examples/graphicsview/portedcanvas/qt-trans.xpm
new file mode 100644
index 0000000000..225f684fd2
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/qt-trans.xpm
@@ -0,0 +1,54 @@
+/* XPM */
+static char *qtlogo_xpm[] = {
+/* width height ncolors chars_per_pixel */
+"54 34 13 1",
+/* colors */
+" c #000000",
+". c #999999",
+"X c #333366",
+"o c #6666CC",
+"O c #333333",
+"@ c #666699",
+"# c #000066",
+"$ c #666666",
+"% c #3333CC",
+"& c #000033",
+"* c #9999CC",
+"= c #333399",
+"+ c None",
+/* pixels */
+"+++++++++++++++++++.$OOO$.++++++++++++++++++++++++++++",
+"+++++++++++++++++$ O.+++++++++++++++++++++++++",
+"+++++++++++++++.O $++++++++++++++++++++++++",
+"++++++++++++++. $.++.$ O+++++++++++++++++++++++",
+"+++++++++++++. O.+++++++$ O++++++++++++++++++++++",
+"+++++++++++++O ++++++++++$ $+++++++++++++++++++++",
+"++++++++++++$ .+++++++++++O .++++++++++++++++++++",
+"+++++++++++. O+++++++++++++ O++++++.+++++++++++++",
+"+++++++++++$ .+++++++++++++$ .+++.O +++++++++++++",
+"+++++++++++ +++++++++++++++ O+++. +++++++++++++",
+"++++++++++. &Xoooo*++++++++++$ +++. +++++++++++++",
+"++++++++++@=%%%%%%%%%%*+++++++. .++. +++++++++++++",
+"+++++++**oooooo**++*o%%%%o+++++ $++O +++++++++++++",
+"+++++*****$OOX@oooo*++*%%%%%*++O $+. OOO$++++++++*",
+"++..+.++....$O$+*ooooo*+*o%%%%%O O+$ $$O.++++++**+",
+"***+*+++++$$....+++*oooo**+*o%%# O++O ++++++***o*++",
+"*+++++++++O $.....++**oooo**+*X &o*O ++++*ooo*++++",
+"++++++++++$ O++.....++**oooo*X &%%& ..*o%%*++++++",
+"++++++++++$ ++++.....+++**ooO $*o& @oo*+++++++++",
+"++++++++++. .++++++.....+++*O Xo*O .++++++++++++",
+"+++++++++++ O+++++++++...... .++O +++++++++++++",
+"+++++++++++O +++.$$$.++++++. O+++O +++++++++++++",
+"+++++++++++. $$OO O.++++O .+++O +++++++++++++",
+"++++++++++++O .+++.O $++. O++++O +++++++++++++",
+"++++++++++++. O+++++O $+O +++++O +++++++++++++",
+"+++++++++++++. O+++++O O .+++++O .++++++++++++",
+"++++++++++++++$ .++++O .++++.+$ O+.$.++++++++",
+"+++++++++++++++. O$$O .+++++... +++++++++",
+"+++++++++++++++++$ O+++++$$+.O O$.+++++++++",
+"+++++++++++++++++++$OO O$.O O.++. .++++++++++++++++",
+"+++++++++++++++++++++++++++. OO .++++++++++++++++",
+"++++++++++++++++++++++++++++. O+++++++++++++++++",
+"+++++++++++++++++++++++++++++. .+++++++++++++++++",
+"++++++++++++++++++++++++++++++.O O.++++++++++++++++++"
+};
diff --git a/examples/graphicsview/portedcanvas/qtlogo.png b/examples/graphicsview/portedcanvas/qtlogo.png
new file mode 100644
index 0000000000..5aac08abb4
--- /dev/null
+++ b/examples/graphicsview/portedcanvas/qtlogo.png
Binary files differ
diff --git a/examples/help/README b/examples/help/README
new file mode 100644
index 0000000000..85f5a4373d
--- /dev/null
+++ b/examples/help/README
@@ -0,0 +1,38 @@
+Support for interactive help is provided by the Qt Assistant application.
+Developers can take advantages of the facilities it offers to display
+specially-prepared documentation to users of their 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/help/contextsensitivehelp/contextsensitivehelp.pro b/examples/help/contextsensitivehelp/contextsensitivehelp.pro
new file mode 100644
index 0000000000..03a26fa157
--- /dev/null
+++ b/examples/help/contextsensitivehelp/contextsensitivehelp.pro
@@ -0,0 +1,20 @@
+TEMPLATE = app
+
+CONFIG += help
+
+SOURCES += main.cpp \
+ wateringconfigdialog.cpp \
+ helpbrowser.cpp
+
+HEADERS += wateringconfigdialog.h \
+ helpbrowser.h
+
+FORMS += wateringconfigdialog.ui
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/help/contextsensitivehelp
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png *.doc doc
+sources.path = $$[QT_INSTALL_EXAMPLES]/help/contextsensitivehelp
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/help/contextsensitivehelp/doc/amount.html b/examples/help/contextsensitivehelp/doc/amount.html
new file mode 100644
index 0000000000..7a02a6fd51
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/amount.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title>Water amount</title>
+ </head>
+ <body>
+ Depending on the plant, temperature and rain fall the amount needs to be larger
+ or smaller. On a really hot day without rain, the suggested <a href="plants.html">amount</a>
+ can be increased by about 10%.
+ </body>
+</html>
diff --git a/examples/help/contextsensitivehelp/doc/filter.html b/examples/help/contextsensitivehelp/doc/filter.html
new file mode 100644
index 0000000000..64861126d8
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/filter.html
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+<title>Filter</title>
+</head>
+<body>
+Depending on the source of water, it needs to be filtered or not. Filtering
+is strongly recommened for the river and lake.
+
+
+</body>
+</html>
diff --git a/examples/help/contextsensitivehelp/doc/plants.html b/examples/help/contextsensitivehelp/doc/plants.html
new file mode 100644
index 0000000000..2d2bb6788c
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/plants.html
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title>Plants</title>
+ </head>
+ <body>
+ Different kind of plants need different amounts of water. Here's a short
+ overview over the most common grown plants and their avarage need of water:
+ <br>
+ <table border=1>
+ <tr>
+ <td>Kind</td>
+ <td>Amount</td>
+ </tr>
+ <tr>
+ <td>Squash</td>
+ <td>2000</td>
+ </tr>
+ <tr>
+ <td>Bean</td>
+ <td>1500</td>
+ </tr>
+ <tr>
+ <td>Carrot</td>
+ <td>1200</td>
+ </tr>
+ <tr>
+ <td>Strawberry</td>
+ <td>1300</td>
+ </tr>
+ <tr>
+ <td>Raspberry</td>
+ <td>1000</td>
+ </tr>
+ <tr>
+ <td>Blueberry</td>
+ <td>1100</td>
+ </tr>
+ </table>
+ <br><br>
+ <font color="#ff0000">Warning:</font> Watering them too much or too little will
+ cause irreversible damage!
+ </body>
+</html>
diff --git a/examples/help/contextsensitivehelp/doc/rain.html b/examples/help/contextsensitivehelp/doc/rain.html
new file mode 100644
index 0000000000..1ffe45240f
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/rain.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title>Rain</title>
+ </head>
+ <body>
+ Depending on the rain fall, the automated watering system should not be
+ switched on at all. Also, the <a href="./temperature.html">temperature</a> should be
+ considered.
+ </body>
+</html>
diff --git a/examples/help/contextsensitivehelp/doc/source.html b/examples/help/contextsensitivehelp/doc/source.html
new file mode 100644
index 0000000000..2140765064
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/source.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title>Water Source</title>
+ </head>
+ <body>
+ The current pipe system connects to four different sources. Be aware that only
+ a limited amount of water can be taken from some sources.
+ <br>
+ <table border=1>
+ <tr>
+ <td>Source</td>
+ <td>Amount</td>
+ </tr>
+ <tr>
+ <td>Foundain</td>
+ <td>4000</td>
+ </tr>
+ <tr>
+ <td>River</td>
+ <td>6000</td>
+ </tr>
+ <tr>
+ <td>Lake</td>
+ <td>10000</td>
+ </tr>
+ <tr>
+ <td>Public Water System</td>
+ <td>unlimited</td>
+ </tr>
+ </table>
+ </body>
+</html>
diff --git a/examples/help/contextsensitivehelp/doc/temperature.html b/examples/help/contextsensitivehelp/doc/temperature.html
new file mode 100644
index 0000000000..4145ed725d
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/temperature.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title>Temperature</title>
+ </head>
+ <body>
+ Depending on the temperature, the plants need more or less water. The higher
+ the temperature the higher the need for water. If the temperature does not
+ reach a certain level, maybe no automatic watering should be done at all.<br>
+ Before setting this parameter for good, you should also take the amount of <a href="./rain.html">
+ rain</a> into account.
+ </body>
+</html>
diff --git a/examples/help/contextsensitivehelp/doc/time.html b/examples/help/contextsensitivehelp/doc/time.html
new file mode 100644
index 0000000000..0cc81f4d02
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/time.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+<title>Starting time</title>
+</head>
+<body>
+Starting the watering too early may be ineffective since most water
+will evaporate.
+
+</body>
+</html>
diff --git a/examples/help/contextsensitivehelp/doc/wateringmachine.qch b/examples/help/contextsensitivehelp/doc/wateringmachine.qch
new file mode 100644
index 0000000000..e74f9b80a3
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/wateringmachine.qch
Binary files differ
diff --git a/examples/help/contextsensitivehelp/doc/wateringmachine.qhc b/examples/help/contextsensitivehelp/doc/wateringmachine.qhc
new file mode 100644
index 0000000000..3227c3a22f
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/wateringmachine.qhc
Binary files differ
diff --git a/examples/help/contextsensitivehelp/doc/wateringmachine.qhcp b/examples/help/contextsensitivehelp/doc/wateringmachine.qhcp
new file mode 100644
index 0000000000..eebf6520ed
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/wateringmachine.qhcp
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<QHelpCollectionProject version="1.0">
+ <docFiles>
+ <generate>
+ <file>
+ <input>wateringmachine.qhp</input>
+ <output>wateringmachine.qch</output>
+ </file>
+ </generate>
+ <register>
+ <file>wateringmachine.qch</file>
+ </register>
+ </docFiles>
+</QHelpCollectionProject> \ No newline at end of file
diff --git a/examples/help/contextsensitivehelp/doc/wateringmachine.qhp b/examples/help/contextsensitivehelp/doc/wateringmachine.qhp
new file mode 100644
index 0000000000..745d881a5c
--- /dev/null
+++ b/examples/help/contextsensitivehelp/doc/wateringmachine.qhp
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<QtHelpProject version="1.0">
+ <virtualFolder>wateringmachine</virtualFolder>
+ <namespace>wateringcompany.com.1_0_0.premium</namespace>
+ <filterSection>
+ <keywords>
+ <keyword name="plants" id="plants" ref="plants.html"/>
+ <keyword name="temperature" id="temperature" ref="temperature.html"/>
+ <keyword name="rain" id="rain" ref="rain.html"/>
+ <keyword name="time" id="time" ref="time.html"/>
+ <keyword name="amount" id="amount" ref="amount.html"/>
+ <keyword name="source" id="source" ref="source.html"/>
+ <keyword name="filtering" id="filtering" ref="filter.html"/>
+ </keywords>
+ <files>
+ <file>plants.html</file>
+ <file>temperature.html</file>
+ <file>rain.html</file>
+ <file>time.html</file>
+ <file>amount.html</file>
+ <file>source.html</file>
+ <file>filter.html</file>
+ </files>
+ </filterSection>
+</QtHelpProject>
diff --git a/examples/help/contextsensitivehelp/helpbrowser.cpp b/examples/help/contextsensitivehelp/helpbrowser.cpp
new file mode 100644
index 0000000000..100b940793
--- /dev/null
+++ b/examples/help/contextsensitivehelp/helpbrowser.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QLibraryInfo>
+#include <QtGui/QApplication>
+#include <QtHelp/QHelpEngineCore>
+
+#include "helpbrowser.h"
+
+HelpBrowser::HelpBrowser(QWidget *parent)
+ : QTextBrowser(parent)
+{
+ QString collectionFile = QLibraryInfo::location(QLibraryInfo::ExamplesPath)
+ + QLatin1String("/help/contextsensitivehelp/doc/wateringmachine.qhc");
+
+ m_helpEngine = new QHelpEngineCore(collectionFile, this);
+ if (!m_helpEngine->setupData()) {
+ delete m_helpEngine;
+ m_helpEngine = 0;
+ }
+}
+
+void HelpBrowser::showHelpForKeyword(const QString &id)
+{
+ if (m_helpEngine) {
+ QMap<QString, QUrl> links = m_helpEngine->linksForIdentifier(id);
+ if (links.count())
+ setSource(links.constBegin().value());
+ }
+}
+
+QVariant HelpBrowser::loadResource(int type, const QUrl &name)
+{
+ QByteArray ba;
+ if (type < 4 && m_helpEngine) {
+ QUrl url(name);
+ if (name.isRelative())
+ url = source().resolved(url);
+ ba = m_helpEngine->fileData(url);
+ }
+ return ba;
+}
+
diff --git a/examples/help/contextsensitivehelp/helpbrowser.h b/examples/help/contextsensitivehelp/helpbrowser.h
new file mode 100644
index 0000000000..133552441e
--- /dev/null
+++ b/examples/help/contextsensitivehelp/helpbrowser.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HELPBROWSER_H
+#define HELPBROWSER_H
+
+#include <QtGui/QTextBrowser>
+
+QT_BEGIN_NAMESPACE
+class QHelpEngineCore;
+QT_END_NAMESPACE;
+
+class HelpBrowser : public QTextBrowser
+{
+ Q_OBJECT
+
+public:
+ HelpBrowser(QWidget *parent);
+ void showHelpForKeyword(const QString &id);
+
+private:
+ QVariant loadResource(int type, const QUrl &name);
+
+ QHelpEngineCore *m_helpEngine;
+};
+
+#endif
diff --git a/examples/help/contextsensitivehelp/main.cpp b/examples/help/contextsensitivehelp/main.cpp
new file mode 100644
index 0000000000..b05cf3e95e
--- /dev/null
+++ b/examples/help/contextsensitivehelp/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+
+#include "wateringconfigdialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ WateringConfigDialog dia;
+ return dia.exec();
+}
diff --git a/examples/help/contextsensitivehelp/wateringconfigdialog.cpp b/examples/help/contextsensitivehelp/wateringconfigdialog.cpp
new file mode 100644
index 0000000000..285123a217
--- /dev/null
+++ b/examples/help/contextsensitivehelp/wateringconfigdialog.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "wateringconfigdialog.h"
+
+WateringConfigDialog::WateringConfigDialog()
+{
+ m_ui.setupUi(this);
+ m_widgetInfo.insert(m_ui.plantComboBox, tr("plants"));
+ m_widgetInfo.insert(m_ui.temperatureCheckBox, tr("temperature"));
+ m_widgetInfo.insert(m_ui.temperatureSpinBox, tr("temperature"));
+ m_widgetInfo.insert(m_ui.rainCheckBox, tr("rain"));
+ m_widgetInfo.insert(m_ui.rainSpinBox, tr("rain"));
+ m_widgetInfo.insert(m_ui.startTimeEdit, tr("starting time"));
+ m_widgetInfo.insert(m_ui.amountSpinBox, tr("water amount"));
+ m_widgetInfo.insert(m_ui.sourceComboBox, tr("water source"));
+ m_widgetInfo.insert(m_ui.filterCheckBox, tr("water filtering"));
+
+ connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
+ this, SLOT(focusChanged(QWidget*, QWidget*)));
+}
+
+void WateringConfigDialog::focusChanged(QWidget *, QWidget *now)
+{
+ if (m_widgetInfo.contains(now)) {
+ m_ui.helpLabel->setText(tr("Information about %1:").arg(m_widgetInfo.value(now)));
+ QStringList lst = m_widgetInfo.value(now).split(QLatin1Char(' '));
+ m_ui.helpBrowser->showHelpForKeyword(lst.last());
+ }
+}
+
diff --git a/examples/help/contextsensitivehelp/wateringconfigdialog.h b/examples/help/contextsensitivehelp/wateringconfigdialog.h
new file mode 100644
index 0000000000..7fc3c514d4
--- /dev/null
+++ b/examples/help/contextsensitivehelp/wateringconfigdialog.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WATERINGCONFIGDIALOG_H
+#define WATERINGCONFIGDIALOG_H
+
+#include <QtGui/QDialog>
+#include "ui_wateringconfigdialog.h"
+
+class WateringConfigDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ WateringConfigDialog();
+
+private slots:
+ void focusChanged(QWidget *old, QWidget *now);
+
+private:
+ Ui::WateringConfigDialog m_ui;
+ QMap<QWidget*, QString> m_widgetInfo;
+};
+
+#endif
diff --git a/examples/help/contextsensitivehelp/wateringconfigdialog.ui b/examples/help/contextsensitivehelp/wateringconfigdialog.ui
new file mode 100644
index 0000000000..a7f5349d78
--- /dev/null
+++ b/examples/help/contextsensitivehelp/wateringconfigdialog.ui
@@ -0,0 +1,446 @@
+<ui version="4.0" >
+ <class>WateringConfigDialog</class>
+ <widget class="QDialog" name="WateringConfigDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>334</width>
+ <height>550</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Watering Configuration</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <item>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Plant:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="3" >
+ <widget class="QComboBox" name="plantComboBox" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Squash</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Bean</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Carrot</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Strawberry</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Raspberry</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Blueberry</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>67</width>
+ <height>16</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Water when:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="3" >
+ <widget class="QCheckBox" name="temperatureCheckBox" >
+ <property name="text" >
+ <string>Temperature is higher than:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>16</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="4" column="2" >
+ <widget class="QSpinBox" name="temperatureSpinBox" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="specialValueText" >
+ <string/>
+ </property>
+ <property name="suffix" >
+ <string>C</string>
+ </property>
+ <property name="minimum" >
+ <number>10</number>
+ </property>
+ <property name="maximum" >
+ <number>60</number>
+ </property>
+ <property name="value" >
+ <number>20</number>
+ </property>
+ </widget>
+ </item>
+ <item row="4" 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="5" column="1" colspan="3" >
+ <widget class="QCheckBox" name="rainCheckBox" >
+ <property name="text" >
+ <string>Rain less than:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>16</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="6" column="2" >
+ <widget class="QSpinBox" name="rainSpinBox" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="specialValueText" >
+ <string/>
+ </property>
+ <property name="suffix" >
+ <string>mm</string>
+ </property>
+ <property name="minimum" >
+ <number>1</number>
+ </property>
+ </widget>
+ </item>
+ <item row="6" 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="7" column="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="8" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Starting Time:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="1" colspan="3" >
+ <widget class="QTimeEdit" name="startTimeEdit" />
+ </item>
+ <item row="9" column="0" >
+ <widget class="QLabel" name="label_4" >
+ <property name="text" >
+ <string>Amount:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="1" colspan="3" >
+ <widget class="QSpinBox" name="amountSpinBox" >
+ <property name="suffix" >
+ <string>l</string>
+ </property>
+ <property name="minimum" >
+ <number>100</number>
+ </property>
+ <property name="maximum" >
+ <number>10000</number>
+ </property>
+ <property name="singleStep" >
+ <number>100</number>
+ </property>
+ <property name="value" >
+ <number>1000</number>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0" >
+ <widget class="QLabel" name="label_5" >
+ <property name="text" >
+ <string>Source:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="1" colspan="3" >
+ <widget class="QComboBox" name="sourceComboBox" >
+ <item>
+ <property name="text" >
+ <string>Foundain</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>River</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Lake</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Public Water System</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="11" column="0" >
+ <widget class="QLabel" name="label_6" >
+ <property name="text" >
+ <string>Filter:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="1" colspan="2" >
+ <widget class="QCheckBox" name="filterCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="12" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>10</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="4" 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>
+ </layout>
+ </item>
+ <item>
+ <layout class="QGridLayout" >
+ <item row="0" column="1" >
+ <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="0" colspan="2" >
+ <widget class="HelpBrowser" name="helpBrowser" />
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="helpLabel" >
+ <property name="text" >
+ <string>&lt;a href="test">Show Details&lt;/a></string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="Line" name="line" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <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>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>HelpBrowser</class>
+ <extends>QTextBrowser</extends>
+ <header>helpbrowser.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>WateringConfigDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>227</x>
+ <y>372</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>WateringConfigDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>286</x>
+ <y>378</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>temperatureCheckBox</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>temperatureSpinBox</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>132</x>
+ <y>101</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>132</x>
+ <y>125</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>rainCheckBox</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>rainSpinBox</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>110</x>
+ <y>154</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>113</x>
+ <y>169</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/help/help.pro b/examples/help/help.pro
new file mode 100644
index 0000000000..293e511ae8
--- /dev/null
+++ b/examples/help/help.pro
@@ -0,0 +1,13 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+
+SUBDIRS += contextsensitivehelp \
+ remotecontrol \
+ simpletextviewer
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/help
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/help/remotecontrol/enter.png b/examples/help/remotecontrol/enter.png
new file mode 100644
index 0000000000..f397f4b9c4
--- /dev/null
+++ b/examples/help/remotecontrol/enter.png
Binary files differ
diff --git a/examples/help/remotecontrol/main.cpp b/examples/help/remotecontrol/main.cpp
new file mode 100644
index 0000000000..746dec420e
--- /dev/null
+++ b/examples/help/remotecontrol/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include "remotecontrol.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(remotecontrol);
+
+ QApplication a(argc, argv);
+ RemoteControl w;
+ w.show();
+ a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
+ return a.exec();
+}
diff --git a/examples/help/remotecontrol/remotecontrol.cpp b/examples/help/remotecontrol/remotecontrol.cpp
new file mode 100644
index 0000000000..8701afbab3
--- /dev/null
+++ b/examples/help/remotecontrol/remotecontrol.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QDir>
+#include <QtCore/QProcess>
+#include <QtCore/QTextStream>
+#include <QtCore/QLibraryInfo>
+
+#include <QtGui/QMessageBox>
+
+#include "remotecontrol.h"
+
+RemoteControl::RemoteControl(QWidget *parent, Qt::WFlags flags)
+ : QMainWindow(parent, flags)
+{
+ ui.setupUi(this);
+ connect(ui.indexLineEdit, SIGNAL(returnPressed()),
+ this, SLOT(on_indexButton_clicked()));
+ connect(ui.identifierLineEdit, SIGNAL(returnPressed()),
+ this, SLOT(on_identifierButton_clicked()));
+ connect(ui.urlLineEdit, SIGNAL(returnPressed()),
+ this, SLOT(on_urlButton_clicked()));
+
+ QString rc;
+ QTextStream(&rc) << QLatin1String("qthelp://com.trolltech.qt.")
+ << (QT_VERSION >> 16) << ((QT_VERSION >> 8) & 0xFF)
+ << (QT_VERSION & 0xFF)
+ << QLatin1String("/qdoc/index.html");
+
+ ui.startUrlLineEdit->setText(rc);
+
+ process = new QProcess(this);
+ connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
+ this, SLOT(helpViewerClosed()));
+}
+
+RemoteControl::~RemoteControl()
+{
+ if (process->state() == QProcess::Running) {
+ process->terminate();
+ process->waitForFinished(3000);
+ }
+}
+
+void RemoteControl::on_actionQuit_triggered()
+{
+ close();
+}
+
+void RemoteControl::on_launchButton_clicked()
+{
+ if (process->state() == QProcess::Running)
+ return;
+
+ QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
+#if !defined(Q_OS_MAC)
+ app += QLatin1String("assistant");
+#else
+ app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
+#endif
+
+ ui.contentsCheckBox->setChecked(true);
+ ui.indexCheckBox->setChecked(true);
+ ui.bookmarksCheckBox->setChecked(true);
+
+ QStringList args;
+ args << QLatin1String("-enableRemoteControl");
+ process->start(app, args);
+ if (!process->waitForStarted()) {
+ QMessageBox::critical(this, tr("Remote Control"),
+ tr("Could not start Qt Assistant from %1.").arg(app));
+ return;
+ }
+
+ if (!ui.startUrlLineEdit->text().isEmpty())
+ sendCommand(QLatin1String("SetSource ")
+ + ui.startUrlLineEdit->text());
+
+ ui.launchButton->setEnabled(false);
+ ui.startUrlLineEdit->setEnabled(false);
+ ui.actionGroupBox->setEnabled(true);
+}
+
+void RemoteControl::sendCommand(const QString &cmd)
+{
+ if (process->state() != QProcess::Running)
+ return;
+ process->write(cmd.toLocal8Bit() + '\0');
+}
+
+void RemoteControl::on_indexButton_clicked()
+{
+ sendCommand(QLatin1String("ActivateKeyword ")
+ + ui.indexLineEdit->text());
+}
+
+void RemoteControl::on_identifierButton_clicked()
+{
+ sendCommand(QLatin1String("ActivateIdentifier ")
+ + ui.identifierLineEdit->text());
+}
+
+void RemoteControl::on_urlButton_clicked()
+{
+ sendCommand(QLatin1String("SetSource ")
+ + ui.urlLineEdit->text());
+}
+
+void RemoteControl::on_syncContentsButton_clicked()
+{
+ sendCommand(QLatin1String("SyncContents"));
+}
+
+void RemoteControl::on_contentsCheckBox_toggled(bool checked)
+{
+ sendCommand(checked ?
+ QLatin1String("Show Contents") : QLatin1String("Hide Contents"));
+}
+
+void RemoteControl::on_indexCheckBox_toggled(bool checked)
+{
+ sendCommand(checked ?
+ QLatin1String("Show Index") : QLatin1String("Hide Index"));
+}
+
+void RemoteControl::on_bookmarksCheckBox_toggled(bool checked)
+{
+ sendCommand(checked ?
+ QLatin1String("Show Bookmarks") : QLatin1String("Hide Bookmarks"));
+}
+
+void RemoteControl::helpViewerClosed()
+{
+ ui.launchButton->setEnabled(true);
+ ui.startUrlLineEdit->setEnabled(true);
+ ui.actionGroupBox->setEnabled(false);
+}
diff --git a/examples/help/remotecontrol/remotecontrol.h b/examples/help/remotecontrol/remotecontrol.h
new file mode 100644
index 0000000000..cc1c1c8570
--- /dev/null
+++ b/examples/help/remotecontrol/remotecontrol.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef REMOTECONTROL_H
+#define REMOTECONTROL_H
+
+#include <QtGui/QMainWindow>
+#include "ui_remotecontrol.h"
+
+QT_BEGIN_NAMESPACE
+class QProcess;
+QT_END_NAMESPACE;
+
+class RemoteControl : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ RemoteControl(QWidget *parent = 0, Qt::WFlags flags = 0);
+ ~RemoteControl();
+
+private:
+ Ui::RemoteControlClass ui;
+ QProcess *process;
+
+private slots:
+ void on_launchButton_clicked();
+ void on_actionQuit_triggered();
+ void on_indexButton_clicked();
+ void on_identifierButton_clicked();
+ void on_urlButton_clicked();
+ void on_syncContentsButton_clicked();
+ void on_contentsCheckBox_toggled(bool checked);
+ void on_indexCheckBox_toggled(bool checked);
+ void on_bookmarksCheckBox_toggled(bool checked);
+ void helpViewerClosed();
+
+ void sendCommand(const QString &cmd);
+};
+
+#endif // REMOTECONTROL_H
diff --git a/examples/help/remotecontrol/remotecontrol.pro b/examples/help/remotecontrol/remotecontrol.pro
new file mode 100644
index 0000000000..e97af6d5e8
--- /dev/null
+++ b/examples/help/remotecontrol/remotecontrol.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+
+HEADERS += remotecontrol.h
+SOURCES += main.cpp \
+ remotecontrol.cpp
+FORMS += remotecontrol.ui
+RESOURCES += remotecontrol.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/help/remotecontrol
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png *.doc doc
+sources.path = $$[QT_INSTALL_EXAMPLES]/help/remotecontrol
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/help/remotecontrol/remotecontrol.qrc b/examples/help/remotecontrol/remotecontrol.qrc
new file mode 100644
index 0000000000..9b4299d217
--- /dev/null
+++ b/examples/help/remotecontrol/remotecontrol.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/remotecontrol" >
+ <file>enter.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/help/remotecontrol/remotecontrol.ui b/examples/help/remotecontrol/remotecontrol.ui
new file mode 100644
index 0000000000..1cfc7f5400
--- /dev/null
+++ b/examples/help/remotecontrol/remotecontrol.ui
@@ -0,0 +1,228 @@
+<ui version="4.0" >
+ <class>RemoteControlClass</class>
+ <widget class="QMainWindow" name="RemoteControlClass" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>344</width>
+ <height>364</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>RemoteControl</string>
+ </property>
+ <widget class="QWidget" name="centralWidget" >
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Start URL:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="2" >
+ <widget class="QLineEdit" name="startUrlLineEdit" />
+ </item>
+ <item row="1" column="1" >
+ <widget class="QPushButton" name="launchButton" >
+ <property name="text" >
+ <string>Launch Qt HelpViewer</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>101</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="1" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>113</width>
+ <height>16</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="3" column="0" colspan="3" >
+ <widget class="QGroupBox" name="actionGroupBox" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="title" >
+ <string>Actions</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Search in Index:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="2" >
+ <layout class="QHBoxLayout" >
+ <property name="spacing" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLineEdit" name="indexLineEdit" />
+ </item>
+ <item>
+ <widget class="QToolButton" name="indexButton" >
+ <property name="text" >
+ <string/>
+ </property>
+ <property name="icon" >
+ <iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_4" >
+ <property name="text" >
+ <string>Identifier:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="2" >
+ <layout class="QHBoxLayout" >
+ <property name="spacing" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLineEdit" name="identifierLineEdit" />
+ </item>
+ <item>
+ <widget class="QToolButton" name="identifierButton" >
+ <property name="text" >
+ <string/>
+ </property>
+ <property name="icon" >
+ <iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Show URL:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" colspan="2" >
+ <layout class="QHBoxLayout" >
+ <property name="spacing" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLineEdit" name="urlLineEdit" />
+ </item>
+ <item>
+ <widget class="QToolButton" name="urlButton" >
+ <property name="text" >
+ <string/>
+ </property>
+ <property name="icon" >
+ <iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QPushButton" name="syncContentsButton" >
+ <property name="text" >
+ <string>Sync Contents</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>81</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="4" column="0" colspan="3" >
+ <widget class="QCheckBox" name="contentsCheckBox" >
+ <property name="text" >
+ <string>Show Contents</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QCheckBox" name="indexCheckBox" >
+ <property name="text" >
+ <string>Show Index</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" colspan="3" >
+ <widget class="QCheckBox" name="bookmarksCheckBox" >
+ <property name="text" >
+ <string>Show Bookmarks</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>344</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile" >
+ <property name="title" >
+ <string>File</string>
+ </property>
+ <addaction name="actionQuit" />
+ </widget>
+ <addaction name="menuFile" />
+ </widget>
+ <widget class="QStatusBar" name="statusBar" />
+ <action name="actionQuit" >
+ <property name="text" >
+ <string>Quit</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11" />
+ <resources>
+ <include location="remotecontrol.qrc" />
+ </resources>
+ <connections/>
+</ui>
diff --git a/examples/help/simpletextviewer/assistant.cpp b/examples/help/simpletextviewer/assistant.cpp
new file mode 100644
index 0000000000..b6fb88aac9
--- /dev/null
+++ b/examples/help/simpletextviewer/assistant.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QByteArray>
+#include <QtCore/QDir>
+#include <QtCore/QLibraryInfo>
+#include <QtCore/QProcess>
+
+#include <QtGui/QMessageBox>
+
+#include "assistant.h"
+
+Assistant::Assistant()
+ : proc(0)
+{
+}
+
+//! [0]
+Assistant::~Assistant()
+{
+ if (proc && proc->state() == QProcess::Running) {
+ proc->terminate();
+ proc->waitForFinished(3000);
+ }
+ delete proc;
+}
+//! [0]
+
+//! [1]
+void Assistant::showDocumentation(const QString &page)
+{
+ if (!startAssistant())
+ return;
+
+ QByteArray ba("SetSource ");
+ ba.append("qthelp://com.trolltech.examples.simpletextviewer/doc/");
+
+ proc->write(ba + page.toLocal8Bit() + '\0');
+}
+//! [1]
+
+//! [2]
+bool Assistant::startAssistant()
+{
+ if (!proc)
+ proc = new QProcess();
+
+ if (proc->state() != QProcess::Running) {
+ QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
+#if !defined(Q_OS_MAC)
+ app += QLatin1String("assistant");
+#else
+ app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
+#endif
+
+ QStringList args;
+ args << QLatin1String("-collectionFile")
+ << QLibraryInfo::location(QLibraryInfo::ExamplesPath)
+ + QLatin1String("/help/simpletextviewer/documentation/simpletextviewer.qhc")
+ << QLatin1String("-enableRemoteControl");
+
+ proc->start(app, args);
+
+ if (!proc->waitForStarted()) {
+ QMessageBox::critical(0, QObject::tr("Simple Text Viewer"),
+ QObject::tr("Unable to launch Qt Assistant (%1)").arg(app));
+ return false;
+ }
+ }
+ return true;
+}
+//! [2]
diff --git a/examples/help/simpletextviewer/assistant.h b/examples/help/simpletextviewer/assistant.h
new file mode 100644
index 0000000000..e58939c82d
--- /dev/null
+++ b/examples/help/simpletextviewer/assistant.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ASSISTANT_H
+#define ASSISTANT_H
+
+#include <QtCore/QString>
+
+QT_BEGIN_NAMESPACE
+class QProcess;
+QT_END_NAMESPACE
+
+class Assistant
+{
+public:
+ Assistant();
+ ~Assistant();
+ void showDocumentation(const QString &file);
+
+private:
+ bool startAssistant();
+ QProcess *proc;
+};
+
+#endif
diff --git a/examples/help/simpletextviewer/documentation/about.txt b/examples/help/simpletextviewer/documentation/about.txt
new file mode 100644
index 0000000000..eeab35f4a6
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/about.txt
@@ -0,0 +1,9 @@
+The Simple Text Viewer enables the user to select and view existing
+files.
+
+HTML files is displayed using rich text, while other files are
+presented as plain text. The application provides a file dialog
+allowing the user to search for files using wildcard matching. The
+search is performed within in the specified directory, and the user is
+given an option to browse the existing file system to find the
+relevant directory.
diff --git a/examples/help/simpletextviewer/documentation/browse.html b/examples/help/simpletextviewer/documentation/browse.html
new file mode 100644
index 0000000000..987abf31f6
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/browse.html
@@ -0,0 +1,34 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Browse</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Browse</h2></center></p>
+
+ <p>
+ The file dialog let you browse the current file system to
+ specify the directory in which the file you want to open
+ resides.
+ Note that only the specified directory will be searched, any
+ subdirectories will simply be ignored.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/browse.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="filedialog.html">File Dialog</a>, <a href="wildcardmatching.html">Wildcard Matching</a>,
+ <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
+
diff --git a/examples/help/simpletextviewer/documentation/filedialog.html b/examples/help/simpletextviewer/documentation/filedialog.html
new file mode 100644
index 0000000000..afa65ed577
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/filedialog.html
@@ -0,0 +1,48 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>File Dialog</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>File Dialog</h2></center></p>
+
+ <p>
+ In the file dialog you can name a particular file name, or
+ search for files using wildcard matching, i.e. specify a
+ file name containing wildcards. In addition you must specify
+ the directory in which the file you search for resides.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/filedialog.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ By default the dialog will search for all files (*) in the
+ current directory (the directory the application is run from).
+ </p>
+
+ <p>
+ When editing the file name and directory parameters, an
+ overview of the matching files are displayed in the
+ dialog. The overview is updated whenever the parameters
+ change.
+ </p>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="browse.html">Browse</a>, <a href="wildcardmatching.html">Wildcard Matching</a>,
+ <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
+
+
diff --git a/examples/help/simpletextviewer/documentation/findfile.html b/examples/help/simpletextviewer/documentation/findfile.html
new file mode 100644
index 0000000000..32e0147181
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/findfile.html
@@ -0,0 +1,32 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Find File</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Find File</h2></center></p>
+
+ <p>
+ To open and view a file in the Simple Text Viewer, select the
+ 'Open...' option in the 'File' menu. The application will then
+ provide you with a file dialog that you can use to search for
+ any existing file.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/fadedfilemenu.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="openfile.html">Open File</a>, <a href="filedialog.html">File Dialog</a>
+ </p>
+ </body>
+</html>
+
diff --git a/examples/help/simpletextviewer/documentation/images/browse.png b/examples/help/simpletextviewer/documentation/images/browse.png
new file mode 100644
index 0000000000..86db6b19eb
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/browse.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/images/fadedfilemenu.png b/examples/help/simpletextviewer/documentation/images/fadedfilemenu.png
new file mode 100644
index 0000000000..fde0e43f67
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/fadedfilemenu.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/images/filedialog.png b/examples/help/simpletextviewer/documentation/images/filedialog.png
new file mode 100644
index 0000000000..883a33a269
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/filedialog.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/images/handbook.png b/examples/help/simpletextviewer/documentation/images/handbook.png
new file mode 100644
index 0000000000..3bd2b928b0
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/handbook.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/images/icon.png b/examples/help/simpletextviewer/documentation/images/icon.png
new file mode 100644
index 0000000000..6daec0ade2
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/icon.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/images/mainwindow.png b/examples/help/simpletextviewer/documentation/images/mainwindow.png
new file mode 100644
index 0000000000..c28d5e9ffe
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/mainwindow.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/images/open.png b/examples/help/simpletextviewer/documentation/images/open.png
new file mode 100644
index 0000000000..1e5bba3c8c
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/open.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/images/wildcard.png b/examples/help/simpletextviewer/documentation/images/wildcard.png
new file mode 100644
index 0000000000..6e83a56cc4
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/images/wildcard.png
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/index.html b/examples/help/simpletextviewer/documentation/index.html
new file mode 100644
index 0000000000..5a7b1d5fac
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/index.html
@@ -0,0 +1,41 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Manual</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Simple Text Viewer</h2></center></p>
+
+ <p>
+ The Simple Text Viewer enables the user to select and view
+ existing files.
+ </p>
+
+ <p><center>
+ <img src="images/mainwindow.png" />
+ </center></p>
+
+ <p>
+ HTML files is displayed using rich text, while
+ other files are presented as plain text. The application
+ provides a file dialog allowing the user to search for files
+ using wildcard matching. The search is performed within in the
+ specified directory, and the user is given an option to browse
+ the existing file system to find the relevant directory.
+ </p>
+
+ <ul>
+ <li><a href="findfile.html">Find File</a></li>
+ <ul>
+ <li><a href="filedialog.html">File Dialog</a></li>
+ <li><a href="wildcardmatching.html">WildCard Matching</a></li>
+ <li><a href="browse.html">Browse</a></li>
+ </ul>
+ <li><a href="openfile.html">Open File</a></li>
+ </ul>
+ </body>
+</html>
+
+
+
diff --git a/examples/help/simpletextviewer/documentation/intro.html b/examples/help/simpletextviewer/documentation/intro.html
new file mode 100644
index 0000000000..2e2aa40de7
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/intro.html
@@ -0,0 +1,28 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Manual</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Simple Text Viewer</h2></center></p>
+
+ <p>
+ The Simple Text Viewer enables the user to select and view
+ existing files.
+ </p>
+
+ <p><center>
+ <img src="images/mainwindow.png" />
+ </center></p>
+
+ <p>
+ The application provides its own custom documentation that is
+ available through the <b>Help</b> menu in the main window's menubar
+ and through the <b>Help</b> button in the application's find file
+ dialog.
+ </p>
+
+ </body>
+</html>
+
diff --git a/examples/help/simpletextviewer/documentation/openfile.html b/examples/help/simpletextviewer/documentation/openfile.html
new file mode 100644
index 0000000000..e172de95ea
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/openfile.html
@@ -0,0 +1,36 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Open File</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Open File</h2></center></p>
+
+ <p>
+ Once the file you want to view appears in the dialog's
+ display, you can open it in two different ways.
+ </p>
+
+ <p>
+ By pressing the 'Open' button the currently selected file will
+ be opened. By default, the first file in the list of matching
+ files is selected. Another way of opening a file is to simply
+ double click the displayed file name.
+ </p>
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/open.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
diff --git a/examples/help/simpletextviewer/documentation/simpletextviewer.qch b/examples/help/simpletextviewer/documentation/simpletextviewer.qch
new file mode 100644
index 0000000000..c40132803e
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/simpletextviewer.qch
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/simpletextviewer.qhc b/examples/help/simpletextviewer/documentation/simpletextviewer.qhc
new file mode 100644
index 0000000000..db380cabfd
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/simpletextviewer.qhc
Binary files differ
diff --git a/examples/help/simpletextviewer/documentation/simpletextviewer.qhcp b/examples/help/simpletextviewer/documentation/simpletextviewer.qhcp
new file mode 100644
index 0000000000..e7c23210ba
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/simpletextviewer.qhcp
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<QHelpCollectionProject version="1.0">
+ <assistant>
+ <title>Simple Text Viewer</title>
+ <applicationIcon>images/handbook.png</applicationIcon>
+ <cacheDirectory>Trolltech/SimpleTextViewer</cacheDirectory>
+ <startPage>qthelp://com.trolltech.examples.simpletextviewer/doc/index.html</startPage>
+ <aboutMenuText>
+ <text>About Simple Text Viewer</text>
+ </aboutMenuText>
+ <aboutDialog>
+ <file>about.txt</file>
+ <icon>images/icon.png</icon>
+ </aboutDialog>
+ <enableDocumentationManager>false</enableDocumentationManager>
+ <enableAddressBar>false</enableAddressBar>
+ <enableFilterFunctionality>false</enableFilterFunctionality>
+ </assistant>
+ <docFiles>
+ <generate>
+ <file>
+ <input>simpletextviewer.qhp</input>
+ <output>simpletextviewer.qch</output>
+ </file>
+ </generate>
+ <register>
+ <file>simpletextviewer.qch</file>
+ </register>
+ </docFiles>
+ </QHelpCollectionProject>
diff --git a/examples/help/simpletextviewer/documentation/simpletextviewer.qhp b/examples/help/simpletextviewer/documentation/simpletextviewer.qhp
new file mode 100644
index 0000000000..4cb83a5f32
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/simpletextviewer.qhp
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<QtHelpProject version="1.0">
+ <namespace>com.trolltech.examples.simpletextviewer</namespace>
+ <virtualFolder>doc</virtualFolder>
+ <filterSection>
+ <toc>
+ <section title="Simple Text Viewer" ref="index.html">
+ <section title="Find File" ref="./findfile.html">
+ <section title="File Dialog" ref="./filedialog.html"></section>
+ <section title="Wildcard Matching" ref="./wildcardmatching.html"></section>
+ <section title="Browse" ref="./browse.html"></section>
+ </section>
+ <section title="Open File" ref="./openfile.html"></section>
+ </section>
+ </toc>
+ <keywords>
+ <keyword name="Display" ref="./index.html"/>
+ <keyword name="Rich text" ref="./index.html"/>
+ <keyword name="Plain text" ref="./index.html"/>
+ <keyword name="Find" ref="./findfile.html"/>
+ <keyword name="File menu" ref="./findfile.html"/>
+ <keyword name="File name" ref="./filedialog.html"/>
+ <keyword name="File dialog" ref="./filedialog.html"/>
+ <keyword name="File globbing" ref="./wildcardmatching.html"/>
+ <keyword name="Wildcard matching" ref="./wildcardmatching.html"/>
+ <keyword name="Wildcard syntax" ref="./wildcardmatching.html"/>
+ <keyword name="Browse" ref="./browse.html"/>
+ <keyword name="Directory" ref="./browse.html"/>
+ <keyword name="Open" ref="./openfile.html"/>
+ <keyword name="Select" ref="./openfile.html"/>
+ </keywords>
+ <files>
+ <file>browse.html</file>
+ <file>filedialog.html</file>
+ <file>findfile.html</file>
+ <file>index.html</file>
+ <file>intro.html</file>
+ <file>openfile.html</file>
+ <file>wildcardmatching.html</file>
+ <file>images/browse.png</file>
+ <file>images/fadedfilemenu.png</file>
+ <file>images/filedialog.png</file>
+ <file>images/handbook.png</file>
+ <file>images/mainwindow.png</file>
+ <file>images/open.png</file>
+ <file>images/wildcard.png</file>
+ </files>
+ </filterSection>
+ </QtHelpProject>
diff --git a/examples/help/simpletextviewer/documentation/wildcardmatching.html b/examples/help/simpletextviewer/documentation/wildcardmatching.html
new file mode 100644
index 0000000000..eb1839a068
--- /dev/null
+++ b/examples/help/simpletextviewer/documentation/wildcardmatching.html
@@ -0,0 +1,57 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Wildcard Matching</title>
+ </head>
+ <body style="font-size:12pt;font-family:helvetica">
+
+ <p><center><h2>Wildcard Matching</h2></center></p>
+
+ <p>
+ Most command shells such as bash or cmd.exe support "file
+ globbing", the ability to identify a group of files by using
+ wildcards.
+
+ <br />
+ <br />
+ <table align="center" cellpadding="2" cellspacing="1" border="0" width="100%">
+ <tr valign="top" bgcolor="#f0f0f0">
+ <td><center><img src="images/wildcard.png" /></center></td>
+ </tr>
+ </table>
+
+ <br />
+ <br />
+ <p>
+ Wildcard matching provides four features:
+ </p>
+
+ <ul>
+ <li>Any character represents itself apart from those
+ mentioned below. Thus 'c' matches the character 'c'.
+ </li>
+ <li>The '?' character matches any single character.</li>
+ <li>The '*' matches zero or more of any characters.</li>
+ <li>Sets of characters can be represented in square brackets.
+ Within the character class, like outside, backslash
+ has no special meaning.
+ </li>
+ </ul>
+
+ <p>
+ For example we could identify HTML files with
+ <code>*.html</code>. This will match zero or more characters
+ followed by a dot followed by 'h', 't', 'm' and 'l'.
+ </p>
+
+ <br />
+ <br />
+ <p>
+ See also: <a href="browse.html">Browse</a>, <a href="filedialog.html">File Dialog</a>,
+ <a href="findfile.html">Find File</a>
+ </p>
+ </body>
+</html>
+
+
+
diff --git a/examples/help/simpletextviewer/findfiledialog.cpp b/examples/help/simpletextviewer/findfiledialog.cpp
new file mode 100644
index 0000000000..51d78cef7b
--- /dev/null
+++ b/examples/help/simpletextviewer/findfiledialog.cpp
@@ -0,0 +1,222 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QDir>
+#include <QtGui/QLayout>
+#include <QtGui/QComboBox>
+#include <QtGui/QTreeWidget>
+#include <QtGui/QLayout>
+#include <QtGui/QFileDialog>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QToolButton>
+#include <QtGui/QPushButton>
+#include <QtGui/QLabel>
+
+#include "findfiledialog.h"
+#include "assistant.h"
+#include "textedit.h"
+
+//! [0]
+FindFileDialog::FindFileDialog(TextEdit *editor, Assistant *assistant)
+ : QDialog(editor)
+{
+ currentAssistant = assistant;
+ currentEditor = editor;
+//! [0]
+
+ createButtons();
+ createComboBoxes();
+ createFilesTree();
+ createLabels();
+ createLayout();
+
+ directoryComboBox->addItem(QDir::toNativeSeparators(QDir::currentPath()));
+ fileNameComboBox->addItem("*");
+ findFiles();
+
+ setWindowTitle(tr("Find File"));
+//! [1]
+}
+//! [1]
+
+void FindFileDialog::browse()
+{
+ QString currentDirectory = directoryComboBox->currentText();
+ QString newDirectory = QFileDialog::getExistingDirectory(this,
+ tr("Select Directory"), currentDirectory);
+ if (!newDirectory.isEmpty()) {
+ directoryComboBox->addItem(QDir::toNativeSeparators(newDirectory));
+ directoryComboBox->setCurrentIndex(directoryComboBox->count() - 1);
+ update();
+ }
+}
+
+//! [2]
+void FindFileDialog::help()
+{
+ currentAssistant->showDocumentation("filedialog.html");
+}
+//! [2]
+
+void FindFileDialog::openFile(QTreeWidgetItem *item)
+{
+ if (!item) {
+ item = foundFilesTree->currentItem();
+ if (!item)
+ return;
+ }
+
+ QString fileName = item->text(0);
+ QString path = directoryComboBox->currentText() + QDir::separator();
+
+ currentEditor->setContents(path + fileName);
+ close();
+}
+
+void FindFileDialog::update()
+{
+ findFiles();
+ buttonBox->button(QDialogButtonBox::Open)->setEnabled(
+ foundFilesTree->topLevelItemCount() > 0);
+}
+
+void FindFileDialog::findFiles()
+{
+ QRegExp filePattern(fileNameComboBox->currentText() + "*");
+ filePattern.setPatternSyntax(QRegExp::Wildcard);
+
+ QDir directory(directoryComboBox->currentText());
+
+ QStringList allFiles = directory.entryList(QDir::Files | QDir::NoSymLinks);
+ QStringList matchingFiles;
+
+ foreach (QString file, allFiles) {
+ if (filePattern.exactMatch(file))
+ matchingFiles << file;
+ }
+ showFiles(matchingFiles);
+}
+
+void FindFileDialog::showFiles(const QStringList &files)
+{
+ foundFilesTree->clear();
+
+ for (int i = 0; i < files.count(); ++i) {
+ QTreeWidgetItem *item = new QTreeWidgetItem(foundFilesTree);
+ item->setText(0, files[i]);
+ }
+
+ if (files.count() > 0)
+ foundFilesTree->setCurrentItem(foundFilesTree->topLevelItem(0));
+}
+
+void FindFileDialog::createButtons()
+{
+ browseButton = new QToolButton;
+ browseButton->setText(tr("..."));
+ connect(browseButton, SIGNAL(clicked()), this, SLOT(browse()));
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Open
+ | QDialogButtonBox::Cancel
+ | QDialogButtonBox::Help);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(openFile()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(help()));
+}
+
+void FindFileDialog::createComboBoxes()
+{
+ directoryComboBox = new QComboBox;
+ fileNameComboBox = new QComboBox;
+
+ fileNameComboBox->setEditable(true);
+ fileNameComboBox->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Preferred);
+
+ directoryComboBox->setMinimumContentsLength(30);
+ directoryComboBox->setSizeAdjustPolicy(
+ QComboBox::AdjustToMinimumContentsLength);
+ directoryComboBox->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Preferred);
+
+ connect(fileNameComboBox, SIGNAL(editTextChanged(const QString &)),
+ this, SLOT(update()));
+ connect(directoryComboBox, SIGNAL(currentIndexChanged(const QString &)),
+ this, SLOT(update()));
+}
+
+void FindFileDialog::createFilesTree()
+{
+ foundFilesTree = new QTreeWidget;
+ foundFilesTree->setColumnCount(1);
+ foundFilesTree->setHeaderLabels(QStringList(tr("Matching Files")));
+ foundFilesTree->setRootIsDecorated(false);
+ foundFilesTree->setSelectionMode(QAbstractItemView::SingleSelection);
+
+ connect(foundFilesTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
+ this, SLOT(openFile(QTreeWidgetItem *)));
+}
+
+void FindFileDialog::createLabels()
+{
+ directoryLabel = new QLabel(tr("Search in:"));
+ fileNameLabel = new QLabel(tr("File name (including wildcards):"));
+}
+
+void FindFileDialog::createLayout()
+{
+ QHBoxLayout *fileLayout = new QHBoxLayout;
+ fileLayout->addWidget(fileNameLabel);
+ fileLayout->addWidget(fileNameComboBox);
+
+ QHBoxLayout *directoryLayout = new QHBoxLayout;
+ directoryLayout->addWidget(directoryLabel);
+ directoryLayout->addWidget(directoryComboBox);
+ directoryLayout->addWidget(browseButton);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(fileLayout);
+ mainLayout->addLayout(directoryLayout);
+ mainLayout->addWidget(foundFilesTree);
+ mainLayout->addStretch();
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+}
diff --git a/examples/help/simpletextviewer/findfiledialog.h b/examples/help/simpletextviewer/findfiledialog.h
new file mode 100644
index 0000000000..97af229274
--- /dev/null
+++ b/examples/help/simpletextviewer/findfiledialog.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDFILEDIALOG_H
+#define FINDFILEDIALOG_H
+
+#include <QtGui/QDialog>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QLabel;
+class QToolButton;
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+class Assistant;
+class TextEdit;
+
+//! [0]
+class FindFileDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindFileDialog(TextEdit *editor, Assistant *assistant);
+
+private slots:
+ void browse();
+ void help();
+ void openFile(QTreeWidgetItem *item = 0);
+ void update();
+
+private:
+ void findFiles();
+ void showFiles(const QStringList &files);
+
+ void createButtons();
+ void createComboBoxes();
+ void createFilesTree();
+ void createLabels();
+ void createLayout();
+
+ Assistant *currentAssistant;
+ TextEdit *currentEditor;
+ QTreeWidget *foundFilesTree;
+
+ QComboBox *directoryComboBox;
+ QComboBox *fileNameComboBox;
+
+ QLabel *directoryLabel;
+ QLabel *fileNameLabel;
+
+ QDialogButtonBox *buttonBox;
+
+ QToolButton *browseButton;
+};
+//! [0]
+
+#endif
diff --git a/examples/help/simpletextviewer/main.cpp b/examples/help/simpletextviewer/main.cpp
new file mode 100644
index 0000000000..ce4ee608b2
--- /dev/null
+++ b/examples/help/simpletextviewer/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/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/help/simpletextviewer/mainwindow.cpp b/examples/help/simpletextviewer/mainwindow.cpp
new file mode 100644
index 0000000000..fc9af58658
--- /dev/null
+++ b/examples/help/simpletextviewer/mainwindow.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QLibraryInfo>
+#include <QtGui/QApplication>
+#include <QtGui/QAction>
+#include <QtGui/QMenu>
+#include <QtGui/QMenuBar>
+#include <QtGui/QMessageBox>
+
+#include "mainwindow.h"
+#include "findfiledialog.h"
+#include "assistant.h"
+#include "textedit.h"
+
+// ![0]
+MainWindow::MainWindow()
+{
+ assistant = new Assistant;
+// ![0]
+ textViewer = new TextEdit;
+ textViewer->setContents(QLibraryInfo::location(QLibraryInfo::ExamplesPath)
+ + QLatin1String("/help/simpletextviewer/documentation/intro.html"));
+ setCentralWidget(textViewer);
+
+ createActions();
+ createMenus();
+
+ setWindowTitle(tr("Simple Text Viewer"));
+ resize(750, 400);
+// ![1]
+}
+//! [1]
+
+//! [2]
+void MainWindow::closeEvent(QCloseEvent *)
+{
+ delete assistant;
+}
+//! [2]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Simple Text Viewer"),
+ tr("This example demonstrates how to use\n"
+ "Qt Assistant as help system for your\n"
+ "own application."));
+}
+
+//! [3]
+void MainWindow::showDocumentation()
+{
+ assistant->showDocumentation("index.html");
+}
+//! [3]
+
+void MainWindow::open()
+{
+ FindFileDialog dialog(textViewer, assistant);
+ dialog.exec();
+}
+
+//! [4]
+void MainWindow::createActions()
+{
+ assistantAct = new QAction(tr("Help Contents"), this);
+ assistantAct->setShortcut(tr("F1"));
+ connect(assistantAct, SIGNAL(triggered()), this, SLOT(showDocumentation()));
+//! [4]
+
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ clearAct = new QAction(tr("&Clear"), this);
+ clearAct->setShortcut(tr("Ctrl+C"));
+ connect(clearAct, SIGNAL(triggered()), textViewer, SLOT(clear()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ 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()));
+//! [5]
+}
+//! [5]
+
+void MainWindow::createMenus()
+{
+ fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(clearAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(assistantAct);
+ helpMenu->addSeparator();
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(helpMenu);
+}
diff --git a/examples/help/simpletextviewer/mainwindow.h b/examples/help/simpletextviewer/mainwindow.h
new file mode 100644
index 0000000000..46d3b82e4d
--- /dev/null
+++ b/examples/help/simpletextviewer/mainwindow.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+
+class Assistant;
+class TextEdit;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+ void showDocumentation(const QString &file);
+
+private slots:
+ void about();
+ void showDocumentation();
+ void open();
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private:
+ void createActions();
+ void createMenus();
+
+ Assistant *assistant;
+ TextEdit *textViewer;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+
+ QAction *assistantAct;
+ QAction *clearAct;
+ QAction *openAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/help/simpletextviewer/simpletextviewer.pro b/examples/help/simpletextviewer/simpletextviewer.pro
new file mode 100644
index 0000000000..a8504e13a6
--- /dev/null
+++ b/examples/help/simpletextviewer/simpletextviewer.pro
@@ -0,0 +1,18 @@
+HEADERS = mainwindow.h \
+ findfiledialog.h \
+ assistant.h \
+ textedit.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ findfiledialog.cpp \
+ assistant.cpp \
+ textedit.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/help/simpletextviewer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES documentation *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/help/simpletextviewer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
diff --git a/examples/help/simpletextviewer/textedit.cpp b/examples/help/simpletextviewer/textedit.cpp
new file mode 100644
index 0000000000..5c0fd1bd6f
--- /dev/null
+++ b/examples/help/simpletextviewer/textedit.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QFileInfo>
+#include <QtCore/QFile>
+
+#include "textedit.h"
+
+TextEdit::TextEdit(QWidget *parent)
+ : QTextEdit(parent)
+{
+ setReadOnly(true);
+}
+
+void TextEdit::setContents(const QString &fileName)
+{
+ QFileInfo fi(fileName);
+ srcUrl = QUrl::fromLocalFile(fi.absoluteFilePath());
+ QFile file(fileName);
+ if (file.open(QIODevice::ReadOnly)) {
+ QString data(file.readAll());
+ if (fileName.endsWith(".html"))
+ setHtml(data);
+ else
+ setPlainText(data);
+ }
+}
+
+QVariant TextEdit::loadResource(int type, const QUrl &name)
+{
+ if (type == QTextDocument::ImageResource) {
+ QFile file(srcUrl.resolved(name).toLocalFile());
+ if (file.open(QIODevice::ReadOnly))
+ return file.readAll();
+ }
+ return QTextEdit::loadResource(type, name);
+}
diff --git a/examples/help/simpletextviewer/textedit.h b/examples/help/simpletextviewer/textedit.h
new file mode 100644
index 0000000000..58b64068ec
--- /dev/null
+++ b/examples/help/simpletextviewer/textedit.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTEDIT_H
+#define TEXTEDIT_H
+
+#include <QtCore/QUrl>
+#include <QtGui/QTextEdit>
+
+class TextEdit : public QTextEdit
+{
+ Q_OBJECT
+
+public:
+ TextEdit(QWidget *parent = 0);
+ void setContents(const QString &fileName);
+
+private:
+ QVariant loadResource(int type, const QUrl &name);
+ QUrl srcUrl;
+};
+
+#endif
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..b758fc48dd
--- /dev/null
+++ b/examples/ipc/ipc.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = sharedmemory
+!wince*: SUBDIRS += localfortuneserver localfortuneclient
+
+# install
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS ipc.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/ipc
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/ipc/localfortuneclient/client.cpp b/examples/ipc/localfortuneclient/client.cpp
new file mode 100644
index 0000000000..2edbcc3fd3
--- /dev/null
+++ b/examples/ipc/localfortuneclient/client.cpp
@@ -0,0 +1,153 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const 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..4dbdeb1cba
--- /dev/null
+++ b/examples/ipc/localfortuneclient/client.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a394169822
--- /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]/ipc/localfortuneclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS localfortuneclient.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/ipc/localfortuneclient
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+
diff --git a/examples/ipc/localfortuneclient/main.cpp b/examples/ipc/localfortuneclient/main.cpp
new file mode 100644
index 0000000000..11dcbc638a
--- /dev/null
+++ b/examples/ipc/localfortuneclient/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..db20791dc8
--- /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]/ipc/localfortuneserver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS localfortuneserver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/ipc/localfortuneserver
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+
diff --git a/examples/ipc/localfortuneserver/main.cpp b/examples/ipc/localfortuneserver/main.cpp
new file mode 100644
index 0000000000..b505c44623
--- /dev/null
+++ b/examples/ipc/localfortuneserver/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..96a2663d4c
--- /dev/null
+++ b/examples/ipc/localfortuneserver/server.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7198fd9721
--- /dev/null
+++ b/examples/ipc/localfortuneserver/server.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..245a4a1a7f
--- /dev/null
+++ b/examples/ipc/sharedmemory/dialog.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..a0c84b6501
--- /dev/null
+++ b/examples/ipc/sharedmemory/dialog.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..533efeb668
--- /dev/null
+++ b/examples/ipc/sharedmemory/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..4dad1d1073
--- /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]/ipc/sharedmemory
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/ipc/sharedmemory
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..3eaba49df5
--- /dev/null
+++ b/examples/itemviews/addressbook/adddialog.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..a68f566f26
--- /dev/null
+++ b/examples/itemviews/addressbook/adddialog.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a03e3b6564
--- /dev/null
+++ b/examples/itemviews/addressbook/addressbook.pro
@@ -0,0 +1,21 @@
+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]/itemviews/addressbook
+sources.files = $$SOURCES $$HEADERS $$RESOURCES addressbook.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/addressbook
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A646 \ No newline at end of file
diff --git a/examples/itemviews/addressbook/addresswidget.cpp b/examples/itemviews/addressbook/addresswidget.cpp
new file mode 100644
index 0000000000..e8d0527ece
--- /dev/null
+++ b/examples/itemviews/addressbook/addresswidget.cpp
@@ -0,0 +1,238 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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;
+
+ 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(const QItemSelection &, const QItemSelection &)),
+ this, SIGNAL(selectionChanged(const 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..826e8b83e9
--- /dev/null
+++ b/examples/itemviews/addressbook/addresswidget.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..da15c26a2d
--- /dev/null
+++ b/examples/itemviews/addressbook/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..892352235e
--- /dev/null
+++ b/examples/itemviews/addressbook/mainwindow.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QItemSelection &)),
+ this, SLOT(updateActions(const 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..8c25e70109
--- /dev/null
+++ b/examples/itemviews/addressbook/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..bd0a314949
--- /dev/null
+++ b/examples/itemviews/addressbook/newaddresstab.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5ef6c37f0a
--- /dev/null
+++ b/examples/itemviews/addressbook/newaddresstab.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..56734518cf
--- /dev/null
+++ b/examples/itemviews/addressbook/tablemodel.cpp
@@ -0,0 +1,185 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..9433bec3a2
--- /dev/null
+++ b/examples/itemviews/addressbook/tablemodel.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a2c8751e08
--- /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]/itemviews/basicsortfiltermodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/basicsortfiltermodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/basicsortfiltermodel/main.cpp b/examples/itemviews/basicsortfiltermodel/main.cpp
new file mode 100644
index 0000000000..da499eda94
--- /dev/null
+++ b/examples/itemviews/basicsortfiltermodel/main.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e60553e687
--- /dev/null
+++ b/examples/itemviews/basicsortfiltermodel/window.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const 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..029a83ad01
--- /dev/null
+++ b/examples/itemviews/basicsortfiltermodel/window.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..3556de03af
--- /dev/null
+++ b/examples/itemviews/chart/chart.pro
@@ -0,0 +1,19 @@
+HEADERS = mainwindow.h \
+ pieview.h
+RESOURCES = chart.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ pieview.cpp
+unix:!mac:!symbian:LIBS+= -lm
+
+TARGET.EPOCHEAPSIZE = 0x200000 0x800000
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/itemviews/chart
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.cht
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/chart
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A647
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..dc3733cd83
--- /dev/null
+++ b/examples/itemviews/chart/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ 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..208a4658b5
--- /dev/null
+++ b/examples/itemviews/chart/mainwindow.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "pieview.h"
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
+ QAction *saveAction = fileMenu->addAction(tr("&Save As..."));
+ saveAction->setShortcut(QKeySequence(tr("Ctrl+S")));
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
+
+ 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..f3a9a10ff1
--- /dev/null
+++ b/examples/itemviews/chart/mainwindow.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..6b62f25c67
--- /dev/null
+++ b/examples/itemviews/chart/pieview.cpp
@@ -0,0 +1,562 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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, this);
+ 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..5bebefc87d
--- /dev/null
+++ b/examples/itemviews/chart/pieview.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f668e6a7e8
--- /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]/itemviews/coloreditorfactory
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/coloreditorfactory
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/coloreditorfactory/colorlisteditor.cpp b/examples/itemviews/coloreditorfactory/colorlisteditor.cpp
new file mode 100644
index 0000000000..88b953ca4d
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/colorlisteditor.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "colorlisteditor.h"
+
+ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget)
+{
+ populateList();
+}
+
+//! [0]
+QColor ColorListEditor::color() const
+{
+ return qVariantValue<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..810e26856b
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/colorlisteditor.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a9740af960
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..2ac64a3e64
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/window.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..fc7b13a1b8
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/window.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7f5c8e8c96
--- /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]/itemviews/combowidgetmapper
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..055ac21f6c
--- /dev/null
+++ b/examples/itemviews/combowidgetmapper/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..69a4c3c9d0
--- /dev/null
+++ b/examples/itemviews/combowidgetmapper/window.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..8c45117166
--- /dev/null
+++ b/examples/itemviews/combowidgetmapper/window.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..091cd9db21
--- /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]/itemviews/customsortfiltermodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/customsortfiltermodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/customsortfiltermodel/main.cpp b/examples/itemviews/customsortfiltermodel/main.cpp
new file mode 100644
index 0000000000..043f28a05d
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/main.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..ead2eb797d
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..0e09bf1a91
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..54ba646e02
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/window.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QString &)),
+ this, SLOT(textFilterChanged()));
+ connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(textFilterChanged()));
+ connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(textFilterChanged()));
+ connect(fromDateEdit, SIGNAL(dateChanged(const QDate &)),
+ this, SLOT(dateFilterChanged()));
+ connect(toDateEdit, SIGNAL(dateChanged(const 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..ba97408f1a
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/window.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..77290a8ad0
--- /dev/null
+++ b/examples/itemviews/dirview/dirview.pro
@@ -0,0 +1,9 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/itemviews/dirview
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/dirview
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/dirview/main.cpp b/examples/itemviews/dirview/main.cpp
new file mode 100644
index 0000000000..65d2ecc07b
--- /dev/null
+++ b/examples/itemviews/dirview/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QDirModel model;
+ 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..4213cd7a9f
--- /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]/itemviews/editabletreemodel
+sources.files = $$FORMS $$HEADERS $$RESOURCES $$SOURCES *.pro *.txt
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/editabletreemodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..e476d2e229
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f81b2febe2
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/mainwindow.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..6de08b693b
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/mainwindow.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <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..81a1bf3ddb
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treeitem.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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..9a3652991e
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treeitem.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f1dff0344a
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treemodel.cpp
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..36ae7396b1
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treemodel.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..dcb84ed39d
--- /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]/itemviews/fetchmore
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..fc51087483
--- /dev/null
+++ b/examples/itemviews/fetchmore/filelistmodel.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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);
+
+ 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..921a9e2e69
--- /dev/null
+++ b/examples/itemviews/fetchmore/filelistmodel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..58c970581e
--- /dev/null
+++ b/examples/itemviews/fetchmore/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..066f26be85
--- /dev/null
+++ b/examples/itemviews/fetchmore/window.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QString &)),
+ model, SLOT(setDirPath(const QString &)));
+ connect(lineEdit, SIGNAL(textChanged(const 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..1b8076fd08
--- /dev/null
+++ b/examples/itemviews/fetchmore/window.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/itemviews.pro b/examples/itemviews/itemviews.pro
new file mode 100644
index 0000000000..adbb9004c7
--- /dev/null
+++ b/examples/itemviews/itemviews.pro
@@ -0,0 +1,28 @@
+TEMPLATE = subdirs
+SUBDIRS = addressbook \
+ basicsortfiltermodel \
+ chart \
+ coloreditorfactory \
+ combowidgetmapper \
+ customsortfiltermodel \
+ dirview \
+ editabletreemodel \
+ fetchmore \
+ pixelator \
+ puzzle \
+ simpledommodel \
+ simpletreemodel \
+ simplewidgetmapper \
+ spinboxdelegate \
+ stardelegate
+
+symbian: SUBDIRS = \
+ addressbook \
+ chart
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/pixelator/imagemodel.cpp b/examples/itemviews/pixelator/imagemodel.cpp
new file mode 100644
index 0000000000..ea42b62de1
--- /dev/null
+++ b/examples/itemviews/pixelator/imagemodel.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e92115afaa
--- /dev/null
+++ b/examples/itemviews/pixelator/imagemodel.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7a303475e0
--- /dev/null
+++ b/examples/itemviews/pixelator/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ 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..a2b98cf63d
--- /dev/null
+++ b/examples/itemviews/pixelator/mainwindow.cpp
@@ -0,0 +1,245 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(QKeySequence(tr("Ctrl+O")));
+
+ printAction = fileMenu->addAction(tr("&Print..."));
+ printAction->setEnabled(false);
+ printAction->setShortcut(QKeySequence(tr("Ctrl+P")));
+
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
+
+ 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..df9510ee58
--- /dev/null
+++ b/examples/itemviews/pixelator/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..8a139d414a
--- /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]/itemviews/pixelator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/pixelator
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/pixelator/pixeldelegate.cpp b/examples/itemviews/pixelator/pixeldelegate.cpp
new file mode 100644
index 0000000000..496b3656db
--- /dev/null
+++ b/examples/itemviews/pixelator/pixeldelegate.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b38e470d01
--- /dev/null
+++ b/examples/itemviews/pixelator/pixeldelegate.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e0e5cc1907
--- /dev/null
+++ b/examples/itemviews/puzzle/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ 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..c6088f69db
--- /dev/null
+++ b/examples/itemviews/puzzle/mainwindow.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(QKeySequence(tr("Ctrl+O")));
+
+ QAction *exitAction = fileMenu->addAction(tr("E&xit"));
+ exitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
+
+ 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..2fb97d4d9a
--- /dev/null
+++ b/examples/itemviews/puzzle/mainwindow.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..f480837737
--- /dev/null
+++ b/examples/itemviews/puzzle/piecesmodel.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 = qVariantValue<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..777768aacd
--- /dev/null
+++ b/examples/itemviews/puzzle/piecesmodel.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e5ee3dd84f
--- /dev/null
+++ b/examples/itemviews/puzzle/puzzle.pro
@@ -0,0 +1,16 @@
+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]/itemviews/puzzle
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.jpg
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/puzzle
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
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..aa41ead1db
--- /dev/null
+++ b/examples/itemviews/puzzle/puzzlewidget.cpp
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..312e25fc77
--- /dev/null
+++ b/examples/itemviews/puzzle/puzzlewidget.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..18f65eadfe
--- /dev/null
+++ b/examples/itemviews/simpledommodel/domitem.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..61f2acc5fe
--- /dev/null
+++ b/examples/itemviews/simpledommodel/domitem.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..495fd55469
--- /dev/null
+++ b/examples/itemviews/simpledommodel/dommodel.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..1178b2c1ff
--- /dev/null
+++ b/examples/itemviews/simpledommodel/dommodel.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d2ecfc941b
--- /dev/null
+++ b/examples/itemviews/simpledommodel/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..ac968998c9
--- /dev/null
+++ b/examples/itemviews/simpledommodel/mainwindow.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(tr("Ctrl+O")));
+ fileMenu->addAction(tr("E&xit"), this, SLOT(close()),
+ QKeySequence(tr("Ctrl+Q")));
+
+ 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..4bc967a545
--- /dev/null
+++ b/examples/itemviews/simpledommodel/mainwindow.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <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..cc7b4de94c
--- /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]/itemviews/simpledommodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/simpledommodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..89bdc774d9
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..b1dd37a264
--- /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]/itemviews/simpletreemodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.txt
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/simpletreemodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..d2c1eed831
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treeitem.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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..7bfd63b3c5
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treeitem.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ec7bd64b9b
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treemodel.cpp
@@ -0,0 +1,219 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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..3b535f92b4
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treemodel.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..055ac21f6c
--- /dev/null
+++ b/examples/itemviews/simplewidgetmapper/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..8bbfef9e61
--- /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]/itemviews/simplewidgetmapper
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/simplewidgetmapper
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/simplewidgetmapper/window.cpp b/examples/itemviews/simplewidgetmapper/window.cpp
new file mode 100644
index 0000000000..406a3d7771
--- /dev/null
+++ b/examples/itemviews/simplewidgetmapper/window.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..726d4d688c
--- /dev/null
+++ b/examples/itemviews/simplewidgetmapper/window.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..03a1a23565
--- /dev/null
+++ b/examples/itemviews/spinboxdelegate/delegate.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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..a81cfd15ca
--- /dev/null
+++ b/examples/itemviews/spinboxdelegate/delegate.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4b9d6a4052
--- /dev/null
+++ b/examples/itemviews/spinboxdelegate/main.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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..31b55d4f32
--- /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]/itemviews/spinboxdelegate
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/spinboxdelegate
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/itemviews/stardelegate/main.cpp b/examples/itemviews/stardelegate/main.cpp
new file mode 100644
index 0000000000..5b27ee1cae
--- /dev/null
+++ b/examples/itemviews/stardelegate/main.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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,
+ qVariantFromValue(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..1e1297108e
--- /dev/null
+++ b/examples/itemviews/stardelegate/stardelegate.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "stardelegate.h"
+#include "stareditor.h"
+#include "starrating.h"
+
+//! [0]
+void StarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ if (qVariantCanConvert<StarRating>(index.data())) {
+ StarRating starRating = qVariantValue<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 (qVariantCanConvert<StarRating>(index.data())) {
+ StarRating starRating = qVariantValue<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 (qVariantCanConvert<StarRating>(index.data())) {
+ 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 (qVariantCanConvert<StarRating>(index.data())) {
+ StarRating starRating = qVariantValue<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 (qVariantCanConvert<StarRating>(index.data())) {
+ StarEditor *starEditor = qobject_cast<StarEditor *>(editor);
+ model->setData(index, qVariantFromValue(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..84814ed45d
--- /dev/null
+++ b/examples/itemviews/stardelegate/stardelegate.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a55b55d368
--- /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]/itemviews/stardelegate
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/stardelegate
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
diff --git a/examples/itemviews/stardelegate/stareditor.cpp b/examples/itemviews/stardelegate/stareditor.cpp
new file mode 100644
index 0000000000..633229f423
--- /dev/null
+++ b/examples/itemviews/stardelegate/stareditor.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7365ca1f1a
--- /dev/null
+++ b/examples/itemviews/stardelegate/stareditor.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e40f22d3cf
--- /dev/null
+++ b/examples/itemviews/stardelegate/starrating.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..1e73076450
--- /dev/null
+++ b/examples/itemviews/stardelegate/starrating.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/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..4ffc8c0aad
--- /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]/layouts/basiclayouts
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/layouts/basiclayouts
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/layouts/basiclayouts/dialog.cpp b/examples/layouts/basiclayouts/dialog.cpp
new file mode 100644
index 0000000000..86cafb9d21
--- /dev/null
+++ b/examples/layouts/basiclayouts/dialog.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b6b1e3a5a3
--- /dev/null
+++ b/examples/layouts/basiclayouts/dialog.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..09c49eece3
--- /dev/null
+++ b/examples/layouts/basiclayouts/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..25a4778e19
--- /dev/null
+++ b/examples/layouts/borderlayout/borderlayout.cpp
@@ -0,0 +1,214 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..781a01fd36
--- /dev/null
+++ b/examples/layouts/borderlayout/borderlayout.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..18b5e6cff4
--- /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]/layouts/borderlayout
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/layouts/borderlayout
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/layouts/borderlayout/main.cpp b/examples/layouts/borderlayout/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/layouts/borderlayout/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..2b085517a5
--- /dev/null
+++ b/examples/layouts/borderlayout/window.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..708d2702d0
--- /dev/null
+++ b/examples/layouts/borderlayout/window.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..eee15f60be
--- /dev/null
+++ b/examples/layouts/dynamiclayouts/dialog.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..bc1225ad38
--- /dev/null
+++ b/examples/layouts/dynamiclayouts/dialog.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..dce1e29d84
--- /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]/layouts/dynamiclayouts
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/layouts/dynamiclayouts
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/layouts/dynamiclayouts/main.cpp b/examples/layouts/dynamiclayouts/main.cpp
new file mode 100644
index 0000000000..09c49eece3
--- /dev/null
+++ b/examples/layouts/dynamiclayouts/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..d1e857d591
--- /dev/null
+++ b/examples/layouts/flowlayout/flowlayout.cpp
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "flowlayout.h"
+
+FlowLayout::FlowLayout(QWidget *parent, int margin, int spacing)
+ : QLayout(parent)
+{
+ setMargin(margin);
+ setSpacing(spacing);
+}
+
+FlowLayout::FlowLayout(int spacing)
+{
+ setSpacing(spacing);
+}
+
+FlowLayout::~FlowLayout()
+{
+ QLayoutItem *item;
+ while ((item = takeAt(0)))
+ delete item;
+}
+
+void FlowLayout::addItem(QLayoutItem *item)
+{
+ itemList.append(item);
+}
+
+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;
+}
+
+Qt::Orientations FlowLayout::expandingDirections() const
+{
+ return 0;
+}
+
+bool FlowLayout::hasHeightForWidth() const
+{
+ return true;
+}
+
+int FlowLayout::heightForWidth(int width) const
+{
+ int height = doLayout(QRect(0, 0, width, 0), true);
+ return height;
+}
+
+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;
+}
+
+int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
+{
+ int x = rect.x();
+ int y = rect.y();
+ int lineHeight = 0;
+
+ QLayoutItem *item;
+ foreach (item, itemList) {
+ QWidget *wid = item->widget();
+ int spaceX = spacing() + wid->style()->layoutSpacing(
+ QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
+ int spaceY = spacing() + wid->style()->layoutSpacing(
+ QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
+ int nextX = x + item->sizeHint().width() + spaceX;
+ if (nextX - spaceX > rect.right() && lineHeight > 0) {
+ x = rect.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();
+}
diff --git a/examples/layouts/flowlayout/flowlayout.h b/examples/layouts/flowlayout/flowlayout.h
new file mode 100644
index 0000000000..f864d8eeab
--- /dev/null
+++ b/examples/layouts/flowlayout/flowlayout.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FLOWLAYOUT_H
+#define FLOWLAYOUT_H
+
+#include <QLayout>
+#include <QRect>
+#include <QWidgetItem>
+
+class FlowLayout : public QLayout
+{
+public:
+ FlowLayout(QWidget *parent, int margin = -1, int spacing = 0);
+ FlowLayout(int spacing = 0);
+ ~FlowLayout();
+
+ void addItem(QLayoutItem *item);
+ 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;
+
+ QList<QLayoutItem *> itemList;
+};
+
+#endif
diff --git a/examples/layouts/flowlayout/flowlayout.pro b/examples/layouts/flowlayout/flowlayout.pro
new file mode 100644
index 0000000000..ece314f9ce
--- /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]/layouts/flowlayout
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/layouts/flowlayout
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/layouts/flowlayout/main.cpp b/examples/layouts/flowlayout/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/layouts/flowlayout/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..51d9886721
--- /dev/null
+++ b/examples/layouts/flowlayout/window.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "flowlayout.h"
+#include "window.h"
+
+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"));
+}
diff --git a/examples/layouts/flowlayout/window.h b/examples/layouts/flowlayout/window.h
new file mode 100644
index 0000000000..ffd60af93d
--- /dev/null
+++ b/examples/layouts/flowlayout/window.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+};
+
+#endif
diff --git a/examples/layouts/layouts.pro b/examples/layouts/layouts.pro
new file mode 100644
index 0000000000..81c15f24f1
--- /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]/layouts
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..149247e4ff
--- /dev/null
+++ b/examples/linguist/arrowpad/arrowpad.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..d87a40c952
--- /dev/null
+++ b/examples/linguist/arrowpad/arrowpad.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7e409a6f2a
--- /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]/linguist/arrowpad
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/linguist/arrowpad
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/linguist/arrowpad/main.cpp b/examples/linguist/arrowpad/main.cpp
new file mode 100644
index 0000000000..912cac41b3
--- /dev/null
+++ b/examples/linguist/arrowpad/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..a167cc2a37
--- /dev/null
+++ b/examples/linguist/arrowpad/mainwindow.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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->setShortcut(tr("Ctrl+Q"));
+ 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..74e89be34c
--- /dev/null
+++ b/examples/linguist/arrowpad/mainwindow.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..ecd480bf93
--- /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]/linguist/hellotr
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/linguist/hellotr
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/linguist/hellotr/main.cpp b/examples/linguist/hellotr/main.cpp
new file mode 100644
index 0000000000..f98089da37
--- /dev/null
+++ b/examples/linguist/hellotr/main.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..ad3f772a23
--- /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]/linguist
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/linguist/trollprint/main.cpp b/examples/linguist/trollprint/main.cpp
new file mode 100644
index 0000000000..9f37661f6c
--- /dev/null
+++ b/examples/linguist/trollprint/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f7aa1ca90d
--- /dev/null
+++ b/examples/linguist/trollprint/mainwindow.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..415512bff4
--- /dev/null
+++ b/examples/linguist/trollprint/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..888c12ae05
--- /dev/null
+++ b/examples/linguist/trollprint/printpanel.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f6eef67bc4
--- /dev/null
+++ b/examples/linguist/trollprint/printpanel.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..27cb38ed4a
--- /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]/linguist/trollprint
+sources.files = $$SOURCES $$HEADERS $$TRANSLATIONS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/linguist/trollprint
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..fc022fc53f
--- /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]/mainwindows/application
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS application.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/application
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..0f9d1b277d
--- /dev/null
+++ b/examples/mainwindows/application/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(application);
+
+ QApplication app(argc, argv);
+ 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..c9ff842a6c
--- /dev/null
+++ b/examples/mainwindows/application/mainwindow.cpp
@@ -0,0 +1,396 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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->setShortcut(tr("Ctrl+Q"));
+//! [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;
+ if (curFile.isEmpty())
+ shownName = "untitled.txt";
+ else
+ shownName = strippedName(curFile);
+
+ setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Application")));
+}
+//! [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..264be03511
--- /dev/null
+++ b/examples/mainwindows/application/mainwindow.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..ea8594d703
--- /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]/mainwindows/dockwidgets
+sources.files = $$SOURCES $$HEADERS $$RESOURCES dockwidgets.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/dockwidgets
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..f4bed914f0
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ 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..16830348b5
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/mainwindow.cpp
@@ -0,0 +1,343 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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->setShortcut(tr("Ctrl+Q"));
+ 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(const QString &)),
+ this, SLOT(insertCustomer(const QString &)));
+ connect(paragraphsList, SIGNAL(currentTextChanged(const QString &)),
+ this, SLOT(addParagraph(const QString &)));
+}
+//! [9]
diff --git a/examples/mainwindows/dockwidgets/mainwindow.h b/examples/mainwindows/dockwidgets/mainwindow.h
new file mode 100644
index 0000000000..f4768d779b
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/mainwindow.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..e310e3db84
--- /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]/mainwindows
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS mainwindows.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..85928365ff
--- /dev/null
+++ b/examples/mainwindows/mdi/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ 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..49f9b21449
--- /dev/null
+++ b/examples/mainwindows/mdi/mainwindow.cpp
@@ -0,0 +1,399 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 (activeMdiChild()) {
+ 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->setShortcut(tr("Ctrl+Q"));
+ 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->setShortcut(tr("Ctrl+F4"));
+ 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..ee91d36174
--- /dev/null
+++ b/examples/mainwindows/mdi/mainwindow.h
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..b0db42cd8c
--- /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]/mainwindows/mdi
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS mdi.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/mdi
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..14334509da
--- /dev/null
+++ b/examples/mainwindows/mdi/mdichild.cpp
@@ -0,0 +1,176 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..04084c74a2
--- /dev/null
+++ b/examples/mainwindows/mdi/mdichild.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..1d51376c06
--- /dev/null
+++ b/examples/mainwindows/menus/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..4c10f7358b
--- /dev/null
+++ b/examples/mainwindows/menus/mainwindow.cpp
@@ -0,0 +1,371 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+Q"));
+ 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->setShortcut(tr("Ctrl+C"));
+ 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(tr("Ctrl+B"));
+ 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(tr("Ctrl+I"));
+ 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..4894a9a4a3
--- /dev/null
+++ b/examples/mainwindows/menus/mainwindow.h
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..448e779971
--- /dev/null
+++ b/examples/mainwindows/menus/menus.pro
@@ -0,0 +1,11 @@
+HEADERS = mainwindow.h
+SOURCES = mainwindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/menus
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS menus.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/menus
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/mainwindows/recentfiles/main.cpp b/examples/mainwindows/recentfiles/main.cpp
new file mode 100644
index 0000000000..d1c8eb0eef
--- /dev/null
+++ b/examples/mainwindows/recentfiles/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow *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..c8c2f88db3
--- /dev/null
+++ b/examples/mainwindows/recentfiles/mainwindow.cpp
@@ -0,0 +1,256 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ textEdit = new QTextEdit;
+ setCentralWidget(textEdit);
+
+ createActions();
+ createMenus();
+ (void)statusBar();
+
+ setWindowTitle(tr("Recent Files"));
+ 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->setShortcut(tr("Ctrl+Q"));
+ 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;
+ if (curFile.isEmpty())
+ setWindowTitle(tr("Recent Files"));
+ else
+ setWindowTitle(tr("%1 - %2").arg(strippedName(curFile))
+ .arg(tr("Recent Files")));
+
+ QSettings settings("Trolltech", "Recent Files Example");
+ 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("Trolltech", "Recent Files Example");
+ 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..9d9d467c7b
--- /dev/null
+++ b/examples/mainwindows/recentfiles/mainwindow.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..8f7ddafd3a
--- /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]/mainwindows/recentfiles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS recentfiles.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/recentfiles
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..163ad939b0
--- /dev/null
+++ b/examples/mainwindows/sdi/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(sdi);
+ QApplication app(argc, argv);
+ 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..61d63b32ff
--- /dev/null
+++ b/examples/mainwindows/sdi/mainwindow.cpp
@@ -0,0 +1,375 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+Q"));
+ 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("Trolltech", "SDI 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", "SDI Example");
+ 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);
+
+ setWindowTitle(tr("%1[*] - %2").arg(strippedName(curFile))
+ .arg(tr("SDI")));
+}
+
+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..f08cee2f98
--- /dev/null
+++ b/examples/mainwindows/sdi/mainwindow.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+ 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..c033e195b4
--- /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]/mainwindows/sdi
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sdi.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/sdi
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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/blockingfortuneclient/blockingclient.cpp b/examples/network/blockingfortuneclient/blockingclient.cpp
new file mode 100644
index 0000000000..207ff5fdf7
--- /dev/null
+++ b/examples/network/blockingfortuneclient/blockingclient.cpp
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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:"));
+
+ hostLineEdit = new QLineEdit("Localhost");
+ 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(const QString &)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(portLineEdit, SIGNAL(textChanged(const QString &)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(getFortuneButton, SIGNAL(clicked()),
+ this, SLOT(requestNewFortune()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+//! [0]
+ connect(&thread, SIGNAL(newFortune(const QString &)),
+ this, SLOT(showFortune(const QString &)));
+//! [0] //! [1]
+ connect(&thread, SIGNAL(error(int, const QString &)),
+ this, SLOT(displayError(int, const 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..2bc0b80e28
--- /dev/null
+++ b/examples/network/blockingfortuneclient/blockingclient.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..96fbc1f173
--- /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]/network/blockingfortuneclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS blockingfortuneclient.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/blockingfortuneclient
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/blockingfortuneclient/fortunethread.cpp b/examples/network/blockingfortuneclient/fortunethread.cpp
new file mode 100644
index 0000000000..af1c612443
--- /dev/null
+++ b/examples/network/blockingfortuneclient/fortunethread.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c2fbe6f039
--- /dev/null
+++ b/examples/network/blockingfortuneclient/fortunethread.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..98982c1cff
--- /dev/null
+++ b/examples/network/blockingfortuneclient/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..36ad0960bb
--- /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]/network/broadcastreceiver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS broadcastreceiver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/broadcastreceiver
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/broadcastreceiver/main.cpp b/examples/network/broadcastreceiver/main.cpp
new file mode 100644
index 0000000000..f815729118
--- /dev/null
+++ b/examples/network/broadcastreceiver/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..ea9ab14008
--- /dev/null
+++ b/examples/network/broadcastreceiver/receiver.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+//! [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..9939cbe4ff
--- /dev/null
+++ b/examples/network/broadcastreceiver/receiver.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..84e65936a2
--- /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]/network/broadcastsender
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS broadcastsender.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/broadcastsender
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/broadcastsender/main.cpp b/examples/network/broadcastsender/main.cpp
new file mode 100644
index 0000000000..85613c588b
--- /dev/null
+++ b/examples/network/broadcastsender/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..a74beaeda9
--- /dev/null
+++ b/examples/network/broadcastsender/sender.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..92265b836a
--- /dev/null
+++ b/examples/network/broadcastsender/sender.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f0db3402c0
--- /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]/network/download
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/download
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/download/main.cpp b/examples/network/download/main.cpp
new file mode 100644
index 0000000000..e0158e72ae
--- /dev/null
+++ b/examples/network/download/main.cpp
@@ -0,0 +1,176 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QFile>
+#include <QFileInfo>
+#include <QList>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QStringList>
+#include <QTimer>
+#include <QUrl>
+
+#include <stdio.h>
+
+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);
+};
+
+DownloadManager::DownloadManager()
+{
+ connect(&manager, SIGNAL(finished(QNetworkReply*)),
+ SLOT(downloadFinished(QNetworkReply*)));
+}
+
+void DownloadManager::doDownload(const QUrl &url)
+{
+ QNetworkRequest request(url);
+ QNetworkReply *reply = manager.get(request);
+
+ 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::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 succeded (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..a4721a2478
--- /dev/null
+++ b/examples/network/downloadmanager/downloadmanager.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..7ed80c4d58
--- /dev/null
+++ b/examples/network/downloadmanager/downloadmanager.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ef7052c2de
--- /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]/network/downloadmanager
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/downloadmanager
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/downloadmanager/main.cpp b/examples/network/downloadmanager/main.cpp
new file mode 100644
index 0000000000..8a3fe2420a
--- /dev/null
+++ b/examples/network/downloadmanager/main.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e1fbf5255c
--- /dev/null
+++ b/examples/network/downloadmanager/textprogressbar.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..34097d0428
--- /dev/null
+++ b/examples/network/downloadmanager/textprogressbar.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4d658280ac
--- /dev/null
+++ b/examples/network/fortuneclient/client.cpp
@@ -0,0 +1,191 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "client.h"
+
+//! [0]
+Client::Client(QWidget *parent)
+ : QDialog(parent)
+{
+//! [0]
+ hostLabel = new QLabel(tr("&Server name:"));
+ portLabel = new QLabel(tr("S&erver port:"));
+
+ hostLineEdit = new QLineEdit("Localhost");
+ 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(const QString &)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(portLineEdit, SIGNAL(textChanged(const 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();
+//! [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(!hostLineEdit->text().isEmpty()
+ && !portLineEdit->text().isEmpty());
+}
diff --git a/examples/network/fortuneclient/client.h b/examples/network/fortuneclient/client.h
new file mode 100644
index 0000000000..b9fe7b11f2
--- /dev/null
+++ b/examples/network/fortuneclient/client.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CLIENT_H
+#define CLIENT_H
+
+#include <QDialog>
+#include <QTcpSocket>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QTcpSocket;
+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();
+
+private:
+ QLabel *hostLabel;
+ QLabel *portLabel;
+ QLineEdit *hostLineEdit;
+ QLineEdit *portLineEdit;
+ QLabel *statusLabel;
+ QPushButton *getFortuneButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+
+ QTcpSocket *tcpSocket;
+ QString currentFortune;
+ quint16 blockSize;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/fortuneclient/fortuneclient.pro b/examples/network/fortuneclient/fortuneclient.pro
new file mode 100644
index 0000000000..bb125e8816
--- /dev/null
+++ b/examples/network/fortuneclient/fortuneclient.pro
@@ -0,0 +1,12 @@
+HEADERS = client.h
+SOURCES = client.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/network/fortuneclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fortuneclient.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/fortuneclient
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/fortuneclient/main.cpp b/examples/network/fortuneclient/main.cpp
new file mode 100644
index 0000000000..11dcbc638a
--- /dev/null
+++ b/examples/network/fortuneclient/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "client.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Client client;
+ client.show();
+ return client.exec();
+}
diff --git a/examples/network/fortuneserver/fortuneserver.pro b/examples/network/fortuneserver/fortuneserver.pro
new file mode 100644
index 0000000000..8cf52ee957
--- /dev/null
+++ b/examples/network/fortuneserver/fortuneserver.pro
@@ -0,0 +1,12 @@
+HEADERS = server.h
+SOURCES = server.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/network/fortuneserver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fortuneserver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/fortuneserver
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/fortuneserver/main.cpp b/examples/network/fortuneserver/main.cpp
new file mode 100644
index 0000000000..b505c44623
--- /dev/null
+++ b/examples/network/fortuneserver/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
new file mode 100644
index 0000000000..09626a8c39
--- /dev/null
+++ b/examples/network/fortuneserver/server.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include <stdlib.h>
+
+#include "server.h"
+
+Server::Server(QWidget *parent)
+ : QDialog(parent)
+{
+ statusLabel = new QLabel;
+ quitButton = new QPushButton(tr("Quit"));
+ quitButton->setAutoDefault(false);
+
+//! [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]
+
+ statusLabel->setText(tr("The server is running on port %1.\n"
+ "Run the Fortune Client example now.")
+ .arg(tcpServer->serverPort()));
+//! [1]
+
+//! [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"));
+}
+
+//! [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..dcd64c72af
--- /dev/null
+++ b/examples/network/fortuneserver/server.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SERVER_H
+#define SERVER_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QTcpServer;
+QT_END_NAMESPACE
+
+//! [0]
+class Server : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Server(QWidget *parent = 0);
+
+private slots:
+ void sendFortune();
+
+private:
+ QLabel *statusLabel;
+ QPushButton *quitButton;
+ QTcpServer *tcpServer;
+ QStringList fortunes;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/ftp/ftp.pro b/examples/network/ftp/ftp.pro
new file mode 100644
index 0000000000..90594f5d54
--- /dev/null
+++ b/examples/network/ftp/ftp.pro
@@ -0,0 +1,21 @@
+HEADERS = ftpwindow.h
+SOURCES = ftpwindow.cpp \
+ main.cpp
+RESOURCES += ftp.qrc
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/network/ftp
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS ftp.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/ftp
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian {
+ #Enable this macro if you have latest Open C and you want to get rid of IAP queries
+ #DEFINES += SETDEFAULTIF_AVAILABLE
+ TARGET.CAPABILITY="NetworkServices"
+ TARGET.UID3 = 0xA000A648
+ contains( DEFINES, SETDEFAULTIF_AVAILABLE ):LIBS+=-lesock
+} \ No newline at end of file
diff --git a/examples/network/ftp/ftp.qrc b/examples/network/ftp/ftp.qrc
new file mode 100644
index 0000000000..b598ab8829
--- /dev/null
+++ b/examples/network/ftp/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/ftp/ftpwindow.cpp b/examples/network/ftp/ftpwindow.cpp
new file mode 100644
index 0000000000..52c31e0bc0
--- /dev/null
+++ b/examples/network/ftp/ftpwindow.cpp
@@ -0,0 +1,364 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "ftpwindow.h"
+
+FtpWindow::FtpWindow(QWidget *parent)
+ : QDialog(parent), ftp(0)
+{
+ ftpServerLabel = new QLabel(tr("Ftp &server:"));
+ ftpServerLineEdit = new QLineEdit("ftp.trolltech.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);
+
+ 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
+ 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(const QUrlInfo &)),
+ this, SLOT(addToList(const 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 += "/" + 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]
+
diff --git a/examples/network/ftp/ftpwindow.h b/examples/network/ftp/ftpwindow.h
new file mode 100644
index 0000000000..a3045faeee
--- /dev/null
+++ b/examples/network/ftp/ftpwindow.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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;
+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();
+//![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;
+//![1]
+};
+
+#endif
diff --git a/examples/network/ftp/images/cdtoparent.png b/examples/network/ftp/images/cdtoparent.png
new file mode 100644
index 0000000000..24b6180829
--- /dev/null
+++ b/examples/network/ftp/images/cdtoparent.png
Binary files differ
diff --git a/examples/network/ftp/images/dir.png b/examples/network/ftp/images/dir.png
new file mode 100644
index 0000000000..0ce5ae75fc
--- /dev/null
+++ b/examples/network/ftp/images/dir.png
Binary files differ
diff --git a/examples/network/ftp/images/file.png b/examples/network/ftp/images/file.png
new file mode 100644
index 0000000000..be6c53089a
--- /dev/null
+++ b/examples/network/ftp/images/file.png
Binary files differ
diff --git a/examples/network/ftp/main.cpp b/examples/network/ftp/main.cpp
new file mode 100644
index 0000000000..a472fd76e3
--- /dev/null
+++ b/examples/network/ftp/main.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#ifdef Q_OS_SYMBIAN
+#include <QDir>
+#include <QDesktopWidget>
+#endif
+#include "ftpwindow.h"
+
+#if defined Q_OS_SYMBIAN && defined SETDEFAULTIF_AVAILABLE
+#include <es_sock.h>
+#include <sys/socket.h>
+#include <net/if.h>
+
+static void setDefaultIapL()
+{
+ TInt err = KErrNone;
+ RSocketServ serv;
+ CleanupClosePushL(serv);
+ User::LeaveIfError(serv.Connect());
+
+ RConnection conn;
+ CleanupClosePushL(conn);
+ User::LeaveIfError(conn.Open(serv));
+ User::LeaveIfError(conn.Start());
+
+ _LIT(KIapNameSetting, "IAP\\Name");
+ TBuf8<50> iapName;
+ User::LeaveIfError(conn.GetDesSetting(TPtrC(KIapNameSetting), iapName));
+
+ struct ifreq ifReq;
+ strcpy( ifReq.ifr_name, (char*)iapName.Ptr());
+ User::LeaveIfError(setdefaultif( &ifReq ));
+
+ CleanupStack::PopAndDestroy(&conn);
+ CleanupStack::PopAndDestroy(&serv);
+}
+
+static int setDefaultIap()
+{
+ TRAPD(err, setDefaultIapL());
+ return err;
+}
+
+#endif
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(ftp);
+
+#ifdef Q_OS_SYMBIAN
+#ifdef SETDEFAULTIF_AVAILABLE
+ setDefaultIap();
+#endif
+ // 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();
+#endif
+ ftpWin.show();
+ return ftpWin.exec();
+}
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..99aa717e71
--- /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]/network/http
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS http.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/http
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp
new file mode 100644
index 0000000000..ebde7703aa
--- /dev/null
+++ b/examples/network/http/httpwindow.cpp
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "httpwindow.h"
+#include "ui_authenticationdialog.h"
+
+HttpWindow::HttpWindow(QWidget *parent)
+ : QDialog(parent)
+{
+#ifndef QT_NO_OPENSSL
+ urlLineEdit = new QLineEdit("https://");
+#else
+ urlLineEdit = new QLineEdit("http://");
+#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);
+
+ http = new QHttp(this);
+
+ connect(urlLineEdit, SIGNAL(textChanged(const QString &)),
+ this, SLOT(enableDownloadButton()));
+ connect(http, SIGNAL(requestFinished(int, bool)),
+ this, SLOT(httpRequestFinished(int, bool)));
+ connect(http, SIGNAL(dataReadProgress(int, int)),
+ this, SLOT(updateDataReadProgress(int, int)));
+ connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
+ this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
+ connect(http, SIGNAL(authenticationRequired(const QString &, quint16, QAuthenticator *)),
+ this, SLOT(slotAuthenticationRequired(const QString &, quint16, QAuthenticator *)));
+#ifndef QT_NO_OPENSSL
+ connect(http, SIGNAL(sslErrors(const QList<QSslError> &)),
+ this, SLOT(sslErrors(const 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::downloadFile()
+{
+ QUrl 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::Ok|QMessageBox::Cancel, QMessageBox::Cancel)
+ == QMessageBox::Cancel)
+ 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;
+ }
+
+ QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
+ http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
+
+ if (!url.userName().isEmpty())
+ http->setUser(url.userName(), url.password());
+
+ httpRequestAborted = false;
+ QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");
+ if (path.isEmpty())
+ path = "/";
+ httpGetId = http->get(path, file);
+
+ progressDialog->setWindowTitle(tr("HTTP"));
+ progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
+ downloadButton->setEnabled(false);
+}
+
+void HttpWindow::cancelDownload()
+{
+ statusLabel->setText(tr("Download canceled."));
+ httpRequestAborted = true;
+ http->abort();
+ downloadButton->setEnabled(true);
+}
+
+void HttpWindow::httpRequestFinished(int requestId, bool error)
+{
+ if (requestId != httpGetId)
+ return;
+ if (httpRequestAborted) {
+ if (file) {
+ file->close();
+ file->remove();
+ delete file;
+ file = 0;
+ }
+
+ progressDialog->hide();
+ return;
+ }
+
+ if (requestId != httpGetId)
+ return;
+
+ progressDialog->hide();
+ file->close();
+
+ if (error) {
+ file->remove();
+ QMessageBox::information(this, tr("HTTP"),
+ tr("Download failed: %1.")
+ .arg(http->errorString()));
+ } else {
+ QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
+ statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName));
+ }
+
+ downloadButton->setEnabled(true);
+ delete file;
+ file = 0;
+}
+
+void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader)
+{
+ switch (responseHeader.statusCode()) {
+ case 200: // Ok
+ case 301: // Moved Permanently
+ case 302: // Found
+ case 303: // See Other
+ case 307: // Temporary Redirect
+ // these are not error conditions
+ break;
+
+ default:
+ QMessageBox::information(this, tr("HTTP"),
+ tr("Download failed: %1.")
+ .arg(responseHeader.reasonPhrase()));
+ httpRequestAborted = true;
+ progressDialog->hide();
+ http->abort();
+ }
+}
+
+void HttpWindow::updateDataReadProgress(int bytesRead, int totalBytes)
+{
+ if (httpRequestAborted)
+ return;
+
+ progressDialog->setMaximum(totalBytes);
+ progressDialog->setValue(bytesRead);
+}
+
+void HttpWindow::enableDownloadButton()
+{
+ downloadButton->setEnabled(!urlLineEdit->text().isEmpty());
+}
+
+void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator *authenticator)
+{
+ QDialog dlg;
+ Ui::Dialog ui;
+ ui.setupUi(&dlg);
+ dlg.adjustSize();
+ ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName));
+
+ if (dlg.exec() == QDialog::Accepted) {
+ authenticator->setUser(ui.userEdit->text());
+ authenticator->setPassword(ui.passwordEdit->text());
+ }
+}
+
+#ifndef QT_NO_OPENSSL
+void HttpWindow::sslErrors(const QList<QSslError> &errors)
+{
+ QString errorString;
+ foreach (const QSslError &error, errors) {
+ if (!errorString.isEmpty())
+ errorString += ", ";
+ errorString += error.errorString();
+ }
+
+ if (QMessageBox::warning(this, tr("HTTP Example"),
+ tr("One or more SSL errors has occurred: %1").arg(errorString),
+ QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) {
+ http->ignoreSslErrors();
+ }
+}
+#endif
diff --git a/examples/network/http/httpwindow.h b/examples/network/http/httpwindow.h
new file mode 100644
index 0000000000..f0fb504433
--- /dev/null
+++ b/examples/network/http/httpwindow.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HTTPWINDOW_H
+#define HTTPWINDOW_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QFile;
+class QHttp;
+class QHttpResponseHeader;
+class QLabel;
+class QLineEdit;
+class QProgressDialog;
+class QPushButton;
+class QSslError;
+class QAuthenticator;
+QT_END_NAMESPACE
+
+class HttpWindow : public QDialog
+{
+ Q_OBJECT
+
+public:
+ HttpWindow(QWidget *parent = 0);
+
+private slots:
+ void downloadFile();
+ void cancelDownload();
+ void httpRequestFinished(int requestId, bool error);
+ void readResponseHeader(const QHttpResponseHeader &responseHeader);
+ void updateDataReadProgress(int bytesRead, int totalBytes);
+ void enableDownloadButton();
+ void slotAuthenticationRequired(const QString &, quint16, QAuthenticator *);
+#ifndef QT_NO_OPENSSL
+ void sslErrors(const QList<QSslError> &errors);
+#endif
+
+private:
+ QLabel *statusLabel;
+ QLabel *urlLabel;
+ QLineEdit *urlLineEdit;
+ QProgressDialog *progressDialog;
+ QPushButton *downloadButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+
+ QHttp *http;
+ 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..dba40828f4
--- /dev/null
+++ b/examples/network/http/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..06ec8dd32b
--- /dev/null
+++ b/examples/network/loopback/dialog.cpp
@@ -0,0 +1,187 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "dialog.h"
+
+#if !defined(Q_OS_WINCE)
+static const int TotalBytes = 50 * 1024 * 1024;
+#else
+static const int TotalBytes = 5 * 1024 * 1024;
+#endif
+static const int PayloadSize = 65536;
+
+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()
+{
+ 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)
+{
+ bytesWritten += (int)numBytes;
+ if (bytesToWrite > 0)
+ 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..cc15376ff5
--- /dev/null
+++ b/examples/network/loopback/dialog.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..0a09e34048
--- /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]/network/loopback
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS loopback.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/loopback
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/loopback/main.cpp b/examples/network/loopback/main.cpp
new file mode 100644
index 0000000000..3e9e62cdb6
--- /dev/null
+++ b/examples/network/loopback/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ dialog.show();
+ return dialog.exec();
+}
diff --git a/examples/network/network-chat/chatdialog.cpp b/examples/network/network-chat/chatdialog.cpp
new file mode 100644
index 0000000000..7e88e5b87e
--- /dev/null
+++ b/examples/network/network-chat/chatdialog.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(&client, SIGNAL(newMessage(const QString &, const QString &)),
+ this, SLOT(appendMessage(const QString &, const QString &)));
+ connect(&client, SIGNAL(newParticipant(const QString &)),
+ this, SLOT(newParticipant(const QString &)));
+ connect(&client, SIGNAL(participantLeft(const QString &)),
+ this, SLOT(participantLeft(const 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..552d79408d
--- /dev/null
+++ b/examples/network/network-chat/chatdialog.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d5931a6bd1
--- /dev/null
+++ b/examples/network/network-chat/client.cpp
@@ -0,0 +1,140 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QString &, const QString &)),
+ this, SIGNAL(newMessage(const QString &, const 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..307df46b47
--- /dev/null
+++ b/examples/network/network-chat/client.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..116ca3acae
--- /dev/null
+++ b/examples/network/network-chat/connection.cpp
@@ -0,0 +1,276 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..078415450e
--- /dev/null
+++ b/examples/network/network-chat/connection.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ffe28c92f0
--- /dev/null
+++ b/examples/network/network-chat/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "chatdialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ ChatDialog dialog;
+ dialog.show();
+ 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..6967228440
--- /dev/null
+++ b/examples/network/network-chat/network-chat.pro
@@ -0,0 +1,21 @@
+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]/network/network-chat
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS network-chat.pro *.chat
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/network-chat
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/network-chat/peermanager.cpp b/examples/network/network-chat/peermanager.cpp
new file mode 100644
index 0000000000..4ed4c5a213
--- /dev/null
+++ b/examples/network/network-chat/peermanager.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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())
+ username = "unknown";
+
+ 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..a7293299fa
--- /dev/null
+++ b/examples/network/network-chat/peermanager.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..26f1e70d90
--- /dev/null
+++ b/examples/network/network-chat/server.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..d2976938de
--- /dev/null
+++ b/examples/network/network-chat/server.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..db63d6ec54
--- /dev/null
+++ b/examples/network/network.pro
@@ -0,0 +1,25 @@
+TEMPLATE = subdirs
+SUBDIRS = blockingfortuneclient \
+ broadcastreceiver \
+ broadcastsender \
+ network-chat \
+ download \
+ downloadmanager \
+ fortuneclient \
+ fortuneserver \
+ ftp \
+ http \
+ loopback \
+ threadedfortuneserver \
+ torrent
+
+symbian: SUBDIRS = ftp
+
+contains(QT_CONFIG, openssl):SUBDIRS += securesocketclient
+
+# install
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS network.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/network
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/securesocketclient/certificateinfo.cpp b/examples/network/securesocketclient/certificateinfo.cpp
new file mode 100644
index 0000000000..d9be2e3c28
--- /dev/null
+++ b/examples/network/securesocketclient/certificateinfo.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..dc6a200785
--- /dev/null
+++ b/examples/network/securesocketclient/certificateinfo.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..200aa267f3
--- /dev/null
+++ b/examples/network/securesocketclient/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..166d7ad248
--- /dev/null
+++ b/examples/network/securesocketclient/securesocketclient.pro
@@ -0,0 +1,18 @@
+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]/network/securesocketclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png *.jpg images
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/securesocketclient
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..bf8443da1c
--- /dev/null
+++ b/examples/network/securesocketclient/sslclient.cpp
@@ -0,0 +1,218 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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"));
+ padLock->setCursor(Qt::ArrowCursor);
+ 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..ae208bbaf0
--- /dev/null
+++ b/examples/network/securesocketclient/sslclient.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4161c7fbfb
--- /dev/null
+++ b/examples/network/threadedfortuneserver/dialog.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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;
+ }
+
+ statusLabel->setText(tr("The server is running on port %1.\n"
+ "Run the Fortune Client example now.")
+ .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..5fe1c677fa
--- /dev/null
+++ b/examples/network/threadedfortuneserver/dialog.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e23c899647
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortuneserver.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..2374f85118
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortuneserver.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..8c41076b66
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortunethread.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..e534032d7c
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortunethread.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..51874952f6
--- /dev/null
+++ b/examples/network/threadedfortuneserver/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..94543bfb30
--- /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]/network/threadedfortuneserver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS threadedfortuneserver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/threadedfortuneserver
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/torrent/addtorrentdialog.cpp b/examples/network/torrent/addtorrentdialog.cpp
new file mode 100644
index 0000000000..fb43f5970a
--- /dev/null
+++ b/examples/network/torrent/addtorrentdialog.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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(const QString &)),
+ this, SLOT(setTorrent(const 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..89cb77c816
--- /dev/null
+++ b/examples/network/torrent/addtorrentdialog.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..9311c0c21b
--- /dev/null
+++ b/examples/network/torrent/bencodeparser.cpp
@@ -0,0 +1,235 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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 << qVariantFromValue<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, qVariantFromValue<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..b4fc74b417
--- /dev/null
+++ b/examples/network/torrent/bencodeparser.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..3b78537011
--- /dev/null
+++ b/examples/network/torrent/connectionmanager.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..3b791e3243
--- /dev/null
+++ b/examples/network/torrent/connectionmanager.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..07d5cca695
--- /dev/null
+++ b/examples/network/torrent/filemanager.cpp
@@ -0,0 +1,447 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..05d1f49f8b
--- /dev/null
+++ b/examples/network/torrent/filemanager.h
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..38212546c9
--- /dev/null
+++ b/examples/network/torrent/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QApplication>
+#include <QtCore>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ 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..6ca3247446
--- /dev/null
+++ b/examples/network/torrent/mainwindow.cpp
@@ -0,0 +1,713 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QString &)),
+ this, SLOT(acceptFileDrop(const 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..32497818d6
--- /dev/null
+++ b/examples/network/torrent/mainwindow.h
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..03d824c196
--- /dev/null
+++ b/examples/network/torrent/metainfo.cpp
@@ -0,0 +1,218 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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 = qVariantValue<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 = qVariantValue<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..de60b999cc
--- /dev/null
+++ b/examples/network/torrent/metainfo.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e79184b471
--- /dev/null
+++ b/examples/network/torrent/peerwireclient.cpp
@@ -0,0 +1,665 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..a21faa272f
--- /dev/null
+++ b/examples/network/torrent/peerwireclient.h
@@ -0,0 +1,210 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..243d897e9c
--- /dev/null
+++ b/examples/network/torrent/ratecontroller.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..fb22159c08
--- /dev/null
+++ b/examples/network/torrent/ratecontroller.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..bfd576776e
--- /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]/network/torrent
+sources.files = $$SOURCES $$HEADERS $$RESOURCES torrent.pro *.torrent
+sources.files += icons forms 3rdparty
+sources.path = $$[QT_INSTALL_EXAMPLES]/network/torrent
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
new file mode 100644
index 0000000000..e8473bb1de
--- /dev/null
+++ b/examples/network/torrent/torrentclient.cpp
@@ -0,0 +1,1529 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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, const QByteArray &)),
+ this, SLOT(sendToPeer(int, int, int, const 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(const QList<TorrentPeer> &)),
+ this, SLOT(addToPeerList(const 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(const QBitArray &)),
+ this, SLOT(peerPiecesAvailable(const QBitArray &)));
+ connect(client, SIGNAL(blockRequested(int, int, int)),
+ this, SLOT(peerRequestsBlock(int, int, int)));
+ connect(client, SIGNAL(blockReceived(int, int, const QByteArray &)),
+ this, SLOT(blockReceived(int, int, const 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 *occurrances = new int[d->pieceCount];
+ memset(occurrances, 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))
+ ++occurrances[i];
+ }
+ }
+
+ // Find the rarest or most common pieces.
+ int numOccurrances = d->state == WarmingUp ? 0 : 99999;
+ QList<int> piecesReadyForDownload;
+ for (int i = 0; i < d->pieceCount; ++i) {
+ if (d->state == WarmingUp) {
+ // Add common pieces
+ if (occurrances[i] >= numOccurrances
+ && incompletePiecesAvailableToClient.testBit(i)) {
+ if (occurrances[i] > numOccurrances)
+ piecesReadyForDownload.clear();
+ piecesReadyForDownload.append(i);
+ numOccurrances = occurrances[i];
+ }
+ } else {
+ // Add rare pieces
+ if (occurrances[i] <= numOccurrances
+ && incompletePiecesAvailableToClient.testBit(i)) {
+ if (occurrances[i] < numOccurrances)
+ piecesReadyForDownload.clear();
+ piecesReadyForDownload.append(i);
+ numOccurrances = occurrances[i];
+ }
+ }
+ }
+
+ // Select one piece randomly
+ pieceIndex = piecesReadyForDownload.at(qrand() % piecesReadyForDownload.size());
+ delete [] occurrances;
+ } 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..6caaf38deb
--- /dev/null
+++ b/examples/network/torrent/torrentclient.h
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..3087d6a02c
--- /dev/null
+++ b/examples/network/torrent/torrentserver.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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(const QByteArray &)),
+ this, SLOT(processInfoHash(const 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..6ae89e1b92
--- /dev/null
+++ b/examples/network/torrent/torrentserver.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..bda8140058
--- /dev/null
+++ b/examples/network/torrent/trackerclient.cpp
@@ -0,0 +1,237 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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 = qVariantValue<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..f1ce37dbf5
--- /dev/null
+++ b/examples/network/torrent/trackerclient.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..01df1da6bd
--- /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]/opengl/2dpainting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 2dpainting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/2dpainting
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/opengl/2dpainting/glwidget.cpp b/examples/opengl/2dpainting/glwidget.cpp
new file mode 100644
index 0000000000..d5f63d2f17
--- /dev/null
+++ b/examples/opengl/2dpainting/glwidget.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f3a9bd5cd7
--- /dev/null
+++ b/examples/opengl/2dpainting/glwidget.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..8796d87b8e
--- /dev/null
+++ b/examples/opengl/2dpainting/helper.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..1d63cc95e2
--- /dev/null
+++ b/examples/opengl/2dpainting/helper.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..58c970581e
--- /dev/null
+++ b/examples/opengl/2dpainting/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..89d46083ed
--- /dev/null
+++ b/examples/opengl/2dpainting/widget.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f88c676d5e
--- /dev/null
+++ b/examples/opengl/2dpainting/widget.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f55e90ea4f
--- /dev/null
+++ b/examples/opengl/2dpainting/window.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..84a44403d9
--- /dev/null
+++ b/examples/opengl/2dpainting/window.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/framebufferobject/bubbles.svg b/examples/opengl/framebufferobject/bubbles.svg
new file mode 100644
index 0000000000..3d7971d547
--- /dev/null
+++ b/examples/opengl/framebufferobject/bubbles.svg
@@ -0,0 +1,202 @@
+<?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="white" 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 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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,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/framebufferobject/designer.png b/examples/opengl/framebufferobject/designer.png
new file mode 100644
index 0000000000..4f32d57496
--- /dev/null
+++ b/examples/opengl/framebufferobject/designer.png
Binary files differ
diff --git a/examples/opengl/framebufferobject/framebufferobject.pro b/examples/opengl/framebufferobject/framebufferobject.pro
new file mode 100644
index 0000000000..a5927ec120
--- /dev/null
+++ b/examples/opengl/framebufferobject/framebufferobject.pro
@@ -0,0 +1,24 @@
+######################################################################
+# 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 += framebufferobject.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/framebufferobject
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.png *.svg
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/framebufferobject
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
diff --git a/examples/opengl/framebufferobject/framebufferobject.qrc b/examples/opengl/framebufferobject/framebufferobject.qrc
new file mode 100644
index 0000000000..986f1ca385
--- /dev/null
+++ b/examples/opengl/framebufferobject/framebufferobject.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/framebufferobject/glwidget.cpp b/examples/opengl/framebufferobject/glwidget.cpp
new file mode 100644
index 0000000000..d3591d60c9
--- /dev/null
+++ b/examples/opengl/framebufferobject/glwidget.cpp
@@ -0,0 +1,309 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QImage>
+#include "glwidget.h"
+
+#include <math.h>
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers|QGL::AlphaChannel), parent)
+{
+ setWindowTitle(tr("OpenGL framebuffer objects"));
+ makeCurrent();
+ fbo = new QGLFramebufferObject(1024, 1024);
+ 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);
+
+ 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
+}
+
+GLWidget::~GLWidget()
+{
+ delete[] wave;
+ glDeleteLists(tile_list, 1);
+ delete fbo;
+}
+
+void GLWidget::paintEvent(QPaintEvent *)
+{
+ draw();
+}
+
+void GLWidget::draw()
+{
+ QPainter p(this); // used for text overlay
+
+ // save the GL state set for QPainter
+ saveGLState();
+
+ // render the 'bubbles.svg' file into our framebuffer object
+ QPainter fbo_painter(fbo);
+ svg_renderer->render(&fbo_painter);
+ fbo_painter.end();
+
+ // 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());
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glBindTexture(GL_TEXTURE_2D, fbo->texture());
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_MULTISAMPLE);
+ glEnable(GL_CULL_FACE);
+
+ // 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();
+
+ // 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 framebuffer object 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/framebufferobject/glwidget.h b/examples/opengl/framebufferobject/glwidget.h
new file mode 100644
index 0000000000..b64cfa87f2
--- /dev/null
+++ b/examples/opengl/framebufferobject/glwidget.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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;
+
+ QImage logo;
+ QTimeLine *anim;
+ QSvgRenderer *svg_renderer;
+ QGLFramebufferObject *fbo;
+};
+
diff --git a/examples/opengl/framebufferobject/main.cpp b/examples/opengl/framebufferobject/main.cpp
new file mode 100644
index 0000000000..f9af3f906b
--- /dev/null
+++ b/examples/opengl/framebufferobject/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+#include "glwidget.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(framebufferobject);
+
+ QApplication a(argc, argv);
+ if (!QGLFormat::hasOpenGL() || !QGLFramebufferObject::hasOpenGLFramebufferObjects()) {
+ QMessageBox::information(0, "OpenGL framebuffer objects",
+ "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/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..076f98c9b9
--- /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]/opengl/framebufferobject2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES framebufferobject2.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/framebufferobject2
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..24bc2ef240
--- /dev/null
+++ b/examples/opengl/framebufferobject2/glwidget.cpp
@@ -0,0 +1,249 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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.8, 0.8, 0.8, 1.0);
+ 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..e200ac22bc
--- /dev/null
+++ b/examples/opengl/framebufferobject2/glwidget.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..912f4ec66a
--- /dev/null
+++ b/examples/opengl/framebufferobject2/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..71550ac540
--- /dev/null
+++ b/examples/opengl/grabber/glwidget.cpp
@@ -0,0 +1,284 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4e66b1ff9a
--- /dev/null
+++ b/examples/opengl/grabber/glwidget.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..23a0c4a4b6
--- /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]/opengl/grabber
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS grabber.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/grabber
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/opengl/grabber/main.cpp b/examples/opengl/grabber/main.cpp
new file mode 100644
index 0000000000..4856752c8c
--- /dev/null
+++ b/examples/opengl/grabber/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..7e878f9677
--- /dev/null
+++ b/examples/opengl/grabber/mainwindow.cpp
@@ -0,0 +1,207 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+Q"));
+ 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..8f777478c8
--- /dev/null
+++ b/examples/opengl/grabber/mainwindow.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..fbca8292d9
--- /dev/null
+++ b/examples/opengl/hellogl/glwidget.cpp
@@ -0,0 +1,250 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+
+#include <math.h>
+
+#include "glwidget.h"
+
+//! [0]
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(parent)
+{
+ object = 0;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+
+ trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
+ trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
+}
+//! [0]
+
+//! [1]
+GLWidget::~GLWidget()
+{
+ makeCurrent();
+ glDeleteLists(object, 1);
+}
+//! [1]
+
+//! [2]
+QSize GLWidget::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+//! [2]
+
+//! [3]
+QSize GLWidget::sizeHint() const
+//! [3] //! [4]
+{
+ return QSize(400, 400);
+}
+//! [4]
+
+//! [5]
+void GLWidget::setXRotation(int angle)
+{
+ normalizeAngle(&angle);
+ if (angle != xRot) {
+ xRot = angle;
+ emit xRotationChanged(angle);
+ updateGL();
+ }
+}
+//! [5]
+
+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();
+ }
+}
+
+//! [6]
+void GLWidget::initializeGL()
+{
+ qglClearColor(trolltechPurple.dark());
+ object = makeObject();
+ glShadeModel(GL_FLAT);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+}
+//! [6]
+
+//! [7]
+void GLWidget::paintGL()
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glTranslated(0.0, 0.0, -10.0);
+ 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);
+ glCallList(object);
+}
+//! [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();
+ glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
+ 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]
+
+GLuint GLWidget::makeObject()
+{
+ GLuint list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+
+ glBegin(GL_QUADS);
+
+ const double Pi = 3.14159265358979323846;
+ const int NumSectors = 200;
+
+ for (int j = 0; j < 2; ++j) {
+ double r = 0.1 + (j * 0.2);
+
+ for (int i = 0; i < NumSectors; ++i) {
+ double angle1 = (i * 2 * Pi) / NumSectors;
+ GLdouble x5 = (r + 0.1) * sin(angle1);
+ GLdouble y5 = (r + 0.1) * cos(angle1);
+ GLdouble x6 = r * sin(angle1);
+ GLdouble y6 = r * cos(angle1);
+
+ double angle2 = ((i + 1) * 2 * Pi) / NumSectors;
+ GLdouble x7 = r * sin(angle2);
+ GLdouble y7 = r * cos(angle2);
+ GLdouble x8 = (r + 0.1) * sin(angle2);
+ GLdouble y8 = (r + 0.1) * cos(angle2);
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+ }
+
+ glEnd();
+
+ glEndList();
+ return list;
+}
+
+void GLWidget::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
+ GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
+{
+ qglColor(trolltechGreen);
+
+ glVertex3d(x1, y1, -0.05);
+ glVertex3d(x2, y2, -0.05);
+ glVertex3d(x3, y3, -0.05);
+ glVertex3d(x4, y4, -0.05);
+
+ glVertex3d(x4, y4, +0.05);
+ glVertex3d(x3, y3, +0.05);
+ glVertex3d(x2, y2, +0.05);
+ glVertex3d(x1, y1, +0.05);
+}
+
+void GLWidget::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
+{
+ qglColor(trolltechGreen.dark(250 + int(100 * x1)));
+
+ glVertex3d(x1, y1, +0.05);
+ glVertex3d(x2, y2, +0.05);
+ glVertex3d(x2, y2, -0.05);
+ glVertex3d(x1, y1, -0.05);
+}
+
+void GLWidget::normalizeAngle(int *angle)
+{
+ while (*angle < 0)
+ *angle += 360 * 16;
+ while (*angle > 360 * 16)
+ *angle -= 360 * 16;
+}
diff --git a/examples/opengl/hellogl/glwidget.h b/examples/opengl/hellogl/glwidget.h
new file mode 100644
index 0000000000..a5f73ee9c5
--- /dev/null
+++ b/examples/opengl/hellogl/glwidget.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+
+//! [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:
+ GLuint makeObject();
+ void quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
+ GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4);
+ void extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);
+ void normalizeAngle(int *angle);
+
+ GLuint object;
+ int xRot;
+ int yRot;
+ int zRot;
+ QPoint lastPos;
+ QColor trolltechGreen;
+ QColor trolltechPurple;
+};
+//! [3]
+
+#endif
diff --git a/examples/opengl/hellogl/hellogl.pro b/examples/opengl/hellogl/hellogl.pro
new file mode 100644
index 0000000000..77034cc1f0
--- /dev/null
+++ b/examples/opengl/hellogl/hellogl.pro
@@ -0,0 +1,14 @@
+HEADERS = glwidget.h \
+ window.h
+SOURCES = glwidget.cpp \
+ main.cpp \
+ window.cpp
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellogl.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/opengl/hellogl/main.cpp b/examples/opengl/hellogl/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/opengl/hellogl/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/opengl/hellogl/window.cpp b/examples/opengl/hellogl/window.cpp
new file mode 100644
index 0000000000..82031ee013
--- /dev/null
+++ b/examples/opengl/hellogl/window.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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]
diff --git a/examples/opengl/hellogl/window.h b/examples/opengl/hellogl/window.h
new file mode 100644
index 0000000000..b20f8a8e13
--- /dev/null
+++ b/examples/opengl/hellogl/window.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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();
+
+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..691d314111
--- /dev/null
+++ b/examples/opengl/hellogl_es/bubble.cpp
@@ -0,0 +1,140 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..a32754fe0c
--- /dev/null
+++ b/examples/opengl/hellogl_es/bubble.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/cl_helper.h b/examples/opengl/hellogl_es/cl_helper.h
new file mode 100644
index 0000000000..416c9bbf04
--- /dev/null
+++ b/examples/opengl/hellogl_es/cl_helper.h
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifdef QT_OPENGL_ES_1_CL
+
+//! [0]
+#define FLOAT2X(f) ((int) ( (f) * (65536)))
+#define X2FLOAT(x) ((float)(x) / 65536.0f)
+
+#define f2vt(f) FLOAT2X(f)
+#define vt2f(x) X2FLOAT(x)
+
+#define q_vertexType GLfixed
+#define q_vertexTypeEnum GL_FIXED
+
+#define q_glFog glFogx
+#define q_glFogv glFogxv
+//! [0]
+
+#define q_glLight glLightx
+#define q_glLightv glLightxv
+#define q_glLightModel glLightModelx
+#define q_glLightModelv glLightModelxv
+
+#define q_glAlphaFunc glAlphaFuncx
+
+#define q_glMaterial glMaterialx
+#define q_glMaterialv glMaterialxv
+#define q_glColor4 glColor4x
+
+#define q_glTexParameter glTexParameterx
+#define q_glTexEnv glTexEnvx
+
+#define q_glOrtho glOrthox
+#define q_glFrustum glFrustumx
+
+#define q_glTranslate glTranslatex
+#define q_glScale glScalex
+#define q_glRotate glRotatex
+#define q_glLoadMatrix glLoadMatrixx
+
+#define q_glClearColor glClearColorx
+
+#define q_glMultMatrix glMultMatrixx
+
+#define q_glNormal3 glNormal3x
+
+#define q_glPolygonOffset glPolygonOffsetx
+#define q_glPointSize glPointSizex
+
+//! [1]
+#else
+
+#define f2vt(f) (f)
+#define vt2f(x) (x)
+
+#define q_vertexType GLfloat
+#define q_vertexTypeEnum GL_FLOAT
+
+#define q_glFog glFogf
+#define q_glFogv glFogfv
+//! [1]
+
+#define q_glLight glLightf
+#define q_glLightv glLightfv
+#define q_glLightModel glLightModelf
+#define q_glLightModelv glLightModelfv
+
+#define q_glAlphaFunc glAlphaFuncf
+
+#define q_glMaterial glMaterialf
+#define q_glMaterialv glMaterialfv
+#define q_glColor4 glColor4f
+
+#define q_glTexParameter glTexParameterf
+#define q_glTexEnv glTexEnvf
+
+#define q_glOrtho glOrthof
+#define q_glFrustum glFrustumf
+
+#define q_glTranslate glTranslatef
+#define q_glScale glScalef
+#define q_glRotate glRotatef
+#define q_glLoadMatrix glLoadMatrixf
+
+#define q_glClearColor glClearColor
+
+#define q_glMultMatrix glMultMatrixf
+
+#define q_glNormal3 glNormal3f
+
+#define q_glPolygonOffset glPolygonOffsetf
+#define q_glPointSize glPointSizef
+
+#endif
diff --git a/examples/opengl/hellogl_es/glwidget.cpp b/examples/opengl/hellogl_es/glwidget.cpp
new file mode 100644
index 0000000000..6098c999f6
--- /dev/null
+++ b/examples/opengl/hellogl_es/glwidget.cpp
@@ -0,0 +1,457 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <QPainter>
+#include <math.h>
+
+#include "bubble.h"
+#include "cl_helper.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,q_vertexTypeEnum,0, createdVertices);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glNormalPointer(q_vertexTypeEnum,0,createdNormals);
+ glDrawArrays(GL_TRIANGLES, 0, m_vertexNumber / 3);
+}
+//! [2]
+
+void GLWidget::paintTexturedCube()
+{
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, m_uiTexture);
+ q_vertexType afVertices[] = {
+ f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(0.5),
+ f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(-0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),
+ f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),
+ f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),
+
+ f2vt(0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(0.5),f2vt(0.5),f2vt(-0.5),
+ f2vt(0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5),f2vt(0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(0.5),
+ f2vt(-0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5),f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(-0.5),
+ f2vt(-0.5), f2vt(-0.5), f2vt(0.5), f2vt(-0.5),f2vt(0.5),f2vt(-0.5),f2vt(-0.5),f2vt(0.5),f2vt(0.5),
+
+ f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(-0.5),
+ f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(0.5),
+ f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5),
+ f2vt(0.5), f2vt(-0.5), f2vt(0.5), f2vt(0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(-0.5), f2vt(0.5)
+ };
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3,q_vertexTypeEnum,0,afVertices);
+
+ q_vertexType afTexCoord[] = {
+ f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),
+ f2vt(1.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),
+ f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),
+ f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),
+
+ f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),
+ f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),
+ f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f),
+ f2vt(1.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f),
+
+ f2vt(0.0f),f2vt(1.0f), f2vt(1.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f),
+ f2vt(1.0f),f2vt(0.0f), f2vt(0.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f),
+ f2vt(1.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f),
+ f2vt(0.0f),f2vt(1.0f), f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f)
+ };
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2,q_vertexTypeEnum,0,afTexCoord);
+
+ q_vertexType afNormals[] = {
+
+ f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1),
+ f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1), f2vt(0),f2vt(0),f2vt(-1),
+ f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1),
+ f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1), f2vt(0),f2vt(0),f2vt(1),
+
+ f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0),
+ f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0), f2vt(-1),f2vt(0),f2vt(0),
+ f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0),
+ f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0), f2vt(1),f2vt(0),f2vt(0),
+
+ f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0),
+ f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0), f2vt(0),f2vt(-1),f2vt(0),
+ f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0),
+ f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0), f2vt(0),f2vt(1),f2vt(0)
+ };
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glNormalPointer(q_vertexTypeEnum,0,afNormals);
+
+ glDrawArrays(GL_TRIANGLES, 0, 36);
+}
+
+void GLWidget::initializeGL ()
+{
+ q_glClearColor(f2vt(0.1f), f2vt(0.1f), f2vt(0.2f), f2vt(1.0f));
+
+ glEnable(GL_TEXTURE_2D);
+ glGenTextures(1, &m_uiTexture);
+ m_uiTexture = bindTexture(QImage(":/qt.png"));
+
+ q_glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ q_glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+
+ q_vertexType aLightPosition[] = {f2vt(0.0f),f2vt(0.3f),f2vt(1.0f),f2vt(0.0f)};
+
+ q_glLightv(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
+
+ q_glClearColor(f2vt(0.1f), f2vt(0.1f), f2vt(0.2f), f2vt(1.0f));
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_TEXTURE_2D);
+
+ q_glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ q_glTexParameter(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();
+
+ q_glRotate(f2vt(m_fAngle), f2vt(0.0), f2vt(1.0), f2vt(0.0));
+ q_glRotate(f2vt(m_fAngle), f2vt(1.0), f2vt(0.0), f2vt(0.0));
+ q_glRotate(f2vt(m_fAngle), f2vt(0.0), f2vt(0.0), f2vt(1.0));
+ q_glScale(f2vt(m_fScale), f2vt(m_fScale),f2vt(m_fScale));
+ q_glTranslate(f2vt(0),f2vt(-0.2),f2vt(0));
+
+ q_vertexType matDiff[] = {f2vt(0.40), f2vt(1.0), f2vt(0.0), f2vt(1.0)};
+ q_glMaterialv(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 q_vertexType[m_vertexNumber];
+ createdNormals = new q_vertexType[m_vertexNumber];
+ for (int i = 0;i < m_vertexNumber;i++) {
+ createdVertices[i] = f2vt(vertices.at(i) * 2);
+ createdNormals[i] = f2vt(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..954342e3af
--- /dev/null
+++ b/examples/opengl/hellogl_es/glwidget.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+#include <QTime>
+
+#include "cl_helper.h"
+
+
+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;
+ q_vertexType *createdVertices;
+ q_vertexType *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..7459456785
--- /dev/null
+++ b/examples/opengl/hellogl_es/hellogl_es.pro
@@ -0,0 +1,34 @@
+######################################################################
+# 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
+
+contains(QT_CONFIG,opengles1) {
+ QMAKE_LIBS += "libGLES_CM.lib"
+}
+contains(QT_CONFIG,opengles1cl) {
+ QMAKE_LIBS += "libGLES_CL.lib"
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl_es
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellogl_es.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..feff054783
--- /dev/null
+++ b/examples/opengl/hellogl_es/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..26fbeaa31b
--- /dev/null
+++ b/examples/opengl/hellogl_es/mainwindow.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <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..72b723c7b6
--- /dev/null
+++ b/examples/opengl/hellogl_es/mainwindow.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..691d314111
--- /dev/null
+++ b/examples/opengl/hellogl_es2/bubble.cpp
@@ -0,0 +1,140 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..a32754fe0c
--- /dev/null
+++ b/examples/opengl/hellogl_es2/bubble.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..213c5b2a36
--- /dev/null
+++ b/examples/opengl/hellogl_es2/glwidget.cpp
@@ -0,0 +1,642 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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;
+}
+
+inline void IdentityMatrix(GLfloat *m)
+{
+ m[0 * 4 + 0] = 1.0f;
+ m[1 * 4 + 0] = 0.0f;
+ m[2 * 4 + 0] = 0.0f;
+ m[3 * 4 + 0] = 0.0f;
+ m[0 * 4 + 1] = 0.0f;
+ m[1 * 4 + 1] = 1.0f;
+ m[2 * 4 + 1] = 0.0f;
+ m[3 * 4 + 1] = 0.0f;
+ m[0 * 4 + 2] = 0.0f;
+ m[1 * 4 + 2] = 0.0f;
+ m[2 * 4 + 2] = 1.0f;
+ m[3 * 4 + 2] = 0.0f;
+ m[0 * 4 + 3] = 0.0f;
+ m[1 * 4 + 3] = 0.0f;
+ m[2 * 4 + 3] = 0.0f;
+ m[3 * 4 + 3] = 1.0f;
+}
+
+// Adjust a 4x4 matrix to apply a scale.
+inline void ScaleMatrix(GLfloat *m, GLfloat scalex, GLfloat scaley, GLfloat scalez)
+{
+ m[0 * 4 + 0] *= scalex;
+ m[0 * 4 + 1] *= scalex;
+ m[0 * 4 + 2] *= scalex;
+ m[0 * 4 + 3] *= scalex;
+ m[1 * 4 + 0] *= scaley;
+ m[1 * 4 + 1] *= scaley;
+ m[1 * 4 + 2] *= scaley;
+ m[1 * 4 + 3] *= scaley;
+ m[2 * 4 + 0] *= scalez;
+ m[2 * 4 + 1] *= scalez;
+ m[2 * 4 + 2] *= scalez;
+ m[2 * 4 + 3] *= scalez;
+}
+
+// Adjust a 4x4 matrix to apply a translation.
+inline void TranslateMatrix(GLfloat *m, GLfloat translatex, GLfloat translatey, GLfloat translatez)
+{
+ m[3 * 4 + 0] += m[0 * 4 + 0] * translatex + m[1 * 4 + 0] * translatey + m[2 * 4 + 0] * translatez;
+ m[3 * 4 + 1] += m[0 * 4 + 1] * translatex + m[1 * 4 + 1] * translatey + m[2 * 4 + 1] * translatez;
+ m[3 * 4 + 2] += m[0 * 4 + 2] * translatex + m[1 * 4 + 2] * translatey + m[2 * 4 + 2] * translatez;
+ m[3 * 4 + 3] += m[0 * 4 + 3] * translatex + m[1 * 4 + 3] * translatey + m[2 * 4 + 3] * translatez;
+}
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+// Adjust a 4x4 matrix to apply a rotation.
+inline void RotateMatrix(GLfloat *m, GLfloat angle, GLfloat vx, GLfloat vy, GLfloat vz)
+{
+ GLfloat len = sqrt(vx * vx + vy * vy + vz * vz);
+ if (len != 0) {
+ vx /= len;
+ vy /= len;
+ vz /= len;
+ }
+
+ GLfloat c, s, ic;
+ c = cos(angle * M_PI / 180.0);
+ s = sin(angle * M_PI / 180.0);
+ ic = 1.0f - c;
+
+ GLfloat rot[16];
+ rot[0 * 4 + 0] = vx * vx * ic + c;
+ rot[1 * 4 + 0] = vx * vy * ic - vz * s;
+ rot[2 * 4 + 0] = vx * vz * ic + vy * s;
+ rot[3 * 4 + 0] = 0.0f;
+ rot[0 * 4 + 1] = vy * vx * ic + vz * s;
+ rot[1 * 4 + 1] = vy * vy * ic + c;
+ rot[2 * 4 + 1] = vy * vz * ic - vx * s;
+ rot[3 * 4 + 1] = 0.0f;
+ rot[0 * 4 + 2] = vx * vz * ic - vy * s;
+ rot[1 * 4 + 2] = vy * vz * ic + vx * s;
+ rot[2 * 4 + 2] = vz * vz * ic + c;
+ rot[3 * 4 + 2] = 0.0f;
+ rot[0 * 4 + 3] = 0.0f;
+ rot[1 * 4 + 3] = 0.0f;
+ rot[2 * 4 + 3] = 0.0f;
+ rot[3 * 4 + 3] = 1.0f;
+
+ GLfloat temp[16];
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ temp[j * 4 + i] = 0.0f;
+ for (int k = 0; k < 4; ++k) {
+ temp[j * 4 + i] += m[k * 4 + i] * rot[j * 4 + k];
+ }
+ }
+ }
+
+ qMemCopy(m, temp, sizeof(temp));
+}
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(parent)
+{
+ qtLogo = true;
+ createdVertices = 0;
+ createdNormals = 0;
+ m_vertexNumber = 0;
+ frames = 0;
+ setAttribute(Qt::WA_PaintOnScreen);
+ setAttribute(Qt::WA_NoSystemBackground);
+ setAutoBufferSwap(false);
+ m_showBubbles = true;
+#ifndef Q_WS_QWS
+ setMinimumSize(300, 250);
+#endif
+}
+
+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;
+}
+
+void GLWidget::paintQtLogo()
+{
+ glDisable(GL_TEXTURE_2D);
+ glVertexAttribPointer(vertexAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdVertices);
+ glEnableVertexAttribArray(vertexAttr1);
+ glVertexAttribPointer(normalAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdNormals);
+ glEnableVertexAttribArray(normalAttr1);
+ glDrawArrays(GL_TRIANGLES, 0, m_vertexNumber / 3);
+ glDisableVertexAttribArray(normalAttr1);
+ glDisableVertexAttribArray(vertexAttr1);
+}
+
+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
+ };
+ glVertexAttribPointer(vertexAttr2, 3, GL_FLOAT, GL_FALSE, 0, afVertices);
+ glEnableVertexAttribArray(vertexAttr2);
+
+ 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
+ };
+ glVertexAttribPointer(texCoordAttr2, 2, GL_FLOAT, GL_FALSE, 0, afTexCoord);
+ glEnableVertexAttribArray(texCoordAttr2);
+
+ 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
+ };
+ glVertexAttribPointer(normalAttr2, 3, GL_FLOAT, GL_FALSE, 0, afNormals);
+ glEnableVertexAttribArray(normalAttr2);
+
+ glUniform1i(textureUniform2, 0); // use texture unit 0
+
+ glDrawArrays(GL_TRIANGLES, 0, 36);
+
+ glDisableVertexAttribArray(vertexAttr2);
+ glDisableVertexAttribArray(normalAttr2);
+ glDisableVertexAttribArray(texCoordAttr2);
+}
+
+static void reportCompileErrors(GLuint shader, const char *src)
+{
+ GLint value = 0;
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &value);
+ bool compiled = (value != 0);
+ value = 0;
+ glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value);
+ if (!compiled && value > 1) {
+ char *log = new char [value];
+ GLint len;
+ glGetShaderInfoLog(shader, value, &len, log);
+ qWarning("%s\n", log);
+ qWarning("when compiling:\n%s\n", src);
+ delete [] log;
+ }
+}
+
+static void reportLinkErrors(GLuint program, const char *vsrc, const char *fsrc)
+{
+ GLint value = 0;
+ glGetProgramiv(program, GL_LINK_STATUS, &value);
+ bool linked = (value != 0);
+ value = 0;
+ glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value);
+ if (!linked && value > 1) {
+ char *log = new char [value];
+ GLint len;
+ glGetProgramInfoLog(program, value, &len, log);
+ qWarning("%s\n", log);
+ qWarning("when linking:\n%s\nwith:\n%s\n", vsrc, fsrc);
+ delete [] log;
+ }
+}
+
+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"));
+
+ GLuint vshader1 = glCreateShader(GL_VERTEX_SHADER);
+ const char *vsrc1[1] = {
+ "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"
+ };
+ glShaderSource(vshader1, 1, vsrc1, 0);
+ glCompileShader(vshader1);
+ reportCompileErrors(vshader1, vsrc1[0]);
+
+ GLuint fshader1 = glCreateShader(GL_FRAGMENT_SHADER);
+ const char *fsrc1[1] = {
+ "varying mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n"
+ };
+ glShaderSource(fshader1, 1, fsrc1, 0);
+ glCompileShader(fshader1);
+ reportCompileErrors(fshader1, fsrc1[0]);
+
+ program1 = glCreateProgram();
+ glAttachShader(program1, vshader1);
+ glAttachShader(program1, fshader1);
+ glLinkProgram(program1);
+ reportLinkErrors(program1, vsrc1[0], fsrc1[0]);
+
+ vertexAttr1 = glGetAttribLocation(program1, "vertex");
+ normalAttr1 = glGetAttribLocation(program1, "normal");
+ matrixUniform1 = glGetUniformLocation(program1, "matrix");
+
+ GLuint vshader2 = glCreateShader(GL_VERTEX_SHADER);
+ const char *vsrc2[1] = {
+ "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"
+ };
+ glShaderSource(vshader2, 1, vsrc2, 0);
+ glCompileShader(vshader2);
+ reportCompileErrors(vshader2, vsrc2[0]);
+
+ GLuint fshader2 = glCreateShader(GL_FRAGMENT_SHADER);
+ const char *fsrc2[1] = {
+ "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"
+ };
+ glShaderSource(fshader2, 1, fsrc2, 0);
+ glCompileShader(fshader2);
+ reportCompileErrors(fshader2, fsrc2[0]);
+
+ program2 = glCreateProgram();
+ glAttachShader(program2, vshader2);
+ glAttachShader(program2, fshader2);
+ glLinkProgram(program2);
+ reportLinkErrors(program2, vsrc2[0], fsrc2[0]);
+
+ vertexAttr2 = glGetAttribLocation(program2, "vertex");
+ normalAttr2 = glGetAttribLocation(program2, "normal");
+ texCoordAttr2 = glGetAttribLocation(program2, "texCoord");
+ matrixUniform2 = glGetUniformLocation(program2, "matrix");
+ textureUniform2 = glGetUniformLocation(program2, "tex");
+
+ 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);
+
+ 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 );
+
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+
+ GLfloat modelview[16];
+ IdentityMatrix(modelview);
+ RotateMatrix(modelview, m_fAngle, 0.0, 1.0, 0.0);
+ RotateMatrix(modelview, m_fAngle, 1.0, 0.0, 0.0);
+ RotateMatrix(modelview, m_fAngle, 0.0, 0.0, 1.0);
+ ScaleMatrix(modelview, m_fScale, m_fScale, m_fScale);
+ TranslateMatrix(modelview, 0, -0.2, 0);
+
+ if (qtLogo) {
+ glUseProgram(program1);
+ glUniformMatrix4fv(matrixUniform1, 1, GL_FALSE, modelview);
+ paintQtLogo();
+ glUseProgram(0);
+ } else {
+ glUseProgram(program2);
+ glUniformMatrix4fv(matrixUniform2, 1, GL_FALSE, modelview);
+ paintTexturedCube();
+ glUseProgram(0);
+ }
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+
+ 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);
+ }
+
+ 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();
+}
+
+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;
+}
+
+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_es2/glwidget.h b/examples/opengl/hellogl_es2/glwidget.h
new file mode 100644
index 0000000000..9a7823a493
--- /dev/null
+++ b/examples/opengl/hellogl_es2/glwidget.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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;
+ GLuint program1;
+ GLuint program2;
+ GLuint vertexAttr1;
+ GLuint normalAttr1;
+ GLuint matrixUniform1;
+ GLuint vertexAttr2;
+ GLuint normalAttr2;
+ GLuint texCoordAttr2;
+ GLuint matrixUniform2;
+ GLuint 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..92b42248de
--- /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]/opengl/hellogl_es2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellogl_es2.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..feff054783
--- /dev/null
+++ b/examples/opengl/hellogl_es2/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..26fbeaa31b
--- /dev/null
+++ b/examples/opengl/hellogl_es2/mainwindow.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <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..72b723c7b6
--- /dev/null
+++ b/examples/opengl/hellogl_es2/mainwindow.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..7b76d86c36
--- /dev/null
+++ b/examples/opengl/opengl.pro
@@ -0,0 +1,31 @@
+TEMPLATE = subdirs
+
+contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles1cl)|contains(QT_CONFIG, opengles2){
+ contains(QT_CONFIG, opengles2) {
+ SUBDIRS = hellogl_es2
+ } else {
+ SUBDIRS = hellogl_es
+ }
+} else {
+ SUBDIRS = 2dpainting \
+ grabber \
+ hellogl \
+ overpainting \
+ pbuffers \
+ framebufferobject2 \
+ samplebuffers \
+ textures
+
+ contains(QT_CONFIG, svg) {
+ SUBDIRS += framebufferobject \
+ pbuffers2
+ }
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS opengl.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/opengl/overpainting/bubble.cpp b/examples/opengl/overpainting/bubble.cpp
new file mode 100644
index 0000000000..8bbe9b0015
--- /dev/null
+++ b/examples/opengl/overpainting/bubble.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7e715503dd
--- /dev/null
+++ b/examples/opengl/overpainting/bubble.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e3a7b1e530
--- /dev/null
+++ b/examples/opengl/overpainting/glwidget.cpp
@@ -0,0 +1,360 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+#include <stdlib.h>
+
+#include <math.h>
+
+#include "bubble.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()));
+
+ object = 0;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+
+ trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
+ trolltechPurple = 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()
+{
+ makeCurrent();
+ glDeleteLists(object, 1);
+}
+//! [1]
+
+void GLWidget::setXRotation(int angle)
+{
+ normalizeAngle(&angle);
+ if (angle != xRot)
+ xRot = angle;
+}
+
+void GLWidget::setYRotation(int angle)
+{
+ normalizeAngle(&angle);
+ if (angle != yRot)
+ yRot = angle;
+}
+
+void GLWidget::setZRotation(int angle)
+{
+ normalizeAngle(&angle);
+ if (angle != zRot)
+ zRot = angle;
+}
+
+//! [2]
+void GLWidget::initializeGL()
+{
+ object = makeObject();
+}
+//! [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(trolltechPurple.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();
+ glTranslated(0.0, 0.0, -10.0);
+ 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);
+ glCallList(object);
+//! [7]
+
+//! [8]
+ 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);
+}
+
+GLuint GLWidget::makeObject()
+{
+ GLuint list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+
+ glEnable(GL_NORMALIZE);
+ glBegin(GL_QUADS);
+
+ static GLfloat logoDiffuseColor[4] = {trolltechGreen.red()/255.0,
+ trolltechGreen.green()/255.0,
+ trolltechGreen.blue()/255.0, 1.0};
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, logoDiffuseColor);
+
+ 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;
+
+ 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 double Pi = 3.14159265358979323846;
+ const int NumSectors = 200;
+
+ 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);
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+
+ glEnd();
+
+ glEndList();
+ return list;
+}
+
+void GLWidget::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
+ GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
+{
+ glNormal3d(0.0, 0.0, -1.0);
+ glVertex3d(x1, y1, -0.05);
+ glVertex3d(x2, y2, -0.05);
+ glVertex3d(x3, y3, -0.05);
+ glVertex3d(x4, y4, -0.05);
+
+ glNormal3d(0.0, 0.0, 1.0);
+ glVertex3d(x4, y4, +0.05);
+ glVertex3d(x3, y3, +0.05);
+ glVertex3d(x2, y2, +0.05);
+ glVertex3d(x1, y1, +0.05);
+}
+
+void GLWidget::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
+{
+ qglColor(trolltechGreen.dark(250 + int(100 * x1)));
+
+ glNormal3d((x1 + x2)/2.0, (y1 + y2)/2.0, 0.0);
+ glVertex3d(x1, y1, +0.05);
+ glVertex3d(x2, y2, +0.05);
+ glVertex3d(x2, y2, -0.05);
+ glVertex3d(x1, y1, -0.05);
+}
+
+void GLWidget::normalizeAngle(int *angle)
+{
+ while (*angle < 0)
+ *angle += 360 * 16;
+ while (*angle > 360 * 16)
+ *angle -= 360 * 16;
+}
+
+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();
+ glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
+ 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..f1b49c1c18
--- /dev/null
+++ b/examples/opengl/overpainting/glwidget.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QBrush>
+#include <QFont>
+#include <QImage>
+#include <QPen>
+#include <QGLWidget>
+#include <QTimer>
+
+class Bubble;
+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:
+ GLuint makeObject();
+ void createBubbles(int number);
+ void drawInstructions(QPainter *painter);
+//! [1]
+ void extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);
+ void normalizeAngle(int *angle);
+ void quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
+ GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4);
+ void setupViewport(int width, int height);
+
+ GLuint object;
+ int xRot;
+ int yRot;
+ int zRot;
+ QPoint lastPos;
+ QColor trolltechGreen;
+ QColor trolltechPurple;
+//! [4]
+ 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..c1b17df90e
--- /dev/null
+++ b/examples/opengl/overpainting/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..3603260258
--- /dev/null
+++ b/examples/opengl/overpainting/overpainting.pro
@@ -0,0 +1,15 @@
+QT += opengl
+
+HEADERS = bubble.h \
+ glwidget.h
+SOURCES = bubble.cpp \
+ glwidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/overpainting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS overpainting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/overpainting
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
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..4dfbcf47be
--- /dev/null
+++ b/examples/opengl/pbuffers/glwidget.cpp
@@ -0,0 +1,260 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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 pbuffer
+ pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
+ timerId = startTimer(20);
+ setWindowTitle(tr("OpenGL pbuffers"));
+}
+
+GLWidget::~GLWidget()
+{
+ pbuffer->releaseFromDynamicTexture();
+ glDeleteTextures(1, &dynamicTexture);
+ glDeleteLists(pbufferList, 1);
+ delete pbuffer;
+}
+
+void GLWidget::initializeGL()
+{
+ glMatrixMode(GL_MODELVIEW);
+
+ glEnable(GL_CULL_FACE);
+ initCommon();
+ initPbuffer();
+
+ 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"));
+}
+
+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()
+{
+ // draw a spinning cube into the pbuffer..
+ pbuffer->makeCurrent();
+ glBindTexture(GL_TEXTURE_2D, cubeTexture);
+ glCallList(pbufferList);
+ glFlush();
+
+ // rendering directly to a texture is not supported on X11 and
+ // some Windows implementations, unfortunately
+ if (!hasDynamicTextureUpdate)
+ pbuffer->updateDynamicTexture(dynamicTexture);
+
+ // ..and use the pbuffer contents as a texture when rendering the
+ // background and the bouncing cubes
+ makeCurrent();
+ glBindTexture(GL_TEXTURE_2D, dynamicTexture);
+ 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.8, 0.8, 0.8, 1.0);
+ glDrawArrays(GL_QUADS, 0, 4);
+ }
+ glTranslatef(-10.0f, 2.0f, 0);
+ }
+ glVertexPointer(3, GL_INT, 0, cubeArray);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ // 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);
+}
+
+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;
+}
+
+void GLWidget::initCommon()
+{
+ 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);
+}
+
+void GLWidget::initPbuffer()
+{
+ // set up the pbuffer context
+ pbuffer->makeCurrent();
+ initCommon();
+
+ glViewport(0, 0, pbuffer->size().width(), pbuffer->size().height());
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1, 1, -1, 1, -99, 99);
+ glTranslatef(-0.5f, -0.5f, 0.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ 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);
+ }
+ glEndList();
+ // 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();
+}
+
diff --git a/examples/opengl/pbuffers/glwidget.h b/examples/opengl/pbuffers/glwidget.h
new file mode 100644
index 0000000000..9f2e86cc2d
--- /dev/null
+++ b/examples/opengl/pbuffers/glwidget.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+ void initCommon();
+ void initPbuffer();
+
+private:
+ GLfloat rot[3], xOffs[3], yOffs[3], xInc[3];
+ GLuint pbufferList;
+ GLuint dynamicTexture;
+ GLuint cubeTexture;
+ int timerId;
+ bool hasDynamicTextureUpdate;
+
+ QGLPixelBuffer *pbuffer;
+};
+
diff --git a/examples/opengl/pbuffers/main.cpp b/examples/opengl/pbuffers/main.cpp
new file mode 100644
index 0000000000..91799e0e6a
--- /dev/null
+++ b/examples/opengl/pbuffers/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+#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..72f20f8690
--- /dev/null
+++ b/examples/opengl/pbuffers/pbuffers.pro
@@ -0,0 +1,13 @@
+HEADERS += glwidget.h
+SOURCES += glwidget.cpp main.cpp
+RESOURCES += pbuffers.qrc
+
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/pbuffers
+sources.files = $$SOURCES $$HEADERS $$RESOURCES pbuffers.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/pbuffers
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..3d7971d547
--- /dev/null
+++ b/examples/opengl/pbuffers2/bubbles.svg
@@ -0,0 +1,202 @@
+<?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="white" 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 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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,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..fa37946303
--- /dev/null
+++ b/examples/opengl/pbuffers2/glwidget.cpp
@@ -0,0 +1,326 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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
+ 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();
+
+ // 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..8058a418a7
--- /dev/null
+++ b/examples/opengl/pbuffers2/glwidget.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..9d03beb7fd
--- /dev/null
+++ b/examples/opengl/pbuffers2/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..7f12483157
--- /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]/opengl/pbuffers2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES pbuffers2.pro *.png *.svg
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/pbuffers2
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..0bc17aa94f
--- /dev/null
+++ b/examples/opengl/samplebuffers/glwidget.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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 trolltechGreen(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0));
+ const double Pi = 3.14159265358979323846;
+ const int NumSectors = 15;
+
+ list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+ {
+ for (int i = 0; i < NumSectors; ++i) {
+ double angle1 = (i * 2 * Pi) / NumSectors;
+ GLdouble x1 = 0.30 * sin(angle1);
+ GLdouble y1 = 0.30 * cos(angle1);
+ GLdouble x2 = 0.20 * sin(angle1);
+ GLdouble y2 = 0.20 * cos(angle1);
+
+ double angle2 = ((i + 1) * 2 * Pi) / NumSectors;
+ GLdouble x3 = 0.20 * sin(angle2);
+ GLdouble y3 = 0.20 * cos(angle2);
+ GLdouble x4 = 0.30 * sin(angle2);
+ GLdouble y4 = 0.30 * cos(angle2);
+
+ qglColor(trolltechGreen);
+ quad(GL_QUADS, x1, y1, x2, y2, x3, y3, x4, y4);
+ qglColor(Qt::black);
+ quad(GL_LINE_LOOP, x1, y1, x2, y2, x3, y3, x4, y4);
+ }
+ }
+ 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..dee739e222
--- /dev/null
+++ b/examples/opengl/samplebuffers/glwidget.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..88a37b4c17
--- /dev/null
+++ b/examples/opengl/samplebuffers/main.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..de09a71e61
--- /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]/opengl/samplebuffers
+sources.files = $$SOURCES $$HEADERS samplebuffers.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/samplebuffers
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
new file mode 100644
index 0000000000..5882373bfc
--- /dev/null
+++ b/examples/opengl/textures/glwidget.cpp
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+
+#include <math.h>
+
+#include "glwidget.h"
+
+GLuint GLWidget::sharedObject = 0;
+int GLWidget::refCount = 0;
+
+GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget)
+ : QGLWidget(parent, shareWidget)
+{
+ clearColor = Qt::black;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+}
+
+GLWidget::~GLWidget()
+{
+ if (--refCount == 0) {
+ makeCurrent();
+ glDeleteLists(sharedObject, 1);
+ }
+}
+
+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()
+{
+ if (!sharedObject)
+ sharedObject = makeObject();
+ ++refCount;
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_TEXTURE_2D);
+}
+
+void GLWidget::paintGL()
+{
+ qglClearColor(clearColor);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glTranslated(0.0, 0.0, -10.0);
+ 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);
+ glCallList(sharedObject);
+}
+
+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();
+ glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+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();
+}
+
+GLuint 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 } }
+ };
+
+
+ GLuint textures[6];
+ for (int j=0; j < 6; ++j)
+ textures[j] = bindTexture(QPixmap(QString(":/images/side%1.png").arg(j + 1)),
+ GL_TEXTURE_2D);
+
+ GLuint list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+ for (int i = 0; i < 6; ++i) {
+ glBindTexture(GL_TEXTURE_2D, textures[i]);
+ glBegin(GL_QUADS);
+ for (int j = 0; j < 4; ++j) {
+ glTexCoord2d(j == 0 || j == 3, j == 0 || j == 1);
+ glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
+ 0.2 * coords[i][j][2]);
+ }
+ glEnd();
+ }
+
+ glEndList();
+ return list;
+}
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
new file mode 100644
index 0000000000..623b301f77
--- /dev/null
+++ b/examples/opengl/textures/glwidget.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+
+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:
+ GLuint makeObject();
+
+ QColor clearColor;
+ QPoint lastPos;
+ int xRot;
+ int yRot;
+ int zRot;
+
+ static GLuint sharedObject;
+ static int refCount;
+};
+
+#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..5129cdaaf4
--- /dev/null
+++ b/examples/opengl/textures/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..086c9ac413
--- /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]/opengl/textures
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS textures.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..a974e68270
--- /dev/null
+++ b/examples/opengl/textures/window.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "glwidget.h"
+#include "window.h"
+
+Window::Window()
+{
+ QGridLayout *mainLayout = new QGridLayout;
+
+ glWidgets[0][0] = 0;
+
+ 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, glWidgets[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..50bb7f07ae
--- /dev/null
+++ b/examples/opengl/textures/window.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/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..df845d9395
--- /dev/null
+++ b/examples/painting/basicdrawing/basicdrawing.pro
@@ -0,0 +1,16 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+RESOURCES = basicdrawing.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/painting/basicdrawing
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS basicdrawing.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting/basicdrawing
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A649 \ No newline at end of file
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..e7c3da4cf6
--- /dev/null
+++ b/examples/painting/basicdrawing/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..22e511f1a5
--- /dev/null
+++ b/examples/painting/basicdrawing/renderarea.cpp
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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]
+ painter.translate(+0.5, +0.5);
+ }
+
+//! [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\nQt Software"));
+ break;
+ case Pixmap:
+ painter.drawPixmap(10, 10, pixmap);
+ }
+//! [12] //! [13]
+ painter.restore();
+ }
+ }
+
+ 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..f59e843ba5
--- /dev/null
+++ b/examples/painting/basicdrawing/renderarea.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..864016247b
--- /dev/null
+++ b/examples/painting/basicdrawing/window.cpp
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7c42aeff56
--- /dev/null
+++ b/examples/painting/basicdrawing/window.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ab62a88c54
--- /dev/null
+++ b/examples/painting/concentriccircles/circlewidget.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c5acaa89de
--- /dev/null
+++ b/examples/painting/concentriccircles/circlewidget.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..bf8398feab
--- /dev/null
+++ b/examples/painting/concentriccircles/concentriccircles.pro
@@ -0,0 +1,15 @@
+HEADERS = circlewidget.h \
+ window.h
+SOURCES = circlewidget.cpp \
+ main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/painting/concentriccircles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS concentriccircles.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting/concentriccircles
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A64A \ No newline at end of file
diff --git a/examples/painting/concentriccircles/main.cpp b/examples/painting/concentriccircles/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/painting/concentriccircles/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..dd5e6e5789
--- /dev/null
+++ b/examples/painting/concentriccircles/window.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..2b3ad67cbb
--- /dev/null
+++ b/examples/painting/concentriccircles/window.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..bc7e0a2dba
--- /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]/painting/fontsampler
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fontsampler.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting/fontsampler
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/painting/fontsampler/main.cpp b/examples/painting/fontsampler/main.cpp
new file mode 100644
index 0000000000..1d51376c06
--- /dev/null
+++ b/examples/painting/fontsampler/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..424f175829
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindow.cpp
@@ -0,0 +1,373 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..25d7730e90
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindow.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "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..c16d85fb3d
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposer.cpp
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e8d039f180
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposer.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..66fcf6ad20
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposition.pro
@@ -0,0 +1,14 @@
+HEADERS = imagecomposer.h
+SOURCES = imagecomposer.cpp \
+ main.cpp
+RESOURCES = imagecomposition.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/painting/imagecomposition
+sources.files = $$SOURCES $$HEADERS $$RESOURCES images *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting/imagecomposition
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A64B \ No newline at end of file
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..34527a479f
--- /dev/null
+++ b/examples/painting/imagecomposition/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..fa8b0abb9d
--- /dev/null
+++ b/examples/painting/painterpaths/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..6c9ba95d61
--- /dev/null
+++ b/examples/painting/painterpaths/painterpaths.pro
@@ -0,0 +1,16 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+unix:!mac:!symbian:LIBS += -lm
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/painting/painterpaths
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS painterpaths.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting/painterpaths
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A64C \ No newline at end of file
diff --git a/examples/painting/painterpaths/renderarea.cpp b/examples/painting/painterpaths/renderarea.cpp
new file mode 100644
index 0000000000..64d149b03a
--- /dev/null
+++ b/examples/painting/painterpaths/renderarea.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..39b7efd477
--- /dev/null
+++ b/examples/painting/painterpaths/renderarea.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..712e961511
--- /dev/null
+++ b/examples/painting/painterpaths/window.cpp
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f2ad0ae0fd
--- /dev/null
+++ b/examples/painting/painterpaths/window.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..8ce3460220
--- /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 += svgviewer
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/painting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS painting.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/painting/svgviewer/files/bubbles.svg b/examples/painting/svgviewer/files/bubbles.svg
new file mode 100644
index 0000000000..3d7971d547
--- /dev/null
+++ b/examples/painting/svgviewer/files/bubbles.svg
@@ -0,0 +1,202 @@
+<?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="white" 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 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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"
+ 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,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/painting/svgviewer/files/cubic.svg b/examples/painting/svgviewer/files/cubic.svg
new file mode 100644
index 0000000000..492bb72b8b
--- /dev/null
+++ b/examples/painting/svgviewer/files/cubic.svg
@@ -0,0 +1,77 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="10cm" height="10cm" viewBox="0 0 1000 1000"
+ xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny">
+ <title>Example cubic02 - cubic Bezier commands in path data</title>
+ <desc>Picture showing examples of "C" and "S" commands,
+ along with annotations showing the control points
+ and end points</desc>
+
+ <rect fill="none" stroke="blue" stroke-width="1" x="1" y="1" width="998" height="998" />
+
+ <!-- Path 1 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="100,200 100,100" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="400,100 400,200" />
+ <path fill="none" stroke="red" stroke-width="5" d="M100,200 C100,100 400,100 400,200" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="200" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="200" r="10" />
+ <circle class="CtlPoint" cx="100" cy="100" r="10" />
+ <circle class="CtlPoint" cx="400" cy="100" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="275">M100,200 C100,100 400,100 400,200</text>
+
+ <!-- Path 2 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="100,500 25,400" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="475,400 400,500" />
+ <path fill="none" stroke="red" stroke-width="5" d="M100,500 C25,400 475,400 400,500" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="500" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="500" r="10" />
+ <circle fill="#888888" stroke="none" cx="25" cy="400" r="10" />
+ <circle fill="#888888" stroke="none" cx="475" cy="400" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="575">M100,500 C25,400 475,400 400,500</text>
+
+ <!-- Path 3 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="100,800 175,700" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="325,700 400,800" />
+ <path fill="none" stroke="red" stroke-width="5" d="M100,800 C175,700 325,700 400,800" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="100" cy="800" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="400" cy="800" r="10" />
+ <circle fill="#888888" stroke="none" cx="175" cy="700" r="10" />
+ <circle fill="#888888" stroke="none" cx="325" cy="700" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="250" y="875">M100,800 C175,700 325,700 400,800</text>
+
+ <!-- Path 4 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="600,200 675,100" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="975,100 900,200" />
+ <path fill="none" stroke="red" stroke-width="5" d="M600,200 C675,100 975,100 900,200" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="200" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="200" r="10" />
+ <circle fill="#888888" stroke="none" cx="675" cy="100" r="10" />
+ <circle fill="#888888" stroke="none" cx="975" cy="100" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="275">M600,200 C675,100 975,100 900,200</text>
+
+ <!-- Path 5 -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="600,500 600,350" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="900,650 900,500" />
+ <path fill="none" stroke="red" stroke-width="5" d="M600,500 C600,350 900,650 900,500" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="500" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="500" r="10" />
+ <circle fill="#888888" stroke="none" cx="600" cy="350" r="10" />
+ <circle fill="#888888" stroke="none" cx="900" cy="650" r="10" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="575">M600,500 C600,350 900,650 900,500</text>
+
+ <!-- Path 6 (C and S command) -->
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="600,800 625,700" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="725,700 750,800" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="750,800 775,900" />
+ <polyline fill="none" stroke="#888888" stroke-width="2" points="875,900 900,800" />
+ <path fill="none" stroke="red" stroke-width="5" d="M600,800 C625,700 725,700 750,800
+ S875,900 900,800" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="600" cy="800" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="750" cy="800" r="10" />
+ <circle fill="none" stroke="#888888" stroke-width="2" cx="900" cy="800" r="10" />
+ <circle fill="#888888" stroke="none" cx="625" cy="700" r="10" />
+ <circle fill="#888888" stroke="none" cx="725" cy="700" r="10" />
+ <circle fill="#888888" stroke="none" cx="875" cy="900" r="10" />
+ <circle fill="none" stroke="blue" stroke-width="4" cx="775" cy="900" r="9" />
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="945">M600,800 C625,700 725,700 750,800</text>
+ <text text-anchor="middle" font-size="22" font-family="Verdana" x="750" y="975">S875,900 900,800</text>
+</svg>
diff --git a/examples/painting/svgviewer/files/spheres.svg b/examples/painting/svgviewer/files/spheres.svg
new file mode 100644
index 0000000000..b23164bce3
--- /dev/null
+++ b/examples/painting/svgviewer/files/spheres.svg
@@ -0,0 +1,72 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="8cm" height="8cm" viewBox="0 0 400 400"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink/"
+ baseProfile="tiny" version="1.2">
+ <title>Spheres</title>
+ <desc>Gradient filled spheres with different colors.</desc>
+ <defs>
+ <!-- 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="white" stop-opacity="0.0" />
+ </radialGradient>
+
+ <!-- Define a shadow for each sphere. -->
+ <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" />
+ </defs>
+ <g fill="#ffee99" stroke="none" >
+ <rect x="0" y="0" width="400" height="400" />
+ </g>
+ <g fill="white" stroke="none" >
+ <rect x="0" y="175" width="400" height="225" />
+ </g>
+ <g transform="translate(200,175)">
+ <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,240)">
+ <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,275)">
+ <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,325)">
+ <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>
+</svg>
diff --git a/examples/painting/svgviewer/main.cpp b/examples/painting/svgviewer/main.cpp
new file mode 100644
index 0000000000..18520f74fd
--- /dev/null
+++ b/examples/painting/svgviewer/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QString>
+#ifndef QT_NO_OPENGL
+#include <QGLFormat>
+#endif
+
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(svgviewer);
+
+ QApplication app(argc, argv);
+
+ MainWindow window;
+ if (argc == 2)
+ window.openFile(argv[1]);
+ else
+ window.openFile(":/files/bubbles.svg");
+ window.show();
+ return app.exec();
+}
diff --git a/examples/painting/svgviewer/mainwindow.cpp b/examples/painting/svgviewer/mainwindow.cpp
new file mode 100644
index 0000000000..22393eb723
--- /dev/null
+++ b/examples/painting/svgviewer/mainwindow.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QtGui>
+
+#include "svgview.h"
+
+MainWindow::MainWindow()
+ : QMainWindow()
+ , m_view(new SvgView)
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
+
+ menuBar()->addMenu(fileMenu);
+
+ QMenu *viewMenu = new QMenu(tr("&View"), this);
+ m_backgroundAction = viewMenu->addAction(tr("&Background"));
+ m_backgroundAction->setEnabled(false);
+ m_backgroundAction->setCheckable(true);
+ m_backgroundAction->setChecked(false);
+ connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool)));
+
+ m_outlineAction = viewMenu->addAction(tr("&Outline"));
+ m_outlineAction->setEnabled(false);
+ m_outlineAction->setCheckable(true);
+ m_outlineAction->setChecked(true);
+ connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool)));
+
+ menuBar()->addMenu(viewMenu);
+
+ QMenu *rendererMenu = new QMenu(tr("&Renderer"), this);
+ m_nativeAction = rendererMenu->addAction(tr("&Native"));
+ m_nativeAction->setCheckable(true);
+ m_nativeAction->setChecked(true);
+#ifndef QT_NO_OPENGL
+ m_glAction = rendererMenu->addAction(tr("&OpenGL"));
+ m_glAction->setCheckable(true);
+#endif
+ m_imageAction = rendererMenu->addAction(tr("&Image"));
+ m_imageAction->setCheckable(true);
+
+#ifndef QT_NO_OPENGL
+ rendererMenu->addSeparator();
+ m_highQualityAntialiasingAction = rendererMenu->addAction(tr("&High Quality Antialiasing"));
+ m_highQualityAntialiasingAction->setEnabled(false);
+ m_highQualityAntialiasingAction->setCheckable(true);
+ m_highQualityAntialiasingAction->setChecked(false);
+ connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), m_view, SLOT(setHighQualityAntialiasing(bool)));
+#endif
+
+ QActionGroup *rendererGroup = new QActionGroup(this);
+ rendererGroup->addAction(m_nativeAction);
+#ifndef QT_NO_OPENGL
+ rendererGroup->addAction(m_glAction);
+#endif
+ rendererGroup->addAction(m_imageAction);
+
+ menuBar()->addMenu(rendererMenu);
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(rendererGroup, SIGNAL(triggered(QAction *)),
+ this, SLOT(setRenderer(QAction *)));
+
+ setCentralWidget(m_view);
+ setWindowTitle(tr("SVG Viewer"));
+}
+
+void MainWindow::openFile(const QString &path)
+{
+ QString fileName;
+ if (path.isNull())
+ fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
+ m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)");
+ else
+ fileName = path;
+
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.exists()) {
+ QMessageBox::critical(this, tr("Open SVG File"),
+ QString("Could not open file '%1'.").arg(fileName));
+
+ m_outlineAction->setEnabled(false);
+ m_backgroundAction->setEnabled(false);
+ return;
+ }
+
+ m_view->openFile(file);
+
+ if (!fileName.startsWith(":/")) {
+ m_currentPath = fileName;
+ setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath));
+ }
+
+ m_outlineAction->setEnabled(true);
+ m_backgroundAction->setEnabled(true);
+
+ resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
+ }
+}
+
+void MainWindow::setRenderer(QAction *action)
+{
+#ifndef QT_NO_OPENGL
+ m_highQualityAntialiasingAction->setEnabled(false);
+#endif
+
+ if (action == m_nativeAction)
+ m_view->setRenderer(SvgView::Native);
+#ifndef QT_NO_OPENGL
+ else if (action == m_glAction) {
+ m_highQualityAntialiasingAction->setEnabled(true);
+ m_view->setRenderer(SvgView::OpenGL);
+ }
+#endif
+ else if (action == m_imageAction) {
+ m_view->setRenderer(SvgView::Image);
+ }
+}
diff --git a/examples/painting/svgviewer/mainwindow.h b/examples/painting/svgviewer/mainwindow.h
new file mode 100644
index 0000000000..5df430b8b7
--- /dev/null
+++ b/examples/painting/svgviewer/mainwindow.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QString>
+
+class SvgView;
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QGraphicsView;
+class QGraphicsScene;
+class QGraphicsRectItem;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void openFile(const QString &path = QString());
+ void setRenderer(QAction *action);
+
+private:
+ QAction *m_nativeAction;
+ QAction *m_glAction;
+ QAction *m_imageAction;
+ QAction *m_highQualityAntialiasingAction;
+ QAction *m_backgroundAction;
+ QAction *m_outlineAction;
+
+ SvgView *m_view;
+
+ QString m_currentPath;
+};
+
+#endif
diff --git a/examples/painting/svgviewer/svgview.cpp b/examples/painting/svgviewer/svgview.cpp
new file mode 100644
index 0000000000..daf7bf0c1b
--- /dev/null
+++ b/examples/painting/svgviewer/svgview.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "svgview.h"
+
+#include <QFile>
+#include <QWheelEvent>
+#include <QMouseEvent>
+#include <QGraphicsRectItem>
+#include <QGraphicsSvgItem>
+#include <QPaintEvent>
+#include <qmath.h>
+
+#ifndef QT_NO_OPENGL
+#include <QGLWidget>
+#endif
+
+SvgView::SvgView(QWidget *parent)
+ : QGraphicsView(parent)
+ , m_renderer(Native)
+ , m_svgItem(0)
+ , m_backgroundItem(0)
+ , m_outlineItem(0)
+{
+ setScene(new QGraphicsScene(this));
+ setTransformationAnchor(AnchorUnderMouse);
+ setDragMode(ScrollHandDrag);
+
+ // Prepare background check-board pattern
+ QPixmap tilePixmap(64, 64);
+ tilePixmap.fill(Qt::white);
+ QPainter tilePainter(&tilePixmap);
+ QColor color(220, 220, 220);
+ tilePainter.fillRect(0, 0, 32, 32, color);
+ tilePainter.fillRect(32, 32, 32, 32, color);
+ tilePainter.end();
+
+ setBackgroundBrush(tilePixmap);
+}
+
+void SvgView::drawBackground(QPainter *p, const QRectF &)
+{
+ p->save();
+ p->resetTransform();
+ p->drawTiledPixmap(viewport()->rect(), backgroundBrush().texture());
+ p->restore();
+}
+
+void SvgView::openFile(const QFile &file)
+{
+ if (!file.exists())
+ return;
+
+ QGraphicsScene *s = scene();
+
+ bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : false);
+ bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : true);
+
+ s->clear();
+ resetTransform();
+
+ m_svgItem = new QGraphicsSvgItem(file.fileName());
+ m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
+ m_svgItem->setCacheMode(QGraphicsItem::NoCache);
+ m_svgItem->setZValue(0);
+
+ m_backgroundItem = new QGraphicsRectItem(m_svgItem->boundingRect());
+ m_backgroundItem->setBrush(Qt::white);
+ m_backgroundItem->setPen(Qt::NoPen);
+ m_backgroundItem->setVisible(drawBackground);
+ m_backgroundItem->setZValue(-1);
+
+ m_outlineItem = new QGraphicsRectItem(m_svgItem->boundingRect());
+ QPen outline(Qt::black, 2, Qt::DashLine);
+ outline.setCosmetic(true);
+ m_outlineItem->setPen(outline);
+ m_outlineItem->setBrush(Qt::NoBrush);
+ m_outlineItem->setVisible(drawOutline);
+ m_outlineItem->setZValue(1);
+
+ s->addItem(m_backgroundItem);
+ s->addItem(m_svgItem);
+ s->addItem(m_outlineItem);
+
+ s->setSceneRect(m_outlineItem->boundingRect().adjusted(-10, -10, 10, 10));
+}
+
+void SvgView::setRenderer(RendererType type)
+{
+ m_renderer = type;
+
+ if (m_renderer == OpenGL) {
+#ifndef QT_NO_OPENGL
+ setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+#endif
+ } else {
+ setViewport(new QWidget);
+ }
+}
+
+void SvgView::setHighQualityAntialiasing(bool highQualityAntialiasing)
+{
+#ifndef QT_NO_OPENGL
+ setRenderHint(QPainter::HighQualityAntialiasing, highQualityAntialiasing);
+#else
+ Q_UNUSED(highQualityAntialiasing);
+#endif
+}
+
+void SvgView::setViewBackground(bool enable)
+{
+ if (!m_backgroundItem)
+ return;
+
+ m_backgroundItem->setVisible(enable);
+}
+
+void SvgView::setViewOutline(bool enable)
+{
+ if (!m_outlineItem)
+ return;
+
+ m_outlineItem->setVisible(enable);
+}
+
+void SvgView::paintEvent(QPaintEvent *event)
+{
+ if (m_renderer == Image) {
+ if (m_image.size() != viewport()->size()) {
+ m_image = QImage(viewport()->size(), QImage::Format_ARGB32_Premultiplied);
+ }
+
+ QPainter imagePainter(&m_image);
+ QGraphicsView::render(&imagePainter);
+ imagePainter.end();
+
+ QPainter p(viewport());
+ p.drawImage(0, 0, m_image);
+
+ } else {
+ QGraphicsView::paintEvent(event);
+ }
+}
+
+void SvgView::wheelEvent(QWheelEvent *event)
+{
+ qreal factor = qPow(1.2, event->delta() / 240.0);
+ scale(factor, factor);
+ event->accept();
+}
+
diff --git a/examples/painting/svgviewer/svgview.h b/examples/painting/svgviewer/svgview.h
new file mode 100644
index 0000000000..993268a897
--- /dev/null
+++ b/examples/painting/svgviewer/svgview.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGVIEW_H
+#define SVGVIEW_H
+
+#include <QGraphicsView>
+
+QT_BEGIN_NAMESPACE
+class QWheelEvent;
+class QPaintEvent;
+class QFile;
+QT_END_NAMESPACE
+
+class SvgView : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ enum RendererType { Native, OpenGL, Image };
+
+ SvgView(QWidget *parent = 0);
+
+ void openFile(const QFile &file);
+ void setRenderer(RendererType type = Native);
+ void drawBackground(QPainter *p, const QRectF &rect);
+
+public slots:
+ void setHighQualityAntialiasing(bool highQualityAntialiasing);
+ void setViewBackground(bool enable);
+ void setViewOutline(bool enable);
+
+protected:
+ void wheelEvent(QWheelEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+private:
+ RendererType m_renderer;
+
+ QGraphicsItem *m_svgItem;
+ QGraphicsRectItem *m_backgroundItem;
+ QGraphicsRectItem *m_outlineItem;
+
+ QImage m_image;
+};
+#endif // SVGVIEW_H
diff --git a/examples/painting/svgviewer/svgviewer.pro b/examples/painting/svgviewer/svgviewer.pro
new file mode 100644
index 0000000000..523dcf68a7
--- /dev/null
+++ b/examples/painting/svgviewer/svgviewer.pro
@@ -0,0 +1,32 @@
+HEADERS = mainwindow.h \
+ svgview.h
+RESOURCES = svgviewer.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ svgview.cpp
+QT += svg xml
+
+contains(QT_CONFIG, opengl): QT += opengl
+
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/painting/svgviewer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES svgviewer.pro files
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting/svgviewer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+wince*: {
+ addFiles.sources = files\*.svg
+ addFiles.path = \My Documents
+ DEPLOYMENT += addFiles
+}
+
+symbian: {
+ TARGET.UID3 = 0xA000A64E
+ addFiles.sources = files\*.svg
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+}
diff --git a/examples/painting/svgviewer/svgviewer.qrc b/examples/painting/svgviewer/svgviewer.qrc
new file mode 100644
index 0000000000..db611f51fd
--- /dev/null
+++ b/examples/painting/svgviewer/svgviewer.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>files/bubbles.svg</file>
+</qresource>
+</RCC>
+
diff --git a/examples/painting/transformations/main.cpp b/examples/painting/transformations/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/painting/transformations/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..a25869b82b
--- /dev/null
+++ b/examples/painting/transformations/renderarea.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..04ab0d318d
--- /dev/null
+++ b/examples/painting/transformations/renderarea.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..6e4fe4f0b3
--- /dev/null
+++ b/examples/painting/transformations/transformations.pro
@@ -0,0 +1,15 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/painting/transformations
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS transformations.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/painting/transformations
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A64D \ No newline at end of file
diff --git a/examples/painting/transformations/window.cpp b/examples/painting/transformations/window.cpp
new file mode 100644
index 0000000000..7d8365418c
--- /dev/null
+++ b/examples/painting/transformations/window.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f4f05d6993
--- /dev/null
+++ b/examples/painting/transformations/window.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/phonon/README b/examples/phonon/README
new file mode 100644
index 0000000000..d0f4462c1f
--- /dev/null
+++ b/examples/phonon/README
@@ -0,0 +1,39 @@
+Qt usese the Phonon cross-platform multimedia framework to play common
+multimedia formats.
+
+Applications can be written to take advantage of the native multimedia
+technologies on each platform via a consistent cross-platform Qt API.
+
+
+Some of the examples in this directory can be run from the example launcher;
+others can only be used from within Qt Designer.
+
+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/phonon/capabilities/capabilities.pro b/examples/phonon/capabilities/capabilities.pro
new file mode 100644
index 0000000000..29d75012b9
--- /dev/null
+++ b/examples/phonon/capabilities/capabilities.pro
@@ -0,0 +1,11 @@
+QT += phonon
+
+HEADERS += window.h
+SOURCES += window.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/phonon/capabilities
+sources.files = $$SOURCES $$HEADERS capabilities.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/phonon/capabilities
+INSTALLS += target sources
diff --git a/examples/phonon/capabilities/main.cpp b/examples/phonon/capabilities/main.cpp
new file mode 100644
index 0000000000..a746925f3b
--- /dev/null
+++ b/examples/phonon/capabilities/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [everything]
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+ app.setApplicationName("Phonon Capabilities Example");
+
+ Window window;
+ window.show();
+
+ return app.exec();
+}
+//! [everything]
+
diff --git a/examples/phonon/capabilities/window.cpp b/examples/phonon/capabilities/window.cpp
new file mode 100644
index 0000000000..920e3e01ab
--- /dev/null
+++ b/examples/phonon/capabilities/window.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [constructor]
+Window::Window()
+{
+ setupUi();
+ updateWidgets();
+
+ connect(Phonon::BackendCapabilities::notifier(),
+ SIGNAL(capabilitiesChanged()), this, SLOT(updateWidgets()));
+ connect(Phonon::BackendCapabilities::notifier(),
+ SIGNAL(availableAudioOutputDevicesChanged()), SLOT(updateWidgets()));
+}
+//! [constructor]
+
+//! [outputDevices]
+void Window::updateWidgets()
+{
+ devicesListView->setModel(new QStandardItemModel());
+ Phonon::ObjectDescriptionModel<Phonon::AudioOutputDeviceType> *model =
+ new Phonon::ObjectDescriptionModel<Phonon::AudioOutputDeviceType>();
+ model->setModelData(Phonon::BackendCapabilities::availableAudioOutputDevices());
+ devicesListView->setModel(model);
+//! [outputDevices]
+
+//! [mimeTypes]
+ mimeListWidget->clear();
+ QStringList mimeTypes =
+ Phonon::BackendCapabilities::availableMimeTypes();
+ foreach (QString mimeType, mimeTypes) {
+ QListWidgetItem *item = new QListWidgetItem(mimeListWidget);
+ item->setText(mimeType);
+ }
+//! [mimeTypes]
+
+//! [effects]
+ effectsTreeWidget->clear();
+ QList<Phonon::EffectDescription> effects =
+ Phonon::BackendCapabilities::availableAudioEffects();
+ foreach (Phonon::EffectDescription effect, effects) {
+ QTreeWidgetItem *item = new QTreeWidgetItem(effectsTreeWidget);
+ item->setText(0, tr("Effect"));
+ item->setText(1, effect.name());
+ item->setText(2, effect.description());
+//! [effects]
+
+//! [effectsParameters]
+ Phonon::Effect *instance = new Phonon::Effect(effect, this);
+ QList<Phonon::EffectParameter> parameters = instance->parameters();
+ for (int i = 0; i < parameters.size(); ++i) {
+ Phonon::EffectParameter parameter = parameters.at(i);
+
+ QVariant defaultValue = parameter.defaultValue();
+ QVariant minimumValue = parameter.minimumValue();
+ QVariant maximumValue = parameter.maximumValue();
+
+ QString valueString = QString("%1 / %2 / %3")
+ .arg(defaultValue.toString()).arg(minimumValue.toString())
+ .arg(maximumValue.toString());
+
+ QTreeWidgetItem *parameterItem = new QTreeWidgetItem(item);
+ parameterItem->setText(0, tr("Parameter"));
+ parameterItem->setText(1, parameter.name());
+ parameterItem->setText(2, parameter.description());
+ parameterItem->setText(3, QVariant::typeToName(parameter.type()));
+ parameterItem->setText(4, valueString);
+ }
+ }
+//! [effectsParameters]
+ for (int i = 0; i < effectsTreeWidget->columnCount(); ++i) {
+ if (i == 0)
+ effectsTreeWidget->setColumnWidth(0, 150);
+ else if (i == 2)
+ effectsTreeWidget->setColumnWidth(2, 350);
+ else
+ effectsTreeWidget->resizeColumnToContents(i);
+ }
+}
+
+void Window::setupUi()
+{
+ setupBackendBox();
+
+ QLayout *layout = new QVBoxLayout;
+ layout->addWidget(backendBox);
+
+ setLayout(layout);
+ setWindowTitle(tr("Backend Capabilities Example"));
+}
+
+void Window::setupBackendBox()
+{
+ backendBox = new QGroupBox(tr("Backend Capabilities"));
+
+ devicesLabel = new QLabel(tr("Available Audio Devices:"));
+ devicesListView = new QListView;
+
+ mimeTypesLabel = new QLabel(tr("Supported MIME Types:"));
+ mimeListWidget = new QListWidget;
+
+ effectsLabel = new QLabel(tr("Available Audio Effects:"));
+
+ QStringList headerLabels;
+ headerLabels << tr("Type") << tr("Name") << tr("Description") <<
+ tr("Value Type") << tr("Default/Min/Max Values");
+
+ effectsTreeWidget = new QTreeWidget;
+ effectsTreeWidget->setHeaderLabels(headerLabels);
+ effectsTreeWidget->setColumnCount(5);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(devicesLabel, 0, 0);
+ layout->addWidget(devicesListView, 1, 0);
+ layout->addWidget(mimeTypesLabel, 0, 1);
+ layout->addWidget(mimeListWidget, 1, 1);
+ layout->addWidget(effectsLabel, 2, 0);
+ layout->addWidget(effectsTreeWidget, 3, 0, 2, 2);
+ layout->setRowStretch(3, 100);
+
+ backendBox = new QGroupBox(tr("Backend Capabilities"));
+ backendBox->setLayout(layout);
+}
+
diff --git a/examples/phonon/capabilities/window.h b/examples/phonon/capabilities/window.h
new file mode 100644
index 0000000000..23121d3084
--- /dev/null
+++ b/examples/phonon/capabilities/window.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+#include <Phonon/AudioOutput>
+#include <Phonon/SeekSlider>
+#include <Phonon/MediaObject>
+#include <Phonon/VolumeSlider>
+#include <Phonon/BackendCapabilities>
+#include <Phonon/Effect>
+#include <Phonon/EffectParameter>
+#include <Phonon/ObjectDescriptionModel>
+#include <QList>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QGroupBox;
+class QPushButton;
+class QLabel;
+class QListWidget;
+class QListView;
+class QTextEdit;
+class QTreeWidget;
+QT_END_NAMESPACE
+
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+//! [windowMembers]
+private slots:
+ void updateWidgets();
+
+private:
+ void setupUi();
+ void setupBackendBox();
+
+ QGroupBox *backendBox;
+
+ QLabel *devicesLabel;
+ QLabel *mimeTypesLabel;
+ QLabel *effectsLabel;
+
+ QListWidget *mimeListWidget;
+ QListView *devicesListView;
+ QTreeWidget *effectsTreeWidget;
+//! [windowMembers]
+};
+
+#endif
+
diff --git a/examples/phonon/musicplayer/main.cpp b/examples/phonon/musicplayer/main.cpp
new file mode 100644
index 0000000000..4a614c8c98
--- /dev/null
+++ b/examples/phonon/musicplayer/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtGui>
+
+#include "mainwindow.h"
+
+//![1]
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+ app.setApplicationName("Music Player");
+ app.setQuitOnLastWindowClosed(true);
+
+ MainWindow window;
+ window.show();
+
+ return app.exec();
+}
+//![1]
diff --git a/examples/phonon/musicplayer/mainwindow.cpp b/examples/phonon/musicplayer/mainwindow.cpp
new file mode 100644
index 0000000000..f50a2bddc4
--- /dev/null
+++ b/examples/phonon/musicplayer/mainwindow.cpp
@@ -0,0 +1,352 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+//![0]
+MainWindow::MainWindow()
+{
+ audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
+ mediaObject = new Phonon::MediaObject(this);
+ metaInformationResolver = new Phonon::MediaObject(this);
+
+ mediaObject->setTickInterval(1000);
+//![0]
+//![2]
+ connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
+ connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
+ this, SLOT(stateChanged(Phonon::State, Phonon::State)));
+ connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
+ this, SLOT(metaStateChanged(Phonon::State, Phonon::State)));
+ connect(mediaObject, SIGNAL(currentSourceChanged(const Phonon::MediaSource &)),
+ this, SLOT(sourceChanged(const Phonon::MediaSource &)));
+ connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
+//![2]
+
+//![1]
+ Phonon::createPath(mediaObject, audioOutput);
+//![1]
+
+ setupActions();
+ setupMenus();
+ setupUi();
+ timeLcd->display("00:00");
+}
+
+//![6]
+void MainWindow::addFiles()
+{
+ QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Music Files"),
+ QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
+
+ if (files.isEmpty())
+ return;
+
+ int index = sources.size();
+ foreach (QString string, files) {
+ Phonon::MediaSource source(string);
+
+ sources.append(source);
+ }
+ if (!sources.isEmpty())
+ metaInformationResolver->setCurrentSource(sources.at(index));
+
+}
+//![6]
+
+void MainWindow::about()
+{
+ QMessageBox::information(this, tr("About Music Player"),
+ tr("The Music Player example shows how to use Phonon - the multimedia"
+ " framework that comes with Qt - to create a simple music player."));
+}
+
+//![9]
+void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
+{
+ switch (newState) {
+ case Phonon::ErrorState:
+ if (mediaObject->errorType() == Phonon::FatalError) {
+ QMessageBox::warning(this, tr("Fatal Error"),
+ mediaObject->errorString());
+ } else {
+ QMessageBox::warning(this, tr("Error"),
+ mediaObject->errorString());
+ }
+ break;
+//![9]
+//![10]
+ case Phonon::PlayingState:
+ playAction->setEnabled(false);
+ pauseAction->setEnabled(true);
+ stopAction->setEnabled(true);
+ break;
+ case Phonon::StoppedState:
+ stopAction->setEnabled(false);
+ playAction->setEnabled(true);
+ pauseAction->setEnabled(false);
+ timeLcd->display("00:00");
+ break;
+ case Phonon::PausedState:
+ pauseAction->setEnabled(false);
+ stopAction->setEnabled(true);
+ playAction->setEnabled(true);
+ break;
+//![10]
+ case Phonon::BufferingState:
+ break;
+ default:
+ ;
+ }
+}
+
+//![11]
+void MainWindow::tick(qint64 time)
+{
+ QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
+
+ timeLcd->display(displayTime.toString("mm:ss"));
+}
+//![11]
+
+//![12]
+void MainWindow::tableClicked(int row, int /* column */)
+{
+ bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
+
+ mediaObject->stop();
+ mediaObject->clearQueue();
+
+ mediaObject->setCurrentSource(sources[row]);
+
+ if (wasPlaying)
+ mediaObject->play();
+ else
+ mediaObject->stop();
+}
+//![12]
+
+//![13]
+void MainWindow::sourceChanged(const Phonon::MediaSource &source)
+{
+ musicTable->selectRow(sources.indexOf(source));
+ timeLcd->display("00:00");
+}
+//![13]
+
+//![14]
+void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */)
+{
+ if (newState == Phonon::ErrorState) {
+ QMessageBox::warning(this, tr("Error opening files"),
+ metaInformationResolver->errorString());
+ while (!sources.isEmpty() &&
+ !(sources.takeLast() == metaInformationResolver->currentSource()));
+ return;
+ }
+
+ if (newState != Phonon::StoppedState && newState != Phonon::PausedState)
+ return;
+
+ if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid)
+ return;
+
+ QMap<QString, QString> metaData = metaInformationResolver->metaData();
+
+ QString title = metaData.value("TITLE");
+ if (title == "")
+ title = metaInformationResolver->currentSource().fileName();
+
+ QTableWidgetItem *titleItem = new QTableWidgetItem(title);
+ titleItem->setFlags(titleItem->flags() ^ Qt::ItemIsEditable);
+ QTableWidgetItem *artistItem = new QTableWidgetItem(metaData.value("ARTIST"));
+ artistItem->setFlags(artistItem->flags() ^ Qt::ItemIsEditable);
+ QTableWidgetItem *albumItem = new QTableWidgetItem(metaData.value("ALBUM"));
+ albumItem->setFlags(albumItem->flags() ^ Qt::ItemIsEditable);
+ QTableWidgetItem *yearItem = new QTableWidgetItem(metaData.value("DATE"));
+ yearItem->setFlags(yearItem->flags() ^ Qt::ItemIsEditable);
+//![14]
+
+ int currentRow = musicTable->rowCount();
+ musicTable->insertRow(currentRow);
+ musicTable->setItem(currentRow, 0, titleItem);
+ musicTable->setItem(currentRow, 1, artistItem);
+ musicTable->setItem(currentRow, 2, albumItem);
+ musicTable->setItem(currentRow, 3, yearItem);
+
+//![15]
+ if (musicTable->selectedItems().isEmpty()) {
+ musicTable->selectRow(0);
+ mediaObject->setCurrentSource(metaInformationResolver->currentSource());
+ }
+
+ Phonon::MediaSource source = metaInformationResolver->currentSource();
+ int index = sources.indexOf(metaInformationResolver->currentSource()) + 1;
+ if (sources.size() > index) {
+ metaInformationResolver->setCurrentSource(sources.at(index));
+ }
+ else {
+ musicTable->resizeColumnsToContents();
+ if (musicTable->columnWidth(0) > 300)
+ musicTable->setColumnWidth(0, 300);
+ }
+}
+//![15]
+
+//![16]
+void MainWindow::aboutToFinish()
+{
+ int index = sources.indexOf(mediaObject->currentSource()) + 1;
+ if (sources.size() > index) {
+ mediaObject->enqueue(sources.at(index));
+ }
+}
+//![16]
+
+void MainWindow::setupActions()
+{
+ playAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), tr("Play"), this);
+ playAction->setShortcut(tr("Crl+P"));
+ playAction->setDisabled(true);
+ pauseAction = new QAction(style()->standardIcon(QStyle::SP_MediaPause), tr("Pause"), this);
+ pauseAction->setShortcut(tr("Ctrl+A"));
+ pauseAction->setDisabled(true);
+ stopAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop), tr("Stop"), this);
+ stopAction->setShortcut(tr("Ctrl+S"));
+ stopAction->setDisabled(true);
+ nextAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipForward), tr("Next"), this);
+ nextAction->setShortcut(tr("Ctrl+N"));
+ previousAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipBackward), tr("Previous"), this);
+ previousAction->setShortcut(tr("Ctrl+R"));
+ addFilesAction = new QAction(tr("Add &Files"), this);
+ addFilesAction->setShortcut(tr("Ctrl+F"));
+ exitAction = new QAction(tr("E&xit"), this);
+ exitAction->setShortcut(tr("Ctrl+X"));
+ aboutAction = new QAction(tr("A&bout"), this);
+ aboutAction->setShortcut(tr("Ctrl+B"));
+ aboutQtAction = new QAction(tr("About &Qt"), this);
+ aboutQtAction->setShortcut(tr("Ctrl+Q"));
+
+//![5]
+ connect(playAction, SIGNAL(triggered()), mediaObject, SLOT(play()));
+ connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
+ connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop()));
+//![5]
+ connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
+ connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+ connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::setupMenus()
+{
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(addFilesAction);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAction);
+
+ QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
+ aboutMenu->addAction(aboutAction);
+ aboutMenu->addAction(aboutQtAction);
+}
+
+//![3]
+void MainWindow::setupUi()
+{
+//![3]
+ QToolBar *bar = new QToolBar;
+
+ bar->addAction(playAction);
+ bar->addAction(pauseAction);
+ bar->addAction(stopAction);
+
+//![4]
+ seekSlider = new Phonon::SeekSlider(this);
+ seekSlider->setMediaObject(mediaObject);
+
+ volumeSlider = new Phonon::VolumeSlider(this);
+ volumeSlider->setAudioOutput(audioOutput);
+//![4]
+ volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
+
+ QLabel *volumeLabel = new QLabel;
+ volumeLabel->setPixmap(QPixmap("images/volume.png"));
+
+ QPalette palette;
+ palette.setBrush(QPalette::Light, Qt::darkGray);
+
+ timeLcd = new QLCDNumber;
+ timeLcd->setPalette(palette);
+
+ QStringList headers;
+ headers << tr("Title") << tr("Artist") << tr("Album") << tr("Year");
+
+ musicTable = new QTableWidget(0, 4);
+ musicTable->setHorizontalHeaderLabels(headers);
+ musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
+ musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+ connect(musicTable, SIGNAL(cellPressed(int, int)),
+ this, SLOT(tableClicked(int, int)));
+
+ QHBoxLayout *seekerLayout = new QHBoxLayout;
+ seekerLayout->addWidget(seekSlider);
+ seekerLayout->addWidget(timeLcd);
+
+ QHBoxLayout *playbackLayout = new QHBoxLayout;
+ playbackLayout->addWidget(bar);
+ playbackLayout->addStretch();
+ playbackLayout->addWidget(volumeLabel);
+ playbackLayout->addWidget(volumeSlider);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(musicTable);
+ mainLayout->addLayout(seekerLayout);
+ mainLayout->addLayout(playbackLayout);
+
+ QWidget *widget = new QWidget;
+ widget->setLayout(mainLayout);
+
+ setCentralWidget(widget);
+ setWindowTitle("Phonon Music Player");
+}
+
diff --git a/examples/phonon/musicplayer/mainwindow.h b/examples/phonon/musicplayer/mainwindow.h
new file mode 100644
index 0000000000..2d4e2977fd
--- /dev/null
+++ b/examples/phonon/musicplayer/mainwindow.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <Phonon/AudioOutput>
+#include <Phonon/SeekSlider>
+#include <Phonon/MediaObject>
+#include <Phonon/VolumeSlider>
+#include <Phonon/BackendCapabilities>
+#include <QList>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QTableWidget;
+class QLCDNumber;
+QT_END_NAMESPACE
+
+//![0]
+
+class MainWindow : public QMainWindow
+{
+//![0]
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+ QSize sizeHint() const {
+ return QSize(500, 300);
+ }
+
+private slots:
+ void addFiles();
+ void about();
+//![1]
+ void stateChanged(Phonon::State newState, Phonon::State oldState);
+ void tick(qint64 time);
+ void sourceChanged(const Phonon::MediaSource &source);
+ void metaStateChanged(Phonon::State newState, Phonon::State oldState);
+ void aboutToFinish();
+ void tableClicked(int row, int column);
+//![1]
+
+private:
+ void setupActions();
+ void setupMenus();
+ void setupUi();
+
+//![2]
+ Phonon::SeekSlider *seekSlider;
+ Phonon::MediaObject *mediaObject;
+ Phonon::MediaObject *metaInformationResolver;
+ Phonon::AudioOutput *audioOutput;
+ Phonon::VolumeSlider *volumeSlider;
+ QList<Phonon::MediaSource> sources;
+//![2]
+
+ QAction *playAction;
+ QAction *pauseAction;
+ QAction *stopAction;
+ QAction *nextAction;
+ QAction *previousAction;
+ QAction *addFilesAction;
+ QAction *exitAction;
+ QAction *aboutAction;
+ QAction *aboutQtAction;
+ QLCDNumber *timeLcd;
+ QTableWidget *musicTable;
+};
+
+#endif
diff --git a/examples/phonon/musicplayer/musicplayer.pro b/examples/phonon/musicplayer/musicplayer.pro
new file mode 100644
index 0000000000..0a93dc26aa
--- /dev/null
+++ b/examples/phonon/musicplayer/musicplayer.pro
@@ -0,0 +1,16 @@
+QT += phonon
+
+HEADERS += mainwindow.h
+SOURCES += main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/phonon/musicplayer
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images
+sources.path = $$[QT_INSTALL_EXAMPLES]/phonon/musicplayer
+INSTALLS += target sources
+
+wince*{
+DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout
+}
+
diff --git a/examples/phonon/phonon.pro b/examples/phonon/phonon.pro
new file mode 100644
index 0000000000..7bb58227ff
--- /dev/null
+++ b/examples/phonon/phonon.pro
@@ -0,0 +1,12 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = musicplayer \
+ capabilities
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/phonon
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS phonon.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/phonon
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qmake/precompile/main.cpp b/examples/qmake/precompile/main.cpp
new file mode 100644
index 0000000000..28eb25ea24
--- /dev/null
+++ b/examples/qmake/precompile/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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..544a94beec
--- /dev/null
+++ b/examples/qmake/precompile/mydialog.cpp
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..948afc22ec
--- /dev/null
+++ b/examples/qmake/precompile/mydialog.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..5d399eb79e
--- /dev/null
+++ b/examples/qmake/precompile/myobject.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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..90fb59d90c
--- /dev/null
+++ b/examples/qmake/precompile/myobject.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..3eaaea9add
--- /dev/null
+++ b/examples/qmake/precompile/stable.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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..c36125857f
--- /dev/null
+++ b/examples/qmake/precompile/util.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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..9edc2afeb3
--- /dev/null
+++ b/examples/qmake/tutorial/hello.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..9e73e47f17
--- /dev/null
+++ b/examples/qmake/tutorial/hello.h
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..0fbeffd4d6
--- /dev/null
+++ b/examples/qmake/tutorial/hellounix.cpp
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// 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..2e966daeb6
--- /dev/null
+++ b/examples/qmake/tutorial/hellowin.cpp
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// 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..e0452e267a
--- /dev/null
+++ b/examples/qmake/tutorial/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..d69adaacf5
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/imagescaling.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "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..46dccf577f
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/imagescaling.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef 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..2040e7c5cf
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/imagescaling.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp imagescaling.cpp
+HEADERS += imagescaling.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/imagescaling
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/imagescaling
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qtconcurrent/imagescaling/main.cpp b/examples/qtconcurrent/imagescaling/main.cpp
new file mode 100644
index 0000000000..c0bf9cec00
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <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..35b484da32
--- /dev/null
+++ b/examples/qtconcurrent/map/main.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..cc80704399
--- /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]/qtconcurrent/map
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/map
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qtconcurrent/progressdialog/main.cpp b/examples/qtconcurrent/progressdialog/main.cpp
new file mode 100644
index 0000000000..249fbc1ee7
--- /dev/null
+++ b/examples/qtconcurrent/progressdialog/main.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 conncect 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..aa6a118aba
--- /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]/qtconcurrent/progressdialog
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/progressdialog
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qtconcurrent/qtconcurrent.pro b/examples/qtconcurrent/qtconcurrent.pro
new file mode 100644
index 0000000000..b21cb17c45
--- /dev/null
+++ b/examples/qtconcurrent/qtconcurrent.pro
@@ -0,0 +1,14 @@
+TEMPLATE = subdirs
+SUBDIRS = imagescaling \
+ map \
+ progressdialog \
+ runfunction \
+ wordcount
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qtconcurrent.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qtconcurrent/runfunction/main.cpp b/examples/qtconcurrent/runfunction/main.cpp
new file mode 100644
index 0000000000..c758f83cd8
--- /dev/null
+++ b/examples/qtconcurrent/runfunction/main.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..58a1375cfe
--- /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]/qtconcurrent/runfunction
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/runfunction
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qtconcurrent/wordcount/main.cpp b/examples/qtconcurrent/wordcount/main.cpp
new file mode 100644
index 0000000000..5008eaff82
--- /dev/null
+++ b/examples/qtconcurrent/wordcount/main.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..581e6c7309
--- /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]/qtconcurrent/wordcount
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/wordcount
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..70115e27aa
--- /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]/qtestlib
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qtestlib.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qtestlib/tutorial1/testqstring.cpp b/examples/qtestlib/tutorial1/testqstring.cpp
new file mode 100644
index 0000000000..cc2e7caa1f
--- /dev/null
+++ b/examples/qtestlib/tutorial1/testqstring.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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..5191a3d59b
--- /dev/null
+++ b/examples/qtestlib/tutorial1/tutorial1.pro
@@ -0,0 +1,12 @@
+SOURCES = testqstring.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C60B \ No newline at end of file
diff --git a/examples/qtestlib/tutorial2/testqstring.cpp b/examples/qtestlib/tutorial2/testqstring.cpp
new file mode 100644
index 0000000000..1c1f6f70e6
--- /dev/null
+++ b/examples/qtestlib/tutorial2/testqstring.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..ae66cace1d
--- /dev/null
+++ b/examples/qtestlib/tutorial2/tutorial2.pro
@@ -0,0 +1,12 @@
+SOURCES = testqstring.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial2
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial2
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C60C \ No newline at end of file
diff --git a/examples/qtestlib/tutorial3/testgui.cpp b/examples/qtestlib/tutorial3/testgui.cpp
new file mode 100644
index 0000000000..8e116f8cdc
--- /dev/null
+++ b/examples/qtestlib/tutorial3/testgui.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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..9fdda2aca1
--- /dev/null
+++ b/examples/qtestlib/tutorial3/tutorial3.pro
@@ -0,0 +1,12 @@
+SOURCES = testgui.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial3
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial3
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C60D \ No newline at end of file
diff --git a/examples/qtestlib/tutorial4/testgui.cpp b/examples/qtestlib/tutorial4/testgui.cpp
new file mode 100644
index 0000000000..f392fec4c7
--- /dev/null
+++ b/examples/qtestlib/tutorial4/testgui.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4cb7bf8a99
--- /dev/null
+++ b/examples/qtestlib/tutorial4/tutorial4.pro
@@ -0,0 +1,12 @@
+SOURCES = testgui.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial4
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial4
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C60E \ No newline at end of file
diff --git a/examples/qtestlib/tutorial5/benchmarking.cpp b/examples/qtestlib/tutorial5/benchmarking.cpp
new file mode 100644
index 0000000000..05ca266e55
--- /dev/null
+++ b/examples/qtestlib/tutorial5/benchmarking.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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/tutorial5.pro b/examples/qtestlib/tutorial5/tutorial5.pro
new file mode 100644
index 0000000000..f98890436f
--- /dev/null
+++ b/examples/qtestlib/tutorial5/tutorial5.pro
@@ -0,0 +1,12 @@
+SOURCES = benchmarking.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial5
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial5
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C60F \ No newline at end of file
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/ahigl/ahigl.pro b/examples/qws/ahigl/ahigl.pro
new file mode 100644
index 0000000000..c8313351e2
--- /dev/null
+++ b/examples/qws/ahigl/ahigl.pro
@@ -0,0 +1,18 @@
+TEMPLATE = lib
+QT += opengl
+CONFIG += plugin
+
+TARGET = qahiglscreen
+
+target.path = $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+HEADERS = qwindowsurface_ahigl_p.h \
+ qscreenahigl_qws.h
+
+SOURCES = qwindowsurface_ahigl.cpp \
+ qscreenahigl_qws.cpp \
+ qscreenahiglplugin.cpp
+
diff --git a/examples/qws/ahigl/qscreenahigl_qws.cpp b/examples/qws/ahigl/qscreenahigl_qws.cpp
new file mode 100644
index 0000000000..b5880b34c5
--- /dev/null
+++ b/examples/qws/ahigl/qscreenahigl_qws.cpp
@@ -0,0 +1,963 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qscreenahigl_qws.h"
+#include "qwindowsurface_ahigl_p.h"
+
+#include <QWSServer>
+#include <QMap>
+#include <QTimer>
+#include <QTimeLine>
+
+#include <qwindowsystem_qws.h>
+#include <private/qwindowsurface_qws_p.h>
+#include <private/qfixed_p.h>
+
+#include <GLES/egl.h>
+#include <GLES/gl.h>
+#include <math.h>
+
+const int animationLength = 1500;
+const int frameSpan = 20;
+
+static GLuint createTexture(const QImage &img);
+
+class QAhiGLCursor : public QScreenCursor
+{
+public:
+ QAhiGLCursor() : texture(0) {}
+ ~QAhiGLCursor();
+
+ void set(const QImage &image, int hotx, int hoty);
+
+ GLuint texture;
+};
+
+QAhiGLCursor::~QAhiGLCursor()
+{
+ if (texture)
+ glDeleteTextures(1, &texture);
+}
+
+void QAhiGLCursor::set(const QImage &image, int hotx, int hoty)
+{
+ if (texture)
+ glDeleteTextures(1, &texture);
+
+ if (image.isNull())
+ texture = 0;
+ else
+ texture = createTexture(image.convertToFormat(QImage::Format_ARGB32));
+
+ QScreenCursor::set(image, hotx, hoty);
+}
+
+
+/*!
+ \class QAhiGLScreenPrivate
+ The QAhiGLScreenPrivate class contains state information for class QAhiGLScreen.
+
+ An instance of this class points to the owning instance of
+ class QAhiGLScreen. This class uses a QTimer to limit the
+ update frequency.
+ */
+//! [0]
+class QAhiGLScreenPrivate : public QObject
+{
+ Q_OBJECT
+
+public:
+ QAhiGLScreenPrivate(QAhiGLScreen *s);
+
+public slots:
+ void windowEvent(QWSWindow *w, QWSServer::WindowEvent e);
+ void redrawScreen();
+
+public:
+ QAhiGLScreen *screen;
+ QAhiGLCursor *cursor;
+
+ EGLContext eglContext;
+ EGLDisplay eglDisplay;
+ EGLSurface eglSurface;
+
+ QTimer updateTimer;
+ bool doEffects;
+};
+//! [0]
+
+//! [1]
+class ShowAnimation : public QTimeLine
+{
+public:
+ ShowAnimation(QAhiGLScreenPrivate *screen);
+ qreal valueForTime(int msec);
+};
+//! [1]
+
+//! [2]
+struct WindowInfo
+{
+ WindowInfo() : texture(0), animation(0) {}
+
+ GLuint texture;
+ QPointer<ShowAnimation> animation;
+};
+
+static QMap<QWSWindow*, WindowInfo*> windowMap;
+//! [2]
+
+/*!
+ Constructs the animation for the transition effect used
+ when the window associated with \a screen is displayed.
+ */
+//! [3]
+ShowAnimation::ShowAnimation(QAhiGLScreenPrivate *screen)
+ : QTimeLine(animationLength)
+{
+ setUpdateInterval(frameSpan);
+ connect(this, SIGNAL(valueChanged(qreal)), screen, SLOT(redrawScreen()));
+ connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
+ start();
+}
+//! [3]
+
+//! [4]
+qreal ShowAnimation::valueForTime(int msec)
+{
+ const qreal t = msec / qreal(duration());
+ return 3*t*t - 2*t*t*t;
+}
+//! [4]
+
+QAhiGLScreenPrivate::QAhiGLScreenPrivate(QAhiGLScreen *s)
+ : screen(s), cursor(0), doEffects(false)
+{
+ connect(&updateTimer, SIGNAL(timeout()), this, SLOT(redrawScreen()));
+}
+
+/*!
+ This slot handles the \a event when the \l {QWSServer}
+ {window server} emits a window event for the specified
+ \a window.
+
+ The \l {QWSServer::WindowEvent} {window events} handled
+ are \c Create, \c Destroy, and \c Show. The \c Create
+ event creates a new instance of \l {WindowInfo} and stores
+ it in a window map to mark the creation of a new window.
+ The \c Destroy event causes the \l {WindoInfo} instance
+ to be removed from the map and destroyed.
+
+ The \c Show event is the most interesting. If the user
+ has started the application with -display ahigl:effects,
+ then the \c Show event is handled by creating a small
+ \l {ShowAnimation} {animation} for use when the window
+ is first shown.
+ */
+//! [5]
+void QAhiGLScreenPrivate::windowEvent(QWSWindow *window,
+ QWSServer::WindowEvent event)
+{
+ switch (event) {
+ case QWSServer::Create:
+ windowMap[window] = new WindowInfo;
+ break;
+ case QWSServer::Show:
+ if (doEffects)
+ windowMap[window]->animation = new ShowAnimation(this);
+ break;
+ case QWSServer::Destroy:
+ delete windowMap[window];
+ windowMap.remove(window);
+ break;
+ default:
+ break;
+ }
+}
+//! [5]
+
+/*!
+ This function assumes the updateTimer is still counting down and stops it
+ and then calls redrawScreen() in the public screen driver class QAhiGLScreen.
+ */
+//! [6]
+void QAhiGLScreenPrivate::redrawScreen()
+{
+ updateTimer.stop();
+ screen->redrawScreen();
+}
+//! [6]
+
+/*!
+ \class QAhiGLScreen
+
+ \brief The QAhiGLScreen class is the screen driver for the ATI handheld device interface.
+
+ QAhiGLScreen is implemented with the d-pointer pattern. That is,
+ the only data member the class contains is a pointer called d_ptr,
+ which means data pointer. It points to an instance of a private
+ class called QAhiGLScreenPrivate, where all the screen driver's
+ context data members are defined. The d-pointer pattern is used
+ so that changes can be made to the screen driver's context data
+ members without destroying the binary compatibility of the public
+ screen driver class.
+
+ The pure virtual functions found in the base class QScreen are
+ listed below. All must have implementations in any screen driver
+ class derived from QScreen. All are impemented in this example,
+ except for setMode(), which has only been given a stub
+ implementation to satisfy the compiler.
+
+ bool connect(const QString & displaySpec);
+ void disconnect();
+ bool initDevice();
+ void setMode(int width, int height, int depth);
+
+ The stub implementation of setMode() is not meant to indicate
+ setMode() can be ignored in your own screen driver class. It was
+ simply decided not to provide a fully implemented screen driver
+ class for the example, which would normally be tailored to your
+ device's specific requirements.
+
+ The base class QGLScreen has only one pure virtual function,
+ hasOpenGL(), which must return true if your screen driver class
+ supports OpenGL.
+
+ QWSWindowSurface * createSurface(const QString & key) const
+ QWSWindowSurface * createSurface(QWidget * widget) const
+ void exposeRegion(QRegion region, int windowIndex)
+
+ */
+
+/*!
+ Constructs a new, ATI handheld device screen driver.
+
+ The displayId identifies the QWS server to connect to.
+ */
+QAhiGLScreen::QAhiGLScreen(int displayId) : QGLScreen(displayId)
+{
+ d_ptr = new QAhiGLScreenPrivate(this);
+ d_ptr->eglDisplay = EGL_NO_DISPLAY;
+ d_ptr->eglSurface = EGL_NO_SURFACE;
+}
+
+/*!
+ Destroys this ATI handheld device screen driver.
+ */
+QAhiGLScreen::~QAhiGLScreen()
+{
+ delete d_ptr;
+}
+
+/*!
+ \reimp
+ */
+//! [7]
+bool QAhiGLScreen::connect(const QString &displaySpec)
+{
+ // Hardcoded values for this device
+ w = 480;
+ h = 640;
+ dw = w;
+ dh = h;
+ d = 16;
+
+ const int dpi = 120;
+ physWidth = qRound(dw * 25.4 / dpi);
+ physHeight = qRound(dh * 25.4 / dpi);
+
+ if (displaySpec.section(':', 1, 1).contains("effects"))
+ d_ptr->doEffects = true;
+
+ return true;
+}
+//! [7]
+
+/*!
+ \reimp
+ */
+//! [8]
+bool QAhiGLScreen::initDevice()
+{
+ EGLint version, subversion;
+ EGLint attrs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_STENCIL_SIZE, 8, EGL_DEPTH_SIZE, 16,
+ EGL_NONE };
+ EGLint numConfig;
+ EGLConfig eglConfig;
+
+ d_ptr->eglDisplay = eglGetDisplay(0);
+ if (d_ptr->eglDisplay == EGL_NO_DISPLAY) {
+ qCritical("QAhiGLScreen::initDevice(): eglGetDisplay failed: 0x%x",
+ eglGetError());
+ return false;
+ }
+
+ if (!eglInitialize(d_ptr->eglDisplay, &version, &subversion)) {
+ qCritical("QAhiGLScreen::initDevice(): eglInitialize failed: 0x%x",
+ eglGetError());
+ return false;
+ }
+
+ if (!eglChooseConfig(d_ptr->eglDisplay, attrs, &eglConfig, 1, &numConfig)) {
+ qCritical("QAhiGLScreen::initDevice(): eglChooseConfig failed: 0x%x",
+ eglGetError());
+ return false;
+ }
+
+ static DummyScreen win = { w, h };
+ d_ptr->eglSurface = eglCreateWindowSurface(d_ptr->eglDisplay, eglConfig,
+ &win, 0);
+ if (d_ptr->eglSurface == EGL_NO_SURFACE) {
+ qCritical("QAhiGLScreen::initDevice(): eglCreateWindowSurface failed: 0x%x",
+ eglGetError());
+ return false;
+ }
+
+ d_ptr->eglContext = eglCreateContext(d_ptr->eglDisplay, eglConfig,
+ EGL_NO_CONTEXT, 0);
+ if (d_ptr->eglContext == EGL_NO_CONTEXT) {
+ qCritical("QAhiGLScreen::initDevice(): eglCreateContext failed: 0x%x",
+ eglGetError());
+ return false;
+ }
+
+ if (!eglMakeCurrent(d_ptr->eglDisplay, d_ptr->eglSurface, d_ptr->eglSurface, d_ptr->eglContext)) {
+ qCritical("QAhiGLScreen::initDevice(): eglMakeCurrent failed: 0x%x",
+ eglGetError());
+ return false;
+ }
+
+ d_ptr->connect(QWSServer::instance(),
+ SIGNAL(windowEvent(QWSWindow*, QWSServer::WindowEvent)),
+ SLOT(windowEvent(QWSWindow*, QWSServer::WindowEvent)));
+
+ d_ptr->cursor = new QAhiGLCursor;
+ qt_screencursor = d_ptr->cursor;
+
+ return true;
+}
+//! [8]
+
+/*!
+ \reimp
+ */
+//! [9]
+void QAhiGLScreen::shutdownDevice()
+{
+ delete d_ptr->cursor;
+ d_ptr->cursor = 0;
+ qt_screencursor = 0;
+
+ eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE,
+ EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglDestroyContext(d_ptr->eglDisplay, d_ptr->eglContext);
+ eglDestroySurface(d_ptr->eglDisplay, d_ptr->eglSurface);
+ eglTerminate(d_ptr->eglDisplay);
+}
+//! [9]
+
+/*!
+ \reimp
+
+ In this case, the reimplimentation does nothing. It is
+ required because the function is declared as pure virtual
+ in the base class QScreen.
+ */
+void QAhiGLScreen::disconnect()
+{
+}
+
+/*
+ This internal function rounds up to the next power of
+ two. If v is already a power of two, that same value is
+ returned.
+ */
+inline static uint nextPowerOfTwo(uint v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ ++v;
+ return v;
+}
+
+/*
+ This internal function creates a texture from the image img
+ and returns its texture identifier.
+
+ The term "texture" is a graphics technology term that refers
+ to a pixmap constructed from an image by adding extra points
+ of contrast to the otherwise plain color image. The texture
+ has a, well, texture, that the original image doesn't have.
+ */
+static GLuint createTexture(const QImage &img)
+{
+ if (img.isNull())
+ return 0;
+
+ int width = img.width();
+ int height = img.height();
+ int textureWidth;
+ int textureHeight;
+ GLuint texture;
+
+ glGenTextures(1, &texture);
+ textureWidth = nextPowerOfTwo(width);
+ textureHeight = nextPowerOfTwo(height);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ switch (img.format()) {
+ case QImage::Format_RGB16:
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
+ textureWidth,
+ textureHeight, 0,
+ GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0);
+
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
+ GL_RGB, GL_UNSIGNED_SHORT_5_6_5, img.bits());
+ break;
+
+ case QImage::Format_ARGB32_Premultiplied:
+ case QImage::Format_ARGB32:
+ case QImage::Format_RGB32:
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ textureWidth,
+ textureHeight, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
+ GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
+ break;
+
+ default:
+ break;
+ }
+
+ return texture;
+}
+
+/*
+ A helper function used by QAhiGLScreen::drawQuad().
+ */
+static void drawQuad_helper(GLshort *coords, GLfloat *texCoords)
+{
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2, GL_SHORT, 0, coords);
+ glEnable(GL_TEXTURE_2D);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glDisable(GL_TEXTURE_2D);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+}
+
+/*
+ A helper function used by QAhiGLScreen::drawQuadWavyFlag().
+ */
+static void drawQuad_helper(GLshort *coords, GLfloat *texCoords,
+ int arraySize, int numArrays)
+{
+ glEnable(GL_TEXTURE_2D);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2, GL_SHORT, 0, coords);
+
+ for (int i = 0; i < numArrays-1; ++i)
+ glDrawArrays(GL_TRIANGLE_STRIP, i*arraySize, arraySize);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisable(GL_TEXTURE_2D);
+}
+
+/*
+ A convenience function used by QAhiGLScreen::drawQuad().
+ */
+static void setRectCoords(GLshort *coords, QRect rect)
+{
+ coords[0] = GLshort(rect.left());
+ coords[1] = GLshort(rect.top());
+
+ coords[2] = GLshort(rect.right());
+ coords[3] = GLshort(rect.top());
+
+ coords[4] = GLshort(rect.right());
+ coords[5] = GLshort(rect.bottom());
+
+ coords[6] = GLshort(rect.left());
+ coords[7] = GLshort(rect.bottom());
+}
+
+/*!
+ A helper function used by QAhiGLScreen::drawWindow() and
+ QAhiGLScreen::redrawScreen().
+ */
+void QAhiGLScreen::drawQuad(const QRect &textureGeometry,
+ const QRect &subGeometry,
+ const QRect &screenGeometry)
+{
+ qreal textureWidth = qreal(nextPowerOfTwo(textureGeometry.width()));
+ qreal textureHeight = qreal(nextPowerOfTwo(textureGeometry.height()));
+
+ GLshort coords[8];
+ setRectCoords(coords, screenGeometry);
+
+ GLfloat texcoords[8];
+ texcoords[0] = (subGeometry.left() - textureGeometry.left()) / textureWidth;
+ texcoords[1] = (subGeometry.top() - textureGeometry.top()) / textureHeight;
+
+ texcoords[2] = (subGeometry.right() - textureGeometry.left()) / textureWidth;
+ texcoords[3] = (subGeometry.top() - textureGeometry.top()) / textureHeight;
+
+ texcoords[4] = (subGeometry.right() - textureGeometry.left()) / textureWidth;
+ texcoords[5] = (subGeometry.bottom() - textureGeometry.top()) / textureHeight;
+
+ texcoords[6] = (subGeometry.left() - textureGeometry.left()) / textureWidth;
+ texcoords[7] = (subGeometry.bottom() - textureGeometry.top()) / textureHeight;
+
+ drawQuad_helper(coords, texcoords);
+}
+
+/*
+ My own sine function.
+ */
+static qreal mySin(QFixed radians)
+{
+ const QFixed twoPI = QFixed::fromReal(2*M_PI);
+
+ const int tableSize = 40;
+ static int *table = 0;
+
+ if (!table) {
+ table = new int[tableSize];
+ for (int i = 0; i < tableSize; ++i) {
+ table[i] = qRound(sin(M_PI*(i*360.0/40.0)/180.0) * 16776960.0);
+ }
+ }
+
+ QFixed tableLookup = radians*tableSize/twoPI;
+ return table[tableLookup.truncate()%tableSize]/16776960.0;
+}
+
+/*
+ My own cosine function.
+ */
+static qreal myCos(QFixed radians)
+{
+ const int twoPI = qRound(2*M_PI);
+
+ const int tableSize = 40;
+ static int *table = 0;
+
+ if (!table) {
+ table = new int[tableSize];
+ for (int i = 0; i < tableSize; ++i) {
+ table[i] = int(cos(M_PI*(i*360.0/40.0)/180.0) * 16776960.0);
+ }
+ }
+
+ QFixed tableLookup = radians*tableSize/twoPI;
+ return table[tableLookup.truncate()%tableSize]/16776960.0;
+}
+
+// number of grid cells in wavy flag tesselation in x- and y-direction
+const int subdivisions = 10;
+
+/*
+ A helper function used by drawQuadWavyFlag(). It computes
+ coordinates for grid cells for a wavy flag tesselation and
+ stores them in the array called coords.
+ */
+static void setFlagCoords(GLshort *coords,
+ QRectF screenGeometry,
+ int frameNum,
+ qreal progress)
+{
+ int coordIndex = 0;
+ qreal waveHeight = 30.0*(1.0-progress);
+ for (int j = 0; j < subdivisions-1; ++j) {
+ for (int i = 0; i < subdivisions; ++i) {
+ qreal c;
+ c = screenGeometry.left()
+ + (i * screenGeometry.width() / (subdivisions - 1))
+ + waveHeight * qRound(mySin(QFixed::fromReal(M_PI * 20 * (frameNum + i) / 180.0)))
+ + waveHeight * qRound(myCos(QFixed::fromReal(M_PI * 20 * (frameNum + j) / 180.0)));
+ coords[coordIndex++] = qRound(c);
+ c = screenGeometry.top()
+ + (j * screenGeometry.height() / (subdivisions - 1))
+ + waveHeight * mySin(QFixed::fromReal(M_PI * 20 * (frameNum + i) / 180.0))
+ + waveHeight * myCos(QFixed::fromReal(M_PI * 20 * (frameNum + j) / 180.0));
+ coords[coordIndex++] = qRound(c);
+ c = screenGeometry.left() + (i * screenGeometry.width() / (subdivisions - 1))
+ + waveHeight * mySin(QFixed::fromReal(M_PI * 20 * (frameNum + i) / 180.0))
+ + waveHeight * myCos(QFixed::fromReal(M_PI * 20 * (frameNum + (j+1)) / 180.0));
+ coords[coordIndex++] = qRound(c);
+
+ c = screenGeometry.top()
+ + ((j + 1) * screenGeometry.height() / (subdivisions - 1))
+ + waveHeight * mySin(QFixed::fromReal(M_PI * 20 * (frameNum + i) / 180.0))
+ + waveHeight * myCos(QFixed::fromReal(M_PI * 20 * (frameNum + (j + 1)) / 180.0));
+ coords[coordIndex++] = qRound(c);
+ }
+ }
+}
+
+static void setFlagTexCoords(GLfloat *texcoords,
+ const QRectF &subTexGeometry,
+ const QRectF &textureGeometry,
+ int textureWidth, int textureHeight)
+{
+ qreal topLeftX = (subTexGeometry.left() - textureGeometry.left())/textureWidth;
+ qreal topLeftY = (textureGeometry.height() - (subTexGeometry.top() - textureGeometry.top()))/textureHeight;
+
+ qreal width = (subTexGeometry.right() - textureGeometry.left())/textureWidth - topLeftX;
+ qreal height = (textureGeometry.height() - (subTexGeometry.bottom() - textureGeometry.top()))/textureHeight - topLeftY;
+
+ int coordIndex = 0;
+ qreal spacing = subdivisions - 1;
+ for (int j = 0; j < subdivisions-1; ++j) {
+ for (int i = 0; i < subdivisions; ++i) {
+ texcoords[coordIndex++] = topLeftX + (i*width) / spacing;
+ texcoords[coordIndex++] = topLeftY + (j*height) / spacing;
+ texcoords[coordIndex++] = topLeftX + (i*width) / spacing;
+ texcoords[coordIndex++] = topLeftY + ((j+1)*height) / spacing;
+ }
+ }
+}
+
+void QAhiGLScreen::drawQuadWavyFlag(const QRect &textureGeometry,
+ const QRect &subTexGeometry,
+ const QRect &screenGeometry,
+ qreal progress)
+{
+ const int textureWidth = nextPowerOfTwo(textureGeometry.width());
+ const int textureHeight = nextPowerOfTwo(textureGeometry.height());
+
+ static int frameNum = 0;
+
+ GLshort coords[subdivisions*subdivisions*2*2];
+ setFlagCoords(coords, screenGeometry, frameNum++, progress);
+
+ GLfloat texcoords[subdivisions*subdivisions*2*2];
+ setFlagTexCoords(texcoords, subTexGeometry, textureGeometry,
+ textureWidth, textureHeight);
+
+ drawQuad_helper(coords, texcoords, subdivisions*2, subdivisions);
+}
+
+void QAhiGLScreen::invalidateTexture(int windowIndex)
+{
+ if (windowIndex < 0)
+ return;
+
+ QList<QWSWindow*> windows = QWSServer::instance()->clientWindows();
+ if (windowIndex > windows.size() - 1)
+ return;
+
+ QWSWindow *win = windows.at(windowIndex);
+ if (!win)
+ return;
+
+ WindowInfo *info = windowMap[win];
+ if (info->texture) {
+ glDeleteTextures(1, &info->texture);
+ info->texture = 0;
+ }
+}
+
+void QAhiGLScreen::drawWindow(QWSWindow *win, qreal progress)
+{
+ const QRect screenRect = win->allocatedRegion().boundingRect();
+ QRect drawRect = screenRect;
+
+ glColor4f(1.0, 1.0, 1.0, progress);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ QWSWindowSurface *surface = win->windowSurface();
+ if (!surface)
+ return;
+
+ if (progress >= 1.0) {
+ if (surface->key() == QLatin1String("ahigl")) {
+ drawRect.setCoords(drawRect.left(), drawRect.bottom(),
+ drawRect.right(), drawRect.top());
+ }
+ drawQuad(win->requestedRegion().boundingRect(), screenRect, drawRect);
+ return;
+ }
+
+ const int dx = qRound((1 - progress) * drawRect.width() / 2);
+ const int dy = qRound((1 - progress) * drawRect.height() / 2);
+
+ drawRect.adjust(dx, dy, -dx, -dy);
+
+ if (surface->key() != QLatin1String("ahigl")) {
+ drawRect.setCoords(drawRect.left(), drawRect.bottom(),
+ drawRect.right(), drawRect.top());
+ }
+
+ drawQuadWavyFlag(win->requestedRegion().boundingRect(), screenRect,
+ drawRect, progress);
+}
+
+/*!
+ The window compositions are constructed here.
+ */
+//! [10]
+void QAhiGLScreen::redrawScreen()
+{
+ glBindFramebufferOES(GL_FRAMEBUFFER_EXT, 0);
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrthof(0, w, h, 0, -999999, 999999);
+ glViewport(0, 0, w, h);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ // Fill background color
+
+ QColor bgColor = QWSServer::instance()->backgroundBrush().color();
+ glClearColor(bgColor.redF(), bgColor.greenF(),
+ bgColor.blueF(), bgColor.alphaF());
+ glClear(GL_COLOR_BUFFER_BIT);
+//! [10]
+
+ // Draw all windows
+
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_STENCIL_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ZERO);
+ glDisable(GL_ALPHA_TEST);
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+//! [11]
+ QList<QWSWindow*> windows = QWSServer::instance()->clientWindows();
+ for (int i = windows.size() - 1; i >= 0; --i) {
+ QWSWindow *win = windows.at(i);
+ QWSWindowSurface *surface = win->windowSurface();
+ if (!surface)
+ continue;
+
+ WindowInfo *info = windowMap[win];
+
+ if (!info->texture) {
+ if (surface->key() == QLatin1String("ahigl"))
+ info->texture = static_cast<QAhiGLWindowSurface*>(surface)->textureId();
+ else
+ info->texture = createTexture(surface->image());
+ }
+ qreal progress;
+ if (info->animation)
+ progress = info->animation->currentValue();
+ else
+ progress = 1.0;
+
+ glBindTexture(GL_TEXTURE_2D, info->texture);
+ drawWindow(win, progress);
+ } // for i
+//! [11] //! [12]
+
+ // Draw cursor
+
+ const QAhiGLCursor *cursor = d_ptr->cursor;
+ if (cursor->texture) {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBindTexture(GL_TEXTURE_2D, d_ptr->cursor->texture);
+ drawQuad(cursor->boundingRect(), cursor->boundingRect(),
+ cursor->boundingRect());
+ }
+
+ glPopMatrix();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+
+ eglSwapBuffers(d_ptr->eglDisplay, d_ptr->eglSurface);
+}
+//! [12]
+
+/*!
+ \reimp
+
+ */
+//! [13]
+void QAhiGLScreen::exposeRegion(QRegion r, int windowIndex)
+{
+ if ((r & region()).isEmpty())
+ return;
+
+ invalidateTexture(windowIndex);
+
+ if (!d_ptr->updateTimer.isActive())
+ d_ptr->updateTimer.start(frameSpan);
+}
+//! [13]
+
+/*!
+ \reimp
+
+ This overloading of createSurface() is called on the client side to
+ create a window surface for a new window. If the \a widget is a
+ QGLWidget, or if the widget's width and height are both less than or
+ equal to 256, it creates an instance of QAhiGLWindowSurface.
+ Otherwise, it calls QScreen::createSurface() to create a non-OpenGL
+ window surface. The pointer to the new window surface is returned.
+
+ Note that this function first asks whether this application is the
+ server, and it only creates an instance of QAhiGLWindowSurface if
+ the answer is yes. What this means is we only let the server have
+ access to the OpenGL hardware, because of an implementation
+ restyriction in the OpenGL libraries we are using. Thus only clients
+ that are in the server process get to create OpenGL window surfaces.
+ */
+//! [14]
+QWSWindowSurface* QAhiGLScreen::createSurface(QWidget *widget) const
+{
+ if (QApplication::type() == QApplication::GuiServer) {
+ if (qobject_cast<QGLWidget*>(widget)) {
+ return new QAhiGLWindowSurface(widget,
+ d_ptr->eglDisplay,
+ d_ptr->eglSurface,
+ d_ptr->eglContext);
+ }
+
+ const QRect rect = widget->frameGeometry();
+ if (rect.width() <= 256 && rect.height() <= 256) {
+ return new QAhiGLWindowSurface(widget,
+ d_ptr->eglDisplay,
+ d_ptr->eglSurface,
+ d_ptr->eglContext);
+ }
+ }
+
+ return QScreen::createSurface(widget);
+}
+//! [14]
+
+/*!
+ \reimp
+
+ This overloading of createSurface() is called on the server side
+ to manage a window surface corresponding to a window surface
+ already created on the client side.
+
+ If the \a key is "ahigl", create an instance of QAhiGLWindowSurface
+ and return it. Otherwise, call QScreen::createSurface() and return
+ the window surface it creates.
+
+ See QScreen::createSurface().
+ */
+//! [15]
+QWSWindowSurface* QAhiGLScreen::createSurface(const QString &key) const
+{
+ if (key == QLatin1String("ahigl")) {
+ return new QAhiGLWindowSurface(d_ptr->eglDisplay,
+ d_ptr->eglSurface,
+ d_ptr->eglContext);
+ }
+
+ return QScreen::createSurface(key);
+}
+//! [15]
+
+/*!
+ This function would normally reset the frame buffer resolution
+ according to \a width, \a height, and the bit \a depth. It would
+ then notify other applications that their frame buffer size had
+ changed so they could redraw. The function is a no-op in this
+ example, which means the example screen driver can't change its
+ frame buffer resolution. There is no significance to that in the
+ example. You would normally implement setMode() in an OpenGL
+ screen driver. This no-op reimplementation is required here
+ because setMode() in QScreen is a pure virtual function.
+
+ See QScreen::setMode()
+ */
+void QAhiGLScreen::setMode(int width, int height, int depth)
+{
+ Q_UNUSED(width);
+ Q_UNUSED(height);
+ Q_UNUSED(depth);
+}
+
+/*!
+ This function would normally be reimplemented to prevent the
+ screen driver from updating the screen if \a on is true. It is a
+ no-op in this example, which means the screen driver can always
+ update the screen.
+
+ See QScreen::blank().
+ */
+void QAhiGLScreen::blank(bool on)
+{
+ Q_UNUSED(on);
+}
+
+/*!
+ This function always returns true, since the purpose of
+ this screen driver class is to implement an OpenGL ES
+ screen driver. In some other class designed to handle both
+ OpenGL and non-OpenGL graphics, it might test the system to
+ determine whether OpenGL graphics are supported and return
+ true or false accordingly.
+ */
+bool QAhiGLScreen::hasOpenGL()
+{
+ return true;
+}
+
+#include "qscreenahigl_qws.moc"
diff --git a/examples/qws/ahigl/qscreenahigl_qws.h b/examples/qws/ahigl/qscreenahigl_qws.h
new file mode 100644
index 0000000000..332d5c3aea
--- /dev/null
+++ b/examples/qws/ahigl/qscreenahigl_qws.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QAHIGLSCREEN_H
+#define QAHIGLSCREEN_H
+
+#include <QGLScreen>
+#include <QWSServer>
+
+QT_BEGIN_NAMESPACE
+class QAhiGLScreenPrivate;
+QT_END_NAMESPACE
+
+//! [0]
+class QAhiGLScreen : public QGLScreen
+{
+public:
+ QAhiGLScreen(int displayId);
+ virtual ~QAhiGLScreen();
+
+ bool initDevice();
+ bool connect(const QString &displaySpec);
+ void disconnect();
+ void shutdownDevice();
+
+ void setMode(int width, int height, int depth);
+ void blank(bool on);
+
+ void exposeRegion(QRegion r, int changing);
+
+ QWSWindowSurface* createSurface(QWidget *widget) const;
+ QWSWindowSurface* createSurface(const QString &key) const;
+
+ bool hasOpenGL();
+
+private:
+ void invalidateTexture(int windowIndex);
+ void redrawScreen();
+ void drawWindow(QWSWindow *win, qreal progress);
+ void drawQuad(const QRect &textureGeometry,
+ const QRect &subGeometry,
+ const QRect &screenGeometry);
+ void drawQuadWavyFlag(const QRect &textureGeometry,
+ const QRect &subTexGeometry,
+ const QRect &screenGeometry,
+ float progress);
+
+ QAhiGLScreenPrivate *d_ptr;
+ friend class QAhiGLScreenPrivate;
+};
+//! [0]
+
+#endif // QAHIGLSCREEN_H
diff --git a/examples/qws/ahigl/qscreenahiglplugin.cpp b/examples/qws/ahigl/qscreenahiglplugin.cpp
new file mode 100644
index 0000000000..828de82998
--- /dev/null
+++ b/examples/qws/ahigl/qscreenahiglplugin.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qscreenahigl_qws.h"
+
+#include <QScreenDriverPlugin>
+#include <QStringList>
+
+//! [0]
+class QAhiGLScreenPlugin : public QScreenDriverPlugin
+{
+public:
+ QAhiGLScreenPlugin();
+
+ QStringList keys() const;
+ QScreen *create(const QString&, int displayId);
+};
+//! [0]
+
+/*!
+ \class QAhiGLScreenPlugin
+ \brief The QAhiGLScreenPlugin class is the plugin for the ATI handheld device graphics driver.
+
+ QAhiGLScreenPlugin inherits QScreenDriverPlugin. See
+ \l{How to Create Qt Plugins} for details.
+ */
+
+/*!
+ This is the default constructor.
+ */
+QAhiGLScreenPlugin::QAhiGLScreenPlugin()
+ : QScreenDriverPlugin()
+{
+}
+
+/*!
+ Returns a string list containing the string "ahigl" which
+ is the only screen driver supported by this plugin.
+ */
+QStringList QAhiGLScreenPlugin::keys() const
+{
+ return (QStringList() << "ahigl");
+}
+
+/*!
+ Creates a screen driver of the kind specified by \a driver.
+ The \a displayId identifies the Qt for Embedded Linux server to connect to.
+ */
+QScreen* QAhiGLScreenPlugin::create(const QString& driver, int displayId)
+{
+ if (driver.toLower() != "ahigl")
+ return 0;
+
+ return new QAhiGLScreen(displayId);
+}
+
+//! [1]
+Q_EXPORT_PLUGIN2(qahiglscreen, QAhiGLScreenPlugin)
+//! [1]
diff --git a/examples/qws/ahigl/qwindowsurface_ahigl.cpp b/examples/qws/ahigl/qwindowsurface_ahigl.cpp
new file mode 100644
index 0000000000..79924f9ff9
--- /dev/null
+++ b/examples/qws/ahigl/qwindowsurface_ahigl.cpp
@@ -0,0 +1,349 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwindowsurface_ahigl_p.h"
+#include "qscreenahigl_qws.h"
+
+#include <qwsdisplay_qws.h>
+#include <QtGui/QPaintDevice>
+#include <QtGui/QWidget>
+#include <QtOpenGL/private/qglpaintdevice_qws_p.h>
+#include <QtOpenGL/private/qgl_p.h>
+#include <GLES/gl.h>
+
+/*!
+ \class QAhiGLWindowSurfacePrivate
+ \internal
+
+ \brief The QAhiGLWindowSurfacePrivate class is the private implementation
+ class for class QAhiGLWindowSurface.
+
+ This class contains only state variables.
+ */
+//! [0]
+class QAhiGLWindowSurfacePrivate
+{
+public:
+ QAhiGLWindowSurfacePrivate(EGLDisplay eglDisplay,
+ EGLSurface eglSurface,
+ EGLContext eglContext);
+
+ QPaintDevice *device;
+
+ int textureWidth;
+ int textureHeight;
+
+ GLuint texture;
+ GLuint frameBufferObject;
+ GLuint depthbuf;
+
+ EGLDisplay display;
+ EGLSurface surface;
+ EGLContext context;
+};
+//! [0]
+
+/*!
+ The construct just sets statwe variables using the ones
+ provided.
+ */
+QAhiGLWindowSurfacePrivate::QAhiGLWindowSurfacePrivate(EGLDisplay eglDisplay,
+ EGLSurface eglSurface,
+ EGLContext eglContext)
+ : texture(0), frameBufferObject(0), depthbuf(0), display(eglDisplay),
+ surface(eglSurface), context(eglContext)
+{
+}
+
+inline static int nextPowerOfTwo(uint v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ ++v;
+ return v;
+}
+
+/*!
+ \class QAhiGLWindowSurface
+ \preliminary
+ \internal
+
+ \brief The QAhiGLWindowSurface class provides the drawing area
+ for top-level windows using OpenGL for drawing on an ATI handheld
+ device.
+
+ In \l{Qt for Embedded Linux}, the default behavior for each client is to
+ render widgets into an area of memory. The server then displays
+ the contents of that memory on the screen. For ATI handheld
+ devices using OpenGL, QAhiGLWindowSurface is the window surface
+ class that allocates and manages the memory areas in the clients
+ and the server.
+
+ When a screen update is required, the server runs through all the
+ top-level windows that intersect with the region being updated,
+ ensuring that the clients have updated their window surfaces. Then
+ the server uses the screen driver to copy the contents of the
+ affected window surfaces into its composition and then display the
+ composition on the screen.
+
+ \tableofcontents
+
+ \section1 Pure Virtual Functions
+
+ There are two window surface instances for each top-level window.
+ One is used by the application when drawing a window, and the
+ other is used by the server application to make its copy for
+ building a window composition to send to the screen.
+
+ The key() function is implemented to uniquely identify this window
+ surface class as "ahigl", and the isValid() function is
+ implemented to determine whether the associated window is still
+ acceptable for representation by this window surface class. It
+ must either be a window using an \l {QGLWidget} {OpenGL widget},
+ or it must be a window whose frame is no bigger than 256 x 256.
+
+ The setGeometry() function is implemented to change the geometry
+ of the frame buffer whenever the geometry of the associated
+ top-level window changes. The image() function is called by the
+ window system when building window compositions to return an image
+ of the top-level window.
+
+ The paintDevice() function is implemented to return the appropriate
+ paint device.
+
+ \section1 Virtual Functions
+
+ When painting onto the surface, the window system will always call
+ the beginPaint() function before any painting operations are
+ performed. It ensures that the correct frame buffer will be used
+ by the OpenGL library for painting operations. Likewise, the
+ endPaint() function is automatically called when the painting is
+ done, but it isn't implemented for this example.
+*/
+
+/*!
+ This is the client side constructor.
+ */
+//! [1]
+QAhiGLWindowSurface::QAhiGLWindowSurface(QWidget *widget,
+ EGLDisplay eglDisplay,
+ EGLSurface eglSurface,
+ EGLContext eglContext)
+ : QWSGLWindowSurface(widget)
+{
+ d_ptr = new QAhiGLWindowSurfacePrivate(eglDisplay, eglSurface, eglContext);
+ d_ptr->device = new QWSGLPaintDevice(widget);
+
+ setSurfaceFlags(QWSWindowSurface::Buffered);
+}
+//! [1]
+
+/*!
+ This is the server side constructor.
+ */
+//! [2]
+QAhiGLWindowSurface::QAhiGLWindowSurface(EGLDisplay eglDisplay,
+ EGLSurface eglSurface,
+ EGLContext eglContext)
+{
+ d_ptr = new QAhiGLWindowSurfacePrivate(eglDisplay, eglSurface, eglContext);
+ setSurfaceFlags(QWSWindowSurface::Buffered);
+}
+//! [2]
+
+/*!
+ The destructor deletes the OpenGL structures held by the
+ private implementation class, and then it deletes the
+ private implementation class.
+ */
+QAhiGLWindowSurface::~QAhiGLWindowSurface()
+{
+ if (d_ptr->texture)
+ glDeleteTextures(1, &d_ptr->texture);
+ if (d_ptr->depthbuf)
+ glDeleteRenderbuffersOES(1, &d_ptr->depthbuf);
+ if (d_ptr->frameBufferObject)
+ glDeleteFramebuffersOES(1, &d_ptr->frameBufferObject);
+
+ delete d_ptr;
+}
+
+/*!
+ This function changes the geometry of the frame buffer
+ to the geometry in \a rect. It is called whenever the
+ geometry of the associated top-level window changes. It
+ also rebuilds the window surface's texture and binds
+ the OpenGL identifier to the texture for use by the
+ OpenGL library.
+ */
+//! [3]
+void QAhiGLWindowSurface::setGeometry(const QRect &rect)
+{
+ QSize size = rect.size();
+
+ const QWidget *w = window();
+ if (w && !w->mask().isEmpty()) {
+ const QRegion region = w->mask()
+ & rect.translated(-w->geometry().topLeft());
+ size = region.boundingRect().size();
+ }
+
+ if (geometry().size() != size) {
+
+ // Driver specific limitations:
+ // FBO maximimum size of 256x256
+ // Depth buffer required
+
+ d_ptr->textureWidth = qMin(256, nextPowerOfTwo(size.width()));
+ d_ptr->textureHeight = qMin(256, nextPowerOfTwo(size.height()));
+
+ glGenTextures(1, &d_ptr->texture);
+ glBindTexture(GL_TEXTURE_2D, d_ptr->texture);
+
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ const int bufSize = d_ptr->textureWidth * d_ptr->textureHeight * 2;
+ GLshort buf[bufSize];
+ memset(buf, 0, sizeof(GLshort) * bufSize);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, d_ptr->textureWidth,
+ d_ptr->textureHeight, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, buf);
+
+ glGenRenderbuffersOES(1, &d_ptr->depthbuf);
+ glBindRenderbufferOES(GL_RENDERBUFFER_EXT, d_ptr->depthbuf);
+ glRenderbufferStorageOES(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16,
+ d_ptr->textureWidth, d_ptr->textureHeight);
+
+ glGenFramebuffersOES(1, &d_ptr->frameBufferObject);
+ glBindFramebufferOES(GL_FRAMEBUFFER_EXT, d_ptr->frameBufferObject);
+
+ glFramebufferTexture2DOES(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_2D, d_ptr->texture, 0);
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_EXT,
+ GL_DEPTH_ATTACHMENT_EXT,
+ GL_RENDERBUFFER_EXT, d_ptr->depthbuf);
+ glBindFramebufferOES(GL_FRAMEBUFFER_EXT, 0);
+ }
+
+ QWSGLWindowSurface::setGeometry(rect);
+}
+//! [3]
+
+/*!
+ Returns the window surface's texture as a QByteArray.
+ */
+QByteArray QAhiGLWindowSurface::permanentState() const
+{
+ QByteArray array;
+ array.resize(sizeof(GLuint));
+
+ char *ptr = array.data();
+ reinterpret_cast<GLuint*>(ptr)[0] = textureId();
+ return array;
+}
+
+/*!
+ Sets the window surface's texture to \a data.
+ */
+void QAhiGLWindowSurface::setPermanentState(const QByteArray &data)
+{
+ const char *ptr = data.constData();
+ d_ptr->texture = reinterpret_cast<const GLuint*>(ptr)[0];
+}
+
+/*!
+ Returns the paint device being used for this window surface.
+ */
+QPaintDevice *QAhiGLWindowSurface::paintDevice()
+{
+ return d_ptr->device;
+}
+
+/*!
+ Returns the window surface's texture.
+ */
+GLuint QAhiGLWindowSurface::textureId() const
+{
+ return d_ptr->texture;
+}
+
+/*!
+ The \l {QWSServer} {window system} always calls this function
+ before any painting operations begin for this window surface.
+ It ensures that the correct frame buffer will be used by the
+ OpenGL library for painting operations.
+ */
+//! [4]
+void QAhiGLWindowSurface::beginPaint(const QRegion &region)
+{
+ QWSGLWindowSurface::beginPaint(region);
+
+ if (d_ptr->frameBufferObject)
+ glBindFramebufferOES(GL_FRAMEBUFFER_EXT, d_ptr->frameBufferObject);
+}
+//! [4]
+
+/*!
+ This function returns true if the window associated with
+ this window surface can still rendered using this window
+ surface class. Either the window's top-level widget must
+ be an \l {QGLWidget} {OpenGL widget}, or the window's
+ frame must be no bigger than 256 x 256.
+ */
+//! [5]
+bool QAhiGLWindowSurface::isValid() const
+{
+ if (!qobject_cast<QGLWidget*>(window())) {
+ const QRect r = window()->frameGeometry();
+ if (r.width() > 256 || r.height() > 256)
+ return false;
+ }
+ return true;
+}
+//! [5]
diff --git a/examples/qws/ahigl/qwindowsurface_ahigl_p.h b/examples/qws/ahigl/qwindowsurface_ahigl_p.h
new file mode 100644
index 0000000000..40a82ed669
--- /dev/null
+++ b/examples/qws/ahigl/qwindowsurface_ahigl_p.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWINDOWSURFACE_AHIGL_P_H
+#define QWINDOWSURFACE_AHIGL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of the QAhiGLWindowSurface class. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtOpenGL/private/qglwindowsurface_qws_p.h>
+#include <GLES/gl.h>
+#include <GLES/egl.h>
+
+QT_BEGIN_NAMESPACE
+class QAhiGLWindowSurfacePrivate;
+QT_END_NAMESPACE
+
+//! [0]
+class QAhiGLWindowSurface : public QWSGLWindowSurface
+{
+public:
+ QAhiGLWindowSurface(QWidget *widget, EGLDisplay eglDisplay,
+ EGLSurface eglSurface, EGLContext eglContext);
+ QAhiGLWindowSurface(EGLDisplay eglDisplay, EGLSurface eglSurface,
+ EGLContext eglContext);
+ ~QAhiGLWindowSurface();
+
+ QString key() const { return QLatin1String("ahigl"); }
+ void setGeometry(const QRect &rect);
+ QPaintDevice *paintDevice();
+ void beginPaint(const QRegion &region);
+ bool isValid() const;
+
+ QByteArray permanentState() const;
+ void setPermanentState(const QByteArray &);
+
+ QImage image() const { return QImage(); }
+
+ GLuint textureId() const;
+
+private:
+ QAhiGLWindowSurfacePrivate *d_ptr;
+};
+//! [0]
+
+#endif // QWINDOWSURFACE_AHIGL_P_H
diff --git a/examples/qws/dbscreen/dbscreen.cpp b/examples/qws/dbscreen/dbscreen.cpp
new file mode 100644
index 0000000000..bd26848859
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.cpp
@@ -0,0 +1,99 @@
+ /****************************************************************************
+ **
+ ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+ **
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ **
+ ****************************************************************************/
+
+#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..00221e9c19
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.h
@@ -0,0 +1,70 @@
+ /****************************************************************************
+ **
+ ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+ **
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ **
+ ****************************************************************************/
+
+#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..86152ab6ce
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += plugin
+
+TARGET = dbscreen
+target.path += $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+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..36587a1b1d
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreendriverplugin.cpp
@@ -0,0 +1,80 @@
+ /****************************************************************************
+ **
+ ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+ **
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ **
+ ****************************************************************************/
+
+#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..0379908499
--- /dev/null
+++ b/examples/qws/framebuffer/framebuffer.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = framebuffer
+CONFIG -= qt
+
+SOURCES += main.c
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qws/framebuffer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS framebuffer.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qws/framebuffer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qws/framebuffer/main.c b/examples/qws/framebuffer/main.c
new file mode 100644
index 0000000000..2c2cf3143b
--- /dev/null
+++ b/examples/qws/framebuffer/main.c
@@ -0,0 +1,586 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7e344e06e9
--- /dev/null
+++ b/examples/qws/mousecalibration/calibration.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..ae862e57d1
--- /dev/null
+++ b/examples/qws/mousecalibration/calibration.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..c318383b28
--- /dev/null
+++ b/examples/qws/mousecalibration/main.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <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..6f60b6dce9
--- /dev/null
+++ b/examples/qws/mousecalibration/mousecalibration.pro
@@ -0,0 +1,13 @@
+HEADERS += calibration.h \
+ scribblewidget.h
+SOURCES += calibration.cpp \
+ scribblewidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qws/mousecalibration
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qws/mousecalibration
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qws/mousecalibration/scribblewidget.cpp b/examples/qws/mousecalibration/scribblewidget.cpp
new file mode 100644
index 0000000000..255afd04dc
--- /dev/null
+++ b/examples/qws/mousecalibration/scribblewidget.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..6693082318
--- /dev/null
+++ b/examples/qws/mousecalibration/scribblewidget.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e9f310fa18
--- /dev/null
+++ b/examples/qws/qws.pro
@@ -0,0 +1,9 @@
+TEMPLATE = subdirs
+SUBDIRS = framebuffer mousecalibration simpledecoration
+
+# install
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qws
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/qws/simpledecoration/analogclock.cpp b/examples/qws/simpledecoration/analogclock.cpp
new file mode 100644
index 0000000000..28155ba0e7
--- /dev/null
+++ b/examples/qws/simpledecoration/analogclock.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f779744314
--- /dev/null
+++ b/examples/qws/simpledecoration/analogclock.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..597f5b3e20
--- /dev/null
+++ b/examples/qws/simpledecoration/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..282bc88959
--- /dev/null
+++ b/examples/qws/simpledecoration/mydecoration.cpp
@@ -0,0 +1,375 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..dffac30076
--- /dev/null
+++ b/examples/qws/simpledecoration/mydecoration.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b40987815c
--- /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]/qws/simpledecoration
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qws/simpledecoration
+INSTALLS += target sources
diff --git a/examples/qws/svgalib/README b/examples/qws/svgalib/README
new file mode 100644
index 0000000000..0b2831f618
--- /dev/null
+++ b/examples/qws/svgalib/README
@@ -0,0 +1,5 @@
+This is the SVGA screen driver plugin example from Qt 4.4. The code does
+not compile with Qt 4.5, because the internal graphics engine has changed.
+
+This is unsupported code, provided for convenience in case there is
+interest in porting it to Qt 4.5.
diff --git a/examples/qws/svgalib/svgalib.pro b/examples/qws/svgalib/svgalib.pro
new file mode 100644
index 0000000000..3ab5a1931a
--- /dev/null
+++ b/examples/qws/svgalib/svgalib.pro
@@ -0,0 +1,21 @@
+TEMPLATE = lib
+CONFIG += plugin
+
+LIBS += -lvgagl -lvga
+
+TARGET = svgalibscreen
+target.path = $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+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..b4e027679b
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintdevice.h"
+#include "svgalibpaintengine.h"
+
+#include <QApplication>
+#include <QDesktopWidget>
+
+SvgalibPaintDevice::SvgalibPaintDevice(QWidget *w)
+ : QCustomRasterPaintDevice(w)
+{
+ pengine = new SvgalibPaintEngine;
+}
+
+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..bf6cc7ac01
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..3621db7a43
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintengine.h"
+
+#include <QColor>
+#include <vga.h>
+#include <vgagl.h>
+
+SvgalibPaintEngine::SvgalibPaintEngine()
+{
+}
+
+SvgalibPaintEngine::~SvgalibPaintEngine()
+{
+}
+
+//! [0]
+bool SvgalibPaintEngine::begin(QPaintDevice *dev)
+{
+ device = dev;
+ pen = Qt::NoPen;
+ simplePen = true;
+ brush = Qt::NoBrush;
+ simpleBrush = true;
+ matrix = QMatrix();
+ 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(const QPaintEngineState &state)
+{
+ QPaintEngine::DirtyFlags flags = state.state();
+
+ if (flags & DirtyTransform) {
+ matrix = state.matrix();
+ simpleMatrix = (matrix.m12() == 0 && matrix.m21() == 0);
+ }
+
+ if (flags & DirtyPen) {
+ pen = state.pen();
+ simplePen = (pen.width() == 0 || pen.widthF() <= 1)
+ && (pen.style() == Qt::NoPen || pen.style() == Qt::SolidLine)
+ && (pen.color().alpha() == 255);
+ }
+
+ if (flags & DirtyBrush) {
+ brush = state.brush();
+ simpleBrush = (brush.style() == Qt::SolidPattern
+ || brush.style() == Qt::NoBrush)
+ && (brush.color().alpha() == 255);
+ }
+
+ if (flags & DirtyClipRegion)
+ setClip(state.clipRegion());
+
+ if (flags & DirtyClipEnabled) {
+ clipEnabled = state.isClipEnabled();
+ updateClip();
+ }
+
+ if (flags & DirtyClipPath) {
+ setClip(QRegion());
+ simpleClip = false;
+ }
+
+ if (flags & DirtyCompositionMode) {
+ const QPainter::CompositionMode m = state.compositionMode();
+ sourceOver = (m == QPainter::CompositionMode_SourceOver);
+ }
+
+ if (flags & DirtyOpacity)
+ opaque = (state.opacity() == 256);
+
+ if (flags & DirtyHints)
+ aliased = !(state.renderHints() & QPainter::Antialiasing);
+
+ QRasterPaintEngine::updateState(state);
+}
+//! [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..1fa97708bb
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBPAINTENGINE_H
+#define SVGALIBPAINTENGINE_H
+
+//! [0]
+#include <private/qpaintengine_raster_p.h>
+
+class SvgalibPaintEngine : public QRasterPaintEngine
+{
+public:
+ SvgalibPaintEngine();
+ ~SvgalibPaintEngine();
+
+ bool begin(QPaintDevice *device);
+ bool end();
+ void updateState(const QPaintEngineState &state);
+ void drawRects(const QRect *rects, int rectCount);
+
+private:
+ void setClip(const QRegion &region);
+ void updateClip();
+
+ QPen pen;
+ bool simplePen;
+ QBrush brush;
+ bool simpleBrush;
+ QMatrix 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..080a350d1c
--- /dev/null
+++ b/examples/qws/svgalib/svgalibplugin.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..1961d3c9d4
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.cpp
@@ -0,0 +1,354 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..4d32b7c04a
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..8e7e6b6e2b
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..c33d51a7d5
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..fb85d96286
--- /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]/richtext/calendar
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calendar.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/richtext/calendar
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/richtext/calendar/main.cpp b/examples/richtext/calendar/main.cpp
new file mode 100644
index 0000000000..aab8adcbfc
--- /dev/null
+++ b/examples/richtext/calendar/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..ca8ab5a175
--- /dev/null
+++ b/examples/richtext/calendar/mainwindow.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..704bdd913b
--- /dev/null
+++ b/examples/richtext/calendar/mainwindow.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..273ed57382
--- /dev/null
+++ b/examples/richtext/orderform/detailsdialog.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c74ff2a4bf
--- /dev/null
+++ b/examples/richtext/orderform/detailsdialog.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d6458bcfda
--- /dev/null
+++ b/examples/richtext/orderform/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e5cffe35a9
--- /dev/null
+++ b/examples/richtext/orderform/mainwindow.cpp
@@ -0,0 +1,250 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "detailsdialog.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *newAction = fileMenu->addAction(tr("&New..."));
+ newAction->setShortcut(tr("Ctrl+N"));
+ printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile()));
+ printAction->setShortcut(tr("Ctrl+P"));
+ printAction->setEnabled(false);
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcut(tr("Ctrl+Q"));
+ 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..70cc9ccaa1
--- /dev/null
+++ b/examples/richtext/orderform/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..3875ea0684
--- /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]/richtext/orderform
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS orderform.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/richtext/orderform
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/richtext/richtext.pro b/examples/richtext/richtext.pro
new file mode 100644
index 0000000000..d48602ef24
--- /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]/richtext
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS richtext.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/richtext
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/richtext/syntaxhighlighter/highlighter.cpp b/examples/richtext/syntaxhighlighter/highlighter.cpp
new file mode 100644
index 0000000000..5d9939d117
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/highlighter.cpp
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..2774212efd
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/highlighter.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..fbb822d246
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..a6312f9a14
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/mainwindow.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(tr("Ctrl+N",
+ "File|New")));
+ fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()),
+ QKeySequence(tr("Ctrl+O",
+ "File|Open")));
+ fileMenu->addAction(tr("E&xit"), qApp, SLOT(quit()),
+ QKeySequence(tr("Ctrl+Q",
+ "File|Exit")));
+}
+
+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..12334abe6d
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "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..4b90aa379e
--- /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]/richtext/syntaxhighlighter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS syntaxhighlighter.pro examples
+sources.path = $$[QT_INSTALL_EXAMPLES]/richtext/syntaxhighlighter
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+wince*: {
+ addFiles.sources = main.cpp mainwindow.cpp
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+}
diff --git a/examples/richtext/textobject/files/heart.svg b/examples/richtext/textobject/files/heart.svg
new file mode 100644
index 0000000000..ba5f050b00
--- /dev/null
+++ b/examples/richtext/textobject/files/heart.svg
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) --><svg viewBox="100 200 550 500" height="595.27559pt" id="svg1" inkscape:version="0.40+cvs" sodipodi:docbase="C:\Documents and Settings\Jon Phillips\My Documents\projects\clipart-project\submissions" sodipodi:docname="heart-left-highlight.svg" sodipodi:version="0.32" width="595.27559pt" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg">
+<metadata>
+<rdf:RDF xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<cc:Work rdf:about="">
+<dc:title>Heart Left-Highlight</dc:title>
+<dc:description>This is a normal valentines day heart.</dc:description>
+<dc:subject>
+<rdf:Bag>
+<rdf:li>holiday</rdf:li>
+<rdf:li>valentines</rdf:li>
+<rdf:li></rdf:li>
+<rdf:li>valentine</rdf:li>
+<rdf:li>hash(0x8a091c0)</rdf:li>
+<rdf:li>hash(0x8a0916c)</rdf:li>
+<rdf:li>signs_and_symbols</rdf:li>
+<rdf:li>hash(0x8a091f0)</rdf:li>
+<rdf:li>day</rdf:li>
+</rdf:Bag>
+</dc:subject>
+<dc:publisher>
+<cc:Agent rdf:about="http://www.openclipart.org">
+<dc:title>Jon Phillips</dc:title>
+</cc:Agent>
+</dc:publisher>
+<dc:creator>
+<cc:Agent>
+<dc:title>Jon Phillips</dc:title>
+</cc:Agent>
+</dc:creator>
+<dc:rights>
+<cc:Agent>
+<dc:title>Jon Phillips</dc:title>
+</cc:Agent>
+</dc:rights>
+<dc:date></dc:date>
+<dc:format>image/svg+xml</dc:format>
+<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+<cc:license rdf:resource="http://web.resource.org/cc/PublicDomain"/>
+<dc:language>en</dc:language>
+</cc:Work>
+<cc:License rdf:about="http://web.resource.org/cc/PublicDomain">
+<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/>
+<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
+</cc:License>
+</rdf:RDF>
+</metadata>
+<defs id="defs3"/>
+<sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="549.40674" inkscape:cy="596.00159" inkscape:document-units="px" inkscape:guide-bbox="true" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="615" inkscape:window-width="866" inkscape:window-x="88" inkscape:window-y="116" inkscape:zoom="0.35000000" pagecolor="#ffffff" showguides="true"/>
+<g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1">
+<path d="M 263.41570,235.14588 C 197.17570,235.14588 143.41575,288.90587 143.41575,355.14588 C 143.41575,489.90139 279.34890,525.23318 371.97820,658.45392 C 459.55244,526.05056 600.54070,485.59932 600.54070,355.14588 C 600.54070,288.90588 546.78080,235.14587 480.54070,235.14588 C 432.49280,235.14588 391.13910,263.51631 371.97820,304.33338 C 352.81740,263.51630 311.46370,235.14587 263.41570,235.14588 z " id="path7" sodipodi:nodetypes="ccccccc" style="fill:#e60000;fill-opacity:1.0000000;stroke:#000000;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/>
+<path d="M 265.00000,253.59375 C 207.04033,253.59375 160.00000,300.63407 160.00000,358.59375 C 160.00000,476.50415 278.91857,507.43251 359.96875,624.00000 C 366.52868,614.08205 220.00000,478.47309 220.00000,378.59375 C 220.00000,320.63407 267.04033,273.59375 325.00000,273.59375 C 325.50453,273.59375 325.99718,273.64912 326.50000,273.65625 C 309.22436,261.07286 288.00557,253.59374 265.00000,253.59375 z " id="path220" sodipodi:nodetypes="ccccccc" style="fill:#e6e6e6;fill-opacity:0.64556962;stroke:none;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/>
+</g>
+</svg>
diff --git a/examples/richtext/textobject/main.cpp b/examples/richtext/textobject/main.cpp
new file mode 100644
index 0000000000..263d03eb25
--- /dev/null
+++ b/examples/richtext/textobject/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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/richtext/textobject/svgtextobject.cpp b/examples/richtext/textobject/svgtextobject.cpp
new file mode 100644
index 0000000000..6c336e5f50
--- /dev/null
+++ b/examples/richtext/textobject/svgtextobject.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtSvg>
+
+#include "svgtextobject.h"
+#include "window.h"
+
+//![0]
+QSizeF SvgTextObject::intrinsicSize(QTextDocument *doc, int posInDocument,
+ const QTextFormat &format)
+{
+ QImage bufferedImage = qVariantValue<QImage>(format.property(Window::SvgData));
+ QSize size = bufferedImage.size();
+
+ if (size.height() > 25)
+ size *= 25.0 / (double) size.height();
+
+ return QSizeF(size);
+}
+//![0]
+
+//![1]
+void SvgTextObject::drawObject(QPainter *painter, const QRectF &rect,
+ QTextDocument *doc, int posInDocument,
+ const QTextFormat &format)
+{
+ QImage bufferedImage = qVariantValue<QImage>(format.property(Window::SvgData));
+
+ painter->drawImage(rect, bufferedImage);
+}
+//![1]
+
diff --git a/examples/richtext/textobject/svgtextobject.h b/examples/richtext/textobject/svgtextobject.h
new file mode 100644
index 0000000000..1e91a8bb27
--- /dev/null
+++ b/examples/richtext/textobject/svgtextobject.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGTEXTOBJECT_H
+#define SVGTEXTOBJECT_H
+
+#include <QTextObjectInterface>
+
+QT_BEGIN_NAMESPACE
+class QTextDocument;
+class QTextFormat;
+class QPainter;
+class QRectF;
+class QSizeF;
+QT_END_NAMESPACE
+
+//![0] //![1]
+class SvgTextObject : public QObject, public QTextObjectInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QTextObjectInterface)
+//![1]
+
+public:
+ QSizeF intrinsicSize(QTextDocument *doc, int posInDocument,
+ const QTextFormat &format);
+ void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc,
+ int posInDocument, const QTextFormat &format);
+};
+//![0]
+
+#endif
diff --git a/examples/richtext/textobject/textobject.pro b/examples/richtext/textobject/textobject.pro
new file mode 100644
index 0000000000..fbb809c545
--- /dev/null
+++ b/examples/richtext/textobject/textobject.pro
@@ -0,0 +1,14 @@
+HEADERS = svgtextobject.h \
+ window.h
+SOURCES = main.cpp \
+ svgtextobject.cpp \
+ window.cpp
+
+QT += svg
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/richtext/textobject
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/richtext/textobject
+INSTALLS += target sources
+
diff --git a/examples/richtext/textobject/window.cpp b/examples/richtext/textobject/window.cpp
new file mode 100644
index 0000000000..5fbb10030c
--- /dev/null
+++ b/examples/richtext/textobject/window.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtSvg>
+
+#include "window.h"
+#include "svgtextobject.h"
+
+Window::Window()
+{
+ setupGui();
+ setupTextObject();
+
+ setWindowTitle("Text Object Example");
+}
+
+//![1]
+void Window::insertTextObject()
+{
+ QString fileName = fileNameLineEdit->text();
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::warning(this, tr("Error Opening File"),
+ tr("Could not open '%1'").arg(fileName));
+ }
+
+ QByteArray svgData = file.readAll();
+//![1]
+
+//![2]
+ QTextCharFormat svgCharFormat;
+ svgCharFormat.setObjectType(SvgTextFormat);
+ QSvgRenderer renderer(svgData);
+
+ QImage svgBufferImage(renderer.defaultSize(), QImage::Format_ARGB32);
+ QPainter painter(&svgBufferImage);
+ renderer.render(&painter, svgBufferImage.rect());
+
+ svgCharFormat.setProperty(SvgData, svgBufferImage);
+
+ QTextCursor cursor = textEdit->textCursor();
+ cursor.insertText(QString(QChar::ObjectReplacementCharacter), svgCharFormat);
+ textEdit->setTextCursor(cursor);
+}
+//![2]
+
+//![3]
+void Window::setupTextObject()
+{
+ QObject *svgInterface = new SvgTextObject;
+ textEdit->document()->documentLayout()->registerHandler(SvgTextFormat, svgInterface);
+}
+//![3]
+
+void Window::setupGui()
+{
+ fileNameLabel = new QLabel(tr("Svg File Name:"));
+ fileNameLineEdit = new QLineEdit;
+ insertTextObjectButton = new QPushButton(tr("Insert Image"));
+
+ fileNameLineEdit->setText("./files/heart.svg");
+ connect(insertTextObjectButton, SIGNAL(clicked()),
+ this, SLOT(insertTextObject()));
+
+ QHBoxLayout *bottomLayout = new QHBoxLayout;
+ bottomLayout->addWidget(fileNameLabel);
+ bottomLayout->addWidget(fileNameLineEdit);
+ bottomLayout->addWidget(insertTextObjectButton);
+
+ textEdit = new QTextEdit;
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(textEdit);
+ mainLayout->addLayout(bottomLayout);
+
+ setLayout(mainLayout);
+}
+
diff --git a/examples/richtext/textobject/window.h b/examples/richtext/textobject/window.h
new file mode 100644
index 0000000000..8994e23a35
--- /dev/null
+++ b/examples/richtext/textobject/window.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include <QTextFormat>
+
+QT_BEGIN_NAMESPACE
+class QTextEdit;
+class QLineEdit;
+class QPushButton;
+class QLabel;
+QT_END_NAMESPACE
+
+//![0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ enum { SvgTextFormat = QTextFormat::UserObject + 1 };
+ enum SvgProperties { SvgData = 1 };
+
+ Window();
+
+private slots:
+ void insertTextObject();
+
+private:
+ void setupTextObject();
+ void setupGui();
+
+private:
+ QTextEdit *textEdit;
+ QLabel *fileNameLabel;
+ QLineEdit *fileNameLineEdit;
+ QPushButton *insertTextObjectButton;
+};
+//![0]
+
+#endif
diff --git a/examples/script/README b/examples/script/README
new file mode 100644
index 0000000000..089a7fac95
--- /dev/null
+++ b/examples/script/README
@@ -0,0 +1,40 @@
+Qt is provided with a powerful embedded scripting environment through the QtScript
+classes.
+
+These examples demonstrate the fundamental aspects of scripting applications
+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/script/calculator/calculator.js b/examples/script/calculator/calculator.js
new file mode 100644
index 0000000000..62c2cba077
--- /dev/null
+++ b/examples/script/calculator/calculator.js
@@ -0,0 +1,264 @@
+//! [0]
+function Calculator(ui)
+{
+ this.ui = ui;
+
+ this.pendingAdditiveOperator = "";
+ this.pendingMultiplicativeOperator = "";
+ this.sumInMemory = 0;
+ this.sumSoFar = 0;
+ this.factorSoFar = 0;
+ this.waitingForOperand = true;
+
+ with (ui) {
+ display.text = "0";
+
+ zeroButton.clicked.connect(this, this.digitClicked);
+ oneButton.clicked.connect(this, "digitClicked");
+ twoButton.clicked.connect(this, "digitClicked");
+ threeButton.clicked.connect(this, "digitClicked");
+ fourButton.clicked.connect(this, "digitClicked");
+ fiveButton.clicked.connect(this, "digitClicked");
+ sixButton.clicked.connect(this, "digitClicked");
+ sevenButton.clicked.connect(this, "digitClicked");
+ eightButton.clicked.connect(this, "digitClicked");
+ nineButton.clicked.connect(this, "digitClicked");
+
+ pointButton.clicked.connect(this, "pointClicked");
+ changeSignButton.clicked.connect(this, "changeSignClicked");
+
+ backspaceButton.clicked.connect(this, "backspaceClicked");
+ clearButton.clicked.connect(this, "clear");
+ clearAllButton.clicked.connect(this, "clearAll");
+
+ clearMemoryButton.clicked.connect(this, "clearMemory");
+ readMemoryButton.clicked.connect(this, "readMemory");
+ setMemoryButton.clicked.connect(this, "setMemory");
+ addToMemoryButton.clicked.connect(this, "addToMemory");
+
+ divisionButton.clicked.connect(this, "multiplicativeOperatorClicked");
+ timesButton.clicked.connect(this, "multiplicativeOperatorClicked");
+ minusButton.clicked.connect(this, "additiveOperatorClicked");
+ plusButton.clicked.connect(this, "additiveOperatorClicked");
+
+ squareRootButton.clicked.connect(this, "unaryOperatorClicked");
+ powerButton.clicked.connect(this, "unaryOperatorClicked");
+ reciprocalButton.clicked.connect(this, "unaryOperatorClicked");
+ equalButton.clicked.connect(this, "equalClicked");
+ }
+}
+//! [0]
+
+Calculator.prototype.abortOperation = function()
+{
+ this.clearAll();
+ this.ui.display.text = "####";
+}
+
+Calculator.prototype.calculate = function(rightOperand, pendingOperator)
+{
+ if (pendingOperator == "+") {
+ this.sumSoFar += rightOperand;
+ } else if (pendingOperator == "-") {
+ this.sumSoFar -= rightOperand;
+ } else if (pendingOperator == "*") {
+ this.factorSoFar *= rightOperand;
+ } else if (pendingOperator == "/") {
+ if (rightOperand == 0)
+ return false;
+ this.factorSoFar /= rightOperand;
+ }
+ return true;
+}
+
+//! [1]
+Calculator.prototype.digitClicked = function()
+{
+ var digitValue = __qt_sender__.text - 0;
+ if ((digitValue == 0) && (this.ui.display.text == "0"))
+ return;
+ if (this.waitingForOperand) {
+ this.ui.display.clear();
+ this.waitingForOperand = false;
+ }
+ this.ui.display.text += digitValue;
+}
+//! [1]
+
+Calculator.prototype.unaryOperatorClicked = function()
+{
+ var operand = this.ui.display.text - 0;
+ var result = 0;
+ if (__qt_sender__.text == "Sqrt") {
+ if (operand < 0) {
+ this.abortOperation();
+ return;
+ }
+ result = Math.sqrt(operand);
+ } else if (__qt_sender__.text == "x^2") {
+ result = Math.pow(operand, 2);
+ } else if (__qt_sender__.text == "1/x") {
+ if (operand == 0.0) {
+ this.abortOperation();
+ return;
+ }
+ result = 1 / operand;
+ }
+ this.ui.display.text = result + "";
+ this.waitingForOperand = true;
+}
+
+Calculator.prototype.additiveOperatorClicked = function()
+{
+ var operand = this.ui.display.text - 0;
+
+ if (this.pendingMultiplicativeOperator.length != 0) {
+ if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
+ this.abortOperation();
+ return;
+ }
+ this.ui.display.text = this.factorSoFar + "";
+ operand = this.factorSoFar;
+ this.factorSoFar = 0;
+ this.pendingMultiplicativeOperator = "";
+ }
+
+ if (this.pendingAdditiveOperator.length != 0) {
+ if (!this.calculate(operand, this.pendingAdditiveOperator)) {
+ this.abortOperation();
+ return;
+ }
+ this.ui.display.text = this.sumSoFar + "";
+ } else {
+ this.sumSoFar = operand;
+ }
+
+ this.pendingAdditiveOperator = __qt_sender__.text;
+ this.waitingForOperand = true;
+}
+
+Calculator.prototype.multiplicativeOperatorClicked = function()
+{
+ var operand = this.ui.display.text - 0;
+
+ if (this.pendingMultiplicativeOperator.length != 0) {
+ if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
+ this.abortOperation();
+ return;
+ }
+ this.ui.display.text = this.factorSoFar + "";
+ } else {
+ this.factorSoFar = operand;
+ }
+
+ this.pendingMultiplicativeOperator = __qt_sender__.text;
+ this.waitingForOperand = true;
+}
+
+Calculator.prototype.equalClicked = function()
+{
+ var operand = this.ui.display.text - 0;
+
+ if (this.pendingMultiplicativeOperator.length != 0) {
+ if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
+ this.abortOperation();
+ return;
+ }
+ operand = this.factorSoFar;
+ this.factorSoFar = 0.0;
+ this.pendingMultiplicativeOperator = "";
+ }
+ if (this.pendingAdditiveOperator.length != 0) {
+ if (!this.calculate(operand, this.pendingAdditiveOperator)) {
+ this.abortOperation();
+ return;
+ }
+ this.pendingAdditiveOperator = "";
+ } else {
+ this.sumSoFar = operand;
+ }
+
+ this.ui.display.text = this.sumSoFar + "";
+ this.sumSoFar = 0.0;
+ this.waitingForOperand = true;
+}
+
+Calculator.prototype.pointClicked = function()
+{
+ if (this.waitingForOperand)
+ this.ui.display.text = "0";
+ if (this.ui.display.text.indexOf(".") == -1)
+ this.ui.display.text += ".";
+ this.waitingForOperand = false;
+}
+
+//! [2]
+Calculator.prototype.changeSignClicked = function()
+{
+ var text = this.ui.display.text;
+ var value = text - 0;
+
+ if (value > 0) {
+ text = "-" + text;
+ } else if (value < 0) {
+ text = text.slice(1);
+ }
+ this.ui.display.text = text;
+}
+//! [2]
+
+Calculator.prototype.backspaceClicked = function()
+{
+ if (this.waitingForOperand)
+ return;
+
+ var text = this.ui.display.text;
+ text = text.slice(0, -1);
+ if (text.length == 0) {
+ text = "0";
+ this.waitingForOperand = true;
+ }
+ this.ui.display.text = text;
+}
+
+Calculator.prototype.clear = function()
+{
+ if (this.waitingForOperand)
+ return;
+
+ this.ui.display.text = "0";
+ this.waitingForOperand = true;
+}
+
+Calculator.prototype.clearAll = function()
+{
+ this.sumSoFar = 0.0;
+ this.factorSoFar = 0.0;
+ this.pendingAdditiveOperator = "";
+ this.pendingMultiplicativeOperator = "";
+ this.ui.display.text = "0";
+ this.waitingForOperand = true;
+}
+
+Calculator.prototype.clearMemory = function()
+{
+ this.sumInMemory = 0.0;
+}
+
+Calculator.prototype.readMemory = function()
+{
+ this.ui.display.text = this.sumInMemory + "";
+ this.waitingForOperand = true;
+}
+
+Calculator.prototype.setMemory = function()
+{
+ this.equalClicked();
+ this.sumInMemory = this.ui.display.text - 0;
+}
+
+Calculator.prototype.addToMemory = function()
+{
+ this.equalClicked();
+ this.sumInMemory += this.ui.display.text - 0;
+}
diff --git a/examples/script/calculator/calculator.pro b/examples/script/calculator/calculator.pro
new file mode 100644
index 0000000000..734078ced2
--- /dev/null
+++ b/examples/script/calculator/calculator.pro
@@ -0,0 +1,14 @@
+QT += script
+CONFIG += uitools
+RESOURCES += calculator.qrc
+SOURCES += main.cpp
+
+contains(QT_CONFIG, scripttools): QT += scripttools
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/calculator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.js *.ui
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/calculator
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/script/calculator/calculator.qrc b/examples/script/calculator/calculator.qrc
new file mode 100644
index 0000000000..afa6686693
--- /dev/null
+++ b/examples/script/calculator/calculator.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>calculator.js</file>
+ <file>calculator.ui</file>
+ </qresource>
+</RCC>
diff --git a/examples/script/calculator/calculator.ui b/examples/script/calculator/calculator.ui
new file mode 100644
index 0000000000..bb519ba2a6
--- /dev/null
+++ b/examples/script/calculator/calculator.ui
@@ -0,0 +1,406 @@
+<ui version="4.0" >
+ <class>Calculator</class>
+ <widget class="QWidget" name="Calculator" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>314</width>
+ <height>301</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize" >
+ <size>
+ <width>314</width>
+ <height>301</height>
+ </size>
+ </property>
+ <property name="maximumSize" >
+ <size>
+ <width>314</width>
+ <height>301</height>
+ </size>
+ </property>
+ <property name="windowTitle" >
+ <string>Calculator</string>
+ </property>
+ <widget class="QToolButton" name="backspaceButton" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>50</y>
+ <width>91</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Backspace</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="clearButton" >
+ <property name="geometry" >
+ <rect>
+ <x>110</x>
+ <y>50</y>
+ <width>91</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Clear</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="clearAllButton" >
+ <property name="geometry" >
+ <rect>
+ <x>210</x>
+ <y>50</y>
+ <width>91</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Clear All</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="clearMemoryButton" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>100</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>MC</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="readMemoryButton" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>150</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>MR</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="setMemoryButton" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>200</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>MS</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="addToMemoryButton" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>250</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>M+</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="sevenButton" >
+ <property name="geometry" >
+ <rect>
+ <x>60</x>
+ <y>100</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>7</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="eightButton" >
+ <property name="geometry" >
+ <rect>
+ <x>110</x>
+ <y>100</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>8</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="nineButton" >
+ <property name="geometry" >
+ <rect>
+ <x>160</x>
+ <y>100</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>9</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="fourButton" >
+ <property name="geometry" >
+ <rect>
+ <x>60</x>
+ <y>150</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>4</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="fiveButton" >
+ <property name="geometry" >
+ <rect>
+ <x>110</x>
+ <y>150</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>5</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="sixButton" >
+ <property name="geometry" >
+ <rect>
+ <x>160</x>
+ <y>150</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>6</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="oneButton" >
+ <property name="geometry" >
+ <rect>
+ <x>60</x>
+ <y>200</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>1</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="twoButton" >
+ <property name="geometry" >
+ <rect>
+ <x>110</x>
+ <y>200</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>2</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="threeButton" >
+ <property name="geometry" >
+ <rect>
+ <x>160</x>
+ <y>200</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>3</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="zeroButton" >
+ <property name="geometry" >
+ <rect>
+ <x>60</x>
+ <y>250</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>0</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="pointButton" >
+ <property name="geometry" >
+ <rect>
+ <x>110</x>
+ <y>250</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>.</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="changeSignButton" >
+ <property name="geometry" >
+ <rect>
+ <x>160</x>
+ <y>250</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>+-</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="plusButton" >
+ <property name="geometry" >
+ <rect>
+ <x>210</x>
+ <y>250</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>+</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="divisionButton" >
+ <property name="geometry" >
+ <rect>
+ <x>210</x>
+ <y>100</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>/</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="timesButton" >
+ <property name="geometry" >
+ <rect>
+ <x>210</x>
+ <y>150</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>*</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="minusButton" >
+ <property name="geometry" >
+ <rect>
+ <x>210</x>
+ <y>200</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>-</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="squareRootButton" >
+ <property name="geometry" >
+ <rect>
+ <x>260</x>
+ <y>100</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Sqrt</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="powerButton" >
+ <property name="geometry" >
+ <rect>
+ <x>260</x>
+ <y>150</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>x^2</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="reciprocalButton" >
+ <property name="geometry" >
+ <rect>
+ <x>260</x>
+ <y>200</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>1/x</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="equalButton" >
+ <property name="geometry" >
+ <rect>
+ <x>260</x>
+ <y>250</y>
+ <width>41</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>=</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="display" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>291</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="maxLength" >
+ <number>15</number>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/script/calculator/main.cpp b/examples/script/calculator/main.cpp
new file mode 100644
index 0000000000..4608aa59da
--- /dev/null
+++ b/examples/script/calculator/main.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QUiLoader>
+#include <QtScript>
+#include <QWidget>
+#include <QFile>
+#include <QMainWindow>
+#include <QLineEdit>
+
+#ifndef QT_NO_SCRIPTTOOLS
+#include <QScriptEngineDebugger>
+#endif
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(calculator);
+
+ QApplication app(argc, argv);
+//! [0a]
+ QScriptEngine engine;
+//! [0a]
+
+#ifndef QT_NO_SCRIPTTOOLS
+ QScriptEngineDebugger debugger;
+ debugger.attachTo(&engine);
+ QMainWindow *debugWindow = debugger.standardWindow();
+ debugWindow->resize(1024, 640);
+#endif
+
+//! [0b]
+ QString scriptFileName(":/calculator.js");
+ QFile scriptFile(scriptFileName);
+ scriptFile.open(QIODevice::ReadOnly);
+ engine.evaluate(scriptFile.readAll(), scriptFileName);
+ scriptFile.close();
+//! [0b]
+
+//! [1]
+ QUiLoader loader;
+ QFile uiFile(":/calculator.ui");
+ uiFile.open(QIODevice::ReadOnly);
+ QWidget *ui = loader.load(&uiFile);
+ uiFile.close();
+//! [1]
+
+//! [2]
+ QScriptValue ctor = engine.evaluate("Calculator");
+ QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
+ QScriptValue calc = ctor.construct(QScriptValueList() << scriptUi);
+//! [2]
+
+#ifndef QT_NO_SCRIPTTOOLS
+ QLineEdit *display = qFindChild<QLineEdit*>(ui, "display");
+ QObject::connect(display, SIGNAL(returnPressed()),
+ debugWindow, SLOT(show()));
+#endif
+//! [3]
+ ui->show();
+ return app.exec();
+//! [3]
+}
diff --git a/examples/script/context2d/context2d.cpp b/examples/script/context2d/context2d.cpp
new file mode 100644
index 0000000000..d49cc3d92f
--- /dev/null
+++ b/examples/script/context2d/context2d.cpp
@@ -0,0 +1,825 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "context2d.h"
+
+#include <QVariant>
+
+#include <math.h>
+static const double Q_PI = 3.14159265358979323846; // pi
+
+#define DEGREES(t) ((t) * 180.0 / Q_PI)
+
+#define qClamp(val, min, max) qMin(qMax(val, min), max)
+static QList<qreal> parseNumbersList(QString::const_iterator &itr)
+{
+ QList<qreal> points;
+ QString temp;
+ while ((*itr).isSpace())
+ ++itr;
+ while ((*itr).isNumber() ||
+ (*itr) == '-' || (*itr) == '+' || (*itr) == '.') {
+ temp = QString();
+
+ if ((*itr) == '-')
+ temp += *itr++;
+ else if ((*itr) == '+')
+ temp += *itr++;
+ while ((*itr).isDigit())
+ temp += *itr++;
+ if ((*itr) == '.')
+ temp += *itr++;
+ while ((*itr).isDigit())
+ temp += *itr++;
+ while ((*itr).isSpace())
+ ++itr;
+ if ((*itr) == ',')
+ ++itr;
+ points.append(temp.toDouble());
+ //eat spaces
+ while ((*itr).isSpace())
+ ++itr;
+ }
+
+ return points;
+}
+
+QColor colorFromString(const QString &name)
+{
+ QString::const_iterator itr = name.constBegin();
+ QList<qreal> compo;
+ if (name.startsWith("rgba(")) {
+ ++itr; ++itr; ++itr; ++itr; ++itr;
+ compo = parseNumbersList(itr);
+ if (compo.size() != 4) {
+ return QColor();
+ }
+ //alpha seems to be always between 0-1
+ compo[3] *= 255;
+ return QColor((int)compo[0], (int)compo[1],
+ (int)compo[2], (int)compo[3]);
+ } else if (name.startsWith("rgb(")) {
+ ++itr; ++itr; ++itr; ++itr;
+ compo = parseNumbersList(itr);
+ if (compo.size() != 3) {
+ return QColor();
+ }
+ return QColor((int)qClamp(compo[0], qreal(0), qreal(255)),
+ (int)qClamp(compo[1], qreal(0), qreal(255)),
+ (int)qClamp(compo[2], qreal(0), qreal(255)));
+ } else {
+ //QRgb color;
+ //CSSParser::parseColor(name, color);
+ return QColor(name);
+ }
+}
+
+
+static QPainter::CompositionMode compositeOperatorFromString(const QString &compositeOperator)
+{
+ if ( compositeOperator == "source-over" ) {
+ return QPainter::CompositionMode_SourceOver;
+ } else if ( compositeOperator == "source-out" ) {
+ return QPainter::CompositionMode_SourceOut;
+ } else if ( compositeOperator == "source-in" ) {
+ return QPainter::CompositionMode_SourceIn;
+ } else if ( compositeOperator == "source-atop" ) {
+ return QPainter::CompositionMode_SourceAtop;
+ } else if ( compositeOperator == "destination-atop" ) {
+ return QPainter::CompositionMode_DestinationAtop;
+ } else if ( compositeOperator == "destination-in" ) {
+ return QPainter::CompositionMode_DestinationIn;
+ } else if ( compositeOperator == "destination-out" ) {
+ return QPainter::CompositionMode_DestinationOut;
+ } else if ( compositeOperator == "destination-over" ) {
+ return QPainter::CompositionMode_DestinationOver;
+ } else if ( compositeOperator == "darker" ) {
+ return QPainter::CompositionMode_SourceOver;
+ } else if ( compositeOperator == "lighter" ) {
+ return QPainter::CompositionMode_SourceOver;
+ } else if ( compositeOperator == "copy" ) {
+ return QPainter::CompositionMode_Source;
+ } else if ( compositeOperator == "xor" ) {
+ return QPainter::CompositionMode_Xor;
+ }
+
+ return QPainter::CompositionMode_SourceOver;
+}
+
+static QString compositeOperatorToString(QPainter::CompositionMode op)
+{
+ switch (op) {
+ case QPainter::CompositionMode_SourceOver:
+ return "source-over";
+ case QPainter::CompositionMode_DestinationOver:
+ return "destination-over";
+ case QPainter::CompositionMode_Clear:
+ return "clear";
+ case QPainter::CompositionMode_Source:
+ return "source";
+ case QPainter::CompositionMode_Destination:
+ return "destination";
+ case QPainter::CompositionMode_SourceIn:
+ return "source-in";
+ case QPainter::CompositionMode_DestinationIn:
+ return "destination-in";
+ case QPainter::CompositionMode_SourceOut:
+ return "source-out";
+ case QPainter::CompositionMode_DestinationOut:
+ return "destination-out";
+ case QPainter::CompositionMode_SourceAtop:
+ return "source-atop";
+ case QPainter::CompositionMode_DestinationAtop:
+ return "destination-atop";
+ case QPainter::CompositionMode_Xor:
+ return "xor";
+ case QPainter::CompositionMode_Plus:
+ return "plus";
+ case QPainter::CompositionMode_Multiply:
+ return "multiply";
+ case QPainter::CompositionMode_Screen:
+ return "screen";
+ case QPainter::CompositionMode_Overlay:
+ return "overlay";
+ case QPainter::CompositionMode_Darken:
+ return "darken";
+ case QPainter::CompositionMode_Lighten:
+ return "lighten";
+ case QPainter::CompositionMode_ColorDodge:
+ return "color-dodge";
+ case QPainter::CompositionMode_ColorBurn:
+ return "color-burn";
+ case QPainter::CompositionMode_HardLight:
+ return "hard-light";
+ case QPainter::CompositionMode_SoftLight:
+ return "soft-light";
+ case QPainter::CompositionMode_Difference:
+ return "difference";
+ case QPainter::CompositionMode_Exclusion:
+ return "exclusion";
+ default:
+ break;
+ }
+ return QString();
+}
+
+void Context2D::save()
+{
+ m_stateStack.push(m_state);
+}
+
+
+void Context2D::restore()
+{
+ if (!m_stateStack.isEmpty()) {
+ m_state = m_stateStack.pop();
+ m_state.flags = AllIsFullOfDirt;
+ }
+}
+
+
+void Context2D::scale(qreal x, qreal y)
+{
+ m_state.matrix.scale(x, y);
+ m_state.flags |= DirtyTransformationMatrix;
+}
+
+
+void Context2D::rotate(qreal angle)
+{
+ m_state.matrix.rotate(DEGREES(angle));
+ m_state.flags |= DirtyTransformationMatrix;
+}
+
+
+void Context2D::translate(qreal x, qreal y)
+{
+ m_state.matrix.translate(x, y);
+ m_state.flags |= DirtyTransformationMatrix;
+}
+
+
+void Context2D::transform(qreal m11, qreal m12, qreal m21, qreal m22,
+ qreal dx, qreal dy)
+{
+ QMatrix mat(m11, m12,
+ m21, m22,
+ dx, dy);
+ m_state.matrix *= mat;
+ m_state.flags |= DirtyTransformationMatrix;
+}
+
+
+void Context2D::setTransform(qreal m11, qreal m12, qreal m21, qreal m22,
+ qreal dx, qreal dy)
+{
+ QMatrix mat(m11, m12,
+ m21, m22,
+ dx, dy);
+ m_state.matrix = mat;
+ m_state.flags |= DirtyTransformationMatrix;
+}
+
+
+QString Context2D::globalCompositeOperation() const
+{
+ return compositeOperatorToString(m_state.globalCompositeOperation);
+}
+
+void Context2D::setGlobalCompositeOperation(const QString &op)
+{
+ QPainter::CompositionMode mode =
+ compositeOperatorFromString(op);
+ m_state.globalCompositeOperation = mode;
+ m_state.flags |= DirtyGlobalCompositeOperation;
+}
+
+QVariant Context2D::strokeStyle() const
+{
+ return m_state.strokeStyle;
+}
+
+void Context2D::setStrokeStyle(const QVariant &style)
+{
+ if (qVariantCanConvert<CanvasGradient>(style)) {
+ CanvasGradient cg = qvariant_cast<CanvasGradient>(style);
+ m_state.strokeStyle = cg.value;
+ } else {
+ QColor color = colorFromString(style.toString());
+ m_state.strokeStyle = color;
+ }
+ m_state.flags |= DirtyStrokeStyle;
+}
+
+QVariant Context2D::fillStyle() const
+{
+ return m_state.fillStyle;
+}
+
+//! [3]
+void Context2D::setFillStyle(const QVariant &style)
+{
+ if (qVariantCanConvert<CanvasGradient>(style)) {
+ CanvasGradient cg = qvariant_cast<CanvasGradient>(style);
+ m_state.fillStyle = cg.value;
+ } else {
+ QColor color = colorFromString(style.toString());
+ m_state.fillStyle = color;
+ }
+ m_state.flags |= DirtyFillStyle;
+}
+//! [3]
+
+qreal Context2D::globalAlpha() const
+{
+ return m_state.globalAlpha;
+}
+
+void Context2D::setGlobalAlpha(qreal alpha)
+{
+ m_state.globalAlpha = alpha;
+ m_state.flags |= DirtyGlobalAlpha;
+}
+
+
+CanvasGradient Context2D::createLinearGradient(qreal x0, qreal y0,
+ qreal x1, qreal y1)
+{
+ QLinearGradient g(x0, y0, x1, y1);
+ return CanvasGradient(g);
+}
+
+
+CanvasGradient Context2D::createRadialGradient(qreal x0, qreal y0,
+ qreal r0, qreal x1,
+ qreal y1, qreal r1)
+{
+ QRadialGradient g(QPointF(x1, y1), r0+r1, QPointF(x0, y0));
+ return CanvasGradient(g);
+}
+
+qreal Context2D::lineWidth() const
+{
+ return m_state.lineWidth;
+}
+
+void Context2D::setLineWidth(qreal w)
+{
+ m_state.lineWidth = w;
+ m_state.flags |= DirtyLineWidth;
+}
+
+//! [0]
+QString Context2D::lineCap() const
+{
+ switch (m_state.lineCap) {
+ case Qt::FlatCap:
+ return "butt";
+ case Qt::SquareCap:
+ return "square";
+ case Qt::RoundCap:
+ return "round";
+ default: ;
+ }
+ return QString();
+}
+
+void Context2D::setLineCap(const QString &capString)
+{
+ Qt::PenCapStyle style;
+ if (capString == "round")
+ style = Qt::RoundCap;
+ else if (capString == "square")
+ style = Qt::SquareCap;
+ else if (capString == "butt")
+ style = Qt::FlatCap;
+ m_state.lineCap = style;
+ m_state.flags |= DirtyLineCap;
+}
+//! [0]
+
+QString Context2D::lineJoin() const
+{
+ switch (m_state.lineJoin) {
+ case Qt::RoundJoin:
+ return "round";
+ case Qt::BevelJoin:
+ return "bevel";
+ case Qt::MiterJoin:
+ return "miter";
+ default: ;
+ }
+ return QString();
+}
+
+void Context2D::setLineJoin(const QString &joinString)
+{
+ Qt::PenJoinStyle style;
+ if (joinString == "round")
+ style = Qt::RoundJoin;
+ else if (joinString == "bevel")
+ style = Qt::BevelJoin;
+ else if (joinString == "miter")
+ style = Qt::MiterJoin;
+ m_state.lineJoin = style;
+ m_state.flags |= DirtyLineJoin;
+}
+
+qreal Context2D::miterLimit() const
+{
+ return m_state.miterLimit;
+}
+
+void Context2D::setMiterLimit(qreal m)
+{
+ m_state.miterLimit = m;
+ m_state.flags |= DirtyMiterLimit;
+}
+
+void Context2D::setShadowOffsetX(qreal x)
+{
+ m_state.shadowOffsetX = x;
+ m_state.flags |= DirtyShadowOffsetX;
+}
+
+void Context2D::setShadowOffsetY(qreal y)
+{
+ m_state.shadowOffsetY = y;
+ m_state.flags |= DirtyShadowOffsetY;
+}
+
+void Context2D::setShadowBlur(qreal b)
+{
+ m_state.shadowBlur = b;
+ m_state.flags |= DirtyShadowBlur;
+}
+
+void Context2D::setShadowColor(const QString &str)
+{
+ m_state.shadowColor = colorFromString(str);
+ m_state.flags |= DirtyShadowColor;
+}
+
+qreal Context2D::shadowOffsetX() const
+{
+ return m_state.shadowOffsetX;
+}
+
+qreal Context2D::shadowOffsetY() const
+{
+ return m_state.shadowOffsetY;
+}
+
+
+qreal Context2D::shadowBlur() const
+{
+ return m_state.shadowBlur;
+}
+
+
+QString Context2D::shadowColor() const
+{
+ return m_state.shadowColor.name();
+}
+
+
+void Context2D::clearRect(qreal x, qreal y, qreal w, qreal h)
+{
+ beginPainting();
+ m_painter.save();
+ m_painter.setMatrix(m_state.matrix, false);
+ m_painter.setCompositionMode(QPainter::CompositionMode_Source);
+ m_painter.fillRect(QRectF(x, y, w, h), QColor(0, 0, 0, 0));
+ m_painter.restore();
+ scheduleChange();
+}
+
+
+//! [1]
+void Context2D::fillRect(qreal x, qreal y, qreal w, qreal h)
+{
+ beginPainting();
+ m_painter.save();
+ m_painter.setMatrix(m_state.matrix, false);
+ m_painter.fillRect(QRectF(x, y, w, h), m_painter.brush());
+ m_painter.restore();
+ scheduleChange();
+}
+//! [1]
+
+
+void Context2D::strokeRect(qreal x, qreal y, qreal w, qreal h)
+{
+ QPainterPath path;
+ path.addRect(x, y, w, h);
+ beginPainting();
+ m_painter.save();
+ m_painter.setMatrix(m_state.matrix, false);
+ m_painter.strokePath(path, m_painter.pen());
+ m_painter.restore();
+ scheduleChange();
+}
+
+
+void Context2D::beginPath()
+{
+ m_path = QPainterPath();
+}
+
+
+void Context2D::closePath()
+{
+ m_path.closeSubpath();
+}
+
+
+void Context2D::moveTo(qreal x, qreal y)
+{
+ QPointF pt = m_state.matrix.map(QPointF(x, y));
+ m_path.moveTo(pt);
+}
+
+
+void Context2D::lineTo(qreal x, qreal y)
+{
+ QPointF pt = m_state.matrix.map(QPointF(x, y));
+ m_path.lineTo(pt);
+}
+
+
+void Context2D::quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y)
+{
+ QPointF cp = m_state.matrix.map(QPointF(cpx, cpy));
+ QPointF xy = m_state.matrix.map(QPointF(x, y));
+ m_path.quadTo(cp, xy);
+}
+
+
+void Context2D::bezierCurveTo(qreal cp1x, qreal cp1y,
+ qreal cp2x, qreal cp2y, qreal x, qreal y)
+{
+ QPointF cp1 = m_state.matrix.map(QPointF(cp1x, cp1y));
+ QPointF cp2 = m_state.matrix.map(QPointF(cp2x, cp2y));
+ QPointF end = m_state.matrix.map(QPointF(x, y));
+ m_path.cubicTo(cp1, cp2, end);
+}
+
+
+void Context2D::arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius)
+{
+ //FIXME: this is surely busted
+ QPointF st = m_state.matrix.map(QPointF(x1, y1));
+ QPointF end = m_state.matrix.map(QPointF(x2, y2));
+ m_path.arcTo(st.x(), st.y(),
+ end.x()-st.x(), end.y()-st.y(),
+ radius, 90);
+}
+
+
+void Context2D::rect(qreal x, qreal y, qreal w, qreal h)
+{
+ QPainterPath path; path.addRect(x, y, w, h);
+ path = m_state.matrix.map(path);
+ m_path.addPath(path);
+}
+
+void Context2D::arc(qreal xc, qreal yc, qreal radius,
+ qreal sar, qreal ear,
+ bool anticlockwise)
+{
+ //### HACK
+ // In Qt we don't switch the coordinate system for degrees
+ // and still use the 0,0 as bottom left for degrees so we need
+ // to switch
+ sar = -sar;
+ ear = -ear;
+ anticlockwise = !anticlockwise;
+ //end hack
+
+ float sa = DEGREES(sar);
+ float ea = DEGREES(ear);
+
+ double span = 0;
+
+ double xs = xc - radius;
+ double ys = yc - radius;
+ double width = radius*2;
+ double height = radius*2;
+
+ if (!anticlockwise && (ea < sa)) {
+ span += 360;
+ } else if (anticlockwise && (sa < ea)) {
+ span -= 360;
+ }
+
+ //### this is also due to switched coordinate system
+ // we would end up with a 0 span instead of 360
+ if (!(qFuzzyCompare(span + (ea - sa) + 1, 1) &&
+ qFuzzyCompare(qAbs(span), 360))) {
+ span += ea - sa;
+ }
+
+ QPainterPath path;
+ path.moveTo(QPointF(xc + radius * cos(sar),
+ yc - radius * sin(sar)));
+
+ path.arcTo(xs, ys, width, height, sa, span);
+ path = m_state.matrix.map(path);
+ m_path.addPath(path);
+}
+
+
+void Context2D::fill()
+{
+ beginPainting();
+ m_painter.fillPath(m_path, m_painter.brush());
+ scheduleChange();
+}
+
+
+void Context2D::stroke()
+{
+ beginPainting();
+ m_painter.save();
+ m_painter.setMatrix(m_state.matrix, false);
+ QPainterPath tmp = m_state.matrix.inverted().map(m_path);
+ m_painter.strokePath(tmp, m_painter.pen());
+ m_painter.restore();
+ scheduleChange();
+}
+
+
+void Context2D::clip()
+{
+ m_state.clipPath = m_path;
+ m_state.flags |= DirtyClippingRegion;
+}
+
+
+bool Context2D::isPointInPath(qreal x, qreal y) const
+{
+ return m_path.contains(QPointF(x, y));
+}
+
+
+ImageData Context2D::getImageData(qreal sx, qreal sy, qreal sw, qreal sh)
+{
+ Q_UNUSED(sx);
+ Q_UNUSED(sy);
+ Q_UNUSED(sw);
+ Q_UNUSED(sh);
+ return ImageData();
+}
+
+
+void Context2D::putImageData(ImageData image, qreal dx, qreal dy)
+{
+ Q_UNUSED(image);
+ Q_UNUSED(dx);
+ Q_UNUSED(dy);
+}
+
+Context2D::Context2D(QObject *parent)
+ : QObject(parent), m_changeTimerId(-1)
+{
+ reset();
+}
+
+const QImage &Context2D::endPainting()
+{
+ if (m_painter.isActive())
+ m_painter.end();
+ return m_image;
+}
+
+void Context2D::beginPainting()
+{
+ if (!m_painter.isActive()) {
+ m_painter.begin(&m_image);
+ m_painter.setRenderHint(QPainter::Antialiasing);
+ if (!m_state.clipPath.isEmpty())
+ m_painter.setClipPath(m_state.clipPath);
+ m_painter.setBrush(m_state.fillStyle);
+ m_painter.setOpacity(m_state.globalAlpha);
+ QPen pen;
+ pen.setBrush(m_state.strokeStyle);
+ if (pen.style() == Qt::NoPen)
+ pen.setStyle(Qt::SolidLine);
+ pen.setCapStyle(m_state.lineCap);
+ pen.setJoinStyle(m_state.lineJoin);
+ pen.setWidthF(m_state.lineWidth);
+ pen.setMiterLimit(m_state.miterLimit);
+ m_painter.setPen(pen);
+ } else {
+ if ((m_state.flags & DirtyClippingRegion) && !m_state.clipPath.isEmpty())
+ m_painter.setClipPath(m_state.clipPath);
+ if (m_state.flags & DirtyFillStyle)
+ m_painter.setBrush(m_state.fillStyle);
+ if (m_state.flags & DirtyGlobalAlpha)
+ m_painter.setOpacity(m_state.globalAlpha);
+ if (m_state.flags & DirtyGlobalCompositeOperation)
+ m_painter.setCompositionMode(m_state.globalCompositeOperation);
+ if (m_state.flags & MDirtyPen) {
+ QPen pen = m_painter.pen();
+ if (m_state.flags & DirtyStrokeStyle)
+ pen.setBrush(m_state.strokeStyle);
+ if (m_state.flags & DirtyLineWidth)
+ pen.setWidthF(m_state.lineWidth);
+ if (m_state.flags & DirtyLineCap)
+ pen.setCapStyle(m_state.lineCap);
+ if (m_state.flags & DirtyLineJoin)
+ pen.setJoinStyle(m_state.lineJoin);
+ if (m_state.flags & DirtyMiterLimit)
+ pen.setMiterLimit(m_state.miterLimit);
+ m_painter.setPen(pen);
+ }
+ m_state.flags = 0;
+ }
+}
+
+void Context2D::clear()
+{
+ endPainting();
+ m_image.fill(qRgba(0,0,0,0));
+ scheduleChange();
+}
+
+void Context2D::reset()
+{
+ m_stateStack.clear();
+ m_state.matrix = QMatrix();
+ m_state.clipPath = QPainterPath();
+ m_state.globalAlpha = 1.0;
+ m_state.globalCompositeOperation = QPainter::CompositionMode_SourceOver;
+ m_state.strokeStyle = Qt::black;
+ m_state.fillStyle = Qt::black;
+ m_state.lineWidth = 1;
+ m_state.lineCap = Qt::FlatCap;
+ m_state.lineJoin = Qt::MiterJoin;
+ m_state.miterLimit = 10;
+ m_state.shadowOffsetX = 0;
+ m_state.shadowOffsetY = 0;
+ m_state.shadowBlur = 0;
+ m_state.shadowColor = qRgba(0, 0, 0, 0);
+ m_state.flags = AllIsFullOfDirt;
+ clear();
+}
+
+void Context2D::setSize(int width, int height)
+{
+ endPainting();
+ QImage newi(width, height, QImage::Format_ARGB32_Premultiplied);
+ newi.fill(qRgba(0,0,0,0));
+ QPainter p(&newi);
+ p.drawImage(0, 0, m_image);
+ p.end();
+ m_image = newi;
+ scheduleChange();
+}
+
+void Context2D::setSize(const QSize &size)
+{
+ setSize(size.width(), size.height());
+}
+
+QSize Context2D::size() const
+{
+ return m_image.size();
+}
+
+void Context2D::drawImage(DomImage *image, qreal dx, qreal dy)
+{
+ if (!image)
+ return;
+ if (dx < 0) {
+ qreal sx = qAbs(dx);
+ qreal sy = qAbs(dy);
+ qreal sw = image->width() - sx;
+ qreal sh = image->height() - sy;
+
+ drawImage(image, sx, sy, sw, sh, 0, 0, sw, sh);
+ } else {
+ beginPainting();
+ m_painter.drawImage(QPointF(dx, dy), image->image());
+ scheduleChange();
+ }
+}
+
+void Context2D::drawImage(DomImage *image, qreal dx, qreal dy,
+ qreal dw, qreal dh)
+{
+ if (!image)
+ return;
+ beginPainting();
+ m_painter.drawImage(QRectF(dx, dy, dw, dh).toRect(), image->image());
+ scheduleChange();
+}
+
+void Context2D::drawImage(DomImage *image, qreal sx, qreal sy,
+ qreal sw, qreal sh, qreal dx, qreal dy,
+ qreal dw, qreal dh)
+{
+ if (!image)
+ return;
+ beginPainting();
+ m_painter.drawImage(QRectF(dx, dy, dw, dh), image->image(),
+ QRectF(sx, sy, sw, sh));
+ scheduleChange();
+}
+
+//! [2]
+void Context2D::scheduleChange()
+{
+ if (m_changeTimerId == -1)
+ m_changeTimerId = startTimer(0);
+}
+
+void Context2D::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == m_changeTimerId) {
+ killTimer(m_changeTimerId);
+ m_changeTimerId = -1;
+ emit changed(endPainting());
+ } else {
+ QObject::timerEvent(e);
+ }
+}
+//! [2]
diff --git a/examples/script/context2d/context2d.h b/examples/script/context2d/context2d.h
new file mode 100644
index 0000000000..38188f7b37
--- /dev/null
+++ b/examples/script/context2d/context2d.h
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONTEXT2D_H
+#define CONTEXT2D_H
+
+#include "domimage.h"
+
+#include <QPainter>
+#include <QPainterPath>
+#include <QString>
+#include <QStack>
+#include <QMetaType>
+#include <QTimerEvent>
+
+// [3]
+class CanvasGradient
+{
+public:
+ CanvasGradient(const QGradient &v)
+ : value(v) {}
+ CanvasGradient() {}
+
+ QGradient value;
+};
+// [3]
+
+Q_DECLARE_METATYPE(CanvasGradient)
+Q_DECLARE_METATYPE(CanvasGradient*)
+
+class ImageData {
+};
+
+class QContext2DCanvas;
+
+//! [0]
+class Context2D : public QObject
+{
+ Q_OBJECT
+ // compositing
+ Q_PROPERTY(qreal globalAlpha READ globalAlpha WRITE setGlobalAlpha)
+ Q_PROPERTY(QString globalCompositeOperation READ globalCompositeOperation WRITE setGlobalCompositeOperation)
+ Q_PROPERTY(QVariant strokeStyle READ strokeStyle WRITE setStrokeStyle)
+ Q_PROPERTY(QVariant fillStyle READ fillStyle WRITE setFillStyle)
+ // line caps/joins
+ Q_PROPERTY(qreal lineWidth READ lineWidth WRITE setLineWidth)
+ Q_PROPERTY(QString lineCap READ lineCap WRITE setLineCap)
+ Q_PROPERTY(QString lineJoin READ lineJoin WRITE setLineJoin)
+ Q_PROPERTY(qreal miterLimit READ miterLimit WRITE setMiterLimit)
+ // shadows
+ Q_PROPERTY(qreal shadowOffsetX READ shadowOffsetX WRITE setShadowOffsetX)
+ Q_PROPERTY(qreal shadowOffsetY READ shadowOffsetY WRITE setShadowOffsetY)
+ Q_PROPERTY(qreal shadowBlur READ shadowBlur WRITE setShadowBlur)
+ Q_PROPERTY(QString shadowColor READ shadowColor WRITE setShadowColor)
+//! [0]
+
+public:
+ Context2D(QObject *parent = 0);
+ void setSize(int width, int height);
+ void setSize(const QSize &size);
+ QSize size() const;
+
+ void clear();
+ void reset();
+
+ // compositing
+ qreal globalAlpha() const; // (default 1.0)
+ QString globalCompositeOperation() const; // (default over)
+ QVariant strokeStyle() const; // (default black)
+ QVariant fillStyle() const; // (default black)
+
+ void setGlobalAlpha(qreal alpha);
+ void setGlobalCompositeOperation(const QString &op);
+ void setStrokeStyle(const QVariant &style);
+ void setFillStyle(const QVariant &style);
+
+ // line caps/joins
+ qreal lineWidth() const; // (default 1)
+ QString lineCap() const; // "butt", "round", "square" (default "butt")
+ QString lineJoin() const; // "round", "bevel", "miter" (default "miter")
+ qreal miterLimit() const; // (default 10)
+
+ void setLineWidth(qreal w);
+ void setLineCap(const QString &s);
+ void setLineJoin(const QString &s);
+ void setMiterLimit(qreal m);
+
+ // shadows
+ qreal shadowOffsetX() const; // (default 0)
+ qreal shadowOffsetY() const; // (default 0)
+ qreal shadowBlur() const; // (default 0)
+ QString shadowColor() const; // (default black)
+
+ void setShadowOffsetX(qreal x);
+ void setShadowOffsetY(qreal y);
+ void setShadowBlur(qreal b);
+ void setShadowColor(const QString &str);
+
+//! [1]
+public slots:
+ void save(); // push state on state stack
+ void restore(); // pop state stack and restore state
+
+ void scale(qreal x, qreal y);
+ void rotate(qreal angle);
+ void translate(qreal x, qreal y);
+ void transform(qreal m11, qreal m12, qreal m21, qreal m22,
+ qreal dx, qreal dy);
+ void setTransform(qreal m11, qreal m12, qreal m21, qreal m22,
+ qreal dx, qreal dy);
+
+ CanvasGradient createLinearGradient(qreal x0, qreal y0,
+ qreal x1, qreal y1);
+ CanvasGradient createRadialGradient(qreal x0, qreal y0,
+ qreal r0, qreal x1,
+ qreal y1, qreal r1);
+
+ // rects
+ void clearRect(qreal x, qreal y, qreal w, qreal h);
+ void fillRect(qreal x, qreal y, qreal w, qreal h);
+ void strokeRect(qreal x, qreal y, qreal w, qreal h);
+
+ // path API
+ void beginPath();
+ void closePath();
+ void moveTo(qreal x, qreal y);
+ void lineTo(qreal x, qreal y);
+ void quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y);
+ void bezierCurveTo(qreal cp1x, qreal cp1y,
+ qreal cp2x, qreal cp2y, qreal x, qreal y);
+ void arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius);
+ void rect(qreal x, qreal y, qreal w, qreal h);
+ void arc(qreal x, qreal y, qreal radius,
+ qreal startAngle, qreal endAngle,
+ bool anticlockwise);
+ void fill();
+ void stroke();
+ void clip();
+ bool isPointInPath(qreal x, qreal y) const;
+//! [1]
+
+ // drawing images
+ void drawImage(DomImage *image, qreal dx, qreal dy);
+ void drawImage(DomImage *image, qreal dx, qreal dy,
+ qreal dw, qreal dh);
+ void drawImage(DomImage *image, qreal sx, qreal sy,
+ qreal sw, qreal sh, qreal dx, qreal dy,
+ qreal dw, qreal dh);
+
+ // pixel manipulation
+ ImageData getImageData(qreal sx, qreal sy, qreal sw, qreal sh);
+ void putImageData(ImageData image, qreal dx, qreal dy);
+
+//! [2]
+signals:
+ void changed(const QImage &image);
+//! [2]
+
+protected:
+ void timerEvent(QTimerEvent *e);
+
+private:
+ void beginPainting();
+ const QImage &endPainting();
+ void scheduleChange();
+
+ int m_changeTimerId;
+ QImage m_image;
+ QPainter m_painter;
+ QPainterPath m_path;
+
+ enum DirtyFlag {
+ DirtyTransformationMatrix = 0x00001,
+ DirtyClippingRegion = 0x00002,
+ DirtyStrokeStyle = 0x00004,
+ DirtyFillStyle = 0x00008,
+ DirtyGlobalAlpha = 0x00010,
+ DirtyLineWidth = 0x00020,
+ DirtyLineCap = 0x00040,
+ DirtyLineJoin = 0x00080,
+ DirtyMiterLimit = 0x00100,
+ MDirtyPen = DirtyStrokeStyle
+ | DirtyLineWidth
+ | DirtyLineCap
+ | DirtyLineJoin
+ | DirtyMiterLimit,
+ DirtyShadowOffsetX = 0x00200,
+ DirtyShadowOffsetY = 0x00400,
+ DirtyShadowBlur = 0x00800,
+ DirtyShadowColor = 0x01000,
+ DirtyGlobalCompositeOperation = 0x2000,
+ DirtyFont = 0x04000,
+ DirtyTextAlign = 0x08000,
+ DirtyTextBaseline = 0x10000,
+ AllIsFullOfDirt = 0xfffff
+ };
+
+ struct State {
+ State() : flags(0) {}
+ QMatrix matrix;
+ QPainterPath clipPath;
+ QBrush strokeStyle;
+ QBrush fillStyle;
+ qreal globalAlpha;
+ qreal lineWidth;
+ Qt::PenCapStyle lineCap;
+ Qt::PenJoinStyle lineJoin;
+ qreal miterLimit;
+ qreal shadowOffsetX;
+ qreal shadowOffsetY;
+ qreal shadowBlur;
+ QColor shadowColor;
+ QPainter::CompositionMode globalCompositeOperation;
+ QFont font;
+ int textAlign;
+ int textBaseline;
+ int flags;
+ };
+ State m_state;
+ QStack<State> m_stateStack;
+};
+
+#endif
diff --git a/examples/script/context2d/context2d.pro b/examples/script/context2d/context2d.pro
new file mode 100644
index 0000000000..be14272b96
--- /dev/null
+++ b/examples/script/context2d/context2d.pro
@@ -0,0 +1,32 @@
+TEMPLATE = app
+QT += script
+# Input
+HEADERS += qcontext2dcanvas.h \
+ context2d.h \
+ domimage.h \
+ environment.h \
+ window.h
+SOURCES += qcontext2dcanvas.cpp \
+ context2d.cpp \
+ domimage.cpp \
+ environment.cpp \
+ window.cpp \
+ main.cpp
+RESOURCES += context2d.qrc
+
+contains(QT_CONFIG, scripttools): QT += scripttools
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/context2d
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS context2d.pro scripts
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/context2d
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+symbian:{
+ TARGET.UID3 = 0xA000C608
+ TARGET.EPOCHEAPSIZE = 0x200000 0xA00000
+ contextScripts.path = .
+ contextScripts.sources = scripts
+ DEPLOYMENT += contextScripts
+} \ No newline at end of file
diff --git a/examples/script/context2d/context2d.qrc b/examples/script/context2d/context2d.qrc
new file mode 100644
index 0000000000..75e570cdcd
--- /dev/null
+++ b/examples/script/context2d/context2d.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>scripts</file>
+</qresource>
+</RCC>
diff --git a/examples/script/context2d/domimage.cpp b/examples/script/context2d/domimage.cpp
new file mode 100644
index 0000000000..66a2c956dd
--- /dev/null
+++ b/examples/script/context2d/domimage.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "domimage.h"
+
+#include <QVariant>
+
+#include <qscriptcontext.h>
+
+QScriptValue DomImage::s_self;
+
+DomImage::DomImage()
+{
+}
+
+
+int DomImage::width() const
+{
+ return m_image.width();
+}
+
+
+int DomImage::height() const
+{
+ return m_image.height();
+}
+
+
+QString DomImage::src() const
+{
+ return m_src;
+}
+
+void DomImage::setSrc(const QString &src)
+{
+ m_src = src;
+ m_image = QImage(m_src);
+}
+
+
+QString DomImage::name() const
+{
+ return m_src;
+}
+
+static QScriptValue Image(QScriptContext *context, QScriptEngine *env)
+{
+ QScriptValue val = context->thisObject();
+ DomImage *image = new DomImage();
+ QScriptValue klass = env->newVariant(qVariantFromValue(image));
+ klass.setPrototype(DomImage::s_self);
+ return klass;
+}
+
+
+static QScriptValue width(QScriptContext *context, QScriptEngine *)
+{
+ QScriptValue val = context->thisObject();
+
+ DomImage *image = qvariant_cast<DomImage*> (val.toVariant());
+ if (image)
+ return image->width();
+
+ return 0;
+}
+
+
+static QScriptValue height(QScriptContext *context, QScriptEngine *)
+{
+ QScriptValue val = context->thisObject();
+
+ DomImage *image = qvariant_cast<DomImage*> (val.toVariant());
+ if (image)
+ return image->height();
+
+ return 0;
+}
+
+
+static QScriptValue setSrc(QScriptContext *context, QScriptEngine *env)
+{
+ QScriptValue val = context->thisObject();
+ QString src = context->argument(0).toString();
+
+ DomImage *image = qvariant_cast<DomImage*> (val.toVariant());
+ if (image)
+ image->setSrc(src);
+
+ return env->undefinedValue();
+}
+
+
+static QScriptValue name(QScriptContext *context, QScriptEngine *)
+{
+ QScriptValue val = context->thisObject();
+
+ DomImage *image = qvariant_cast<DomImage*> (val.toVariant());
+ if (image)
+ return image->name();
+
+ return QString();
+}
+
+
+void DomImage::setup(QScriptEngine *e)
+{
+ qRegisterMetaType<DomImage>();
+
+ e->globalObject().setProperty("Image",
+ e->newFunction(::Image, 0));
+
+ s_self = e->newObject();
+ s_self.setProperty("setSrc", e->newFunction(&::setSrc, 1));
+ s_self.setProperty("width", e->newFunction(&::width));
+ s_self.setProperty("height", e->newFunction(&::height));
+ s_self.setProperty("name", e->newFunction(&::name));
+
+ e->setDefaultPrototype(qMetaTypeId<DomImage>(), s_self);
+}
diff --git a/examples/script/context2d/domimage.h b/examples/script/context2d/domimage.h
new file mode 100644
index 0000000000..0793d1dae3
--- /dev/null
+++ b/examples/script/context2d/domimage.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DOMIMAGE_H
+#define DOMIMAGE_H
+
+#include <QPixmap>
+#include <QImage>
+#include <QMetaType>
+
+#include <qscriptengine.h>
+
+class DomImage
+{
+public:
+ DomImage();
+ static void setup(QScriptEngine *e);
+
+ int width() const;
+ int height() const;
+
+ QString src() const;
+ void setSrc(const QString &src);
+
+ QString name() const;
+
+ static QScriptValue s_self;
+
+ const QImage &image() const
+ {
+ return m_image;
+ }
+private:
+ QImage m_image;
+ QString m_src;
+ //attribute boolean isMap;
+ //attribute DOMString longDesc;
+ //attribute DOMString useMap;
+ //attribute DOMString align;
+ //attribute DOMString alt;
+ //attribute DOMString border;
+ //attribute long vspace;
+ //attribute long hspace;
+};
+
+Q_DECLARE_METATYPE(DomImage)
+Q_DECLARE_METATYPE(DomImage*)
+
+#endif
diff --git a/examples/script/context2d/environment.cpp b/examples/script/context2d/environment.cpp
new file mode 100644
index 0000000000..1c1a3a6abf
--- /dev/null
+++ b/examples/script/context2d/environment.cpp
@@ -0,0 +1,561 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "environment.h"
+#include "qcontext2dcanvas.h"
+#include "context2d.h"
+#include <QScriptValueIterator>
+#include <QDateTime>
+
+struct FakeDomEvent
+{
+ enum KeyCodes {
+ DOM_VK_UNDEFINED = 0x0,
+ DOM_VK_RIGHT_ALT = 0x12,
+ DOM_VK_LEFT_ALT = 0x12,
+ DOM_VK_LEFT_CONTROL = 0x11,
+ DOM_VK_RIGHT_CONTROL = 0x11,
+ DOM_VK_LEFT_SHIFT = 0x10,
+ DOM_VK_RIGHT_SHIFT = 0x10,
+ DOM_VK_META = 0x9D,
+ DOM_VK_BACK_SPACE = 0x08,
+ DOM_VK_CAPS_LOCK = 0x14,
+ DOM_VK_DELETE = 0x7F,
+ DOM_VK_END = 0x23,
+ DOM_VK_ENTER = 0x0D,
+ DOM_VK_ESCAPE = 0x1B,
+ DOM_VK_HOME = 0x24,
+ DOM_VK_NUM_LOCK = 0x90,
+ DOM_VK_PAUSE = 0x13,
+ DOM_VK_PRINTSCREEN = 0x9A,
+ DOM_VK_SCROLL_LOCK = 0x91,
+ DOM_VK_SPACE = 0x20,
+ DOM_VK_TAB = 0x09,
+ DOM_VK_LEFT = 0x25,
+ DOM_VK_RIGHT = 0x27,
+ DOM_VK_UP = 0x26,
+ DOM_VK_DOWN = 0x28,
+ DOM_VK_PAGE_DOWN = 0x22,
+ DOM_VK_PAGE_UP = 0x21,
+ DOM_VK_F1 = 0x70,
+ DOM_VK_F2 = 0x71,
+ DOM_VK_F3 = 0x72,
+ DOM_VK_F4 = 0x73,
+ DOM_VK_F5 = 0x74,
+ DOM_VK_F6 = 0x75,
+ DOM_VK_F7 = 0x76,
+ DOM_VK_F8 = 0x77,
+ DOM_VK_F9 = 0x78,
+ DOM_VK_F10 = 0x79,
+ DOM_VK_F11 = 0x7A,
+ DOM_VK_F12 = 0x7B,
+ DOM_VK_F13 = 0xF000,
+ DOM_VK_F14 = 0xF001,
+ DOM_VK_F15 = 0xF002,
+ DOM_VK_F16 = 0xF003,
+ DOM_VK_F17 = 0xF004,
+ DOM_VK_F18 = 0xF005,
+ DOM_VK_F19 = 0xF006,
+ DOM_VK_F20 = 0xF007,
+ DOM_VK_F21 = 0xF008,
+ DOM_VK_F22 = 0xF009,
+ DOM_VK_F23 = 0xF00A,
+ DOM_VK_F24 = 0xF00B
+ };
+
+ static int qtToDomKey(int keyCode);
+};
+
+int FakeDomEvent::qtToDomKey(int keyCode)
+{
+ switch (keyCode) {
+ case Qt::Key_Backspace:
+ return DOM_VK_BACK_SPACE;
+ case Qt::Key_Enter:
+ return DOM_VK_ENTER;
+ case Qt::Key_Return:
+ return DOM_VK_ENTER;
+ case Qt::Key_NumLock:
+ return DOM_VK_NUM_LOCK;
+ case Qt::Key_Alt:
+ return DOM_VK_RIGHT_ALT;
+ case Qt::Key_Control:
+ return DOM_VK_LEFT_CONTROL;
+ case Qt::Key_Shift:
+ return DOM_VK_LEFT_SHIFT;
+ case Qt::Key_Meta:
+ return DOM_VK_META;
+ case Qt::Key_CapsLock:
+ return DOM_VK_CAPS_LOCK;
+ case Qt::Key_Delete:
+ return DOM_VK_DELETE;
+ case Qt::Key_End:
+ return DOM_VK_END;
+ case Qt::Key_Escape:
+ return DOM_VK_ESCAPE;
+ case Qt::Key_Home:
+ return DOM_VK_HOME;
+ case Qt::Key_Pause:
+ return DOM_VK_PAUSE;
+ case Qt::Key_Print:
+ return DOM_VK_PRINTSCREEN;
+ case Qt::Key_ScrollLock:
+ return DOM_VK_SCROLL_LOCK;
+ case Qt::Key_Left:
+ return DOM_VK_LEFT;
+ case Qt::Key_Right:
+ return DOM_VK_RIGHT;
+ case Qt::Key_Up:
+ return DOM_VK_UP;
+ case Qt::Key_Down:
+ return DOM_VK_DOWN;
+ case Qt::Key_PageDown:
+ return DOM_VK_PAGE_DOWN;
+ case Qt::Key_PageUp:
+ return DOM_VK_PAGE_UP;
+ case Qt::Key_F1:
+ return DOM_VK_F1;
+ case Qt::Key_F2:
+ return DOM_VK_F2;
+ case Qt::Key_F3:
+ return DOM_VK_F3;
+ case Qt::Key_F4:
+ return DOM_VK_F4;
+ case Qt::Key_F5:
+ return DOM_VK_F5;
+ case Qt::Key_F6:
+ return DOM_VK_F6;
+ case Qt::Key_F7:
+ return DOM_VK_F7;
+ case Qt::Key_F8:
+ return DOM_VK_F8;
+ case Qt::Key_F9:
+ return DOM_VK_F9;
+ case Qt::Key_F10:
+ return DOM_VK_F10;
+ case Qt::Key_F11:
+ return DOM_VK_F11;
+ case Qt::Key_F12:
+ return DOM_VK_F12;
+ case Qt::Key_F13:
+ return DOM_VK_F13;
+ case Qt::Key_F14:
+ return DOM_VK_F14;
+ case Qt::Key_F15:
+ return DOM_VK_F15;
+ case Qt::Key_F16:
+ return DOM_VK_F16;
+ case Qt::Key_F17:
+ return DOM_VK_F17;
+ case Qt::Key_F18:
+ return DOM_VK_F18;
+ case Qt::Key_F19:
+ return DOM_VK_F19;
+ case Qt::Key_F20:
+ return DOM_VK_F20;
+ case Qt::Key_F21:
+ return DOM_VK_F21;
+ case Qt::Key_F22:
+ return DOM_VK_F22;
+ case Qt::Key_F23:
+ return DOM_VK_F23;
+ case Qt::Key_F24:
+ return DOM_VK_F24;
+ }
+ return keyCode;
+}
+
+//! [0]
+Environment::Environment(QObject *parent)
+ : QObject(parent)
+{
+ m_engine = new QScriptEngine(this);
+
+ m_document = m_engine->newQObject(
+ new Document(this), QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSuperClassContents);
+
+ CanvasGradientPrototype::setup(m_engine);
+
+ m_originalGlobalObject = m_engine->globalObject();
+ reset();
+}
+//! [0]
+
+Environment::~Environment()
+{
+}
+
+QScriptEngine *Environment::engine() const
+{
+ return m_engine;
+}
+
+QScriptValue Environment::document() const
+{
+ return m_document;
+}
+
+int Environment::setTimeout(const QScriptValue &expression, int delay)
+{
+ if (expression.isString() || expression.isFunction()) {
+ int timerId = startTimer(delay);
+ m_timeoutHash.insert(timerId, expression);
+ return timerId;
+ }
+ return -1;
+}
+
+void Environment::clearTimeout(int timerId)
+{
+ killTimer(timerId);
+ m_timeoutHash.remove(timerId);
+}
+
+//! [1]
+int Environment::setInterval(const QScriptValue &expression, int delay)
+{
+ if (expression.isString() || expression.isFunction()) {
+ int timerId = startTimer(delay);
+ m_intervalHash.insert(timerId, expression);
+ return timerId;
+ }
+ return -1;
+}
+
+void Environment::clearInterval(int timerId)
+{
+ killTimer(timerId);
+ m_intervalHash.remove(timerId);
+}
+
+void Environment::timerEvent(QTimerEvent *event)
+{
+ int id = event->timerId();
+ QScriptValue expression = m_intervalHash.value(id);
+ if (!expression.isValid()) {
+ expression = m_timeoutHash.value(id);
+ if (expression.isValid())
+ killTimer(id);
+ }
+ if (expression.isString()) {
+ evaluate(expression.toString());
+ } else if (expression.isFunction()) {
+ expression.call();
+ }
+ maybeEmitScriptError();
+}
+//! [1]
+
+//! [5]
+void Environment::addCanvas(QContext2DCanvas *canvas)
+{
+ m_canvases.append(canvas);
+}
+
+QContext2DCanvas *Environment::canvasByName(const QString &name) const
+{
+ for (int i = 0; i < m_canvases.size(); ++i) {
+ QContext2DCanvas *canvas = m_canvases.at(i);
+ if (canvas->objectName() == name)
+ return canvas;
+ }
+ return 0;
+}
+//! [5]
+
+QList<QContext2DCanvas*> Environment::canvases() const
+{
+ return m_canvases;
+}
+
+void Environment::reset()
+{
+ if (m_engine->isEvaluating())
+ m_engine->abortEvaluation();
+
+ {
+ QHash<int, QScriptValue>::const_iterator it;
+ for (it = m_intervalHash.constBegin(); it != m_intervalHash.constEnd(); ++it)
+ killTimer(it.key());
+ m_intervalHash.clear();
+ for (it = m_timeoutHash.constBegin(); it != m_timeoutHash.constEnd(); ++it)
+ killTimer(it.key());
+ m_timeoutHash.clear();
+ }
+
+ for (int i = 0; i < m_canvases.size(); ++i)
+ m_canvases.at(i)->reset();
+
+ QScriptValue self = m_engine->newQObject(
+ this, QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSuperClassContents);
+
+ {
+ QScriptValueIterator it(m_originalGlobalObject);
+ while (it.hasNext()) {
+ it.next();
+ self.setProperty(it.scriptName(), it.value(), it.flags());
+ }
+ }
+
+ self.setProperty("self", self);
+ self.setProperty("window", self);
+
+ QScriptValue navigator = m_engine->newObject();
+ navigator.setProperty("appCodeName", "context2d");
+ navigator.setProperty("appMinorVersion", 1);
+ navigator.setProperty("appVersion", 1);
+ navigator.setProperty("browserLanguage", "en_US");
+ navigator.setProperty("cookieEnabled", false);
+ navigator.setProperty("cpuClass", "i686");
+ navigator.setProperty("onLine", false);
+ navigator.setProperty("platform", "bogus OS");
+ navigator.setProperty("systemLanguage", "en_US");
+ navigator.setProperty("userAgent", "Context2D/1.1");
+ navigator.setProperty("userLanguage", "en_US");
+ self.setProperty("navigator", navigator);
+
+ m_engine->setGlobalObject(self);
+
+ m_engine->collectGarbage();
+}
+
+QScriptValue Environment::evaluate(const QString &code, const QString &fileName)
+{
+ return m_engine->evaluate(code, fileName);
+}
+
+//! [2]
+QScriptValue Environment::toWrapper(QObject *object)
+{
+ return m_engine->newQObject(object, QScriptEngine::QtOwnership,
+ QScriptEngine::PreferExistingWrapperObject
+ | QScriptEngine::ExcludeSuperClassContents);
+}
+//! [2]
+
+//! [3]
+void Environment::handleEvent(QContext2DCanvas *canvas, QMouseEvent *e)
+{
+ QString type;
+ switch (e->type()) {
+ case QEvent::MouseButtonPress:
+ type = "mousedown"; break;
+ case QEvent::MouseButtonRelease:
+ type = "mouseup"; break;
+ case QEvent::MouseMove:
+ type = "mousemove"; break;
+ default: break;
+ }
+ if (type.isEmpty())
+ return;
+
+ QScriptValue handlerObject;
+ QScriptValue handler = eventHandler(canvas, type, &handlerObject);
+ if (!handler.isFunction())
+ return;
+
+ QScriptValue scriptEvent = newFakeDomEvent(type, toWrapper(canvas));
+ // MouseEvent
+ scriptEvent.setProperty("screenX", e->globalX(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("screenY", e->globalY(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("clientX", e->x(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("clientY", e->y(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("layerX", e->x(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("layerY", e->y(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("pageX", e->x(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("pageY", e->y(), QScriptValue::ReadOnly);
+ scriptEvent.setProperty("altKey", (e->modifiers() & Qt::AltModifier) != 0,
+ QScriptValue::ReadOnly);
+ scriptEvent.setProperty("ctrlKey", (e->modifiers() & Qt::ControlModifier) != 0,
+ QScriptValue::ReadOnly);
+ scriptEvent.setProperty("metaKey", (e->modifiers() & Qt::MetaModifier) != 0,
+ QScriptValue::ReadOnly);
+ scriptEvent.setProperty("shiftKey", (e->modifiers() & Qt::ShiftModifier) != 0,
+ QScriptValue::ReadOnly);
+ int button = 0;
+ if (e->button() == Qt::RightButton)
+ button = 2;
+ else if (e->button() == Qt::MidButton)
+ button = 1;
+ scriptEvent.setProperty("button", button);
+ scriptEvent.setProperty("relatedTarget", m_engine->nullValue(),
+ QScriptValue::ReadOnly);
+ handler.call(handlerObject, QScriptValueList() << scriptEvent);
+ maybeEmitScriptError();
+}
+//! [3]
+
+void Environment::handleEvent(QContext2DCanvas *canvas, QKeyEvent *e)
+{
+ QString type;
+ switch (e->type()) {
+ case QEvent::KeyPress:
+ type = "keydown"; break;
+ case QEvent::KeyRelease:
+ type = "keyup"; break;
+ default: break;
+ }
+ if (type.isEmpty())
+ return;
+
+ QScriptValue handlerObject;
+ QScriptValue handler = eventHandler(canvas, type, &handlerObject);
+ if (!handler.isFunction())
+ return;
+
+ QScriptValue scriptEvent = newFakeDomEvent(type, toWrapper(canvas));
+ // KeyEvent
+ scriptEvent.setProperty("isChar", !e->text().isEmpty());
+ scriptEvent.setProperty("charCode", e->text());
+ scriptEvent.setProperty("keyCode", FakeDomEvent::qtToDomKey(e->key()));
+ scriptEvent.setProperty("which", e->key());
+
+ handler.call(handlerObject, QScriptValueList() << scriptEvent);
+ maybeEmitScriptError();
+}
+
+QScriptValue Environment::eventHandler(QContext2DCanvas *canvas, const QString &type,
+ QScriptValue *who)
+{
+ QString handlerName = "on" + type;
+ QScriptValue obj = toWrapper(canvas);
+ QScriptValue handler = obj.property(handlerName);
+ if (!handler.isValid()) {
+ obj = m_document;
+ handler = obj.property(handlerName);
+ }
+ if (who && handler.isFunction())
+ *who = obj;
+ return handler;
+}
+
+//! [4]
+QScriptValue Environment::newFakeDomEvent(const QString &type, const QScriptValue &target)
+{
+ QScriptValue e = m_engine->newObject();
+ // Event
+ e.setProperty("type", type, QScriptValue::ReadOnly);
+ e.setProperty("bubbles", true, QScriptValue::ReadOnly);
+ e.setProperty("cancelable", false, QScriptValue::ReadOnly);
+ e.setProperty("target", target, QScriptValue::ReadOnly);
+ e.setProperty("currentTarget", target, QScriptValue::ReadOnly);
+ e.setProperty("eventPhase", 3); // bubbling
+ e.setProperty("timeStamp", QDateTime::currentDateTime().toTime_t());
+ // UIEvent
+ e.setProperty("detail", 0, QScriptValue::ReadOnly);
+ e.setProperty("view", m_engine->globalObject(), QScriptValue::ReadOnly);
+ return e;
+}
+//! [4]
+
+void Environment::maybeEmitScriptError()
+{
+ if (m_engine->hasUncaughtException())
+ emit scriptError(m_engine->uncaughtException());
+}
+
+
+Document::Document(Environment *env)
+ : QObject(env)
+{
+}
+
+Document::~Document()
+{
+}
+
+QScriptValue Document::getElementById(const QString &id) const
+{
+ Environment *env = qobject_cast<Environment*>(parent());
+ QContext2DCanvas *canvas = env->canvasByName(id);
+ if (!canvas)
+ return QScriptValue();
+ return env->toWrapper(canvas);
+}
+
+QScriptValue Document::getElementsByTagName(const QString &name) const
+{
+ if (name != "canvas")
+ return QScriptValue();
+ Environment *env = qobject_cast<Environment*>(parent());
+ QList<QContext2DCanvas*> list = env->canvases();
+ QScriptValue result = env->engine()->newArray(list.size());
+ for (int i = 0; i < list.size(); ++i)
+ result.setProperty(i, env->toWrapper(list.at(i)));
+ return result;
+}
+
+void Document::addEventListener(const QString &type, const QScriptValue &listener,
+ bool useCapture)
+{
+ Q_UNUSED(useCapture);
+ if (listener.isFunction()) {
+ Environment *env = qobject_cast<Environment*>(parent());
+ QScriptValue self = env->toWrapper(this);
+ self.setProperty("on" + type, listener);
+ }
+}
+
+
+QColor colorFromString(const QString &name);
+
+CanvasGradientPrototype::CanvasGradientPrototype(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void CanvasGradientPrototype::addColorStop(qreal offset, const QString &color)
+{
+ CanvasGradient *self = qscriptvalue_cast<CanvasGradient*>(thisObject());
+ if (!self || (self->value.type() == QGradient::NoGradient))
+ return;
+ self->value.setColorAt(offset, colorFromString(color));
+}
+
+void CanvasGradientPrototype::setup(QScriptEngine *engine)
+{
+ CanvasGradientPrototype *proto = new CanvasGradientPrototype();
+ engine->setDefaultPrototype(qMetaTypeId<CanvasGradient>(),
+ engine->newQObject(proto, QScriptEngine::ScriptOwnership,
+ QScriptEngine::ExcludeSuperClassContents));
+}
diff --git a/examples/script/context2d/environment.h b/examples/script/context2d/environment.h
new file mode 100644
index 0000000000..e47e6cbfd3
--- /dev/null
+++ b/examples/script/context2d/environment.h
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ENVIRONMENT_H
+#define ENVIRONMENT_H
+
+#include <qobject.h>
+#include <qlist.h>
+#include <qhash.h>
+#include <QTimerEvent>
+#include <QMouseEvent>
+#include <QKeyEvent>
+#include <QScriptEngine>
+#include <QScriptable>
+class QContext2DCanvas;
+
+//! [0]
+class Environment : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QScriptValue document READ document)
+public:
+ Environment(QObject *parent = 0);
+ ~Environment();
+
+ QScriptValue document() const;
+
+ void addCanvas(QContext2DCanvas *canvas);
+ QContext2DCanvas *canvasByName(const QString &name) const;
+ QList<QContext2DCanvas*> canvases() const;
+
+ QScriptValue evaluate(const QString &code,
+ const QString &fileName = QString());
+
+ QScriptValue toWrapper(QObject *object);
+
+ void handleEvent(QContext2DCanvas *canvas, QMouseEvent *e);
+ void handleEvent(QContext2DCanvas *canvas, QKeyEvent *e);
+
+ void reset();
+//! [0]
+
+ QScriptEngine *engine() const;
+
+//! [1]
+public slots:
+ int setInterval(const QScriptValue &expression, int delay);
+ void clearInterval(int timerId);
+
+ int setTimeout(const QScriptValue &expression, int delay);
+ void clearTimeout(int timerId);
+//! [1]
+
+//! [2]
+signals:
+ void scriptError(const QScriptValue &error);
+//! [2]
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+private:
+ QScriptValue eventHandler(QContext2DCanvas *canvas,
+ const QString &type, QScriptValue *who);
+ QScriptValue newFakeDomEvent(const QString &type,
+ const QScriptValue &target);
+ void maybeEmitScriptError();
+
+ QScriptEngine *m_engine;
+ QScriptValue m_originalGlobalObject;
+ QScriptValue m_document;
+ QList<QContext2DCanvas*> m_canvases;
+ QHash<int, QScriptValue> m_intervalHash;
+ QHash<int, QScriptValue> m_timeoutHash;
+};
+
+//! [3]
+class Document : public QObject
+{
+ Q_OBJECT
+public:
+ Document(Environment *env);
+ ~Document();
+
+public slots:
+ QScriptValue getElementById(const QString &id) const;
+ QScriptValue getElementsByTagName(const QString &name) const;
+
+ // EventTarget
+ void addEventListener(const QString &type, const QScriptValue &listener,
+ bool useCapture);
+};
+//! [3]
+
+class CanvasGradientPrototype : public QObject, public QScriptable
+{
+ Q_OBJECT
+protected:
+ CanvasGradientPrototype(QObject *parent = 0);
+public:
+ static void setup(QScriptEngine *engine);
+
+public slots:
+ void addColorStop(qreal offset, const QString &color);
+};
+
+#endif
diff --git a/examples/script/context2d/main.cpp b/examples/script/context2d/main.cpp
new file mode 100644
index 0000000000..08744d3a33
--- /dev/null
+++ b/examples/script/context2d/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "window.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(context2d);
+
+ QApplication app(argc, argv);
+ Window win;
+ //win.show();
+ win.showFullScreen();
+ return app.exec();
+}
diff --git a/examples/script/context2d/qcontext2dcanvas.cpp b/examples/script/context2d/qcontext2dcanvas.cpp
new file mode 100644
index 0000000000..30bb3ebc2e
--- /dev/null
+++ b/examples/script/context2d/qcontext2dcanvas.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcontext2dcanvas.h"
+
+#include "context2d.h"
+#include "environment.h"
+#include "domimage.h"
+
+#include <QPainter>
+#include <QPaintEvent>
+
+//! [3]
+QContext2DCanvas::QContext2DCanvas(Context2D *context, Environment *env, QWidget *parent)
+ : QWidget(parent), m_context(context), m_env(env)
+{
+ QObject::connect(context, SIGNAL(changed(QImage)), this, SLOT(contentsChanged(QImage)));
+ setMouseTracking(true);
+}
+//! [3]
+
+QContext2DCanvas::~QContext2DCanvas()
+{
+}
+
+Context2D *QContext2DCanvas::context() const
+{
+ return m_context;
+}
+
+//! [0]
+QScriptValue QContext2DCanvas::getContext(const QString &str)
+{
+ if (str != "2d")
+ return QScriptValue();
+ return m_env->toWrapper(m_context);
+}
+//! [0]
+
+//! [1]
+void QContext2DCanvas::contentsChanged(const QImage &image)
+{
+ m_image = image;
+ update();
+}
+
+void QContext2DCanvas::paintEvent(QPaintEvent *e)
+{
+ QPainter p(this);
+ p.setClipRect(e->rect());
+ p.drawImage(0, 0, m_image);
+}
+//! [1]
+
+//! [2]
+void QContext2DCanvas::mouseMoveEvent(QMouseEvent *e)
+{
+ m_env->handleEvent(this, e);
+}
+
+void QContext2DCanvas::mousePressEvent(QMouseEvent *e)
+{
+ m_env->handleEvent(this, e);
+}
+
+void QContext2DCanvas::mouseReleaseEvent(QMouseEvent *e)
+{
+ m_env->handleEvent(this, e);
+}
+
+void QContext2DCanvas::keyPressEvent(QKeyEvent *e)
+{
+ m_env->handleEvent(this, e);
+}
+
+void QContext2DCanvas::keyReleaseEvent(QKeyEvent *e)
+{
+ m_env->handleEvent(this, e);
+}
+//! [2]
+
+void QContext2DCanvas::resizeEvent(QResizeEvent *e)
+{
+ m_context->setSize(e->size().width(), e->size().height());
+}
+
+void QContext2DCanvas::resize(int width, int height)
+{
+ QWidget::resize(width, height);
+}
+
+void QContext2DCanvas::reset()
+{
+ m_context->reset();
+}
+
+void QContext2DCanvas::addEventListener(const QString &type, const QScriptValue &listener,
+ bool useCapture)
+{
+ Q_UNUSED(useCapture);
+ if (listener.isFunction()) {
+ QScriptValue self = m_env->toWrapper(this);
+ self.setProperty("on" + type, listener);
+ }
+}
diff --git a/examples/script/context2d/qcontext2dcanvas.h b/examples/script/context2d/qcontext2dcanvas.h
new file mode 100644
index 0000000000..657ffc3b5c
--- /dev/null
+++ b/examples/script/context2d/qcontext2dcanvas.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCONTEXT2DCANVAS_H
+#define QCONTEXT2DCANVAS_H
+
+#include <qscriptengine.h>
+#include <qscriptcontext.h>
+#include <qscriptvalue.h>
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+class QResizeEvent;
+class QMouseEvent;
+class QKeyEvent;
+QT_END_NAMESPACE
+class Environment;
+class Context2D;
+
+//! [0]
+class QContext2DCanvas : public QWidget
+{
+ Q_OBJECT
+public:
+ QContext2DCanvas(Context2D *context, Environment *env, QWidget *parent = 0);
+ ~QContext2DCanvas();
+
+ Context2D *context() const;
+ void reset();
+
+public slots:
+ QScriptValue getContext(const QString &str);
+ void resize(int width, int height);
+
+ // EventTarget
+ void addEventListener(const QString &type, const QScriptValue &listener,
+ bool useCapture);
+
+protected:
+ virtual void paintEvent(QPaintEvent *e);
+ virtual void mouseMoveEvent(QMouseEvent *e);
+ virtual void mousePressEvent(QMouseEvent *e);
+ virtual void mouseReleaseEvent(QMouseEvent *e);
+ virtual void keyPressEvent(QKeyEvent *e);
+ virtual void keyReleaseEvent(QKeyEvent *e);
+ virtual void resizeEvent(QResizeEvent *e);
+
+private slots:
+ void contentsChanged(const QImage &image);
+//! [0]
+
+private:
+ Context2D *m_context;
+ Environment *m_env;
+ QImage m_image;
+};
+
+#endif
diff --git a/examples/script/context2d/scripts/alpha.js b/examples/script/context2d/scripts/alpha.js
new file mode 100644
index 0000000000..23fa5d4d9d
--- /dev/null
+++ b/examples/script/context2d/scripts/alpha.js
@@ -0,0 +1,21 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+ // draw background
+ ctx.fillStyle = '#FD0';
+ ctx.fillRect(0,0,75,75);
+ ctx.fillStyle = '#6C0';
+ ctx.fillRect(75,0,75,75);
+ ctx.fillStyle = '#09F';
+ ctx.fillRect(0,75,75,75);
+ ctx.fillStyle = '#F30';
+ ctx.fillRect(75,75,75,75);
+ ctx.fillStyle = '#FFF';
+
+ // set transparency value
+ ctx.globalAlpha = 0.2;
+
+ // Draw semi transparent circles
+ for (i=0;i<7;i++){
+ ctx.beginPath();
+ ctx.arc(75,75,10+10*i,0,Math.PI*2,true);
+ ctx.fill();
+ }
diff --git a/examples/script/context2d/scripts/arc.js b/examples/script/context2d/scripts/arc.js
new file mode 100644
index 0000000000..650bcda49c
--- /dev/null
+++ b/examples/script/context2d/scripts/arc.js
@@ -0,0 +1,30 @@
+var canvas = document.getElementById('tutorial');
+
+ // Make sure we don't execute when canvas isn't supported
+ if (canvas.getContext){
+
+ // use getContext to use the canvas for drawing
+ var ctx = canvas.getContext('2d');
+
+ // Draw shapes
+ for (i=0;i<4;i++){
+ for(j=0;j<3;j++){
+ ctx.beginPath();
+ var x = 25+j*50; // x coordinate
+ var y = 25+i*50; // y coordinate
+ var radius = 20; // Arc radius
+ var startAngle = 0; // Starting point on circle
+ var endAngle = Math.PI+(Math.PI*j)/2; // End point on circle
+ var clockwise = i%2==0 ? false : true; // clockwise or anticlockwise
+
+ ctx.arc(x,y,radius,startAngle,endAngle, clockwise);
+
+ if (i>1){
+ ctx.fill();
+ } else {
+ ctx.stroke();
+ }
+ }
+ }
+
+ }
diff --git a/examples/script/context2d/scripts/bezier.js b/examples/script/context2d/scripts/bezier.js
new file mode 100644
index 0000000000..719800ebe5
--- /dev/null
+++ b/examples/script/context2d/scripts/bezier.js
@@ -0,0 +1,26 @@
+function drawShape() {
+// get the canvas element using the DOM
+var canvas = document.getElementById('tutorial');
+
+ // Make sure we don't execute when canvas isn't supported
+ if (canvas.getContext){
+
+ // use getContext to use the canvas for drawing
+ var ctx = canvas.getContext('2d');
+
+ // Draw shapes
+
+ ctx.beginPath();
+ ctx.moveTo(75,40);
+ ctx.bezierCurveTo(75,37,70,25,50,25);
+ ctx.bezierCurveTo(20,25,20,62.5,20,62.5);
+ ctx.bezierCurveTo(20,80,40,102,75,120);
+ ctx.bezierCurveTo(110,102,130,80,130,62.5);
+ ctx.bezierCurveTo(130,62.5,130,25,100,25);
+ ctx.bezierCurveTo(85,25,75,37,75,40);
+ ctx.fill();
+ ctx.globalAlpha = 0.5;
+ }
+}
+
+drawShape();
diff --git a/examples/script/context2d/scripts/clock.js b/examples/script/context2d/scripts/clock.js
new file mode 100644
index 0000000000..ad287d8202
--- /dev/null
+++ b/examples/script/context2d/scripts/clock.js
@@ -0,0 +1,99 @@
+function init(){
+ clock();
+ setInterval('clock()',1000);
+}
+function clock(){
+ var now = new Date();
+ var ctx = document.getElementById('tutorial').getContext('2d');
+ ctx.save();
+ ctx.clearRect(0,0,150,150);
+ ctx.translate(75,75);
+ ctx.scale(0.4,0.4);
+ ctx.rotate(-Math.PI/2);
+ ctx.strokeStyle = "black";
+ ctx.fillStyle = "white";
+ ctx.lineWidth = 8;
+ ctx.lineCap = "round";
+
+ // Hour marks
+ ctx.save();
+ ctx.beginPath();
+ for (i=0;i<12;i++){
+ ctx.rotate(Math.PI/6);
+ ctx.moveTo(100,0);
+ ctx.lineTo(120,0);
+ }
+ ctx.stroke();
+ ctx.restore();
+
+ // Minute marks
+ ctx.save();
+ ctx.lineWidth = 5;
+ ctx.beginPath();
+ for (i=0;i<60;i++){
+ if (i%5!=0) {
+ ctx.moveTo(117,0);
+ ctx.lineTo(120,0);
+ }
+ ctx.rotate(Math.PI/30);
+ }
+ ctx.stroke();
+ ctx.restore();
+
+ var sec = now.getSeconds();
+ var min = now.getMinutes();
+ var hr = now.getHours();
+ hr = hr>=12 ? hr-12 : hr;
+
+ ctx.fillStyle = "black";
+
+ // write Hours
+ ctx.save();
+ ctx.rotate( hr*(Math.PI/6) + (Math.PI/360)*min + (Math.PI/21600)*sec )
+ ctx.lineWidth = 14;
+ ctx.beginPath();
+ ctx.moveTo(-20,0);
+ ctx.lineTo(80,0);
+ ctx.stroke();
+ ctx.restore();
+
+ // write Minutes
+ ctx.save();
+ ctx.rotate( (Math.PI/30)*min + (Math.PI/1800)*sec )
+ ctx.lineWidth = 10;
+ ctx.beginPath();
+ ctx.moveTo(-28,0);
+ ctx.lineTo(112,0);
+ ctx.stroke();
+ ctx.restore();
+
+ // Write seconds
+ ctx.save();
+ ctx.rotate(sec * Math.PI/30);
+ ctx.strokeStyle = "#D40000";
+ ctx.fillStyle = "#D40000";
+ ctx.lineWidth = 6;
+ ctx.beginPath();
+ ctx.moveTo(-30,0);
+ ctx.lineTo(83,0);
+ ctx.stroke();
+ ctx.beginPath();
+ ctx.arc(0,0,10,0,Math.PI*2,true);
+ ctx.fill();
+ ctx.beginPath();
+ ctx.arc(95,0,10,0,Math.PI*2,true);
+ ctx.stroke();
+ ctx.fillStyle = "#555";
+ ctx.arc(0,0,3,0,Math.PI*2,true);
+ ctx.fill();
+ ctx.restore();
+
+ ctx.beginPath();
+ ctx.lineWidth = 14;
+ ctx.strokeStyle = '#325FA2';
+ ctx.arc(0,0,142,0,Math.PI*2,true);
+ ctx.stroke();
+
+ ctx.restore();
+}
+init();
diff --git a/examples/script/context2d/scripts/fill1.js b/examples/script/context2d/scripts/fill1.js
new file mode 100644
index 0000000000..db5eeb7cb0
--- /dev/null
+++ b/examples/script/context2d/scripts/fill1.js
@@ -0,0 +1,8 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+ for (i=0;i<6;i++){
+ for (j=0;j<6;j++){
+ ctx.fillStyle = 'rgb(' + Math.floor(255-42.5*i) + ',' +
+ Math.floor(255-42.5*j) + ',0)';
+ ctx.fillRect(j*25,i*25,25,25);
+ }
+ }
diff --git a/examples/script/context2d/scripts/grad.js b/examples/script/context2d/scripts/grad.js
new file mode 100644
index 0000000000..24ccfbbda6
--- /dev/null
+++ b/examples/script/context2d/scripts/grad.js
@@ -0,0 +1,20 @@
+ var ctx = document.getElementById('tutorial').getContext('2d');
+
+ // Create gradients
+ var lingrad = ctx.createLinearGradient(0,0,0,150);
+ lingrad.addColorStop(0, '#00ABEB');
+ lingrad.addColorStop(0.5, '#fff');
+ lingrad.addColorStop(0.5, '#66CC00');
+ lingrad.addColorStop(1, '#fff');
+
+ var lingrad2 = ctx.createLinearGradient(0,50,0,95);
+ lingrad2.addColorStop(0.5, '#000');
+ lingrad2.addColorStop(1, 'rgba(0,0,0,0)');
+
+ // assign gradients to fill and stroke styles
+ ctx.fillStyle = lingrad;
+ ctx.strokeStyle = lingrad2;
+
+ // draw shapes
+ ctx.fillRect(10,10,130,130);
+ ctx.strokeRect(50,50,50,50);
diff --git a/examples/script/context2d/scripts/linecap.js b/examples/script/context2d/scripts/linecap.js
new file mode 100644
index 0000000000..18ceb2353b
--- /dev/null
+++ b/examples/script/context2d/scripts/linecap.js
@@ -0,0 +1,24 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+ var lineCap = ['butt','round','square'];
+
+ // Draw guides
+ ctx.save();
+ ctx.strokeStyle = '#09f';
+ ctx.beginPath();
+ ctx.moveTo(10,10);
+ ctx.lineTo(140,10);
+ ctx.moveTo(10,140);
+ ctx.lineTo(140,140);
+ ctx.stroke();
+
+ // Draw lines
+ ctx.strokeStyle = 'black';
+ for (i=0;i<lineCap.length;i++){
+ ctx.lineWidth = 15;
+ ctx.lineCap = lineCap[i];
+ ctx.beginPath();
+ ctx.moveTo(25+i*50,10);
+ ctx.lineTo(25+i*50,140);
+ ctx.stroke();
+ }
+ ctx.restore();
diff --git a/examples/script/context2d/scripts/linestye.js b/examples/script/context2d/scripts/linestye.js
new file mode 100644
index 0000000000..728e3e69e5
--- /dev/null
+++ b/examples/script/context2d/scripts/linestye.js
@@ -0,0 +1,10 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+ctx.save();
+ for (i=0;i<10;i++){
+ ctx.lineWidth = 1+i;
+ ctx.beginPath();
+ ctx.moveTo(5+i*14,5);
+ ctx.lineTo(5+i*14,140);
+ ctx.stroke();
+ }
+ctx.restore(); \ No newline at end of file
diff --git a/examples/script/context2d/scripts/moveto.js b/examples/script/context2d/scripts/moveto.js
new file mode 100644
index 0000000000..73c4e8d13d
--- /dev/null
+++ b/examples/script/context2d/scripts/moveto.js
@@ -0,0 +1,20 @@
+var canvas = document.getElementById('tutorial');
+
+ // Make sure we don't execute when canvas isn't supported
+ if (canvas.getContext){
+
+ // use getContext to use the canvas for drawing
+ var ctx = canvas.getContext('2d');
+
+ // Draw shapes
+ ctx.beginPath();
+ ctx.arc(75,75,50,0,Math.PI*2,true); // Outer circle
+ ctx.moveTo(110,75);
+ ctx.arc(75,75,35,0,Math.PI,false); // Mouth
+ ctx.moveTo(65,65);
+ ctx.arc(60,65,5,0,Math.PI*2,true); // Left eye
+ ctx.moveTo(95,65);
+ ctx.arc(90,65,5,0,Math.PI*2,true); // Right eye
+ ctx.stroke();
+
+ }
diff --git a/examples/script/context2d/scripts/moveto2.js b/examples/script/context2d/scripts/moveto2.js
new file mode 100644
index 0000000000..021f47b836
--- /dev/null
+++ b/examples/script/context2d/scripts/moveto2.js
@@ -0,0 +1,24 @@
+var canvas = document.getElementById('tutorial');
+
+ // Make sure we don't execute when canvas isn't supported
+ if (canvas.getContext){
+
+ // use getContext to use the canvas for drawing
+ var ctx = canvas.getContext('2d');
+
+ // Filled triangle
+ ctx.beginPath();
+ ctx.moveTo(25,25);
+ ctx.lineTo(105,25);
+ ctx.lineTo(25,105);
+ ctx.fill();
+
+ // Stroked triangle
+ ctx.beginPath();
+ ctx.moveTo(125,125);
+ ctx.lineTo(125,45);
+ ctx.lineTo(45,125);
+ ctx.closePath();
+ ctx.stroke();
+
+ }
diff --git a/examples/script/context2d/scripts/pacman.js b/examples/script/context2d/scripts/pacman.js
new file mode 100644
index 0000000000..af3750f6cb
--- /dev/null
+++ b/examples/script/context2d/scripts/pacman.js
@@ -0,0 +1,83 @@
+function roundedRect(ctx,x,y,width,height,radius){
+ ctx.beginPath();
+ ctx.moveTo(x,y+radius);
+ ctx.lineTo(x,y+height-radius);
+ ctx.quadraticCurveTo(x,y+height,x+radius,y+height);
+ ctx.lineTo(x+width-radius,y+height);
+ ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);
+ ctx.lineTo(x+width,y+radius);
+ ctx.quadraticCurveTo(x+width,y,x+width-radius,y);
+ ctx.lineTo(x+radius,y);
+ ctx.quadraticCurveTo(x,y,x,y+radius);
+ ctx.stroke();
+}
+
+var canvas = document.getElementById('tutorial');
+
+ // Make sure we don't execute when canvas isn't supported
+ if (canvas.getContext){
+
+ // use getContext to use the canvas for drawing
+ var ctx = canvas.getContext('2d');
+
+ // Draw shapes
+ roundedRect(ctx,12,12,150,150,15);
+ roundedRect(ctx,19,19,150,150,9);
+ roundedRect(ctx,53,53,49,33,10);
+ roundedRect(ctx,53,119,49,16,6);
+ roundedRect(ctx,135,53,49,33,10);
+ roundedRect(ctx,135,119,25,49,10);
+
+ // Character 1
+ ctx.beginPath();
+ ctx.arc(37,37,13,Math.PI/7,-Math.PI/7,false);
+ ctx.lineTo(34,37);
+ ctx.fill();
+
+ // blocks
+ for(i=0;i<8;i++){
+ ctx.fillRect(51+i*16,35,4,4);
+ }
+ for(i=0;i<6;i++){
+ ctx.fillRect(115,51+i*16,4,4);
+ }
+ for(i=0;i<8;i++){
+ ctx.fillRect(51+i*16,99,4,4);
+ }
+
+ // character 2
+ ctx.beginPath();
+ ctx.moveTo(83,116);
+ ctx.lineTo(83,102);
+
+ ctx.bezierCurveTo(83,94,89,88,97,88);
+ ctx.bezierCurveTo(105,88,111,94,111,102);
+ ctx.lineTo(111,116);
+ ctx.lineTo(106.333,111.333);
+ ctx.lineTo(101.666,116);
+ ctx.lineTo(97,111.333);
+ ctx.lineTo(92.333,116);
+ ctx.lineTo(87.666,111.333);
+ ctx.lineTo(83,116);
+ ctx.fill();
+ ctx.fillStyle = "white";
+ ctx.beginPath();
+ ctx.moveTo(91,96);
+ ctx.bezierCurveTo(88,96,87,99,87,101);
+ ctx.bezierCurveTo(87,103,88,106,91,106);
+ ctx.bezierCurveTo(94,106,95,103,95,101);
+ ctx.bezierCurveTo(95,99,94,96,91,96);
+ ctx.moveTo(103,96);
+ ctx.bezierCurveTo(100,96,99,99,99,101);
+ ctx.bezierCurveTo(99,103,100,106,103,106);
+ ctx.bezierCurveTo(106,106,107,103,107,101);
+ ctx.bezierCurveTo(107,99,106,96,103,96);
+ ctx.fill();
+ ctx.fillStyle = "black";
+ ctx.beginPath();
+ ctx.arc(101,102,2,0,Math.PI*2,true);
+ ctx.fill();
+ ctx.beginPath();
+ ctx.arc(89,102,2,0,Math.PI*2,true);
+ ctx.fill();
+ }
diff --git a/examples/script/context2d/scripts/plasma.js b/examples/script/context2d/scripts/plasma.js
new file mode 100644
index 0000000000..1aa9294dfb
--- /dev/null
+++ b/examples/script/context2d/scripts/plasma.js
@@ -0,0 +1,58 @@
+var counter = 0;
+
+var PIXEL_SIZE = 4;
+
+var temp_1 = 0;
+
+function init()
+{
+ setInterval('render()',50);
+}
+
+function dist(a, b, c, d)
+{
+ return Math.sqrt((a - c) * (a - c) + (b - d) * (b - d));
+}
+
+
+function render()
+{
+ var canvas = document.getElementById('tutorial');
+ canvas.resize(128, 128);
+ var ctx = canvas.getContext('2d');
+ ctx.save();
+
+ var time = counter * 5;
+
+
+ for( y = 0; y < 128; y+=PIXEL_SIZE) {
+ for( x = 0 ; x < 128; x+=PIXEL_SIZE) {
+
+
+ var temp_val = Math.floor(Math.sin(dist(x + time, y, 128.0, 128.0) / 8.0)
+ + Math.sin(dist(x, y, 64.0, 64.0) / 8.0)
+ + Math.sin(dist(x, y + time / 7, 192.0, 64) / 7.0)
+ + Math.sin(dist(x, y, 192.0, 100.0) / 8.0));
+
+
+
+
+ var temp_col = Math.floor((2 + temp_val) * 50);
+
+ var rand_red = temp_col * 3;
+ var rand_green = temp_col ;
+ var rand_blue = 128 - temp_col;
+
+ ctx.fillStyle = "rgb("+rand_red+","+rand_green+","+rand_blue+")";
+
+ ctx.fillRect(x,y,PIXEL_SIZE,PIXEL_SIZE);
+ }
+ }
+
+
+ ctx.restore();
+ counter++;
+
+}
+
+init();
diff --git a/examples/script/context2d/scripts/pong.js b/examples/script/context2d/scripts/pong.js
new file mode 100644
index 0000000000..2bff053f33
--- /dev/null
+++ b/examples/script/context2d/scripts/pong.js
@@ -0,0 +1,235 @@
+// globals
+playarea_canvas = document.getElementById('tutorial');
+playarea_canvas.resize(320,200);
+playarea = playarea_canvas.getContext('2d');
+//p1_scr = document.getElementById('p1_scr');
+//p2_scr = document.getElementById('p2_scr');
+//status_msg = document.getElementById('status');
+//debug = document.getElementById('debug');
+ball_direction = 0;
+up = -1;
+down = 1;
+
+//key codes
+key_up = 38;
+key_down = 40;
+key_W = 87;
+key_S = 83;
+key_pause = 32;
+
+speed = 2; //controls the speed of the ball
+paddle_inc = 10; //how many pixels paddle can move in either direction
+pause = false;
+
+player_1 = 0; //player IDs
+player_2 = 1;
+player_1_scr = 0; //player scores
+player_2_scr = 0;
+player_1_direction = null; //null = no movement whatsoever
+player_2_direction = null;
+
+pa = new Array();
+divider = new Array();
+paddle_1 = new Array();
+paddle_2 = new Array();
+ball = new Array();
+
+
+function sleep(numberMillis)
+{
+ var now = new Date();
+ var exitTime = now.getTime() + numberMillis;
+ while (true) {
+ now = new Date();
+ if (now.getTime() > exitTime)
+ return;
+ }
+}
+
+function init()
+{
+ pa['width'] = 150;
+ pa['height'] = 140;
+ pa['player_margin'] = 10; //area behind player paddles
+ pa['foreground'] = "#FFFFFF";
+ pa['background'] = "#000000";
+
+ divider['pos'] = pa['width']/2;
+ divider['width'] = 4;
+
+ paddle_1['width'] = 8;
+ paddle_1['height'] = 64;
+ paddle_1['x'] = pa['player_margin'];
+ paddle_1['y'] = (pa['height'] /2 ) - (paddle_1['height'] / 2);
+
+ paddle_2['width'] = 8;
+ paddle_2['height'] = 64;
+ paddle_2['x'] = (pa['width'] - pa['player_margin'] - paddle_2['width']);
+ paddle_2['y'] = (pa['height'] /2 ) - (paddle_2['height'] / 2);
+
+ ball['width'] = 10;
+ ball['height'] = 10;
+ ball['x'] = (pa['width']/2) - (ball['width'] / 2);
+ ball['y'] = (pa['height']/2) - (ball['height'] / 2);
+
+ ball_direction = Math.random() * 360; //initialize ball direction, which is determined by angle, at random
+ speed = 2;
+}
+
+function renderPlayarea()
+{
+ playarea.beginPath();
+
+ playarea.clearRect(0,0,pa['width'],pa['height']);
+ playarea.fillStyle = pa['background'];
+ playarea.strokeStyle = pa['foreground'];
+ playarea.fillRect(0,0, pa['width'], pa['height']);
+
+ //move paddles
+ if(player_1_direction != null)
+ {
+ if(player_1_direction == up)
+ paddle_1['y'] = paddle_1['y'] - paddle_inc;
+ else
+ paddle_1['y'] = paddle_1['y'] + paddle_inc;
+ }
+ if(player_2_direction != null)
+ {
+ if(player_2_direction == up)
+ paddle_2['y'] = paddle_2['y'] - paddle_inc;
+ else
+ paddle_2['y'] = paddle_2['y'] + paddle_inc;
+ }
+ playarea.rect(paddle_1['x'],paddle_1['y'],paddle_1['width'],paddle_1['height']);
+ playarea.rect(paddle_2['x'],paddle_2['y'],paddle_2['width'],paddle_2['height']);
+
+ //move ball
+ playarea.rect(ball['x'], ball['y'], ball['width'], ball['height']);
+ ball['x'] = ball['x'] + Math.cos((ball_direction)*Math.PI/180) * speed;
+ ball['y'] = ball['y'] + Math.sin((ball_direction)*Math.PI/180) * speed;
+
+ playarea.fillStyle = pa['foreground'];
+ playarea.fill();
+
+ playarea.beginPath();
+ //redraw divider
+ playarea.lineWidth = divider['width'];
+ playarea.lineTo(divider['pos'], 0);
+ playarea.lineTo(divider['pos'], pa['height'] = 200);
+ playarea.lineWidth = 1;
+
+ playarea.stroke();
+ playarea.closePath();
+}
+
+function testCollisions()
+{
+ //make sure paddles don't go beyond play area
+ if(((paddle_1['y'] <= 0) && (player_1_direction == up)) || ((paddle_1['y'] >= (pa['height'] - paddle_1['height'])) && (player_1_direction == down)))
+ player_1_direction = null;
+ if(((paddle_2['y'] <= 0) && (player_2_direction == up)) || ((paddle_2['y'] >= (pa['height'] - paddle_2['height'])) && (player_2_direction == down)))
+ player_2_direction = null;
+
+ //check to see if ball went beyond paddles, and if so, score accordingly and reset playarea
+ if(ball['x'] <= 0)
+ {
+ setScore(player_2);
+ init()
+ sleep(1000);
+ }
+ if(ball['x'] >= (pa['width'] - ball['width']))
+ {
+ setScore(player_1);
+ init();
+ sleep(1000);
+ }
+
+ //check to see if ball hit top or bottom wall. if so, change direction
+ if((ball['y'] >= (pa['height'] - ball['height'])) || ball['y'] <= 0)
+ ball_direction = -ball_direction;
+
+ //check to see if the ball hit a paddle, and if so, change ball angle dependant on where it hit the paddle
+ if((ball['x'] <= (paddle_1['x'] + paddle_1['width'])) && (ball['y'] >= paddle_1['y']) && (ball['y'] <= (paddle_1['y'] + paddle_1['height'])))
+ {
+ ball_direction = -ball_direction/2;
+ speed += .5;
+ }
+ if(((ball['x'] + ball['width']) >= paddle_2['x']) && (ball['y'] >= paddle_2['y']) && (ball['y'] <= (paddle_2['y'] + paddle_2['height'])))
+ {
+ ball_direction = (180+ball_direction)/2;
+ speed += .5;
+ }
+}
+
+function setScore(p)
+{
+ if(p == player_1)
+ {
+ player_1_scr++;
+ //p1_scr.firstChild.nodeValue = player_1_scr;
+ }
+ if(p == player_2)
+ {
+ player_2_scr++;
+ //p2_scr.firstChild.nodeValue = player_2_scr;
+ }
+}
+
+
+//handle input
+document.onkeydown = function(ev)
+{
+ switch(ev.keyCode)
+ {
+ case key_W:
+ player_1_direction = up;
+ break;
+ case key_S:
+ player_1_direction = down;
+ break;
+ case key_up:
+ player_2_direction = up;
+ break;
+ case key_down:
+ player_2_direction = down;
+ break;
+ }
+}
+
+document.onkeyup = function(ev)
+{
+ switch(ev.keyCode)
+ {
+ case key_W:
+ case key_S:
+ player_1_direction = null;
+ break;
+ case key_up:
+ case key_down:
+ player_2_direction = null;
+ break;
+ case key_pause:
+ if(pause == false)
+ {
+ clearInterval(game);
+ //status_msg.style.visibility = "visible";
+ pause = true;
+ }
+ else
+ {
+ game = setInterval(main, 25);
+ //status_msg.style.visibility = "hidden";
+ pause = false;
+ }
+ break;
+ }
+}
+
+function main()
+{
+ testCollisions();
+ renderPlayarea();
+}
+
+init();
+game = setInterval(main, 25);
diff --git a/examples/script/context2d/scripts/quad.js b/examples/script/context2d/scripts/quad.js
new file mode 100644
index 0000000000..ad3a0d5786
--- /dev/null
+++ b/examples/script/context2d/scripts/quad.js
@@ -0,0 +1,21 @@
+var canvas = document.getElementById('tutorial');
+
+ // Make sure we don't execute when canvas isn't supported
+ if (canvas.getContext){
+
+ // use getContext to use the canvas for drawing
+ var ctx = canvas.getContext('2d');
+
+ // Draw shapes
+
+ ctx.beginPath();
+ ctx.moveTo(75,25);
+ ctx.quadraticCurveTo(25,25,25,62.5);
+ ctx.quadraticCurveTo(25,100,50,100);
+ ctx.quadraticCurveTo(50,120,30,125);
+ ctx.quadraticCurveTo(60,120,65,100);
+ ctx.quadraticCurveTo(125,100,125,62.5);
+ ctx.quadraticCurveTo(125,25,75,25);
+ ctx.stroke();
+
+ }
diff --git a/examples/script/context2d/scripts/rgba.js b/examples/script/context2d/scripts/rgba.js
new file mode 100644
index 0000000000..a4e5e9a53e
--- /dev/null
+++ b/examples/script/context2d/scripts/rgba.js
@@ -0,0 +1,19 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+
+ // Draw background
+ ctx.fillStyle = 'rgb(255,221,0)';
+ ctx.fillRect(0,0,150,37.5);
+ ctx.fillStyle = 'rgb(102,204,0)';
+ ctx.fillRect(0,37.5,150,37.5);
+ ctx.fillStyle = 'rgb(0,153,255)';
+ ctx.fillRect(0,75,150,37.5);
+ ctx.fillStyle = 'rgb(255,51,0)';
+ ctx.fillRect(0,112.5,150,37.5);
+
+ // Draw semi transparent rectangles
+ for (i=0;i<10;i++){
+ ctx.fillStyle = 'rgba(255,255,255,'+(i+1)/10+')';
+ for (j=0;j<4;j++){
+ ctx.fillRect(5+i*14,5+j*37.5,14,27.5)
+ }
+ }
diff --git a/examples/script/context2d/scripts/rotate.js b/examples/script/context2d/scripts/rotate.js
new file mode 100644
index 0000000000..c7ef369de6
--- /dev/null
+++ b/examples/script/context2d/scripts/rotate.js
@@ -0,0 +1,16 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+ ctx.translate(75,75);
+
+ for (i=1;i<6;i++){ // Loop through rings (from inside to out)
+ ctx.save();
+ ctx.fillStyle = 'rgb('+(51*i)+','+(255-51*i)+',255)';
+
+ for (j=0;j<i*6;j++){ // draw individual dots
+ ctx.rotate(Math.PI*2/(i*6));
+ ctx.beginPath();
+ ctx.arc(0,i*12.5,5,0,Math.PI*2,true);
+ ctx.fill();
+ }
+
+ ctx.restore();
+ }
diff --git a/examples/script/context2d/scripts/scale.js b/examples/script/context2d/scripts/scale.js
new file mode 100644
index 0000000000..75ef8650c0
--- /dev/null
+++ b/examples/script/context2d/scripts/scale.js
@@ -0,0 +1,67 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+ ctx.strokeStyle = "#fc0";
+ ctx.lineWidth = 1.5;
+ ctx.fillRect(0,0,300,300);
+
+ // Uniform scaling
+ ctx.save()
+ ctx.translate(50,50);
+ drawSpirograph(ctx,22,6,5); // no scaling
+
+ ctx.translate(100,0);
+ ctx.scale(0.75,0.75);
+ drawSpirograph(ctx,22,6,5);
+
+ ctx.translate(133.333,0);
+ ctx.scale(0.75,0.75);
+ drawSpirograph(ctx,22,6,5);
+ ctx.restore();
+
+ // Non uniform scaling (y direction)
+ ctx.strokeStyle = "#0cf";
+ ctx.save()
+ ctx.translate(50,150);
+ ctx.scale(1,0.75);
+ drawSpirograph(ctx,22,6,5);
+
+ ctx.translate(100,0);
+ ctx.scale(1,0.75);
+ drawSpirograph(ctx,22,6,5);
+
+ ctx.translate(100,0);
+ ctx.scale(1,0.75);
+ drawSpirograph(ctx,22,6,5);
+ ctx.restore();
+
+ // Non uniform scaling (x direction)
+ ctx.strokeStyle = "#cf0";
+ ctx.save()
+ ctx.translate(50,250);
+ ctx.scale(0.75,1);
+ drawSpirograph(ctx,22,6,5);
+
+ ctx.translate(133.333,0);
+ ctx.scale(0.75,1);
+ drawSpirograph(ctx,22,6,5);
+
+ ctx.translate(177.777,0);
+ ctx.scale(0.75,1);
+ drawSpirograph(ctx,22,6,5);
+ ctx.restore();
+function drawSpirograph(ctx,R,r,O){
+ var x1 = R-O;
+ var y1 = 0;
+ var i = 1;
+ ctx.beginPath();
+ ctx.moveTo(x1,y1);
+ do {
+ if (i>20000) break;
+ var x2 = (R+r)*Math.cos(i*Math.PI/72) - (r+O)*Math.cos(((R+r)/r)*(i*Math.PI/72))
+ var y2 = (R+r)*Math.sin(i*Math.PI/72) - (r+O)*Math.sin(((R+r)/r)*(i*Math.PI/72))
+ ctx.lineTo(x2,y2);
+ x1 = x2;
+ y1 = y2;
+ i++;
+ } while (x2 != R-O && y2 != 0 );
+ ctx.stroke();
+}
diff --git a/examples/script/context2d/scripts/stroke1.js b/examples/script/context2d/scripts/stroke1.js
new file mode 100644
index 0000000000..0561a52ed0
--- /dev/null
+++ b/examples/script/context2d/scripts/stroke1.js
@@ -0,0 +1,10 @@
+var ctx = document.getElementById('tutorial').getContext('2d');
+ for (i=0;i<6;i++){
+ for (j=0;j<6;j++){
+ ctx.strokeStyle = 'rgb(0,' + Math.floor(255-42.5*i) + ',' +
+ Math.floor(255-42.5*j) + ')';
+ ctx.beginPath();
+ ctx.arc(12.5+j*25,12.5+i*25,10,0,Math.PI*2,true);
+ ctx.stroke();
+ }
+ }
diff --git a/examples/script/context2d/scripts/translate.js b/examples/script/context2d/scripts/translate.js
new file mode 100644
index 0000000000..7c944330bb
--- /dev/null
+++ b/examples/script/context2d/scripts/translate.js
@@ -0,0 +1,29 @@
+ var ctx = document.getElementById('tutorial').getContext('2d');
+ ctx.fillRect(0,0,300,300);
+ for (var i=0;i<3;i++) {
+ for (var j=0;j<3;j++) {
+ ctx.save();
+ ctx.strokeStyle = "#9CFF00";
+ ctx.translate(50+j*100,50+i*100);
+ drawSpirograph(ctx,20*(j+2)/(j+1),-8*(i+3)/(i+1),10);
+ ctx.restore();
+ }
+ }
+
+function drawSpirograph(ctx,R,r,O){
+ var x1 = R-O;
+ var y1 = 0;
+ var i = 1;
+ ctx.beginPath();
+ ctx.moveTo(x1,y1);
+ do {
+ if (i>20000) break;
+ var x2 = (R+r)*Math.cos(i*Math.PI/72) - (r+O)*Math.cos(((R+r)/r)*(i*Math.PI/72))
+ var y2 = (R+r)*Math.sin(i*Math.PI/72) - (r+O)*Math.sin(((R+r)/r)*(i*Math.PI/72))
+ ctx.lineTo(x2,y2);
+ x1 = x2;
+ y1 = y2;
+ i++;
+ } while (x2 != R-O && y2 != 0 );
+ ctx.stroke();
+}
diff --git a/examples/script/context2d/window.cpp b/examples/script/context2d/window.cpp
new file mode 100644
index 0000000000..a93bf3045f
--- /dev/null
+++ b/examples/script/context2d/window.cpp
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "window.h"
+#include "environment.h"
+#include "context2d.h"
+#include "qcontext2dcanvas.h"
+#include <QHBoxLayout>
+#include <QListWidget>
+#include <QDir>
+#include <QMessageBox>
+
+#ifndef QT_NO_SCRIPTTOOLS
+#include <QAction>
+#include <QApplication>
+#include <QMainWindow>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QScriptEngineDebugger>
+#endif
+
+static QString scriptsDir()
+{
+ if (QFile::exists("./scripts"))
+ return "./scripts";
+ return ":/scripts";
+}
+
+//! [0]
+Window::Window(QWidget *parent)
+ : QWidget(parent)
+{
+ m_env = new Environment(this);
+ QObject::connect(m_env, SIGNAL(scriptError(QScriptValue)),
+ this, SLOT(reportScriptError(QScriptValue)));
+
+ Context2D *context = new Context2D(this);
+ context->setSize(150, 150);
+ m_canvas = new QContext2DCanvas(context, m_env, this);
+ m_canvas->setFixedSize(context->size());
+ m_canvas->setObjectName("tutorial");
+ m_env->addCanvas(m_canvas);
+//! [0]
+
+#ifndef QT_NO_SCRIPTTOOLS
+ QVBoxLayout *vbox = new QVBoxLayout();
+ vbox->addWidget(m_canvas);
+ m_debugButton = new QPushButton(tr("Run in Debugger"));
+ connect(m_debugButton, SIGNAL(clicked()), this, SLOT(runInDebugger()));
+ vbox->addWidget(m_debugButton);
+#endif
+
+ QHBoxLayout *hbox = new QHBoxLayout(this);
+ m_view = new QListWidget(this);
+ m_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ hbox->addWidget(m_view);
+#ifndef QT_NO_SCRIPTTOOLS
+ hbox->addLayout(vbox);
+#else
+ hbox->addWidget(m_canvas);
+#endif
+
+//! [1]
+ QDir dir(scriptsDir());
+ QFileInfoList entries = dir.entryInfoList(QStringList() << "*.js");
+ for (int i = 0; i < entries.size(); ++i)
+ m_view->addItem(entries.at(i).fileName());
+ connect(m_view, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
+ this, SLOT(selectScript(QListWidgetItem*)));
+//! [1]
+
+#ifndef QT_NO_SCRIPTTOOLS
+ m_debugger = new QScriptEngineDebugger(this);
+ m_debugger->attachTo(m_env->engine());
+ m_debugWindow = m_debugger->standardWindow();
+ m_debugWindow->setWindowModality(Qt::ApplicationModal);
+ m_debugWindow->resize(1280, 704);
+#endif
+
+ setWindowTitle(tr("Context 2D"));
+}
+
+//! [2]
+void Window::selectScript(QListWidgetItem *item)
+{
+ QString fileName = item->text();
+ runScript(fileName, /*debug=*/false);
+}
+//! [2]
+
+void Window::reportScriptError(const QScriptValue &error)
+{
+ QMessageBox::warning(this, tr("Context 2D"), tr("Line %0: %1")
+ .arg(error.property("lineNumber").toInt32())
+ .arg(error.toString()));
+}
+
+#ifndef QT_NO_SCRIPTTOOLS
+//! [3]
+void Window::runInDebugger()
+{
+ QListWidgetItem *item = m_view->currentItem();
+ if (item) {
+ QString fileName = item->text();
+ runScript(fileName, /*debug=*/true);
+ }
+}
+//! [3]
+#endif
+
+//! [4]
+void Window::runScript(const QString &fileName, bool debug)
+{
+ QFile file(scriptsDir() + "/" + fileName);
+ file.open(QIODevice::ReadOnly);
+ QString contents = file.readAll();
+ file.close();
+ m_env->reset();
+
+#ifndef QT_NO_SCRIPTTOOLS
+ if (debug)
+ m_debugger->action(QScriptEngineDebugger::InterruptAction)->trigger();
+#else
+ Q_UNUSED(debug);
+#endif
+
+ QScriptValue ret = m_env->evaluate(contents, fileName);
+
+#ifndef QT_NO_SCRIPTTOOLS
+ m_debugWindow->hide();
+#endif
+
+ if (ret.isError())
+ reportScriptError(ret);
+}
+//! [4]
diff --git a/examples/script/context2d/window.h b/examples/script/context2d/window.h
new file mode 100644
index 0000000000..a0aff8e01f
--- /dev/null
+++ b/examples/script/context2d/window.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+class Environment;
+class QContext2DCanvas;
+QT_BEGIN_NAMESPACE
+class QListWidget;
+class QListWidgetItem;
+class QMainWindow;
+class QPushButton;
+class QScriptValue;
+class QScriptEngineDebugger;
+QT_END_NAMESPACE
+
+class Window : public QWidget
+{
+ Q_OBJECT
+public:
+ Window(QWidget *parent = 0);
+private slots:
+ void selectScript(QListWidgetItem *item);
+ void reportScriptError(const QScriptValue &value);
+#ifndef QT_NO_SCRIPTTOOLS
+ void runInDebugger();
+#endif
+private:
+ void runScript(const QString &fileName, bool debug);
+
+ QListWidget *m_view;
+ Environment *m_env;
+ QContext2DCanvas *m_canvas;
+#ifndef QT_NO_SCRIPTTOOLS
+ QScriptEngineDebugger *m_debugger;
+ QPushButton *m_debugButton;
+ QMainWindow *m_debugWindow;
+#endif
+};
+
+#endif // WINDOW_H
diff --git a/examples/script/customclass/bytearrayclass.cpp b/examples/script/customclass/bytearrayclass.cpp
new file mode 100644
index 0000000000..7865381a03
--- /dev/null
+++ b/examples/script/customclass/bytearrayclass.cpp
@@ -0,0 +1,304 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtScript/QScriptClassPropertyIterator>
+#include <QtScript/QScriptEngine>
+#include "bytearrayclass.h"
+#include "bytearrayprototype.h"
+
+#include <stdlib.h>
+
+Q_DECLARE_METATYPE(QByteArray*)
+Q_DECLARE_METATYPE(ByteArrayClass*)
+
+class ByteArrayClassPropertyIterator : public QScriptClassPropertyIterator
+{
+public:
+ ByteArrayClassPropertyIterator(const QScriptValue &object);
+ ~ByteArrayClassPropertyIterator();
+
+ bool hasNext() const;
+ void next();
+
+ bool hasPrevious() const;
+ void previous();
+
+ void toFront();
+ void toBack();
+
+ QScriptString name() const;
+ uint id() const;
+
+private:
+ int m_index;
+ int m_last;
+};
+
+static qint32 toArrayIndex(const QString &str)
+{
+ QByteArray bytes = str.toUtf8();
+ char *eptr;
+ quint32 pos = strtoul(bytes.constData(), &eptr, 10);
+ if ((eptr == bytes.constData() + bytes.size())
+ && (QByteArray::number(pos) == bytes)) {
+ return pos;
+ }
+ return -1;
+}
+
+//! [0]
+ByteArrayClass::ByteArrayClass(QScriptEngine *engine)
+ : QObject(engine), QScriptClass(engine)
+{
+ qScriptRegisterMetaType<QByteArray>(engine, toScriptValue, fromScriptValue);
+
+ length = engine->toStringHandle(QLatin1String("length"));
+
+ proto = engine->newQObject(new ByteArrayPrototype(this),
+ QScriptEngine::QtOwnership,
+ QScriptEngine::SkipMethodsInEnumeration
+ | QScriptEngine::ExcludeSuperClassMethods
+ | QScriptEngine::ExcludeSuperClassProperties);
+ QScriptValue global = engine->globalObject();
+ proto.setPrototype(global.property("Object").property("prototype"));
+
+ ctor = engine->newFunction(construct);
+ ctor.setData(qScriptValueFromValue(engine, this));
+}
+//! [0]
+
+ByteArrayClass::~ByteArrayClass()
+{
+}
+
+//! [3]
+QScriptClass::QueryFlags ByteArrayClass::queryProperty(const QScriptValue &object,
+ const QScriptString &name,
+ QueryFlags flags, uint *id)
+{
+ QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
+ if (!ba)
+ return 0;
+ if (name == length) {
+ return flags;
+ } else {
+ qint32 pos = toArrayIndex(name);
+ if (pos == -1)
+ return 0;
+ *id = pos;
+ if ((flags & HandlesReadAccess) && (pos >= ba->size()))
+ flags &= ~HandlesReadAccess;
+ return flags;
+ }
+}
+//! [3]
+
+//! [4]
+QScriptValue ByteArrayClass::property(const QScriptValue &object,
+ const QScriptString &name, uint id)
+{
+ QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
+ if (!ba)
+ return QScriptValue();
+ if (name == length) {
+ return ba->length();
+ } else {
+ qint32 pos = id;
+ if ((pos < 0) || (pos >= ba->size()))
+ return QScriptValue();
+ return uint(ba->at(pos)) & 255;
+ }
+ return QScriptValue();
+}
+//! [4]
+
+//! [5]
+void ByteArrayClass::setProperty(QScriptValue &object,
+ const QScriptString &name,
+ uint id, const QScriptValue &value)
+{
+ QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
+ if (!ba)
+ return;
+ if (name == length) {
+ ba->resize(value.toInt32());
+ } else {
+ qint32 pos = id;
+ if (pos < 0)
+ return;
+ if (ba->size() <= pos)
+ ba->resize(pos + 1);
+ (*ba)[pos] = char(value.toInt32());
+ }
+}
+//! [5]
+
+//! [6]
+QScriptValue::PropertyFlags ByteArrayClass::propertyFlags(
+ const QScriptValue &/*object*/, const QScriptString &name, uint /*id*/)
+{
+ if (name == length) {
+ return QScriptValue::Undeletable
+ | QScriptValue::SkipInEnumeration;
+ }
+ return QScriptValue::Undeletable;
+}
+//! [6]
+
+//! [7]
+QScriptClassPropertyIterator *ByteArrayClass::newIterator(const QScriptValue &object)
+{
+ return new ByteArrayClassPropertyIterator(object);
+}
+//! [7]
+
+QString ByteArrayClass::name() const
+{
+ return QLatin1String("ByteArray");
+}
+
+QScriptValue ByteArrayClass::prototype() const
+{
+ return proto;
+}
+
+QScriptValue ByteArrayClass::constructor()
+{
+ return ctor;
+}
+
+QScriptValue ByteArrayClass::newInstance(int size)
+{
+ return newInstance(QByteArray(size, /*ch=*/0));
+}
+
+//! [1]
+QScriptValue ByteArrayClass::newInstance(const QByteArray &ba)
+{
+ QScriptValue data = engine()->newVariant(qVariantFromValue(ba));
+ return engine()->newObject(this, data);
+}
+//! [1]
+
+//! [2]
+QScriptValue ByteArrayClass::construct(QScriptContext *ctx, QScriptEngine *)
+{
+ ByteArrayClass *cls = qscriptvalue_cast<ByteArrayClass*>(ctx->callee().data());
+ if (!cls)
+ return QScriptValue();
+ int size = ctx->argument(0).toInt32();
+ return cls->newInstance(size);
+}
+//! [2]
+
+QScriptValue ByteArrayClass::toScriptValue(QScriptEngine *eng, const QByteArray &ba)
+{
+ QScriptValue ctor = eng->globalObject().property("ByteArray");
+ ByteArrayClass *cls = qscriptvalue_cast<ByteArrayClass*>(ctor.data());
+ if (!cls)
+ return eng->newVariant(qVariantFromValue(ba));
+ return cls->newInstance(ba);
+}
+
+void ByteArrayClass::fromScriptValue(const QScriptValue &obj, QByteArray &ba)
+{
+ ba = qscriptvalue_cast<QByteArray>(obj.data());
+}
+
+
+
+ByteArrayClassPropertyIterator::ByteArrayClassPropertyIterator(const QScriptValue &object)
+ : QScriptClassPropertyIterator(object)
+{
+ toFront();
+}
+
+ByteArrayClassPropertyIterator::~ByteArrayClassPropertyIterator()
+{
+}
+
+//! [8]
+bool ByteArrayClassPropertyIterator::hasNext() const
+{
+ QByteArray *ba = qscriptvalue_cast<QByteArray*>(object().data());
+ return m_index < ba->size();
+}
+
+void ByteArrayClassPropertyIterator::next()
+{
+ m_last = m_index;
+ ++m_index;
+}
+
+bool ByteArrayClassPropertyIterator::hasPrevious() const
+{
+ return (m_index > 0);
+}
+
+void ByteArrayClassPropertyIterator::previous()
+{
+ --m_index;
+ m_last = m_index;
+}
+
+void ByteArrayClassPropertyIterator::toFront()
+{
+ m_index = 0;
+ m_last = -1;
+}
+
+void ByteArrayClassPropertyIterator::toBack()
+{
+ QByteArray *ba = qscriptvalue_cast<QByteArray*>(object().data());
+ m_index = ba->size();
+ m_last = -1;
+}
+
+QScriptString ByteArrayClassPropertyIterator::name() const
+{
+ return QScriptString();
+}
+
+uint ByteArrayClassPropertyIterator::id() const
+{
+ return m_last;
+}
+//! [8]
diff --git a/examples/script/customclass/bytearrayclass.h b/examples/script/customclass/bytearrayclass.h
new file mode 100644
index 0000000000..e9a5f077a8
--- /dev/null
+++ b/examples/script/customclass/bytearrayclass.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BYTEARRAYCLASS_H
+#define BYTEARRAYCLASS_H
+
+#include <QtCore/QObject>
+#include <QtScript/QScriptClass>
+#include <QtScript/QScriptString>
+
+class ByteArrayClass : public QObject, public QScriptClass
+{
+public:
+ ByteArrayClass(QScriptEngine *engine);
+ ~ByteArrayClass();
+
+ QScriptValue constructor();
+
+ QScriptValue newInstance(int size = 0);
+ QScriptValue newInstance(const QByteArray &ba);
+
+ QueryFlags queryProperty(const QScriptValue &object,
+ const QScriptString &name,
+ QueryFlags flags, uint *id);
+
+ QScriptValue property(const QScriptValue &object,
+ const QScriptString &name, uint id);
+
+ void setProperty(QScriptValue &object, const QScriptString &name,
+ uint id, const QScriptValue &value);
+
+ QScriptValue::PropertyFlags propertyFlags(
+ const QScriptValue &object, const QScriptString &name, uint id);
+
+ QScriptClassPropertyIterator *newIterator(const QScriptValue &object);
+
+ QString name() const;
+
+ QScriptValue prototype() const;
+
+private:
+ static QScriptValue construct(QScriptContext *ctx, QScriptEngine *eng);
+
+ static QScriptValue toScriptValue(QScriptEngine *eng, const QByteArray &ba);
+ static void fromScriptValue(const QScriptValue &obj, QByteArray &ba);
+
+ QScriptString length;
+ QScriptValue proto;
+ QScriptValue ctor;
+};
+
+#endif
diff --git a/examples/script/customclass/bytearrayclass.pri b/examples/script/customclass/bytearrayclass.pri
new file mode 100644
index 0000000000..05fdeb4e77
--- /dev/null
+++ b/examples/script/customclass/bytearrayclass.pri
@@ -0,0 +1,6 @@
+SOURCES += $$PWD/bytearrayclass.cpp \
+ $$PWD/bytearrayprototype.cpp
+HEADERS += $$PWD/bytearrayclass.h \
+ $$PWD/bytearrayprototype.h
+
+INCLUDEPATH += $$PWD
diff --git a/examples/script/customclass/bytearrayprototype.cpp b/examples/script/customclass/bytearrayprototype.cpp
new file mode 100644
index 0000000000..eeb73f9621
--- /dev/null
+++ b/examples/script/customclass/bytearrayprototype.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "bytearrayprototype.h"
+#include <QtScript/QScriptEngine>
+
+Q_DECLARE_METATYPE(QByteArray*)
+
+ByteArrayPrototype::ByteArrayPrototype(QObject *parent)
+ : QObject(parent)
+{
+}
+
+ByteArrayPrototype::~ByteArrayPrototype()
+{
+}
+
+//! [0]
+QByteArray *ByteArrayPrototype::thisByteArray() const
+{
+ return qscriptvalue_cast<QByteArray*>(thisObject().data());
+}
+//! [0]
+
+void ByteArrayPrototype::chop(int n)
+{
+ thisByteArray()->chop(n);
+}
+
+bool ByteArrayPrototype::equals(const QByteArray &other)
+{
+ return *thisByteArray() == other;
+}
+
+QByteArray ByteArrayPrototype::left(int len) const
+{
+ return thisByteArray()->left(len);
+}
+
+//! [1]
+QByteArray ByteArrayPrototype::mid(int pos, int len) const
+{
+ return thisByteArray()->mid(pos, len);
+}
+
+QScriptValue ByteArrayPrototype::remove(int pos, int len)
+{
+ thisByteArray()->remove(pos, len);
+ return thisObject();
+}
+//! [1]
+
+QByteArray ByteArrayPrototype::right(int len) const
+{
+ return thisByteArray()->right(len);
+}
+
+QByteArray ByteArrayPrototype::simplified() const
+{
+ return thisByteArray()->simplified();
+}
+
+QByteArray ByteArrayPrototype::toBase64() const
+{
+ return thisByteArray()->toBase64();
+}
+
+QByteArray ByteArrayPrototype::toLower() const
+{
+ return thisByteArray()->toLower();
+}
+
+QByteArray ByteArrayPrototype::toUpper() const
+{
+ return thisByteArray()->toUpper();
+}
+
+QByteArray ByteArrayPrototype::trimmed() const
+{
+ return thisByteArray()->trimmed();
+}
+
+void ByteArrayPrototype::truncate(int pos)
+{
+ thisByteArray()->truncate(pos);
+}
+
+QString ByteArrayPrototype::toLatin1String() const
+{
+ return QString::fromLatin1(*thisByteArray());
+}
+
+//! [2]
+QScriptValue ByteArrayPrototype::valueOf() const
+{
+ return thisObject().data();
+}
+//! [2]
diff --git a/examples/script/customclass/bytearrayprototype.h b/examples/script/customclass/bytearrayprototype.h
new file mode 100644
index 0000000000..fe9e15b859
--- /dev/null
+++ b/examples/script/customclass/bytearrayprototype.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BYTEARRAYPROTOTYPE_H
+#define BYTEARRAYPROTOTYPE_H
+
+#include <QtCore/QByteArray>
+#include <QtCore/QObject>
+#include <QtScript/QScriptable>
+#include <QtScript/QScriptValue>
+
+//! [0]
+class ByteArrayPrototype : public QObject, public QScriptable
+{
+Q_OBJECT
+public:
+ ByteArrayPrototype(QObject *parent = 0);
+ ~ByteArrayPrototype();
+
+public slots:
+ void chop(int n);
+ bool equals(const QByteArray &other);
+ QByteArray left(int len) const;
+ QByteArray mid(int pos, int len = -1) const;
+ QScriptValue remove(int pos, int len);
+ QByteArray right(int len) const;
+ QByteArray simplified() const;
+ QByteArray toBase64() const;
+ QByteArray toLower() const;
+ QByteArray toUpper() const;
+ QByteArray trimmed() const;
+ void truncate(int pos);
+ QString toLatin1String() const;
+ QScriptValue valueOf() const;
+
+private:
+ QByteArray *thisByteArray() const;
+};
+//! [0]
+
+
+#endif
diff --git a/examples/script/customclass/customclass.pro b/examples/script/customclass/customclass.pro
new file mode 100644
index 0000000000..bb263d2709
--- /dev/null
+++ b/examples/script/customclass/customclass.pro
@@ -0,0 +1,15 @@
+QT = core script
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+include(bytearrayclass.pri)
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/customclass
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.pri
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/customclass
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/script/customclass/main.cpp b/examples/script/customclass/main.cpp
new file mode 100644
index 0000000000..1c3ceb1af3
--- /dev/null
+++ b/examples/script/customclass/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtScript>
+#include "bytearrayclass.h"
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QScriptEngine eng;
+
+ ByteArrayClass *baClass = new ByteArrayClass(&eng);
+ eng.globalObject().setProperty("ByteArray", baClass->constructor());
+
+ qDebug() << "ba = new ByteArray(4):" << eng.evaluate("ba = new ByteArray(4)").toString();
+ qDebug() << "ba.length:" << eng.evaluate("ba.length").toNumber();
+ qDebug() << "ba[1] = 123; ba[1]:" << eng.evaluate("ba[1] = 123; ba[1]").toNumber();
+ qDebug() << "ba[7] = 224; ba.length:" << eng.evaluate("ba[7] = 224; ba.length").toNumber();
+ qDebug() << "for-in loop:" << eng.evaluate("result = '';\n"
+ "for (var p in ba) {\n"
+ " if (result.length > 0)\n"
+ " result += ', ';\n"
+ " result += '(' + p + ',' + ba[p] + ')';\n"
+ "} result").toString();
+ qDebug() << "ba.toBase64():" << eng.evaluate("b64 = ba.toBase64()").toString();
+ qDebug() << "ba.toBase64().toLatin1String():" << eng.evaluate("b64.toLatin1String()").toString();
+ qDebug() << "ba.valueOf():" << eng.evaluate("ba.valueOf()").toString();
+ qDebug() << "ba.chop(2); ba.length:" << eng.evaluate("ba.chop(2); ba.length").toNumber();
+
+ return 0;
+}
diff --git a/examples/script/defaultprototypes/code.js b/examples/script/defaultprototypes/code.js
new file mode 100644
index 0000000000..048e1319df
--- /dev/null
+++ b/examples/script/defaultprototypes/code.js
@@ -0,0 +1,20 @@
+//! [0]
+listWidget.addItem("Red");
+listWidget.addItem("Blue");
+listWidget.addItem("Green");
+listWidget.addItem("Cyan");
+listWidget.addItem("Yellow");
+listWidget.addItem("Purple");
+listWidget.addItems(["Orange", "Gray"]);
+//! [0]
+
+//! [1]
+listWidget.currentItemChanged.connect(
+ function(item)
+ {
+ listWidget.setBackgroundColor(item.text);
+ }
+);
+//! [1]
+
+listWidget.show();
diff --git a/examples/script/defaultprototypes/defaultprototypes.pro b/examples/script/defaultprototypes/defaultprototypes.pro
new file mode 100644
index 0000000000..21328e6060
--- /dev/null
+++ b/examples/script/defaultprototypes/defaultprototypes.pro
@@ -0,0 +1,12 @@
+QT += script
+RESOURCES += defaultprototypes.qrc
+SOURCES += main.cpp prototypes.cpp
+HEADERS += prototypes.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/defaultprototypes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.js defaultprototypes.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/defaultprototypes
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/script/defaultprototypes/defaultprototypes.qrc b/examples/script/defaultprototypes/defaultprototypes.qrc
new file mode 100644
index 0000000000..ada405b130
--- /dev/null
+++ b/examples/script/defaultprototypes/defaultprototypes.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>code.js</file>
+ </qresource>
+</RCC>
diff --git a/examples/script/defaultprototypes/main.cpp b/examples/script/defaultprototypes/main.cpp
new file mode 100644
index 0000000000..3245ae0327
--- /dev/null
+++ b/examples/script/defaultprototypes/main.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtScript>
+#include "prototypes.h"
+
+//! [0]
+Q_DECLARE_METATYPE(QListWidgetItem*)
+Q_DECLARE_METATYPE(QListWidget*)
+//! [0]
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(defaultprototypes);
+
+ QApplication app(argc, argv);
+//! [1]
+ QScriptEngine engine;
+
+ ListWidgetItemPrototype lwiProto;
+ engine.setDefaultPrototype(qMetaTypeId<QListWidgetItem*>(),
+ engine.newQObject(&lwiProto));
+
+ ListWidgetPrototype lwProto;
+ engine.setDefaultPrototype(qMetaTypeId<QListWidget*>(),
+ engine.newQObject(&lwProto));
+//! [1]
+
+//! [2]
+ QListWidget listWidget;
+ engine.globalObject().setProperty("listWidget",
+ engine.newQObject(&listWidget));
+//! [2]
+
+ QFile file(":/code.js");
+ file.open(QIODevice::ReadOnly);
+ QScriptValue result = engine.evaluate(file.readAll());
+ file.close();
+ if (engine.hasUncaughtException()) {
+ int lineNo = engine.uncaughtExceptionLineNumber();
+ qWarning() << "line" << lineNo << ":" << result.toString();
+ }
+
+ return app.exec();
+}
diff --git a/examples/script/defaultprototypes/prototypes.cpp b/examples/script/defaultprototypes/prototypes.cpp
new file mode 100644
index 0000000000..b2bad4514c
--- /dev/null
+++ b/examples/script/defaultprototypes/prototypes.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "prototypes.h"
+#include <QtGui/QListWidgetItem>
+#include <QtGui/QListWidget>
+#include <QtScript/QScriptValue>
+#include <QtScript/QScriptEngine>
+
+Q_DECLARE_METATYPE(QListWidgetItem*)
+Q_DECLARE_METATYPE(QListWidget*)
+
+//! [0]
+ListWidgetItemPrototype::ListWidgetItemPrototype(QObject *parent)
+ : QObject(parent)
+{
+}
+
+QString ListWidgetItemPrototype::text() const
+{
+ QListWidgetItem *item = qscriptvalue_cast<QListWidgetItem*>(thisObject());
+ if (item)
+ return item->text();
+ return QString();
+}
+
+void ListWidgetItemPrototype::setText(const QString &text)
+{
+ QListWidgetItem *item = qscriptvalue_cast<QListWidgetItem*>(thisObject());
+ if (item)
+ item->setText(text);
+}
+
+QString ListWidgetItemPrototype::toString() const
+{
+ return QString("ListWidgetItem(text = %0)").arg(text());
+}
+//! [0]
+
+
+
+//! [1]
+ListWidgetPrototype::ListWidgetPrototype(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void ListWidgetPrototype::addItem(const QString &text)
+{
+ QListWidget *widget = qscriptvalue_cast<QListWidget*>(thisObject());
+ if (widget)
+ widget->addItem(text);
+}
+
+void ListWidgetPrototype::addItems(const QStringList &texts)
+{
+ QListWidget *widget = qscriptvalue_cast<QListWidget*>(thisObject());
+ if (widget)
+ widget->addItems(texts);
+}
+
+void ListWidgetPrototype::setBackgroundColor(const QString &colorName)
+{
+ QListWidget *widget = qscriptvalue_cast<QListWidget*>(thisObject());
+ if (widget) {
+ QPalette palette = widget->palette();
+ QColor color(colorName);
+ palette.setBrush(QPalette::Base, color);
+ widget->setPalette(palette);
+ }
+}
+//! [1]
diff --git a/examples/script/defaultprototypes/prototypes.h b/examples/script/defaultprototypes/prototypes.h
new file mode 100644
index 0000000000..76cecaa81c
--- /dev/null
+++ b/examples/script/defaultprototypes/prototypes.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PROTOTYPES_H
+#define PROTOTYPES_H
+
+#include <QtCore/QObject>
+#include <QtScript/QScriptable>
+
+//! [0]
+class ListWidgetItemPrototype : public QObject, public QScriptable
+{
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText)
+public:
+ ListWidgetItemPrototype(QObject *parent = 0);
+
+ QString text() const;
+ void setText(const QString &text);
+
+public slots:
+ QString toString() const;
+};
+//! [0]
+
+//! [1]
+class ListWidgetPrototype : public QObject, public QScriptable
+{
+ Q_OBJECT
+public:
+ ListWidgetPrototype(QObject *parent = 0);
+
+public slots:
+ void addItem(const QString &text);
+ void addItems(const QStringList &texts);
+ void setBackgroundColor(const QString &colorName);
+};
+//! [1]
+
+#endif
diff --git a/examples/script/helloscript/helloscript.pro b/examples/script/helloscript/helloscript.pro
new file mode 100644
index 0000000000..5b04f84ee2
--- /dev/null
+++ b/examples/script/helloscript/helloscript.pro
@@ -0,0 +1,11 @@
+QT += script
+RESOURCES += helloscript.qrc
+SOURCES += main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/helloscript
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS helloscript.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/helloscript
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/script/helloscript/helloscript.qrc b/examples/script/helloscript/helloscript.qrc
new file mode 100644
index 0000000000..dc93461d59
--- /dev/null
+++ b/examples/script/helloscript/helloscript.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>helloscript.qs</file>
+ </qresource>
+</RCC>
diff --git a/examples/script/helloscript/helloscript.qs b/examples/script/helloscript/helloscript.qs
new file mode 100644
index 0000000000..6d8e87cb3b
--- /dev/null
+++ b/examples/script/helloscript/helloscript.qs
@@ -0,0 +1,5 @@
+//! [0]
+button.text = qsTr('Hello World!');
+button.styleSheet = 'font-style: italic';
+button.show();
+//! [0]
diff --git a/examples/script/helloscript/main.cpp b/examples/script/helloscript/main.cpp
new file mode 100644
index 0000000000..4d243a61a0
--- /dev/null
+++ b/examples/script/helloscript/main.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMessageBox>
+#include <QPushButton>
+#include <QtScript>
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(helloscript);
+//! [0]
+
+//! [1]
+ QApplication app(argc, argv);
+
+ QScriptEngine engine;
+
+ QTranslator translator;
+ translator.load("helloscript_la");
+ app.installTranslator(&translator);
+ engine.installTranslatorFunctions();
+//! [1]
+
+//! [2]
+ QPushButton button;
+ QScriptValue scriptButton = engine.newQObject(&button);
+ engine.globalObject().setProperty("button", scriptButton);
+//! [2]
+
+//! [3]
+ QString fileName(":/helloscript.qs");
+ QFile scriptFile(fileName);
+ scriptFile.open(QIODevice::ReadOnly);
+ QTextStream stream(&scriptFile);
+ QString contents = stream.readAll();
+ scriptFile.close();
+//! [3]
+
+//! [4]
+ QScriptValue result = engine.evaluate(contents, fileName);
+//! [4]
+
+//! [5]
+ if (result.isError()) {
+ QMessageBox::critical(0, "Hello Script",
+ QString::fromLatin1("%0:%1: %2")
+ .arg(fileName)
+ .arg(result.property("lineNumber").toInt32())
+ .arg(result.toString()));
+ return -1;
+ }
+//! [5]
+
+//! [6]
+ return app.exec();
+}
+//! [6]
diff --git a/examples/script/marshal/main.cpp b/examples/script/marshal/main.cpp
new file mode 100644
index 0000000000..e5dbdde616
--- /dev/null
+++ b/examples/script/marshal/main.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtScript>
+
+template <class Container>
+QScriptValue toScriptValue(QScriptEngine *eng, const Container &cont)
+{
+ QScriptValue a = eng->newArray();
+ typename Container::const_iterator begin = cont.begin();
+ typename Container::const_iterator end = cont.end();
+ typename Container::const_iterator it;
+ for (it = begin; it != end; ++it)
+ a.setProperty(quint32(it - begin), qScriptValueFromValue(eng, *it));
+ return a;
+}
+
+template <class Container>
+void fromScriptValue(const QScriptValue &value, Container &cont)
+{
+ quint32 len = value.property("length").toUInt32();
+ for (quint32 i = 0; i < len; ++i) {
+ QScriptValue item = value.property(i);
+ typedef typename Container::value_type ContainerValue;
+ cont.push_back(qscriptvalue_cast<ContainerValue>(item));
+ }
+}
+
+typedef QVector<int> IntVector;
+typedef QVector<QString> StringVector;
+
+Q_DECLARE_METATYPE(IntVector)
+Q_DECLARE_METATYPE(StringVector)
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+
+ QScriptEngine eng;
+ // register our custom types
+ qScriptRegisterMetaType<IntVector>(&eng, toScriptValue, fromScriptValue);
+ qScriptRegisterMetaType<StringVector>(&eng, toScriptValue, fromScriptValue);
+
+ QScriptValue val = eng.evaluate("[1, 4, 7, 11, 50, 3, 19, 60]");
+
+ fprintf(stdout, "Script array: %s\n", qPrintable(val.toString()));
+
+ IntVector iv = qscriptvalue_cast<IntVector>(val);
+
+ fprintf(stdout, "qscriptvalue_cast to QVector<int>: ");
+ for (int i = 0; i < iv.size(); ++i)
+ fprintf(stdout, "%s%d", (i > 0) ? "," : "", iv.at(i));
+ fprintf(stdout, "\n");
+
+ val = eng.evaluate("[9, 'foo', 46.5, 'bar', 'Qt', 555, 'hello']");
+
+ fprintf(stdout, "Script array: %s\n", qPrintable(val.toString()));
+
+ StringVector sv = qscriptvalue_cast<StringVector>(val);
+
+ fprintf(stdout, "qscriptvalue_cast to QVector<QString>: ");
+ for (int i = 0; i < sv.size(); ++i)
+ fprintf(stdout, "%s%s", (i > 0) ? "," : "", qPrintable(sv.at(i)));
+ fprintf(stdout, "\n");
+
+ return 0;
+}
diff --git a/examples/script/marshal/marshal.pro b/examples/script/marshal/marshal.pro
new file mode 100644
index 0000000000..69fc578640
--- /dev/null
+++ b/examples/script/marshal/marshal.pro
@@ -0,0 +1,11 @@
+QT = core script
+CONFIG += console
+SOURCES += main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/marshal
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS marshal.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/marshal
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/script/qscript/main.cpp b/examples/script/qscript/main.cpp
new file mode 100644
index 0000000000..891c89f713
--- /dev/null
+++ b/examples/script/qscript/main.cpp
@@ -0,0 +1,221 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <qscriptengine.h>
+
+#include <QtCore/QFile>
+#include <QtCore/QTextStream>
+#include <QtCore/QStringList>
+#include <QtGui/QApplication>
+
+#include <stdlib.h>
+
+#include "bytearrayclass.h"
+
+static bool wantsToQuit;
+
+static QScriptValue qtscript_quit(QScriptContext *ctx, QScriptEngine *eng)
+{
+ Q_UNUSED(ctx);
+ wantsToQuit = true;
+ return eng->undefinedValue();
+}
+
+static void interactive(QScriptEngine *eng)
+{
+ QScriptValue global = eng->globalObject();
+ QScriptValue quitFunction = eng->newFunction(qtscript_quit);
+ if (!global.property(QLatin1String("exit")).isValid())
+ global.setProperty(QLatin1String("exit"), quitFunction);
+ if (!global.property(QLatin1String("quit")).isValid())
+ global.setProperty(QLatin1String("quit"), quitFunction);
+ wantsToQuit = false;
+
+ QTextStream qin(stdin, QFile::ReadOnly);
+
+ const char *qscript_prompt = "qs> ";
+ const char *dot_prompt = ".... ";
+ const char *prompt = qscript_prompt;
+
+ QString code;
+
+ forever {
+ QString line;
+
+ printf("%s", prompt);
+ fflush(stdout);
+
+ line = qin.readLine();
+ if (line.isNull())
+ break;
+
+ code += line;
+ code += QLatin1Char('\n');
+
+ if (line.trimmed().isEmpty()) {
+ continue;
+
+ } else if (! eng->canEvaluate(code)) {
+ prompt = dot_prompt;
+
+ } else {
+ QScriptValue result = eng->evaluate(code, QLatin1String("typein"));
+
+ code.clear();
+ prompt = qscript_prompt;
+
+ if (! result.isUndefined())
+ fprintf(stderr, "%s\n", qPrintable(result.toString()));
+
+ if (wantsToQuit)
+ break;
+ }
+ }
+}
+
+static QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine)
+{
+ return engine->importExtension(context->argument(0).toString());
+}
+
+static QScriptValue loadScripts(QScriptContext *context, QScriptEngine *engine)
+{
+ for (int i = 0; i < context->argumentCount(); ++i) {
+ QString fileName = context->argument(0).toString();
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly))
+ return context->throwError(QString::fromLatin1("could not open %0 for reading").arg(fileName));
+ QTextStream ts(&file);
+ QString contents = ts.readAll();
+ file.close();
+ QScriptContext *pc = context->parentContext();
+ context->setActivationObject(pc->activationObject());
+ context->setThisObject(pc->thisObject());
+ QScriptValue ret = engine->evaluate(contents);
+ if (engine->hasUncaughtException())
+ return ret;
+ }
+ return engine->undefinedValue();
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication *app;
+ if (argc >= 2 && !qstrcmp(argv[1], "-tty")) {
+ ++argv;
+ --argc;
+ app = new QApplication(argc, argv, QApplication::Tty);
+ } else {
+ app = new QApplication(argc, argv);
+ }
+
+ QScriptEngine *eng = new QScriptEngine();
+
+ QScriptValue globalObject = eng->globalObject();
+
+ globalObject.setProperty("load", eng->newFunction(loadScripts, /*length=*/1));
+
+ {
+ if (!globalObject.property("qt").isObject())
+ globalObject.setProperty("qt", eng->newObject());
+ QScriptValue qscript = eng->newObject();
+ qscript.setProperty("importExtension", eng->newFunction(importExtension));
+ globalObject.property("qt").setProperty("script", qscript);
+ }
+
+ ByteArrayClass *byteArrayClass = new ByteArrayClass(eng);
+ globalObject.setProperty("ByteArray", byteArrayClass->constructor());
+
+ if (! *++argv) {
+ interactive(eng);
+ return EXIT_SUCCESS;
+ }
+
+ while (const char *arg = *argv++) {
+ QString fn = QString::fromLocal8Bit(arg);
+
+ if (fn == QLatin1String("-i")) {
+ interactive(eng);
+ break;
+ }
+
+ QString contents;
+ int lineNumber = 1;
+
+ if (fn == QLatin1String("-")) {
+ QTextStream stream(stdin, QFile::ReadOnly);
+ contents = stream.readAll();
+ }
+
+ else {
+ QFile file(fn);
+
+ if (file.open(QFile::ReadOnly)) {
+ QTextStream stream(&file);
+ contents = stream.readAll();
+ file.close();
+
+ // strip off #!/usr/bin/env qscript line
+ if (contents.startsWith("#!")) {
+ contents.remove(0, contents.indexOf("\n"));
+ ++lineNumber;
+ }
+ }
+ }
+
+ if (contents.isEmpty())
+ continue;
+
+ QScriptValue r = eng->evaluate(contents, fn, lineNumber);
+ if (eng->hasUncaughtException()) {
+ QStringList backtrace = eng->uncaughtExceptionBacktrace();
+ fprintf (stderr, " %s\n%s\n\n", qPrintable(r.toString()),
+ qPrintable(backtrace.join("\n")));
+ return EXIT_FAILURE;
+ }
+ }
+
+ delete eng;
+ delete app;
+
+ return EXIT_SUCCESS;
+}
diff --git a/examples/script/qscript/qscript.pro b/examples/script/qscript/qscript.pro
new file mode 100644
index 0000000000..3c03545177
--- /dev/null
+++ b/examples/script/qscript/qscript.pro
@@ -0,0 +1,16 @@
+
+QT += script
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+include(../customclass/bytearrayclass.pri)
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/qscript
+sources.files = $$RESOURCES $$FORMS main.cpp qscript.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/qscript
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/script/qsdbg/example.qs b/examples/script/qsdbg/example.qs
new file mode 100644
index 0000000000..47c1363d49
--- /dev/null
+++ b/examples/script/qsdbg/example.qs
@@ -0,0 +1,17 @@
+function bar() {
+ var x = 1;
+ var y = 2;
+ return x + y;
+}
+
+function foo(a, b, c) {
+ var i = a + bar();
+ var j = b - bar();
+ var k = c * bar();
+ return Math.cos(i) + Math.sin(j) - Math.atan(k);
+}
+
+var first = foo(1, 2, 3);
+var second = foo(4, 5, 6);
+print("first was:", first, ", and second was:", second);
+
diff --git a/examples/script/qsdbg/main.cpp b/examples/script/qsdbg/main.cpp
new file mode 100644
index 0000000000..eb377cf2a5
--- /dev/null
+++ b/examples/script/qsdbg/main.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtScript>
+
+#include "scriptdebugger.h"
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ fprintf(stderr, "*** you must specify a script file to evaluate (try example.qs)\n");
+ return(-1);
+ }
+
+ QString fileName = QString::fromLatin1(argv[1]);
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ fprintf(stderr, "*** failed to open `%s' for reading\n", argv[1]);
+ return(-1);
+ }
+
+ QScriptEngine engine;
+ QString code = QTextStream(&file).readAll();
+ file.close();
+
+ fprintf(stdout, "\n*** Welcome to qsdbg. Debugger commands start with a . (period)\n");
+ fprintf(stdout, "*** Any other input will be evaluated by the script interpreter.\n");
+ fprintf(stdout, "*** Type .help for help.\n\n");
+
+ ScriptDebugger *dbg = new ScriptDebugger(&engine);
+ dbg->breakAtNextStatement();
+
+ engine.evaluate(code, fileName);
+
+ return 0;
+}
diff --git a/examples/script/qsdbg/qsdbg.pri b/examples/script/qsdbg/qsdbg.pri
new file mode 100644
index 0000000000..618e623e6a
--- /dev/null
+++ b/examples/script/qsdbg/qsdbg.pri
@@ -0,0 +1,9 @@
+SOURCES += \
+ $$PWD/scriptdebugger.cpp \
+ $$PWD/scriptbreakpointmanager.cpp
+
+HEADERS += \
+ $$PWD/scriptdebugger.h \
+ $$PWD/scriptbreakpointmanager.h
+
+INCLUDEPATH += $$PWD
diff --git a/examples/script/qsdbg/qsdbg.pro b/examples/script/qsdbg/qsdbg.pro
new file mode 100644
index 0000000000..77b55a2c96
--- /dev/null
+++ b/examples/script/qsdbg/qsdbg.pro
@@ -0,0 +1,21 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += script
+win32: CONFIG += console
+mac: CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+include(qsdbg.pri)
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/qsdbg
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qsdbg.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/qsdbg
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+
diff --git a/examples/script/qsdbg/scriptbreakpointmanager.cpp b/examples/script/qsdbg/scriptbreakpointmanager.cpp
new file mode 100644
index 0000000000..7668d7bcb8
--- /dev/null
+++ b/examples/script/qsdbg/scriptbreakpointmanager.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "scriptbreakpointmanager.h"
+
+ScriptBreakpointManager::ScriptBreakpointManager()
+{
+}
+
+ScriptBreakpointManager::~ScriptBreakpointManager()
+{
+}
+
+bool ScriptBreakpointManager::hasBreakpoints() const
+{
+ return !breakpoints.isEmpty();
+}
+
+int ScriptBreakpointManager::setBreakpoint(const QString &fileName, int lineNumber)
+{
+ breakpoints.append(ScriptBreakpointInfo(fileName, lineNumber));
+ return breakpoints.size() - 1;
+}
+
+int ScriptBreakpointManager::setBreakpoint(const QString &functionName, const QString &fileName)
+{
+ breakpoints.append(ScriptBreakpointInfo(functionName, fileName));
+ return breakpoints.size() - 1;
+}
+
+int ScriptBreakpointManager::setBreakpoint(const QScriptValue &function)
+{
+ breakpoints.append(ScriptBreakpointInfo(function));
+ return breakpoints.size() - 1;
+}
+
+void ScriptBreakpointManager::removeBreakpoint(int id)
+{
+ if (id >= 0 && id < breakpoints.size())
+ breakpoints[id] = ScriptBreakpointInfo();
+}
+
+int ScriptBreakpointManager::findBreakpoint(const QString &fileName, int lineNumber) const
+{
+ for (int i = 0; i < breakpoints.size(); ++i) {
+ const ScriptBreakpointInfo &brk = breakpoints.at(i);
+ if (brk.type != ScriptBreakpointInfo::File)
+ continue;
+ if (brk.fileName == fileName && brk.lineNumber == lineNumber)
+ return i;
+ }
+ return -1;
+}
+
+int ScriptBreakpointManager::findBreakpoint(const QString &functionName, const QString &fileName) const
+{
+ for (int i = 0; i < breakpoints.size(); ++i) {
+ const ScriptBreakpointInfo &brk = breakpoints.at(i);
+ if (brk.type != ScriptBreakpointInfo::FunctionName)
+ continue;
+ if (brk.functionName == functionName && brk.fileName == fileName)
+ return i;
+ }
+ return -1;
+}
+
+int ScriptBreakpointManager::findBreakpoint(const QScriptValue &function) const
+{
+ for (int i = 0; i < breakpoints.size(); ++i) {
+ const ScriptBreakpointInfo &brk = breakpoints.at(i);
+ if (brk.type != ScriptBreakpointInfo::Function)
+ continue;
+ if (brk.function.strictlyEquals(function))
+ return i;
+ }
+ return -1;
+}
+
+bool ScriptBreakpointManager::isBreakpointEnabled(int id) const
+{
+ return breakpoints.value(id).enabled;
+}
+
+void ScriptBreakpointManager::setBreakpointEnabled(int id, bool enabled)
+{
+ if (id >= 0 && id < breakpoints.size())
+ breakpoints[id].enabled = enabled;
+}
+
+QString ScriptBreakpointManager::breakpointCondition(int id) const
+{
+ return breakpoints.value(id).condition;
+}
+
+void ScriptBreakpointManager::setBreakpointCondition(int id, const QString &expression)
+{
+ if (id >= 0 && id < breakpoints.size())
+ breakpoints[id].condition = expression;
+}
+
+int ScriptBreakpointManager::breakpointIgnoreCount(int id) const
+{
+ return breakpoints.value(id).ignoreCount;
+}
+
+void ScriptBreakpointManager::setBreakpointIgnoreCount(int id, int ignoreCount)
+{
+ if (id >= 0 && id < breakpoints.size())
+ breakpoints[id].ignoreCount = ignoreCount;
+}
+
+bool ScriptBreakpointManager::isBreakpointSingleShot(int id) const
+{
+ return breakpoints.value(id).singleShot;
+}
+
+void ScriptBreakpointManager::setBreakpointSingleShot(int id, bool singleShot)
+{
+ if (id >= 0 && id < breakpoints.size())
+ breakpoints[id].singleShot = singleShot;
+}
diff --git a/examples/script/qsdbg/scriptbreakpointmanager.h b/examples/script/qsdbg/scriptbreakpointmanager.h
new file mode 100644
index 0000000000..cdb176c7b5
--- /dev/null
+++ b/examples/script/qsdbg/scriptbreakpointmanager.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCRIPTBREAKPOINTMANAGER_H
+#define SCRIPTBREAKPOINTMANAGER_H
+
+#include <QtCore/qlist.h>
+#include <QtCore/qstring.h>
+#include <QtScript/qscriptvalue.h>
+
+class ScriptBreakpointInfo
+{
+public:
+ enum Type {
+ File,
+ FunctionName,
+ Function,
+ Invalid
+ };
+
+ Type type;
+ QString functionName;
+ QString fileName;
+ int lineNumber;
+ QScriptValue function;
+ bool enabled;
+ QString condition;
+ int ignoreCount;
+ bool singleShot;
+
+ ScriptBreakpointInfo(const QString &fileName, int lineNumber)
+ : type(File), fileName(fileName), lineNumber(lineNumber),
+ enabled(true), ignoreCount(0), singleShot(false)
+ { }
+ ScriptBreakpointInfo(const QString &functionName, const QString &fileName = QString())
+ : type(FunctionName), functionName(functionName), fileName(fileName),
+ enabled(true), ignoreCount(0), singleShot(false)
+ { }
+ ScriptBreakpointInfo(const QScriptValue &function)
+ : type(Function), function(function),
+ enabled(true), ignoreCount(0), singleShot(false)
+ { }
+ ScriptBreakpointInfo()
+ : type(Invalid)
+ { }
+};
+
+class ScriptBreakpointManager
+{
+public:
+ ScriptBreakpointManager();
+ ~ScriptBreakpointManager();
+
+ bool hasBreakpoints() const;
+
+ int setBreakpoint(const QString &fileName, int lineNumber);
+ int setBreakpoint(const QString &functionName, const QString &fileName = QString());
+ int setBreakpoint(const QScriptValue &function);
+
+ void removeBreakpoint(int id);
+
+ int findBreakpoint(const QString &fileName, int lineNumber) const;
+ int findBreakpoint(const QString &functionName, const QString &fileName = QString()) const;
+ int findBreakpoint(const QScriptValue &function) const;
+
+ bool isBreakpointEnabled(int id) const;
+ void setBreakpointEnabled(int id, bool enabled);
+
+ QString breakpointCondition(int id) const;
+ void setBreakpointCondition(int id, const QString &expression);
+
+ int breakpointIgnoreCount(int id) const;
+ void setBreakpointIgnoreCount(int id, int ignoreCount);
+
+ bool isBreakpointSingleShot(int id) const;
+ void setBreakpointSingleShot(int id, bool singleShot);
+
+private:
+ QList<ScriptBreakpointInfo> breakpoints;
+
+ Q_DISABLE_COPY(ScriptBreakpointManager)
+};
+
+#endif // SCRIPTBREAKPOINTMANAGER_H
diff --git a/examples/script/qsdbg/scriptdebugger.cpp b/examples/script/qsdbg/scriptdebugger.cpp
new file mode 100644
index 0000000000..e3639b93bc
--- /dev/null
+++ b/examples/script/qsdbg/scriptdebugger.cpp
@@ -0,0 +1,737 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "scriptdebugger.h"
+#include "scriptbreakpointmanager.h"
+
+#include <QtScript/QScriptEngine>
+#include <QtScript/QScriptEngineAgent>
+#include <QtScript/QScriptContextInfo>
+#include <QtScript/QScriptValueIterator>
+#include <QtCore/QTextStream>
+#include <QtCore/QStack>
+
+static QString safeValueToString(const QScriptValue &value)
+{
+ if (value.isObject())
+ return QLatin1String("[object Object]");
+ else
+ return value.toString();
+}
+
+class ScriptInfo;
+class ScriptBreakpointManager;
+
+class ScriptDebuggerPrivate
+ : public QScriptEngineAgent
+{
+ Q_DECLARE_PUBLIC(ScriptDebugger)
+public:
+ enum Mode {
+ Run,
+ StepInto,
+ StepOver
+ };
+
+ ScriptDebuggerPrivate(QScriptEngine *engine);
+ ~ScriptDebuggerPrivate();
+
+ // QScriptEngineAgent interface
+ void scriptLoad(qint64 id, const QString &program,
+ const QString &fileName, int lineNumber);
+ void scriptUnload(qint64 id);
+
+ void positionChange(qint64 scriptId,
+ int lineNumber, int columnNumber);
+
+ void functionEntry(qint64 scriptId);
+ void functionExit(qint64 scriptId,
+ const QScriptValue &returnValue);
+
+ void exceptionThrow(qint64 scriptId,
+ const QScriptValue &exception, bool hasHandler);
+
+
+ void interactive();
+ bool executeCommand(const QString &command, const QStringList &args);
+
+ void setMode(Mode mode);
+ Mode mode() const;
+
+ int frameCount() const;
+ void setCurrentFrameIndex(int index);
+ int currentFrameIndex() const;
+
+ QScriptContext *frameContext(int index) const;
+ QScriptContext *currentFrameContext() const;
+
+ ScriptInfo *scriptInfo(QScriptContext *context) const;
+
+ int listLineNumber() const;
+ void setListLineNumber(int lineNumber);
+
+ QString readLine();
+ void output(const QString &text);
+ void message(const QString &text);
+ void errorMessage(const QString &text);
+
+ // attributes
+ QTextStream *m_defaultInputStream;
+ QTextStream *m_defaultOutputStream;
+ QTextStream *m_defaultErrorStream;
+ QTextStream *m_inputStream;
+ QTextStream *m_outputStream;
+ QTextStream *m_errorStream;
+
+ ScriptBreakpointManager *m_bpManager;
+ Mode m_mode;
+ QMap<qint64, ScriptInfo*> m_scripts;
+ QMap<QScriptContext*, QStack<qint64> > m_contextProgramIds;
+
+ QString m_lastInteractiveCommand;
+ QString m_commandPrefix;
+ int m_stepDepth;
+ int m_currentFrameIndex;
+ int m_listLineNumber;
+
+ ScriptDebugger *q_ptr;
+};
+
+class ScriptInfo
+{
+public:
+ ScriptInfo(const QString &code, const QString &fileName, int lineNumber)
+ : m_code(code), m_fileName(fileName), m_lineNumber(lineNumber)
+ { }
+
+ inline QString code() const
+ { return m_code; }
+ inline QString fileName() const
+ { return m_fileName; }
+ inline int lineNumber() const
+ { return m_lineNumber; }
+
+ QString lineText(int lineNumber);
+ QMap<int, int> m_lineOffsets;
+
+private:
+ int lineOffset(int lineNumber);
+
+ QString m_code;
+ QString m_fileName;
+ int m_lineNumber;
+};
+
+int ScriptInfo::lineOffset(int lineNumber)
+{
+ QMap<int, int>::const_iterator it = m_lineOffsets.constFind(lineNumber);
+ if (it != m_lineOffsets.constEnd())
+ return it.value();
+
+ int offset;
+ it = m_lineOffsets.constFind(lineNumber - 1);
+ if (it != m_lineOffsets.constEnd()) {
+ offset = it.value();
+ offset = m_code.indexOf(QLatin1Char('\n'), offset);
+ if (offset != -1)
+ ++offset;
+ m_lineOffsets.insert(lineNumber, offset);
+ } else {
+ int index;
+ it = m_lineOffsets.lowerBound(lineNumber);
+ --it;
+ if (it != m_lineOffsets.constBegin()) {
+ index = it.key();
+ offset = it.value();
+ } else {
+ index = m_lineNumber;
+ offset = 0;
+ }
+ int j = index;
+ for ( ; j < lineNumber; ++j) {
+ m_lineOffsets.insert(j, offset);
+ offset = m_code.indexOf(QLatin1Char('\n'), offset);
+ if (offset == -1)
+ break;
+ ++offset;
+ }
+ m_lineOffsets.insert(j, offset);
+ }
+ return offset;
+}
+
+QString ScriptInfo::lineText(int lineNumber)
+{
+ int startOffset = lineOffset(lineNumber);
+ if (startOffset == -1)
+ return QString();
+ int endOffset = lineOffset(lineNumber + 1);
+ if (endOffset == -1)
+ return m_code.mid(startOffset);
+ else
+ return m_code.mid(startOffset, endOffset - startOffset - 1);
+}
+
+
+
+ScriptDebuggerPrivate::ScriptDebuggerPrivate(QScriptEngine *engine)
+ : QScriptEngineAgent(engine), m_mode(Run)
+{
+ m_commandPrefix = QLatin1String(".");
+ m_bpManager = new ScriptBreakpointManager;
+ m_defaultInputStream = new QTextStream(stdin);
+ m_defaultOutputStream = new QTextStream(stdout);
+ m_defaultErrorStream = new QTextStream(stderr);
+ m_inputStream = m_defaultInputStream;
+ m_outputStream = m_defaultOutputStream;
+ m_errorStream = m_defaultErrorStream;
+}
+
+ScriptDebuggerPrivate::~ScriptDebuggerPrivate()
+{
+ delete m_defaultInputStream;
+ delete m_defaultOutputStream;
+ delete m_defaultErrorStream;
+ delete m_bpManager;
+ qDeleteAll(m_scripts);
+}
+
+QString ScriptDebuggerPrivate::readLine()
+{
+ return m_inputStream->readLine();
+}
+
+void ScriptDebuggerPrivate::output(const QString &text)
+{
+ *m_outputStream << text;
+}
+
+void ScriptDebuggerPrivate::message(const QString &text)
+{
+ *m_outputStream << text << endl;
+ m_outputStream->flush();
+}
+
+void ScriptDebuggerPrivate::errorMessage(const QString &text)
+{
+ *m_errorStream << text << endl;
+ m_errorStream->flush();
+}
+
+void ScriptDebuggerPrivate::setMode(Mode mode)
+{
+ m_mode = mode;
+}
+
+ScriptDebuggerPrivate::Mode ScriptDebuggerPrivate::mode() const
+{
+ return m_mode;
+}
+
+QScriptContext *ScriptDebuggerPrivate::frameContext(int index) const
+{
+ QScriptContext *ctx = engine()->currentContext();
+ for (int i = 0; i < index; ++i) {
+ ctx = ctx->parentContext();
+ if (!ctx)
+ break;
+ }
+ return ctx;
+}
+
+int ScriptDebuggerPrivate::currentFrameIndex() const
+{
+ return m_currentFrameIndex;
+}
+
+void ScriptDebuggerPrivate::setCurrentFrameIndex(int index)
+{
+ m_currentFrameIndex = index;
+ m_listLineNumber = -1;
+}
+
+int ScriptDebuggerPrivate::listLineNumber() const
+{
+ return m_listLineNumber;
+}
+
+void ScriptDebuggerPrivate::setListLineNumber(int lineNumber)
+{
+ m_listLineNumber = lineNumber;
+}
+
+QScriptContext *ScriptDebuggerPrivate::currentFrameContext() const
+{
+ return frameContext(currentFrameIndex());
+}
+
+int ScriptDebuggerPrivate::frameCount() const
+{
+ int count = 0;
+ QScriptContext *ctx = engine()->currentContext();
+ while (ctx) {
+ ++count;
+ ctx = ctx->parentContext();
+ }
+ return count;
+}
+
+ScriptInfo *ScriptDebuggerPrivate::scriptInfo(QScriptContext *context) const
+{
+ QStack<qint64> pids = m_contextProgramIds.value(context);
+ if (pids.isEmpty())
+ return 0;
+ return m_scripts.value(pids.top());
+}
+
+void ScriptDebuggerPrivate::interactive()
+{
+ setCurrentFrameIndex(0);
+
+ QString qsdbgPrompt = QString::fromLatin1("(qsdbg) ");
+ QString dotPrompt = QString::fromLatin1(".... ");
+ QString prompt = qsdbgPrompt;
+
+ QString code;
+
+ forever {
+
+ *m_outputStream << prompt;
+ m_outputStream->flush();
+
+ QString line = readLine();
+
+ if (code.isEmpty() && (line.isEmpty() || line.startsWith(m_commandPrefix))) {
+ if (line.isEmpty())
+ line = m_lastInteractiveCommand;
+ else
+ m_lastInteractiveCommand = line;
+
+ QStringList parts = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ if (!parts.isEmpty()) {
+ QString command = parts.takeFirst().mid(1);
+ if (executeCommand(command, parts))
+ break;
+ }
+
+ } else {
+ if (line.isEmpty())
+ continue;
+
+ code += line;
+ code += QLatin1Char('\n');
+
+ if (line.trimmed().isEmpty()) {
+ continue;
+
+ } else if (! engine()->canEvaluate(code)) {
+ prompt = dotPrompt;
+
+ } else {
+ setMode(Run);
+ QScriptValue result = engine()->evaluate(code, QLatin1String("typein"));
+
+ code.clear();
+ prompt = qsdbgPrompt;
+
+ if (! result.isUndefined()) {
+ errorMessage(result.toString());
+ engine()->clearExceptions();
+ }
+ }
+ }
+ }
+}
+
+bool ScriptDebuggerPrivate::executeCommand(const QString &command, const QStringList &args)
+{
+ if (command == QLatin1String("c")
+ || command == QLatin1String("continue")) {
+ setMode(Run);
+ return true;
+ } else if (command == QLatin1String("s")
+ || command == QLatin1String("step")) {
+ setMode(StepInto);
+ return true;
+ } else if (command == QLatin1String("n")
+ || command == QLatin1String("next")) {
+ setMode(StepOver);
+ m_stepDepth = 0;
+ return true;
+ } else if (command == QLatin1String("f")
+ || command == QLatin1String("frame")) {
+ bool ok = false;
+ int index = args.value(0).toInt(&ok);
+ if (ok) {
+ if (index < 0 || index >= frameCount()) {
+ errorMessage("No such frame.");
+ } else {
+ setCurrentFrameIndex(index);
+ QScriptContext *ctx = currentFrameContext();
+ message(QString::fromLatin1("#%0 %1").arg(index).arg(ctx->toString()));
+ }
+ }
+ } else if (command == QLatin1String("bt")
+ || command == QLatin1String("backtrace")) {
+ QScriptContext *ctx = engine()->currentContext();
+ int index = -1;
+ while (ctx) {
+ ++index;
+ QString line = ctx->toString();
+ message(QString::fromLatin1("#%0 %1").arg(index).arg(line));
+ ctx = ctx->parentContext();
+ }
+ } else if (command == QLatin1String("up")) {
+ int index = currentFrameIndex() + 1;
+ if (index == frameCount()) {
+ errorMessage(QString::fromLatin1("Initial frame selected; you cannot go up."));
+ } else {
+ setCurrentFrameIndex(index);
+ QScriptContext *ctx = currentFrameContext();
+ message(QString::fromLatin1("#%0 %1").arg(index).arg(ctx->toString()));
+ }
+ } else if (command == QLatin1String("down")) {
+ int index = currentFrameIndex() - 1;
+ if (index < 0) {
+ errorMessage(QString::fromLatin1("Bottom (innermost) frame selected; you cannot go down."));
+ } else {
+ setCurrentFrameIndex(index);
+ QScriptContext *ctx = currentFrameContext();
+ message(QString::fromLatin1("#%0 %1").arg(index).arg(ctx->toString()));
+ }
+ } else if (command == QLatin1String("b")
+ || command == QLatin1String("break")) {
+ QString str = args.value(0);
+ int colonIndex = str.indexOf(QLatin1Char(':'));
+ if (colonIndex != -1) {
+ // filename:line form
+ QString fileName = str.left(colonIndex);
+ int lineNumber = str.mid(colonIndex+1).toInt();
+ int id = m_bpManager->setBreakpoint(fileName, lineNumber);
+ message(QString::fromLatin1("Breakpoint %0 at %1, line %2.").arg(id+1).arg(fileName).arg(lineNumber));
+ } else {
+ // function
+ QScriptValue fun = engine()->globalObject().property(str);
+ if (fun.isFunction()) {
+ int id = m_bpManager->setBreakpoint(fun);
+ message(QString::fromLatin1("Breakpoint %0 at %1().").arg(id+1).arg(str));
+ }
+ }
+ } else if (command == QLatin1String("d")
+ || command == QLatin1String("delete")) {
+ int id = args.value(0).toInt() - 1;
+ m_bpManager->removeBreakpoint(id);
+ } else if (command == QLatin1String("disable")) {
+ int id = args.value(0).toInt() - 1;
+ m_bpManager->setBreakpointEnabled(id, false);
+ } else if (command == QLatin1String("enable")) {
+ int id = args.value(0).toInt() - 1;
+ m_bpManager->setBreakpointEnabled(id, true);
+ } else if (command == QLatin1String("list")) {
+ QScriptContext *ctx = currentFrameContext();
+ ScriptInfo *progInfo = scriptInfo(ctx);
+ if (!progInfo) {
+ errorMessage("No source text available for this frame.");
+ } else {
+ QScriptContextInfo ctxInfo(ctx);
+ bool ok;
+ int line = args.value(0).toInt(&ok);
+ if (ok) {
+ line = qMax(1, line - 5);
+ } else {
+ line = listLineNumber();
+ if (line == -1)
+ line = qMax(progInfo->lineNumber(), ctxInfo.lineNumber() - 5);
+ }
+ for (int i = line; i < line + 10; ++i) {
+ message(QString::fromLatin1("%0\t%1").arg(i).arg(progInfo->lineText(i)));
+ }
+ setListLineNumber(line + 10);
+ }
+ } else if (command == QLatin1String("info")) {
+ if (args.size() < 1) {
+ } else {
+ QString what = args.value(0);
+ if (what == QLatin1String("locals")) {
+ QScriptValueIterator it(currentFrameContext()->activationObject());
+ while (it.hasNext()) {
+ it.next();
+ QString line;
+ line.append(it.name());
+ line.append(QLatin1String(" = "));
+ line.append(safeValueToString(it.value()));
+ message(line);
+ }
+ }
+ }
+ } else if (command == QLatin1String("help")) {
+ message("continue - continue execution\n"
+ "step - step into statement\n"
+ "next - step over statement\n"
+ "list - show where you are\n"
+ "\n"
+ "break - set breakpoint\n"
+ "delete - remove breakpoint\n"
+ "disable - disable breakpoint\n"
+ "enable - enable breakpoint\n"
+ "\n"
+ "backtrace - show backtrace\n"
+ "up - one frame up\n"
+ "down - one frame down\n"
+ "frame - set frame\n"
+ "\n"
+ "info locals - show local variables");
+ } else {
+ errorMessage(QString::fromLatin1("Undefined command \"%0\". Try \"help\".")
+ .arg(command));
+ }
+
+ return false;
+}
+
+
+// QScriptEngineAgent interface
+
+void ScriptDebuggerPrivate::scriptLoad(qint64 id, const QString &program,
+ const QString &fileName, int lineNumber)
+{
+ ScriptInfo *info = new ScriptInfo(program, fileName, lineNumber);
+ m_scripts.insert(id, info);
+}
+
+void ScriptDebuggerPrivate::scriptUnload(qint64 id)
+{
+ ScriptInfo *info = m_scripts.take(id);
+ delete info;
+}
+
+void ScriptDebuggerPrivate::functionEntry(qint64 scriptId)
+{
+ if (scriptId != -1) {
+ QScriptContext *ctx = engine()->currentContext();
+ QStack<qint64> ids = m_contextProgramIds.value(ctx);
+ ids.push(scriptId);
+ m_contextProgramIds.insert(ctx, ids);
+ }
+
+ if (mode() == StepOver)
+ ++m_stepDepth;
+}
+
+void ScriptDebuggerPrivate::functionExit(qint64 scriptId,
+ const QScriptValue &/*returnValue*/)
+{
+ if (scriptId != -1) {
+ QScriptContext *ctx = engine()->currentContext();
+ QStack<qint64> ids = m_contextProgramIds.value(ctx);
+ Q_ASSERT(!ids.isEmpty());
+ Q_ASSERT(ids.top() == scriptId);
+ ids.pop();
+ m_contextProgramIds.insert(ctx, ids);
+ }
+
+ if (mode() == StepOver)
+ --m_stepDepth;
+}
+
+void ScriptDebuggerPrivate::positionChange(qint64 scriptId,
+ int lineNumber, int /*columnNumber*/)
+{
+ ScriptInfo *info = 0;
+ bool enterInteractiveMode = false;
+
+ if (m_bpManager->hasBreakpoints()) {
+ // check if we hit a breakpoint
+ info = m_scripts.value(scriptId);
+ QScriptContext *ctx = engine()->currentContext();
+ QScriptContextInfo ctxInfo(ctx);
+ QScriptValue callee = ctx->callee();
+
+ // try fileName:lineNumber
+ int bpid = m_bpManager->findBreakpoint(info->fileName(), lineNumber);
+ if ((bpid != -1) && m_bpManager->isBreakpointEnabled(bpid)) {
+ message(QString::fromLatin1("Breakpoint %0 at %1:%2")
+ .arg(bpid + 1).arg(info->fileName()).arg(lineNumber));
+ if (m_bpManager->isBreakpointSingleShot(bpid))
+ m_bpManager->removeBreakpoint(bpid);
+ }
+ if (bpid == -1) {
+ // try function
+ bpid = m_bpManager->findBreakpoint(callee);
+ if ((bpid != -1) && m_bpManager->isBreakpointEnabled(bpid)) {
+ message(QString::fromLatin1("Breakpoint %0, %1()")
+ .arg(bpid + 1).arg(ctxInfo.functionName()));
+ if (m_bpManager->isBreakpointSingleShot(bpid))
+ m_bpManager->removeBreakpoint(bpid);
+ }
+ }
+ if ((bpid == -1) && !ctxInfo.functionName().isEmpty()) {
+ // try functionName:fileName
+ bpid = m_bpManager->findBreakpoint(ctxInfo.functionName(), ctxInfo.fileName());
+ if ((bpid != -1) && m_bpManager->isBreakpointEnabled(bpid)) {
+ message(QString::fromLatin1("Breakpoint %0, %1():%2").arg(bpid + 1)
+ .arg(ctxInfo.functionName()).arg(ctxInfo.fileName()));
+ if (m_bpManager->isBreakpointSingleShot(bpid))
+ m_bpManager->removeBreakpoint(bpid);
+ }
+ }
+
+ enterInteractiveMode = (bpid != -1);
+ }
+
+ switch (mode()) {
+ case Run:
+ break;
+
+ case StepInto:
+ enterInteractiveMode = true;
+ break;
+
+ case StepOver:
+ enterInteractiveMode = enterInteractiveMode || (m_stepDepth <= 0);
+ break;
+ }
+
+ if (enterInteractiveMode) {
+ if (!info)
+ info = m_scripts.value(scriptId);
+ Q_ASSERT(info);
+ message(QString::fromLatin1("%0\t%1").arg(lineNumber).arg(info->lineText(lineNumber)));
+ interactive();
+ }
+}
+
+void ScriptDebuggerPrivate::exceptionThrow(qint64 /*scriptId*/,
+ const QScriptValue &exception,
+ bool hasHandler)
+{
+ if (!hasHandler) {
+ errorMessage(QString::fromLatin1("uncaught exception: %0").arg(exception.toString()));
+ QScriptContext *ctx = engine()->currentContext();
+ int lineNumber = QScriptContextInfo(ctx).lineNumber();
+ ScriptInfo *info = scriptInfo(ctx);
+ QString lineText = info ? info->lineText(lineNumber) : QString("(no source text available)");
+ message(QString::fromLatin1("%0\t%1").arg(lineNumber).arg(lineText));
+ interactive();
+ }
+}
+
+
+
+ScriptDebugger::ScriptDebugger(QScriptEngine *engine)
+ : d_ptr(new ScriptDebuggerPrivate(engine))
+{
+ d_ptr->q_ptr = this;
+ engine->setAgent(d_ptr);
+}
+
+ScriptDebugger::ScriptDebugger(QScriptEngine *engine, ScriptDebuggerPrivate &dd)
+ : d_ptr(&dd)
+{
+ d_ptr->q_ptr = this;
+ engine->setAgent(d_ptr);
+}
+
+ScriptDebugger::~ScriptDebugger()
+{
+ delete d_ptr;
+ d_ptr = 0;
+}
+
+void ScriptDebugger::breakAtNextStatement()
+{
+ Q_D(ScriptDebugger);
+ d->setMode(ScriptDebuggerPrivate::StepInto);
+}
+
+void ScriptDebugger::setBreakpoint(const QString &fileName, int lineNumber)
+{
+ Q_D(ScriptDebugger);
+ d->m_bpManager->setBreakpoint(fileName, lineNumber);
+}
+
+void ScriptDebugger::setBreakpoint(const QString &functionName, const QString &fileName)
+{
+ Q_D(ScriptDebugger);
+ d->m_bpManager->setBreakpoint(functionName, fileName);
+}
+
+void ScriptDebugger::setBreakpoint(const QScriptValue &function)
+{
+ Q_D(ScriptDebugger);
+ d->m_bpManager->setBreakpoint(function);
+}
+
+QTextStream *ScriptDebugger::inputStream() const
+{
+ Q_D(const ScriptDebugger);
+ return d->m_inputStream;
+}
+
+void ScriptDebugger::setInputStream(QTextStream *inputStream)
+{
+ Q_D(ScriptDebugger);
+ d->m_inputStream = inputStream;
+}
+
+QTextStream *ScriptDebugger::outputStream() const
+{
+ Q_D(const ScriptDebugger);
+ return d->m_outputStream;
+}
+
+void ScriptDebugger::setOutputStream(QTextStream *outputStream)
+{
+ Q_D(ScriptDebugger);
+ d->m_outputStream = outputStream;
+}
+
+QTextStream *ScriptDebugger::errorStream() const
+{
+ Q_D(const ScriptDebugger);
+ return d->m_errorStream;
+}
+
+void ScriptDebugger::setErrorStream(QTextStream *errorStream)
+{
+ Q_D(ScriptDebugger);
+ d->m_errorStream = errorStream;
+}
diff --git a/examples/script/qsdbg/scriptdebugger.h b/examples/script/qsdbg/scriptdebugger.h
new file mode 100644
index 0000000000..c33adf65c7
--- /dev/null
+++ b/examples/script/qsdbg/scriptdebugger.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCRIPTDEBUGGER_H
+#define SCRIPTDEBUGGER_H
+
+#include <QtCore/qlist.h>
+#include <QtCore/qstring.h>
+
+QT_BEGIN_NAMESPACE
+class QScriptEngine;
+class QScriptValue;
+class QTextStream;
+QT_END_NAMESPACE
+
+class ScriptDebuggerPrivate;
+class ScriptDebugger
+{
+public:
+ ScriptDebugger(QScriptEngine *engine);
+ virtual ~ScriptDebugger();
+
+ void breakAtNextStatement();
+
+ void setBreakpoint(const QString &fileName, int lineNumber);
+ void setBreakpoint(const QString &functionName, const QString &fileName = QString());
+ void setBreakpoint(const QScriptValue &function);
+
+ QTextStream *inputStream() const;
+ void setInputStream(QTextStream *inputStream);
+
+ QTextStream *outputStream() const;
+ void setOutputStream(QTextStream *outputStream);
+
+ QTextStream *errorStream() const;
+ void setErrorStream(QTextStream *errorStream);
+
+protected:
+ ScriptDebugger(QScriptEngine *engine, ScriptDebuggerPrivate &dd);
+ ScriptDebuggerPrivate *d_ptr;
+
+private:
+ Q_DECLARE_PRIVATE(ScriptDebugger)
+ Q_DISABLE_COPY(ScriptDebugger)
+};
+
+#endif // SCRIPTDEBUGGER_H
diff --git a/examples/script/qstetrix/main.cpp b/examples/script/qstetrix/main.cpp
new file mode 100644
index 0000000000..6d7af45ec9
--- /dev/null
+++ b/examples/script/qstetrix/main.cpp
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tetrixboard.h"
+
+#include <QtGui>
+#include <QtScript>
+#include <QUiLoader>
+
+#ifndef QT_NO_SCRIPTTOOLS
+#include <QtScriptTools>
+#endif
+
+struct QtMetaObject : private QObject
+{
+public:
+ static const QMetaObject *get()
+ { return &static_cast<QtMetaObject*>(0)->staticQtMetaObject; }
+};
+
+//! [0]
+class TetrixUiLoader : public QUiLoader
+{
+public:
+ TetrixUiLoader(QObject *parent = 0)
+ : QUiLoader(parent)
+ { }
+ virtual QWidget *createWidget(const QString &className, QWidget *parent = 0,
+ const QString &name = QString())
+ {
+ if (className == QLatin1String("TetrixBoard")) {
+ QWidget *board = new TetrixBoard(parent);
+ board->setObjectName(name);
+ return board;
+ }
+ return QUiLoader::createWidget(className, parent, name);
+ }
+};
+//! [0]
+
+static QScriptValue evaluateFile(QScriptEngine &engine, const QString &fileName)
+{
+ QFile file(fileName);
+ file.open(QIODevice::ReadOnly);
+ return engine.evaluate(file.readAll(), fileName);
+}
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(tetrix);
+
+//! [1]
+ QApplication app(argc, argv);
+ QScriptEngine engine;
+
+ QScriptValue Qt = engine.newQMetaObject(QtMetaObject::get());
+ Qt.setProperty("App", engine.newQObject(&app));
+ engine.globalObject().setProperty("Qt", Qt);
+//! [1]
+
+#ifndef QT_NO_SCRIPTTOOLS
+ QScriptEngineDebugger debugger;
+ debugger.attachTo(&engine);
+ QMainWindow *debugWindow = debugger.standardWindow();
+ debugWindow->resize(1024, 640);
+#endif
+
+//! [2]
+ evaluateFile(engine, ":/tetrixpiece.js");
+ evaluateFile(engine, ":/tetrixboard.js");
+ evaluateFile(engine, ":/tetrixwindow.js");
+//! [2]
+
+//! [3]
+ TetrixUiLoader loader;
+ QFile uiFile(":/tetrixwindow.ui");
+ uiFile.open(QIODevice::ReadOnly);
+ QWidget *ui = loader.load(&uiFile);
+ uiFile.close();
+
+ QScriptValue ctor = engine.evaluate("TetrixWindow");
+ QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
+ QScriptValue tetrix = ctor.construct(QScriptValueList() << scriptUi);
+//! [3]
+
+ QPushButton *debugButton = qFindChild<QPushButton*>(ui, "debugButton");
+#ifndef QT_NO_SCRIPTTOOLS
+ QObject::connect(debugButton, SIGNAL(clicked()),
+ debugger.action(QScriptEngineDebugger::InterruptAction),
+ SIGNAL(triggered()));
+ QObject::connect(debugButton, SIGNAL(clicked()),
+ debugWindow, SLOT(show()));
+#else
+ debugButton->hide();
+#endif
+
+//! [4]
+ ui->resize(550, 370);
+ ui->show();
+
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ return app.exec();
+//! [4]
+}
diff --git a/examples/script/qstetrix/qstetrix.pro b/examples/script/qstetrix/qstetrix.pro
new file mode 100644
index 0000000000..3db66ab26b
--- /dev/null
+++ b/examples/script/qstetrix/qstetrix.pro
@@ -0,0 +1,17 @@
+QT += script
+CONFIG += uitools
+
+HEADERS = tetrixboard.h
+SOURCES = main.cpp \
+ tetrixboard.cpp
+
+FORMS = tetrixwindow.ui
+RESOURCES = tetrix.qrc
+
+contains(QT_CONFIG, scripttools): QT += scripttools
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script/qstetrix
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qstetrix.pro *.js
+sources.path = $$[QT_INSTALL_EXAMPLES]/script/qstetrix
+INSTALLS += target sources
diff --git a/examples/script/qstetrix/tetrix.qrc b/examples/script/qstetrix/tetrix.qrc
new file mode 100644
index 0000000000..58d085aacf
--- /dev/null
+++ b/examples/script/qstetrix/tetrix.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>tetrixwindow.js</file>
+ <file>tetrixwindow.ui</file>
+ <file>tetrixboard.js</file>
+ <file>tetrixpiece.js</file>
+ </qresource>
+</RCC>
diff --git a/examples/script/qstetrix/tetrixboard.cpp b/examples/script/qstetrix/tetrixboard.cpp
new file mode 100644
index 0000000000..55c4d3c08a
--- /dev/null
+++ b/examples/script/qstetrix/tetrixboard.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tetrixboard.h"
+
+#include <QtGui>
+
+Q_DECLARE_METATYPE(QPainter*)
+
+TetrixBoard::TetrixBoard(QWidget *parent)
+ : QFrame(parent)
+{
+ timer = new QTimer(this);
+ qMetaTypeId<QPainter*>();
+}
+
+void TetrixBoard::setNextPieceLabel(QWidget *label)
+{
+ nextPieceLabel = qobject_cast<QLabel*>(label);
+}
+
+QObject *TetrixBoard::getTimer()
+{
+ return timer;
+}
+
+QSize TetrixBoard::minimumSizeHint() const
+{
+ return QSize(BoardWidth * 5 + frameWidth() * 2,
+ BoardHeight * 5 + frameWidth() * 2);
+}
+
+void TetrixBoard::paintEvent(QPaintEvent *event)
+{
+ QFrame::paintEvent(event);
+ QPainter painter(this);
+ painter.drawImage(0, 0, image);
+}
+
+void TetrixBoard::keyPressEvent(QKeyEvent *event)
+{
+ emit keyPressed(event->key());
+}
+
+void TetrixBoard::showNextPiece(int width, int height)
+{
+ if (!nextPieceLabel)
+ return;
+
+ QPixmap pixmap(width * squareWidth(), height * squareHeight());
+ QPainter painter(&pixmap);
+ painter.fillRect(pixmap.rect(), nextPieceLabel->palette().background());
+
+ emit paintNextPieceRequested(&painter);
+
+ nextPieceLabel->setPixmap(pixmap);
+}
+
+void TetrixBoard::drawPauseScreen(QPainter *painter)
+{
+ painter->drawText(contentsRect(), Qt::AlignCenter, tr("Pause"));
+}
+
+void TetrixBoard::drawSquare(QPainter *painter, int x, int y, int shape)
+{
+ static const QRgb colorTable[8] = {
+ 0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
+ 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00
+ };
+
+ x = x*squareWidth();
+ y = y*squareHeight();
+
+ QColor color = colorTable[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);
+}
+
+void TetrixBoard::update()
+{
+ QRect rect = contentsRect();
+ if (image.size() != rect.size())
+ image = QImage(rect.size(), QImage::Format_ARGB32_Premultiplied);
+ image.fill(qRgba(0,0,0,0));
+ QPainter painter;
+ painter.begin(&image);
+ int boardTop = rect.bottom() - BoardHeight*squareHeight();
+ painter.translate(rect.left(), boardTop);
+ emit paintRequested(&painter);
+ QFrame::update();
+}
diff --git a/examples/script/qstetrix/tetrixboard.h b/examples/script/qstetrix/tetrixboard.h
new file mode 100644
index 0000000000..e8c1016b6d
--- /dev/null
+++ b/examples/script/qstetrix/tetrixboard.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TETRIXBOARD_H
+#define TETRIXBOARD_H
+
+#include <QTimer>
+#include <QFrame>
+#include <QPointer>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+
+class TetrixBoard : public QFrame
+{
+ Q_OBJECT
+ Q_PROPERTY(QObject* timer READ getTimer)
+ Q_PROPERTY(QWidget* nextPieceLabel WRITE setNextPieceLabel)
+
+public:
+ TetrixBoard(QWidget *parent = 0);
+
+ void setNextPieceLabel(QWidget *label);
+ void setBoardWidth(int width);
+ void setBoardHeight(int height);
+ QSize minimumSizeHint() const;
+
+ QObject *getTimer();
+
+signals:
+ void scoreChanged(int score);
+ void levelChanged(int level);
+ void linesRemovedChanged(int numLines);
+
+#if !defined(Q_MOC_RUN)
+private: // can only be emitted by TetrixBoard
+#endif
+ void keyPressed(int key);
+ void paintRequested(QPainter *painter);
+ void paintNextPieceRequested(QPainter *painter);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void keyPressEvent(QKeyEvent *event);
+
+protected slots:
+ void showNextPiece(int width, int height);
+ void drawPauseScreen(QPainter *painter);
+ void drawSquare(QPainter *painter, int x, int y, int shape);
+ void update();
+
+private:
+ enum { BoardWidth = 10, BoardHeight = 22 };
+
+ int squareWidth() { return contentsRect().width() / BoardWidth; }
+ int squareHeight() { return contentsRect().height() / BoardHeight; }
+
+ QTimer *timer;
+ QPointer<QLabel> nextPieceLabel;
+ QImage image;
+};
+
+#endif
diff --git a/examples/script/qstetrix/tetrixboard.js b/examples/script/qstetrix/tetrixboard.js
new file mode 100644
index 0000000000..f19839768e
--- /dev/null
+++ b/examples/script/qstetrix/tetrixboard.js
@@ -0,0 +1,261 @@
+function TetrixBoard(ui)
+{
+ this.ui = ui;
+
+ this.isStarted = false;
+ this.isPaused = false;
+ this.inKeyPress = false;
+
+ this._board = new Array(TetrixBoard.BoardWidth * TetrixBoard.BoardHeight);
+ this.clearBoard();
+
+ this.curPiece = new TetrixPiece();
+ this.nextPiece = new TetrixPiece();
+ this.nextPiece.setRandomShape();
+
+ ui.timer.singleShot = true;
+ ui.timer.timeout.connect(this, this.onTimer);
+ ui.keyPressed.connect(this, this.onKeyPress);
+ ui.paintRequested.connect(this, this.onPaint);
+ ui.paintNextPieceRequested.connect(this, this.onPaintNextPiece);
+}
+
+TetrixBoard.BoardWidth = 10;
+TetrixBoard.BoardHeight = 22;
+
+TetrixBoard.prototype.start = function() {
+ if (this.isPaused)
+ return;
+
+ this.isStarted = true;
+ this.isWaitingAfterLine = false;
+ this.numLinesRemoved = 0;
+ this.numPiecesDropped = 0;
+ this.score = 0;
+ this.level = 1;
+ this.clearBoard();
+
+ this.ui.linesRemovedChanged(this.numLinesRemoved);
+ this.ui.scoreChanged(this.score);
+ this.ui.levelChanged(this.level);
+
+ this.newPiece();
+ this.ui.timer.start(this.timeoutTime());
+}
+
+TetrixBoard.prototype.pause = function() {
+ if (!this.isStarted)
+ return;
+
+ this.isPaused = !this.isPaused;
+ if (this.isPaused) {
+ this.ui.timer.stop();
+ } else {
+ this.ui.timer.start(this.timeoutTime());
+ }
+ this.ui.update();
+}
+
+TetrixBoard.prototype.getShapeAt = function(x, y) {
+ return this._board[(y * TetrixBoard.BoardWidth) + x];
+}
+
+TetrixBoard.prototype.setShapeAt = function(x, y, newShape) {
+ this._board[(y * TetrixBoard.BoardWidth) + x] = newShape;
+}
+
+TetrixBoard.prototype.clearBoard = function() {
+ for (var i = 0; i < TetrixBoard.BoardHeight * TetrixBoard.BoardWidth; ++i)
+ this._board[i] = TetrixShape.NoShape;
+}
+
+TetrixBoard.prototype.dropDown = function() {
+ var dropHeight = 0;
+ var newY = this.curY;
+ while (newY > 0) {
+ if (!this.tryMove(this.curPiece, this.curX, newY - 1))
+ break;
+ --newY;
+ ++dropHeight;
+ }
+ this.pieceDropped(dropHeight);
+}
+
+TetrixBoard.prototype.oneLineDown = function() {
+ if (!this.tryMove(this.curPiece, this.curX, this.curY - 1))
+ this.pieceDropped(0);
+}
+
+TetrixBoard.prototype.pieceDropped = function(dropHeight) {
+ for (var i = 0; i < 4; ++i) {
+ var x = this.curX + this.curPiece.getX(i);
+ var y = this.curY - this.curPiece.getY(i);
+ this.setShapeAt(x, y, this.curPiece.shape);
+ }
+
+ ++this.numPiecesDropped;
+ if ((this.numPiecesDropped % 25) == 0) {
+ ++this.level;
+ this.ui.timer.start(this.timeoutTime());
+ this.ui.levelChanged(this.level);
+ }
+
+ this.score += dropHeight + 7;
+ this.ui.scoreChanged(this.score);
+ this.removeFullLines();
+
+ if (!this.isWaitingAfterLine)
+ this.newPiece();
+
+ if (this.isStarted && !this.ui.timer.active)
+ this.ui.timer.start(this.timeoutTime());
+}
+
+TetrixBoard.prototype.removeFullLines = function() {
+ var numFullLines = 0;
+
+ for (var i = TetrixBoard.BoardHeight - 1; i >= 0; --i) {
+ var lineIsFull = true;
+
+ for (var j = 0; j < TetrixBoard.BoardWidth; ++j) {
+ if (this.getShapeAt(j, i) == TetrixShape.NoShape) {
+ lineIsFull = false;
+ break;
+ }
+ }
+
+ if (lineIsFull) {
+ ++numFullLines;
+ for (var k = i; k < TetrixBoard.BoardHeight - 1; ++k) {
+ for (var j = 0; j < TetrixBoard.BoardWidth; ++j)
+ this.setShapeAt(j, k, this.getShapeAt(j, k + 1));
+ }
+ for (var j = 0; j < TetrixBoard.BoardWidth; ++j)
+ this.setShapeAt(j, TetrixBoard.BoardHeight - 1, TetrixShape.NoShape);
+ }
+ }
+
+ if (numFullLines > 0) {
+ this.numLinesRemoved += numFullLines;
+ this.score += 10 * numFullLines;
+ this.ui.linesRemovedChanged(this.numLinesRemoved);
+ this.ui.scoreChanged(this.score);
+
+ this.ui.timer.start(500);
+ this.isWaitingAfterLine = true;
+ this.curPiece.shape = TetrixShape.NoShape;
+ this.ui.update();
+ }
+}
+
+TetrixBoard.prototype.newPiece = function() {
+ this.curPiece = this.nextPiece;
+ this.nextPiece = new TetrixPiece();
+ this.nextPiece.setRandomShape();
+ this.ui.showNextPiece(this.nextPiece.maxX - this.nextPiece.minX + 1,
+ this.nextPiece.maxY - this.nextPiece.minY + 1);
+ this.curX = TetrixBoard.BoardWidth / 2 + 1;
+ this.curY = TetrixBoard.BoardHeight - 1 + this.curPiece.minY;
+
+ if (!this.tryMove(this.curPiece, this.curX, this.curY)) {
+ this.curPiece.shape = TetrixShape.NoShape;
+ this.ui.timer.stop();
+ this.isStarted = false;
+ }
+}
+
+TetrixBoard.prototype.tryMove = function(newPiece, newX, newY) {
+ for (var i = 0; i < 4; ++i) {
+ var x = newX + newPiece.getX(i);
+ var y = newY - newPiece.getY(i);
+ if ((x < 0) || (x >= TetrixBoard.BoardWidth) || (y < 0) || (y >= TetrixBoard.BoardHeight))
+ return false;
+ if (this.getShapeAt(x, y) != TetrixShape.NoShape)
+ return false;
+ }
+
+ this.curPiece = newPiece;
+ this.curX = newX;
+ this.curY = newY;
+ this.ui.update();
+ return true;
+}
+
+TetrixBoard.prototype.onPaint = function(painter) {
+ if (this.isPaused) {
+ this.ui.drawPauseScreen(painter);
+ return;
+ }
+
+ for (var i = 0; i < TetrixBoard.BoardHeight; ++i) {
+ for (var j = 0; j < TetrixBoard.BoardWidth; ++j) {
+ var shape = this.getShapeAt(j, TetrixBoard.BoardHeight - i - 1);
+ if (shape != TetrixShape.NoShape)
+ this.ui.drawSquare(painter, j, i, shape);
+ }
+ }
+
+ if (this.curPiece.shape != TetrixShape.NoShape) {
+ for (var i = 0; i < 4; ++i) {
+ var x = this.curX + this.curPiece.getX(i);
+ var y = this.curY - this.curPiece.getY(i);
+ this.ui.drawSquare(painter, x, TetrixBoard.BoardHeight - y - 1,
+ this.curPiece.shape);
+ }
+ }
+}
+
+TetrixBoard.prototype.onPaintNextPiece = function(painter) {
+ for (var i = 0; i < 4; ++i) {
+ var x = this.nextPiece.getX(i) - this.nextPiece.minX;
+ var y = this.nextPiece.getY(i) - this.nextPiece.minY;
+ this.ui.drawSquare(painter, x, y, this.nextPiece.shape);
+ }
+}
+
+TetrixBoard.prototype.onKeyPress = function(key) {
+ if (!this.isStarted || this.isPaused || (this.curPiece.shape == TetrixShape.NoShape))
+ return;
+ this.inKeyPress = true;
+ switch (key) {
+ case Qt.Key_Left:
+ this.tryMove(this.curPiece, this.curX - 1, this.curY);
+ break;
+ case Qt.Key_Right:
+ this.tryMove(this.curPiece, this.curX + 1, this.curY);
+ break;
+ case Qt.Key_Down:
+ this.tryMove(this.curPiece.rotatedRight(), this.curX, this.curY);
+ break;
+ case Qt.Key_Up:
+ this.tryMove(this.curPiece.rotatedLeft(), this.curX, this.curY);
+ break;
+ case Qt.Key_Space:
+ this.dropDown();
+ break;
+ case Qt.Key_D:
+ this.oneLineDown();
+ break;
+ }
+ this.inKeyPress = false;
+ if (this.isStarted && !this.ui.timer.active)
+ this.ui.timer.start(this.timeoutTime());
+}
+
+TetrixBoard.prototype.onTimer = function() {
+ if (this.isWaitingAfterLine) {
+ this.isWaitingAfterLine = false;
+ this.newPiece();
+ this.ui.timer.start(this.timeoutTime());
+ } else {
+ if (!this.inKeyPress) {
+ this.oneLineDown();
+ if (this.isStarted && !this.ui.timer.active)
+ this.ui.timer.start(this.timeoutTime());
+ }
+ }
+}
+
+TetrixBoard.prototype.timeoutTime = function() {
+ return 1000 / (1 + this.level);
+}
diff --git a/examples/script/qstetrix/tetrixpiece.js b/examples/script/qstetrix/tetrixpiece.js
new file mode 100644
index 0000000000..e99fa8a179
--- /dev/null
+++ b/examples/script/qstetrix/tetrixpiece.js
@@ -0,0 +1,131 @@
+TetrixShape = {
+ NoShape:0,
+ ZShape:1,
+ SShape:2,
+ LineShape:3,
+ TShape:4,
+ SquareShape:5,
+ LShape:6,
+ MirroredLShape:7
+}
+
+TetrixCoordsTable = [
+ [ [ 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 ] ]
+]
+
+function TetrixPiece()
+{
+ this.shape = TetrixShape.NoShape;
+}
+
+TetrixPiece.prototype.__defineGetter__(
+ "shape",
+ function() {
+ return this._shape;
+ }
+);
+
+TetrixPiece.prototype.__defineSetter__(
+ "shape",
+ function(shape) {
+ this._shape = shape;
+ this._coords = new Array(4);
+ for (var i = 0; i < 4; ++i)
+ this._coords[i] = TetrixCoordsTable[shape][i].slice();
+ }
+);
+
+TetrixPiece.prototype.setRandomShape = function() {
+ this.shape = Math.floor(((Math.random() * 100000) % 7) + 1);
+}
+
+TetrixPiece.prototype.getX = function(index) {
+ return this._coords[index][0];
+}
+
+TetrixPiece.prototype.getY = function(index) {
+ return this._coords[index][1];
+}
+
+TetrixPiece.prototype._setX = function(index, x) {
+ this._coords[index][0] = x;
+}
+
+TetrixPiece.prototype._setY = function(index, y) {
+ this._coords[index][1] = y;
+}
+
+TetrixPiece.prototype.__defineGetter__(
+ "minX",
+ function() {
+ var min = this._coords[0][0];
+ for (var i = 1; i < 4; ++i)
+ min = Math.min(min, this._coords[i][0]);
+ return min;
+ }
+);
+
+TetrixPiece.prototype.__defineGetter__(
+ "maxX",
+ function() {
+ var max = this._coords[0][0];
+ for (var i = 1; i < 4; ++i)
+ max = Math.max(max, this._coords[i][0]);
+ return max;
+ }
+);
+
+TetrixPiece.prototype.__defineGetter__(
+ "minY",
+ function() {
+ var min = this._coords[0][1];
+ for (var i = 1; i < 4; ++i)
+ min = Math.min(min, this._coords[i][1]);
+ return min;
+ }
+);
+
+TetrixPiece.prototype.__defineGetter__(
+ "maxY",
+ function() {
+ var max = this._coords[0][1];
+ for (var i = 1; i < 4; ++i)
+ max = Math.max(max, this._coords[i][1]);
+ return max;
+ }
+);
+
+TetrixPiece.prototype.rotatedLeft = function() {
+ var result = new TetrixPiece();
+ if (this._shape == TetrixShape.SquareShape) {
+ result.shape = this._shape;
+ return result;
+ }
+ result._shape = this._shape;
+ for (var i = 0; i < 4; ++i) {
+ result._setX(i, this.getY(i));
+ result._setY(i, -this.getX(i));
+ }
+ return result;
+}
+
+TetrixPiece.prototype.rotatedRight = function() {
+ var result = new TetrixPiece();
+ if (this._shape == TetrixShape.SquareShape) {
+ result.shape = this._shape;
+ return result;
+ }
+ result._shape = this._shape;
+ for (var i = 0; i < 4; ++i) {
+ result._setX(i, -this.getY(i));
+ result._setY(i, this.getX(i));
+ }
+ return result;
+}
diff --git a/examples/script/qstetrix/tetrixwindow.js b/examples/script/qstetrix/tetrixwindow.js
new file mode 100644
index 0000000000..6157a8ce36
--- /dev/null
+++ b/examples/script/qstetrix/tetrixwindow.js
@@ -0,0 +1,16 @@
+function TetrixWindow(ui)
+{
+ this.ui = ui;
+
+ var boardUi = ui.findChild("board");
+ boardUi.nextPieceLabel = ui.findChild("nextPieceLabel");
+
+ this.board = new TetrixBoard(boardUi);
+
+ ui.findChild("startButton").clicked.connect(this.board, this.board.start);
+ ui.findChild("quitButton").clicked.connect(Qt.App.quit);
+ ui.findChild("pauseButton").clicked.connect(this.board, this.board.pause);
+ boardUi.scoreChanged.connect(ui.findChild("scoreLcd")["display(int)"]);
+ boardUi.levelChanged.connect(ui.findChild("levelLcd")["display(int)"]);
+ boardUi.linesRemovedChanged.connect(ui.findChild("linesLcd")["display(int)"]);
+}
diff --git a/examples/script/qstetrix/tetrixwindow.ui b/examples/script/qstetrix/tetrixwindow.ui
new file mode 100644
index 0000000000..a53e94faf5
--- /dev/null
+++ b/examples/script/qstetrix/tetrixwindow.ui
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TetrixWindow</class>
+ <widget class="QWidget" name="TetrixWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>537</width>
+ <height>475</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Tetrix</string>
+ </property>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <layout class="QGridLayout">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <item row="4" column="0">
+ <widget class="QPushButton" name="startButton">
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>&amp;Start</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="QLCDNumber" name="linesLcd">
+ <property name="segmentStyle">
+ <enum>QLCDNumber::Filled</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QLabel" name="linesRemovedLabel">
+ <property name="text">
+ <string>LINES REMOVED</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QLCDNumber" name="scoreLcd">
+ <property name="segmentStyle">
+ <enum>QLCDNumber::Filled</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" rowspan="6">
+ <widget class="TetrixBoard" name="board">
+ <property name="focusPolicy">
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::Panel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Sunken</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="levelLabel">
+ <property name="text">
+ <string>LEVEL</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="nextLabel">
+ <property name="text">
+ <string>NEXT</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLCDNumber" name="levelLcd">
+ <property name="segmentStyle">
+ <enum>QLCDNumber::Filled</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLabel" name="scoreLabel">
+ <property name="text">
+ <string>SCORE</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="nextPieceLabel">
+ <property name="frameShape">
+ <enum>QFrame::Box</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QPushButton" name="quitButton">
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>&amp;Quit</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="2">
+ <widget class="QPushButton" name="pauseButton">
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>&amp;Pause</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="2">
+ <widget class="QPushButton" name="debugButton">
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>&amp;Debug</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>TetrixBoard</class>
+ <extends>QFrame</extends>
+ <header>tetrixboard.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/script/script.pro b/examples/script/script.pro
new file mode 100644
index 0000000000..c5a37ef601
--- /dev/null
+++ b/examples/script/script.pro
@@ -0,0 +1,15 @@
+TEMPLATE = subdirs
+SUBDIRS = helloscript context2d defaultprototypes customclass
+
+!wince*:SUBDIRS += qscript marshal
+!wince*:!cross_compile:SUBDIRS += calculator qstetrix
+
+symbian: SUBDIRS = context2d
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/script
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS script.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/script
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
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..89e97aece0
--- /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]/sql/cachedtable
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS cachedtable.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/cachedtable
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/sql/cachedtable/main.cpp b/examples/sql/cachedtable/main.cpp
new file mode 100644
index 0000000000..47e3b9fdf4
--- /dev/null
+++ b/examples/sql/cachedtable/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "../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..33ddd54c2a
--- /dev/null
+++ b/examples/sql/cachedtable/tableeditor.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..3485fd3b8b
--- /dev/null
+++ b/examples/sql/cachedtable/tableeditor.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d4b77ef266
--- /dev/null
+++ b/examples/sql/connection.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7907bd2393
--- /dev/null
+++ b/examples/sql/drilldown/drilldown.pro
@@ -0,0 +1,20 @@
+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]/sql/drilldown
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS drilldown.pro *.png *.jpg images
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/drilldown
+INSTALLS += target sources
+
+symbian:TARGET.UID3 = 0xA000C612
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..620afed048
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..20c781139a
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ea66b0ba58
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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()));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(locationLabel, 0, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(countryLabel, 1, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(imageFileLabel, 2, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(descriptionLabel, 3, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(locationText, 0, 1);
+ layout->addWidget(countryText, 1, 1);
+ layout->addWidget(imageFileEditor, 2, 1);
+ layout->addWidget(descriptionEditor, 3, 1);
+ layout->addWidget(buttonBox, 4, 0, 1, 2);
+ setLayout(layout);
+
+ locationId = id;
+ displayedImage = imageFileEditor->currentText();
+
+ setWindowFlags(Qt::Window);
+ enableButtons(false);
+ setWindowTitle(tr("Office: %1").arg(locationText->text()));
+#ifndef Q_OS_SYMBIAN
+ resize(320, sizeHint().height());
+#endif
+}
+//! [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;
+ buttonBox->addButton(submitButton, QDialogButtonBox::ResetRole);
+ 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..f28b47d548
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..c340f5ec96
--- /dev/null
+++ b/examples/sql/drilldown/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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
+ return app.exec();
+}
diff --git a/examples/sql/drilldown/view.cpp b/examples/sql/drilldown/view.cpp
new file mode 100644
index 0000000000..778767b315
--- /dev/null
+++ b/examples/sql/drilldown/view.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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->showFullScreen();
+#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->showFullScreen();
+#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..37ddabba54
--- /dev/null
+++ b/examples/sql/drilldown/view.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a760e41741
--- /dev/null
+++ b/examples/sql/masterdetail/database.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..0adf20819f
--- /dev/null
+++ b/examples/sql/masterdetail/dialog.cpp
@@ -0,0 +1,283 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..0f4b54a2a5
--- /dev/null
+++ b/examples/sql/masterdetail/dialog.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..932b67a051
--- /dev/null
+++ b/examples/sql/masterdetail/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..67825d6149
--- /dev/null
+++ b/examples/sql/masterdetail/mainwindow.cpp
@@ -0,0 +1,430 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "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"),
+ QString(tr("Are you sure you want to " \
+ "delete '%1' by '%2'?"))
+ .arg(title).arg(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->setShortcut(tr("Ctrl+Q"));
+
+ 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..4d05022ba5
--- /dev/null
+++ b/examples/sql/masterdetail/mainwindow.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..2363e5450c
--- /dev/null
+++ b/examples/sql/masterdetail/masterdetail.pro
@@ -0,0 +1,18 @@
+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]/sql/masterdetail
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS masterdetail.pro *.xml images
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/masterdetail
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..e122ce89bb
--- /dev/null
+++ b/examples/sql/querymodel/customsqlmodel.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 qVariantFromValue(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..f4a0eab454
--- /dev/null
+++ b/examples/sql/querymodel/customsqlmodel.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d7841f6457
--- /dev/null
+++ b/examples/sql/querymodel/editablesqlmodel.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..3606ebccde
--- /dev/null
+++ b/examples/sql/querymodel/editablesqlmodel.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..90d4265e6f
--- /dev/null
+++ b/examples/sql/querymodel/main.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f20898cc9d
--- /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]/sql/querymodel
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS querymodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/querymodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/sql/relationaltablemodel/relationaltablemodel.cpp b/examples/sql/relationaltablemodel/relationaltablemodel.cpp
new file mode 100644
index 0000000000..b38cdda6fb
--- /dev/null
+++ b/examples/sql/relationaltablemodel/relationaltablemodel.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e57729ef91
--- /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]/sql/relationaltablemodel
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS relationaltablemodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/relationaltablemodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/sql/sql.pro b/examples/sql/sql.pro
new file mode 100644
index 0000000000..7bdff69fd7
--- /dev/null
+++ b/examples/sql/sql.pro
@@ -0,0 +1,18 @@
+TEMPLATE = subdirs
+
+SUBDIRS = drilldown
+!symbian: SUBDIRS += cachedtable \
+ relationaltablemodel \
+ sqlwidgetmapper
+
+!wince*:!symbian: SUBDIRS += \
+ querymodel \
+ tablemodel \
+ masterdetail
+
+# install
+sources.files = connection.h sql.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/sql/sqlwidgetmapper/main.cpp b/examples/sql/sqlwidgetmapper/main.cpp
new file mode 100644
index 0000000000..055ac21f6c
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..1881fce1fd
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro
@@ -0,0 +1,10 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/sql/sqlwidgetmapper
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/sqlwidgetmapper
+INSTALLS += target sources
diff --git a/examples/sql/sqlwidgetmapper/window.cpp b/examples/sql/sqlwidgetmapper/window.cpp
new file mode 100644
index 0000000000..ebfa2cf247
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/window.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..a3628a955b
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f24c62f52a
--- /dev/null
+++ b/examples/sql/tablemodel/tablemodel.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7adf40c10b
--- /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]/sql/tablemodel
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS tablemodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/tablemodel
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
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..2395ff6479
--- /dev/null
+++ b/examples/threads/mandelbrot/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..8f552a800a
--- /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:LIBS += -lm
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/threads/mandelbrot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS mandelbrot.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/threads/mandelbrot
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/threads/mandelbrot/mandelbrotwidget.cpp b/examples/threads/mandelbrot/mandelbrotwidget.cpp
new file mode 100644
index 0000000000..74b27d81aa
--- /dev/null
+++ b/examples/threads/mandelbrot/mandelbrotwidget.cpp
@@ -0,0 +1,240 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QImage &, double)),
+ this, SLOT(updatePixmap(const 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..3e8084cf73
--- /dev/null
+++ b/examples/threads/mandelbrot/mandelbrotwidget.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..5879035057
--- /dev/null
+++ b/examples/threads/mandelbrot/renderthread.cpp
@@ -0,0 +1,216 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..2b0318608a
--- /dev/null
+++ b/examples/threads/mandelbrot/renderthread.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..1a14f09426
--- /dev/null
+++ b/examples/threads/queuedcustomtype/block.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..2a75529456
--- /dev/null
+++ b/examples/threads/queuedcustomtype/block.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..93dab49b1c
--- /dev/null
+++ b/examples/threads/queuedcustomtype/main.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..052dd39bfe
--- /dev/null
+++ b/examples/threads/queuedcustomtype/renderthread.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..9c7f04957d
--- /dev/null
+++ b/examples/threads/queuedcustomtype/renderthread.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7282e0c67f
--- /dev/null
+++ b/examples/threads/queuedcustomtype/window.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c0ed280125
--- /dev/null
+++ b/examples/threads/queuedcustomtype/window.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..548380d255
--- /dev/null
+++ b/examples/threads/semaphores/semaphores.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5331383e06
--- /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]/threads/semaphores
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS semaphores.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/threads/semaphores
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/threads/threads.pro b/examples/threads/threads.pro
new file mode 100644
index 0000000000..a0e69c81b1
--- /dev/null
+++ b/examples/threads/threads.pro
@@ -0,0 +1,12 @@
+TEMPLATE = subdirs
+SUBDIRS = mandelbrot \
+ semaphores \
+ waitconditions
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/threads
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS threads.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/threads
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/threads/waitconditions/waitconditions.cpp b/examples/threads/waitconditions/waitconditions.cpp
new file mode 100644
index 0000000000..44188d58c6
--- /dev/null
+++ b/examples/threads/waitconditions/waitconditions.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..49fe318537
--- /dev/null
+++ b/examples/threads/waitconditions/waitconditions.pro
@@ -0,0 +1,22 @@
+######################################################################
+# Automatically generated by qmake (1.08a) Fri Jan 7 15:25:07 2005
+######################################################################
+
+TEMPLATE = app
+CONFIG -= moc app_bundle
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += waitconditions.cpp
+CONFIG += qt warn_on create_prl link_prl console
+OBJECTS_DIR=obj/debug-shared
+MOC_DIR=moc/debug-shared
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/threads/waitconditions
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS waitconditions.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/threads/waitconditions
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..7cc0ae836c
--- /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]/tools/codecs
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS encodedfiles codecs.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/codecs
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/codecs/encodedfiles/.gitattributes b/examples/tools/codecs/encodedfiles/.gitattributes
new file mode 100644
index 0000000000..996aab2a08
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/.gitattributes
@@ -0,0 +1,2 @@
+iso-8859-15.txt -crlf
+iso-8859-1.txt -crlf
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..4a7ebe3c8b
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-1.txt
@@ -0,0 +1,6 @@
+Paulo Coelho: O Gênio e as Rosas
+Anna Hallström, Urban Östberg: Svår svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schloß
+Walter Moers: Die 13œ Leben des Käpt'n Blaubär
+Dag Solstad: Forsøk 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..cd43ea3e00
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-15.txt
@@ -0,0 +1,8 @@
+Paulo Coelho: O Gênio e as Rosas
+Jean-Pierre Coffe: À table en famille avec 15 € par jour
+Anna Hallström, Urban Östberg: Svår svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schloß
+Helena Lehecková: Tšekkiä suomalaisille
+Arthur Rimbaud: Œuvres complètes
+Dag Solstad: Forsøk 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..4856752c8c
--- /dev/null
+++ b/examples/tools/codecs/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..1e6fa69546
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+O"));
+ 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->setShortcut(tr("Ctrl+Q"));
+ 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..1702d5c586
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..cbe084f043
--- /dev/null
+++ b/examples/tools/codecs/previewform.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..130cb79296
--- /dev/null
+++ b/examples/tools/codecs/previewform.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4f3145438d
--- /dev/null
+++ b/examples/tools/completer/completer.pro
@@ -0,0 +1,14 @@
+HEADERS = dirmodel.h \
+ mainwindow.h
+SOURCES = dirmodel.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = completer.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/completer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS completer.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/completer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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/dirmodel.cpp b/examples/tools/completer/dirmodel.cpp
new file mode 100644
index 0000000000..1daf03ce73
--- /dev/null
+++ b/examples/tools/completer/dirmodel.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "dirmodel.h"
+
+//! [0]
+DirModel::DirModel(QObject *parent)
+ : QDirModel(parent)
+{
+}
+//! [0]
+
+//! [1]
+QVariant DirModel::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 QDirModel::data(index, role);
+}
+//! [1]
diff --git a/examples/tools/completer/dirmodel.h b/examples/tools/completer/dirmodel.h
new file mode 100644
index 0000000000..bd49ca9290
--- /dev/null
+++ b/examples/tools/completer/dirmodel.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIRMODEL_H
+#define DIRMODEL_H
+
+#include <QDirModel>
+
+// With a QDirModel, 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 DirModel : public QDirModel
+{
+public:
+ DirModel(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..a414cd571b
--- /dev/null
+++ b/examples/tools/completer/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [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..862967a7f8
--- /dev/null
+++ b/examples/tools/completer/mainwindow.cpp
@@ -0,0 +1,264 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "dirmodel.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("QDirModel"));
+ modelCombo->addItem(tr("QDirModel 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]
+ 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)));
+//! [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(wrapCheckBox, 3, 0);
+ layout->addWidget(contentsLabel, 4, 0, 1, 2);
+ layout->addWidget(lineEdit, 5, 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);
+
+ switch (modelCombo->currentIndex()) {
+ default:
+ case 0:
+ { // Unsorted QDirModel
+ QDirModel *dirModel = new QDirModel(completer);
+ completer->setModel(dirModel);
+ contentsLabel->setText(tr("Enter file path"));
+ }
+ break;
+//! [11] //! [12]
+ case 1:
+ { // DirModel that shows full paths
+ DirModel *dirModel = new DirModel(completer);
+ completer->setModel(dirModel);
+ 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::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates the "
+ "different features of the QCompleter class."));
+}
+//! [15]
diff --git a/examples/tools/completer/mainwindow.h b/examples/tools/completer/mainwindow.h
new file mode 100644
index 0000000000..f6fba9c29e
--- /dev/null
+++ b/examples/tools/completer/mainwindow.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QCompleter;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+class QCheckBox;
+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();
+//! [0]
+
+//! [1]
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QComboBox *caseCombo;
+ QComboBox *modeCombo;
+ QComboBox *modelCombo;
+ 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..e598a19b59
--- /dev/null
+++ b/examples/tools/completer/resources/wordlist.txt
@@ -0,0 +1,1486 @@
+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
+Trolltech
+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/customcompleter/customcompleter.pro b/examples/tools/customcompleter/customcompleter.pro
new file mode 100644
index 0000000000..8a11cf15d7
--- /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]/tools/customcompleter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS customcompleter.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/customcompleter
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..8e64f6cea1
--- /dev/null
+++ b/examples/tools/customcompleter/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [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..8d75ddd7bd
--- /dev/null
+++ b/examples/tools/customcompleter/mainwindow.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..77089c265b
--- /dev/null
+++ b/examples/tools/customcompleter/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..a5de826396
--- /dev/null
+++ b/examples/tools/customcompleter/resources/wordlist.txt
@@ -0,0 +1,1455 @@
+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
+Trolltech
+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..ecafa8fa22
--- /dev/null
+++ b/examples/tools/customcompleter/textedit.cpp
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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(const QString&)),
+ this, SLOT(insertCompletion(const 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) // dont 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..d727228050
--- /dev/null
+++ b/examples/tools/customcompleter/textedit.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e8f4265e53
--- /dev/null
+++ b/examples/tools/customtype/main.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 = qVariantValue<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..b6fd536dca
--- /dev/null
+++ b/examples/tools/customtype/message.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..26205572e4
--- /dev/null
+++ b/examples/tools/customtype/message.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..336f3d8c38
--- /dev/null
+++ b/examples/tools/customtypesending/main.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..69928048dd
--- /dev/null
+++ b/examples/tools/customtypesending/message.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..55f9568cf8
--- /dev/null
+++ b/examples/tools/customtypesending/message.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..be79518362
--- /dev/null
+++ b/examples/tools/customtypesending/window.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..cbe9775eb0
--- /dev/null
+++ b/examples/tools/customtypesending/window.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..6146b4901f
--- /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]/tools/echoplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS echoplugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/echoplugin/echowindow/echointerface.h b/examples/tools/echoplugin/echowindow/echointerface.h
new file mode 100644
index 0000000000..d4aecd2efa
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echointerface.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..0de85ea333
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7378e62ca2
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..142438bac0
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.pro
@@ -0,0 +1,20 @@
+HEADERS = echowindow.h \
+ echointerface.h
+SOURCES = echowindow.cpp \
+ main.cpp
+
+TARGET = echoplugin
+win32 {
+ debug:DESTDIR = ../debug/
+ release:DESTDIR = ../release/
+} else {
+ DESTDIR = ../
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS echowindow.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin/echowindow
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/echoplugin/echowindow/main.cpp b/examples/tools/echoplugin/echowindow/main.cpp
new file mode 100644
index 0000000000..cc18f66e6b
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..67126be5dc
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/echoplugin.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..7ea1d47674
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/echoplugin.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d943425f24
--- /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]/tools/echoplugin/plugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin/plugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..a065611c87
--- /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]/tools/i18n
+sources.files = $$SOURCES $$HEADERS $$RESOURCES translations i18n.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/i18n
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..a8e97791d4
--- /dev/null
+++ b/examples/tools/i18n/languagechooser.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..69914f708a
--- /dev/null
+++ b/examples/tools/i18n/languagechooser.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..98d3da0e56
--- /dev/null
+++ b/examples/tools/i18n/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..33cd5f57e7
--- /dev/null
+++ b/examples/tools/i18n/mainwindow.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5928be2588
--- /dev/null
+++ b/examples/tools/i18n/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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/plugandpaint/interfaces.h b/examples/tools/plugandpaint/interfaces.h
new file mode 100644
index 0000000000..87eb9d0f20
--- /dev/null
+++ b/examples/tools/plugandpaint/interfaces.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7778cac419
--- /dev/null
+++ b/examples/tools/plugandpaint/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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..224bc71e04
--- /dev/null
+++ b/examples/tools/plugandpaint/mainwindow.cpp
@@ -0,0 +1,310 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "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->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcut(tr("Ctrl+S"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ 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..47afb2d6c3
--- /dev/null
+++ b/examples/tools/plugandpaint/mainwindow.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..9d5b3c5f2a
--- /dev/null
+++ b/examples/tools/plugandpaint/paintarea.cpp
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "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..e4215d5885
--- /dev/null
+++ b/examples/tools/plugandpaint/paintarea.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..fef1b86f7c
--- /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]/tools/plugandpaint
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugandpaint.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaint
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/plugandpaint/plugindialog.cpp b/examples/tools/plugandpaint/plugindialog.cpp
new file mode 100644
index 0000000000..5e37a8b635
--- /dev/null
+++ b/examples/tools/plugandpaint/plugindialog.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "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..73cb6e498f
--- /dev/null
+++ b/examples/tools/plugandpaint/plugindialog.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f9cd4a6a85
--- /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]/tools/plugandpaint/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS basictools.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins/basictools
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp
new file mode 100644
index 0000000000..95b239f450
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp
@@ -0,0 +1,198 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..98aed0ba8b
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..7fbb6d1787
--- /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]/tools/plugandpaint/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS extrafilters.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins/extrafilters
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..b54d8b6d78
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b1b497eaed
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ccc042c307
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/plugandpaintplugins.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = basictools \
+ extrafilters
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugandpaintplugins.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/regexp/main.cpp b/examples/tools/regexp/main.cpp
new file mode 100644
index 0000000000..4fc8de8071
--- /dev/null
+++ b/examples/tools/regexp/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..bbb3fd390e
--- /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]/tools/regexp
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS regexp.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/regexp
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/regexp/regexpdialog.cpp b/examples/tools/regexp/regexpdialog.cpp
new file mode 100644
index 0000000000..8fe7383444
--- /dev/null
+++ b/examples/tools/regexp/regexpdialog.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+
+ 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(const QString &)),
+ this, SLOT(refresh()));
+ connect(textComboBox, SIGNAL(editTextChanged(const 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.numCaptures());
+ captureEdits[i]->setEnabled(i <= rx.numCaptures());
+ 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..d4dfb650e7
--- /dev/null
+++ b/examples/tools/regexp/regexpdialog.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..600038b228
--- /dev/null
+++ b/examples/tools/settingseditor/locationdialog.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..3ea8359569
--- /dev/null
+++ b/examples/tools/settingseditor/locationdialog.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4856752c8c
--- /dev/null
+++ b/examples/tools/settingseditor/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..0f48a5c390
--- /dev/null
+++ b/examples/tools/settingseditor/mainwindow.cpp
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+O"));
+ 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->setShortcut(tr("Ctrl+Q"));
+ 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..749602d78b
--- /dev/null
+++ b/examples/tools/settingseditor/mainwindow.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..c6838bc73f
--- /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]/tools/settingseditor
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS settingseditor.pro inifiles
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/settingseditor
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/settingseditor/settingstree.cpp b/examples/tools/settingseditor/settingstree.cpp
new file mode 100644
index 0000000000..82d32fdb0d
--- /dev/null
+++ b/examples/tools/settingseditor/settingstree.cpp
@@ -0,0 +1,263 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f82034b710
--- /dev/null
+++ b/examples/tools/settingseditor/settingstree.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..937a0e14ab
--- /dev/null
+++ b/examples/tools/settingseditor/variantdelegate.cpp
@@ -0,0 +1,317 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..60997f7bc2
--- /dev/null
+++ b/examples/tools/settingseditor/variantdelegate.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..2a36d51b34
--- /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 {
+ debug:DESTDIR = ../debug/styles/
+ release:DESTDIR = ../release/styles/
+} else {
+ DESTDIR = ../styles/
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin/styles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin/plugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..900c772881
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyle.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f4c499cfa9
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyle.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..6845c814af
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyleplugin.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..106c4a909c
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyleplugin.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..74f77b5883
--- /dev/null
+++ b/examples/tools/styleplugin/styleplugin.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = stylewindow \
+ plugin
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS styleplugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/styleplugin/stylewindow/main.cpp b/examples/tools/styleplugin/stylewindow/main.cpp
new file mode 100644
index 0000000000..b6e69efd01
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..8a813baee0
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5eba7513f3
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..df68168387
--- /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]/tools/styleplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS stylewindow.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin/stylewindow
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/tools.pro b/examples/tools/tools.pro
new file mode 100644
index 0000000000..17a3ea2fa4
--- /dev/null
+++ b/examples/tools/tools.pro
@@ -0,0 +1,24 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = codecs \
+ completer \
+ customcompleter \
+ echoplugin \
+ i18n \
+ plugandpaintplugins \
+ plugandpaint \
+ regexp \
+ settingseditor \
+ styleplugin \
+ treemodelcompleter \
+ undoframework
+
+plugandpaint.depends = plugandpaintplugins
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tools.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/treemodelcompleter/main.cpp b/examples/tools/treemodelcompleter/main.cpp
new file mode 100644
index 0000000000..982575e77a
--- /dev/null
+++ b/examples/tools/treemodelcompleter/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [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..9f69e8017d
--- /dev/null
+++ b/examples/tools/treemodelcompleter/mainwindow.cpp
@@ -0,0 +1,247 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QModelIndex&)),
+ this, SLOT(highlight(const 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(const QString&)),
+ completer, SLOT(setSeparator(const 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(const QString&)),
+ this, SLOT(updateContentsLabel(const 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(QString(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..be14c34247
--- /dev/null
+++ b/examples/tools/treemodelcompleter/mainwindow.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <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..c1464b004e
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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..51a59028f0
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ef5c0cb38b
--- /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]/tools/treemodelcompleter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS treemodelcompleter.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/treemodelcompleter
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..78f0c162a3
--- /dev/null
+++ b/examples/tools/undoframework/commands.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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]
+
+//! [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..17e4f3cb2b
--- /dev/null
+++ b/examples/tools/undoframework/commands.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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);
+
+ 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..1b4301e356
--- /dev/null
+++ b/examples/tools/undoframework/diagramitem.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..68da876bfe
--- /dev/null
+++ b/examples/tools/undoframework/diagramitem.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..fcc63c90f0
--- /dev/null
+++ b/examples/tools/undoframework/diagramscene.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e1537cc353
--- /dev/null
+++ b/examples/tools/undoframework/diagramscene.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..170d292b8a
--- /dev/null
+++ b/examples/tools/undoframework/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..f912ff2bba
--- /dev/null
+++ b/examples/tools/undoframework/mainwindow.cpp
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "diagramscene.h"
+#include "diagramitem.h"
+#include "commands.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ undoStack = new QUndoStack();
+
+ 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 *, const QPointF &)),
+ this, SLOT(itemMoved(DiagramItem *, const 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->setShortcut(tr("Ctrl+Z"));
+
+ redoAction = undoStack->createRedoAction(this, tr("&Redo"));
+ QList<QKeySequence> redoShortcuts;
+ redoShortcuts << tr("Ctrl+Y") << tr("Shift+Ctrl+Z");
+ redoAction->setShortcuts(redoShortcuts);
+//! [5]
+
+ exitAction = new QAction(tr("E&xit"), this);
+ exitAction->setShortcut(tr("Ctrl+Q"));
+ 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..5f08ffc2fe
--- /dev/null
+++ b/examples/tools/undoframework/mainwindow.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..f797eb501c
--- /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]/tools/undoframework
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS undoframework.pro README images
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/undoframework
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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/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..2d528b5200
--- /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://doc.trolltech.com/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..2cdd4587c4
--- /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]/tutorials/addressbook-fr
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS addressbook-fr.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..d0107ba067
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part1/addressbook.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..811fb057af
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part1/addressbook.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..22bfd3ee3e
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part1/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..bb181dd392
--- /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]/tutorials/addressbook/part1
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part1.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..ac4b9c123a
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part2/addressbook.cpp
@@ -0,0 +1,158 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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..c99b3735b9
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part2/addressbook.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..22bfd3ee3e
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part2/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..01ce34465f
--- /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]/tutorials/addressbook/part2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part2.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..49c5206160
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part3/addressbook.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and adderss."));
+ 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));
+ return;
+ }
+
+ 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..c13dc21a8b
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part3/addressbook.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part3/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..128c0380e9
--- /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]/tutorials/addressbook/part3
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part3.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..95def9c4d0
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part4/addressbook.cpp
@@ -0,0 +1,291 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+//! [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));
+ return;
+ }
+ } 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..83c7af3e9d
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part4/addressbook.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part4/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..23ce3e6008
--- /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]/tutorials/addressbook/part4
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part4.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..5afb6b8e0a
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/addressbook.cpp
@@ -0,0 +1,315 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+ } 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));
+ return;
+ }
+ } 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..04dfa00ee8
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/addressbook.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f8839505b0
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/finddialog.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..db60784f48
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/finddialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..95123d000e
--- /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]/tutorials/addressbook/part5
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part5.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..b7cd446925
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/addressbook.cpp
@@ -0,0 +1,396 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+ } 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));
+ return;
+ }
+ } 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..5a36af3e69
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/addressbook.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e28bbaef39
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/finddialog.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c94baad5d3
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/finddialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..dc8956132a
--- /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]/tutorials/addressbook/part6
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part6.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..2f81d2bd61
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/addressbook.cpp
@@ -0,0 +1,449 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+ } 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));
+ return;
+ }
+ } 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..3a6ae41e76
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/addressbook.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e28bbaef39
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/finddialog.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c94baad5d3
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/finddialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..a726d91003
--- /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]/tutorials/addressbook/part7
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part7.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part7
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook/README b/examples/tutorials/addressbook/README
new file mode 100644
index 0000000000..2d528b5200
--- /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://doc.trolltech.com/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/addressbook.pro b/examples/tutorials/addressbook/addressbook.pro
new file mode 100644
index 0000000000..8e9859301d
--- /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]/tutorials/addressbook
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS addressbook.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/addressbook/part1/addressbook.cpp b/examples/tutorials/addressbook/part1/addressbook.cpp
new file mode 100644
index 0000000000..d0107ba067
--- /dev/null
+++ b/examples/tutorials/addressbook/part1/addressbook.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..811fb057af
--- /dev/null
+++ b/examples/tutorials/addressbook/part1/addressbook.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..22bfd3ee3e
--- /dev/null
+++ b/examples/tutorials/addressbook/part1/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..505f814f4e
--- /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]/tutorials/addressbook/part1
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part1.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part1
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/addressbook/part2/addressbook.cpp b/examples/tutorials/addressbook/part2/addressbook.cpp
new file mode 100644
index 0000000000..ac4b9c123a
--- /dev/null
+++ b/examples/tutorials/addressbook/part2/addressbook.cpp
@@ -0,0 +1,158 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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..c99b3735b9
--- /dev/null
+++ b/examples/tutorials/addressbook/part2/addressbook.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..22bfd3ee3e
--- /dev/null
+++ b/examples/tutorials/addressbook/part2/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..fdc0079086
--- /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]/tutorials/addressbook/part2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part2.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part2
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/addressbook/part3/addressbook.cpp b/examples/tutorials/addressbook/part3/addressbook.cpp
new file mode 100644
index 0000000000..49c5206160
--- /dev/null
+++ b/examples/tutorials/addressbook/part3/addressbook.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and adderss."));
+ 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));
+ return;
+ }
+
+ 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..c13dc21a8b
--- /dev/null
+++ b/examples/tutorials/addressbook/part3/addressbook.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook/part3/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..6e33cb84f0
--- /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]/tutorials/addressbook/part3
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part3.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part3
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/addressbook/part4/addressbook.cpp b/examples/tutorials/addressbook/part4/addressbook.cpp
new file mode 100644
index 0000000000..95def9c4d0
--- /dev/null
+++ b/examples/tutorials/addressbook/part4/addressbook.cpp
@@ -0,0 +1,291 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+//! [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));
+ return;
+ }
+ } 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..83c7af3e9d
--- /dev/null
+++ b/examples/tutorials/addressbook/part4/addressbook.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook/part4/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..0cfb546993
--- /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]/tutorials/addressbook/part4
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part4.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part4
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/addressbook/part5/addressbook.cpp b/examples/tutorials/addressbook/part5/addressbook.cpp
new file mode 100644
index 0000000000..5afb6b8e0a
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/addressbook.cpp
@@ -0,0 +1,315 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+ } 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));
+ return;
+ }
+ } 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..04dfa00ee8
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/addressbook.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f8839505b0
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/finddialog.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..db60784f48
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/finddialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..92e3d51db5
--- /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]/tutorials/addressbook/part5
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part5.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part5
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/addressbook/part6/addressbook.cpp b/examples/tutorials/addressbook/part6/addressbook.cpp
new file mode 100644
index 0000000000..b7cd446925
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/addressbook.cpp
@@ -0,0 +1,396 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+ } 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));
+ return;
+ }
+ } 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..5a36af3e69
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/addressbook.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e28bbaef39
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/finddialog.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c94baad5d3
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/finddialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..1b57b1670a
--- /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]/tutorials/addressbook/part6
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part6.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part6
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/addressbook/part7/addressbook.cpp b/examples/tutorials/addressbook/part7/addressbook.cpp
new file mode 100644
index 0000000000..2f81d2bd61
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/addressbook.cpp
@@ -0,0 +1,449 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 == "" || address == "") {
+ 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));
+ return;
+ }
+ } 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));
+ return;
+ }
+ } 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..3a6ae41e76
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/addressbook.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e28bbaef39
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/finddialog.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..c94baad5d3
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/finddialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b25d6561a9
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook *addressBook = new 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..fc47fae4c6
--- /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]/tutorials/addressbook/part7
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part7.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/addressbook/part7
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tutorials/tutorials.pro b/examples/tutorials/tutorials.pro
new file mode 100644
index 0000000000..427dc03f87
--- /dev/null
+++ b/examples/tutorials/tutorials.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ addressbook
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials
+INSTALLS += sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/uitools/multipleinheritance/calculatorform.cpp b/examples/uitools/multipleinheritance/calculatorform.cpp
new file mode 100644
index 0000000000..d2241d264a
--- /dev/null
+++ b/examples/uitools/multipleinheritance/calculatorform.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..24832441e8
--- /dev/null
+++ b/examples/uitools/multipleinheritance/calculatorform.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..2ed0016074
--- /dev/null
+++ b/examples/uitools/multipleinheritance/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..5340ac513a
--- /dev/null
+++ b/examples/uitools/multipleinheritance/multipleinheritance.pro
@@ -0,0 +1,13 @@
+#! [0]
+SOURCES = calculatorform.cpp main.cpp
+HEADERS = calculatorform.h
+FORMS = calculatorform.ui
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/uitools/multipleinheritance
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/uitools/multipleinheritance
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/uitools/textfinder/forms/input.txt b/examples/uitools/textfinder/forms/input.txt
new file mode 100644
index 0000000000..fae542f529
--- /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..dac93c653b
--- /dev/null
+++ b/examples/uitools/textfinder/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "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..d4b5d9ecf9
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtUiTools>
+#include <QtGui>
+#include "textfinder.h"
+
+//! [0]
+TextFinder::TextFinder(QWidget *parent)
+ : QWidget(parent)
+{
+ QWidget *formWidget = loadUiFile();
+
+//! [1]
+ ui_findButton = qFindChild<QPushButton*>(this, "findButton");
+ ui_textEdit = qFindChild<QTextEdit*>(this, "textEdit");
+ ui_lineEdit = qFindChild<QLineEdit*>(this, "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 == "") {
+ 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..c4880dc49d
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f4f14e1418
--- /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]/uitools/textfinder
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro forms
+sources.path = $$[QT_INSTALL_EXAMPLES]/uitools/textfinder
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..78c15fa00f
--- /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]/uitools
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS uitools.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/uitools
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/webkit/formextractor/form.html b/examples/webkit/formextractor/form.html
new file mode 100755
index 0000000000..18ddff1e87
--- /dev/null
+++ b/examples/webkit/formextractor/form.html
@@ -0,0 +1,64 @@
+<html><script>
+function extractFormValues()
+{
+ var firstName = document.getElementById("firstname").value;
+ var lastName = document.getElementById("lastname").value;
+ var maleGender = document.getElementById("genderMale");
+ var femaleGender = document.getElementById("genderFemale");
+
+ var gender = "";
+ if (maleGender.checked)
+ gender = maleGender.value;
+ else if (femaleGender.checked)
+ gender = femaleGender.value;
+
+ var updates = document.getElementById("updates").checked;
+
+ formExtractor.setValues(firstName, lastName, gender, updates);
+}
+</script><body>
+<h1>
+The Green People Book Club
+</h1>
+
+<p>
+Welcome to The Green People Book Club. Please register to obtain a membership with us.
+</p>
+ <form onsubmit="extractFormValues()">
+ <table>
+ <tbody><tr>
+ <td>
+ First name:
+ </td>
+ <td>
+ <input type="text" id="firstname">
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Last name:
+ </td>
+ <td>
+ <input type="text" id="lastname">
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Gender:
+ </td>
+ <td>
+ <input type="radio" name="gender" id="genderMale" value="Male"> Male
+ <input type="radio" name="gender" id="genderFemale" value="Female"> Female
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <input type="checkbox" id="updates" value="receive">
+ Check here if you would like to receive regular updates from us:
+ </td>
+ </tr>
+ </tbody></table>
+ <input type="submit" value="Submit">
+ </form>
+
+</body></html> \ No newline at end of file
diff --git a/examples/webkit/formextractor/formextractor.cpp b/examples/webkit/formextractor/formextractor.cpp
new file mode 100644
index 0000000000..d5ecc29cb6
--- /dev/null
+++ b/examples/webkit/formextractor/formextractor.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "formextractor.h"
+
+FormExtractor::FormExtractor(QWidget *parent, Qt::WFlags flags)
+ : QWidget(parent, flags)
+{
+ ui.setupUi(this);
+ ui.webView->setUrl(QUrl("qrc:/form.html"));
+ connect(ui.webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
+ this, SLOT(populateJavaScriptWindowObject()));
+ resize(300, 300);
+}
+
+FormExtractor::~FormExtractor()
+{
+}
+
+void FormExtractor::setValues(const QString &firstName, const QString &lastName,
+ const QString &gender, bool updates)
+{
+ ui.firstNameEdit->setText(firstName);
+ ui.lastNameEdit->setText(lastName);
+ ui.genderEdit->setText(gender);
+
+ if (updates == false)
+ ui.updatesEdit->setText("No");
+ else
+ ui.updatesEdit->setText("Yes");
+}
+
+void FormExtractor::populateJavaScriptWindowObject()
+{
+ ui.webView->page()->mainFrame()->addToJavaScriptWindowObject("formExtractor", this);
+}
diff --git a/examples/webkit/formextractor/formextractor.h b/examples/webkit/formextractor/formextractor.h
new file mode 100644
index 0000000000..5b11565dc6
--- /dev/null
+++ b/examples/webkit/formextractor/formextractor.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FORMEXTRACTOR_H
+#define FORMEXTRACTOR_H
+
+#include <QtGui/QWidget>
+#include <QWebFrame>
+#include "ui_formextractor.h"
+
+class FormExtractor : public QWidget
+{
+ Q_OBJECT
+
+public:
+ FormExtractor(QWidget *parent = 0, Qt::WFlags flags = 0);
+ ~FormExtractor();
+
+public slots:
+ void setValues(const QString &firstName, const QString &lastName,
+ const QString &gender, bool updates);
+
+ void populateJavaScriptWindowObject();
+
+private:
+ Ui::Form ui;
+};
+
+#endif // FORMEXTRACTOR_H
diff --git a/examples/webkit/formextractor/formextractor.pro b/examples/webkit/formextractor/formextractor.pro
new file mode 100644
index 0000000000..ddd39b4c6b
--- /dev/null
+++ b/examples/webkit/formextractor/formextractor.pro
@@ -0,0 +1,18 @@
+QT += webkit
+TARGET = formExtractor
+TEMPLATE = app
+SOURCES += main.cpp \
+ formextractor.cpp \
+ mainwindow.cpp
+HEADERS += formextractor.h \
+ mainwindow.h
+FORMS += formextractor.ui
+RESOURCES += formextractor.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/webkit/formextractor
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro form.html images
+sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/formextractor
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/webkit/formextractor/formextractor.qrc b/examples/webkit/formextractor/formextractor.qrc
new file mode 100644
index 0000000000..e35f4b28ab
--- /dev/null
+++ b/examples/webkit/formextractor/formextractor.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>form.html</file>
+ </qresource>
+ </RCC> \ No newline at end of file
diff --git a/examples/webkit/formextractor/formextractor.ui b/examples/webkit/formextractor/formextractor.ui
new file mode 100644
index 0000000000..5c4afec213
--- /dev/null
+++ b/examples/webkit/formextractor/formextractor.ui
@@ -0,0 +1,159 @@
+<ui version="4.0" >
+ <class>Form</class>
+ <widget class="QWidget" name="Form" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>680</width>
+ <height>218</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QGroupBox" name="webFormGroupBox" >
+ <property name="title" >
+ <string>Web Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QWebView" name="webView" >
+ <property name="minimumSize" >
+ <size>
+ <width>200</width>
+ <height>150</height>
+ </size>
+ </property>
+ <property name="maximumSize" >
+ <size>
+ <width>400</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="url" >
+ <url>
+ <string>about:blank</string>
+ </url>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>28</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="dataGroupBox" >
+ <property name="title" >
+ <string>Extracted Data</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3" >
+ <item>
+ <layout class="QFormLayout" name="formLayout" >
+ <property name="fieldGrowthPolicy" >
+ <enum>QFormLayout::FieldsStayAtSizeHint</enum>
+ </property>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="firstNameLabel" >
+ <property name="text" >
+ <string>First Name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="firstNameEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="lastNameLabel" >
+ <property name="text" >
+ <string>Last Name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLineEdit" name="lastNameEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="genderLabel" >
+ <property name="text" >
+ <string>Gender</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLineEdit" name="genderEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="updatesLabel" >
+ <property name="text" >
+ <string>Receive Updates</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLineEdit" name="updatesEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>24</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QWebView</class>
+ <extends>QWidget</extends>
+ <header>QtWebKit/QWebView</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/webkit/formextractor/main.cpp b/examples/webkit/formextractor/main.cpp
new file mode 100644
index 0000000000..aa7847d3fd
--- /dev/null
+++ b/examples/webkit/formextractor/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(formextractor);
+ QApplication app(argc, argv);
+ MainWindow mainWindow;
+ mainWindow.setWindowTitle("Form Extractor");
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/webkit/formextractor/mainwindow.cpp b/examples/webkit/formextractor/mainwindow.cpp
new file mode 100644
index 0000000000..222d9b208d
--- /dev/null
+++ b/examples/webkit/formextractor/mainwindow.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+ createActions();
+ createMenus();
+ centralWidget = new FormExtractor(this);
+ setCentralWidget(centralWidget);
+}
+
+void MainWindow::createActions()
+{
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setStatusTip(tr("Exit the application"));
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ connect(exitAct, 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(exitAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Form Extractor"),
+ tr("The <b>Form Extractor</b> example demonstrates how to "
+ "extract data from a web form using QtWebKit."));
+
+}
diff --git a/examples/webkit/formextractor/mainwindow.h b/examples/webkit/formextractor/mainwindow.h
new file mode 100644
index 0000000000..7918870f41
--- /dev/null
+++ b/examples/webkit/formextractor/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include "formextractor.h"
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void about();
+
+private:
+ FormExtractor *centralWidget;
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+
+ void createActions();
+ void createMenus();
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/webkit/previewer/main.cpp b/examples/webkit/previewer/main.cpp
new file mode 100644
index 0000000000..87612e2c01
--- /dev/null
+++ b/examples/webkit/previewer/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char * argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow *mainWindow = new MainWindow;
+ mainWindow->show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/webkit/previewer/mainwindow.cpp b/examples/webkit/previewer/mainwindow.cpp
new file mode 100644
index 0000000000..abe7941f03
--- /dev/null
+++ b/examples/webkit/previewer/mainwindow.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtWebKit>
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ createActions();
+ createMenus();
+ centralWidget = new Previewer(this);
+ setCentralWidget(centralWidget);
+
+ connect(centralWidget->webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(updateTextEdit()));
+ setStartupText();
+}
+//! [0]
+
+//! [1]
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcut(tr("Ctrl+O"));
+ openAct->setStatusTip(tr("Open an existing HTML file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ openUrlAct = new QAction(tr("&Open URL..."), this);
+ openUrlAct->setShortcut(tr("Ctrl+U"));
+ openUrlAct->setStatusTip(tr("Open a URL"));
+ connect(openUrlAct, SIGNAL(triggered()), this, SLOT(openUrl()));
+//! [1]
+
+ saveAct = new QAction(tr("&Save"), this);
+ saveAct->setShortcut(tr("Ctrl+S"));
+ saveAct->setStatusTip(tr("Save the HTML file to disk"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setStatusTip(tr("Exit the application"));
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ connect(exitAct, 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()));
+}
+
+//! [2]
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(openUrlAct);
+ fileMenu->addAction(saveAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [2]
+
+//! [3]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Previewer"),
+ tr("The <b>Previewer</b> example demonstrates how to "
+ "view HTML documents using a QWebView."));
+}
+//! [3]
+
+//! [4]
+void MainWindow::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty()) {
+ // read from file
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QTextStream out(&file);
+ QString output = out.readAll();
+
+ // display contents
+ centralWidget->plainTextEdit->setPlainText(output);
+ centralWidget->setBaseUrl(QUrl::fromLocalFile(fileName));
+ }
+}
+//! [4]
+
+//! [5]
+void MainWindow::openUrl()
+{
+ bool ok;
+ QString url = QInputDialog::getText(this, tr("Enter a URL"),
+ tr("URL:"), QLineEdit::Normal, "http://", &ok);
+
+ if (ok && !url.isEmpty()) {
+ centralWidget->webView->setUrl(url);
+ }
+}
+//! [5]
+
+//! [6]
+void MainWindow::save()
+{
+ QString content = centralWidget->plainTextEdit->toPlainText();
+ QString fileName = QFileDialog::getSaveFileName(this);
+
+ if (!fileName.isEmpty()) {
+ // save to file
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QTextStream in(&file);
+ in << content;
+ }
+}
+//! [6]
+
+//! [7]
+void MainWindow::updateTextEdit()
+{
+ QWebFrame *mainFrame = centralWidget->webView->page()->mainFrame();
+ QString frameText = mainFrame->toHtml();
+ centralWidget->plainTextEdit->setPlainText(frameText);
+}
+//! [7]
+
+//! [8]
+void MainWindow::setStartupText()
+{
+ QString string = "<html><body><h1>HTML Previewer</h1>"
+ " <p>This example shows you how to use QWebView to"
+ " preview HTML data written in a QPlainTextEdit.</p>"
+ " </body></html>";
+ centralWidget->webView->setHtml(string);
+}
+//! [8]
diff --git a/examples/webkit/previewer/mainwindow.h b/examples/webkit/previewer/mainwindow.h
new file mode 100644
index 0000000000..3a0a4b15b7
--- /dev/null
+++ b/examples/webkit/previewer/mainwindow.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include "previewer.h"
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void open();
+ void openUrl();
+ void save();
+ void about();
+ void updateTextEdit();
+//! [0]
+
+//! [1]
+private:
+ Previewer *centralWidget;
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QAction *openAct;
+ QAction *openUrlAct;
+ QAction *saveAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+
+ void createActions();
+ void createMenus();
+ void setStartupText();
+};
+//! [1]
+
+#endif
diff --git a/examples/webkit/previewer/previewer.cpp b/examples/webkit/previewer/previewer.cpp
new file mode 100644
index 0000000000..51419d7869
--- /dev/null
+++ b/examples/webkit/previewer/previewer.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "previewer.h"
+
+//! [0]
+Previewer::Previewer(QWidget *parent)
+ : QWidget(parent)
+{
+ setupUi(this);
+}
+//! [0]
+
+void Previewer::setBaseUrl(const QUrl &url)
+{
+ baseUrl = url;
+}
+
+//! [1]
+void Previewer::on_previewButton_clicked()
+{
+ // Update the contents in web viewer
+ QString text = plainTextEdit->toPlainText();
+ webView->setHtml(text, baseUrl);
+}
+//! [1]
diff --git a/examples/webkit/previewer/previewer.h b/examples/webkit/previewer/previewer.h
new file mode 100644
index 0000000000..ae70f9f598
--- /dev/null
+++ b/examples/webkit/previewer/previewer.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PREVIEWER_H
+#define PREVIEWER_H
+
+#include "ui_previewer.h"
+
+//! [0]
+class Previewer : public QWidget, public Ui::Form
+{
+ Q_OBJECT
+
+public:
+ Previewer(QWidget *parent = 0);
+
+ void setBaseUrl(const QUrl &url);
+
+public slots:
+ void on_previewButton_clicked();
+
+private:
+ QUrl baseUrl;
+};
+//! [0]
+
+#endif
diff --git a/examples/webkit/previewer/previewer.pro b/examples/webkit/previewer/previewer.pro
new file mode 100644
index 0000000000..4c8a09d6ff
--- /dev/null
+++ b/examples/webkit/previewer/previewer.pro
@@ -0,0 +1,15 @@
+QT += webkit
+HEADERS = previewer.h \
+ mainwindow.h
+SOURCES = main.cpp \
+ previewer.cpp \
+ mainwindow.cpp
+FORMS = previewer.ui
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/webkit/previewer
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/previewer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/webkit/previewer/previewer.ui b/examples/webkit/previewer/previewer.ui
new file mode 100644
index 0000000000..d4c9992b04
--- /dev/null
+++ b/examples/webkit/previewer/previewer.ui
@@ -0,0 +1,99 @@
+<ui version="4.0" >
+ <class>Form</class>
+ <widget class="QWidget" name="Form" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>911</width>
+ <height>688</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_4" >
+ <item>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QGroupBox" name="editorBox" >
+ <property name="title" >
+ <string>HTML Editor</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <widget class="QPlainTextEdit" name="plainTextEdit" />
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QPushButton" name="clearButton" >
+ <property name="text" >
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="previewButton" >
+ <property name="text" >
+ <string>Preview</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QGroupBox" name="previewerBox" >
+ <property name="title" >
+ <string>HTML Preview</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_3" >
+ <item>
+ <widget class="QWebView" name="webView" >
+ <property name="url" >
+ <url>
+ <string>about:blank</string>
+ </url>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QWebView</class>
+ <extends>QWidget</extends>
+ <header>QtWebKit/QWebView</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>clearButton</sender>
+ <signal>clicked()</signal>
+ <receiver>plainTextEdit</receiver>
+ <slot>clear()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>56</x>
+ <y>653</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>98</x>
+ <y>551</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/webkit/webkit.pro b/examples/webkit/webkit.pro
new file mode 100644
index 0000000000..6e26d36035
--- /dev/null
+++ b/examples/webkit/webkit.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS += formextractor \
+ previewer
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/webkit
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS webkit.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/webkit
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
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..5856ec9c91
--- /dev/null
+++ b/examples/widgets/analogclock/analogclock.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4a322195ba
--- /dev/null
+++ b/examples/widgets/analogclock/analogclock.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..9865a1134b
--- /dev/null
+++ b/examples/widgets/analogclock/analogclock.pro
@@ -0,0 +1,13 @@
+HEADERS = analogclock.h
+SOURCES = analogclock.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/analogclock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS analogclock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/analogclock
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000A64F \ No newline at end of file
diff --git a/examples/widgets/analogclock/main.cpp b/examples/widgets/analogclock/main.cpp
new file mode 100644
index 0000000000..e8fa08b2d1
--- /dev/null
+++ b/examples/widgets/analogclock/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..e77442ef3f
--- /dev/null
+++ b/examples/widgets/calculator/button.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5637e6b35c
--- /dev/null
+++ b/examples/widgets/calculator/button.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..9c2ef4a329
--- /dev/null
+++ b/examples/widgets/calculator/calculator.cpp
@@ -0,0 +1,398 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4955c2869a
--- /dev/null
+++ b/examples/widgets/calculator/calculator.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..178f43e77c
--- /dev/null
+++ b/examples/widgets/calculator/calculator.pro
@@ -0,0 +1,15 @@
+HEADERS = button.h \
+ calculator.h
+SOURCES = button.cpp \
+ calculator.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/calculator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calculator.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/calculator
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C602 \ No newline at end of file
diff --git a/examples/widgets/calculator/main.cpp b/examples/widgets/calculator/main.cpp
new file mode 100644
index 0000000000..ddb0028bca
--- /dev/null
+++ b/examples/widgets/calculator/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..63c154b5e4
--- /dev/null
+++ b/examples/widgets/calendarwidget/calendarwidget.pro
@@ -0,0 +1,13 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/calendarwidget
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calendarwidget.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/calendarwidget
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C603 \ No newline at end of file
diff --git a/examples/widgets/calendarwidget/main.cpp b/examples/widgets/calendarwidget/main.cpp
new file mode 100644
index 0000000000..a2fa3994ba
--- /dev/null
+++ b/examples/widgets/calendarwidget/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..613a30af3d
--- /dev/null
+++ b/examples/widgets/calendarwidget/window.cpp
@@ -0,0 +1,462 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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()
+{
+ QTextCharFormat mayFirstFormat;
+ if (mayFirstCheckBox->isChecked())
+ mayFirstFormat.setForeground(Qt::red);
+
+ QTextCharFormat firstFridayFormat;
+ if (firstFridayCheckBox->isChecked())
+ firstFridayFormat.setForeground(Qt::blue);
+
+ QDate date(calendar->yearShown(), calendar->monthShown(), 1);
+
+ calendar->setDateTextFormat(QDate(date.year(), 5, 1), mayFirstFormat);
+
+ date.setDate(date.year(), date.month(), 1);
+ while (date.dayOfWeek() != Qt::Friday)
+ date = date.addDays(1);
+ calendar->setDateTextFormat(date, firstFridayFormat);
+}
+//! [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(const QDate &)),
+ calendar, SLOT(setSelectedDate(const QDate &)));
+ connect(calendar, SIGNAL(selectionChanged()),
+ this, SLOT(selectedDateChanged()));
+ connect(minimumDateEdit, SIGNAL(dateChanged(const QDate &)),
+ this, SLOT(minimumDateChanged(const QDate &)));
+ connect(maximumDateEdit, SIGNAL(dateChanged(const QDate &)),
+ this, SLOT(maximumDateChanged(const 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(const 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..a483cf553b
--- /dev/null
+++ b/examples/widgets/calendarwidget/window.h
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..97632875b9
--- /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]/widgets/charactermap
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS charactermap.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/charactermap
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/charactermap/characterwidget.cpp b/examples/widgets/charactermap/characterwidget.cpp
new file mode 100644
index 0000000000..3409169bf4
--- /dev/null
+++ b/examples/widgets/charactermap/characterwidget.cpp
@@ -0,0 +1,178 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..aa95963eba
--- /dev/null
+++ b/examples/widgets/charactermap/characterwidget.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..1d51376c06
--- /dev/null
+++ b/examples/widgets/charactermap/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..a1e206b38d
--- /dev/null
+++ b/examples/widgets/charactermap/mainwindow.cpp
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QFont &)),
+ this, SLOT(findStyles(const QFont &)));
+ connect(fontCombo, SIGNAL(currentFontChanged(const QFont &)),
+ this, SLOT(findSizes(const QFont &)));
+ connect(fontCombo, SIGNAL(currentFontChanged(const QFont &)),
+ characterWidget, SLOT(updateFont(const QFont &)));
+ connect(sizeCombo, SIGNAL(currentIndexChanged(const QString &)),
+ characterWidget, SLOT(updateSize(const QString &)));
+ connect(styleCombo, SIGNAL(currentIndexChanged(const QString &)),
+ characterWidget, SLOT(updateStyle(const QString &)));
+//! [4] //! [5]
+ connect(characterWidget, SIGNAL(characterSelected(const QString &)),
+ this, SLOT(insertCharacter(const 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..3f3208cd68
--- /dev/null
+++ b/examples/widgets/charactermap/mainwindow.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <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..b855c7a8cf
--- /dev/null
+++ b/examples/widgets/codeeditor/codeeditor.cpp
@@ -0,0 +1,171 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QRect &, int)), this, SLOT(updateLineNumberArea(const 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..51ecf11fc8
--- /dev/null
+++ b/examples/widgets/codeeditor/codeeditor.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..a94a5e054a
--- /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]/widgets/codeeditor
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/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..a8b26c9657
--- /dev/null
+++ b/examples/widgets/codeeditor/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5bc9292923
--- /dev/null
+++ b/examples/widgets/digitalclock/digitalclock.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4bf26bc1b9
--- /dev/null
+++ b/examples/widgets/digitalclock/digitalclock.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b7c8e09f1b
--- /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]/widgets/digitalclock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS digitalclock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/digitalclock
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/digitalclock/main.cpp b/examples/widgets/digitalclock/main.cpp
new file mode 100644
index 0000000000..9e7e16d464
--- /dev/null
+++ b/examples/widgets/digitalclock/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..8d09f5f3b4
--- /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]/widgets/groupbox
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS groupbox.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/groupbox
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/groupbox/main.cpp b/examples/widgets/groupbox/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/widgets/groupbox/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..8acc307728
--- /dev/null
+++ b/examples/widgets/groupbox/window.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..9f196fd23d
--- /dev/null
+++ b/examples/widgets/groupbox/window.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d80d41d963
--- /dev/null
+++ b/examples/widgets/icons/iconpreviewarea.cpp
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..9b915a483d
--- /dev/null
+++ b/examples/widgets/icons/iconpreviewarea.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ea9c848573
--- /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]/widgets/icons
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS icons.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/icons
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+wince*: {
+ imageFiles.sources = 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..22f45e9cf9
--- /dev/null
+++ b/examples/widgets/icons/iconsizespinbox.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..ea84dc798d
--- /dev/null
+++ b/examples/widgets/icons/iconsizespinbox.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..e8e79b3eff
--- /dev/null
+++ b/examples/widgets/icons/imagedelegate.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..638c0ebe41
--- /dev/null
+++ b/examples/widgets/icons/imagedelegate.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..4856752c8c
--- /dev/null
+++ b/examples/widgets/icons/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..00ce8b01e7
--- /dev/null
+++ b/examples/widgets/icons/mainwindow.cpp
@@ -0,0 +1,443 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+Q"));
+ 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..3494359d10
--- /dev/null
+++ b/examples/widgets/icons/mainwindow.h
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..39d1b3554b
--- /dev/null
+++ b/examples/widgets/imageviewer/imageviewer.cpp
@@ -0,0 +1,278 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..b84f7d577a
--- /dev/null
+++ b/examples/widgets/imageviewer/imageviewer.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..597d95bc3f
--- /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]/widgets/imageviewer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS imageviewer.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/imageviewer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..090580c674
--- /dev/null
+++ b/examples/widgets/imageviewer/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..534714805c
--- /dev/null
+++ b/examples/widgets/lineedits/lineedits.pro
@@ -0,0 +1,13 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/lineedits
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS lineedits.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/lineedits
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C604 \ No newline at end of file
diff --git a/examples/widgets/lineedits/main.cpp b/examples/widgets/lineedits/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/widgets/lineedits/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..13acffdfca
--- /dev/null
+++ b/examples/widgets/lineedits/window.cpp
@@ -0,0 +1,257 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..2d10d78765
--- /dev/null
+++ b/examples/widgets/lineedits/window.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..50bec7331f
--- /dev/null
+++ b/examples/widgets/movie/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..25f1c282f7
--- /dev/null
+++ b/examples/widgets/movie/movie.pro
@@ -0,0 +1,11 @@
+HEADERS = movieplayer.h
+SOURCES = main.cpp \
+ movieplayer.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie
+sources.files = $$SOURCES $$HEADERS $$RESOURCES movie.pro movies
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/movie/movieplayer.cpp b/examples/widgets/movie/movieplayer.cpp
new file mode 100644
index 0000000000..1ffc233c7e
--- /dev/null
+++ b/examples/widgets/movie/movieplayer.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..123c2e248b
--- /dev/null
+++ b/examples/widgets/movie/movieplayer.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..1d51376c06
--- /dev/null
+++ b/examples/widgets/scribble/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..ad1a837b7e
--- /dev/null
+++ b/examples/widgets/scribble/mainwindow.cpp
@@ -0,0 +1,251 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->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()));
+
+ 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..0c3b2a40e3
--- /dev/null
+++ b/examples/widgets/scribble/mainwindow.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..a9190f7664
--- /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]/widgets/scribble
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS scribble.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/scribble
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/scribble/scribblearea.cpp b/examples/widgets/scribble/scribblearea.cpp
new file mode 100644
index 0000000000..0d10fcdeda
--- /dev/null
+++ b/examples/widgets/scribble/scribblearea.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+ painter.drawImage(QPoint(0, 0), image);
+}
+//! [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..afa3cbc418
--- /dev/null
+++ b/examples/widgets/scribble/scribblearea.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..889aac1f2f
--- /dev/null
+++ b/examples/widgets/shapedclock/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..9b8a282bb6
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..1de52e78e6
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..c4d48f6d84
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.pro
@@ -0,0 +1,13 @@
+HEADERS = shapedclock.h
+SOURCES = shapedclock.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/shapedclock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS shapedclock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/shapedclock
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C605 \ No newline at end of file
diff --git a/examples/widgets/sliders/main.cpp b/examples/widgets/sliders/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/widgets/sliders/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..742fc27309
--- /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]/widgets/sliders
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sliders.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/sliders
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/sliders/slidersgroup.cpp b/examples/widgets/sliders/slidersgroup.cpp
new file mode 100644
index 0000000000..9a0b98bed4
--- /dev/null
+++ b/examples/widgets/sliders/slidersgroup.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..1f2ea8256e
--- /dev/null
+++ b/examples/widgets/sliders/slidersgroup.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..f74af74617
--- /dev/null
+++ b/examples/widgets/sliders/window.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..e8854fb623
--- /dev/null
+++ b/examples/widgets/sliders/window.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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/spinboxes/main.cpp b/examples/widgets/spinboxes/main.cpp
new file mode 100644
index 0000000000..fa8b0abb9d
--- /dev/null
+++ b/examples/widgets/spinboxes/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..b859ab7330
--- /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]/widgets/spinboxes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spinboxes.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/spinboxes
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/spinboxes/window.cpp b/examples/widgets/spinboxes/window.cpp
new file mode 100644
index 0000000000..0dae9c5d96
--- /dev/null
+++ b/examples/widgets/spinboxes/window.cpp
@@ -0,0 +1,252 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QString &)),
+ this, SLOT(setFormatString(const 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..68055f66d3
--- /dev/null
+++ b/examples/widgets/spinboxes/window.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..8998858757
--- /dev/null
+++ b/examples/widgets/styles/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..1be5db03cf
--- /dev/null
+++ b/examples/widgets/styles/norwegianwoodstyle.cpp
@@ -0,0 +1,331 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..07c77977e8
--- /dev/null
+++ b/examples/widgets/styles/norwegianwoodstyle.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..8918d21f39
--- /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]/widgets/styles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS styles.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/styles
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..9a071a64ed
--- /dev/null
+++ b/examples/widgets/styles/widgetgallery.cpp
@@ -0,0 +1,276 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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(const QString &)),
+//! [1] //! [2]
+ this, SLOT(changeStyle(const 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..f9f172398c
--- /dev/null
+++ b/examples/widgets/styles/widgetgallery.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..931a89be8c
--- /dev/null
+++ b/examples/widgets/stylesheet/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..a1307a83b8
--- /dev/null
+++ b/examples/widgets/stylesheet/mainwindow.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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://doc.trolltech.com/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..eedca888af
--- /dev/null
+++ b/examples/widgets/stylesheet/mainwindow.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <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..740d37bbd4
--- /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 &amp;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="styleSheet" >
+ <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..71dfc6d1dd
--- /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]/widgets/stylesheet
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro images layouts qss
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/stylesheet
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..12104158a3
--- /dev/null
+++ b/examples/widgets/stylesheet/stylesheeteditor.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..bd90f9e28a
--- /dev/null
+++ b/examples/widgets/stylesheet/stylesheeteditor.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..15043a61fb
--- /dev/null
+++ b/examples/widgets/tablet/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..56a10cd769
--- /dev/null
+++ b/examples/widgets/tablet/mainwindow.cpp
@@ -0,0 +1,275 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+X"));
+ connect(exitAction, SIGNAL(triggered()),
+ this, SLOT(close()));
+
+ loadAction = new QAction(tr("&Open..."), this);
+ loadAction->setShortcut(tr("Ctrl+O"));
+ connect(loadAction, SIGNAL(triggered()),
+ this, SLOT(loadAct()));
+
+ saveAction = new QAction(tr("&Save As..."), this);
+ saveAction->setShortcut(tr("Ctrl+S"));
+ 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..85be425ae1
--- /dev/null
+++ b/examples/widgets/tablet/mainwindow.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..ee25888942
--- /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]/widgets/tablet
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tablet.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/tablet
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/tablet/tabletapplication.cpp b/examples/widgets/tablet/tabletapplication.cpp
new file mode 100644
index 0000000000..c318b85a40
--- /dev/null
+++ b/examples/widgets/tablet/tabletapplication.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..acbaa50695
--- /dev/null
+++ b/examples/widgets/tablet/tabletapplication.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..dc42c3cef9
--- /dev/null
+++ b/examples/widgets/tablet/tabletcanvas.cpp
@@ -0,0 +1,257 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <math.h>
+
+#include "tabletcanvas.h"
+
+//! [0]
+TabletCanvas::TabletCanvas()
+{
+ resize(500, 500);
+ myBrush = QBrush();
+ myPen = QPen();
+ initImage();
+ setAutoFillBackground(true);
+ deviceDown = false;
+ myColor = Qt::red;
+ myTabletDevice = QTabletEvent::Stylus;
+ alphaChannelType = NoAlpha;
+ colorSaturationType = NoSaturation;
+ lineWidthType = LineWidthPressure;
+}
+
+void TabletCanvas::initImage()
+{
+ QImage newImage = QImage(width(), height(), QImage::Format_ARGB32);
+ QPainter painter(&newImage);
+ painter.fillRect(0, 0, newImage.width(), newImage.height(), Qt::white);
+ if (!image.isNull())
+ painter.drawImage(0, 0, image);
+ painter.end();
+ image = newImage;
+}
+//! [0]
+
+//! [1]
+bool TabletCanvas::saveImage(const QString &file)
+{
+ return image.save(file);
+}
+//! [1]
+
+//! [2]
+bool TabletCanvas::loadImage(const QString &file)
+{
+ bool success = image.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;
+ 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(&image);
+ paintImage(painter, event);
+ }
+ break;
+ default:
+ break;
+ }
+ update();
+}
+//! [3]
+
+//! [4]
+void TabletCanvas::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.drawImage(QPoint(0, 0), image);
+}
+//! [4]
+
+//! [5]
+void TabletCanvas::paintImage(QPainter &painter, QTabletEvent *event)
+{
+ QPoint brushAdjust(10, 10);
+
+ switch (myTabletDevice) {
+ case QTabletEvent::Stylus:
+ painter.setBrush(myBrush);
+ painter.setPen(myPen);
+ painter.drawLine(polyLine[1], event->pos());
+ break;
+ 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:
+ qWarning("This input device is not supported by the example.");
+ break;
+ default:
+ qWarning("Unknown tablet device.");
+ }
+}
+//! [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 *event)
+{
+ initImage();
+ 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..90eb1db135
--- /dev/null
+++ b/examples/widgets/tablet/tabletcanvas.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TABLETCANVAS_H
+#define TABLETCANVAS_H
+
+#include <QWidget>
+#include <QImage>
+#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 initImage();
+ void paintImage(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;
+
+ QImage image;
+ 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..c9bf49a869
--- /dev/null
+++ b/examples/widgets/tetrix/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..2223b8619f
--- /dev/null
+++ b/examples/widgets/tetrix/tetrix.pro
@@ -0,0 +1,17 @@
+HEADERS = tetrixboard.h \
+ tetrixpiece.h \
+ tetrixwindow.h
+SOURCES = main.cpp \
+ tetrixboard.cpp \
+ tetrixpiece.cpp \
+ tetrixwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tetrix
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tetrix.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/tetrix
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C606 \ No newline at end of file
diff --git a/examples/widgets/tetrix/tetrixboard.cpp b/examples/widgets/tetrix/tetrixboard.cpp
new file mode 100644
index 0000000000..e8ef4bfc52
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixboard.cpp
@@ -0,0 +1,409 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5d71125443
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixboard.h
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..eeaab532f2
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixpiece.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..cbf55837e6
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixpiece.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..98e460a5dd
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixwindow.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..ad22b0ffcc
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..2f4c713331
--- /dev/null
+++ b/examples/widgets/tooltips/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..a8d8f3aca7
--- /dev/null
+++ b/examples/widgets/tooltips/shapeitem.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..d41b9908c6
--- /dev/null
+++ b/examples/widgets/tooltips/shapeitem.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..995da3e075
--- /dev/null
+++ b/examples/widgets/tooltips/sortingbox.cpp
@@ -0,0 +1,302 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..fb565cdc79
--- /dev/null
+++ b/examples/widgets/tooltips/sortingbox.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..0eca4c8a19
--- /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]/widgets/tooltips
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tooltips.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/tooltips
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..9213755b3c
--- /dev/null
+++ b/examples/widgets/validators/ledwidget.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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..08992f97f2
--- /dev/null
+++ b/examples/widgets/validators/ledwidget.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..b725d2666d
--- /dev/null
+++ b/examples/widgets/validators/localeselector.cpp
@@ -0,0 +1,313 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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, qVariantFromValue(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 = qVariantValue<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..763b58b4af
--- /dev/null
+++ b/examples/widgets/validators/localeselector.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..6822b62dc0
--- /dev/null
+++ b/examples/widgets/validators/main.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..d7f9dde851
--- /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]/widgets/validators
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/validators
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..f05b96fbe0
--- /dev/null
+++ b/examples/widgets/validators/validators.ui
@@ -0,0 +1,467 @@
+<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>668</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</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="LocaleSelector" name="localeSelector" />
+ </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>
+ <item>
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="title" >
+ <string>QIntValidator</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>
+ <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 vsizetype="Fixed" hsizetype="Minimum" >
+ <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 vsizetype="Fixed" hsizetype="Minimum" >
+ <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="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="LEDWidget" name="ledWidget" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <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" >
+ <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="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>
+ <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 vsizetype="Fixed" hsizetype="Minimum" >
+ <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 vsizetype="Fixed" hsizetype="Minimum" >
+ <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="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</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" >
+ <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" >
+ <size>
+ <width>20</width>
+ <height>111</height>
+ </size>
+ </property>
+ </spacer>
+ </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>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..018cc0c449
--- /dev/null
+++ b/examples/widgets/widgets.pro
@@ -0,0 +1,42 @@
+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
+
+contains(styles, motif): SUBDIRS += styles
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS widgets.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/widgets/wiggly/dialog.cpp b/examples/widgets/wiggly/dialog.cpp
new file mode 100644
index 0000000000..4df6aac906
--- /dev/null
+++ b/examples/widgets/wiggly/dialog.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+
+ 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..70ab11fed9
--- /dev/null
+++ b/examples/widgets/wiggly/dialog.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..ef6ec4d7d0
--- /dev/null
+++ b/examples/widgets/wiggly/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ bool smallScreen = false;
+ for (int i=0; i<argc; i++)
+ if (QString(argv[i]) == "-small-screen")
+ smallScreen = true;
+ 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..42407655ba
--- /dev/null
+++ b/examples/widgets/wiggly/wiggly.pro
@@ -0,0 +1,15 @@
+HEADERS = wigglywidget.h \
+ dialog.h
+SOURCES = wigglywidget.cpp \
+ dialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/wiggly
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS wiggly.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/wiggly
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C607 \ No newline at end of file
diff --git a/examples/widgets/wiggly/wigglywidget.cpp b/examples/widgets/wiggly/wigglywidget.cpp
new file mode 100644
index 0000000000..e89fdde38d
--- /dev/null
+++ b/examples/widgets/wiggly/wigglywidget.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..8b6a137667
--- /dev/null
+++ b/examples/widgets/wiggly/wigglywidget.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..075bcb3fdb
--- /dev/null
+++ b/examples/widgets/windowflags/controllerwindow.cpp
@@ -0,0 +1,221 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ 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..467ab7d2a2
--- /dev/null
+++ b/examples/widgets/windowflags/controllerwindow.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..338da5663f
--- /dev/null
+++ b/examples/widgets/windowflags/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "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..6fbd654510
--- /dev/null
+++ b/examples/widgets/windowflags/previewwindow.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..22ec64914a
--- /dev/null
+++ b/examples/widgets/windowflags/previewwindow.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..007c10a9b4
--- /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]/widgets/windowflags
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS windowflags.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/windowflags
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.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..f38321f45c
--- /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]/xml/dombookmarks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS dombookmarks.pro *.xbel
+sources.path = $$[QT_INSTALL_EXAMPLES]/xml/dombookmarks
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+wince*: {
+ addFiles.sources = 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..d6a12c68e9
--- /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://doc.trolltech.com/2.3/">
+ <title>Qt 2.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/3.3/">
+ <title>Qt 3.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 Reference</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.com/">
+ <title>Trolltech 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..597880affc
--- /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>Trolltech 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://doc.trolltech.com/qq/">
+ <title>Qt Quarterly</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.com/">
+ <title>Trolltech's home page</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 documentation</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.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..3f0a207265
--- /dev/null
+++ b/examples/xml/dombookmarks/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..6b0c1010da
--- /dev/null
+++ b/examples/xml/dombookmarks/mainwindow.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcut(tr("Ctrl+S"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ 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..cf30a3ec76
--- /dev/null
+++ b/examples/xml/dombookmarks/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..37e8bb2983
--- /dev/null
+++ b/examples/xml/dombookmarks/xbeltree.cpp
@@ -0,0 +1,187 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4f2d304f64
--- /dev/null
+++ b/examples/xml/dombookmarks/xbeltree.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d8285184d4
--- /dev/null
+++ b/examples/xml/htmlinfo/htmlinfo.pro
@@ -0,0 +1,18 @@
+SOURCES += main.cpp
+QT -= gui
+
+wince*|symbian:{
+ htmlfiles.sources = *.html
+ htmlfiles.path = .
+ DEPLOYMENT += htmlfiles
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xml/htmlinfo
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.html htmlinfo.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/xml/htmlinfo
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C609
diff --git a/examples/xml/htmlinfo/main.cpp b/examples/xml/htmlinfo/main.cpp
new file mode 100644
index 0000000000..fcf480b11f
--- /dev/null
+++ b/examples/xml/htmlinfo/main.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $TROLLTECH_DUAL_LICENSE$
+**
+****************************************************************************/
+
+#include <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)
+{
+ // intialize 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..87ccf36e27
--- /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.trolltech.com/">developer blogs</a></p>
+ <p>And the last paragraph. Or our <a href="http://doc.trolltech.com/">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..0c9b275815
--- /dev/null
+++ b/examples/xml/rsslisting/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+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..9212c110ae
--- /dev/null
+++ b/examples/xml/rsslisting/rsslisting.cpp
@@ -0,0 +1,239 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+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, two push buttons, and a
+ list view widget. The line edit is used for entering the URLs of news
+ sources; the push buttons start and abort the process of reading the
+ news.
+*/
+
+RSSListing::RSSListing(QWidget *parent)
+ : QWidget(parent)
+{
+ lineEdit = new QLineEdit(this);
+ lineEdit->setText("http://labs.trolltech.com/blogs/feed");
+
+ fetchButton = new QPushButton(tr("Fetch"), this);
+ abortButton = new QPushButton(tr("Abort"), this);
+ abortButton->setEnabled(false);
+
+ 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(&http, SIGNAL(readyRead(const QHttpResponseHeader &)),
+ this, SLOT(readData(const QHttpResponseHeader &)));
+
+ connect(&http, SIGNAL(requestFinished(int, bool)),
+ this, SLOT(finished(int, bool)));
+
+ connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch()));
+ connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch()));
+ connect(abortButton, SIGNAL(clicked()), &http, SLOT(abort()));
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ QHBoxLayout *hboxLayout = new QHBoxLayout;
+
+ hboxLayout->addWidget(lineEdit);
+ hboxLayout->addWidget(fetchButton);
+ hboxLayout->addWidget(abortButton);
+
+ layout->addLayout(hboxLayout);
+ layout->addWidget(treeWidget);
+
+ setWindowTitle(tr("RSS listing example"));
+ resize(640,480);
+}
+
+/*
+ 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, and the abort button is enabled to allow
+ the user to interrupt processing. 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.
+
+ The HTTP handler is supplied with the raw contents of the line edit and
+ a fetch is initiated. We keep the ID value returned by the HTTP handler
+ for future reference.
+*/
+
+void RSSListing::fetch()
+{
+ lineEdit->setReadOnly(true);
+ fetchButton->setEnabled(false);
+ abortButton->setEnabled(true);
+ treeWidget->clear();
+
+ xml.clear();
+
+ QUrl url(lineEdit->text());
+
+ http.setHost(url.host());
+ connectionId = http.get(url.path());
+}
+
+/*
+ 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.
+
+ If parsing fails for any reason, we abort the fetch.
+*/
+
+void RSSListing::readData(const QHttpResponseHeader &resp)
+{
+ if (resp.statusCode() != 200)
+ http.abort();
+ else {
+ xml.addData(http.readAll());
+ 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(int id, bool error)
+{
+ if (error) {
+ qWarning("Received error during HTTP fetch.");
+ lineEdit->setReadOnly(false);
+ abortButton->setEnabled(false);
+ fetchButton->setEnabled(true);
+ }
+ else if (id == connectionId) {
+ lineEdit->setReadOnly(false);
+ abortButton->setEnabled(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();
+ http.abort();
+ }
+}
+
+/*
+ Open the link in the browser
+*/
+void RSSListing::itemActivated(QTreeWidgetItem * item)
+{
+ QDesktopServices::openUrl(QUrl(item->text(1)));
+}
diff --git a/examples/xml/rsslisting/rsslisting.h b/examples/xml/rsslisting/rsslisting.h
new file mode 100644
index 0000000000..f0007deaeb
--- /dev/null
+++ b/examples/xml/rsslisting/rsslisting.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RSSLISTING_H
+#define RSSLISTING_H
+
+#include <QHttp>
+#include <QWidget>
+#include <QBuffer>
+#include <QXmlStreamReader>
+
+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(int id, bool error);
+ void readData(const QHttpResponseHeader &);
+ void itemActivated(QTreeWidgetItem * item);
+
+private:
+ void parseXml();
+
+ QXmlStreamReader xml;
+ QString currentTag;
+ QString linkString;
+ QString titleString;
+
+ QHttp http;
+ int connectionId;
+
+ QLineEdit *lineEdit;
+ QTreeWidget *treeWidget;
+ QPushButton *abortButton;
+ QPushButton *fetchButton;
+};
+
+#endif
+
diff --git a/examples/xml/rsslisting/rsslisting.pro b/examples/xml/rsslisting/rsslisting.pro
new file mode 100644
index 0000000000..c0a1ad33ed
--- /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]/xml/rsslisting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS rsslisting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/xml/rsslisting
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
diff --git a/examples/xml/saxbookmarks/frank.xbel b/examples/xml/saxbookmarks/frank.xbel
new file mode 100644
index 0000000000..d6a12c68e9
--- /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://doc.trolltech.com/2.3/">
+ <title>Qt 2.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/3.3/">
+ <title>Qt 3.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 Reference</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.com/">
+ <title>Trolltech 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/frankf.xbel b/examples/xml/saxbookmarks/frankf.xbel
new file mode 100644
index 0000000000..07a9463677
--- /dev/null
+++ b/examples/xml/saxbookmarks/frankf.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://doc.trolltech.com/2.3/">
+ <title>Qt 2.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/3.3/">
+ <title>Qt 3.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 Reference</title>
+ </bookmark>
+ <bookmark href="http://www.trolltech.com/">
+ <title>Trolltech 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..597880affc
--- /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>Trolltech 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://doc.trolltech.com/qq/">
+ <title>Qt Quarterly</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.com/">
+ <title>Trolltech's home page</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 documentation</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.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/jenniferf.xbel b/examples/xml/saxbookmarks/jenniferf.xbel
new file mode 100644
index 0000000000..1f7810b94b
--- /dev/null
+++ b/examples/xml/saxbookmarks/jenniferf.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>Trolltech 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://doc.trolltech.com/qq/">
+ <title>Qt Quarterly</title>
+ </bookmark>
+ <bookmark href="http://www.trolltech.com/">
+ <title>Trolltech's home page</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 documentation</title>
+ </bookmark>
+ <bookmark href="http://www.trolltech.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..31c2246f07
--- /dev/null
+++ b/examples/xml/saxbookmarks/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow 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..4bdd1f0546
--- /dev/null
+++ b/examples/xml/saxbookmarks/mainwindow.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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)
+ QDir::setCurrent("/Data/qt/saxbookmarks");
+#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->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcut(tr("Ctrl+S"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ 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..2c70d4ae4a
--- /dev/null
+++ b/examples/xml/saxbookmarks/mainwindow.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..3556c117ef
--- /dev/null
+++ b/examples/xml/saxbookmarks/saxbookmarks.pro
@@ -0,0 +1,29 @@
+HEADERS = mainwindow.h \
+ xbelgenerator.h \
+ xbelhandler.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ xbelgenerator.cpp \
+ xbelhandler.cpp
+QT += xml
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xml/saxbookmarks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS saxbookmarks.pro *.xbel
+sources.path = $$[QT_INSTALL_EXAMPLES]/xml/saxbookmarks
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+wince*: {
+ addFiles.sources = frank.xbel jennifer.xbel
+ addFiles.path = \My Documents
+ DEPLOYMENT += addFiles
+}
+
+symbian: {
+ TARGET.UID3 = 0xA000C60A
+ addFiles.sources = frank.xbel jennifer.xbel
+ addFiles.path = /data/qt/saxbookmarks
+ DEPLOYMENT += addFiles
+} \ No newline at end of file
diff --git a/examples/xml/saxbookmarks/xbelgenerator.cpp b/examples/xml/saxbookmarks/xbelgenerator.cpp
new file mode 100644
index 0000000000..cafaf51286
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelgenerator.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..023d626e15
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelgenerator.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..2fdb1fab09
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelhandler.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..5b6c0c03c0
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelhandler.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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..d6a12c68e9
--- /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://doc.trolltech.com/2.3/">
+ <title>Qt 2.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/3.3/">
+ <title>Qt 3.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 Reference</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.com/">
+ <title>Trolltech 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..597880affc
--- /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>Trolltech 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://doc.trolltech.com/qq/">
+ <title>Qt Quarterly</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.com/">
+ <title>Trolltech's home page</title>
+ </bookmark>
+ <bookmark href="http://doc.trolltech.com/4.0/">
+ <title>Qt 4.0 documentation</title>
+ </bookmark>
+ <bookmark href="http://qtsoftware.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..58b5c5e1f5
--- /dev/null
+++ b/examples/xml/streambookmarks/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+//! [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..2136b4bc9c
--- /dev/null
+++ b/examples/xml/streambookmarks/mainwindow.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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 at line %2, column %3:\n%4")
+ .arg(fileName)
+ .arg(reader.lineNumber())
+ .arg(reader.columnNumber())
+ .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->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcut(tr("Ctrl+S"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ 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..8bed33d7ed
--- /dev/null
+++ b/examples/xml/streambookmarks/mainwindow.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+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..f16a02ebaf
--- /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]/xml/streambookmarks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS streambookmarks.pro *.xbel
+sources.path = $$[QT_INSTALL_EXAMPLES]/xml/streambookmarks
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xml/streambookmarks/xbelreader.cpp b/examples/xml/streambookmarks/xbelreader.cpp
new file mode 100644
index 0000000000..561997adb7
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelreader.cpp
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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)
+{
+ setDevice(device);
+
+ while (!atEnd()) {
+ readNext();
+
+ if (isStartElement()) {
+ if (name() == "xbel" && attributes().value("version") == "1.0")
+ readXBEL();
+ else
+ raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
+ }
+ }
+
+ return !error();
+}
+//! [1]
+
+//! [2]
+void XbelReader::readUnknownElement()
+{
+ Q_ASSERT(isStartElement());
+
+ while (!atEnd()) {
+ readNext();
+
+ if (isEndElement())
+ break;
+
+ if (isStartElement())
+ readUnknownElement();
+ }
+}
+//! [2]
+
+//! [3]
+void XbelReader::readXBEL()
+{
+ Q_ASSERT(isStartElement() && name() == "xbel");
+
+ while (!atEnd()) {
+ readNext();
+
+ if (isEndElement())
+ break;
+
+ if (isStartElement()) {
+ if (name() == "folder")
+ readFolder(0);
+ else if (name() == "bookmark")
+ readBookmark(0);
+ else if (name() == "separator")
+ readSeparator(0);
+ else
+ readUnknownElement();
+ }
+ }
+}
+//! [3]
+
+//! [4]
+void XbelReader::readTitle(QTreeWidgetItem *item)
+{
+ Q_ASSERT(isStartElement() && name() == "title");
+
+ QString title = readElementText();
+ item->setText(0, title);
+}
+//! [4]
+
+//! [5]
+void XbelReader::readSeparator(QTreeWidgetItem *item)
+{
+ QTreeWidgetItem *separator = createChildItem(item);
+ separator->setFlags(item->flags() & ~Qt::ItemIsSelectable);
+ separator->setText(0, QString(30, 0xB7));
+ readElementText();
+}
+//! [5]
+
+void XbelReader::readFolder(QTreeWidgetItem *item)
+{
+ Q_ASSERT(isStartElement() && name() == "folder");
+
+ QTreeWidgetItem *folder = createChildItem(item);
+ bool folded = (attributes().value("folded") != "no");
+ treeWidget->setItemExpanded(folder, !folded);
+
+ while (!atEnd()) {
+ readNext();
+
+ if (isEndElement())
+ break;
+
+ if (isStartElement()) {
+ if (name() == "title")
+ readTitle(folder);
+ else if (name() == "folder")
+ readFolder(folder);
+ else if (name() == "bookmark")
+ readBookmark(folder);
+ else if (name() == "separator")
+ readSeparator(folder);
+ else
+ readUnknownElement();
+ }
+ }
+}
+
+void XbelReader::readBookmark(QTreeWidgetItem *item)
+{
+ Q_ASSERT(isStartElement() && 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, attributes().value("href").toString());
+ while (!atEnd()) {
+ readNext();
+
+ if (isEndElement())
+ break;
+
+ if (isStartElement()) {
+ if (name() == "title")
+ readTitle(bookmark);
+ else
+ readUnknownElement();
+ }
+ }
+}
+
+QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item)
+{
+ QTreeWidgetItem *childItem;
+ if (item) {
+ childItem = new QTreeWidgetItem(item);
+ } else {
+ childItem = new QTreeWidgetItem(treeWidget);
+ }
+ childItem->setData(0, Qt::UserRole, name().toString());
+ return childItem;
+}
diff --git a/examples/xml/streambookmarks/xbelreader.h b/examples/xml/streambookmarks/xbelreader.h
new file mode 100644
index 0000000000..dc5eac94be
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelreader.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XBELREADER_H
+#define XBELREADER_H
+
+#include <QIcon>
+#include <QXmlStreamReader>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+//! [0]
+class XbelReader : public QXmlStreamReader
+{
+public:
+//! [1]
+ XbelReader(QTreeWidget *treeWidget);
+//! [1]
+
+ bool read(QIODevice *device);
+
+private:
+//! [2]
+ void readUnknownElement();
+ void readXBEL();
+ void readTitle(QTreeWidgetItem *item);
+ void readSeparator(QTreeWidgetItem *item);
+ void readFolder(QTreeWidgetItem *item);
+ void readBookmark(QTreeWidgetItem *item);
+
+ QTreeWidgetItem *createChildItem(QTreeWidgetItem *item);
+
+ 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..b3ce288dfb
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelwriter.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "xbelwriter.h"
+
+//! [0]
+XbelWriter::XbelWriter(QTreeWidget *treeWidget)
+ : treeWidget(treeWidget)
+{
+ setAutoFormatting(true);
+}
+//! [0]
+
+//! [1]
+bool XbelWriter::writeFile(QIODevice *device)
+{
+ setDevice(device);
+
+ writeStartDocument();
+ writeDTD("<!DOCTYPE xbel>");
+ writeStartElement("xbel");
+ writeAttribute("version", "1.0");
+ for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
+ writeItem(treeWidget->topLevelItem(i));
+
+ 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);
+ writeStartElement(tagName);
+ writeAttribute("folded", folded ? "yes" : "no");
+ writeTextElement("title", item->text(0));
+ for (int i = 0; i < item->childCount(); ++i)
+ writeItem(item->child(i));
+ writeEndElement();
+ } else if (tagName == "bookmark") {
+ writeStartElement(tagName);
+ if (!item->text(1).isEmpty())
+ writeAttribute("href", item->text(1));
+ writeTextElement("title", item->text(0));
+ writeEndElement();
+ } else if (tagName == "separator") {
+ writeEmptyElement(tagName);
+ }
+}
+//! [2]
diff --git a/examples/xml/streambookmarks/xbelwriter.h b/examples/xml/streambookmarks/xbelwriter.h
new file mode 100644
index 0000000000..ec80e054fc
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelwriter.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XBELWRITER_H
+#define XBELWRITER_H
+
+#include <QXmlStreamWriter>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+//! [0]
+class XbelWriter : public QXmlStreamWriter
+{
+public:
+ XbelWriter(QTreeWidget *treeWidget);
+ bool writeFile(QIODevice *device);
+
+private:
+ void writeItem(QTreeWidgetItem *item);
+ QTreeWidget *treeWidget;
+};
+//! [0]
+
+#endif
diff --git a/examples/xml/xml.pro b/examples/xml/xml.pro
new file mode 100644
index 0000000000..2b6415c0cf
--- /dev/null
+++ b/examples/xml/xml.pro
@@ -0,0 +1,17 @@
+TEMPLATE = subdirs
+SUBDIRS = dombookmarks \
+ htmlinfo \
+ rsslisting \
+ saxbookmarks \
+ streambookmarks \
+ xmlstreamlint
+
+symbian: SUBDIRS = htmlinfo saxbookmarks
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xml
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xml.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/xml
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xml/xmlstreamlint/main.cpp b/examples/xml/xmlstreamlint/main.cpp
new file mode 100644
index 0000000000..6063b84433
--- /dev/null
+++ b/examples/xml/xmlstreamlint/main.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <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..4f97387dfc
--- /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]/xml/xmlstreamlint
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xmlstreamlint.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/xml/xmlstreamlint
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/README b/examples/xmlpatterns/README
new file mode 100644
index 0000000000..5d585dc52a
--- /dev/null
+++ b/examples/xmlpatterns/README
@@ -0,0 +1,38 @@
+XQuery queries and XPath expressions can be used in Qt with the
+QtXmlPatterns module.
+
+XQuery is a query language used to query XML in a concise and safe manner.
+
+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/xmlpatterns/filetree/filetree.cpp b/examples/xmlpatterns/filetree/filetree.cpp
new file mode 100644
index 0000000000..6695a965ac
--- /dev/null
+++ b/examples/xmlpatterns/filetree/filetree.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QUrl>
+#include <QtCore/QVariant>
+#include <QtXmlPatterns/QXmlNamePool>
+#include "filetree.h"
+
+/*
+The model has two types of nodes: elements & attributes.
+
+ <directory name="">
+ <file name="">
+ </file>
+ </directory>
+
+ In QXmlNodeModelIndex we store two values. QXmlNodeIndex::data()
+ is treated as a signed int, and it is an index into m_fileInfos
+ unless it is -1, in which case it has no meaning and the value
+ of QXmlNodeModelIndex::additionalData() is a Type name instead.
+ */
+
+/*!
+ The constructor passes \a pool to the base class, then loads an
+ internal vector with an instance of QXmlName for each of the
+ strings "file", "directory", "fileName", "filePath", "size",
+ "mimeType", and "suffix".
+ */
+//! [2]
+FileTree::FileTree(const QXmlNamePool& pool)
+ : QSimpleXmlNodeModel(pool),
+ m_filterAllowAll(QDir::AllEntries |
+ QDir::AllDirs |
+ QDir::NoDotAndDotDot |
+ QDir::Hidden),
+ m_sortFlags(QDir::Name)
+{
+ QXmlNamePool np = namePool();
+ m_names.resize(7);
+ m_names[File] = QXmlName(np, QLatin1String("file"));
+ m_names[Directory] = QXmlName(np, QLatin1String("directory"));
+ m_names[AttributeFileName] = QXmlName(np, QLatin1String("fileName"));
+ m_names[AttributeFilePath] = QXmlName(np, QLatin1String("filePath"));
+ m_names[AttributeSize] = QXmlName(np, QLatin1String("size"));
+ m_names[AttributeMIMEType] = QXmlName(np, QLatin1String("mimeType"));
+ m_names[AttributeSuffix] = QXmlName(np, QLatin1String("suffix"));
+}
+//! [2]
+
+/*!
+ Returns the QXmlNodeModelIndex for the model node representing
+ the directory \a dirName.
+
+ It calls QDir::cleanPath(), because an instance of QFileInfo
+ constructed for a path ending in '/' will return the empty string in
+ fileName(), instead of the directory name.
+*/
+QXmlNodeModelIndex FileTree::nodeFor(const QString& dirName) const
+{
+ QFileInfo dirInfo(QDir::cleanPath(dirName));
+ Q_ASSERT(dirInfo.exists());
+ return toNodeIndex(dirInfo);
+}
+
+/*!
+ Since the value will always be in m_fileInfos, it is safe for
+ us to return a const reference to it.
+ */
+//! [6]
+const QFileInfo&
+FileTree::toFileInfo(const QXmlNodeModelIndex &nodeIndex) const
+{
+ return m_fileInfos.at(nodeIndex.data());
+}
+//! [6]
+
+/*!
+ Returns the model node index for the node specified by the
+ QFileInfo and node Type.
+ */
+//! [1]
+QXmlNodeModelIndex
+FileTree::toNodeIndex(const QFileInfo &fileInfo, Type attributeName) const
+{
+ const int indexOf = m_fileInfos.indexOf(fileInfo);
+
+ if (indexOf == -1) {
+ m_fileInfos.append(fileInfo);
+ return createIndex(m_fileInfos.count()-1, attributeName);
+ }
+ else
+ return createIndex(indexOf, attributeName);
+}
+//! [1]
+
+/*!
+ Returns the model node index for the node specified by the
+ QFileInfo, which must be a Type::File or Type::Directory.
+ */
+//! [0]
+QXmlNodeModelIndex FileTree::toNodeIndex(const QFileInfo &fileInfo) const
+{
+ return toNodeIndex(fileInfo, fileInfo.isDir() ? Directory : File);
+}
+//! [0]
+
+/*!
+ This private helper function is only called by nextFromSimpleAxis().
+ It is called whenever nextFromSimpleAxis() is called with an axis
+ parameter of either \c{PreviousSibling} or \c{NextSibling}.
+ */
+//! [5]
+QXmlNodeModelIndex FileTree::nextSibling(const QXmlNodeModelIndex &nodeIndex,
+ const QFileInfo &fileInfo,
+ qint8 offset) const
+{
+ Q_ASSERT(offset == -1 || offset == 1);
+
+ // Get the context node's parent.
+ const QXmlNodeModelIndex parent(nextFromSimpleAxis(Parent, nodeIndex));
+
+ if (parent.isNull())
+ return QXmlNodeModelIndex();
+
+ // Get the parent's child list.
+ const QFileInfo parentFI(toFileInfo(parent));
+ Q_ASSERT(Type(parent.additionalData()) == Directory);
+ const QFileInfoList siblings(QDir(parentFI.absoluteFilePath()).entryInfoList(QStringList(),
+ m_filterAllowAll,
+ m_sortFlags));
+ Q_ASSERT_X(!siblings.isEmpty(), Q_FUNC_INFO, "Can't happen! We started at a child.");
+
+ // Find the index of the child where we started.
+ const int indexOfMe = siblings.indexOf(fileInfo);
+
+ // Apply the offset.
+ const int siblingIndex = indexOfMe + offset;
+ if (siblingIndex < 0 || siblingIndex > siblings.count() - 1)
+ return QXmlNodeModelIndex();
+ else
+ return toNodeIndex(siblings.at(siblingIndex));
+}
+//! [5]
+
+/*!
+ This function is called by the QtXmlPatterns query engine when it
+ wants to move to the next node in the model. It moves along an \a
+ axis, \e from the node specified by \a nodeIndex.
+
+ This function is usually the one that requires the most design and
+ implementation work, because the implementation depends on the
+ perhaps unique structure of your non-XML data.
+
+ There are \l {QAbstractXmlNodeModel::SimpleAxis} {four values} for
+ \a axis that the implementation must handle, but there are really
+ only two axes, i.e., vertical and horizontal. Two of the four values
+ specify direction on the vertical axis (\c{Parent} and
+ \c{FirstChild}), and the other two values specify direction on the
+ horizontal axis (\c{PreviousSibling} and \c{NextSibling}).
+
+ The typical implementation will be a \c switch statement with
+ a case for each of the four \a axis values.
+ */
+//! [4]
+QXmlNodeModelIndex
+FileTree::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &nodeIndex) const
+{
+ const QFileInfo fi(toFileInfo(nodeIndex));
+ const Type type = Type(nodeIndex.additionalData());
+
+ if (type != File && type != Directory) {
+ Q_ASSERT_X(axis == Parent, Q_FUNC_INFO, "An attribute only has a parent!");
+ return toNodeIndex(fi, Directory);
+ }
+
+ switch (axis) {
+ case Parent:
+ return toNodeIndex(QFileInfo(fi.path()), Directory);
+
+ case FirstChild:
+ {
+ if (type == File) // A file has no children.
+ return QXmlNodeModelIndex();
+ else {
+ Q_ASSERT(type == Directory);
+ Q_ASSERT_X(fi.isDir(), Q_FUNC_INFO, "It isn't really a directory!");
+ const QDir dir(fi.absoluteFilePath());
+ Q_ASSERT(dir.exists());
+
+ const QFileInfoList children(dir.entryInfoList(QStringList(),
+ m_filterAllowAll,
+ m_sortFlags));
+ if (children.isEmpty())
+ return QXmlNodeModelIndex();
+ const QFileInfo firstChild(children.first());
+ return toNodeIndex(firstChild);
+ }
+ }
+
+ case PreviousSibling:
+ return nextSibling(nodeIndex, fi, -1);
+
+ case NextSibling:
+ return nextSibling(nodeIndex, fi, 1);
+ }
+
+ Q_ASSERT_X(false, Q_FUNC_INFO, "Don't ever get here!");
+ return QXmlNodeModelIndex();
+}
+//! [4]
+
+/*!
+ No matter what part of the file system we model (the whole file
+ tree or a subtree), \a node will always have \c{file:///} as
+ the document URI.
+ */
+QUrl FileTree::documentUri(const QXmlNodeModelIndex &node) const
+{
+ Q_UNUSED(node);
+ return QUrl("file:///");
+}
+
+/*!
+ This function returns QXmlNodeModelIndex::Element if \a node
+ is a directory or a file, and QXmlNodeModelIndex::Attribute
+ otherwise.
+ */
+QXmlNodeModelIndex::NodeKind
+FileTree::kind(const QXmlNodeModelIndex &node) const
+{
+ switch (Type(node.additionalData())) {
+ case Directory:
+ case File:
+ return QXmlNodeModelIndex::Element;
+ default:
+ return QXmlNodeModelIndex::Attribute;
+ }
+}
+
+/*!
+ No order is defined for this example, so we always return
+ QXmlNodeModelIndex::Precedes, just to keep everyone happy.
+ */
+QXmlNodeModelIndex::DocumentOrder
+FileTree::compareOrder(const QXmlNodeModelIndex&,
+ const QXmlNodeModelIndex&) const
+{
+ return QXmlNodeModelIndex::Precedes;
+}
+
+/*!
+ Returns the name of \a node. The caller guarantees that \a node is
+ not null and that it is contained in this node model.
+ */
+//! [3]
+QXmlName FileTree::name(const QXmlNodeModelIndex &node) const
+{
+ return m_names.at(node.additionalData());
+}
+//! [3]
+
+/*!
+ Always returns the QXmlNodeModelIndex for the root of the
+ file system, i.e. "/".
+ */
+QXmlNodeModelIndex FileTree::root(const QXmlNodeModelIndex &node) const
+{
+ Q_UNUSED(node);
+ return toNodeIndex(QFileInfo(QLatin1String("/")));
+}
+
+/*!
+ Returns the typed value for \a node, which must be either an
+ attribute or an element. The QVariant returned represents the atomic
+ value of an attribute or the atomic value contained in an element.
+
+ If the QVariant is returned as a default constructed variant,
+ it means that \a node has no typed value.
+ */
+QVariant FileTree::typedValue(const QXmlNodeModelIndex &node) const
+{
+ const QFileInfo &fi = toFileInfo(node);
+
+ switch (Type(node.additionalData())) {
+ case Directory:
+ // deliberate fall through.
+ case File:
+ return QString();
+ case AttributeFileName:
+ return fi.fileName();
+ case AttributeFilePath:
+ return fi.filePath();
+ case AttributeSize:
+ return fi.size();
+ case AttributeMIMEType:
+ {
+ /* We don't have any MIME detection code currently, so return
+ * the most generic one. */
+ return QLatin1String("application/octet-stream");
+ }
+ case AttributeSuffix:
+ return fi.suffix();
+ }
+
+ Q_ASSERT_X(false, Q_FUNC_INFO, "This line should never be reached.");
+ return QString();
+}
+
+/*!
+ Returns the attributes of \a element. The caller guarantees
+ that \a element is an element in this node model.
+ */
+QVector<QXmlNodeModelIndex>
+FileTree::attributes(const QXmlNodeModelIndex &element) const
+{
+ QVector<QXmlNodeModelIndex> result;
+
+ /* Both elements has this attribute. */
+ const QFileInfo &forElement = toFileInfo(element);
+ result.append(toNodeIndex(forElement, AttributeFilePath));
+ result.append(toNodeIndex(forElement, AttributeFileName));
+
+ if (Type(element.additionalData() == File)) {
+ result.append(toNodeIndex(forElement, AttributeSize));
+ result.append(toNodeIndex(forElement, AttributeSuffix));
+ //result.append(toNodeIndex(forElement, AttributeMIMEType));
+ }
+ else {
+ Q_ASSERT(element.additionalData() == Directory);
+ }
+
+ return result;
+}
+
diff --git a/examples/xmlpatterns/filetree/filetree.h b/examples/xmlpatterns/filetree/filetree.h
new file mode 100644
index 0000000000..7c8f3caf07
--- /dev/null
+++ b/examples/xmlpatterns/filetree/filetree.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QFileInfo>
+#include <QtCore/QDir>
+#include <QtCore/QVector>
+#include <QtXmlPatterns/QSimpleXmlNodeModel>
+
+class FileTree : public QSimpleXmlNodeModel
+{
+ public:
+ FileTree(const QXmlNamePool &namePool);
+
+ QXmlNodeModelIndex nodeFor(const QString &fileName) const;
+
+ //! [0]
+ virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex&, const QXmlNodeModelIndex&) const;
+ virtual QXmlName name(const QXmlNodeModelIndex &node) const;
+ virtual QUrl documentUri(const QXmlNodeModelIndex &node) const;
+ virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &node) const;
+ virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &node) const;
+ virtual QVariant typedValue(const QXmlNodeModelIndex &node) const;
+ //! [0]
+ protected:
+ //! [1]
+ virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex &element) const;
+ virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis, const QXmlNodeModelIndex&) const;
+ //! [1]
+
+ private:
+ //! [4]
+ enum Type {
+ File,
+ Directory,
+ AttributeFileName,
+ AttributeFilePath,
+ AttributeSize,
+ AttributeMIMEType,
+ AttributeSuffix
+ };
+ //! [4]
+
+ inline QXmlNodeModelIndex nextSibling(const QXmlNodeModelIndex &nodeIndex,
+ const QFileInfo &from,
+ qint8 offset) const;
+ inline const QFileInfo &toFileInfo(const QXmlNodeModelIndex &index) const;
+ inline QXmlNodeModelIndex toNodeIndex(const QFileInfo &index,
+ Type attributeName) const;
+ inline QXmlNodeModelIndex toNodeIndex(const QFileInfo &index) const;
+
+ /*
+ One possible improvement is to use a hash, and use the &*&value()
+ trick to get a pointer, which would be stored in data() instead
+ of the index.
+ */
+ //! [2]
+ mutable QVector<QFileInfo> m_fileInfos;
+ const QDir::Filters m_filterAllowAll;
+ const QDir::SortFlags m_sortFlags;
+ QVector<QXmlName> m_names;
+ //! [2]
+};
+
+ //! [3]
+ //! [3]
diff --git a/examples/xmlpatterns/filetree/filetree.pro b/examples/xmlpatterns/filetree/filetree.pro
new file mode 100644
index 0000000000..e30f2cf117
--- /dev/null
+++ b/examples/xmlpatterns/filetree/filetree.pro
@@ -0,0 +1,15 @@
+SOURCES += main.cpp filetree.cpp mainwindow.cpp ../shared/xmlsyntaxhighlighter.cpp
+HEADERS += filetree.h mainwindow.h ../shared/xmlsyntaxhighlighter.h
+FORMS += forms/mainwindow.ui
+QT += xmlpatterns
+CONFIG -= app_bundle
+RESOURCES += queries.qrc
+INCLUDEPATH += ../shared/
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/filetree
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xq *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/filetree
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/filetree/forms/mainwindow.ui b/examples/xmlpatterns/filetree/forms/mainwindow.ui
new file mode 100644
index 0000000000..993050f7f4
--- /dev/null
+++ b/examples/xmlpatterns/filetree/forms/mainwindow.ui
@@ -0,0 +1,200 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>910</width>
+ <height>676</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>File Tree</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>29</y>
+ <width>910</width>
+ <height>625</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3" >
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font" >
+ <font>
+ <italic>true</italic>
+ </font>
+ </property>
+ <property name="text" >
+ <string></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSplitter" name="splitter_2" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QWidget" name="" >
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <widget class="QLabel" name="treeInfo" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>TextLabel</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="fileTree" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&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>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="" >
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QComboBox" name="queryBox" />
+ </item>
+ <item>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QTextEdit" name="queryEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&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>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QTextEdit" name="output" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&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>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ <zorder>label</zorder>
+ <zorder>splitter_2</zorder>
+ <zorder>queryBox</zorder>
+ <zorder>treeInfo</zorder>
+ <zorder>splitter</zorder>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>910</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="actionOpenDirectory" />
+ </widget>
+ <widget class="QMenu" name="menu_Help" >
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="actionAbout" />
+ </widget>
+ <addaction name="menuFile" />
+ <addaction name="menu_Help" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>654</y>
+ <width>910</width>
+ <height>22</height>
+ </rect>
+ </property>
+ </widget>
+ <action name="actionOpenDirectory" >
+ <property name="text" >
+ <string>Open Directory...</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+O</string>
+ </property>
+ </action>
+ <action name="actionAbout" >
+ <property name="text" >
+ <string>&amp;About</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+A</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/xmlpatterns/filetree/main.cpp b/examples/xmlpatterns/filetree/main.cpp
new file mode 100644
index 0000000000..e407a458e7
--- /dev/null
+++ b/examples/xmlpatterns/filetree/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(queries);
+ QApplication app(argc, argv);
+ MainWindow mainWindow;
+
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/xmlpatterns/filetree/mainwindow.cpp b/examples/xmlpatterns/filetree/mainwindow.cpp
new file mode 100644
index 0000000000..341128a838
--- /dev/null
+++ b/examples/xmlpatterns/filetree/mainwindow.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QLibraryInfo>
+#include <QtXmlPatterns>
+
+#include "mainwindow.h"
+#include "xmlsyntaxhighlighter.h"
+
+//! [0]
+MainWindow::MainWindow() : m_fileTree(m_namePool)
+{
+ setupUi(this);
+
+ new XmlSyntaxHighlighter(fileTree->document());
+
+ // Set up the font.
+ {
+ QFont font("Courier",10);
+ font.setFixedPitch(true);
+
+ fileTree->setFont(font);
+ queryEdit->setFont(font);
+ output->setFont(font);
+ }
+
+ const QString dir(QLibraryInfo::location(QLibraryInfo::ExamplesPath) + "/xmlpatterns/filetree");
+ qDebug() << dir;
+
+ if (QDir(dir).exists())
+ loadDirectory(dir);
+ else
+ fileTree->setPlainText(tr("Use the Open menu entry to select a directory."));
+
+ const QStringList queries(QDir(":/queries/", "*.xq").entryList());
+ int len = queries.count();
+
+ for (int i = 0; i < len; ++i)
+ queryBox->addItem(queries.at(i));
+
+}
+//! [0]
+
+//! [2]
+void MainWindow::on_queryBox_currentIndexChanged()
+{
+ QFile queryFile(":/queries/" + queryBox->currentText());
+ queryFile.open(QIODevice::ReadOnly);
+
+ queryEdit->setPlainText(QString::fromLatin1(queryFile.readAll()));
+ evaluateResult();
+}
+//! [2]
+
+//! [3]
+void MainWindow::evaluateResult()
+{
+ if (queryBox->currentText().isEmpty())
+ return;
+
+ QXmlQuery query(m_namePool);
+ query.bindVariable("fileTree", m_fileNode);
+ query.setQuery(QUrl("qrc:/queries/" + queryBox->currentText()));
+
+ QByteArray formatterOutput;
+ QBuffer buffer(&formatterOutput);
+ buffer.open(QIODevice::WriteOnly);
+
+ QXmlFormatter formatter(query, &buffer);
+ query.evaluateTo(&formatter);
+
+ output->setText(QString::fromLatin1(formatterOutput.constData()));
+}
+//! [3]
+
+//! [1]
+void MainWindow::on_actionOpenDirectory_triggered()
+{
+ const QString directoryName = QFileDialog::getExistingDirectory(this);
+ if (!directoryName.isEmpty())
+ loadDirectory(directoryName);
+}
+//! [1]
+
+//! [4]
+//! [5]
+void MainWindow::loadDirectory(const QString &directory)
+{
+ Q_ASSERT(QDir(directory).exists());
+
+ m_fileNode = m_fileTree.nodeFor(directory);
+//! [5]
+
+ QXmlQuery query(m_namePool);
+ query.bindVariable("fileTree", m_fileNode);
+ query.setQuery(QUrl("qrc:/queries/wholeTree.xq"));
+
+ QByteArray output;
+ QBuffer buffer(&output);
+ buffer.open(QIODevice::WriteOnly);
+
+ QXmlFormatter formatter(query, &buffer);
+ query.evaluateTo(&formatter);
+
+ treeInfo->setText((QString(tr("Model of %1 output as XML.")).arg(directory)));
+ fileTree->setText(QString::fromLatin1(output.constData()));
+ evaluateResult();
+//! [6]
+}
+//! [6]
+//! [4]
+
+void MainWindow::on_actionAbout_triggered()
+{
+ QMessageBox::about(this, tr("About File Tree"),
+ tr("<p>Select <b>File->Open Directory</b> and "
+ "choose a directory. The directory is then "
+ "loaded into the model, and the model is "
+ "displayed on the left as XML.</p>"
+
+ "<p>From the query menu on the right, select "
+ "a query. The query is displayed and then run "
+ "on the model. The results are displayed below "
+ "the query.</p>"));
+}
+
+
diff --git a/examples/xmlpatterns/filetree/mainwindow.h b/examples/xmlpatterns/filetree/mainwindow.h
new file mode 100644
index 0000000000..6651c80470
--- /dev/null
+++ b/examples/xmlpatterns/filetree/mainwindow.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QFile>
+#include <QMainWindow>
+#include <QXmlNamePool>
+//! [0]
+#include "filetree.h"
+#include "ui_mainwindow.h"
+
+class MainWindow : public QMainWindow, private Ui_MainWindow
+{
+ Q_OBJECT
+
+ public:
+ MainWindow();
+
+ private slots:
+ void on_actionOpenDirectory_triggered();
+ void on_actionAbout_triggered();
+ void on_queryBox_currentIndexChanged();
+
+ private:
+ void loadDirectory(const QString &directory);
+ void evaluateResult();
+
+ const QXmlNamePool m_namePool;
+ const FileTree m_fileTree;
+ QXmlNodeModelIndex m_fileNode;
+};
+//! [0]
+#endif
diff --git a/examples/xmlpatterns/filetree/queries.qrc b/examples/xmlpatterns/filetree/queries.qrc
new file mode 100644
index 0000000000..2e48601ead
--- /dev/null
+++ b/examples/xmlpatterns/filetree/queries.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC>
+ <RCC version="1.0">
+<qresource>
+ <file>queries/listCPPFiles.xq</file>
+ <file>queries/wholeTree.xq</file>
+</qresource>
+</RCC>
diff --git a/examples/xmlpatterns/filetree/queries/listCPPFiles.xq b/examples/xmlpatterns/filetree/queries/listCPPFiles.xq
new file mode 100644
index 0000000000..e311d27f1e
--- /dev/null
+++ b/examples/xmlpatterns/filetree/queries/listCPPFiles.xq
@@ -0,0 +1,19 @@
+declare variable $where as xs:string := string($fileTree/@filePath);
+<html>
+ <head>
+ <title>All cpp files in: {$where}</title>
+ </head>
+ <body>
+ <p>
+ cpp-files found in {$where} sorted by size:
+ </p>
+ <ul> {
+ for $file in $fileTree//file[@suffix = "cpp"]
+ order by xs:integer($file/@size)
+ return
+ <li>
+ {string($file/@fileName)}, size: {string($file/@size)}
+ </li>
+ } </ul>
+ </body>
+</html>
diff --git a/examples/xmlpatterns/filetree/queries/wholeTree.xq b/examples/xmlpatterns/filetree/queries/wholeTree.xq
new file mode 100644
index 0000000000..ec2977b65e
--- /dev/null
+++ b/examples/xmlpatterns/filetree/queries/wholeTree.xq
@@ -0,0 +1 @@
+$fileTree
diff --git a/examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui b/examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui
new file mode 100644
index 0000000000..ad43284a21
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui
@@ -0,0 +1,196 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>QObjectXmlModel Example</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>29</y>
+ <width>800</width>
+ <height>549</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4" >
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="font" >
+ <font>
+ <italic>true</italic>
+ </font>
+ </property>
+ <property name="text" >
+ <string>See the About menu entry for a description of this example.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTabWidget" name="inheritanceTab" >
+ <property name="autoFillBackground" >
+ <bool>true</bool>
+ </property>
+ <property name="currentIndex" >
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="wholeTreeTab" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>778</width>
+ <height>475</height>
+ </rect>
+ </property>
+ <attribute name="title" >
+ <string>Whole QObjectTree</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QTextEdit" name="wholeTree" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&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>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QTextEdit" name="wholeTreeOutput" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&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>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="htmlTab" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>778</width>
+ <height>475</height>
+ </rect>
+ </property>
+ <attribute name="title" >
+ <string>Statistics in HTML </string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <widget class="QSplitter" name="splitter_2" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QTextEdit" name="htmlQueryEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&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>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QWebView" name="htmlOutput" >
+ <property name="url" >
+ <url>
+ <string>about:blank</string>
+ </url>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuHelp" >
+ <property name="title" >
+ <string>Help</string>
+ </property>
+ <addaction name="actionAbout" />
+ </widget>
+ <addaction name="menuHelp" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>578</y>
+ <width>800</width>
+ <height>22</height>
+ </rect>
+ </property>
+ </widget>
+ <action name="actionAbout" >
+ <property name="text" >
+ <string>About</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+B</string>
+ </property>
+ </action>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QWebView</class>
+ <extends>QWidget</extends>
+ <header>QtWebKit/QWebView</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/xmlpatterns/qobjectxmlmodel/main.cpp b/examples/xmlpatterns/qobjectxmlmodel/main.cpp
new file mode 100644
index 0000000000..c73d211e6f
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+int main(int argc, char* argv[])
+{
+ Q_INIT_RESOURCE(queries);
+ QApplication app(argc, argv);
+ MainWindow mainWindow;
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp
new file mode 100644
index 0000000000..056ebaec28
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtXmlPatterns>
+
+#include "mainwindow.h"
+#include "qobjectxmlmodel.h"
+#include "xmlsyntaxhighlighter.h"
+
+MainWindow::MainWindow()
+{
+ setupUi(this);
+
+ new XmlSyntaxHighlighter(wholeTreeOutput->document());
+
+ /* Setup the font. */
+ {
+ QFont font("Courier");
+ font.setFixedPitch(true);
+
+ wholeTree->setFont(font);
+ wholeTreeOutput->setFont(font);
+ htmlQueryEdit->setFont(font);
+ }
+
+ QXmlNamePool namePool;
+ QObjectXmlModel qObjectModel(this, namePool);
+ QXmlQuery query(namePool);
+
+ /* The QObject tree as XML view. */
+ {
+ query.bindVariable("root", qObjectModel.root());
+ query.setQuery(QUrl("qrc:/queries/wholeTree.xq"));
+
+ Q_ASSERT(query.isValid());
+ QByteArray output;
+ QBuffer buffer(&output);
+ buffer.open(QIODevice::WriteOnly);
+
+ /* Let's the use the formatter, so it's a bit easier to read. */
+ QXmlFormatter serializer(query, &buffer);
+
+ query.evaluateTo(&serializer);
+ buffer.close();
+
+ {
+ QFile queryFile(":/queries/wholeTree.xq");
+ queryFile.open(QIODevice::ReadOnly);
+ wholeTree->setPlainText(QString::fromUtf8(queryFile.readAll()));
+ wholeTreeOutput->setPlainText(QString::fromUtf8(output.constData()));
+ }
+ }
+
+ /* The QObject occurrence statistics as HTML view. */
+ {
+ query.setQuery(QUrl("qrc:/queries/statisticsInHTML.xq"));
+ Q_ASSERT(query.isValid());
+
+ QByteArray output;
+ QBuffer buffer(&output);
+ buffer.open(QIODevice::WriteOnly);
+
+ /* Let's the use the serializer, so we gain a bit of speed. */
+ QXmlSerializer serializer(query, &buffer);
+
+ query.evaluateTo(&serializer);
+ buffer.close();
+
+ {
+ QFile queryFile(":/queries/statisticsInHTML.xq");
+ queryFile.open(QIODevice::ReadOnly);
+ htmlQueryEdit->setPlainText(QString::fromUtf8(queryFile.readAll()));
+ htmlOutput->setHtml(QString(output));
+ }
+ }
+}
+
+void MainWindow::on_actionAbout_triggered()
+{
+ QMessageBox::about(this,
+ tr("About QObject XML Model"),
+ tr("<p>The <b>QObject XML Model</b> example shows "
+ "how to use XQuery on top of data of your choice "
+ "without converting it to an XML document.</p>"
+ "<p>In this example a QSimpleXmlNodeModel subclass "
+ "makes it possible to query a QObject tree using "
+ "XQuery and retrieve the result as pointers to "
+ "QObjects, or as XML.</p>"
+ "<p>A possible use case of this could be to write "
+ "an application that tests a graphical interface "
+ "against Human Interface Guidelines, or that "
+ "queries an application's data which is modeled "
+ "using a QObject tree and dynamic properties."));
+}
+
+
diff --git a/examples/xmlpatterns/qobjectxmlmodel/mainwindow.h b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.h
new file mode 100644
index 0000000000..362bd0ec10
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QFile>
+
+#include "ui_mainwindow.h"
+
+//! [0]
+class MainWindow : public QMainWindow,
+ private Ui_MainWindow
+{
+ Q_OBJECT
+
+ public:
+ MainWindow();
+
+ private slots:
+ void on_actionAbout_triggered();
+};
+//! [0]
+
+#endif
diff --git a/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp
new file mode 100644
index 0000000000..3eee67ade3
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp
@@ -0,0 +1,459 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QVector>
+#include <QtDebug>
+
+#include <QCoreApplication>
+#include <QMetaProperty>
+#include <QXmlQuery>
+#include <QXmlResultItems>
+
+#include "qobjectxmlmodel.h"
+
+QT_BEGIN_NAMESPACE
+
+/*
+<metaObjects>
+ <metaObject className="QObject"/>
+ <metaObject className="QWidget" superClass="QObject">
+ </metaObject>
+ ...
+</metaObjects>
+<QObject objectName="MyWidget" property1="..." property2="..."> <!-- This is root() -->
+ <QObject objectName="MyFOO" property1="..."/>
+ ....
+</QObject>
+*/
+
+QObjectXmlModel::QObjectXmlModel(QObject *const object, const QXmlNamePool &np)
+ : QSimpleXmlNodeModel(np),
+ m_baseURI(QUrl::fromLocalFile(QCoreApplication::applicationFilePath())),
+ m_root(object),
+ m_allMetaObjects(allMetaObjects())
+{
+ Q_ASSERT(m_baseURI.isValid());
+}
+
+//! [5]
+QXmlNodeModelIndex QObjectXmlModel::qObjectSibling(const int pos, const QXmlNodeModelIndex &n) const
+{
+ Q_ASSERT(pos == 1 || pos == -1);
+ Q_ASSERT(asQObject(n));
+
+ const QObject *parent = asQObject(n)->parent();
+ if (parent) {
+ const QList<QObject *> &children = parent->children();
+ const int siblingPos = children.indexOf(asQObject(n)) + pos;
+
+ if (siblingPos >= 0 && siblingPos < children.count())
+ return createIndex(children.at(siblingPos));
+ else
+ return QXmlNodeModelIndex();
+ }
+ else
+ return QXmlNodeModelIndex();
+}
+//! [5]
+
+//! [1]
+QObjectXmlModel::QObjectNodeType QObjectXmlModel::toNodeType(const QXmlNodeModelIndex &n)
+{
+ return QObjectNodeType(n.additionalData() & (15 << 26));
+}
+//! [1]
+
+//! [9]
+QObjectXmlModel::AllMetaObjects QObjectXmlModel::allMetaObjects() const
+{
+ QXmlQuery query(namePool());
+ query.bindVariable("root", root());
+ query.setQuery("declare variable $root external;"
+ "$root/descendant-or-self::QObject");
+ Q_ASSERT(query.isValid());
+
+ QXmlResultItems result;
+ query.evaluateTo(&result);
+ QXmlItem i(result.next());
+
+ AllMetaObjects objects;
+ while (!i.isNull()) {
+ const QMetaObject *moo = asQObject(i.toNodeModelIndex())->metaObject();
+ while (moo) {
+ if (!objects.contains(moo))
+ objects.append(moo);
+ moo = moo->superClass();
+ }
+ i = result.next();
+ }
+
+ Q_ASSERT(!objects.contains(0));
+ return objects;
+}
+//! [9]
+
+QXmlNodeModelIndex QObjectXmlModel::metaObjectSibling(const int pos, const QXmlNodeModelIndex &n) const
+{
+ Q_ASSERT(pos == 1 || pos == -1);
+ Q_ASSERT(!n.isNull());
+
+ const int indexOf = m_allMetaObjects.indexOf(static_cast<const QMetaObject *>(n.internalPointer())) + pos;
+
+ if (indexOf >= 0 && indexOf < m_allMetaObjects.count())
+ return createIndex(const_cast<QMetaObject *>(m_allMetaObjects.at(indexOf)), MetaObject);
+ else
+ return QXmlNodeModelIndex();
+}
+
+//! [2]
+QXmlNodeModelIndex QObjectXmlModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &n) const
+{
+ switch (toNodeType(n))
+ {
+ case IsQObject:
+ {
+ switch (axis)
+ {
+ case Parent:
+ return createIndex(asQObject(n)->parent());
+
+ case FirstChild:
+ {
+ if (!asQObject(n) || asQObject(n)->children().isEmpty())
+ return QXmlNodeModelIndex();
+ else
+ return createIndex(asQObject(n)->children().first());
+ }
+
+ case NextSibling:
+ return qObjectSibling(1, n);
+
+//! [10]
+ case PreviousSibling:
+ {
+ if (asQObject(n) == m_root)
+ return createIndex(qint64(0), MetaObjects);
+ else
+ return qObjectSibling(-1, n);
+ }
+//! [10]
+ }
+ Q_ASSERT(false);
+ }
+
+//! [7]
+ case QObjectClassName:
+ case QObjectProperty:
+ {
+ Q_ASSERT(axis == Parent);
+ return createIndex(asQObject(n));
+ }
+//! [7]
+//! [2]
+//! [3]
+
+//! [11]
+ case MetaObjects:
+ {
+ switch (axis)
+ {
+ case Parent:
+ return QXmlNodeModelIndex();
+ case PreviousSibling:
+ return QXmlNodeModelIndex();
+ case NextSibling:
+ return root();
+ case FirstChild:
+ {
+ return createIndex(const_cast<QMetaObject*>(m_allMetaObjects.first()),MetaObject);
+ }
+ }
+ Q_ASSERT(false);
+ }
+//! [11]
+
+ case MetaObject:
+ {
+ switch (axis)
+ {
+ case FirstChild:
+ return QXmlNodeModelIndex();
+ case Parent:
+ return createIndex(qint64(0), MetaObjects);
+ case PreviousSibling:
+ return metaObjectSibling(-1, n);
+ case NextSibling:
+ return metaObjectSibling(1, n);
+ }
+ }
+
+ case MetaObjectClassName:
+ case MetaObjectSuperClass:
+ {
+ Q_ASSERT(axis == Parent);
+ return createIndex(asQObject(n), MetaObject);
+ }
+//! [3]
+//! [4]
+ }
+
+ Q_ASSERT(false);
+ return QXmlNodeModelIndex();
+}
+//! [4]
+
+//! [6]
+QVector<QXmlNodeModelIndex> QObjectXmlModel::attributes(const QXmlNodeModelIndex& n) const
+{
+ QVector<QXmlNodeModelIndex> result;
+ QObject *const object = asQObject(n);
+
+ switch(toNodeType(n))
+ {
+ case IsQObject:
+ {
+ const QMetaObject *const metaObject = object->metaObject();
+ const int count = metaObject->propertyCount();
+ result.append(createIndex(object, QObjectClassName));
+
+ for (int i = 0; i < count; ++i) {
+ const QMetaProperty qmp(metaObject->property(i));
+ const int ii = metaObject->indexOfProperty(qmp.name());
+ if (i == ii)
+ result.append(createIndex(object, QObjectProperty | i));
+ }
+ return result;
+ }
+//! [6]
+
+ case MetaObject:
+ {
+ result.append(createIndex(object, MetaObjectClassName));
+ result.append(createIndex(object, MetaObjectSuperClass));
+ return result;
+ }
+//! [8]
+ default:
+ return QVector<QXmlNodeModelIndex>();
+ }
+}
+//! [8]
+
+QObject *QObjectXmlModel::asQObject(const QXmlNodeModelIndex &n)
+{
+ return static_cast<QObject *>(n.internalPointer());
+}
+
+bool QObjectXmlModel::isProperty(const QXmlNodeModelIndex n)
+{
+ return n.additionalData() & QObjectProperty;
+}
+
+QUrl QObjectXmlModel::documentUri(const QXmlNodeModelIndex& ) const
+{
+ return m_baseURI;
+}
+
+QXmlNodeModelIndex::NodeKind QObjectXmlModel::kind(const QXmlNodeModelIndex& n) const
+{
+ switch (toNodeType(n))
+ {
+ case IsQObject:
+ case MetaObject:
+ case MetaObjects:
+ return QXmlNodeModelIndex::Element;
+
+ case QObjectProperty:
+ case MetaObjectClassName:
+ case MetaObjectSuperClass:
+ case QObjectClassName:
+ return QXmlNodeModelIndex::Attribute;
+ }
+
+ Q_ASSERT(false);
+ return QXmlNodeModelIndex::Element;
+}
+
+QXmlNodeModelIndex::DocumentOrder QObjectXmlModel::compareOrder(const QXmlNodeModelIndex& , const QXmlNodeModelIndex& ) const
+{
+ return QXmlNodeModelIndex::Follows; // TODO
+}
+
+//! [0]
+QXmlNodeModelIndex QObjectXmlModel::root() const
+{
+ return createIndex(m_root);
+}
+//! [0]
+
+QXmlNodeModelIndex QObjectXmlModel::root(const QXmlNodeModelIndex& n) const
+{
+ QObject *p = asQObject(n);
+ Q_ASSERT(p);
+
+ do {
+ QObject *const candidate = p->parent();
+ if (candidate)
+ p = candidate;
+ else
+ break;
+ }
+ while (true);
+
+ return createIndex(p);
+}
+
+/*!
+ We simply throw all of them into a QList and
+ return an iterator over it.
+ */
+QXmlNodeModelIndex::List QObjectXmlModel::ancestors(const QXmlNodeModelIndex n) const
+{
+ const QObject *p = asQObject(n);
+ Q_ASSERT(p);
+
+ QXmlNodeModelIndex::List result;
+ do {
+ QObject *const candidate = p->parent();
+ if (candidate) {
+ result.append(createIndex(candidate, 0));
+ p = candidate;
+ }
+ else
+ break;
+ }
+ while (true);
+
+ return result;
+}
+
+QMetaProperty QObjectXmlModel::toMetaProperty(const QXmlNodeModelIndex &n)
+{
+ const int propertyOffset = n.additionalData() & (~QObjectProperty);
+ const QObject *const qo = asQObject(n);
+ return qo->metaObject()->property(propertyOffset);
+}
+
+QXmlName QObjectXmlModel::name(const QXmlNodeModelIndex &n) const
+{
+ switch (toNodeType(n))
+ {
+ case IsQObject:
+ return QXmlName(namePool(), QLatin1String("QObject"));
+ case MetaObject:
+ return QXmlName(namePool(), QLatin1String("metaObject"));
+ case QObjectClassName:
+ case MetaObjectClassName:
+ return QXmlName(namePool(), QLatin1String("className"));
+ case QObjectProperty:
+ return QXmlName(namePool(), toMetaProperty(n).name());
+ case MetaObjects:
+ return QXmlName(namePool(), QLatin1String("metaObjects"));
+ case MetaObjectSuperClass:
+ return QXmlName(namePool(), QLatin1String("superClass"));
+ }
+
+ Q_ASSERT(false);
+ return QXmlName();
+}
+
+QVariant QObjectXmlModel::typedValue(const QXmlNodeModelIndex &n) const
+{
+ switch (toNodeType(n))
+ {
+ case QObjectProperty:
+ {
+ const QVariant &candidate = toMetaProperty(n).read(asQObject(n));
+ if (isTypeSupported(candidate.type()))
+ return candidate;
+ else
+ return QVariant();
+ }
+
+ case MetaObjectClassName:
+ return QVariant(static_cast<QMetaObject*>(n.internalPointer())->className());
+
+ case MetaObjectSuperClass:
+ {
+ const QMetaObject *const superClass = static_cast<QMetaObject*>(n.internalPointer())->superClass();
+ if (superClass)
+ return QVariant(superClass->className());
+ else
+ return QVariant();
+ }
+
+ case QObjectClassName:
+ return QVariant(asQObject(n)->metaObject()->className());
+
+ default:
+ return QVariant();
+ }
+}
+
+/*!
+ Returns \c true if QVariants of type \a type can be used
+ in QtXmlPatterns, otherwise \c false.
+ */
+bool QObjectXmlModel::isTypeSupported(QVariant::Type type)
+{
+ /* See data/qatomicvalue.cpp too. */
+ switch (type)
+ {
+ /* Fallthrough all these. */
+ case QVariant::Char:
+ case QVariant::String:
+ case QVariant::Url:
+ case QVariant::Bool:
+ case QVariant::ByteArray:
+ case QVariant::Int:
+ case QVariant::LongLong:
+ case QVariant::ULongLong:
+ case QVariant::Date:
+ case QVariant::DateTime:
+ case QVariant::Time:
+ case QVariant::Double:
+ return true;
+ default:
+ return false;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h
new file mode 100644
index 0000000000..2c2b468ecd
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef Patternist_QObjectNodeModel_H
+#define Patternist_QObjectNodeModel_H
+
+#include <QSimpleXmlNodeModel>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QObject;
+class PropertyToAtomicValue;
+
+/**
+ * @short Delegates QtCore's QObject into Patternist's QAbstractXmlNodeModel.
+ * known as pre/post numbering.
+ *
+ * QObjectXmlModel sets the toggle on QXmlNodeModelIndex to @c true, if it
+ * represents a property of the QObject. That is, if the QXmlNodeModelIndex is
+ * an attribute.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+class QObjectXmlModel : public QSimpleXmlNodeModel
+{
+ public:
+ QObjectXmlModel(QObject *const object, const QXmlNamePool &np);
+
+ QXmlNodeModelIndex root() const;
+
+//! [0]
+ virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &n1, const QXmlNodeModelIndex &n2) const;
+ virtual QXmlName name(const QXmlNodeModelIndex &n) const;
+ virtual QUrl documentUri(const QXmlNodeModelIndex &n) const;
+ virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &n) const;
+ virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const;
+ virtual QVariant typedValue(const QXmlNodeModelIndex &n) const;
+ virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex&) const;
+ virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis, const QXmlNodeModelIndex&) const;
+//! [0]
+
+ private:
+ /**
+ * The highest three bits are used to signify whether the node index
+ * is an artificial node.
+ *
+ * @short if QXmlNodeModelIndex::additionalData() has the
+ * QObjectPropery flag set, then the QXmlNodeModelIndex is an
+ * attribute of the QObject element, and the remaining bits form
+ * an offset to the QObject property that the QXmlNodeModelIndex
+ * refers to.
+ *
+ */
+//! [3]
+ enum QObjectNodeType
+ {
+ IsQObject = 0,
+ QObjectProperty = 1 << 26,
+ MetaObjects = 2 << 26,
+ MetaObject = 3 << 26,
+ MetaObjectClassName = 4 << 26,
+ MetaObjectSuperClass = 5 << 26,
+ QObjectClassName = 6 << 26
+ };
+//! [3]
+
+//! [1]
+ typedef QVector<const QMetaObject *> AllMetaObjects;
+//! [1]
+ AllMetaObjects allMetaObjects() const;
+
+ static QObjectNodeType toNodeType(const QXmlNodeModelIndex &n);
+ static bool isTypeSupported(QVariant::Type type);
+ static inline QObject *asQObject(const QXmlNodeModelIndex &n);
+ static inline bool isProperty(const QXmlNodeModelIndex n);
+ static inline QMetaProperty toMetaProperty(const QXmlNodeModelIndex &n);
+ /**
+ * Returns the ancestors of @p n. Does therefore not include
+ * @p n.
+ */
+ inline QXmlNodeModelIndex::List ancestors(const QXmlNodeModelIndex n) const;
+ QXmlNodeModelIndex qObjectSibling(const int pos,
+ const QXmlNodeModelIndex &n) const;
+ QXmlNodeModelIndex metaObjectSibling(const int pos,
+ const QXmlNodeModelIndex &n) const;
+
+//! [2]
+ const QUrl m_baseURI;
+ QObject *const m_root;
+//! [4]
+ const AllMetaObjects m_allMetaObjects;
+//! [4]
+//! [2]
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro
new file mode 100644
index 0000000000..39f01062cc
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro
@@ -0,0 +1,13 @@
+
+FORMS += forms/mainwindow.ui
+QT += xmlpatterns webkit
+SOURCES += qobjectxmlmodel.cpp main.cpp mainwindow.cpp ../shared/xmlsyntaxhighlighter.cpp
+HEADERS += qobjectxmlmodel.h mainwindow.h ../shared/xmlsyntaxhighlighter.h
+RESOURCES = queries.qrc
+INCLUDEPATH += ../shared/
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/qobjectxmlmodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xq *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/qobjectxmlmodel
+INSTALLS += target sources
diff --git a/examples/xmlpatterns/qobjectxmlmodel/queries.qrc b/examples/xmlpatterns/qobjectxmlmodel/queries.qrc
new file mode 100644
index 0000000000..ec8cc6b718
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/queries.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC>
+ <RCC version="1.0">
+<qresource>
+ <file>queries/wholeTree.xq</file>
+ <file>queries/statisticsInHTML.xq</file>
+</qresource>
+</RCC>
diff --git a/examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq b/examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq
new file mode 100644
index 0000000000..14a7a14cb7
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq
@@ -0,0 +1,58 @@
+<html>
+ <head>
+ <title></title>
+ </head>
+ <body>
+ <p>In total the tree has {count($root//QObject)} QObject instances.</p>
+ <p>Order by occurrence, the QObjects are:</p>
+
+ <ol>
+ {
+ for $i in $root/preceding-sibling::metaObjects/metaObject
+ let $count := count($root//QObject[@className eq $i/@className])
+ stable order by $count descending
+ return if($count > 1)
+ then <li>{string($i/@className), $count} occurrences</li>
+ else ()
+ }
+ </ol>
+
+ <h1>Properties</h1>
+ {
+ (: For each QObject, we create a table listing
+ : the properties of that object. :)
+ for $object in $root//QObject
+ return (<h2>{let $name := string($object/@objectName)
+ return if(string-length($name))
+ then $name
+ else "[no name]",
+ '(', string($object/@className), ')'}</h2>,
+ <table border="1">
+ <thead>
+ <tr>
+ <td>Property Name</td>
+ <td>Value</td>
+ </tr>
+ </thead>
+ <tbody>
+ {
+ $object/@*/<tr>
+ <td>
+ {
+ name()
+ }
+ </td>
+ <td>
+ {
+ if(data(.))
+ then string(.)
+ else "N/A"
+ }
+ </td>
+ </tr>
+ }
+ </tbody>
+ </table>)
+ }
+ </body>
+</html>
diff --git a/examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq b/examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq
new file mode 100644
index 0000000000..253cd43967
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq
@@ -0,0 +1,3 @@
+<!-- This is the QObject tree for this application, rendered as XML. -->,
+$root/preceding-sibling::metaObjects,
+$root
diff --git a/examples/xmlpatterns/recipes/files/allRecipes.xq b/examples/xmlpatterns/recipes/files/allRecipes.xq
new file mode 100644
index 0000000000..6888c3103c
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/allRecipes.xq
@@ -0,0 +1,4 @@
+(: Select all recipes. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe/<p>{string(title)}</p>
diff --git a/examples/xmlpatterns/recipes/files/cookbook.xml b/examples/xmlpatterns/recipes/files/cookbook.xml
new file mode 100644
index 0000000000..3b6f621ff5
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/cookbook.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<cookbook>
+ <recipe xml:id="MushroomSoup">
+ <title>Quick and Easy Mushroom Soup</title>
+ <ingredient name="Fresh mushrooms"
+ quantity="7"
+ unit="pieces"/>
+ <ingredient name="Garlic"
+ quantity="1"
+ unit="cloves"/>
+ <ingredient name="Olive oil"
+ quantity="2"
+ unit="tablespoons"/>
+ <ingredient name="Milk"
+ quantity="200"
+ unit="milliliters"/>
+ <ingredient name="Water"
+ quantity="200"
+ unit="milliliters"/>
+ <ingredient name="Cream"
+ quantity="100"
+ unit="milliliters"/>
+ <ingredient name="Vegetable soup cube"
+ quantity="1/2"
+ unit="cubes"/>
+ <ingredient name="Ground black pepper"
+ quantity="1/2"
+ unit="teaspoons"/>
+ <ingredient name="Dried parsley"
+ quantity="1"
+ unit="teaspoons"/>
+ <time quantity="20"
+ unit="minutes"/>
+ <method>
+ <step>1. Slice mushrooms and garlic.</step>
+ <step>2. Fry mushroom slices and garlic with olive oil.</step>
+ <step>3. Once mushrooms are cooked, add milk, cream water. Stir.</step>
+ <step>4. Add vegetable soup cube.</step>
+ <step>5. Reduce heat, add pepper and parsley.</step>
+ <step>6. Turn off the stove before the mixture boils.</step>
+ <step>7. Blend the mixture.</step>
+ </method>
+ </recipe>
+ <recipe xml:id="CheeseOnToast">
+ <title>Cheese on Toast</title>
+ <ingredient name="Bread"
+ quantity="2"
+ unit="slices"/>
+ <ingredient name="Cheese"
+ quantity="2"
+ unit="slices"/>
+ <time quantity="3"
+ unit="minutes"/>
+ <method>
+ <step>1. Slice the bread and cheese.</step>
+ <step>2. Grill one side of each slice of bread.</step>
+ <step>3. Turn over the bread and place a slice of cheese on each piece.</step>
+ <step>4. Grill until the cheese has started to melt.</step>
+ <step>5. Serve and enjoy!</step>
+ </method>
+ </recipe>
+</cookbook>
diff --git a/examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq b/examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq
new file mode 100644
index 0000000000..3baecd8df3
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq
@@ -0,0 +1,5 @@
+(: All liquid ingredients form Mushroom Soup. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe[@xml:id = "MushroomSoup"]/ingredient[@unit = "milliliters"]/
+<p>{@name, @quantity, @unit}</p>
diff --git a/examples/xmlpatterns/recipes/files/mushroomSoup.xq b/examples/xmlpatterns/recipes/files/mushroomSoup.xq
new file mode 100644
index 0000000000..b1fee349be
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/mushroomSoup.xq
@@ -0,0 +1,5 @@
+(: All ingredients for Mushroom Soup. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe[@xml:id = "MushroomSoup"]/ingredient/
+<p>{@name, @quantity}</p>
diff --git a/examples/xmlpatterns/recipes/files/preparationLessThan30.xq b/examples/xmlpatterns/recipes/files/preparationLessThan30.xq
new file mode 100644
index 0000000000..d74a4eb937
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/preparationLessThan30.xq
@@ -0,0 +1,9 @@
+(: All recipes taking 10 minutes or less to prepare. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe/time[@unit = "minutes" and xs:integer(@quantity) <= 10]/
+<p>
+ {
+ concat(../title, ' (', @quantity, ' ', @unit, ')')
+ }
+</p>
diff --git a/examples/xmlpatterns/recipes/files/preparationTimes.xq b/examples/xmlpatterns/recipes/files/preparationTimes.xq
new file mode 100644
index 0000000000..cb4217ff62
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/preparationTimes.xq
@@ -0,0 +1,5 @@
+(: All recipes with preparation times. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe/
+<recipe title="{title}" time="{time/@quantity} {time/@unit}"/>
diff --git a/examples/xmlpatterns/recipes/forms/querywidget.ui b/examples/xmlpatterns/recipes/forms/querywidget.ui
new file mode 100644
index 0000000000..fb2ab64282
--- /dev/null
+++ b/examples/xmlpatterns/recipes/forms/querywidget.ui
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QueryWidget</class>
+ <widget class="QMainWindow" name="QueryWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>570</width>
+ <height>531</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Recipes XQuery Example</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QGroupBox" name="inputGroupBox">
+ <property name="minimumSize">
+ <size>
+ <width>550</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Input Document</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QVBoxLayout" name="_2">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="inputTextEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="queryGroupBox">
+ <property name="minimumSize">
+ <size>
+ <width>550</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Select your query:</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <widget class="QComboBox" name="defaultQueries"/>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="queryTextEdit">
+ <property name="minimumSize">
+ <size>
+ <width>400</width>
+ <height>60</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="outputGroupBox">
+ <property name="minimumSize">
+ <size>
+ <width>550</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Output Document</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_6">
+ <item>
+ <layout class="QVBoxLayout" name="_3">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="outputTextEdit">
+ <property name="minimumSize">
+ <size>
+ <width>500</width>
+ <height>80</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>570</width>
+ <height>26</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/xmlpatterns/recipes/main.cpp b/examples/xmlpatterns/recipes/main.cpp
new file mode 100644
index 0000000000..ee0698fbf3
--- /dev/null
+++ b/examples/xmlpatterns/recipes/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "querymainwindow.h"
+
+//! [0]
+int main(int argc, char* argv[])
+{
+ Q_INIT_RESOURCE(recipes);
+ QApplication app(argc, argv);
+ QueryMainWindow* const queryWindow = new QueryMainWindow;
+ queryWindow->show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/xmlpatterns/recipes/querymainwindow.cpp b/examples/xmlpatterns/recipes/querymainwindow.cpp
new file mode 100644
index 0000000000..0438ab9e4d
--- /dev/null
+++ b/examples/xmlpatterns/recipes/querymainwindow.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtXmlPatterns>
+
+#include "querymainwindow.h"
+#include "xmlsyntaxhighlighter.h"
+
+//! [0]
+QueryMainWindow::QueryMainWindow() : ui_defaultQueries(0)
+{
+ setupUi(this);
+
+ new XmlSyntaxHighlighter(qFindChild<QTextEdit*>(this, "inputTextEdit")->document());
+ new XmlSyntaxHighlighter(qFindChild<QTextEdit*>(this, "outputTextEdit")->document());
+
+ ui_defaultQueries = qFindChild<QComboBox*>(this, "defaultQueries");
+ QMetaObject::connectSlotsByName(this);
+ connect(ui_defaultQueries, SIGNAL(currentIndexChanged(int)), SLOT(displayQuery(int)));
+
+ loadInputFile();
+ const QStringList queries(QDir(":/files/", "*.xq").entryList());
+ int len = queries.count();
+ for(int i = 0; i < len; ++i)
+ ui_defaultQueries->addItem(queries.at(i));
+}
+//! [0]
+
+
+//! [1]
+void QueryMainWindow::displayQuery(int index)
+{
+ QFile queryFile(QString(":files/") + ui_defaultQueries->itemText(index));
+ queryFile.open(QIODevice::ReadOnly);
+ const QString query(QString::fromLatin1(queryFile.readAll()));
+ qFindChild<QTextEdit*>(this, "queryTextEdit")->setPlainText(query);
+
+ evaluate(query);
+}
+//! [1]
+
+
+void QueryMainWindow::loadInputFile()
+{
+ QFile forView;
+ forView.setFileName(":/files/cookbook.xml");
+ if (!forView.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this,
+ tr("Unable to open file"), forView.errorString());
+ return;
+ }
+
+ QTextStream in(&forView);
+ QString inputDocument = in.readAll();
+ qFindChild<QTextEdit*>(this, "inputTextEdit")->setPlainText(inputDocument);
+}
+
+
+//! [2]
+void QueryMainWindow::evaluate(const QString &str)
+{
+ QFile sourceDocument;
+ sourceDocument.setFileName(":/files/cookbook.xml");
+ sourceDocument.open(QIODevice::ReadOnly);
+
+ QByteArray outArray;
+ QBuffer buffer(&outArray);
+ buffer.open(QIODevice::ReadWrite);
+
+ QXmlQuery query;
+ query.bindVariable("inputDocument", &sourceDocument);
+ query.setQuery(str);
+ if (!query.isValid())
+ return;
+
+ QXmlFormatter formatter(query, &buffer);
+ if (!query.evaluateTo(&formatter))
+ return;
+
+ buffer.close();
+ qFindChild<QTextEdit*>(this, "outputTextEdit")->setPlainText(QString::fromUtf8(outArray.constData()));
+
+}
+//! [2]
+
diff --git a/examples/xmlpatterns/recipes/querymainwindow.h b/examples/xmlpatterns/recipes/querymainwindow.h
new file mode 100644
index 0000000000..2c85932c77
--- /dev/null
+++ b/examples/xmlpatterns/recipes/querymainwindow.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QUERYMAINWINDOW_H
+#define QUERYMAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "ui_querywidget.h"
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+QT_END_NAMESPACE
+
+//! [0]
+class QueryMainWindow : public QMainWindow,
+ private Ui::QueryWidget
+{
+ Q_OBJECT
+
+ public:
+ QueryMainWindow();
+
+ public slots:
+ void displayQuery(int index);
+
+ private:
+ QComboBox* ui_defaultQueries;
+
+ void evaluate(const QString &str);
+ void loadInputFile();
+};
+//! [0]
+#endif
diff --git a/examples/xmlpatterns/recipes/recipes.pro b/examples/xmlpatterns/recipes/recipes.pro
new file mode 100644
index 0000000000..cee7b6d730
--- /dev/null
+++ b/examples/xmlpatterns/recipes/recipes.pro
@@ -0,0 +1,13 @@
+QT += xmlpatterns
+FORMS += forms/querywidget.ui
+HEADERS = querymainwindow.h ../shared/xmlsyntaxhighlighter.h
+RESOURCES = recipes.qrc
+SOURCES = main.cpp querymainwindow.cpp ../shared/xmlsyntaxhighlighter.cpp
+INCLUDEPATH += ../shared/
+
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/recipes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.xq *.html forms files
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/recipes
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/recipes/recipes.qrc b/examples/xmlpatterns/recipes/recipes.qrc
new file mode 100644
index 0000000000..2f375eef7a
--- /dev/null
+++ b/examples/xmlpatterns/recipes/recipes.qrc
@@ -0,0 +1,11 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>forms/querywidget.ui</file>
+ <file>files/cookbook.xml</file>
+ <file>files/allRecipes.xq</file>
+ <file>files/liquidIngredientsInSoup.xq</file>
+ <file>files/mushroomSoup.xq</file>
+ <file>files/preparationLessThan30.xq</file>
+ <file>files/preparationTimes.xq</file>
+</qresource>
+</RCC>
diff --git a/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp
new file mode 100644
index 0000000000..c796f81b8d
--- /dev/null
+++ b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xmlsyntaxhighlighter.h"
+
+XmlSyntaxHighlighter::XmlSyntaxHighlighter(QTextDocument *parent)
+ : QSyntaxHighlighter(parent)
+{
+ HighlightingRule rule;
+
+ // tag format
+ tagFormat.setForeground(Qt::darkBlue);
+ tagFormat.setFontWeight(QFont::Bold);
+ rule.pattern = QRegExp("(<[a-zA-Z:]+\\b|<\\?[a-zA-Z:]+\\b|\\?>|>|/>|</[a-zA-Z:]+>)");
+ rule.format = tagFormat;
+ highlightingRules.append(rule);
+
+ // attribute format
+ attributeFormat.setForeground(Qt::darkGreen);
+ rule.pattern = QRegExp("[a-zA-Z:]+=");
+ rule.format = attributeFormat;
+ highlightingRules.append(rule);
+
+ // attribute content format
+ attributeContentFormat.setForeground(Qt::red);
+ rule.pattern = QRegExp("(\"[^\"]*\"|'[^']*')");
+ rule.format = attributeContentFormat;
+ highlightingRules.append(rule);
+
+ commentFormat.setForeground(Qt::lightGray);
+ commentFormat.setFontItalic(true);
+
+ commentStartExpression = QRegExp("<!--");
+ commentEndExpression = QRegExp("-->");
+}
+
+void XmlSyntaxHighlighter::highlightBlock(const QString &text)
+{
+ foreach (const HighlightingRule &rule, highlightingRules) {
+ QRegExp expression(rule.pattern);
+ int index = text.indexOf(expression);
+ while (index >= 0) {
+ int length = expression.matchedLength();
+ setFormat(index, length, rule.format);
+ index = text.indexOf(expression, index + length);
+ }
+ }
+ setCurrentBlockState(0);
+
+ int startIndex = 0;
+ if (previousBlockState() != 1)
+ startIndex = text.indexOf(commentStartExpression);
+
+ while (startIndex >= 0) {
+ int endIndex = text.indexOf(commentEndExpression, startIndex);
+ int commentLength;
+ if (endIndex == -1) {
+ setCurrentBlockState(1);
+ commentLength = text.length() - startIndex;
+ } else {
+ commentLength = endIndex - startIndex
+ + commentEndExpression.matchedLength();
+ }
+ setFormat(startIndex, commentLength, commentFormat);
+ startIndex = text.indexOf(commentStartExpression,
+ startIndex + commentLength);
+ }
+}
diff --git a/examples/xmlpatterns/shared/xmlsyntaxhighlighter.h b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.h
new file mode 100644
index 0000000000..5fe9aa46e2
--- /dev/null
+++ b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XMLSYNTAXHIGHLIGHTER_H
+#define XMLSYNTAXHIGHLIGHTER_H
+
+#include <QtGui/QSyntaxHighlighter>
+
+class XmlSyntaxHighlighter : public QSyntaxHighlighter
+{
+ public:
+ XmlSyntaxHighlighter(QTextDocument *parent = 0);
+
+ protected:
+ virtual void highlightBlock(const QString &text);
+
+ private:
+ struct HighlightingRule
+ {
+ QRegExp pattern;
+ QTextCharFormat format;
+ };
+ QVector<HighlightingRule> highlightingRules;
+
+ QRegExp commentStartExpression;
+ QRegExp commentEndExpression;
+
+ QTextCharFormat tagFormat;
+ QTextCharFormat attributeFormat;
+ QTextCharFormat attributeContentFormat;
+ QTextCharFormat commentFormat;
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/main.cpp b/examples/xmlpatterns/trafficinfo/main.cpp
new file mode 100644
index 0000000000..97b2bf7958
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QtGui/QApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MainWindow window;
+ window.show();
+
+ return app.exec();
+}
diff --git a/examples/xmlpatterns/trafficinfo/mainwindow.cpp b/examples/xmlpatterns/trafficinfo/mainwindow.cpp
new file mode 100644
index 0000000000..c4ca731957
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/mainwindow.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "stationdialog.h"
+
+#include <QtCore/QSettings>
+#include <QtCore/QTimer>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QBitmap>
+#include <QtGui/QLinearGradient>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QPainter>
+
+MainWindow::MainWindow()
+ : QWidget(0, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
+{
+ QAction *quitAction = new QAction(tr("E&xit"), this);
+ quitAction->setShortcut(tr("Ctrl+Q"));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ QAction *configAction = new QAction(tr("&Select station..."), this);
+ configAction->setShortcut(tr("Ctrl+C"));
+ connect(configAction, SIGNAL(triggered()), this, SLOT(configure()));
+
+ addAction(configAction);
+ addAction(quitAction);
+
+ setContextMenuPolicy(Qt::ActionsContextMenu);
+
+ setWindowTitle(tr("Traffic Info Oslo"));
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(updateTimeInformation()));
+ timer->start(1000*60);
+
+ const QSettings settings("Qt Software", "trafficinfo");
+ m_station = StationInformation(settings.value("stationId", "03012130").toString(),
+ settings.value("stationName", "Nydalen [T-bane] (OSL)").toString());
+ m_lines = settings.value("lines", QStringList()).toStringList();
+
+ updateTimeInformation();
+}
+
+MainWindow::~MainWindow()
+{
+ QSettings settings("Qt Software", "trafficinfo");
+ settings.setValue("stationId", m_station.id());
+ settings.setValue("stationName", m_station.name());
+ settings.setValue("lines", m_lines);
+}
+
+QSize MainWindow::sizeHint() const
+{
+ return QSize(300, 200);
+}
+
+void MainWindow::mouseMoveEvent(QMouseEvent *event)
+{
+ if (event->buttons() & Qt::LeftButton) {
+ move(event->globalPos() - m_dragPosition);
+ event->accept();
+ }
+}
+
+void MainWindow::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ m_dragPosition = event->globalPos() - frameGeometry().topLeft();
+ event->accept();
+ }
+}
+
+void MainWindow::paintEvent(QPaintEvent*)
+{
+ QLinearGradient gradient(QPoint(width()/2, 0), QPoint(width()/2, height()));
+ const QColor qtGreen(102, 176, 54);
+ gradient.setColorAt(0, qtGreen.dark());
+ gradient.setColorAt(0.5, qtGreen);
+ gradient.setColorAt(1, qtGreen.dark());
+
+ QPainter p(this);
+ p.fillRect(0, 0, width(), height(), gradient);
+
+ QFont headerFont("Sans Serif", 12, QFont::Bold);
+ QFont normalFont("Sans Serif", 9, QFont::Normal);
+
+ // draw it twice for shadow effect
+ p.setFont(headerFont);
+ QRect headerRect(1, 1, width(), 25);
+ p.setPen(Qt::black);
+ p.drawText(headerRect, Qt::AlignCenter, m_station.name());
+
+ headerRect.moveTopLeft(QPoint(0, 0));
+ p.setPen(Qt::white);
+ p.drawText(headerRect, Qt::AlignCenter, m_station.name());
+
+ p.setFont(normalFont);
+ int pos = 40;
+ for (int i = 0; i < m_times.count() && i < 9; ++i) {
+ p.setPen(Qt::black);
+ p.drawText(51, pos + 1, m_times.at(i).time());
+ p.drawText(101, pos + 1, m_times.at(i).direction());
+
+ p.setPen(Qt::white);
+ p.drawText(50, pos, m_times.at(i).time());
+ p.drawText(100, pos, m_times.at(i).direction());
+
+ pos += 18;
+ }
+}
+
+void MainWindow::resizeEvent(QResizeEvent*)
+{
+ QBitmap maskBitmap(width(), height());
+ maskBitmap.clear();
+
+ QPainter p(&maskBitmap);
+ p.setBrush(Qt::black);
+ p.drawRoundRect(0, 0, width(), height(), 20, 30);
+ p.end();
+
+ setMask(maskBitmap);
+}
+
+void MainWindow::updateTimeInformation()
+{
+ TimeQuery query;
+ m_times = query.query(m_station.id(), m_lines, QDateTime::currentDateTime());
+
+ update();
+}
+
+void MainWindow::configure()
+{
+ StationDialog dlg(m_station.name(), m_lines, this);
+ if (dlg.exec()) {
+ m_station = dlg.selectedStation();
+ m_lines = dlg.lineNumbers();
+ updateTimeInformation();
+ }
+}
diff --git a/examples/xmlpatterns/trafficinfo/mainwindow.h b/examples/xmlpatterns/trafficinfo/mainwindow.h
new file mode 100644
index 0000000000..d48109d4f2
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "stationquery.h"
+#include "timequery.h"
+
+#include <QtGui/QWidget>
+
+class MainWindow : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ MainWindow();
+ ~MainWindow();
+
+ QSize sizeHint() const;
+
+ protected:
+ void mouseMoveEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+ private Q_SLOTS:
+ void updateTimeInformation();
+ void configure();
+
+ private:
+ QPoint m_dragPosition;
+ TimeInformation::List m_times;
+ StationInformation m_station;
+ QStringList m_lines;
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/station_example.wml b/examples/xmlpatterns/trafficinfo/station_example.wml
new file mode 100644
index 0000000000..da7f82f697
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/station_example.wml
@@ -0,0 +1,31 @@
+//! [0]
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
+<wml>
+<template>
+ <do type="prev" name="b" label="Tilbake"><prev/></do>
+ <do type="options" label="Nytt søk"><go href="velkommen.wml"/></do>
+</template>
+<card id="Liste" title="Trafikanten">
+<p>
+<small>
+Velg stoppsted: <br />
+
+ <a title="Velg" href="DateLink.asp?fra=05280320">Nydalen (Østre Toten) (Ø-T)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012126">Nydalen st. (i Store ringvei) (OSL)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012131">Nydalen T [buss] (OSL)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012130">Nydalen [T-bane] (OSL)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012125">Nydalen [tog] (OSL)</a><br />
+
+<br/>
+<a title="Nytt søk" href="Velkommen.wml">"Nytt søk"</a>
+<br/>
+</small>
+</p>
+</card>
+</wml>
+//! [0]
diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.cpp b/examples/xmlpatterns/trafficinfo/stationdialog.cpp
new file mode 100644
index 0000000000..9876bdb838
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationdialog.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "stationdialog.h"
+#include "ui_stationdialog.h"
+
+#include <QtCore/QAbstractListModel>
+
+class StationModel : public QAbstractListModel
+{
+ public:
+ enum Role
+ {
+ StationIdRole = Qt::UserRole + 1,
+ StationNameRole
+ };
+
+ StationModel(QObject *parent = 0)
+ : QAbstractListModel(parent)
+ {
+ }
+
+ void setStations(const StationInformation::List &list)
+ {
+ m_stations = list;
+ layoutChanged();
+ }
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const
+ {
+ if (!parent.isValid())
+ return m_stations.count();
+ else
+ return 0;
+ }
+
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const
+ {
+ if (!parent.isValid())
+ return 1;
+ else
+ return 0;
+ }
+
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
+ {
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.column() > 1 || index.row() >= m_stations.count())
+ return QVariant();
+
+ const StationInformation info = m_stations.at(index.row());
+ if (role == Qt::DisplayRole || role == StationNameRole)
+ return info.name();
+ else if (role == StationIdRole)
+ return info.id();
+
+ return QVariant();
+ }
+
+ private:
+ StationInformation::List m_stations;
+};
+
+StationDialog::StationDialog(const QString &name, const QStringList &lineNumbers, QWidget *parent)
+ : QDialog(parent)
+{
+ m_ui.setupUi(this);
+
+ connect(m_ui.m_searchButton, SIGNAL(clicked()), this, SLOT(searchStations()));
+
+ m_ui.m_searchButton->setDefault(true);
+ m_ui.m_input->setText(name);
+
+ m_model = new StationModel(this);
+ m_ui.m_view->setModel(m_model);
+
+ for (int i = 0; i < lineNumbers.count(); ++i) {
+ if (i == 0)
+ m_ui.m_line1->setText(lineNumbers.at(i));
+ else if (i == 1)
+ m_ui.m_line2->setText(lineNumbers.at(i));
+ else if (i == 2)
+ m_ui.m_line3->setText(lineNumbers.at(i));
+ else if (i == 3)
+ m_ui.m_line4->setText(lineNumbers.at(i));
+ }
+
+ searchStations();
+}
+
+StationInformation StationDialog::selectedStation() const
+{
+ const QModelIndex index = m_ui.m_view->currentIndex();
+
+ if (!index.isValid())
+ return StationInformation();
+
+ return StationInformation(index.data(StationModel::StationIdRole).toString(),
+ index.data(StationModel::StationNameRole).toString());
+}
+
+QStringList StationDialog::lineNumbers() const
+{
+ QStringList lines;
+
+ if (!m_ui.m_line1->text().simplified().isEmpty())
+ lines.append(m_ui.m_line1->text().simplified());
+ if (!m_ui.m_line2->text().simplified().isEmpty())
+ lines.append(m_ui.m_line2->text().simplified());
+ if (!m_ui.m_line3->text().simplified().isEmpty())
+ lines.append(m_ui.m_line3->text().simplified());
+ if (!m_ui.m_line4->text().simplified().isEmpty())
+ lines.append(m_ui.m_line4->text().simplified());
+
+ return lines;
+}
+
+void StationDialog::searchStations()
+{
+ StationQuery query;
+
+ m_model->setStations(query.query(m_ui.m_input->text()));
+ m_ui.m_view->keyboardSearch(m_ui.m_input->text());
+}
diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.h b/examples/xmlpatterns/trafficinfo/stationdialog.h
new file mode 100644
index 0000000000..5ac1635bd1
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationdialog.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATIONDIALOG_H
+#define STATIONDIALOG_H
+
+#include <QtGui/QDialog>
+
+#include "stationquery.h"
+#include "ui_stationdialog.h"
+
+class StationModel;
+
+class StationDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ StationDialog(const QString &id, const QStringList &lineNumbers, QWidget *parent);
+
+ StationInformation selectedStation() const;
+ QStringList lineNumbers() const;
+
+ private Q_SLOTS:
+ void searchStations();
+
+ private:
+ Ui_StationDialog m_ui;
+ StationModel *m_model;
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.ui b/examples/xmlpatterns/trafficinfo/stationdialog.ui
new file mode 100644
index 0000000000..254dedbdc3
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationdialog.ui
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>StationDialog</class>
+ <widget class="QDialog" name="StationDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>462</width>
+ <height>391</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Select Station</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLineEdit" name="m_input"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="m_searchButton">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QListView" name="m_view"/>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Lines:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line1"/>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line2"/>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line3"/>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line4"/>
+ </item>
+ </layout>
+ </item>
+ <item row="3" 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>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>StationDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>228</x>
+ <y>373</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>StationDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>296</x>
+ <y>372</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/xmlpatterns/trafficinfo/stationquery.cpp b/examples/xmlpatterns/trafficinfo/stationquery.cpp
new file mode 100644
index 0000000000..ab42ad93d2
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationquery.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "stationquery.h"
+
+#include <QtCore/QStringList>
+#include <QtXmlPatterns/QXmlQuery>
+
+StationInformation::StationInformation()
+{
+}
+
+StationInformation::StationInformation(const QString &id, const QString &name)
+ : m_id(id), m_name(name)
+{
+}
+
+QString StationInformation::id() const
+{
+ return m_id;
+}
+
+QString StationInformation::name() const
+{
+ return m_name;
+}
+
+//! [0]
+StationInformation::List StationQuery::query(const QString &name)
+{
+ const QString stationIdQueryUrl = QString("doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/substring(@href,18)");
+ const QString stationNameQueryUrl = QString("doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/string()");
+
+ QStringList stationIds;
+ QStringList stationNames;
+
+ QXmlQuery query;
+
+ query.bindVariable("station", QVariant(QString::fromLatin1(QUrl::toPercentEncoding(name))));
+ query.setQuery(stationIdQueryUrl);
+ query.evaluateTo(&stationIds);
+
+ query.bindVariable("station", QVariant(QString::fromLatin1(QUrl::toPercentEncoding(name))));
+ query.setQuery(stationNameQueryUrl);
+ query.evaluateTo(&stationNames);
+
+ if (stationIds.count() != stationNames.count()) // something went wrong...
+ return StationInformation::List();
+
+ StationInformation::List information;
+ for (int i = 0; i < stationIds.count(); ++i)
+ information.append(StationInformation(stationIds.at(i), stationNames.at(i)));
+
+ return information;
+}
+//! [0]
diff --git a/examples/xmlpatterns/trafficinfo/stationquery.h b/examples/xmlpatterns/trafficinfo/stationquery.h
new file mode 100644
index 0000000000..5cbf28ac9b
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationquery.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATIONQUERY_H
+#define STATIONQUERY_H
+
+#include <QtCore/QList>
+#include <QtCore/QString>
+
+//! [0]
+class StationInformation
+{
+ public:
+ typedef QList<StationInformation> List;
+
+ StationInformation();
+ StationInformation(const QString &id, const QString &name);
+
+ QString id() const;
+ QString name() const;
+
+ private:
+ QString m_id;
+ QString m_name;
+};
+//! [0]
+
+//! [1]
+class StationQuery
+{
+ public:
+ static StationInformation::List query(const QString &name);
+};
+//! [1]
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/time_example.wml b/examples/xmlpatterns/trafficinfo/time_example.wml
new file mode 100644
index 0000000000..75e340880d
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/time_example.wml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
+<wml>
+<template>
+ <do type="prev" name="b" label="Tilbake"><prev/></do>
+ <do type="options" name="n" label="Nytt søk"><go href="velkommen.wml"/></do>
+</template>
+<card id="Liste" title="Trafikanten">
+<p>
+<small>
+Fra Nydalen [T-bane]:<br />
+
+ <a href="Rute.asp?d=3011030&amp;t=21832&amp;l=4&amp;Start=1">13.00</a>
+ 4 Bergkrystallen [T-bane]<br />
+
+ <a href="Rute.asp?d=3012585&amp;t=22543&amp;l=6&amp;Start=1">13.05</a>
+ 6 Åsjordet<br />
+
+ <a href="Rute.asp?d=3011730&amp;t=22264&amp;l=5&amp;Start=1">13.09</a>
+ 5 Vestli [T-bane]<br />
+
+ <a href="Rute.asp?d=3012120&amp;t=22080&amp;l=5&amp;Start=1">13.13</a>
+ 5 Storo [T-bane]<br />
+
+ <a href="Rute.asp?d=3011030&amp;t=21831&amp;l=4&amp;Start=1">13.15</a>
+ 4 Bergkrystallen [T-bane]<br />
+
+ <a href="Rute.asp?d=3012585&amp;t=22542&amp;l=6&amp;Start=1">13.20</a>
+ 6 Åsjordet<br />
+
+ <a href="Rute.asp?d=3011730&amp;t=22263&amp;l=5&amp;Start=1">13.24</a>
+ 5 Vestli [T-bane]<br />
+
+ <a href="Rute.asp?d=3012120&amp;t=22079&amp;l=5&amp;Start=1">13.28</a>
+ 5 Storo [T-bane]<br />
+
+ <a href="Rute.asp?d=3011030&amp;t=21830&amp;l=4&amp;Start=1">13.30</a>
+ 4 Bergkrystallen [T-bane]<br />
+
+ <a href="Rute.asp?d=3012585&amp;t=22541&amp;l=6&amp;Start=1">13.35</a>
+ 6 Åsjordet<br />
+
+ <br />
+ <a title="Neste 10" href="F.asp?f=03012130&amp;t=13&amp;m=35&amp;d=14.11.2008&amp;Start=11">Neste 10 avganger</a>
+
+<br/>
+<a href="F.asp?f=03012130&amp;t=14&amp;d=14.11.2008&amp;Start=1">Neste timeintervall</a>
+<br/>
+<a href="F.asp?f=03012130&amp;t=12&amp;d=14.11.2008&amp;Start=1">Forrige timeintervall</a>
+<br/>
+<a href="Velkommen.wml">"Nytt søk"</a>
+<br/>
+</small>
+</p>
+</card>
+</wml>
diff --git a/examples/xmlpatterns/trafficinfo/timequery.cpp b/examples/xmlpatterns/trafficinfo/timequery.cpp
new file mode 100644
index 0000000000..bd63560083
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/timequery.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "timequery.h"
+
+#include <QtCore/QStringList>
+#include <QtXmlPatterns/QXmlQuery>
+
+TimeInformation::TimeInformation(const QString &time, const QString &direction)
+ : m_time(time), m_direction(direction)
+{
+}
+
+QString TimeInformation::time() const
+{
+ return m_time;
+}
+
+QString TimeInformation::direction() const
+{
+ return m_direction;
+}
+
+TimeInformation::List TimeQuery::query(const QString &stationId, const QStringList &lineNumbers, const QDateTime &dateTime)
+{
+ const TimeInformation::List information = queryInternal(stationId, dateTime);
+
+ TimeInformation::List filteredInformation;
+
+ if (!lineNumbers.isEmpty()) {
+ for (int i = 0; i < information.count(); ++i) {
+ const TimeInformation info = information.at(i);
+ for (int j = 0; j < lineNumbers.count(); ++j) {
+ if (info.direction().startsWith(QString("%1 ").arg(lineNumbers.at(j))))
+ filteredInformation.append(info);
+ }
+ }
+ } else {
+ filteredInformation = information;
+ }
+
+ return filteredInformation;
+}
+
+//! [1]
+TimeInformation::List TimeQuery::queryInternal(const QString &stationId, const QDateTime &dateTime)
+{
+ const QString timesQueryUrl = QString("doc('http://wap.trafikanten.no/F.asp?f=%1&amp;t=%2&amp;m=%3&amp;d=%4&amp;start=1')/wml/card/p/small/a[fn:starts-with(@href, 'Rute')]/string()")
+ .arg(stationId)
+ .arg(dateTime.time().hour())
+ .arg(dateTime.time().minute())
+ .arg(dateTime.toString("dd.MM.yyyy"));
+ const QString directionsQueryUrl = QString("doc('http://wap.trafikanten.no/F.asp?f=%1&amp;t=%2&amp;m=%3&amp;d=%4&amp;start=1')/wml/card/p/small/text()[matches(., '[0-9].*')]/string()")
+ .arg(stationId)
+ .arg(dateTime.time().hour())
+ .arg(dateTime.time().minute())
+ .arg(dateTime.toString("dd.MM.yyyy"));
+
+ QStringList times;
+ QStringList directions;
+
+ QXmlQuery query;
+ query.setQuery(timesQueryUrl);
+ query.evaluateTo(&times);
+
+ query.setQuery(directionsQueryUrl);
+ query.evaluateTo(&directions);
+
+ if (times.count() != directions.count()) // something went wrong...
+ return TimeInformation::List();
+
+ TimeInformation::List information;
+ for (int i = 0; i < times.count(); ++i)
+ information.append(TimeInformation(times.at(i).simplified(), directions.at(i).simplified()));
+
+ return information;
+}
+//! [1]
diff --git a/examples/xmlpatterns/trafficinfo/timequery.h b/examples/xmlpatterns/trafficinfo/timequery.h
new file mode 100644
index 0000000000..f88e62c63b
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/timequery.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TIMEQUERY_H
+#define TIMEQUERY_H
+
+#include <QtCore/QDateTime>
+#include <QtCore/QList>
+#include <QtCore/QStringList>
+
+class TimeInformation
+{
+ public:
+ typedef QList<TimeInformation> List;
+
+ TimeInformation(const QString &time, const QString &direction);
+
+ QString time() const;
+ QString direction() const;
+
+ private:
+ QString m_time;
+ QString m_direction;
+};
+
+
+class TimeQuery
+{
+ public:
+ static TimeInformation::List query(const QString &stationId, const QStringList &lineNumbers, const QDateTime &dateTime);
+
+ private:
+ static TimeInformation::List queryInternal(const QString &stationId, const QDateTime &dateTime);
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/trafficinfo.pro b/examples/xmlpatterns/trafficinfo/trafficinfo.pro
new file mode 100644
index 0000000000..52bcc19f16
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/trafficinfo.pro
@@ -0,0 +1,9 @@
+QT += xmlpatterns
+HEADERS = mainwindow.h stationdialog.h stationquery.h timequery.h
+SOURCES = main.cpp mainwindow.cpp stationdialog.cpp stationquery.cpp timequery.cpp
+FORMS = stationdialog.ui
+
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/trafficinfo
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/trafficinfo
+INSTALLS += target sources
diff --git a/examples/xmlpatterns/xmlpatterns.pro b/examples/xmlpatterns/xmlpatterns.pro
new file mode 100644
index 0000000000..081abdebb7
--- /dev/null
+++ b/examples/xmlpatterns/xmlpatterns.pro
@@ -0,0 +1,16 @@
+TEMPLATE = subdirs
+SUBDIRS = recipes \
+ trafficinfo \
+ xquery \
+ filetree
+
+# This example depends on QtWebkit as well.
+contains(QT_CONFIG, webkit):SUBDIRS += qobjectxmlmodel
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xmlpatterns.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/xquery/globalVariables/globalVariables.pro b/examples/xmlpatterns/xquery/globalVariables/globalVariables.pro
new file mode 100644
index 0000000000..0016c41f33
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globalVariables.pro
@@ -0,0 +1,11 @@
+# We don't have any C++ files to build, so in order to trick qmake which
+# doesn't understand that, we use the subdirs template, but without specifying
+# any subdirs.
+TEMPLATE = subdirs
+
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery/globalVariables
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.cpp *.pro *.xq *.html globals.gccxml
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery/globalVariables
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/xquery/globalVariables/globals.cpp b/examples/xmlpatterns/xquery/globalVariables/globals.cpp
new file mode 100644
index 0000000000..7ecd9edf1e
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globals.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+ 1. int mutablePrimitive1;
+ 2. int mutablePrimitive2;
+ 3. const int constPrimitive1 = 4;
+ 4. const int constPrimitive2 = 3;
+ 5.
+ 6. class ComplexClass
+ 7. {
+ 8. public:
+ 9. ComplexClass();
+10. ComplexClass(const ComplexClass &);
+11. ~ComplexClass();
+12. };
+13.
+14. ComplexClass mutableComplex1;
+15. ComplexClass mutableComplex2;
+16. const ComplexClass constComplex1;
+17. const ComplexClass constComplex2;
+18.
+19. int main()
+20. {
+22. int localVariable;
+23. localVariable = 0;
+24. return localVariable;
+25. }
+//! [0]
diff --git a/examples/xmlpatterns/xquery/globalVariables/globals.gccxml b/examples/xmlpatterns/xquery/globalVariables/globals.gccxml
new file mode 100644
index 0000000000..81bcb2202b
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globals.gccxml
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<GCC_XML>
+ <Namespace id="_1" name="::" members="_3 _4 _5 _6 _7 _8 _9 _10 _11 _12 _13 _14 _15 " mangled="_Z2::"/>
+ <Namespace id="_2" name="std" context="_1" members="" mangled="_Z3std"/>
+ <Function id="_3" name="_GLOBAL__D_globals.cppwVRo3a" returns="_16" context="_1" location="f0:14" file="f0" line="14" endline="14"/>
+ <Function id="_4" name="_GLOBAL__I_globals.cppwVRo3a" returns="_16" context="_1" location="f0:14" file="f0" line="14" endline="14"/>
+ <Function id="_5" name="__static_initialization_and_destruction_0" returns="_16" context="_1" mangled="_Z41__static_initialization_and_destruction_0ii" location="f0:23" file="f0" line="23" endline="14">
+ <Argument name="__initialize_p" type="_17"/>
+ <Argument name="__priority" type="_17"/>
+ </Function>
+ <Function id="_6" name="main" returns="_17" context="_1" location="f0:20" file="f0" line="20" endline="24"/>
+ <Variable id="_7" name="constComplex2" type="_11c" context="_1" location="f0:17" file="f0" line="17"/>
+ <Variable id="_8" name="constComplex1" type="_11c" context="_1" location="f0:16" file="f0" line="16"/>
+ <Variable id="_9" name="mutableComplex2" type="_11" context="_1" location="f0:15" file="f0" line="15"/>
+ <Variable id="_10" name="mutableComplex1" type="_11" context="_1" location="f0:14" file="f0" line="14"/>
+ <Class id="_11" name="ComplexClass" context="_1" mangled="12ComplexClass" location="f0:7" file="f0" line="7" members="_19 _20 _21 " bases=""/>
+ <Variable id="_12" name="constPrimitive2" type="_17c" init="3" context="_1" location="f0:4" file="f0" line="4"/>
+ <Variable id="_13" name="constPrimitive1" type="_17c" init="4" context="_1" location="f0:3" file="f0" line="3"/>
+ <Variable id="_14" name="mutablePrimitive2" type="_17" context="_1" location="f0:2" file="f0" line="2"/>
+ <Variable id="_15" name="mutablePrimitive1" type="_17" context="_1" location="f0:1" file="f0" line="1"/>
+ <FundamentalType id="_16" name="void"/>
+ <FundamentalType id="_17" name="int"/>
+ <CvQualifiedType id="_11c" type="_11" const="1"/>
+ <Constructor id="_19" name="ComplexClass" context="_11" mangled="_ZN12ComplexClassC1Ev *INTERNAL* " location="f0:9" file="f0" line="9" extern="1"/>
+ <Constructor id="_20" name="ComplexClass" context="_11" mangled="_ZN12ComplexClassC1ERKS_ *INTERNAL* " location="f0:10" file="f0" line="10" extern="1">
+ <Argument type="_23"/>
+ </Constructor>
+ <Destructor id="_21" name="ComplexClass" context="_11" mangled="_ZN12ComplexClassD1Ev *INTERNAL* " location="f0:11" file="f0" line="11" extern="1">
+ </Destructor>
+ <CvQualifiedType id="_17c" type="_17" const="1"/>
+ <ReferenceType id="_23" type="_11c"/>
+ <File id="f0" name="globals.cpp"/>
+</GCC_XML>
diff --git a/examples/xmlpatterns/xquery/globalVariables/globals.html b/examples/xmlpatterns/xquery/globalVariables/globals.html
new file mode 100644
index 0000000000..d8affc88b1
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globals.html
@@ -0,0 +1,40 @@
+<html xmlns="http://www.w3.org/1999/xhtml/" xml:lang="en" lang="en">
+ <head>
+ <title>Global variables report for globals.gccxml</title>
+ </head>
+ <style type="text/css">
+ .details
+ {
+ text-align: center;
+ font-size: 80%;
+ color: blue
+ }
+ .variableName
+ {
+ font-family: courier;
+ color: blue
+ }
+ </style>
+ <body>
+ <p class="details">Start report: 2008-12-16T13:43:49.65Z</p>
+ <p>Global variables with complex types:</p>
+ <ol>
+ <li>
+ <span class="variableName">mutableComplex1</span> in globals.cpp at line 14</li>
+ <li>
+ <span class="variableName">mutableComplex2</span> in globals.cpp at line 15</li>
+ <li>
+ <span class="variableName">constComplex1</span> in globals.cpp at line 16</li>
+ <li>
+ <span class="variableName">constComplex2</span> in globals.cpp at line 17</li>
+ </ol>
+ <p>Mutable global variables with primitives types:</p>
+ <ol>
+ <li>
+ <span class="variableName">mutablePrimitive1</span> in globals.cpp at line 1</li>
+ <li>
+ <span class="variableName">mutablePrimitive2</span> in globals.cpp at line 2</li>
+ </ol>
+ <p class="details">End report: 2008-12-16T13:43:49.65Z</p>
+ </body>
+</html>
diff --git a/examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq b/examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq
new file mode 100644
index 0000000000..026679d6f4
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq
@@ -0,0 +1,110 @@
+(:
+ This XQuery loads a GCC-XML file and reports the locations of all
+ global variables in the original C++ source. To run the query,
+ use the command line:
+
+ xmlpatterns reportGlobals.xq -param fileToOpen=globals.gccxml -output globals.html
+
+ "fileToOpen=globals.gccxml" binds the file name "globals.gccxml"
+ to the variable "fileToOpen" declared and used below.
+:)
+
+declare variable $fileToOpen as xs:anyURI external;
+declare variable $inDoc as document-node() := doc($fileToOpen);
+
+(:
+ This function determines whether the typeId is a complex type,
+ e.g. QString. We only check whether it's a class. To be strictly
+ correct, we should check whether the class has a non-synthesized
+ constructor. We accept both mutable and const types.
+:)
+declare function local:isComplexType($typeID as xs:string) as xs:boolean
+{
+ exists($inDoc/GCC_XML/Class[@id = $typeID])
+ or
+ exists($inDoc/GCC_XML/Class[@id = $inDoc/GCC_XML/CvQualifiedType[@id = $typeID]/@type])
+};
+
+(:
+ This function determines whether the typeId is a primitive type.
+:)
+declare function local:isPrimitive($typeId as xs:string) as xs:boolean
+{
+ exists($inDoc/GCC_XML/FundamentalType[@id = $typeId])
+};
+
+(:
+ This function constructs a line for the report. The line contains
+ a variable name, the source file, and the line number.
+:)
+declare function local:location($block as element()) as xs:string
+{
+ concat($inDoc/GCC_XML/File[@id = $block/@file]/@name, " at line ", $block/@line)
+};
+
+(:
+ This function generates the report. Note that it is called once
+ in the <body> element of the <html> output.
+
+ It ignores const variables of simple types but reports all others.
+:)
+declare function local:report() as element()+
+{
+ let $complexVariables as element(Variable)* := $inDoc/GCC_XML/Variable[local:isComplexType(@type)]
+ return if (exists($complexVariables))
+ then (<p xmlns="http://www.w3.org/1999/xhtml/">Global variables with complex types:</p>,
+ <ol xmlns="http://www.w3.org/1999/xhtml/">
+ {
+ (: For each Variable in $complexVariables... :)
+ $complexVariables/<li><span class="variableName">{string(@name)}</span> in {local:location(.)}</li>
+ }
+ </ol>)
+ else <p xmlns="http://www.w3.org/1999/xhtml/">No complex global variables found.</p>
+
+ ,
+
+ let $primitiveVariables as element(Variable)+ := $inDoc/GCC_XML/Variable[local:isPrimitive(@type)]
+ return if (exists($primitiveVariables))
+ then (<p xmlns="http://www.w3.org/1999/xhtml/">Mutable global variables with primitives types:</p>,
+ <ol xmlns="http://www.w3.org/1999/xhtml/">
+ {
+ (: For each Variable in $complexVariables... :)
+ $primitiveVariables/<li><span class="variableName">{string(@name)}</span> in {local:location(.)}</li>
+ }
+ </ol>)
+ else <p xmlns="http://www.w3.org/1999/xhtml/">No mutable primitive global variables found.</p>
+};
+
+(:
+ This is where the <html> report is output. First
+ there is some style stuff, then the <body> element,
+ which contains the call to the \c{local:report()}
+ declared above.
+:)
+<html xmlns="http://www.w3.org/1999/xhtml/" xml:lang="en" lang="en">
+ <head>
+ <title>Global variables report for {$fileToOpen}</title>
+ </head>
+ <style type="text/css">
+ .details
+ {{
+ text-align: left;
+ font-size: 80%;
+ color: blue
+ }}
+ .variableName
+ {{
+ font-family: courier;
+ color: blue
+ }}
+ </style>
+
+ <body>
+ <p class="details">Start report: {current-dateTime()}</p>
+ {
+ local:report()
+ }
+ <p class="details">End report: {current-dateTime()}</p>
+ </body>
+
+</html>
diff --git a/examples/xmlpatterns/xquery/xquery.pro b/examples/xmlpatterns/xquery/xquery.pro
new file mode 100644
index 0000000000..2a911889cf
--- /dev/null
+++ b/examples/xmlpatterns/xquery/xquery.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS += globalVariables
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xquery.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)