summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.pro3
-rw-r--r--examples/gui/analogclock/main.cpp4
-rw-r--r--examples/gui/openglwindow/main.cpp4
-rw-r--r--examples/gui/openglwindow/openglwindow.h4
-rw-r--r--examples/gui/rasterwindow/rasterwindow.h6
-rw-r--r--examples/network/bearermonitor/sessionwidget.h2
-rw-r--r--examples/network/blockingfortuneclient/fortunethread.h2
-rw-r--r--examples/network/googlesuggest/googlesuggest.h2
-rw-r--r--examples/network/network-chat/connection.h2
-rw-r--r--examples/network/network-chat/server.h2
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.h2
-rw-r--r--examples/network/threadedfortuneserver/fortunethread.h2
-rw-r--r--examples/network/torrent/filemanager.h2
-rw-r--r--examples/network/torrent/mainwindow.cpp12
-rw-r--r--examples/network/torrent/mainwindow.h4
-rw-r--r--examples/network/torrent/peerwireclient.h14
-rw-r--r--examples/network/torrent/torrentclient.h2
-rw-r--r--examples/network/torrent/torrentserver.h2
-rw-r--r--examples/network/torrent/trackerclient.h2
-rw-r--r--examples/opengl/2dpainting/2dpainting.pro2
-rw-r--r--examples/opengl/2dpainting/glwidget.cpp5
-rw-r--r--examples/opengl/2dpainting/glwidget.h6
-rw-r--r--examples/opengl/2dpainting/main.cpp6
-rw-r--r--examples/opengl/2dpainting/widget.cpp2
-rw-r--r--examples/opengl/2dpainting/widget.h2
-rw-r--r--examples/opengl/cube/cube.pro21
-rw-r--r--examples/opengl/cube/geometryengine.cpp46
-rw-r--r--examples/opengl/cube/geometryengine.h15
-rw-r--r--examples/opengl/cube/main.cpp8
-rw-r--r--examples/opengl/cube/mainwidget.cpp46
-rw-r--r--examples/opengl/cube/mainwidget.h30
-rw-r--r--examples/opengl/doc/images/framebufferobject2-example.pngbin203754 -> 0 bytes
-rw-r--r--examples/opengl/doc/images/grabber-example.pngbin9893 -> 0 bytes
-rw-r--r--examples/opengl/doc/images/hellogl-es-example.pngbin61110 -> 0 bytes
-rw-r--r--examples/opengl/doc/images/hellogl-example.pngbin9520 -> 0 bytes
-rw-r--r--examples/opengl/doc/images/hellogl2-example.pngbin0 -> 19031 bytes
-rw-r--r--examples/opengl/doc/images/overpainting-example.pngbin67841 -> 0 bytes
-rw-r--r--examples/opengl/doc/images/pbuffers-example.pngbin192554 -> 0 bytes
-rw-r--r--examples/opengl/doc/images/pbuffers2-example.pngbin176171 -> 0 bytes
-rw-r--r--examples/opengl/doc/images/samplebuffers-example.pngbin16292 -> 0 bytes
-rw-r--r--examples/opengl/doc/src/cube.qdoc4
-rw-r--r--examples/opengl/doc/src/framebufferobject2.qdoc38
-rw-r--r--examples/opengl/doc/src/grabber.qdoc36
-rw-r--r--examples/opengl/doc/src/hellogl.qdoc306
-rw-r--r--examples/opengl/doc/src/hellogl2.qdoc (renamed from examples/opengl/doc/src/pbuffers.qdoc)21
-rw-r--r--examples/opengl/doc/src/overpainting.qdoc244
-rw-r--r--examples/opengl/doc/src/pbuffers2.qdoc38
-rw-r--r--examples/opengl/doc/src/samplebuffers.qdoc37
-rw-r--r--examples/opengl/hellogl2/glwidget.cpp289
-rw-r--r--examples/opengl/hellogl2/glwidget.h104
-rw-r--r--examples/opengl/hellogl2/hellogl2.pro15
-rw-r--r--examples/opengl/hellogl2/logo.cpp141
-rw-r--r--examples/opengl/hellogl2/logo.h65
-rw-r--r--examples/opengl/hellogl2/main.cpp71
-rw-r--r--examples/opengl/hellogl2/mainwindow.cpp66
-rw-r--r--examples/opengl/hellogl2/mainwindow.h (renamed from examples/opengl/hellogl_es2/mainwindow.h)5
-rw-r--r--examples/opengl/hellogl2/window.cpp133
-rw-r--r--examples/opengl/hellogl2/window.h78
-rw-r--r--examples/opengl/hellogl_es2/glwidget.cpp461
-rw-r--r--examples/opengl/hellogl_es2/hellogl_es2.pro23
-rw-r--r--examples/opengl/hellogl_es2/mainwindow.cpp107
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp39
-rw-r--r--examples/opengl/hellowindow/hellowindow.h14
-rw-r--r--examples/opengl/hellowindow/main.cpp6
-rw-r--r--examples/opengl/legacy/README4
-rw-r--r--examples/opengl/legacy/framebufferobject2/cubelogo.png (renamed from examples/opengl/framebufferobject2/cubelogo.png)bin5920 -> 5920 bytes
-rw-r--r--examples/opengl/legacy/framebufferobject2/framebufferobject2.pro (renamed from examples/opengl/framebufferobject2/framebufferobject2.pro)0
-rw-r--r--examples/opengl/legacy/framebufferobject2/framebufferobject2.qrc (renamed from examples/opengl/framebufferobject2/framebufferobject2.qrc)0
-rw-r--r--examples/opengl/legacy/framebufferobject2/glwidget.cpp (renamed from examples/opengl/framebufferobject2/glwidget.cpp)0
-rw-r--r--examples/opengl/legacy/framebufferobject2/glwidget.h (renamed from examples/opengl/framebufferobject2/glwidget.h)12
-rw-r--r--examples/opengl/legacy/framebufferobject2/main.cpp (renamed from examples/opengl/framebufferobject2/main.cpp)0
-rw-r--r--examples/opengl/legacy/grabber/glwidget.cpp (renamed from examples/opengl/grabber/glwidget.cpp)0
-rw-r--r--examples/opengl/legacy/grabber/glwidget.h (renamed from examples/opengl/grabber/glwidget.h)10
-rw-r--r--examples/opengl/legacy/grabber/grabber.pro (renamed from examples/opengl/grabber/grabber.pro)0
-rw-r--r--examples/opengl/legacy/grabber/main.cpp (renamed from examples/opengl/grabber/main.cpp)0
-rw-r--r--examples/opengl/legacy/grabber/mainwindow.cpp (renamed from examples/opengl/grabber/mainwindow.cpp)0
-rw-r--r--examples/opengl/legacy/grabber/mainwindow.h (renamed from examples/opengl/grabber/mainwindow.h)0
-rw-r--r--examples/opengl/legacy/hellogl/glwidget.cpp (renamed from examples/opengl/hellogl/glwidget.cpp)6
-rw-r--r--examples/opengl/legacy/hellogl/glwidget.h (renamed from examples/opengl/hellogl/glwidget.h)14
-rw-r--r--examples/opengl/legacy/hellogl/hellogl.pro (renamed from examples/opengl/hellogl/hellogl.pro)0
-rw-r--r--examples/opengl/legacy/hellogl/main.cpp (renamed from examples/opengl/hellogl/main.cpp)0
-rw-r--r--examples/opengl/legacy/hellogl/window.cpp (renamed from examples/opengl/hellogl/window.cpp)0
-rw-r--r--examples/opengl/legacy/hellogl/window.h (renamed from examples/opengl/hellogl/window.h)2
-rw-r--r--examples/opengl/legacy/legacy.pro16
-rw-r--r--examples/opengl/legacy/overpainting/bubble.cpp (renamed from examples/opengl/overpainting/bubble.cpp)0
-rw-r--r--examples/opengl/legacy/overpainting/bubble.h (renamed from examples/opengl/overpainting/bubble.h)0
-rw-r--r--examples/opengl/legacy/overpainting/glwidget.cpp (renamed from examples/opengl/overpainting/glwidget.cpp)0
-rw-r--r--examples/opengl/legacy/overpainting/glwidget.h (renamed from examples/opengl/overpainting/glwidget.h)14
-rw-r--r--examples/opengl/legacy/overpainting/main.cpp (renamed from examples/opengl/overpainting/main.cpp)0
-rw-r--r--examples/opengl/legacy/overpainting/overpainting.pro (renamed from examples/opengl/overpainting/overpainting.pro)0
-rw-r--r--examples/opengl/legacy/pbuffers/cube.cpp (renamed from examples/opengl/pbuffers/cube.cpp)0
-rw-r--r--examples/opengl/legacy/pbuffers/cube.h (renamed from examples/opengl/pbuffers/cube.h)0
-rw-r--r--examples/opengl/legacy/pbuffers/cubelogo.png (renamed from examples/opengl/pbuffers/cubelogo.png)bin5920 -> 5920 bytes
-rw-r--r--examples/opengl/legacy/pbuffers/glwidget.cpp (renamed from examples/opengl/pbuffers/glwidget.cpp)0
-rw-r--r--examples/opengl/legacy/pbuffers/glwidget.h (renamed from examples/opengl/pbuffers/glwidget.h)10
-rw-r--r--examples/opengl/legacy/pbuffers/main.cpp (renamed from examples/opengl/pbuffers/main.cpp)0
-rw-r--r--examples/opengl/legacy/pbuffers/pbuffers.pro (renamed from examples/opengl/pbuffers/pbuffers.pro)0
-rw-r--r--examples/opengl/legacy/pbuffers/pbuffers.qrc (renamed from examples/opengl/pbuffers/pbuffers.qrc)0
-rw-r--r--examples/opengl/legacy/pbuffers2/bubbles.svg (renamed from examples/opengl/pbuffers2/bubbles.svg)0
-rw-r--r--examples/opengl/legacy/pbuffers2/designer.png (renamed from examples/opengl/pbuffers2/designer.png)bin2810 -> 2810 bytes
-rw-r--r--examples/opengl/legacy/pbuffers2/glwidget.cpp (renamed from examples/opengl/pbuffers2/glwidget.cpp)0
-rw-r--r--examples/opengl/legacy/pbuffers2/glwidget.h (renamed from examples/opengl/pbuffers2/glwidget.h)0
-rw-r--r--examples/opengl/legacy/pbuffers2/main.cpp (renamed from examples/opengl/pbuffers2/main.cpp)0
-rw-r--r--examples/opengl/legacy/pbuffers2/pbuffers2.pro (renamed from examples/opengl/pbuffers2/pbuffers2.pro)0
-rw-r--r--examples/opengl/legacy/pbuffers2/pbuffers2.qrc (renamed from examples/opengl/pbuffers2/pbuffers2.qrc)0
-rw-r--r--examples/opengl/legacy/samplebuffers/glwidget.cpp (renamed from examples/opengl/samplebuffers/glwidget.cpp)0
-rw-r--r--examples/opengl/legacy/samplebuffers/glwidget.h (renamed from examples/opengl/samplebuffers/glwidget.h)8
-rw-r--r--examples/opengl/legacy/samplebuffers/main.cpp (renamed from examples/opengl/samplebuffers/main.cpp)0
-rw-r--r--examples/opengl/legacy/samplebuffers/samplebuffers.pro (renamed from examples/opengl/samplebuffers/samplebuffers.pro)0
-rw-r--r--examples/opengl/legacy/shared/qtlogo.cpp (renamed from examples/opengl/shared/qtlogo.cpp)0
-rw-r--r--examples/opengl/legacy/shared/qtlogo.h (renamed from examples/opengl/shared/qtlogo.h)0
-rw-r--r--examples/opengl/opengl.pro31
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.h4
-rw-r--r--examples/opengl/qopenglwidget/bubble.cpp (renamed from examples/opengl/hellogl_es2/bubble.cpp)8
-rw-r--r--examples/opengl/qopenglwidget/bubble.h (renamed from examples/opengl/hellogl_es2/bubble.h)2
-rw-r--r--examples/opengl/qopenglwidget/glwidget.cpp549
-rw-r--r--examples/opengl/qopenglwidget/glwidget.h (renamed from examples/opengl/hellogl_es2/glwidget.h)89
-rw-r--r--examples/opengl/qopenglwidget/main.cpp61
-rw-r--r--examples/opengl/qopenglwidget/mainwindow.cpp149
-rw-r--r--examples/opengl/qopenglwidget/mainwindow.h66
-rw-r--r--examples/opengl/qopenglwidget/qopenglwidget.pro15
-rw-r--r--examples/opengl/qopenglwidget/qt.png (renamed from examples/opengl/hellogl_es2/qt.png)bin5174 -> 5174 bytes
-rw-r--r--examples/opengl/qopenglwidget/texture.qrc (renamed from examples/opengl/hellogl_es2/texture.qrc)0
-rw-r--r--examples/opengl/qopenglwindow/background.frag25
-rw-r--r--examples/opengl/qopenglwindow/background_renderer.cpp201
-rw-r--r--examples/opengl/qopenglwindow/background_renderer.h78
-rw-r--r--examples/opengl/qopenglwindow/main.cpp193
-rw-r--r--examples/opengl/qopenglwindow/qopenglwindow.pro15
-rw-r--r--examples/opengl/qopenglwindow/shaders.qrc5
-rw-r--r--examples/opengl/textures/glwidget.cpp78
-rw-r--r--examples/opengl/textures/glwidget.h36
-rw-r--r--examples/opengl/textures/main.cpp8
-rw-r--r--examples/opengl/textures/textures.pro4
-rw-r--r--examples/opengl/textures/window.cpp4
-rw-r--r--examples/opengl/textures/window.h2
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.cpp364
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.h126
-rw-r--r--examples/opengl/threadedqopenglwidget/main.cpp74
-rw-r--r--examples/opengl/threadedqopenglwidget/mainwindow.cpp (renamed from examples/opengl/hellogl_es2/main.cpp)18
-rw-r--r--examples/opengl/threadedqopenglwidget/mainwindow.h54
-rw-r--r--examples/opengl/threadedqopenglwidget/threadedqopenglwidget.pro11
-rw-r--r--examples/qpa/qpa.pro3
-rw-r--r--examples/qpa/qrasterwindow/main.cpp127
-rw-r--r--examples/qpa/qrasterwindow/qrasterwindow.pro4
-rw-r--r--examples/qpa/windows/window.h14
-rw-r--r--examples/qtconcurrent/map/main.cpp2
-rw-r--r--examples/sql/books/bookdelegate.h8
-rw-r--r--examples/sql/drilldown/imageitem.h4
-rw-r--r--examples/sql/drilldown/view.h2
-rw-r--r--examples/sql/querymodel/customsqlmodel.h2
-rw-r--r--examples/sql/querymodel/editablesqlmodel.h4
-rw-r--r--examples/sql/sqlbrowser/browser.h2
-rw-r--r--examples/threads/mandelbrot/mandelbrotwidget.h14
-rw-r--r--examples/threads/mandelbrot/renderthread.h2
-rw-r--r--examples/threads/semaphores/semaphores.cpp4
-rw-r--r--examples/threads/waitconditions/waitconditions.cpp4
-rw-r--r--examples/tools/contiguouscache/randomlistmodel.h4
-rw-r--r--examples/touch/fingerpaint/mainwindow.h2
-rw-r--r--examples/touch/fingerpaint/scribblearea.h6
-rw-r--r--examples/touch/knobs/knob.h2
-rw-r--r--examples/touch/pinchzoom/graphicsview.h2
-rw-r--r--examples/touch/pinchzoom/mouse.h8
-rw-r--r--examples/widgets/animation/animatedtiles/main.cpp12
-rw-r--r--examples/widgets/animation/appchooser/main.cpp8
-rw-r--r--examples/widgets/animation/easing/animation.h2
-rw-r--r--examples/widgets/animation/moveblocks/main.cpp12
-rw-r--r--examples/widgets/animation/states/main.cpp6
-rw-r--r--examples/widgets/animation/stickman/graphicsview.h4
-rw-r--r--examples/widgets/animation/stickman/lifecycle.cpp4
-rw-r--r--examples/widgets/animation/stickman/node.h12
-rw-r--r--examples/widgets/animation/stickman/rectbutton.h6
-rw-r--r--examples/widgets/animation/stickman/stickman.h6
-rw-r--r--examples/widgets/animation/sub-attaq/boat.h2
-rw-r--r--examples/widgets/animation/sub-attaq/boat_p.h18
-rw-r--r--examples/widgets/animation/sub-attaq/pixmapitem.h4
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.h6
-rw-r--r--examples/widgets/animation/sub-attaq/states.h22
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.h2
-rw-r--r--examples/widgets/animation/sub-attaq/submarine_p.h6
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.h2
-rw-r--r--examples/widgets/desktop/systray/window.h4
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.h8
-rw-r--r--examples/widgets/dialogs/licensewizard/licensewizard.h14
-rw-r--r--examples/widgets/draganddrop/draggableicons/dragwidget.h8
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.h6
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.h8
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.h8
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.h8
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.h12
-rw-r--r--examples/widgets/effects/blurpicker/blureffect.h2
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.h6
-rw-r--r--examples/widgets/effects/lighting/lighting.h2
-rw-r--r--examples/widgets/gestures/imagegestures/imagewidget.h8
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h8
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.h14
-rw-r--r--examples/widgets/graphicsview/boxes/main.cpp2
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.h32
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h26
-rw-r--r--examples/widgets/graphicsview/chip/chip.h12
-rw-r--r--examples/widgets/graphicsview/chip/view.h2
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.h8
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.h8
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.h6
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.h6
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramtextitem.h8
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/coloritem.h10
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/main.cpp2
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.h26
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.h6
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.h8
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.h14
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.h12
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h10
-rw-r--r--examples/widgets/graphicsview/graphicsview.pro2
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.cpp2
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.h2
-rw-r--r--examples/widgets/graphicsview/padnavigator/roundrectitem.h4
-rw-r--r--examples/widgets/graphicsview/padnavigator/splashitem.h4
-rw-r--r--examples/widgets/graphicsview/simpleanchorlayout/main.cpp2
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/main.cpp12
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.h16
-rw-r--r--examples/widgets/itemviews/chart/pieview.h40
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h4
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treemodel.h26
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.h8
-rw-r--r--examples/widgets/itemviews/frozencolumn/freezetablewidget.h6
-rw-r--r--examples/widgets/itemviews/interview/model.h16
-rw-r--r--examples/widgets/itemviews/itemviews.pro3
-rw-r--r--examples/widgets/itemviews/pixelator/imagemodel.h8
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.h4
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.h16
-rw-r--r--examples/widgets/itemviews/puzzle/puzzlewidget.h12
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.h14
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treeitem.cpp24
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treeitem.h10
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treemodel.cpp2
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treemodel.h14
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/delegate.h8
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h6
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetitem.h6
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.h10
-rw-r--r--examples/widgets/itemviews/stardelegate/stareditor.h8
-rw-r--r--examples/widgets/itemviews/storageview/main.cpp62
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.cpp177
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.h79
-rw-r--r--examples/widgets/itemviews/storageview/storageview.pro7
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.h18
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.h20
-rw-r--r--examples/widgets/mainwindows/application/mainwindow.cpp8
-rw-r--r--examples/widgets/mainwindows/application/mainwindow.h2
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.cpp6
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.h12
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.cpp13
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.h2
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.h4
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.h2
-rw-r--r--examples/widgets/mainwindows/mdi/mdichild.h2
-rw-r--r--examples/widgets/mainwindows/menus/mainwindow.h2
-rw-r--r--examples/widgets/mainwindows/sdi/mainwindow.h2
-rw-r--r--examples/widgets/painting/affine/xform.h12
-rw-r--r--examples/widgets/painting/basicdrawing/renderarea.h6
-rw-r--r--examples/widgets/painting/composition/composition.cpp12
-rw-r--r--examples/widgets/painting/composition/composition.h12
-rw-r--r--examples/widgets/painting/composition/composition.pro6
-rw-r--r--examples/widgets/painting/concentriccircles/circlewidget.h6
-rw-r--r--examples/widgets/painting/deform/pathdeform.h12
-rw-r--r--examples/widgets/painting/gradients/gradients.h10
-rw-r--r--examples/widgets/painting/painterpaths/renderarea.h6
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.h16
-rw-r--r--examples/widgets/painting/shared/arthurstyle.h20
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.h8
-rw-r--r--examples/widgets/painting/shared/hoverpoints.h2
-rw-r--r--examples/widgets/painting/transformations/renderarea.h6
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.h2
-rw-r--r--examples/widgets/richtext/textedit/example.html2
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp4
-rw-r--r--examples/widgets/richtext/textedit/textedit.h2
-rw-r--r--examples/widgets/scroller/graphicsview/main.cpp18
-rw-r--r--examples/widgets/statemachine/factorial/main.cpp8
-rw-r--r--examples/widgets/statemachine/pingpong/main.cpp10
-rw-r--r--examples/widgets/statemachine/rogue/movementtransition.h4
-rw-r--r--examples/widgets/statemachine/rogue/window.h4
-rw-r--r--examples/widgets/statemachine/trafficlight/main.cpp2
-rw-r--r--examples/widgets/tools/completer/fsmodel.h2
-rw-r--r--examples/widgets/tools/customcompleter/textedit.h4
-rw-r--r--examples/widgets/tools/echoplugin/plugin/echoplugin.h2
-rw-r--r--examples/widgets/tools/i18n/languagechooser.h4
-rw-r--r--examples/widgets/tools/plugandpaint/paintarea.h10
-rw-r--r--examples/widgets/tools/plugandpaintplugins/basictools/basictoolsplugin.h16
-rw-r--r--examples/widgets/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h4
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.h4
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.h8
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.h2
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h2
-rw-r--r--examples/widgets/tools/treemodelcompleter/treemodelcompleter.h4
-rw-r--r--examples/widgets/tools/undo/commands.h24
-rw-r--r--examples/widgets/tools/undo/document.h8
-rw-r--r--examples/widgets/tools/undoframework/commands.h16
-rw-r--r--examples/widgets/tools/undoframework/diagramitem.h2
-rw-r--r--examples/widgets/tools/undoframework/diagramscene.h4
-rw-r--r--examples/widgets/tutorials/modelview/1_readonly/mymodel.h6
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/mymodel.h6
-rw-r--r--examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h6
-rw-r--r--examples/widgets/tutorials/modelview/4_headers/mymodel.h8
-rw-r--r--examples/widgets/tutorials/modelview/5_edit/mymodel.h10
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.h2
-rw-r--r--examples/widgets/widgets/calculator/button.h2
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.h8
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.h6
-rw-r--r--examples/widgets/widgets/elidedlabel/elidedlabel.h2
-rw-r--r--examples/widgets/widgets/elidedlabel/testwidget.h2
-rw-r--r--examples/widgets/widgets/icons/iconsizespinbox.h4
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.h6
-rw-r--r--examples/widgets/widgets/mousebuttons/buttontester.h8
-rw-r--r--examples/widgets/widgets/scribble/mainwindow.h2
-rw-r--r--examples/widgets/widgets/scribble/scribblearea.h10
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.h10
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.h14
-rw-r--r--examples/widgets/widgets/tablet/tabletapplication.h2
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.h6
-rw-r--r--examples/widgets/widgets/tetrix/tetrixboard.h10
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.h12
-rw-r--r--examples/widgets/widgets/wiggly/dialog.cpp22
-rw-r--r--examples/widgets/widgets/wiggly/dialog.h4
-rw-r--r--examples/widgets/widgets/wiggly/main.cpp11
-rw-r--r--examples/widgets/widgets/wiggly/wigglywidget.h4
-rw-r--r--examples/widgets/windowcontainer/windowcontainer.cpp16
-rw-r--r--examples/xml/saxbookmarks/xbelhandler.h10
328 files changed, 4532 insertions, 2327 deletions
diff --git a/examples/examples.pro b/examples/examples.pro
index 79d8d14fce..052802b803 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -8,7 +8,6 @@ SUBDIRS = \
ipc \
json \
network \
- opengl \
qpa \
qtconcurrent \
qtestlib \
@@ -19,6 +18,8 @@ SUBDIRS = \
widgets \
xml
+contains(QT_CONFIG, opengl): SUBDIRS += opengl
+
aggregate.files = aggregate/examples.pro
aggregate.path = $$[QT_INSTALL_EXAMPLES]
readme.files = README
diff --git a/examples/gui/analogclock/main.cpp b/examples/gui/analogclock/main.cpp
index 1e10fcd07b..d51f440dff 100644
--- a/examples/gui/analogclock/main.cpp
+++ b/examples/gui/analogclock/main.cpp
@@ -49,8 +49,8 @@ public:
AnalogClockWindow();
protected:
- void timerEvent(QTimerEvent *);
- void render(QPainter *p);
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
+ void render(QPainter *p) Q_DECL_OVERRIDE;
private:
int m_timerId;
diff --git a/examples/gui/openglwindow/main.cpp b/examples/gui/openglwindow/main.cpp
index aa1c6d7fa1..0b0a0e19f0 100644
--- a/examples/gui/openglwindow/main.cpp
+++ b/examples/gui/openglwindow/main.cpp
@@ -53,8 +53,8 @@ class TriangleWindow : public OpenGLWindow
public:
TriangleWindow();
- void initialize();
- void render();
+ void initialize() Q_DECL_OVERRIDE;
+ void render() Q_DECL_OVERRIDE;
private:
GLuint loadShader(GLenum type, const char *source);
diff --git a/examples/gui/openglwindow/openglwindow.h b/examples/gui/openglwindow/openglwindow.h
index f6b53e3b33..cee888250b 100644
--- a/examples/gui/openglwindow/openglwindow.h
+++ b/examples/gui/openglwindow/openglwindow.h
@@ -67,9 +67,9 @@ public slots:
void renderNow();
protected:
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
- void exposeEvent(QExposeEvent *event);
+ void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE;
private:
bool m_update_pending;
diff --git a/examples/gui/rasterwindow/rasterwindow.h b/examples/gui/rasterwindow/rasterwindow.h
index 8dc3993849..bca73c19e7 100644
--- a/examples/gui/rasterwindow/rasterwindow.h
+++ b/examples/gui/rasterwindow/rasterwindow.h
@@ -57,10 +57,10 @@ public slots:
void renderNow();
protected:
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
- void resizeEvent(QResizeEvent *event);
- void exposeEvent(QExposeEvent *event);
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE;
private:
QBackingStore *m_backingStore;
diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h
index 8d262cb693..a42c20495d 100644
--- a/examples/network/bearermonitor/sessionwidget.h
+++ b/examples/network/bearermonitor/sessionwidget.h
@@ -59,7 +59,7 @@ public:
explicit SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0);
~SessionWidget();
- void timerEvent(QTimerEvent *);
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
private:
void updateSessionState(QNetworkSession::State state);
diff --git a/examples/network/blockingfortuneclient/fortunethread.h b/examples/network/blockingfortuneclient/fortunethread.h
index b0c7301b87..1986873dd9 100644
--- a/examples/network/blockingfortuneclient/fortunethread.h
+++ b/examples/network/blockingfortuneclient/fortunethread.h
@@ -55,7 +55,7 @@ public:
~FortuneThread();
void requestNewFortune(const QString &hostName, quint16 port);
- void run();
+ void run() Q_DECL_OVERRIDE;
signals:
void newFortune(const QString &fortune);
diff --git a/examples/network/googlesuggest/googlesuggest.h b/examples/network/googlesuggest/googlesuggest.h
index b86f6929eb..818a0512e2 100644
--- a/examples/network/googlesuggest/googlesuggest.h
+++ b/examples/network/googlesuggest/googlesuggest.h
@@ -60,7 +60,7 @@ class GSuggestCompletion : public QObject
public:
GSuggestCompletion(QLineEdit *parent = 0);
~GSuggestCompletion();
- bool eventFilter(QObject *obj, QEvent *ev);
+ bool eventFilter(QObject *obj, QEvent *ev) Q_DECL_OVERRIDE;
void showCompletion(const QStringList &choices, const QStringList &hits);
public slots:
diff --git a/examples/network/network-chat/connection.h b/examples/network/network-chat/connection.h
index ee61052faf..2a0603a46f 100644
--- a/examples/network/network-chat/connection.h
+++ b/examples/network/network-chat/connection.h
@@ -78,7 +78,7 @@ signals:
void newMessage(const QString &from, const QString &message);
protected:
- void timerEvent(QTimerEvent *timerEvent);
+ void timerEvent(QTimerEvent *timerEvent) Q_DECL_OVERRIDE;
private slots:
void processReadyRead();
diff --git a/examples/network/network-chat/server.h b/examples/network/network-chat/server.h
index ec22981f30..971eafe10c 100644
--- a/examples/network/network-chat/server.h
+++ b/examples/network/network-chat/server.h
@@ -56,7 +56,7 @@ signals:
void newConnection(Connection *connection);
protected:
- void incomingConnection(qintptr socketDescriptor);
+ void incomingConnection(qintptr socketDescriptor) Q_DECL_OVERRIDE;
};
#endif
diff --git a/examples/network/threadedfortuneserver/fortuneserver.h b/examples/network/threadedfortuneserver/fortuneserver.h
index 2efe2d6207..c49b9058f4 100644
--- a/examples/network/threadedfortuneserver/fortuneserver.h
+++ b/examples/network/threadedfortuneserver/fortuneserver.h
@@ -53,7 +53,7 @@ public:
FortuneServer(QObject *parent = 0);
protected:
- void incomingConnection(qintptr socketDescriptor);
+ void incomingConnection(qintptr socketDescriptor) Q_DECL_OVERRIDE;
private:
QStringList fortunes;
diff --git a/examples/network/threadedfortuneserver/fortunethread.h b/examples/network/threadedfortuneserver/fortunethread.h
index c02d8b48f6..569d35aef8 100644
--- a/examples/network/threadedfortuneserver/fortunethread.h
+++ b/examples/network/threadedfortuneserver/fortunethread.h
@@ -52,7 +52,7 @@ class FortuneThread : public QThread
public:
FortuneThread(int socketDescriptor, const QString &fortune, QObject *parent);
- void run();
+ void run() Q_DECL_OVERRIDE;
signals:
void error(QTcpSocket::SocketError socketError);
diff --git a/examples/network/torrent/filemanager.h b/examples/network/torrent/filemanager.h
index 41f1aa9a40..81b0321ae5 100644
--- a/examples/network/torrent/filemanager.h
+++ b/examples/network/torrent/filemanager.h
@@ -90,7 +90,7 @@ signals:
void pieceVerified(int pieceIndex, bool verified);
protected:
- void run();
+ void run() Q_DECL_OVERRIDE;
private slots:
bool verifySinglePiece(int pieceIndex);
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp
index 649dbb0a77..fe7bbdaf3b 100644
--- a/examples/network/torrent/mainwindow.cpp
+++ b/examples/network/torrent/mainwindow.cpp
@@ -57,8 +57,8 @@ signals:
void fileDropped(const QString &fileName);
protected:
- void dragMoveEvent(QDragMoveEvent *event);
- void dropEvent(QDropEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
#endif
};
@@ -69,8 +69,8 @@ class TorrentViewDelegate : public QItemDelegate
public:
inline TorrentViewDelegate(MainWindow *mainWindow) : QItemDelegate(mainWindow) {}
- inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index ) const
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index ) const Q_DECL_OVERRIDE
{
if (index.column() != 2) {
QItemDelegate::paint(painter, option, index);
@@ -173,6 +173,10 @@ MainWindow::MainWindow(QWidget *parent)
bottomBar->addWidget((uploadLimitLabel = new QLabel(tr("0 KB/s"))));
uploadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing()));
+#ifdef Q_OS_OSX
+ setUnifiedTitleAndToolBarOnMac(true);
+#endif
+
// Set up connections
connect(torrentView, SIGNAL(itemSelectionChanged()),
this, SLOT(setActionsEnabled()));
diff --git a/examples/network/torrent/mainwindow.h b/examples/network/torrent/mainwindow.h
index 6ba42be81f..1862d857ff 100644
--- a/examples/network/torrent/mainwindow.h
+++ b/examples/network/torrent/mainwindow.h
@@ -63,11 +63,11 @@ class MainWindow : public QMainWindow
public:
MainWindow(QWidget *parent = 0);
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
const TorrentClient *clientForRow(int row) const;
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void loadSettings();
diff --git a/examples/network/torrent/peerwireclient.h b/examples/network/torrent/peerwireclient.h
index 35e4cc6ffb..12ce0696f6 100644
--- a/examples/network/torrent/peerwireclient.h
+++ b/examples/network/torrent/peerwireclient.h
@@ -112,14 +112,14 @@ public:
qint64 uploadSpeed() const;
bool canTransferMore() const;
- qint64 bytesAvailable() const { return incomingBuffer.size() + QTcpSocket::bytesAvailable(); }
+ qint64 bytesAvailable() const Q_DECL_OVERRIDE { return incomingBuffer.size() + QTcpSocket::bytesAvailable(); }
qint64 socketBytesAvailable() const { return socket.bytesAvailable(); }
qint64 socketBytesToWrite() const { return socket.bytesToWrite(); }
- void setReadBufferSize(qint64 size);
+ void setReadBufferSize(qint64 size) Q_DECL_OVERRIDE;
void connectToHost(const QHostAddress &address,
- quint16 port, OpenMode openMode = ReadWrite);
+ quint16 port, OpenMode openMode = ReadWrite) Q_DECL_OVERRIDE;
void diconnectFromHost();
signals:
@@ -138,11 +138,11 @@ signals:
void bytesReceived(qint64 size);
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
- qint64 readData(char *data, qint64 maxlen);
- qint64 readLineData(char *data, qint64 maxlen);
- qint64 writeData(const char *data, qint64 len);
+ qint64 readData(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 readLineData(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 writeData(const char *data, qint64 len) Q_DECL_OVERRIDE;
private slots:
void sendHandShake();
diff --git a/examples/network/torrent/torrentclient.h b/examples/network/torrent/torrentclient.h
index 7f48d1697c..ef9c99aea1 100644
--- a/examples/network/torrent/torrentclient.h
+++ b/examples/network/torrent/torrentclient.h
@@ -158,7 +158,7 @@ public slots:
void setupIncomingConnection(PeerWireClient *client);
protected slots:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
private slots:
// File management
diff --git a/examples/network/torrent/torrentserver.h b/examples/network/torrent/torrentserver.h
index 50cc99c7d6..0f1be50c5b 100644
--- a/examples/network/torrent/torrentserver.h
+++ b/examples/network/torrent/torrentserver.h
@@ -58,7 +58,7 @@ public:
void removeClient(TorrentClient *client);
protected:
- void incomingConnection(qintptr socketDescriptor);
+ void incomingConnection(qintptr socketDescriptor) Q_DECL_OVERRIDE;
private slots:
void removeClient();
diff --git a/examples/network/torrent/trackerclient.h b/examples/network/torrent/trackerclient.h
index 6647422e3f..da8b457b0f 100644
--- a/examples/network/torrent/trackerclient.h
+++ b/examples/network/torrent/trackerclient.h
@@ -78,7 +78,7 @@ signals:
void stopped();
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
private slots:
void fetchPeerList();
diff --git a/examples/opengl/2dpainting/2dpainting.pro b/examples/opengl/2dpainting/2dpainting.pro
index 08383a4d39..b9611f5b40 100644
--- a/examples/opengl/2dpainting/2dpainting.pro
+++ b/examples/opengl/2dpainting/2dpainting.pro
@@ -1,4 +1,4 @@
-QT += opengl widgets
+QT += widgets
HEADERS = glwidget.h \
helper.h \
diff --git a/examples/opengl/2dpainting/glwidget.cpp b/examples/opengl/2dpainting/glwidget.cpp
index 0443d5b5bd..5e040ae347 100644
--- a/examples/opengl/2dpainting/glwidget.cpp
+++ b/examples/opengl/2dpainting/glwidget.cpp
@@ -41,11 +41,12 @@
#include "glwidget.h"
#include "helper.h"
+#include <QPainter>
#include <QTimer>
//! [0]
GLWidget::GLWidget(Helper *helper, QWidget *parent)
- : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), helper(helper)
+ : QOpenGLWidget(parent), helper(helper)
{
elapsed = 0;
setFixedSize(200, 200);
@@ -57,7 +58,7 @@ GLWidget::GLWidget(Helper *helper, QWidget *parent)
void GLWidget::animate()
{
elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
- repaint();
+ update();
}
//! [1]
diff --git a/examples/opengl/2dpainting/glwidget.h b/examples/opengl/2dpainting/glwidget.h
index 0e6786a308..07b279117c 100644
--- a/examples/opengl/2dpainting/glwidget.h
+++ b/examples/opengl/2dpainting/glwidget.h
@@ -41,12 +41,12 @@
#ifndef GLWIDGET_H
#define GLWIDGET_H
-#include <QGLWidget>
+#include <QOpenGLWidget>
//! [0]
class Helper;
-class GLWidget : public QGLWidget
+class GLWidget : public QOpenGLWidget
{
Q_OBJECT
@@ -57,7 +57,7 @@ public slots:
void animate();
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
Helper *helper;
diff --git a/examples/opengl/2dpainting/main.cpp b/examples/opengl/2dpainting/main.cpp
index 5daff5c66f..fb3454b1cd 100644
--- a/examples/opengl/2dpainting/main.cpp
+++ b/examples/opengl/2dpainting/main.cpp
@@ -41,10 +41,16 @@
#include "window.h"
#include <QApplication>
+#include <QSurfaceFormat>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+
+ QSurfaceFormat fmt;
+ fmt.setSamples(4);
+ QSurfaceFormat::setDefaultFormat(fmt);
+
Window window;
window.show();
return app.exec();
diff --git a/examples/opengl/2dpainting/widget.cpp b/examples/opengl/2dpainting/widget.cpp
index 12b7935a94..edfff5ba79 100644
--- a/examples/opengl/2dpainting/widget.cpp
+++ b/examples/opengl/2dpainting/widget.cpp
@@ -57,7 +57,7 @@ Widget::Widget(Helper *helper, QWidget *parent)
void Widget::animate()
{
elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
- repaint();
+ update();
}
//! [1]
diff --git a/examples/opengl/2dpainting/widget.h b/examples/opengl/2dpainting/widget.h
index 474ce2be3d..9e2602e73c 100644
--- a/examples/opengl/2dpainting/widget.h
+++ b/examples/opengl/2dpainting/widget.h
@@ -57,7 +57,7 @@ public slots:
void animate();
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
Helper *helper;
diff --git a/examples/opengl/cube/cube.pro b/examples/opengl/cube/cube.pro
index 85272bc471..b9416f1a9d 100644
--- a/examples/opengl/cube/cube.pro
+++ b/examples/opengl/cube/cube.pro
@@ -5,20 +5,17 @@ TEMPLATE = app
SOURCES += main.cpp
-qtHaveModule(opengl) {
- QT += opengl
+SOURCES += \
+ mainwidget.cpp \
+ geometryengine.cpp
- SOURCES += mainwidget.cpp \
- geometryengine.cpp
+HEADERS += \
+ mainwidget.h \
+ geometryengine.h
- HEADERS += \
- mainwidget.h \
- geometryengine.h
-
- RESOURCES += \
- shaders.qrc \
- textures.qrc
-}
+RESOURCES += \
+ shaders.qrc \
+ textures.qrc
# install
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/cube
diff --git a/examples/opengl/cube/geometryengine.cpp b/examples/opengl/cube/geometryengine.cpp
index 0a34213084..618a080c37 100644
--- a/examples/opengl/cube/geometryengine.cpp
+++ b/examples/opengl/cube/geometryengine.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -49,29 +49,27 @@ struct VertexData
QVector2D texCoord;
};
+//! [0]
GeometryEngine::GeometryEngine()
+ : indexBuf(QOpenGLBuffer::IndexBuffer)
{
-}
-
-GeometryEngine::~GeometryEngine()
-{
- glDeleteBuffers(2, vboIds);
-}
-
-void GeometryEngine::init()
-{
- initializeGLFunctions();
+ initializeOpenGLFunctions();
-//! [0]
// Generate 2 VBOs
- glGenBuffers(2, vboIds);
-
-//! [0]
+ arrayBuf.create();
+ indexBuf.create();
// Initializes cube geometry and transfers it to VBOs
initCubeGeometry();
}
+GeometryEngine::~GeometryEngine()
+{
+ arrayBuf.destroy();
+ indexBuf.destroy();
+}
+//! [0]
+
void GeometryEngine::initCubeGeometry()
{
// For cube we would need only 8 vertices but we have to
@@ -133,21 +131,21 @@ void GeometryEngine::initCubeGeometry()
//! [1]
// Transfer vertex data to VBO 0
- glBindBuffer(GL_ARRAY_BUFFER, vboIds[0]);
- glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(VertexData), vertices, GL_STATIC_DRAW);
+ arrayBuf.bind();
+ arrayBuf.allocate(vertices, 24 * sizeof(VertexData));
// Transfer index data to VBO 1
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIds[1]);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, 34 * sizeof(GLushort), indices, GL_STATIC_DRAW);
+ indexBuf.bind();
+ indexBuf.allocate(indices, 34 * sizeof(GLushort));
//! [1]
}
//! [2]
-void GeometryEngine::drawCubeGeometry(QGLShaderProgram *program)
+void GeometryEngine::drawCubeGeometry(QOpenGLShaderProgram *program)
{
// Tell OpenGL which VBOs to use
- glBindBuffer(GL_ARRAY_BUFFER, vboIds[0]);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIds[1]);
+ arrayBuf.bind();
+ indexBuf.bind();
// Offset for position
quintptr offset = 0;
@@ -155,7 +153,7 @@ void GeometryEngine::drawCubeGeometry(QGLShaderProgram *program)
// Tell OpenGL programmable pipeline how to locate vertex position data
int vertexLocation = program->attributeLocation("a_position");
program->enableAttributeArray(vertexLocation);
- glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);
+ program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
// Offset for texture coordinate
offset += sizeof(QVector3D);
@@ -163,7 +161,7 @@ void GeometryEngine::drawCubeGeometry(QGLShaderProgram *program)
// Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
int texcoordLocation = program->attributeLocation("a_texcoord");
program->enableAttributeArray(texcoordLocation);
- glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);
+ program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
// Draw cube geometry using indices from VBO 1
glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, 0);
diff --git a/examples/opengl/cube/geometryengine.h b/examples/opengl/cube/geometryengine.h
index fe90c436c6..0b51ebf5f2 100644
--- a/examples/opengl/cube/geometryengine.h
+++ b/examples/opengl/cube/geometryengine.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -41,22 +41,23 @@
#ifndef GEOMETRYENGINE_H
#define GEOMETRYENGINE_H
-#include <QGLFunctions>
-#include <QGLShaderProgram>
+#include <QOpenGLFunctions>
+#include <QOpenGLShaderProgram>
+#include <QOpenGLBuffer>
-class GeometryEngine : protected QGLFunctions
+class GeometryEngine : protected QOpenGLFunctions
{
public:
GeometryEngine();
virtual ~GeometryEngine();
- void init();
- void drawCubeGeometry(QGLShaderProgram *program);
+ void drawCubeGeometry(QOpenGLShaderProgram *program);
private:
void initCubeGeometry();
- GLuint vboIds[2];
+ QOpenGLBuffer arrayBuf;
+ QOpenGLBuffer indexBuf;
};
#endif // GEOMETRYENGINE_H
diff --git a/examples/opengl/cube/main.cpp b/examples/opengl/cube/main.cpp
index a414fad023..73363da016 100644
--- a/examples/opengl/cube/main.cpp
+++ b/examples/opengl/cube/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -40,6 +40,7 @@
#include <QApplication>
#include <QLabel>
+#include <QSurfaceFormat>
#ifndef QT_NO_OPENGL
#include "mainwidget.h"
@@ -48,6 +49,11 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+
+ QSurfaceFormat format;
+ format.setDepthBufferSize(24);
+ QSurfaceFormat::setDefaultFormat(format);
+
app.setApplicationName("cube");
app.setApplicationVersion("0.1");
#ifndef QT_NO_OPENGL
diff --git a/examples/opengl/cube/mainwidget.cpp b/examples/opengl/cube/mainwidget.cpp
index 5c1cd28b54..b5a7a972d1 100644
--- a/examples/opengl/cube/mainwidget.cpp
+++ b/examples/opengl/cube/mainwidget.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -45,14 +45,21 @@
#include <math.h>
MainWidget::MainWidget(QWidget *parent) :
- QGLWidget(parent),
+ QOpenGLWidget(parent),
+ geometries(0),
+ texture(0),
angularSpeed(0)
{
}
MainWidget::~MainWidget()
{
- deleteTexture(texture);
+ // Make sure the context is current when deleting the texture
+ // and the buffers.
+ makeCurrent();
+ delete texture;
+ delete geometries;
+ doneCurrent();
}
//! [0]
@@ -95,16 +102,18 @@ void MainWidget::timerEvent(QTimerEvent *)
// Update rotation
rotation = QQuaternion::fromAxisAndAngle(rotationAxis, angularSpeed) * rotation;
- // Update scene
- updateGL();
+ // Request an update
+ update();
}
}
//! [1]
void MainWidget::initializeGL()
{
- initializeGLFunctions();
- qglClearColor(Qt::black);
+ initializeOpenGLFunctions();
+
+ glClearColor(0, 0, 0, 1);
+
initShaders();
initTextures();
@@ -116,7 +125,7 @@ void MainWidget::initializeGL()
glEnable(GL_CULL_FACE);
//! [2]
- geometries.init();
+ geometries = new GeometryEngine;
// Use QBasicTimer because its faster than QTimer
timer.start(12, this);
@@ -126,11 +135,11 @@ void MainWidget::initializeGL()
void MainWidget::initShaders()
{
// Compile vertex shader
- if (!program.addShaderFromSourceFile(QGLShader::Vertex, ":/vshader.glsl"))
+ if (!program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vshader.glsl"))
close();
// Compile fragment shader
- if (!program.addShaderFromSourceFile(QGLShader::Fragment, ":/fshader.glsl"))
+ if (!program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fshader.glsl"))
close();
// Link shader pipeline
@@ -147,28 +156,23 @@ void MainWidget::initShaders()
void MainWidget::initTextures()
{
// Load cube.png image
- glEnable(GL_TEXTURE_2D);
- texture = bindTexture(QImage(":/cube.png"));
+ texture = new QOpenGLTexture(QImage(":/cube.png").mirrored());
// Set nearest filtering mode for texture minification
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ texture->setMinificationFilter(QOpenGLTexture::Nearest);
// Set bilinear filtering mode for texture magnification
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ texture->setMagnificationFilter(QOpenGLTexture::Linear);
// Wrap texture coordinates by repeating
// f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ texture->setWrapMode(QOpenGLTexture::Repeat);
}
//! [4]
//! [5]
void MainWidget::resizeGL(int w, int h)
{
- // Set OpenGL viewport to cover whole widget
- glViewport(0, 0, w, h);
-
// Calculate aspect ratio
qreal aspect = qreal(w) / qreal(h ? h : 1);
@@ -188,6 +192,8 @@ void MainWidget::paintGL()
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ texture->bind();
+
//! [6]
// Calculate model view transformation
QMatrix4x4 matrix;
@@ -202,5 +208,5 @@ void MainWidget::paintGL()
program.setUniformValue("texture", 0);
// Draw cube geometry
- geometries.drawCubeGeometry(&program);
+ geometries->drawCubeGeometry(&program);
}
diff --git a/examples/opengl/cube/mainwidget.h b/examples/opengl/cube/mainwidget.h
index 2e6b6bcc77..8aff8f7714 100644
--- a/examples/opengl/cube/mainwidget.h
+++ b/examples/opengl/cube/mainwidget.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -43,18 +43,18 @@
#include "geometryengine.h"
-#include <QGLWidget>
-#include <QGLFunctions>
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector2D>
#include <QBasicTimer>
-#include <QGLShaderProgram>
-
+#include <QOpenGLShaderProgram>
+#include <QOpenGLTexture>
class GeometryEngine;
-class MainWidget : public QGLWidget, protected QGLFunctions
+class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
@@ -63,23 +63,23 @@ public:
~MainWidget();
protected:
- void mousePressEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent *e);
- void timerEvent(QTimerEvent *e);
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE;
- void initializeGL();
- void resizeGL(int w, int h);
- void paintGL();
+ void initializeGL() Q_DECL_OVERRIDE;
+ void resizeGL(int w, int h) Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
void initShaders();
void initTextures();
private:
QBasicTimer timer;
- QGLShaderProgram program;
- GeometryEngine geometries;
+ QOpenGLShaderProgram program;
+ GeometryEngine *geometries;
- GLuint texture;
+ QOpenGLTexture *texture;
QMatrix4x4 projection;
diff --git a/examples/opengl/doc/images/framebufferobject2-example.png b/examples/opengl/doc/images/framebufferobject2-example.png
deleted file mode 100644
index bafb05a08b..0000000000
--- a/examples/opengl/doc/images/framebufferobject2-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/images/grabber-example.png b/examples/opengl/doc/images/grabber-example.png
deleted file mode 100644
index 6a05b94bec..0000000000
--- a/examples/opengl/doc/images/grabber-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/images/hellogl-es-example.png b/examples/opengl/doc/images/hellogl-es-example.png
deleted file mode 100644
index 7e55f09a7a..0000000000
--- a/examples/opengl/doc/images/hellogl-es-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/images/hellogl-example.png b/examples/opengl/doc/images/hellogl-example.png
deleted file mode 100644
index ecb3a3a7b0..0000000000
--- a/examples/opengl/doc/images/hellogl-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/images/hellogl2-example.png b/examples/opengl/doc/images/hellogl2-example.png
new file mode 100644
index 0000000000..5bb702e71c
--- /dev/null
+++ b/examples/opengl/doc/images/hellogl2-example.png
Binary files differ
diff --git a/examples/opengl/doc/images/overpainting-example.png b/examples/opengl/doc/images/overpainting-example.png
deleted file mode 100644
index 0368dcabc8..0000000000
--- a/examples/opengl/doc/images/overpainting-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/images/pbuffers-example.png b/examples/opengl/doc/images/pbuffers-example.png
deleted file mode 100644
index c34a6fd02b..0000000000
--- a/examples/opengl/doc/images/pbuffers-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/images/pbuffers2-example.png b/examples/opengl/doc/images/pbuffers2-example.png
deleted file mode 100644
index 4a9c7175a3..0000000000
--- a/examples/opengl/doc/images/pbuffers2-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/images/samplebuffers-example.png b/examples/opengl/doc/images/samplebuffers-example.png
deleted file mode 100644
index b751c143b3..0000000000
--- a/examples/opengl/doc/images/samplebuffers-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/doc/src/cube.qdoc b/examples/opengl/doc/src/cube.qdoc
index e6b2548cd1..ed1390db1a 100644
--- a/examples/opengl/doc/src/cube.qdoc
+++ b/examples/opengl/doc/src/cube.qdoc
@@ -117,7 +117,9 @@
aren't facing towards screen.
Creating vertex buffer objects and transferring data to them is quite simple using
- OpenGL provided functions.
+ QOpenGLBuffer. MainWidget makes sure the GeometryEngine instance is created and
+ destroyed with the OpenGL context current. This way we can use OpenGL resources
+ in the constructor and perform proper cleanup in the destructor.
\snippet cube/geometryengine.cpp 0
diff --git a/examples/opengl/doc/src/framebufferobject2.qdoc b/examples/opengl/doc/src/framebufferobject2.qdoc
deleted file mode 100644
index 33d641be10..0000000000
--- a/examples/opengl/doc/src/framebufferobject2.qdoc
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: http://www.gnu.org/copyleft/fdl.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example framebufferobject2
- \title Framebuffer Object 2 Example
-
- \ingroup examples-widgets-opengl
- \brief The Framebuffer Object 2 example demonstrates how to use the
- QGLFramebufferObject class to render into an off-screen buffer and
- use the contents as a texture in a QGLWidget.
-
- \image framebufferobject2-example.png
-*/
diff --git a/examples/opengl/doc/src/grabber.qdoc b/examples/opengl/doc/src/grabber.qdoc
deleted file mode 100644
index fd2a2cf748..0000000000
--- a/examples/opengl/doc/src/grabber.qdoc
+++ /dev/null
@@ -1,36 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: http://www.gnu.org/copyleft/fdl.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example grabber
- \title Grabber Example
- \ingroup examples-widgets-opengl
-
- \brief The Grabber examples shows how to retrieve the contents of an OpenGL framebuffer.
-
- \image grabber-example.png
-*/
diff --git a/examples/opengl/doc/src/hellogl.qdoc b/examples/opengl/doc/src/hellogl.qdoc
deleted file mode 100644
index b4aef0ae02..0000000000
--- a/examples/opengl/doc/src/hellogl.qdoc
+++ /dev/null
@@ -1,306 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: http://www.gnu.org/copyleft/fdl.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example hellogl
- \title Hello GL Example
- \ingroup examples-widgets-opengl
-
- \brief The Hello GL example demonstrates the basic use of the OpenGL-related classes
- provided with Qt.
-
- \image hellogl-example.png
-
- Qt provides the QGLWidget class to enable OpenGL graphics to be rendered within
- a standard application user interface. By subclassing this class, and providing
- reimplementations of event handler functions, 3D scenes can be displayed on
- widgets that can be placed in layouts, connected to other objects using signals
- and slots, and manipulated like any other widget.
-
- \tableofcontents
-
- \section1 GLWidget Class Definition
-
- The \c GLWidget class contains some standard public definitions for the
- constructor, destructor, \l{QWidget::sizeHint()}{sizeHint()}, and
- \l{QWidget::minimumSizeHint()}{minimumSizeHint()} functions:
-
- \snippet hellogl/glwidget.h 0
-
- We use a destructor to ensure that any OpenGL-specific data structures
- are deleted when the widget is no longer needed (although in this case nothing
- needs cleaning up).
-
- \snippet hellogl/glwidget.h 1
-
- The signals and slots are used to allow other objects to interact with the
- 3D scene.
-
- \snippet hellogl/glwidget.h 2
-
- OpenGL initialization, viewport resizing, and painting are handled by
- reimplementing the QGLWidget::initializeGL(), QGLWidget::resizeGL(), and
- QGLWidget::paintGL() handler functions. To enable the user to interact
- directly with the scene using the mouse, we reimplement
- QWidget::mousePressEvent() and QWidget::mouseMoveEvent().
-
- \snippet hellogl/glwidget.h 3
-
- The rest of the class contains utility functions and variables that are
- used to construct and hold orientation information for the scene. The
- \c logo variable will be used to hold a pointer to the QtLogo object which
- contains all the geometry.
-
- \section1 GLWidget Class Implementation
-
- In this example, we split the class into groups of functions and describe
- them separately. This helps to illustrate the differences between subclasses
- of native widgets (such as QWidget and QFrame) and QGLWidget subclasses.
-
- \section2 Widget Construction and Sizing
-
- The constructor provides default rotation angles for the scene, sets
- the pointer to the QtLogo object to null, and sets up some colors for
- later use.
-
- \snippet hellogl/glwidget.cpp 0
-
- We also implement a destructor to release OpenGL-related resources when the
- widget is deleted:
-
- \snippet hellogl/glwidget.cpp 1
-
- In this case nothing requires cleaning up.
-
- We provide size hint functions to ensure that the widget is shown at a
- reasonable size:
-
- \snippet hellogl/glwidget.cpp 2
- \codeline
- \snippet hellogl/glwidget.cpp 3
- \snippet hellogl/glwidget.cpp 4
-
- The widget provides three slots that enable other components in the
- example to change the orientation of the scene:
-
- \snippet hellogl/glwidget.cpp 5
-
- In the above slot, the \c xRot variable is updated only if the new angle
- is different to the old one, the \c xRotationChanged() signal is emitted to
- allow other components to be updated, and the widget's
- \l{QGLWidget::updateGL()}{updateGL()} handler function is called.
-
- The \c setYRotation() and \c setZRotation() slots perform the same task for
- rotations measured by the \c yRot and \c zRot variables.
-
- \section2 OpenGL Initialization
-
- The \l{QGLWidget::initializeGL()}{initializeGL()} function is used to
- perform useful initialization tasks that are needed to render the 3D scene.
- These often involve defining colors and materials, enabling and disabling
- certain rendering flags, and setting other properties used to customize the
- rendering process.
-
- \snippet hellogl/glwidget.cpp 6
-
- In this example, we reimplement the function to set the background color,
- create a QtLogo object instance which will contain all the geometry to
- display, and set up the rendering process to use a particular shading model
- and rendering flags.
-
- \section2 Resizing the Viewport
-
- The \l{QGLWidget::resizeGL()}{resizeGL()} function is used to ensure that
- the OpenGL implementation renders the scene onto a viewport that matches the
- size of the widget, using the correct transformation from 3D coordinates to
- 2D viewport coordinates.
-
- The function is called whenever the widget's dimensions change, and is
- supplied with the new width and height. Here, we define a square viewport
- based on the length of the smallest side of the widget to ensure that
- the scene is not distorted if the widget has sides of unequal length:
-
- \snippet hellogl/glwidget.cpp 8
-
- A discussion of the projection transformation used is outside the scope of
- this example. Please consult the OpenGL reference documentation for an
- explanation of projection matrices.
-
- \section2 Painting the Scene
-
- The \l{QGLWidget::paintGL()}{paintGL()} function is used to paint the
- contents of the scene onto the widget. For widgets that only need to be
- decorated with pure OpenGL content, we reimplement QGLWidget::paintGL()
- \e instead of reimplementing QWidget::paintEvent():
-
- \snippet hellogl/glwidget.cpp 7
-
- In this example, we clear the widget using the background color that
- we defined in the \l{QGLWidget::initializeGL()}{initializeGL()} function,
- set up the frame of reference for the geometry we want to display, and
- call the draw method of the QtLogo object to render the scene.
-
- \section2 Mouse Handling
-
- Just as in subclasses of native widgets, mouse events are handled by
- reimplementing functions such as QWidget::mousePressEvent() and
- QWidget::mouseMoveEvent().
-
- The \l{QWidget::mousePressEvent()}{mousePressEvent()} function simply
- records the position of the mouse when a button is initially pressed:
-
- \snippet hellogl/glwidget.cpp 9
-
- The \l{QWidget::mouseMoveEvent()}{mouseMoveEvent()} function uses the
- previous location of the mouse cursor to determine how much the object
- in the scene should be rotated, and in which direction:
-
- \snippet hellogl/glwidget.cpp 10
-
- Since the user is expected to hold down the mouse button and drag the
- cursor to rotate the object, the cursor's position is updated every time
- a move event is received.
-
- \section1 QtLogo Class
-
- This class encapsulates the OpenGL geometry data which will be rendered
- in the basic 3D scene.
-
- \snippet shared/qtlogo.h 0
-
- The geometry is divided into a list of parts which may be rendered in
- different ways. The data itself is contained in a Geometry structure that
- includes the vertices, their lighting normals and index values which
- point into the vertices, grouping them into faces.
-
- \snippet shared/qtlogo.cpp 0
-
- The data in the Geometry class is stored in QVector<QVector3D> members
- which are convenient for use with OpenGL because they expose raw
- contiguous floating point values via the constData() method. Methods
- are included for adding new vertex data, either with smooth normals, or
- facetted normals; and for enabling the geometry ready for rendering.
-
- \snippet shared/qtlogo.cpp 1
-
- The higher level Patch class has methods for accumulating the geometry
- one face at a time, and treating collections of faces or "patches" with
- transformations, applying different colors or smoothing. Although faces
- may be added as triangles or quads, at the OpenGL level all data is
- treated as triangles for compatibility with OpenGL/ES.
-
- \snippet shared/qtlogo.cpp 2
-
- Drawing a Patch is simply acheived by applying any transformation,
- and material effect, then drawing the data using the index range for
- the patch. The model-view matrix is saved and then restored so that
- any transformation does not affect other parts of the scene.
-
- \snippet shared/qtlogo.cpp 3
-
- The geometry is built once on construction of the QtLogo, and it is
- paramaterized on a number of divisions - which controls how "chunky" the
- curved section of the logo looks - and on a scale, so larger and smaller
- QtLogo objects can be created without having to use OpenGL scaling
- (which would force normal recalculation).
-
- The building process is done by helper classes (read the source for full
- details) which only exist during the build phase, to assemble the parts
- of the scene.
-
- \snippet shared/qtlogo.cpp 4
-
- Finally the complete QtLogo scene is simply drawn by enabling the data arrays
- and then iterating over the parts, calling draw() on each one.
-
- \section1 Window Class Definition
-
- The \c Window class is used as a container for the \c GLWidget used to
- display the scene:
-
- \snippet hellogl/window.h 0
-
- In addition, it contains sliders that are used to change the orientation
- of the object in the scene.
-
- \section1 Window Class Implementation
-
- The constructor constructs an instance of the \c GLWidget class and some
- sliders to manipulate its contents.
-
- \snippet hellogl/window.cpp 0
-
- We connect the \l{QAbstractSlider::valueChanged()}{valueChanged()} signal
- from each of the sliders to the appropriate slots in \c{glWidget}.
- This allows the user to change the orientation of the object by dragging
- the sliders.
-
- We also connect the \c xRotationChanged(), \c yRotationChanged(), and
- \c zRotationChanged() signals from \c glWidget to the
- \l{QAbstractSlider::setValue()}{setValue()} slots in the
- corresponding sliders.
-
- \snippet hellogl/window.cpp 1
-
- The sliders are placed horizontally in a layout alongside the \c GLWidget,
- and initialized with suitable default values.
-
- The \c createSlider() utility function constructs a QSlider, and ensures
- that it is set up with a suitable range, step value, tick interval, and
- page step value before returning it to the calling function:
-
- \snippet hellogl/window.cpp 2
-
- \section1 Summary
-
- The \c GLWidget class implementation shows how to subclass QGLWidget for
- the purposes of rendering a 3D scene using OpenGL calls. Since QGLWidget
- is a subclass of QWidget, subclasses of QGLWidget can be placed in layouts
- and provided with interactive features just like normal custom widgets.
-
- We ensure that the widget is able to correctly render the scene using OpenGL
- by reimplementing the following functions:
-
- \list
- \li QGLWidget::initializeGL() sets up resources needed by the OpenGL implementation
- to render the scene.
- \li QGLWidget::resizeGL() resizes the viewport so that the rendered scene fits onto
- the widget, and sets up a projection matrix to map 3D coordinates to 2D viewport
- coordinates.
- \li QGLWidget::paintGL() performs painting operations using OpenGL calls.
- \endlist
-
- Since QGLWidget is a subclass of QWidget, it can also be used
- as a normal paint device, allowing 2D graphics to be drawn with QPainter.
- This use of QGLWidget is discussed in the \l{2D Painting Example}{2D Painting}
- example.
-
- More advanced users may want to paint over parts of a scene rendered using
- OpenGL. QGLWidget allows pure OpenGL rendering to be mixed with QPainter
- calls, but care must be taken to maintain the state of the OpenGL implementation.
- See the \l{Overpainting Example}{Overpainting} example for more information.
-*/
diff --git a/examples/opengl/doc/src/pbuffers.qdoc b/examples/opengl/doc/src/hellogl2.qdoc
index 8e79ebb17c..adaf9d4719 100644
--- a/examples/opengl/doc/src/pbuffers.qdoc
+++ b/examples/opengl/doc/src/hellogl2.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -26,13 +26,18 @@
****************************************************************************/
/*!
- \example pbuffers
- \title Pixel Buffers Example
-
+ \example hellogl2
+ \title Hello GL2 Example
\ingroup examples-widgets-opengl
- \brief The Pixel Buffers example demonstrates how to use the
- QGLPixelBuffer class to render into an off-screen buffer and use
- the contents as a dynamic texture in a QGLWidget.
- \image pbuffers-example.png
+ \brief The Hello GL2 example demonstrates the basic use of the OpenGL-related classes
+ provided with Qt.
+
+ \image hellogl2-example.png
+
+ Qt provides the QOpenGLWidget class to enable OpenGL graphics to be rendered
+ within a standard application user interface. By subclassing this class, and
+ providing reimplementations of event handler functions, 3D scenes can be
+ displayed on widgets that can be placed in layouts, connected to other
+ objects using signals and slots, and manipulated like any other widget.
*/
diff --git a/examples/opengl/doc/src/overpainting.qdoc b/examples/opengl/doc/src/overpainting.qdoc
deleted file mode 100644
index e9cbbab2c4..0000000000
--- a/examples/opengl/doc/src/overpainting.qdoc
+++ /dev/null
@@ -1,244 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: http://www.gnu.org/copyleft/fdl.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example overpainting
- \title Overpainting Example
-
- \ingroup examples-widgets-opengl
- \brief The Overpainting example shows how QPainter can be used
- to overpaint a scene rendered using OpenGL in a QGLWidget.
-
- \image overpainting-example.png
-
- QGLWidget provides a widget with integrated OpenGL graphics support
- that enables 3D graphics to be displayed using normal OpenGL calls,
- yet also behaves like any other standard Qt widget with support for
- signals and slots, properties, and Qt's action system.
-
- Usually, QGLWidget is subclassed to display a pure 3D scene. The
- developer reimplements \l{QGLWidget::initializeGL()}{initializeGL()}
- to initialize any required resources, \l{QGLWidget::resizeGL()}{resizeGL()}
- to set up the projection and viewport, and
- \l{QGLWidget::paintGL()}{paintGL()} to perform the OpenGL calls needed
- to render the scene. However, it is possible to subclass QGLWidget
- differently to allow 2D graphics, drawn using QPainter, to be
- painted over a scene rendered using OpenGL.
-
- In this example, we demonstrate how this is done by reusing the code
- from the \l{Hello GL Example}{Hello GL} example to provide a 3D scene,
- and painting over it with some translucent 2D graphics. Instead of
- examining each class in detail, we only cover the parts of the
- \c GLWidget class that enable overpainting, and provide more detailed
- discussion in the final section of this document.
-
- \section1 GLWidget Class Definition
-
- The \c GLWidget class is a subclass of QGLWidget, based on the one used
- in the \l{Hello GL Example}{Hello GL} example. Rather than describe the
- class as a whole, we show the first few lines of the class and only
- discuss the changes we have made to the rest of it:
-
- \snippet overpainting/glwidget.h 0
- \dots
- \snippet overpainting/glwidget.h 1
- \dots
- \snippet overpainting/glwidget.h 4
-
- As usual, the widget uses \l{QGLWidget::initializeGL()}{initializeGL()}
- to set up geometry for our scene and perform OpenGL initialization tasks.
- The \l{QGLWidget::resizeGL()}{resizeGL()} function is used to ensure that
- the 3D graphics in the scene are transformed correctly to the 2D viewport
- displayed in the widget.
-
- Instead of implementing \l{QGLWidget::paintGL()}{paintGL()} to handle updates
- to the widget, we implement a normal QWidget::paintEvent(). This
- allows us to mix OpenGL calls and QPainter operations in a controlled way.
-
- In this example, we also implement QWidget::showEvent() to help with the
- initialization of the 2D graphics used.
-
- The new private member functions and variables relate exclusively to the
- 2D graphics and animation. The \c animate() slot is called periodically by the
- \c animationTimer to update the widget; the \c createBubbles() function
- initializes the \c bubbles list with instances of a helper class used to
- draw the animation; the \c drawInstructions() function is responsible for
- a semi-transparent message that is also overpainted onto the OpenGL scene.
-
- \section1 GLWidget Class Implementation
-
- Again, we only show the parts of the \c GLWidget implementation that are
- relevant to this example. In the constructor, we initialize a QTimer to
- control the animation:
-
- \snippet overpainting/glwidget.cpp 0
-
- We turn off the widget's \l{QWidget::autoFillBackground}{autoFillBackground} property to
- instruct OpenGL not to paint a background for the widget when
- \l{QPainter::begin()}{QPainter::begin()} is called.
-
- As in the \l{Hello GL Example}{Hello GL} example, the destructor is responsible
- for freeing any OpenGL-related resources:
-
- \snippet overpainting/glwidget.cpp 1
-
- The \c initializeGL() function is fairly minimal, only setting up the QtLogo
- object used in the scene. See the \l{Hello GL Example}{Hello GL} example
- for details of the QtLogo class.
-
- \snippet overpainting/glwidget.cpp 2
-
- To cooperate fully with QPainter, we defer matrix stack operations and attribute
- initialization until the widget needs to be updated.
-
- In this example, we implement \l{QWidget::paintEvent()}{paintEvent()} rather
- than \l{QGLWidget::paintGL()}{paintGL()} to render
- our scene. When drawing on a QGLWidget, the paint engine used by QPainter
- performs certain operations that change the states of the OpenGL
- implementation's matrix and property stacks. Therefore, it is necessary to
- make all the OpenGL calls to display the 3D graphics before we construct
- a QPainter to draw the 2D overlay.
-
- We render a 3D scene by setting up model and projection transformations
- and other attributes. We use an OpenGL stack operation to preserve the
- original matrix state, allowing us to recover it later:
-
- \snippet overpainting/glwidget.cpp 4
-
- We define a color to use for the widget's background, and set up various
- attributes that define how the scene will be rendered.
-
- \snippet overpainting/glwidget.cpp 6
-
- We call the \c setupViewport() private function to set up the
- projection used for the scene. This is unnecessary in OpenGL
- examples that implement the \l{QGLWidget::paintGL()}{paintGL()}
- function because the matrix stacks are usually unmodified between
- calls to \l{QGLWidget::resizeGL()}{resizeGL()} and
- \l{QGLWidget::paintGL()}{paintGL()}.
-
- Since the widget's background is not drawn by the system or by Qt, we use
- an OpenGL call to paint it before positioning the object defined earlier
- in the scene:
-
- \snippet overpainting/glwidget.cpp 7
-
- Once the QtLogo object's draw method has been executed, the GL
- states we changed and the matrix stack needs to be restored to its
- original state at the start of this function before we can begin
- overpainting:
-
- \snippet overpainting/glwidget.cpp 8
-
- With the 3D graphics done, we construct a QPainter for use on the widget
- and simply overpaint the widget with 2D graphics; in this case, using a
- helper class to draw a number of translucent bubbles onto the widget,
- and calling \c drawInstructions() to overlay some instructions:
-
- \snippet overpainting/glwidget.cpp 10
-
- When QPainter::end() is called, suitable OpenGL-specific calls are made to
- write the scene, and its additional contents, onto the widget.
-
- With \l{QGLWidget::paintGL()}{paintGL()} the
- \l{QGLWidget::swapBuffers()}{swapBuffers()} call is done for us. But an explicit
- call to swapBuffers() is still not required because in the
- \l{QWidget::paintEvent()}{paintEvent()} method the QPainter on the OpenGL
- widget takes care of this for us.
-
- The implementation of the \l{QGLWidget::resizeGL()}{resizeGL()} function
- sets up the dimensions of the viewport and defines a projection
- transformation:
-
- \snippet overpainting/glwidget.cpp 11
-
- Ideally, we want to arrange the 2D graphics to suit the widget's dimensions.
- To achieve this, we implement the \l{QWidget::showEvent()}{showEvent()} handler,
- creating new graphic elements (bubbles) if necessary at appropriate positions
- in the widget.
-
- \snippet overpainting/glwidget.cpp 12
-
- This function only has an effect if less than 20 bubbles have already been
- created.
-
- The \c animate() slot is called every time the widget's \c animationTimer emits
- the \l{QTimer::timeout()}{timeout()} signal. This keeps the bubbles moving
- around.
-
- \snippet overpainting/glwidget.cpp 13
-
- We simply iterate over the bubbles in the \c bubbles list, updating the
- widget before and after each of them is moved.
-
- The \c setupViewport() function is called from \c paintEvent()
- and \c resizeGL().
-
- \snippet overpainting/glwidget.cpp 14
-
- The \c drawInstructions() function is used to prepare some basic
- instructions that will be painted with the other 2D graphics over
- the 3D scene.
-
- \snippet overpainting/glwidget.cpp 15
-
- \section1 Summary
-
- When overpainting 2D content onto 3D content, we need to use a QPainter
- \e and make OpenGL calls to achieve the desired effect. Since QPainter
- itself uses OpenGL calls when used on a QGLWidget subclass, we need to
- preserve the state of various OpenGL stacks when we perform our own
- calls, using the following approach:
-
- \list
- \li Reimplement QGLWidget::initializeGL(), but only perform minimal
- initialization. QPainter will perform its own initialization
- routines, modifying the matrix and property stacks, so it is better
- to defer certain initialization tasks until just before you render
- the 3D scene.
- \li Reimplement QGLWidget::resizeGL() as in the pure 3D case.
- \li Reimplement QWidget::paintEvent() to draw both 2D and 3D graphics.
- \endlist
-
- The \l{QWidget::paintEvent()}{paintEvent()} implementation performs the
- following tasks:
-
- \list
- \li Push the current OpenGL modelview matrix onto a stack.
- \li Perform initialization tasks usually done in the
- \l{QGLWidget::initializeGL()}{initializeGL()} function.
- \li Perform code that would normally be located in the widget's
- \l{QGLWidget::resizeGL()}{resizeGL()} function to set the correct
- perspective transformation and set up the viewport.
- \li Render the scene using OpenGL calls.
- \li Pop the OpenGL modelview matrix off the stack.
- \li Construct a QPainter object.
- \li Initialize it for use on the widget with the QPainter::begin() function.
- \li Draw primitives using QPainter's member functions.
- \li Call QPainter::end() to finish painting.
- \endlist
-*/
diff --git a/examples/opengl/doc/src/pbuffers2.qdoc b/examples/opengl/doc/src/pbuffers2.qdoc
deleted file mode 100644
index 249b8fa25f..0000000000
--- a/examples/opengl/doc/src/pbuffers2.qdoc
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: http://www.gnu.org/copyleft/fdl.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example pbuffers2
- \title Pixel Buffers 2 Example
-
- \ingroup examples-widgets-opengl
- \brief The Pixel Buffers 2 example demonstrates how to use the
- QGLPixelBuffer class to render into an off-screen buffer and use
- the contents as a dynamic texture in a QGLWidget.
-
- \image pbuffers2-example.png
-*/
diff --git a/examples/opengl/doc/src/samplebuffers.qdoc b/examples/opengl/doc/src/samplebuffers.qdoc
deleted file mode 100644
index 4d4d26450e..0000000000
--- a/examples/opengl/doc/src/samplebuffers.qdoc
+++ /dev/null
@@ -1,37 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: http://www.gnu.org/copyleft/fdl.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example samplebuffers
- \title Sample Buffers Example
-
- \ingroup examples-widgets-opengl
- \brief The Sample Buffers example demonstrates how to use and enable
- sample buffers in a QGLWidget.
-
- \image samplebuffers-example.png
-*/
diff --git a/examples/opengl/hellogl2/glwidget.cpp b/examples/opengl/hellogl2/glwidget.cpp
new file mode 100644
index 0000000000..7764fa8dfc
--- /dev/null
+++ b/examples/opengl/hellogl2/glwidget.cpp
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <QMouseEvent>
+#include <QOpenGLShaderProgram>
+#include <QCoreApplication>
+#include <math.h>
+
+GLWidget::GLWidget(QWidget *parent)
+ : QOpenGLWidget(parent),
+ m_xRot(0),
+ m_yRot(0),
+ m_zRot(0),
+ m_program(0)
+{
+ m_core = QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"));
+ // --transparent causes the clear color to be transparent. Therefore, on systems that
+ // support it, the widget will become transparent apart from the logo.
+ m_transparent = QCoreApplication::arguments().contains(QStringLiteral("--transparent"));
+ if (m_transparent)
+ setAttribute(Qt::WA_TranslucentBackground);
+}
+
+GLWidget::~GLWidget()
+{
+ cleanup();
+}
+
+QSize GLWidget::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+
+QSize GLWidget::sizeHint() const
+{
+ return QSize(400, 400);
+}
+
+static void qNormalizeAngle(int &angle)
+{
+ while (angle < 0)
+ angle += 360 * 16;
+ while (angle > 360 * 16)
+ angle -= 360 * 16;
+}
+
+void GLWidget::setXRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != m_xRot) {
+ m_xRot = angle;
+ emit xRotationChanged(angle);
+ update();
+ }
+}
+
+void GLWidget::setYRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != m_yRot) {
+ m_yRot = angle;
+ emit yRotationChanged(angle);
+ update();
+ }
+}
+
+void GLWidget::setZRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != m_zRot) {
+ m_zRot = angle;
+ emit zRotationChanged(angle);
+ update();
+ }
+}
+
+void GLWidget::cleanup()
+{
+ makeCurrent();
+ m_logoVbo.destroy();
+ delete m_program;
+ m_program = 0;
+ doneCurrent();
+}
+
+static const char *vertexShaderSourceCore =
+ "#version 150\n"
+ "in vec4 vertex;\n"
+ "in vec3 normal;\n"
+ "out vec3 vert;\n"
+ "out vec3 vertNormal;\n"
+ "uniform mat4 projMatrix;\n"
+ "uniform mat4 mvMatrix;\n"
+ "uniform mat3 normalMatrix;\n"
+ "void main() {\n"
+ " vert = vertex.xyz;\n"
+ " vertNormal = normalMatrix * normal;\n"
+ " gl_Position = projMatrix * mvMatrix * vertex;\n"
+ "}\n";
+
+static const char *fragmentShaderSourceCore =
+ "#version 150\n"
+ "in highp vec3 vert;\n"
+ "in highp vec3 vertNormal;\n"
+ "out highp vec4 fragColor;\n"
+ "uniform highp vec3 lightPos;\n"
+ "void main() {\n"
+ " highp vec3 L = normalize(lightPos - vert);\n"
+ " highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n"
+ " highp vec3 color = vec3(0.39, 1.0, 0.0);\n"
+ " highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n"
+ " fragColor = vec4(col, 1.0);\n"
+ "}\n";
+
+static const char *vertexShaderSource =
+ "attribute vec4 vertex;\n"
+ "attribute vec3 normal;\n"
+ "varying vec3 vert;\n"
+ "varying vec3 vertNormal;\n"
+ "uniform mat4 projMatrix;\n"
+ "uniform mat4 mvMatrix;\n"
+ "uniform mat3 normalMatrix;\n"
+ "void main() {\n"
+ " vert = vertex.xyz;\n"
+ " vertNormal = normalMatrix * normal;\n"
+ " gl_Position = projMatrix * mvMatrix * vertex;\n"
+ "}\n";
+
+static const char *fragmentShaderSource =
+ "varying highp vec3 vert;\n"
+ "varying highp vec3 vertNormal;\n"
+ "uniform highp vec3 lightPos;\n"
+ "void main() {\n"
+ " highp vec3 L = normalize(lightPos - vert);\n"
+ " highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n"
+ " highp vec3 color = vec3(0.39, 1.0, 0.0);\n"
+ " highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n"
+ " gl_FragColor = vec4(col, 1.0);\n"
+ "}\n";
+
+void GLWidget::initializeGL()
+{
+ // In this example the widget's corresponding top-level window can change
+ // several times during the widget's lifetime. Whenever this happens, the
+ // QOpenGLWidget's associated context is destroyed and a new one is created.
+ // Therefore we have to be prepared to clean up the resources on the
+ // aboutToBeDestroyed() signal, instead of the destructor. The emission of
+ // the signal will be followed by an invocation of initializeGL() where we
+ // can recreate all resources.
+ connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &GLWidget::cleanup);
+
+ initializeOpenGLFunctions();
+ glClearColor(0, 0, 0, m_transparent ? 0 : 1);
+
+ m_program = new QOpenGLShaderProgram;
+ m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_core ? vertexShaderSourceCore : vertexShaderSource);
+ m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_core ? fragmentShaderSourceCore : fragmentShaderSource);
+ m_program->bindAttributeLocation("vertex", 0);
+ m_program->bindAttributeLocation("normal", 1);
+ m_program->link();
+
+ m_program->bind();
+ m_projMatrixLoc = m_program->uniformLocation("projMatrix");
+ m_mvMatrixLoc = m_program->uniformLocation("mvMatrix");
+ m_normalMatrixLoc = m_program->uniformLocation("normalMatrix");
+ m_lightPosLoc = m_program->uniformLocation("lightPos");
+
+ // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
+ // implementations this is optional and support may not be present
+ // at all. Nonetheless the below code works in all cases and makes
+ // sure there is a VAO when one is needed.
+ m_vao.create();
+ QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
+
+ // Setup our vertex buffer object.
+ m_logoVbo.create();
+ m_logoVbo.bind();
+ m_logoVbo.allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
+
+ // Store the vertex attribute bindings for the program.
+ setupVertexAttribs();
+
+ // Our camera never changes in this example.
+ m_camera.setToIdentity();
+ m_camera.translate(0, 0, -1);
+
+ // Light position is fixed.
+ m_program->setUniformValue(m_lightPosLoc, QVector3D(0, 0, 70));
+
+ m_program->release();
+}
+
+void GLWidget::setupVertexAttribs()
+{
+ m_logoVbo.bind();
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ f->glEnableVertexAttribArray(0);
+ f->glEnableVertexAttribArray(1);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
+ f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
+ m_logoVbo.release();
+}
+
+void GLWidget::paintGL()
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+
+ m_world.setToIdentity();
+ m_world.rotate(180.0f - (m_xRot / 16.0f), 1, 0, 0);
+ m_world.rotate(m_yRot / 16.0f, 0, 1, 0);
+ m_world.rotate(m_zRot / 16.0f, 0, 0, 1);
+
+ QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
+ m_program->bind();
+ m_program->setUniformValue(m_projMatrixLoc, m_proj);
+ m_program->setUniformValue(m_mvMatrixLoc, m_camera * m_world);
+ QMatrix3x3 normalMatrix = m_world.normalMatrix();
+ m_program->setUniformValue(m_normalMatrixLoc, normalMatrix);
+
+ glDrawArrays(GL_TRIANGLES, 0, m_logo.vertexCount());
+
+ m_program->release();
+}
+
+void GLWidget::resizeGL(int w, int h)
+{
+ m_proj.setToIdentity();
+ m_proj.perspective(45.0f, GLfloat(w) / h, 0.01f, 100.0f);
+}
+
+void GLWidget::mousePressEvent(QMouseEvent *event)
+{
+ m_lastPos = event->pos();
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ int dx = event->x() - m_lastPos.x();
+ int dy = event->y() - m_lastPos.y();
+
+ if (event->buttons() & Qt::LeftButton) {
+ setXRotation(m_xRot + 8 * dy);
+ setYRotation(m_yRot + 8 * dx);
+ } else if (event->buttons() & Qt::RightButton) {
+ setXRotation(m_xRot + 8 * dy);
+ setZRotation(m_zRot + 8 * dx);
+ }
+ m_lastPos = event->pos();
+}
diff --git a/examples/opengl/hellogl2/glwidget.h b/examples/opengl/hellogl2/glwidget.h
new file mode 100644
index 0000000000..2d642649f1
--- /dev/null
+++ b/examples/opengl/hellogl2/glwidget.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions>
+#include <QOpenGLVertexArrayObject>
+#include <QOpenGLBuffer>
+#include <QMatrix4x4>
+#include "logo.h"
+
+QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
+
+class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent = 0);
+ ~GLWidget();
+
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
+
+public slots:
+ void setXRotation(int angle);
+ void setYRotation(int angle);
+ void setZRotation(int angle);
+ void cleanup();
+
+signals:
+ void xRotationChanged(int angle);
+ void yRotationChanged(int angle);
+ void zRotationChanged(int angle);
+
+protected:
+ void initializeGL() Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void resizeGL(int width, int height) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+
+private:
+ void setupVertexAttribs();
+
+ bool m_core;
+ int m_xRot;
+ int m_yRot;
+ int m_zRot;
+ QPoint m_lastPos;
+ Logo m_logo;
+ QOpenGLVertexArrayObject m_vao;
+ QOpenGLBuffer m_logoVbo;
+ QOpenGLShaderProgram *m_program;
+ int m_projMatrixLoc;
+ int m_mvMatrixLoc;
+ int m_normalMatrixLoc;
+ int m_lightPosLoc;
+ QMatrix4x4 m_proj;
+ QMatrix4x4 m_camera;
+ QMatrix4x4 m_world;
+ bool m_transparent;
+};
+
+#endif
diff --git a/examples/opengl/hellogl2/hellogl2.pro b/examples/opengl/hellogl2/hellogl2.pro
new file mode 100644
index 0000000000..3a52e04d74
--- /dev/null
+++ b/examples/opengl/hellogl2/hellogl2.pro
@@ -0,0 +1,15 @@
+HEADERS = glwidget.h \
+ window.h \
+ mainwindow.h \
+ logo.h
+SOURCES = glwidget.cpp \
+ main.cpp \
+ window.cpp \
+ mainwindow.cpp \
+ logo.cpp
+
+QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl2
+INSTALLS += target
diff --git a/examples/opengl/hellogl2/logo.cpp b/examples/opengl/hellogl2/logo.cpp
new file mode 100644
index 0000000000..1ba47ddfb5
--- /dev/null
+++ b/examples/opengl/hellogl2/logo.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "logo.h"
+#include <qmath.h>
+
+Logo::Logo()
+ : m_count(0)
+{
+ m_data.resize(2500 * 6);
+
+ const GLfloat x1 = +0.06f;
+ const GLfloat y1 = -0.14f;
+ const GLfloat x2 = +0.14f;
+ const GLfloat y2 = -0.06f;
+ const GLfloat x3 = +0.08f;
+ const GLfloat y3 = +0.00f;
+ const GLfloat x4 = +0.30f;
+ const GLfloat 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 int NumSectors = 100;
+
+ for (int i = 0; i < NumSectors; ++i) {
+ GLfloat angle = (i * 2 * M_PI) / NumSectors;
+ GLfloat angleSin = qSin(angle);
+ GLfloat angleCos = qCos(angle);
+ const GLfloat x5 = 0.30f * angleSin;
+ const GLfloat y5 = 0.30f * angleCos;
+ const GLfloat x6 = 0.20f * angleSin;
+ const GLfloat y6 = 0.20f * angleCos;
+
+ angle = ((i + 1) * 2 * M_PI) / NumSectors;
+ angleSin = qSin(angle);
+ angleCos = qCos(angle);
+ const GLfloat x7 = 0.20f * angleSin;
+ const GLfloat y7 = 0.20f * angleCos;
+ const GLfloat x8 = 0.30f * angleSin;
+ const GLfloat y8 = 0.30f * angleCos;
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+}
+
+void Logo::add(const QVector3D &v, const QVector3D &n)
+{
+ GLfloat *p = m_data.data() + m_count;
+ *p++ = v.x();
+ *p++ = v.y();
+ *p++ = v.z();
+ *p++ = n.x();
+ *p++ = n.y();
+ *p++ = n.z();
+ m_count += 6;
+}
+
+void Logo::quad(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3, GLfloat x4, GLfloat y4)
+{
+ QVector3D n = QVector3D::normal(QVector3D(x4 - x1, y4 - y1, 0.0f), QVector3D(x2 - x1, y2 - y1, 0.0f));
+
+ add(QVector3D(x1, y1, -0.05f), n);
+ add(QVector3D(x4, y4, -0.05f), n);
+ add(QVector3D(x2, y2, -0.05f), n);
+
+ add(QVector3D(x3, y3, -0.05f), n);
+ add(QVector3D(x2, y2, -0.05f), n);
+ add(QVector3D(x4, y4, -0.05f), n);
+
+ n = QVector3D::normal(QVector3D(x1 - x4, y1 - y4, 0.0f), QVector3D(x2 - x4, y2 - y4, 0.0f));
+
+ add(QVector3D(x4, y4, 0.05f), n);
+ add(QVector3D(x1, y1, 0.05f), n);
+ add(QVector3D(x2, y2, 0.05f), n);
+
+ add(QVector3D(x2, y2, 0.05f), n);
+ add(QVector3D(x3, y3, 0.05f), n);
+ add(QVector3D(x4, y4, 0.05f), n);
+}
+
+void Logo::extrude(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+ QVector3D n = QVector3D::normal(QVector3D(0.0f, 0.0f, -0.1f), QVector3D(x2 - x1, y2 - y1, 0.0f));
+
+ add(QVector3D(x1, y1, +0.05f), n);
+ add(QVector3D(x1, y1, -0.05f), n);
+ add(QVector3D(x2, y2, +0.05f), n);
+
+ add(QVector3D(x2, y2, -0.05f), n);
+ add(QVector3D(x2, y2, +0.05f), n);
+ add(QVector3D(x1, y1, -0.05f), n);
+}
diff --git a/examples/opengl/hellogl2/logo.h b/examples/opengl/hellogl2/logo.h
new file mode 100644
index 0000000000..29bb7fa241
--- /dev/null
+++ b/examples/opengl/hellogl2/logo.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LOGO_H
+#define LOGO_H
+
+#include <qopengl.h>
+#include <QVector>
+#include <QVector3D>
+
+class Logo
+{
+public:
+ Logo();
+ const GLfloat *constData() const { return m_data.constData(); }
+ int count() const { return m_count; }
+ int vertexCount() const { return m_count / 6; }
+
+private:
+ void quad(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3, GLfloat x4, GLfloat y4);
+ void extrude(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
+ void add(const QVector3D &v, const QVector3D &n);
+
+ QVector<GLfloat> m_data;
+ int m_count;
+};
+
+#endif // LOGO_H
diff --git a/examples/opengl/hellogl2/main.cpp b/examples/opengl/hellogl2/main.cpp
new file mode 100644
index 0000000000..2d439878e4
--- /dev/null
+++ b/examples/opengl/hellogl2/main.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QSurfaceFormat>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QSurfaceFormat fmt;
+ fmt.setDepthBufferSize(24);
+ if (QCoreApplication::arguments().contains(QStringLiteral("--multisample")))
+ fmt.setSamples(4);
+ if (QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"))) {
+ fmt.setVersion(3, 2);
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
+ }
+ QSurfaceFormat::setDefaultFormat(fmt);
+
+ MainWindow mainWindow;
+ mainWindow.resize(mainWindow.sizeHint());
+ int desktopArea = QApplication::desktop()->width() *
+ QApplication::desktop()->height();
+ int widgetArea = mainWindow.width() * mainWindow.height();
+ if (((float)widgetArea / (float)desktopArea) < 0.75f)
+ mainWindow.show();
+ else
+ mainWindow.showMaximized();
+ return app.exec();
+}
diff --git a/examples/opengl/hellogl2/mainwindow.cpp b/examples/opengl/hellogl2/mainwindow.cpp
new file mode 100644
index 0000000000..ee85cda35c
--- /dev/null
+++ b/examples/opengl/hellogl2/mainwindow.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "window.h"
+#include <QMenuBar>
+#include <QMenu>
+#include <QMessageBox>
+
+MainWindow::MainWindow()
+{
+ QMenuBar *menuBar = new QMenuBar;
+ QMenu *menuWindow = menuBar->addMenu(tr("&Window"));
+ QAction *addNew = new QAction(menuWindow);
+ addNew->setText(tr("Add new"));
+ menuWindow->addAction(addNew);
+ connect(addNew, SIGNAL(triggered()), this, SLOT(onAddNew()));
+ setMenuBar(menuBar);
+
+ onAddNew();
+}
+
+void MainWindow::onAddNew()
+{
+ if (!centralWidget())
+ setCentralWidget(new Window(this));
+ else
+ QMessageBox::information(0, tr("Cannot add new window"), tr("Already occupied. Undock first."));
+}
diff --git a/examples/opengl/hellogl_es2/mainwindow.h b/examples/opengl/hellogl2/mainwindow.h
index 3f05fd4a78..53d4555ce8 100644
--- a/examples/opengl/hellogl_es2/mainwindow.h
+++ b/examples/opengl/hellogl2/mainwindow.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -50,7 +50,8 @@ class MainWindow : public QMainWindow
public:
MainWindow();
-private:
+private slots:
+ void onAddNew();
};
#endif
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
new file mode 100644
index 0000000000..0b20870487
--- /dev/null
+++ b/examples/opengl/hellogl2/window.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include "window.h"
+#include "mainwindow.h"
+#include <QSlider>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QKeyEvent>
+#include <QPushButton>
+#include <QDesktopWidget>
+#include <QApplication>
+#include <QMessageBox>
+
+Window::Window(MainWindow *mw)
+ : mainWindow(mw)
+{
+ 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)));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ QHBoxLayout *container = new QHBoxLayout;
+ container->addWidget(glWidget);
+ container->addWidget(xSlider);
+ container->addWidget(ySlider);
+ container->addWidget(zSlider);
+
+ QWidget *w = new QWidget;
+ w->setLayout(container);
+ mainLayout->addWidget(w);
+ dockBtn = new QPushButton(tr("Undock"), this);
+ connect(dockBtn, SIGNAL(clicked()), this, SLOT(dockUndock()));
+ mainLayout->addWidget(dockBtn);
+
+ setLayout(mainLayout);
+
+ xSlider->setValue(15 * 16);
+ ySlider->setValue(345 * 16);
+ zSlider->setValue(0 * 16);
+
+ setWindowTitle(tr("Hello GL"));
+}
+
+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;
+}
+
+void Window::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape)
+ close();
+ else
+ QWidget::keyPressEvent(e);
+}
+
+void Window::dockUndock()
+{
+ if (parent()) {
+ setParent(0);
+ setAttribute(Qt::WA_DeleteOnClose);
+ move(QApplication::desktop()->width() / 2 - width() / 2,
+ QApplication::desktop()->height() / 2 - height() / 2);
+ dockBtn->setText(tr("Dock"));
+ show();
+ } else {
+ if (!mainWindow->centralWidget()) {
+ if (mainWindow->isVisible()) {
+ setAttribute(Qt::WA_DeleteOnClose, false);
+ dockBtn->setText(tr("Undock"));
+ mainWindow->setCentralWidget(this);
+ } else {
+ QMessageBox::information(0, tr("Cannot dock"), tr("Main window already closed"));
+ }
+ } else {
+ QMessageBox::information(0, tr("Cannot dock"), tr("Main window already occupied"));
+ }
+ }
+}
diff --git a/examples/opengl/hellogl2/window.h b/examples/opengl/hellogl2/window.h
new file mode 100644
index 0000000000..a850bd6a5a
--- /dev/null
+++ b/examples/opengl/hellogl2/window.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QSlider;
+class QPushButton;
+QT_END_NAMESPACE
+
+class GLWidget;
+class MainWindow;
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window(MainWindow *mw);
+
+protected:
+ void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+
+private slots:
+ void dockUndock();
+
+private:
+ QSlider *createSlider();
+
+ GLWidget *glWidget;
+ QSlider *xSlider;
+ QSlider *ySlider;
+ QSlider *zSlider;
+ QPushButton *dockBtn;
+ MainWindow *mainWindow;
+};
+
+#endif
diff --git a/examples/opengl/hellogl_es2/glwidget.cpp b/examples/opengl/hellogl_es2/glwidget.cpp
deleted file mode 100644
index 7267cfd124..0000000000
--- a/examples/opengl/hellogl_es2/glwidget.cpp
+++ /dev/null
@@ -1,461 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
-** of its contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-#include <QPainter>
-#include <QPaintEngine>
-#include <math.h>
-
-#include "bubble.h"
-
-
-const int bubbleNum = 8;
-
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(parent)
-{
- qtLogo = true;
- frames = 0;
- setAttribute(Qt::WA_PaintOnScreen);
- setAttribute(Qt::WA_NoSystemBackground);
- setAutoBufferSwap(false);
- m_showBubbles = true;
- setMinimumSize(300, 250);
-}
-
-GLWidget::~GLWidget()
-{
-}
-
-void GLWidget::setScaling(int scale) {
-
- if (scale > 50)
- m_fScale = 1 + qreal(scale -50) / 50 * 0.5;
- else if (scale < 50)
- m_fScale = 1- (qreal(50 - scale) / 50 * 1/2);
- else
- m_fScale = 1;
-}
-
-void GLWidget::setLogo() {
- qtLogo = true;
-}
-
-void GLWidget::setTexture() {
- qtLogo = false;
-}
-
-void GLWidget::showBubbles(bool bubbles)
-{
- m_showBubbles = bubbles;
-}
-
-void GLWidget::paintQtLogo()
-{
- program1.enableAttributeArray(normalAttr1);
- program1.enableAttributeArray(vertexAttr1);
- program1.setAttributeArray(vertexAttr1, vertices.constData());
- program1.setAttributeArray(normalAttr1, normals.constData());
- glDrawArrays(GL_TRIANGLES, 0, vertices.size());
- program1.disableAttributeArray(normalAttr1);
- program1.disableAttributeArray(vertexAttr1);
-}
-
-void GLWidget::paintTexturedCube()
-{
- glBindTexture(GL_TEXTURE_2D, m_uiTexture);
- GLfloat afVertices[] = {
- -0.5, 0.5, 0.5, 0.5,-0.5,0.5,-0.5,-0.5,0.5,
- 0.5, -0.5, 0.5, -0.5,0.5,0.5,0.5,0.5,0.5,
- -0.5, -0.5, -0.5, 0.5,-0.5,-0.5,-0.5,0.5,-0.5,
- 0.5, 0.5, -0.5, -0.5,0.5,-0.5,0.5,-0.5,-0.5,
-
- 0.5, -0.5, -0.5, 0.5,-0.5,0.5,0.5,0.5,-0.5,
- 0.5, 0.5, 0.5, 0.5,0.5,-0.5,0.5,-0.5,0.5,
- -0.5, 0.5, -0.5, -0.5,-0.5,0.5,-0.5,-0.5,-0.5,
- -0.5, -0.5, 0.5, -0.5,0.5,-0.5,-0.5,0.5,0.5,
-
- 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5,
- -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5,
- -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5,
- 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5
- };
- program2.setAttributeArray(vertexAttr2, afVertices, 3);
-
- GLfloat afTexCoord[] = {
- 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
- 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
- 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
- 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
-
- 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
- 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
- 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
- 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
-
- 0.0f,1.0f, 1.0f,0.0f, 1.0f,1.0f,
- 1.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f,
- 1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f,
- 0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f
- };
- program2.setAttributeArray(texCoordAttr2, afTexCoord, 2);
-
- GLfloat afNormals[] = {
-
- 0,0,-1, 0,0,-1, 0,0,-1,
- 0,0,-1, 0,0,-1, 0,0,-1,
- 0,0,1, 0,0,1, 0,0,1,
- 0,0,1, 0,0,1, 0,0,1,
-
- -1,0,0, -1,0,0, -1,0,0,
- -1,0,0, -1,0,0, -1,0,0,
- 1,0,0, 1,0,0, 1,0,0,
- 1,0,0, 1,0,0, 1,0,0,
-
- 0,-1,0, 0,-1,0, 0,-1,0,
- 0,-1,0, 0,-1,0, 0,-1,0,
- 0,1,0, 0,1,0, 0,1,0,
- 0,1,0, 0,1,0, 0,1,0
- };
- program2.setAttributeArray(normalAttr2, afNormals, 3);
-
- program2.setUniformValue(textureUniform2, 0); // use texture unit 0
-
- program2.enableAttributeArray(vertexAttr2);
- program2.enableAttributeArray(normalAttr2);
- program2.enableAttributeArray(texCoordAttr2);
-
- glDrawArrays(GL_TRIANGLES, 0, 36);
-
- program2.disableAttributeArray(vertexAttr2);
- program2.disableAttributeArray(normalAttr2);
- program2.disableAttributeArray(texCoordAttr2);
-}
-
-void GLWidget::initializeGL ()
-{
- glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
-
- glGenTextures(1, &m_uiTexture);
- m_uiTexture = bindTexture(QImage(":/qt.png"));
-
- QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);
- const char *vsrc1 =
- "attribute highp vec4 vertex;\n"
- "attribute mediump vec3 normal;\n"
- "uniform mediump mat4 matrix;\n"
- "varying mediump vec4 color;\n"
- "void main(void)\n"
- "{\n"
- " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
- " float angle = max(dot(normal, toLight), 0.0);\n"
- " vec3 col = vec3(0.40, 1.0, 0.0);\n"
- " color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);\n"
- " color = clamp(color, 0.0, 1.0);\n"
- " gl_Position = matrix * vertex;\n"
- "}\n";
- vshader1->compileSourceCode(vsrc1);
-
- QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
- const char *fsrc1 =
- "varying mediump vec4 color;\n"
- "void main(void)\n"
- "{\n"
- " gl_FragColor = color;\n"
- "}\n";
- fshader1->compileSourceCode(fsrc1);
-
- program1.addShader(vshader1);
- program1.addShader(fshader1);
- program1.link();
-
- vertexAttr1 = program1.attributeLocation("vertex");
- normalAttr1 = program1.attributeLocation("normal");
- matrixUniform1 = program1.uniformLocation("matrix");
-
- QGLShader *vshader2 = new QGLShader(QGLShader::Vertex);
- const char *vsrc2 =
- "attribute highp vec4 vertex;\n"
- "attribute highp vec4 texCoord;\n"
- "attribute mediump vec3 normal;\n"
- "uniform mediump mat4 matrix;\n"
- "varying highp vec4 texc;\n"
- "varying mediump float angle;\n"
- "void main(void)\n"
- "{\n"
- " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
- " angle = max(dot(normal, toLight), 0.0);\n"
- " gl_Position = matrix * vertex;\n"
- " texc = texCoord;\n"
- "}\n";
- vshader2->compileSourceCode(vsrc2);
-
- QGLShader *fshader2 = new QGLShader(QGLShader::Fragment);
- const char *fsrc2 =
- "varying highp vec4 texc;\n"
- "uniform sampler2D tex;\n"
- "varying mediump float angle;\n"
- "void main(void)\n"
- "{\n"
- " highp vec3 color = texture2D(tex, texc.st).rgb;\n"
- " color = color * 0.2 + color * 0.8 * angle;\n"
- " gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
- "}\n";
- fshader2->compileSourceCode(fsrc2);
-
- program2.addShader(vshader2);
- program2.addShader(fshader2);
- program2.link();
-
- vertexAttr2 = program2.attributeLocation("vertex");
- normalAttr2 = program2.attributeLocation("normal");
- texCoordAttr2 = program2.attributeLocation("texCoord");
- matrixUniform2 = program2.uniformLocation("matrix");
- textureUniform2 = program2.uniformLocation("tex");
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-
- m_fAngle = 0;
- m_fScale = 1;
- createGeometry();
- createBubbles(bubbleNum - bubbles.count());
-}
-
-void GLWidget::paintGL()
-{
- createBubbles(bubbleNum - bubbles.count());
-
- QPainter painter;
- painter.begin(this);
-
- painter.beginNativePainting();
-
- glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-
- glFrontFace(GL_CW);
- glCullFace(GL_FRONT);
- glEnable(GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
-
- QMatrix4x4 modelview;
- modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
- modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
- modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
- modelview.scale(m_fScale);
- modelview.translate(0.0f, -0.2f, 0.0f);
-
- if (qtLogo) {
- program1.bind();
- program1.setUniformValue(matrixUniform1, modelview);
- paintQtLogo();
- program1.release();
- } else {
- program2.bind();
- program1.setUniformValue(matrixUniform2, modelview);
- paintTexturedCube();
- program2.release();
- }
-
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
-
- painter.endNativePainting();
-
- if (m_showBubbles)
- foreach (Bubble *bubble, bubbles) {
- bubble->drawBubble(&painter);
- }
-
- if (const int elapsed = time.elapsed()) {
- QString framesPerSecond;
- framesPerSecond.setNum(frames /(elapsed / 1000.0), 'f', 2);
- painter.setPen(Qt::white);
- painter.drawText(20, 40, framesPerSecond + " fps");
- }
-
- painter.end();
-
- swapBuffers();
-
- QMutableListIterator<Bubble*> iter(bubbles);
-
- while (iter.hasNext()) {
- Bubble *bubble = iter.next();
- bubble->move(rect());
- }
- if (!(frames % 100)) {
- time.start();
- frames = 0;
- }
- m_fAngle += 1.0f;
- frames ++;
-}
-
-void GLWidget::createBubbles(int number)
-{
- for (int i = 0; i < number; ++i) {
- QPointF position(width()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))),
- height()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))));
- qreal radius = qMin(width(), height())*(0.0175 + 0.0875*qrand()/(RAND_MAX+1.0));
- QPointF velocity(width()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)),
- height()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)));
-
- bubbles.append(new Bubble(position, radius, velocity));
- }
-}
-
-void GLWidget::createGeometry()
-{
- vertices.clear();
- normals.clear();
-
- qreal x1 = +0.06f;
- qreal y1 = -0.14f;
- qreal x2 = +0.14f;
- qreal y2 = -0.06f;
- qreal x3 = +0.08f;
- qreal y3 = +0.00f;
- qreal x4 = +0.30f;
- qreal y4 = +0.22f;
-
- quad(x1, y1, x2, y2, y2, x2, y1, x1);
- quad(x3, y3, x4, y4, y4, x4, y3, x3);
-
- extrude(x1, y1, x2, y2);
- extrude(x2, y2, y2, x2);
- extrude(y2, x2, y1, x1);
- extrude(y1, x1, x1, y1);
- extrude(x3, y3, x4, y4);
- extrude(x4, y4, y4, x4);
- extrude(y4, x4, y3, x3);
-
- const qreal Pi = 3.14159f;
- const int NumSectors = 100;
-
- for (int i = 0; i < NumSectors; ++i) {
- qreal angle1 = (i * 2 * Pi) / NumSectors;
- qreal x5 = 0.30 * sin(angle1);
- qreal y5 = 0.30 * cos(angle1);
- qreal x6 = 0.20 * sin(angle1);
- qreal y6 = 0.20 * cos(angle1);
-
- qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors;
- qreal x7 = 0.20 * sin(angle2);
- qreal y7 = 0.20 * cos(angle2);
- qreal x8 = 0.30 * sin(angle2);
- qreal y8 = 0.30 * cos(angle2);
-
- quad(x5, y5, x6, y6, x7, y7, x8, y8);
-
- extrude(x6, y6, x7, y7);
- extrude(x8, y8, x5, y5);
- }
-
- for (int i = 0;i < vertices.size();i++)
- vertices[i] *= 2.0f;
-}
-
-void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
-{
- vertices << QVector3D(x1, y1, -0.05f);
- vertices << QVector3D(x2, y2, -0.05f);
- vertices << QVector3D(x4, y4, -0.05f);
-
- vertices << QVector3D(x3, y3, -0.05f);
- vertices << QVector3D(x4, y4, -0.05f);
- vertices << QVector3D(x2, y2, -0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-
- vertices << QVector3D(x4, y4, 0.05f);
- vertices << QVector3D(x2, y2, 0.05f);
- vertices << QVector3D(x1, y1, 0.05f);
-
- vertices << QVector3D(x2, y2, 0.05f);
- vertices << QVector3D(x4, y4, 0.05f);
- vertices << QVector3D(x3, y3, 0.05f);
-
- n = QVector3D::normal
- (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-}
-
-void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
-{
- vertices << QVector3D(x1, y1, +0.05f);
- vertices << QVector3D(x2, y2, +0.05f);
- vertices << QVector3D(x1, y1, -0.05f);
-
- vertices << QVector3D(x2, y2, -0.05f);
- vertices << QVector3D(x1, y1, -0.05f);
- vertices << QVector3D(x2, y2, +0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-}
diff --git a/examples/opengl/hellogl_es2/hellogl_es2.pro b/examples/opengl/hellogl_es2/hellogl_es2.pro
deleted file mode 100644
index b15e8d1909..0000000000
--- a/examples/opengl/hellogl_es2/hellogl_es2.pro
+++ /dev/null
@@ -1,23 +0,0 @@
-QT += opengl widgets
-
-SOURCES += main.cpp
-SOURCES += glwidget.cpp
-SOURCES += mainwindow.cpp
-SOURCES += bubble.cpp
-
-HEADERS += glwidget.h
-HEADERS += mainwindow.h
-HEADERS += bubble.h
-
-RESOURCES += texture.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl_es2
-INSTALLS += target
-
-maemo5 {
- # Debian package name may not contain numbers or special characters
- # such as '_', lets change this in Maemo.
- TARGET = helloglestwo
- CONFIG += qt_example
-}
diff --git a/examples/opengl/hellogl_es2/mainwindow.cpp b/examples/opengl/hellogl_es2/mainwindow.cpp
deleted file mode 100644
index eb4ce0ac3e..0000000000
--- a/examples/opengl/hellogl_es2/mainwindow.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
-** of its contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mainwindow.h"
-
-#include <QApplication>
-#include <QMenuBar>
-#include <QGroupBox>
-#include <QGridLayout>
-#include <QSlider>
-#include <QLabel>
-#include <QTimer>
-
-#include "glwidget.h"
-
-MainWindow::MainWindow()
-{
- GLWidget *glwidget = new GLWidget();
- QLabel *label = new QLabel(this);
- QTimer *timer = new QTimer(this);
- QSlider *slider = new QSlider(this);
- slider->setOrientation(Qt::Horizontal);
-
- slider->setRange(0, 100);
- slider->setSliderPosition(50);
- timer->setInterval(10);
- label->setText("A QGlWidget with OpenGl ES");
- label->setAlignment(Qt::AlignHCenter);
-
- QGroupBox * groupBox = new QGroupBox(this);
- setCentralWidget(groupBox);
- groupBox->setTitle("OpenGL ES Example");
-
- QGridLayout *layout = new QGridLayout(groupBox);
-
- layout->addWidget(glwidget,1,0,8,1);
- layout->addWidget(label,9,0,1,1);
- layout->addWidget(slider, 11,0,1,1);
-
- groupBox->setLayout(layout);
-
- QMenu *fileMenu = new QMenu("File");
- QMenu *helpMenu = new QMenu("Help");
- QMenu *showMenu = new QMenu("Show");
- menuBar()->addMenu(fileMenu);
- menuBar()->addMenu(showMenu);
- menuBar()->addMenu(helpMenu);
- QAction *exit = new QAction("Exit", fileMenu);
- QAction *aboutQt = new QAction("AboutQt", helpMenu);
- QAction *showLogo = new QAction("Show 3D Logo", showMenu);
- QAction *showTexture = new QAction("Show 2D Texture", showMenu);
- QAction *showBubbles = new QAction("Show bubbles", showMenu);
- showBubbles->setCheckable(true);
- showBubbles->setChecked(true);
- fileMenu->addAction(exit);
- helpMenu->addAction(aboutQt);
- showMenu->addAction(showLogo);
- showMenu->addAction(showTexture);
- showMenu->addAction(showBubbles);
-
- QObject::connect(timer, SIGNAL(timeout()), glwidget, SLOT(updateGL()));
- QObject::connect(exit, SIGNAL(triggered(bool)), this, SLOT(close()));
- QObject::connect(aboutQt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
-
- QObject::connect(showLogo, SIGNAL(triggered(bool)), glwidget, SLOT(setLogo()));
- QObject::connect(showTexture, SIGNAL(triggered(bool)), glwidget, SLOT(setTexture()));
- QObject::connect(showBubbles, SIGNAL(triggered(bool)), glwidget, SLOT(showBubbles(bool)));
- QObject::connect(slider, SIGNAL(valueChanged(int)), glwidget, SLOT(setScaling(int)));
- timer->start();
-}
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp
index 3b5971c0d3..57eb111edb 100644
--- a/examples/opengl/hellowindow/hellowindow.cpp
+++ b/examples/opengl/hellowindow/hellowindow.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -145,29 +145,33 @@ void Renderer::render()
QOpenGLFunctions *f = m_context->functions();
f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
-
- f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
f->glFrontFace(GL_CW);
f->glCullFace(GL_FRONT);
f->glEnable(GL_CULL_FACE);
f->glEnable(GL_DEPTH_TEST);
+ m_program->bind();
+ m_vbo.bind();
+
+ m_program->enableAttributeArray(vertexAttr);
+ m_program->enableAttributeArray(normalAttr);
+ m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
+ const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
+ m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3);
+
QMatrix4x4 modelview;
modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
modelview.translate(0.0f, -0.2f, 0.0f);
- m_program->bind();
m_program->setUniformValue(matrixUniform, modelview);
m_program->setUniformValue(colorUniform, color);
- paintQtLogo();
- m_program->release();
- f->glDisable(GL_DEPTH_TEST);
- f->glDisable(GL_CULL_FACE);
+ m_context->functions()->glDrawArrays(GL_TRIANGLES, 0, vertices.size());
m_context->swapBuffers(surface);
@@ -176,17 +180,6 @@ void Renderer::render()
QTimer::singleShot(0, this, SLOT(render()));
}
-void Renderer::paintQtLogo()
-{
- m_program->enableAttributeArray(normalAttr);
- m_program->enableAttributeArray(vertexAttr);
- m_program->setAttributeArray(vertexAttr, vertices.constData());
- m_program->setAttributeArray(normalAttr, normals.constData());
- glDrawArrays(GL_TRIANGLES, 0, vertices.size());
- m_program->disableAttributeArray(normalAttr);
- m_program->disableAttributeArray(vertexAttr);
-}
-
void Renderer::initialize()
{
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
@@ -218,6 +211,7 @@ void Renderer::initialize()
m_program->addShader(vshader);
m_program->addShader(fshader);
m_program->link();
+ m_program->bind();
vertexAttr = m_program->attributeLocation("vertex");
normalAttr = m_program->attributeLocation("normal");
@@ -226,6 +220,13 @@ void Renderer::initialize()
m_fAngle = 0;
createGeometry();
+
+ m_vbo.create();
+ m_vbo.bind();
+ const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
+ m_vbo.allocate(verticesSize * 2);
+ m_vbo.write(0, vertices.constData(), verticesSize);
+ m_vbo.write(verticesSize, normals.constData(), verticesSize);
}
void Renderer::createGeometry()
diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h
index 6d66f0204a..6a6fa275e2 100644
--- a/examples/opengl/hellowindow/hellowindow.h
+++ b/examples/opengl/hellowindow/hellowindow.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -43,6 +43,7 @@
#include <QColor>
#include <QMutex>
#include <QOpenGLShaderProgram>
+#include <QOpenGLBuffer>
#include <QSharedPointer>
#include <QTimer>
@@ -65,13 +66,13 @@ private slots:
private:
void initialize();
- qreal m_fAngle;
- bool m_showBubbles;
- 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);
+
+ qreal m_fAngle;
+
QVector<QVector3D> vertices;
QVector<QVector3D> normals;
int vertexAttr;
@@ -83,6 +84,7 @@ private:
QSurfaceFormat m_format;
QOpenGLContext *m_context;
QOpenGLShaderProgram *m_program;
+ QOpenGLBuffer m_vbo;
QList<HelloWindow *> m_windows;
int m_currentWindow;
@@ -98,10 +100,10 @@ public:
QColor color() const;
void updateColor();
- void exposeEvent(QExposeEvent *event);
+ void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE;
private:
- void mousePressEvent(QMouseEvent *);
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
int m_colorIndex;
QColor m_color;
diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp
index 5b2552ee3e..62b6bfca3f 100644
--- a/examples/opengl/hellowindow/main.cpp
+++ b/examples/opengl/hellowindow/main.cpp
@@ -41,7 +41,6 @@
#include "hellowindow.h"
#include <qpa/qplatformintegration.h>
-#include <private/qguiapplication_p.h>
#include <QGuiApplication>
#include <QScreen>
@@ -51,10 +50,7 @@ int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
- QPlatformIntegration *integ = QGuiApplicationPrivate::platformIntegration();
- const bool multipleWindows = integ->hasCapability(QPlatformIntegration::ThreadedOpenGL)
- && integ->hasCapability(QPlatformIntegration::WindowManagement)
- && !QGuiApplication::arguments().contains(QStringLiteral("--single"));
+ const bool multipleWindows = QGuiApplication::arguments().contains(QStringLiteral("--multiple"));
QScreen *screen = QGuiApplication::primaryScreen();
diff --git a/examples/opengl/legacy/README b/examples/opengl/legacy/README
new file mode 100644
index 0000000000..8d6cbdef2a
--- /dev/null
+++ b/examples/opengl/legacy/README
@@ -0,0 +1,4 @@
+This directory contains legacy examples that use the fixed pipeline
+and thus are not compatible with OpenGL ES 2.0+ and the core profile of
+OpenGL 3.0+. They also rely on the Qt OpenGL module (e.g. QGLWidget) which
+is not advisable in new application.
diff --git a/examples/opengl/framebufferobject2/cubelogo.png b/examples/opengl/legacy/framebufferobject2/cubelogo.png
index 3ae0f9ba3f..3ae0f9ba3f 100644
--- a/examples/opengl/framebufferobject2/cubelogo.png
+++ b/examples/opengl/legacy/framebufferobject2/cubelogo.png
Binary files differ
diff --git a/examples/opengl/framebufferobject2/framebufferobject2.pro b/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro
index e0067cf27f..e0067cf27f 100644
--- a/examples/opengl/framebufferobject2/framebufferobject2.pro
+++ b/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro
diff --git a/examples/opengl/framebufferobject2/framebufferobject2.qrc b/examples/opengl/legacy/framebufferobject2/framebufferobject2.qrc
index 9fc1a56a1a..9fc1a56a1a 100644
--- a/examples/opengl/framebufferobject2/framebufferobject2.qrc
+++ b/examples/opengl/legacy/framebufferobject2/framebufferobject2.qrc
diff --git a/examples/opengl/framebufferobject2/glwidget.cpp b/examples/opengl/legacy/framebufferobject2/glwidget.cpp
index 32b9799a4a..32b9799a4a 100644
--- a/examples/opengl/framebufferobject2/glwidget.cpp
+++ b/examples/opengl/legacy/framebufferobject2/glwidget.cpp
diff --git a/examples/opengl/framebufferobject2/glwidget.h b/examples/opengl/legacy/framebufferobject2/glwidget.h
index f3f7640d28..2991a4fdf2 100644
--- a/examples/opengl/framebufferobject2/glwidget.h
+++ b/examples/opengl/legacy/framebufferobject2/glwidget.h
@@ -45,12 +45,12 @@ 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 initializeGL() Q_DECL_OVERRIDE;
+ void resizeGL(int w, int h) Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE { update(); }
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE { killTimer(timerId); }
+ void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE { timerId = startTimer(20); }
void drawCube(int i, GLfloat z, GLfloat ri, GLfloat jmp, GLfloat amp);
diff --git a/examples/opengl/framebufferobject2/main.cpp b/examples/opengl/legacy/framebufferobject2/main.cpp
index 4c9aa9840f..4c9aa9840f 100644
--- a/examples/opengl/framebufferobject2/main.cpp
+++ b/examples/opengl/legacy/framebufferobject2/main.cpp
diff --git a/examples/opengl/grabber/glwidget.cpp b/examples/opengl/legacy/grabber/glwidget.cpp
index abe3a8540a..abe3a8540a 100644
--- a/examples/opengl/grabber/glwidget.cpp
+++ b/examples/opengl/legacy/grabber/glwidget.cpp
diff --git a/examples/opengl/grabber/glwidget.h b/examples/opengl/legacy/grabber/glwidget.h
index 976d22a421..12071be173 100644
--- a/examples/opengl/grabber/glwidget.h
+++ b/examples/opengl/legacy/grabber/glwidget.h
@@ -66,11 +66,11 @@ signals:
void zRotationChanged(int angle);
protected:
- void initializeGL();
- void paintGL();
- void resizeGL(int width, int height);
- void mousePressEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
+ void initializeGL() Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void resizeGL(int width, int height) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private slots:
void advanceGears();
diff --git a/examples/opengl/grabber/grabber.pro b/examples/opengl/legacy/grabber/grabber.pro
index b8567580f0..b8567580f0 100644
--- a/examples/opengl/grabber/grabber.pro
+++ b/examples/opengl/legacy/grabber/grabber.pro
diff --git a/examples/opengl/grabber/main.cpp b/examples/opengl/legacy/grabber/main.cpp
index 145e4120ef..145e4120ef 100644
--- a/examples/opengl/grabber/main.cpp
+++ b/examples/opengl/legacy/grabber/main.cpp
diff --git a/examples/opengl/grabber/mainwindow.cpp b/examples/opengl/legacy/grabber/mainwindow.cpp
index 9f82ee10ba..9f82ee10ba 100644
--- a/examples/opengl/grabber/mainwindow.cpp
+++ b/examples/opengl/legacy/grabber/mainwindow.cpp
diff --git a/examples/opengl/grabber/mainwindow.h b/examples/opengl/legacy/grabber/mainwindow.h
index a7895bf4c4..a7895bf4c4 100644
--- a/examples/opengl/grabber/mainwindow.h
+++ b/examples/opengl/legacy/grabber/mainwindow.h
diff --git a/examples/opengl/hellogl/glwidget.cpp b/examples/opengl/legacy/hellogl/glwidget.cpp
index 29879fa804..3a9faaca5f 100644
--- a/examples/opengl/hellogl/glwidget.cpp
+++ b/examples/opengl/legacy/hellogl/glwidget.cpp
@@ -100,7 +100,7 @@ void GLWidget::setXRotation(int angle)
if (angle != xRot) {
xRot = angle;
emit xRotationChanged(angle);
- updateGL();
+ update();
}
}
//! [5]
@@ -111,7 +111,7 @@ void GLWidget::setYRotation(int angle)
if (angle != yRot) {
yRot = angle;
emit yRotationChanged(angle);
- updateGL();
+ update();
}
}
@@ -121,7 +121,7 @@ void GLWidget::setZRotation(int angle)
if (angle != zRot) {
zRot = angle;
emit zRotationChanged(angle);
- updateGL();
+ update();
}
}
diff --git a/examples/opengl/hellogl/glwidget.h b/examples/opengl/legacy/hellogl/glwidget.h
index 3344e931e7..0989be1dc6 100644
--- a/examples/opengl/hellogl/glwidget.h
+++ b/examples/opengl/legacy/hellogl/glwidget.h
@@ -54,8 +54,8 @@ public:
GLWidget(QWidget *parent = 0);
~GLWidget();
- QSize minimumSizeHint() const;
- QSize sizeHint() const;
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
//! [0]
//! [1]
@@ -72,11 +72,11 @@ signals:
//! [2]
protected:
- void initializeGL();
- void paintGL();
- void resizeGL(int width, int height);
- void mousePressEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
+ void initializeGL() Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void resizeGL(int width, int height) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
//! [2]
//! [3]
diff --git a/examples/opengl/hellogl/hellogl.pro b/examples/opengl/legacy/hellogl/hellogl.pro
index 500bd85b3c..500bd85b3c 100644
--- a/examples/opengl/hellogl/hellogl.pro
+++ b/examples/opengl/legacy/hellogl/hellogl.pro
diff --git a/examples/opengl/hellogl/main.cpp b/examples/opengl/legacy/hellogl/main.cpp
index 2e83a11e95..2e83a11e95 100644
--- a/examples/opengl/hellogl/main.cpp
+++ b/examples/opengl/legacy/hellogl/main.cpp
diff --git a/examples/opengl/hellogl/window.cpp b/examples/opengl/legacy/hellogl/window.cpp
index 2a85bbec57..2a85bbec57 100644
--- a/examples/opengl/hellogl/window.cpp
+++ b/examples/opengl/legacy/hellogl/window.cpp
diff --git a/examples/opengl/hellogl/window.h b/examples/opengl/legacy/hellogl/window.h
index 68862fbcfe..900e6b13fc 100644
--- a/examples/opengl/hellogl/window.h
+++ b/examples/opengl/legacy/hellogl/window.h
@@ -57,7 +57,7 @@ public:
Window();
protected:
- void keyPressEvent(QKeyEvent *event);
+ void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
private:
QSlider *createSlider();
diff --git a/examples/opengl/legacy/legacy.pro b/examples/opengl/legacy/legacy.pro
new file mode 100644
index 0000000000..0a74d50f7f
--- /dev/null
+++ b/examples/opengl/legacy/legacy.pro
@@ -0,0 +1,16 @@
+requires(qtHaveModule(opengl))
+
+TEMPLATE = subdirs
+
+!contains(QT_CONFIG, dynamicgl): !contains(QT_CONFIG, opengles2) {
+ # legacy desktop-only examples, no dynamic GL support
+ SUBDIRS = \
+ grabber \
+ hellogl \
+ overpainting \
+ pbuffers \
+ framebufferobject2 \
+ samplebuffers
+}
+
+EXAMPLE_FILES = shared
diff --git a/examples/opengl/overpainting/bubble.cpp b/examples/opengl/legacy/overpainting/bubble.cpp
index dbcb72bc93..dbcb72bc93 100644
--- a/examples/opengl/overpainting/bubble.cpp
+++ b/examples/opengl/legacy/overpainting/bubble.cpp
diff --git a/examples/opengl/overpainting/bubble.h b/examples/opengl/legacy/overpainting/bubble.h
index 10d24b8af7..10d24b8af7 100644
--- a/examples/opengl/overpainting/bubble.h
+++ b/examples/opengl/legacy/overpainting/bubble.h
diff --git a/examples/opengl/overpainting/glwidget.cpp b/examples/opengl/legacy/overpainting/glwidget.cpp
index 420ae3e881..420ae3e881 100644
--- a/examples/opengl/overpainting/glwidget.cpp
+++ b/examples/opengl/legacy/overpainting/glwidget.cpp
diff --git a/examples/opengl/overpainting/glwidget.h b/examples/opengl/legacy/overpainting/glwidget.h
index cd3a125b38..1d1d48458d 100644
--- a/examples/opengl/overpainting/glwidget.h
+++ b/examples/opengl/legacy/overpainting/glwidget.h
@@ -57,7 +57,7 @@ public:
~GLWidget();
//! [0]
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
int xRotation() const { return xRot; }
int yRotation() const { return yRot; }
int zRotation() const { return zRot; }
@@ -69,12 +69,12 @@ public slots:
//! [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);
+ void initializeGL() Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeGL(int width, int height) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
private slots:
void animate();
diff --git a/examples/opengl/overpainting/main.cpp b/examples/opengl/legacy/overpainting/main.cpp
index 57c520b528..57c520b528 100644
--- a/examples/opengl/overpainting/main.cpp
+++ b/examples/opengl/legacy/overpainting/main.cpp
diff --git a/examples/opengl/overpainting/overpainting.pro b/examples/opengl/legacy/overpainting/overpainting.pro
index c1bda7853d..c1bda7853d 100644
--- a/examples/opengl/overpainting/overpainting.pro
+++ b/examples/opengl/legacy/overpainting/overpainting.pro
diff --git a/examples/opengl/pbuffers/cube.cpp b/examples/opengl/legacy/pbuffers/cube.cpp
index dc1bb23fea..dc1bb23fea 100644
--- a/examples/opengl/pbuffers/cube.cpp
+++ b/examples/opengl/legacy/pbuffers/cube.cpp
diff --git a/examples/opengl/pbuffers/cube.h b/examples/opengl/legacy/pbuffers/cube.h
index 05017cb376..05017cb376 100644
--- a/examples/opengl/pbuffers/cube.h
+++ b/examples/opengl/legacy/pbuffers/cube.h
diff --git a/examples/opengl/pbuffers/cubelogo.png b/examples/opengl/legacy/pbuffers/cubelogo.png
index 3ae0f9ba3f..3ae0f9ba3f 100644
--- a/examples/opengl/pbuffers/cubelogo.png
+++ b/examples/opengl/legacy/pbuffers/cubelogo.png
Binary files differ
diff --git a/examples/opengl/pbuffers/glwidget.cpp b/examples/opengl/legacy/pbuffers/glwidget.cpp
index b319951ccd..b319951ccd 100644
--- a/examples/opengl/pbuffers/glwidget.cpp
+++ b/examples/opengl/legacy/pbuffers/glwidget.cpp
diff --git a/examples/opengl/pbuffers/glwidget.h b/examples/opengl/legacy/pbuffers/glwidget.h
index c4d71c0b76..1d23b7772a 100644
--- a/examples/opengl/pbuffers/glwidget.h
+++ b/examples/opengl/legacy/pbuffers/glwidget.h
@@ -57,11 +57,11 @@ public:
~GLWidget();
protected:
- void initializeGL();
- void paintGL();
- void resizeGL(int width, int height);
- void mousePressEvent(QMouseEvent *) { setAnimationPaused(true); }
- void mouseReleaseEvent(QMouseEvent *) { setAnimationPaused(false); }
+ void initializeGL() Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void resizeGL(int width, int height) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE { setAnimationPaused(true); }
+ void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE { setAnimationPaused(false); }
private:
void initializeGeometry();
diff --git a/examples/opengl/pbuffers/main.cpp b/examples/opengl/legacy/pbuffers/main.cpp
index 8be6640e92..8be6640e92 100644
--- a/examples/opengl/pbuffers/main.cpp
+++ b/examples/opengl/legacy/pbuffers/main.cpp
diff --git a/examples/opengl/pbuffers/pbuffers.pro b/examples/opengl/legacy/pbuffers/pbuffers.pro
index a349e39f68..a349e39f68 100644
--- a/examples/opengl/pbuffers/pbuffers.pro
+++ b/examples/opengl/legacy/pbuffers/pbuffers.pro
diff --git a/examples/opengl/pbuffers/pbuffers.qrc b/examples/opengl/legacy/pbuffers/pbuffers.qrc
index 9fc1a56a1a..9fc1a56a1a 100644
--- a/examples/opengl/pbuffers/pbuffers.qrc
+++ b/examples/opengl/legacy/pbuffers/pbuffers.qrc
diff --git a/examples/opengl/pbuffers2/bubbles.svg b/examples/opengl/legacy/pbuffers2/bubbles.svg
index 51730124a2..51730124a2 100644
--- a/examples/opengl/pbuffers2/bubbles.svg
+++ b/examples/opengl/legacy/pbuffers2/bubbles.svg
diff --git a/examples/opengl/pbuffers2/designer.png b/examples/opengl/legacy/pbuffers2/designer.png
index 4f32d57496..4f32d57496 100644
--- a/examples/opengl/pbuffers2/designer.png
+++ b/examples/opengl/legacy/pbuffers2/designer.png
Binary files differ
diff --git a/examples/opengl/pbuffers2/glwidget.cpp b/examples/opengl/legacy/pbuffers2/glwidget.cpp
index de30bb8b21..de30bb8b21 100644
--- a/examples/opengl/pbuffers2/glwidget.cpp
+++ b/examples/opengl/legacy/pbuffers2/glwidget.cpp
diff --git a/examples/opengl/pbuffers2/glwidget.h b/examples/opengl/legacy/pbuffers2/glwidget.h
index 20dd796a48..20dd796a48 100644
--- a/examples/opengl/pbuffers2/glwidget.h
+++ b/examples/opengl/legacy/pbuffers2/glwidget.h
diff --git a/examples/opengl/pbuffers2/main.cpp b/examples/opengl/legacy/pbuffers2/main.cpp
index 79fd88a3c8..79fd88a3c8 100644
--- a/examples/opengl/pbuffers2/main.cpp
+++ b/examples/opengl/legacy/pbuffers2/main.cpp
diff --git a/examples/opengl/pbuffers2/pbuffers2.pro b/examples/opengl/legacy/pbuffers2/pbuffers2.pro
index f9dd269eea..f9dd269eea 100644
--- a/examples/opengl/pbuffers2/pbuffers2.pro
+++ b/examples/opengl/legacy/pbuffers2/pbuffers2.pro
diff --git a/examples/opengl/pbuffers2/pbuffers2.qrc b/examples/opengl/legacy/pbuffers2/pbuffers2.qrc
index 986f1ca385..986f1ca385 100644
--- a/examples/opengl/pbuffers2/pbuffers2.qrc
+++ b/examples/opengl/legacy/pbuffers2/pbuffers2.qrc
diff --git a/examples/opengl/samplebuffers/glwidget.cpp b/examples/opengl/legacy/samplebuffers/glwidget.cpp
index 28abf3d6c0..28abf3d6c0 100644
--- a/examples/opengl/samplebuffers/glwidget.cpp
+++ b/examples/opengl/legacy/samplebuffers/glwidget.cpp
diff --git a/examples/opengl/samplebuffers/glwidget.h b/examples/opengl/legacy/samplebuffers/glwidget.h
index 0e20b4dd4d..494c5861df 100644
--- a/examples/opengl/samplebuffers/glwidget.h
+++ b/examples/opengl/legacy/samplebuffers/glwidget.h
@@ -46,10 +46,10 @@ public:
GLWidget(QWidget *parent);
protected:
- void initializeGL();
- void resizeGL(int w, int h);
- void paintGL();
- void timerEvent(QTimerEvent *);
+ void initializeGL() Q_DECL_OVERRIDE;
+ void resizeGL(int w, int h) Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
void makeObject();
void quad(GLenum primitive, GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
diff --git a/examples/opengl/samplebuffers/main.cpp b/examples/opengl/legacy/samplebuffers/main.cpp
index a1272af4db..a1272af4db 100644
--- a/examples/opengl/samplebuffers/main.cpp
+++ b/examples/opengl/legacy/samplebuffers/main.cpp
diff --git a/examples/opengl/samplebuffers/samplebuffers.pro b/examples/opengl/legacy/samplebuffers/samplebuffers.pro
index b57599aae4..b57599aae4 100644
--- a/examples/opengl/samplebuffers/samplebuffers.pro
+++ b/examples/opengl/legacy/samplebuffers/samplebuffers.pro
diff --git a/examples/opengl/shared/qtlogo.cpp b/examples/opengl/legacy/shared/qtlogo.cpp
index 608f5b3f2b..608f5b3f2b 100644
--- a/examples/opengl/shared/qtlogo.cpp
+++ b/examples/opengl/legacy/shared/qtlogo.cpp
diff --git a/examples/opengl/shared/qtlogo.h b/examples/opengl/legacy/shared/qtlogo.h
index 5508372b01..5508372b01 100644
--- a/examples/opengl/shared/qtlogo.h
+++ b/examples/opengl/legacy/shared/qtlogo.h
diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro
index 7bc96234df..7c055d2a82 100644
--- a/examples/opengl/opengl.pro
+++ b/examples/opengl/opengl.pro
@@ -1,23 +1,16 @@
-requires(qtHaveModule(opengl))
-
TEMPLATE = subdirs
-contains(QT_CONFIG, opengles2) {
- SUBDIRS = hellogl_es2
-} else {
- SUBDIRS = 2dpainting \
- grabber \
- hellogl \
- overpainting \
- pbuffers \
- framebufferobject2 \
- samplebuffers
-}
+SUBDIRS = hellowindow \
+ paintedwindow \
+ qopenglwindow
-SUBDIRS += hellowindow \
- paintedwindow \
- contextinfo \
- cube \
- textures
+qtHaveModule(widgets) {
+ SUBDIRS += contextinfo \
+ threadedqopenglwidget \
+ 2dpainting \
+ hellogl2
-EXAMPLE_FILES = shared
+ !wince*: SUBDIRS += qopenglwidget \
+ cube \
+ textures
+}
diff --git a/examples/opengl/paintedwindow/paintedwindow.h b/examples/opengl/paintedwindow/paintedwindow.h
index f185cd3733..140af6db4d 100644
--- a/examples/opengl/paintedwindow/paintedwindow.h
+++ b/examples/opengl/paintedwindow/paintedwindow.h
@@ -74,8 +74,8 @@ private slots:
void rotationDone();
private:
- void exposeEvent(QExposeEvent *);
- void mousePressEvent(QMouseEvent *);
+ void exposeEvent(QExposeEvent *) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void paint(QPainter *painter, const QRect &rect);
diff --git a/examples/opengl/hellogl_es2/bubble.cpp b/examples/opengl/qopenglwidget/bubble.cpp
index 3e0f053bc8..c78e26a1d4 100644
--- a/examples/opengl/hellogl_es2/bubble.cpp
+++ b/examples/opengl/qopenglwidget/bubble.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -56,15 +56,15 @@ void Bubble::updateCache()
{
if (cache)
delete cache;
- cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32);
+ cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied);
cache->fill(0x00000000);
QPainter p(cache);
- p.setRenderHint(QPainter::HighQualityAntialiasing);
+ p.setRenderHint(QPainter::Antialiasing);
QPen pen(Qt::white);
pen.setWidth(2);
p.setPen(pen);
p.setBrush(brush);
- p.drawEllipse(0, 0, int(2*radius), int(2*radius));
+ p.drawEllipse(1, 1, int(2*radius), int(2*radius));
}
//! [0]
diff --git a/examples/opengl/hellogl_es2/bubble.h b/examples/opengl/qopenglwidget/bubble.h
index 60195b4415..ea33466ef7 100644
--- a/examples/opengl/hellogl_es2/bubble.h
+++ b/examples/opengl/qopenglwidget/bubble.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp
new file mode 100644
index 0000000000..de581f8d47
--- /dev/null
+++ b/examples/opengl/qopenglwidget/glwidget.cpp
@@ -0,0 +1,549 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ ** Contact: http://www.qt-project.org/legal
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:BSD$
+ ** You may use this file under the terms of the BSD license as follows:
+ **
+ ** "Redistribution and use in source and binary forms, with or without
+ ** modification, are permitted provided that the following conditions are
+ ** met:
+ ** * Redistributions of source code must retain the above copyright
+ ** notice, this list of conditions and the following disclaimer.
+ ** * Redistributions in binary form must reproduce the above copyright
+ ** notice, this list of conditions and the following disclaimer in
+ ** the documentation and/or other materials provided with the
+ ** distribution.
+ ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+ ** of its contributors may be used to endorse or promote products derived
+ ** from this software without specific prior written permission.
+ **
+ **
+ ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#include "glwidget.h"
+#include <QPainter>
+#include <QPaintEngine>
+#include <QOpenGLShaderProgram>
+#include <QOpenGLTexture>
+#include <QCoreApplication>
+#include <math.h>
+
+#include "mainwindow.h"
+#include "bubble.h"
+
+const int bubbleNum = 8;
+
+GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background)
+ : m_mainWindow(mw),
+ m_showBubbles(true),
+ m_qtLogo(true),
+ m_frames(0),
+ m_program1(0),
+ m_program2(0),
+ m_texture(0),
+ m_transparent(false),
+ m_btn(0),
+ m_hasButton(button),
+ m_background(background)
+{
+ setMinimumSize(300, 250);
+}
+
+GLWidget::~GLWidget()
+{
+ qDeleteAll(m_bubbles);
+
+ // And now release all OpenGL resources.
+ makeCurrent();
+ delete m_texture;
+ delete m_program1;
+ delete m_program2;
+ delete m_vshader1;
+ delete m_fshader1;
+ delete m_vshader2;
+ delete m_fshader2;
+ m_vbo1.destroy();
+ m_vbo2.destroy();
+ doneCurrent();
+}
+
+void GLWidget::setScaling(int scale)
+{
+ if (scale > 30)
+ m_fScale = 1 + qreal(scale - 30) / 30 * 0.25;
+ else if (scale < 30)
+ m_fScale = 1 - (qreal(30 - scale) / 30 * 0.25);
+ else
+ m_fScale = 1;
+}
+
+void GLWidget::setLogo()
+{
+ m_qtLogo = true;
+}
+
+void GLWidget::setTexture()
+{
+ m_qtLogo = false;
+}
+
+void GLWidget::setShowBubbles(bool bubbles)
+{
+ m_showBubbles = bubbles;
+}
+
+void GLWidget::paintQtLogo()
+{
+ m_program1->enableAttributeArray(m_vertexAttr1);
+ m_program1->enableAttributeArray(m_normalAttr1);
+
+ m_vbo1.bind();
+ // The data in the buffer is placed like this:
+ // vertex1.x, vertex1.y, vertex1.z, normal1.x, normal1.y, normal1.z, vertex2.x, ...
+ m_program1->setAttributeBuffer(m_vertexAttr1, GL_FLOAT, 0, 3, 6 * sizeof(GLfloat));
+ m_program1->setAttributeBuffer(m_normalAttr1, GL_FLOAT, 3 * sizeof(GLfloat), 3, 6 * sizeof(GLfloat));
+ m_vbo1.release();
+
+ glDrawArrays(GL_TRIANGLES, 0, m_vertices.size());
+
+ m_program1->disableAttributeArray(m_normalAttr1);
+ m_program1->disableAttributeArray(m_vertexAttr1);
+}
+
+void GLWidget::paintTexturedCube()
+{
+ m_texture->bind();
+
+ if (!m_vbo2.isCreated()) {
+ static 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
+ };
+
+ static 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
+ };
+
+ 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
+ };
+
+ m_vbo2.create();
+ m_vbo2.bind();
+ m_vbo2.allocate(36 * 8 * sizeof(GLfloat));
+ m_vbo2.write(0, afVertices, sizeof(afVertices));
+ m_vbo2.write(sizeof(afVertices), afTexCoord, sizeof(afTexCoord));
+ m_vbo2.write(sizeof(afVertices) + sizeof(afTexCoord), afNormals, sizeof(afNormals));
+ m_vbo2.release();
+ }
+
+ m_program2->setUniformValue(m_textureUniform2, 0); // use texture unit 0
+
+ m_program2->enableAttributeArray(m_vertexAttr2);
+ m_program2->enableAttributeArray(m_normalAttr2);
+ m_program2->enableAttributeArray(m_texCoordAttr2);
+
+ m_vbo2.bind();
+ // In the buffer we first have 36 vertices (3 floats for each), then 36 texture
+ // coordinates (2 floats for each), then 36 normals (3 floats for each).
+ m_program2->setAttributeBuffer(m_vertexAttr2, GL_FLOAT, 0, 3);
+ m_program2->setAttributeBuffer(m_texCoordAttr2, GL_FLOAT, 36 * 3 * sizeof(GLfloat), 2);
+ m_program2->setAttributeBuffer(m_normalAttr2, GL_FLOAT, 36 * 5 * sizeof(GLfloat), 3);
+ m_vbo2.release();
+
+ glDrawArrays(GL_TRIANGLES, 0, 36);
+
+ m_program2->disableAttributeArray(m_vertexAttr2);
+ m_program2->disableAttributeArray(m_normalAttr2);
+ m_program2->disableAttributeArray(m_texCoordAttr2);
+}
+
+void GLWidget::initializeGL()
+{
+ initializeOpenGLFunctions();
+
+ m_texture = new QOpenGLTexture(QImage(":/qt.png"));
+
+ m_vshader1 = new QOpenGLShader(QOpenGLShader::Vertex);
+ const char *vsrc1 =
+ "attribute highp vec4 vertex;\n"
+ "attribute mediump vec3 normal;\n"
+ "uniform mediump mat4 matrix;\n"
+ "varying mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
+ " float angle = max(dot(normal, toLight), 0.0);\n"
+ " vec3 col = vec3(0.40, 1.0, 0.0);\n"
+ " color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);\n"
+ " color = clamp(color, 0.0, 1.0);\n"
+ " gl_Position = matrix * vertex;\n"
+ "}\n";
+ m_vshader1->compileSourceCode(vsrc1);
+
+ m_fshader1 = new QOpenGLShader(QOpenGLShader::Fragment);
+ const char *fsrc1 =
+ "varying mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+ m_fshader1->compileSourceCode(fsrc1);
+
+ m_program1 = new QOpenGLShaderProgram;
+ m_program1->addShader(m_vshader1);
+ m_program1->addShader(m_fshader1);
+ m_program1->link();
+
+ m_vertexAttr1 = m_program1->attributeLocation("vertex");
+ m_normalAttr1 = m_program1->attributeLocation("normal");
+ m_matrixUniform1 = m_program1->uniformLocation("matrix");
+
+ m_vshader2 = new QOpenGLShader(QOpenGLShader::Vertex);
+ const char *vsrc2 =
+ "attribute highp vec4 vertex;\n"
+ "attribute highp vec4 texCoord;\n"
+ "attribute mediump vec3 normal;\n"
+ "uniform mediump mat4 matrix;\n"
+ "varying highp vec4 texc;\n"
+ "varying mediump float angle;\n"
+ "void main(void)\n"
+ "{\n"
+ " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
+ " angle = max(dot(normal, toLight), 0.0);\n"
+ " gl_Position = matrix * vertex;\n"
+ " texc = texCoord;\n"
+ "}\n";
+ m_vshader2->compileSourceCode(vsrc2);
+
+ m_fshader2 = new QOpenGLShader(QOpenGLShader::Fragment);
+ const char *fsrc2 =
+ "varying highp vec4 texc;\n"
+ "uniform sampler2D tex;\n"
+ "varying mediump float angle;\n"
+ "void main(void)\n"
+ "{\n"
+ " highp vec3 color = texture2D(tex, texc.st).rgb;\n"
+ " color = color * 0.2 + color * 0.8 * angle;\n"
+ " gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
+ "}\n";
+ m_fshader2->compileSourceCode(fsrc2);
+
+ m_program2 = new QOpenGLShaderProgram;
+ m_program2->addShader(m_vshader2);
+ m_program2->addShader(m_fshader2);
+ m_program2->link();
+
+ m_vertexAttr2 = m_program2->attributeLocation("vertex");
+ m_normalAttr2 = m_program2->attributeLocation("normal");
+ m_texCoordAttr2 = m_program2->attributeLocation("texCoord");
+ m_matrixUniform2 = m_program2->uniformLocation("matrix");
+ m_textureUniform2 = m_program2->uniformLocation("tex");
+
+ m_fAngle = 0;
+ m_fScale = 1;
+
+ createGeometry();
+
+ // Use a vertex buffer object. Client-side pointers are old-school and should be avoided.
+ m_vbo1.create();
+ m_vbo1.bind();
+ // For the cube all the data belonging to the texture coordinates and
+ // normals is placed separately, after the vertices. Here, for the Qt logo,
+ // let's do something different and potentially more efficient: create a
+ // properly interleaved data set.
+ const int vertexCount = m_vertices.count();
+ QVector<GLfloat> buf;
+ buf.resize(vertexCount * 3 * 2);
+ GLfloat *p = buf.data();
+ for (int i = 0; i < vertexCount; ++i) {
+ *p++ = m_vertices[i].x();
+ *p++ = m_vertices[i].y();
+ *p++ = m_vertices[i].z();
+ *p++ = m_normals[i].x();
+ *p++ = m_normals[i].y();
+ *p++ = m_normals[i].z();
+ }
+ m_vbo1.allocate(buf.constData(), buf.count() * sizeof(GLfloat));
+ m_vbo1.release();
+
+ createBubbles(bubbleNum - m_bubbles.count());
+}
+
+void GLWidget::paintGL()
+{
+ createBubbles(bubbleNum - m_bubbles.count());
+
+ QPainter painter;
+ painter.begin(this);
+
+ painter.beginNativePainting();
+
+ glClearColor(m_background.redF(), m_background.greenF(), m_background.blueF(), m_transparent ? 0.0f : 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+
+ QMatrix4x4 modelview;
+ modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
+ modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
+ modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
+ modelview.scale(m_fScale);
+ modelview.translate(0.0f, -0.2f, 0.0f);
+
+ if (m_qtLogo) {
+ m_program1->bind();
+ m_program1->setUniformValue(m_matrixUniform1, modelview);
+ paintQtLogo();
+ m_program1->release();
+ } else {
+ m_program2->bind();
+ m_program2->setUniformValue(m_matrixUniform2, modelview);
+ paintTexturedCube();
+ m_program2->release();
+ }
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+
+ painter.endNativePainting();
+
+ if (m_showBubbles)
+ foreach (Bubble *bubble, m_bubbles) {
+ bubble->drawBubble(&painter);
+ }
+
+ if (const int elapsed = m_time.elapsed()) {
+ QString framesPerSecond;
+ framesPerSecond.setNum(m_frames /(elapsed / 1000.0), 'f', 2);
+ painter.setPen(m_transparent ? Qt::black : Qt::white);
+ painter.drawText(20, 40, framesPerSecond + " paintGL calls / s");
+ }
+
+ painter.end();
+
+ QMutableListIterator<Bubble*> iter(m_bubbles);
+
+ while (iter.hasNext()) {
+ Bubble *bubble = iter.next();
+ bubble->move(rect());
+ }
+ if (!(m_frames % 100)) {
+ m_time.start();
+ m_frames = 0;
+ }
+ m_fAngle += 1.0f;
+ ++m_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)));
+
+ m_bubbles.append(new Bubble(position, radius, velocity));
+ }
+}
+
+void GLWidget::createGeometry()
+{
+ m_vertices.clear();
+ m_normals.clear();
+
+ qreal x1 = +0.06f;
+ qreal y1 = -0.14f;
+ qreal x2 = +0.14f;
+ qreal y2 = -0.06f;
+ qreal x3 = +0.08f;
+ qreal y3 = +0.00f;
+ qreal x4 = +0.30f;
+ qreal y4 = +0.22f;
+
+ quad(x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(x3, y3, x4, y4, y4, x4, y3, x3);
+
+ extrude(x1, y1, x2, y2);
+ extrude(x2, y2, y2, x2);
+ extrude(y2, x2, y1, x1);
+ extrude(y1, x1, x1, y1);
+ extrude(x3, y3, x4, y4);
+ extrude(x4, y4, y4, x4);
+ extrude(y4, x4, y3, x3);
+
+ const qreal Pi = 3.14159f;
+ const int NumSectors = 100;
+
+ for (int i = 0; i < NumSectors; ++i) {
+ qreal angle1 = (i * 2 * Pi) / NumSectors;
+ qreal x5 = 0.30 * sin(angle1);
+ qreal y5 = 0.30 * cos(angle1);
+ qreal x6 = 0.20 * sin(angle1);
+ qreal y6 = 0.20 * cos(angle1);
+
+ qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors;
+ qreal x7 = 0.20 * sin(angle2);
+ qreal y7 = 0.20 * cos(angle2);
+ qreal x8 = 0.30 * sin(angle2);
+ qreal y8 = 0.30 * cos(angle2);
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+
+ for (int i = 0;i < m_vertices.size();i++)
+ m_vertices[i] *= 2.0f;
+}
+
+void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
+{
+ m_vertices << QVector3D(x1, y1, -0.05f);
+ m_vertices << QVector3D(x2, y2, -0.05f);
+ m_vertices << QVector3D(x4, y4, -0.05f);
+
+ m_vertices << QVector3D(x3, y3, -0.05f);
+ m_vertices << QVector3D(x4, y4, -0.05f);
+ m_vertices << QVector3D(x2, y2, -0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_vertices << QVector3D(x4, y4, 0.05f);
+ m_vertices << QVector3D(x2, y2, 0.05f);
+ m_vertices << QVector3D(x1, y1, 0.05f);
+
+ m_vertices << QVector3D(x2, y2, 0.05f);
+ m_vertices << QVector3D(x4, y4, 0.05f);
+ m_vertices << QVector3D(x3, y3, 0.05f);
+
+ n = QVector3D::normal
+ (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+}
+
+void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
+{
+ m_vertices << QVector3D(x1, y1, +0.05f);
+ m_vertices << QVector3D(x2, y2, +0.05f);
+ m_vertices << QVector3D(x1, y1, -0.05f);
+
+ m_vertices << QVector3D(x2, y2, -0.05f);
+ m_vertices << QVector3D(x1, y1, -0.05f);
+ m_vertices << QVector3D(x2, y2, +0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+}
+
+void GLWidget::setTransparent(bool transparent)
+{
+ setAttribute(Qt::WA_AlwaysStackOnTop, transparent);
+ m_transparent = transparent;
+ // Call update() on the top-level window after toggling AlwayStackOnTop to make sure
+ // the entire backingstore is updated accordingly.
+ window()->update();
+}
+
+void GLWidget::resizeGL(int w, int h)
+{
+ if (m_hasButton) {
+ if (!m_btn) {
+ m_btn = new QPushButton("A widget on top.\nPress me!", this);
+ connect(m_btn, &QPushButton::clicked, this, &GLWidget::handleButtonPress);
+ }
+ m_btn->move(w / 2, h / 2);
+ }
+}
+
+void GLWidget::handleButtonPress()
+{
+ m_mainWindow->addNew();
+}
diff --git a/examples/opengl/hellogl_es2/glwidget.h b/examples/opengl/qopenglwidget/glwidget.h
index 8ed86b1e01..ba8317df4a 100644
--- a/examples/opengl/hellogl_es2/glwidget.h
+++ b/examples/opengl/qopenglwidget/glwidget.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -41,54 +41,83 @@
#ifndef GLWIDGET_H
#define GLWIDGET_H
-#include <QGLWidget>
-#include <QtGui/qvector3d.h>
-#include <QtGui/qmatrix4x4.h>
-#include <QtOpenGL/qglshaderprogram.h>
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions>
+#include <QOpenGLBuffer>
+#include <QVector3D>
+#include <QMatrix4x4>
#include <QTime>
#include <QVector>
+#include <QPushButton>
class Bubble;
-class GLWidget : public QGLWidget {
+class MainWindow;
+QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)
+QT_FORWARD_DECLARE_CLASS(QOpenGLShader)
+QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
+
+class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
+{
Q_OBJECT
public:
- GLWidget(QWidget *parent = 0);
+ GLWidget(MainWindow *mw, bool button, const QColor &background);
~GLWidget();
+
public slots:
void setScaling(int scale);
void setLogo();
void setTexture();
- void showBubbles(bool);
+ void setShowBubbles(bool);
+ void setTransparent(bool transparent);
+
+private slots:
+ void handleButtonPress();
+
protected:
- void paintGL ();
- void initializeGL ();
+ void resizeGL(int w, int h) Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void initializeGL() Q_DECL_OVERRIDE;
+
private:
- GLuint m_uiTexture;
- qreal m_fAngle;
- qreal m_fScale;
- bool m_showBubbles;
void paintTexturedCube();
void paintQtLogo();
void createGeometry();
void createBubbles(int number);
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
- QVector<QVector3D> vertices;
- QVector<QVector3D> normals;
- bool qtLogo;
- QList<Bubble*> bubbles;
- int frames;
- QTime time;
- QGLShaderProgram program1;
- QGLShaderProgram program2;
- int vertexAttr1;
- int normalAttr1;
- int matrixUniform1;
- int vertexAttr2;
- int normalAttr2;
- int texCoordAttr2;
- int matrixUniform2;
- int textureUniform2;
+
+ MainWindow *m_mainWindow;
+ qreal m_fAngle;
+ qreal m_fScale;
+ bool m_showBubbles;
+ QVector<QVector3D> m_vertices;
+ QVector<QVector3D> m_normals;
+ bool m_qtLogo;
+ QList<Bubble *> m_bubbles;
+ int m_frames;
+ QTime m_time;
+ QOpenGLShader *m_vshader1;
+ QOpenGLShader *m_fshader1;
+ QOpenGLShader *m_vshader2;
+ QOpenGLShader *m_fshader2;
+ QOpenGLShaderProgram *m_program1;
+ QOpenGLShaderProgram *m_program2;
+ QOpenGLTexture *m_texture;
+ QOpenGLBuffer m_vbo1;
+ QOpenGLBuffer m_vbo2;
+ int m_vertexAttr1;
+ int m_normalAttr1;
+ int m_matrixUniform1;
+ int m_vertexAttr2;
+ int m_normalAttr2;
+ int m_texCoordAttr2;
+ int m_matrixUniform2;
+ int m_textureUniform2;
+ bool m_transparent;
+ QPushButton *m_btn;
+ bool m_hasButton;
+ QColor m_background;
};
+
#endif
diff --git a/examples/opengl/qopenglwidget/main.cpp b/examples/opengl/qopenglwidget/main.cpp
new file mode 100644
index 0000000000..a545c27249
--- /dev/null
+++ b/examples/opengl/qopenglwidget/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMainWindow>
+#include <QSurfaceFormat>
+#include "mainwindow.h"
+
+int main( int argc, char ** argv )
+{
+ Q_INIT_RESOURCE(texture);
+ QApplication a( argc, argv );
+
+ QSurfaceFormat format;
+ format.setDepthBufferSize(24);
+ format.setStencilBufferSize(8);
+ if (QCoreApplication::arguments().contains(QStringLiteral("--multisample")))
+ format.setSamples(4);
+ QSurfaceFormat::setDefaultFormat(format);
+
+ MainWindow mw;
+ mw.showMaximized();
+ return a.exec();
+}
diff --git a/examples/opengl/qopenglwidget/mainwindow.cpp b/examples/opengl/qopenglwidget/mainwindow.cpp
new file mode 100644
index 0000000000..7645c75d8c
--- /dev/null
+++ b/examples/opengl/qopenglwidget/mainwindow.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QApplication>
+#include <QMenuBar>
+#include <QGroupBox>
+#include <QSlider>
+#include <QLabel>
+#include <QCheckBox>
+#include <QSpinBox>
+
+#include "glwidget.h"
+
+MainWindow::MainWindow()
+ : m_nextX(1), m_nextY(1)
+{
+ GLWidget *glwidget = new GLWidget(this, true, qRgb(20, 20, 50));
+ QLabel *label = new QLabel(this);
+ m_timer = new QTimer(this);
+ QSlider *slider = new QSlider(this);
+ slider->setOrientation(Qt::Horizontal);
+
+ QLabel *updateLabel = new QLabel("Update interval");
+ QSpinBox *updateInterval = new QSpinBox(this);
+ updateInterval->setSuffix(" ms");
+ updateInterval->setValue(10);
+ updateInterval->setToolTip("Interval for the timer that calls update().\n"
+ "Note that on most systems the swap will block to wait for vsync\n"
+ "and therefore an interval < 16 ms will likely lead to a 60 FPS update rate.");
+ QGroupBox *updateGroupBox = new QGroupBox(this);
+ QCheckBox *transparent = new QCheckBox("Transparent background", this);
+ transparent->setToolTip("Toggles Qt::WA_AlwaysStackOnTop and transparent clear color for glClear().\n"
+ "Note how the button on top stacks incorrectly when enabling this.");
+ QHBoxLayout *updateLayout = new QHBoxLayout;
+ updateLayout->addWidget(updateLabel);
+ updateLayout->addWidget(updateInterval);
+ updateLayout->addWidget(transparent);
+ updateGroupBox->setLayout(updateLayout);
+
+ slider->setRange(0, 50);
+ slider->setSliderPosition(30);
+ m_timer->setInterval(10);
+ label->setText("A QOpenGLWidget");
+ label->setAlignment(Qt::AlignHCenter);
+
+ QGroupBox * groupBox = new QGroupBox(this);
+ setCentralWidget(groupBox);
+ groupBox->setTitle("QOpenGLWidget Example");
+
+ m_layout = new QGridLayout(groupBox);
+
+ m_layout->addWidget(glwidget,1,0,8,1);
+ m_layout->addWidget(label,9,0,1,1);
+ m_layout->addWidget(updateGroupBox, 10, 0, 1, 1);
+ m_layout->addWidget(slider, 11,0,1,1);
+
+ groupBox->setLayout(m_layout);
+
+ QMenu *fileMenu = menuBar()->addMenu("&File");
+ QMenu *showMenu = menuBar()->addMenu("&Show");
+ QMenu *helpMenu = menuBar()->addMenu("&Help");
+ QAction *exit = new QAction("E&xit", fileMenu);
+ QAction *aboutQt = new QAction("About Qt", 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);
+
+ connect(exit, SIGNAL(triggered(bool)), this, SLOT(close()));
+ connect(aboutQt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
+
+ connect(m_timer, SIGNAL(timeout()), glwidget, SLOT(update()));
+
+ connect(showLogo, SIGNAL(triggered(bool)), glwidget, SLOT(setLogo()));
+ connect(showTexture, SIGNAL(triggered(bool)), glwidget, SLOT(setTexture()));
+ connect(showBubbles, SIGNAL(triggered(bool)), glwidget, SLOT(setShowBubbles(bool)));
+ connect(slider, SIGNAL(valueChanged(int)), glwidget, SLOT(setScaling(int)));
+ connect(transparent, &QCheckBox::toggled, glwidget, &GLWidget::setTransparent);
+
+ connect(updateInterval, SIGNAL(valueChanged(int)), this, SLOT(updateIntervalChanged(int)));
+
+ m_timer->start();
+}
+
+void MainWindow::updateIntervalChanged(int value)
+{
+ m_timer->setInterval(value);
+ m_timer->start();
+}
+
+void MainWindow::addNew()
+{
+ if (m_nextY == 4)
+ return;
+ GLWidget *w = new GLWidget(this, false, qRgb(qrand() % 256, qrand() % 256, qrand() % 256));
+ connect(m_timer, SIGNAL(timeout()), w, SLOT(update()));
+ m_layout->addWidget(w, m_nextY, m_nextX, 1, 1);
+ if (m_nextX == 3) {
+ m_nextX = 1;
+ ++m_nextY;
+ } else {
+ ++m_nextX;
+ }
+}
diff --git a/examples/opengl/qopenglwidget/mainwindow.h b/examples/opengl/qopenglwidget/mainwindow.h
new file mode 100644
index 0000000000..9db3e8cbec
--- /dev/null
+++ b/examples/opengl/qopenglwidget/mainwindow.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QTimer>
+#include <QGridLayout>
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+ void addNew();
+
+private slots:
+ void updateIntervalChanged(int value);
+
+private:
+ QTimer *m_timer;
+ QGridLayout *m_layout;
+ int m_nextX;
+ int m_nextY;
+};
+
+#endif
diff --git a/examples/opengl/qopenglwidget/qopenglwidget.pro b/examples/opengl/qopenglwidget/qopenglwidget.pro
new file mode 100644
index 0000000000..0165285c02
--- /dev/null
+++ b/examples/opengl/qopenglwidget/qopenglwidget.pro
@@ -0,0 +1,15 @@
+QT += widgets
+
+SOURCES += main.cpp \
+ glwidget.cpp \
+ mainwindow.cpp \
+ bubble.cpp
+
+HEADERS += glwidget.h \
+ mainwindow.h \
+ bubble.h
+
+RESOURCES += texture.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/qopenglwidget
+INSTALLS += target
diff --git a/examples/opengl/hellogl_es2/qt.png b/examples/opengl/qopenglwidget/qt.png
index 79e383cf50..79e383cf50 100644
--- a/examples/opengl/hellogl_es2/qt.png
+++ b/examples/opengl/qopenglwidget/qt.png
Binary files differ
diff --git a/examples/opengl/hellogl_es2/texture.qrc b/examples/opengl/qopenglwidget/texture.qrc
index ff1d0e535f..ff1d0e535f 100644
--- a/examples/opengl/hellogl_es2/texture.qrc
+++ b/examples/opengl/qopenglwidget/texture.qrc
diff --git a/examples/opengl/qopenglwindow/background.frag b/examples/opengl/qopenglwindow/background.frag
new file mode 100644
index 0000000000..572c941f08
--- /dev/null
+++ b/examples/opengl/qopenglwindow/background.frag
@@ -0,0 +1,25 @@
+uniform int currentTime;
+uniform highp vec2 windowSize;
+
+highp float noise(highp vec2 co)
+{
+ return 0.5 * fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
+}
+
+highp float curvSpeed()
+{
+ return mod(float(currentTime), 1000000.0) / 500.0;
+}
+
+highp float curv()
+{
+ return 1.0 - abs((gl_FragCoord.y / (windowSize.y / 10.0) - 5.0) - sin((gl_FragCoord.x / (windowSize.x/20.0)) - curvSpeed()));
+}
+
+void main()
+{
+ highp float coordNoise = noise(gl_FragCoord.xy);
+ highp float proximity = smoothstep(0.5, 1.0, (curv() + 1.0) * (coordNoise ));
+ highp vec3 color = vec3(coordNoise) * proximity;
+ gl_FragColor = vec4(color, 1.0);
+}
diff --git a/examples/opengl/qopenglwindow/background_renderer.cpp b/examples/opengl/qopenglwindow/background_renderer.cpp
new file mode 100644
index 0000000000..2c830ac13c
--- /dev/null
+++ b/examples/opengl/qopenglwindow/background_renderer.cpp
@@ -0,0 +1,201 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "background_renderer.h"
+
+#include <qmath.h>
+#include <QFileInfo>
+#include <QTime>
+
+#include <QOpenGLShaderProgram>
+#include <QOpenGLContext>
+#include <QOpenGLFunctions>
+
+#include <math.h>
+
+static const char vertex_shader[] =
+ "attribute highp vec3 vertexCoord;"
+ "void main() {"
+ " gl_Position = vec4(vertexCoord,1.0);"
+ "}";
+
+static const char fragment_shader[] =
+ "void main() {"
+ " gl_FragColor = vec4(0.0,1.0,0.0,1.0);"
+ "}";
+
+static const float vertices[] = { -1, -1, 0,
+ -1, 1, 0,
+ 1, -1, 0,
+ 1, 1, 0 };
+
+FragmentToy::FragmentToy(const QString &fragmentSource, QObject *parent)
+ : QObject(parent)
+ , m_recompile_shaders(true)
+{
+ if (QFile::exists(fragmentSource)) {
+ QFileInfo info(fragmentSource);
+ m_fragment_file_last_modified = info.lastModified();
+ m_fragment_file = fragmentSource;
+#ifndef QT_NO_FILESYSTEMWATCHER
+ m_watcher.addPath(info.canonicalFilePath());
+ QObject::connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &FragmentToy::fileChanged);
+#endif
+ }
+}
+
+void FragmentToy::draw(const QSize &windowSize)
+{
+ if (!m_program)
+ initializeOpenGLFunctions();
+
+ glDisable(GL_STENCIL_TEST);
+ glDisable(GL_DEPTH_TEST);
+
+ glClearColor(0, 0, 0, 1);
+ glClear(GL_COLOR_BUFFER_BIT);
+ if (!m_vao.isCreated())
+ m_vao.create();
+
+ m_vao.bind();
+
+ if (!m_vertex_buffer.isCreated()) {
+ m_vertex_buffer.create();
+ m_vertex_buffer.bind();
+ m_vertex_buffer.allocate(vertices, sizeof(vertices));
+ m_vertex_buffer.release();
+ }
+
+ if (!m_program) {
+ m_program.reset(new QOpenGLShaderProgram);
+ m_program->create();
+ m_vertex_shader.reset(new QOpenGLShader(QOpenGLShader::Vertex));
+ if (!m_vertex_shader->compileSourceCode(vertex_shader)) {
+ qWarning() << "Failed to compile the vertex shader:" << m_vertex_shader->log();
+ }
+ if (!m_program->addShader(m_vertex_shader.data())) {
+ qWarning() << "Failed to add vertex shader to program:" << m_program->log();
+ }
+ }
+
+ if (!m_fragment_shader) {
+ QByteArray data;
+ if (m_fragment_file.size()) {
+ QFile file(m_fragment_file);
+ if (file.open(QIODevice::ReadOnly)) {
+ data = file.readAll();
+ } else {
+ qWarning() << "Failed to load input file, falling back to default";
+ data = QByteArray::fromRawData(fragment_shader, sizeof(fragment_shader));
+ }
+ } else {
+ QFile qrcFile(":/background.frag");
+ if (qrcFile.open(QIODevice::ReadOnly))
+ data = qrcFile.readAll();
+ else
+ data = QByteArray::fromRawData(fragment_shader, sizeof(fragment_shader));
+ }
+ if (data.size()) {
+ m_fragment_shader.reset(new QOpenGLShader(QOpenGLShader::Fragment));
+ if (!m_fragment_shader->compileSourceCode(data)) {
+ qWarning() << "Failed to compile fragment shader:" << m_fragment_shader->log();
+ m_fragment_shader.reset(Q_NULLPTR);
+ }
+ } else {
+ qWarning() << "Unknown error, no fragment shader";
+ }
+
+ if (m_fragment_shader) {
+ if (!m_program->addShader(m_fragment_shader.data())) {
+ qWarning() << "Failed to add fragment shader to program:" << m_program->log();
+ }
+ }
+ }
+
+ if (m_recompile_shaders) {
+ m_recompile_shaders = false;
+
+ if (m_program->link()) {
+ m_vertex_coord_pos = m_program->attributeLocation("vertexCoord");
+ } else {
+ qWarning() << "Failed to link shader program" << m_program->log();
+ }
+
+ }
+
+ m_program->bind();
+
+ m_vertex_buffer.bind();
+ m_program->setAttributeBuffer("vertexCoord", GL_FLOAT, 0, 3, 0);
+ m_program->enableAttributeArray("vertexCoord");
+ m_vertex_buffer.release();
+
+ float radiens = (QTime::currentTime().msecsSinceStartOfDay() / 60) / (2 * M_PI);
+ m_program->setUniformValue("currentTime", (uint) QDateTime::currentDateTime().toMSecsSinceEpoch());
+ m_program->setUniformValue("radiens", radiens);
+ m_program->setUniformValue("windowSize", windowSize);
+
+ QOpenGLContext::currentContext()->functions()->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ m_program->release();
+ m_vao.release();
+}
+
+void FragmentToy::fileChanged(const QString &path)
+{
+ Q_UNUSED(path);
+ if (QFile::exists(m_fragment_file)) {
+ QFileInfo fragment_source(m_fragment_file);
+ if (fragment_source.lastModified() > m_fragment_file_last_modified) {
+ m_fragment_file_last_modified = fragment_source.lastModified();
+ m_recompile_shaders = true;
+ if (m_program) {
+ m_program->removeShader(m_fragment_shader.data());
+ m_fragment_shader.reset(Q_NULLPTR);
+ }
+ }
+ } else {
+ m_recompile_shaders = true;
+ if (m_program) {
+ m_program->removeShader(m_fragment_shader.data());
+ m_fragment_shader.reset(Q_NULLPTR);
+ }
+ }
+}
diff --git a/examples/opengl/qopenglwindow/background_renderer.h b/examples/opengl/qopenglwindow/background_renderer.h
new file mode 100644
index 0000000000..3759de478c
--- /dev/null
+++ b/examples/opengl/qopenglwindow/background_renderer.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FRAGMENT_TOY_H
+#define FRAGMENT_TOY_H
+
+#include <QObject>
+#include <QFile>
+#include <QDateTime>
+#include <QFileSystemWatcher>
+#include <QOpenGLVertexArrayObject>
+#include <QOpenGLBuffer>
+#include <QOpenGLShaderProgram>
+#include <QOpenGLFunctions>
+
+class FragmentToy : public QObject, protected QOpenGLFunctions
+{
+ Q_OBJECT
+public:
+ FragmentToy(const QString &fragmentSource, QObject *parent = 0);
+
+ void draw(const QSize &windowSize);
+
+private:
+ void fileChanged(const QString &path);
+ bool m_recompile_shaders;
+#ifndef QT_NO_FILESYSTEMWATCHER
+ QFileSystemWatcher m_watcher;
+#endif
+ QString m_fragment_file;
+ QDateTime m_fragment_file_last_modified;
+
+ QScopedPointer<QOpenGLShaderProgram> m_program;
+ QScopedPointer<QOpenGLShader> m_vertex_shader;
+ QScopedPointer<QOpenGLShader> m_fragment_shader;
+ QOpenGLVertexArrayObject m_vao;
+ QOpenGLBuffer m_vertex_buffer;
+ GLuint m_vertex_coord_pos;
+};
+
+#endif //FRAGMENT_TOY_H
diff --git a/examples/opengl/qopenglwindow/main.cpp b/examples/opengl/qopenglwindow/main.cpp
new file mode 100644
index 0000000000..bf95d09ecd
--- /dev/null
+++ b/examples/opengl/qopenglwindow/main.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QOpenGLWindow>
+#include <QScreen>
+#include <QPainter>
+#include <QGuiApplication>
+#include <QMatrix4x4>
+#include <QStaticText>
+#include <QKeyEvent>
+
+#include "background_renderer.h"
+
+static QPainterPath painterPathForTriangle()
+{
+ static const QPointF bottomLeft(-1.0, -1.0);
+ static const QPointF top(0.0, 1.0);
+ static const QPointF bottomRight(1.0, -1.0);
+
+ QPainterPath path(bottomLeft);
+ path.lineTo(top);
+ path.lineTo(bottomRight);
+ path.closeSubpath();
+ return path;
+}
+
+class OpenGLWindow : public QOpenGLWindow
+{
+ Q_OBJECT
+
+public:
+ OpenGLWindow();
+
+protected:
+ void paintGL() Q_DECL_OVERRIDE;
+ void resizeGL(int w, int h) Q_DECL_OVERRIDE;
+ void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
+
+private:
+ void setAnimating(bool enabled);
+
+ QMatrix4x4 m_window_normalised_matrix;
+ QMatrix4x4 m_window_painter_matrix;
+ QMatrix4x4 m_projection;
+ QMatrix4x4 m_view;
+ QMatrix4x4 m_model_triangle;
+ QMatrix4x4 m_model_text;
+ QBrush m_brush;
+
+ FragmentToy m_fragment_toy;
+ QStaticText m_text_layout;
+ bool m_animate;
+};
+
+// Use NoPartialUpdate. This means that all the rendering goes directly to
+// the window surface, no additional framebuffer object stands in the
+// middle. This is fine since we will clear the entire framebuffer on each
+// paint. Under the hood this means that the behavior is equivalent to the
+// manual makeCurrent - perform OpenGL calls - swapBuffers loop that is
+// typical in pure QWindow-based applications.
+OpenGLWindow::OpenGLWindow()
+ : QOpenGLWindow(QOpenGLWindow::NoPartialUpdate)
+ , m_fragment_toy("background.frag")
+ , m_text_layout("The triangle and this text is rendered with QPainter")
+ , m_animate(true)
+{
+ m_view.lookAt(QVector3D(3,1,1),
+ QVector3D(0,0,0),
+ QVector3D(0,1,0));
+
+ QLinearGradient gradient(QPointF(-1,-1), QPointF(1,1));
+ gradient.setColorAt(0, Qt::red);
+ gradient.setColorAt(1, Qt::green);
+
+ m_brush = QBrush(gradient);
+
+ setAnimating(m_animate);
+}
+
+void OpenGLWindow::paintGL()
+{
+ m_fragment_toy.draw(size());
+
+ QPainter p(this);
+ p.setWorldTransform(m_window_normalised_matrix.toTransform());
+
+ QMatrix4x4 mvp = m_projection * m_view * m_model_triangle;
+ p.setTransform(mvp.toTransform(), true);
+
+ p.fillPath(painterPathForTriangle(), m_brush);
+
+ QTransform text_transform = (m_window_painter_matrix * m_view * m_model_text).toTransform();
+ p.setTransform(text_transform, false);
+ p.setPen(QPen(Qt::white));
+ m_text_layout.prepare(text_transform);
+ qreal x = - (m_text_layout.size().width() / 2);
+ qreal y = 0;
+ p.drawStaticText(x, y, m_text_layout);
+
+ m_model_triangle.rotate(-1, 0, 1, 0);
+ m_model_text.rotate(1, 0, 1, 0);
+}
+
+void OpenGLWindow::resizeGL(int w, int h)
+{
+ m_window_normalised_matrix.setToIdentity();
+ m_window_normalised_matrix.translate(w / 2.0, h / 2.0);
+ m_window_normalised_matrix.scale(w / 2.0, -h / 2.0);
+
+ m_window_painter_matrix.setToIdentity();
+ m_window_painter_matrix.translate(w / 2.0, h / 2.0);
+
+ m_text_layout.setTextWidth(std::max(w * 0.2, 80.0));
+
+ m_projection.setToIdentity();
+ m_projection.perspective(45.f, qreal(w) / qreal(h), 0.1f, 100.f);
+}
+
+void OpenGLWindow::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_P) { // pause
+ m_animate = !m_animate;
+ setAnimating(m_animate);
+ }
+}
+
+void OpenGLWindow::setAnimating(bool enabled)
+{
+ if (enabled) {
+ // Animate continuously, throttled by the blocking swapBuffers() call the
+ // QOpenGLWindow internally executes after each paint. Once that is done
+ // (frameSwapped signal is emitted), we schedule a new update. This
+ // obviously assumes that the swap interval (see
+ // QSurfaceFormat::setSwapInterval()) is non-zero.
+ connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
+ update();
+ } else {
+ disconnect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
+ }
+}
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ OpenGLWindow window;
+ QSurfaceFormat fmt;
+ fmt.setDepthBufferSize(24);
+ fmt.setStencilBufferSize(8);
+ window.setFormat(fmt);
+ window.showMaximized();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/opengl/qopenglwindow/qopenglwindow.pro b/examples/opengl/qopenglwindow/qopenglwindow.pro
new file mode 100644
index 0000000000..dad4b58158
--- /dev/null
+++ b/examples/opengl/qopenglwindow/qopenglwindow.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+TARGET = qopenglwindow
+INCLUDEPATH += .
+
+RESOURCES += shaders.qrc
+
+SOURCES += \
+ main.cpp \
+ background_renderer.cpp
+
+HEADERS += \
+ background_renderer.h
+
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/qopenglwindow
+INSTALLS += target
diff --git a/examples/opengl/qopenglwindow/shaders.qrc b/examples/opengl/qopenglwindow/shaders.qrc
new file mode 100644
index 0000000000..64eefe2c70
--- /dev/null
+++ b/examples/opengl/qopenglwindow/shaders.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>background.frag</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
index 305ca1aa4c..96c732f8a6 100644
--- a/examples/opengl/textures/glwidget.cpp
+++ b/examples/opengl/textures/glwidget.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -38,23 +38,30 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include <QtOpenGL>
-
#include "glwidget.h"
-
-GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget)
- : QGLWidget(parent, shareWidget)
+#include <QOpenGLShaderProgram>
+#include <QOpenGLTexture>
+#include <QMouseEvent>
+
+GLWidget::GLWidget(QWidget *parent)
+ : QOpenGLWidget(parent),
+ clearColor(Qt::black),
+ xRot(0),
+ yRot(0),
+ zRot(0),
+ program(0)
{
- clearColor = Qt::black;
- xRot = 0;
- yRot = 0;
- zRot = 0;
- program = 0;
+ memset(textures, 0, sizeof(textures));
}
GLWidget::~GLWidget()
{
+ makeCurrent();
+ vbo.destroy();
+ for (int i = 0; i < 6; ++i)
+ delete textures[i];
+ delete program;
+ doneCurrent();
}
QSize GLWidget::minimumSizeHint() const
@@ -72,13 +79,13 @@ void GLWidget::rotateBy(int xAngle, int yAngle, int zAngle)
xRot += xAngle;
yRot += yAngle;
zRot += zAngle;
- updateGL();
+ update();
}
void GLWidget::setClearColor(const QColor &color)
{
clearColor = color;
- updateGL();
+ update();
}
void GLWidget::initializeGL()
@@ -89,14 +96,11 @@ void GLWidget::initializeGL()
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
-#ifdef GL_TEXTURE_2D
- glEnable(GL_TEXTURE_2D);
-#endif
#define PROGRAM_VERTEX_ATTRIBUTE 0
#define PROGRAM_TEXCOORD_ATTRIBUTE 1
- QGLShader *vshader = new QGLShader(QGLShader::Vertex, this);
+ QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
const char *vsrc =
"attribute highp vec4 vertex;\n"
"attribute mediump vec4 texCoord;\n"
@@ -109,7 +113,7 @@ void GLWidget::initializeGL()
"}\n";
vshader->compileSourceCode(vsrc);
- QGLShader *fshader = new QGLShader(QGLShader::Fragment, this);
+ QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
const char *fsrc =
"uniform sampler2D texture;\n"
"varying mediump vec4 texc;\n"
@@ -119,7 +123,7 @@ void GLWidget::initializeGL()
"}\n";
fshader->compileSourceCode(fsrc);
- program = new QGLShaderProgram(this);
+ program = new QOpenGLShaderProgram;
program->addShader(vshader);
program->addShader(fshader);
program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE);
@@ -132,7 +136,7 @@ void GLWidget::initializeGL()
void GLWidget::paintGL()
{
- qglClearColor(clearColor);
+ glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), clearColor.alphaF());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 m;
@@ -145,17 +149,14 @@ void GLWidget::paintGL()
program->setUniformValue("matrix", m);
program->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
program->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
- program->setAttributeArray
- (PROGRAM_VERTEX_ATTRIBUTE, vertices.constData());
- program->setAttributeArray
- (PROGRAM_TEXCOORD_ATTRIBUTE, texCoords.constData());
+ program->setAttributeBuffer(PROGRAM_VERTEX_ATTRIBUTE, GL_FLOAT, 0, 3, 5 * sizeof(GLfloat));
+ program->setAttributeBuffer(PROGRAM_TEXCOORD_ATTRIBUTE, GL_FLOAT, 3 * sizeof(GLfloat), 2, 5 * sizeof(GLfloat));
for (int i = 0; i < 6; ++i) {
- glBindTexture(GL_TEXTURE_2D, textures[i]);
+ textures[i]->bind();
glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
}
}
-
void GLWidget::resizeGL(int width, int height)
{
int side = qMin(width, height);
@@ -196,18 +197,23 @@ void GLWidget::makeObject()
{ { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
};
- for (int j=0; j < 6; ++j) {
- textures[j] = bindTexture
- (QPixmap(QString(":/images/side%1.png").arg(j + 1)), GL_TEXTURE_2D);
- }
+ for (int j = 0; j < 6; ++j)
+ textures[j] = new QOpenGLTexture(QImage(QString(":/images/side%1.png").arg(j + 1)).mirrored());
+ QVector<GLfloat> vertData;
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 4; ++j) {
- texCoords.append
- (QVector2D(j == 0 || j == 3, j == 0 || j == 1));
- vertices.append
- (QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
- 0.2 * coords[i][j][2]));
+ // vertex position
+ vertData.append(0.2 * coords[i][j][0]);
+ vertData.append(0.2 * coords[i][j][1]);
+ vertData.append(0.2 * coords[i][j][2]);
+ // texture coordinate
+ vertData.append(j == 0 || j == 3);
+ vertData.append(j == 0 || j == 1);
}
}
+
+ vbo.create();
+ vbo.bind();
+ vbo.allocate(vertData.constData(), vertData.count() * sizeof(GLfloat));
}
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
index b210b0fd8f..eb47266e64 100644
--- a/examples/opengl/textures/glwidget.h
+++ b/examples/opengl/textures/glwidget.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -41,22 +41,23 @@
#ifndef GLWIDGET_H
#define GLWIDGET_H
-#include <QtWidgets>
-#include <QGLWidget>
+#include <QOpenGLWidget>
#include <QOpenGLFunctions>
+#include <QOpenGLBuffer>
-QT_FORWARD_DECLARE_CLASS(QGLShaderProgram);
+QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram);
+QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)
-class GLWidget : public QGLWidget, protected QOpenGLFunctions
+class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
- explicit GLWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0);
+ explicit GLWidget(QWidget *parent = 0);
~GLWidget();
- QSize minimumSizeHint() const;
- QSize sizeHint() const;
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
void rotateBy(int xAngle, int yAngle, int zAngle);
void setClearColor(const QColor &color);
@@ -64,12 +65,12 @@ 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);
+ void initializeGL() Q_DECL_OVERRIDE;
+ void paintGL() Q_DECL_OVERRIDE;
+ void resizeGL(int width, int height) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
void makeObject();
@@ -79,10 +80,9 @@ private:
int xRot;
int yRot;
int zRot;
- GLuint textures[6];
- QVector<QVector3D> vertices;
- QVector<QVector2D> texCoords;
- QGLShaderProgram *program;
+ QOpenGLTexture *textures[6];
+ QOpenGLShaderProgram *program;
+ QOpenGLBuffer vbo;
};
#endif
diff --git a/examples/opengl/textures/main.cpp b/examples/opengl/textures/main.cpp
index 541c2a5fcc..30b0bfa607 100644
--- a/examples/opengl/textures/main.cpp
+++ b/examples/opengl/textures/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -39,6 +39,7 @@
****************************************************************************/
#include <QApplication>
+#include <QSurfaceFormat>
#include "window.h"
@@ -47,6 +48,11 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(textures);
QApplication app(argc, argv);
+
+ QSurfaceFormat format;
+ format.setDepthBufferSize(24);
+ QSurfaceFormat::setDefaultFormat(format);
+
Window window;
window.show();
return app.exec();
diff --git a/examples/opengl/textures/textures.pro b/examples/opengl/textures/textures.pro
index d83077cb6a..7a7d19bee6 100644
--- a/examples/opengl/textures/textures.pro
+++ b/examples/opengl/textures/textures.pro
@@ -3,8 +3,10 @@ HEADERS = glwidget.h \
SOURCES = glwidget.cpp \
main.cpp \
window.cpp
+
RESOURCES = textures.qrc
-QT += opengl widgets
+
+QT += widgets
# install
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
diff --git a/examples/opengl/textures/window.cpp b/examples/opengl/textures/window.cpp
index 6e3497c684..8876de5602 100644
--- a/examples/opengl/textures/window.cpp
+++ b/examples/opengl/textures/window.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -54,7 +54,7 @@ Window::Window()
/ (NumRows * NumColumns - 1),
255, 63);
- glWidgets[i][j] = new GLWidget(0, 0);
+ glWidgets[i][j] = new GLWidget;
glWidgets[i][j]->setClearColor(clearColor);
glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
mainLayout->addWidget(glWidgets[i][j], i, j);
diff --git a/examples/opengl/textures/window.h b/examples/opengl/textures/window.h
index 1dd2271ff5..0b53387024 100644
--- a/examples/opengl/textures/window.h
+++ b/examples/opengl/textures/window.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp
new file mode 100644
index 0000000000..d447f0c716
--- /dev/null
+++ b/examples/opengl/threadedqopenglwidget/glwidget.cpp
@@ -0,0 +1,364 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <math.h>
+#include <QGuiApplication>
+
+const int bubbleNum = 8;
+
+GLWidget::GLWidget(QWidget *parent)
+ : QOpenGLWidget(parent)
+{
+ setMinimumSize(300, 250);
+
+ connect(this, &QOpenGLWidget::aboutToCompose, this, &GLWidget::onAboutToCompose);
+ connect(this, &QOpenGLWidget::frameSwapped, this, &GLWidget::onFrameSwapped);
+ connect(this, &QOpenGLWidget::aboutToResize, this, &GLWidget::onAboutToResize);
+ connect(this, &QOpenGLWidget::resized, this, &GLWidget::onResized);
+
+ m_thread = new QThread;
+ m_renderer = new Renderer(this);
+ m_renderer->moveToThread(m_thread);
+ connect(m_thread, &QThread::finished, m_renderer, &QObject::deleteLater);
+
+ connect(this, &GLWidget::renderRequested, m_renderer, &Renderer::render);
+ connect(m_renderer, &Renderer::contextWanted, this, &GLWidget::grabContext);
+
+ m_thread->start();
+}
+
+GLWidget::~GLWidget()
+{
+ m_renderer->prepareExit();
+ m_thread->quit();
+ m_thread->wait();
+ delete m_thread;
+}
+
+void GLWidget::onAboutToCompose()
+{
+ // We are on the gui thread here. Composition is about to
+ // begin. Wait until the render thread finishes.
+ m_renderer->lockRenderer();
+}
+
+void GLWidget::onFrameSwapped()
+{
+ m_renderer->unlockRenderer();
+ // Assuming a blocking swap, our animation is driven purely by the
+ // vsync in this example.
+ emit renderRequested();
+}
+
+void GLWidget::onAboutToResize()
+{
+ m_renderer->lockRenderer();
+}
+
+void GLWidget::onResized()
+{
+ m_renderer->unlockRenderer();
+}
+
+void GLWidget::grabContext()
+{
+ m_renderer->lockRenderer();
+ QMutexLocker lock(m_renderer->grabMutex());
+ context()->moveToThread(m_thread);
+ m_renderer->grabCond()->wakeAll();
+ m_renderer->unlockRenderer();
+}
+
+Renderer::Renderer(GLWidget *w)
+ : m_inited(false),
+ m_glwidget(w),
+ m_exiting(false)
+{
+}
+
+void Renderer::paintQtLogo()
+{
+ vbo.bind();
+ program.setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
+ program.setAttributeBuffer(normalAttr, GL_FLOAT, vertices.count() * 3 * sizeof(GLfloat), 3);
+ vbo.release();
+
+ program.enableAttributeArray(vertexAttr);
+ program.enableAttributeArray(normalAttr);
+
+ glDrawArrays(GL_TRIANGLES, 0, vertices.size());
+
+ program.disableAttributeArray(normalAttr);
+ program.disableAttributeArray(vertexAttr);
+}
+
+// Some OpenGL implementations have serious issues with compiling and linking
+// shaders on multiple threads concurrently. Avoid this.
+Q_GLOBAL_STATIC(QMutex, initMutex)
+
+void Renderer::render()
+{
+ if (m_exiting)
+ return;
+
+ QOpenGLContext *ctx = m_glwidget->context();
+ if (!ctx) // QOpenGLWidget not yet initialized
+ return;
+
+ // Grab the context.
+ m_grabMutex.lock();
+ emit contextWanted();
+ m_grabCond.wait(&m_grabMutex);
+ QMutexLocker lock(&m_renderMutex);
+ m_grabMutex.unlock();
+
+ if (m_exiting)
+ return;
+
+ Q_ASSERT(ctx->thread() == QThread::currentThread());
+
+ // Make the context (and an offscreen surface) current for this thread. The
+ // QOpenGLWidget's fbo is bound in the context.
+ m_glwidget->makeCurrent();
+
+ if (!m_inited) {
+ m_inited = true;
+ initializeOpenGLFunctions();
+
+ QMutexLocker initLock(initMutex());
+ QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
+ const char *vsrc =
+ "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";
+ vshader->compileSourceCode(vsrc);
+
+ QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
+ const char *fsrc =
+ "varying mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+ fshader->compileSourceCode(fsrc);
+
+ program.addShader(vshader);
+ program.addShader(fshader);
+ program.link();
+
+ vertexAttr = program.attributeLocation("vertex");
+ normalAttr = program.attributeLocation("normal");
+ matrixUniform = program.uniformLocation("matrix");
+
+ m_fAngle = 0;
+ m_fScale = 1;
+ createGeometry();
+
+ vbo.create();
+ vbo.bind();
+ const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
+ vbo.allocate(verticesSize * 2);
+ vbo.write(0, vertices.constData(), verticesSize);
+ vbo.write(verticesSize, normals.constData(), verticesSize);
+
+ m_elapsed.start();
+ }
+
+ //qDebug("%p elapsed %lld", QThread::currentThread(), m_elapsed.restart());
+
+ glClearColor(0.1f, 0.2f, 0.2f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+
+ QMatrix4x4 modelview;
+ modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
+ modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
+ modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
+ modelview.scale(m_fScale);
+ modelview.translate(0.0f, -0.2f, 0.0f);
+
+ program.bind();
+ program.setUniformValue(matrixUniform, modelview);
+ paintQtLogo();
+ program.release();
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+
+ m_fAngle += 1.0f;
+
+ // Make no context current on this thread and move the QOpenGLWidget's
+ // context back to the gui thread.
+ m_glwidget->doneCurrent();
+ ctx->moveToThread(qGuiApp->thread());
+
+ // Schedule composition. Note that this will use QueuedConnection, meaning
+ // that update() will be invoked on the gui thread.
+ QMetaObject::invokeMethod(m_glwidget, "update");
+}
+
+void Renderer::createGeometry()
+{
+ vertices.clear();
+ normals.clear();
+
+ qreal x1 = +0.06f;
+ qreal y1 = -0.14f;
+ qreal x2 = +0.14f;
+ qreal y2 = -0.06f;
+ qreal x3 = +0.08f;
+ qreal y3 = +0.00f;
+ qreal x4 = +0.30f;
+ qreal y4 = +0.22f;
+
+ quad(x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(x3, y3, x4, y4, y4, x4, y3, x3);
+
+ extrude(x1, y1, x2, y2);
+ extrude(x2, y2, y2, x2);
+ extrude(y2, x2, y1, x1);
+ extrude(y1, x1, x1, y1);
+ extrude(x3, y3, x4, y4);
+ extrude(x4, y4, y4, x4);
+ extrude(y4, x4, y3, x3);
+
+ const qreal Pi = 3.14159f;
+ const int NumSectors = 100;
+
+ for (int i = 0; i < NumSectors; ++i) {
+ qreal angle1 = (i * 2 * Pi) / NumSectors;
+ qreal x5 = 0.30 * sin(angle1);
+ qreal y5 = 0.30 * cos(angle1);
+ qreal x6 = 0.20 * sin(angle1);
+ qreal y6 = 0.20 * cos(angle1);
+
+ qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors;
+ qreal x7 = 0.20 * sin(angle2);
+ qreal y7 = 0.20 * cos(angle2);
+ qreal x8 = 0.30 * sin(angle2);
+ qreal y8 = 0.30 * cos(angle2);
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+
+ for (int i = 0;i < vertices.size();i++)
+ vertices[i] *= 2.0f;
+}
+
+void Renderer::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
+{
+ vertices << QVector3D(x1, y1, -0.05f);
+ vertices << QVector3D(x2, y2, -0.05f);
+ vertices << QVector3D(x4, y4, -0.05f);
+
+ vertices << QVector3D(x3, y3, -0.05f);
+ vertices << QVector3D(x4, y4, -0.05f);
+ vertices << QVector3D(x2, y2, -0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ vertices << QVector3D(x4, y4, 0.05f);
+ vertices << QVector3D(x2, y2, 0.05f);
+ vertices << QVector3D(x1, y1, 0.05f);
+
+ vertices << QVector3D(x2, y2, 0.05f);
+ vertices << QVector3D(x4, y4, 0.05f);
+ vertices << QVector3D(x3, y3, 0.05f);
+
+ n = QVector3D::normal
+ (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ normals << n;
+ normals << n;
+ normals << n;
+}
+
+void Renderer::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
+{
+ vertices << QVector3D(x1, y1, +0.05f);
+ vertices << QVector3D(x2, y2, +0.05f);
+ vertices << QVector3D(x1, y1, -0.05f);
+
+ vertices << QVector3D(x2, y2, -0.05f);
+ vertices << QVector3D(x1, y1, -0.05f);
+ vertices << QVector3D(x2, y2, +0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ normals << n;
+ normals << n;
+ normals << n;
+}
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.h b/examples/opengl/threadedqopenglwidget/glwidget.h
new file mode 100644
index 0000000000..8319faf322
--- /dev/null
+++ b/examples/opengl/threadedqopenglwidget/glwidget.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions>
+#include <QOpenGLShaderProgram>
+#include <QOpenGLBuffer>
+#include <QVector3D>
+#include <QMatrix4x4>
+#include <QThread>
+#include <QMutex>
+#include <QWaitCondition>
+#include <QElapsedTimer>
+
+class GLWidget;
+
+class Renderer : public QObject, protected QOpenGLFunctions
+{
+ Q_OBJECT
+
+public:
+ Renderer(GLWidget *w);
+ void lockRenderer() { m_renderMutex.lock(); }
+ void unlockRenderer() { m_renderMutex.unlock(); }
+ QMutex *grabMutex() { return &m_grabMutex; }
+ QWaitCondition *grabCond() { return &m_grabCond; }
+ void prepareExit() { m_exiting = true; m_grabCond.wakeAll(); }
+
+signals:
+ void contextWanted();
+
+public slots:
+ void render();
+
+private:
+ void paintQtLogo();
+ void createGeometry();
+ 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);
+
+ bool m_inited;
+ qreal m_fAngle;
+ qreal m_fScale;
+ QVector<QVector3D> vertices;
+ QVector<QVector3D> normals;
+ QOpenGLShaderProgram program;
+ QOpenGLBuffer vbo;
+ int vertexAttr;
+ int normalAttr;
+ int matrixUniform;
+ GLWidget *m_glwidget;
+ QMutex m_renderMutex;
+ QElapsedTimer m_elapsed;
+ QMutex m_grabMutex;
+ QWaitCondition m_grabCond;
+ bool m_exiting;
+};
+
+class GLWidget : public QOpenGLWidget
+{
+ Q_OBJECT
+public:
+ GLWidget(QWidget *parent);
+ ~GLWidget();
+
+protected:
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE { }
+
+signals:
+ void renderRequested();
+
+public slots:
+ void grabContext();
+
+private slots:
+ void onAboutToCompose();
+ void onFrameSwapped();
+ void onAboutToResize();
+ void onResized();
+
+private:
+ QThread *m_thread;
+ Renderer *m_renderer;
+};
+
+#endif
diff --git a/examples/opengl/threadedqopenglwidget/main.cpp b/examples/opengl/threadedqopenglwidget/main.cpp
new file mode 100644
index 0000000000..75b7f5e46f
--- /dev/null
+++ b/examples/opengl/threadedqopenglwidget/main.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMainWindow>
+#include <QSurfaceFormat>
+#include "mainwindow.h"
+#include "glwidget.h"
+
+int main( int argc, char ** argv )
+{
+ QApplication a( argc, argv );
+
+ QSurfaceFormat format;
+ format.setDepthBufferSize(16);
+ QSurfaceFormat::setDefaultFormat(format);
+
+ // Two top-level windows with two QOpenGLWidget children in each.
+ // The rendering for the four QOpenGLWidgets happens on four separate threads.
+ MainWindow mw1;
+ mw1.setMinimumSize(800, 400);
+ mw1.show();
+
+ QScopedPointer<MainWindow> mw2;
+ if (!QApplication::arguments().contains(QStringLiteral("--single"))) {
+ mw2.reset(new MainWindow);
+ mw2->setMinimumSize(800, 400);
+ mw2->show();
+
+ // And a top-level.
+ GLWidget *bonus = new GLWidget(0);
+ bonus->resize(200, 200);
+ bonus->show();
+ }
+
+ return a.exec();
+}
diff --git a/examples/opengl/hellogl_es2/main.cpp b/examples/opengl/threadedqopenglwidget/mainwindow.cpp
index 5fb3385989..29c59573cf 100644
--- a/examples/opengl/hellogl_es2/main.cpp
+++ b/examples/opengl/threadedqopenglwidget/mainwindow.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -38,15 +38,15 @@
**
****************************************************************************/
-#include <QApplication>
-#include <QMainWindow>
#include "mainwindow.h"
+#include "glwidget.h"
-int main( int argc, char ** argv )
+MainWindow::MainWindow()
{
- Q_INIT_RESOURCE(texture);
- QApplication a( argc, argv );
- MainWindow mw;
- mw.showMaximized();
- return a.exec();
+ GLWidget *glwidget1 = new GLWidget(this);
+ glwidget1->resize(400, 400);
+
+ GLWidget *glwidget2 = new GLWidget(this);
+ glwidget2->resize(400, 400);
+ glwidget2->move(400, 0);
}
diff --git a/examples/opengl/threadedqopenglwidget/mainwindow.h b/examples/opengl/threadedqopenglwidget/mainwindow.h
new file mode 100644
index 0000000000..91f7580717
--- /dev/null
+++ b/examples/opengl/threadedqopenglwidget/mainwindow.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QWidget>
+
+class MainWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+};
+
+#endif
diff --git a/examples/opengl/threadedqopenglwidget/threadedqopenglwidget.pro b/examples/opengl/threadedqopenglwidget/threadedqopenglwidget.pro
new file mode 100644
index 0000000000..4e941b28c4
--- /dev/null
+++ b/examples/opengl/threadedqopenglwidget/threadedqopenglwidget.pro
@@ -0,0 +1,11 @@
+QT += widgets
+
+SOURCES += main.cpp \
+ glwidget.cpp \
+ mainwindow.cpp
+
+HEADERS += glwidget.h \
+ mainwindow.h
+
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/threadedqopenglwidget
+INSTALLS += target
diff --git a/examples/qpa/qpa.pro b/examples/qpa/qpa.pro
index 27293482ef..85b51dc5f4 100644
--- a/examples/qpa/qpa.pro
+++ b/examples/qpa/qpa.pro
@@ -1,4 +1,5 @@
requires(qtHaveModule(gui))
TEMPLATE = subdirs
-SUBDIRS = windows
+SUBDIRS = windows \
+ qrasterwindow
diff --git a/examples/qpa/qrasterwindow/main.cpp b/examples/qpa/qrasterwindow/main.cpp
new file mode 100644
index 0000000000..0e87d41682
--- /dev/null
+++ b/examples/qpa/qrasterwindow/main.cpp
@@ -0,0 +1,127 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ ** Contact: http://www.qt-project.org/legal
+ **
+ ** This file is part of the examples of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:BSD$
+ ** You may use this file under the terms of the BSD license as follows:
+ **
+ ** "Redistribution and use in source and binary forms, with or without
+ ** modification, are permitted provided that the following conditions are
+ ** met:
+ ** * Redistributions of source code must retain the above copyright
+ ** notice, this list of conditions and the following disclaimer.
+ ** * Redistributions in binary form must reproduce the above copyright
+ ** notice, this list of conditions and the following disclaimer in
+ ** the documentation and/or other materials provided with the
+ ** distribution.
+ ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+ ** of its contributors may be used to endorse or promote products derived
+ ** from this software without specific prior written permission.
+ **
+ **
+ ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#include <QRasterWindow>
+#include <QPainter>
+#include <QGuiApplication>
+#include <QMatrix4x4>
+#include <QTimer>
+
+static QPainterPath painterPathForTriangle()
+{
+ static const QPointF bottomLeft(-1.0, -1.0);
+ static const QPointF top(0.0, 1.0);
+ static const QPointF bottomRight(1.0, -1.0);
+
+ QPainterPath path(bottomLeft);
+ path.lineTo(top);
+ path.lineTo(bottomRight);
+ path.closeSubpath();
+ return path;
+}
+
+class PaintedWindow : public QRasterWindow
+{
+ Q_OBJECT
+
+public:
+ PaintedWindow()
+ {
+ m_view.lookAt(QVector3D(3,1,1),
+ QVector3D(0,0,0),
+ QVector3D(0,1,0));
+ m_timer.setInterval(16);
+ connect(&m_timer, SIGNAL(timeout()), this, SLOT(update()));
+ m_timer.start();
+ }
+
+protected:
+ void paintEvent(QPaintEvent *)
+ {
+ QPainter p(this);
+ p.fillRect(QRect(0,0,width(),height()),Qt::gray);
+
+ p.setWorldTransform(m_window_matrix.toTransform());
+
+ QMatrix4x4 mvp = m_projection * m_view * m_model;
+ p.setTransform(mvp.toTransform(), true);
+
+ p.fillPath(painterPathForTriangle(), m_brush);
+
+ m_model.rotate(1, 0, 1, 0);
+ }
+
+ void resizeEvent(QResizeEvent *)
+ {
+ m_window_matrix = QTransform();
+ m_window_matrix.translate(width() / 2.0, height() / 2.0);
+ m_window_matrix.scale(width() / 2.0, -height() / 2.0);
+
+ m_projection.setToIdentity();
+ m_projection.perspective(45.f, qreal(width()) / qreal(height()), 0.1f, 100.f);
+
+ QLinearGradient gradient(QPointF(-1,-1), QPointF(1,1));
+ gradient.setColorAt(0, Qt::red);
+ gradient.setColorAt(1, Qt::green);
+
+ m_brush = QBrush(gradient);
+ }
+
+private:
+ QMatrix4x4 m_window_matrix;
+ QMatrix4x4 m_projection;
+ QMatrix4x4 m_view;
+ QMatrix4x4 m_model;
+ QBrush m_brush;
+ QTimer m_timer;
+};
+
+int main (int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ PaintedWindow window;
+ window.create();
+ window.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/qpa/qrasterwindow/qrasterwindow.pro b/examples/qpa/qrasterwindow/qrasterwindow.pro
new file mode 100644
index 0000000000..e5bf34f25c
--- /dev/null
+++ b/examples/qpa/qrasterwindow/qrasterwindow.pro
@@ -0,0 +1,4 @@
+SOURCES += main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/qpa/qrasterwindow
+INSTALLS += target
diff --git a/examples/qpa/windows/window.h b/examples/qpa/windows/window.h
index 88cf6db431..f9abfc0821 100644
--- a/examples/qpa/windows/window.h
+++ b/examples/qpa/windows/window.h
@@ -48,16 +48,16 @@ public:
Window(QScreen *screen);
protected:
- void mousePressEvent(QMouseEvent *);
- void mouseMoveEvent(QMouseEvent *);
- void mouseReleaseEvent(QMouseEvent *);
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
- void keyPressEvent(QKeyEvent *);
+ void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
- void exposeEvent(QExposeEvent *);
- void resizeEvent(QResizeEvent *);
+ void exposeEvent(QExposeEvent *) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
- void timerEvent(QTimerEvent *);
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
private:
void render();
diff --git a/examples/qtconcurrent/map/main.cpp b/examples/qtconcurrent/map/main.cpp
index 01595f0c2e..cec07dad66 100644
--- a/examples/qtconcurrent/map/main.cpp
+++ b/examples/qtconcurrent/map/main.cpp
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
// Use QtConcurrentBlocking::mapped to apply the scale function to all the
// images in the list.
- QList<QImage> thumbnails = QtConcurrent::blockingMapped(images, scale);
+ QList<QImage> thumbnails = QtConcurrent::blockingMapped<QList<QImage> >(images, scale);
return 0;
}
diff --git a/examples/sql/books/bookdelegate.h b/examples/sql/books/bookdelegate.h
index 732e418ca4..b1de0546cb 100644
--- a/examples/sql/books/bookdelegate.h
+++ b/examples/sql/books/bookdelegate.h
@@ -55,16 +55,16 @@ public:
BookDelegate(QObject *parent);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
- QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
+ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option,
- const QModelIndex &index);
+ const QModelIndex &index) Q_DECL_OVERRIDE;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
private:
QPixmap star;
diff --git a/examples/sql/drilldown/imageitem.h b/examples/sql/drilldown/imageitem.h
index 59f468e3a6..3935c157a7 100644
--- a/examples/sql/drilldown/imageitem.h
+++ b/examples/sql/drilldown/imageitem.h
@@ -56,8 +56,8 @@ public:
int id();
protected:
- void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
private slots:
void setFrame(int frame);
diff --git a/examples/sql/drilldown/view.h b/examples/sql/drilldown/view.h
index c9fc040bb1..b7fb72fe74 100644
--- a/examples/sql/drilldown/view.h
+++ b/examples/sql/drilldown/view.h
@@ -56,7 +56,7 @@ public:
View(const QString &items, const QString &images, QWidget *parent = 0);
protected:
- void mouseReleaseEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
//! [0]
//! [1]
diff --git a/examples/sql/querymodel/customsqlmodel.h b/examples/sql/querymodel/customsqlmodel.h
index 63ab38f57f..ec673305a8 100644
--- a/examples/sql/querymodel/customsqlmodel.h
+++ b/examples/sql/querymodel/customsqlmodel.h
@@ -51,7 +51,7 @@ class CustomSqlModel : public QSqlQueryModel
public:
CustomSqlModel(QObject *parent = 0);
- QVariant data(const QModelIndex &item, int role) const;
+ QVariant data(const QModelIndex &item, int role) const Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/sql/querymodel/editablesqlmodel.h b/examples/sql/querymodel/editablesqlmodel.h
index 53bb7ac908..a1f3f1a302 100644
--- a/examples/sql/querymodel/editablesqlmodel.h
+++ b/examples/sql/querymodel/editablesqlmodel.h
@@ -50,8 +50,8 @@ class EditableSqlModel : public QSqlQueryModel
public:
EditableSqlModel(QObject *parent = 0);
- Qt::ItemFlags flags(const QModelIndex &index) const;
- bool setData(const QModelIndex &index, const QVariant &value, int role);
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex &index, const QVariant &value, int role) Q_DECL_OVERRIDE;
private:
bool setFirstName(int personId, const QString &firstName);
diff --git a/examples/sql/sqlbrowser/browser.h b/examples/sql/sqlbrowser/browser.h
index db57404ec3..1819b90ce7 100644
--- a/examples/sql/sqlbrowser/browser.h
+++ b/examples/sql/sqlbrowser/browser.h
@@ -108,7 +108,7 @@ class CustomModel: public QSqlTableModel
Q_OBJECT
public:
explicit CustomModel(QObject *parent = 0, QSqlDatabase db = QSqlDatabase()):QSqlTableModel(parent, db) {}
- QVariant data(const QModelIndex &idx, int role) const
+ QVariant data(const QModelIndex &idx, int role) const Q_DECL_OVERRIDE
{
if (role == Qt::BackgroundRole && isDirty(idx))
return QBrush(QColor(Qt::yellow));
diff --git a/examples/threads/mandelbrot/mandelbrotwidget.h b/examples/threads/mandelbrot/mandelbrotwidget.h
index 0867270305..183edf2e26 100644
--- a/examples/threads/mandelbrot/mandelbrotwidget.h
+++ b/examples/threads/mandelbrot/mandelbrotwidget.h
@@ -55,15 +55,15 @@ public:
MandelbrotWidget(QWidget *parent = 0);
protected:
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *event);
- void keyPressEvent(QKeyEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
#ifndef QT_NO_WHEELEVENT
- void wheelEvent(QWheelEvent *event);
+ void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
#endif
- void mousePressEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private slots:
void updatePixmap(const QImage &image, double scaleFactor);
diff --git a/examples/threads/mandelbrot/renderthread.h b/examples/threads/mandelbrot/renderthread.h
index 9c1ab1828d..881870665f 100644
--- a/examples/threads/mandelbrot/renderthread.h
+++ b/examples/threads/mandelbrot/renderthread.h
@@ -65,7 +65,7 @@ signals:
void renderedImage(const QImage &image, double scaleFactor);
protected:
- void run();
+ void run() Q_DECL_OVERRIDE;
private:
uint rgbFromWaveLength(double wave);
diff --git a/examples/threads/semaphores/semaphores.cpp b/examples/threads/semaphores/semaphores.cpp
index fb7f1f2376..f519e5f323 100644
--- a/examples/threads/semaphores/semaphores.cpp
+++ b/examples/threads/semaphores/semaphores.cpp
@@ -58,7 +58,7 @@ class Producer : public QThread
//! [1] //! [2]
{
public:
- void run()
+ void run() Q_DECL_OVERRIDE
{
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
for (int i = 0; i < DataSize; ++i) {
@@ -76,7 +76,7 @@ class Consumer : public QThread
{
Q_OBJECT
public:
- void run()
+ void run() Q_DECL_OVERRIDE
{
for (int i = 0; i < DataSize; ++i) {
usedBytes.acquire();
diff --git a/examples/threads/waitconditions/waitconditions.cpp b/examples/threads/waitconditions/waitconditions.cpp
index 6f5f56e737..b0336f4c2b 100644
--- a/examples/threads/waitconditions/waitconditions.cpp
+++ b/examples/threads/waitconditions/waitconditions.cpp
@@ -64,7 +64,7 @@ public:
{
}
- void run()
+ void run() Q_DECL_OVERRIDE
{
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
@@ -95,7 +95,7 @@ public:
{
}
- void run()
+ void run() Q_DECL_OVERRIDE
{
for (int i = 0; i < DataSize; ++i) {
mutex.lock();
diff --git a/examples/tools/contiguouscache/randomlistmodel.h b/examples/tools/contiguouscache/randomlistmodel.h
index 490cabddd7..3acafc23ff 100644
--- a/examples/tools/contiguouscache/randomlistmodel.h
+++ b/examples/tools/contiguouscache/randomlistmodel.h
@@ -52,8 +52,8 @@ public:
RandomListModel(QObject *parent = 0);
~RandomListModel();
- int rowCount(const QModelIndex & = QModelIndex()) const;
- QVariant data(const QModelIndex &, int) const;
+ int rowCount(const QModelIndex & = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &, int) const Q_DECL_OVERRIDE;
private:
void cacheRows(int, int) const;
diff --git a/examples/touch/fingerpaint/mainwindow.h b/examples/touch/fingerpaint/mainwindow.h
index 4d97f7e13f..997ea064f2 100644
--- a/examples/touch/fingerpaint/mainwindow.h
+++ b/examples/touch/fingerpaint/mainwindow.h
@@ -55,7 +55,7 @@ public:
MainWindow();
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void open();
diff --git a/examples/touch/fingerpaint/scribblearea.h b/examples/touch/fingerpaint/scribblearea.h
index e6c8e8d155..2019bfc58f 100644
--- a/examples/touch/fingerpaint/scribblearea.h
+++ b/examples/touch/fingerpaint/scribblearea.h
@@ -64,9 +64,9 @@ public slots:
void print();
protected:
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *event);
- bool event(QEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
private:
void resizeImage(QImage *image, const QSize &newSize);
diff --git a/examples/touch/knobs/knob.h b/examples/touch/knobs/knob.h
index 645e2174a8..a3315a9b1d 100644
--- a/examples/touch/knobs/knob.h
+++ b/examples/touch/knobs/knob.h
@@ -48,7 +48,7 @@ class Knob : public QGraphicsEllipseItem
public:
Knob();
- bool sceneEvent(QEvent *event);
+ bool sceneEvent(QEvent *event) Q_DECL_OVERRIDE;
};
#endif // KNOB_H
diff --git a/examples/touch/pinchzoom/graphicsview.h b/examples/touch/pinchzoom/graphicsview.h
index 5553f4b6d6..63728acaf6 100644
--- a/examples/touch/pinchzoom/graphicsview.h
+++ b/examples/touch/pinchzoom/graphicsview.h
@@ -48,7 +48,7 @@ class GraphicsView : public QGraphicsView
public:
GraphicsView(QGraphicsScene *scene = 0, QWidget *parent = 0);
- bool viewportEvent(QEvent *event);
+ bool viewportEvent(QEvent *event) Q_DECL_OVERRIDE;
private:
qreal totalScaleFactor;
diff --git a/examples/touch/pinchzoom/mouse.h b/examples/touch/pinchzoom/mouse.h
index 22b571b692..9a705e5062 100644
--- a/examples/touch/pinchzoom/mouse.h
+++ b/examples/touch/pinchzoom/mouse.h
@@ -51,13 +51,13 @@ class Mouse : public QGraphicsObject
public:
Mouse();
- QRectF boundingRect() const;
- QPainterPath shape() const;
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ QPainterPath shape() const Q_DECL_OVERRIDE;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget);
+ QWidget *widget) Q_DECL_OVERRIDE;
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
private:
qreal angle;
diff --git a/examples/widgets/animation/animatedtiles/main.cpp b/examples/widgets/animation/animatedtiles/main.cpp
index 6eab018929..09e9790646 100644
--- a/examples/widgets/animation/animatedtiles/main.cpp
+++ b/examples/widgets/animation/animatedtiles/main.cpp
@@ -64,19 +64,19 @@ public:
setCacheMode(DeviceCoordinateCache);
}
- QRectF boundingRect() const
+ QRectF boundingRect() const Q_DECL_OVERRIDE
{
return QRectF(-65, -65, 130, 130);
}
- QPainterPath shape() const
+ QPainterPath shape() const Q_DECL_OVERRIDE
{
QPainterPath path;
path.addEllipse(boundingRect());
return path;
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) Q_DECL_OVERRIDE
{
bool down = option->state & QStyle::State_Sunken;
QRectF r = boundingRect();
@@ -101,13 +101,13 @@ signals:
void pressed();
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *)
+ void mousePressEvent(QGraphicsSceneMouseEvent *) Q_DECL_OVERRIDE
{
emit pressed();
update();
}
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *) Q_DECL_OVERRIDE
{
update();
}
@@ -122,7 +122,7 @@ public:
View(QGraphicsScene *scene) : QGraphicsView(scene) { }
protected:
- void resizeEvent(QResizeEvent *event)
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
{
QGraphicsView::resizeEvent(event);
fitInView(sceneRect(), Qt::KeepAspectRatio);
diff --git a/examples/widgets/animation/appchooser/main.cpp b/examples/widgets/animation/appchooser/main.cpp
index a65e998b32..652e458411 100644
--- a/examples/widgets/animation/appchooser/main.cpp
+++ b/examples/widgets/animation/appchooser/main.cpp
@@ -52,17 +52,17 @@ public:
{
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE
{
painter->drawPixmap(QPointF(), p);
}
- virtual void mousePressEvent(QGraphicsSceneMouseEvent * )
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent * ) Q_DECL_OVERRIDE
{
emit clicked();
}
- virtual void setGeometry(const QRectF &rect)
+ virtual void setGeometry(const QRectF &rect) Q_DECL_OVERRIDE
{
QGraphicsWidget::setGeometry(rect);
@@ -88,7 +88,7 @@ public:
{
}
- virtual void resizeEvent(QResizeEvent *)
+ virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE
{
fitInView(sceneRect(), Qt::KeepAspectRatio);
}
diff --git a/examples/widgets/animation/easing/animation.h b/examples/widgets/animation/easing/animation.h
index d12a219abd..296f4c9da1 100644
--- a/examples/widgets/animation/easing/animation.h
+++ b/examples/widgets/animation/easing/animation.h
@@ -67,7 +67,7 @@ public:
m_path = QPainterPath();
}
- void updateCurrentTime(int currentTime)
+ void updateCurrentTime(int currentTime) Q_DECL_OVERRIDE
{
if (m_pathType == CirclePath) {
if (m_path.isEmpty()) {
diff --git a/examples/widgets/animation/moveblocks/main.cpp b/examples/widgets/animation/moveblocks/main.cpp
index 6d08381a53..57f13ceebe 100644
--- a/examples/widgets/animation/moveblocks/main.cpp
+++ b/examples/widgets/animation/moveblocks/main.cpp
@@ -70,7 +70,7 @@ class QGraphicsRectWidget : public QGraphicsWidget
{
public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *,
- QWidget *)
+ QWidget *) Q_DECL_OVERRIDE
{
painter->fillRect(rect(), Qt::blue);
}
@@ -88,14 +88,14 @@ public:
protected:
//![14]
- virtual bool eventTest(QEvent *event)
+ virtual bool eventTest(QEvent *event) Q_DECL_OVERRIDE
{
return (event->type() == QEvent::Type(StateSwitchEvent::StateSwitchType))
&& (static_cast<StateSwitchEvent *>(event)->rand() == m_rand);
}
//![14]
- virtual void onTransition(QEvent *) {}
+ virtual void onTransition(QEvent *) Q_DECL_OVERRIDE {}
private:
int m_rand;
@@ -112,7 +112,7 @@ public:
//![10]
//![11]
- virtual void onEntry(QEvent *)
+ virtual void onEntry(QEvent *) Q_DECL_OVERRIDE
{
int n;
while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex)
@@ -120,7 +120,7 @@ public:
m_lastIndex = n;
machine()->postEvent(new StateSwitchEvent(n));
}
- virtual void onExit(QEvent *) {}
+ virtual void onExit(QEvent *) Q_DECL_OVERRIDE {}
//![11]
//![12]
@@ -164,7 +164,7 @@ public:
}
protected:
- virtual void resizeEvent(QResizeEvent *event)
+ virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
{
fitInView(scene()->sceneRect());
QGraphicsView::resizeEvent(event);
diff --git a/examples/widgets/animation/states/main.cpp b/examples/widgets/animation/states/main.cpp
index fc633bd972..8bc8535ece 100644
--- a/examples/widgets/animation/states/main.cpp
+++ b/examples/widgets/animation/states/main.cpp
@@ -48,12 +48,12 @@ public:
{
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE
{
painter->drawPixmap(QPointF(), p);
}
- QRectF boundingRect() const
+ QRectF boundingRect() const Q_DECL_OVERRIDE
{
return QRectF( QPointF(0, 0), p.size());
}
@@ -69,7 +69,7 @@ public:
{
}
- virtual void resizeEvent(QResizeEvent *)
+ virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE
{
fitInView(sceneRect(), Qt::KeepAspectRatio);
}
diff --git a/examples/widgets/animation/stickman/graphicsview.h b/examples/widgets/animation/stickman/graphicsview.h
index 60abb6448f..cdccbbfbd3 100644
--- a/examples/widgets/animation/stickman/graphicsview.h
+++ b/examples/widgets/animation/stickman/graphicsview.h
@@ -51,8 +51,8 @@ public:
GraphicsView(QWidget *parent = 0);
protected:
- virtual void resizeEvent(QResizeEvent *event);
- void keyPressEvent(QKeyEvent *);
+ virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
signals:
void keyPressed(int key);
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp
index 09ca45e55b..7b089b5459 100644
--- a/examples/widgets/animation/stickman/lifecycle.cpp
+++ b/examples/widgets/animation/stickman/lifecycle.cpp
@@ -60,7 +60,7 @@ public:
setTargetState(target);
}
- virtual bool eventTest(QEvent *e)
+ virtual bool eventTest(QEvent *e) Q_DECL_OVERRIDE
{
if (QSignalTransition::eventTest(e)) {
QVariant key = static_cast<QStateMachine::SignalEvent*>(e)->arguments().at(0);
@@ -85,7 +85,7 @@ public:
startTimer(1000);
}
- virtual bool eventTest(QEvent *e)
+ virtual bool eventTest(QEvent *e) Q_DECL_OVERRIDE
{
return QEventTransition::eventTest(e) && ((qrand() % 50) == 0);
}
diff --git a/examples/widgets/animation/stickman/node.h b/examples/widgets/animation/stickman/node.h
index 9c7cc8d75a..6da83d5474 100644
--- a/examples/widgets/animation/stickman/node.h
+++ b/examples/widgets/animation/stickman/node.h
@@ -50,18 +50,18 @@ public:
explicit Node(const QPointF &pos, QGraphicsItem *parent = 0);
~Node();
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
signals:
void positionChanged();
protected:
- QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
- void mousePressEvent(QGraphicsSceneMouseEvent *);
- void mouseMoveEvent(QGraphicsSceneMouseEvent *);
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
+ void mousePressEvent(QGraphicsSceneMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *) Q_DECL_OVERRIDE;
private:
bool m_dragging;
diff --git a/examples/widgets/animation/stickman/rectbutton.h b/examples/widgets/animation/stickman/rectbutton.h
index 16c70fddd4..1cc9be2f97 100644
--- a/examples/widgets/animation/stickman/rectbutton.h
+++ b/examples/widgets/animation/stickman/rectbutton.h
@@ -50,13 +50,13 @@ public:
RectButton(QString buttonText);
~RectButton();
- virtual QRectF boundingRect() const;
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
protected:
QString m_ButtonText;
- virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
+ virtual void mousePressEvent (QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
signals:
void clicked();
diff --git a/examples/widgets/animation/stickman/stickman.h b/examples/widgets/animation/stickman/stickman.h
index 08928a48a6..d8538efc52 100644
--- a/examples/widgets/animation/stickman/stickman.h
+++ b/examples/widgets/animation/stickman/stickman.h
@@ -59,8 +59,8 @@ public:
StickMan();
~StickMan();
- virtual QRectF boundingRect() const;
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
int nodeCount() const;
Node *node(int idx) const;
@@ -82,7 +82,7 @@ public slots:
void childPositionChanged();
protected:
- void timerEvent(QTimerEvent *e);
+ void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE;
private:
diff --git a/examples/widgets/animation/sub-attaq/boat.h b/examples/widgets/animation/sub-attaq/boat.h
index 82f43572e8..561ba49d27 100644
--- a/examples/widgets/animation/sub-attaq/boat.h
+++ b/examples/widgets/animation/sub-attaq/boat.h
@@ -77,7 +77,7 @@ public:
void updateBoatMovement();
- virtual int type() const;
+ virtual int type() const Q_DECL_OVERRIDE;
signals:
void boatDestroyed();
diff --git a/examples/widgets/animation/sub-attaq/boat_p.h b/examples/widgets/animation/sub-attaq/boat_p.h
index fc3ba81d63..19c5dad9ba 100644
--- a/examples/widgets/animation/sub-attaq/boat_p.h
+++ b/examples/widgets/animation/sub-attaq/boat_p.h
@@ -72,7 +72,7 @@ public:
{
}
protected:
- virtual bool eventTest(QEvent *event)
+ virtual bool eventTest(QEvent *event) Q_DECL_OVERRIDE
{
if (!QKeyEventTransition::eventTest(event))
return false;
@@ -91,13 +91,13 @@ public:
{
}
protected:
- virtual bool eventTest(QEvent *event)
+ virtual bool eventTest(QEvent *event) Q_DECL_OVERRIDE
{
if (!QKeyEventTransition::eventTest(event))
return false;
return (boat->currentSpeed() >= 0);
}
- void onTransition(QEvent *)
+ void onTransition(QEvent *) Q_DECL_OVERRIDE
{
//We decrease the speed if needed
if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right)
@@ -122,7 +122,7 @@ public:
{
}
protected:
- virtual bool eventTest(QEvent *event)
+ virtual bool eventTest(QEvent *event) Q_DECL_OVERRIDE
{
if (!QKeyEventTransition::eventTest(event))
return false;
@@ -141,7 +141,7 @@ public:
{
}
protected:
- void onEntry(QEvent *)
+ void onEntry(QEvent *) Q_DECL_OVERRIDE
{
boat->setCurrentDirection(Boat::Right);
boat->updateBoatMovement();
@@ -158,7 +158,7 @@ public:
{
}
protected:
- void onEntry(QEvent *)
+ void onEntry(QEvent *) Q_DECL_OVERRIDE
{
boat->setCurrentDirection(Boat::Left);
boat->updateBoatMovement();
@@ -175,7 +175,7 @@ public:
{
}
protected:
- void onEntry(QEvent *)
+ void onEntry(QEvent *) Q_DECL_OVERRIDE
{
boat->setCurrentSpeed(0);
boat->setCurrentDirection(Boat::None);
@@ -193,7 +193,7 @@ public:
{
}
protected:
- void onEntry(QEvent *)
+ void onEntry(QEvent *) Q_DECL_OVERRIDE
{
Bomb *b = new Bomb();
b->setPos(boat->x()+boat->size().width(),boat->y());
@@ -214,7 +214,7 @@ public:
{
}
protected:
- void onEntry(QEvent *)
+ void onEntry(QEvent *) Q_DECL_OVERRIDE
{
Bomb *b = new Bomb();
b->setPos(boat->x() - b->size().width(), boat->y());
diff --git a/examples/widgets/animation/sub-attaq/pixmapitem.h b/examples/widgets/animation/sub-attaq/pixmapitem.h
index e093fbd5b5..baca0c1cba 100644
--- a/examples/widgets/animation/sub-attaq/pixmapitem.h
+++ b/examples/widgets/animation/sub-attaq/pixmapitem.h
@@ -54,8 +54,8 @@ public:
PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem * parent = 0);
PixmapItem(const QString &fileName, QGraphicsScene *scene);
QSizeF size() const;
- QRectF boundingRect() const;
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE;
private:
QPixmap pix;
};
diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.h b/examples/widgets/animation/sub-attaq/qanimationstate.h
index 68eac43e13..c2b7e12211 100644
--- a/examples/widgets/animation/sub-attaq/qanimationstate.h
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.h
@@ -71,9 +71,9 @@ signals:
void animationFinished();
protected:
- void onEntry(QEvent *);
- void onExit(QEvent *);
- bool event(QEvent *e);
+ void onEntry(QEvent *) Q_DECL_OVERRIDE;
+ void onExit(QEvent *) Q_DECL_OVERRIDE;
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QAnimationState)
diff --git a/examples/widgets/animation/sub-attaq/states.h b/examples/widgets/animation/sub-attaq/states.h
index 3cd27be9a4..19016cb76e 100644
--- a/examples/widgets/animation/sub-attaq/states.h
+++ b/examples/widgets/animation/sub-attaq/states.h
@@ -63,7 +63,7 @@ public:
~PlayState();
protected:
- void onEntry(QEvent *);
+ void onEntry(QEvent *) Q_DECL_OVERRIDE;
private :
GraphicsScene *scene;
@@ -85,7 +85,7 @@ class LevelState : public QState
public:
LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
protected:
- void onEntry(QEvent *);
+ void onEntry(QEvent *) Q_DECL_OVERRIDE;
private :
void initializeLevel();
GraphicsScene *scene;
@@ -98,8 +98,8 @@ public:
explicit PauseState(GraphicsScene *scene, QState *parent = 0);
protected:
- void onEntry(QEvent *);
- void onExit(QEvent *);
+ void onEntry(QEvent *) Q_DECL_OVERRIDE;
+ void onExit(QEvent *) Q_DECL_OVERRIDE;
private :
GraphicsScene *scene;
};
@@ -110,8 +110,8 @@ public:
LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
protected:
- void onEntry(QEvent *);
- void onExit(QEvent *);
+ void onEntry(QEvent *) Q_DECL_OVERRIDE;
+ void onExit(QEvent *) Q_DECL_OVERRIDE;
private :
GraphicsScene *scene;
PlayState *game;
@@ -123,8 +123,8 @@ public:
WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
protected:
- void onEntry(QEvent *);
- void onExit(QEvent *);
+ void onEntry(QEvent *) Q_DECL_OVERRIDE;
+ void onExit(QEvent *) Q_DECL_OVERRIDE;
private :
GraphicsScene *scene;
PlayState *game;
@@ -143,7 +143,7 @@ class UpdateScoreTransition : public QSignalTransition
public:
UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target);
protected:
- virtual bool eventTest(QEvent *event);
+ virtual bool eventTest(QEvent *event) Q_DECL_OVERRIDE;
private:
PlayState * game;
GraphicsScene *scene;
@@ -155,7 +155,7 @@ class WinTransition : public QSignalTransition
public:
WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target);
protected:
- virtual bool eventTest(QEvent *event);
+ virtual bool eventTest(QEvent *event) Q_DECL_OVERRIDE;
private:
PlayState * game;
GraphicsScene *scene;
@@ -167,7 +167,7 @@ private:
public:
CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key);
protected:
- virtual bool eventTest(QEvent *event);
+ virtual bool eventTest(QEvent *event) Q_DECL_OVERRIDE;
private:
PlayState *game;
};
diff --git a/examples/widgets/animation/sub-attaq/submarine.h b/examples/widgets/animation/sub-attaq/submarine.h
index 802bf6f81c..b087d0178d 100644
--- a/examples/widgets/animation/sub-attaq/submarine.h
+++ b/examples/widgets/animation/sub-attaq/submarine.h
@@ -72,7 +72,7 @@ public:
void launchTorpedo(int speed);
void destroy();
- virtual int type() const;
+ virtual int type() const Q_DECL_OVERRIDE;
QGraphicsRotation *rotation() const { return graphicsRotation; }
diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h
index e1755505df..f117be7b8c 100644
--- a/examples/widgets/animation/sub-attaq/submarine_p.h
+++ b/examples/widgets/animation/sub-attaq/submarine_p.h
@@ -84,7 +84,7 @@ protected slots:
}
protected:
- void onEntry(QEvent *e)
+ void onEntry(QEvent *e) Q_DECL_OVERRIDE
{
if (submarine->currentDirection() == SubMarine::Left) {
movementAnimation->setEndValue(QPointF(0,submarine->y()));
@@ -116,14 +116,14 @@ public:
}
protected:
- void onEntry(QEvent *e)
+ void onEntry(QEvent *e) Q_DECL_OVERRIDE
{
returnAnimation->stop();
returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.);
QAnimationState::onEntry(e);
}
- void onExit(QEvent *e)
+ void onExit(QEvent *e) Q_DECL_OVERRIDE
{
submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right);
QAnimationState::onExit(e);
diff --git a/examples/widgets/desktop/screenshot/screenshot.h b/examples/widgets/desktop/screenshot/screenshot.h
index 2331feeaec..6ad4281335 100644
--- a/examples/widgets/desktop/screenshot/screenshot.h
+++ b/examples/widgets/desktop/screenshot/screenshot.h
@@ -64,7 +64,7 @@ public:
Screenshot();
protected:
- void resizeEvent(QResizeEvent *event);
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private slots:
void newScreenshot();
diff --git a/examples/widgets/desktop/systray/window.h b/examples/widgets/desktop/systray/window.h
index c93228754b..24d0d3ae18 100644
--- a/examples/widgets/desktop/systray/window.h
+++ b/examples/widgets/desktop/systray/window.h
@@ -68,10 +68,10 @@ class Window : public QDialog
public:
Window();
- void setVisible(bool visible);
+ void setVisible(bool visible) Q_DECL_OVERRIDE;
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void setIcon(int index);
diff --git a/examples/widgets/dialogs/classwizard/classwizard.h b/examples/widgets/dialogs/classwizard/classwizard.h
index 34a35a2ce9..a709fd3405 100644
--- a/examples/widgets/dialogs/classwizard/classwizard.h
+++ b/examples/widgets/dialogs/classwizard/classwizard.h
@@ -59,7 +59,7 @@ class ClassWizard : public QWizard
public:
ClassWizard(QWidget *parent = 0);
- void accept();
+ void accept() Q_DECL_OVERRIDE;
};
//! [0]
@@ -107,7 +107,7 @@ public:
CodeStylePage(QWidget *parent = 0);
protected:
- void initializePage();
+ void initializePage() Q_DECL_OVERRIDE;
private:
QCheckBox *commentCheckBox;
@@ -128,7 +128,7 @@ public:
OutputFilesPage(QWidget *parent = 0);
protected:
- void initializePage();
+ void initializePage() Q_DECL_OVERRIDE;
private:
QLabel *outputDirLabel;
@@ -147,7 +147,7 @@ public:
ConclusionPage(QWidget *parent = 0);
protected:
- void initializePage();
+ void initializePage() Q_DECL_OVERRIDE;
private:
QLabel *label;
diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.h b/examples/widgets/dialogs/licensewizard/licensewizard.h
index a6dc0aec53..afdb984700 100644
--- a/examples/widgets/dialogs/licensewizard/licensewizard.h
+++ b/examples/widgets/dialogs/licensewizard/licensewizard.h
@@ -78,7 +78,7 @@ class IntroPage : public QWizardPage
public:
IntroPage(QWidget *parent = 0);
- int nextId() const;
+ int nextId() const Q_DECL_OVERRIDE;
private:
QLabel *topLabel;
@@ -95,7 +95,7 @@ class EvaluatePage : public QWizardPage
public:
EvaluatePage(QWidget *parent = 0);
- int nextId() const;
+ int nextId() const Q_DECL_OVERRIDE;
private:
QLabel *nameLabel;
@@ -112,7 +112,7 @@ class RegisterPage : public QWizardPage
public:
RegisterPage(QWidget *parent = 0);
- int nextId() const;
+ int nextId() const Q_DECL_OVERRIDE;
private:
QLabel *nameLabel;
@@ -128,7 +128,7 @@ class DetailsPage : public QWizardPage
public:
DetailsPage(QWidget *parent = 0);
- int nextId() const;
+ int nextId() const Q_DECL_OVERRIDE;
private:
QLabel *companyLabel;
@@ -147,9 +147,9 @@ class ConclusionPage : public QWizardPage
public:
ConclusionPage(QWidget *parent = 0);
- void initializePage();
- int nextId() const;
- void setVisible(bool visible);
+ void initializePage() Q_DECL_OVERRIDE;
+ int nextId() const Q_DECL_OVERRIDE;
+ void setVisible(bool visible) Q_DECL_OVERRIDE;
private slots:
void printButtonClicked();
diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.h b/examples/widgets/draganddrop/draggableicons/dragwidget.h
index e9d3bb88c7..a1b570a876 100644
--- a/examples/widgets/draganddrop/draggableicons/dragwidget.h
+++ b/examples/widgets/draganddrop/draggableicons/dragwidget.h
@@ -55,10 +55,10 @@ public:
DragWidget(QWidget *parent = 0);
protected:
- void dragEnterEvent(QDragEnterEvent *event);
- void dragMoveEvent(QDragMoveEvent *event);
- void dropEvent(QDropEvent *event);
- void mousePressEvent(QMouseEvent *event);
+ void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
+ void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.h b/examples/widgets/draganddrop/draggabletext/dragwidget.h
index 4198e00091..a214ca0d66 100644
--- a/examples/widgets/draganddrop/draggabletext/dragwidget.h
+++ b/examples/widgets/draganddrop/draggabletext/dragwidget.h
@@ -54,9 +54,9 @@ public:
DragWidget(QWidget *parent = 0);
protected:
- void dragEnterEvent(QDragEnterEvent *event);
- void dropEvent(QDropEvent *event);
- void mousePressEvent(QMouseEvent *event);
+ void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
};
#endif // DRAGWIDGET_H
diff --git a/examples/widgets/draganddrop/dropsite/droparea.h b/examples/widgets/draganddrop/dropsite/droparea.h
index 6b4b3c49aa..6d4be00252 100644
--- a/examples/widgets/draganddrop/dropsite/droparea.h
+++ b/examples/widgets/draganddrop/dropsite/droparea.h
@@ -64,10 +64,10 @@ signals:
//! [DropArea header part2]
protected:
- void dragEnterEvent(QDragEnterEvent *event);
- void dragMoveEvent(QDragMoveEvent *event);
- void dragLeaveEvent(QDragLeaveEvent *event);
- void dropEvent(QDropEvent *event);
+ void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
+ void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
+ void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
private:
QLabel *label;
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
index 6d231b73ff..6c45e19da8 100644
--- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
+++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
@@ -55,10 +55,10 @@ public:
DragWidget(QWidget *parent = 0);
protected:
- void dragEnterEvent(QDragEnterEvent *event);
- void dragMoveEvent(QDragMoveEvent *event);
- void dropEvent(QDropEvent *event);
- void mousePressEvent(QMouseEvent *event);
+ void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
+ void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.h b/examples/widgets/draganddrop/puzzle/pieceslist.h
index c032a67364..8baed434db 100644
--- a/examples/widgets/draganddrop/puzzle/pieceslist.h
+++ b/examples/widgets/draganddrop/puzzle/pieceslist.h
@@ -52,10 +52,10 @@ public:
void addPiece(QPixmap pixmap, QPoint location);
protected:
- void dragEnterEvent(QDragEnterEvent *event);
- void dragMoveEvent(QDragMoveEvent *event);
- void dropEvent(QDropEvent *event);
- void startDrag(Qt::DropActions supportedActions);
+ void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
+ void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
+ void startDrag(Qt::DropActions supportedActions) Q_DECL_OVERRIDE;
int m_PieceSize;
};
diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.h b/examples/widgets/draganddrop/puzzle/puzzlewidget.h
index d437993b64..2793f2aa77 100644
--- a/examples/widgets/draganddrop/puzzle/puzzlewidget.h
+++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.h
@@ -67,12 +67,12 @@ 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);
+ void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
+ void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;
+ void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
int findPiece(const QRect &pieceRect) const;
diff --git a/examples/widgets/effects/blurpicker/blureffect.h b/examples/widgets/effects/blurpicker/blureffect.h
index 97459ac707..3c0399e24f 100644
--- a/examples/widgets/effects/blurpicker/blureffect.h
+++ b/examples/widgets/effects/blurpicker/blureffect.h
@@ -53,7 +53,7 @@ public:
QRectF boundingRect() const;
- void draw(QPainter *painter);
+ void draw(QPainter *painter) Q_DECL_OVERRIDE;
private:
void adjustForItem();
diff --git a/examples/widgets/effects/blurpicker/blurpicker.h b/examples/widgets/effects/blurpicker/blurpicker.h
index 4c3d463fa8..0d06f6c28f 100644
--- a/examples/widgets/effects/blurpicker/blurpicker.h
+++ b/examples/widgets/effects/blurpicker/blurpicker.h
@@ -59,9 +59,9 @@ public:
void setIndex(qreal);
protected:
- void keyPressEvent(QKeyEvent *event);
- void resizeEvent(QResizeEvent *event);
- void mousePressEvent(QMouseEvent *event);
+ void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
void setupScene();
diff --git a/examples/widgets/effects/lighting/lighting.h b/examples/widgets/effects/lighting/lighting.h
index c33bb7ad16..29c6616c0c 100644
--- a/examples/widgets/effects/lighting/lighting.h
+++ b/examples/widgets/effects/lighting/lighting.h
@@ -58,7 +58,7 @@ private:
void setupScene();
protected:
- void resizeEvent(QResizeEvent *event);
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private:
qreal angle;
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.h b/examples/widgets/gestures/imagegestures/imagewidget.h
index d061935fe0..fc1faf9379 100644
--- a/examples/widgets/gestures/imagegestures/imagewidget.h
+++ b/examples/widgets/gestures/imagegestures/imagewidget.h
@@ -65,10 +65,10 @@ public:
void grabGestures(const QList<Qt::GestureType> &gestures);
protected:
- bool event(QEvent *event);
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *event);
- void mouseDoubleClickEvent(QMouseEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
bool gestureEvent(QGestureEvent *event);
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
index 143aefe211..7b12aa805b 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
@@ -51,12 +51,12 @@ public:
LayoutItem(QGraphicsItem *parent = 0);
~LayoutItem();
// Inherited from QGraphicsLayoutItem
- void setGeometry(const QRectF &geom);
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
+ void setGeometry(const QRectF &geom) Q_DECL_OVERRIDE;
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const Q_DECL_OVERRIDE;
// Inherited from QGraphicsItem
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
private:
QPixmap *m_pix;
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.h b/examples/widgets/graphicsview/boxes/glbuffers.h
index 304b3da87a..6c6c80eed2 100644
--- a/examples/widgets/graphicsview/boxes/glbuffers.h
+++ b/examples/widgets/graphicsview/boxes/glbuffers.h
@@ -101,8 +101,8 @@ public:
GLTexture2D(int width, int height);
explicit GLTexture2D(const QString& fileName, int width = 0, int height = 0);
void load(int width, int height, QRgb *data);
- virtual void bind();
- virtual void unbind();
+ virtual void bind() Q_DECL_OVERRIDE;
+ virtual void unbind() Q_DECL_OVERRIDE;
};
class GLTexture3D : public GLTexture
@@ -112,8 +112,8 @@ public:
// TODO: Implement function below
//GLTexture3D(const QString& fileName, int width = 0, int height = 0);
void load(int width, int height, int depth, QRgb *data);
- virtual void bind();
- virtual void unbind();
+ virtual void bind() Q_DECL_OVERRIDE;
+ virtual void unbind() Q_DECL_OVERRIDE;
};
class GLTextureCube : public GLTexture
@@ -122,8 +122,8 @@ public:
GLTextureCube(int size);
explicit GLTextureCube(const QStringList& fileNames, int size = 0);
void load(int size, int face, QRgb *data);
- virtual void bind();
- virtual void unbind();
+ virtual void bind() Q_DECL_OVERRIDE;
+ virtual void unbind() Q_DECL_OVERRIDE;
};
// TODO: Define and implement class below
@@ -137,7 +137,7 @@ public:
void begin(int face);
// end rendering
void end();
- virtual bool failed() const {return m_failed || m_fbo.failed();}
+ virtual bool failed() const Q_DECL_OVERRIDE {return m_failed || m_fbo.failed();}
static void getViewMatrix(QMatrix4x4& mat, int face);
static void getProjectionMatrix(QMatrix4x4& mat, float nearZ, float farZ);
diff --git a/examples/widgets/graphicsview/boxes/main.cpp b/examples/widgets/graphicsview/boxes/main.cpp
index dcbf72e992..d138a268d9 100644
--- a/examples/widgets/graphicsview/boxes/main.cpp
+++ b/examples/widgets/graphicsview/boxes/main.cpp
@@ -58,7 +58,7 @@ public:
}
protected:
- void resizeEvent(QResizeEvent *event) {
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE {
if (scene())
scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
QGraphicsView::resizeEvent(event);
diff --git a/examples/widgets/graphicsview/boxes/qtbox.h b/examples/widgets/graphicsview/boxes/qtbox.h
index f71d66d3af..7b6975d80e 100644
--- a/examples/widgets/graphicsview/boxes/qtbox.h
+++ b/examples/widgets/graphicsview/boxes/qtbox.h
@@ -54,18 +54,18 @@ public:
ItemBase(int size, int x, int y);
virtual ~ItemBase();
- virtual QRectF boundingRect() const;
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
protected:
virtual ItemBase *createNew(int size, int x, int y) = 0;
- virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
- virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
- virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
- virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- virtual void keyPressEvent(QKeyEvent *event);
- virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
- virtual int type() const;
+ virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE;
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ virtual void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+ virtual void wheelEvent(QGraphicsSceneWheelEvent *event) Q_DECL_OVERRIDE;
+ virtual int type() const Q_DECL_OVERRIDE;
bool isInResizeArea(const QPointF &pos);
static void duplicateSelectedItems(QGraphicsScene *scene);
@@ -83,9 +83,9 @@ class QtBox : public ItemBase
public:
QtBox(int size, int x, int y);
virtual ~QtBox();
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
protected:
- virtual ItemBase *createNew(int size, int x, int y);
+ virtual ItemBase *createNew(int size, int x, int y) Q_DECL_OVERRIDE;
private:
QVector3D m_vertices[8];
QVector3D m_texCoords[4];
@@ -97,9 +97,9 @@ class CircleItem : public ItemBase
{
public:
CircleItem(int size, int x, int y);
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
protected:
- virtual ItemBase *createNew(int size, int x, int y);
+ virtual ItemBase *createNew(int size, int x, int y) Q_DECL_OVERRIDE;
QColor m_color;
};
@@ -108,9 +108,9 @@ class SquareItem : public ItemBase
{
public:
SquareItem(int size, int x, int y);
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
protected:
- virtual ItemBase *createNew(int size, int x, int y);
+ virtual ItemBase *createNew(int size, int x, int y) Q_DECL_OVERRIDE;
QPixmap m_image;
};
diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h
index f3c36af565..d20449b3db 100644
--- a/examples/widgets/graphicsview/boxes/scene.h
+++ b/examples/widgets/graphicsview/boxes/scene.h
@@ -72,13 +72,13 @@ class ColorEdit : public ParameterEdit
public:
ColorEdit(QRgb initialColor, int id);
QRgb color() const {return m_color;}
- virtual void emitChange() {emit colorChanged(m_color, m_id);}
+ virtual void emitChange() Q_DECL_OVERRIDE {emit colorChanged(m_color, m_id);}
public slots:
void editDone();
signals:
void colorChanged(QRgb color, int id);
protected:
- virtual void mousePressEvent(QMouseEvent *event);
+ virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void setColor(QRgb color); // also emits colorChanged()
private:
QGraphicsScene *m_dialogParentScene;
@@ -94,7 +94,7 @@ class FloatEdit : public ParameterEdit
public:
FloatEdit(float initialValue, int id);
float value() const {return m_value;}
- virtual void emitChange() {emit valueChanged(m_value, m_id);}
+ virtual void emitChange() Q_DECL_OVERRIDE {emit valueChanged(m_value, m_id);}
public slots:
void editDone();
signals:
@@ -111,9 +111,9 @@ class GraphicsWidget : public QGraphicsProxyWidget
public:
GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
protected:
- virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
- virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
+ virtual void resizeEvent(QGraphicsSceneResizeEvent *event) Q_DECL_OVERRIDE;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
};
class TwoSidedGraphicsWidget : public QObject
@@ -153,7 +153,7 @@ signals:
void shaderChanged(int);
void doubleClicked();
protected:
- virtual void mouseDoubleClickEvent(QMouseEvent *event);
+ virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
QVector<QByteArray> m_parameterNames;
QComboBox *m_textureCombo;
@@ -180,7 +180,7 @@ signals:
void doubleClicked();
void newItemTriggered(ItemDialog::ItemType type);
protected:
- virtual void mouseDoubleClickEvent(QMouseEvent *event);
+ virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
};
class Scene : public QGraphicsScene
@@ -189,7 +189,7 @@ class Scene : public QGraphicsScene
public:
Scene(int width, int height, int maxTextureSize);
~Scene();
- virtual void drawBackground(QPainter *painter, const QRectF &rect);
+ virtual void drawBackground(QPainter *painter, const QRectF &rect) Q_DECL_OVERRIDE;
public slots:
void setShader(int index);
@@ -205,10 +205,10 @@ protected:
void defaultStates();
void renderCubemaps();
- virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
- virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- virtual void wheelEvent(QGraphicsSceneWheelEvent * event);
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ virtual void wheelEvent(QGraphicsSceneWheelEvent * event) Q_DECL_OVERRIDE;
private:
void initGL();
QPointF pixelPosToViewPos(const QPointF& p);
diff --git a/examples/widgets/graphicsview/chip/chip.h b/examples/widgets/graphicsview/chip/chip.h
index f71ab13328..98d8a9ce0a 100644
--- a/examples/widgets/graphicsview/chip/chip.h
+++ b/examples/widgets/graphicsview/chip/chip.h
@@ -50,14 +50,14 @@ class Chip : public QGraphicsItem
public:
Chip(const QColor &color, int x, int y);
- QRectF boundingRect() const;
- QPainterPath shape() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ QPainterPath shape() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) Q_DECL_OVERRIDE;
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *event);
- void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
private:
int x;
diff --git a/examples/widgets/graphicsview/chip/view.h b/examples/widgets/graphicsview/chip/view.h
index 0abebaadad..18f3460b2a 100644
--- a/examples/widgets/graphicsview/chip/view.h
+++ b/examples/widgets/graphicsview/chip/view.h
@@ -61,7 +61,7 @@ public:
protected:
#ifndef QT_NO_WHEELEVENT
- void wheelEvent(QWheelEvent *);
+ void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE;
#endif
private:
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.h b/examples/widgets/graphicsview/collidingmice/mouse.h
index f2be900c6a..a6c39e1801 100644
--- a/examples/widgets/graphicsview/collidingmice/mouse.h
+++ b/examples/widgets/graphicsview/collidingmice/mouse.h
@@ -49,13 +49,13 @@ class Mouse : public QGraphicsItem
public:
Mouse();
- QRectF boundingRect() const;
- QPainterPath shape() const;
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ QPainterPath shape() const Q_DECL_OVERRIDE;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget);
+ QWidget *widget) Q_DECL_OVERRIDE;
protected:
- void advance(int step);
+ void advance(int step) Q_DECL_OVERRIDE;
private:
qreal angle;
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.h b/examples/widgets/graphicsview/diagramscene/arrow.h
index a8c81aee5f..80a5d23635 100644
--- a/examples/widgets/graphicsview/diagramscene/arrow.h
+++ b/examples/widgets/graphicsview/diagramscene/arrow.h
@@ -63,9 +63,9 @@ public:
Arrow(DiagramItem *startItem, DiagramItem *endItem,
QGraphicsItem *parent = 0);
- int type() const { return Type; }
- QRectF boundingRect() const;
- QPainterPath shape() const;
+ int type() const Q_DECL_OVERRIDE { return Type; }
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ QPainterPath shape() const Q_DECL_OVERRIDE;
void setColor(const QColor &color) { myColor = color; }
DiagramItem *startItem() const { return myStartItem; }
DiagramItem *endItem() const { return myEndItem; }
@@ -73,7 +73,7 @@ public:
void updatePosition();
protected:
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
private:
DiagramItem *myStartItem;
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.h b/examples/widgets/graphicsview/diagramscene/diagramitem.h
index 6681d9b548..af13f76e7e 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramitem.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.h
@@ -75,11 +75,11 @@ public:
QPolygonF polygon() const { return myPolygon; }
void addArrow(Arrow *arrow);
QPixmap image() const;
- int type() const { return Type;}
+ int type() const Q_DECL_OVERRIDE { return Type;}
protected:
- void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
- QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE;
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
private:
DiagramType myDiagramType;
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.h b/examples/widgets/graphicsview/diagramscene/diagramscene.h
index a28eba99e8..17666e208c 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramscene.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.h
@@ -85,9 +85,9 @@ signals:
void itemSelected(QGraphicsItem *item);
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
- void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
+ void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) Q_DECL_OVERRIDE;
private:
bool isItemChange(int type);
diff --git a/examples/widgets/graphicsview/diagramscene/diagramtextitem.h b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
index 8041ccb53c..6a6015fdec 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
@@ -61,16 +61,16 @@ public:
DiagramTextItem(QGraphicsItem *parent = 0);
- int type() const { return Type; }
+ int type() const Q_DECL_OVERRIDE { 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);
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
+ void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
+ void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/graphicsview/dragdroprobot/coloritem.h b/examples/widgets/graphicsview/dragdroprobot/coloritem.h
index 31ad3ddc07..833f0836ea 100644
--- a/examples/widgets/graphicsview/dragdroprobot/coloritem.h
+++ b/examples/widgets/graphicsview/dragdroprobot/coloritem.h
@@ -49,13 +49,13 @@ class ColorItem : public QGraphicsItem
public:
ColorItem();
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *event);
- void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
private:
QColor color;
diff --git a/examples/widgets/graphicsview/dragdroprobot/main.cpp b/examples/widgets/graphicsview/dragdroprobot/main.cpp
index ab7ad97d30..34f190f0a5 100644
--- a/examples/widgets/graphicsview/dragdroprobot/main.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/main.cpp
@@ -53,7 +53,7 @@ public:
}
protected:
- virtual void resizeEvent(QResizeEvent *)
+ virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE
{
}
};
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.h b/examples/widgets/graphicsview/dragdroprobot/robot.h
index a0c842e72c..6ab60756ee 100644
--- a/examples/widgets/graphicsview/dragdroprobot/robot.h
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.h
@@ -55,9 +55,9 @@ public:
RobotPart(QGraphicsItem *parent = 0);
protected:
- void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
- void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
- void dropEvent(QGraphicsSceneDragDropEvent *event);
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event) Q_DECL_OVERRIDE;
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QGraphicsSceneDragDropEvent *event) Q_DECL_OVERRIDE;
QColor color;
bool dragOver;
@@ -70,12 +70,12 @@ class RobotHead : public RobotPart
public:
RobotHead(QGraphicsItem *parent = 0);
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
protected:
- void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
- void dropEvent(QGraphicsSceneDragDropEvent *event);
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QGraphicsSceneDragDropEvent *event) Q_DECL_OVERRIDE;
private:
QPixmap pixmap;
@@ -88,8 +88,8 @@ class RobotTorso : public RobotPart
public:
RobotTorso(QGraphicsItem *parent = 0);
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
};
//! [2]
@@ -99,8 +99,8 @@ class RobotLimb : public RobotPart
public:
RobotLimb(QGraphicsItem *parent = 0);
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
};
//! [3]
@@ -110,8 +110,8 @@ class Robot : public RobotPart
public:
Robot(QGraphicsItem *parent = 0);
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
};
//! [4]
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.h b/examples/widgets/graphicsview/elasticnodes/edge.h
index 6ab71e3478..8a3cb7b19a 100644
--- a/examples/widgets/graphicsview/elasticnodes/edge.h
+++ b/examples/widgets/graphicsview/elasticnodes/edge.h
@@ -57,11 +57,11 @@ public:
void adjust();
enum { Type = UserType + 2 };
- int type() const { return Type; }
+ int type() const Q_DECL_OVERRIDE { return Type; }
protected:
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
private:
Node *source, *dest;
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.h b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
index 301a02dd25..a7480945e3 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.h
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
@@ -61,12 +61,12 @@ public slots:
void zoomOut();
protected:
- void keyPressEvent(QKeyEvent *event);
- void timerEvent(QTimerEvent *event);
+ void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
#ifndef QT_NO_WHEELEVENT
- void wheelEvent(QWheelEvent *event);
+ void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
#endif
- void drawBackground(QPainter *painter, const QRectF &rect);
+ void drawBackground(QPainter *painter, const QRectF &rect) Q_DECL_OVERRIDE;
void scaleView(qreal scaleFactor);
diff --git a/examples/widgets/graphicsview/elasticnodes/node.h b/examples/widgets/graphicsview/elasticnodes/node.h
index 813dbb1c54..2d18a64654 100644
--- a/examples/widgets/graphicsview/elasticnodes/node.h
+++ b/examples/widgets/graphicsview/elasticnodes/node.h
@@ -60,20 +60,20 @@ public:
QList<Edge *> edges() const;
enum { Type = UserType + 1 };
- int type() const { return Type; }
+ int type() const Q_DECL_OVERRIDE { return Type; }
void calculateForces();
bool advance();
- QRectF boundingRect() const;
- QPainterPath shape() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ QPainterPath shape() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
protected:
- QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
- void mousePressEvent(QGraphicsSceneMouseEvent *event);
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
private:
QList<Edge *> edgeList;
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
index 7257a90b12..7708c165ad 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
@@ -52,15 +52,15 @@ class CustomProxy : public QGraphicsProxyWidget
public:
explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
- QRectF boundingRect() const;
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget);
+ QWidget *widget) Q_DECL_OVERRIDE;
protected:
- void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
- QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) Q_DECL_OVERRIDE;
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
private slots:
void updateStep(qreal step);
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.h b/examples/widgets/graphicsview/flowlayout/flowlayout.h
index f1419f6a24..06ceca2885 100644
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.h
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.h
@@ -50,14 +50,14 @@ public:
qreal spacing(Qt::Orientation o) const;
// inherited functions
- void setGeometry(const QRectF &geom);
+ void setGeometry(const QRectF &geom) Q_DECL_OVERRIDE;
- int count() const;
- QGraphicsLayoutItem *itemAt(int index) const;
- void removeAt(int index);
+ int count() const Q_DECL_OVERRIDE;
+ QGraphicsLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE;
+ void removeAt(int index) Q_DECL_OVERRIDE;
protected:
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const Q_DECL_OVERRIDE;
private:
qreal doLayout(const QRectF &geom, bool applyNewGeometry) const;
diff --git a/examples/widgets/graphicsview/graphicsview.pro b/examples/widgets/graphicsview/graphicsview.pro
index 9d6d7a75f6..06a7ce8071 100644
--- a/examples/widgets/graphicsview/graphicsview.pro
+++ b/examples/widgets/graphicsview/graphicsview.pro
@@ -15,6 +15,6 @@ SUBDIRS = \
contains(DEFINES, QT_NO_CURSOR)|contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= dragdroprobot
-qtHaveModule(opengl):!contains(QT_CONFIG, opengles.) {
+qtHaveModule(opengl):!contains(QT_CONFIG, opengles.):!contains(QT_CONFIG,dynamicgl) {
SUBDIRS += boxes
}
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.cpp b/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
index 82671578fb..977b65395a 100644
--- a/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
@@ -292,7 +292,7 @@ PadNavigator::PadNavigator(const QSize &size, QWidget *parent)
| QPainter::SmoothPixmapTransform
| QPainter::TextAntialiasing);
#ifndef QT_NO_OPENGL
- setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+ setViewport(new QOpenGLWidget);
#endif
stateMachine->start();
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.h b/examples/widgets/graphicsview/padnavigator/padnavigator.h
index a666fe85d3..7e3e6fc29d 100644
--- a/examples/widgets/graphicsview/padnavigator/padnavigator.h
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.h
@@ -57,7 +57,7 @@ public:
explicit PadNavigator(const QSize &size, QWidget *parent = 0);
protected:
- void resizeEvent(QResizeEvent *event);
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private:
Ui::Form form;
diff --git a/examples/widgets/graphicsview/padnavigator/roundrectitem.h b/examples/widgets/graphicsview/padnavigator/roundrectitem.h
index 15c8847279..f8eeafcfd6 100644
--- a/examples/widgets/graphicsview/padnavigator/roundrectitem.h
+++ b/examples/widgets/graphicsview/padnavigator/roundrectitem.h
@@ -56,8 +56,8 @@ public:
QPixmap pixmap() const;
void setPixmap(const QPixmap &pixmap);
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
bool fill() const;
void setFill(bool fill);
diff --git a/examples/widgets/graphicsview/padnavigator/splashitem.h b/examples/widgets/graphicsview/padnavigator/splashitem.h
index 2423a18c3d..35646900d2 100644
--- a/examples/widgets/graphicsview/padnavigator/splashitem.h
+++ b/examples/widgets/graphicsview/padnavigator/splashitem.h
@@ -50,8 +50,8 @@ class SplashItem : public QGraphicsObject
public:
explicit SplashItem(QGraphicsItem *parent = 0);
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QRectF boundingRect() const Q_DECL_OVERRIDE;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) Q_DECL_OVERRIDE;
private:
QString text;
diff --git a/examples/widgets/graphicsview/simpleanchorlayout/main.cpp b/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
index c17c0252c3..eed05f3189 100644
--- a/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
+++ b/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
@@ -52,7 +52,7 @@ public:
{
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = 0)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = 0) Q_DECL_OVERRIDE
{
QFont font;
font.setPixelSize(0.75 * qMin(boundingRect().width(), boundingRect().height()));
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/main.cpp b/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
index 6f742756be..c3db6275e1 100644
--- a/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
+++ b/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
@@ -59,7 +59,7 @@ public:
{
}
- virtual void resizeEvent(QResizeEvent *event)
+ virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
{
w->setGeometry(0, 0, event->size().width(), event->size().height());
}
@@ -91,7 +91,7 @@ public:
original->setZValue(z);
}
- void setGeometry (const QRectF &rect)
+ void setGeometry (const QRectF &rect) Q_DECL_OVERRIDE
{
original->setTransform(QTransform::fromScale(rect.width() / r.width(),
rect.height() / r.height()), true);
@@ -100,7 +100,7 @@ public:
}
protected:
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const Q_DECL_OVERRIDE
{
Q_UNUSED(constraint);
QSizeF sh;
@@ -138,7 +138,7 @@ public:
{
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*) Q_DECL_OVERRIDE
{
QPointF reflection = QPointF();
reflection.setY(scaled.height() + 2);
@@ -170,14 +170,14 @@ public:
painter->drawPixmap(reflection, tmp);
}
- void resizeEvent(QGraphicsSceneResizeEvent *event)
+ void resizeEvent(QGraphicsSceneResizeEvent *event) Q_DECL_OVERRIDE
{
QSize newSize = event->newSize().toSize();
newSize.setHeight(newSize.height() / 2);
scaled = original.scaled(newSize);
}
- QRectF boundingRect() const
+ QRectF boundingRect() const Q_DECL_OVERRIDE
{
QSize size(scaled.width(), scaled.height() * 2 + 2);
return QRectF(QPointF(0, 0), size);
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.h b/examples/widgets/itemviews/addressbook/tablemodel.h
index e282defa1b..d505dbf6e7 100644
--- a/examples/widgets/itemviews/addressbook/tablemodel.h
+++ b/examples/widgets/itemviews/addressbook/tablemodel.h
@@ -54,14 +54,14 @@ 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());
+ int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
+ bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) Q_DECL_OVERRIDE;
QList<QPair<QString, QString> > getList();
private:
diff --git a/examples/widgets/itemviews/chart/pieview.h b/examples/widgets/itemviews/chart/pieview.h
index e8eb59758f..7ad893c03a 100644
--- a/examples/widgets/itemviews/chart/pieview.h
+++ b/examples/widgets/itemviews/chart/pieview.h
@@ -51,44 +51,44 @@ class PieView : public QAbstractItemView
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;
+ QRect visualRect(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) Q_DECL_OVERRIDE;
+ QModelIndex indexAt(const QPoint &point) const Q_DECL_OVERRIDE;
protected slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
- const QVector<int> &roles = QVector<int>());
- void rowsInserted(const QModelIndex &parent, int start, int end);
- void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
+ const QVector<int> &roles = QVector<int>()) Q_DECL_OVERRIDE;
+ void rowsInserted(const QModelIndex &parent, int start, int end) Q_DECL_OVERRIDE;
+ void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) Q_DECL_OVERRIDE;
protected:
- bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event);
+ bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) Q_DECL_OVERRIDE;
QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction,
- Qt::KeyboardModifiers modifiers);
+ Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;
- int horizontalOffset() const;
- int verticalOffset() const;
+ int horizontalOffset() const Q_DECL_OVERRIDE;
+ int verticalOffset() const Q_DECL_OVERRIDE;
- bool isIndexHidden(const QModelIndex &index) const;
+ bool isIndexHidden(const QModelIndex &index) const Q_DECL_OVERRIDE;
- void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command);
+ void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command) Q_DECL_OVERRIDE;
- void mousePressEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
- void mouseMoveEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *event);
- void scrollContentsBy(int dx, int dy);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE;
- QRegion visualRegionForSelection(const QItemSelection &selection) const;
+ QRegion visualRegionForSelection(const QItemSelection &selection) const Q_DECL_OVERRIDE;
private:
QRect itemRect(const QModelIndex &item) const;
QRegion itemRegion(const QModelIndex &index) const;
int rows(const QModelIndex &index = QModelIndex()) const;
- void updateGeometries();
+ void updateGeometries() Q_DECL_OVERRIDE;
int margin;
int totalSize;
diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
index c0c9aa3012..b251a54c3d 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
+++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
@@ -59,8 +59,8 @@ public:
void setFilterMaximumDate(const QDate &date);
protected:
- bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
- bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
private:
bool dateInRange(const QDate &date) const;
diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.h b/examples/widgets/itemviews/editabletreemodel/treemodel.h
index 078e5e4077..0d0a9178d6 100644
--- a/examples/widgets/itemviews/editabletreemodel/treemodel.h
+++ b/examples/widgets/itemviews/editabletreemodel/treemodel.h
@@ -58,33 +58,33 @@ public:
~TreeModel();
//! [0] //! [1]
- QVariant data(const QModelIndex &index, int role) const;
+ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
+ int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex &index) const;
+ const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
//! [1]
//! [2]
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
bool setData(const QModelIndex &index, const QVariant &value,
- int role = Qt::EditRole);
+ int role = Qt::EditRole) Q_DECL_OVERRIDE;
bool setHeaderData(int section, Qt::Orientation orientation,
- const QVariant &value, int role = Qt::EditRole);
+ const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
bool insertColumns(int position, int columns,
- const QModelIndex &parent = QModelIndex());
+ const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
bool removeColumns(int position, int columns,
- const QModelIndex &parent = QModelIndex());
+ const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
bool insertRows(int position, int rows,
- const QModelIndex &parent = QModelIndex());
+ const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
bool removeRows(int position, int rows,
- const QModelIndex &parent = QModelIndex());
+ const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
private:
void setupModelData(const QStringList &lines, TreeItem *parent);
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.h b/examples/widgets/itemviews/fetchmore/filelistmodel.h
index 5daef80a83..99c1490495 100644
--- a/examples/widgets/itemviews/fetchmore/filelistmodel.h
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.h
@@ -53,8 +53,8 @@ class FileListModel : public QAbstractListModel
public:
FileListModel(QObject *parent = 0);
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
signals:
void numberPopulated(int number);
@@ -63,8 +63,8 @@ public slots:
void setDirPath(const QString &path);
protected:
- bool canFetchMore(const QModelIndex &parent) const;
- void fetchMore(const QModelIndex &parent);
+ bool canFetchMore(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ void fetchMore(const QModelIndex &parent) Q_DECL_OVERRIDE;
private:
QStringList fileList;
diff --git a/examples/widgets/itemviews/frozencolumn/freezetablewidget.h b/examples/widgets/itemviews/frozencolumn/freezetablewidget.h
index 53805316aa..ea3b0d4b6f 100644
--- a/examples/widgets/itemviews/frozencolumn/freezetablewidget.h
+++ b/examples/widgets/itemviews/frozencolumn/freezetablewidget.h
@@ -53,9 +53,9 @@ public:
protected:
- virtual void resizeEvent(QResizeEvent *event);
- virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
- void scrollTo (const QModelIndex & index, ScrollHint hint = EnsureVisible);
+ virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;
+ void scrollTo (const QModelIndex & index, ScrollHint hint = EnsureVisible) Q_DECL_OVERRIDE;
private:
QTableView *frozenTableView;
diff --git a/examples/widgets/itemviews/interview/model.h b/examples/widgets/itemviews/interview/model.h
index 02c267f69a..0dd722b855 100644
--- a/examples/widgets/itemviews/interview/model.h
+++ b/examples/widgets/itemviews/interview/model.h
@@ -55,17 +55,17 @@ public:
Model(int rows, int columns, QObject *parent = 0);
~Model();
- QModelIndex index(int row, int column, const QModelIndex &parent) const;
- QModelIndex parent(const QModelIndex &child) const;
+ QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
- int rowCount(const QModelIndex &parent) const;
- int columnCount(const QModelIndex &parent) const;
+ int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
- QVariant data(const QModelIndex &index, int role) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
- bool hasChildren(const QModelIndex &parent) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ bool hasChildren(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
private:
diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro
index 5d5eef1b0f..a76c8a1077 100644
--- a/examples/widgets/itemviews/itemviews.pro
+++ b/examples/widgets/itemviews/itemviews.pro
@@ -17,5 +17,6 @@ SUBDIRS = addressbook \
simplewidgetmapper \
spinboxdelegate \
spreadsheet \
- stardelegate
+ stardelegate \
+ storageview
contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= puzzle
diff --git a/examples/widgets/itemviews/pixelator/imagemodel.h b/examples/widgets/itemviews/pixelator/imagemodel.h
index 3cb5d32b20..49c3b3269d 100644
--- a/examples/widgets/itemviews/pixelator/imagemodel.h
+++ b/examples/widgets/itemviews/pixelator/imagemodel.h
@@ -54,11 +54,11 @@ public:
void setImage(const QImage &image);
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
private:
QImage modelImage;
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.h b/examples/widgets/itemviews/pixelator/pixeldelegate.h
index b4426ea268..c7d27ba52d 100644
--- a/examples/widgets/itemviews/pixelator/pixeldelegate.h
+++ b/examples/widgets/itemviews/pixelator/pixeldelegate.h
@@ -62,10 +62,10 @@ public:
PixelDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
QSize sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index ) const;
+ const QModelIndex &index ) const Q_DECL_OVERRIDE;
public slots:
void setPixelSize(int size);
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.h b/examples/widgets/itemviews/puzzle/piecesmodel.h
index 72df1cef92..a6e31f2107 100644
--- a/examples/widgets/itemviews/puzzle/piecesmodel.h
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.h
@@ -58,16 +58,16 @@ class PiecesModel : public QAbstractListModel
public:
explicit PiecesModel(int pieceSize, QObject *parent = 0);
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
- bool removeRows(int row, int count, const QModelIndex &parent);
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ bool removeRows(int row, int count, const QModelIndex &parent) Q_DECL_OVERRIDE;
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;
+ int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
+ QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE;
+ QStringList mimeTypes() const Q_DECL_OVERRIDE;
+ int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
void addPiece(const QPixmap &pixmap, const QPoint &location);
void addPieces(const QPixmap& pixmap);
diff --git a/examples/widgets/itemviews/puzzle/puzzlewidget.h b/examples/widgets/itemviews/puzzle/puzzlewidget.h
index 5da81b9c63..41dc141ee4 100644
--- a/examples/widgets/itemviews/puzzle/puzzlewidget.h
+++ b/examples/widgets/itemviews/puzzle/puzzlewidget.h
@@ -67,12 +67,12 @@ 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);
+ void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
+ void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;
+ void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
int findPiece(const QRect &pieceRect) const;
diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.h b/examples/widgets/itemviews/simpledommodel/dommodel.h
index 7e56707198..27ece11b45 100644
--- a/examples/widgets/itemviews/simpledommodel/dommodel.h
+++ b/examples/widgets/itemviews/simpledommodel/dommodel.h
@@ -56,15 +56,15 @@ public:
explicit DomModel(QDomDocument document, QObject *parent = 0);
~DomModel();
- QVariant data(const QModelIndex &index, int role) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
+ int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
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;
+ const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
private:
QDomDocument domDocument;
diff --git a/examples/widgets/itemviews/simpletreemodel/treeitem.cpp b/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
index f48a840a00..a5feac3178 100644
--- a/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
+++ b/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
@@ -51,65 +51,65 @@
//! [0]
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
{
- parentItem = parent;
- itemData = data;
+ m_parentItem = parent;
+ m_itemData = data;
}
//! [0]
//! [1]
TreeItem::~TreeItem()
{
- qDeleteAll(childItems);
+ qDeleteAll(m_childItems);
}
//! [1]
//! [2]
void TreeItem::appendChild(TreeItem *item)
{
- childItems.append(item);
+ m_childItems.append(item);
}
//! [2]
//! [3]
TreeItem *TreeItem::child(int row)
{
- return childItems.value(row);
+ return m_childItems.value(row);
}
//! [3]
//! [4]
int TreeItem::childCount() const
{
- return childItems.count();
+ return m_childItems.count();
}
//! [4]
//! [5]
int TreeItem::columnCount() const
{
- return itemData.count();
+ return m_itemData.count();
}
//! [5]
//! [6]
QVariant TreeItem::data(int column) const
{
- return itemData.value(column);
+ return m_itemData.value(column);
}
//! [6]
//! [7]
-TreeItem *TreeItem::parent()
+TreeItem *TreeItem::parentItem()
{
- return parentItem;
+ return m_parentItem;
}
//! [7]
//! [8]
int TreeItem::row() const
{
- if (parentItem)
- return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
+ if (m_parentItem)
+ return m_parentItem->m_childItems.indexOf(const_cast<TreeItem*>(this));
return 0;
}
diff --git a/examples/widgets/itemviews/simpletreemodel/treeitem.h b/examples/widgets/itemviews/simpletreemodel/treeitem.h
index e775b5083e..33dbd8b993 100644
--- a/examples/widgets/itemviews/simpletreemodel/treeitem.h
+++ b/examples/widgets/itemviews/simpletreemodel/treeitem.h
@@ -48,7 +48,7 @@
class TreeItem
{
public:
- explicit TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
+ explicit TreeItem(const QList<QVariant> &data, TreeItem *parentItem = 0);
~TreeItem();
void appendChild(TreeItem *child);
@@ -58,12 +58,12 @@ public:
int columnCount() const;
QVariant data(int column) const;
int row() const;
- TreeItem *parent();
+ TreeItem *parentItem();
private:
- QList<TreeItem*> childItems;
- QList<QVariant> itemData;
- TreeItem *parentItem;
+ QList<TreeItem*> m_childItems;
+ QList<QVariant> m_itemData;
+ TreeItem *m_parentItem;
};
//! [0]
diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
index 971a813328..b15a717ef2 100644
--- a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
+++ b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
@@ -143,7 +143,7 @@ QModelIndex TreeModel::parent(const QModelIndex &index) const
return QModelIndex();
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
- TreeItem *parentItem = childItem->parent();
+ TreeItem *parentItem = childItem->parentItem();
if (parentItem == rootItem)
return QModelIndex();
diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.h b/examples/widgets/itemviews/simpletreemodel/treemodel.h
index 3bd593bc3e..964f0077c1 100644
--- a/examples/widgets/itemviews/simpletreemodel/treemodel.h
+++ b/examples/widgets/itemviews/simpletreemodel/treemodel.h
@@ -56,15 +56,15 @@ public:
explicit TreeModel(const QString &data, QObject *parent = 0);
~TreeModel();
- QVariant data(const QModelIndex &index, int role) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
+ int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
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;
+ const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
private:
void setupModelData(const QStringList &lines, TreeItem *parent);
diff --git a/examples/widgets/itemviews/spinboxdelegate/delegate.h b/examples/widgets/itemviews/spinboxdelegate/delegate.h
index 454471e155..9f5eb2b28b 100644
--- a/examples/widgets/itemviews/spinboxdelegate/delegate.h
+++ b/examples/widgets/itemviews/spinboxdelegate/delegate.h
@@ -52,14 +52,14 @@ public:
SpinBoxDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
- void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
void updateEditorGeometry(QWidget *editor,
- const QStyleOptionViewItem &option, const QModelIndex &index) const;
+ const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
index 464c2c3170..b67a2b690a 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
@@ -53,10 +53,10 @@ class SpreadSheetDelegate : public QItemDelegate
public:
SpreadSheetDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
- const QModelIndex &index) const;
- void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
private slots:
void commitAndCloseEditor();
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
index 4f1c1e1e4c..5af1fd1656 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
@@ -52,10 +52,10 @@ public:
SpreadSheetItem();
SpreadSheetItem(const QString &text);
- QTableWidgetItem *clone() const;
+ QTableWidgetItem *clone() const Q_DECL_OVERRIDE;
- QVariant data(int role) const;
- void setData(int role, const QVariant &value);
+ QVariant data(int role) const Q_DECL_OVERRIDE;
+ void setData(int role, const QVariant &value) Q_DECL_OVERRIDE;
QVariant display() const;
inline QString formula() const
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.h b/examples/widgets/itemviews/stardelegate/stardelegate.h
index 334dfbf375..03cd5d7e9b 100644
--- a/examples/widgets/itemviews/stardelegate/stardelegate.h
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.h
@@ -52,14 +52,14 @@ public:
StarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
QSize sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
- void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
private slots:
void commitAndCloseEditor();
diff --git a/examples/widgets/itemviews/stardelegate/stareditor.h b/examples/widgets/itemviews/stardelegate/stareditor.h
index a9a635b55b..c917d12b49 100644
--- a/examples/widgets/itemviews/stardelegate/stareditor.h
+++ b/examples/widgets/itemviews/stardelegate/stareditor.h
@@ -53,7 +53,7 @@ class StarEditor : public QWidget
public:
StarEditor(QWidget *parent = 0);
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
void setStarRating(const StarRating &starRating) {
myStarRating = starRating;
}
@@ -63,9 +63,9 @@ signals:
void editingFinished();
protected:
- void paintEvent(QPaintEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
int starAtPosition(int x);
diff --git a/examples/widgets/itemviews/storageview/main.cpp b/examples/widgets/itemviews/storageview/main.cpp
new file mode 100644
index 0000000000..a49046f851
--- /dev/null
+++ b/examples/widgets/itemviews/storageview/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Ivan Komissarov
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QTreeView>
+
+#include "storagemodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ QTreeView view;
+ view.setModel(new StorageModel(&view));
+ view.resize(640, 480);
+ view.setSelectionBehavior(QAbstractItemView::SelectRows);
+ int columnCount = view.model()->columnCount();
+ for (int c = 0; c < columnCount; ++c)
+ view.resizeColumnToContents(c);
+ view.show();
+
+ return a.exec();
+}
diff --git a/examples/widgets/itemviews/storageview/storagemodel.cpp b/examples/widgets/itemviews/storageview/storagemodel.cpp
new file mode 100644
index 0000000000..2445223390
--- /dev/null
+++ b/examples/widgets/itemviews/storageview/storagemodel.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Ivan Komissarov
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "storagemodel.h"
+
+#include <QDir>
+#include <qmath.h>
+
+static QString sizeToString(qint64 size)
+{
+ static const char *const strings[] = { "b", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
+
+ if (size <= 0)
+ return StorageModel::tr("0 b");
+
+ double power = log((double)size)/log(1024.0);
+ int intPower = (int)power;
+ intPower = intPower >= 8 ? 8 - 1 : intPower;
+
+ double normSize = size / pow(1024.0, intPower);
+ //: this should expand to "1.23 GB"
+ return StorageModel::tr("%1 %2").arg(normSize, 0, 'f', intPower > 0 ? 2 : 0).arg(strings[intPower]);
+}
+
+StorageModel::StorageModel(QObject *parent) :
+ QAbstractTableModel(parent),
+ m_volumes(QStorageInfo::mountedVolumes())
+{
+}
+
+int StorageModel::columnCount(const QModelIndex &/*parent*/) const
+{
+ return ColumnCount;
+}
+
+int StorageModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+ return m_volumes.count();
+}
+
+QVariant StorageModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ const QStorageInfo &volume = m_volumes.at(index.row());
+ switch (index.column()) {
+ case ColumnRootPath:
+ return QDir::toNativeSeparators(volume.rootPath());
+ case ColumnName:
+ return volume.name();
+ case ColumnDevice:
+ return volume.device();
+ case ColumnFileSystemName:
+ return volume.fileSystemType();
+ case ColumnTotal:
+ return sizeToString(volume.bytesTotal());
+ case ColumnFree:
+ return sizeToString(volume.bytesFree());
+ case ColumnAvailable:
+ return sizeToString(volume.bytesAvailable());
+ case ColumnIsReady:
+ return volume.isReady();
+ case ColumnIsReadOnly:
+ return volume.isReadOnly();
+ case ColumnIsValid:
+ return volume.isValid();
+ default:
+ break;
+ }
+ } else if (role == Qt::ToolTipRole) {
+ const QStorageInfo &volume = m_volumes.at(index.row());
+ return tr("Root path : %1\n"
+ "Name: %2\n"
+ "Display Name: %3\n"
+ "Device: %4\n"
+ "FileSystem: %5\n"
+ "Total size: %6\n"
+ "Free size: %7\n"
+ "Available size: %8\n"
+ "Is Ready: %9\n"
+ "Is Read-only: %10\n"
+ "Is Valid: %11\n"
+ "Is Root: %12"
+ ).
+ arg(QDir::toNativeSeparators(volume.rootPath())).
+ arg(volume.name()).
+ arg(volume.displayName()).
+ arg(QString::fromUtf8(volume.device())).
+ arg(QString::fromUtf8(volume.fileSystemType())).
+ arg(sizeToString(volume.bytesTotal())).
+ arg(sizeToString(volume.bytesFree())).
+ arg(sizeToString(volume.bytesAvailable())).
+ arg(volume.isReady() ? tr("true") : tr("false")).
+ arg(volume.isReadOnly() ? tr("true") : tr("false")).
+ arg(volume.isValid() ? tr("true") : tr("false")).
+ arg(volume.isRoot() ? tr("true") : tr("false"));
+ }
+ return QVariant();
+}
+
+QVariant StorageModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (orientation != Qt::Horizontal)
+ return QVariant();
+
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ switch (section) {
+ case ColumnRootPath:
+ return tr("Root path");
+ case ColumnName:
+ return tr("Volume Name");
+ case ColumnDevice:
+ return tr("Device");
+ case ColumnFileSystemName:
+ return tr("File system");
+ case ColumnTotal:
+ return tr("Total");
+ case ColumnFree:
+ return tr("Free");
+ case ColumnAvailable:
+ return tr("Available");
+ case ColumnIsReady:
+ return tr("Ready");
+ case ColumnIsReadOnly:
+ return tr("Read-only");
+ case ColumnIsValid:
+ return tr("Valid");
+ default:
+ break;
+ }
+
+ return QVariant();
+}
diff --git a/examples/widgets/itemviews/storageview/storagemodel.h b/examples/widgets/itemviews/storageview/storagemodel.h
new file mode 100644
index 0000000000..50b18a60bb
--- /dev/null
+++ b/examples/widgets/itemviews/storageview/storagemodel.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Ivan Komissarov
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STORAGEMODEL_H
+#define STORAGEMODEL_H
+
+#include <QAbstractTableModel>
+#include <QStorageInfo>
+
+class StorageModel : public QAbstractTableModel
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(StorageModel)
+public:
+ enum Column {
+ ColumnRootPath = 0,
+ ColumnName,
+ ColumnDevice,
+ ColumnFileSystemName,
+ ColumnTotal,
+ ColumnFree,
+ ColumnAvailable,
+ ColumnIsReady,
+ ColumnIsReadOnly,
+ ColumnIsValid,
+ ColumnCount
+ };
+
+ explicit StorageModel(QObject *parent = 0);
+
+ int columnCount(const QModelIndex &parent) const;
+ int rowCount(const QModelIndex &parent) const;
+
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+private:
+ QList<QStorageInfo> m_volumes;
+};
+
+#endif // STORAGEMODEL_H
diff --git a/examples/widgets/itemviews/storageview/storageview.pro b/examples/widgets/itemviews/storageview/storageview.pro
new file mode 100644
index 0000000000..c5c01dc4f1
--- /dev/null
+++ b/examples/widgets/itemviews/storageview/storageview.pro
@@ -0,0 +1,7 @@
+QT += core gui widgets
+TARGET = storageview
+TEMPLATE = app
+SOURCES += storagemodel.cpp \
+ main.cpp
+HEADERS += \
+ storagemodel.h
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.h b/examples/widgets/layouts/borderlayout/borderlayout.h
index eae425d5e6..3a6031a997 100644
--- a/examples/widgets/layouts/borderlayout/borderlayout.h
+++ b/examples/widgets/layouts/borderlayout/borderlayout.h
@@ -53,16 +53,16 @@ public:
BorderLayout(int spacing = -1);
~BorderLayout();
- void addItem(QLayoutItem *item);
+ void addItem(QLayoutItem *item) Q_DECL_OVERRIDE;
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);
+ Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE;
+ bool hasHeightForWidth() const Q_DECL_OVERRIDE;
+ int count() const Q_DECL_OVERRIDE;
+ QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE;
+ QSize minimumSize() const Q_DECL_OVERRIDE;
+ void setGeometry(const QRect &rect) Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
+ QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE;
void add(QLayoutItem *item, Position position);
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.h b/examples/widgets/layouts/flowlayout/flowlayout.h
index f7107be6b2..6c4b9e5ec5 100644
--- a/examples/widgets/layouts/flowlayout/flowlayout.h
+++ b/examples/widgets/layouts/flowlayout/flowlayout.h
@@ -52,18 +52,18 @@ public:
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
- void addItem(QLayoutItem *item);
+ void addItem(QLayoutItem *item) Q_DECL_OVERRIDE;
int horizontalSpacing() const;
int verticalSpacing() const;
- Qt::Orientations expandingDirections() const;
- bool hasHeightForWidth() const;
- int heightForWidth(int) const;
- int count() const;
- QLayoutItem *itemAt(int index) const;
- QSize minimumSize() const;
- void setGeometry(const QRect &rect);
- QSize sizeHint() const;
- QLayoutItem *takeAt(int index);
+ Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE;
+ bool hasHeightForWidth() const Q_DECL_OVERRIDE;
+ int heightForWidth(int) const Q_DECL_OVERRIDE;
+ int count() const Q_DECL_OVERRIDE;
+ QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE;
+ QSize minimumSize() const Q_DECL_OVERRIDE;
+ void setGeometry(const QRect &rect) Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
+ QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE;
private:
int doLayout(const QRect &rect, bool testOnly) const;
diff --git a/examples/widgets/mainwindows/application/mainwindow.cpp b/examples/widgets/mainwindows/application/mainwindow.cpp
index a5a0def0a6..dd8751973d 100644
--- a/examples/widgets/mainwindows/application/mainwindow.cpp
+++ b/examples/widgets/mainwindows/application/mainwindow.cpp
@@ -121,10 +121,10 @@ bool MainWindow::saveAs()
QFileDialog dialog(this);
dialog.setWindowModality(Qt::WindowModal);
dialog.setAcceptMode(QFileDialog::AcceptSave);
- dialog.exec();
- QStringList files = dialog.selectedFiles();
-
- if (files.isEmpty())
+ QStringList files;
+ if (dialog.exec())
+ files = dialog.selectedFiles();
+ else
return false;
return saveFile(files.at(0));
diff --git a/examples/widgets/mainwindows/application/mainwindow.h b/examples/widgets/mainwindows/application/mainwindow.h
index b4d5c10755..828db44dc6 100644
--- a/examples/widgets/mainwindows/application/mainwindow.h
+++ b/examples/widgets/mainwindows/application/mainwindow.h
@@ -58,7 +58,7 @@ public:
MainWindow();
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void newFile();
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
index b39c45118c..e481a71409 100644
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
@@ -101,8 +101,8 @@ class ColorDock : public QFrame
public:
ColorDock(const QString &c, QWidget *parent);
- virtual QSize sizeHint() const;
- virtual QSize minimumSizeHint() const;
+ virtual QSize sizeHint() const Q_DECL_OVERRIDE;
+ virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE;
void setCustomSizeHint(const QSize &size);
@@ -110,7 +110,7 @@ public slots:
void changeSizeHints();
protected:
- void paintEvent(QPaintEvent *);
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
QString color;
QSize szHint, minSzHint;
};
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h
index b83a6ba76a..73f3fbdaa6 100644
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.h
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.h
@@ -85,8 +85,8 @@ public:
void setCustomSizeHint(const QSize &size);
protected:
- virtual void contextMenuEvent(QContextMenuEvent *event);
- virtual void resizeEvent(QResizeEvent *e);
+ virtual void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
+ virtual void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
private:
void allow(Qt::DockWidgetArea area, bool allow);
@@ -120,11 +120,11 @@ class BlueTitleBar : public QWidget
public:
BlueTitleBar(QWidget *parent = 0);
- QSize sizeHint() const { return minimumSizeHint(); }
- QSize minimumSizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE { return minimumSizeHint(); }
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
protected:
- void paintEvent(QPaintEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
public slots:
void updateMask();
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
index fe54f4569a..0a29edee74 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
@@ -109,6 +109,10 @@ void MainWindow::actionTriggered(QAction *action)
void MainWindow::setupToolBar()
{
+#ifdef Q_OS_OSX
+ setUnifiedTitleAndToolBarOnMac(true);
+#endif
+
for (int i = 0; i < 3; ++i) {
ToolBar *tb = new ToolBar(QString::fromLatin1("Tool Bar %1").arg(i + 1), this);
toolBars.append(tb);
@@ -164,6 +168,15 @@ void MainWindow::setupMenuBar()
for (int i = 0; i < toolBars.count(); ++i)
toolBarMenu->addMenu(toolBars.at(i)->menu);
+#ifdef Q_OS_OSX
+ toolBarMenu->addSeparator();
+
+ action = toolBarMenu->addAction(tr("Unified"));
+ action->setCheckable(true);
+ action->setChecked(unifiedTitleAndToolBarOnMac());
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setUnifiedTitleAndToolBarOnMac(bool)));
+#endif
+
dockWidgetMenu = menuBar()->addMenu(tr("&Dock Widgets"));
}
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.h b/examples/widgets/mainwindows/mainwindow/mainwindow.h
index 4f8b65ab3a..d61cd4e267 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.h
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.h
@@ -67,7 +67,7 @@ public:
QWidget *parent = 0, Qt::WindowFlags flags = 0);
protected:
- void showEvent(QShowEvent *event);
+ void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
public slots:
void actionTriggered(QAction *action);
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.h b/examples/widgets/mainwindows/mainwindow/toolbar.h
index 1060e32ce1..b773227eac 100644
--- a/examples/widgets/mainwindows/mainwindow/toolbar.h
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.h
@@ -84,8 +84,8 @@ public:
QMenu *menu;
protected:
- void enterEvent(QEvent*);
- void leaveEvent(QEvent*);
+ void enterEvent(QEvent*) Q_DECL_OVERRIDE;
+ void leaveEvent(QEvent*) Q_DECL_OVERRIDE;
private:
void allow(Qt::ToolBarArea area, bool allow);
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.h b/examples/widgets/mainwindows/mdi/mainwindow.h
index c2d50728b8..b24cdd4db1 100644
--- a/examples/widgets/mainwindows/mdi/mainwindow.h
+++ b/examples/widgets/mainwindows/mdi/mainwindow.h
@@ -60,7 +60,7 @@ public:
MainWindow();
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void newFile();
diff --git a/examples/widgets/mainwindows/mdi/mdichild.h b/examples/widgets/mainwindows/mdi/mdichild.h
index 8fa08f7bf2..fe5fb39478 100644
--- a/examples/widgets/mainwindows/mdi/mdichild.h
+++ b/examples/widgets/mainwindows/mdi/mdichild.h
@@ -59,7 +59,7 @@ public:
QString currentFile() { return curFile; }
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void documentWasModified();
diff --git a/examples/widgets/mainwindows/menus/mainwindow.h b/examples/widgets/mainwindows/menus/mainwindow.h
index fc61ed66b6..0130007b65 100644
--- a/examples/widgets/mainwindows/menus/mainwindow.h
+++ b/examples/widgets/mainwindows/menus/mainwindow.h
@@ -59,7 +59,7 @@ public:
MainWindow();
protected:
- void contextMenuEvent(QContextMenuEvent *event);
+ void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
//! [0]
//! [1]
diff --git a/examples/widgets/mainwindows/sdi/mainwindow.h b/examples/widgets/mainwindows/sdi/mainwindow.h
index 51a2de4a41..dc8498a247 100644
--- a/examples/widgets/mainwindows/sdi/mainwindow.h
+++ b/examples/widgets/mainwindows/sdi/mainwindow.h
@@ -60,7 +60,7 @@ public:
MainWindow(const QString &fileName);
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void newFile();
diff --git a/examples/widgets/painting/affine/xform.h b/examples/widgets/painting/affine/xform.h
index 67ebf43689..46038b29fd 100644
--- a/examples/widgets/painting/affine/xform.h
+++ b/examples/widgets/painting/affine/xform.h
@@ -71,14 +71,14 @@ public:
enum XFormType { VectorType, PixmapType, TextType };
XFormView(QWidget *parent);
- void paint(QPainter *);
+ void paint(QPainter *) Q_DECL_OVERRIDE;
void drawVectorType(QPainter *painter);
void drawPixmapType(QPainter *painter);
void drawTextType(QPainter *painter);
- QSize sizeHint() const { return QSize(500, 500); }
+ QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(500, 500); }
- void mousePressEvent(QMouseEvent *e);
- void resizeEvent(QResizeEvent *e);
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
HoverPoints *hoverPoints() { return pts; }
bool animation() const { return timer.isActive(); }
@@ -115,9 +115,9 @@ signals:
void shearChanged(int shear);
protected:
- void timerEvent(QTimerEvent *e);
+ void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE;
#ifndef QT_NO_WHEELEVENT
- void wheelEvent(QWheelEvent *);
+ void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE;
#endif
private:
diff --git a/examples/widgets/painting/basicdrawing/renderarea.h b/examples/widgets/painting/basicdrawing/renderarea.h
index 3975ddbbe3..e39db21d32 100644
--- a/examples/widgets/painting/basicdrawing/renderarea.h
+++ b/examples/widgets/painting/basicdrawing/renderarea.h
@@ -57,8 +57,8 @@ public:
RenderArea(QWidget *parent = 0);
- QSize minimumSizeHint() const;
- QSize sizeHint() const;
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
public slots:
void setShape(Shape shape);
@@ -68,7 +68,7 @@ public slots:
void setTransformed(bool transformed);
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
Shape shape;
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp
index d89f9d5fb1..a591cafd06 100644
--- a/examples/widgets/painting/composition/composition.cpp
+++ b/examples/widgets/painting/composition/composition.cpp
@@ -127,7 +127,7 @@ CompositionWidget::CompositionWidget(QWidget *parent)
QPushButton *showSourceButton = new QPushButton(mainGroup);
showSourceButton->setText(tr("Show Source"));
-#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+#if defined(USE_OPENGL) && !defined(QT_OPENGL_ES)
QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
enableOpenGLButton->setText(tr("Use OpenGL"));
enableOpenGLButton->setCheckable(true);
@@ -157,7 +157,7 @@ CompositionWidget::CompositionWidget(QWidget *parent)
mainGroupLayout->addWidget(animateButton);
mainGroupLayout->addWidget(whatsThisButton);
mainGroupLayout->addWidget(showSourceButton);
-#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+#if defined(USE_OPENGL) && !defined(QT_OPENGL_ES)
mainGroupLayout->addWidget(enableOpenGLButton);
#endif
@@ -201,7 +201,7 @@ CompositionWidget::CompositionWidget(QWidget *parent)
connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool)));
connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool)));
connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource()));
-#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+#if defined(USE_OPENGL) && !defined(QT_OPENGL_ES)
connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool)));
#endif
connect(animateButton, SIGNAL(toggled(bool)), view, SLOT(setAnimationEnabled(bool)));
@@ -249,7 +249,7 @@ CompositionRenderer::CompositionRenderer(QWidget *parent)
m_circle_pos = QPoint(200, 100);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-#ifdef QT_OPENGL_SUPPORT
+#ifdef USE_OPENGL
m_pbuffer = 0;
m_pbuffer_size = 1024;
#endif
@@ -341,7 +341,7 @@ void CompositionRenderer::drawSource(QPainter &p)
void CompositionRenderer::paint(QPainter *painter)
{
-#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+#if defined(USE_OPENGL) && !defined(QT_OPENGL_ES)
if (usesOpenGL()) {
int new_pbuf_size = m_pbuffer_size;
@@ -511,7 +511,7 @@ void CompositionRenderer::setCirclePos(const QPointF &pos)
const QRect oldRect = rectangle_around(m_circle_pos).toAlignedRect();
m_circle_pos = pos;
const QRect newRect = rectangle_around(m_circle_pos).toAlignedRect();
-#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+#if defined(USE_OPENGL) && !defined(QT_OPENGL_ES)
if (usesOpenGL()) {
update();
return;
diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h
index b52cc51681..610017a5d8 100644
--- a/examples/widgets/painting/composition/composition.h
+++ b/examples/widgets/painting/composition/composition.h
@@ -109,21 +109,21 @@ class CompositionRenderer : public ArthurFrame
public:
CompositionRenderer(QWidget *parent);
- void paint(QPainter *);
+ void paint(QPainter *) Q_DECL_OVERRIDE;
void setCirclePos(const QPointF &pos);
- QSize sizeHint() const { return QSize(500, 400); }
+ QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(500, 400); }
bool animationEnabled() const { return m_animation_enabled; }
int circleColor() const { return m_circle_hue; }
int circleAlpha() const { return m_circle_alpha; }
protected:
- void mousePressEvent(QMouseEvent *);
- void mouseMoveEvent(QMouseEvent *);
- void mouseReleaseEvent(QMouseEvent *);
- void timerEvent(QTimerEvent *);
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
public slots:
void setClearMode() { m_composition_mode = QPainter::CompositionMode_Clear; update(); }
diff --git a/examples/widgets/painting/composition/composition.pro b/examples/widgets/painting/composition/composition.pro
index 0269945ac8..332291c2a4 100644
--- a/examples/widgets/painting/composition/composition.pro
+++ b/examples/widgets/painting/composition/composition.pro
@@ -6,9 +6,9 @@ SHARED_FOLDER = ../shared
include($$SHARED_FOLDER/shared.pri)
RESOURCES += composition.qrc
-qtHaveModule(opengl) {
- DEFINES += QT_OPENGL_SUPPORT
- QT += opengl
+qtHaveModule(opengl): !contains(QT_CONFIG,dynamicgl) {
+ DEFINES += USE_OPENGL
+ QT += opengl
}
QT += widgets
diff --git a/examples/widgets/painting/concentriccircles/circlewidget.h b/examples/widgets/painting/concentriccircles/circlewidget.h
index a1ca3dfe43..f09ab10a48 100644
--- a/examples/widgets/painting/concentriccircles/circlewidget.h
+++ b/examples/widgets/painting/concentriccircles/circlewidget.h
@@ -54,14 +54,14 @@ public:
void setFloatBased(bool floatBased);
void setAntialiased(bool antialiased);
- QSize minimumSizeHint() const;
- QSize sizeHint() const;
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
public slots:
void nextAnimationFrame();
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
bool floatBased;
diff --git a/examples/widgets/painting/deform/pathdeform.h b/examples/widgets/painting/deform/pathdeform.h
index c5c86d1017..f89c5a2c86 100644
--- a/examples/widgets/painting/deform/pathdeform.h
+++ b/examples/widgets/painting/deform/pathdeform.h
@@ -60,14 +60,14 @@ class PathDeformRenderer : public ArthurFrame
public:
explicit PathDeformRenderer(QWidget *widget, bool smallScreen = false);
- void paint(QPainter *painter);
+ void paint(QPainter *painter) Q_DECL_OVERRIDE;
- void mousePressEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent *e);
- void mouseMoveEvent(QMouseEvent *e);
- void timerEvent(QTimerEvent *e);
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE;
- QSize sizeHint() const { return QSize(600, 500); }
+ QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(600, 500); }
bool animated() const { return m_animated; }
int radius() const { return int(m_radius); }
diff --git a/examples/widgets/painting/gradients/gradients.h b/examples/widgets/painting/gradients/gradients.h
index ee719bb3c2..7d9aa9c1e6 100644
--- a/examples/widgets/painting/gradients/gradients.h
+++ b/examples/widgets/painting/gradients/gradients.h
@@ -67,9 +67,9 @@ public:
void setGradientStops(const QGradientStops &stops);
- void paintEvent(QPaintEvent *e);
+ void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
- QSize sizeHint() const { return QSize(150, 40); }
+ QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(150, 40); }
QPolygonF points() const;
HoverPoints *hoverPoints() const { return m_hoverPoints; }
@@ -116,12 +116,12 @@ class GradientRenderer : public ArthurFrame
public:
GradientRenderer(QWidget *parent);
- void paint(QPainter *p);
+ void paint(QPainter *p) Q_DECL_OVERRIDE;
- QSize sizeHint() const { return QSize(400, 400); }
+ QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(400, 400); }
HoverPoints *hoverPoints() const { return m_hoverPoints; }
- void mousePressEvent(QMouseEvent *e);
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
public slots:
void setGradientStops(const QGradientStops &stops);
diff --git a/examples/widgets/painting/painterpaths/renderarea.h b/examples/widgets/painting/painterpaths/renderarea.h
index 02d0adb1ec..be5de5952d 100644
--- a/examples/widgets/painting/painterpaths/renderarea.h
+++ b/examples/widgets/painting/painterpaths/renderarea.h
@@ -52,8 +52,8 @@ class RenderArea : public QWidget
public:
explicit RenderArea(const QPainterPath &path, QWidget *parent = 0);
- QSize minimumSizeHint() const;
- QSize sizeHint() const;
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
public slots:
void setFillRule(Qt::FillRule rule);
@@ -63,7 +63,7 @@ public slots:
void setRotationAngle(int degrees);
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
//! [0]
//! [1]
diff --git a/examples/widgets/painting/pathstroke/pathstroke.h b/examples/widgets/painting/pathstroke/pathstroke.h
index a697101448..d801b05b08 100644
--- a/examples/widgets/painting/pathstroke/pathstroke.h
+++ b/examples/widgets/painting/pathstroke/pathstroke.h
@@ -56,14 +56,14 @@ public:
explicit PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
- void paint(QPainter *);
- void mousePressEvent(QMouseEvent *e);
- void mouseMoveEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent *e);
- void timerEvent(QTimerEvent *e);
- bool event(QEvent *e);
-
- QSize sizeHint() const { return QSize(500, 500); }
+ void paint(QPainter *) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE;
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
+
+ QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(500, 500); }
bool animation() const { return m_timer.isActive(); }
diff --git a/examples/widgets/painting/shared/arthurstyle.h b/examples/widgets/painting/shared/arthurstyle.h
index ede7fe860b..8b78aa14de 100644
--- a/examples/widgets/painting/shared/arthurstyle.h
+++ b/examples/widgets/painting/shared/arthurstyle.h
@@ -54,23 +54,23 @@ public:
void drawHoverRect(QPainter *painter, const QRect &rect) const;
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
- QPainter *painter, const QWidget *widget = 0) const;
+ QPainter *painter, const QWidget *widget = 0) const Q_DECL_OVERRIDE;
void drawControl(ControlElement element, const QStyleOption *option,
- QPainter *painter, const QWidget *widget) const;
+ QPainter *painter, const QWidget *widget) const Q_DECL_OVERRIDE;
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
- QPainter *painter, const QWidget *widget) const;
+ QPainter *painter, const QWidget *widget) const Q_DECL_OVERRIDE;
QSize sizeFromContents(ContentsType type, const QStyleOption *option,
- const QSize &size, const QWidget *widget) const;
+ const QSize &size, const QWidget *widget) const Q_DECL_OVERRIDE;
- QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const;
+ QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const Q_DECL_OVERRIDE;
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
- SubControl sc, const QWidget *widget) const;
+ SubControl sc, const QWidget *widget) const Q_DECL_OVERRIDE;
- int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const;
+ int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const Q_DECL_OVERRIDE;
- void polish(QPalette &palette);
- void polish(QWidget *widget);
- void unpolish(QWidget *widget);
+ void polish(QPalette &palette) Q_DECL_OVERRIDE;
+ void polish(QWidget *widget) Q_DECL_OVERRIDE;
+ void unpolish(QWidget *widget) Q_DECL_OVERRIDE;
};
#endif
diff --git a/examples/widgets/painting/shared/arthurwidgets.h b/examples/widgets/painting/shared/arthurwidgets.h
index 2d96ed63d4..02d0a56656 100644
--- a/examples/widgets/painting/shared/arthurwidgets.h
+++ b/examples/widgets/painting/shared/arthurwidgets.h
@@ -59,9 +59,9 @@ public:
setAttribute(Qt::WA_AcceptTouchEvents);
}
void disableAutoBufferSwap() { setAutoBufferSwap(false); }
- void paintEvent(QPaintEvent *) { parentWidget()->update(); }
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE { parentWidget()->update(); }
protected:
- bool event(QEvent *event)
+ bool event(QEvent *event) Q_DECL_OVERRIDE
{
switch (event->type()) {
case QEvent::TouchBegin:
@@ -117,8 +117,8 @@ signals:
void descriptionEnabledChanged(bool);
protected:
- void paintEvent(QPaintEvent *);
- void resizeEvent(QResizeEvent *);
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
#if defined(QT_OPENGL_SUPPORT)
GLWidget *glw;
diff --git a/examples/widgets/painting/shared/hoverpoints.h b/examples/widgets/painting/shared/hoverpoints.h
index adc920de30..7fa28c79ed 100644
--- a/examples/widgets/painting/shared/hoverpoints.h
+++ b/examples/widgets/painting/shared/hoverpoints.h
@@ -76,7 +76,7 @@ public:
HoverPoints(QWidget *widget, PointShape shape);
- bool eventFilter(QObject *object, QEvent *event);
+ bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
void paintPoints();
diff --git a/examples/widgets/painting/transformations/renderarea.h b/examples/widgets/painting/transformations/renderarea.h
index 214c3803d0..fb814d580c 100644
--- a/examples/widgets/painting/transformations/renderarea.h
+++ b/examples/widgets/painting/transformations/renderarea.h
@@ -65,11 +65,11 @@ public:
void setOperations(const QList<Operation> &operations);
void setShape(const QPainterPath &shape);
- QSize minimumSizeHint() const;
- QSize sizeHint() const;
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
//! [1]
//! [2]
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.h b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
index 3e6e9022c9..88fa469cb5 100644
--- a/examples/widgets/richtext/syntaxhighlighter/highlighter.h
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
@@ -57,7 +57,7 @@ public:
Highlighter(QTextDocument *parent = 0);
protected:
- void highlightBlock(const QString &text);
+ void highlightBlock(const QString &text) Q_DECL_OVERRIDE;
private:
struct HighlightingRule
diff --git a/examples/widgets/richtext/textedit/example.html b/examples/widgets/richtext/textedit/example.html
index cdc8d2a23d..e3a56d1154 100644
--- a/examples/widgets/richtext/textedit/example.html
+++ b/examples/widgets/richtext/textedit/example.html
@@ -5,7 +5,7 @@ p, li { white-space: pre-wrap; }
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">The QTextEdit widget is an advanced editor that supports formatted rich text. It can be used to display HTML and other rich document formats. Internally, QTextEdit uses the QTextDocument class to describe both the high-level structure of each document and the low-level formatting of paragraphs.</span></p>
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">If you are viewing this document in the <span style=" font-style:italic;">textedit</span> example, you can edit this document to explore Qt's rich text editing features. We have included some comments in each of the following sections to encourage you to experiment. </p>
<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:18pt; font-weight:600;"><span style=" font-size:16pt;">Font and Paragraph Styles</span></p>
-<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit supports </span><span style=" font-size:11pt; font-weight:600;">bold</span><span style=" font-size:11pt;">, </span><span style=" font-size:11pt; font-style:italic;">italic</span><span style=" font-size:11pt;">, and </span><span style=" font-size:11pt; text-decoration: underline;">underlined</span><span style=" font-size:11pt;"> font styles, and can display </span><span style=" font-size:11pt; font-weight:600; color:#00007f;">multicolored</span><span style=" font-size:11pt;"> </span><span style=" font-size:11pt; font-weight:600; color:#aa0000;">text</span><span style=" font-size:11pt;">. Font families such as </span><span style=" font-family:'Times'; font-size:11pt; font-weight:600;">Times New Roman</span><span style=" font-size:11pt;"> and </span><span style=" font-family:'Courier'; font-size:11pt; font-weight:600;">Courier</span><span style=" font-size:11pt;"> can also be used directly. </span><span style=" font-size:11pt; font-style:italic;">If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit supports </span><span style=" font-size:11pt; font-weight:600;">bold</span><span style=" font-size:11pt;">, </span><span style=" font-size:11pt; font-style:italic;">italic</span><span style=" font-size:11pt;">, and </span><span style=" font-size:11pt; text-decoration: underline;">underlined</span><span style=" font-size:11pt;"> font styles, and can display </span><span style=" font-size:11pt; font-weight:600; color:#00007f;">multicolored</span><span style=" font-size:11pt;"> </span><span style=" font-size:11pt; font-weight:600; color:#aa0000;">text</span><span style=" font-size:11pt;">. Font families such as </span><span style=" font-family:'Times New Roman'; font-size:11pt; font-weight:600;">Times New Roman</span><span style=" font-size:11pt;"> and </span><span style=" font-family:'Courier'; font-size:11pt; font-weight:600;">Courier</span><span style=" font-size:11pt;"> can also be used directly. </span><span style=" font-size:11pt; font-style:italic;">If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.</span></p>
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.</p>
<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try changing the alignment of some text and resize the editor to see how the text layout changes.</span> </p>
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:16pt; font-weight:600;">Lists</span></p>
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
index 32483bb072..b161c271aa 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -78,6 +78,10 @@ const QString rsrcPath = ":/images/win";
TextEdit::TextEdit(QWidget *parent)
: QMainWindow(parent)
{
+#ifdef Q_OS_OSX
+ setUnifiedTitleAndToolBarOnMac(true);
+#endif
+
setToolButtonStyle(Qt::ToolButtonFollowStyle);
setupFileActions();
setupEditActions();
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
index a19a13e684..a61240599f 100644
--- a/examples/widgets/richtext/textedit/textedit.h
+++ b/examples/widgets/richtext/textedit/textedit.h
@@ -64,7 +64,7 @@ public:
TextEdit(QWidget *parent = 0);
protected:
- virtual void closeEvent(QCloseEvent *e);
+ virtual void closeEvent(QCloseEvent *e) Q_DECL_OVERRIDE;
private:
void setupFileActions();
diff --git a/examples/widgets/scroller/graphicsview/main.cpp b/examples/widgets/scroller/graphicsview/main.cpp
index c17529d7c8..ef81315ca7 100644
--- a/examples/widgets/scroller/graphicsview/main.cpp
+++ b/examples/widgets/scroller/graphicsview/main.cpp
@@ -64,7 +64,7 @@ public:
setFlag(QGraphicsItem::ItemClipsToShape, true);
}
- QRectF boundingRect() const
+ QRectF boundingRect() const Q_DECL_OVERRIDE
{
// here we only want the size of the children and not the size of the children of the children...
qreal halfpw = m_pen.widthF() / 2;
@@ -75,7 +75,7 @@ public:
return rect;
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
{
Q_UNUSED(option);
Q_UNUSED(widget);
@@ -104,7 +104,7 @@ public:
: QGraphicsObject(parent)
{ }
- QRectF boundingRect() const
+ QRectF boundingRect() const Q_DECL_OVERRIDE
{
QRectF rect;
foreach (QGraphicsItem *item, childItems())
@@ -112,7 +112,7 @@ public:
return rect;
}
- void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
+ void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) Q_DECL_OVERRIDE
{ }
};
@@ -140,7 +140,7 @@ public:
return m_viewport;
}
- bool event(QEvent *e)
+ bool event(QEvent *e) Q_DECL_OVERRIDE
{
switch (e->type()) {
// ![2]
@@ -169,7 +169,7 @@ public:
return QGraphicsObject::event(e);
}
- bool sceneEvent(QEvent *e)
+ bool sceneEvent(QEvent *e) Q_DECL_OVERRIDE
{
switch (e->type()) {
case QEvent::TouchBegin: {
@@ -194,12 +194,12 @@ public:
return QGraphicsObject::sceneEvent(e);
}
- QRectF boundingRect() const
+ QRectF boundingRect() const Q_DECL_OVERRIDE
{
return QRectF(0, 0, m_size.width() + 3, m_size.height());
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
{
Q_UNUSED(option);
Q_UNUSED(widget);
@@ -265,7 +265,7 @@ public:
protected:
- void resizeEvent(QResizeEvent *e)
+ void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE
{
// resize the scene according to our own size to prevent scrolling
m_scene->setSceneRect(0, 0, m_view->viewport()->width(), m_view->viewport()->height());
diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp
index 1ad2740563..5e83e27b08 100644
--- a/examples/widgets/statemachine/factorial/main.cpp
+++ b/examples/widgets/statemachine/factorial/main.cpp
@@ -93,7 +93,7 @@ public:
: QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact)
{}
- virtual bool eventTest(QEvent *e)
+ virtual bool eventTest(QEvent *e) Q_DECL_OVERRIDE
{
if (!QSignalTransition::eventTest(e))
return false;
@@ -101,7 +101,7 @@ public:
return se->arguments().at(0).toInt() > 1;
}
- virtual void onTransition(QEvent *e)
+ virtual void onTransition(QEvent *e) Q_DECL_OVERRIDE
{
QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(e);
int x = se->arguments().at(0).toInt();
@@ -123,7 +123,7 @@ public:
: QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact)
{}
- virtual bool eventTest(QEvent *e)
+ virtual bool eventTest(QEvent *e) Q_DECL_OVERRIDE
{
if (!QSignalTransition::eventTest(e))
return false;
@@ -131,7 +131,7 @@ public:
return se->arguments().at(0).toInt() <= 1;
}
- virtual void onTransition(QEvent *)
+ virtual void onTransition(QEvent *) Q_DECL_OVERRIDE
{
fprintf(stdout, "%d\n", m_fact->property("fac").toInt());
}
diff --git a/examples/widgets/statemachine/pingpong/main.cpp b/examples/widgets/statemachine/pingpong/main.cpp
index 869728f993..acb125d54b 100644
--- a/examples/widgets/statemachine/pingpong/main.cpp
+++ b/examples/widgets/statemachine/pingpong/main.cpp
@@ -65,7 +65,7 @@ public:
: QState(parent) {}
protected:
- virtual void onEntry(QEvent *)
+ virtual void onEntry(QEvent *) Q_DECL_OVERRIDE
{
machine()->postEvent(new PingEvent());
fprintf(stdout, "ping?\n");
@@ -80,10 +80,10 @@ public:
PongTransition() {}
protected:
- virtual bool eventTest(QEvent *e) {
+ virtual bool eventTest(QEvent *e) Q_DECL_OVERRIDE {
return (e->type() == QEvent::User+3);
}
- virtual void onTransition(QEvent *)
+ virtual void onTransition(QEvent *) Q_DECL_OVERRIDE
{
machine()->postDelayedEvent(new PingEvent(), 500);
fprintf(stdout, "ping?\n");
@@ -98,10 +98,10 @@ public:
PingTransition() {}
protected:
- virtual bool eventTest(QEvent *e) {
+ virtual bool eventTest(QEvent *e) Q_DECL_OVERRIDE {
return (e->type() == QEvent::User+2);
}
- virtual void onTransition(QEvent *)
+ virtual void onTransition(QEvent *) Q_DECL_OVERRIDE
{
machine()->postDelayedEvent(new PongEvent(), 500);
fprintf(stdout, "pong!\n");
diff --git a/examples/widgets/statemachine/rogue/movementtransition.h b/examples/widgets/statemachine/rogue/movementtransition.h
index 23359f7886..5cfa868b22 100644
--- a/examples/widgets/statemachine/rogue/movementtransition.h
+++ b/examples/widgets/statemachine/rogue/movementtransition.h
@@ -59,7 +59,7 @@ public:
//![1]
protected:
- bool eventTest(QEvent *event) {
+ bool eventTest(QEvent *event) Q_DECL_OVERRIDE {
if (event->type() == QEvent::StateMachineWrapped &&
static_cast<QStateMachine::WrappedEvent *>(event)->event()->type() == QEvent::KeyPress) {
QEvent *wrappedEvent = static_cast<QStateMachine::WrappedEvent *>(event)->event();
@@ -76,7 +76,7 @@ protected:
//![1]
//![2]
- void onTransition(QEvent *event) {
+ void onTransition(QEvent *event) Q_DECL_OVERRIDE {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(
static_cast<QStateMachine::WrappedEvent *>(event)->event());
diff --git a/examples/widgets/statemachine/rogue/window.h b/examples/widgets/statemachine/rogue/window.h
index 71f195cba1..482c8cf111 100644
--- a/examples/widgets/statemachine/rogue/window.h
+++ b/examples/widgets/statemachine/rogue/window.h
@@ -67,10 +67,10 @@ public:
void setStatus(const QString &status);
QString status() const;
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
//![0]
//![1]
diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp
index 5fb6063ca0..62d335a89b 100644
--- a/examples/widgets/statemachine/trafficlight/main.cpp
+++ b/examples/widgets/statemachine/trafficlight/main.cpp
@@ -64,7 +64,7 @@ public slots:
void turnOn() { setOn(true); }
protected:
- virtual void paintEvent(QPaintEvent *)
+ virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
{
if (!m_on)
return;
diff --git a/examples/widgets/tools/completer/fsmodel.h b/examples/widgets/tools/completer/fsmodel.h
index 85b08e532b..690f8b8569 100644
--- a/examples/widgets/tools/completer/fsmodel.h
+++ b/examples/widgets/tools/completer/fsmodel.h
@@ -53,7 +53,7 @@ class FileSystemModel : public QFileSystemModel
{
public:
FileSystemModel(QObject *parent = 0);
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/tools/customcompleter/textedit.h b/examples/widgets/tools/customcompleter/textedit.h
index 362db96749..eb0b307b1c 100644
--- a/examples/widgets/tools/customcompleter/textedit.h
+++ b/examples/widgets/tools/customcompleter/textedit.h
@@ -60,8 +60,8 @@ public:
QCompleter *completer() const;
protected:
- void keyPressEvent(QKeyEvent *e);
- void focusInEvent(QFocusEvent *e);
+ void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
+ void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE;
private slots:
void insertCompletion(const QString &completion);
diff --git a/examples/widgets/tools/echoplugin/plugin/echoplugin.h b/examples/widgets/tools/echoplugin/plugin/echoplugin.h
index fc6818c5be..30d9a673e0 100644
--- a/examples/widgets/tools/echoplugin/plugin/echoplugin.h
+++ b/examples/widgets/tools/echoplugin/plugin/echoplugin.h
@@ -53,7 +53,7 @@ class EchoPlugin : public QObject, EchoInterface
Q_INTERFACES(EchoInterface)
public:
- QString echo(const QString &message);
+ QString echo(const QString &message) Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/tools/i18n/languagechooser.h b/examples/widgets/tools/i18n/languagechooser.h
index a2282cdaf5..3f177a790d 100644
--- a/examples/widgets/tools/i18n/languagechooser.h
+++ b/examples/widgets/tools/i18n/languagechooser.h
@@ -61,8 +61,8 @@ public:
explicit LanguageChooser(const QString& defaultLang = QString(), QWidget *parent = 0);
protected:
- bool eventFilter(QObject *object, QEvent *event);
- void closeEvent(QCloseEvent *event);
+ bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void checkBoxToggled();
diff --git a/examples/widgets/tools/plugandpaint/paintarea.h b/examples/widgets/tools/plugandpaint/paintarea.h
index 84936576cf..214e8c9c0b 100644
--- a/examples/widgets/tools/plugandpaint/paintarea.h
+++ b/examples/widgets/tools/plugandpaint/paintarea.h
@@ -66,13 +66,13 @@ public:
QImage image() const { return theImage; }
QColor brushColor() const { return color; }
int brushWidth() const { return thickness; }
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
protected:
- void paintEvent(QPaintEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
void setupPainter(QPainter &painter);
diff --git a/examples/widgets/tools/plugandpaintplugins/basictools/basictoolsplugin.h b/examples/widgets/tools/plugandpaintplugins/basictools/basictoolsplugin.h
index 55593f6db0..121501a878 100644
--- a/examples/widgets/tools/plugandpaintplugins/basictools/basictoolsplugin.h
+++ b/examples/widgets/tools/plugandpaintplugins/basictools/basictoolsplugin.h
@@ -68,22 +68,22 @@ class BasicToolsPlugin : public QObject,
public:
//! [1]
// BrushInterface
- QStringList brushes() const;
+ QStringList brushes() const Q_DECL_OVERRIDE;
QRect mousePress(const QString &brush, QPainter &painter,
- const QPoint &pos);
+ const QPoint &pos) Q_DECL_OVERRIDE;
QRect mouseMove(const QString &brush, QPainter &painter,
- const QPoint &oldPos, const QPoint &newPos);
+ const QPoint &oldPos, const QPoint &newPos) Q_DECL_OVERRIDE;
QRect mouseRelease(const QString &brush, QPainter &painter,
- const QPoint &pos);
+ const QPoint &pos) Q_DECL_OVERRIDE;
// ShapeInterface
- QStringList shapes() const;
- QPainterPath generateShape(const QString &shape, QWidget *parent);
+ QStringList shapes() const Q_DECL_OVERRIDE;
+ QPainterPath generateShape(const QString &shape, QWidget *parent) Q_DECL_OVERRIDE;
// FilterInterface
- QStringList filters() const;
+ QStringList filters() const Q_DECL_OVERRIDE;
QImage filterImage(const QString &filter, const QImage &image,
- QWidget *parent);
+ QWidget *parent) Q_DECL_OVERRIDE;
//! [3]
};
//! [2] //! [3]
diff --git a/examples/widgets/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h b/examples/widgets/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h
index 6f793b26c6..bc0bae3152 100644
--- a/examples/widgets/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h
+++ b/examples/widgets/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h
@@ -56,9 +56,9 @@ class ExtraFiltersPlugin : public QObject, public FilterInterface
Q_INTERFACES(FilterInterface)
public:
- QStringList filters() const;
+ QStringList filters() const Q_DECL_OVERRIDE;
QImage filterImage(const QString &filter, const QImage &image,
- QWidget *parent);
+ QWidget *parent) Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/tools/settingseditor/settingstree.h b/examples/widgets/tools/settingseditor/settingstree.h
index 24c2266899..663a71c790 100644
--- a/examples/widgets/tools/settingseditor/settingstree.h
+++ b/examples/widgets/tools/settingseditor/settingstree.h
@@ -57,7 +57,7 @@ public:
SettingsTree(QWidget *parent = 0);
void setSettingsObject(QSettings *settings);
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
public slots:
void setAutoRefresh(bool autoRefresh);
@@ -66,7 +66,7 @@ public slots:
void refresh();
protected:
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
private slots:
void updateSetting(QTreeWidgetItem *item);
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h
index 0e23c016da..fed69ef47d 100644
--- a/examples/widgets/tools/settingseditor/variantdelegate.h
+++ b/examples/widgets/tools/settingseditor/variantdelegate.h
@@ -52,12 +52,12 @@ public:
VariantDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
- void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
static bool isSupportedType(QVariant::Type type);
static QString displayText(const QVariant &value);
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.h b/examples/widgets/tools/styleplugin/plugin/simplestyle.h
index 2db04d206f..95c04c5355 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.h
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyle.h
@@ -54,7 +54,7 @@ class SimpleStyle : public QProxyStyle
public:
SimpleStyle() {};
- void polish(QPalette &palette);
+ void polish(QPalette &palette) Q_DECL_OVERRIDE;
};
#endif
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
index 22965de121..77739168e4 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
@@ -58,7 +58,7 @@ public:
SimpleStylePlugin() {}
QStringList keys() const;
- QStyle *create(const QString &key);
+ QStyle *create(const QString &key) Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
index 69d6cdfe78..2f2a45c3d3 100644
--- a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
+++ b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
@@ -58,8 +58,8 @@ public slots:
void setSeparator(const QString &separator);
protected:
- QStringList splitPath(const QString &path) const;
- QString pathFromIndex(const QModelIndex &index) const;
+ QStringList splitPath(const QString &path) const Q_DECL_OVERRIDE;
+ QString pathFromIndex(const QModelIndex &index) const Q_DECL_OVERRIDE;
private:
QString sep;
diff --git a/examples/widgets/tools/undo/commands.h b/examples/widgets/tools/undo/commands.h
index b8984c1d34..f75ac34256 100644
--- a/examples/widgets/tools/undo/commands.h
+++ b/examples/widgets/tools/undo/commands.h
@@ -49,8 +49,8 @@ class AddShapeCommand : public QUndoCommand
{
public:
AddShapeCommand(Document *doc, const Shape &shape, QUndoCommand *parent = 0);
- void undo();
- void redo();
+ void undo() Q_DECL_OVERRIDE;
+ void redo() Q_DECL_OVERRIDE;
private:
Document *m_doc;
@@ -62,8 +62,8 @@ class RemoveShapeCommand : public QUndoCommand
{
public:
RemoveShapeCommand(Document *doc, const QString &shapeName, QUndoCommand *parent = 0);
- void undo();
- void redo();
+ void undo() Q_DECL_OVERRIDE;
+ void redo() Q_DECL_OVERRIDE;
private:
Document *m_doc;
@@ -77,11 +77,11 @@ public:
SetShapeColorCommand(Document *doc, const QString &shapeName, const QColor &color,
QUndoCommand *parent = 0);
- void undo();
- void redo();
+ void undo() Q_DECL_OVERRIDE;
+ void redo() Q_DECL_OVERRIDE;
- bool mergeWith(const QUndoCommand *command);
- int id() const;
+ bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
+ int id() const Q_DECL_OVERRIDE;
private:
Document *m_doc;
@@ -96,11 +96,11 @@ public:
SetShapeRectCommand(Document *doc, const QString &shapeName, const QRect &rect,
QUndoCommand *parent = 0);
- void undo();
- void redo();
+ void undo() Q_DECL_OVERRIDE;
+ void redo() Q_DECL_OVERRIDE;
- bool mergeWith(const QUndoCommand *command);
- int id() const;
+ bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
+ int id() const Q_DECL_OVERRIDE;
private:
Document *m_doc;
diff --git a/examples/widgets/tools/undo/document.h b/examples/widgets/tools/undo/document.h
index 4f362a9597..9246c9320d 100644
--- a/examples/widgets/tools/undo/document.h
+++ b/examples/widgets/tools/undo/document.h
@@ -101,10 +101,10 @@ signals:
void currentShapeChanged(const QString &shapeName);
protected:
- void paintEvent(QPaintEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
void setCurrentShape(int index);
diff --git a/examples/widgets/tools/undoframework/commands.h b/examples/widgets/tools/undoframework/commands.h
index f15e586e91..0e68c5f533 100644
--- a/examples/widgets/tools/undoframework/commands.h
+++ b/examples/widgets/tools/undoframework/commands.h
@@ -54,10 +54,10 @@ public:
MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
QUndoCommand *parent = 0);
- void undo();
- void redo();
- bool mergeWith(const QUndoCommand *command);
- int id() const { return Id; }
+ void undo() Q_DECL_OVERRIDE;
+ void redo() Q_DECL_OVERRIDE;
+ bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
+ int id() const Q_DECL_OVERRIDE { return Id; }
private:
DiagramItem *myDiagramItem;
@@ -72,8 +72,8 @@ class DeleteCommand : public QUndoCommand
public:
explicit DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
- void undo();
- void redo();
+ void undo() Q_DECL_OVERRIDE;
+ void redo() Q_DECL_OVERRIDE;
private:
DiagramItem *myDiagramItem;
@@ -89,8 +89,8 @@ public:
QUndoCommand *parent = 0);
~AddCommand();
- void undo();
- void redo();
+ void undo() Q_DECL_OVERRIDE;
+ void redo() Q_DECL_OVERRIDE;
private:
DiagramItem *myDiagramItem;
diff --git a/examples/widgets/tools/undoframework/diagramitem.h b/examples/widgets/tools/undoframework/diagramitem.h
index 2c115c3b20..44495fc57e 100644
--- a/examples/widgets/tools/undoframework/diagramitem.h
+++ b/examples/widgets/tools/undoframework/diagramitem.h
@@ -61,7 +61,7 @@ public:
DiagramType diagramType() const {
return polygon() == boxPolygon ? Box : Triangle;
}
- int type() const { return Type; }
+ int type() const Q_DECL_OVERRIDE { return Type; }
private:
QPolygonF boxPolygon;
diff --git a/examples/widgets/tools/undoframework/diagramscene.h b/examples/widgets/tools/undoframework/diagramscene.h
index 6ad9647df5..925ab450d2 100644
--- a/examples/widgets/tools/undoframework/diagramscene.h
+++ b/examples/widgets/tools/undoframework/diagramscene.h
@@ -62,8 +62,8 @@ signals:
void itemMoved(DiagramItem *movedItem, const QPointF &movedFromPosition);
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *event);
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
private:
QGraphicsItem *movingItem;
diff --git a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h
index e1dd4be478..d17f409da3 100644
--- a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h
+++ b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h
@@ -50,9 +50,9 @@ class MyModel : public QAbstractTableModel
Q_OBJECT
public:
MyModel(QObject *parent);
- int rowCount(const QModelIndex &parent = QModelIndex()) const ;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
};
//! [Quoting ModelView Tutorial]
diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
index 3ae0b7b009..39e431be41 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
+++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
@@ -48,9 +48,9 @@ class MyModel : public QAbstractTableModel
Q_OBJECT
public:
MyModel(QObject *parent);
- int rowCount(const QModelIndex &parent = QModelIndex()) const ;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
};
#endif // MYMODEL_H
diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h
index d59eddc6bb..56184772bf 100644
--- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h
+++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h
@@ -49,9 +49,9 @@ class MyModel : public QAbstractTableModel
Q_OBJECT
public:
MyModel(QObject *parent);
- int rowCount(const QModelIndex &parent = QModelIndex()) const ;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QTimer *timer;
private:
int selectedCell;
diff --git a/examples/widgets/tutorials/modelview/4_headers/mymodel.h b/examples/widgets/tutorials/modelview/4_headers/mymodel.h
index d8fd1ff10a..3d4992dc48 100644
--- a/examples/widgets/tutorials/modelview/4_headers/mymodel.h
+++ b/examples/widgets/tutorials/modelview/4_headers/mymodel.h
@@ -48,10 +48,10 @@ class MyModel : public QAbstractTableModel
Q_OBJECT
public:
MyModel(QObject *parent);
- int rowCount(const QModelIndex &parent = QModelIndex()) const ;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
};
#endif // MYMODEL_H
diff --git a/examples/widgets/tutorials/modelview/5_edit/mymodel.h b/examples/widgets/tutorials/modelview/5_edit/mymodel.h
index 2aa54ff5ae..be6ebc28c9 100644
--- a/examples/widgets/tutorials/modelview/5_edit/mymodel.h
+++ b/examples/widgets/tutorials/modelview/5_edit/mymodel.h
@@ -55,11 +55,11 @@ class MyModel : public QAbstractTableModel
Q_OBJECT
public:
MyModel(QObject *parent);
- int rowCount(const QModelIndex &parent = QModelIndex()) const ;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
- Qt::ItemFlags flags(const QModelIndex & index) const ;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex & index) const Q_DECL_OVERRIDE ;
private:
QString m_gridData[ROWS][COLS]; //holds text entered into QTableView
signals:
diff --git a/examples/widgets/widgets/analogclock/analogclock.h b/examples/widgets/widgets/analogclock/analogclock.h
index a675e2b05d..9a12277d2f 100644
--- a/examples/widgets/widgets/analogclock/analogclock.h
+++ b/examples/widgets/widgets/analogclock/analogclock.h
@@ -52,7 +52,7 @@ public:
AnalogClock(QWidget *parent = 0);
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/widgets/calculator/button.h b/examples/widgets/widgets/calculator/button.h
index aec6e10af8..7cc28b079c 100644
--- a/examples/widgets/widgets/calculator/button.h
+++ b/examples/widgets/widgets/calculator/button.h
@@ -51,7 +51,7 @@ class Button : public QToolButton
public:
explicit Button(const QString &text, QWidget *parent = 0);
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/widgets/charactermap/characterwidget.h b/examples/widgets/widgets/charactermap/characterwidget.h
index 96bafd4222..d5ba947aa2 100644
--- a/examples/widgets/widgets/charactermap/characterwidget.h
+++ b/examples/widgets/widgets/charactermap/characterwidget.h
@@ -59,7 +59,7 @@ class CharacterWidget : public QWidget
public:
CharacterWidget(QWidget *parent = 0);
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
public slots:
void updateFont(const QFont &font);
@@ -71,9 +71,9 @@ signals:
void characterSelected(const QString &character);
protected:
- void mouseMoveEvent(QMouseEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void paintEvent(QPaintEvent *event);
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
QFont displayFont;
diff --git a/examples/widgets/widgets/codeeditor/codeeditor.h b/examples/widgets/widgets/codeeditor/codeeditor.h
index 8668140728..ac72318654 100644
--- a/examples/widgets/widgets/codeeditor/codeeditor.h
+++ b/examples/widgets/widgets/codeeditor/codeeditor.h
@@ -66,7 +66,7 @@ public:
int lineNumberAreaWidth();
protected:
- void resizeEvent(QResizeEvent *event);
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
@@ -87,12 +87,12 @@ public:
codeEditor = editor;
}
- QSize sizeHint() const {
+ QSize sizeHint() const Q_DECL_OVERRIDE {
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
- void paintEvent(QPaintEvent *event) {
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE {
codeEditor->lineNumberAreaPaintEvent(event);
}
diff --git a/examples/widgets/widgets/elidedlabel/elidedlabel.h b/examples/widgets/widgets/elidedlabel/elidedlabel.h
index cf4aaea14c..409dd777eb 100644
--- a/examples/widgets/widgets/elidedlabel/elidedlabel.h
+++ b/examples/widgets/widgets/elidedlabel/elidedlabel.h
@@ -62,7 +62,7 @@ public:
bool isElided() const { return elided; }
protected:
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
signals:
void elisionChanged(bool elided);
diff --git a/examples/widgets/widgets/elidedlabel/testwidget.h b/examples/widgets/widgets/elidedlabel/testwidget.h
index edc611a0c6..7beb54978f 100644
--- a/examples/widgets/widgets/elidedlabel/testwidget.h
+++ b/examples/widgets/widgets/elidedlabel/testwidget.h
@@ -57,7 +57,7 @@ public:
TestWidget(QWidget *parent = 0);
protected:
- void resizeEvent(QResizeEvent *event);
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private slots:
void switchText();
diff --git a/examples/widgets/widgets/icons/iconsizespinbox.h b/examples/widgets/widgets/icons/iconsizespinbox.h
index fff8a87ff1..a7704e147c 100644
--- a/examples/widgets/widgets/icons/iconsizespinbox.h
+++ b/examples/widgets/widgets/icons/iconsizespinbox.h
@@ -51,8 +51,8 @@ class IconSizeSpinBox : public QSpinBox
public:
IconSizeSpinBox(QWidget *parent = 0);
- int valueFromText(const QString &text) const;
- QString textFromValue(int value) const;
+ int valueFromText(const QString &text) const Q_DECL_OVERRIDE;
+ QString textFromValue(int value) const Q_DECL_OVERRIDE;
};
//! [0]
diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h
index e3777d4130..7d143d2140 100644
--- a/examples/widgets/widgets/icons/imagedelegate.h
+++ b/examples/widgets/widgets/icons/imagedelegate.h
@@ -54,10 +54,10 @@ public:
//! [1]
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
- void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const;
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
//! [1] //! [2]
private slots:
diff --git a/examples/widgets/widgets/mousebuttons/buttontester.h b/examples/widgets/widgets/mousebuttons/buttontester.h
index 156a44e9d0..9e7011ac9a 100644
--- a/examples/widgets/widgets/mousebuttons/buttontester.h
+++ b/examples/widgets/widgets/mousebuttons/buttontester.h
@@ -53,11 +53,11 @@ class ButtonTester : public QTextEdit
Q_OBJECT
protected:
- void mousePressEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
- void mouseDoubleClickEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
#ifndef QT_NO_WHEELEVENT
- void wheelEvent(QWheelEvent * event);
+ void wheelEvent(QWheelEvent * event) Q_DECL_OVERRIDE;
#endif
int buttonByNumber(const Qt::MouseButton button);
QString enumNameFromValue(const Qt::MouseButton button);
diff --git a/examples/widgets/widgets/scribble/mainwindow.h b/examples/widgets/widgets/scribble/mainwindow.h
index 276052c10c..a26976be1b 100644
--- a/examples/widgets/widgets/scribble/mainwindow.h
+++ b/examples/widgets/widgets/scribble/mainwindow.h
@@ -55,7 +55,7 @@ public:
MainWindow();
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void open();
diff --git a/examples/widgets/widgets/scribble/scribblearea.h b/examples/widgets/widgets/scribble/scribblearea.h
index 3b984426a9..f92d41157d 100644
--- a/examples/widgets/widgets/scribble/scribblearea.h
+++ b/examples/widgets/widgets/scribble/scribblearea.h
@@ -68,11 +68,11 @@ public slots:
void print();
protected:
- void mousePressEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *event);
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private:
void drawLineTo(const QPoint &endPoint);
diff --git a/examples/widgets/widgets/shapedclock/shapedclock.h b/examples/widgets/widgets/shapedclock/shapedclock.h
index f98489e9f3..e94963d904 100644
--- a/examples/widgets/widgets/shapedclock/shapedclock.h
+++ b/examples/widgets/widgets/shapedclock/shapedclock.h
@@ -50,13 +50,13 @@ class ShapedClock : public QWidget
public:
ShapedClock(QWidget *parent = 0);
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
protected:
- void mouseMoveEvent(QMouseEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *event);
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private:
QPoint dragPosition;
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.h b/examples/widgets/widgets/styles/norwegianwoodstyle.h
index 0a1ec93b81..e4eebabb79 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.h
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.h
@@ -56,17 +56,17 @@ class NorwegianWoodStyle : public QProxyStyle
public:
NorwegianWoodStyle();
- void polish(QPalette &palette);
- void polish(QWidget *widget);
- void unpolish(QWidget *widget);
+ void polish(QPalette &palette) Q_DECL_OVERRIDE;
+ void polish(QWidget *widget) Q_DECL_OVERRIDE;
+ void unpolish(QWidget *widget) Q_DECL_OVERRIDE;
int pixelMetric(PixelMetric metric, const QStyleOption *option,
- const QWidget *widget) const;
+ const QWidget *widget) const Q_DECL_OVERRIDE;
int styleHint(StyleHint hint, const QStyleOption *option,
- const QWidget *widget, QStyleHintReturn *returnData) const;
+ const QWidget *widget, QStyleHintReturn *returnData) const Q_DECL_OVERRIDE;
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
- QPainter *painter, const QWidget *widget) const;
+ QPainter *painter, const QWidget *widget) const Q_DECL_OVERRIDE;
void drawControl(ControlElement control, const QStyleOption *option,
- QPainter *painter, const QWidget *widget) const;
+ QPainter *painter, const QWidget *widget) const Q_DECL_OVERRIDE;
private:
static void setTexture(QPalette &palette, QPalette::ColorRole role,
diff --git a/examples/widgets/widgets/tablet/tabletapplication.h b/examples/widgets/widgets/tablet/tabletapplication.h
index c6e9ad1355..0e99fd0721 100644
--- a/examples/widgets/widgets/tablet/tabletapplication.h
+++ b/examples/widgets/widgets/tablet/tabletapplication.h
@@ -54,7 +54,7 @@ public:
TabletApplication(int &argv, char **args)
: QApplication(argv, args) {}
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
void setCanvas(TabletCanvas *canvas)
{ myCanvas = canvas; }
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.h b/examples/widgets/widgets/tablet/tabletcanvas.h
index 27f8afcd55..beb3cdc471 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.h
+++ b/examples/widgets/widgets/tablet/tabletcanvas.h
@@ -86,9 +86,9 @@ public:
{ return a > b ? a : b; }
protected:
- void tabletEvent(QTabletEvent *event);
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *event);
+ void tabletEvent(QTabletEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private:
void initPixmap();
diff --git a/examples/widgets/widgets/tetrix/tetrixboard.h b/examples/widgets/widgets/tetrix/tetrixboard.h
index ec4b81e29f..b36ba32fbe 100644
--- a/examples/widgets/widgets/tetrix/tetrixboard.h
+++ b/examples/widgets/widgets/tetrix/tetrixboard.h
@@ -60,8 +60,8 @@ public:
TetrixBoard(QWidget *parent = 0);
void setNextPieceLabel(QLabel *label);
- QSize sizeHint() const;
- QSize minimumSizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
+ QSize minimumSizeHint() const Q_DECL_OVERRIDE;
public slots:
void start();
@@ -73,9 +73,9 @@ signals:
void linesRemovedChanged(int numLines);
protected:
- void paintEvent(QPaintEvent *event);
- void keyPressEvent(QKeyEvent *event);
- void timerEvent(QTimerEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
//! [0]
//! [1]
diff --git a/examples/widgets/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h
index 65c3cd89b2..50a0b1933c 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.h
+++ b/examples/widgets/widgets/tooltips/sortingbox.h
@@ -60,12 +60,12 @@ 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);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private slots:
void createNewCircle();
diff --git a/examples/widgets/widgets/wiggly/dialog.cpp b/examples/widgets/widgets/wiggly/dialog.cpp
index 1279d9d05b..3bb4f60d76 100644
--- a/examples/widgets/widgets/wiggly/dialog.cpp
+++ b/examples/widgets/widgets/wiggly/dialog.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -38,32 +38,26 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include <QtWidgets>
+#include <QLineEdit>
+#include <QVBoxLayout>
#include "dialog.h"
#include "wigglywidget.h"
//! [0]
-Dialog::Dialog(QWidget *parent, bool smallScreen)
+Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
WigglyWidget *wigglyWidget = new WigglyWidget;
QLineEdit *lineEdit = new QLineEdit;
- QVBoxLayout *layout = new QVBoxLayout;
+ QVBoxLayout *layout = new QVBoxLayout(this);
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!"));
- }
+ connect(lineEdit, &QLineEdit::textChanged, wigglyWidget, &WigglyWidget::setText);
+ lineEdit->setText(tr("Hello world!"));
+
setWindowTitle(tr("Wiggly"));
resize(360, 145);
}
diff --git a/examples/widgets/widgets/wiggly/dialog.h b/examples/widgets/widgets/wiggly/dialog.h
index 7355a56887..885671c69e 100644
--- a/examples/widgets/widgets/wiggly/dialog.h
+++ b/examples/widgets/widgets/wiggly/dialog.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -49,7 +49,7 @@ class Dialog : public QDialog
Q_OBJECT
public:
- explicit Dialog(QWidget *parent = 0, bool smallScreen = false);
+ explicit Dialog(QWidget *parent = 0);
};
//! [0]
diff --git a/examples/widgets/widgets/wiggly/main.cpp b/examples/widgets/widgets/wiggly/main.cpp
index df5d5487bc..caf00eb748 100644
--- a/examples/widgets/widgets/wiggly/main.cpp
+++ b/examples/widgets/widgets/wiggly/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -45,14 +45,9 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- bool smallScreen = QApplication::arguments().contains("-small-screen");
+ Dialog dialog;
+ dialog.show();
- Dialog dialog(0, smallScreen);
-
- if (!smallScreen)
- dialog.show();
- else
- dialog.showFullScreen();
return app.exec();
}
diff --git a/examples/widgets/widgets/wiggly/wigglywidget.h b/examples/widgets/widgets/wiggly/wigglywidget.h
index 8f3ed13787..620d8bdebb 100644
--- a/examples/widgets/widgets/wiggly/wigglywidget.h
+++ b/examples/widgets/widgets/wiggly/wigglywidget.h
@@ -56,8 +56,8 @@ public slots:
void setText(const QString &newText) { text = newText; }
protected:
- void paintEvent(QPaintEvent *event);
- void timerEvent(QTimerEvent *event);
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
private:
QBasicTimer timer;
diff --git a/examples/widgets/windowcontainer/windowcontainer.cpp b/examples/widgets/windowcontainer/windowcontainer.cpp
index 42523a53d0..ad19949ee3 100644
--- a/examples/widgets/windowcontainer/windowcontainer.cpp
+++ b/examples/widgets/windowcontainer/windowcontainer.cpp
@@ -63,7 +63,7 @@ public:
{
}
- void render(QPainter *p) {
+ void render(QPainter *p) Q_DECL_OVERRIDE {
QLinearGradient g(0, 0, 0, height());
g.setColorAt(0, QColor("lightsteelblue"));
g.setColorAt(1, Qt::black);
@@ -91,43 +91,43 @@ public:
p->drawPolyline(m_polygon);
}
- void mousePressEvent(QMouseEvent *e) {
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE {
m_mouseDown = true;
m_polygon.clear();
m_polygon.append(e->pos());
renderLater();
}
- void mouseMoveEvent(QMouseEvent *e) {
+ void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE {
if (m_mouseDown) {
m_polygon.append(e->pos());
renderLater();
}
}
- void mouseReleaseEvent(QMouseEvent *e) {
+ void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE {
m_mouseDown = false;
m_polygon.append(e->pos());
renderLater();
}
- void focusInEvent(QFocusEvent *) {
+ void focusInEvent(QFocusEvent *) Q_DECL_OVERRIDE {
m_focus = true;
renderLater();
}
- void focusOutEvent(QFocusEvent *) {
+ void focusOutEvent(QFocusEvent *) Q_DECL_OVERRIDE {
m_focus = false;
m_polygon.clear();
renderLater();
}
- void keyPressEvent(QKeyEvent *e) {
+ void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE {
m_key = e->text();
renderLater();
}
- void keyReleaseEvent(QKeyEvent *) {
+ void keyReleaseEvent(QKeyEvent *) Q_DECL_OVERRIDE {
m_key = QString();
renderLater();
}
diff --git a/examples/xml/saxbookmarks/xbelhandler.h b/examples/xml/saxbookmarks/xbelhandler.h
index 27b7e280db..0646ee796a 100644
--- a/examples/xml/saxbookmarks/xbelhandler.h
+++ b/examples/xml/saxbookmarks/xbelhandler.h
@@ -55,12 +55,12 @@ public:
XbelHandler(QTreeWidget *treeWidget);
bool startElement(const QString &namespaceURI, const QString &localName,
- const QString &qName, const QXmlAttributes &attributes);
+ const QString &qName, const QXmlAttributes &attributes) Q_DECL_OVERRIDE;
bool endElement(const QString &namespaceURI, const QString &localName,
- const QString &qName);
- bool characters(const QString &str);
- bool fatalError(const QXmlParseException &exception);
- QString errorString() const;
+ const QString &qName) Q_DECL_OVERRIDE;
+ bool characters(const QString &str) Q_DECL_OVERRIDE;
+ bool fatalError(const QXmlParseException &exception) Q_DECL_OVERRIDE;
+ QString errorString() const Q_DECL_OVERRIDE;
private:
QTreeWidgetItem *createChildItem(const QString &tagName);