summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt17
-rw-r--r--examples/corelib/CMakeLists.txt7
-rw-r--r--examples/corelib/bindableproperties/CMakeLists.txt35
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/CMakeLists.txt47
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp6
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h2
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/bindableuser.h1
-rw-r--r--examples/corelib/bindableproperties/bindablesubscription/main.cpp41
-rw-r--r--examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc3
-rw-r--r--examples/corelib/bindableproperties/shared/CMakeLists.txt23
-rw-r--r--examples/corelib/bindableproperties/subscription/CMakeLists.txt42
-rw-r--r--examples/corelib/bindableproperties/subscription/main.cpp29
-rw-r--r--examples/corelib/bindableproperties/subscription/subscription.cpp2
-rw-r--r--examples/corelib/ipc/CMakeLists.txt4
-rw-r--r--examples/corelib/ipc/doc/images/localfortuneserver-example.pngbin5715 -> 14948 bytes
-rw-r--r--examples/corelib/ipc/doc/src/localfortuneclient.qdoc8
-rw-r--r--examples/corelib/ipc/doc/src/localfortuneserver.qdoc5
-rw-r--r--examples/corelib/ipc/doc/src/sharedmemory.qdoc7
-rw-r--r--examples/corelib/ipc/localfortuneclient/CMakeLists.txt21
-rw-r--r--examples/corelib/ipc/localfortuneclient/client.cpp29
-rw-r--r--examples/corelib/ipc/localfortuneclient/client.h11
-rw-r--r--examples/corelib/ipc/localfortuneclient/main.cpp4
-rw-r--r--examples/corelib/ipc/localfortuneserver/CMakeLists.txt21
-rw-r--r--examples/corelib/ipc/localfortuneserver/main.cpp4
-rw-r--r--examples/corelib/ipc/localfortuneserver/server.cpp98
-rw-r--r--examples/corelib/ipc/localfortuneserver/server.h24
-rw-r--r--examples/corelib/ipc/sharedmemory/CMakeLists.txt21
-rw-r--r--examples/corelib/ipc/sharedmemory/dialog.cpp9
-rw-r--r--examples/corelib/ipc/sharedmemory/dialog.h11
-rw-r--r--examples/corelib/ipc/sharedmemory/main.cpp3
-rw-r--r--examples/corelib/mimetypes/CMakeLists.txt2
-rw-r--r--examples/corelib/mimetypes/doc/src/mimetypebrowser.qdoc3
-rw-r--r--examples/corelib/mimetypes/mimetypebrowser/CMakeLists.txt21
-rw-r--r--examples/corelib/mimetypes/mimetypebrowser/main.cpp4
-rw-r--r--examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp27
-rw-r--r--examples/corelib/mimetypes/mimetypebrowser/mainwindow.h7
-rw-r--r--examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.h8
-rw-r--r--examples/corelib/permissions/CMakeLists.txt47
-rw-r--r--examples/corelib/permissions/Info.plist59
-rw-r--r--examples/corelib/permissions/android/AndroidManifest.xml53
-rw-r--r--examples/corelib/permissions/main.cpp87
-rw-r--r--examples/corelib/platform/CMakeLists.txt6
-rw-r--r--examples/corelib/platform/androidnotifier/CMakeLists.txt22
-rw-r--r--examples/corelib/platform/androidnotifier/android/AndroidManifest.xml16
-rw-r--r--examples/corelib/platform/androidnotifier/androidnotifier.pro4
-rw-r--r--examples/corelib/platform/androidnotifier/doc/src/androidnotifier-example.qdoc3
-rw-r--r--examples/corelib/platform/androidnotifier/main.cpp4
-rw-r--r--examples/corelib/platform/androidnotifier/notificationclient.cpp12
-rw-r--r--examples/corelib/serialization/CMakeLists.txt11
-rw-r--r--examples/corelib/serialization/cbordump/CMakeLists.txt21
-rwxr-xr-xexamples/corelib/serialization/cbordump/cbortag.py2
-rw-r--r--examples/corelib/serialization/cbordump/doc/src/cbordump.qdoc2
-rw-r--r--examples/corelib/serialization/cbordump/main.cpp94
-rw-r--r--examples/corelib/serialization/convert/CMakeLists.txt25
-rw-r--r--examples/corelib/serialization/convert/cborconverter.cpp101
-rw-r--r--examples/corelib/serialization/convert/cborconverter.h28
-rw-r--r--examples/corelib/serialization/convert/convert.pro16
-rw-r--r--examples/corelib/serialization/convert/converter.cpp44
-rw-r--r--examples/corelib/serialization/convert/converter.h50
-rw-r--r--examples/corelib/serialization/convert/datastreamconverter.cpp131
-rw-r--r--examples/corelib/serialization/convert/datastreamconverter.h28
-rw-r--r--examples/corelib/serialization/convert/debugtextdumper.cpp74
-rw-r--r--examples/corelib/serialization/convert/debugtextdumper.h20
-rw-r--r--examples/corelib/serialization/convert/doc/images/convert.pngbin49201 -> 7707 bytes
-rw-r--r--examples/corelib/serialization/convert/doc/src/convert.qdoc180
-rw-r--r--examples/corelib/serialization/convert/jsonconverter.cpp55
-rw-r--r--examples/corelib/serialization/convert/jsonconverter.h17
-rw-r--r--examples/corelib/serialization/convert/main.cpp206
-rw-r--r--examples/corelib/serialization/convert/nullconverter.cpp41
-rw-r--r--examples/corelib/serialization/convert/nullconverter.h12
-rw-r--r--examples/corelib/serialization/convert/textconverter.cpp52
-rw-r--r--examples/corelib/serialization/convert/textconverter.h14
-rw-r--r--examples/corelib/serialization/convert/variantorderedmap.h24
-rw-r--r--examples/corelib/serialization/convert/xmlconverter.cpp162
-rw-r--r--examples/corelib/serialization/convert/xmlconverter.h15
-rw-r--r--examples/corelib/serialization/savegame/CMakeLists.txt21
-rw-r--r--examples/corelib/serialization/savegame/character.cpp13
-rw-r--r--examples/corelib/serialization/savegame/character.h5
-rw-r--r--examples/corelib/serialization/savegame/doc/src/savegame.qdoc7
-rw-r--r--examples/corelib/serialization/savegame/game.cpp56
-rw-r--r--examples/corelib/serialization/savegame/game.h5
-rw-r--r--examples/corelib/serialization/savegame/level.cpp7
-rw-r--r--examples/corelib/serialization/savegame/level.h1
-rw-r--r--examples/corelib/serialization/serialization.pro2
-rw-r--r--examples/corelib/serialization/streambookmarks/CMakeLists.txt21
-rw-r--r--examples/corelib/serialization/streambookmarks/doc/images/filemenu.pngbin0 -> 3728 bytes
-rw-r--r--examples/corelib/serialization/streambookmarks/doc/images/helpmenu.pngbin0 -> 2099 bytes
-rw-r--r--examples/corelib/serialization/streambookmarks/doc/images/screenshot.pngbin0 -> 66567 bytes
-rw-r--r--examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-filemenu.pngbin9380 -> 0 bytes
-rw-r--r--examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-helpmenu.pngbin10856 -> 0 bytes
-rw-r--r--examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-screenshot.pngbin22323 -> 0 bytes
-rw-r--r--examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc233
-rw-r--r--examples/corelib/serialization/streambookmarks/jennifer.xbel46
-rw-r--r--examples/corelib/serialization/streambookmarks/main.cpp4
-rw-r--r--examples/corelib/serialization/streambookmarks/mainwindow.cpp129
-rw-r--r--examples/corelib/serialization/streambookmarks/mainwindow.h4
-rw-r--r--examples/corelib/serialization/streambookmarks/streambookmarks.pro2
-rw-r--r--examples/corelib/serialization/streambookmarks/xbelreader.cpp114
-rw-r--r--examples/corelib/serialization/streambookmarks/xbelreader.h5
-rw-r--r--examples/corelib/serialization/streambookmarks/xbelwriter.cpp32
-rw-r--r--examples/corelib/threads/CMakeLists.txt8
-rw-r--r--examples/corelib/threads/doc/src/mandelbrot.qdoc5
-rw-r--r--examples/corelib/threads/doc/src/queuedcustomtype.qdoc25
-rw-r--r--examples/corelib/threads/doc/src/semaphores.qdoc12
-rw-r--r--examples/corelib/threads/doc/src/waitconditions.qdoc12
-rw-r--r--examples/corelib/threads/mandelbrot/CMakeLists.txt21
-rw-r--r--examples/corelib/threads/mandelbrot/main.cpp11
-rw-r--r--examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp50
-rw-r--r--examples/corelib/threads/mandelbrot/mandelbrotwidget.h14
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.cpp7
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.h2
-rw-r--r--examples/corelib/threads/queuedcustomtype/CMakeLists.txt21
-rw-r--r--examples/corelib/threads/queuedcustomtype/main.cpp15
-rw-r--r--examples/corelib/threads/queuedcustomtype/renderthread.cpp31
-rw-r--r--examples/corelib/threads/queuedcustomtype/renderthread.h9
-rw-r--r--examples/corelib/threads/queuedcustomtype/window.cpp19
-rw-r--r--examples/corelib/threads/queuedcustomtype/window.h11
-rw-r--r--examples/corelib/threads/semaphores/CMakeLists.txt21
-rw-r--r--examples/corelib/threads/semaphores/semaphores.cpp4
-rw-r--r--examples/corelib/threads/waitconditions/CMakeLists.txt21
-rw-r--r--examples/corelib/tools/CMakeLists.txt4
-rw-r--r--examples/corelib/tools/contiguouscache/CMakeLists.txt21
-rw-r--r--examples/corelib/tools/contiguouscache/randomlistmodel.cpp20
-rw-r--r--examples/corelib/tools/contiguouscache/randomlistmodel.h1
-rw-r--r--examples/corelib/tools/customtype/CMakeLists.txt37
-rw-r--r--examples/corelib/tools/customtype/customtype.pro8
-rw-r--r--examples/corelib/tools/customtype/main.cpp37
-rw-r--r--examples/corelib/tools/customtype/message.cpp38
-rw-r--r--examples/corelib/tools/customtype/message.h38
-rw-r--r--examples/corelib/tools/customtypesending/CMakeLists.txt38
-rw-r--r--examples/corelib/tools/customtypesending/customtypesending.pro10
-rw-r--r--examples/corelib/tools/customtypesending/main.cpp31
-rw-r--r--examples/corelib/tools/customtypesending/message.cpp19
-rw-r--r--examples/corelib/tools/customtypesending/message.h34
-rw-r--r--examples/corelib/tools/customtypesending/window.cpp43
-rw-r--r--examples/corelib/tools/customtypesending/window.h35
-rw-r--r--examples/corelib/tools/doc/src/contiguouscache.qdoc1
-rw-r--r--examples/corelib/tools/doc/src/customtype.qdoc111
-rw-r--r--examples/corelib/tools/tools.pro4
-rw-r--r--examples/dbus/CMakeLists.txt10
-rw-r--r--examples/dbus/chat/CMakeLists.txt21
-rw-r--r--examples/dbus/complexpingpong/CMakeLists.txt28
-rw-r--r--examples/dbus/doc/src/chat.qdoc3
-rw-r--r--examples/dbus/doc/src/complexpingpong.qdoc1
-rw-r--r--examples/dbus/doc/src/pingpong.qdoc1
-rw-r--r--examples/dbus/pingpong/CMakeLists.txt28
-rw-r--r--examples/dbus/remotecontrolledcar/CMakeLists.txt2
-rw-r--r--examples/dbus/remotecontrolledcar/car/CMakeLists.txt21
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.cpp19
-rw-r--r--examples/dbus/remotecontrolledcar/car/main.cpp2
-rw-r--r--examples/dbus/remotecontrolledcar/controller/CMakeLists.txt35
-rw-r--r--examples/dbus/remotecontrolledcar/controller/connected.svg4
-rw-r--r--examples/dbus/remotecontrolledcar/controller/connecting.svg4
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.cpp45
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.h12
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.pro2
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.ui64
-rw-r--r--examples/dbus/remotecontrolledcar/controller/down.svg3
-rw-r--r--examples/dbus/remotecontrolledcar/controller/icons.qrc10
-rw-r--r--examples/dbus/remotecontrolledcar/controller/left.svg3
-rw-r--r--examples/dbus/remotecontrolledcar/controller/right.svg3
-rw-r--r--examples/dbus/remotecontrolledcar/controller/up.svg3
-rw-r--r--examples/dbus/remotecontrolledcar/doc/images/remotecontrolledcar-car-example.webpbin14484 -> 8346 bytes
-rw-r--r--examples/dbus/remotecontrolledcar/doc/src/dbus-remotecontrolledcar.qdoc1
-rw-r--r--examples/dbus/remotecontrolledcar/remotecontrolledcar.pro2
-rw-r--r--examples/embedded/CMakeLists.txt12
-rw-r--r--examples/embedded/digiflip/CMakeLists.txt36
-rw-r--r--examples/embedded/digiflip/digiflip.cpp372
-rw-r--r--examples/embedded/digiflip/digiflip.pro6
-rw-r--r--examples/embedded/embedded.pro7
-rw-r--r--examples/embedded/flickable/CMakeLists.txt37
-rw-r--r--examples/embedded/flickable/flickable.cpp246
-rw-r--r--examples/embedded/flickable/flickable.h40
-rw-r--r--examples/embedded/flickable/flickable.pro7
-rw-r--r--examples/embedded/flickable/main.cpp190
-rw-r--r--examples/embedded/flightinfo/CMakeLists.txt50
-rw-r--r--examples/embedded/flightinfo/aircraft.pngbin20200 -> 0 bytes
-rw-r--r--examples/embedded/flightinfo/flightinfo.cpp354
-rw-r--r--examples/embedded/flightinfo/flightinfo.pro9
-rw-r--r--examples/embedded/flightinfo/flightinfo.qrc5
-rw-r--r--examples/embedded/flightinfo/form.ui226
-rw-r--r--examples/embedded/lightmaps/CMakeLists.txt40
-rw-r--r--examples/embedded/lightmaps/lightmaps.cpp238
-rw-r--r--examples/embedded/lightmaps/lightmaps.h50
-rw-r--r--examples/embedded/lightmaps/lightmaps.pro12
-rw-r--r--examples/embedded/lightmaps/main.cpp18
-rw-r--r--examples/embedded/lightmaps/mapzoom.cpp58
-rw-r--r--examples/embedded/lightmaps/mapzoom.h28
-rw-r--r--examples/embedded/lightmaps/slippymap.cpp164
-rw-r--r--examples/embedded/lightmaps/slippymap.h52
-rw-r--r--examples/embedded/raycasting/CMakeLists.txt48
-rw-r--r--examples/embedded/raycasting/raycasting.cpp336
-rw-r--r--examples/embedded/raycasting/raycasting.pro7
-rw-r--r--examples/embedded/raycasting/raycasting.qrc5
-rw-r--r--examples/embedded/raycasting/textures.pngbin17669 -> 0 bytes
-rw-r--r--examples/embedded/styleexample/CMakeLists.txt56
-rw-r--r--examples/embedded/styleexample/files/add.pngbin1474 -> 0 bytes
-rw-r--r--examples/embedded/styleexample/files/application.qss125
-rw-r--r--examples/embedded/styleexample/files/blue.qss38
-rw-r--r--examples/embedded/styleexample/files/khaki.qss99
-rw-r--r--examples/embedded/styleexample/files/nature_1.jpgbin167443 -> 0 bytes
-rw-r--r--examples/embedded/styleexample/files/nostyle.qss0
-rw-r--r--examples/embedded/styleexample/files/remove.pngbin865 -> 0 bytes
-rw-r--r--examples/embedded/styleexample/files/transparent.qss139
-rw-r--r--examples/embedded/styleexample/main.cpp21
-rw-r--r--examples/embedded/styleexample/styleexample.pro9
-rw-r--r--examples/embedded/styleexample/styleexample.qrc13
-rw-r--r--examples/embedded/styleexample/stylewidget.cpp74
-rw-r--r--examples/embedded/styleexample/stylewidget.h27
-rw-r--r--examples/embedded/styleexample/stylewidget.ui417
-rw-r--r--examples/examples.pro4
-rw-r--r--examples/gui/CMakeLists.txt2
-rw-r--r--examples/gui/doc/src/rasterwindow.qdoc1
-rw-r--r--examples/gui/doc/src/rhiwindow.qdoc6
-rw-r--r--examples/gui/rasterwindow/CMakeLists.txt21
-rw-r--r--examples/gui/rhiwindow/CMakeLists.txt21
-rw-r--r--examples/gui/rhiwindow/main.cpp14
-rw-r--r--examples/gui/rhiwindow/rhiwindow.cpp11
-rw-r--r--examples/network/CMakeLists.txt5
-rw-r--r--examples/network/blockingfortuneclient/CMakeLists.txt21
-rw-r--r--examples/network/broadcastreceiver/CMakeLists.txt21
-rw-r--r--examples/network/broadcastsender/CMakeLists.txt21
-rw-r--r--examples/network/dnslookup/CMakeLists.txt21
-rw-r--r--examples/network/dnslookup/dnslookup.cpp10
-rw-r--r--examples/network/doc/images/dnslookup-example.webpbin0 -> 7532 bytes
-rw-r--r--examples/network/doc/images/multi-stream-client-example.webpbin0 -> 27060 bytes
-rw-r--r--examples/network/doc/images/multi-stream-server-example.webpbin0 -> 19164 bytes
-rw-r--r--examples/network/doc/images/network-chat-example.pngbin17453 -> 0 bytes
-rw-r--r--examples/network/doc/images/network-chat-example.webpbin0 -> 11864 bytes
-rw-r--r--examples/network/doc/images/rsslisting.png (renamed from examples/corelib/serialization/rsslisting/doc/images/rsslisting.png)bin19739 -> 19739 bytes
-rw-r--r--examples/network/doc/images/securesocketclient-example.webpbin0 -> 86522 bytes
-rw-r--r--examples/network/doc/images/securesocketclient.pngbin12056 -> 0 bytes
-rw-r--r--examples/network/doc/images/securesocketclient2.pngbin15532 -> 0 bytes
-rw-r--r--examples/network/doc/images/torrent-example.pngbin18915 -> 11343 bytes
-rw-r--r--examples/network/doc/src/blockingfortuneclient.qdoc2
-rw-r--r--examples/network/doc/src/broadcastreceiver.qdoc4
-rw-r--r--examples/network/doc/src/broadcastsender.qdoc4
-rw-r--r--examples/network/doc/src/dnslookup.qdoc17
-rw-r--r--examples/network/doc/src/fortuneclient.qdoc2
-rw-r--r--examples/network/doc/src/http.qdoc1
-rw-r--r--examples/network/doc/src/multistreamclient.qdoc15
-rw-r--r--examples/network/doc/src/multistreamserver.qdoc16
-rw-r--r--examples/network/doc/src/network-chat.qdoc2
-rw-r--r--examples/network/doc/src/rsslisting.qdoc (renamed from examples/corelib/serialization/rsslisting/doc/src/rsslisting.qdoc)16
-rw-r--r--examples/network/doc/src/securesocketclient.qdoc7
-rw-r--r--examples/network/doc/src/secureudpclient.qdoc1
-rw-r--r--examples/network/doc/src/secureudpserver.qdoc1
-rw-r--r--examples/network/doc/src/torrent.qdoc1
-rw-r--r--examples/network/fortuneclient/CMakeLists.txt21
-rw-r--r--examples/network/fortuneserver/CMakeLists.txt21
-rw-r--r--examples/network/http/CMakeLists.txt21
-rw-r--r--examples/network/multicastreceiver/CMakeLists.txt21
-rw-r--r--examples/network/multicastsender/CMakeLists.txt21
-rw-r--r--examples/network/multistreamclient/CMakeLists.txt21
-rw-r--r--examples/network/multistreamserver/CMakeLists.txt21
-rw-r--r--examples/network/network-chat/CMakeLists.txt21
-rw-r--r--examples/network/network-chat/client.cpp40
-rw-r--r--examples/network/network-chat/client.h4
-rw-r--r--examples/network/network-chat/connection.cpp49
-rw-r--r--examples/network/network-chat/connection.h9
-rw-r--r--examples/network/network-chat/peermanager.cpp26
-rw-r--r--examples/network/network-chat/peermanager.h2
-rw-r--r--examples/network/network.pro14
-rw-r--r--examples/network/rsslisting/CMakeLists.txt (renamed from examples/corelib/serialization/rsslisting/CMakeLists.txt)21
-rw-r--r--examples/network/rsslisting/main.cpp (renamed from examples/corelib/serialization/rsslisting/main.cpp)0
-rw-r--r--examples/network/rsslisting/rsslisting.cpp (renamed from examples/corelib/serialization/rsslisting/rsslisting.cpp)0
-rw-r--r--examples/network/rsslisting/rsslisting.h (renamed from examples/corelib/serialization/rsslisting/rsslisting.h)0
-rw-r--r--examples/network/rsslisting/rsslisting.pro (renamed from examples/corelib/serialization/rsslisting/rsslisting.pro)2
-rw-r--r--examples/network/securesocketclient/CMakeLists.txt21
-rw-r--r--examples/network/securesocketclient/certificateinfo.cpp24
-rw-r--r--examples/network/securesocketclient/main.cpp2
-rw-r--r--examples/network/securesocketclient/sslclient.cpp2
-rw-r--r--examples/network/secureudpclient/CMakeLists.txt21
-rw-r--r--examples/network/secureudpserver/CMakeLists.txt21
-rw-r--r--examples/network/threadedfortuneserver/CMakeLists.txt21
-rw-r--r--examples/network/torrent/CMakeLists.txt38
-rw-r--r--examples/network/torrent/icons.qrc23
-rw-r--r--examples/network/torrent/icons/1downarrow.pngbin895 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/1downarrow.svg3
-rw-r--r--examples/network/torrent/icons/1uparrow.pngbin822 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/1uparrow.svg3
-rw-r--r--examples/network/torrent/icons/about.svg4
-rw-r--r--examples/network/torrent/icons/bottom.pngbin1632 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/bottom.svg6
-rw-r--r--examples/network/torrent/icons/edit_add.pngbin394 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/edit_add.svg4
-rw-r--r--examples/network/torrent/icons/edit_remove.pngbin368 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/edit_remove.svg3
-rw-r--r--examples/network/torrent/icons/exit.pngbin1426 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/exit.svg4
-rw-r--r--examples/network/torrent/icons/peertopeer.pngbin10072 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/peertopeer.svg62
-rw-r--r--examples/network/torrent/icons/player_pause.pngbin690 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/player_pause.svg6
-rw-r--r--examples/network/torrent/icons/player_play.pngbin900 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/player_play.svg3
-rw-r--r--examples/network/torrent/icons/player_stop.pngbin627 -> 0 bytes
-rw-r--r--examples/network/torrent/icons/player_stop.svg5
-rw-r--r--examples/network/torrent/icons/stop.pngbin1252 -> 0 bytes
-rw-r--r--examples/network/torrent/main.cpp2
-rw-r--r--examples/network/torrent/mainwindow.cpp43
-rw-r--r--examples/opengl/2dpainting/CMakeLists.txt21
-rw-r--r--examples/opengl/CMakeLists.txt3
-rw-r--r--examples/opengl/contextinfo/CMakeLists.txt39
-rw-r--r--examples/opengl/contextinfo/contextinfo.pro14
-rw-r--r--examples/opengl/contextinfo/main.cpp25
-rw-r--r--examples/opengl/contextinfo/renderwindow.cpp191
-rw-r--r--examples/opengl/contextinfo/renderwindow.h48
-rw-r--r--examples/opengl/contextinfo/widget.cpp360
-rw-r--r--examples/opengl/contextinfo/widget.h46
-rw-r--r--examples/opengl/cube/CMakeLists.txt21
-rw-r--r--examples/opengl/cube/fshader.glsl2
-rw-r--r--examples/opengl/cube/vshader.glsl2
-rw-r--r--examples/opengl/doc/src/2dpainting.qdoc1
-rw-r--r--examples/opengl/doc/src/cube.qdoc1
-rw-r--r--examples/opengl/doc/src/hellogl2.qdoc1
-rw-r--r--examples/opengl/doc/src/hellogles3.qdoc2
-rw-r--r--examples/opengl/doc/src/openglwindow.qdoc2
-rw-r--r--examples/opengl/doc/src/stereoqopenglwidget.qdoc15
-rw-r--r--examples/opengl/hellogl2/CMakeLists.txt21
-rw-r--r--examples/opengl/hellogl2/mainwindow.cpp18
-rw-r--r--examples/opengl/hellogl2/window.cpp80
-rw-r--r--examples/opengl/hellogl2/window.h6
-rw-r--r--examples/opengl/hellogles3/CMakeLists.txt21
-rw-r--r--examples/opengl/opengl.pro3
-rw-r--r--examples/opengl/openglwindow/CMakeLists.txt21
-rw-r--r--examples/opengl/openglwindow/main.cpp81
-rw-r--r--examples/opengl/stereoqopenglwidget/CMakeLists.txt21
-rw-r--r--examples/opengl/textures/CMakeLists.txt21
-rw-r--r--examples/opengl/textures/main.cpp2
-rw-r--r--examples/qpa/CMakeLists.txt8
-rw-r--r--examples/qpa/qpa.pro5
-rw-r--r--examples/qpa/qrasterwindow/CMakeLists.txt35
-rw-r--r--examples/qpa/qrasterwindow/main.cpp91
-rw-r--r--examples/qpa/qrasterwindow/qrasterwindow.pro4
-rw-r--r--examples/qpa/windows/CMakeLists.txt38
-rw-r--r--examples/qpa/windows/main.cpp50
-rw-r--r--examples/qpa/windows/window.cpp164
-rw-r--r--examples/qpa/windows/window.h41
-rw-r--r--examples/qpa/windows/windows.pro9
-rw-r--r--examples/qtconcurrent/CMakeLists.txt2
-rw-r--r--examples/qtconcurrent/imagescaling/CMakeLists.txt21
-rw-r--r--examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc1
-rw-r--r--examples/qtconcurrent/primecounter/CMakeLists.txt21
-rw-r--r--examples/qtconcurrent/primecounter/doc/src/qtconcurrent-primecounter.qdoc1
-rw-r--r--examples/qtconcurrent/wordcount/CMakeLists.txt21
-rw-r--r--examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc1
-rw-r--r--examples/qtestlib/CMakeLists.txt2
-rw-r--r--examples/qtestlib/tutorial1/CMakeLists.txt21
-rw-r--r--examples/qtestlib/tutorial2/CMakeLists.txt21
-rw-r--r--examples/qtestlib/tutorial3/CMakeLists.txt21
-rw-r--r--examples/qtestlib/tutorial4/CMakeLists.txt21
-rw-r--r--examples/qtestlib/tutorial5/CMakeLists.txt21
-rw-r--r--examples/sql/CMakeLists.txt2
-rw-r--r--examples/sql/books/CMakeLists.txt26
-rw-r--r--examples/sql/books/bookdelegate.cpp50
-rw-r--r--examples/sql/books/bookdelegate.h6
-rw-r--r--examples/sql/books/books.pro1
-rw-r--r--examples/sql/books/books.qrc3
-rw-r--r--examples/sql/books/bookwindow.cpp205
-rw-r--r--examples/sql/books/bookwindow.h38
-rw-r--r--examples/sql/books/bookwindow.ui164
-rw-r--r--examples/sql/books/images/star-filled.svg1
-rw-r--r--examples/sql/books/images/star.pngbin782 -> 0 bytes
-rw-r--r--examples/sql/books/images/star.svg1
-rw-r--r--examples/sql/books/initdb.h4
-rw-r--r--examples/sql/books/main.cpp4
-rw-r--r--examples/sql/cachedtable/CMakeLists.txt21
-rw-r--r--examples/sql/cachedtable/tableeditor.cpp11
-rw-r--r--examples/sql/cachedtable/tableeditor.h8
-rw-r--r--examples/sql/doc/images/books-demo.pngbin14782 -> 13975 bytes
-rw-r--r--examples/sql/doc/images/drilldown-example.pngbin6612 -> 10335 bytes
-rw-r--r--examples/sql/doc/src/books.qdoc1
-rw-r--r--examples/sql/doc/src/cachedtable.qdoc2
-rw-r--r--examples/sql/doc/src/drilldown.qdoc9
-rw-r--r--examples/sql/doc/src/masterdetail.qdoc1
-rw-r--r--examples/sql/doc/src/querymodel.qdoc1
-rw-r--r--examples/sql/doc/src/relationaltablemodel.qdoc1
-rw-r--r--examples/sql/doc/src/sqlbrowser.qdoc1
-rw-r--r--examples/sql/doc/src/sqlwidgetmapper.qdoc12
-rw-r--r--examples/sql/doc/src/tablemodel.qdoc1
-rw-r--r--examples/sql/drilldown/CMakeLists.txt21
-rw-r--r--examples/sql/drilldown/imageitem.cpp6
-rw-r--r--examples/sql/drilldown/imageitem.h3
-rw-r--r--examples/sql/drilldown/images/qt-creator.pngbin6655 -> 8355 bytes
-rw-r--r--examples/sql/drilldown/images/qt-logo.pngbin5527 -> 6650 bytes
-rw-r--r--examples/sql/drilldown/images/qt-project.pngbin16832 -> 8376 bytes
-rw-r--r--examples/sql/drilldown/images/qt-quick.pngbin26635 -> 8029 bytes
-rw-r--r--examples/sql/drilldown/informationwindow.cpp14
-rw-r--r--examples/sql/drilldown/informationwindow.h8
-rw-r--r--examples/sql/drilldown/main.cpp2
-rw-r--r--examples/sql/drilldown/view.cpp4
-rw-r--r--examples/sql/drilldown/view.h3
-rw-r--r--examples/sql/masterdetail/CMakeLists.txt21
-rw-r--r--examples/sql/masterdetail/dialog.cpp39
-rw-r--r--examples/sql/masterdetail/dialog.h27
-rw-r--r--examples/sql/masterdetail/main.cpp4
-rw-r--r--examples/sql/masterdetail/mainwindow.cpp59
-rw-r--r--examples/sql/masterdetail/mainwindow.h29
-rw-r--r--examples/sql/querymodel/CMakeLists.txt21
-rw-r--r--examples/sql/querymodel/customsqlmodel.cpp4
-rw-r--r--examples/sql/querymodel/editablesqlmodel.cpp12
-rw-r--r--examples/sql/querymodel/main.cpp2
-rw-r--r--examples/sql/relationaltablemodel/CMakeLists.txt21
-rw-r--r--examples/sql/sqlbrowser/CMakeLists.txt21
-rw-r--r--examples/sql/sqlbrowser/browser.cpp212
-rw-r--r--examples/sql/sqlbrowser/browser.h66
-rw-r--r--examples/sql/sqlbrowser/connectionwidget.cpp63
-rw-r--r--examples/sql/sqlbrowser/connectionwidget.h9
-rw-r--r--examples/sql/sqlbrowser/main.cpp40
-rw-r--r--examples/sql/sqlbrowser/qsqlconnectiondialog.cpp45
-rw-r--r--examples/sql/sqlbrowser/qsqlconnectiondialog.h17
-rw-r--r--examples/sql/sqlwidgetmapper/CMakeLists.txt21
-rw-r--r--examples/sql/sqlwidgetmapper/window.cpp15
-rw-r--r--examples/sql/sqlwidgetmapper/window.h22
-rw-r--r--examples/sql/tablemodel/CMakeLists.txt21
-rw-r--r--examples/sql/tablemodel/tablemodel.cpp2
-rw-r--r--examples/vulkan/CMakeLists.txt2
-rw-r--r--examples/vulkan/doc/src/hellovulkancubes.qdoc1
-rw-r--r--examples/vulkan/doc/src/hellovulkantriangle.qdoc1
-rw-r--r--examples/vulkan/doc/src/hellovulkanwidget.qdoc1
-rw-r--r--examples/vulkan/hellovulkancubes/CMakeLists.txt21
-rw-r--r--examples/vulkan/hellovulkancubes/mainwindow.cpp2
-rw-r--r--examples/vulkan/hellovulkancubes/renderer.cpp2
-rw-r--r--examples/vulkan/hellovulkantriangle/CMakeLists.txt21
-rw-r--r--examples/vulkan/hellovulkanwidget/CMakeLists.txt21
-rw-r--r--examples/widgets/CMakeLists.txt8
-rw-r--r--examples/widgets/animation/CMakeLists.txt2
-rw-r--r--examples/widgets/animation/easing/CMakeLists.txt21
-rw-r--r--examples/widgets/animation/easing/main.cpp1
-rw-r--r--examples/widgets/desktop/CMakeLists.txt2
-rw-r--r--examples/widgets/desktop/screenshot/CMakeLists.txt21
-rw-r--r--examples/widgets/desktop/systray/CMakeLists.txt21
-rw-r--r--examples/widgets/desktop/systray/doc/images/systemtray-editor.pngbin25407 -> 16137 bytes
-rw-r--r--examples/widgets/desktop/systray/doc/images/systemtray-example.pngbin47588 -> 49858 bytes
-rw-r--r--examples/widgets/desktop/systray/doc/src/systray.qdoc1
-rw-r--r--examples/widgets/desktop/systray/images/bad.pngbin2496 -> 2101 bytes
-rw-r--r--examples/widgets/desktop/systray/images/heart.pngbin25780 -> 1834 bytes
-rw-r--r--examples/widgets/desktop/systray/images/trash.pngbin12128 -> 1285 bytes
-rw-r--r--examples/widgets/desktop/systray/main.cpp2
-rw-r--r--examples/widgets/dialogs/CMakeLists.txt2
-rw-r--r--examples/widgets/dialogs/licensewizard/CMakeLists.txt21
-rw-r--r--examples/widgets/dialogs/licensewizard/main.cpp2
-rw-r--r--examples/widgets/dialogs/standarddialogs/CMakeLists.txt21
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp13
-rw-r--r--examples/widgets/dialogs/tabdialog/CMakeLists.txt21
-rw-r--r--examples/widgets/dialogs/trivialwizard/CMakeLists.txt21
-rw-r--r--examples/widgets/doc/dropsite.qdoc1
-rw-r--r--examples/widgets/doc/images/analogclock-viewport.pngbin29668 -> 176093 bytes
-rw-r--r--examples/widgets/doc/images/calendar-example.pngbin13539 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/draganddroppuzzle-example.pngbin259104 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/echoplugin.pngbin7758 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/echopluginexample.pngbin10610 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/fademessageeffect-example-faded.pngbin81894 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/fademessageeffect-example.pngbin104987 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/fridgemagnets-example.pngbin31707 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/graphicsflowlayout-example.pngbin18988 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/imagegestures-example.jpgbin38962 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/imagegestures-example.pngbin0 -> 300080 bytes
-rw-r--r--examples/widgets/doc/images/imageviewer-fit_to_window_1.pngbin84584 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/imageviewer-fit_to_window_2.pngbin145998 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/imageviewer-original_size.pngbin61567 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/imageviewer-zoom_in_1.pngbin84559 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/imageviewer-zoom_in_2.pngbin85537 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/itemviewspuzzle-example.pngbin196251 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/mainwindow-demo.pngbin85771 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/plugandpaint-plugindialog.pngbin8706 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/plugandpaint.pngbin7540 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/settingseditor-example.pngbin19473 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/stylepluginexample.pngbin15331 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/stylesheet-pagefold.pngbin29118 -> 0 bytes
-rw-r--r--examples/widgets/doc/images/textedit-demo.pngbin46980 -> 0 bytes
-rw-r--r--examples/widgets/doc/src/addressbook.qdoc1
-rw-r--r--examples/widgets/doc/src/affine.qdoc3
-rw-r--r--examples/widgets/doc/src/analogclock.qdoc80
-rw-r--r--examples/widgets/doc/src/application.qdoc370
-rw-r--r--examples/widgets/doc/src/basicdrawing.qdoc1
-rw-r--r--examples/widgets/doc/src/basicgraphicslayouts.qdoc1
-rw-r--r--examples/widgets/doc/src/basiclayouts.qdoc1
-rw-r--r--examples/widgets/doc/src/basicsortfiltermodel.qdoc1
-rw-r--r--examples/widgets/doc/src/blurpicker.qdoc20
-rw-r--r--examples/widgets/doc/src/borderlayout.qdoc46
-rw-r--r--examples/widgets/doc/src/calculator.qdoc1
-rw-r--r--examples/widgets/doc/src/calendar.qdoc202
-rw-r--r--examples/widgets/doc/src/calendarwidget.qdoc1
-rw-r--r--examples/widgets/doc/src/charactermap.qdoc251
-rw-r--r--examples/widgets/doc/src/chart.qdoc58
-rw-r--r--examples/widgets/doc/src/chip.qdoc1
-rw-r--r--examples/widgets/doc/src/collidingmice-example.qdoc1
-rw-r--r--examples/widgets/doc/src/coloreditorfactory.qdoc131
-rw-r--r--examples/widgets/doc/src/combowidgetmapper.qdoc21
-rw-r--r--examples/widgets/doc/src/completer.qdoc5
-rw-r--r--examples/widgets/doc/src/composition.qdoc3
-rw-r--r--examples/widgets/doc/src/concentriccircles.qdoc209
-rw-r--r--examples/widgets/doc/src/cuberhiwidget.qdoc170
-rw-r--r--examples/widgets/doc/src/customsortfiltermodel.qdoc1
-rw-r--r--examples/widgets/doc/src/deform.qdoc1
-rw-r--r--examples/widgets/doc/src/diagramscene.qdoc7
-rw-r--r--examples/widgets/doc/src/digitalclock.qdoc51
-rw-r--r--examples/widgets/doc/src/dirview.qdoc49
-rw-r--r--examples/widgets/doc/src/dockwidgets.qdoc140
-rw-r--r--examples/widgets/doc/src/draganddroppuzzle.qdoc18
-rw-r--r--examples/widgets/doc/src/dragdroprobot.qdoc1
-rw-r--r--examples/widgets/doc/src/draggableicons.qdoc1
-rw-r--r--examples/widgets/doc/src/draggabletext.qdoc1
-rw-r--r--examples/widgets/doc/src/dynamiclayouts.qdoc91
-rw-r--r--examples/widgets/doc/src/easing.qdoc1
-rw-r--r--examples/widgets/doc/src/echoplugin.qdoc181
-rw-r--r--examples/widgets/doc/src/editabletreemodel.qdoc52
-rw-r--r--examples/widgets/doc/src/elasticnodes.qdoc1
-rw-r--r--examples/widgets/doc/src/embeddeddialogs.qdoc15
-rw-r--r--examples/widgets/doc/src/fademessage.qdoc15
-rw-r--r--examples/widgets/doc/src/fetchmore.qdoc1
-rw-r--r--examples/widgets/doc/src/flowlayout.qdoc1
-rw-r--r--examples/widgets/doc/src/fontsampler.qdoc13
-rw-r--r--examples/widgets/doc/src/fridgemagnets.qdoc338
-rw-r--r--examples/widgets/doc/src/frozencolumn.qdoc1
-rw-r--r--examples/widgets/doc/src/gallery.qdoc1
-rw-r--r--examples/widgets/doc/src/gradients.qdoc1
-rw-r--r--examples/widgets/doc/src/graphicsview-flowlayout.qdoc28
-rw-r--r--examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc1
-rw-r--r--examples/widgets/doc/src/groupbox.qdoc116
-rw-r--r--examples/widgets/doc/src/icons.qdoc805
-rw-r--r--examples/widgets/doc/src/imagecomposition.qdoc1
-rw-r--r--examples/widgets/doc/src/imageviewer.qdoc320
-rw-r--r--examples/widgets/doc/src/interview.qdoc15
-rw-r--r--examples/widgets/doc/src/itemviewspuzzle.qdoc19
-rw-r--r--examples/widgets/doc/src/licensewizard.qdoc1
-rw-r--r--examples/widgets/doc/src/lineedits.qdoc1
-rw-r--r--examples/widgets/doc/src/mainwindow.qdoc13
-rw-r--r--examples/widgets/doc/src/mdi.qdoc14
-rw-r--r--examples/widgets/doc/src/menus.qdoc4
-rw-r--r--examples/widgets/doc/src/movie.qdoc16
-rw-r--r--examples/widgets/doc/src/orderform.qdoc1
-rw-r--r--examples/widgets/doc/src/painterpaths.qdoc12
-rw-r--r--examples/widgets/doc/src/pathstroke.qdoc1
-rw-r--r--examples/widgets/doc/src/pixelator.qdoc231
-rw-r--r--examples/widgets/doc/src/plugandpaint.qdoc527
-rw-r--r--examples/widgets/doc/src/regularexpression.qdoc1
-rw-r--r--examples/widgets/doc/src/screenshot.qdoc1
-rw-r--r--examples/widgets/doc/src/scribble.qdoc1
-rw-r--r--examples/widgets/doc/src/settingseditor.qdoc14
-rw-r--r--examples/widgets/doc/src/shapedclock.qdoc1
-rw-r--r--examples/widgets/doc/src/shortcuteditor.qdoc1
-rw-r--r--examples/widgets/doc/src/simpledommodel.qdoc256
-rw-r--r--examples/widgets/doc/src/simplerhiwidget.qdoc204
-rw-r--r--examples/widgets/doc/src/simpletreemodel.qdoc59
-rw-r--r--examples/widgets/doc/src/simplewidgetmapper.qdoc101
-rw-r--r--examples/widgets/doc/src/sliders.qdoc89
-rw-r--r--examples/widgets/doc/src/spinboxdelegate.qdoc117
-rw-r--r--examples/widgets/doc/src/spinboxes.qdoc1
-rw-r--r--examples/widgets/doc/src/spreadsheet.qdoc1
-rw-r--r--examples/widgets/doc/src/standarddialogs.qdoc1
-rw-r--r--examples/widgets/doc/src/stardelegate.qdoc1
-rw-r--r--examples/widgets/doc/src/styleplugin.qdoc139
-rw-r--r--examples/widgets/doc/src/styles.qdoc448
-rw-r--r--examples/widgets/doc/src/stylesheet.qdoc64
-rw-r--r--examples/widgets/doc/src/syntaxhighlighter.qdoc1
-rw-r--r--examples/widgets/doc/src/tabdialog.qdoc1
-rw-r--r--examples/widgets/doc/src/tablet.qdoc7
-rw-r--r--examples/widgets/doc/src/tetrix.qdoc407
-rw-r--r--examples/widgets/doc/src/textedit.qdoc15
-rw-r--r--examples/widgets/doc/src/tooltips.qdoc374
-rw-r--r--examples/widgets/doc/src/transformations.qdoc1
-rw-r--r--examples/widgets/doc/src/treemodelcompleter.qdoc1
-rw-r--r--examples/widgets/doc/src/trivialwizard.qdoc1
-rw-r--r--examples/widgets/doc/src/undoframework.qdoc1
-rw-r--r--examples/widgets/doc/src/validators.qdoc11
-rw-r--r--examples/widgets/doc/src/windowflags.qdoc1
-rw-r--r--examples/widgets/draganddrop/CMakeLists.txt4
-rw-r--r--examples/widgets/draganddrop/draganddrop.pro4
-rw-r--r--examples/widgets/draganddrop/draggableicons/CMakeLists.txt26
-rw-r--r--examples/widgets/draganddrop/draggableicons/draggableicons.pro4
-rw-r--r--examples/widgets/draganddrop/draggableicons/main.cpp2
-rw-r--r--examples/widgets/draganddrop/draggabletext/CMakeLists.txt25
-rw-r--r--examples/widgets/draganddrop/draggabletext/draggabletext.pro3
-rw-r--r--examples/widgets/draganddrop/draggabletext/main.cpp2
-rw-r--r--examples/widgets/draganddrop/draggabletext/words.txt64
-rw-r--r--examples/widgets/draganddrop/dropsite/CMakeLists.txt21
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt50
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/draglabel.cpp51
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/draglabel.h27
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp176
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.h28
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro12
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc5
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/main.cpp25
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/words.txt48
-rw-r--r--examples/widgets/draganddrop/puzzle/CMakeLists.txt51
-rw-r--r--examples/widgets/draganddrop/puzzle/example.jpgbin42654 -> 0 bytes
-rw-r--r--examples/widgets/draganddrop/puzzle/main.cpp17
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.cpp118
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.h40
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.cpp87
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.h28
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.pro17
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.qrc5
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.cpp167
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.h56
-rw-r--r--examples/widgets/effects/CMakeLists.txt2
-rw-r--r--examples/widgets/effects/blurpicker/CMakeLists.txt58
-rw-r--r--examples/widgets/effects/blurpicker/blureffect.cpp31
-rw-r--r--examples/widgets/effects/blurpicker/blureffect.h29
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.cpp122
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.h38
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.pro9
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.qrc14
-rw-r--r--examples/widgets/effects/blurpicker/images/README.txt5
-rw-r--r--examples/widgets/effects/blurpicker/images/accessories-calculator.pngbin3760 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/accessories-text-editor.pngbin4746 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/background.jpgbin16259 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/help-browser.pngbin5392 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/internet-group-chat.pngbin2809 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/internet-mail.pngbin3899 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/internet-web-browser.pngbin6376 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/office-calendar.pngbin4010 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/system-users.pngbin5353 -> 0 bytes
-rw-r--r--examples/widgets/effects/blurpicker/main.cpp18
-rw-r--r--examples/widgets/effects/effects.pro5
-rw-r--r--examples/widgets/effects/fademessage/CMakeLists.txt49
-rw-r--r--examples/widgets/effects/fademessage/README2
-rw-r--r--examples/widgets/effects/fademessage/background.jpgbin159108 -> 0 bytes
-rw-r--r--examples/widgets/effects/fademessage/fademessage.cpp91
-rw-r--r--examples/widgets/effects/fademessage/fademessage.h33
-rw-r--r--examples/widgets/effects/fademessage/fademessage.pro9
-rw-r--r--examples/widgets/effects/fademessage/fademessage.qrc5
-rw-r--r--examples/widgets/effects/fademessage/main.cpp18
-rw-r--r--examples/widgets/gallery/CMakeLists.txt21
-rw-r--r--examples/widgets/gallery/main.cpp1
-rw-r--r--examples/widgets/gallery/widgetgallery.cpp24
-rw-r--r--examples/widgets/gestures/CMakeLists.txt2
-rw-r--r--examples/widgets/gestures/imagegestures/CMakeLists.txt21
-rw-r--r--examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc3
-rw-r--r--examples/widgets/gestures/imagegestures/imagewidget.cpp38
-rw-r--r--examples/widgets/gestures/imagegestures/imagewidget.h7
-rw-r--r--examples/widgets/graphicsview/CMakeLists.txt4
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/CMakeLists.txt21
-rw-r--r--examples/widgets/graphicsview/chip/CMakeLists.txt21
-rw-r--r--examples/widgets/graphicsview/chip/main.cpp2
-rw-r--r--examples/widgets/graphicsview/collidingmice/CMakeLists.txt21
-rw-r--r--examples/widgets/graphicsview/diagramscene/CMakeLists.txt21
-rw-r--r--examples/widgets/graphicsview/diagramscene/main.cpp2
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/CMakeLists.txt21
-rw-r--r--examples/widgets/graphicsview/elasticnodes/CMakeLists.txt21
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt50
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpgbin30730 -> 0 bytes
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp133
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.h39
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp70
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h33
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui88
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro18
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc5
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/main.cpp43
-rw-r--r--examples/widgets/graphicsview/flowlayout/CMakeLists.txt38
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.cpp170
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h44
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.pro10
-rw-r--r--examples/widgets/graphicsview/flowlayout/main.cpp24
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.cpp24
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.h16
-rw-r--r--examples/widgets/graphicsview/graphicsview.pro2
-rw-r--r--examples/widgets/graphicsview/simpleanchorlayout/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/CMakeLists.txt18
-rw-r--r--examples/widgets/itemviews/addressbook/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.cpp5
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/chart/CMakeLists.txt56
-rw-r--r--examples/widgets/itemviews/chart/chart.pro14
-rw-r--r--examples/widgets/itemviews/chart/chart.qrc5
-rw-r--r--examples/widgets/itemviews/chart/main.cpp16
-rw-r--r--examples/widgets/itemviews/chart/mainwindow.cpp136
-rw-r--r--examples/widgets/itemviews/chart/mainwindow.h34
-rw-r--r--examples/widgets/itemviews/chart/pieview.cpp506
-rw-r--r--examples/widgets/itemviews/chart/pieview.h66
-rw-r--r--examples/widgets/itemviews/chart/qtdata.cht14
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt38
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro12
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp39
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h32
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/main.cpp16
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/window.cpp55
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/window.h20
-rw-r--r--examples/widgets/itemviews/combowidgetmapper/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/dirview/CMakeLists.txt36
-rw-r--r--examples/widgets/itemviews/dirview/dirview.pro8
-rw-r--r--examples/widgets/itemviews/dirview/main.cpp62
-rw-r--r--examples/widgets/itemviews/editabletreemodel/CMakeLists.txt55
-rw-r--r--examples/widgets/itemviews/editabletreemodel/default.txt10
-rw-r--r--examples/widgets/itemviews/editabletreemodel/main.cpp7
-rw-r--r--examples/widgets/itemviews/editabletreemodel/mainwindow.cpp9
-rw-r--r--examples/widgets/itemviews/editabletreemodel/test.cpp37
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treeitem.cpp84
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treeitem.h11
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treemodel.cpp108
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treemodel.h22
-rw-r--r--examples/widgets/itemviews/fetchmore/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/flattreeview/CMakeLists.txt36
-rw-r--r--examples/widgets/itemviews/flattreeview/flattreeview.pro7
-rw-r--r--examples/widgets/itemviews/flattreeview/main.cpp37
-rw-r--r--examples/widgets/itemviews/frozencolumn/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/frozencolumn/main.cpp3
-rw-r--r--examples/widgets/itemviews/interview/CMakeLists.txt51
-rw-r--r--examples/widgets/itemviews/interview/README2
-rw-r--r--examples/widgets/itemviews/interview/images/folder.pngbin3910 -> 0 bytes
-rw-r--r--examples/widgets/itemviews/interview/images/interview.pngbin174 -> 0 bytes
-rw-r--r--examples/widgets/itemviews/interview/images/services.pngbin3749 -> 0 bytes
-rw-r--r--examples/widgets/itemviews/interview/interview.pro16
-rw-r--r--examples/widgets/itemviews/interview/interview.qrc7
-rw-r--r--examples/widgets/itemviews/interview/main.cpp57
-rw-r--r--examples/widgets/itemviews/interview/model.cpp110
-rw-r--r--examples/widgets/itemviews/interview/model.h53
-rw-r--r--examples/widgets/itemviews/itemviews.pro15
-rw-r--r--examples/widgets/itemviews/pixelator/CMakeLists.txt58
-rw-r--r--examples/widgets/itemviews/pixelator/imagemodel.cpp53
-rw-r--r--examples/widgets/itemviews/pixelator/imagemodel.h31
-rw-r--r--examples/widgets/itemviews/pixelator/images.qrc5
-rw-r--r--examples/widgets/itemviews/pixelator/images/qt.pngbin1506 -> 0 bytes
-rw-r--r--examples/widgets/itemviews/pixelator/main.cpp17
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.cpp214
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.h37
-rw-r--r--examples/widgets/itemviews/pixelator/pixelator.pro16
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.cpp68
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.h41
-rw-r--r--examples/widgets/itemviews/puzzle/CMakeLists.txt51
-rw-r--r--examples/widgets/itemviews/puzzle/example.jpgbin42654 -> 0 bytes
-rw-r--r--examples/widgets/itemviews/puzzle/main.cpp17
-rw-r--r--examples/widgets/itemviews/puzzle/mainwindow.cpp115
-rw-r--r--examples/widgets/itemviews/puzzle/mainwindow.h41
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.cpp168
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.h45
-rw-r--r--examples/widgets/itemviews/puzzle/puzzle.pro15
-rw-r--r--examples/widgets/itemviews/puzzle/puzzle.qrc5
-rw-r--r--examples/widgets/itemviews/puzzle/puzzlewidget.cpp163
-rw-r--r--examples/widgets/itemviews/puzzle/puzzlewidget.h56
-rw-r--r--examples/widgets/itemviews/simpledommodel/CMakeLists.txt40
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.cpp62
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.h29
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.cpp153
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.h38
-rw-r--r--examples/widgets/itemviews/simpledommodel/main.cpp15
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.cpp47
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.h33
-rw-r--r--examples/widgets/itemviews/simpledommodel/simpledommodel.pro14
-rw-r--r--examples/widgets/itemviews/simpletreemodel/CMakeLists.txt55
-rw-r--r--examples/widgets/itemviews/simpletreemodel/default.txt10
-rw-r--r--examples/widgets/itemviews/simpletreemodel/main.cpp20
-rw-r--r--examples/widgets/itemviews/simpletreemodel/test.cpp35
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treeitem.cpp54
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treeitem.h9
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treemodel.cpp125
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treemodel.h14
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/CMakeLists.txt37
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/main.cpp14
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro10
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/window.cpp93
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/window.h47
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/CMakeLists.txt37
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/delegate.cpp66
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/delegate.h29
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/main.cpp48
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro10
-rw-r--r--examples/widgets/itemviews/spreadsheet/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/spreadsheet/main.cpp4
-rw-r--r--examples/widgets/itemviews/stardelegate/CMakeLists.txt21
-rw-r--r--examples/widgets/itemviews/storageview/CMakeLists.txt37
-rw-r--r--examples/widgets/itemviews/storageview/main.cpp32
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.cpp164
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.h46
-rw-r--r--examples/widgets/itemviews/storageview/storageview.pro12
-rw-r--r--examples/widgets/layouts/CMakeLists.txt4
-rw-r--r--examples/widgets/layouts/basiclayouts/CMakeLists.txt21
-rw-r--r--examples/widgets/layouts/borderlayout/CMakeLists.txt38
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.cpp171
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.h50
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.pro11
-rw-r--r--examples/widgets/layouts/borderlayout/main.cpp14
-rw-r--r--examples/widgets/layouts/borderlayout/window.cpp31
-rw-r--r--examples/widgets/layouts/borderlayout/window.h24
-rw-r--r--examples/widgets/layouts/dynamiclayouts/CMakeLists.txt37
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.cpp136
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.h53
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro10
-rw-r--r--examples/widgets/layouts/dynamiclayouts/main.cpp15
-rw-r--r--examples/widgets/layouts/flowlayout/CMakeLists.txt21
-rw-r--r--examples/widgets/layouts/layouts.pro2
-rw-r--r--examples/widgets/mainwindows/CMakeLists.txt6
-rw-r--r--examples/widgets/mainwindows/application/CMakeLists.txt54
-rw-r--r--examples/widgets/mainwindows/application/application.pro13
-rw-r--r--examples/widgets/mainwindows/application/application.qrc10
-rw-r--r--examples/widgets/mainwindows/application/images/copy.pngbin1338 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/cut.pngbin1323 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/new.pngbin852 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/open.pngbin2073 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/paste.pngbin1645 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/save.pngbin2699 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/application/main.cpp32
-rw-r--r--examples/widgets/mainwindows/application/mainwindow.cpp370
-rw-r--r--examples/widgets/mainwindows/application/mainwindow.h55
-rw-r--r--examples/widgets/mainwindows/dockwidgets/CMakeLists.txt59
-rw-r--r--examples/widgets/mainwindows/dockwidgets/dockwidgets.pro12
-rw-r--r--examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc8
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/new.pngbin977 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/print.pngbin1732 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/save.pngbin1894 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/undo.pngbin1768 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/main.cpp15
-rw-r--r--examples/widgets/mainwindows/dockwidgets/mainwindow.cpp298
-rw-r--r--examples/widgets/mainwindows/dockwidgets/mainwindow.h46
-rw-r--r--examples/widgets/mainwindows/mainwindow/CMakeLists.txt54
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.cpp685
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.h102
-rw-r--r--examples/widgets/mainwindows/mainwindow/main.cpp147
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.cpp444
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.h50
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.pro16
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.qrc8
-rw-r--r--examples/widgets/mainwindows/mainwindow/qt.pngbin2991 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/titlebarCenter.pngbin146 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/titlebarLeft.pngbin5148 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/titlebarRight.pngbin2704 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.cpp308
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.h74
-rw-r--r--examples/widgets/mainwindows/mainwindows.pro6
-rw-r--r--examples/widgets/mainwindows/mdi/CMakeLists.txt55
-rw-r--r--examples/widgets/mainwindows/mdi/images/copy.pngbin1338 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/cut.pngbin1323 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/new.pngbin852 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/open.pngbin2073 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/paste.pngbin1645 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/save.pngbin2699 -> 0 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/main.cpp31
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.cpp461
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.h84
-rw-r--r--examples/widgets/mainwindows/mdi/mdi.pro13
-rw-r--r--examples/widgets/mainwindows/mdi/mdi.qrc10
-rw-r--r--examples/widgets/mainwindows/mdi/mdichild.cpp150
-rw-r--r--examples/widgets/mainwindows/mdi/mdichild.h39
-rw-r--r--examples/widgets/mainwindows/menus/CMakeLists.txt21
-rw-r--r--examples/widgets/mainwindows/menus/mainwindow.cpp51
-rw-r--r--examples/widgets/painting/CMakeLists.txt6
-rw-r--r--examples/widgets/painting/affine/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/affine/main.cpp2
-rw-r--r--examples/widgets/painting/affine/xform.cpp12
-rw-r--r--examples/widgets/painting/basicdrawing/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/basicdrawing/main.cpp2
-rw-r--r--examples/widgets/painting/composition/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/composition/composition.cpp117
-rw-r--r--examples/widgets/painting/composition/composition.h13
-rw-r--r--examples/widgets/painting/concentriccircles/CMakeLists.txt38
-rw-r--r--examples/widgets/painting/concentriccircles/circlewidget.cpp84
-rw-r--r--examples/widgets/painting/concentriccircles/circlewidget.h36
-rw-r--r--examples/widgets/painting/concentriccircles/concentriccircles.pro11
-rw-r--r--examples/widgets/painting/concentriccircles/main.cpp14
-rw-r--r--examples/widgets/painting/concentriccircles/window.cpp56
-rw-r--r--examples/widgets/painting/concentriccircles/window.h33
-rw-r--r--examples/widgets/painting/deform/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/deform/main.cpp2
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp74
-rw-r--r--examples/widgets/painting/fontsampler/CMakeLists.txt45
-rw-r--r--examples/widgets/painting/fontsampler/fontsampler.pro12
-rw-r--r--examples/widgets/painting/fontsampler/main.cpp14
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.cpp314
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.h54
-rw-r--r--examples/widgets/painting/fontsampler/mainwindowbase.ui142
-rw-r--r--examples/widgets/painting/gradients/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp14
-rw-r--r--examples/widgets/painting/gradients/main.cpp2
-rw-r--r--examples/widgets/painting/imagecomposition/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/imagecomposition/main.cpp2
-rw-r--r--examples/widgets/painting/painterpaths/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/painting.pro4
-rw-r--r--examples/widgets/painting/pathstroke/CMakeLists.txt21
-rw-r--r--examples/widgets/painting/pathstroke/main.cpp2
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.cpp27
-rw-r--r--examples/widgets/painting/shared/CMakeLists.txt14
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.cpp80
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.h17
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.cpp75
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.h46
-rw-r--r--examples/widgets/painting/shared/hoverpoints.cpp23
-rw-r--r--examples/widgets/painting/shared/shared.pri6
-rw-r--r--examples/widgets/painting/shared/use_lib.cmake6
-rw-r--r--examples/widgets/painting/transformations/CMakeLists.txt21
-rw-r--r--examples/widgets/qnx/foreignwindows/collector.cpp2
-rw-r--r--examples/widgets/qnx/foreignwindows/collector.h2
-rw-r--r--examples/widgets/qnx/foreignwindows/main.cpp2
-rw-r--r--examples/widgets/rhi/CMakeLists.txt8
-rw-r--r--examples/widgets/rhi/cuberhiwidget/CMakeLists.txt48
-rw-r--r--examples/widgets/rhi/cuberhiwidget/cube.h139
-rw-r--r--examples/widgets/rhi/cuberhiwidget/cuberhiwidget.pro12
-rw-r--r--examples/widgets/rhi/cuberhiwidget/cuberhiwidget.qrc6
-rw-r--r--examples/widgets/rhi/cuberhiwidget/examplewidget.cpp172
-rw-r--r--examples/widgets/rhi/cuberhiwidget/examplewidget.h72
-rw-r--r--examples/widgets/rhi/cuberhiwidget/main.cpp166
-rw-r--r--examples/widgets/rhi/cuberhiwidget/shader_assets/texture.frag.qsbbin0 -> 1042 bytes
-rw-r--r--examples/widgets/rhi/cuberhiwidget/shader_assets/texture.vert.qsbbin0 -> 1161 bytes
-rw-r--r--examples/widgets/rhi/cuberhiwidget/shaders/texture.frag12
-rw-r--r--examples/widgets/rhi/cuberhiwidget/shaders/texture.vert15
-rw-r--r--examples/widgets/rhi/rhi.pro4
-rw-r--r--examples/widgets/rhi/simplerhiwidget/CMakeLists.txt48
-rw-r--r--examples/widgets/rhi/simplerhiwidget/examplewidget.cpp102
-rw-r--r--examples/widgets/rhi/simplerhiwidget/examplewidget.h30
-rw-r--r--examples/widgets/rhi/simplerhiwidget/main.cpp26
-rw-r--r--examples/widgets/rhi/simplerhiwidget/shader_assets/color.frag.qsbbin0 -> 738 bytes
-rw-r--r--examples/widgets/rhi/simplerhiwidget/shader_assets/color.vert.qsbbin0 -> 1091 bytes
-rw-r--r--examples/widgets/rhi/simplerhiwidget/shaders/color.frag10
-rw-r--r--examples/widgets/rhi/simplerhiwidget/shaders/color.vert16
-rw-r--r--examples/widgets/rhi/simplerhiwidget/simplerhiwidget.pro12
-rw-r--r--examples/widgets/rhi/simplerhiwidget/simplerhiwidget.qrc6
-rw-r--r--examples/widgets/richtext/CMakeLists.txt4
-rw-r--r--examples/widgets/richtext/calendar/CMakeLists.txt37
-rw-r--r--examples/widgets/richtext/calendar/calendar.pro10
-rw-r--r--examples/widgets/richtext/calendar/main.cpp15
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.cpp179
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.h36
-rw-r--r--examples/widgets/richtext/orderform/CMakeLists.txt21
-rw-r--r--examples/widgets/richtext/richtext.pro6
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/CMakeLists.txt21
-rw-r--r--examples/widgets/richtext/textedit/CMakeLists.txt105
-rw-r--r--examples/widgets/richtext/textedit/example.html84
-rw-r--r--examples/widgets/richtext/textedit/example.md104
-rw-r--r--examples/widgets/richtext/textedit/images/logo32.pngbin1410 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/checkbox-checked.pngbin1167 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/checkbox.pngbin779 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editcopy.pngbin1468 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editcut.pngbin1512 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editpaste.pngbin1906 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editredo.pngbin1752 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editundo.pngbin1746 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/exportpdf.pngbin12637 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/filenew.pngbin1172 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/fileopen.pngbin2168 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/fileprint.pngbin2087 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/filesave.pngbin2699 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/format-indent-less.pngbin1201 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/format-indent-more.pngbin993 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textbold.pngbin1611 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textcenter.pngbin1404 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textitalic.pngbin1164 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textjustify.pngbin1257 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textleft.pngbin1235 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textright.pngbin1406 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textunder.pngbin1183 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textundercolor.pngbin6916 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/zoomin.pngbin1696 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/zoomout.pngbin1662 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/checkbox-checked.pngbin1167 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/checkbox.pngbin779 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editcopy.pngbin1325 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editcut.pngbin1896 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editpaste.pngbin1482 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editredo.pngbin1787 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editundo.pngbin1768 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/exportpdf.pngbin1215 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/filenew.pngbin768 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/fileopen.pngbin1662 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/fileprint.pngbin1456 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/filesave.pngbin1205 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/format-indent-less.pngbin1201 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/format-indent-more.pngbin993 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textbold.pngbin1134 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textcenter.pngbin627 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textitalic.pngbin829 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textjustify.pngbin695 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textleft.pngbin673 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textright.pngbin677 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textunder.pngbin971 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textundercolor.pngbin6916 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/zoomin.pngbin1208 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/zoomout.pngbin1226 -> 0 bytes
-rw-r--r--examples/widgets/richtext/textedit/main.cpp38
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp851
-rw-r--r--examples/widgets/richtext/textedit/textedit.h103
-rw-r--r--examples/widgets/richtext/textedit/textedit.pro22
-rw-r--r--examples/widgets/richtext/textedit/textedit.qdoc20
-rw-r--r--examples/widgets/richtext/textedit/textedit.qrc54
-rw-r--r--examples/widgets/scroller/CMakeLists.txt1
-rw-r--r--examples/widgets/scroller/graphicsview/CMakeLists.txt36
-rw-r--r--examples/widgets/scroller/graphicsview/graphicsview.pro8
-rw-r--r--examples/widgets/scroller/graphicsview/main.cpp255
-rw-r--r--examples/widgets/scroller/scroller.pro2
-rw-r--r--examples/widgets/tools/CMakeLists.txt12
-rw-r--r--examples/widgets/tools/completer/CMakeLists.txt21
-rw-r--r--examples/widgets/tools/completer/main.cpp2
-rw-r--r--examples/widgets/tools/customcompleter/CMakeLists.txt21
-rw-r--r--examples/widgets/tools/customcompleter/main.cpp2
-rw-r--r--examples/widgets/tools/echoplugin/CMakeLists.txt18
-rw-r--r--examples/widgets/tools/echoplugin/echoplugin.pro5
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/CMakeLists.txt35
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echointerface.h27
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echowindow.cpp90
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echowindow.h42
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echowindow.pro21
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/main.cpp19
-rw-r--r--examples/widgets/tools/echoplugin/plugin/CMakeLists.txt26
-rw-r--r--examples/widgets/tools/echoplugin/plugin/echoplugin.cpp11
-rw-r--r--examples/widgets/tools/echoplugin/plugin/echoplugin.h23
-rw-r--r--examples/widgets/tools/echoplugin/plugin/echoplugin.json1
-rw-r--r--examples/widgets/tools/echoplugin/plugin/plugin.pro18
-rw-r--r--examples/widgets/tools/plugandpaint/CMakeLists.txt18
-rw-r--r--examples/widgets/tools/plugandpaint/app/CMakeLists.txt36
-rw-r--r--examples/widgets/tools/plugandpaint/app/app.pro37
-rw-r--r--examples/widgets/tools/plugandpaint/app/interfaces.h76
-rw-r--r--examples/widgets/tools/plugandpaint/app/main.cpp19
-rw-r--r--examples/widgets/tools/plugandpaint/app/mainwindow.cpp282
-rw-r--r--examples/widgets/tools/plugandpaint/app/mainwindow.h68
-rw-r--r--examples/widgets/tools/plugandpaint/app/paintarea.cpp152
-rw-r--r--examples/widgets/tools/plugandpaint/app/paintarea.h54
-rw-r--r--examples/widgets/tools/plugandpaint/app/plugindialog.cpp118
-rw-r--r--examples/widgets/tools/plugandpaint/app/plugindialog.h38
-rw-r--r--examples/widgets/tools/plugandpaint/plugandpaint.pro7
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/CMakeLists.txt2
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt18
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictools.json1
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro17
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp150
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h54
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt26
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.json1
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro17
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp82
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.h28
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/plugins.pro3
-rw-r--r--examples/widgets/tools/regularexpression/CMakeLists.txt21
-rw-r--r--examples/widgets/tools/settingseditor/CMakeLists.txt40
-rw-r--r--examples/widgets/tools/settingseditor/inifiles/licensepage.ini46
-rw-r--r--examples/widgets/tools/settingseditor/inifiles/qsa.ini26
-rw-r--r--examples/widgets/tools/settingseditor/locationdialog.cpp193
-rw-r--r--examples/widgets/tools/settingseditor/locationdialog.h49
-rw-r--r--examples/widgets/tools/settingseditor/main.cpp17
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.cpp175
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.h44
-rw-r--r--examples/widgets/tools/settingseditor/settingseditor.pro18
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp231
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.h61
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.cpp377
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.h53
-rw-r--r--examples/widgets/tools/styleplugin/CMakeLists.txt18
-rw-r--r--examples/widgets/tools/styleplugin/plugin/CMakeLists.txt41
-rw-r--r--examples/widgets/tools/styleplugin/plugin/plugin.pro34
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.cpp9
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.h19
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.json3
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp21
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h23
-rw-r--r--examples/widgets/tools/styleplugin/styleplugin.pro3
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt30
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/main.cpp26
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp25
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/stylewindow.h17
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/stylewindow.pro19
-rw-r--r--examples/widgets/tools/tools.pro9
-rw-r--r--examples/widgets/tools/treemodelcompleter/CMakeLists.txt21
-rw-r--r--examples/widgets/tools/treemodelcompleter/main.cpp2
-rw-r--r--examples/widgets/tools/undoframework/CMakeLists.txt21
-rw-r--r--examples/widgets/tools/undoframework/main.cpp2
-rw-r--r--examples/widgets/touch/CMakeLists.txt5
-rw-r--r--examples/widgets/touch/dials/CMakeLists.txt37
-rw-r--r--examples/widgets/touch/dials/dials.pro8
-rw-r--r--examples/widgets/touch/dials/dials.ui77
-rw-r--r--examples/widgets/touch/dials/doc/images/touch-dials-example.pngbin17676 -> 0 bytes
-rw-r--r--examples/widgets/touch/dials/doc/src/touch-dials.qdoc14
-rw-r--r--examples/widgets/touch/dials/main.cpp21
-rw-r--r--examples/widgets/touch/fingerpaint/CMakeLists.txt45
-rw-r--r--examples/widgets/touch/fingerpaint/doc/src/fingerpaint.qdoc18
-rw-r--r--examples/widgets/touch/fingerpaint/fingerpaint.pro13
-rw-r--r--examples/widgets/touch/fingerpaint/main.cpp14
-rw-r--r--examples/widgets/touch/fingerpaint/mainwindow.cpp180
-rw-r--r--examples/widgets/touch/fingerpaint/mainwindow.h51
-rw-r--r--examples/widgets/touch/fingerpaint/scribblearea.cpp190
-rw-r--r--examples/widgets/touch/fingerpaint/scribblearea.h43
-rw-r--r--examples/widgets/touch/knobs/CMakeLists.txt21
-rw-r--r--examples/widgets/touch/knobs/doc/images/touch-knobs-example.pngbin1290 -> 13386 bytes
-rw-r--r--examples/widgets/touch/knobs/doc/src/touch-knobs.qdoc1
-rw-r--r--examples/widgets/touch/knobs/main.cpp1
-rw-r--r--examples/widgets/touch/pinchzoom/CMakeLists.txt50
-rw-r--r--examples/widgets/touch/pinchzoom/doc/images/pinch-zoom-example.pngbin42493 -> 0 bytes
-rw-r--r--examples/widgets/touch/pinchzoom/doc/src/pinchzoom.qdoc14
-rw-r--r--examples/widgets/touch/pinchzoom/graphicsview.cpp48
-rw-r--r--examples/widgets/touch/pinchzoom/graphicsview.h18
-rw-r--r--examples/widgets/touch/pinchzoom/images/cheese.jpgbin3029 -> 0 bytes
-rw-r--r--examples/widgets/touch/pinchzoom/main.cpp47
-rw-r--r--examples/widgets/touch/pinchzoom/mice.qrc5
-rw-r--r--examples/widgets/touch/pinchzoom/mouse.cpp158
-rw-r--r--examples/widgets/touch/pinchzoom/mouse.h33
-rw-r--r--examples/widgets/touch/pinchzoom/pinchzoom.pro16
-rw-r--r--examples/widgets/touch/touch.pro2
-rw-r--r--examples/widgets/tutorials/CMakeLists.txt2
-rw-r--r--examples/widgets/tutorials/modelview/1_readonly/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/modelview/3_changingmodel/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/modelview/4_headers/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/modelview/5_edit/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/modelview/7_selections/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/modelview/CMakeLists.txt2
-rw-r--r--examples/widgets/tutorials/notepad/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/notepad/gettingstartedqt.qdoc19
-rw-r--r--examples/widgets/tutorials/widgets/CMakeLists.txt2
-rw-r--r--examples/widgets/tutorials/widgets/childwidget/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/widgets/nestedlayouts/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/widgets/toplevel/CMakeLists.txt21
-rw-r--r--examples/widgets/tutorials/widgets/windowlayout/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets.pro6
-rw-r--r--examples/widgets/widgets/CMakeLists.txt15
-rw-r--r--examples/widgets/widgets/analogclock/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.cpp74
-rw-r--r--examples/widgets/widgets/calculator/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/calendarwidget/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/charactermap/CMakeLists.txt38
-rw-r--r--examples/widgets/widgets/charactermap/charactermap.pro12
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.cpp145
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.h50
-rw-r--r--examples/widgets/widgets/charactermap/main.cpp14
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp264
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.h50
-rw-r--r--examples/widgets/widgets/digitalclock/CMakeLists.txt37
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.cpp36
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.h22
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.pro9
-rw-r--r--examples/widgets/widgets/digitalclock/main.cpp14
-rw-r--r--examples/widgets/widgets/groupbox/CMakeLists.txt37
-rw-r--r--examples/widgets/widgets/groupbox/groupbox.pro9
-rw-r--r--examples/widgets/widgets/groupbox/main.cpp14
-rw-r--r--examples/widgets/widgets/groupbox/window.cpp155
-rw-r--r--examples/widgets/widgets/groupbox/window.h29
-rw-r--r--examples/widgets/widgets/icons/CMakeLists.txt44
-rw-r--r--examples/widgets/widgets/icons/iconpreviewarea.cpp130
-rw-r--r--examples/widgets/widgets/icons/iconpreviewarea.h47
-rw-r--r--examples/widgets/widgets/icons/icons.pro20
-rw-r--r--examples/widgets/widgets/icons/iconsizespinbox.cpp33
-rw-r--r--examples/widgets/widgets/icons/iconsizespinbox.h22
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.cpp64
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.h31
-rw-r--r--examples/widgets/widgets/icons/images/designer.pngbin3604 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/find_disabled.pngbin501 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/find_normal.pngbin838 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_128x128.pngbin7045 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_16x16.pngbin683 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_32x32.pngbin1609 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_64x64.pngbin3533 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_128x128.pngbin6909 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_16x16.pngbin681 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_32x32.pngbin1577 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_64x64.pngbin3479 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_16x16.pngbin1263 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_32x32.pngbin15518 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_48x48.pngbin789 -> 0 bytes
-rw-r--r--examples/widgets/widgets/icons/main.cpp34
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp478
-rw-r--r--examples/widgets/widgets/icons/mainwindow.h74
-rw-r--r--examples/widgets/widgets/imageviewer/CMakeLists.txt44
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp363
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.h74
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.pro11
-rw-r--r--examples/widgets/widgets/imageviewer/main.cpp24
-rw-r--r--examples/widgets/widgets/lineedits/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/movie/CMakeLists.txt37
-rw-r--r--examples/widgets/widgets/movie/animation.gifbin42629 -> 0 bytes
-rw-r--r--examples/widgets/widgets/movie/main.cpp15
-rw-r--r--examples/widgets/widgets/movie/movie.pro12
-rw-r--r--examples/widgets/widgets/movie/movieplayer.cpp180
-rw-r--r--examples/widgets/widgets/movie/movieplayer.h59
-rw-r--r--examples/widgets/widgets/scribble/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/shapedclock/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.cpp55
-rw-r--r--examples/widgets/widgets/shortcuteditor/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/sliders/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/sliders/slidersgroup.cpp34
-rw-r--r--examples/widgets/widgets/sliders/slidersgroup.h6
-rw-r--r--examples/widgets/widgets/sliders/window.cpp97
-rw-r--r--examples/widgets/widgets/sliders/window.h8
-rw-r--r--examples/widgets/widgets/spinboxes/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/styles/CMakeLists.txt51
-rw-r--r--examples/widgets/widgets/styles/images/woodbackground.pngbin7691 -> 0 bytes
-rw-r--r--examples/widgets/widgets/styles/images/woodbutton.pngbin7689 -> 0 bytes
-rw-r--r--examples/widgets/widgets/styles/main.cpp19
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp310
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.h43
-rw-r--r--examples/widgets/widgets/styles/styles.pro13
-rw-r--r--examples/widgets/widgets/styles/styles.qrc6
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.cpp277
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.h86
-rw-r--r--examples/widgets/widgets/stylesheet/CMakeLists.txt84
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_checked.pngbin263 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_checked_hover.pngbin266 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_checked_pressed.pngbin425 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_unchecked.pngbin159 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_unchecked_hover.pngbin159 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_unchecked_pressed.pngbin320 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/down_arrow.pngbin175 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/down_arrow_disabled.pngbin174 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/frame.pngbin253 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pagefold.pngbin1545 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pushbutton.pngbin533 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pushbutton_hover.pngbin525 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pushbutton_pressed.pngbin513 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_checked.pngbin355 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_checked_hover.pngbin532 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_checked_pressed.pngbin599 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_unchecked.pngbin240 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_hover.pngbin492 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_pressed.pngbin556 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/sizegrip.pngbin129 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown.pngbin276 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown_hover.pngbin268 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown_off.pngbin249 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown_pressed.pngbin264 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup.pngbin283 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup_hover.pngbin277 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup_off.pngbin274 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup_pressed.pngbin277 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/up_arrow.pngbin197 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/up_arrow_disabled.pngbin172 -> 0 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/layouts/default.ui329
-rw-r--r--examples/widgets/widgets/stylesheet/layouts/pagefold.ui349
-rw-r--r--examples/widgets/widgets/stylesheet/main.cpp16
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.cpp41
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.h29
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.ui356
-rw-r--r--examples/widgets/widgets/stylesheet/qss/coffee.qss117
-rw-r--r--examples/widgets/widgets/stylesheet/qss/default.qss1
-rw-r--r--examples/widgets/widgets/stylesheet/qss/pagefold.qss299
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheet.pro15
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheet.qrc39
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.cpp64
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.h30
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.ui171
-rw-r--r--examples/widgets/widgets/tablet/CMakeLists.txt21
-rw-r--r--examples/widgets/widgets/tetrix/CMakeLists.txt39
-rw-r--r--examples/widgets/widgets/tetrix/main.cpp14
-rw-r--r--examples/widgets/widgets/tetrix/tetrix.pro13
-rw-r--r--examples/widgets/widgets/tetrix/tetrixboard.cpp371
-rw-r--r--examples/widgets/widgets/tetrix/tetrixboard.h79
-rw-r--r--examples/widgets/widgets/tetrix/tetrixpiece.cpp106
-rw-r--r--examples/widgets/widgets/tetrix/tetrixpiece.h38
-rw-r--r--examples/widgets/widgets/tetrix/tetrixwindow.cpp82
-rw-r--r--examples/widgets/widgets/tetrix/tetrixwindow.h38
-rw-r--r--examples/widgets/widgets/tooltips/CMakeLists.txt52
-rw-r--r--examples/widgets/widgets/tooltips/images/circle.pngbin165 -> 0 bytes
-rw-r--r--examples/widgets/widgets/tooltips/images/square.pngbin94 -> 0 bytes
-rw-r--r--examples/widgets/widgets/tooltips/images/triangle.pngbin170 -> 0 bytes
-rw-r--r--examples/widgets/widgets/tooltips/main.cpp16
-rw-r--r--examples/widgets/widgets/tooltips/shapeitem.cpp60
-rw-r--r--examples/widgets/widgets/tooltips/shapeitem.h33
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp277
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.h71
-rw-r--r--examples/widgets/widgets/tooltips/tooltips.pro12
-rw-r--r--examples/widgets/widgets/tooltips/tooltips.qrc7
-rw-r--r--examples/widgets/widgets/validators/CMakeLists.txt55
-rw-r--r--examples/widgets/widgets/validators/ledoff.pngbin562 -> 0 bytes
-rw-r--r--examples/widgets/widgets/validators/ledon.pngbin486 -> 0 bytes
-rw-r--r--examples/widgets/widgets/validators/ledwidget.cpp25
-rw-r--r--examples/widgets/widgets/validators/ledwidget.h27
-rw-r--r--examples/widgets/widgets/validators/localeselector.cpp48
-rw-r--r--examples/widgets/widgets/validators/localeselector.h23
-rw-r--r--examples/widgets/widgets/validators/main.cpp18
-rw-r--r--examples/widgets/widgets/validators/validators.pro12
-rw-r--r--examples/widgets/widgets/validators/validators.qrc6
-rw-r--r--examples/widgets/widgets/validators/validators.ui468
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.cpp75
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.h22
-rw-r--r--examples/widgets/widgets/widgets.pro11
-rw-r--r--examples/widgets/widgets/windowflags/CMakeLists.txt21
-rw-r--r--examples/widgets/windowcontainer/CMakeLists.txt42
-rw-r--r--examples/widgets/windowcontainer/windowcontainer.cpp136
-rw-r--r--examples/widgets/windowcontainer/windowcontainer.pro9
-rw-r--r--examples/xml/CMakeLists.txt2
-rw-r--r--examples/xml/dombookmarks/CMakeLists.txt21
-rw-r--r--examples/xml/dombookmarks/doc/images/dombookmarks-example.pngbin19405 -> 0 bytes
-rw-r--r--examples/xml/dombookmarks/doc/images/screenshot.pngbin0 -> 67075 bytes
-rw-r--r--examples/xml/dombookmarks/doc/src/dombookmarks.qdoc19
-rw-r--r--examples/xml/dombookmarks/dombookmarks.pro2
-rw-r--r--examples/xml/dombookmarks/jennifer.xbel46
-rw-r--r--examples/xml/dombookmarks/mainwindow.cpp39
-rw-r--r--examples/xml/dombookmarks/xbeltree.cpp76
-rw-r--r--examples/xml/dombookmarks/xbeltree.h4
1279 files changed, 6635 insertions, 42343 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 2bc1e4d378..d1b6b67aa0 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,11 +1,22 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+if(QT_BUILD_STANDALONE_EXAMPLES)
+ # Needed for early feature values, despite it being found later on in qt_build_tests().
+ # Needs to be find_package, not qt_find_package, because qt_find_package doesn't handle finding
+ # component for a super-package that has already been found.
+ find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core)
+
+ # Modify the optimization flags specifically for qtbase standalone examples. Other projects
+ # are handled by qt_enable_cmake_languages().
+ qt_internal_set_up_config_optimizations_like_in_qmake()
+endif()
qt_examples_build_begin(EXTERNAL_BUILD)
+add_compile_definitions(QT_NO_CONTEXTLESS_CONNECT)
+
add_subdirectory(corelib)
-add_subdirectory(embedded)
-add_subdirectory(qpa)
if(TARGET Qt6::DBus)
add_subdirectory(dbus)
endif()
diff --git a/examples/corelib/CMakeLists.txt b/examples/corelib/CMakeLists.txt
index 638db2dda9..38a883b4ea 100644
--- a/examples/corelib/CMakeLists.txt
+++ b/examples/corelib/CMakeLists.txt
@@ -1,17 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
add_subdirectory(ipc)
add_subdirectory(mimetypes)
add_subdirectory(serialization)
add_subdirectory(tools)
add_subdirectory(platform)
-if(QT_FEATURE_permissions)
- add_subdirectory(permissions)
-endif()
if(QT_FEATURE_thread)
add_subdirectory(threads)
endif()
if(QT_FEATURE_widgets)
- add_subdirectory(bindableproperties)
+ qt_internal_add_example(bindableproperties)
endif()
diff --git a/examples/corelib/bindableproperties/CMakeLists.txt b/examples/corelib/bindableproperties/CMakeLists.txt
index c6d9076fd8..07a2b7a2cf 100644
--- a/examples/corelib/bindableproperties/CMakeLists.txt
+++ b/examples/corelib/bindableproperties/CMakeLists.txt
@@ -1,2 +1,33 @@
-qt_internal_add_example(bindablesubscription)
-qt_internal_add_example(subscription)
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(bindableproperties LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+
+qt_standard_project_setup()
+
+add_subdirectory(shared)
+add_subdirectory(subscription)
+add_subdirectory(bindablesubscription)
+
+install(TARGETS subscription bindablesubscription
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET subscription
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
+
+qt_generate_deploy_app_script(
+ TARGET bindablesubscription
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/bindableproperties/bindablesubscription/CMakeLists.txt b/examples/corelib/bindableproperties/bindablesubscription/CMakeLists.txt
index c4a2e5fcfc..2734f44a17 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/CMakeLists.txt
+++ b/examples/corelib/bindableproperties/bindablesubscription/CMakeLists.txt
@@ -1,50 +1,15 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(bindablesubscription LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/bindableproperties/bindablesubscription")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_add_executable(bindablesubscription
- ../shared/subscriptionwindow.cpp ../shared/subscriptionwindow.h ../shared/subscriptionwindow.ui
main.cpp
- bindablesubscription.cpp bindablesubscription.h
- bindableuser.cpp bindableuser.h
+ bindablesubscription.cpp
+ bindablesubscription.h
+ bindableuser.cpp
+ bindableuser.h
)
target_link_libraries(bindablesubscription PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
+ bindableproperties_shared
)
-# Resources:
-set(countries_resource_files
- "../shared/finland.png"
- "../shared/germany.png"
- "../shared/norway.png"
-)
-
-qt_add_resources(bindablesubscription "countries"
- PREFIX
- "/"
- BASE
- "../shared"
- FILES
- ${countries_resource_files}
-)
-
-install(TARGETS bindablesubscription
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp
index a52b68f85b..32f4194635 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp
+++ b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp
@@ -10,7 +10,8 @@ BindableSubscription::BindableSubscription(BindableUser *user) : m_user(user)
{
Q_ASSERT(user);
- m_price.setBinding([this] { return qRound(calculateDiscount() * m_duration * basePrice()); });
+ m_price.setBinding(
+ [this] { return qRound(calculateDiscount() * int(m_duration) * basePrice()); });
m_isValid.setBinding([this] {
return m_user->country() != BindableUser::Country::AnyCountry && m_user->age() > 12;
@@ -38,8 +39,7 @@ double BindableSubscription::calculateDiscount() const
case Yearly:
return 0.6;
}
- Q_ASSERT(false);
- return -1;
+ Q_UNREACHABLE_RETURN(-1);
}
int BindableSubscription::basePrice() const
diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h
index 3406693b94..03870d0617 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h
+++ b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h
@@ -4,7 +4,7 @@
#ifndef BINDABLESUBSCRIPTION_H
#define BINDABLESUBSCRIPTION_H
-#include <QPointer>
+#include <QBindable>
#include <QProperty>
class BindableUser;
diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h
index d172a7cb22..6bb9bcdcb5 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h
+++ b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h
@@ -4,6 +4,7 @@
#ifndef BINDABLEUSER_H
#define BINDABLEUSER_H
+#include <QBindable>
#include <QLocale>
#include <QProperty>
diff --git a/examples/corelib/bindableproperties/bindablesubscription/main.cpp b/examples/corelib/bindableproperties/bindablesubscription/main.cpp
index 6cf73c1337..466f487b8e 100644
--- a/examples/corelib/bindableproperties/bindablesubscription/main.cpp
+++ b/examples/corelib/bindableproperties/bindablesubscription/main.cpp
@@ -6,11 +6,15 @@
#include "bindableuser.h"
#include <QApplication>
-#include <QButtonGroup>
+#include <QBindable>
#include <QLabel>
+#include <QLocale>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
+#include <QString>
+
+using namespace Qt::StringLiterals;
int main(int argc, char *argv[])
{
@@ -19,41 +23,42 @@ int main(int argc, char *argv[])
BindableSubscription subscription(&user);
SubscriptionWindow w;
+ // clazy:excludeall=lambda-in-connect
+ // when subscription is out of scope so is window
// Initialize subscription data
- QRadioButton *monthly = w.findChild<QRadioButton *>("btnMonthly");
- QObject::connect(monthly, &QRadioButton::clicked, [&] {
+ QRadioButton *monthly = w.findChild<QRadioButton *>(u"btnMonthly"_s);
+ QObject::connect(monthly, &QRadioButton::clicked, monthly, [&] {
subscription.setDuration(BindableSubscription::Monthly);
});
- QRadioButton *quarterly = w.findChild<QRadioButton *>("btnQuarterly");
- QObject::connect(quarterly, &QRadioButton::clicked, [&] {
+ QRadioButton *quarterly = w.findChild<QRadioButton *>(u"btnQuarterly"_s);
+ QObject::connect(quarterly, &QRadioButton::clicked, quarterly, [&] {
subscription.setDuration(BindableSubscription::Quarterly);
});
- QRadioButton *yearly = w.findChild<QRadioButton *>("btnYearly");
- QObject::connect(yearly, &QRadioButton::clicked, [&] {
+ QRadioButton *yearly = w.findChild<QRadioButton *>(u"btnYearly"_s);
+ QObject::connect(yearly, &QRadioButton::clicked, yearly, [&] {
subscription.setDuration(BindableSubscription::Yearly);
});
// Initialize user data
- QPushButton *germany = w.findChild<QPushButton *>("btnGermany");
- QObject::connect(germany, &QPushButton::clicked, [&] {
+ QPushButton *germany = w.findChild<QPushButton *>(u"btnGermany"_s);
+ QObject::connect(germany, &QPushButton::clicked, germany, [&] {
user.setCountry(BindableUser::Country::Germany);
});
- QPushButton *finland = w.findChild<QPushButton *>("btnFinland");
- QObject::connect(finland, &QPushButton::clicked, [&] {
+ QPushButton *finland = w.findChild<QPushButton *>(u"btnFinland"_s);
+ QObject::connect(finland, &QPushButton::clicked, finland, [&] {
user.setCountry(BindableUser::Country::Finland);
});
- QPushButton *norway = w.findChild<QPushButton *>("btnNorway");
- QObject::connect(norway, &QPushButton::clicked, [&] {
+ QPushButton *norway = w.findChild<QPushButton *>(u"btnNorway"_s);
+ QObject::connect(norway, &QPushButton::clicked, norway, [&] {
user.setCountry(BindableUser::Country::Norway);
});
- QSpinBox *ageSpinBox = w.findChild<QSpinBox *>("ageSpinBox");
- QObject::connect(ageSpinBox, &QSpinBox::valueChanged, [&](int value) {
- user.setAge(value);
- });
+ QSpinBox *ageSpinBox = w.findChild<QSpinBox *>(u"ageSpinBox"_s);
+ QBindable<int> ageBindable(ageSpinBox, "value");
+ user.bindableAge().setBinding([ageBindable](){ return ageBindable.value();});
- QLabel *priceDisplay = w.findChild<QLabel *>("priceDisplay");
+ QLabel *priceDisplay = w.findChild<QLabel *>(u"priceDisplay"_s);
// Track price changes
//! [update-ui]
diff --git a/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc b/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc
index e63662dfbb..476522b086 100644
--- a/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc
+++ b/examples/corelib/bindableproperties/doc/src/bindableproperties.qdoc
@@ -3,7 +3,8 @@
/*!
\example bindableproperties
- \title Bindable Properties Example
+ \examplecategory {Data Processing & I/O}
+ \title Bindable Properties
\brief Demonstrates how the usage of bindable properties can simplify
your C++ code.
diff --git a/examples/corelib/bindableproperties/shared/CMakeLists.txt b/examples/corelib/bindableproperties/shared/CMakeLists.txt
new file mode 100644
index 0000000000..efc85e5d4d
--- /dev/null
+++ b/examples/corelib/bindableproperties/shared/CMakeLists.txt
@@ -0,0 +1,23 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+add_library(bindableproperties_shared STATIC
+ subscriptionwindow.cpp
+ subscriptionwindow.h
+ subscriptionwindow.ui
+)
+
+target_link_libraries(bindableproperties_shared PUBLIC
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Widgets
+)
+
+qt_add_resources(bindableproperties_shared "countries"
+ PREFIX
+ "/"
+ FILES
+ "finland.png"
+ "germany.png"
+ "norway.png"
+)
diff --git a/examples/corelib/bindableproperties/subscription/CMakeLists.txt b/examples/corelib/bindableproperties/subscription/CMakeLists.txt
index 0dd027fc24..91b9340fbf 100644
--- a/examples/corelib/bindableproperties/subscription/CMakeLists.txt
+++ b/examples/corelib/bindableproperties/subscription/CMakeLists.txt
@@ -1,50 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(subscription LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/bindableproperties/subscription")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_add_executable(subscription
- ../shared/subscriptionwindow.cpp ../shared/subscriptionwindow.h ../shared/subscriptionwindow.ui
main.cpp
subscription.cpp subscription.h
user.cpp user.h
)
target_link_libraries(subscription PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(countries_resource_files
- "../shared/finland.png"
- "../shared/germany.png"
- "../shared/norway.png"
-)
-
-qt_add_resources(subscription "countries"
- PREFIX
- "/"
- BASE
- "../shared"
- FILES
- ${countries_resource_files}
-)
-
-install(TARGETS subscription
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ bindableproperties_shared
)
diff --git a/examples/corelib/bindableproperties/subscription/main.cpp b/examples/corelib/bindableproperties/subscription/main.cpp
index 1f41486728..3f98da7467 100644
--- a/examples/corelib/bindableproperties/subscription/main.cpp
+++ b/examples/corelib/bindableproperties/subscription/main.cpp
@@ -6,11 +6,14 @@
#include "user.h"
#include <QApplication>
-#include <QButtonGroup>
#include <QLabel>
+#include <QLocale>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
+#include <QString>
+
+using namespace Qt::StringLiterals;
int main(int argc, char *argv[])
{
@@ -24,65 +27,65 @@ int main(int argc, char *argv[])
SubscriptionWindow w;
// Initialize subscription data
- QRadioButton *monthly = w.findChild<QRadioButton *>("btnMonthly");
+ QRadioButton *monthly = w.findChild<QRadioButton *>(u"btnMonthly"_s);
QObject::connect(monthly, &QRadioButton::clicked, &subscription, [&] {
subscription.setDuration(Subscription::Monthly);
});
- QRadioButton *quarterly = w.findChild<QRadioButton *>("btnQuarterly");
+ QRadioButton *quarterly = w.findChild<QRadioButton *>(u"btnQuarterly"_s);
QObject::connect(quarterly, &QRadioButton::clicked, &subscription, [&] {
subscription.setDuration(Subscription::Quarterly);
});
- QRadioButton *yearly = w.findChild<QRadioButton *>("btnYearly");
+ QRadioButton *yearly = w.findChild<QRadioButton *>(u"btnYearly"_s);
QObject::connect(yearly, &QRadioButton::clicked, &subscription, [&] {
subscription.setDuration(Subscription::Yearly);
});
// Initialize user data
- QPushButton *germany = w.findChild<QPushButton *>("btnGermany");
+ QPushButton *germany = w.findChild<QPushButton *>(u"btnGermany"_s);
QObject::connect(germany, &QPushButton::clicked, &user, [&] {
user.setCountry(User::Country::Germany);
});
- QPushButton *finland = w.findChild<QPushButton *>("btnFinland");
+ QPushButton *finland = w.findChild<QPushButton *>(u"btnFinland"_s);
QObject::connect(finland, &QPushButton::clicked, &user, [&] {
user.setCountry(User::Country::Finland);
});
- QPushButton *norway = w.findChild<QPushButton *>("btnNorway");
+ QPushButton *norway = w.findChild<QPushButton *>(u"btnNorway"_s);
QObject::connect(norway, &QPushButton::clicked, &user, [&] {
user.setCountry(User::Country::Norway);
});
- QSpinBox *ageSpinBox = w.findChild<QSpinBox *>("ageSpinBox");
+ QSpinBox *ageSpinBox = w.findChild<QSpinBox *>(u"ageSpinBox"_s);
QObject::connect(ageSpinBox, &QSpinBox::valueChanged, &user, [&](int value) {
user.setAge(value);
});
// Initialize price data
- QLabel *priceDisplay = w.findChild<QLabel *>("priceDisplay");
+ QLabel *priceDisplay = w.findChild<QLabel *>(u"priceDisplay"_s);
priceDisplay->setText(QString::number(subscription.price()));
priceDisplay->setEnabled(subscription.isValid());
// Track the price changes
//! [connect-price-changed]
- QObject::connect(&subscription, &Subscription::priceChanged, [&] {
+ QObject::connect(&subscription, &Subscription::priceChanged, priceDisplay, [&] {
QLocale lc{QLocale::AnyLanguage, user.country()};
priceDisplay->setText(lc.toCurrencyString(subscription.price() / subscription.duration()));
});
//! [connect-price-changed]
//! [connect-validity-changed]
- QObject::connect(&subscription, &Subscription::isValidChanged, [&] {
+ QObject::connect(&subscription, &Subscription::isValidChanged, priceDisplay, [&] {
priceDisplay->setEnabled(subscription.isValid());
});
//! [connect-validity-changed]
//! [connect-user]
- QObject::connect(&user, &User::countryChanged, [&] {
+ QObject::connect(&user, &User::countryChanged, &subscription, [&] {
subscription.calculatePrice();
subscription.updateValidity();
});
- QObject::connect(&user, &User::ageChanged, [&] {
+ QObject::connect(&user, &User::ageChanged, &subscription, [&] {
subscription.updateValidity();
});
//! [connect-user]
diff --git a/examples/corelib/bindableproperties/subscription/subscription.cpp b/examples/corelib/bindableproperties/subscription/subscription.cpp
index 5d040f76d9..85cc5798cc 100644
--- a/examples/corelib/bindableproperties/subscription/subscription.cpp
+++ b/examples/corelib/bindableproperties/subscription/subscription.cpp
@@ -15,7 +15,7 @@ void Subscription::calculatePrice()
{
const auto oldPrice = m_price;
- m_price = qRound(calculateDiscount() * m_duration * basePrice());
+ m_price = qRound(calculateDiscount() * int(m_duration) * basePrice());
if (m_price != oldPrice)
emit priceChanged();
}
diff --git a/examples/corelib/ipc/CMakeLists.txt b/examples/corelib/ipc/CMakeLists.txt
index d1cfc7bc1b..270f71faec 100644
--- a/examples/corelib/ipc/CMakeLists.txt
+++ b/examples/corelib/ipc/CMakeLists.txt
@@ -1,10 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Widgets)
return()
endif()
-if(QT_FEATURE_sharedmemory)
+if(QT_FEATURE_sharedmemory AND QT_FEATURE_systemsemaphore)
qt_internal_add_example(sharedmemory)
endif()
if(QT_FEATURE_localserver AND TARGET Qt6::Network)
diff --git a/examples/corelib/ipc/doc/images/localfortuneserver-example.png b/examples/corelib/ipc/doc/images/localfortuneserver-example.png
index 2f04c7528e..778c7c85b0 100644
--- a/examples/corelib/ipc/doc/images/localfortuneserver-example.png
+++ b/examples/corelib/ipc/doc/images/localfortuneserver-example.png
Binary files differ
diff --git a/examples/corelib/ipc/doc/src/localfortuneclient.qdoc b/examples/corelib/ipc/doc/src/localfortuneclient.qdoc
index f7fa46c932..a2bdb69b8b 100644
--- a/examples/corelib/ipc/doc/src/localfortuneclient.qdoc
+++ b/examples/corelib/ipc/doc/src/localfortuneclient.qdoc
@@ -3,14 +3,16 @@
/*!
\example ipc/localfortuneclient
- \title Local Fortune Client Example
+ \examplecategory {Connectivity}
+ \title Local Fortune Client
\ingroup examples-ipc
\brief Demonstrates using QLocalSocket for a simple local service client.
The Local Fortune Client example shows how to create a client for a simple
local service using QLocalSocket. It is intended to be run alongside the
- \l{Local Fortune Server Example}.
+ \l{Local Fortune Server} example.
- \image localfortuneclient-example.png Screenshot of the Local Fortune Client example
+ \image localfortuneclient-example.png Screenshot of the Local Fortune Client
+ example
*/
diff --git a/examples/corelib/ipc/doc/src/localfortuneserver.qdoc b/examples/corelib/ipc/doc/src/localfortuneserver.qdoc
index 281fd3b4be..6b359a8680 100644
--- a/examples/corelib/ipc/doc/src/localfortuneserver.qdoc
+++ b/examples/corelib/ipc/doc/src/localfortuneserver.qdoc
@@ -3,13 +3,14 @@
/*!
\example ipc/localfortuneserver
- \title Local Fortune Server Example
+ \examplecategory {Connectivity}
+ \title Local Fortune Server
\ingroup examples-ipc
\brief Demonstrates using QLocalServer and QLocalSocket for serving a simple local service.
The Local Fortune Server example shows how to create a server for a simple
local service. It is intended to be run alongside the
- \l{Local Fortune Client Example}
+ \l{Local Fortune Client} example.
\image localfortuneserver-example.png Screenshot of the Local Fortune Server example
*/
diff --git a/examples/corelib/ipc/doc/src/sharedmemory.qdoc b/examples/corelib/ipc/doc/src/sharedmemory.qdoc
index 7ea4ffb25d..80645f3495 100644
--- a/examples/corelib/ipc/doc/src/sharedmemory.qdoc
+++ b/examples/corelib/ipc/doc/src/sharedmemory.qdoc
@@ -3,10 +3,11 @@
/*!
\example ipc/sharedmemory
- \title Shared Memory Example
+ \examplecategory {Data Processing & I/O}
+ \title IPC: Shared Memory
\ingroup examples-ipc
- \brief Demonstrates doing inter-process communication using shared memory with
- the QSharedMemory class.
+ \brief Demonstrates how to share image data between different processes
+ using the Shared Memory IPC mechanism.
The Shared Memory example shows how to use the QSharedMemory class
to implement inter-process communication using shared memory. To
diff --git a/examples/corelib/ipc/localfortuneclient/CMakeLists.txt b/examples/corelib/ipc/localfortuneclient/CMakeLists.txt
index b3337e1f46..f3f2b13f92 100644
--- a/examples/corelib/ipc/localfortuneclient/CMakeLists.txt
+++ b/examples/corelib/ipc/localfortuneclient/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(localfortuneclient LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/ipc/localfortuneclient")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(localfortuneclient PRIVATE
)
install(TARGETS localfortuneclient
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET localfortuneclient
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/ipc/localfortuneclient/client.cpp b/examples/corelib/ipc/localfortuneclient/client.cpp
index 31f8cf475b..b71409560b 100644
--- a/examples/corelib/ipc/localfortuneclient/client.cpp
+++ b/examples/corelib/ipc/localfortuneclient/client.cpp
@@ -1,14 +1,19 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-#include <QtNetwork>
-
#include "client.h"
+#include <QDialogButtonBox>
+#include <QGridLayout>
+#include <QGuiApplication>
+#include <QMessageBox>
+#include <QTimer>
+
+using namespace Qt::StringLiterals;
+
Client::Client(QWidget *parent)
: QDialog(parent),
- hostLineEdit(new QLineEdit("fortune")),
+ hostLineEdit(new QLineEdit(u"fortune"_s)),
getFortuneButton(new QPushButton(tr("Get Fortune"))),
statusLabel(new QLabel(tr("This examples requires that you run the "
"Local Fortune Server example as well."))),
@@ -28,7 +33,7 @@ Client::Client(QWidget *parent)
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
in.setDevice(socket);
- in.setVersion(QDataStream::Qt_5_10);
+ in.setVersion(QDataStream::Qt_6_0);
connect(hostLineEdit, &QLineEdit::textChanged,
this, &Client::enableGetFortuneButton);
@@ -58,20 +63,14 @@ void Client::requestNewFortune()
void Client::readFortune()
{
- if (blockSize == 0) {
- // Relies on the fact that QDataStream serializes a quint32 into
- // sizeof(quint32) bytes
- if (socket->bytesAvailable() < (int)sizeof(quint32))
- return;
- in >> blockSize;
- }
-
- if (socket->bytesAvailable() < blockSize || in.atEnd())
- return;
+ in.startTransaction();
QString nextFortune;
in >> nextFortune;
+ if (!in.commitTransaction())
+ return;
+
if (nextFortune == currentFortune) {
QTimer::singleShot(0, this, &Client::requestNewFortune);
return;
diff --git a/examples/corelib/ipc/localfortuneclient/client.h b/examples/corelib/ipc/localfortuneclient/client.h
index c7275252fe..b4c949a21a 100644
--- a/examples/corelib/ipc/localfortuneclient/client.h
+++ b/examples/corelib/ipc/localfortuneclient/client.h
@@ -4,15 +4,12 @@
#ifndef CLIENT_H
#define CLIENT_H
-#include <QDialog>
#include <QDataStream>
+#include <QDialog>
+#include <QLabel>
+#include <QLineEdit>
#include <QLocalSocket>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QLineEdit;
-class QPushButton;
-QT_END_NAMESPACE
+#include <QPushButton>
class Client : public QDialog
{
diff --git a/examples/corelib/ipc/localfortuneclient/main.cpp b/examples/corelib/ipc/localfortuneclient/main.cpp
index 3c2a7b284c..f52807ec48 100644
--- a/examples/corelib/ipc/localfortuneclient/main.cpp
+++ b/examples/corelib/ipc/localfortuneclient/main.cpp
@@ -1,10 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-
#include "client.h"
+#include <QApplication>
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
diff --git a/examples/corelib/ipc/localfortuneserver/CMakeLists.txt b/examples/corelib/ipc/localfortuneserver/CMakeLists.txt
index 411fc04eb5..75f037171c 100644
--- a/examples/corelib/ipc/localfortuneserver/CMakeLists.txt
+++ b/examples/corelib/ipc/localfortuneserver/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(localfortuneserver LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/ipc/localfortuneserver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(localfortuneserver PRIVATE
)
install(TARGETS localfortuneserver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET localfortuneserver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/ipc/localfortuneserver/main.cpp b/examples/corelib/ipc/localfortuneserver/main.cpp
index 291a6b3f22..c18fa17dfb 100644
--- a/examples/corelib/ipc/localfortuneserver/main.cpp
+++ b/examples/corelib/ipc/localfortuneserver/main.cpp
@@ -1,10 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-
#include "server.h"
+#include <QApplication>
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
diff --git a/examples/corelib/ipc/localfortuneserver/server.cpp b/examples/corelib/ipc/localfortuneserver/server.cpp
index bfdf425f5d..a602a57f72 100644
--- a/examples/corelib/ipc/localfortuneserver/server.cpp
+++ b/examples/corelib/ipc/localfortuneserver/server.cpp
@@ -3,27 +3,33 @@
#include "server.h"
-#include <QtWidgets>
-#include <QtNetwork>
+#include <QDialogButtonBox>
+#include <QGuiApplication>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QLocalSocket>
+#include <QMessageBox>
+#include <QPushButton>
+#include <QRandomGenerator>
+
+using namespace Qt::StringLiterals;
+
+static const QString idleStateText = QObject::tr("Press \"Listen\" to start the server");
Server::Server(QWidget *parent)
- : QDialog(parent)
+ : QDialog(parent),
+ server(new QLocalServer(this)),
+ hostLineEdit(new QLineEdit(u"fortune"_s)),
+ statusLabel(new QLabel(idleStateText)),
+ listenButton(new QPushButton(tr("Listen"))),
+ stopListeningButton(new QPushButton(tr("Stop Listening")))
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- server = new QLocalServer(this);
- if (!server->listen("fortune")) {
- QMessageBox::critical(this, tr("Local Fortune Server"),
- tr("Unable to start the server: %1.")
- .arg(server->errorString()));
- close();
- return;
- }
-
- QLabel *statusLabel = new QLabel;
statusLabel->setWordWrap(true);
- statusLabel->setText(tr("The server is running.\n"
- "Run the Local Fortune Client example now."));
+
+ stopListeningButton->setDisabled(true);
fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
<< tr("You've got to think about tomorrow.")
@@ -33,31 +39,73 @@ Server::Server(QWidget *parent)
<< tr("You cannot kill time without injuring eternity.")
<< tr("Computers are not intelligent. They only think they are.");
+ QLabel *hostLabel = new QLabel(tr("Server name:"));
+
+ connect(server, &QLocalServer::newConnection, this, &Server::sendFortune);
+ connect(hostLineEdit, &QLineEdit::textChanged, this, &Server::toggleListenButton);
+ connect(listenButton, &QPushButton::clicked, this, &Server::listenToServer);
+ connect(stopListeningButton, &QPushButton::clicked,this, &Server::stopListening);
+
QPushButton *quitButton = new QPushButton(tr("Quit"));
quitButton->setAutoDefault(false);
connect(quitButton, &QPushButton::clicked, this, &Server::close);
- connect(server, &QLocalServer::newConnection, this, &Server::sendFortune);
- QHBoxLayout *buttonLayout = new QHBoxLayout;
- buttonLayout->addStretch(1);
- buttonLayout->addWidget(quitButton);
- buttonLayout->addStretch(1);
+ QDialogButtonBox *buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(listenButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(stopListeningButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
- QVBoxLayout *mainLayout = new QVBoxLayout(this);
- mainLayout->addWidget(statusLabel);
- mainLayout->addLayout(buttonLayout);
+ QGridLayout *mainLayout = new QGridLayout(this);
+ mainLayout->addWidget(hostLabel, 0, 0);
+ mainLayout->addWidget(hostLineEdit, 0, 1);
+ mainLayout->addWidget(statusLabel, 2, 0, 3, 2);
+ mainLayout->addWidget(buttonBox, 10, 0, 2, 2);
setWindowTitle(QGuiApplication::applicationDisplayName());
+ hostLineEdit->setFocus();
+}
+
+void Server::listenToServer()
+{
+ name = hostLineEdit->text();
+ if (!server->listen(name)) {
+ QMessageBox::critical(this, tr("Local Fortune Server"),
+ tr("Unable to start the server: %1.")
+ .arg(server->errorString()));
+ name.clear();
+ return;
+ }
+ statusLabel->setText(tr("The server is running.\n"
+ "Run the Local Fortune Client example now."));
+ toggleListenButton();
+}
+
+void Server::stopListening()
+{
+ server->close();
+ name.clear();
+ statusLabel->setText(idleStateText);
+ toggleListenButton();
+}
+
+void Server::toggleListenButton()
+{
+ if (server->isListening()) {
+ listenButton->setDisabled(true);
+ stopListeningButton->setEnabled(true);
+ } else {
+ listenButton->setEnabled(!hostLineEdit->text().isEmpty());
+ stopListeningButton->setDisabled(true);
+ }
}
void Server::sendFortune()
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
- out.setVersion(QDataStream::Qt_5_10);
+ out.setVersion(QDataStream::Qt_6_5);
const int fortuneIndex = QRandomGenerator::global()->bounded(0, fortunes.size());
const QString &message = fortunes.at(fortuneIndex);
- out << quint32(message.size());
out << message;
QLocalSocket *clientConnection = server->nextPendingConnection();
diff --git a/examples/corelib/ipc/localfortuneserver/server.h b/examples/corelib/ipc/localfortuneserver/server.h
index 26e4792347..1efba8fca9 100644
--- a/examples/corelib/ipc/localfortuneserver/server.h
+++ b/examples/corelib/ipc/localfortuneserver/server.h
@@ -4,27 +4,33 @@
#ifndef SERVER_H
#define SERVER_H
+#include <QApplication>
#include <QDialog>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QPushButton;
-class QLocalServer;
-QT_END_NAMESPACE
+#include <QLabel>
+#include <QLineEdit>
+#include <QLocalServer>
+#include <QPushButton>
class Server : public QDialog
{
- Q_OBJECT
+ Q_DECLARE_TR_FUNCTIONS(Server)
public:
explicit Server(QWidget *parent = nullptr);
-private slots:
+private:
void sendFortune();
+ void toggleListenButton();
+ void listenToServer();
+ void stopListening();
-private:
QLocalServer *server;
+ QLineEdit *hostLineEdit;
+ QLabel *statusLabel;
+ QPushButton *listenButton;
+ QPushButton *stopListeningButton;
QStringList fortunes;
+ QString name;
};
#endif
diff --git a/examples/corelib/ipc/sharedmemory/CMakeLists.txt b/examples/corelib/ipc/sharedmemory/CMakeLists.txt
index 21f5ff339b..db94911fc6 100644
--- a/examples/corelib/ipc/sharedmemory/CMakeLists.txt
+++ b/examples/corelib/ipc/sharedmemory/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(sharedmemory LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/ipc/sharedmemory")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(sharedmemory PRIVATE
)
install(TARGETS sharedmemory
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET sharedmemory
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/ipc/sharedmemory/dialog.cpp b/examples/corelib/ipc/sharedmemory/dialog.cpp
index b656cc0c67..4e8f93a77b 100644
--- a/examples/corelib/ipc/sharedmemory/dialog.cpp
+++ b/examples/corelib/ipc/sharedmemory/dialog.cpp
@@ -2,8 +2,12 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "dialog.h"
-#include <QFileDialog>
+
#include <QBuffer>
+#include <QFileDialog>
+#include <QNativeIpcKey>
+
+using namespace Qt::StringLiterals;
/*!
\class Dialog
@@ -29,8 +33,9 @@
each button.
*/
//! [0]
+
Dialog::Dialog(QWidget *parent)
- : QDialog(parent), sharedMemory("QSharedMemoryExample")
+ : QDialog(parent), sharedMemory(QNativeIpcKey(u"QSharedMemoryExample"_s))
{
ui.setupUi(this);
connect(ui.loadFromFileButton, &QPushButton::clicked,
diff --git a/examples/corelib/ipc/sharedmemory/dialog.h b/examples/corelib/ipc/sharedmemory/dialog.h
index 0f8abaa8b6..679af423ff 100644
--- a/examples/corelib/ipc/sharedmemory/dialog.h
+++ b/examples/corelib/ipc/sharedmemory/dialog.h
@@ -6,6 +6,7 @@
#include <QDialog>
#include <QSharedMemory>
+
#include "ui_dialog.h"
//! [0]
@@ -13,21 +14,21 @@ class Dialog : public QDialog
{
Q_OBJECT
- public:
+public:
Dialog(QWidget *parent = nullptr);
- public slots:
+public slots:
void loadFromFile();
void loadFromMemory();
- private:
+private:
void detach();
- private:
+private:
Ui::Dialog ui;
QSharedMemory sharedMemory;
};
//! [0]
-#endif
+#endif // DIALOG_H
diff --git a/examples/corelib/ipc/sharedmemory/main.cpp b/examples/corelib/ipc/sharedmemory/main.cpp
index bf5bd457ae..ffdd656502 100644
--- a/examples/corelib/ipc/sharedmemory/main.cpp
+++ b/examples/corelib/ipc/sharedmemory/main.cpp
@@ -1,9 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
#include "dialog.h"
+#include <QApplication>
+
//! [0]
int main(int argc, char *argv[])
{
diff --git a/examples/corelib/mimetypes/CMakeLists.txt b/examples/corelib/mimetypes/CMakeLists.txt
index 9ba3873bf4..3b395090a2 100644
--- a/examples/corelib/mimetypes/CMakeLists.txt
+++ b/examples/corelib/mimetypes/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(TARGET Qt6::Widgets)
qt_internal_add_example(mimetypebrowser)
diff --git a/examples/corelib/mimetypes/doc/src/mimetypebrowser.qdoc b/examples/corelib/mimetypes/doc/src/mimetypebrowser.qdoc
index 17c8d765a8..cc76abe2e5 100644
--- a/examples/corelib/mimetypes/doc/src/mimetypebrowser.qdoc
+++ b/examples/corelib/mimetypes/doc/src/mimetypebrowser.qdoc
@@ -3,8 +3,9 @@
/*!
\example mimetypes/mimetypebrowser
+ \examplecategory {Data Processing & I/O}
\ingroup examples-mimetype
- \title MIME Type Browser Example
+ \title MIME Type Browser
\brief Shows the hierarchy of MIME types and
can be used to determine the MIME type of a file.
diff --git a/examples/corelib/mimetypes/mimetypebrowser/CMakeLists.txt b/examples/corelib/mimetypes/mimetypebrowser/CMakeLists.txt
index c03ccae085..b514965ff9 100644
--- a/examples/corelib/mimetypes/mimetypebrowser/CMakeLists.txt
+++ b/examples/corelib/mimetypes/mimetypebrowser/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mimetypebrowser LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/mimetypes/mimetypebrowser")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(mimetypebrowser PRIVATE
)
install(TARGETS mimetypebrowser
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mimetypebrowser
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/mimetypes/mimetypebrowser/main.cpp b/examples/corelib/mimetypes/mimetypebrowser/main.cpp
index 9aaad7b836..03c905e6af 100644
--- a/examples/corelib/mimetypes/mimetypebrowser/main.cpp
+++ b/examples/corelib/mimetypes/mimetypebrowser/main.cpp
@@ -4,10 +4,8 @@
#include "mainwindow.h"
#include <QApplication>
-#include <QScreen>
-
#include <QCommandLineParser>
-#include <QCommandLineOption>
+#include <QScreen>
int main(int argc, char *argv[])
{
diff --git a/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp b/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp
index 07cb3872d4..0163fec574 100644
--- a/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp
+++ b/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp
@@ -4,23 +4,18 @@
#include "mainwindow.h"
#include "mimetypemodel.h"
-#include <QAction>
#include <QApplication>
#include <QFileDialog>
+#include <QFileInfo>
#include <QInputDialog>
+#include <QItemSelectionModel>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
-#include <QPlainTextEdit>
-#include <QSplitter>
-#include <QStatusBar>
-#include <QTextEdit>
-#include <QTreeView>
-
-#include <QFileInfo>
-#include <QItemSelectionModel>
#include <QMimeDatabase>
#include <QMimeType>
+#include <QSplitter>
+#include <QStatusBar>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@@ -45,7 +40,8 @@ MainWindow::MainWindow(QWidget *parent)
findAction->setShortcuts(QKeySequence::Find);
m_findNextAction = findMenu->addAction(tr("Find &Next"), this, &MainWindow::findNext);
m_findNextAction->setShortcuts(QKeySequence::FindNext);
- m_findPreviousAction = findMenu->addAction(tr("Find &Previous"), this, &MainWindow::findPrevious);
+ m_findPreviousAction = findMenu->addAction(tr("Find &Previous"), this,
+ &MainWindow::findPrevious);
m_findPreviousAction->setShortcuts(QKeySequence::FindPrevious);
menuBar()->addMenu(tr("&About"))->addAction(tr("&About Qt"), qApp, &QApplication::aboutQt);
@@ -54,8 +50,8 @@ MainWindow::MainWindow(QWidget *parent)
setCentralWidget(centralSplitter);
m_treeView->setUniformRowHeights(true);
m_treeView->setModel(m_model);
-
- const auto items = m_model->findItems("application/octet-stream", Qt::MatchContains | Qt::MatchFixedString | Qt::MatchRecursive);
+ const auto flags = Qt::MatchContains | Qt::MatchFixedString | Qt::MatchRecursive;
+ const auto items = m_model->findItems("application/octet-stream", flags);
if (!items.isEmpty())
m_treeView->expand(m_model->indexFromItem(items.constFirst()));
@@ -93,7 +89,8 @@ void MainWindow::detectFile()
const QModelIndex index = mimeType.isValid()
? m_model->indexForMimeType(mimeType.name()) : QModelIndex();
if (index.isValid()) {
- statusBar()->showMessage(tr("\"%1\" is of type \"%2\"").arg(fi.fileName(), mimeType.name()));
+ statusBar()->showMessage(tr("\"%1\" is of type \"%2\"").arg(fi.fileName(),
+ mimeType.name()));
selectAndGoTo(index);
} else {
QMessageBox::information(this, tr("Unknown File Type"),
@@ -138,8 +135,8 @@ void MainWindow::find()
m_findMatches.clear();
m_findIndex = 0;
- const QList<QStandardItem *> items =
- m_model->findItems(value, Qt::MatchContains | Qt::MatchFixedString | Qt::MatchRecursive);
+ const auto flags = Qt::MatchContains | Qt::MatchFixedString | Qt::MatchRecursive;
+ const QList<QStandardItem *> items = m_model->findItems(value, flags);
for (const QStandardItem *item : items)
m_findMatches.append(m_model->indexFromItem(item));
statusBar()->showMessage(tr("%n mime types match \"%1\".", 0, m_findMatches.size()).arg(value));
diff --git a/examples/corelib/mimetypes/mimetypebrowser/mainwindow.h b/examples/corelib/mimetypes/mimetypebrowser/mainwindow.h
index 4554d0873d..04827529fa 100644
--- a/examples/corelib/mimetypes/mimetypebrowser/mainwindow.h
+++ b/examples/corelib/mimetypes/mimetypebrowser/mainwindow.h
@@ -4,12 +4,11 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
+#include <QAction>
#include <QMainWindow>
#include <QModelIndexList>
-
-QT_FORWARD_DECLARE_CLASS(QAction)
-QT_FORWARD_DECLARE_CLASS(QTextEdit)
-QT_FORWARD_DECLARE_CLASS(QTreeView)
+#include <QTextEdit>
+#include <QTreeView>
class MimetypeModel;
diff --git a/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.h b/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.h
index b1c84a7797..061ede3c47 100644
--- a/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.h
+++ b/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.h
@@ -4,14 +4,14 @@
#ifndef MIMETYPEMODEL_H
#define MIMETYPEMODEL_H
-#include <QStandardItemModel>
+#include <QCoreApplication>
#include <QHash>
-
-QT_FORWARD_DECLARE_CLASS(QMimeType)
+#include <QMimeType>
+#include <QStandardItemModel>
class MimetypeModel : public QStandardItemModel
{
- Q_OBJECT
+ Q_DECLARE_TR_FUNCTIONS(MimetypeModel)
public:
enum Columns { NameColumn, ColumnCount };
diff --git a/examples/corelib/permissions/CMakeLists.txt b/examples/corelib/permissions/CMakeLists.txt
deleted file mode 100644
index 39a207b1ce..0000000000
--- a/examples/corelib/permissions/CMakeLists.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(permissions LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/permissions")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(permissions
- MANUAL_FINALIZATION
- main.cpp
- android/AndroidManifest.xml
-)
-
-set_target_properties(permissions PROPERTIES
- MACOSX_BUNDLE TRUE
- MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
- MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.examples.permissions"
- QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android"
-)
-
-target_link_libraries(permissions PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS permissions
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
-
-if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
- add_custom_command(TARGET permissions
- POST_BUILD COMMAND codesign -s - permissions.app)
-endif()
-
-qt_finalize_executable(permissions)
diff --git a/examples/corelib/permissions/Info.plist b/examples/corelib/permissions/Info.plist
deleted file mode 100644
index 57625d03dc..0000000000
--- a/examples/corelib/permissions/Info.plist
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>CFBundleInfoDictionaryVersion</key>
- <string>6.0</string>
- <key>CFBundlePackageType</key>
- <string>APPL</string>
-
- <key>CFBundleName</key>
- <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
- <key>CFBundleIdentifier</key>
- <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
- <key>CFBundleExecutable</key>
- <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
-
- <key>CFBundleVersion</key>
- <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
- <key>CFBundleShortVersionString</key>
- <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
-
- <key>LSMinimumSystemVersion</key>
- <string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
-
- <key>NSHumanReadableCopyright</key>
- <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
-
- <key>CFBundleIconFile</key>
- <string>${MACOSX_BUNDLE_ICON_FILE}</string>
-
- <key>CFBundleDevelopmentRegion</key>
- <string>English</string>
-
- <key>NSSupportsAutomaticGraphicsSwitching</key>
- <true/>
-
- <key>NSBluetoothAlwaysUsageDescription</key>
- <string>Testing BluetoothAlways</string>
- <key>NSCalendarsUsageDescription</key>
- <string>Testing Calendars</string>
- <key>NSCameraUsageDescription</key>
- <string>Testing Camera</string>
- <key>NSContactsUsageDescription</key>
- <string>Testing Contacts</string>
- <key>NSHealthShareUsageDescription</key>
- <string>Testing HealthShare</string>
- <key>NSHealthUpdateUsageDescription</key>
- <string>Testing HealthUpdate</string>
- <key>NSLocationUsageDescription</key>
- <string>Testing Location on macOS</string>
- <key>NSLocationWhenInUseUsageDescription</key>
- <string>Testing Location when in use on iOS</string>
- <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
- <string>Testing Location always and when in use on iOS</string>
- <key>NSMicrophoneUsageDescription</key>
- <string>Testing Microphone</string>
-
-</dict>
-</plist>
diff --git a/examples/corelib/permissions/android/AndroidManifest.xml b/examples/corelib/permissions/android/AndroidManifest.xml
deleted file mode 100644
index 557ec8007e..0000000000
--- a/examples/corelib/permissions/android/AndroidManifest.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.qtproject.example"
- android:installLocation="auto"
- android:versionCode="-- %%INSERT_VERSION_CODE%% --"
- android:versionName="-- %%INSERT_VERSION_NAME%% --">
- <uses-permission android:name="android.permission.CAMERA" />
- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
- <uses-permission android:name="android.permission.RECORD_AUDIO" />
- <uses-permission android:name="android.permission.BLUETOOTH" />
- <uses-permission android:name="android.permission.READ_CONTACTS" />
- <uses-permission android:name="android.permission.WRITE_CONTACTS" />
- <uses-permission android:name="android.permission.READ_CALENDAR" />
- <uses-permission android:name="android.permission.WRITE_CALENDAR" />
- <!-- %%INSERT_PERMISSIONS -->
- <!-- %%INSERT_FEATURES -->
- <supports-screens
- android:anyDensity="true"
- android:largeScreens="true"
- android:normalScreens="true"
- android:smallScreens="true" />
- <application
- android:name="org.qtproject.qt.android.bindings.QtApplication"
- android:hardwareAccelerated="true"
- android:label="-- %%INSERT_APP_NAME%% --"
- android:requestLegacyExternalStorage="true"
- android:allowNativeHeapPointerTagging="false"
- android:allowBackup="true"
- android:fullBackupOnly="false">
- <activity
- android:name="org.qtproject.qt.android.bindings.QtActivity"
- android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
- android:label="-- %%INSERT_APP_NAME%% --"
- android:launchMode="singleTop"
- android:screenOrientation="unspecified"
- android:exported="true">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
-
- <meta-data
- android:name="android.app.lib_name"
- android:value="-- %%INSERT_APP_LIB_NAME%% --" />
-
- <meta-data
- android:name="android.app.extract_android_style"
- android:value="minimal" />
- </activity>
- </application>
-</manifest>
diff --git a/examples/corelib/permissions/main.cpp b/examples/corelib/permissions/main.cpp
deleted file mode 100644
index 913aed2fec..0000000000
--- a/examples/corelib/permissions/main.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore/qmetaobject.h>
-#include <QtWidgets/qapplication.h>
-#include <QtWidgets/qwidget.h>
-#include <QtWidgets/qpushbutton.h>
-#include <QtWidgets/qlayout.h>
-#include <QtWidgets/qmessagebox.h>
-
-#if !QT_CONFIG(permissions)
-#error "This example requires the permissions feature, which is not enabled on this platform"
-#endif
-
-#include <QtCore/qpermissions.h>
-
-class PermissionWidget : public QWidget
-{
- Q_OBJECT
-public:
- explicit PermissionWidget(QWidget *parent = nullptr) : QWidget(parent)
- {
- QVBoxLayout *layout = new QVBoxLayout(this);
-
- static const QPermission permissions[] = {
- QCameraPermission{},
- QMicrophonePermission{},
- QBluetoothPermission{},
- QContactsPermission{},
- QCalendarPermission{},
- QLocationPermission{}
- };
-
- for (auto permission : permissions) {
- auto permissionName = QString::fromLatin1(permission.type().name());
- QPushButton *button = new QPushButton(permissionName.sliced(1, permissionName.length() - 11));
- connect(button, &QPushButton::clicked, this, &PermissionWidget::buttonClicked);
- button->setProperty("permission", QVariant::fromValue(permission));
- layout->addWidget(button);
- }
-
- QPalette pal = palette();
- pal.setBrush(QPalette::Window, QGradient(QGradient::HappyAcid));
- setPalette(pal);
- }
-
-private:
- void buttonClicked()
- {
- auto *button = static_cast<QPushButton*>(sender());
-
- auto permission = button->property("permission").value<QPermission>();
- Q_ASSERT(permission.type().isValid());
-
- switch (qApp->checkPermission(permission)) {
- case Qt::PermissionStatus::Undetermined:
- qApp->requestPermission(permission, this,
- [button](const QPermission &permission) {
- Q_UNUSED(permission);
- emit button->clicked(); // Try again
- }
- );
- return;
- case Qt::PermissionStatus::Denied:
- QMessageBox::warning(this, button->text(),
- tr("Permission is needed to use %1. Please grant permission "\
- "to this application in the system settings.").arg(button->text()));
- return;
- case Qt::PermissionStatus::Granted:
- break; // Proceed
- }
-
- // All good, can use the feature
- QMessageBox::information(this, button->text(),
- tr("Accessing %1").arg(button->text()));
- }
-};
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
- PermissionWidget widget;
- widget.show();
- return app.exec();
-}
-
-#include "main.moc"
diff --git a/examples/corelib/platform/CMakeLists.txt b/examples/corelib/platform/CMakeLists.txt
index 8eeda13095..b195713074 100644
--- a/examples/corelib/platform/CMakeLists.txt
+++ b/examples/corelib/platform/CMakeLists.txt
@@ -1,6 +1,6 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(ANDROID)
- add_subdirectory(androidnotifier)
+ qt_internal_add_example(androidnotifier)
endif()
diff --git a/examples/corelib/platform/androidnotifier/CMakeLists.txt b/examples/corelib/platform/androidnotifier/CMakeLists.txt
index e5271edd79..b356b15a43 100644
--- a/examples/corelib/platform/androidnotifier/CMakeLists.txt
+++ b/examples/corelib/platform/androidnotifier/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(androidnotifier LANGUAGES CXX)
@@ -8,16 +8,10 @@ if(NOT ANDROID)
message(FATAL_ERROR "Example only works on Android")
endif()
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
find_package(Qt6 REQUIRED COMPONENTS Widgets)
qt_standard_project_setup()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/platform/androidnotifier")
-
qt_add_executable(androidnotifier
MANUAL_FINALIZATION
main.cpp
@@ -28,6 +22,7 @@ qt_add_executable(androidnotifier
)
target_link_libraries(androidnotifier PRIVATE
+ Qt6::CorePrivate
Qt6::Widgets
)
@@ -49,7 +44,14 @@ qt_add_resources(androidnotifier "main"
)
install(TARGETS androidnotifier
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET androidnotifier
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/platform/androidnotifier/android/AndroidManifest.xml b/examples/corelib/platform/androidnotifier/android/AndroidManifest.xml
index b2d9cc7680..1d3cf1325b 100644
--- a/examples/corelib/platform/androidnotifier/android/AndroidManifest.xml
+++ b/examples/corelib/platform/androidnotifier/android/AndroidManifest.xml
@@ -4,12 +4,9 @@
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0">
- <!-- The comment below will be replaced with dependencies permissions upon deployment.
- Remove the comment if you do not require these default permissions. -->
- <!-- %%INSERT_PERMISSIONS -->
- <!-- The comment below will be replaced with dependencies permissions upon deployment.
- Remove the comment if you do not require these default features. -->
+ <!-- %%INSERT_PERMISSIONS -->
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<!-- %%INSERT_FEATURES -->
<supports-screens
@@ -29,7 +26,6 @@
<activity
android:name="org.qtproject.qt.android.bindings.QtActivity"
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
- android:label="Qt Notifier"
android:launchMode="singleTop"
android:screenOrientation="unspecified"
android:exported="true">
@@ -41,14 +37,6 @@
<meta-data
android:name="android.app.lib_name"
android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
-
- <meta-data
- android:name="android.app.background_running"
- android:value="false"/>
-
- <meta-data
- android:name="android.app.extract_android_style"
- android:value="none" />
</activity>
</application>
</manifest>
diff --git a/examples/corelib/platform/androidnotifier/androidnotifier.pro b/examples/corelib/platform/androidnotifier/androidnotifier.pro
index f1650c1911..7e5b845e10 100644
--- a/examples/corelib/platform/androidnotifier/androidnotifier.pro
+++ b/examples/corelib/platform/androidnotifier/androidnotifier.pro
@@ -1,5 +1,5 @@
-QT += core gui
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+QT += core gui widgets
+QT += core-private # For Notification permission request
SOURCES += \
main.cpp \
diff --git a/examples/corelib/platform/androidnotifier/doc/src/androidnotifier-example.qdoc b/examples/corelib/platform/androidnotifier/doc/src/androidnotifier-example.qdoc
index 186be9ec5a..1315ad7762 100644
--- a/examples/corelib/platform/androidnotifier/doc/src/androidnotifier-example.qdoc
+++ b/examples/corelib/platform/androidnotifier/doc/src/androidnotifier-example.qdoc
@@ -4,8 +4,9 @@
/*!
\title Qt Android Notifier
\example platform/androidnotifier
- \examplecategory {Mobile}
+ \meta tag {widgets,android,notification}
\brief Demonstrates calling Java code from Qt in an Android application.
+ \ingroup androidplatform
\image androidnotifier.png
diff --git a/examples/corelib/platform/androidnotifier/main.cpp b/examples/corelib/platform/androidnotifier/main.cpp
index 33e77c7018..07eff5d2b0 100644
--- a/examples/corelib/platform/androidnotifier/main.cpp
+++ b/examples/corelib/platform/androidnotifier/main.cpp
@@ -41,11 +41,11 @@ int main(int argc, char *argv[])
widget.setLayout(&mainLayout);
//! [Connect button signals]
- QObject::connect(&happyButton, &QPushButton::clicked, []() {
+ QObject::connect(&happyButton, &QPushButton::clicked, &happyButton, []() {
NotificationClient().setNotification("The user is happy!");
});
- QObject::connect(&sadButton, &QPushButton::clicked, []() {
+ QObject::connect(&sadButton, &QPushButton::clicked, &happyButton, []() {
NotificationClient().setNotification("The user is sad!");
});
//! [Connect button signals]
diff --git a/examples/corelib/platform/androidnotifier/notificationclient.cpp b/examples/corelib/platform/androidnotifier/notificationclient.cpp
index af1cb7322a..aa6093c29c 100644
--- a/examples/corelib/platform/androidnotifier/notificationclient.cpp
+++ b/examples/corelib/platform/androidnotifier/notificationclient.cpp
@@ -5,10 +5,22 @@
#include <QtCore/qjniobject.h>
#include <QtCore/qcoreapplication.h>
+#include <QtCore/private/qandroidextras_p.h>
+
+using namespace Qt::StringLiterals;
NotificationClient::NotificationClient(QObject *parent)
: QObject(parent)
{
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= __ANDROID_API_T__) {
+ const auto notificationPermission = "android.permission.POST_NOTIFICATIONS"_L1;
+ auto requestResult = QtAndroidPrivate::requestPermission(notificationPermission);
+ if (requestResult.result() != QtAndroidPrivate::Authorized) {
+ qWarning() << "Failed to acquire permission to post notifications "
+ "(required for Android 13+)";
+ }
+ }
+
connect(this, &NotificationClient::notificationChanged,
this, &NotificationClient::updateAndroidNotification);
}
diff --git a/examples/corelib/serialization/CMakeLists.txt b/examples/corelib/serialization/CMakeLists.txt
index 7dd5d476d1..e32e4df441 100644
--- a/examples/corelib/serialization/CMakeLists.txt
+++ b/examples/corelib/serialization/CMakeLists.txt
@@ -1,11 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-qt_internal_add_example(cbordump)
-qt_internal_add_example(convert)
-qt_internal_add_example(savegame)
-if(TARGET Qt6::Network AND TARGET Qt6::Widgets)
- qt_internal_add_example(rsslisting)
+if(NOT ANDROID)
+ qt_internal_add_example(cbordump)
+ qt_internal_add_example(convert)
+ qt_internal_add_example(savegame)
endif()
if(TARGET Qt6::Widgets)
qt_internal_add_example(streambookmarks)
diff --git a/examples/corelib/serialization/cbordump/CMakeLists.txt b/examples/corelib/serialization/cbordump/CMakeLists.txt
index 813b02b9c0..b2c3a536e3 100644
--- a/examples/corelib/serialization/cbordump/CMakeLists.txt
+++ b/examples/corelib/serialization/cbordump/CMakeLists.txt
@@ -1,15 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(cbordump LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/serialization/cbordump")
-
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
@@ -23,7 +21,14 @@ target_link_libraries(cbordump PRIVATE
)
install(TARGETS cbordump
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET cbordump
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/serialization/cbordump/cbortag.py b/examples/corelib/serialization/cbordump/cbortag.py
index 8634dcdc20..26a0f969e4 100755
--- a/examples/corelib/serialization/cbordump/cbortag.py
+++ b/examples/corelib/serialization/cbordump/cbortag.py
@@ -165,7 +165,7 @@ def main(argv, speak):
struct CborTagDescription
{{
QCborTag tag;
- const char *description; // with space and parentheses
+ const char *description; // with space and parentheses
}};
// {title}
diff --git a/examples/corelib/serialization/cbordump/doc/src/cbordump.qdoc b/examples/corelib/serialization/cbordump/doc/src/cbordump.qdoc
index bfb19768d8..a4dc01116f 100644
--- a/examples/corelib/serialization/cbordump/doc/src/cbordump.qdoc
+++ b/examples/corelib/serialization/cbordump/doc/src/cbordump.qdoc
@@ -3,7 +3,7 @@
/*!
\example serialization/cbordump
- \examplecategory {Input/Output}
+ \examplecategory {Data Processing & I/O}
\meta tag {network}
\title Parsing and displaying CBOR data
diff --git a/examples/corelib/serialization/cbordump/main.cpp b/examples/corelib/serialization/cbordump/main.cpp
index 4c02abd304..03c940452e 100644
--- a/examples/corelib/serialization/cbordump/main.cpp
+++ b/examples/corelib/serialization/cbordump/main.cpp
@@ -14,6 +14,8 @@
#include <stdarg.h>
#include <stdio.h>
+using namespace Qt::StringLiterals;
+
/*
* To regenerate:
* curl -O https://www.iana.org/assignments/cbor-tags/cbor-tags.xml
@@ -27,7 +29,7 @@
struct CborTagDescription
{
QCborTag tag;
- const char *description; // with space and parentheses
+ const char *description; // with space and parentheses
};
// Concise Binary Object Representation (CBOR) Tags
@@ -131,22 +133,18 @@ static const CborTagDescription tagDescriptions[] = {
enum {
// See RFC 7049 section 2.
- SmallValueBitLength = 5,
- SmallValueMask = (1 << SmallValueBitLength) - 1, /* 0x1f */
- Value8Bit = 24,
- Value16Bit = 25,
- Value32Bit = 26,
- Value64Bit = 27
+ SmallValueBitLength = 5,
+ SmallValueMask = (1 << SmallValueBitLength) - 1, /* 0x1f */
+ Value8Bit = 24,
+ Value16Bit = 25,
+ Value32Bit = 26,
+ Value64Bit = 27
};
//! [0]
struct CborDumper
{
- enum DumpOption {
- ShowCompact = 0x01,
- ShowWidthIndicators = 0x02,
- ShowAnnotated = 0x04
- };
+ enum DumpOption { ShowCompact = 0x01, ShowWidthIndicators = 0x02, ShowAnnotated = 0x04 };
Q_DECLARE_FLAGS(DumpOptions, DumpOption)
CborDumper(QFile *f, DumpOptions opts_);
@@ -183,8 +181,7 @@ static int cborNumberSize(quint64 value)
return normalSize;
}
-CborDumper::CborDumper(QFile *f, DumpOptions opts_)
- : opts(opts_)
+CborDumper::CborDumper(QFile *f, DumpOptions opts_) : opts(opts_)
{
// try to mmap the file, this is faster
char *ptr = reinterpret_cast<char *>(f->map(0, f->size(), QFile::MapPrivateOption));
@@ -231,7 +228,8 @@ QCborError CborDumper::dump()
return err;
}
-template <typename T> static inline bool canConvertTo(double v)
+template<typename T>
+static inline bool canConvertTo(double v)
{
using TypeInfo = std::numeric_limits<T>;
// The [conv.fpint] (7.10 Floating-integral conversions) section of the
@@ -252,31 +250,32 @@ template <typename T> static inline bool canConvertTo(double v)
return v == floor(v);
}
-static QString fpToString(double v, const char *suffix)
+static QString fpToString(double v, QLatin1StringView suffix = ""_L1)
{
if (qIsInf(v))
- return v < 0 ? QStringLiteral("-inf") : QStringLiteral("inf");
+ return v < 0 ? "-inf"_L1 : "inf"_L1;
if (qIsNaN(v))
- return QStringLiteral("nan");
+ return "nan"_L1;
if (canConvertTo<qint64>(v))
- return QString::number(qint64(v)) + ".0" + suffix;
+ return QString::number(qint64(v)) + ".0"_L1 + suffix;
if (canConvertTo<quint64>(v))
- return QString::number(quint64(v)) + ".0" + suffix;
+ return QString::number(quint64(v)) + ".0"_L1 + suffix;
QString s = QString::number(v, 'g', QLocale::FloatingPointShortest);
- if (!s.contains('.') && !s.contains('e'))
- s += '.';
- s += suffix;
+ if (!s.contains(u'.') && !s.contains(u'e'))
+ s += u'.';
+ if (suffix.size())
+ s += suffix;
return s;
};
void CborDumper::dumpOne(int nestingLevel)
{
- QString indent(1, QLatin1Char(' '));
+ QString indent(1, u' ');
QString indented = indent;
if (!opts.testFlag(ShowCompact)) {
- indent = QLatin1Char('\n') + QString(4 * nestingLevel, QLatin1Char(' '));
- indented = QLatin1Char('\n') + QString(4 + 4 * nestingLevel, QLatin1Char(' '));
+ indent = u'\n' + QString(4 * nestingLevel, u' ');
+ indented = u'\n' + QString(4 + 4 * nestingLevel, u' ');
}
switch (reader.type()) {
@@ -316,7 +315,7 @@ void CborDumper::dumpOne(int nestingLevel)
printStringWidthIndicator(r.data.size());
r = reader.readByteArray();
- comma = QLatin1Char(',') + indented;
+ comma = u',' + indented;
}
} else {
auto r = reader.readString();
@@ -325,7 +324,7 @@ void CborDumper::dumpOne(int nestingLevel)
printStringWidthIndicator(r.data.toUtf8().size());
r = reader.readString();
- comma = QLatin1Char(',') + indented;
+ comma = u',' + indented;
}
}
@@ -381,7 +380,7 @@ void CborDumper::dumpOne(int nestingLevel)
if (reader.next()) {
printWidthIndicator(quint64(tag));
printf("(");
- dumpOne(nestingLevel); // same level!
+ dumpOne(nestingLevel); // same level!
printf(")");
}
@@ -413,15 +412,15 @@ void CborDumper::dumpOne(int nestingLevel)
break;
case QCborStreamReader::Float16:
- printf("%s", qPrintable(fpToString(reader.toFloat16(), "f16")));
+ printf("%s", qPrintable(fpToString(reader.toFloat16(), "f16"_L1)));
reader.next();
break;
case QCborStreamReader::Float:
- printf("%s", qPrintable(fpToString(reader.toFloat(), "f")));
+ printf("%s", qPrintable(fpToString(reader.toFloat(), "f"_L1)));
reader.next();
break;
case QCborStreamReader::Double:
- printf("%s", qPrintable(fpToString(reader.toDouble(), "")));
+ printf("%s", qPrintable(fpToString(reader.toDouble())));
reader.next();
break;
case QCborStreamReader::Invalid:
@@ -446,7 +445,7 @@ void CborDumper::dumpOneDetailed(int nestingLevel)
if (cborNumberSize(value) != actualSize)
printf(" (overlong)");
};
- auto print = [=](const char *descr, const char *fmt, ...) {
+ auto print = [&](const char *descr, const char *fmt, ...) {
qint64 prevOffset = offset;
offset = reader.currentOffset();
if (prevOffset == offset)
@@ -474,13 +473,13 @@ void CborDumper::dumpOneDetailed(int nestingLevel)
};
auto printFp = [=](const char *descr, double d) {
- QString s = fpToString(d, "");
+ QString s = fpToString(d);
if (s.size() <= 6)
return print(descr, "%s", qPrintable(s));
return print(descr, "%a", d);
};
- auto printString = [=](const char *descr) {
+ auto printString = [&](const char *descr) {
constexpr qsizetype ChunkSizeLimit = std::numeric_limits<int>::max();
QByteArray indent(nestingLevel * 2, ' ');
const char *chunkStr = (reader.isLengthKnown() ? "" : "chunk ");
@@ -489,7 +488,7 @@ void CborDumper::dumpOneDetailed(int nestingLevel)
qsizetype size = reader.currentStringChunkSize();
if (size < 0)
- return; // error
+ return; // error
if (size >= ChunkSizeLimit) {
fprintf(stderr, "String length too big, %lli\n", qint64(size));
exit(EXIT_FAILURE);
@@ -534,7 +533,7 @@ void CborDumper::dumpOneDetailed(int nestingLevel)
printf(" %s%s", indent.constData(), section.toHex(' ').constData());
// print the decode
- QByteArray spaces(width > 0 ? width - section.size() * 3 + 1: 0, ' ');
+ QByteArray spaces(width > 0 ? width - section.size() * 3 + 1 : 0, ' ');
printf("%s # \"", spaces.constData());
auto ptr = reinterpret_cast<const uchar *>(section.constData());
for (int j = 0; j < section.size(); ++j)
@@ -546,7 +545,7 @@ void CborDumper::dumpOneDetailed(int nestingLevel)
// get the next chunk
size = reader.currentStringChunkSize();
if (size < 0)
- return; // error
+ return; // error
if (size >= ChunkSizeLimit) {
fprintf(stderr, "String length too big, %lli\n", qint64(size));
exit(EXIT_FAILURE);
@@ -685,7 +684,9 @@ void CborDumper::printByteArray(const QByteArray &ba)
break;
case quint8(QCborKnownTags::ExpectedBase64url):
- printf("b64'%s'", ba.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals).constData());
+ printf("b64'%s'",
+ ba.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)
+ .constData());
break;
}
}
@@ -726,23 +727,20 @@ int main(int argc, char *argv[])
setlocale(LC_ALL, "C");
QCommandLineParser parser;
- parser.setApplicationDescription(QStringLiteral("CBOR Dumper tool"));
+ parser.setApplicationDescription("CBOR Dumper tool"_L1);
parser.addHelpOption();
- QCommandLineOption compact({QStringLiteral("c"), QStringLiteral("compact")},
- QStringLiteral("Use compact form (no line breaks)"));
+ QCommandLineOption compact({"c"_L1, "compact"_L1}, "Use compact form (no line breaks)"_L1);
parser.addOption(compact);
- QCommandLineOption showIndicators({QStringLiteral("i"), QStringLiteral("indicators")},
- QStringLiteral("Show indicators for width of lengths and integrals"));
+ QCommandLineOption showIndicators({ "i"_L1, "indicators"_L1 },
+ "Show indicators for width of lengths and integrals"_L1);
parser.addOption(showIndicators);
- QCommandLineOption verbose({QStringLiteral("a"), QStringLiteral("annotated")},
- QStringLiteral("Show bytes and annotated decoding"));
+ QCommandLineOption verbose({"a"_L1, "annotated"_L1}, "Show bytes and annotated decoding"_L1);
parser.addOption(verbose);
- parser.addPositionalArgument(QStringLiteral("[source]"),
- QStringLiteral("CBOR file to read from"));
+ parser.addPositionalArgument("[source]"_L1, "CBOR file to read from"_L1);
parser.process(app);
diff --git a/examples/corelib/serialization/convert/CMakeLists.txt b/examples/corelib/serialization/convert/CMakeLists.txt
index 5a10a78a5a..24ad5bbb6a 100644
--- a/examples/corelib/serialization/convert/CMakeLists.txt
+++ b/examples/corelib/serialization/convert/CMakeLists.txt
@@ -1,27 +1,27 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(convert LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/serialization/convert")
-
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
qt_add_executable(convert
cborconverter.cpp cborconverter.h
- converter.h
+ converter.cpp converter.h
datastreamconverter.cpp datastreamconverter.h
+ debugtextdumper.cpp debugtextdumper.h
jsonconverter.cpp jsonconverter.h
main.cpp
nullconverter.cpp nullconverter.h
textconverter.cpp textconverter.h
+ variantorderedmap.h
xmlconverter.cpp xmlconverter.h
)
@@ -30,7 +30,14 @@ target_link_libraries(convert PRIVATE
)
install(TARGETS convert
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET convert
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/serialization/convert/cborconverter.cpp b/examples/corelib/serialization/convert/cborconverter.cpp
index 85ca8c12ed..969f2741e0 100644
--- a/examples/corelib/serialization/convert/cborconverter.cpp
+++ b/examples/corelib/serialization/convert/cborconverter.cpp
@@ -2,20 +2,24 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "cborconverter.h"
+#include "variantorderedmap.h"
+#include <QCborArray>
+#include <QCborMap>
#include <QCborStreamReader>
#include <QCborStreamWriter>
-#include <QCborMap>
-#include <QCborArray>
#include <QCborValue>
#include <QDataStream>
-#include <QFloat16>
+#include <QDebug>
#include <QFile>
+#include <QFloat16>
#include <QMetaType>
#include <QTextStream>
#include <stdio.h>
+using namespace Qt::StringLiterals;
+
static CborConverter cborConverter;
static CborDiagnosticDumper cborDiagnosticDumper;
@@ -55,9 +59,9 @@ QT_END_NAMESPACE
// non-string keys in CBOR maps (QVariantMap can't handle those). Instead, we
// have our own set of converter functions so we can keep the keys properly.
+//! [0]
static QVariant convertCborValue(const QCborValue &value);
-//! [0]
static QVariant convertCborMap(const QCborMap &map)
{
VariantOrderedMap result;
@@ -85,8 +89,9 @@ static QVariant convertCborValue(const QCborValue &value)
return value.toVariant();
}
//! [0]
-enum TrimFloatingPoint { Double, Float, Float16 };
+
//! [1]
+enum TrimFloatingPoint { Double, Float, Float16 };
static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrimming)
{
if (v.userType() == QMetaType::QVariantList) {
@@ -118,41 +123,28 @@ static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrim
}
//! [1]
-QString CborDiagnosticDumper::name()
+QString CborDiagnosticDumper::name() const
{
- return QStringLiteral("cbor-dump");
+ return "cbor-dump"_L1;
}
-Converter::Direction CborDiagnosticDumper::directions()
+Converter::Directions CborDiagnosticDumper::directions() const
{
- return Out;
+ return Direction::Out;
}
-Converter::Options CborDiagnosticDumper::outputOptions()
+Converter::Options CborDiagnosticDumper::outputOptions() const
{
return SupportsArbitraryMapKeys;
}
-const char *CborDiagnosticDumper::optionsHelp()
+const char *CborDiagnosticDumper::optionsHelp() const
{
return diagnosticHelp;
}
-bool CborDiagnosticDumper::probeFile(QIODevice *f)
-{
- Q_UNUSED(f);
- return false;
-}
-
-QVariant CborDiagnosticDumper::loadFile(QIODevice *f, Converter *&outputConverter)
-{
- Q_UNREACHABLE();
- Q_UNUSED(f);
- Q_UNUSED(outputConverter);
- return QVariant();
-}
-
-void CborDiagnosticDumper::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
+void CborDiagnosticDumper::saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const
{
QCborValue::DiagnosticNotationOptions opts = QCborValue::LineWrapped;
for (const QString &s : options) {
@@ -175,14 +167,12 @@ void CborDiagnosticDumper::saveFile(QIODevice *f, const QVariant &contents, cons
}
}
- fprintf(stderr, "Unknown CBOR diagnostic option '%s'. Available options are:\n%s",
- qPrintable(s), diagnosticHelp);
- exit(EXIT_FAILURE);
+ qFatal("Unknown CBOR diagnostic option '%s'. Available options are:\n%s",
+ qPrintable(s), diagnosticHelp);
}
QTextStream out(f);
- out << convertFromVariant(contents, Double).toDiagnosticNotation(opts)
- << Qt::endl;
+ out << convertFromVariant(contents, Double).toDiagnosticNotation(opts) << Qt::endl;
}
CborConverter::CborConverter()
@@ -190,37 +180,36 @@ CborConverter::CborConverter()
qRegisterMetaType<QCborTag>();
}
-QString CborConverter::name()
+QString CborConverter::name() const
{
return "cbor";
}
-Converter::Direction CborConverter::directions()
+Converter::Directions CborConverter::directions() const
{
- return InOut;
+ return Direction::InOut;
}
-Converter::Options CborConverter::outputOptions()
+Converter::Options CborConverter::outputOptions() const
{
return SupportsArbitraryMapKeys;
}
-const char *CborConverter::optionsHelp()
+const char *CborConverter::optionsHelp() const
{
return cborOptionHelp;
}
-bool CborConverter::probeFile(QIODevice *f)
+bool CborConverter::probeFile(QIODevice *f) const
{
if (QFile *file = qobject_cast<QFile *>(f)) {
- if (file->fileName().endsWith(QLatin1String(".cbor")))
+ if (file->fileName().endsWith(".cbor"_L1))
return true;
}
return f->isReadable() && f->peek(3) == QByteArray("\xd9\xd9\xf7", 3);
}
-//! [2]
-QVariant CborConverter::loadFile(QIODevice *f, Converter *&outputConverter)
+QVariant CborConverter::loadFile(QIODevice *f, const Converter *&outputConverter) const
{
const char *ptr = nullptr;
if (auto file = qobject_cast<QFile *>(f))
@@ -237,28 +226,25 @@ QVariant CborConverter::loadFile(QIODevice *f, Converter *&outputConverter)
QCborValue contents = QCborValue::fromCbor(reader);
qint64 offset = reader.currentOffset();
if (reader.lastError()) {
- fprintf(stderr, "Error loading CBOR contents (byte %lld): %s\n", offset,
- qPrintable(reader.lastError().toString()));
- fprintf(stderr, " bytes: %s\n",
- (ptr ? mapped.mid(offset, 9) : f->read(9)).toHex(' ').constData());
- exit(EXIT_FAILURE);
+ qFatal().nospace()
+ << "Error loading CBOR contents (byte " << offset
+ << "): " << reader.lastError().toString()
+ << "\n bytes: " << (ptr ? mapped.mid(offset, 9) : f->read(9));
} else if (offset < mapped.size() || (!ptr && f->bytesAvailable())) {
- fprintf(stderr, "Warning: bytes remaining at the end of the CBOR stream\n");
+ qWarning("Warning: bytes remaining at the end of the CBOR stream");
}
if (outputConverter == nullptr)
outputConverter = &cborDiagnosticDumper;
- else if (outputConverter == null)
+ else if (isNull(outputConverter))
return QVariant();
else if (!outputConverter->outputOptions().testFlag(SupportsArbitraryMapKeys))
return contents.toVariant();
return convertCborValue(contents);
}
-//! [2]
-//! [3]
-void CborConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
+
+void CborConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) const
{
- //! [3]
bool useSignature = true;
bool useIntegers = true;
enum { Yes, No, Always } useFloat16 = Yes, useFloat = Yes;
@@ -313,13 +299,13 @@ void CborConverter::saveFile(QIODevice *f, const QVariant &contents, const QStri
}
}
- fprintf(stderr, "Unknown CBOR format option '%s'. Valid options are:\n%s",
- qPrintable(s), cborOptionHelp);
- exit(EXIT_FAILURE);
+ qFatal("Unknown CBOR format option '%s'. Valid options are:\n%s",
+ qPrintable(s), cborOptionHelp);
}
- //! [4]
- QCborValue v = convertFromVariant(contents,
- useFloat16 == Always ? Float16 : useFloat == Always ? Float : Double);
+
+ QCborValue v =
+ convertFromVariant(contents,
+ useFloat16 == Always ? Float16 : useFloat == Always ? Float : Double);
QCborStreamWriter writer(f);
if (useSignature)
writer.append(QCborKnownTags::Signature);
@@ -333,4 +319,3 @@ void CborConverter::saveFile(QIODevice *f, const QVariant &contents, const QStri
opts |= QCborValue::UseFloat16;
v.toCbor(writer, opts);
}
-//! [4]
diff --git a/examples/corelib/serialization/convert/cborconverter.h b/examples/corelib/serialization/convert/cborconverter.h
index d19c9eb33e..db68f99fda 100644
--- a/examples/corelib/serialization/convert/cborconverter.h
+++ b/examples/corelib/serialization/convert/cborconverter.h
@@ -10,13 +10,12 @@ class CborDiagnosticDumper : public Converter
{
// Converter interface
public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
+ QString name() const override;
+ Directions directions() const override;
+ Options outputOptions() const override;
+ const char *optionsHelp() const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
};
class CborConverter : public Converter
@@ -26,13 +25,14 @@ public:
// Converter interface
public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
+ QString name() const override;
+ Directions directions() const override;
+ Options outputOptions() const override;
+ const char *optionsHelp() const override;
+ bool probeFile(QIODevice *f) const override;
+ QVariant loadFile(QIODevice *f, const Converter *&outputConverter) const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
};
#endif // CBORCONVERTER_H
diff --git a/examples/corelib/serialization/convert/convert.pro b/examples/corelib/serialization/convert/convert.pro
index 4c6b0b557a..7592de7a22 100644
--- a/examples/corelib/serialization/convert/convert.pro
+++ b/examples/corelib/serialization/convert/convert.pro
@@ -11,18 +11,22 @@ target.path = $$[QT_INSTALL_EXAMPLES]/corelib/serialization/convert
INSTALLS += target
SOURCES += main.cpp \
+ converter.cpp \
cborconverter.cpp \
- jsonconverter.cpp \
datastreamconverter.cpp \
+ debugtextdumper.cpp \
+ jsonconverter.cpp \
+ nullconverter.cpp \
textconverter.cpp \
- xmlconverter.cpp \
- nullconverter.cpp
+ xmlconverter.cpp
HEADERS += \
converter.h \
cborconverter.h \
- jsonconverter.h \
datastreamconverter.h \
+ debugtextdumper.h \
+ jsonconverter.h \
+ nullconverter.h \
textconverter.h \
- xmlconverter.h \
- nullconverter.h
+ variantorderedmap.h \
+ xmlconverter.h
diff --git a/examples/corelib/serialization/convert/converter.cpp b/examples/corelib/serialization/convert/converter.cpp
new file mode 100644
index 0000000000..a57f305971
--- /dev/null
+++ b/examples/corelib/serialization/convert/converter.cpp
@@ -0,0 +1,44 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "converter.h"
+
+//! [0]
+Converter::Converter()
+{
+ converters().append(this);
+}
+
+Converter::~Converter()
+{
+ converters().removeAll(this);
+}
+
+QList<const Converter *> &Converter::converters()
+{
+ Q_CONSTINIT static QList<const Converter *> store;
+ return store;
+}
+
+const QList<const Converter *> &Converter::allConverters()
+{
+ return converters();
+}
+//! [0]
+
+// Some virtual methods that Converter classes needn't override, when not relevant:
+Converter::Options Converter::outputOptions() const { return {}; }
+const char *Converter::optionsHelp() const { return nullptr; }
+bool Converter::probeFile(QIODevice *) const { return false; }
+
+// The virtual method they should override if they claim to support In:
+QVariant Converter::loadFile(QIODevice *, const Converter *&outputConverter) const
+{
+ Q_ASSERT(!directions().testFlag(Converter::Direction::In));
+ // For those that don't, this should never be called.
+ Q_UNIMPLEMENTED();
+ // But every implementation should at least do this:
+ if (!outputConverter)
+ outputConverter = this;
+ return QVariant();
+}
diff --git a/examples/corelib/serialization/convert/converter.h b/examples/corelib/serialization/convert/converter.h
index 4da4d47267..40b7575a1e 100644
--- a/examples/corelib/serialization/convert/converter.h
+++ b/examples/corelib/serialization/convert/converter.h
@@ -5,53 +5,41 @@
#define CONVERTER_H
#include <QIODevice>
-#include <QPair>
-#include <QVariant>
-#include <QVariantMap>
#include <QList>
+#include <QStringList>
+#include <QVariant>
-class VariantOrderedMap : public QList<QPair<QVariant, QVariant>>
-{
-public:
- VariantOrderedMap() = default;
- VariantOrderedMap(const QVariantMap &map)
- {
- reserve(map.size());
- for (auto it = map.begin(); it != map.end(); ++it)
- append({it.key(), it.value()});
- }
-};
-using Map = VariantOrderedMap;
-Q_DECLARE_METATYPE(Map)
-
+//! [0]
class Converter
{
+ static QList<const Converter *> &converters();
protected:
Converter();
+ static bool isNull(const Converter *converter); // in nullconverter.cpp
public:
- static Converter *null;
+ static const QList<const Converter *> &allConverters();
- enum Direction {
- In = 1, Out = 2, InOut = 3
- };
+ enum class Direction { In = 1, Out = 2, InOut = In | Out };
+ Q_DECLARE_FLAGS(Directions, Direction)
- enum Option {
- SupportsArbitraryMapKeys = 0x01
- };
+ enum Option { SupportsArbitraryMapKeys = 0x01 };
Q_DECLARE_FLAGS(Options, Option)
virtual ~Converter() = 0;
- virtual QString name() = 0;
- virtual Direction directions() = 0;
- virtual Options outputOptions() = 0;
- virtual const char *optionsHelp() = 0;
- virtual bool probeFile(QIODevice *f) = 0;
- virtual QVariant loadFile(QIODevice *f, Converter *&outputConverter) = 0;
- virtual void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) = 0;
+ virtual QString name() const = 0;
+ virtual Directions directions() const = 0;
+ virtual Options outputOptions() const;
+ virtual const char *optionsHelp() const;
+ virtual bool probeFile(QIODevice *f) const;
+ virtual QVariant loadFile(QIODevice *f, const Converter *&outputConverter) const;
+ virtual void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const = 0;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(Converter::Directions)
Q_DECLARE_OPERATORS_FOR_FLAGS(Converter::Options)
+//! [0]
#endif // CONVERTER_H
diff --git a/examples/corelib/serialization/convert/datastreamconverter.cpp b/examples/corelib/serialization/convert/datastreamconverter.cpp
index 451688e378..ce28fcb98e 100644
--- a/examples/corelib/serialization/convert/datastreamconverter.cpp
+++ b/examples/corelib/serialization/convert/datastreamconverter.cpp
@@ -2,20 +2,22 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "datastreamconverter.h"
+#include "debugtextdumper.h"
+#include "variantorderedmap.h"
#include <QDataStream>
-#include <QDebug>
-#include <QTextStream>
+
+using namespace Qt::StringLiterals;
static const char dataStreamOptionHelp[] =
"byteorder=host|big|little Byte order to use.\n"
- "version=<n> QDataStream version (default: Qt 5.0).\n"
+ "version=<n> QDataStream version (default: Qt 6.0).\n"
;
static const char signature[] = "qds";
-static DataStreamDumper dataStreamDumper;
-static DataStreamConverter DataStreamConverter;
+static DataStreamConverter dataStreamConverter;
+static DebugTextDumper debugTextDumper;
QDataStream &operator<<(QDataStream &ds, const VariantOrderedMap &map)
{
@@ -42,126 +44,44 @@ QDataStream &operator>>(QDataStream &ds, VariantOrderedMap &map)
return ds;
}
-
-static QString dumpVariant(const QVariant &v, const QString &indent = QLatin1String("\n"))
-{
- QString result;
- QString indented = indent + QLatin1String(" ");
-
- int type = v.userType();
- if (type == qMetaTypeId<VariantOrderedMap>() || type == QMetaType::QVariantMap) {
- const auto map = (type == QMetaType::QVariantMap) ?
- VariantOrderedMap(v.toMap()) : qvariant_cast<VariantOrderedMap>(v);
-
- result = QLatin1String("Map {");
- for (const auto &pair : map) {
- result += indented + dumpVariant(pair.first, indented);
- result.chop(1); // remove comma
- result += QLatin1String(" => ") + dumpVariant(pair.second, indented);
-
- }
- result.chop(1); // remove comma
- result += indent + QLatin1String("},");
- } else if (type == QMetaType::QVariantList) {
- const QVariantList list = v.toList();
-
- result = QLatin1String("List [");
- for (const auto &item : list)
- result += indented + dumpVariant(item, indented);
- result.chop(1); // remove comma
- result += indent + QLatin1String("],");
- } else {
- QDebug debug(&result);
- debug.nospace() << v << ',';
- }
- return result;
-}
-
-QString DataStreamDumper::name()
-{
- return QStringLiteral("datastream-dump");
-}
-
-Converter::Direction DataStreamDumper::directions()
-{
- return Out;
-}
-
-Converter::Options DataStreamDumper::outputOptions()
-{
- return SupportsArbitraryMapKeys;
-}
-
-const char *DataStreamDumper::optionsHelp()
-{
- return nullptr;
-}
-
-bool DataStreamDumper::probeFile(QIODevice *f)
-{
- Q_UNUSED(f);
- return false;
-}
-
-QVariant DataStreamDumper::loadFile(QIODevice *f, Converter *&outputConverter)
-{
- Q_UNREACHABLE();
- Q_UNUSED(f);
- Q_UNUSED(outputConverter);
- return QVariant();
-}
-
-void DataStreamDumper::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
-{
- Q_UNUSED(options);
- QString s = dumpVariant(contents);
- s[s.size() - 1] = QLatin1Char('\n'); // replace the comma with newline
-
- QTextStream out(f);
- out << s;
-}
-
DataStreamConverter::DataStreamConverter()
{
qRegisterMetaType<VariantOrderedMap>();
}
-QString DataStreamConverter::name()
+QString DataStreamConverter::name() const
{
- return QStringLiteral("datastream");
+ return "datastream"_L1;
}
-Converter::Direction DataStreamConverter::directions()
+Converter::Directions DataStreamConverter::directions() const
{
- return InOut;
+ return Direction::InOut;
}
-Converter::Options DataStreamConverter::outputOptions()
+Converter::Options DataStreamConverter::outputOptions() const
{
return SupportsArbitraryMapKeys;
}
-const char *DataStreamConverter::optionsHelp()
+const char *DataStreamConverter::optionsHelp() const
{
return dataStreamOptionHelp;
}
-bool DataStreamConverter::probeFile(QIODevice *f)
+bool DataStreamConverter::probeFile(QIODevice *f) const
{
return f->isReadable() && f->peek(sizeof(signature) - 1) == signature;
}
-QVariant DataStreamConverter::loadFile(QIODevice *f, Converter *&outputConverter)
+QVariant DataStreamConverter::loadFile(QIODevice *f, const Converter *&outputConverter) const
{
if (!outputConverter)
- outputConverter = &dataStreamDumper;
+ outputConverter = &debugTextDumper;
char c;
- if (f->read(sizeof(signature) -1) != signature ||
- !f->getChar(&c) || (c != 'l' && c != 'B')) {
- fprintf(stderr, "Could not load QDataStream file: invalid signature.\n");
- exit(EXIT_FAILURE);
- }
+ if (f->read(sizeof(signature) - 1) != signature || !f->getChar(&c) || (c != 'l' && c != 'B'))
+ qFatal("Could not load QDataStream file: invalid signature.");
QDataStream ds(f);
ds.setByteOrder(c == 'l' ? QDataStream::LittleEndian : QDataStream::BigEndian);
@@ -175,9 +95,10 @@ QVariant DataStreamConverter::loadFile(QIODevice *f, Converter *&outputConverter
return result;
}
-void DataStreamConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
+void DataStreamConverter::saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const
{
- QDataStream::Version version = QDataStream::Qt_5_0;
+ QDataStream::Version version = QDataStream::Qt_6_0;
auto order = QDataStream::ByteOrder(QSysInfo::ByteOrder);
for (const QString &option : options) {
const QStringList pair = option.split('=');
@@ -202,18 +123,16 @@ void DataStreamConverter::saveFile(QIODevice *f, const QVariant &contents, const
continue;
}
- fprintf(stderr, "Invalid version number '%s': must be a number from 1 to %d.\n",
- qPrintable(pair.last()), QDataStream::Qt_DefaultCompiledVersion);
- exit(EXIT_FAILURE);
+ qFatal("Invalid version number '%s': must be a number from 1 to %d.",
+ qPrintable(pair.last()), QDataStream::Qt_DefaultCompiledVersion);
}
}
- fprintf(stderr, "Unknown QDataStream formatting option '%s'. Available options are:\n%s",
+ qFatal("Unknown QDataStream formatting option '%s'. Available options are:\n%s",
qPrintable(option), dataStreamOptionHelp);
- exit(EXIT_FAILURE);
}
- char c = order == QDataStream::LittleEndian ? 'l' : 'B';
+ char c = order == QDataStream::LittleEndian ? 'l' : 'B';
f->write(signature);
f->write(&c, 1);
diff --git a/examples/corelib/serialization/convert/datastreamconverter.h b/examples/corelib/serialization/convert/datastreamconverter.h
index 95c8861e0e..201f3c4754 100644
--- a/examples/corelib/serialization/convert/datastreamconverter.h
+++ b/examples/corelib/serialization/convert/datastreamconverter.h
@@ -6,19 +6,6 @@
#include "converter.h"
-class DataStreamDumper : public Converter
-{
- // Converter interface
-public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
-};
-
class DataStreamConverter : public Converter
{
public:
@@ -26,13 +13,14 @@ public:
// Converter interface
public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
+ QString name() const override;
+ Directions directions() const override;
+ Options outputOptions() const override;
+ const char *optionsHelp() const override;
+ bool probeFile(QIODevice *f) const override;
+ QVariant loadFile(QIODevice *f, const Converter *&outputConverter) const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
};
#endif // DATASTREAMCONVERTER_H
diff --git a/examples/corelib/serialization/convert/debugtextdumper.cpp b/examples/corelib/serialization/convert/debugtextdumper.cpp
new file mode 100644
index 0000000000..f010bd8e2a
--- /dev/null
+++ b/examples/corelib/serialization/convert/debugtextdumper.cpp
@@ -0,0 +1,74 @@
+// Copyright (C) 2018 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "debugtextdumper.h"
+#include "variantorderedmap.h"
+
+#include <QDebug>
+#include <QTextStream>
+
+using namespace Qt::StringLiterals;
+
+// Static instance is declared in datastreamconverter.cpp, since it uses it.
+
+static QString dumpVariant(const QVariant &v, const QString &indent = "\n"_L1)
+{
+ QString result;
+ QString indented = indent + " "_L1;
+
+ int type = v.userType();
+ if (type == qMetaTypeId<VariantOrderedMap>() || type == QMetaType::QVariantMap) {
+ const auto map = (type == QMetaType::QVariantMap) ? VariantOrderedMap(v.toMap())
+ : qvariant_cast<VariantOrderedMap>(v);
+
+ result = "Map {"_L1;
+ for (const auto &pair : map) {
+ result += indented + dumpVariant(pair.first, indented);
+ result.chop(1); // remove comma
+ result += " => "_L1 + dumpVariant(pair.second, indented);
+ }
+ result.chop(1); // remove comma
+ result += indent + "},"_L1;
+ } else if (type == QMetaType::QVariantList) {
+ const QVariantList list = v.toList();
+
+ result = "List ["_L1;
+ for (const auto &item : list)
+ result += indented + dumpVariant(item, indented);
+ result.chop(1); // remove comma
+ result += indent + "],"_L1;
+ } else {
+ QDebug debug(&result);
+ debug.nospace() << v << ',';
+ }
+ return result;
+}
+
+QString DebugTextDumper::name() const
+{
+ return "debugtext-dump"_L1;
+}
+
+Converter::Directions DebugTextDumper::directions() const
+{
+ return Direction::Out;
+}
+
+Converter::Options DebugTextDumper::outputOptions() const
+{
+ return SupportsArbitraryMapKeys;
+}
+
+void DebugTextDumper::saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const
+{
+ if (!options.isEmpty()) {
+ qFatal("Unknown option '%s' to debug text output. This format has no options.",
+ qPrintable(options.first()));
+ }
+ QString s = dumpVariant(contents);
+ s[s.size() - 1] = u'\n'; // replace the comma with newline
+
+ QTextStream out(f);
+ out << s;
+}
diff --git a/examples/corelib/serialization/convert/debugtextdumper.h b/examples/corelib/serialization/convert/debugtextdumper.h
new file mode 100644
index 0000000000..7d3d762104
--- /dev/null
+++ b/examples/corelib/serialization/convert/debugtextdumper.h
@@ -0,0 +1,20 @@
+// Copyright (C) 2018 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef DEBUGTEXTDUMPER_H
+#define DEBUGTEXTDUMPER_H
+
+#include "converter.h"
+
+class DebugTextDumper : public Converter
+{
+ // Converter interface
+public:
+ QString name() const override;
+ Directions directions() const override;
+ Options outputOptions() const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
+};
+
+#endif // DEBUGTEXTDUMPER_H
diff --git a/examples/corelib/serialization/convert/doc/images/convert.png b/examples/corelib/serialization/convert/doc/images/convert.png
index 8d6816a626..53e05b4333 100644
--- a/examples/corelib/serialization/convert/doc/images/convert.png
+++ b/examples/corelib/serialization/convert/doc/images/convert.png
Binary files differ
diff --git a/examples/corelib/serialization/convert/doc/src/convert.qdoc b/examples/corelib/serialization/convert/doc/src/convert.qdoc
index 7baef83de2..187e81a85e 100644
--- a/examples/corelib/serialization/convert/doc/src/convert.qdoc
+++ b/examples/corelib/serialization/convert/doc/src/convert.qdoc
@@ -3,80 +3,154 @@
/*!
\example serialization/convert
- \examplecategory {Input/Output}
+ \examplecategory {Data Processing & I/O}
\meta tag {network}
- \title Convert Example
+ \title Serialization Converter
- \brief The Convert example demonstrates how to convert between different
- serialization formats.
+ \brief How to convert between different serialization formats.
- The Convert example converts between the serialization formats JSON, CBOR,
- XML, QDataStream and text. It can also auto detect the format being used.
- Not all formats support both input and output, and they have different
- sets of which types they support. QDataStream and XML are the richest,
- followed by CBOR, then JSON, and then the plain text one.
+ This example converts between JSON, CBOR, XML, QDataStream and some simple
+ text formats. It can auto-detect the format being used, or be told which
+ format to use. Not all formats support both input and output, and they have
+ different sets of which content datatypes they support. QDataStream and XML
+ are the richest, followed by CBOR, then JSON, and then the plain text
+ formats. Conversion via the less capable formats is apt to lose structure
+ from the data.
\image convert.png
+ \sa {Parsing and displaying CBOR data}, {Saving and Loading a Game}
+
\section1 The Converter Class
- The Converter class is the abstract superclass for all the converters to
- and from all the formats. They all convert to and from the QVariant class,
- which is used to represent all the datastructures internally.
- The name() function returns the name of the converter. The directions()
- function is used to determine if a converter can be used for input, output,
- or both. The outputOptions() and optionsHelp() functions are used to get
- and query which options are used by the different converters. The
- probeFile() function is used to determine if a file has the same file
- format as the converter. The loadFile() function deserializes the given
- file, while the saveFile() serializes to the given file.
+ The Converter class is the abstract superclass for all the converters to and
+ from all the formats. They all convert from or to the QVariant class, which
+ is used to represent all the datastructures internally.
- \section1 The CborConverter Class
+ \snippet serialization/convert/converter.h 0
- The CborConverter class shows how to serialize to and from the CBOR-format.
- There is also a CborDiagnosticDumper class to output in CBOR diagnostic
- notation. That is similar to JSON, but not exactly, because it allows
- displaying the contents of a CBOR stream losslessly, while a conversion
- to JSON is lossy.
+ The Converter constructor and destructor manage a list of available
+ converters used by the main program so that it knows what converters are
+ available. Each converter type defines a static instance that ensures it is
+ constructed and thus available to the main program via this list. The \c
+ allConverters() method provides \c main()'s code with access to the list.
- The convertCborValue() function is used to convert a QCborValue to a
- QVariant. It uses the helper functions convertCborMap() and
- convertCborArray().
- \snippet serialization/convert/cborconverter.cpp 0
-
- A CBOR-file is read using loadFile() function.
- \snippet serialization/convert/cborconverter.cpp 2
-
- The convertFromVariant() function is used to convert a QVariant to a
- QCborValue.
- \snippet serialization/convert/cborconverter.cpp 1
+ \snippet serialization/convert/converter.cpp 0
- A CBOR-file is written using the saveFile() function.
- \snippet serialization/convert/cborconverter.cpp 3
- \snippet serialization/convert/cborconverter.cpp 4
+ The name() function returns the name of the converter. The directions()
+ function is used to determine if a converter can be used for input, output,
+ or both. These enable the main program to report what converters are
+ available in its help text for the command-line options to select input and
+ output formats.
+
+ \snippet serialization/convert/main.cpp 0
+
+ The optionsHelp() function is used to report the various command-line
+ options supported by the available formats, when queried using its \c
+ {--format-options <format>} command-line option.
+
+ \snippet serialization/convert/main.cpp 1
+
+ The outputOptions() function reports the output capabilities of a converter.
+ At present the only optional feature is support for arbitrary keys in
+ mappings from keys to values. An input converter's loadFile() can use this
+ information to tailor the form in which it presents the data it has read, to
+ be as faithfully represented by the output converter as its capabilities
+ permit.
+
+ The probeFile() function is used to determine if a file matches the format
+ of the converter. The main program uses this to determine what format to use
+ when reading or writing a file, based on its name and potentially content,
+ when the user has not specified the format to use on the command-line.
+
+ The loadFile() function deserializes data. The caller tells loadFile() which
+ serializer it intends to use, so that loadFile() can query its
+ outputOptions() to determine the form in which to represent the loaded data.
+ If the caller hasn't settled on a choice of output converter, loadFile()
+ supplies it with a default output converter suitable to the data it is
+ returning.
+
+ The saveFile() function serializes data. It is passed options from the
+ command-line, as described by loadHelp(), that can tune the details of how
+ it represents the data when saving to file.
+
+ Both loadFile() and saveFile() can be used with an arbitrary \l QIODevice.
+ This means that a Converter could also be used with a network socket or
+ other source of data, to read from or write to. In the present program, the
+ main program always passes a \l QFile, accessing either a file on disk or
+ one of the standard streams of the process.
+
+ \section2 The Available Converters
+
+ Several converters are supported, illustrating how the converter program
+ could be adapted to other formats, should the need arise. See the source
+ code for each for its details. The CBOR converters serve as a relatively
+ full-featured illustration of the ways converters can work, that we'll look
+ into in more detail below. This table summarizes the available converters:
+
+ \table
+ \header \li Class \li mode \li format
+ \row \li CborConverter \li In/Out \li CBOR
+ \row \li CborDiagnosticDumper \li Out \li CBOR diagnostic
+ \row \li DataStreamConverter \li In/Out \li QDataStream
+ \row \li DebugTextDumper \li Out \li Lossless, non-standard, human-readable
+ \row \li JsonConverter \li In/Out \li JSON
+ \row \li NullConverter \li Out \li No output
+ \row \li TextConverter \li In/Out \li Structured plain text
+ \row \li XmlConverter \li In/Out \li XML
+ \endtable
+
+ Those that support input use themselves as loadFile()'s fallback converter,
+ except for the CBOR and QDataStream converters, which use their respective
+ output-only dumper companion classes. The null converter can be used as
+ output converter when running the program for the sake of any validation or
+ verification that an input converter may perform.
+
+ \section2 The CborConverter and CborDiagnosticDumper Classes
+
+ The CborConverter class supports serializing to and from the CBOR format.
+ It supports various options to configure the output of floating point values
+ and a \c{signature} option to determine whether to start its output with a
+ CBOR tag that serves as a file header, identifying the file as containing
+ CBOR data.
- \sa {CBOR Support in Qt}
+ There is also a CborDiagnosticDumper class to output in CBOR diagnostic
+ notation. It does not support loading data. The form of its output can be
+ configured using two options. One selects whether to use the (more verbose)
+ extended CBOR diagnostic format. The other control whether each CBOR value
+ appears on a separate line.
- \section1 The DataStreamConverter Class
+ The plain diagnostic notation is similar to JSON, but not exactly, because
+ it supports displaying the contents of a CBOR stream losslessly, while a
+ conversion to JSON can be lossy. CborConverter's loadFile() uses
+ CborDiagnosticDumper for the fallback output converter, if its caller hasn't
+ determined the output format for itself.
- The DataStreamConverter class is used to serialize to and from the
- QDataStream format. There is also the DataStreamDumper class for outputting
- the data lossless in a non-standardized human readable format.
+ The convertCborValue(), convertCborMap() and convertCborArray() helper
+ functions are used to convert a QCborValue to a QVariant, for the benefit of
+ CborConverter::loadFile().
- \section1 The JsonConverter Class
+ \snippet serialization/convert/cborconverter.cpp 0
- The JsonConverter class is used to serialize to and from the JSON-format.
- \sa {JSON Support in Qt}
+ The convertFromVariant() function is used to convert a QVariant to a
+ QCborValue for output by the \c saveFile() of either class.
- \section1 The XmlConverter Class
+ \snippet serialization/convert/cborconverter.cpp 1
- The XmlConverter class is used to serialize to and from the XML-format.
+ \sa {CBOR Support in Qt}
- \section1 The TextConverter Class
+ \section1 The convert program
- The TextConverter class is used to serialize to and from a text format.
+ The \c main() function sets up a \l QApplication and a \l QCommandLineParser
+ to make sense of the options the user has specified and provide help if the
+ user asks for it. It uses the values obtained for the various \l
+ QCommandLineOption instances describing the user's choices, plus the
+ positional arguments for file names, to prepare the converters it will use.
- \section1 The NullConverter Class
+ It then uses its input converter to load data (and possibly resolve its
+ choice of output converter, if it hasn't selected one yet) and its output
+ converter to serialize that data, taking account of any output options the
+ user has supplied on the command-line.
- The NullConverter class is an output serializer that does nothing.
+ \snippet serialization/convert/main.cpp 2
*/
diff --git a/examples/corelib/serialization/convert/jsonconverter.cpp b/examples/corelib/serialization/convert/jsonconverter.cpp
index f52c9db554..1b59ed5c1f 100644
--- a/examples/corelib/serialization/convert/jsonconverter.cpp
+++ b/examples/corelib/serialization/convert/jsonconverter.cpp
@@ -9,49 +9,39 @@
#include <QJsonObject>
#include <QJsonValue>
+using namespace Qt::StringLiterals;
+
static JsonConverter jsonConverter;
-static const char jsonOptionHelp[] =
- "compact=no|yes Use compact JSON form.\n";
+static const char jsonOptionHelp[] = "compact=no|yes Use compact JSON form.\n";
static QJsonDocument convertFromVariant(const QVariant &v)
{
QJsonDocument doc = QJsonDocument::fromVariant(v);
- if (!doc.isObject() && !doc.isArray()) {
- fprintf(stderr, "Could not convert contents to JSON.\n");
- exit(EXIT_FAILURE);
- }
+ if (!doc.isObject() && !doc.isArray())
+ qFatal("Could not convert contents to JSON.");
return doc;
}
-JsonConverter::JsonConverter()
-{
-}
-
-QString JsonConverter::name()
-{
- return "json";
-}
-
-Converter::Direction JsonConverter::directions()
+QString JsonConverter::name() const
{
- return InOut;
+ return "json"_L1;
}
-Converter::Options JsonConverter::outputOptions()
+Converter::Directions JsonConverter::directions() const
{
- return {};
+ return Direction::InOut;
}
-const char *JsonConverter::optionsHelp()
+const char *JsonConverter::optionsHelp() const
{
return jsonOptionHelp;
}
-bool JsonConverter::probeFile(QIODevice *f)
+bool JsonConverter::probeFile(QIODevice *f) const
{
if (QFile *file = qobject_cast<QFile *>(f)) {
- if (file->fileName().endsWith(QLatin1String(".json")))
+ if (file->fileName().endsWith(".json"_L1))
return true;
}
@@ -62,7 +52,7 @@ bool JsonConverter::probeFile(QIODevice *f)
return false;
}
-QVariant JsonConverter::loadFile(QIODevice *f, Converter *&outputConverter)
+QVariant JsonConverter::loadFile(QIODevice *f, const Converter *&outputConverter) const
{
if (!outputConverter)
outputConverter = this;
@@ -78,27 +68,26 @@ QVariant JsonConverter::loadFile(QIODevice *f, Converter *&outputConverter)
if (doc.isNull())
doc = QJsonDocument::fromJson(f->readAll(), &error);
if (error.error) {
- fprintf(stderr, "Could not parse JSON content: offset %d: %s",
- error.offset, qPrintable(error.errorString()));
- exit(EXIT_FAILURE);
+ qFatal("Could not parse JSON content: offset %d: %s",
+ error.offset, qPrintable(error.errorString()));
}
- if (outputConverter == null)
+ if (isNull(outputConverter))
return QVariant();
return doc.toVariant();
}
-void JsonConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
+void JsonConverter::saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const
{
QJsonDocument::JsonFormat format = QJsonDocument::Indented;
for (const QString &s : options) {
- if (s == QLatin1String("compact=no")) {
+ if (s == "compact=no"_L1) {
format = QJsonDocument::Indented;
- } else if (s == QLatin1String("compact=yes")) {
+ } else if (s == "compact=yes"_L1) {
format = QJsonDocument::Compact;
} else {
- fprintf(stderr, "Unknown option '%s' to JSON output. Valid options are:\n%s",
- qPrintable(s), jsonOptionHelp);
- exit(EXIT_FAILURE);
+ qFatal("Unknown option '%s' to JSON output. Valid options are:\n%s",
+ qPrintable(s), jsonOptionHelp);
}
}
diff --git a/examples/corelib/serialization/convert/jsonconverter.h b/examples/corelib/serialization/convert/jsonconverter.h
index 40430a6b70..e1dd1ecdb4 100644
--- a/examples/corelib/serialization/convert/jsonconverter.h
+++ b/examples/corelib/serialization/convert/jsonconverter.h
@@ -8,18 +8,15 @@
class JsonConverter : public Converter
{
-public:
- JsonConverter();
-
// Converter interface
public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
+ QString name() const override;
+ Directions directions() const override;
+ const char *optionsHelp() const override;
+ bool probeFile(QIODevice *f) const override;
+ QVariant loadFile(QIODevice *f, const Converter *&outputConverter) const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
};
#endif // JSONCONVERTER_H
diff --git a/examples/corelib/serialization/convert/main.cpp b/examples/corelib/serialization/convert/main.cpp
index 00c626e1c8..d3021fadca 100644
--- a/examples/corelib/serialization/convert/main.cpp
+++ b/examples/corelib/serialization/convert/main.cpp
@@ -1,4 +1,5 @@
// Copyright (C) 2018 Intel Corporation.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "converter.h"
@@ -11,177 +12,144 @@
#include <stdio.h>
-static QList<Converter *> *availableConverters;
+using namespace Qt::StringLiterals;
-Converter::Converter()
+static const Converter *prepareConverter(QString format, Converter::Direction direction,
+ QFile *stream)
{
- if (!availableConverters)
- availableConverters = new QList<Converter *>;
- availableConverters->append(this);
-}
+ const bool out = direction == Converter::Direction::Out;
+ const QIODevice::OpenMode mode = out
+ ? QIODevice::WriteOnly | QIODevice::Truncate
+ : QIODevice::ReadOnly;
+ const char *dirn = out ? "output" : "input";
+
+ if (stream->fileName().isEmpty())
+ stream->open(out ? stdout : stdin, mode);
+ else
+ stream->open(mode);
+
+ if (!stream->isOpen()) {
+ qFatal("Could not open \"%s\" for %s: %s",
+ qPrintable(stream->fileName()), dirn, qPrintable(stream->errorString()));
+ } else if (format == "auto"_L1) {
+ for (const Converter *conv : Converter::allConverters()) {
+ if (conv->directions().testFlag(direction) && conv->probeFile(stream))
+ return conv;
+ }
+ if (out) // Failure to identify output format can be remedied by loadFile().
+ return nullptr;
-Converter::~Converter()
-{
- availableConverters->removeAll(this);
+ // Input format, however, we must know before we can call that:
+ qFatal("Could not determine input format. Specify it with the -I option.");
+ } else {
+ for (const Converter *conv : Converter::allConverters()) {
+ if (conv->name() == format) {
+ if (!conv->directions().testFlag(direction)) {
+ qWarning("File format \"%s\" cannot be used for %s",
+ qPrintable(format), dirn);
+ continue; // on the off chance there's another with the same name
+ }
+ return conv;
+ }
+ }
+ qFatal("Unknown %s file format \"%s\"", dirn, qPrintable(format));
+ }
+ Q_UNREACHABLE_RETURN(nullptr);
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
+//! [0]
QStringList inputFormats;
QStringList outputFormats;
- for (Converter *conv : std::as_const(*availableConverters)) {
+ for (const Converter *conv : Converter::allConverters()) {
auto direction = conv->directions();
QString name = conv->name();
- if (direction & Converter::In)
+ if (direction.testFlag(Converter::Direction::In))
inputFormats << name;
- if (direction & Converter::Out)
+ if (direction.testFlag(Converter::Direction::Out))
outputFormats << name;
}
+//! [0]
inputFormats.sort();
outputFormats.sort();
- inputFormats.prepend("auto");
- outputFormats.prepend("auto");
+ inputFormats.prepend("auto"_L1);
+ outputFormats.prepend("auto"_L1);
QCommandLineParser parser;
- parser.setApplicationDescription(QStringLiteral("Qt file format conversion tool"));
+ parser.setApplicationDescription("Qt serialization format conversion tool"_L1);
parser.addHelpOption();
- QCommandLineOption inputFormatOption(QStringList{"I", "input-format"});
- inputFormatOption.setDescription(QLatin1String("Select the input format for the input file. Available formats: ") +
- inputFormats.join(", "));
- inputFormatOption.setValueName("format");
+ QCommandLineOption inputFormatOption(QStringList{ "I"_L1, "input-format"_L1 });
+ inputFormatOption.setDescription(
+ "Select the input format for the input file. Available formats: "_L1
+ + inputFormats.join(", "_L1));
+ inputFormatOption.setValueName("format"_L1);
inputFormatOption.setDefaultValue(inputFormats.constFirst());
parser.addOption(inputFormatOption);
- QCommandLineOption outputFormatOption(QStringList{"O", "output-format"});
- outputFormatOption.setDescription(QLatin1String("Select the output format for the output file. Available formats: ") +
- outputFormats.join(", "));
- outputFormatOption.setValueName("format");
+ QCommandLineOption outputFormatOption(QStringList{ "O"_L1, "output-format"_L1 });
+ outputFormatOption.setDescription(
+ "Select the output format for the output file. Available formats: "_L1
+ + outputFormats.join(", "_L1));
+ outputFormatOption.setValueName("format"_L1);
outputFormatOption.setDefaultValue(outputFormats.constFirst());
parser.addOption(outputFormatOption);
- QCommandLineOption optionOption(QStringList{"o", "option"});
- optionOption.setDescription(QStringLiteral("Format-specific options. Use --format-options to find out what options are available."));
- optionOption.setValueName("options...");
+ QCommandLineOption optionOption(QStringList{ "o"_L1, "option"_L1 });
+ optionOption.setDescription(
+ "Format-specific options. Use --format-options to find out what options are available."_L1);
+ optionOption.setValueName("options..."_L1);
optionOption.setDefaultValues({});
parser.addOption(optionOption);
- QCommandLineOption formatOptionsOption("format-options");
- formatOptionsOption.setDescription(QStringLiteral("Prints the list of valid options for --option for the converter format <format>."));
- formatOptionsOption.setValueName("format");
+ QCommandLineOption formatOptionsOption("format-options"_L1);
+ formatOptionsOption.setDescription(
+ "Prints the list of valid options for --option for the converter format <format>."_L1);
+ formatOptionsOption.setValueName("format"_L1);
parser.addOption(formatOptionsOption);
- parser.addPositionalArgument(QStringLiteral("[source]"),
- QStringLiteral("File to read from (stdin if none)"));
- parser.addPositionalArgument(QStringLiteral("[destination]"),
- QStringLiteral("File to write to (stdout if none)"));
+ parser.addPositionalArgument("[source]"_L1, "File to read from (stdin if none)"_L1);
+ parser.addPositionalArgument("[destination]"_L1, "File to write to (stdout if none)"_L1);
parser.process(app);
if (parser.isSet(formatOptionsOption)) {
QString format = parser.value(formatOptionsOption);
- for (Converter *conv : std::as_const(*availableConverters)) {
+//! [1]
+ for (const Converter *conv : Converter::allConverters()) {
if (conv->name() == format) {
const char *help = conv->optionsHelp();
- if (help)
- printf("The following options are available for format '%s':\n\n%s", qPrintable(format), help);
- else
- printf("Format '%s' supports no options.\n", qPrintable(format));
+ if (help) {
+ qInfo("The following options are available for format '%s':\n\n%s",
+ qPrintable(format), help);
+ } else {
+ qInfo("Format '%s' supports no options.", qPrintable(format));
+ }
return EXIT_SUCCESS;
}
}
+//! [1]
- fprintf(stderr, "Unknown file format '%s'\n", qPrintable(format));
- return EXIT_FAILURE;
- }
-
- Converter *inconv = nullptr;
- QString format = parser.value(inputFormatOption);
- if (format != "auto") {
- for (Converter *conv : std::as_const(*availableConverters)) {
- if (conv->name() == format) {
- inconv = conv;
- break;
- }
- }
-
- if (!inconv) {
- fprintf(stderr, "Unknown file format \"%s\"\n", qPrintable(format));
- return EXIT_FAILURE;
- }
- }
-
- Converter *outconv = nullptr;
- format = parser.value(outputFormatOption);
- if (format != "auto") {
- for (Converter *conv : std::as_const(*availableConverters)) {
- if (conv->name() == format) {
- outconv = conv;
- break;
- }
- }
-
- if (!outconv) {
- fprintf(stderr, "Unknown file format \"%s\"\n", qPrintable(format));
- return EXIT_FAILURE;
- }
+ qFatal("Unknown file format '%s'", qPrintable(format));
}
+//! [2]
QStringList files = parser.positionalArguments();
QFile input(files.value(0));
QFile output(files.value(1));
+ const Converter *inconv = prepareConverter(parser.value(inputFormatOption),
+ Converter::Direction::In, &input);
+ const Converter *outconv = prepareConverter(parser.value(outputFormatOption),
+ Converter::Direction::Out, &output);
- if (input.fileName().isEmpty())
- input.open(stdin, QIODevice::ReadOnly);
- else
- input.open(QIODevice::ReadOnly);
- if (!input.isOpen()) {
- fprintf(stderr, "Could not open \"%s\" for reading: %s\n",
- qPrintable(input.fileName()), qPrintable(input.errorString()));
- return EXIT_FAILURE;
- }
-
- if (output.fileName().isEmpty())
- output.open(stdout, QIODevice::WriteOnly | QIODevice::Truncate);
- else
- output.open(QIODevice::WriteOnly | QIODevice::Truncate);
- if (!output.isOpen()) {
- fprintf(stderr, "Could not open \"%s\" for writing: %s\n",
- qPrintable(output.fileName()), qPrintable(output.errorString()));
- return EXIT_FAILURE;
- }
-
- if (!inconv) {
- // probe the input to find a file format
- for (Converter *conv : std::as_const(*availableConverters)) {
- if (conv->directions() & Converter::In && conv->probeFile(&input)) {
- inconv = conv;
- break;
- }
- }
-
- if (!inconv) {
- fprintf(stderr, "Could not determine input format. pass -I option.\n");
- return EXIT_FAILURE;
- }
- }
-
- if (!outconv) {
- // probe the output to find a file format
- for (Converter *conv : std::as_const(*availableConverters)) {
- if (conv->directions() & Converter::Out && conv->probeFile(&output)) {
- outconv = conv;
- break;
- }
- }
- }
-
- // now finally perform the conversion
+ // Now finally perform the conversion:
QVariant data = inconv->loadFile(&input, outconv);
- Q_ASSERT_X(outconv, "Converter Tool",
+ Q_ASSERT_X(outconv, "Serialization Converter",
"Internal error: converter format did not provide default");
outconv->saveFile(&output, data, parser.values(optionOption));
return EXIT_SUCCESS;
+//! [2]
}
diff --git a/examples/corelib/serialization/convert/nullconverter.cpp b/examples/corelib/serialization/convert/nullconverter.cpp
index a3f0bcd99b..fb8be5c944 100644
--- a/examples/corelib/serialization/convert/nullconverter.cpp
+++ b/examples/corelib/serialization/convert/nullconverter.cpp
@@ -3,48 +3,35 @@
#include "nullconverter.h"
-static NullConverter nullConverter;
-Converter* Converter::null = &nullConverter;
-
-QString NullConverter::name()
-{
- return QLatin1String("null");
-}
-
-Converter::Direction NullConverter::directions()
-{
- return Out;
-}
+using namespace Qt::StringLiterals;
-Converter::Options NullConverter::outputOptions()
+static NullConverter nullConverter;
+bool Converter::isNull(const Converter *converter)
{
- return SupportsArbitraryMapKeys;
+ return converter == &nullConverter;
}
-const char *NullConverter::optionsHelp()
+QString NullConverter::name() const
{
- return nullptr;
+ return "null"_L1;
}
-bool NullConverter::probeFile(QIODevice *f)
+Converter::Directions NullConverter::directions() const
{
- Q_UNUSED(f);
- return false;
+ return Direction::Out;
}
-QVariant NullConverter::loadFile(QIODevice *f, Converter *&outputConverter)
+Converter::Options NullConverter::outputOptions() const
{
- Q_UNUSED(f);
- Q_UNUSED(outputConverter);
- outputConverter = this;
- return QVariant();
+ return SupportsArbitraryMapKeys;
}
-void NullConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
+void NullConverter::saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const
{
if (!options.isEmpty()) {
- fprintf(stderr, "Unknown option '%s' to null output. This format has no options.\n", qPrintable(options.first()));
- exit(EXIT_FAILURE);
+ qFatal("Unknown option '%s' to null output. This format has no options.",
+ qPrintable(options.first()));
}
Q_UNUSED(f);
diff --git a/examples/corelib/serialization/convert/nullconverter.h b/examples/corelib/serialization/convert/nullconverter.h
index b2c69593f5..1bdf9f22f7 100644
--- a/examples/corelib/serialization/convert/nullconverter.h
+++ b/examples/corelib/serialization/convert/nullconverter.h
@@ -10,13 +10,11 @@ class NullConverter : public Converter
{
// Converter interface
public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
+ QString name() const override;
+ Directions directions() const override;
+ Options outputOptions() const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
};
#endif // NULLCONVERTER_H
diff --git a/examples/corelib/serialization/convert/textconverter.cpp b/examples/corelib/serialization/convert/textconverter.cpp
index b02ce12f66..1f8b4f9c19 100644
--- a/examples/corelib/serialization/convert/textconverter.cpp
+++ b/examples/corelib/serialization/convert/textconverter.cpp
@@ -6,6 +6,8 @@
#include <QFile>
#include <QTextStream>
+using namespace Qt::StringLiterals;
+
static void dumpVariant(QTextStream &out, const QVariant &v)
{
switch (v.userType()) {
@@ -42,68 +44,52 @@ static void dumpVariant(QTextStream &out, const QVariant &v)
}
}
-QString TextConverter::name()
-{
- return QStringLiteral("text");
-}
-
-Converter::Direction TextConverter::directions()
-{
- return InOut;
-}
-
-Converter::Options TextConverter::outputOptions()
+QString TextConverter::name() const
{
- return {};
+ return "text"_L1;
}
-const char *TextConverter::optionsHelp()
+Converter::Directions TextConverter::directions() const
{
- return nullptr;
+ return Direction::InOut;
}
-bool TextConverter::probeFile(QIODevice *f)
+bool TextConverter::probeFile(QIODevice *f) const
{
if (QFile *file = qobject_cast<QFile *>(f))
- return file->fileName().endsWith(QLatin1String(".txt"));
+ return file->fileName().endsWith(".txt"_L1);
return false;
}
-QVariant TextConverter::loadFile(QIODevice *f, Converter *&outputConverter)
+QVariant TextConverter::loadFile(QIODevice *f, const Converter *&outputConverter) const
{
if (!outputConverter)
outputConverter = this;
QVariantList list;
QTextStream in(f);
- QString line ;
+ QString line;
while (!in.atEnd()) {
in.readLineInto(&line);
-
bool ok;
- qint64 v = line.toLongLong(&ok);
- if (ok) {
- list.append(v);
- continue;
- }
- double d = line.toDouble(&ok);
- if (ok) {
+ if (qint64 v = line.toLongLong(&ok); ok)
+ list.append(v);
+ else if (double d = line.toDouble(&ok); ok)
list.append(d);
- continue;
- }
-
- list.append(line);
+ else
+ list.append(line);
}
return list;
}
-void TextConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
+void TextConverter::saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const
{
if (!options.isEmpty()) {
- fprintf(stderr, "Unknown option '%s' to text output. This format has no options.\n", qPrintable(options.first()));
- exit(EXIT_FAILURE);
+ qFatal("Unknown option '%s' to text output. This format has no options.",
+ qPrintable(options.first()));
}
QTextStream out(f);
diff --git a/examples/corelib/serialization/convert/textconverter.h b/examples/corelib/serialization/convert/textconverter.h
index 6379ffc82f..526f295517 100644
--- a/examples/corelib/serialization/convert/textconverter.h
+++ b/examples/corelib/serialization/convert/textconverter.h
@@ -8,16 +8,14 @@
class TextConverter : public Converter
{
-
// Converter interface
public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
+ QString name() const override;
+ Directions directions() const override;
+ bool probeFile(QIODevice *f) const override;
+ QVariant loadFile(QIODevice *f, const Converter *&outputConverter) const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
};
#endif // TEXTCONVERTER_H
diff --git a/examples/corelib/serialization/convert/variantorderedmap.h b/examples/corelib/serialization/convert/variantorderedmap.h
new file mode 100644
index 0000000000..c65316b182
--- /dev/null
+++ b/examples/corelib/serialization/convert/variantorderedmap.h
@@ -0,0 +1,24 @@
+// Copyright (C) 2018 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef VARIANTORDEREDMAP_H
+#define VARIANTORDEREDMAP_H
+
+#include <QList>
+#include <QPair>
+#include <QVariant>
+#include <QVariantMap>
+
+class VariantOrderedMap : public QList<QPair<QVariant, QVariant>>
+{
+public:
+ VariantOrderedMap() = default;
+ VariantOrderedMap(const QVariantMap &map)
+ {
+ reserve(map.size());
+ for (auto it = map.begin(); it != map.end(); ++it)
+ append({it.key(), it.value()});
+ }
+};
+
+#endif // VARIANTORDEREDMAP_H
diff --git a/examples/corelib/serialization/convert/xmlconverter.cpp b/examples/corelib/serialization/convert/xmlconverter.cpp
index 080528f678..ef71fecb9f 100644
--- a/examples/corelib/serialization/convert/xmlconverter.cpp
+++ b/examples/corelib/serialization/convert/xmlconverter.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "xmlconverter.h"
+#include "variantorderedmap.h"
#include <QBitArray>
#include <QtCborCommon>
@@ -13,8 +14,9 @@
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
-static const char xmlOptionHelp[] =
- "compact=no|yes Use compact XML form.\n";
+using namespace Qt::StringLiterals;
+
+static const char xmlOptionHelp[] = "compact=no|yes Use compact XML form.\n";
static XmlConverter xmlConverter;
@@ -23,7 +25,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
static QVariantList listFromXml(QXmlStreamReader &xml, Converter::Options options)
{
QVariantList list;
- while (!xml.atEnd() && !(xml.isEndElement() && xml.name() == QLatin1String("list"))) {
+ while (!xml.atEnd() && !(xml.isEndElement() && xml.name() == "list"_L1)) {
xml.readNext();
switch (xml.tokenType()) {
case QXmlStreamReader::StartElement:
@@ -47,20 +49,19 @@ static QVariantList listFromXml(QXmlStreamReader &xml, Converter::Options option
break;
}
- fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
- xml.lineNumber(), xml.columnNumber(),
- qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML %s '%s'.", xml.lineNumber(), xml.columnNumber(),
+ qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
}
xml.readNext();
return list;
}
-static VariantOrderedMap::value_type mapEntryFromXml(QXmlStreamReader &xml, Converter::Options options)
+static VariantOrderedMap::value_type mapEntryFromXml(QXmlStreamReader &xml,
+ Converter::Options options)
{
QVariant key, value;
- while (!xml.atEnd() && !(xml.isEndElement() && xml.name() == QLatin1String("entry"))) {
+ while (!xml.atEnd() && !(xml.isEndElement() && xml.name() == "entry"_L1)) {
xml.readNext();
switch (xml.tokenType()) {
case QXmlStreamReader::StartElement:
@@ -89,10 +90,8 @@ static VariantOrderedMap::value_type mapEntryFromXml(QXmlStreamReader &xml, Conv
break;
}
- fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
- xml.lineNumber(), xml.columnNumber(),
- qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML %s '%s'.", xml.lineNumber(), xml.columnNumber(),
+ qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
}
return { key, value };
@@ -103,11 +102,11 @@ static QVariant mapFromXml(QXmlStreamReader &xml, Converter::Options options)
QVariantMap map1;
VariantOrderedMap map2;
- while (!xml.atEnd() && !(xml.isEndElement() && xml.name() == QLatin1String("map"))) {
+ while (!xml.atEnd() && !(xml.isEndElement() && xml.name() == "map"_L1)) {
xml.readNext();
switch (xml.tokenType()) {
case QXmlStreamReader::StartElement:
- if (xml.name() == QLatin1String("entry")) {
+ if (xml.name() == "entry"_L1) {
auto pair = mapEntryFromXml(xml, options);
if (options & Converter::SupportsArbitraryMapKeys)
map2.append(pair);
@@ -134,10 +133,8 @@ static QVariant mapFromXml(QXmlStreamReader &xml, Converter::Options options)
break;
}
- fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
- xml.lineNumber(), xml.columnNumber(),
- qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML %s '%s'.", xml.lineNumber(), xml.columnNumber(),
+ qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
}
xml.readNext();
@@ -149,18 +146,17 @@ static QVariant mapFromXml(QXmlStreamReader &xml, Converter::Options options)
static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options)
{
QStringView name = xml.name();
- if (name == QLatin1String("list"))
+ if (name == "list"_L1)
return listFromXml(xml, options);
- if (name == QLatin1String("map"))
+ if (name == "map"_L1)
return mapFromXml(xml, options);
- if (name != QLatin1String("value")) {
- fprintf(stderr, "%lld:%lld: Invalid XML key '%s'.\n",
- xml.lineNumber(), xml.columnNumber(), qPrintable(name.toString()));
- exit(EXIT_FAILURE);
+ if (name != "value"_L1) {
+ qFatal("%lld:%lld: Invalid XML key '%s'.",
+ xml.lineNumber(), xml.columnNumber(), qPrintable(name.toString()));
}
QXmlStreamAttributes attrs = xml.attributes();
- QStringView type = attrs.value(QLatin1String("type"));
+ QStringView type = attrs.value("type"_L1);
forever {
xml.readNext();
@@ -169,10 +165,8 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
if (xml.isCDATA() || xml.isCharacters() || xml.isEndElement())
break;
- fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
- xml.lineNumber(), xml.columnNumber(),
- qPrintable(xml.tokenString()), qPrintable(name.toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML %s '%s'.", xml.lineNumber(), xml.columnNumber(),
+ qPrintable(xml.tokenString()), qPrintable(name.toString()));
}
QStringView text = xml.text();
@@ -180,45 +174,43 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
text = text.trimmed();
QVariant result;
- bool ok;
if (type.isEmpty()) {
// ok
- } else if (type == QLatin1String("number")) {
+ } else if (type == "number"_L1) {
// try integer first
+ bool ok;
qint64 v = text.toLongLong(&ok);
if (ok) {
result = v;
} else {
// let's see floating point
double d = text.toDouble(&ok);
- result = d;
if (!ok) {
- fprintf(stderr, "%lld:%lld: Invalid XML: could not interpret '%s' as a number.\n",
- xml.lineNumber(), xml.columnNumber(), qPrintable(text.toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML: could not interpret '%s' as a number.",
+ xml.lineNumber(), xml.columnNumber(), qPrintable(text.toString()));
}
+ result = d;
}
- } else if (type == QLatin1String("bytes")) {
+ } else if (type == "bytes"_L1) {
QByteArray data = text.toLatin1();
QStringView encoding = attrs.value("encoding");
- if (encoding == QLatin1String("base64url")) {
+ if (encoding == "base64url"_L1) {
result = QByteArray::fromBase64(data, QByteArray::Base64UrlEncoding);
- } else if (encoding == QLatin1String("hex")) {
+ } else if (encoding == "hex"_L1) {
result = QByteArray::fromHex(data);
- } else if (encoding.isEmpty() || encoding == QLatin1String("base64")) {
+ } else if (encoding.isEmpty() || encoding == "base64"_L1) {
result = QByteArray::fromBase64(data);
} else {
- fprintf(stderr, "%lld:%lld: Invalid XML: unknown encoding '%s' for bytes.\n",
- xml.lineNumber(), xml.columnNumber(), qPrintable(encoding.toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML: unknown encoding '%s' for bytes.",
+ xml.lineNumber(), xml.columnNumber(), qPrintable(encoding.toString()));
}
- } else if (type == QLatin1String("string")) {
+ } else if (type == "string"_L1) {
result = text.toString();
- } else if (type == QLatin1String("null")) {
+ } else if (type == "null"_L1) {
result = QVariant::fromValue(nullptr);
- } else if (type == QLatin1String("CBOR simple type")) {
+ } else if (type == "CBOR simple type"_L1) {
result = QVariant::fromValue(QCborSimpleType(text.toShort()));
- } else if (type == QLatin1String("bits")) {
+ } else if (type == "bits"_L1) {
QBitArray ba;
ba.resize(text.size());
qsizetype n = 0;
@@ -229,36 +221,33 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
} else if (c == '0') {
++n;
} else if (!c.isSpace()) {
- fprintf(stderr, "%lld:%lld: Invalid XML: invalid bit string '%s'.\n",
- xml.lineNumber(), xml.columnNumber(), qPrintable(text.toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML: invalid bit string '%s'.",
+ xml.lineNumber(), xml.columnNumber(), qPrintable(text.toString()));
}
}
ba.resize(n);
result = ba;
} else {
int id = QMetaType::UnknownType;
- if (type == QLatin1String("datetime"))
+ if (type == "datetime"_L1)
id = QMetaType::QDateTime;
- else if (type == QLatin1String("url"))
+ else if (type == "url"_L1)
id = QMetaType::QUrl;
- else if (type == QLatin1String("uuid"))
+ else if (type == "uuid"_L1)
id = QMetaType::QUuid;
- else if (type == QLatin1String("regex"))
+ else if (type == "regex"_L1)
id = QMetaType::QRegularExpression;
else
id = QMetaType::fromName(type.toLatin1()).id();
if (id == QMetaType::UnknownType) {
- fprintf(stderr, "%lld:%lld: Invalid XML: unknown type '%s'.\n",
- xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML: unknown type '%s'.",
+ xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString()));
}
result = text.toString();
if (!result.convert(QMetaType(id))) {
- fprintf(stderr, "%lld:%lld: Invalid XML: could not parse content as type '%s'.\n",
- xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML: could not parse content as type '%s'.",
+ xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString()));
}
}
@@ -267,10 +256,8 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
} while (xml.isComment() || xml.isWhitespace());
if (!xml.isEndElement()) {
- fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
- xml.lineNumber(), xml.columnNumber(),
- qPrintable(xml.tokenString()), qPrintable(name.toString()));
- exit(EXIT_FAILURE);
+ qFatal("%lld:%lld: Invalid XML %s '%s'.", xml.lineNumber(), xml.columnNumber(),
+ qPrintable(xml.tokenString()), qPrintable(name.toString()));
}
xml.readNext();
@@ -287,9 +274,9 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
variantToXml(xml, v);
xml.writeEndElement();
} else if (type == QMetaType::QVariantMap || type == qMetaTypeId<VariantOrderedMap>()) {
- const VariantOrderedMap map = (type == QMetaType::QVariantMap) ?
- VariantOrderedMap(v.toMap()) :
- qvariant_cast<VariantOrderedMap>(v);
+ const VariantOrderedMap map = (type == QMetaType::QVariantMap)
+ ? VariantOrderedMap(v.toMap())
+ : qvariant_cast<VariantOrderedMap>(v);
xml.writeStartElement("map");
for (const auto &pair : map) {
@@ -301,7 +288,7 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
xml.writeEndElement();
} else {
xml.writeStartElement("value");
- QString typeString = QStringLiteral("type");
+ QString typeString = "type"_L1;
switch (type) {
case QMetaType::Short:
case QMetaType::UShort:
@@ -390,8 +377,7 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
xml.writeAttribute(typeString, QString::fromLatin1(typeName));
xml.writeCharacters(copy.toString());
} else {
- fprintf(stderr, "XML: don't know how to serialize type '%s'.\n", typeName);
- exit(EXIT_FAILURE);
+ qFatal("XML: don't know how to serialize type '%s'.", typeName);
}
}
}
@@ -399,37 +385,37 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
}
}
-QString XmlConverter::name()
+QString XmlConverter::name() const
{
- return QStringLiteral("xml");
+ return "xml"_L1;
}
-Converter::Direction XmlConverter::directions()
+Converter::Directions XmlConverter::directions() const
{
- return InOut;
+ return Direction::InOut;
}
-Converter::Options XmlConverter::outputOptions()
+Converter::Options XmlConverter::outputOptions() const
{
return SupportsArbitraryMapKeys;
}
-const char *XmlConverter::optionsHelp()
+const char *XmlConverter::optionsHelp() const
{
return xmlOptionHelp;
}
-bool XmlConverter::probeFile(QIODevice *f)
+bool XmlConverter::probeFile(QIODevice *f) const
{
if (QFile *file = qobject_cast<QFile *>(f)) {
- if (file->fileName().endsWith(QLatin1String(".xml")))
+ if (file->fileName().endsWith(".xml"_L1))
return true;
}
return f->isReadable() && f->peek(5) == "<?xml";
}
-QVariant XmlConverter::loadFile(QIODevice *f, Converter *&outputConverter)
+QVariant XmlConverter::loadFile(QIODevice *f, const Converter *&outputConverter) const
{
if (!outputConverter)
outputConverter = this;
@@ -437,26 +423,24 @@ QVariant XmlConverter::loadFile(QIODevice *f, Converter *&outputConverter)
QXmlStreamReader xml(f);
xml.readNextStartElement();
QVariant v = variantFromXml(xml, outputConverter->outputOptions());
- if (xml.hasError()) {
- fprintf(stderr, "XML error: %s", qPrintable(xml.errorString()));
- exit(EXIT_FAILURE);
- }
+ if (xml.hasError())
+ qFatal("XML error: %s", qPrintable(xml.errorString()));
return v;
}
-void XmlConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
+void XmlConverter::saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const
{
bool compact = false;
for (const QString &s : options) {
- if (s == QLatin1String("compact=no")) {
+ if (s == "compact=no"_L1) {
compact = false;
- } else if (s == QLatin1String("compact=yes")) {
+ } else if (s == "compact=yes"_L1) {
compact = true;
} else {
- fprintf(stderr, "Unknown option '%s' to XML output. Valid options are:\n%s",
- qPrintable(s), xmlOptionHelp);
- exit(EXIT_FAILURE);
+ qFatal("Unknown option '%s' to XML output. Valid options are:\n%s",
+ qPrintable(s), xmlOptionHelp);
}
}
diff --git a/examples/corelib/serialization/convert/xmlconverter.h b/examples/corelib/serialization/convert/xmlconverter.h
index 19bde6c7c6..4888b0616f 100644
--- a/examples/corelib/serialization/convert/xmlconverter.h
+++ b/examples/corelib/serialization/convert/xmlconverter.h
@@ -10,13 +10,14 @@ class XmlConverter : public Converter
{
// Converter interface
public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
+ QString name() const override;
+ Directions directions() const override;
+ Options outputOptions() const override;
+ const char *optionsHelp() const override;
+ bool probeFile(QIODevice *f) const override;
+ QVariant loadFile(QIODevice *f, const Converter *&outputConverter) const override;
+ void saveFile(QIODevice *f, const QVariant &contents,
+ const QStringList &options) const override;
};
#endif // XMLCONVERTER_H
diff --git a/examples/corelib/serialization/savegame/CMakeLists.txt b/examples/corelib/serialization/savegame/CMakeLists.txt
index 8871a9d687..14621ccc23 100644
--- a/examples/corelib/serialization/savegame/CMakeLists.txt
+++ b/examples/corelib/serialization/savegame/CMakeLists.txt
@@ -1,15 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(savegame LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/serialization/savegame")
-
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
@@ -26,7 +24,14 @@ target_link_libraries(savegame PRIVATE
)
install(TARGETS savegame
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET savegame
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/serialization/savegame/character.cpp b/examples/corelib/serialization/savegame/character.cpp
index 039aa1fa94..863fcb9153 100644
--- a/examples/corelib/serialization/savegame/character.cpp
+++ b/examples/corelib/serialization/savegame/character.cpp
@@ -6,15 +6,10 @@
#include <QMetaEnum>
#include <QTextStream>
-Character::Character()
- = default;
-
-Character::Character(const QString &name,
- int level,
- Character::ClassType classType) :
- mName(name),
- mLevel(level),
- mClassType(classType)
+Character::Character() = default;
+
+Character::Character(const QString &name, int level, Character::ClassType classType)
+ : mName(name), mLevel(level), mClassType(classType)
{
}
diff --git a/examples/corelib/serialization/savegame/character.h b/examples/corelib/serialization/savegame/character.h
index cffa5fa659..0504750320 100644
--- a/examples/corelib/serialization/savegame/character.h
+++ b/examples/corelib/serialization/savegame/character.h
@@ -16,9 +16,7 @@ class Character
Q_GADGET
public:
- enum ClassType {
- Warrior, Mage, Archer
- };
+ enum ClassType { Warrior, Mage, Archer };
Q_ENUM(ClassType)
Character();
@@ -37,6 +35,7 @@ public:
QJsonObject toJson() const;
void print(QTextStream &s, int indentation = 0) const;
+
private:
QString mName;
int mLevel = 0;
diff --git a/examples/corelib/serialization/savegame/doc/src/savegame.qdoc b/examples/corelib/serialization/savegame/doc/src/savegame.qdoc
index 37a461d7bd..46fca15b62 100644
--- a/examples/corelib/serialization/savegame/doc/src/savegame.qdoc
+++ b/examples/corelib/serialization/savegame/doc/src/savegame.qdoc
@@ -3,11 +3,10 @@
/*!
\example serialization/savegame
- \examplecategory {Input/Output}
- \title JSON Save Game Example
+ \examplecategory {Data Processing & I/O}
+ \title Saving and Loading a Game
- \brief The JSON Save Game example demonstrates how to save and load a
- small game using QJsonDocument, QJsonObject and QJsonArray.
+ \brief How to save and load a game using Qt's JSON or CBOR classes.
Many games provide save functionality, so that the player's progress through
the game can be saved and loaded at a later time. The process of saving a
diff --git a/examples/corelib/serialization/savegame/game.cpp b/examples/corelib/serialization/savegame/game.cpp
index 85a2619b42..f99ecb8b51 100644
--- a/examples/corelib/serialization/savegame/game.cpp
+++ b/examples/corelib/serialization/savegame/game.cpp
@@ -11,6 +11,8 @@
#include <QRandomGenerator>
#include <QTextStream>
+using namespace Qt::StringLiterals;
+
Character Game::player() const
{
return mPlayer;
@@ -25,37 +27,32 @@ QList<Level> Game::levels() const
void Game::newGame()
{
mPlayer = Character();
- mPlayer.setName(QStringLiteral("Hero"));
+ mPlayer.setName("Hero"_L1);
mPlayer.setClassType(Character::Archer);
mPlayer.setLevel(QRandomGenerator::global()->bounded(15, 21));
mLevels.clear();
mLevels.reserve(2);
- Level village(QStringLiteral("Village"));
+ Level village("Village"_L1);
QList<Character> villageNpcs;
villageNpcs.reserve(2);
- villageNpcs.append(Character(QStringLiteral("Barry the Blacksmith"),
- QRandomGenerator::global()->bounded(8, 11),
- Character::Warrior));
- villageNpcs.append(Character(QStringLiteral("Terry the Trader"),
- QRandomGenerator::global()->bounded(6, 8),
- Character::Warrior));
+ villageNpcs.append(Character("Barry the Blacksmith"_L1,
+ QRandomGenerator::global()->bounded(8, 11), Character::Warrior));
+ villageNpcs.append(Character("Terry the Trader"_L1,
+ QRandomGenerator::global()->bounded(6, 8), Character::Warrior));
village.setNpcs(villageNpcs);
mLevels.append(village);
- Level dungeon(QStringLiteral("Dungeon"));
+ Level dungeon("Dungeon"_L1);
QList<Character> dungeonNpcs;
dungeonNpcs.reserve(3);
- dungeonNpcs.append(Character(QStringLiteral("Eric the Evil"),
- QRandomGenerator::global()->bounded(18, 26),
- Character::Mage));
- dungeonNpcs.append(Character(QStringLiteral("Eric's Left Minion"),
- QRandomGenerator::global()->bounded(5, 7),
- Character::Warrior));
- dungeonNpcs.append(Character(QStringLiteral("Eric's Right Minion"),
- QRandomGenerator::global()->bounded(4, 9),
- Character::Warrior));
+ dungeonNpcs.append(Character("Eric the Evil"_L1,
+ QRandomGenerator::global()->bounded(18, 26), Character::Mage));
+ dungeonNpcs.append(Character("Eric's Left Minion"_L1,
+ QRandomGenerator::global()->bounded(5, 7), Character::Warrior));
+ dungeonNpcs.append(Character("Eric's Right Minion"_L1,
+ QRandomGenerator::global()->bounded(4, 9), Character::Warrior));
dungeon.setNpcs(dungeonNpcs);
mLevels.append(dungeon);
}
@@ -64,9 +61,7 @@ void Game::newGame()
//! [loadGame]
bool Game::loadGame(Game::SaveFormat saveFormat)
{
- QFile loadFile(saveFormat == Json
- ? QStringLiteral("save.json")
- : QStringLiteral("save.dat"));
+ QFile loadFile(saveFormat == Json ? "save.json"_L1 : "save.dat"_L1);
if (!loadFile.open(QIODevice::ReadOnly)) {
qWarning("Couldn't open save file.");
@@ -76,15 +71,13 @@ bool Game::loadGame(Game::SaveFormat saveFormat)
QByteArray saveData = loadFile.readAll();
QJsonDocument loadDoc(saveFormat == Json
- ? QJsonDocument::fromJson(saveData)
- : QJsonDocument(QCborValue::fromCbor(saveData).toMap().toJsonObject()));
+ ? QJsonDocument::fromJson(saveData)
+ : QJsonDocument(QCborValue::fromCbor(saveData).toMap().toJsonObject()));
read(loadDoc.object());
- QTextStream(stdout) << "Loaded save for "
- << loadDoc["player"]["name"].toString()
- << " using "
- << (saveFormat != Json ? "CBOR" : "JSON") << "...\n";
+ QTextStream(stdout) << "Loaded save for " << loadDoc["player"]["name"].toString()
+ << " using " << (saveFormat != Json ? "CBOR" : "JSON") << "...\n";
return true;
}
//! [loadGame]
@@ -92,9 +85,7 @@ bool Game::loadGame(Game::SaveFormat saveFormat)
//! [saveGame]
bool Game::saveGame(Game::SaveFormat saveFormat) const
{
- QFile saveFile(saveFormat == Json
- ? QStringLiteral("save.json")
- : QStringLiteral("save.dat"));
+ QFile saveFile(saveFormat == Json ? "save.json"_L1 : "save.dat"_L1);
if (!saveFile.open(QIODevice::WriteOnly)) {
qWarning("Couldn't open save file.");
@@ -102,9 +93,8 @@ bool Game::saveGame(Game::SaveFormat saveFormat) const
}
QJsonObject gameObject = toJson();
- saveFile.write(saveFormat == Json
- ? QJsonDocument(gameObject).toJson()
- : QCborValue::fromJsonValue(gameObject).toCbor());
+ saveFile.write(saveFormat == Json ? QJsonDocument(gameObject).toJson()
+ : QCborValue::fromJsonValue(gameObject).toCbor());
return true;
}
diff --git a/examples/corelib/serialization/savegame/game.h b/examples/corelib/serialization/savegame/game.h
index 2d7630c7df..5ba5952923 100644
--- a/examples/corelib/serialization/savegame/game.h
+++ b/examples/corelib/serialization/savegame/game.h
@@ -16,9 +16,7 @@ QT_FORWARD_DECLARE_CLASS(QTextStream)
class Game
{
public:
- enum SaveFormat {
- Json, Binary
- };
+ enum SaveFormat { Json, Binary };
Character player() const;
QList<Level> levels() const;
@@ -31,6 +29,7 @@ public:
QJsonObject toJson() const;
void print(QTextStream &s, int indentation = 0) const;
+
private:
Character mPlayer;
QList<Level> mLevels;
diff --git a/examples/corelib/serialization/savegame/level.cpp b/examples/corelib/serialization/savegame/level.cpp
index 489a25e204..f30d35e57f 100644
--- a/examples/corelib/serialization/savegame/level.cpp
+++ b/examples/corelib/serialization/savegame/level.cpp
@@ -6,9 +6,7 @@
#include <QJsonArray>
#include <QTextStream>
-Level::Level(const QString &name) : mName(name)
-{
-}
+Level::Level(const QString &name) : mName(name) { }
QString Level::name() const
{
@@ -61,8 +59,7 @@ void Level::print(QTextStream &s, int indentation) const
{
const QString indent(indentation * 2, ' ');
- s << indent << "Name:\t" << mName << "\n"
- << indent << "NPCs:\n";
+ s << indent << "Name:\t" << mName << "\n" << indent << "NPCs:\n";
for (const Character &character : mNpcs)
character.print(s, indentation + 1);
}
diff --git a/examples/corelib/serialization/savegame/level.h b/examples/corelib/serialization/savegame/level.h
index ad8d0fd593..e487e55ae3 100644
--- a/examples/corelib/serialization/savegame/level.h
+++ b/examples/corelib/serialization/savegame/level.h
@@ -27,6 +27,7 @@ public:
QJsonObject toJson() const;
void print(QTextStream &s, int indentation = 0) const;
+
private:
QString mName;
QList<Character> mNpcs;
diff --git a/examples/corelib/serialization/serialization.pro b/examples/corelib/serialization/serialization.pro
index 9f0ced0282..e20fcb57fd 100644
--- a/examples/corelib/serialization/serialization.pro
+++ b/examples/corelib/serialization/serialization.pro
@@ -6,6 +6,4 @@ SUBDIRS = \
qtHaveModule(widgets) {
SUBDIRS += streambookmarks
- qtHaveModule(network): SUBDIRS += \
- rsslisting
}
diff --git a/examples/corelib/serialization/streambookmarks/CMakeLists.txt b/examples/corelib/serialization/streambookmarks/CMakeLists.txt
index 1d0ab8690b..bad55fa661 100644
--- a/examples/corelib/serialization/streambookmarks/CMakeLists.txt
+++ b/examples/corelib/serialization/streambookmarks/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(streambookmarks LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/serialization/streambookmarks")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(streambookmarks PRIVATE
)
install(TARGETS streambookmarks
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET streambookmarks
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/serialization/streambookmarks/doc/images/filemenu.png b/examples/corelib/serialization/streambookmarks/doc/images/filemenu.png
new file mode 100644
index 0000000000..1a92895ccf
--- /dev/null
+++ b/examples/corelib/serialization/streambookmarks/doc/images/filemenu.png
Binary files differ
diff --git a/examples/corelib/serialization/streambookmarks/doc/images/helpmenu.png b/examples/corelib/serialization/streambookmarks/doc/images/helpmenu.png
new file mode 100644
index 0000000000..baa98bee96
--- /dev/null
+++ b/examples/corelib/serialization/streambookmarks/doc/images/helpmenu.png
Binary files differ
diff --git a/examples/corelib/serialization/streambookmarks/doc/images/screenshot.png b/examples/corelib/serialization/streambookmarks/doc/images/screenshot.png
new file mode 100644
index 0000000000..422873b6d0
--- /dev/null
+++ b/examples/corelib/serialization/streambookmarks/doc/images/screenshot.png
Binary files differ
diff --git a/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-filemenu.png b/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-filemenu.png
deleted file mode 100644
index e074fb7c41..0000000000
--- a/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-filemenu.png
+++ /dev/null
Binary files differ
diff --git a/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-helpmenu.png b/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-helpmenu.png
deleted file mode 100644
index 0dc4392b94..0000000000
--- a/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-helpmenu.png
+++ /dev/null
Binary files differ
diff --git a/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-screenshot.png b/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-screenshot.png
deleted file mode 100644
index bbaa423061..0000000000
--- a/examples/corelib/serialization/streambookmarks/doc/images/xmlstreamexample-screenshot.png
+++ /dev/null
Binary files differ
diff --git a/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc b/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc
index a1498f0ff5..8e32dd8d0b 100644
--- a/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc
+++ b/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc
@@ -3,170 +3,221 @@
/*!
\example serialization/streambookmarks
- \examplecategory {Input/Output}
+ \examplecategory {Data Processing & I/O}
\meta tag {network}
\title QXmlStream Bookmarks Example
- \brief Demonstrates how to read and write to XBEL files.
+ \brief Demonstrates how to read and write XBEL files.
\ingroup xml-examples
- The QXmlStream Bookmarks example provides a reader for XML Bookmark
- Exchange Language (XBEL) files using Qt's QXmlStreamReader class
- for reading, and QXmlStreamWriter class for writing the files.
+ The QXmlStream Bookmarks example provides a viewer for XML Bookmark Exchange
+ Language (XBEL) files. It can read bookmarks using Qt's QXmlStreamReader and
+ write them back out again using QXmlStreamWriter. As this example aims to
+ show how to use these reader and writer types, it provides no means to open
+ a bookmark, add a new one, or merge two bookmark files, and only minimal
+ scope for editing bookmarks. None the less, it could surely be extended with
+ such features, if desired.
- \image xmlstreamexample-screenshot.png
+ \image screenshot.png
\section1 XbelWriter Class Definition
- The \c XbelWriter class contains a private instance of QXmlStreamWriter,
- which provides an XML writer with a streaming API. \c XbelWriter also
- has a reference to the QTreeWidget instance where the bookmark hierarchy
- is stored.
+ The \c XbelWriter class takes a \l{QTreeWidget}{tree widget} describing a
+ hierarchy of folders containing bookmarks. Its \c writeFile() provides the
+ means to write out this hierarchy, in XBEL format, to a given output device.
+
+ Internally, it records the tree widget it was given and packages a private
+ instance of QXmlStreamWriter, which provides it with the means to stream
+ XML. It has an internal \c writeItem() to write each item in its tree.
\snippet serialization/streambookmarks/xbelwriter.h 0
\section1 XbelWriter Class Implementation
- The \c XbelWriter constructor accepts a \a treeWidget to initialize within
- its definition. We enable \l{QXmlStreamWriter}'s auto-formatting property
- to ensure line-breaks and indentations are added automatically to empty
- sections between elements, increasing readability as the data is split into
- several lines.
+ The \c XbelWriter constructor accepts the \a treeWidget it will describe. It
+ stores that and enables \l{QXmlStreamWriter}'s auto-formatting property.
+ This last splits the data into several lines, with indentation to indicate
+ the structure of the tree, which makes the XML output easier to read.
\snippet serialization/streambookmarks/xbelwriter.cpp 0
- The \c writeFile() function accepts a QIODevice object and sets it using
- \c setDevice(). This function then writes the document type
- definition(DTD), the start element, the version, and \c{treeWidget}'s
- top-level items.
+ The \c writeFile() function accepts a QIODevice object and directs its
+ QXmlStreamWriter member to write to this device, using \c setDevice(). This
+ function then writes the document type definition(DTD), the start element,
+ the version, and delegates writing of each of the \c{treeWidget}'s top-level
+ items to \c writeItem(). Finally, it closes the document and returns.
\snippet serialization/streambookmarks/xbelwriter.cpp 1
- The \c writeItem() function accepts a QTreeWidgetItem object and writes it
- to the stream, depending on its \c tagName, which can either be a "folder",
- "bookmark", or "separator".
+ The \c writeItem() function accepts a QTreeWidgetItem object and writes to
+ its XML stream a representation of the object, which depends on its \c
+ UserRole, which can be one of a \c{"folder"}, \c{"bookmark"},
+ or \c{"separator"}. Within each folder, it calls itself recursively on each
+ child item, to recursively include a representation of each child within the
+ folder's XML element.
\snippet serialization/streambookmarks/xbelwriter.cpp 2
\section1 XbelReader Class Definition
- The \c XbelReader contains a private instance of QXmlStreamReader, the
- companion class to QXmlStreamWriter. \c XbelReader also contains a
- reference to the QTreeWidget that is used to group the bookmarks according
- to their hierarchy.
+ The \c XbelReader takes a \l{QTreeWidget}{tree widget} to populate with
+ items describing a bookmark hierarchy. It supports reading XBEL data from a
+ QIODevice as a source of these items. If parsing of the XBEL data fails, it
+ can report what went wrong.
+
+ Internally, it records the QTreeWidget that it will populate and packages an
+ instance of QXmlStreamReader, the companion class to QXmlStreamWriter, which
+ it will use to read XBEL data.
\snippet serialization/streambookmarks/xbelreader.h 0
\section1 XbelReader Class Implementation
- The \c XbelReader constructor accepts a QTreeWidget to initialize the
- \c treeWidget within its definition. A QStyle object is used to set
- \c{treeWidget}'s style property. The \c folderIcon is set to QIcon::Normal
- mode where the pixmap is only displayed when the user is not interacting
- with the icon. The QStyle::SP_DirClosedIcon, QStyle::SP_DirOpenIcon, and
- QStyle::SP_FileIcon correspond to standard pixmaps that follow the style
- of your GUI.
+ Since the XBEL reader is only concerned with reading XML elements, it makes
+ extensive use of the \l{QXmlStreamReader::}{readNextStartElement()}
+ convenience function.
+
+ The \c XbelReader constructor requires a QTreeWidget that it will populate.
+ It populates the tree widget's style with suitable icons: a folder icon that
+ changes form to indicate whether each folder as open or closed; and a
+ standard file icon for the individual bookmarks within those folders.
\snippet serialization/streambookmarks/xbelreader.cpp 0
- The \c read() function accepts a QIODevice and sets it using
- \l{QXmlStreamReader::}{setDevice()}. The actual process of reading only
- takes place if the file is a valid XBEL 1.0 file. Note that the XML input
- needs to be well-formed to be accepted by QXmlStreamReader. Otherwise, the
- \l{QXmlStreamReader::}{raiseError()} function is used to display an error
- message. Since the XBEL reader is only concerned with reading XML elements,
- it makes extensive use of the \l{QXmlStreamReader::}{readNextStartElement()}
- convenience function.
+ The \c read() function accepts a QIODevice. It directs its QXmlStreamReader
+ member to read content from that device. Note that the XML input must be
+ well-formed to be accepted by QXmlStreamReader. First it reads the outer
+ structure and verifies the content is an XBEL 1.0 file; if it is, \c read()
+ delegates the actual reading of content to the internal \c readXBEL().
+
+ Otherwise, the \l{QXmlStreamReader::}{raiseError()} function is used to
+ record an error message. The reader itself may also do the same if it
+ encounters errors in the input. When \c read() has finished, it returns
+ true if there were no errors.
\snippet serialization/streambookmarks/xbelreader.cpp 1
- The \c errorString() function is used if an error occurred, in order to
- obtain a description of the error complete with line and column number
- information.
+ If \c read() returns false, its caller can obtain a description of the
+ error, complete with line and column number within the stream, by calling
+ the \c errorString() function.
\snippet serialization/streambookmarks/xbelreader.cpp 2
- The \c readXBEL() function reads the name of a startElement and calls
- the appropriate function to read it, depending on whether if its a
- "folder", "bookmark" or "separator". Otherwise, it calls
- \l{QXmlStreamReader::}{skipCurrentElement()}. The Q_ASSERT() macro is used
- to provide a pre-condition for the function.
+ The \c readXBEL() function reads the name of a startElement and calls the
+ appropriate function to read it, depending on whether if its tag name
+ is \c{"folder"}, \c{"bookmark"} or \c{"separator"}. Any other elements
+ encountered are skipped. The function starts with a precondition, verifying
+ that the XML reader has just opened an \c{"xbel"} element.
\snippet serialization/streambookmarks/xbelreader.cpp 3
- The \c readTitle() function reads the bookmark's title.
+ The \c readBookmark() function creates a new editable item representing a
+ single bookmark. It records the XML \c{"href"} attribute of the current
+ element as second column text of the item and provisionally sets its first
+ column text to \c{"Unknown title"} before scanning the rest of the element
+ for a title element to over-ride that, skipping any unrecognized child
+ elements.
- \snippet serialization/streambookmarks/xbelreader.cpp 4
+ \snippet serialization/streambookmarks/xbelreader.cpp 5
- The \c readSeparator() function creates a separator and sets its flags.
- The text is set to 30 "0xB7", the HEX equivalent for period. The element
- is then skipped using \l{QXmlStreamReader::}{skipCurrentElement()}.
+ The \c readTitle() function reads a bookmark's title and records it as the
+ title (first column text) of the item for which it was called.
- \snippet serialization/streambookmarks/xbelreader.cpp 5
+ \snippet serialization/streambookmarks/xbelreader.cpp 6
+
+ The \c readSeparator() function creates a separator and sets its flags. The
+ separator item's text is set to 30 centered dots. The rest of the element is
+ then skipped using \l{QXmlStreamReader::}{skipCurrentElement()}.
+
+ \snippet serialization/streambookmarks/xbelreader.cpp 6
+
+ The \c readFolder() function creates an item and iterates the content of the
+ folder element, adding children to this item to represent the contents of
+ the folder element. The loop over folder content is similar in form to the
+ one in \c readXBEL(), save that it now accepts a title element to set the
+ title of the folder.
+
+ \snippet serialization/streambookmarks/xbelreader.cpp 7
+
+ The \c createChildItem() helper function creates a new tree widget item
+ that's either a child of the given item or, if no parent item is given, a
+ direct child of the tree widget. It sets the new item's \c UserRole to the
+ tag name of the current XML element, matching how XbelWriter::writeFile()
+ uses that \c UserRole.
+
+ \snippet serialization/streambookmarks/xbelreader.cpp 8
\section1 MainWindow Class Definition
- The \c MainWindow class is a subclass of QMainWindow, with a
- \c File menu and a \c Help menu.
+ The \c MainWindow class is a subclass of QMainWindow, with a \c File menu
+ and a \c Help menu.
\snippet serialization/streambookmarks/mainwindow.h 0
\section1 MainWindow Class Implementation
- The \c MainWindow constructor instantiates the QTreeWidget object, \c
- treeWidget and sets its header with a QStringList object, \c labels.
- The constructor also invokes \c createActions() and \c createMenus()
- to set up the menus and their corresponding actions. The \c statusBar()
- is used to display the message "Ready" and the window's size is fixed
- to 480x320 pixels.
+ The \c MainWindow constructor sets up its QTreeWidget object, \c treeWidget,
+ as its own central widget, with column headings for the title and location
+ of each book-mark. It configures a custom menu that enables the user to
+ perform actions on individual bookmarks within the tree widget.
+
+ It invokes \c createMenus() to set up its own menus and their corresponding
+ actions. It sets its title, announces itself as ready and sets its size to a
+ reasonable proportion of the available screen space.
\snippet serialization/streambookmarks/mainwindow.cpp 0
- The \c open() function enables the user to open an XBEL file using
- QFileDialog::getOpenFileName(). A warning message is displayed along
- with the \c fileName and \c errorString if the file cannot be read or
- if there is a parse error.
+ A custom menu, triggered when the user right-clicks on a bookmark, provides
+ for copying the bookmark as a link or directing a desktop browser to open
+ the URL it references. This menu is implemented (when relevant features are
+ enabled) by \c onCustomContextMenuRequested().
\snippet serialization/streambookmarks/mainwindow.cpp 1
- The \c saveAs() function displays a QFileDialog, prompting the user for
- a \c fileName using QFileDialog::getSaveFileName(). Similar to the
- \c open() function, this function also displays a warning message if
- the file cannot be written to.
+ The \c createMenus() function creates the \c fileMenu and \c helpMenu and
+ adds QAction objects to them, bound variously to the \c open(), \c saveAs()
+ and \c about() functions, along with QWidget::close() and
+ QApplication::aboutQt(). The connections are as shown below:
\snippet serialization/streambookmarks/mainwindow.cpp 2
- The \c about() function displays a QMessageBox with a brief description
- of the example.
+ This creates the menu shown in the screenshots below:
- \snippet serialization/streambookmarks/mainwindow.cpp 3
+ \table
+ \row
+ \li \inlineimage filemenu.png
+ \li \inlineimage helpmenu.png
+ \endtable
- In order to implement the \c open(), \c saveAs(), \c exit(), \c about()
- and \c aboutQt() functions, we connect them to QAction objects and
- add them to the \c fileMenu and \c helpMenu. The connections are as shown
- below:
+ The \c open() function, when triggered, offers the user a file dialog to use
+ to select a bookmarks file. If a file is selected, it is parsed using an \c
+ XBelReader to populate the \c treeWidget with bookmarks. If problems arise
+ with opening or parsing the file, a suitable warning message is displayed to
+ the user, including file name and error message. Otherwise, the bookmarks
+ read from the file are displayed and the window's status bar briefly reports
+ that the file has been loaded.
- \snippet serialization/streambookmarks/mainwindow.cpp 5
+ \snippet serialization/streambookmarks/mainwindow.cpp 3
- The \c createMenus() function creates the \c fileMenu and \c helpMenu
- and adds the QAction objects to them in order to create the menu shown
- in the screenshot below:
+ The \c saveAs() function displays a QFileDialog, prompting the user for a \c
+ fileName, to which to save a copy of the bookmarks data. Similar to the \c
+ open() function, this function also displays a warning message if the file
+ cannot be written to.
- \table
- \row
- \li \inlineimage xmlstreamexample-filemenu.png
- \li \inlineimage xmlstreamexample-helpmenu.png
- \endtable
+ \snippet serialization/streambookmarks/mainwindow.cpp 4
+
+ The \c about() function displays a QMessageBox with a brief description of
+ the example, or general information about Qt and the version of it in use.
\snippet serialization/streambookmarks/mainwindow.cpp 5
\section1 \c{main()} Function
The \c main() function instantiates \c MainWindow and invokes the \c show()
- function.
+ function to display it, then its \c open(), as this is most likely what the
+ user shall want to do first.
\snippet serialization/streambookmarks/main.cpp 0
- See the \l{http://pyxml.sourceforge.net/topics/xbel/}
- {XML Bookmark Exchange Language Resource Page} for more information
- about XBEL files.
+ See the \l{https://pyxml.sourceforge.net/topics/xbel/} {XML Bookmark
+ Exchange Language Resource Page} for more information about XBEL files.
*/
diff --git a/examples/corelib/serialization/streambookmarks/jennifer.xbel b/examples/corelib/serialization/streambookmarks/jennifer.xbel
index 2501c118af..d504236830 100644
--- a/examples/corelib/serialization/streambookmarks/jennifer.xbel
+++ b/examples/corelib/serialization/streambookmarks/jennifer.xbel
@@ -3,66 +3,66 @@
<xbel version="1.0">
<folder folded="no">
<title>Qt Resources</title>
- <bookmark href="http://qt.io/">
+ <bookmark href="https://www.qt.io/">
<title>Qt home page</title>
</bookmark>
- <bookmark href="https://www.qt.io/partners/">
+ <bookmark href="https://www.qt.io/contact-us/partners">
<title>Qt Partners</title>
</bookmark>
- <bookmark href="https://www.qt.io/qt-training/">
- <title>Training</title>
+ <bookmark href="https://www.qt.io/qt-professional-services">
+ <title>Professional Services</title>
</bookmark>
- <bookmark href="http://doc.qt.io/">
- <title>Qt 5 documentation</title>
- </bookmark>
- <bookmark href="http://qt-project.org/faq/">
- <title>Frequently Asked Questions</title>
+ <bookmark href="https://doc.qt.io/">
+ <title>Qt Documentation</title>
</bookmark>
<folder folded="yes">
<title>Community Resources</title>
- <bookmark href="http://www.qtcentre.org/content/">
+ <bookmark href="https://contribute.qt-project.org">
+ <title>The Qt Project</title>
+ </bookmark>
+ <bookmark href="https://www.qtcentre.org/content/">
<title>Qt Centre</title>
</bookmark>
- <bookmark href="http://www.qtforum.org/">
- <title>QtForum.org</title>
+ <bookmark href="https://forum.qt.io/">
+ <title>Forum.Qt.org</title>
</bookmark>
- <bookmark href="http://digitalfanatics.org/projects/qt_tutorial/">
+ <bookmark href="https://digitalfanatics.org/projects/qt_tutorial/">
<title>The Independent Qt Tutorial</title>
</bookmark>
- <bookmark href="http://www.qtforum.de/">
+ <bookmark href="https://www.qtforum.de/">
<title>German Qt Forum</title>
</bookmark>
- <bookmark href="http://www.korone.net/">
+ <bookmark href="https://www.qt-dev.com/">
<title>Korean Qt Community Site</title>
</bookmark>
- <bookmark href="http://prog.org.ru/">
+ <bookmark href="http://www.prog.org.ru/">
<title>Russian Qt Forum</title>
</bookmark>
</folder>
</folder>
<folder folded="no">
<title>Online Dictionaries</title>
- <bookmark href="http://www.dictionary.com/">
+ <bookmark href="https://www.dictionary.com/">
<title>Dictionary.com</title>
</bookmark>
- <bookmark href="http://www.m-w.com/">
+ <bookmark href="https://www.merriam-webster.com/">
<title>Merriam-Webster Online</title>
</bookmark>
- <bookmark href="http://dictionary.cambridge.org/">
+ <bookmark href="https://dictionary.cambridge.org/">
<title>Cambridge Dictionaries Online</title>
</bookmark>
- <bookmark href="http://www.onelook.com/">
+ <bookmark href="https://www.onelook.com/">
<title>OneLook Dictionary Search</title>
</bookmark>
<separator/>
- <bookmark href="http://dict.tu-chemnitz.de/">
- <title>TU Chemnitz German-English Dictionary</title>
+ <bookmark href="https://dict.tu-chemnitz.de/">
+ <title>BEOLINGUS, a service of TU Chemnitz</title>
</bookmark>
<separator/>
<bookmark href="http://atilf.atilf.fr/tlf.htm">
<title>Trésor de la Langue Française informatisé</title>
</bookmark>
- <bookmark href="http://dictionnaires.atilf.fr/dictionnaires/ACADEMIE/">
+ <bookmark href="https://www.dictionnaire-academie.fr/">
<title>Dictionnaire de l'Académie Française</title>
</bookmark>
</folder>
diff --git a/examples/corelib/serialization/streambookmarks/main.cpp b/examples/corelib/serialization/streambookmarks/main.cpp
index 75b5d646c6..0fd317de43 100644
--- a/examples/corelib/serialization/streambookmarks/main.cpp
+++ b/examples/corelib/serialization/streambookmarks/main.cpp
@@ -1,10 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-
#include "mainwindow.h"
+#include <QApplication>
+
//! [0]
int main(int argc, char *argv[])
{
diff --git a/examples/corelib/serialization/streambookmarks/mainwindow.cpp b/examples/corelib/serialization/streambookmarks/mainwindow.cpp
index 644681d706..a863f77ab7 100644
--- a/examples/corelib/serialization/streambookmarks/mainwindow.cpp
+++ b/examples/corelib/serialization/streambookmarks/mainwindow.cpp
@@ -1,22 +1,33 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "xbelreader.h"
#include "xbelwriter.h"
+#include <QFileDialog>
+#include <QHeaderView>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStatusBar>
+#include <QTreeWidget>
+
+#include <QAction>
+#if QT_CONFIG(clipboard)
+# include <QClipboard>
+#endif
+#include <QDesktopServices>
+#include <QApplication>
+#include <QScreen>
+
+using namespace Qt::StringLiterals;
+
//! [0]
-MainWindow::MainWindow()
+MainWindow::MainWindow() : treeWidget(new QTreeWidget)
{
- QStringList labels;
- labels << tr("Title") << tr("Location");
-
- treeWidget = new QTreeWidget;
treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch);
- treeWidget->setHeaderLabels(labels);
-#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD)
+ treeWidget->setHeaderLabels(QStringList{tr("Title"), tr("Location")});
+#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(treeWidget, &QWidget::customContextMenuRequested,
this, &MainWindow::onCustomContextMenuRequested);
@@ -33,7 +44,8 @@ MainWindow::MainWindow()
}
//! [0]
-#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD)
+//! [1]
+#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
void MainWindow::onCustomContextMenuRequested(const QPoint &pos)
{
const QTreeWidgetItem *item = treeWidget->itemAt(pos);
@@ -49,59 +61,77 @@ void MainWindow::onCustomContextMenuRequested(const QPoint &pos)
else if (action == openAction)
QDesktopServices::openUrl(QUrl(url));
}
-#endif // !QT_NO_CONTEXTMENU && !QT_NO_CLIPBOARD
-
+#endif // QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
//! [1]
+
+//! [2]
+void MainWindow::createMenus()
+{
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ QAction *openAct = fileMenu->addAction(tr("&Open..."), this, &MainWindow::open);
+ openAct->setShortcuts(QKeySequence::Open);
+
+ QAction *saveAsAct = fileMenu->addAction(tr("&Save As..."), this, &MainWindow::saveAs);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+
+ QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
+ exitAct->setShortcuts(QKeySequence::Quit);
+
+ menuBar()->addSeparator();
+
+ QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(tr("&About"), this, &MainWindow::about);
+ helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
+}
+//! [2]
+
+//! [3]
void MainWindow::open()
{
- QString fileName =
- QFileDialog::getOpenFileName(this, tr("Open Bookmark File"),
- QDir::currentPath(),
- tr("XBEL Files (*.xbel *.xml)"));
- if (fileName.isEmpty())
+ QFileDialog fileDialog(this, tr("Open Bookmark File"), QDir::currentPath());
+ fileDialog.setMimeTypeFilters({"application/x-xbel"_L1});
+ if (fileDialog.exec() != QDialog::Accepted)
return;
treeWidget->clear();
-
+ const QString fileName = fileDialog.selectedFiles().constFirst();
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
tr("Cannot read file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName),
- file.errorString()));
+ .arg(QDir::toNativeSeparators(fileName), file.errorString()));
return;
}
XbelReader reader(treeWidget);
if (!reader.read(&file)) {
- QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
- tr("Parse error in file %1:\n\n%2")
- .arg(QDir::toNativeSeparators(fileName),
- reader.errorString()));
+ QMessageBox::warning(
+ this, tr("QXmlStream Bookmarks"),
+ tr("Parse error in file %1:\n\n%2")
+ .arg(QDir::toNativeSeparators(fileName), reader.errorString()));
} else {
statusBar()->showMessage(tr("File loaded"), 2000);
}
-
}
-//! [1]
+//! [3]
-//! [2]
+//! [4]
void MainWindow::saveAs()
{
- QString fileName =
- QFileDialog::getSaveFileName(this, tr("Save Bookmark File"),
- QDir::currentPath(),
- tr("XBEL Files (*.xbel *.xml)"));
- if (fileName.isEmpty())
+ QFileDialog fileDialog(this, tr("Save Bookmark File"), QDir::currentPath());
+ fileDialog.setAcceptMode(QFileDialog::AcceptSave);
+ fileDialog.setDefaultSuffix("xbel"_L1);
+ fileDialog.setMimeTypeFilters({"application/x-xbel"_L1});
+ if (fileDialog.exec() != QDialog::Accepted)
return;
+ const QString fileName = fileDialog.selectedFiles().constFirst();
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
tr("Cannot write file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName),
- file.errorString()));
+ .arg(QDir::toNativeSeparators(fileName), file.errorString()));
return;
}
@@ -109,34 +139,13 @@ void MainWindow::saveAs()
if (writer.writeFile(&file))
statusBar()->showMessage(tr("File saved"), 2000);
}
-//! [2]
-
-//! [3]
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About QXmlStream Bookmarks"),
- tr("The <b>QXmlStream Bookmarks</b> example demonstrates how to use Qt's "
- "QXmlStream classes to read and write XML documents."));
-}
-//! [3]
+//! [4]
//! [5]
-void MainWindow::createMenus()
+void MainWindow::about()
{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- QAction *openAct = fileMenu->addAction(tr("&Open..."), this, &MainWindow::open);
- openAct->setShortcuts(QKeySequence::Open);
-
- QAction *saveAsAct = fileMenu->addAction(tr("&Save As..."), this, &MainWindow::saveAs);
- saveAsAct->setShortcuts(QKeySequence::SaveAs);
-
- QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
- exitAct->setShortcuts(QKeySequence::Quit);
-
- menuBar()->addSeparator();
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- helpMenu->addAction(tr("About &Qt"), qApp, &QCoreApplication::quit);
+ QMessageBox::about(this, tr("About QXmlStream Bookmarks"),
+ tr("The <b>QXmlStream Bookmarks</b> example demonstrates how to use Qt's "
+ "QXmlStream classes to read and write XML documents."));
}
//! [5]
diff --git a/examples/corelib/serialization/streambookmarks/mainwindow.h b/examples/corelib/serialization/streambookmarks/mainwindow.h
index 7a4a922e43..d9efe6b5a5 100644
--- a/examples/corelib/serialization/streambookmarks/mainwindow.h
+++ b/examples/corelib/serialization/streambookmarks/mainwindow.h
@@ -22,13 +22,13 @@ public slots:
void open();
void saveAs();
void about();
-#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD)
+#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
void onCustomContextMenuRequested(const QPoint &pos);
#endif
private:
void createMenus();
- QTreeWidget *treeWidget;
+ QTreeWidget *const treeWidget;
};
//! [0]
diff --git a/examples/corelib/serialization/streambookmarks/streambookmarks.pro b/examples/corelib/serialization/streambookmarks/streambookmarks.pro
index 9b067c7bba..34d2caae82 100644
--- a/examples/corelib/serialization/streambookmarks/streambookmarks.pro
+++ b/examples/corelib/serialization/streambookmarks/streambookmarks.pro
@@ -8,7 +8,7 @@ SOURCES = main.cpp \
QT += widgets
requires(qtConfig(filedialog))
-EXAMPLE_FILES = frank.xbel jennifer.xbel
+EXAMPLE_FILES = jennifer.xbel
# install
target.path = $$[QT_INSTALL_EXAMPLES]/corelib/serialization/streambookmarks
diff --git a/examples/corelib/serialization/streambookmarks/xbelreader.cpp b/examples/corelib/serialization/streambookmarks/xbelreader.cpp
index 74e25f12a8..c622cf6642 100644
--- a/examples/corelib/serialization/streambookmarks/xbelreader.cpp
+++ b/examples/corelib/serialization/streambookmarks/xbelreader.cpp
@@ -1,20 +1,21 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-
#include "xbelreader.h"
+#include <QStyle>
+#include <QTreeWidget>
+
+using namespace Qt::StringLiterals;
+
//! [0]
-XbelReader::XbelReader(QTreeWidget *treeWidget)
- : treeWidget(treeWidget)
+XbelReader::XbelReader(QTreeWidget *treeWidget) : treeWidget(treeWidget)
{
QStyle *style = treeWidget->style();
- folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon),
- QIcon::Normal, QIcon::Off);
- folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon),
- QIcon::Normal, QIcon::On);
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal,
+ QIcon::Off);
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On);
bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon));
}
//! [0]
@@ -25,12 +26,10 @@ bool XbelReader::read(QIODevice *device)
xml.setDevice(device);
if (xml.readNextStartElement()) {
- if (xml.name() == QLatin1String("xbel")
- && xml.attributes().value(versionAttribute()) == QLatin1String("1.0")) {
+ if (xml.name() == "xbel"_L1 && xml.attributes().value("version"_L1) == "1.0"_L1)
readXBEL();
- } else {
+ else
xml.raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
- }
}
return !xml.error();
@@ -50,15 +49,15 @@ QString XbelReader::errorString() const
//! [3]
void XbelReader::readXBEL()
{
- Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("xbel"));
+ Q_ASSERT(xml.isStartElement() && xml.name() == "xbel"_L1);
while (xml.readNextStartElement()) {
- if (xml.name() == QLatin1String("folder"))
- readFolder(0);
- else if (xml.name() == QLatin1String("bookmark"))
- readBookmark(0);
- else if (xml.name() == QLatin1String("separator"))
- readSeparator(0);
+ if (xml.name() == "folder"_L1)
+ readFolder(nullptr);
+ else if (xml.name() == "bookmark"_L1)
+ readBookmark(nullptr);
+ else if (xml.name() == "separator"_L1)
+ readSeparator(nullptr);
else
xml.skipCurrentElement();
}
@@ -66,75 +65,76 @@ void XbelReader::readXBEL()
//! [3]
//! [4]
-void XbelReader::readTitle(QTreeWidgetItem *item)
+void XbelReader::readBookmark(QTreeWidgetItem *item)
{
- Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("title"));
+ Q_ASSERT(xml.isStartElement() && xml.name() == "bookmark"_L1);
- QString title = xml.readElementText();
- item->setText(0, title);
+ QTreeWidgetItem *bookmark = createChildItem(item);
+ bookmark->setFlags(bookmark->flags() | Qt::ItemIsEditable);
+ bookmark->setIcon(0, bookmarkIcon);
+ bookmark->setText(0, QObject::tr("Unknown title"));
+ bookmark->setText(1, xml.attributes().value("href"_L1).toString());
+
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "title"_L1)
+ readTitle(bookmark);
+ else
+ xml.skipCurrentElement();
+ }
}
//! [4]
//! [5]
+void XbelReader::readTitle(QTreeWidgetItem *item)
+{
+ Q_ASSERT(xml.isStartElement() && xml.name() == "title"_L1);
+ item->setText(0, xml.readElementText());
+}
+//! [5]
+
+//! [6]
void XbelReader::readSeparator(QTreeWidgetItem *item)
{
- Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("separator"));
+ Q_ASSERT(xml.isStartElement() && xml.name() == "separator"_L1);
+ constexpr char16_t midDot = u'\xB7';
+ static const QString dots(30, midDot);
QTreeWidgetItem *separator = createChildItem(item);
- separator->setFlags(item->flags() & ~Qt::ItemIsSelectable);
- separator->setText(0, QString(30, u'\xB7'));
+ separator->setFlags(item ? item->flags() & ~Qt::ItemIsSelectable : Qt::ItemFlags{});
+ separator->setText(0, dots);
xml.skipCurrentElement();
}
-//! [5]
+//! [6]
+//! [7]
void XbelReader::readFolder(QTreeWidgetItem *item)
{
- Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("folder"));
+ Q_ASSERT(xml.isStartElement() && xml.name() == "folder"_L1);
QTreeWidgetItem *folder = createChildItem(item);
- bool folded = (xml.attributes().value(foldedAttribute()) != QLatin1String("no"));
+ bool folded = xml.attributes().value("folded"_L1) != "no"_L1;
folder->setExpanded(!folded);
while (xml.readNextStartElement()) {
- if (xml.name() == QLatin1String("title"))
+ if (xml.name() == "title"_L1)
readTitle(folder);
- else if (xml.name() == QLatin1String("folder"))
+ else if (xml.name() == "folder"_L1)
readFolder(folder);
- else if (xml.name() == QLatin1String("bookmark"))
+ else if (xml.name() == "bookmark"_L1)
readBookmark(folder);
- else if (xml.name() == QLatin1String("separator"))
+ else if (xml.name() == "separator"_L1)
readSeparator(folder);
else
xml.skipCurrentElement();
}
}
+//! [7]
-void XbelReader::readBookmark(QTreeWidgetItem *item)
-{
- Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("bookmark"));
-
- QTreeWidgetItem *bookmark = createChildItem(item);
- bookmark->setFlags(bookmark->flags() | Qt::ItemIsEditable);
- bookmark->setIcon(0, bookmarkIcon);
- bookmark->setText(0, QObject::tr("Unknown title"));
- bookmark->setText(1, xml.attributes().value(hrefAttribute()).toString());
-
- while (xml.readNextStartElement()) {
- if (xml.name() == QLatin1String("title"))
- readTitle(bookmark);
- else
- xml.skipCurrentElement();
- }
-}
-
+//! [8]
QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item)
{
- QTreeWidgetItem *childItem;
- if (item) {
- childItem = new QTreeWidgetItem(item);
- } else {
- childItem = new QTreeWidgetItem(treeWidget);
- }
+ QTreeWidgetItem *childItem = item ? new QTreeWidgetItem(item) : new QTreeWidgetItem(treeWidget);
childItem->setData(0, Qt::UserRole, xml.name().toString());
return childItem;
}
+//! [8]
diff --git a/examples/corelib/serialization/streambookmarks/xbelreader.h b/examples/corelib/serialization/streambookmarks/xbelreader.h
index 81a59b32b5..a3fa59d813 100644
--- a/examples/corelib/serialization/streambookmarks/xbelreader.h
+++ b/examples/corelib/serialization/streambookmarks/xbelreader.h
@@ -21,13 +21,8 @@ public:
//! [1]
bool read(QIODevice *device);
-
QString errorString() const;
- static inline QString versionAttribute() { return QStringLiteral("version"); }
- static inline QString hrefAttribute() { return QStringLiteral("href"); }
- static inline QString foldedAttribute() { return QStringLiteral("folded"); }
-
private:
//! [2]
void readXBEL();
diff --git a/examples/corelib/serialization/streambookmarks/xbelwriter.cpp b/examples/corelib/serialization/streambookmarks/xbelwriter.cpp
index 6cfcd2bc1a..e50f47a5a5 100644
--- a/examples/corelib/serialization/streambookmarks/xbelwriter.cpp
+++ b/examples/corelib/serialization/streambookmarks/xbelwriter.cpp
@@ -1,18 +1,14 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-
#include "xbelwriter.h"
-#include "xbelreader.h"
-static inline QString yesValue() { return QStringLiteral("yes"); }
-static inline QString noValue() { return QStringLiteral("no"); }
-static inline QString titleElement() { return QStringLiteral("title"); }
+#include <QTreeWidget>
+
+using namespace Qt::StringLiterals;
//! [0]
-XbelWriter::XbelWriter(const QTreeWidget *treeWidget)
- : treeWidget(treeWidget)
+XbelWriter::XbelWriter(const QTreeWidget *treeWidget) : treeWidget(treeWidget)
{
xml.setAutoFormatting(true);
}
@@ -24,9 +20,9 @@ bool XbelWriter::writeFile(QIODevice *device)
xml.setDevice(device);
xml.writeStartDocument();
- xml.writeDTD(QStringLiteral("<!DOCTYPE xbel>"));
- xml.writeStartElement(QStringLiteral("xbel"));
- xml.writeAttribute(XbelReader::versionAttribute(), QStringLiteral("1.0"));
+ xml.writeDTD("<!DOCTYPE xbel>"_L1);
+ xml.writeStartElement("xbel"_L1);
+ xml.writeAttribute("version"_L1, "1.0"_L1);
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
writeItem(treeWidget->topLevelItem(i));
@@ -39,21 +35,21 @@ bool XbelWriter::writeFile(QIODevice *device)
void XbelWriter::writeItem(const QTreeWidgetItem *item)
{
QString tagName = item->data(0, Qt::UserRole).toString();
- if (tagName == QLatin1String("folder")) {
+ if (tagName == "folder"_L1) {
bool folded = !item->isExpanded();
xml.writeStartElement(tagName);
- xml.writeAttribute(XbelReader::foldedAttribute(), folded ? yesValue() : noValue());
- xml.writeTextElement(titleElement(), item->text(0));
+ xml.writeAttribute("folded"_L1, folded ? "yes"_L1 : "no"_L1);
+ xml.writeTextElement("title"_L1, item->text(0));
for (int i = 0; i < item->childCount(); ++i)
writeItem(item->child(i));
xml.writeEndElement();
- } else if (tagName == QLatin1String("bookmark")) {
+ } else if (tagName == "bookmark"_L1) {
xml.writeStartElement(tagName);
if (!item->text(1).isEmpty())
- xml.writeAttribute(XbelReader::hrefAttribute(), item->text(1));
- xml.writeTextElement(titleElement(), item->text(0));
+ xml.writeAttribute("href"_L1, item->text(1));
+ xml.writeTextElement("title"_L1, item->text(0));
xml.writeEndElement();
- } else if (tagName == QLatin1String("separator")) {
+ } else if (tagName == "separator"_L1) {
xml.writeEmptyElement(tagName);
}
}
diff --git a/examples/corelib/threads/CMakeLists.txt b/examples/corelib/threads/CMakeLists.txt
index 4ced9a50e5..670821a77d 100644
--- a/examples/corelib/threads/CMakeLists.txt
+++ b/examples/corelib/threads/CMakeLists.txt
@@ -1,8 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-qt_internal_add_example(semaphores)
-qt_internal_add_example(waitconditions)
+if(NOT ANDROID)
+ qt_internal_add_example(semaphores)
+ qt_internal_add_example(waitconditions)
+endif()
if(TARGET Qt6::Widgets)
qt_internal_add_example(mandelbrot)
qt_internal_add_example(queuedcustomtype)
diff --git a/examples/corelib/threads/doc/src/mandelbrot.qdoc b/examples/corelib/threads/doc/src/mandelbrot.qdoc
index fa9a7fc3f6..6081912e69 100644
--- a/examples/corelib/threads/doc/src/mandelbrot.qdoc
+++ b/examples/corelib/threads/doc/src/mandelbrot.qdoc
@@ -3,7 +3,8 @@
/*!
\example threads/mandelbrot
- \title Mandelbrot Example
+ \examplecategory {Data Processing & I/O}
+ \title Mandelbrot
\ingroup qtconcurrent-mtexamples
\brief The Mandelbrot example demonstrates multi-thread programming
@@ -151,7 +152,7 @@
it needs to access \c{RenderThread}'s member variables (e.g., in
\c render()).
- The \c forever keyword is, like \c foreach, a Qt pseudo-keyword.
+ The \c forever keyword is a Qt pseudo-keyword.
\snippet threads/mandelbrot/renderthread.cpp 4
\snippet threads/mandelbrot/renderthread.cpp 5
diff --git a/examples/corelib/threads/doc/src/queuedcustomtype.qdoc b/examples/corelib/threads/doc/src/queuedcustomtype.qdoc
index df904cc438..8d56695c79 100644
--- a/examples/corelib/threads/doc/src/queuedcustomtype.qdoc
+++ b/examples/corelib/threads/doc/src/queuedcustomtype.qdoc
@@ -3,8 +3,8 @@
/*!
\example threads/queuedcustomtype
- \title Queued Custom Type Example
- \brief Demonstrates multi-thread programming using Qt.
+ \examplecategory {Data Processing & I/O}
+ \title Queued Custom Type
\ingroup qtconcurrent-mtexamples
\brief The Queued Custom Type example shows how to send custom types between
@@ -18,20 +18,15 @@
\section1 Overview
- In the \l{Custom Type Example}, we showed how to integrate custom types with
- the meta-object system, enabling them to be stored in QVariant objects, written
- out in debugging information and used in signal-slot communication.
-
- In this example, we create a new value class, \c Block, and register it
- with the meta-object system to enable us to send instances of it between
- threads using queued signals and slots.
+ In this example, we create a value class, \c Block, and register it with
+ the meta-object system to enable us to send instances of it between threads
+ using queued signals and slots.
\section1 The Block Class
- The \c Block class is similar to the \c Message class described in the
- \l{Custom Type Example}. It provides the default constructor, copy
- constructor and destructor in the public section of the class that the
- meta-object system requires. It describes a colored rectangle.
+ The \c Block class provides the default constructor, copy constructor, and
+ a destructor in the public section of the class as required by the
+ meta-object system. The class describes a colored rectangle.
\snippet threads/queuedcustomtype/block.h custom type definition and meta-type declaration
@@ -127,9 +122,7 @@
This example showed how a custom type can be registered with the
meta-object system so that it can be used with signal-slot connections
- between threads. For ordinary communication involving direct signals and
- slots, it is enough to simply declare the type in the way described in the
- \l{Custom Type Example}.
+ between threads.
In practice, both the Q_DECLARE_METATYPE() macro and the qRegisterMetaType()
template function can be used to register custom types, but
diff --git a/examples/corelib/threads/doc/src/semaphores.qdoc b/examples/corelib/threads/doc/src/semaphores.qdoc
index b8e1ab1b52..f5ff90b014 100644
--- a/examples/corelib/threads/doc/src/semaphores.qdoc
+++ b/examples/corelib/threads/doc/src/semaphores.qdoc
@@ -3,13 +3,13 @@
/*!
\example threads/semaphores
- \title Semaphores Example
- \brief Demonstrates multi-thread programming using Qt.
+ \examplecategory {Data Processing & I/O}
+ \title Producer and Consumer using Semaphores
\ingroup qtconcurrent-mtexamples
- \brief The Semaphores example shows how to use QSemaphore to control
- access to a circular buffer shared by a producer thread and a
- consumer thread.
+ \brief The Producer and Consumer using Semaphores example shows how
+ to use QSemaphore to control access to a circular buffer shared
+ by a producer thread and a consumer thread.
The producer writes data to the buffer until it reaches the end
of the buffer, at which point it restarts from the beginning,
@@ -30,7 +30,7 @@
An alternative to using QSemaphore to solve the producer-consumer
problem is to use QWaitCondition and QMutex. This is what the
- \l{Wait Conditions Example} does.
+ \l{Producer and Consumer using Wait Conditions} example does.
\section1 Global Variables
diff --git a/examples/corelib/threads/doc/src/waitconditions.qdoc b/examples/corelib/threads/doc/src/waitconditions.qdoc
index ae9e767c13..d46442d079 100644
--- a/examples/corelib/threads/doc/src/waitconditions.qdoc
+++ b/examples/corelib/threads/doc/src/waitconditions.qdoc
@@ -3,13 +3,13 @@
/*!
\example threads/waitconditions
- \title Wait Conditions Example
- \brief Demonstrates multi-thread programming using Qt.
+ \examplecategory {Data Processing & I/O}
+ \title Producer and Consumer using Wait Conditions
\ingroup qtconcurrent-mtexamples
- \brief The Wait Conditions example shows how to use QWaitCondition and
- QMutex to control access to a circular buffer shared by a
- producer thread and a consumer thread.
+ \brief The Producer and Consumer using Wait Conditions example shows
+ how to use QWaitCondition and QMutex to control access to a circular
+ buffer shared by a producer thread and a consumer thread.
The producer writes data to the buffer until it reaches the end
of the buffer, at which point it restarts from the beginning,
@@ -30,7 +30,7 @@
An alternative to using QWaitCondition and QMutex to solve the
producer-consumer problem is to use QSemaphore. This is what the
- \l{Semaphores Example} does.
+ \l{Producer and Consumer using Semaphores} example does.
\section1 Global Variables
diff --git a/examples/corelib/threads/mandelbrot/CMakeLists.txt b/examples/corelib/threads/mandelbrot/CMakeLists.txt
index 9c5a553966..be296918cc 100644
--- a/examples/corelib/threads/mandelbrot/CMakeLists.txt
+++ b/examples/corelib/threads/mandelbrot/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mandelbrot LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/threads/mandelbrot")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(mandelbrot PRIVATE
)
install(TARGETS mandelbrot
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mandelbrot
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/threads/mandelbrot/main.cpp b/examples/corelib/threads/mandelbrot/main.cpp
index d0d4680978..8aafebf7d7 100644
--- a/examples/corelib/threads/mandelbrot/main.cpp
+++ b/examples/corelib/threads/mandelbrot/main.cpp
@@ -2,15 +2,14 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mandelbrotwidget.h"
+#include "renderthread.h"
#include <QApplication>
-
-#include <QScreen>
-
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QDebug>
-#include <QRect>
+
+using namespace Qt::StringLiterals;
//! [0]
int main(int argc, char *argv[])
@@ -18,10 +17,10 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QCommandLineParser parser;
- parser.setApplicationDescription("Qt Mandelbrot Example");
+ parser.setApplicationDescription(u"Qt Mandelbrot Example"_s);
parser.addHelpOption();
parser.addVersionOption();
- QCommandLineOption passesOption("passes", "Number of passes (1-8)", "passes");
+ QCommandLineOption passesOption(u"passes"_s, u"Number of passes (1-8)"_s, u"passes"_s);
parser.addOption(passesOption);
parser.process(app);
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
index e0f33a2b0b..bbe694831d 100644
--- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
+++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
@@ -4,19 +4,20 @@
#include "mandelbrotwidget.h"
#include <QGesture>
+#include <QGestureEvent>
#include <QKeyEvent>
#include <QPainter>
#include <math.h>
//! [0]
-const double DefaultCenterX = -0.637011;
-const double DefaultCenterY = -0.0395159;
-const double DefaultScale = 0.00403897;
+constexpr double DefaultCenterX = -0.637011;
+constexpr double DefaultCenterY = -0.0395159;
+constexpr double DefaultScale = 0.00403897;
-const double ZoomInFactor = 0.8;
-const double ZoomOutFactor = 1 / ZoomInFactor;
-const int ScrollStep = 20;
+constexpr double ZoomInFactor = 0.8;
+constexpr double ZoomOutFactor = 1 / ZoomInFactor;
+constexpr int ScrollStep = 20;
//! [0]
//! [1]
@@ -46,7 +47,8 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
if (pixmap.isNull()) {
painter.setPen(Qt::white);
- painter.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap, tr("Rendering initial image, please wait..."));
+ painter.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap,
+ tr("Rendering initial image, please wait..."));
//! [2] //! [3]
return;
//! [3] //! [4]
@@ -60,47 +62,47 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
//! [6] //! [7]
} else {
//! [7] //! [8]
- auto previewPixmap = qFuzzyCompare(pixmap.devicePixelRatio(), qreal(1))
+ const auto previewPixmap = qFuzzyCompare(pixmap.devicePixelRatio(), qreal(1))
? pixmap
: pixmap.scaled(pixmap.deviceIndependentSize().toSize(), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
- double scaleFactor = pixmapScale / curScale;
- int newWidth = int(previewPixmap.width() * scaleFactor);
- int newHeight = int(previewPixmap.height() * scaleFactor);
- int newX = pixmapOffset.x() + (previewPixmap.width() - newWidth) / 2;
- int newY = pixmapOffset.y() + (previewPixmap.height() - newHeight) / 2;
+ const double scaleFactor = pixmapScale / curScale;
+ const int newWidth = int(previewPixmap.width() * scaleFactor);
+ const int newHeight = int(previewPixmap.height() * scaleFactor);
+ const int newX = pixmapOffset.x() + (previewPixmap.width() - newWidth) / 2;
+ const int newY = pixmapOffset.y() + (previewPixmap.height() - newHeight) / 2;
painter.save();
painter.translate(newX, newY);
painter.scale(scaleFactor, scaleFactor);
- QRectF exposed = painter.transform().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1);
+ const QRectF exposed = painter.transform().inverted().mapRect(rect())
+ .adjusted(-1, -1, 1, 1);
painter.drawPixmap(exposed, previewPixmap, exposed);
painter.restore();
}
//! [8] //! [9]
- QFontMetrics metrics = painter.fontMetrics();
+ const QFontMetrics metrics = painter.fontMetrics();
if (!info.isEmpty()){
- int infoWidth = metrics.horizontalAdvance(info);
- int infoHeight = metrics.height();
+ const int infoWidth = metrics.horizontalAdvance(info);
+ const int infoHeight = (infoWidth/width() + 1) * (metrics.height() + 5);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 127));
- infoHeight = (infoWidth/width()+1) * (infoHeight + 5);
painter.drawRect((width() - infoWidth) / 2 - 5, 0, infoWidth + 10, infoHeight);
painter.setPen(Qt::white);
painter.drawText(rect(), Qt::AlignHCenter|Qt::AlignTop|Qt::TextWordWrap, info);
}
- int helpWidth = metrics.horizontalAdvance(help);
- int helpHeight = metrics.height();
+ const int helpWidth = metrics.horizontalAdvance(help);
+ const int helpHeight = (helpWidth/width() + 1) * (metrics.height() + 5);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 127));
- helpHeight = (helpWidth/width()+1) * (helpHeight + 5);
- painter.drawRect((width() - helpWidth) / 2 - 5, height()-helpHeight, helpWidth + 10, helpHeight);
+ painter.drawRect((width() - helpWidth) / 2 - 5, height()-helpHeight, helpWidth + 10,
+ helpHeight);
painter.setPen(Qt::white);
painter.drawText(rect(), Qt::AlignHCenter|Qt::AlignBottom|Qt::TextWordWrap, help);
@@ -184,8 +186,8 @@ void MandelbrotWidget::mouseReleaseEvent(QMouseEvent *event)
lastDragPos = QPoint();
const auto pixmapSize = pixmap.deviceIndependentSize().toSize();
- int deltaX = (width() - pixmapSize.width()) / 2 - pixmapOffset.x();
- int deltaY = (height() - pixmapSize.height()) / 2 - pixmapOffset.y();
+ const int deltaX = (width() - pixmapSize.width()) / 2 - pixmapOffset.x();
+ const int deltaY = (height() - pixmapSize.height()) / 2 - pixmapOffset.y();
scroll(deltaX, deltaY);
}
}
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
index 23c3a2bf40..0d0fce56b3 100644
--- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
+++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
@@ -4,16 +4,20 @@
#ifndef MANDELBROTWIDGET_H
#define MANDELBROTWIDGET_H
-#include <QGestureEvent>
+#include "renderthread.h"
+
+#include <QCoreApplication>
#include <QPixmap>
#include <QWidget>
-#include "renderthread.h"
+QT_BEGIN_NAMESPACE
+class QGestureEvent;
+QT_END_NAMESPACE
//! [0]
class MandelbrotWidget : public QWidget
{
- Q_OBJECT
+ Q_DECLARE_TR_FUNCTIONS(MandelbrotWidget)
public:
MandelbrotWidget(QWidget *parent = nullptr);
@@ -33,11 +37,9 @@ protected:
bool event(QEvent *event) override;
#endif
-private slots:
+private:
void updatePixmap(const QImage &image, double scaleFactor);
void zoom(double zoomFactor);
-
-private:
void scroll(int deltaX, int deltaY);
#ifndef QT_NO_GESTURES
bool gestureEvent(QGestureEvent *event);
diff --git a/examples/corelib/threads/mandelbrot/renderthread.cpp b/examples/corelib/threads/mandelbrot/renderthread.cpp
index 9e6c884f91..77a14a6ac1 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.cpp
+++ b/examples/corelib/threads/mandelbrot/renderthread.cpp
@@ -4,7 +4,6 @@
#include "renderthread.h"
#include <QImage>
-
#include <QElapsedTimer>
#include <QTextStream>
@@ -70,16 +69,16 @@ void RenderThread::run()
//! [3]
//! [4]
- int halfWidth = resultSize.width() / 2;
+ const int halfWidth = resultSize.width() / 2;
//! [4] //! [5]
- int halfHeight = resultSize.height() / 2;
+ const int halfHeight = resultSize.height() / 2;
QImage image(resultSize, QImage::Format_RGB32);
image.setDevicePixelRatio(devicePixelRatio);
int pass = 0;
while (pass < numPasses) {
const int MaxIterations = (1 << (2 * pass + 6)) + 32;
- const int Limit = 4;
+ constexpr int Limit = 4;
bool allBlack = true;
timer.restart();
diff --git a/examples/corelib/threads/mandelbrot/renderthread.h b/examples/corelib/threads/mandelbrot/renderthread.h
index 6e509eee94..ecd8ae084d 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.h
+++ b/examples/corelib/threads/mandelbrot/renderthread.h
@@ -49,7 +49,7 @@ private:
bool restart = false;
bool abort = false;
- enum { ColormapSize = 512 };
+ static constexpr int ColormapSize = 512;
uint colormap[ColormapSize];
};
//! [0]
diff --git a/examples/corelib/threads/queuedcustomtype/CMakeLists.txt b/examples/corelib/threads/queuedcustomtype/CMakeLists.txt
index 5a247bacc9..725c268615 100644
--- a/examples/corelib/threads/queuedcustomtype/CMakeLists.txt
+++ b/examples/corelib/threads/queuedcustomtype/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(queuedcustomtype LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/threads/queuedcustomtype")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(queuedcustomtype PRIVATE
)
install(TARGETS queuedcustomtype
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET queuedcustomtype
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/threads/queuedcustomtype/main.cpp b/examples/corelib/threads/queuedcustomtype/main.cpp
index 0cf019990a..0a14cb48e1 100644
--- a/examples/corelib/threads/queuedcustomtype/main.cpp
+++ b/examples/corelib/threads/queuedcustomtype/main.cpp
@@ -1,12 +1,17 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-#include <QPainter>
-#include <QTime>
#include "block.h"
#include "window.h"
+#include <QApplication>
+#include <QBrush>
+#include <QImage>
+#include <QPainter>
+#include <QPen>
+#include <QPointF>
+#include <QRect>
+
QImage createImage(int width, int height)
{
QImage image(width, height, QImage::Format_RGB16);
@@ -43,8 +48,8 @@ QImage createImage(int width, int height)
int x = 0;
int y = 0;
- int starWidth = image.width()/3;
- int starHeight = image.height()/3;
+ const int starWidth = image.width()/3;
+ const int starHeight = image.height()/3;
QRect rect(x, y, starWidth, starHeight);
diff --git a/examples/corelib/threads/queuedcustomtype/renderthread.cpp b/examples/corelib/threads/queuedcustomtype/renderthread.cpp
index d7b2172608..34a439f3fe 100644
--- a/examples/corelib/threads/queuedcustomtype/renderthread.cpp
+++ b/examples/corelib/threads/queuedcustomtype/renderthread.cpp
@@ -1,22 +1,19 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include "block.h"
#include "renderthread.h"
#include <QRandomGenerator>
+#include <QRgb>
RenderThread::RenderThread(QObject *parent)
: QThread(parent)
{
- m_abort = false;
}
RenderThread::~RenderThread()
{
- mutex.lock();
- m_abort = true;
- mutex.unlock();
-
wait();
}
@@ -27,27 +24,26 @@ void RenderThread::processImage(const QImage &image)
return;
m_image = image;
- m_abort = false;
start();
}
void RenderThread::run()
{
- int size = qMax(m_image.width()/20, m_image.height()/20);
+ const int size = qMax(m_image.width()/20, m_image.height()/20);
for (int s = size; s > 0; --s) {
for (int c = 0; c < 400; ++c) {
//![processing the image (start)]
- int x1 = qMax(0, QRandomGenerator::global()->bounded(m_image.width()) - s/2);
- int x2 = qMin(x1 + s/2 + 1, m_image.width());
- int y1 = qMax(0, QRandomGenerator::global()->bounded(m_image.height()) - s/2);
- int y2 = qMin(y1 + s/2 + 1, m_image.height());
+ const int x1 = qMax(0, QRandomGenerator::global()->bounded(m_image.width()) - s/2);
+ const int x2 = qMin(x1 + s/2 + 1, m_image.width());
+ const int y1 = qMax(0, QRandomGenerator::global()->bounded(m_image.height()) - s/2);
+ const int y2 = qMin(y1 + s/2 + 1, m_image.height());
int n = 0;
int red = 0;
int green = 0;
int blue = 0;
for (int i = y1; i < y2; ++i) {
for (int j = x1; j < x2; ++j) {
- QRgb pixel = m_image.pixel(j, i);
+ const QRgb pixel = m_image.pixel(j, i);
red += qRed(pixel);
green += qGreen(pixel);
blue += qBlue(pixel);
@@ -55,20 +51,13 @@ void RenderThread::run()
}
}
//![processing the image (finish)]
- Block block(QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1),
+ const Block block(QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1),
QColor(red/n, green/n, blue/n));
emit sendBlock(block);
- if (m_abort)
+ if (isInterruptionRequested())
return;
msleep(10);
}
}
}
//![processing the image (finish)]
-
-void RenderThread::stopProcess()
-{
- mutex.lock();
- m_abort = true;
- mutex.unlock();
-}
diff --git a/examples/corelib/threads/queuedcustomtype/renderthread.h b/examples/corelib/threads/queuedcustomtype/renderthread.h
index afbc70ec75..c3152e4081 100644
--- a/examples/corelib/threads/queuedcustomtype/renderthread.h
+++ b/examples/corelib/threads/queuedcustomtype/renderthread.h
@@ -5,9 +5,9 @@
#define RENDERTHREAD_H
#include <QImage>
-#include <QMutex>
#include <QThread>
-#include "block.h"
+
+class Block;
//! [RenderThread class definition]
class RenderThread : public QThread
@@ -23,16 +23,11 @@ public:
signals:
void sendBlock(const Block &block);
-public slots:
- void stopProcess();
-
protected:
void run();
private:
- bool m_abort;
QImage m_image;
- QMutex mutex;
};
//! [RenderThread class definition]
diff --git a/examples/corelib/threads/queuedcustomtype/window.cpp b/examples/corelib/threads/queuedcustomtype/window.cpp
index 1adfe7ed38..db12133206 100644
--- a/examples/corelib/threads/queuedcustomtype/window.cpp
+++ b/examples/corelib/threads/queuedcustomtype/window.cpp
@@ -1,8 +1,17 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include "block.h"
+#include "renderthread.h"
#include "window.h"
-#include <QtWidgets>
+
+#include <QFileDialog>
+#include <QGuiApplication>
+#include <QHBoxLayout>
+#include <QImageReader>
+#include <QPainter>
+#include <QScreen>
+#include <QVBoxLayout>
//! [Window constructor start]
Window::Window(QWidget *parent)
@@ -20,7 +29,7 @@ Window::Window(QWidget *parent)
connect(loadButton, &QPushButton::clicked,
this, QOverload<>::of(&Window::loadImage));
connect(resetButton, &QPushButton::clicked,
- thread, &RenderThread::stopProcess);
+ thread, &RenderThread::requestInterruption);
connect(thread, &RenderThread::finished,
this, &Window::resetUi);
//! [set up widgets and connections] //! [connecting signal with custom type]
@@ -51,13 +60,13 @@ void Window::loadImage()
if (format.toLower() == format)
formats.append(QLatin1String("*.") + QString::fromLatin1(format));
- QString newPath = QFileDialog::getOpenFileName(this, tr("Open Image"),
+ const QString newPath = QFileDialog::getOpenFileName(this, tr("Open Image"),
path, tr("Image files (%1)").arg(formats.join(' ')));
if (newPath.isEmpty())
return;
- QImage image(newPath);
+ const QImage image(newPath);
if (!image.isNull()) {
loadImage(image);
path = newPath;
@@ -67,7 +76,7 @@ void Window::loadImage()
void Window::loadImage(const QImage &image)
{
QImage useImage;
- QRect space = QGuiApplication::primaryScreen()->availableGeometry();
+ const QRect space = QGuiApplication::primaryScreen()->availableGeometry();
if (image.width() > 0.75*space.width() || image.height() > 0.75*space.height())
useImage = image.scaled(0.75*space.width(), 0.75*space.height(),
Qt::KeepAspectRatio, Qt::SmoothTransformation);
diff --git a/examples/corelib/threads/queuedcustomtype/window.h b/examples/corelib/threads/queuedcustomtype/window.h
index b1ab4f6c24..a4f995696e 100644
--- a/examples/corelib/threads/queuedcustomtype/window.h
+++ b/examples/corelib/threads/queuedcustomtype/window.h
@@ -4,13 +4,14 @@
#ifndef WINDOW_H
#define WINDOW_H
+#include <QImage>
+#include <QLabel>
+#include <QPixmap>
+#include <QPushButton>
#include <QWidget>
-#include "renderthread.h"
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QPushButton;
-QT_END_NAMESPACE
+class Block;
+class RenderThread;
//! [Window class definition]
class Window : public QWidget
diff --git a/examples/corelib/threads/semaphores/CMakeLists.txt b/examples/corelib/threads/semaphores/CMakeLists.txt
index bccf6e1e37..a096616e5a 100644
--- a/examples/corelib/threads/semaphores/CMakeLists.txt
+++ b/examples/corelib/threads/semaphores/CMakeLists.txt
@@ -1,15 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(semaphores LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/threads/semaphores")
-
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
@@ -23,7 +21,14 @@ target_link_libraries(semaphores PRIVATE
)
install(TARGETS semaphores
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET semaphores
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/threads/semaphores/semaphores.cpp b/examples/corelib/threads/semaphores/semaphores.cpp
index 5a49555110..103f331b0c 100644
--- a/examples/corelib/threads/semaphores/semaphores.cpp
+++ b/examples/corelib/threads/semaphores/semaphores.cpp
@@ -7,9 +7,9 @@
#include <stdlib.h>
//! [0]
-const int DataSize = 100000;
+constexpr int DataSize = 100000;
-const int BufferSize = 8192;
+constexpr int BufferSize = 8192;
char buffer[BufferSize];
QSemaphore freeBytes(BufferSize);
diff --git a/examples/corelib/threads/waitconditions/CMakeLists.txt b/examples/corelib/threads/waitconditions/CMakeLists.txt
index 45818e2bfc..5fc44a079b 100644
--- a/examples/corelib/threads/waitconditions/CMakeLists.txt
+++ b/examples/corelib/threads/waitconditions/CMakeLists.txt
@@ -1,15 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(waitconditions LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/threads/waitconditions")
-
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
@@ -23,7 +21,14 @@ target_link_libraries(waitconditions PRIVATE
)
install(TARGETS waitconditions
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET waitconditions
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/tools/CMakeLists.txt b/examples/corelib/tools/CMakeLists.txt
index 0ec145da29..15188b0219 100644
--- a/examples/corelib/tools/CMakeLists.txt
+++ b/examples/corelib/tools/CMakeLists.txt
@@ -1,9 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Widgets)
return()
endif()
qt_internal_add_example(contiguouscache)
-qt_internal_add_example(customtype)
-qt_internal_add_example(customtypesending)
diff --git a/examples/corelib/tools/contiguouscache/CMakeLists.txt b/examples/corelib/tools/contiguouscache/CMakeLists.txt
index 1a23099968..2fab4803c1 100644
--- a/examples/corelib/tools/contiguouscache/CMakeLists.txt
+++ b/examples/corelib/tools/contiguouscache/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(contiguouscache LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/tools/contiguouscache")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(contiguouscache PRIVATE
)
install(TARGETS contiguouscache
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET contiguouscache
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/tools/contiguouscache/randomlistmodel.cpp b/examples/corelib/tools/contiguouscache/randomlistmodel.cpp
index 3997be2198..4832f0ae24 100644
--- a/examples/corelib/tools/contiguouscache/randomlistmodel.cpp
+++ b/examples/corelib/tools/contiguouscache/randomlistmodel.cpp
@@ -3,16 +3,12 @@
#include "randomlistmodel.h"
#include <QRandomGenerator>
-static const int bufferSize(500);
-static const int lookAhead(100);
-static const int halfLookAhead(lookAhead/2);
+static constexpr int bufferSize(500);
+static constexpr int lookAhead(100);
+static constexpr int halfLookAhead(lookAhead / 2);
RandomListModel::RandomListModel(QObject *parent)
-: QAbstractListModel(parent), m_rows(bufferSize), m_count(10000)
-{
-}
-
-RandomListModel::~RandomListModel()
+ : QAbstractListModel(parent), m_rows(bufferSize), m_count(10000)
{
}
@@ -31,14 +27,14 @@ QVariant RandomListModel::data(const QModelIndex &index, int role) const
if (row > m_rows.lastIndex()) {
if (row - m_rows.lastIndex() > lookAhead)
- cacheRows(row-halfLookAhead, qMin(m_count, row+halfLookAhead));
+ cacheRows(row - halfLookAhead, qMin(m_count, row + halfLookAhead));
else while (row > m_rows.lastIndex())
- m_rows.append(fetchRow(m_rows.lastIndex()+1));
+ m_rows.append(fetchRow(m_rows.lastIndex() + 1));
} else if (row < m_rows.firstIndex()) {
if (m_rows.firstIndex() - row > lookAhead)
- cacheRows(qMax(0, row-halfLookAhead), row+halfLookAhead);
+ cacheRows(qMax(0, row - halfLookAhead), row + halfLookAhead);
else while (row < m_rows.firstIndex())
- m_rows.prepend(fetchRow(m_rows.firstIndex()-1));
+ m_rows.prepend(fetchRow(m_rows.firstIndex() - 1));
}
return m_rows.at(row);
diff --git a/examples/corelib/tools/contiguouscache/randomlistmodel.h b/examples/corelib/tools/contiguouscache/randomlistmodel.h
index 72a6e05f7c..b95acdf3f9 100644
--- a/examples/corelib/tools/contiguouscache/randomlistmodel.h
+++ b/examples/corelib/tools/contiguouscache/randomlistmodel.h
@@ -13,7 +13,6 @@ class RandomListModel : public QAbstractListModel
Q_OBJECT
public:
RandomListModel(QObject *parent = nullptr);
- ~RandomListModel();
int rowCount(const QModelIndex & = QModelIndex()) const override;
QVariant data(const QModelIndex &, int) const override;
diff --git a/examples/corelib/tools/customtype/CMakeLists.txt b/examples/corelib/tools/customtype/CMakeLists.txt
deleted file mode 100644
index 21c9003f56..0000000000
--- a/examples/corelib/tools/customtype/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(customtype LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/tools/customtype")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(customtype
- main.cpp
- message.cpp message.h
-)
-
-set_target_properties(customtype PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(customtype PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS customtype
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/corelib/tools/customtype/customtype.pro b/examples/corelib/tools/customtype/customtype.pro
deleted file mode 100644
index 0e0fe9b1a5..0000000000
--- a/examples/corelib/tools/customtype/customtype.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-HEADERS = message.h
-SOURCES = main.cpp \
- message.cpp
-QT += widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/corelib/tools/customtype
-INSTALLS += target
diff --git a/examples/corelib/tools/customtype/main.cpp b/examples/corelib/tools/customtype/main.cpp
deleted file mode 100644
index e37aa0dab8..0000000000
--- a/examples/corelib/tools/customtype/main.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QCoreApplication>
-#include <QDebug>
-#include <QVariant>
-#include "message.h"
-
-int main(int argc, char *argv[])
-{
- QCoreApplication app(argc, argv);
- QStringList headers;
- headers << "Subject: Hello World"
- << "From: address@example.com";
- QString body = "This is a test.\r\n";
-
-//! [printing a custom type]
- Message message(body, headers);
- qDebug() << "Original:" << message;
-//! [printing a custom type]
-
-//! [storing a custom value]
- QVariant stored;
- stored.setValue(message);
-//! [storing a custom value]
-
- qDebug() << "Stored:" << stored;
-
-//! [retrieving a custom value]
- Message retrieved = qvariant_cast<Message>(stored);
- qDebug() << "Retrieved:" << retrieved;
- retrieved = qvariant_cast<Message>(stored);
- qDebug() << "Retrieved:" << retrieved;
-//! [retrieving a custom value]
-
- return 0;
-}
diff --git a/examples/corelib/tools/customtype/message.cpp b/examples/corelib/tools/customtype/message.cpp
deleted file mode 100644
index eb0e4b8d7a..0000000000
--- a/examples/corelib/tools/customtype/message.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "message.h"
-
-#include <QDebug>
-
-Message::Message(const QString &body, const QStringList &headers)
- : m_body(body), m_headers(headers)
-{
-}
-
-//! [custom type streaming operator]
-QDebug operator<<(QDebug dbg, const Message &message)
-{
- QDebugStateSaver saver(dbg);
- QList<QStringView> pieces = message.body().split(u"\r\n", Qt::SkipEmptyParts);
- if (pieces.isEmpty())
- dbg.nospace() << "Message()";
- else if (pieces.size() == 1)
- dbg.nospace() << "Message(" << pieces.first() << ")";
- else
- dbg.nospace() << "Message(" << pieces.first() << " ...)";
- return dbg;
-}
-//! [custom type streaming operator]
-
-//! [getter functions]
-QStringView Message::body() const
-{
- return m_body;
-}
-
-QStringList Message::headers() const
-{
- return m_headers;
-}
-//! [getter functions]
diff --git a/examples/corelib/tools/customtype/message.h b/examples/corelib/tools/customtype/message.h
deleted file mode 100644
index d359f79161..0000000000
--- a/examples/corelib/tools/customtype/message.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MESSAGE_H
-#define MESSAGE_H
-
-#include <QMetaType>
-#include <QStringList>
-
-//! [custom type definition]
-class Message
-{
-public:
- Message() = default;
- ~Message() = default;
- Message(const Message &) = default;
- Message &operator=(const Message &) = default;
-
- Message(const QString &body, const QStringList &headers);
-
- QStringView body() const;
- QStringList headers() const;
-
-private:
- QString m_body;
- QStringList m_headers;
-};
-//! [custom type definition]
-
-//! [custom type meta-type declaration]
-Q_DECLARE_METATYPE(Message);
-//! [custom type meta-type declaration]
-
-//! [custom type streaming operator]
-QDebug operator<<(QDebug dbg, const Message &message);
-//! [custom type streaming operator]
-
-#endif
diff --git a/examples/corelib/tools/customtypesending/CMakeLists.txt b/examples/corelib/tools/customtypesending/CMakeLists.txt
deleted file mode 100644
index a993d81160..0000000000
--- a/examples/corelib/tools/customtypesending/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(customtypesending LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/tools/customtypesending")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(customtypesending
- main.cpp
- message.cpp message.h
- window.cpp window.h
-)
-
-set_target_properties(customtypesending PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(customtypesending PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS customtypesending
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/corelib/tools/customtypesending/customtypesending.pro b/examples/corelib/tools/customtypesending/customtypesending.pro
deleted file mode 100644
index da351ce828..0000000000
--- a/examples/corelib/tools/customtypesending/customtypesending.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-HEADERS = message.h \
- window.h
-SOURCES = main.cpp \
- message.cpp \
- window.cpp
-QT += widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/corelib/tools/customtypesending
-INSTALLS += target
diff --git a/examples/corelib/tools/customtypesending/main.cpp b/examples/corelib/tools/customtypesending/main.cpp
deleted file mode 100644
index 94f41d73a8..0000000000
--- a/examples/corelib/tools/customtypesending/main.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include "message.h"
-#include "window.h"
-
-//! [main function]
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- QStringList headers;
- headers << "Subject: Hello World"
- << "From: address@example.com";
- QString body = "This is a test.\r\n";
- Message message(body, headers);
-
- Window window1;
- window1.setMessage(message);
-
- Window window2;
- QObject::connect(&window1, &Window::messageSent,
- &window2, &Window::setMessage);
- QObject::connect(&window2, &Window::messageSent,
- &window1, &Window::setMessage);
- window1.show();
- window2.show();
- return app.exec();
-}
-//! [main function]
diff --git a/examples/corelib/tools/customtypesending/message.cpp b/examples/corelib/tools/customtypesending/message.cpp
deleted file mode 100644
index dfb5c5359a..0000000000
--- a/examples/corelib/tools/customtypesending/message.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "message.h"
-
-Message::Message(const QString &body, const QStringList &headers)
- : m_body(body), m_headers(headers)
-{
-}
-
-QString Message::body() const
-{
- return m_body;
-}
-
-QStringList Message::headers() const
-{
- return m_headers;
-}
diff --git a/examples/corelib/tools/customtypesending/message.h b/examples/corelib/tools/customtypesending/message.h
deleted file mode 100644
index 2df50115c4..0000000000
--- a/examples/corelib/tools/customtypesending/message.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MESSAGE_H
-#define MESSAGE_H
-
-#include <QMetaType>
-#include <QStringList>
-
-//! [custom type definition]
-class Message
-{
-public:
- Message() = default;
- ~Message() = default;
- Message(const Message &) = default;
- Message &operator=(const Message &) = default;
-
- Message(const QString &body, const QStringList &headers);
-
- QString body() const;
- QStringList headers() const;
-
-private:
- QString m_body;
- QStringList m_headers;
-};
-//! [custom type definition]
-
-//! [custom type meta-type declaration]
-Q_DECLARE_METATYPE(Message);
-//! [custom type meta-type declaration]
-
-#endif
diff --git a/examples/corelib/tools/customtypesending/window.cpp b/examples/corelib/tools/customtypesending/window.cpp
deleted file mode 100644
index f294af3ec2..0000000000
--- a/examples/corelib/tools/customtypesending/window.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-#include "window.h"
-
-//! [Window constructor]
-Window::Window(QWidget *parent)
- : QWidget(parent), editor(new QTextEdit(this))
-{
- QPushButton *sendButton = new QPushButton(tr("&Send message"));
-
- connect(sendButton, &QPushButton::clicked,
- this, &Window::sendMessage);
-
- QHBoxLayout *buttonLayout = new QHBoxLayout;
- buttonLayout->addStretch();
- buttonLayout->addWidget(sendButton);
- buttonLayout->addStretch();
-
- QVBoxLayout *layout = new QVBoxLayout(this);
- layout->addWidget(editor);
- layout->addLayout(buttonLayout);
-
- setWindowTitle(tr("Custom Type Sending"));
-}
-//! [Window constructor]
-
-//! [sending a message]
-void Window::sendMessage()
-{
- thisMessage = Message(editor->toPlainText(), thisMessage.headers());
- emit messageSent(thisMessage);
-}
-//! [sending a message]
-
-//! [receiving a message]
-void Window::setMessage(const Message &message)
-{
- thisMessage = message;
- editor->setPlainText(thisMessage.body());
-}
-//! [receiving a message]
diff --git a/examples/corelib/tools/customtypesending/window.h b/examples/corelib/tools/customtypesending/window.h
deleted file mode 100644
index a3a318e382..0000000000
--- a/examples/corelib/tools/customtypesending/window.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWidget>
-#include "message.h"
-
-QT_FORWARD_DECLARE_CLASS(QTextEdit)
-
-//! [Window class definition]
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window(QWidget *parent = nullptr);
-
-signals:
- void messageSent(const Message &message);
-
-public slots:
- void setMessage(const Message &message);
-
-private slots:
- void sendMessage();
-
-private:
- Message thisMessage;
- QTextEdit *editor;
-};
-//! [Window class definition]
-
-#endif
diff --git a/examples/corelib/tools/doc/src/contiguouscache.qdoc b/examples/corelib/tools/doc/src/contiguouscache.qdoc
index bb8616818f..9fc572927b 100644
--- a/examples/corelib/tools/doc/src/contiguouscache.qdoc
+++ b/examples/corelib/tools/doc/src/contiguouscache.qdoc
@@ -4,6 +4,7 @@
/*!
\example tools/contiguouscache
\title Contiguous Cache Example
+ \examplecategory {Data Processing & I/O}
\brief The Contiguous Cache example shows how to use QContiguousCache to manage memory usage for
very large models. In some environments memory is limited and, even when it
diff --git a/examples/corelib/tools/doc/src/customtype.qdoc b/examples/corelib/tools/doc/src/customtype.qdoc
deleted file mode 100644
index 55d29609ce..0000000000
--- a/examples/corelib/tools/doc/src/customtype.qdoc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example tools/customtype
- \title Custom Type Example
-
- \brief The Custom Type example shows how to integrate a custom type into Qt's
- meta-object system.
-
- Contents:
-
- \tableofcontents
-
- \section1 Overview
-
- Qt provides a range of standard value types that are used to provide
- rich and meaningful APIs. These types are integrated with the meta-object
- system, enabling them to be stored in QVariant objects, written out in
- debugging information and sent between components in signal-slot
- communication.
-
- Custom types can also be integrated with the meta-object system as long as
- they are written to conform to some simple guidelines. In this example, we
- introduce a simple \c Message class, we describe how we make it work with
- QVariant, and we show how it can be extended to generate a printable
- representation of itself for use in debugging output.
-
- \section1 The Message Class Definition
-
- The \c Message class is a simple value class that contains two pieces
- of information (a QString and a QStringList), each of which can be read
- using trivial getter functions:
-
- \snippet tools/customtype/message.h custom type definition
-
- The default constructor, copy constructor and destructor are
- all required, and must be public, if the type is to be integrated into the
- meta-object system. Other than this, we are free to implement whatever we
- need to make the type do what we want, so we also include a constructor
- that lets us set the type's data members.
-
- To enable the type to be used with QVariant, we declare it using the
- Q_DECLARE_METATYPE() macro:
-
- \snippet tools/customtype/message.h custom type meta-type declaration
-
- We do not need to write any additional code to accompany this macro.
-
- To allow us to see a readable description of each \c Message object when it
- is sent to the debug output stream, we define a streaming operator:
-
- \snippet tools/customtype/message.h custom type streaming operator
-
- This facility is useful if you need to insert tracing statements in your
- code for debugging purposes.
-
- \section1 The Message Class Implementation
-
- The streaming operator is implemented in the following way:
-
- \snippet tools/customtype/message.cpp custom type streaming operator
-
- Here, we want to represent each value depending on how many lines are stored
- in the message body. We stream text to the QDebug object passed to the
- operator and return the QDebug object obtained from its maybeSpace() member
- function; this is described in more detail in the
- \l{Creating Custom Qt Types#Making the Type Printable}{Creating Custom Qt Types}
- document.
-
- We include the code for the getter functions for completeness:
-
- \snippet tools/customtype/message.cpp getter functions
-
- With the type fully defined, implemented, and integrated with the
- meta-object system, we can now use it.
-
- \section1 Using the Message
-
- In the example's \c{main()} function, we show how a \c Message object can
- be printed to the console by sending it to the debug stream:
-
- \snippet tools/customtype/main.cpp printing a custom type
-
- You can use the type with QVariant in exactly the same way as you would
- use standard Qt value types. Here's how to store a value using the
- QVariant::setValue() function:
-
- \snippet tools/customtype/main.cpp storing a custom value
-
- Alternatively, the QVariant::fromValue() function can be used if
- you are using a compiler without support for member template
- functions.
-
- The value can be retrieved using the QVariant::value() member template
- function:
-
- \snippet tools/customtype/main.cpp retrieving a custom value
-
- \section1 Further Reading
-
- The custom \c Message type can also be used with direct signal-slot
- connections.
-
- To register a custom type for use with queued signals and slots, such as
- those used in cross-thread communication, see the
- \l{Queued Custom Type Example}.
-
- More information on using custom types with Qt can be found in the
- \l{Creating Custom Qt Types} document.
-*/
diff --git a/examples/corelib/tools/tools.pro b/examples/corelib/tools/tools.pro
index 6fb4a1214f..618628d274 100644
--- a/examples/corelib/tools/tools.pro
+++ b/examples/corelib/tools/tools.pro
@@ -1,6 +1,4 @@
requires(qtHaveModule(widgets))
TEMPLATE = subdirs
-SUBDIRS = contiguouscache \
- customtype \
- customtypesending
+SUBDIRS = contiguouscache
diff --git a/examples/dbus/CMakeLists.txt b/examples/dbus/CMakeLists.txt
index 738d1e47f7..79caaf949d 100644
--- a/examples/dbus/CMakeLists.txt
+++ b/examples/dbus/CMakeLists.txt
@@ -1,12 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::DBus)
return()
endif()
-qt_internal_add_example(pingpong)
-if(QT_FEATURE_process)
- qt_internal_add_example(complexpingpong)
+if(NOT ANDROID)
+ qt_internal_add_example(pingpong)
+ if(QT_FEATURE_process)
+ qt_internal_add_example(complexpingpong)
+ endif()
endif()
if(TARGET Qt6::Widgets)
qt_internal_add_example(chat)
diff --git a/examples/dbus/chat/CMakeLists.txt b/examples/dbus/chat/CMakeLists.txt
index b6b17e294d..472d893dee 100644
--- a/examples/dbus/chat/CMakeLists.txt
+++ b/examples/dbus/chat/CMakeLists.txt
@@ -1,17 +1,11 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chat LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/dbus/chat")
-
find_package(Qt6 REQUIRED COMPONENTS Core DBus Gui Widgets)
qt_standard_project_setup()
@@ -48,7 +42,14 @@ target_link_libraries(chat PRIVATE
)
install(TARGETS chat
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET chat
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/dbus/complexpingpong/CMakeLists.txt b/examples/dbus/complexpingpong/CMakeLists.txt
index 377b56b1ab..da4ca95288 100644
--- a/examples/dbus/complexpingpong/CMakeLists.txt
+++ b/examples/dbus/complexpingpong/CMakeLists.txt
@@ -1,15 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(complexpingpong LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/dbus/complexpingpong")
-
find_package(Qt6 REQUIRED COMPONENTS Core DBus)
qt_standard_project_setup()
@@ -34,7 +32,21 @@ target_link_libraries(complexpong PRIVATE
)
install(TARGETS complexping complexpong
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET complexping
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
+
+qt_generate_deploy_app_script(
+ TARGET complexpong
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/dbus/doc/src/chat.qdoc b/examples/dbus/doc/src/chat.qdoc
index 12bd498ac9..fdbc2f30ae 100644
--- a/examples/dbus/doc/src/chat.qdoc
+++ b/examples/dbus/doc/src/chat.qdoc
@@ -4,11 +4,12 @@
/*!
\example chat
\title D-Bus Chat
+ \examplecategory {Connectivity}
\ingroup examples-dbus
\brief Demonstrates communication among instances of an application.
\e Chat is a \l{Qt D-Bus} example which demonstrates a simple chat system
- among instances of an application. Users connect and send message to
+ among instances of an application. Users connect and send messages to
each other.
\image dbus-chat-example.webp
diff --git a/examples/dbus/doc/src/complexpingpong.qdoc b/examples/dbus/doc/src/complexpingpong.qdoc
index 0521eafb19..84fccdf561 100644
--- a/examples/dbus/doc/src/complexpingpong.qdoc
+++ b/examples/dbus/doc/src/complexpingpong.qdoc
@@ -4,6 +4,7 @@
/*!
\example complexpingpong
\title D-Bus Complex Ping Pong
+ \examplecategory {Connectivity}
\ingroup examples-dbus
\brief Demonstrates usage of the Qt D-Bus typesystem.
diff --git a/examples/dbus/doc/src/pingpong.qdoc b/examples/dbus/doc/src/pingpong.qdoc
index 1e2b114a0e..1ab0ec62fe 100644
--- a/examples/dbus/doc/src/pingpong.qdoc
+++ b/examples/dbus/doc/src/pingpong.qdoc
@@ -4,6 +4,7 @@
/*!
\example pingpong
\title D-Bus Ping Pong
+ \examplecategory {Connectivity}
\ingroup examples-dbus
\brief Demonstrates a simple message system using D-Bus.
diff --git a/examples/dbus/pingpong/CMakeLists.txt b/examples/dbus/pingpong/CMakeLists.txt
index 5d59813784..d159ad9ba4 100644
--- a/examples/dbus/pingpong/CMakeLists.txt
+++ b/examples/dbus/pingpong/CMakeLists.txt
@@ -1,15 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(pingpong LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/dbus/pingpong")
-
find_package(Qt6 REQUIRED COMPONENTS Core DBus)
qt_standard_project_setup()
@@ -35,7 +33,21 @@ target_link_libraries(pong PRIVATE
)
install(TARGETS ping pong
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET ping
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
+
+qt_generate_deploy_app_script(
+ TARGET pong
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/dbus/remotecontrolledcar/CMakeLists.txt b/examples/dbus/remotecontrolledcar/CMakeLists.txt
index 1704591026..fdca3256ad 100644
--- a/examples/dbus/remotecontrolledcar/CMakeLists.txt
+++ b/examples/dbus/remotecontrolledcar/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(remotecontrolledcar LANGUAGES CXX)
diff --git a/examples/dbus/remotecontrolledcar/car/CMakeLists.txt b/examples/dbus/remotecontrolledcar/car/CMakeLists.txt
index 3b95730625..24bbdb669c 100644
--- a/examples/dbus/remotecontrolledcar/car/CMakeLists.txt
+++ b/examples/dbus/remotecontrolledcar/car/CMakeLists.txt
@@ -1,14 +1,8 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/dbus/remotecontrolledcar/car")
-
set(car_SRCS)
qt_add_dbus_adaptor(car_SRCS
../common/car.xml
@@ -36,7 +30,14 @@ target_link_libraries(car PRIVATE
)
install(TARGETS car
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET car
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/dbus/remotecontrolledcar/car/car.cpp b/examples/dbus/remotecontrolledcar/car/car.cpp
index 7d12e54071..0920658281 100644
--- a/examples/dbus/remotecontrolledcar/car/car.cpp
+++ b/examples/dbus/remotecontrolledcar/car/car.cpp
@@ -93,5 +93,24 @@ void Car::timerEvent(QTimerEvent *event)
setTransform(QTransform().rotate(rotation), true);
setTransform(QTransform::fromTranslate(0, -speed), true);
+
+ if (!scene()->views().isEmpty()) {
+ QRect viewRect = scene()->views().at(0)->sceneRect().toRect();
+ QTransform fx = transform();
+ qreal dx = fx.dx();
+ qreal dy = fx.dy();
+ while (dx < viewRect.left() - 10)
+ dx += viewRect.width();
+ while (dy < viewRect.top() - 10)
+ dy += viewRect.height();
+ while (dx > viewRect.right() + 10)
+ dx -= viewRect.width();
+ while (dy > viewRect.bottom() + 10)
+ dy -= viewRect.width();
+ setTransform(QTransform(fx.m11(), fx.m12(), fx.m13(),
+ fx.m21(), fx.m22(), fx.m23(),
+ dx, dy, fx.m33()));
+ }
+
update();
}
diff --git a/examples/dbus/remotecontrolledcar/car/main.cpp b/examples/dbus/remotecontrolledcar/car/main.cpp
index 9c732fed5e..81b8cdfc20 100644
--- a/examples/dbus/remotecontrolledcar/car/main.cpp
+++ b/examples/dbus/remotecontrolledcar/car/main.cpp
@@ -23,7 +23,7 @@ int main(int argc, char *argv[])
view.setRenderHint(QPainter::Antialiasing);
view.setBackgroundBrush(Qt::darkGray);
view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Qt DBus Controlled Car"));
- view.resize(400, 300);
+ view.resize(view.sizeHint());
view.show();
new CarInterfaceAdaptor(car);
diff --git a/examples/dbus/remotecontrolledcar/controller/CMakeLists.txt b/examples/dbus/remotecontrolledcar/controller/CMakeLists.txt
index e94d79a634..a0c1aea7c5 100644
--- a/examples/dbus/remotecontrolledcar/controller/CMakeLists.txt
+++ b/examples/dbus/remotecontrolledcar/controller/CMakeLists.txt
@@ -1,14 +1,8 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/dbus/remotecontrolledcar/controller")
-
set(controller_SRCS)
qt_add_dbus_interface(controller_SRCS
../common/car.xml
@@ -16,11 +10,23 @@ qt_add_dbus_interface(controller_SRCS
)
qt_add_executable(controller
- controller.cpp controller.h controller.ui
+ controller.cpp controller.h
main.cpp
${controller_SRCS}
)
+qt_add_resources(controller
+ PREFIX
+ "/"
+ FILES
+ down.svg
+ left.svg
+ right.svg
+ up.svg
+ connected.svg
+ connecting.svg
+)
+
set_target_properties(controller PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
@@ -34,7 +40,14 @@ target_link_libraries(controller PRIVATE
)
install(TARGETS controller
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET controller
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/dbus/remotecontrolledcar/controller/connected.svg b/examples/dbus/remotecontrolledcar/controller/connected.svg
new file mode 100644
index 0000000000..a3616b769e
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/connected.svg
@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M19 11C19 11.5523 19.4477 12 20 12C20.5523 12 21 11.5523 21 11V10.8478C21 8.11075 19.7088 5.53404 17.5163 3.89561C17.0739 3.56501 16.4472 3.65565 16.1166 4.09805C15.786 4.54046 15.8767 5.1671 16.3191 5.4977C18.0064 6.75857 19 8.74149 19 10.8478V11ZM4 12C4.55228 12 5 11.5523 5 11V10.8478C5 8.74149 5.99363 6.75857 7.68091 5.4977C8.12331 5.1671 8.21395 4.54046 7.88335 4.09805C7.55275 3.65565 6.92611 3.56501 6.4837 3.89561C4.29117 5.53404 3 8.11075 3 10.8478V11C3 11.5523 3.44772 12 4 12ZM7.10555 19.5528C7.35253 19.0588 7.95321 18.8586 8.44719 19.1055C10.6837 20.2238 13.3162 20.2238 15.5528 19.1056C16.0467 18.8586 16.6474 19.0588 16.8944 19.5528C17.1414 20.0468 16.9412 20.6474 16.4472 20.8944C13.6476 22.2942 10.3523 22.2942 7.55276 20.8944C7.05878 20.6474 6.85856 20.0467 7.10555 19.5528Z" fill="black"/>
+<path id="Layer02" fill-rule="evenodd" clip-rule="evenodd" d="M13 5C13 5.55228 12.5523 6 12 6C11.4477 6 11 5.55228 11 5C11 4.44772 11.4477 4 12 4C12.5523 4 13 4.44772 13 5ZM15 5C15 6.65685 13.6569 8 12 8C10.3431 8 9 6.65685 9 5C9 3.34315 10.3431 2 12 2C13.6569 2 15 3.34315 15 5ZM5 17C5.55228 17 6 16.5523 6 16C6 15.4477 5.55228 15 5 15C4.44772 15 4 15.4477 4 16C4 16.5523 4.44772 17 5 17ZM5 19C6.65685 19 8 17.6569 8 16C8 14.3431 6.65685 13 5 13C3.34315 13 2 14.3431 2 16C2 17.6569 3.34315 19 5 19ZM19 17C19.5523 17 20 16.5523 20 16C20 15.4477 19.5523 15 19 15C18.4477 15 18 15.4477 18 16C18 16.5523 18.4477 17 19 17ZM19 19C20.6569 19 22 17.6569 22 16C22 14.3431 20.6569 13 19 13C17.3431 13 16 14.3431 16 16C16 17.6569 17.3431 19 19 19Z" fill="black"/>
+</svg>
diff --git a/examples/dbus/remotecontrolledcar/controller/connecting.svg b/examples/dbus/remotecontrolledcar/controller/connecting.svg
new file mode 100644
index 0000000000..4097d0b276
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/connecting.svg
@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path id="Layer01" d="M14 12C14 13.1046 13.1046 14 12 14C10.8954 14 10 13.1046 10 12C10 10.8954 10.8954 10 12 10C13.1046 10 14 10.8954 14 12Z" fill="#0D0D0D"/>
+<path id="Layer02" fill-rule="evenodd" clip-rule="evenodd" d="M3 12C3 14.2728 3.94193 16.5032 5.71196 18.2978C6.09978 18.691 6.09543 19.3241 5.70223 19.712C5.30902 20.0998 4.67587 20.0954 4.28805 19.7022C2.18112 17.5661 1 14.8427 1 12C1 9.15729 2.18112 6.43389 4.28805 4.29777C4.67587 3.90457 5.30902 3.90022 5.70223 4.28804C6.09543 4.67587 6.09978 5.30902 5.71195 5.70223C3.94193 7.49678 3 9.72715 3 12ZM8.80201 14.404C8.27734 13.6971 7.99902 12.8569 7.99902 12C7.99902 11.1431 8.27734 10.3029 8.80201 9.596C9.13117 9.15252 9.0385 8.52617 8.59502 8.19701C8.15154 7.86785 7.5252 7.96052 7.19604 8.404C6.41969 9.44998 5.99902 10.7067 5.99902 12C5.99902 13.2933 6.41969 14.55 7.19604 15.596C7.5252 16.0395 8.15154 16.1321 8.59502 15.803C9.0385 15.4738 9.13117 14.8475 8.80201 14.404ZM15.197 14.404C15.7217 13.6971 16 12.8569 16 12C16 11.1431 15.7217 10.3029 15.197 9.596C14.8679 9.15252 14.9605 8.52617 15.404 8.19701C15.8475 7.86785 16.4738 7.96052 16.803 8.404C17.5793 9.44998 18 10.7067 18 12C18 13.2933 17.5793 14.55 16.803 15.596C16.4738 16.0395 15.8475 16.1321 15.404 15.803C14.9605 15.4738 14.8679 14.8475 15.197 14.404ZM18.2871 18.2978C20.0571 16.5032 20.999 14.2728 20.999 12C20.999 9.72715 20.0571 7.49678 18.2871 5.70223C17.8992 5.30902 17.9036 4.67587 18.2968 4.28804C18.69 3.90022 19.3232 3.90457 19.711 4.29777C21.8179 6.43389 22.999 9.15729 22.999 12C22.999 14.8427 21.8179 17.5661 19.711 19.7022C19.3231 20.0954 18.69 20.0998 18.2968 19.712C17.9036 19.3241 17.8992 18.691 18.2871 18.2978Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.cpp b/examples/dbus/remotecontrolledcar/controller/controller.cpp
index f5f0fa8866..ccff2b1743 100644
--- a/examples/dbus/remotecontrolledcar/controller/controller.cpp
+++ b/examples/dbus/remotecontrolledcar/controller/controller.cpp
@@ -2,18 +2,47 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "controller.h"
+#include <QGridLayout>
+#include <QHBoxLayout>
using org::example::Examples::CarInterface;
Controller::Controller(QWidget *parent) : QWidget(parent)
{
- ui.setupUi(this);
car = new CarInterface("org.example.CarExample", "/Car", QDBusConnection::sessionBus(), this);
- connect(ui.accelerate, &QPushButton::clicked, car, &CarInterface::accelerate);
- connect(ui.decelerate, &QPushButton::clicked, car, &CarInterface::decelerate);
- connect(ui.left, &QPushButton::clicked, car, &CarInterface::turnLeft);
- connect(ui.right, &QPushButton::clicked, car, &CarInterface::turnRight);
+ accelerate = new QPushButton(QIcon(":up.svg"), "", this);
+ accelerate->setFixedSize(80, 64);
+ accelerate->setIconSize(QSize(44, 44));
+ decelerate = new QPushButton(QIcon(":down.svg"), "", this);
+ decelerate->setFixedSize(80, 64);
+ decelerate->setIconSize(QSize(44, 44));
+ left = new QPushButton(QIcon(":left.svg"), "", this);
+ left->setFixedSize(64, 80);
+ left->setIconSize(QSize(44, 44));
+ right = new QPushButton(QIcon(":right.svg"), "", this);
+ right->setFixedSize(64, 80);
+ right->setIconSize(QSize(44, 44));
+
+ status = new QLabel(this);
+ statusSymbol = new QLabel(this);
+ statusSymbol->setFixedHeight(24);
+
+ QGridLayout *layout = new QGridLayout(this);
+ layout->addWidget(accelerate, 1, 1);
+ layout->addWidget(left, 2, 0);
+ layout->addWidget(right, 2, 2);
+ layout->addWidget(decelerate, 3, 1);
+
+ QHBoxLayout *statusLayout = new QHBoxLayout();
+ statusLayout->addWidget(status);
+ statusLayout->addWidget(statusSymbol);
+ layout->addLayout(statusLayout, 0, 1, 1, 2, Qt::AlignTop | Qt::AlignRight);
+
+ connect(accelerate, &QPushButton::clicked, car, &CarInterface::accelerate);
+ connect(decelerate, &QPushButton::clicked, car, &CarInterface::decelerate);
+ connect(left, &QPushButton::clicked, car, &CarInterface::turnLeft);
+ connect(right, &QPushButton::clicked, car, &CarInterface::turnRight);
startTimer(1000);
}
@@ -21,5 +50,9 @@ Controller::Controller(QWidget *parent) : QWidget(parent)
void Controller::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
- ui.label->setText(car->isValid() ? tr("connected") : tr("disconnected"));
+
+ static QPixmap connectedIcon = QPixmap::fromImage(QImage(":connected.svg"));
+ static QPixmap connectingIcon = QPixmap::fromImage(QImage(":connecting.svg"));
+ status->setText(car->isValid() ? tr("connected") : tr("searching..."));
+ statusSymbol->setPixmap(car->isValid() ? connectedIcon : connectingIcon);
}
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.h b/examples/dbus/remotecontrolledcar/controller/controller.h
index 4fd1833330..8df4ed2d1e 100644
--- a/examples/dbus/remotecontrolledcar/controller/controller.h
+++ b/examples/dbus/remotecontrolledcar/controller/controller.h
@@ -4,7 +4,10 @@
#ifndef CONTROLLER_H
#define CONTROLLER_H
-#include "ui_controller.h"
+#include <QWidget>
+#include <QPushButton>
+#include <QLabel>
+
#include "car_interface.h"
class Controller : public QWidget
@@ -18,8 +21,13 @@ protected:
void timerEvent(QTimerEvent *event) override;
private:
- Ui::Controller ui;
org::example::Examples::CarInterface *car;
+ QPushButton *accelerate;
+ QPushButton *decelerate;
+ QPushButton *left;
+ QPushButton *right;
+ QLabel *statusSymbol;
+ QLabel *status;
};
#endif
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.pro b/examples/dbus/remotecontrolledcar/controller/controller.pro
index eddcbdefdf..ce16f21f36 100644
--- a/examples/dbus/remotecontrolledcar/controller/controller.pro
+++ b/examples/dbus/remotecontrolledcar/controller/controller.pro
@@ -1,9 +1,9 @@
QT += dbus widgets
DBUS_INTERFACES += ../common/car.xml
-FORMS += controller.ui
HEADERS += controller.h
SOURCES += main.cpp controller.cpp
+RESOURCES += icons.qrc
# Work-around CI issue. Not needed in user code.
CONFIG += no_batch
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.ui b/examples/dbus/remotecontrolledcar/controller/controller.ui
deleted file mode 100644
index 379015bf30..0000000000
--- a/examples/dbus/remotecontrolledcar/controller/controller.ui
+++ /dev/null
@@ -1,64 +0,0 @@
-<ui version="4.0" >
- <class>Controller</class>
- <widget class="QWidget" name="Controller" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>255</width>
- <height>111</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>Controller</string>
- </property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="1" column="1" >
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>Controller</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item row="2" column="1" >
- <widget class="QPushButton" name="decelerate" >
- <property name="text" >
- <string>Decelerate</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1" >
- <widget class="QPushButton" name="accelerate" >
- <property name="text" >
- <string>Accelerate</string>
- </property>
- </widget>
- </item>
- <item row="1" column="2" >
- <widget class="QPushButton" name="right" >
- <property name="text" >
- <string>Right</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QPushButton" name="left" >
- <property name="text" >
- <string>Left</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/dbus/remotecontrolledcar/controller/down.svg b/examples/dbus/remotecontrolledcar/controller/down.svg
new file mode 100644
index 0000000000..f9a417b65e
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/down.svg
@@ -0,0 +1,3 @@
+<svg width="55" height="55" viewBox="0 0 55 55" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M49.7455 16.7129C48.8505 15.8179 47.3995 15.8179 46.5046 16.7129L27.5 35.7174L8.49547 16.7129C7.60052 15.8179 6.14952 15.8179 5.25456 16.7129C4.35961 17.6078 4.35961 19.0588 5.25456 19.9538L25.8796 40.5788C26.7745 41.4737 28.2255 41.4737 29.1205 40.5788L49.7455 19.9538C50.6404 19.0588 50.6404 17.6078 49.7455 16.7129Z" fill="black"/>
+</svg>
diff --git a/examples/dbus/remotecontrolledcar/controller/icons.qrc b/examples/dbus/remotecontrolledcar/controller/icons.qrc
new file mode 100644
index 0000000000..0aad87cf32
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/icons.qrc
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource prefix="/">
+ <file>connected.svg</file>
+ <file>connecting.svg</file>
+ <file>down.svg</file>
+ <file>left.svg</file>
+ <file>right.svg</file>
+ <file>up.svg</file>
+ </qresource>
+</RCC>
diff --git a/examples/dbus/remotecontrolledcar/controller/left.svg b/examples/dbus/remotecontrolledcar/controller/left.svg
new file mode 100644
index 0000000000..12d6420f48
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/left.svg
@@ -0,0 +1,3 @@
+<svg width="55" height="55" viewBox="0 0 55 55" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M38.2871 5.25453C39.1821 6.14948 39.1821 7.60048 38.2871 8.49543L19.2826 27.5L38.2871 46.5045C39.1821 47.3995 39.1821 48.8505 38.2871 49.7454C37.3922 50.6404 35.9412 50.6404 35.0462 49.7454L14.4212 29.1204C13.5263 28.2255 13.5263 26.7745 14.4212 25.8795L35.0462 5.25453C35.9412 4.35958 37.3922 4.35958 38.2871 5.25453Z" fill="black"/>
+</svg>
diff --git a/examples/dbus/remotecontrolledcar/controller/right.svg b/examples/dbus/remotecontrolledcar/controller/right.svg
new file mode 100644
index 0000000000..26a39a74ca
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/right.svg
@@ -0,0 +1,3 @@
+<svg width="55" height="55" viewBox="0 0 55 55" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M16.7129 5.25453C15.8179 6.14948 15.8179 7.60048 16.7129 8.49543L35.7174 27.5L16.7129 46.5045C15.8179 47.3995 15.8179 48.8505 16.7129 49.7454C17.6078 50.6404 19.0588 50.6404 19.9538 49.7454L40.5788 29.1204C41.4737 28.2255 41.4737 26.7745 40.5788 25.8795L19.9538 5.25453C19.0588 4.35958 17.6078 4.35958 16.7129 5.25453Z" fill="black"/>
+</svg>
diff --git a/examples/dbus/remotecontrolledcar/controller/up.svg b/examples/dbus/remotecontrolledcar/controller/up.svg
new file mode 100644
index 0000000000..ea5f1bfcfb
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/up.svg
@@ -0,0 +1,3 @@
+<svg width="55" height="55" viewBox="0 0 55 55" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M49.7455 38.2871C48.8505 39.1821 47.3995 39.1821 46.5046 38.2871L27.5 19.2826L8.49547 38.2871C7.60052 39.1821 6.14952 39.1821 5.25456 38.2871C4.35961 37.3922 4.35961 35.9412 5.25456 35.0462L25.8796 14.4212C26.7745 13.5263 28.2255 13.5263 29.1205 14.4212L49.7455 35.0462C50.6404 35.9412 50.6404 37.3922 49.7455 38.2871Z" fill="black"/>
+</svg>
diff --git a/examples/dbus/remotecontrolledcar/doc/images/remotecontrolledcar-car-example.webp b/examples/dbus/remotecontrolledcar/doc/images/remotecontrolledcar-car-example.webp
index cc2f1de3dc..958b466e9f 100644
--- a/examples/dbus/remotecontrolledcar/doc/images/remotecontrolledcar-car-example.webp
+++ b/examples/dbus/remotecontrolledcar/doc/images/remotecontrolledcar-car-example.webp
Binary files differ
diff --git a/examples/dbus/remotecontrolledcar/doc/src/dbus-remotecontrolledcar.qdoc b/examples/dbus/remotecontrolledcar/doc/src/dbus-remotecontrolledcar.qdoc
index a9c04e821a..94c914b642 100644
--- a/examples/dbus/remotecontrolledcar/doc/src/dbus-remotecontrolledcar.qdoc
+++ b/examples/dbus/remotecontrolledcar/doc/src/dbus-remotecontrolledcar.qdoc
@@ -4,6 +4,7 @@
/*!
\example remotecontrolledcar
\title D-Bus Remote Controlled Car
+ \examplecategory {Connectivity}
\ingroup examples-dbus
\brief Shows how to use Qt D-Bus to control a car from another application.
diff --git a/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro b/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro
index 2a1fddb500..dd275b1099 100644
--- a/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro
+++ b/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = car \
- controller
+ controller
diff --git a/examples/embedded/CMakeLists.txt b/examples/embedded/CMakeLists.txt
deleted file mode 100644
index 1eb8bc7537..0000000000
--- a/examples/embedded/CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-if(NOT TARGET Qt6::Gui OR (NOT embedded AND NOT x11))
- return()
-endif()
-qt_internal_add_example(styleexample)
-qt_internal_add_example(raycasting)
-qt_internal_add_example(flickable)
-qt_internal_add_example(digiflip)
-qt_internal_add_example(lightmaps)
-qt_internal_add_example(flightinfo)
diff --git a/examples/embedded/digiflip/CMakeLists.txt b/examples/embedded/digiflip/CMakeLists.txt
deleted file mode 100644
index 9678c74772..0000000000
--- a/examples/embedded/digiflip/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(digiflip LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/embedded/digiflip")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(digiflip
- digiflip.cpp
-)
-
-set_target_properties(digiflip PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(digiflip PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS digiflip
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/embedded/digiflip/digiflip.cpp b/examples/embedded/digiflip/digiflip.cpp
deleted file mode 100644
index ab5075a4ec..0000000000
--- a/examples/embedded/digiflip/digiflip.cpp
+++ /dev/null
@@ -1,372 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore>
-#include <QtWidgets>
-
-class Digits: public QWidget
-{
- Q_OBJECT
-
-public:
-
- enum {
- Slide,
- Flip,
- Rotate
- };
-
- Digits(QWidget *parent)
- : QWidget(parent)
- , m_number(0)
- , m_transition(Slide)
- {
- setAttribute(Qt::WA_OpaquePaintEvent, true);
- setAttribute(Qt::WA_NoSystemBackground, true);
- connect(&m_animator, &QTimeLine::frameChanged,
- this, qOverload<>(&Digits::update));
- m_animator.setFrameRange(0, 100);
- m_animator.setDuration(600);
- m_animator.setEasingCurve(QEasingCurve::InOutSine);
- }
-
- void setTransition(int tr) {
- m_transition = tr;
- }
-
- int transition() const {
- return m_transition;
- }
-
- void setNumber(int n) {
- if (m_number != n) {
- m_number = qBound(0, n, 99);
- preparePixmap();
- update();
- }
- }
-
- void flipTo(int n) {
- if (m_number != n) {
- m_number = qBound(0, n, 99);
- m_lastPixmap = m_pixmap;
- preparePixmap();
- m_animator.stop();
- m_animator.start();
- }
- }
-
-protected:
-
- void drawFrame(QPainter *p, const QRect &rect) {
- p->setPen(Qt::NoPen);
- QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
- gradient.setColorAt(0.00, QColor(245, 245, 245));
- gradient.setColorAt(0.49, QColor(192, 192, 192));
- gradient.setColorAt(0.51, QColor(245, 245, 245));
- gradient.setColorAt(1.00, QColor(192, 192, 192));
- p->setBrush(gradient);
- QRect r = rect;
- p->drawRoundedRect(r, 15, 15, Qt::RelativeSize);
- r.adjust(1, 4, -1, -4);
- p->setPen(QColor(181, 181, 181));
- p->setBrush(Qt::NoBrush);
- p->drawRoundedRect(r, 15, 15, Qt::RelativeSize);
- p->setPen(QColor(159, 159, 159));
- int y = rect.top() + rect.height() / 2 - 1;
- p->drawLine(rect.left(), y, rect.right(), y);
- }
-
- QPixmap drawDigits(int n, const QRect &rect) {
-
- int scaleFactor = 2;
-
- QString str = QString::number(n);
- if (str.length() == 1)
- str.prepend('0');
-
- QFont font;
- font.setFamily("Helvetica");
- int fontHeight = scaleFactor * 0.55 * rect.height();
- font.setPixelSize(fontHeight);
- font.setBold(true);
-
- QPixmap pixmap(rect.size() * scaleFactor);
- pixmap.fill(Qt::transparent);
-
- QLinearGradient gradient(QPoint(0, 0), QPoint(0, pixmap.height()));
- gradient.setColorAt(0.00, QColor(128, 128, 128));
- gradient.setColorAt(0.49, QColor(64, 64, 64));
- gradient.setColorAt(0.51, QColor(128, 128, 128));
- gradient.setColorAt(1.00, QColor(16, 16, 16));
-
- QPainter p;
- p.begin(&pixmap);
- p.setFont(font);
- QPen pen;
- pen.setBrush(QBrush(gradient));
- p.setPen(pen);
- p.drawText(pixmap.rect(), Qt::AlignCenter, str);
- p.end();
-
- return pixmap.scaledToWidth(width(), Qt::SmoothTransformation);
- }
-
- void preparePixmap() {
- m_pixmap = QPixmap(size());
- m_pixmap.fill(Qt::transparent);
- QPainter p;
- p.begin(&m_pixmap);
- p.drawPixmap(0, 0, drawDigits(m_number, rect()));
- p.end();
- }
-
- void resizeEvent(QResizeEvent*) {
- preparePixmap();
- update();
- }
-
- void paintStatic() {
- QPainter p(this);
- p.fillRect(rect(), Qt::black);
-
- int pad = width() / 10;
- drawFrame(&p, rect().adjusted(pad, pad, -pad, -pad));
- p.drawPixmap(0, 0, m_pixmap);
- }
-
- void paintSlide() {
- QPainter p(this);
- p.fillRect(rect(), Qt::black);
-
- int pad = width() / 10;
- QRect fr = rect().adjusted(pad, pad, -pad, -pad);
- drawFrame(&p, fr);
- p.setClipRect(fr);
-
- int y = height() * m_animator.currentFrame() / 100;
- p.drawPixmap(0, y, m_lastPixmap);
- p.drawPixmap(0, y - height(), m_pixmap);
- }
-
- void paintFlip() {
- QPainter p(this);
- p.setRenderHint(QPainter::SmoothPixmapTransform, true);
- p.setRenderHint(QPainter::Antialiasing, true);
- p.fillRect(rect(), Qt::black);
-
- int hw = width() / 2;
- int hh = height() / 2;
-
- // behind is the new pixmap
- int pad = width() / 10;
- QRect fr = rect().adjusted(pad, pad, -pad, -pad);
- drawFrame(&p, fr);
- p.drawPixmap(0, 0, m_pixmap);
-
- int index = m_animator.currentFrame();
-
- if (index <= 50) {
-
- // the top part of the old pixmap is flipping
- int angle = -180 * index / 100;
- QTransform transform;
- transform.translate(hw, hh);
- transform.rotate(angle, Qt::XAxis);
- p.setTransform(transform);
- drawFrame(&p, fr.adjusted(-hw, -hh, -hw, -hh));
- p.drawPixmap(-hw, -hh, m_lastPixmap);
-
- // the bottom part is still the old pixmap
- p.resetTransform();
- p.setClipRect(0, hh, width(), hh);
- drawFrame(&p, fr);
- p.drawPixmap(0, 0, m_lastPixmap);
- } else {
-
- p.setClipRect(0, hh, width(), hh);
-
- // the bottom part is still the old pixmap
- drawFrame(&p, fr);
- p.drawPixmap(0, 0, m_lastPixmap);
-
- // the bottom part of the new pixmap is flipping
- int angle = 180 - 180 * m_animator.currentFrame() / 100;
- QTransform transform;
- transform.translate(hw, hh);
- transform.rotate(angle, Qt::XAxis);
- p.setTransform(transform);
- drawFrame(&p, fr.adjusted(-hw, -hh, -hw, -hh));
- p.drawPixmap(-hw, -hh, m_pixmap);
-
- }
-
- }
-
- void paintRotate() {
- QPainter p(this);
-
- int pad = width() / 10;
- QRect fr = rect().adjusted(pad, pad, -pad, -pad);
- drawFrame(&p, fr);
- p.setClipRect(fr);
-
- int angle1 = -180 * m_animator.currentFrame() / 100;
- int angle2 = 180 - 180 * m_animator.currentFrame() / 100;
- int angle = (m_animator.currentFrame() <= 50) ? angle1 : angle2;
- QPixmap pix = (m_animator.currentFrame() <= 50) ? m_lastPixmap : m_pixmap;
-
- QTransform transform;
- transform.translate(width() / 2, height() / 2);
- transform.rotate(angle, Qt::XAxis);
-
- p.setTransform(transform);
- p.setRenderHint(QPainter::SmoothPixmapTransform, true);
- p.drawPixmap(-width() / 2, -height() / 2, pix);
- }
-
- void paintEvent(QPaintEvent *event) {
- Q_UNUSED(event);
- if (m_animator.state() == QTimeLine::Running) {
- if (m_transition == Slide)
- paintSlide();
- if (m_transition == Flip)
- paintFlip();
- if (m_transition == Rotate)
- paintRotate();
- } else {
- paintStatic();
- }
- }
-
-private:
- int m_number;
- int m_transition;
- QPixmap m_pixmap;
- QPixmap m_lastPixmap;
- QTimeLine m_animator;
-};
-
-class DigiFlip : public QMainWindow
-{
- Q_OBJECT
-
-public:
- DigiFlip(QWidget *parent = nullptr)
- : QMainWindow(parent)
- {
- m_hour = new Digits(this);
- m_hour->show();
- m_minute = new Digits(this);
- m_minute->show();
-
- QPalette pal = palette();
- pal.setColor(QPalette::Window, Qt::black);
- setPalette(pal);
-
- m_ticker.start(1000, this);
- QTime t = QTime::currentTime();
- m_hour->setNumber(t.hour());
- m_minute->setNumber(t.minute());
- updateTime();
-
- QAction *slideAction = new QAction("&Slide", this);
- QAction *flipAction = new QAction("&Flip", this);
- QAction *rotateAction = new QAction("&Rotate", this);
- connect(slideAction, &QAction::triggered, this, &DigiFlip::chooseSlide);
- connect(flipAction, &QAction::triggered, this, &DigiFlip::chooseFlip);
- connect(rotateAction, &QAction::triggered, this, &DigiFlip::chooseRotate);
- addAction(slideAction);
- addAction(flipAction);
- addAction(rotateAction);
- setContextMenuPolicy(Qt::ActionsContextMenu);
- }
-
- void updateTime() {
- QTime t = QTime::currentTime();
- m_hour->flipTo(t.hour());
- m_minute->flipTo(t.minute());
- QString str = t.toString("hh:mm:ss");
- str.prepend(": ");
- if (m_hour->transition() == Digits::Slide)
- str.prepend("Slide");
- if (m_hour->transition() == Digits::Flip)
- str.prepend("Flip");
- if (m_hour->transition() == Digits::Rotate)
- str.prepend("Rotate");
- setWindowTitle(str);
- }
-
- void switchTransition(int delta) {
- int i = (m_hour->transition() + delta + 3) % 3;
- m_hour->setTransition(i);
- m_minute->setTransition(i);
- updateTime();
- }
-
-protected:
- void resizeEvent(QResizeEvent*) {
- int digitsWidth = width() / 2;
- int digitsHeight = digitsWidth * 1.2;
-
- int y = (height() - digitsHeight) / 3;
-
- m_hour->resize(digitsWidth, digitsHeight);
- m_hour->move(0, y);
-
- m_minute->resize(digitsWidth, digitsHeight);
- m_minute->move(width() / 2, y);
- }
-
- void timerEvent(QTimerEvent*) {
- updateTime();
- }
-
- void keyPressEvent(QKeyEvent *event) {
- if (event->key() == Qt::Key_Right) {
- switchTransition(1);
- event->accept();
- }
- if (event->key() == Qt::Key_Left) {
- switchTransition(-1);
- event->accept();
- }
- }
-
-private slots:
- void chooseSlide() {
- m_hour->setTransition(0);
- m_minute->setTransition(0);
- updateTime();
- }
-
- void chooseFlip() {
- m_hour->setTransition(1);
- m_minute->setTransition(1);
- updateTime();
- }
-
- void chooseRotate() {
- m_hour->setTransition(2);
- m_minute->setTransition(2);
- updateTime();
- }
-
-private:
- QBasicTimer m_ticker;
- Digits *m_hour;
- Digits *m_minute;
-};
-
-#include "digiflip.moc"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- DigiFlip time;
- time.resize(320, 240);
- time.show();
-
- return app.exec();
-}
diff --git a/examples/embedded/digiflip/digiflip.pro b/examples/embedded/digiflip/digiflip.pro
deleted file mode 100644
index af6c2773c8..0000000000
--- a/examples/embedded/digiflip/digiflip.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-QT += widgets
-
-SOURCES = digiflip.cpp
-
-target.path = $$[QT_INSTALL_EXAMPLES]/embedded/digiflip
-INSTALLS += target
diff --git a/examples/embedded/embedded.pro b/examples/embedded/embedded.pro
deleted file mode 100644
index e772eb88aa..0000000000
--- a/examples/embedded/embedded.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-requires(if(embedded|x11):qtHaveModule(gui))
-
-TEMPLATE = subdirs
-SUBDIRS = styleexample raycasting flickable digiflip
-
-SUBDIRS += lightmaps
-SUBDIRS += flightinfo
diff --git a/examples/embedded/flickable/CMakeLists.txt b/examples/embedded/flickable/CMakeLists.txt
deleted file mode 100644
index 835d4ec77a..0000000000
--- a/examples/embedded/flickable/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(flickable LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/embedded/flickable")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(flickable
- flickable.cpp flickable.h
- main.cpp
-)
-
-set_target_properties(flickable PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(flickable PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS flickable
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/embedded/flickable/flickable.cpp b/examples/embedded/flickable/flickable.cpp
deleted file mode 100644
index 5b19d96193..0000000000
--- a/examples/embedded/flickable/flickable.cpp
+++ /dev/null
@@ -1,246 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "flickable.h"
-
-#include <QtCore>
-#include <QtWidgets>
-
-class FlickableTicker: QObject
-{
-public:
- FlickableTicker(Flickable *scroller) {
- m_scroller = scroller;
- }
-
- void start(int interval) {
- if (!m_timer.isActive())
- m_timer.start(interval, this);
- }
-
- void stop() {
- m_timer.stop();
- }
-
-protected:
- void timerEvent(QTimerEvent *event) {
- Q_UNUSED(event);
- m_scroller->tick();
- }
-
-private:
- Flickable *m_scroller;
- QBasicTimer m_timer;
-};
-
-class FlickablePrivate
-{
-public:
- typedef enum {
- Steady,
- Pressed,
- ManualScroll,
- AutoScroll,
- Stop
- } State;
-
- State state;
- int threshold;
- QPoint pressPos;
- QPoint offset;
- QPoint delta;
- QPoint speed;
- FlickableTicker *ticker;
- QElapsedTimer timeStamp;
- QWidget *target;
- QList<QEvent*> ignoreList;
-};
-
-Flickable::Flickable()
-{
- d = new FlickablePrivate;
- d->state = FlickablePrivate::Steady;
- d->threshold = 10;
- d->ticker = new FlickableTicker(this);
- d->timeStamp.start();
- d->target = 0;
-}
-
-Flickable::~Flickable()
-{
- delete d;
-}
-
-void Flickable::setThreshold(int th)
-{
- if (th >= 0)
- d->threshold = th;
-}
-
-int Flickable::threshold() const
-{
- return d->threshold;
-}
-
-void Flickable::setAcceptMouseClick(QWidget *target)
-{
- d->target = target;
-}
-
-static QPoint deaccelerate(const QPoint &speed, int a = 1, int max = 64)
-{
- int x = qBound(-max, speed.x(), max);
- int y = qBound(-max, speed.y(), max);
- x = (x == 0) ? x : (x > 0) ? qMax(0, x - a) : qMin(0, x + a);
- y = (y == 0) ? y : (y > 0) ? qMax(0, y - a) : qMin(0, y + a);
- return QPoint(x, y);
-}
-
-void Flickable::handleMousePress(QMouseEvent *event)
-{
- event->ignore();
-
- if (event->button() != Qt::LeftButton)
- return;
-
- if (d->ignoreList.removeAll(event))
- return;
-
- switch (d->state) {
-
- case FlickablePrivate::Steady:
- event->accept();
- d->state = FlickablePrivate::Pressed;
- d->pressPos = event->position().toPoint();
- break;
-
- case FlickablePrivate::AutoScroll:
- event->accept();
- d->state = FlickablePrivate::Stop;
- d->speed = QPoint(0, 0);
- d->pressPos = event->position().toPoint();
- d->offset = scrollOffset();
- d->ticker->stop();
- break;
-
- default:
- break;
- }
-}
-
-void Flickable::handleMouseRelease(QMouseEvent *event)
-{
- event->ignore();
-
- if (event->button() != Qt::LeftButton)
- return;
-
- if (d->ignoreList.removeAll(event))
- return;
-
- QPoint delta;
-
- switch (d->state) {
-
- case FlickablePrivate::Pressed:
- event->accept();
- d->state = FlickablePrivate::Steady;
- if (d->target) {
- QMouseEvent *event1 = new QMouseEvent(QEvent::MouseButtonPress,
- d->pressPos, Qt::LeftButton,
- Qt::LeftButton, Qt::NoModifier);
- QMouseEvent *event2 = event->clone();
- d->ignoreList << event1;
- d->ignoreList << event2;
- QApplication::postEvent(d->target, event1);
- QApplication::postEvent(d->target, event2);
- }
- break;
-
- case FlickablePrivate::ManualScroll:
- event->accept();
- delta = event->position().toPoint() - d->pressPos;
- if (d->timeStamp.elapsed() > 100) {
- d->timeStamp.start();
- d->speed = delta - d->delta;
- d->delta = delta;
- }
- d->offset = scrollOffset();
- d->pressPos = event->position().toPoint();
- if (d->speed == QPoint(0, 0)) {
- d->state = FlickablePrivate::Steady;
- } else {
- d->speed /= 4;
- d->state = FlickablePrivate::AutoScroll;
- d->ticker->start(20);
- }
- break;
-
- case FlickablePrivate::Stop:
- event->accept();
- d->state = FlickablePrivate::Steady;
- d->offset = scrollOffset();
- break;
-
- default:
- break;
- }
-}
-
-void Flickable::handleMouseMove(QMouseEvent *event)
-{
- event->ignore();
-
- if (!(event->buttons() & Qt::LeftButton))
- return;
-
- if (d->ignoreList.removeAll(event))
- return;
-
- QPoint delta;
-
- switch (d->state) {
-
- case FlickablePrivate::Pressed:
- case FlickablePrivate::Stop:
- delta = event->position().toPoint() - d->pressPos;
- if (delta.x() > d->threshold || delta.x() < -d->threshold ||
- delta.y() > d->threshold || delta.y() < -d->threshold) {
- d->timeStamp.start();
- d->state = FlickablePrivate::ManualScroll;
- d->delta = QPoint(0, 0);
- d->pressPos = event->position().toPoint();
- event->accept();
- }
- break;
-
- case FlickablePrivate::ManualScroll:
- event->accept();
- delta = event->position().toPoint() - d->pressPos;
- setScrollOffset(d->offset - delta);
- if (d->timeStamp.elapsed() > 100) {
- d->timeStamp.start();
- d->speed = delta - d->delta;
- d->delta = delta;
- }
- break;
-
- default:
- break;
- }
-}
-
-void Flickable::tick()
-{
- if (d->state == FlickablePrivate:: AutoScroll) {
- d->speed = deaccelerate(d->speed);
- setScrollOffset(d->offset - d->speed);
- d->offset = scrollOffset();
- if (d->speed == QPoint(0, 0)) {
- d->state = FlickablePrivate::Steady;
- d->ticker->stop();
- }
- } else {
- d->ticker->stop();
- }
-}
diff --git a/examples/embedded/flickable/flickable.h b/examples/embedded/flickable/flickable.h
deleted file mode 100644
index e34b08d49a..0000000000
--- a/examples/embedded/flickable/flickable.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef FLICKABLE_H
-#define FLICKABLE_H
-
-#include <QWidget>
-
-class FlickableTicker;
-class FlickablePrivate;
-
-class Flickable
-{
-public:
-
- Flickable();
- virtual ~Flickable();
-
- void setThreshold(int threshold);
- int threshold() const;
-
- void setAcceptMouseClick(QWidget *target);
-
- void handleMousePress(QMouseEvent *event);
- void handleMouseMove(QMouseEvent *event);
- void handleMouseRelease(QMouseEvent *event);
-
-protected:
- virtual QPoint scrollOffset() const = 0;
- virtual void setScrollOffset(const QPoint &offset) = 0;
-
-private:
- void tick();
-
-private:
- FlickablePrivate *d;
- friend class FlickableTicker;
-};
-
-#endif // FLICKABLE_H
diff --git a/examples/embedded/flickable/flickable.pro b/examples/embedded/flickable/flickable.pro
deleted file mode 100644
index 5929207414..0000000000
--- a/examples/embedded/flickable/flickable.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-QT += widgets
-
-SOURCES = flickable.cpp main.cpp
-HEADERS = flickable.h
-
-target.path = $$[QT_INSTALL_EXAMPLES]/embedded/flickable
-INSTALLS += target
diff --git a/examples/embedded/flickable/main.cpp b/examples/embedded/flickable/main.cpp
deleted file mode 100644
index ba229c5245..0000000000
--- a/examples/embedded/flickable/main.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore>
-#include <QtWidgets>
-
-#include "flickable.h"
-
-// Returns a list of two-word color names
-static QStringList colorPairs(int max)
-{
- // capitalize the first letter
- QStringList colors = QColor::colorNames();
- colors.removeAll("transparent");
- int num = colors.count();
- for (int c = 0; c < num; ++c)
- colors[c] = colors[c][0].toUpper() + colors[c].mid(1);
-
- // combine two colors, e.g. "lime skyblue"
- QStringList combinedColors;
- for (int i = 0; i < num; ++i)
- for (int j = 0; j < num; ++j)
- combinedColors << QString("%1 %2").arg(colors[i]).arg(colors[j]);
-
- // randomize it
- colors.clear();
- while (combinedColors.count()) {
- int i = QRandomGenerator::global()->bounded(combinedColors.count());
- colors << combinedColors[i];
- combinedColors.removeAt(i);
- if (colors.count() == max)
- break;
- }
-
- return colors;
-}
-
-class ColorList : public QWidget, public Flickable
-{
- Q_OBJECT
-
-public:
- ColorList(QWidget *parent = nullptr)
- : QWidget(parent) {
- m_offset = 0;
- m_height = QFontMetrics(font()).height() + 5;
- m_highlight = -1;
- m_selected = -1;
-
- QStringList colors = colorPairs(999);
- for (int i = 0; i < colors.count(); ++i) {
- const QString c = colors[i];
- const QString str = QString::asprintf("%4d", i + 1);
- m_colorNames << (str + " " + c);
-
- QStringList duet = c.split(' ');
- m_firstColor << QColor::fromString(duet[0]);
- m_secondColor << QColor::fromString(duet[1]);
- }
-
- setAttribute(Qt::WA_OpaquePaintEvent, true);
- setAttribute(Qt::WA_NoSystemBackground, true);
-
- setMouseTracking(true);
- Flickable::setAcceptMouseClick(this);
- }
-
-protected:
- // reimplement from Flickable
- virtual QPoint scrollOffset() const {
- return QPoint(0, m_offset);
- }
-
- // reimplement from Flickable
- virtual void setScrollOffset(const QPoint &offset) {
- int yy = offset.y();
- if (yy != m_offset) {
- m_offset = qBound(0, yy, m_height * m_colorNames.count() - height());
- update();
- }
- }
-
-protected:
- void paintEvent(QPaintEvent *event) {
- QPainter p(this);
- p.fillRect(event->rect(), Qt::white);
- int start = m_offset / m_height;
- int y = start * m_height - m_offset;
- if (m_offset <= 0) {
- start = 0;
- y = -m_offset;
- }
- int end = start + height() / m_height + 1;
- if (end > m_colorNames.count() - 1)
- end = m_colorNames.count() - 1;
- for (int i = start; i <= end; ++i, y += m_height) {
-
- p.setBrush(Qt::NoBrush);
- p.setPen(Qt::black);
- if (i == m_highlight) {
- p.fillRect(0, y, width(), m_height, QColor(0, 64, 128));
- p.setPen(Qt::white);
- }
- if (i == m_selected) {
- p.fillRect(0, y, width(), m_height, QColor(0, 128, 240));
- p.setPen(Qt::white);
- }
-
- p.drawText(m_height + 2, y, width(), m_height, Qt::AlignVCenter, m_colorNames[i]);
-
- p.setPen(Qt::NoPen);
- p.setBrush(m_firstColor[i]);
- p.drawRect(1, y + 1, m_height - 2, m_height - 2);
- p.setBrush(m_secondColor[i]);
- p.drawRect(5, y + 5, m_height - 11, m_height - 11);
- }
- p.end();
- }
-
- void keyReleaseEvent(QKeyEvent *event) {
- if (event->key() == Qt::Key_Down) {
- m_offset += 20;
- event->accept();
- update();
- return;
- }
- if (event->key() == Qt::Key_Up) {
- m_offset -= 20;
- event->accept();
- update();
- return;
- }
- }
-
- void mousePressEvent(QMouseEvent *event) {
- Flickable::handleMousePress(event);
- if (event->isAccepted())
- return;
-
- if (event->button() == Qt::LeftButton) {
- int y = event->position().toPoint().y() + m_offset;
- int i = y / m_height;
- if (i != m_highlight) {
- m_highlight = i;
- m_selected = -1;
- update();
- }
- event->accept();
- }
- }
-
- void mouseMoveEvent(QMouseEvent *event) {
- Flickable::handleMouseMove(event);
- }
-
- void mouseReleaseEvent(QMouseEvent *event) {
- Flickable::handleMouseRelease(event);
- if (event->isAccepted())
- return;
-
- if (event->button() == Qt::LeftButton) {
- m_selected = m_highlight;
- event->accept();
- update();
- }
- }
-
-private:
- int m_offset;
- int m_height;
- int m_highlight;
- int m_selected;
- QStringList m_colorNames;
- QList<QColor> m_firstColor;
- QList<QColor> m_secondColor;
-};
-
-#include "main.moc"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- ColorList list;
- list.setWindowTitle("Kinetic Scrolling");
- list.resize(320, 320);
- list.show();
-
- return app.exec();
-}
diff --git a/examples/embedded/flightinfo/CMakeLists.txt b/examples/embedded/flightinfo/CMakeLists.txt
deleted file mode 100644
index 8e31aedd49..0000000000
--- a/examples/embedded/flightinfo/CMakeLists.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(flightinfo LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/embedded/flightinfo")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(flightinfo
- flightinfo.cpp
- form.ui
-)
-
-set_target_properties(flightinfo PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(flightinfo PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Network
- Qt6::Widgets
-)
-
-# Resources:
-set(flightinfo_resource_files
- "aircraft.png"
-)
-
-qt_add_resources(flightinfo "flightinfo"
- PREFIX
- "/"
- FILES
- ${flightinfo_resource_files}
-)
-
-install(TARGETS flightinfo
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/embedded/flightinfo/aircraft.png b/examples/embedded/flightinfo/aircraft.png
deleted file mode 100644
index 2312bcc9f0..0000000000
--- a/examples/embedded/flightinfo/aircraft.png
+++ /dev/null
Binary files differ
diff --git a/examples/embedded/flightinfo/flightinfo.cpp b/examples/embedded/flightinfo/flightinfo.cpp
deleted file mode 100644
index 6a5eb55d99..0000000000
--- a/examples/embedded/flightinfo/flightinfo.cpp
+++ /dev/null
@@ -1,354 +0,0 @@
-// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore>
-#include <QtWidgets>
-#include <QtNetwork>
-
-#include "ui_form.h"
-
-#define FLIGHTVIEW_URL "http://mobile.flightview.com/TrackByFlight.aspx"
-#define FLIGHTVIEW_RANDOM "http://mobile.flightview.com/TrackSampleFlight.aspx"
-
-// strips all invalid constructs that might trip QXmlStreamReader
-static QString sanitized(const QString &xml)
-{
- QString data = xml;
-
- // anything up to the html tag
- int i = data.indexOf("<html");
- if (i > 0)
- data.remove(0, i - 1);
-
- // everything inside the head tag
- i = data.indexOf("<head");
- if (i > 0)
- data.remove(i, data.indexOf("</head>") - i + 7);
-
- // invalid link for JavaScript code
- while (true) {
- i = data.indexOf("onclick=\"gotoUrl(");
- if (i < 0)
- break;
- data.remove(i, data.indexOf('\"', i + 9) - i + 1);
- }
-
- // all inline frames
- while (true) {
- i = data.indexOf("<iframe");
- if (i < 0)
- break;
- data.remove(i, data.indexOf("</iframe>") - i + 8);
- }
-
- // entities
- data.remove("&nbsp;");
- data.remove("&copy;");
-
- return data;
-}
-
-class FlightInfo : public QMainWindow
-{
- Q_OBJECT
-
-private:
-
- Ui_Form ui;
- QUrl m_url;
- QDate m_searchDate;
- QPixmap m_map;
- QNetworkAccessManager m_manager;
- QList<QNetworkReply *> mapReplies;
-
-public:
-
- FlightInfo(QMainWindow *parent = nullptr): QMainWindow(parent) {
-
- QWidget *w = new QWidget(this);
- ui.setupUi(w);
- setCentralWidget(w);
-
- ui.searchBar->hide();
- ui.infoBox->hide();
- connect(ui.searchButton, &QPushButton::clicked, this, &FlightInfo::startSearch);
- connect(ui.flightEdit, &QLineEdit::returnPressed, this, &FlightInfo::startSearch);
-
- setWindowTitle("Flight Info");
-
- // Rendered from the public-domain vectorized aircraft
- // http://openclipart.org/media/people/Jarno
- m_map = QPixmap(":/aircraft.png");
-
- QAction *searchTodayAction = new QAction("Today's Flight", this);
- QAction *searchYesterdayAction = new QAction("Yesterday's Flight", this);
- QAction *randomAction = new QAction("Random Flight", this);
- connect(searchTodayAction, &QAction::triggered, this, &FlightInfo::today);
- connect(searchYesterdayAction, &QAction::triggered, this, &FlightInfo::yesterday);
- connect(randomAction, &QAction::triggered, this, &FlightInfo::randomFlight);
- connect(&m_manager, &QNetworkAccessManager::finished,
- this, &FlightInfo::handleNetworkData);
- addAction(searchTodayAction);
- addAction(searchYesterdayAction);
- addAction(randomAction);
- setContextMenuPolicy(Qt::ActionsContextMenu);
- }
-
-private slots:
-
- void handleNetworkData(QNetworkReply *networkReply) {
- if (!networkReply->error()) {
- if (!mapReplies.contains(networkReply)) {
- // Assume UTF-8 encoded
- QByteArray data = networkReply->readAll();
- QString xml = QString::fromUtf8(data);
- digest(xml);
- } else {
- mapReplies.removeOne(networkReply);
- m_map.loadFromData(networkReply->readAll());
- update();
- }
- }
- networkReply->deleteLater();
- }
-
- void today() {
- QDateTime timestamp = QDateTime::currentDateTime();
- m_searchDate = timestamp.date();
- searchFlight();
- }
-
- void yesterday() {
- QDateTime timestamp = QDateTime::currentDateTime();
- timestamp = timestamp.addDays(-1);
- m_searchDate = timestamp.date();
- searchFlight();
- }
-
- void searchFlight() {
- ui.searchBar->show();
- ui.infoBox->hide();
- ui.flightStatus->hide();
- ui.flightName->setText("Enter flight number");
- ui.flightEdit->setFocus();
-#ifdef QT_KEYPAD_NAVIGATION
- ui.flightEdit->setEditFocus(true);
-#endif
- m_map = QPixmap();
- update();
- }
-
- void startSearch() {
- ui.searchBar->hide();
- QString flight = ui.flightEdit->text().simplified();
- if (!flight.isEmpty())
- request(flight, m_searchDate);
- }
-
- void randomFlight() {
- request(QString(), QDate::currentDate());
- }
-
-public slots:
-
- void request(const QString &flightCode, QDate date) {
-
- setWindowTitle("Loading...");
-
- QString code = flightCode.simplified();
- QString airlineCode = code.left(2).toUpper();
- QString flightNumber = code.mid(2, code.length());
-
- ui.flightName->setText("Searching for " + code);
-
- QUrlQuery query;
- query.addQueryItem("view", "detail");
- query.addQueryItem("al", airlineCode);
- query.addQueryItem("fn", flightNumber);
- query.addQueryItem("dpdat", date.toString("yyyyMMdd"));
- m_url = QUrl(FLIGHTVIEW_URL);
- m_url.setQuery(query);
-
- if (code.isEmpty()) {
- // random flight as sample
- m_url = QUrl(FLIGHTVIEW_RANDOM);
- ui.flightName->setText("Getting a random flight...");
- }
-
- m_manager.get(QNetworkRequest(m_url));
- }
-
-
-private:
-
- void digest(const QString &content) {
-
- setWindowTitle("Flight Info");
- QString data = sanitized(content);
-
- // do we only get the flight list?
- // we grab the first leg in the flight list
- // then fetch another URL for the real flight info
- int i = data.indexOf("a href=\"?view=detail");
- if (i > 0) {
- QString href = data.mid(i, data.indexOf('\"', i + 8) - i + 1);
- QRegularExpression regex("dpap=([A-Za-z0-9]+)");
- QRegularExpressionMatch match = regex.match(href);
- QString airport = match.captured(1);
- QUrlQuery query(m_url);
- query.addQueryItem("dpap", airport);
- m_url.setQuery(query);
- m_manager.get(QNetworkRequest(m_url));
- return;
- }
-
- QXmlStreamReader xml(data);
- bool inFlightName = false;
- bool inFlightStatus = false;
- bool inFlightMap = false;
- bool inFieldName = false;
- bool inFieldValue = false;
-
- QString flightName;
- QString flightStatus;
- QStringList fieldNames;
- QStringList fieldValues;
-
- while (!xml.atEnd()) {
- xml.readNext();
-
- if (xml.tokenType() == QXmlStreamReader::StartElement) {
- auto className = xml.attributes().value("class");
- inFlightName |= xml.name() == u"h1";
- inFlightStatus |= className == u"FlightDetailHeaderStatus";
- inFlightMap |= className == u"flightMap";
- if (xml.name() == u"td" && !className.isEmpty()) {
- if (className.contains(u"fieldTitle")) {
- inFieldName = true;
- fieldNames += QString();
- fieldValues += QString();
- }
- if (className.contains(u"fieldValue"))
- inFieldValue = true;
- }
- if (xml.name() == u"img" && inFlightMap) {
- const QByteArray encoded
- = ("http://mobile.flightview.com/" % xml.attributes().value("src")).toLatin1();
- QUrl url = QUrl::fromPercentEncoding(encoded);
- mapReplies.append(m_manager.get(QNetworkRequest(url)));
- }
- }
-
- if (xml.tokenType() == QXmlStreamReader::EndElement) {
- inFlightName &= xml.name() != u"h1";
- inFlightStatus &= xml.name() != u"div";
- inFlightMap &= xml.name() != u"div";
- inFieldName &= xml.name() != u"td";
- inFieldValue &= xml.name() != u"td";
- }
-
- if (xml.tokenType() == QXmlStreamReader::Characters) {
- if (inFlightName)
- flightName += xml.text();
- if (inFlightStatus)
- flightStatus += xml.text();
- if (inFieldName)
- fieldNames.last() += xml.text();
- if (inFieldValue)
- fieldValues.last() += xml.text();
- }
- }
-
- if (fieldNames.isEmpty()) {
- QString code = ui.flightEdit->text().simplified().left(10);
- QString msg = QString("Flight %1 is not found").arg(code);
- ui.flightName->setText(msg);
- return;
- }
-
- ui.flightName->setText(flightName);
- flightStatus.remove("Status: ");
- ui.flightStatus->setText(flightStatus);
- ui.flightStatus->show();
-
- QStringList whiteList;
- whiteList << "Departure";
- whiteList << "Arrival";
- whiteList << "Scheduled";
- whiteList << "Takeoff";
- whiteList << "Estimated";
- whiteList << "Term-Gate";
-
- QString text;
- text = QString("<table width=%1>").arg(width() - 25);
- for (int i = 0; i < fieldNames.count(); i++) {
- QString fn = fieldNames[i].simplified();
- if (fn.endsWith(':'))
- fn = fn.left(fn.length() - 1);
- if (!whiteList.contains(fn))
- continue;
-
- QString fv = fieldValues[i].simplified();
- bool special = false;
- special |= fn.startsWith("Departure");
- special |= fn.startsWith("Arrival");
- text += "<tr>";
- if (special) {
- text += "<td align=center colspan=2>";
- text += "<b><font size=+1>" + fv + "</font></b>";
- text += "</td>";
- } else {
- text += "<td align=right>";
- text += fn;
- text += " : ";
- text += "&nbsp;";
- text += "</td>";
- text += "<td>";
- text += fv;
- text += "</td>";
- }
- text += "</tr>";
- }
- text += "</table>";
- ui.detailedInfo->setText(text);
- ui.infoBox->show();
- }
-
- void resizeEvent(QResizeEvent *event) {
- Q_UNUSED(event);
- ui.detailedInfo->setMaximumWidth(width() - 25);
- }
-
- void paintEvent(QPaintEvent *event) {
- QMainWindow::paintEvent(event);
- QPainter p(this);
- p.fillRect(rect(), QColor(131, 171, 210));
- if (!m_map.isNull()) {
- int x = (width() - m_map.width()) / 2;
- int space = ui.infoBox->pos().y();
- if (!ui.infoBox->isVisible())
- space = height();
- int top = ui.titleBox->height();
- int y = qMax(top, (space - m_map.height()) / 2);
- p.drawPixmap(x, y, m_map);
- }
- p.end();
- }
-
-};
-
-
-#include "flightinfo.moc"
-
-int main(int argc, char **argv)
-{
- Q_INIT_RESOURCE(flightinfo);
-
- QApplication app(argc, argv);
-
- FlightInfo w;
- w.resize(360, 504);
- w.show();
-
- return app.exec();
-}
diff --git a/examples/embedded/flightinfo/flightinfo.pro b/examples/embedded/flightinfo/flightinfo.pro
deleted file mode 100644
index 4e62b24576..0000000000
--- a/examples/embedded/flightinfo/flightinfo.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = flightinfo
-SOURCES = flightinfo.cpp
-FORMS += form.ui
-RESOURCES = flightinfo.qrc
-QT += network widgets
-
-target.path = $$[QT_INSTALL_EXAMPLES]/embedded/flightinfo
-INSTALLS += target
diff --git a/examples/embedded/flightinfo/flightinfo.qrc b/examples/embedded/flightinfo/flightinfo.qrc
deleted file mode 100644
index babea7e0cb..0000000000
--- a/examples/embedded/flightinfo/flightinfo.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>aircraft.png</file>
- </qresource>
-</RCC>
diff --git a/examples/embedded/flightinfo/form.ui b/examples/embedded/flightinfo/form.ui
deleted file mode 100644
index 3a24c758a6..0000000000
--- a/examples/embedded/flightinfo/form.ui
+++ /dev/null
@@ -1,226 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>Form</class>
- <widget class="QWidget" name="Form">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>220</width>
- <height>171</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <property name="spacing">
- <number>0</number>
- </property>
- <property name="margin">
- <number>0</number>
- </property>
- <item>
- <widget class="QFrame" name="titleBox">
- <property name="styleSheet">
- <string>QFrame {
-background-color: #45629a;
-}
-
-QLabel {
-color: white;
-}</string>
- </property>
- <property name="frameShape">
- <enum>QFrame::NoFrame</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
- </property>
- <property name="lineWidth">
- <number>0</number>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <property name="spacing">
- <number>0</number>
- </property>
- <property name="margin">
- <number>4</number>
- </property>
- <item>
- <widget class="QLabel" name="flightName">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Powered by FlightView</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="flightStatus">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="font">
- <font>
- <weight>75</weight>
- <bold>true</bold>
- </font>
- </property>
- <property name="styleSheet">
- <string>background-color: white;
-color: #45629a;</string>
- </property>
- <property name="lineWidth">
- <number>0</number>
- </property>
- <property name="text">
- <string>Ready</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- <property name="margin">
- <number>4</number>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QFrame" name="searchBar">
- <property name="frameShape">
- <enum>QFrame::NoFrame</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <property name="margin">
- <number>5</number>
- </property>
- <item>
- <widget class="QLineEdit" name="flightEdit">
- <property name="styleSheet">
- <string>color: black;
-border: 1px solid black;
-background: white;
-selection-background-color: lightgray;</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="searchButton">
- <property name="styleSheet">
- <string>color: rgb(255, 255, 255);
-background-color: rgb(85, 85, 255);
-padding: 2px;
-border: 2px solid rgb(0, 0, 127);</string>
- </property>
- <property name="text">
- <string>Search</string>
- </property>
- <property name="toolButtonStyle">
- <enum>Qt::ToolButtonTextBesideIcon</enum>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>58</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QFrame" name="infoBox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="styleSheet">
- <string>QFrame { border: 2px solid white;
-border-radius: 10px;
-margin: 5px;
-background-color: rgba(69, 98, 154, 192); }</string>
- </property>
- <property name="frameShape">
- <enum>QFrame::NoFrame</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <property name="spacing">
- <number>0</number>
- </property>
- <property name="margin">
- <number>5</number>
- </property>
- <item>
- <widget class="QLabel" name="detailedInfo">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="styleSheet">
- <string>color: white;
-border: none;
-background-color: none;</string>
- </property>
- <property name="text">
- <string/>
- </property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- <property name="textInteractionFlags">
- <set>Qt::NoTextInteraction</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/embedded/lightmaps/CMakeLists.txt b/examples/embedded/lightmaps/CMakeLists.txt
deleted file mode 100644
index c637aa705c..0000000000
--- a/examples/embedded/lightmaps/CMakeLists.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(lightmaps LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/embedded/lightmaps")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(lightmaps
- lightmaps.cpp lightmaps.h
- main.cpp
- mapzoom.cpp mapzoom.h
- slippymap.cpp slippymap.h
-)
-
-set_target_properties(lightmaps PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(lightmaps PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Network
- Qt6::Widgets
-)
-
-install(TARGETS lightmaps
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/embedded/lightmaps/lightmaps.cpp b/examples/embedded/lightmaps/lightmaps.cpp
deleted file mode 100644
index 566ba243ee..0000000000
--- a/examples/embedded/lightmaps/lightmaps.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore>
-#include <QtWidgets>
-#include <QtNetwork>
-
-#include "lightmaps.h"
-#include "slippymap.h"
-
-// how long (milliseconds) the user need to hold (after a tap on the screen)
-// before triggering the magnifying glass feature
-// 701, a prime number, is the sum of 229, 233, 239
-// (all three are also prime numbers, consecutive!)
-#define HOLD_TIME 701
-
-// maximum size of the magnifier
-// Hint: see above to find why I picked this one :)
-#define MAX_MAGNIFIER 229
-
-LightMaps::LightMaps(QWidget *parent)
- : QWidget(parent), pressed(false), snapped(false), zoomed(false),
- invert(false)
-{
- m_normalMap = new SlippyMap(this);
- m_largeMap = new SlippyMap(this);
- connect(m_normalMap, &SlippyMap::updated, this, &LightMaps::updateMap);
- connect(m_largeMap, &SlippyMap::updated, this, &LightMaps::updateMap);
-}
-
-void LightMaps::setCenter(qreal lat, qreal lng)
-{
- m_normalMap->latitude = lat;
- m_normalMap->longitude = lng;
- m_normalMap->invalidate();
- m_largeMap->latitude = lat;
- m_largeMap->longitude = lng;
- m_largeMap->invalidate();
-}
-
-void LightMaps::toggleNightMode()
-{
- invert = !invert;
- update();
-}
-
-void LightMaps::updateMap(const QRect &r)
-{
- update(r);
-}
-
-void LightMaps::activateZoom()
-{
- zoomed = true;
- tapTimer.stop();
- m_largeMap->zoom = m_normalMap->zoom + 1;
- m_largeMap->width = m_normalMap->width * 2;
- m_largeMap->height = m_normalMap->height * 2;
- m_largeMap->latitude = m_normalMap->latitude;
- m_largeMap->longitude = m_normalMap->longitude;
- m_largeMap->invalidate();
- update();
-}
-
-void LightMaps::resizeEvent(QResizeEvent *)
-{
- m_normalMap->width = width();
- m_normalMap->height = height();
- m_normalMap->invalidate();
- m_largeMap->width = m_normalMap->width * 2;
- m_largeMap->height = m_normalMap->height * 2;
- m_largeMap->invalidate();
-}
-
-void LightMaps::paintEvent(QPaintEvent *event)
-{
- QPainter p;
- p.begin(this);
- m_normalMap->render(&p, event->rect());
- p.setPen(Qt::black);
- p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap,
- "Map data CCBYSA 2009 OpenStreetMap.org contributors");
- p.end();
-
- if (zoomed) {
- int dim = qMin(width(), height());
- int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3);
- int radius = magnifierSize / 2;
- int ring = radius - 15;
- QSize box = QSize(magnifierSize, magnifierSize);
-
- // reupdate our mask
- if (maskPixmap.size() != box) {
- maskPixmap = QPixmap(box);
- maskPixmap.fill(Qt::transparent);
-
- QRadialGradient g;
- g.setCenter(radius, radius);
- g.setFocalPoint(radius, radius);
- g.setRadius(radius);
- g.setColorAt(1.0, QColor(255, 255, 255, 0));
- g.setColorAt(0.5, QColor(128, 128, 128, 255));
-
- QPainter mask(&maskPixmap);
- mask.setRenderHint(QPainter::Antialiasing);
- mask.setCompositionMode(QPainter::CompositionMode_Source);
- mask.setBrush(g);
- mask.setPen(Qt::NoPen);
- mask.drawRect(maskPixmap.rect());
- mask.setBrush(QColor(Qt::transparent));
- mask.drawEllipse(g.center(), ring, ring);
- mask.end();
- }
-
- QPoint center = dragPos - QPoint(0, radius);
- center = center + QPoint(0, radius / 2);
- QPoint corner = center - QPoint(radius, radius);
-
- QPoint xy = center * 2 - QPoint(radius, radius);
-
- // only set the dimension to the magnified portion
- if (zoomPixmap.size() != box) {
- zoomPixmap = QPixmap(box);
- zoomPixmap.fill(Qt::lightGray);
- }
- if (true) {
- QPainter p(&zoomPixmap);
- p.translate(-xy);
- m_largeMap->render(&p, QRect(xy, box));
- p.end();
- }
-
- QPainterPath clipPath;
- clipPath.addEllipse(center, ring, ring);
-
- QPainter p(this);
- p.setRenderHint(QPainter::Antialiasing);
- p.setClipPath(clipPath);
- p.drawPixmap(corner, zoomPixmap);
- p.setClipping(false);
- p.drawPixmap(corner, maskPixmap);
- p.setPen(Qt::gray);
- p.drawPath(clipPath);
- }
- if (invert) {
- QPainter p(this);
- p.setCompositionMode(QPainter::CompositionMode_Difference);
- p.fillRect(event->rect(), Qt::white);
- p.end();
- }
-}
-
-void LightMaps::timerEvent(QTimerEvent *)
-{
- if (!zoomed)
- activateZoom();
- update();
-}
-
-void LightMaps::mousePressEvent(QMouseEvent *event)
-{
- if (event->buttons() != Qt::LeftButton)
- return;
- pressed = snapped = true;
- pressPos = dragPos = event->position().toPoint();
- tapTimer.stop();
- tapTimer.start(HOLD_TIME, this);
-}
-
-void LightMaps::mouseMoveEvent(QMouseEvent *event)
-{
- if (!event->buttons())
- return;
- if (!zoomed) {
- if (!pressed || !snapped) {
- QPoint delta = event->position().toPoint() - pressPos;
- pressPos = event->position().toPoint();
- m_normalMap->pan(delta);
- return;
- } else {
- const int threshold = 10;
- QPoint delta = event->position().toPoint() - pressPos;
- if (snapped) {
- snapped &= delta.x() < threshold;
- snapped &= delta.y() < threshold;
- snapped &= delta.x() > -threshold;
- snapped &= delta.y() > -threshold;
- }
- if (!snapped)
- tapTimer.stop();
- }
- } else {
- dragPos = event->position().toPoint();
- update();
- }
-}
-
-void LightMaps::mouseReleaseEvent(QMouseEvent *)
-{
- zoomed = false;
- update();
-}
-
-void LightMaps::keyPressEvent(QKeyEvent *event)
-{
- if (!zoomed) {
- if (event->key() == Qt::Key_Left)
- m_normalMap->pan(QPoint(20, 0));
- if (event->key() == Qt::Key_Right)
- m_normalMap->pan(QPoint(-20, 0));
- if (event->key() == Qt::Key_Up)
- m_normalMap->pan(QPoint(0, 20));
- if (event->key() == Qt::Key_Down)
- m_normalMap->pan(QPoint(0, -20));
- if (event->key() == Qt::Key_Z || event->key() == Qt::Key_Select) {
- dragPos = QPoint(width() / 2, height() / 2);
- activateZoom();
- }
- } else {
- if (event->key() == Qt::Key_Z || event->key() == Qt::Key_Select) {
- zoomed = false;
- update();
- }
- QPoint delta(0, 0);
- if (event->key() == Qt::Key_Left)
- delta = QPoint(-15, 0);
- if (event->key() == Qt::Key_Right)
- delta = QPoint(15, 0);
- if (event->key() == Qt::Key_Up)
- delta = QPoint(0, -15);
- if (event->key() == Qt::Key_Down)
- delta = QPoint(0, 15);
- if (delta != QPoint(0, 0)) {
- dragPos += delta;
- update();
- }
- }
-}
diff --git a/examples/embedded/lightmaps/lightmaps.h b/examples/embedded/lightmaps/lightmaps.h
deleted file mode 100644
index d932fe2ce4..0000000000
--- a/examples/embedded/lightmaps/lightmaps.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef LIGHTMAPS_H
-#define LIGHTMAPS_H
-
-#include <QBasicTimer>
-#include <QWidget>
-
-class SlippyMap;
-
-class LightMaps: public QWidget
-{
- Q_OBJECT
-
-public:
- LightMaps(QWidget *parent = nullptr);
- void setCenter(qreal lat, qreal lng);
-
-public slots:
- void toggleNightMode();
-
-protected:
- void activateZoom();
- void resizeEvent(QResizeEvent *);
- void paintEvent(QPaintEvent *event);
- void timerEvent(QTimerEvent *);
- void mousePressEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *);
- void keyPressEvent(QKeyEvent *event);
-
-private slots:
- void updateMap(const QRect &r);
-
-private:
- SlippyMap *m_normalMap;
- SlippyMap *m_largeMap;
- bool pressed;
- bool snapped;
- QPoint pressPos;
- QPoint dragPos;
- QBasicTimer tapTimer;
- bool zoomed;
- QPixmap zoomPixmap;
- QPixmap maskPixmap;
- bool invert;
-};
-
-#endif
diff --git a/examples/embedded/lightmaps/lightmaps.pro b/examples/embedded/lightmaps/lightmaps.pro
deleted file mode 100644
index bb75cf0a9c..0000000000
--- a/examples/embedded/lightmaps/lightmaps.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-TEMPLATE = app
-HEADERS = lightmaps.h \
- mapzoom.h \
- slippymap.h
-SOURCES = lightmaps.cpp \
- main.cpp \
- mapzoom.cpp \
- slippymap.cpp
-QT += network widgets
-
-target.path = $$[QT_INSTALL_EXAMPLES]/embedded/lightmaps
-INSTALLS += target
diff --git a/examples/embedded/lightmaps/main.cpp b/examples/embedded/lightmaps/main.cpp
deleted file mode 100644
index 9719eec837..0000000000
--- a/examples/embedded/lightmaps/main.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include "mapzoom.h"
-
-int main(int argc, char **argv)
-{
-
- QApplication app(argc, argv);
- app.setApplicationName("LightMaps");
-
- MapZoom w;
- w.resize(600, 450);
- w.show();
-
- return app.exec();
-}
diff --git a/examples/embedded/lightmaps/mapzoom.cpp b/examples/embedded/lightmaps/mapzoom.cpp
deleted file mode 100644
index f29dcfa8fe..0000000000
--- a/examples/embedded/lightmaps/mapzoom.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-#include <QtNetwork>
-#include "lightmaps.h"
-#include "mapzoom.h"
-
-MapZoom::MapZoom()
- : QMainWindow(0)
-{
- map = new LightMaps(this);
- setCentralWidget(map);
- map->setFocus();
-
- QAction *osloAction = new QAction(tr("&Oslo"), this);
- QAction *berlinAction = new QAction(tr("&Berlin"), this);
- QAction *jakartaAction = new QAction(tr("&Jakarta"), this);
- QAction *nightModeAction = new QAction(tr("Night Mode"), this);
- nightModeAction->setCheckable(true);
- nightModeAction->setChecked(false);
- QAction *osmAction = new QAction(tr("About OpenStreetMap"), this);
- connect(osloAction, SIGNAL(triggered()), SLOT(chooseOslo()));
- connect(berlinAction, SIGNAL(triggered()), SLOT(chooseBerlin()));
- connect(jakartaAction, SIGNAL(triggered()), SLOT(chooseJakarta()));
- connect(nightModeAction, SIGNAL(triggered()), map, SLOT(toggleNightMode()));
- connect(osmAction, SIGNAL(triggered()), SLOT(aboutOsm()));
-
- QMenu *menu = menuBar()->addMenu(tr("&Options"));
- menu->addAction(osloAction);
- menu->addAction(berlinAction);
- menu->addAction(jakartaAction);
- menu->addSeparator();
- menu->addAction(nightModeAction);
- menu->addAction(osmAction);
-
- setWindowTitle(tr("Light Maps"));
-}
-
-void MapZoom::chooseOslo()
-{
- map->setCenter(59.9138204, 10.7387413);
-}
-
-void MapZoom::chooseBerlin()
-{
- map->setCenter(52.52958999943302, 13.383053541183472);
-}
-
-void MapZoom::chooseJakarta()
-{
- map->setCenter(-6.211544, 106.845172);
-}
-
-void MapZoom::aboutOsm()
-{
- QDesktopServices::openUrl(QUrl("http://www.openstreetmap.org"));
-}
diff --git a/examples/embedded/lightmaps/mapzoom.h b/examples/embedded/lightmaps/mapzoom.h
deleted file mode 100644
index 2f1425988b..0000000000
--- a/examples/embedded/lightmaps/mapzoom.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAPZOOM_H
-#define MAPZOOM_H
-
-#include <QMainWindow>
-
-class LightMaps;
-
-class MapZoom : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MapZoom();
-
-private slots:
- void chooseOslo();
- void chooseBerlin();
- void chooseJakarta();
- void aboutOsm();
-
-private:
- LightMaps *map;
-};
-
-#endif
diff --git a/examples/embedded/lightmaps/slippymap.cpp b/examples/embedded/lightmaps/slippymap.cpp
deleted file mode 100644
index 76ac80bfaa..0000000000
--- a/examples/embedded/lightmaps/slippymap.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-#include <QtNetwork>
-#include "slippymap.h"
-#include "qmath.h"
-
-// tile size in pixels
-const int tdim = 256;
-
-QPointF tileForCoordinate(qreal lat, qreal lng, int zoom)
-{
- qreal radianLat = qDegreesToRadians(lat);
- qreal zn = static_cast<qreal>(1 << zoom);
- qreal tx = (lng + 180.0) / 360.0;
- qreal ty = 0.5 - log(tan(radianLat) + 1.0 / cos(radianLat)) / M_PI / 2.0;
- return QPointF(tx * zn, ty * zn);
-}
-
-qreal longitudeFromTile(qreal tx, int zoom)
-{
- qreal zn = static_cast<qreal>(1 << zoom);
- qreal lat = tx / zn * 360.0 - 180.0;
- return lat;
-}
-
-qreal latitudeFromTile(qreal ty, int zoom)
-{
- qreal zn = static_cast<qreal>(1 << zoom);
- qreal n = M_PI - 2 * M_PI * ty / zn;
- return qRadiansToDegrees(atan(sinh(n)));
-}
-
-
-SlippyMap::SlippyMap(QObject *parent)
- : QObject(parent), width(400), height(300), zoom(15),
- latitude(59.9138204), longitude(10.7387413)
-{
- m_emptyTile = QPixmap(tdim, tdim);
- m_emptyTile.fill(Qt::lightGray);
-
- QNetworkDiskCache *cache = new QNetworkDiskCache;
- cache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
- m_manager.setCache(cache);
- connect(&m_manager, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(handleNetworkData(QNetworkReply*)));
-}
-
-void SlippyMap::invalidate()
-{
- if (width <= 0 || height <= 0)
- return;
-
- QPointF ct = tileForCoordinate(latitude, longitude, zoom);
- qreal tx = ct.x();
- qreal ty = ct.y();
-
- // top-left corner of the center tile
- int xp = width / 2 - (tx - floor(tx)) * tdim;
- int yp = height / 2 - (ty - floor(ty)) * tdim;
-
- // first tile vertical and horizontal
- int xa = (xp + tdim - 1) / tdim;
- int ya = (yp + tdim - 1) / tdim;
- int xs = static_cast<int>(tx) - xa;
- int ys = static_cast<int>(ty) - ya;
-
- // offset for top-left tile
- m_offset = QPoint(xp - xa * tdim, yp - ya * tdim);
-
- // last tile vertical and horizontal
- int xe = static_cast<int>(tx) + (width - xp - 1) / tdim;
- int ye = static_cast<int>(ty) + (height - yp - 1) / tdim;
-
- // build a rect
- m_tilesRect = QRect(xs, ys, xe - xs + 1, ye - ys + 1);
-
- if (m_url.isEmpty())
- download();
-
- emit updated(QRect(0, 0, width, height));
-}
-
-void SlippyMap::render(QPainter *p, const QRect &rect)
-{
- for (int x = 0; x <= m_tilesRect.width(); ++x)
- for (int y = 0; y <= m_tilesRect.height(); ++y) {
- QPoint tp(x + m_tilesRect.left(), y + m_tilesRect.top());
- QRect box = tileRect(tp);
- if (rect.intersects(box)) {
- if (m_tilePixmaps.contains(tp))
- p->drawPixmap(box, m_tilePixmaps.value(tp));
- else
- p->drawPixmap(box, m_emptyTile);
- }
- }
-}
-
-void SlippyMap::pan(const QPoint &delta)
-{
- QPointF dx = QPointF(delta) / qreal(tdim);
- QPointF center = tileForCoordinate(latitude, longitude, zoom) - dx;
- latitude = latitudeFromTile(center.y(), zoom);
- longitude = longitudeFromTile(center.x(), zoom);
- invalidate();
-}
-
-void SlippyMap::handleNetworkData(QNetworkReply *reply)
-{
- QImage img;
- QPoint tp = reply->request().attribute(QNetworkRequest::User).toPoint();
- if (!reply->error())
- if (!img.load(reply, 0))
- img = QImage();
- reply->deleteLater();
- m_tilePixmaps[tp] = QPixmap::fromImage(img);
- if (img.isNull())
- m_tilePixmaps[tp] = m_emptyTile;
- emit updated(tileRect(tp));
-
- // purge unused spaces
- const QRect bound = m_tilesRect.adjusted(-2, -2, 2, 2);
- for (auto it = m_tilePixmaps.keyBegin(); it != m_tilePixmaps.keyEnd(); ++it) {
- const QPoint &tp = *it;
- if (!bound.contains(tp))
- m_tilePixmaps.remove(tp);
- }
-
- download();
-}
-
-void SlippyMap::download()
-{
- QPoint grab(0, 0);
- for (int x = 0; x <= m_tilesRect.width(); ++x)
- for (int y = 0; y <= m_tilesRect.height(); ++y) {
- QPoint tp = m_tilesRect.topLeft() + QPoint(x, y);
- if (!m_tilePixmaps.contains(tp)) {
- grab = tp;
- break;
- }
- }
- if (grab == QPoint(0, 0)) {
- m_url = QUrl();
- return;
- }
-
- QString path = "http://tile.openstreetmap.org/%1/%2/%3.png";
- m_url = QUrl(path.arg(zoom).arg(grab.x()).arg(grab.y()));
- QNetworkRequest request;
- request.setUrl(m_url);
- request.setRawHeader("User-Agent", "The Qt Company (Qt) Graphics Dojo 1.0");
- request.setAttribute(QNetworkRequest::User, QVariant(grab));
- m_manager.get(request);
-}
-
-QRect SlippyMap::tileRect(const QPoint &tp)
-{
- QPoint t = tp - m_tilesRect.topLeft();
- int x = t.x() * tdim + m_offset.x();
- int y = t.y() * tdim + m_offset.y();
- return QRect(x, y, tdim, tdim);
-}
diff --git a/examples/embedded/lightmaps/slippymap.h b/examples/embedded/lightmaps/slippymap.h
deleted file mode 100644
index 85afac09dc..0000000000
--- a/examples/embedded/lightmaps/slippymap.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SLIPPYMAP_H
-#define SLIPPYMAP_H
-
-#include <QNetworkAccessManager>
-#include <QPixmap>
-#include <QUrl>
-
-QT_BEGIN_NAMESPACE
-class QNetworkReply;
-class QPainter;
-QT_END_NAMESPACE
-
-class SlippyMap: public QObject
-{
- Q_OBJECT
-
-public:
- SlippyMap(QObject *parent = nullptr);
- void invalidate();
- void render(QPainter *p, const QRect &rect);
- void pan(const QPoint &delta);
-
- int width;
- int height;
- int zoom;
- qreal latitude;
- qreal longitude;
-
-signals:
- void updated(const QRect &rect);
-
-private slots:
- void handleNetworkData(QNetworkReply *reply);
- void download();
-
-protected:
- QRect tileRect(const QPoint &tp);
-
-private:
- QPoint m_offset;
- QRect m_tilesRect;
- QPixmap m_emptyTile;
- QHash<QPoint, QPixmap> m_tilePixmaps;
- QNetworkAccessManager m_manager;
- QUrl m_url;
-};
-
-#endif
-
diff --git a/examples/embedded/raycasting/CMakeLists.txt b/examples/embedded/raycasting/CMakeLists.txt
deleted file mode 100644
index 7186fddb8f..0000000000
--- a/examples/embedded/raycasting/CMakeLists.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(raycasting LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/embedded/raycasting")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(raycasting
- raycasting.cpp
-)
-
-set_target_properties(raycasting PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(raycasting PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(raycasting_resource_files
- "textures.png"
-)
-
-qt_add_resources(raycasting "raycasting"
- PREFIX
- "/"
- FILES
- ${raycasting_resource_files}
-)
-
-install(TARGETS raycasting
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/embedded/raycasting/raycasting.cpp b/examples/embedded/raycasting/raycasting.cpp
deleted file mode 100644
index 1823974f8c..0000000000
--- a/examples/embedded/raycasting/raycasting.cpp
+++ /dev/null
@@ -1,336 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore>
-#include <QtWidgets>
-#include <qmath.h>
-
-#define WORLD_SIZE 8
-int world_map[WORLD_SIZE][WORLD_SIZE] = {
- { 1, 1, 1, 1, 6, 1, 1, 1 },
- { 1, 0, 0, 1, 0, 0, 0, 7 },
- { 1, 1, 0, 1, 0, 1, 1, 1 },
- { 6, 0, 0, 0, 0, 0, 0, 3 },
- { 1, 8, 8, 0, 8, 0, 8, 1 },
- { 2, 2, 0, 0, 8, 8, 7, 1 },
- { 3, 0, 0, 0, 0, 0, 0, 5 },
- { 2, 2, 2, 2, 7, 4, 4, 4 },
-};
-
-#define TEXTURE_SIZE 64
-#define TEXTURE_BLOCK (TEXTURE_SIZE * TEXTURE_SIZE)
-
-class Raycasting: public QWidget
-{
-public:
- Raycasting(QWidget *parent = nullptr)
- : QWidget(parent)
- , angle(0.5)
- , playerPos(1.5, 1.5)
- , angleDelta(0)
- , moveDelta(0)
- , touchDevice(false) {
-
- // http://www.areyep.com/RIPandMCS-TextureLibrary.html
- textureImg.load(":/textures.png");
- textureImg = textureImg.convertToFormat(QImage::Format_ARGB32);
- Q_ASSERT(textureImg.width() == TEXTURE_SIZE * 2);
- Q_ASSERT(textureImg.bytesPerLine() == 4 * TEXTURE_SIZE * 2);
- textureCount = textureImg.height() / TEXTURE_SIZE;
-
- watch.start();
- ticker.start(25, this);
- setAttribute(Qt::WA_OpaquePaintEvent, true);
- setMouseTracking(false);
- }
-
- void updatePlayer() {
- int interval = qBound(20ll, watch.elapsed(), 250ll);
- watch.start();
- angle += angleDelta * interval / 1000;
- qreal step = moveDelta * interval / 1000;
- qreal dx = cos(angle) * step;
- qreal dy = sin(angle) * step;
- QPointF pos = playerPos + 3 * QPointF(dx, dy);
- int xi = static_cast<int>(pos.x());
- int yi = static_cast<int>(pos.y());
- if (world_map[yi][xi] == 0)
- playerPos = playerPos + QPointF(dx, dy);
- }
-
- void showFps() {
- static QElapsedTimer frameTick;
- static int totalFrame = 0;
- if (!(totalFrame & 31)) {
- const qint64 elapsed = frameTick.elapsed();
- frameTick.start();
- int fps = 32 * 1000 / (1 + elapsed);
- setWindowTitle(QString("Raycasting (%1 FPS)").arg(fps));
- }
- totalFrame++;
- }
-
- void render() {
-
- // setup the screen surface
- if (buffer.size() != bufferSize)
- buffer = QImage(bufferSize, QImage::Format_ARGB32);
- int bufw = buffer.width();
- int bufh = buffer.height();
- if (bufw <= 0 || bufh <= 0)
- return;
-
- // we intentionally cheat here, to avoid detach
- const uchar *ptr = buffer.bits();
- QRgb *start = (QRgb*)(ptr);
- QRgb stride = buffer.bytesPerLine() / 4;
- QRgb *finish = start + stride * bufh;
-
- // prepare the texture pointer
- const uchar *src = textureImg.bits();
- const QRgb *texsrc = reinterpret_cast<const QRgb*>(src);
-
- // cast all rays here
- qreal sina = sin(angle);
- qreal cosa = cos(angle);
- qreal u = cosa - sina;
- qreal v = sina + cosa;
- qreal du = 2 * sina / bufw;
- qreal dv = -2 * cosa / bufw;
-
- for (int ray = 0; ray < bufw; ++ray, u += du, v += dv) {
- // every time this ray advances 'u' units in x direction,
- // it also advanced 'v' units in y direction
- qreal uu = (u < 0) ? -u : u;
- qreal vv = (v < 0) ? -v : v;
- qreal duu = 1 / uu;
- qreal dvv = 1 / vv;
- int stepx = (u < 0) ? -1 : 1;
- int stepy = (v < 0) ? -1 : 1;
-
- // the cell in the map that we need to check
- qreal px = playerPos.x();
- qreal py = playerPos.y();
- int mapx = static_cast<int>(px);
- int mapy = static_cast<int>(py);
-
- // the position and texture for the hit
- int texture = 0;
- qreal hitdist = 0.1;
- qreal texofs = 0;
- bool dark = false;
-
- // first hit at constant x and constant y lines
- qreal distx = (u > 0) ? (mapx + 1 - px) * duu : (px - mapx) * duu;
- qreal disty = (v > 0) ? (mapy + 1 - py) * dvv : (py - mapy) * dvv;
-
- // loop until we hit something
- while (texture <= 0) {
- if (distx > disty) {
- // shorter distance to a hit in constant y line
- hitdist = disty;
- disty += dvv;
- mapy += stepy;
- texture = world_map[mapy][mapx];
- if (texture > 0) {
- dark = true;
- if (stepy > 0) {
- qreal ofs = px + u * (mapy - py) / v;
- texofs = ofs - floor(ofs);
- } else {
- qreal ofs = px + u * (mapy + 1 - py) / v;
- texofs = ofs - floor(ofs);
- }
- }
- } else {
- // shorter distance to a hit in constant x line
- hitdist = distx;
- distx += duu;
- mapx += stepx;
- texture = world_map[mapy][mapx];
- if (texture > 0) {
- if (stepx > 0) {
- qreal ofs = py + v * (mapx - px) / u;
- texofs = ofs - floor(ofs);
- } else {
- qreal ofs = py + v * (mapx + 1 - px) / u;
- texofs = ceil(ofs) - ofs;
- }
- }
- }
- }
-
- // get the texture, note that the texture image
- // has two textures horizontally, "normal" vs "dark"
- int col = static_cast<int>(texofs * TEXTURE_SIZE);
- col = qBound(0, col, TEXTURE_SIZE - 1);
- texture = (texture - 1) % textureCount;
- const QRgb *tex = texsrc + TEXTURE_BLOCK * texture * 2 +
- (TEXTURE_SIZE * 2 * col);
- if (dark)
- tex += TEXTURE_SIZE;
-
- // start from the texture center (horizontally)
- int h = static_cast<int>(bufw / hitdist / 2);
- int dy = (TEXTURE_SIZE << 12) / h;
- int p1 = ((TEXTURE_SIZE / 2) << 12) - dy;
- int p2 = p1 + dy;
-
- // start from the screen center (vertically)
- // y1 will go up (decrease), y2 will go down (increase)
- int y1 = bufh / 2;
- int y2 = y1 + 1;
- QRgb *pixel1 = start + y1 * stride + ray;
- QRgb *pixel2 = pixel1 + stride;
-
- // map the texture to the sliver
- while (y1 >= 0 && y2 < bufh && p1 >= 0) {
- *pixel1 = tex[p1 >> 12];
- *pixel2 = tex[p2 >> 12];
- p1 -= dy;
- p2 += dy;
- --y1;
- ++y2;
- pixel1 -= stride;
- pixel2 += stride;
- }
-
- // ceiling and floor
- for (; pixel1 > start; pixel1 -= stride)
- *pixel1 = qRgb(0, 0, 0);
- for (; pixel2 < finish; pixel2 += stride)
- *pixel2 = qRgb(96, 96, 96);
- }
-
- update(QRect(QPoint(0, 0), bufferSize));
- }
-
-protected:
-
- void resizeEvent(QResizeEvent*) {
- touchDevice = false;
- if (touchDevice) {
- if (width() < height()) {
- trackPad = QRect(0, height() / 2, width(), height() / 2);
- centerPad = QPoint(width() / 2, height() * 3 / 4);
- bufferSize = QSize(width(), height() / 2);
- } else {
- trackPad = QRect(width() / 2, 0, width() / 2, height());
- centerPad = QPoint(width() * 3 / 4, height() / 2);
- bufferSize = QSize(width() / 2, height());
- }
- } else {
- trackPad = QRect();
- bufferSize = size();
- }
- update();
- }
-
- void timerEvent(QTimerEvent*) {
- updatePlayer();
- render();
- showFps();
- }
-
- void paintEvent(QPaintEvent *event) {
- QPainter p(this);
- p.setCompositionMode(QPainter::CompositionMode_Source);
-
- p.drawImage(event->rect(), buffer, event->rect());
-
- if (touchDevice && event->rect().intersects(trackPad)) {
- p.fillRect(trackPad, Qt::white);
- p.setPen(QPen(QColor(224, 224, 224), 6));
- int rad = qMin(trackPad.width(), trackPad.height()) * 0.3;
- p.drawEllipse(centerPad, rad, rad);
-
- p.setPen(Qt::NoPen);
- p.setBrush(Qt::gray);
-
- QPolygon poly;
- poly << QPoint(-30, 0);
- poly << QPoint(0, -40);
- poly << QPoint(30, 0);
-
- p.translate(centerPad);
- for (int i = 0; i < 4; ++i) {
- p.rotate(90);
- p.translate(0, 20 - rad);
- p.drawPolygon(poly);
- p.translate(0, rad - 20);
- }
- }
-
- p.end();
- }
-
- void keyPressEvent(QKeyEvent *event) {
- event->accept();
- if (event->key() == Qt::Key_Left)
- angleDelta = 1.3 * M_PI;
- if (event->key() == Qt::Key_Right)
- angleDelta = -1.3 * M_PI;
- if (event->key() == Qt::Key_Up)
- moveDelta = 2.5;
- if (event->key() == Qt::Key_Down)
- moveDelta = -2.5;
- }
-
- void keyReleaseEvent(QKeyEvent *event) {
- event->accept();
- if (event->key() == Qt::Key_Left)
- angleDelta = (angleDelta > 0) ? 0 : angleDelta;
- if (event->key() == Qt::Key_Right)
- angleDelta = (angleDelta < 0) ? 0 : angleDelta;
- if (event->key() == Qt::Key_Up)
- moveDelta = (moveDelta > 0) ? 0 : moveDelta;
- if (event->key() == Qt::Key_Down)
- moveDelta = (moveDelta < 0) ? 0 : moveDelta;
- }
-
- void mousePressEvent(QMouseEvent *event) {
- qreal dx = centerPad.x() - event->position().toPoint().x();
- qreal dy = centerPad.y() - event->position().toPoint().y();
- angleDelta = dx * 2 * M_PI / width();
- moveDelta = dy * 10 / height();
- }
-
- void mouseMoveEvent(QMouseEvent *event) {
- qreal dx = centerPad.x() - event->position().toPoint().x();
- qreal dy = centerPad.y() - event->position().toPoint().y();
- angleDelta = dx * 2 * M_PI / width();
- moveDelta = dy * 10 / height();
- }
-
- void mouseReleaseEvent(QMouseEvent*) {
- angleDelta = 0;
- moveDelta = 0;
- }
-
-private:
- QElapsedTimer watch;
- QBasicTimer ticker;
- QImage buffer;
- qreal angle;
- QPointF playerPos;
- qreal angleDelta;
- qreal moveDelta;
- QImage textureImg;
- int textureCount;
- bool touchDevice;
- QRect trackPad;
- QPoint centerPad;
- QSize bufferSize;
-};
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
-
- Raycasting w;
- w.setWindowTitle("Raycasting");
- w.resize(640, 480);
- w.show();
-
- return app.exec();
-}
diff --git a/examples/embedded/raycasting/raycasting.pro b/examples/embedded/raycasting/raycasting.pro
deleted file mode 100644
index 51bf4bf4b0..0000000000
--- a/examples/embedded/raycasting/raycasting.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TEMPLATE = app
-QT += widgets
-SOURCES = raycasting.cpp
-RESOURCES += raycasting.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/embedded/raycasting
-INSTALLS += target
diff --git a/examples/embedded/raycasting/raycasting.qrc b/examples/embedded/raycasting/raycasting.qrc
deleted file mode 100644
index 974a06093c..0000000000
--- a/examples/embedded/raycasting/raycasting.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>textures.png</file>
- </qresource>
-</RCC>
diff --git a/examples/embedded/raycasting/textures.png b/examples/embedded/raycasting/textures.png
deleted file mode 100644
index 2eb1ba7ff6..0000000000
--- a/examples/embedded/raycasting/textures.png
+++ /dev/null
Binary files differ
diff --git a/examples/embedded/styleexample/CMakeLists.txt b/examples/embedded/styleexample/CMakeLists.txt
deleted file mode 100644
index becc8dbb84..0000000000
--- a/examples/embedded/styleexample/CMakeLists.txt
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(styleexample LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/embedded/styleexample")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(styleexample
- main.cpp
- stylewidget.cpp stylewidget.h stylewidget.ui
-)
-
-set_target_properties(styleexample PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(styleexample PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(styleexample_resource_files
- "files/add.png"
- "files/application.qss"
- "files/blue.qss"
- "files/khaki.qss"
- "files/nature_1.jpg"
- "files/nostyle.qss"
- "files/remove.png"
- "files/transparent.qss"
-)
-
-qt_add_resources(styleexample "styleexample"
- PREFIX
- "/"
- FILES
- ${styleexample_resource_files}
-)
-
-install(TARGETS styleexample
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/embedded/styleexample/files/add.png b/examples/embedded/styleexample/files/add.png
deleted file mode 100644
index fc5c16d4c8..0000000000
--- a/examples/embedded/styleexample/files/add.png
+++ /dev/null
Binary files differ
diff --git a/examples/embedded/styleexample/files/application.qss b/examples/embedded/styleexample/files/application.qss
deleted file mode 100644
index 432fe6bc76..0000000000
--- a/examples/embedded/styleexample/files/application.qss
+++ /dev/null
@@ -1,125 +0,0 @@
-QWidget#StyleWidget
-{
- background-color: none;
- background-image: url(icons:nature_1.jpg);
-}
-
-QLabel, QAbstractButton
-{
- font: bold;
- color: beige;
-}
-
-QAbstractButton
-{
- background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(173,216,230,60%), stop:1 rgba(0,0,139,60%) );
- border-color: black;
- border-style: solid;
- border-width: 3px;
- border-radius: 6px;
-}
-
-QAbstractButton:pressed, QAbstractButton:checked
-{
- background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(0,0,139,60%), stop:1 rgba(173,216,230,60%) );
-}
-
-QSpinBox {
- padding-left: 24px;
- padding-right: 24px;
- border-color: darkkhaki;
- border-style: solid;
- border-radius: 5;
- border-width: 3;
-}
-
-QSpinBox::up-button
-{
- subcontrol-origin: padding;
- subcontrol-position: right; /* position at the top right corner */
- width: 24px;
- height: 24px;
- border-width: 3px;
-
-}
-
-QSpinBox::up-arrow
-{
- image: url(icons:add.png);
- width: 18px;
- height: 18px;
-}
-
-
-QSpinBox::down-button
-{
- subcontrol-origin: border;
- subcontrol-position: left;
- width: 24px;
- height: 24px;
- border-width: 3px;
-}
-
-QSpinBox::down-arrow
-{
- image: url(icons:remove.png);
- width: 18px;
- height: 18px;
-}
-
-
-QScrollBar:horizontal
-{
- border: 1px solid black;
- background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0,0,139,60%), stop:1 rgba(173,216,230,60%) );
- height: 15px;
- margin: 0px 20px 0 20px;
-}
-
-QScrollBar::handle:horizontal
-{
- border: 1px solid black;
- background: rgba(0,0,139,60%);
- min-width: 20px;
-}
-
-QScrollBar::add-line:horizontal
-{
- border: 1px solid black;
- background: rgba(0,0,139,60%);
- width: 20px;
- subcontrol-position: right;
- subcontrol-origin: margin;
-}
-
-QScrollBar::sub-line:horizontal
-{
- border: 1px solid black;
- background: rgba(0,0,139,60%);
- width: 20px;
- subcontrol-position: left;
- subcontrol-origin: margin;
-}
-
-QScrollBar:left-arrow:horizontal, QScrollBar::right-arrow:horizontal
-{
- border: none;
- width: 16px;
- height: 16px;
-}
-
-QScrollBar:left-arrow:horizontal
-{
- image: url(icons:add.png)
-}
-
-QScrollBar::right-arrow:horizontal
-{
- image: url(icons:remove.png)
-}
-
-QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal
-{
- background: none;
-}
-
diff --git a/examples/embedded/styleexample/files/blue.qss b/examples/embedded/styleexample/files/blue.qss
deleted file mode 100644
index ac8671b5e4..0000000000
--- a/examples/embedded/styleexample/files/blue.qss
+++ /dev/null
@@ -1,38 +0,0 @@
-*
-{
- color: beige;
-}
-
-QLabel, QAbstractButton
-{
- font: bold;
- color: yellow;
-}
-
-QFrame
-{
- background-color: rgba(96,96,255,60%);
- border-color: rgb(32,32,196);
- border-width: 3px;
- border-style: solid;
- border-radius: 5;
- padding: 3px;
-}
-
-QAbstractButton
-{
- background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
- stop:0 lightblue, stop:0.5 darkblue);
- border-width: 3px;
- border-color: darkblue;
- border-style: solid;
- border-radius: 5;
- padding: 3px;
-}
-
-QAbstractButton:pressed
-{
- background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
- stop:0.5 darkblue, stop:1 lightblue);
- border-color: beige;
-}
diff --git a/examples/embedded/styleexample/files/khaki.qss b/examples/embedded/styleexample/files/khaki.qss
deleted file mode 100644
index b0d4a0fa6f..0000000000
--- a/examples/embedded/styleexample/files/khaki.qss
+++ /dev/null
@@ -1,99 +0,0 @@
-
-QWidget#StartScreen, QWidget#MainWidget {
- border: none;
-}
-
-QWidget#StartScreen, .QFrame {
- background-color: beige;
-}
-
-QPushButton, QToolButton {
- background-color: palegoldenrod;
- border-width: 2px;
- border-color: darkkhaki;
- border-style: solid;
- border-radius: 5;
- padding: 3px;
- /* min-width: 96px; */
- /* min-height: 48px; */
-}
-
-QPushButton:hover, QToolButton:hover {
- background-color: khaki;
-}
-
-QPushButton:pressed, QToolButton:pressed {
- padding-left: 5px;
- padding-top: 5px;
- background-color: #d0d67c;
-}
-
-QLabel, QAbstractButton {
- font: italic "Times New Roman";
-}
-
-QFrame, QLabel#title {
- border-width: 2px;
- padding: 1px;
- border-style: solid;
- border-color: darkkhaki;
- border-radius: 5px;
-}
-
-QFrame:focus {
- border-width: 3px;
- padding: 0px;
-}
-
-
-QLabel {
- border: none;
- padding: 0;
- background: none;
-}
-
-QLabel#title {
- font: 32px bold;
-}
-
-QSpinBox {
- padding-left: 24px;
- padding-right: 24px;
- border-color: darkkhaki;
- border-style: solid;
- border-radius: 5;
- border-width: 3;
-}
-
-QSpinBox::up-button
-{
- subcontrol-origin: padding;
- subcontrol-position: right; /* position at the top right corner */
- width: 24px;
- height: 24px;
- border-width: 3px;
- border-image: url(:/files/spindownpng) 1;
-}
-
-QSpinBox::up-arrow {
- image: url(:/files/add.png);
- width: 12px;
- height: 12px;
- }
-
-
-QSpinBox::down-button
-{
- subcontrol-origin: border;
- subcontrol-position: left;
- width: 24px;
- height: 24px;
- border-width: 3px;
- border-image: url(:/files/spindownpng) 1;
-}
-
-QSpinBox::down-arrow {
- image: url(:/files/remove.png);
- width: 12px;
- height: 12px;
- }
diff --git a/examples/embedded/styleexample/files/nature_1.jpg b/examples/embedded/styleexample/files/nature_1.jpg
deleted file mode 100644
index 3a04edb96a..0000000000
--- a/examples/embedded/styleexample/files/nature_1.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/embedded/styleexample/files/nostyle.qss b/examples/embedded/styleexample/files/nostyle.qss
deleted file mode 100644
index e69de29bb2..0000000000
--- a/examples/embedded/styleexample/files/nostyle.qss
+++ /dev/null
diff --git a/examples/embedded/styleexample/files/remove.png b/examples/embedded/styleexample/files/remove.png
deleted file mode 100644
index a0ab1fa21a..0000000000
--- a/examples/embedded/styleexample/files/remove.png
+++ /dev/null
Binary files differ
diff --git a/examples/embedded/styleexample/files/transparent.qss b/examples/embedded/styleexample/files/transparent.qss
deleted file mode 100644
index b38eb366f4..0000000000
--- a/examples/embedded/styleexample/files/transparent.qss
+++ /dev/null
@@ -1,139 +0,0 @@
-QWidget#StyleWidget
-{
- background-color: none;
- background-image: url(:/files/nature_1.jpg);
-}
-
-QLabel, QAbstractButton
-{
- color: beige;
-}
-
-QFrame, QLabel#title {
- border-width: 2px;
- padding: 1px;
- border-style: solid;
- border-color: black;
- border-radius: 5px;
-}
-
-QFrame:focus {
- border-width: 3px;
- padding: 0px;
-}
-
-
-
-QAbstractButton
-{
- background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(173,216,230,60%), stop:1 rgba(0,0,139,60%) );
- border-color: black;
- border-style: solid;
- border-width: 3px;
- border-radius: 6px;
-}
-
-QAbstractButton:pressed, QAbstractButton:checked
-{
- background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(0,0,139,60%), stop:1 rgba(173,216,230,60%) );
-}
-
-QSpinBox {
- padding-left: 24px;
- padding-right: 24px;
- border-color: darkkhaki;
- border-style: solid;
- border-radius: 5;
- border-width: 3;
-}
-
-QSpinBox::up-button
-{
- subcontrol-origin: padding;
- subcontrol-position: right; /* position at the top right corner */
- width: 24px;
- height: 24px;
- border-width: 3px;
-
-}
-
-QSpinBox::up-arrow
-{
- image: url(:/files/add.png);
- width: 18px;
- height: 18px;
-}
-
-
-QSpinBox::down-button
-{
- subcontrol-origin: border;
- subcontrol-position: left;
- width: 24px;
- height: 24px;
- border-width: 3px;
-}
-
-QSpinBox::down-arrow
-{
- image: url(:/files/remove.png);
- width: 18px;
- height: 18px;
-}
-
-
-QScrollBar:horizontal
-{
- border: 1px solid black;
- background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0,0,139,60%), stop:1 rgba(173,216,230,60%) );
- height: 15px;
- margin: 0px 20px 0 20px;
-}
-
-QScrollBar::handle:horizontal
-{
- border: 1px solid black;
- background: rgba(0,0,139,60%);
- min-width: 20px;
-}
-
-QScrollBar::add-line:horizontal
-{
- border: 1px solid black;
- background: rgba(0,0,139,60%);
- width: 20px;
- subcontrol-position: right;
- subcontrol-origin: margin;
-}
-
-QScrollBar::sub-line:horizontal
-{
- border: 1px solid black;
- background: rgba(0,0,139,60%);
- width: 20px;
- subcontrol-position: left;
- subcontrol-origin: margin;
-}
-
-QScrollBar:left-arrow:horizontal, QScrollBar::right-arrow:horizontal
-{
- border: none;
- width: 16px;
- height: 16px;
-}
-
-QScrollBar:left-arrow:horizontal
-{
- image: url(:/files/add.png)
-}
-
-QScrollBar::right-arrow:horizontal
-{
- image: url(:/files/remove.png)
-}
-
-QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal
-{
- background: none;
-}
-
diff --git a/examples/embedded/styleexample/main.cpp b/examples/embedded/styleexample/main.cpp
deleted file mode 100644
index 2a7577e845..0000000000
--- a/examples/embedded/styleexample/main.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-
-#include "stylewidget.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Q_INIT_RESOURCE(styleexample);
-
- app.setApplicationName("style");
- app.setOrganizationName("QtProject");
- app.setOrganizationDomain("www.qt-project.org");
-
- StyleWidget widget;
- widget.showFullScreen();
-
- return app.exec();
-}
-
diff --git a/examples/embedded/styleexample/styleexample.pro b/examples/embedded/styleexample/styleexample.pro
deleted file mode 100644
index 8f29203df2..0000000000
--- a/examples/embedded/styleexample/styleexample.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-QT += widgets
-
-HEADERS += stylewidget.h
-FORMS += stylewidget.ui
-SOURCES += main.cpp stylewidget.cpp
-RESOURCES += styleexample.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/embedded/styleexample
-INSTALLS += target
diff --git a/examples/embedded/styleexample/styleexample.qrc b/examples/embedded/styleexample/styleexample.qrc
deleted file mode 100644
index 96237d4203..0000000000
--- a/examples/embedded/styleexample/styleexample.qrc
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
- <file>files/add.png</file>
- <file>files/blue.qss</file>
- <file>files/khaki.qss</file>
- <file>files/nostyle.qss</file>
- <file>files/transparent.qss</file>
- <file>files/application.qss</file>
- <file>files/nature_1.jpg</file>
- <file>files/remove.png</file>
-</qresource>
-</RCC>
-
diff --git a/examples/embedded/styleexample/stylewidget.cpp b/examples/embedded/styleexample/stylewidget.cpp
deleted file mode 100644
index 5b1eab4d12..0000000000
--- a/examples/embedded/styleexample/stylewidget.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-#include <QString>
-#include <QFile>
-
-#include "stylewidget.h"
-
-
-
-StyleWidget::StyleWidget(QWidget *parent)
- : QFrame(parent)
-{
- m_ui.setupUi(this);
-}
-
-
-void StyleWidget::on_close_clicked()
-{
- close();
-}
-
-void StyleWidget::on_blueStyle_clicked()
-{
- QFile styleSheet(":/files/blue.qss");
-
- if (!styleSheet.open(QIODevice::ReadOnly)) {
- qWarning("Unable to open :/files/blue.qss");
- return;
- }
-
- qApp->setStyleSheet(styleSheet.readAll());
-}
-
-void StyleWidget::on_khakiStyle_clicked()
-{
- QFile styleSheet(":/files/khaki.qss");
-
- if (!styleSheet.open(QIODevice::ReadOnly)) {
- qWarning("Unable to open :/files/khaki.qss");
- return;
- }
-
- qApp->setStyleSheet(styleSheet.readAll());
-}
-
-
-void StyleWidget::on_noStyle_clicked()
-{
- QFile styleSheet(":/files/nostyle.qss");
-
- if (!styleSheet.open(QIODevice::ReadOnly)) {
- qWarning("Unable to open :/files/nostyle.qss");
- return;
- }
-
- qApp->setStyleSheet(styleSheet.readAll());
-}
-
-
-void StyleWidget::on_transparentStyle_clicked()
-{
- QFile styleSheet(":/files/transparent.qss");
-
- if (!styleSheet.open(QIODevice::ReadOnly)) {
- qWarning("Unable to open :/files/transparent.qss");
- return;
- }
-
- qApp->setStyleSheet(styleSheet.readAll());
-}
-
-
-
diff --git a/examples/embedded/styleexample/stylewidget.h b/examples/embedded/styleexample/stylewidget.h
deleted file mode 100644
index 739830a74d..0000000000
--- a/examples/embedded/styleexample/stylewidget.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#ifndef STYLEWIDGET_H
-#define STYLEWIDGET_H
-
-#include <QFrame>
-
-#include "ui_stylewidget.h"
-
-class StyleWidget : public QFrame
-{
- Q_OBJECT
-public:
- StyleWidget(QWidget *parent = nullptr);
-
-private:
- Ui_StyleWidget m_ui;
-
-private slots:
- void on_close_clicked();
- void on_blueStyle_clicked();
- void on_khakiStyle_clicked();
- void on_noStyle_clicked();
- void on_transparentStyle_clicked();
-};
-
-#endif
diff --git a/examples/embedded/styleexample/stylewidget.ui b/examples/embedded/styleexample/stylewidget.ui
deleted file mode 100644
index ebe2961ec6..0000000000
--- a/examples/embedded/styleexample/stylewidget.ui
+++ /dev/null
@@ -1,417 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>StyleWidget</class>
- <widget class="QWidget" name="StyleWidget">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>184</width>
- <height>245</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0" colspan="2">
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>Styles</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_2">
- <property name="margin">
- <number>4</number>
- </property>
- <property name="spacing">
- <number>4</number>
- </property>
- <item row="0" column="0">
- <widget class="QPushButton" name="transparentStyle">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <property name="text">
- <string>Transp.</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>false</bool>
- </property>
- <property name="autoExclusive">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QPushButton" name="blueStyle">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <property name="text">
- <string>Blue</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>false</bool>
- </property>
- <property name="autoExclusive">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QPushButton" name="khakiStyle">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <property name="text">
- <string>Khaki</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>false</bool>
- </property>
- <property name="autoExclusive">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QPushButton" name="noStyle">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <property name="text">
- <string>None</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- <property name="autoExclusive">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item row="1" column="0" colspan="2">
- <spacer name="verticalSpacer_3">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="2" column="0" colspan="2">
- <layout class="QHBoxLayout" name="horizontalLayout">
- <property name="margin">
- <number>4</number>
- </property>
- <item>
- <widget class="QLabel" name="label">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Value:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="spinBox">
- <property name="focusPolicy">
- <enum>Qt::WheelFocus</enum>
- </property>
- <property name="alignment">
- <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
- </property>
- <property name="keyboardTracking">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="3" column="0">
- <widget class="QScrollBar" name="horizontalScrollBar">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>24</height>
- </size>
- </property>
- <property name="focusPolicy">
- <enum>Qt::TabFocus</enum>
- </property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QScrollBar" name="horizontalScrollBar_2">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>24</height>
- </size>
- </property>
- <property name="focusPolicy">
- <enum>Qt::TabFocus</enum>
- </property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QPushButton" name="pushButton_2">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <property name="text">
- <string>Show</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- <property name="flat">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="4" column="1">
- <widget class="QPushButton" name="pushButton">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <property name="text">
- <string>Enable</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- <property name="flat">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="5" column="0" colspan="2">
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="6" column="0">
- <spacer>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="6" column="1">
- <widget class="QPushButton" name="close">
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <property name="text">
- <string>Close</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources>
- <include location="styleexample.qrc"/>
- </resources>
- <connections>
- <connection>
- <sender>horizontalScrollBar</sender>
- <signal>valueChanged(int)</signal>
- <receiver>horizontalScrollBar_2</receiver>
- <slot>setValue(int)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>84</x>
- <y>147</y>
- </hint>
- <hint type="destinationlabel">
- <x>166</x>
- <y>147</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>horizontalScrollBar_2</sender>
- <signal>valueChanged(int)</signal>
- <receiver>horizontalScrollBar</receiver>
- <slot>setValue(int)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>166</x>
- <y>147</y>
- </hint>
- <hint type="destinationlabel">
- <x>84</x>
- <y>147</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>pushButton</sender>
- <signal>clicked(bool)</signal>
- <receiver>horizontalScrollBar_2</receiver>
- <slot>setEnabled(bool)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>166</x>
- <y>175</y>
- </hint>
- <hint type="destinationlabel">
- <x>166</x>
- <y>147</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>pushButton_2</sender>
- <signal>clicked(bool)</signal>
- <receiver>horizontalScrollBar</receiver>
- <slot>setVisible(bool)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>84</x>
- <y>175</y>
- </hint>
- <hint type="destinationlabel">
- <x>84</x>
- <y>147</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>spinBox</sender>
- <signal>valueChanged(int)</signal>
- <receiver>horizontalScrollBar_2</receiver>
- <slot>setValue(int)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>166</x>
- <y>115</y>
- </hint>
- <hint type="destinationlabel">
- <x>166</x>
- <y>147</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>horizontalScrollBar_2</sender>
- <signal>valueChanged(int)</signal>
- <receiver>spinBox</receiver>
- <slot>setValue(int)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>132</x>
- <y>132</y>
- </hint>
- <hint type="destinationlabel">
- <x>135</x>
- <y>110</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/examples/examples.pro b/examples/examples.pro
index fe6c6dc7d4..87f00ca060 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -2,9 +2,7 @@ TEMPLATE = subdirs
CONFIG += no_docs_target
SUBDIRS = \
- corelib \
- embedded \
- qpa
+ corelib
!contains(TEMPLATE, "vc.*") { # QTBUG-91033
qtHaveModule(dbus): SUBDIRS += dbus
diff --git a/examples/gui/CMakeLists.txt b/examples/gui/CMakeLists.txt
index 8eda006a11..afc52ac3fa 100644
--- a/examples/gui/CMakeLists.txt
+++ b/examples/gui/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Gui)
return()
diff --git a/examples/gui/doc/src/rasterwindow.qdoc b/examples/gui/doc/src/rasterwindow.qdoc
index 4458f12782..d30b4d7643 100644
--- a/examples/gui/doc/src/rasterwindow.qdoc
+++ b/examples/gui/doc/src/rasterwindow.qdoc
@@ -4,6 +4,7 @@
/*!
\example rasterwindow
\title Raster Window Example
+ \examplecategory {Graphics}
\brief This example shows how to create a minimal QWindow based
application using QPainter for rendering.
diff --git a/examples/gui/doc/src/rhiwindow.qdoc b/examples/gui/doc/src/rhiwindow.qdoc
index e3c6b83c16..3ee33c8002 100644
--- a/examples/gui/doc/src/rhiwindow.qdoc
+++ b/examples/gui/doc/src/rhiwindow.qdoc
@@ -4,6 +4,7 @@
/*!
\example rhiwindow
\title RHI Window Example
+ \examplecategory {Graphics}
\brief This example shows how to create a minimal QWindow-based
application using QRhi.
@@ -426,6 +427,11 @@
QRhiShaderResourceBindings, continue to be valid all the time. It is only
the underlying native resources that come and go over time.
+ Note also that we set a device pixel ratio on the image that matches
+ the window that we're drawing into. This ensures that the drawing code
+ can be DPR-agnostic, producing the same layout regardless of the DPR,
+ while also taking advantage of the additional pixels for improved fidelity.
+
\snippet rhiwindow/rhiwindow.cpp ensure-texture
Once a QImage is generated and the QPainter-based drawing into it has
diff --git a/examples/gui/rasterwindow/CMakeLists.txt b/examples/gui/rasterwindow/CMakeLists.txt
index 1a7878cc0a..7fb00895c9 100644
--- a/examples/gui/rasterwindow/CMakeLists.txt
+++ b/examples/gui/rasterwindow/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(rasterwindow LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/gui/rasterwindow")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(rasterwindow PRIVATE
)
install(TARGETS rasterwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET rasterwindow
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/gui/rhiwindow/CMakeLists.txt b/examples/gui/rhiwindow/CMakeLists.txt
index 3c50add134..49b36286ee 100644
--- a/examples/gui/rhiwindow/CMakeLists.txt
+++ b/examples/gui/rhiwindow/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2023 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(rhiwindow LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/gui/rhiwindow")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui)
qt_standard_project_setup()
@@ -53,7 +47,14 @@ qt_add_resources(rhiwindow "rhiwindow"
)
install(TARGETS rhiwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET rhiwindow
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/gui/rhiwindow/main.cpp b/examples/gui/rhiwindow/main.cpp
index c6d9ce5669..37977e3a34 100644
--- a/examples/gui/rhiwindow/main.cpp
+++ b/examples/gui/rhiwindow/main.cpp
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
// Use platform-specific defaults when no command-line arguments given.
#if defined(Q_OS_WIN)
graphicsApi = QRhi::D3D11;
-#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+#elif QT_CONFIG(metal)
graphicsApi = QRhi::Metal;
#elif QT_CONFIG(vulkan)
graphicsApi = QRhi::Vulkan;
@@ -52,10 +52,20 @@ int main(int argc, char **argv)
graphicsApi = QRhi::Metal;
//! [api-setup]
- // For OpenGL.
+ // For OpenGL, to ensure there is a depth/stencil buffer for the window.
+ // With other APIs this is under the application's control (QRhiRenderBuffer etc.)
+ // and so no special setup is needed for those.
QSurfaceFormat fmt;
fmt.setDepthBufferSize(24);
fmt.setStencilBufferSize(8);
+ // Special case macOS to allow using OpenGL there.
+ // (the default Metal is the recommended approach, though)
+ // gl_VertexID is a GLSL 130 feature, and so the default OpenGL 2.1 context
+ // we get on macOS is not sufficient.
+#ifdef Q_OS_MACOS
+ fmt.setVersion(4, 1);
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
+#endif
QSurfaceFormat::setDefaultFormat(fmt);
// For Vulkan.
diff --git a/examples/gui/rhiwindow/rhiwindow.cpp b/examples/gui/rhiwindow/rhiwindow.cpp
index 5022244b86..3ae6faa802 100644
--- a/examples/gui/rhiwindow/rhiwindow.cpp
+++ b/examples/gui/rhiwindow/rhiwindow.cpp
@@ -146,7 +146,7 @@ void RhiWindow::init()
}
#endif
-#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+#if QT_CONFIG(metal)
if (m_graphicsApi == QRhi::Metal) {
QRhiMetalInitParams params;
m_rhi.reset(QRhi::create(QRhi::Metal, &params));
@@ -281,17 +281,18 @@ void HelloWindow::ensureFullscreenTexture(const QSize &pixelSize, QRhiResourceUp
m_texture->create();
QImage image(pixelSize, QImage::Format_RGBA8888_Premultiplied);
+ image.setDevicePixelRatio(devicePixelRatio());
//! [ensure-texture]
QPainter painter(&image);
- painter.fillRect(QRectF(QPointF(0, 0), pixelSize), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f));
+ painter.fillRect(QRectF(QPointF(0, 0), size()), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f));
painter.setPen(Qt::transparent);
painter.setBrush({ QGradient(QGradient::DeepBlue) });
- painter.drawRoundedRect(QRectF(QPointF(20, 20), pixelSize - QSize(40, 40)), 16, 16);
+ painter.drawRoundedRect(QRectF(QPointF(20, 20), size() - QSize(40, 40)), 16, 16);
painter.setPen(Qt::black);
QFont font;
- font.setPixelSize(0.05 * qMin(pixelSize.width(), pixelSize.height()));
+ font.setPixelSize(0.05 * qMin(width(), height()));
painter.setFont(font);
- painter.drawText(QRectF(QPointF(60, 60), pixelSize - QSize(120, 120)), 0,
+ painter.drawText(QRectF(QPointF(60, 60), size() - QSize(120, 120)), 0,
QLatin1String("Rendering with QRhi to a resizable QWindow.\nThe 3D API is %1.\nUse the command-line options to choose a different API.")
.arg(graphicsApiName()));
painter.end();
diff --git a/examples/network/CMakeLists.txt b/examples/network/CMakeLists.txt
index 4e19a2dffd..6222bb7c8b 100644
--- a/examples/network/CMakeLists.txt
+++ b/examples/network/CMakeLists.txt
@@ -1,10 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Network)
return()
endif()
-if(NOT INTEGRITY)
+if(NOT INTEGRITY AND NOT ANDROID)
qt_internal_add_example(dnslookup)
endif()
if(TARGET Qt6::Widgets)
@@ -18,6 +18,7 @@ if(TARGET Qt6::Widgets)
qt_internal_add_example(multicastsender)
qt_internal_add_example(fortuneclient)
qt_internal_add_example(fortuneserver)
+ qt_internal_add_example(rsslisting)
endif()
if(QT_FEATURE_processenvironment AND TARGET Qt6::Widgets)
qt_internal_add_example(network-chat)
diff --git a/examples/network/blockingfortuneclient/CMakeLists.txt b/examples/network/blockingfortuneclient/CMakeLists.txt
index cfcb03af2d..de010f3805 100644
--- a/examples/network/blockingfortuneclient/CMakeLists.txt
+++ b/examples/network/blockingfortuneclient/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(blockingfortuneclient LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/blockingfortuneclient")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(blockingfortuneclient PRIVATE
)
install(TARGETS blockingfortuneclient
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET blockingfortuneclient
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/broadcastreceiver/CMakeLists.txt b/examples/network/broadcastreceiver/CMakeLists.txt
index 2e694c7a3f..fca4b8d48e 100644
--- a/examples/network/broadcastreceiver/CMakeLists.txt
+++ b/examples/network/broadcastreceiver/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(broadcastreceiver LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/broadcastreceiver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(broadcastreceiver PRIVATE
)
install(TARGETS broadcastreceiver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET broadcastreceiver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/broadcastsender/CMakeLists.txt b/examples/network/broadcastsender/CMakeLists.txt
index bf010463a8..447fcd5425 100644
--- a/examples/network/broadcastsender/CMakeLists.txt
+++ b/examples/network/broadcastsender/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(broadcastsender LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/broadcastsender")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(broadcastsender PRIVATE
)
install(TARGETS broadcastsender
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET broadcastsender
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/dnslookup/CMakeLists.txt b/examples/network/dnslookup/CMakeLists.txt
index e90cdaff2d..b1baef23d9 100644
--- a/examples/network/dnslookup/CMakeLists.txt
+++ b/examples/network/dnslookup/CMakeLists.txt
@@ -1,15 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(dnslookup LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/dnslookup")
-
find_package(Qt6 REQUIRED COMPONENTS Core Network)
qt_standard_project_setup()
@@ -24,7 +22,14 @@ target_link_libraries(dnslookup PRIVATE
)
install(TARGETS dnslookup
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET dnslookup
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp
index bfcd60813b..9e74ddcf42 100644
--- a/examples/network/dnslookup/dnslookup.cpp
+++ b/examples/network/dnslookup/dnslookup.cpp
@@ -80,7 +80,7 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, DnsQuery *qu
if (query->nameServer.isNull()
|| query->nameServer.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol) {
return { Status::Error,
- u"Bad nameserver address: %1"_qs.arg(nameserver) };
+ u"Bad nameserver address: %1"_s.arg(nameserver) };
}
}
@@ -89,14 +89,14 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, DnsQuery *qu
if (std::optional<QDnsLookup::Type> type = typeFromParameter(typeParameter))
query->type = *type;
else
- return { Status::Error, u"Bad record type: %1"_qs.arg(typeParameter) };
+ return { Status::Error, u"Bad record type: %1"_s.arg(typeParameter) };
}
const QStringList positionalArguments = parser.positionalArguments();
if (positionalArguments.isEmpty())
- return { Status::Error, u"Argument 'name' missing."_qs };
+ return { Status::Error, u"Argument 'name' missing."_s };
if (positionalArguments.size() > 1)
- return { Status::Error, u"Several 'name' arguments specified."_qs };
+ return { Status::Error, u"Several 'name' arguments specified."_s };
query->name = positionalArguments.first();
return { Status::Ok };
@@ -203,7 +203,7 @@ int main(int argc, char *argv[])
case Status::Ok:
break;
case Status::Error:
- std::fputs(qPrintable(parseResult.errorString.value_or(u"Unknown error occurred"_qs)),
+ std::fputs(qPrintable(parseResult.errorString.value_or(u"Unknown error occurred"_s)),
stderr);
std::fputs("\n\n", stderr);
std::fputs(qPrintable(parser.helpText()), stderr);
diff --git a/examples/network/doc/images/dnslookup-example.webp b/examples/network/doc/images/dnslookup-example.webp
new file mode 100644
index 0000000000..c835cf1af3
--- /dev/null
+++ b/examples/network/doc/images/dnslookup-example.webp
Binary files differ
diff --git a/examples/network/doc/images/multi-stream-client-example.webp b/examples/network/doc/images/multi-stream-client-example.webp
new file mode 100644
index 0000000000..6ec651ae9e
--- /dev/null
+++ b/examples/network/doc/images/multi-stream-client-example.webp
Binary files differ
diff --git a/examples/network/doc/images/multi-stream-server-example.webp b/examples/network/doc/images/multi-stream-server-example.webp
new file mode 100644
index 0000000000..95610e7267
--- /dev/null
+++ b/examples/network/doc/images/multi-stream-server-example.webp
Binary files differ
diff --git a/examples/network/doc/images/network-chat-example.png b/examples/network/doc/images/network-chat-example.png
deleted file mode 100644
index 949bb07d87..0000000000
--- a/examples/network/doc/images/network-chat-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/doc/images/network-chat-example.webp b/examples/network/doc/images/network-chat-example.webp
new file mode 100644
index 0000000000..9b8cc1fd8a
--- /dev/null
+++ b/examples/network/doc/images/network-chat-example.webp
Binary files differ
diff --git a/examples/corelib/serialization/rsslisting/doc/images/rsslisting.png b/examples/network/doc/images/rsslisting.png
index 0b05375f93..0b05375f93 100644
--- a/examples/corelib/serialization/rsslisting/doc/images/rsslisting.png
+++ b/examples/network/doc/images/rsslisting.png
Binary files differ
diff --git a/examples/network/doc/images/securesocketclient-example.webp b/examples/network/doc/images/securesocketclient-example.webp
new file mode 100644
index 0000000000..658f93d053
--- /dev/null
+++ b/examples/network/doc/images/securesocketclient-example.webp
Binary files differ
diff --git a/examples/network/doc/images/securesocketclient.png b/examples/network/doc/images/securesocketclient.png
deleted file mode 100644
index 8736cbc264..0000000000
--- a/examples/network/doc/images/securesocketclient.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/doc/images/securesocketclient2.png b/examples/network/doc/images/securesocketclient2.png
deleted file mode 100644
index 23db851e61..0000000000
--- a/examples/network/doc/images/securesocketclient2.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/doc/images/torrent-example.png b/examples/network/doc/images/torrent-example.png
index 1032716e04..485bc7f719 100644
--- a/examples/network/doc/images/torrent-example.png
+++ b/examples/network/doc/images/torrent-example.png
Binary files differ
diff --git a/examples/network/doc/src/blockingfortuneclient.qdoc b/examples/network/doc/src/blockingfortuneclient.qdoc
index cd7a8e4c9a..ec99447b4b 100644
--- a/examples/network/doc/src/blockingfortuneclient.qdoc
+++ b/examples/network/doc/src/blockingfortuneclient.qdoc
@@ -109,7 +109,7 @@
Now we can create a QDataStream object, passing the socket to
QDataStream's constructor, and as in the other client examples we set
- the stream protocol version to QDataStream::Qt_4_0.
+ the stream protocol version to QDataStream::Qt_6_5.
\snippet blockingfortuneclient/fortunethread.cpp 12
diff --git a/examples/network/doc/src/broadcastreceiver.qdoc b/examples/network/doc/src/broadcastreceiver.qdoc
index 0a0531dd9e..cb134c699d 100644
--- a/examples/network/doc/src/broadcastreceiver.qdoc
+++ b/examples/network/doc/src/broadcastreceiver.qdoc
@@ -3,7 +3,9 @@
/*!
\example broadcastreceiver
- \title Broadcast Receiver Example
+ \title Broadcast Receiver
+ \examplecategory {Networking}
+ \meta tags {network,broadcast,udp}
\ingroup examples-network
\brief Demonstrates how to receive information broadcasted over a local network.
diff --git a/examples/network/doc/src/broadcastsender.qdoc b/examples/network/doc/src/broadcastsender.qdoc
index 675482c6d2..d02b179b77 100644
--- a/examples/network/doc/src/broadcastsender.qdoc
+++ b/examples/network/doc/src/broadcastsender.qdoc
@@ -3,7 +3,9 @@
/*!
\example broadcastsender
- \title Broadcast Sender Example
+ \title Broadcast Sender
+ \examplecategory {Networking}
+ \meta tags {network,broadcast,udp}
\ingroup examples-network
\brief Demonstrates how to broadcast information to multiple clients on a local network.
diff --git a/examples/network/doc/src/dnslookup.qdoc b/examples/network/doc/src/dnslookup.qdoc
new file mode 100644
index 0000000000..0a5a69f70a
--- /dev/null
+++ b/examples/network/doc/src/dnslookup.qdoc
@@ -0,0 +1,17 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example dnslookup
+ \title DNS lookup
+ \examplecategory {Networking}
+ \meta tags {network,dns,command line parser,command line,console}
+ \ingroup examples-network
+ \brief Demonstrates how to lookup a host name using QDnsLookup.
+
+ This example uses QDnsLookup to demonstrate how to look up a host
+ name and print the results on the command line. As well as how you can
+ use QCommandLineParser to parse command line arguments.
+
+ \image dnslookup-example.webp
+*/
diff --git a/examples/network/doc/src/fortuneclient.qdoc b/examples/network/doc/src/fortuneclient.qdoc
index c22641940c..054937e893 100644
--- a/examples/network/doc/src/fortuneclient.qdoc
+++ b/examples/network/doc/src/fortuneclient.qdoc
@@ -61,7 +61,7 @@
The protocol is based on QDataStream, so we set the stream device to the
newly created socket. We then explicitly set the protocol version of the
- stream to QDataStream::Qt_4_0 to ensure that we're using the same version
+ stream to QDataStream::Qt_6_5 to ensure that we're using the same version
as the fortune server, no matter which version of Qt the client and
server use.
diff --git a/examples/network/doc/src/http.qdoc b/examples/network/doc/src/http.qdoc
index 0dcaffd42b..c155997394 100644
--- a/examples/network/doc/src/http.qdoc
+++ b/examples/network/doc/src/http.qdoc
@@ -4,6 +4,7 @@
/*!
\example http
\examplecategory {Networking}
+ \examplecategory {Web Technologies}
\meta tags {http,network,https,proxy}
\title HTTP Client
\ingroup examples-network
diff --git a/examples/network/doc/src/multistreamclient.qdoc b/examples/network/doc/src/multistreamclient.qdoc
new file mode 100644
index 0000000000..bb70eac741
--- /dev/null
+++ b/examples/network/doc/src/multistreamclient.qdoc
@@ -0,0 +1,15 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example multistreamclient
+ \title Multi-stream Client
+ \examplecategory {Networking}
+ \meta tags {network,sctp}
+ \ingroup examples-network
+ \brief Demonstrates how to use SCTP on the client side.
+
+ This example demonstrates how to use SCTP, with multiple channels,
+ to interact with other clients through a server.
+ \image multi-stream-client-example.webp
+*/
diff --git a/examples/network/doc/src/multistreamserver.qdoc b/examples/network/doc/src/multistreamserver.qdoc
new file mode 100644
index 0000000000..9e498be3c9
--- /dev/null
+++ b/examples/network/doc/src/multistreamserver.qdoc
@@ -0,0 +1,16 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example multistreamserver
+ \title Multi-stream Server
+ \examplecategory {Networking}
+ \meta tags {network,sctp}
+ \ingroup examples-network
+ \brief Demonstrates how to use SCTP on the server side.
+
+ This example demonstrates how to use SCTP, with multiple channels,
+ on the server side, receiving multiple connections and sending
+ messages to connected clients.
+ \image multi-stream-server-example.webp
+*/
diff --git a/examples/network/doc/src/network-chat.qdoc b/examples/network/doc/src/network-chat.qdoc
index da12f5f6f0..6a8f0024e3 100644
--- a/examples/network/doc/src/network-chat.qdoc
+++ b/examples/network/doc/src/network-chat.qdoc
@@ -12,5 +12,5 @@
This example uses broadcasting with QUdpSocket and QNetworkInterface to
discover its peers.
- \image network-chat-example.png
+ \image network-chat-example.webp
*/
diff --git a/examples/corelib/serialization/rsslisting/doc/src/rsslisting.qdoc b/examples/network/doc/src/rsslisting.qdoc
index b86fab1e1b..a1e91932f6 100644
--- a/examples/corelib/serialization/rsslisting/doc/src/rsslisting.qdoc
+++ b/examples/network/doc/src/rsslisting.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
- \example serialization/rsslisting
+ \example rsslisting
\examplecategory {Networking}
\meta tag {serialization}
\title A minimal RSS listing application
@@ -24,18 +24,18 @@
the parsed content may start in one chunk of data but not be completed until
a later chunk, requiring the parser to retain state between calls.
- \image rsslisting.cpp
+ \image rsslisting.png
The main program is fairly minimal. It simply instantiates a \l QApplication
and the \c RSSListing widget, shows the latter and hands over control to the
former. For the sake of illustration, it gives the widget the Qt blog's URL
as default value for the resource to check.
- \snippet serialization/rsslisting/main.cpp 0
+ \snippet rsslisting/main.cpp 0
\section1 The RSSListing class
- \snippet serialization/rsslisting/rsslisting.h 0
+ \snippet rsslisting/rsslisting.h 0
The widget itself provides a simple user interface for specifying the URL to
fetch and, once available updates are displayed, controlling the downloading
@@ -51,7 +51,7 @@
\section2 Construction
- \snippet serialization/rsslisting/rsslisting.cpp setup
+ \snippet rsslisting/rsslisting.cpp setup
The constructor sets up the assorted components of the widget and connects
their various signals to the slots it shall use to handle them.
@@ -69,7 +69,7 @@
\section2 The slots
- \snippet serialization/rsslisting/rsslisting.cpp slots
+ \snippet rsslisting/rsslisting.cpp slots
All slots are kept simple by delegating any hard work to private methods.
@@ -94,7 +94,7 @@
\section2 The get() method
- \snippet serialization/rsslisting/rsslisting.cpp get
+ \snippet rsslisting/rsslisting.cpp get
The private \c get() method is used by the \c fetch() slot to initiate an
HTTP GET request. It first clears the XML stream reader and, if a reply is
@@ -106,7 +106,7 @@
\section2 The parseXml() method
- \snippet serialization/rsslisting/rsslisting.cpp parse
+ \snippet rsslisting/rsslisting.cpp parse
When data is received, and thus made available to the XML stream reader, \c
parseXml() reads from the XML stream, checking for \c item elements and,
diff --git a/examples/network/doc/src/securesocketclient.qdoc b/examples/network/doc/src/securesocketclient.qdoc
index b0272ca1f0..7ff3ae6da5 100644
--- a/examples/network/doc/src/securesocketclient.qdoc
+++ b/examples/network/doc/src/securesocketclient.qdoc
@@ -3,7 +3,9 @@
/*!
\example securesocketclient
- \title Secure Socket Client Example
+ \title Secure Socket Client
+ \examplecategory {Networking}
+ \meta tags {tcp,network,tls,ssl}
\ingroup examples-network
\brief Demonstrates how to communicate over an encrypted (SSL) connection.
@@ -11,6 +13,5 @@
encrypted connection, deal with authenticity problems, and display security
and certificate information.
- \image securesocketclient.png
- \image securesocketclient2.png
+ \image securesocketclient-example.webp
*/
diff --git a/examples/network/doc/src/secureudpclient.qdoc b/examples/network/doc/src/secureudpclient.qdoc
index 0f673b0a66..b7a51c0814 100644
--- a/examples/network/doc/src/secureudpclient.qdoc
+++ b/examples/network/doc/src/secureudpclient.qdoc
@@ -4,6 +4,7 @@
/*!
\example secureudpclient
\title DTLS client
+ \examplecategory {Networking}
\ingroup examples-network
\brief This example demonstrates how to implement client-side DTLS connections.
diff --git a/examples/network/doc/src/secureudpserver.qdoc b/examples/network/doc/src/secureudpserver.qdoc
index f98ee74164..3d224d91bc 100644
--- a/examples/network/doc/src/secureudpserver.qdoc
+++ b/examples/network/doc/src/secureudpserver.qdoc
@@ -4,6 +4,7 @@
/*!
\example secureudpserver
\title DTLS server
+ \examplecategory {Networking}
\ingroup examples-network
\brief This examples demonstrates how to implement a simple DTLS server.
diff --git a/examples/network/doc/src/torrent.qdoc b/examples/network/doc/src/torrent.qdoc
index 301be1863a..124a697293 100644
--- a/examples/network/doc/src/torrent.qdoc
+++ b/examples/network/doc/src/torrent.qdoc
@@ -4,6 +4,7 @@
/*!
\example torrent
\title Torrent Example
+ \examplecategory {Networking}
\ingroup examples-network
\brief Demonstrates complex TCP/IP operations.
diff --git a/examples/network/fortuneclient/CMakeLists.txt b/examples/network/fortuneclient/CMakeLists.txt
index 3546aca929..ba55939b37 100644
--- a/examples/network/fortuneclient/CMakeLists.txt
+++ b/examples/network/fortuneclient/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(fortuneclient LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/fortuneclient")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(fortuneclient PRIVATE
)
install(TARGETS fortuneclient
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET fortuneclient
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/fortuneserver/CMakeLists.txt b/examples/network/fortuneserver/CMakeLists.txt
index 8ed91f6bef..af51db6a5e 100644
--- a/examples/network/fortuneserver/CMakeLists.txt
+++ b/examples/network/fortuneserver/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(fortuneserver LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/fortuneserver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(fortuneserver PRIVATE
)
install(TARGETS fortuneserver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET fortuneserver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/http/CMakeLists.txt b/examples/network/http/CMakeLists.txt
index 0592dfa8e2..705c3a0beb 100644
--- a/examples/network/http/CMakeLists.txt
+++ b/examples/network/http/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(http LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/http")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(http PRIVATE
)
install(TARGETS http
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET http
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/multicastreceiver/CMakeLists.txt b/examples/network/multicastreceiver/CMakeLists.txt
index 90feeb5b80..cb1139e69a 100644
--- a/examples/network/multicastreceiver/CMakeLists.txt
+++ b/examples/network/multicastreceiver/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(multicastreceiver LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/multicastreceiver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(multicastreceiver PRIVATE
)
install(TARGETS multicastreceiver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET multicastreceiver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/multicastsender/CMakeLists.txt b/examples/network/multicastsender/CMakeLists.txt
index 1598eae3cd..eb45b9f2fa 100644
--- a/examples/network/multicastsender/CMakeLists.txt
+++ b/examples/network/multicastsender/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(multicastsender LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/multicastsender")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(multicastsender PRIVATE
)
install(TARGETS multicastsender
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET multicastsender
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/multistreamclient/CMakeLists.txt b/examples/network/multistreamclient/CMakeLists.txt
index bb6f0d97a9..1226a4b3c7 100644
--- a/examples/network/multistreamclient/CMakeLists.txt
+++ b/examples/network/multistreamclient/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(multistreamclient LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/multistreamclient")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -36,7 +30,14 @@ target_link_libraries(multistreamclient PRIVATE
)
install(TARGETS multistreamclient
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET multistreamclient
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/multistreamserver/CMakeLists.txt b/examples/network/multistreamserver/CMakeLists.txt
index aedf2a4fc8..3f77506f70 100644
--- a/examples/network/multistreamserver/CMakeLists.txt
+++ b/examples/network/multistreamserver/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(multistreamserver LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/multistreamserver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -36,7 +30,14 @@ target_link_libraries(multistreamserver PRIVATE
)
install(TARGETS multistreamserver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET multistreamserver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/network-chat/CMakeLists.txt b/examples/network/network-chat/CMakeLists.txt
index dd3164a1e7..127a4c2fb5 100644
--- a/examples/network/network-chat/CMakeLists.txt
+++ b/examples/network/network-chat/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(network-chat LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/network-chat")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -40,7 +34,14 @@ target_link_libraries(network-chat PRIVATE
)
install(TARGETS network-chat
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET network-chat
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/network-chat/client.cpp b/examples/network/network-chat/client.cpp
index 54bde6cd03..c637224127 100644
--- a/examples/network/network-chat/client.cpp
+++ b/examples/network/network-chat/client.cpp
@@ -37,43 +37,35 @@ QString Client::nickName() const
+ ':' + QString::number(server.serverPort());
}
-bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const
+bool Client::hasConnection(const QByteArray &peerUniqueId) const
{
- auto [begin, end] = peers.equal_range(senderIp);
- if (begin == peers.constEnd())
- return false;
-
- if (senderPort == -1)
- return true;
-
- for (; begin != end; ++begin) {
- Connection *connection = *begin;
- if (connection->peerPort() == senderPort)
- return true;
- }
-
- return false;
+ return peers.contains(peerUniqueId);
}
void Client::newConnection(Connection *connection)
{
- connection->setGreetingMessage(peerManager->userName());
-
- connect(connection, &Connection::errorOccurred, this, &Client::connectionError);
- connect(connection, &Connection::disconnected, this, &Client::disconnected);
+ connection->setGreetingMessage(peerManager->userName(), peerManager->uniqueId());
connect(connection, &Connection::readyForUse, this, &Client::readyForUse);
+ connect(connection, &Connection::errorOccurred, connection, &QObject::deleteLater);
+ connect(connection, &Connection::disconnected, connection, &QObject::deleteLater);
}
void Client::readyForUse()
{
Connection *connection = qobject_cast<Connection *>(sender());
- if (!connection || hasConnection(connection->peerAddress(), connection->peerPort()))
+ if (!connection || hasConnection(connection->uniqueId())) {
+ if (connection) {
+ connection->disconnectFromHost();
+ connection->deleteLater();
+ }
return;
+ }
- connect(connection, &Connection::newMessage,
- this, &Client::newMessage);
+ connect(connection, &Connection::errorOccurred, this, &Client::connectionError);
+ connect(connection, &Connection::disconnected, this, &Client::disconnected);
+ connect(connection, &Connection::newMessage, this, &Client::newMessage);
- peers.insert(connection->peerAddress(), connection);
+ peers.insert(connection->uniqueId(), connection);
QString nick = connection->name();
if (!nick.isEmpty())
emit newParticipant(nick);
@@ -93,7 +85,7 @@ void Client::connectionError(QAbstractSocket::SocketError /* socketError */)
void Client::removeConnection(Connection *connection)
{
- if (peers.remove(connection->peerAddress(), connection) > 0) {
+ if (peers.remove(connection->uniqueId())) {
QString nick = connection->name();
if (!nick.isEmpty())
emit participantLeft(nick);
diff --git a/examples/network/network-chat/client.h b/examples/network/network-chat/client.h
index 55abd84c9e..a09d0c21f6 100644
--- a/examples/network/network-chat/client.h
+++ b/examples/network/network-chat/client.h
@@ -21,7 +21,7 @@ public:
void sendMessage(const QString &message);
QString nickName() const;
- bool hasConnection(const QHostAddress &senderIp, int senderPort = -1) const;
+ bool hasConnection(const QByteArray &peerUniqueId) const;
signals:
void newMessage(const QString &from, const QString &message);
@@ -39,7 +39,7 @@ private:
PeerManager *peerManager;
Server server;
- QMultiHash<QHostAddress, Connection *> peers;
+ QHash<QByteArray, Connection *> peers;
};
#endif
diff --git a/examples/network/network-chat/connection.cpp b/examples/network/network-chat/connection.cpp
index 414faa80a9..0f59cc91ed 100644
--- a/examples/network/network-chat/connection.cpp
+++ b/examples/network/network-chat/connection.cpp
@@ -21,7 +21,7 @@ static const int PingInterval = 5 * 1000;
* plaintext = { 0 => text }
* ping = { 1 => null }
* pong = { 2 => null }
- * greeting = { 3 => text }
+ * greeting = { 3 => { text, bytes } }
*/
Connection::Connection(QObject *parent)
@@ -48,7 +48,7 @@ Connection::Connection(qintptr socketDescriptor, QObject *parent)
Connection::~Connection()
{
- if (isGreetingMessageSent) {
+ if (isGreetingMessageSent && QAbstractSocket::state() != QAbstractSocket::UnconnectedState) {
// Indicate clean shutdown.
writer.endArray();
waitForBytesWritten(2000);
@@ -60,9 +60,15 @@ QString Connection::name() const
return username;
}
-void Connection::setGreetingMessage(const QString &message)
+void Connection::setGreetingMessage(const QString &message, const QByteArray &uniqueId)
{
greetingMessage = message;
+ localUniqueId = uniqueId;
+}
+
+QByteArray Connection::uniqueId() const
+{
+ return peerUniqueId;
}
bool Connection::sendMessage(const QString &message)
@@ -118,7 +124,29 @@ void Connection::processReadyRead()
reader.next();
} else {
// Current state: read command payload
- if (reader.isString()) {
+ if (currentDataType == Greeting) {
+ if (state == ReadingGreeting) {
+ if (!reader.isContainer() || !reader.isLengthKnown() || reader.length() != 2)
+ break; // protocol error
+ state = ProcessingGreeting;
+ reader.enterContainer();
+ }
+ if (state != ProcessingGreeting)
+ break; // protocol error
+ if (reader.isString()) {
+ auto r = reader.readString();
+ buffer += r.data;
+ } else if (reader.isByteArray()) {
+ auto r = reader.readByteArray();
+ peerUniqueId += r.data;
+ if (r.status == QCborStreamReader::EndOfString) {
+ reader.leaveContainer();
+ processGreeting();
+ }
+ }
+ if (state == ProcessingGreeting)
+ continue;
+ } else if (reader.isString()) {
auto r = reader.readString();
buffer += r.data;
if (r.status != QCborStreamReader::EndOfString)
@@ -126,7 +154,7 @@ void Connection::processReadyRead()
} else if (reader.isNull()) {
reader.next();
} else {
- break; // protocol error
+ break; // protocol error
}
// Next state: no command read
@@ -136,13 +164,7 @@ void Connection::processReadyRead()
transferTimerId = -1;
}
- if (state == ReadingGreeting) {
- if (currentDataType != Greeting)
- break; // protocol error
- processGreeting();
- } else {
- processData();
- }
+ processData();
}
}
@@ -172,7 +194,10 @@ void Connection::sendGreetingMessage()
writer.startMap(1);
writer.append(Greeting);
+ writer.startArray(2);
writer.append(greetingMessage);
+ writer.append(localUniqueId);
+ writer.endArray();
writer.endMap();
isGreetingMessageSent = true;
diff --git a/examples/network/network-chat/connection.h b/examples/network/network-chat/connection.h
index 77c116cf6b..4b063e7def 100644
--- a/examples/network/network-chat/connection.h
+++ b/examples/network/network-chat/connection.h
@@ -12,8 +12,6 @@
#include <QTcpSocket>
#include <QTimer>
-static const int MaxBufferSize = 1024000;
-
class Connection : public QTcpSocket
{
Q_OBJECT
@@ -22,6 +20,7 @@ public:
enum ConnectionState {
WaitingForGreeting,
ReadingGreeting,
+ ProcessingGreeting,
ReadyForUse
};
enum DataType {
@@ -37,9 +36,11 @@ public:
~Connection();
QString name() const;
- void setGreetingMessage(const QString &message);
+ void setGreetingMessage(const QString &message, const QByteArray &uniqueId);
bool sendMessage(const QString &message);
+ QByteArray uniqueId() const;
+
signals:
void readyForUse();
void newMessage(const QString &from, const QString &message);
@@ -64,6 +65,8 @@ private:
QTimer pingTimer;
QElapsedTimer pongTime;
QString buffer;
+ QByteArray localUniqueId;
+ QByteArray peerUniqueId;
ConnectionState state = WaitingForGreeting;
DataType currentDataType = Undefined;
int transferTimerId = -1;
diff --git a/examples/network/network-chat/peermanager.cpp b/examples/network/network-chat/peermanager.cpp
index da4210d85b..a70ed7da73 100644
--- a/examples/network/network-chat/peermanager.cpp
+++ b/examples/network/network-chat/peermanager.cpp
@@ -7,6 +7,7 @@
#include "peermanager.h"
#include <QNetworkInterface>
+#include <QUuid>
static const qint32 BroadcastInterval = 2000;
static const unsigned broadcastPort = 45000;
@@ -27,6 +28,11 @@ PeerManager::PeerManager(Client *client)
if (username.isEmpty())
username = "unknown";
+ // We generate a unique per-process identifier so we can avoid multiple
+ // connections to/from the same remote peer as well as ignore our own
+ // broadcasts.
+ localUniqueId = QUuid::createUuid().toByteArray();
+
updateAddresses();
broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress
@@ -49,6 +55,11 @@ QString PeerManager::userName() const
return username;
}
+QByteArray PeerManager::uniqueId() const
+{
+ return localUniqueId;
+}
+
void PeerManager::startBroadcasting()
{
broadcastTimer.start();
@@ -65,7 +76,7 @@ void PeerManager::sendBroadcastDatagram()
{
QCborStreamWriter writer(&datagram);
writer.startArray(2);
- writer.append(username);
+ writer.append(localUniqueId);
writer.append(serverPort);
writer.endArray();
}
@@ -92,6 +103,7 @@ void PeerManager::readBroadcastDatagram()
continue;
int senderServerPort;
+ QByteArray peerUniqueId;
{
// decode the datagram
QCborStreamReader reader(datagram);
@@ -101,10 +113,12 @@ void PeerManager::readBroadcastDatagram()
continue;
reader.enterContainer();
- if (reader.lastError() != QCborError::NoError || !reader.isString())
+ if (reader.lastError() != QCborError::NoError || !reader.isByteArray())
continue;
- while (reader.readString().status == QCborStreamReader::Ok) {
- // we don't actually need the username right now
+ auto r = reader.readByteArray();
+ while (r.status == QCborStreamReader::Ok) {
+ peerUniqueId = r.data;
+ r = reader.readByteArray();
}
if (reader.lastError() != QCborError::NoError || !reader.isUnsignedInteger())
@@ -112,10 +126,10 @@ void PeerManager::readBroadcastDatagram()
senderServerPort = reader.toInteger();
}
- if (isLocalHostAddress(senderIp) && senderServerPort == serverPort)
+ if (peerUniqueId == localUniqueId)
continue;
- if (!client->hasConnection(senderIp)) {
+ if (!client->hasConnection(peerUniqueId)) {
Connection *connection = new Connection(this);
emit newConnection(connection);
connection->connectToHost(senderIp, senderServerPort);
diff --git a/examples/network/network-chat/peermanager.h b/examples/network/network-chat/peermanager.h
index dadabd88aa..fff48540ea 100644
--- a/examples/network/network-chat/peermanager.h
+++ b/examples/network/network-chat/peermanager.h
@@ -22,6 +22,7 @@ public:
void setServerPort(int port);
QString userName() const;
+ QByteArray uniqueId() const;
void startBroadcasting();
bool isLocalHostAddress(const QHostAddress &address) const;
@@ -41,6 +42,7 @@ private:
QUdpSocket broadcastSocket;
QTimer broadcastTimer;
QString username;
+ QByteArray localUniqueId;
int serverPort = 0;
};
diff --git a/examples/network/network.pro b/examples/network/network.pro
index 7981560943..a0fc95dbf8 100644
--- a/examples/network/network.pro
+++ b/examples/network/network.pro
@@ -8,18 +8,16 @@ qtHaveModule(widgets) {
blockingfortuneclient \
broadcastreceiver \
broadcastsender \
+ fortuneclient \
+ fortuneserver \
http \
- threadedfortuneserver \
- torrent \
multicastreceiver \
- multicastsender
+ multicastsender \
+ rsslisting \
+ threadedfortuneserver \
+ torrent
qtConfig(processenvironment): SUBDIRS += network-chat
-
- SUBDIRS += \
- fortuneclient \
- fortuneserver
-
qtConfig(ssl): SUBDIRS += securesocketclient
qtConfig(dtls): SUBDIRS += secureudpserver secureudpclient
qtConfig(sctp): SUBDIRS += multistreamserver multistreamclient
diff --git a/examples/corelib/serialization/rsslisting/CMakeLists.txt b/examples/network/rsslisting/CMakeLists.txt
index 405a01ce56..58d9edcb92 100644
--- a/examples/corelib/serialization/rsslisting/CMakeLists.txt
+++ b/examples/network/rsslisting/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(rsslisting LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/serialization/rsslisting")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(rsslisting PRIVATE
)
install(TARGETS rsslisting
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET rsslisting
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/serialization/rsslisting/main.cpp b/examples/network/rsslisting/main.cpp
index 7a64db8a0c..7a64db8a0c 100644
--- a/examples/corelib/serialization/rsslisting/main.cpp
+++ b/examples/network/rsslisting/main.cpp
diff --git a/examples/corelib/serialization/rsslisting/rsslisting.cpp b/examples/network/rsslisting/rsslisting.cpp
index ed7c163c76..ed7c163c76 100644
--- a/examples/corelib/serialization/rsslisting/rsslisting.cpp
+++ b/examples/network/rsslisting/rsslisting.cpp
diff --git a/examples/corelib/serialization/rsslisting/rsslisting.h b/examples/network/rsslisting/rsslisting.h
index 499bc5d1d4..499bc5d1d4 100644
--- a/examples/corelib/serialization/rsslisting/rsslisting.h
+++ b/examples/network/rsslisting/rsslisting.h
diff --git a/examples/corelib/serialization/rsslisting/rsslisting.pro b/examples/network/rsslisting/rsslisting.pro
index 7619755b8f..aacbe3127f 100644
--- a/examples/corelib/serialization/rsslisting/rsslisting.pro
+++ b/examples/network/rsslisting/rsslisting.pro
@@ -4,5 +4,5 @@ QT += network widgets
requires(qtConfig(treewidget))
# install
-target.path = $$[QT_INSTALL_EXAMPLES]/corelib/serialization/rsslisting
+target.path = $$[QT_INSTALL_EXAMPLES]/network/rsslisting
INSTALLS += target
diff --git a/examples/network/securesocketclient/CMakeLists.txt b/examples/network/securesocketclient/CMakeLists.txt
index 642f87ea74..8066e5eba7 100644
--- a/examples/network/securesocketclient/CMakeLists.txt
+++ b/examples/network/securesocketclient/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(securesocketclient LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/securesocketclient")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -46,7 +40,14 @@ qt_add_resources(securesocketclient "securesocketclient"
)
install(TARGETS securesocketclient
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET securesocketclient
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/securesocketclient/certificateinfo.cpp b/examples/network/securesocketclient/certificateinfo.cpp
index 2d6a943d60..a5778d2e0a 100644
--- a/examples/network/securesocketclient/certificateinfo.cpp
+++ b/examples/network/securesocketclient/certificateinfo.cpp
@@ -39,19 +39,19 @@ void CertificateInfo::updateCertificateInfo(int index)
if (index >= 0 && index < certificateChain.size()) {
const QSslCertificate &cert = certificateChain.at(index);
QStringList lines;
- lines << tr("Organization: %1").arg(cert.subjectInfo(QSslCertificate::Organization).join(QLatin1Char(' ')))
- << tr("Subunit: %1").arg(cert.subjectInfo(QSslCertificate::OrganizationalUnitName).join(QLatin1Char(' ')))
- << tr("Country: %1").arg(cert.subjectInfo(QSslCertificate::CountryName).join(QLatin1Char(' ')))
- << tr("Locality: %1").arg(cert.subjectInfo(QSslCertificate::LocalityName).join(QLatin1Char(' ')))
- << tr("State/Province: %1").arg(cert.subjectInfo(QSslCertificate::StateOrProvinceName).join(QLatin1Char(' ')))
- << tr("Common Name: %1").arg(cert.subjectInfo(QSslCertificate::CommonName).join(QLatin1Char(' ')))
+ lines << tr("Organization: %1").arg(cert.subjectInfo(QSslCertificate::Organization).join(u' '))
+ << tr("Subunit: %1").arg(cert.subjectInfo(QSslCertificate::OrganizationalUnitName).join(u' '))
+ << tr("Country: %1").arg(cert.subjectInfo(QSslCertificate::CountryName).join(u' '))
+ << tr("Locality: %1").arg(cert.subjectInfo(QSslCertificate::LocalityName).join(u' '))
+ << tr("State/Province: %1").arg(cert.subjectInfo(QSslCertificate::StateOrProvinceName).join(u' '))
+ << tr("Common Name: %1").arg(cert.subjectInfo(QSslCertificate::CommonName).join(u' '))
<< QString()
- << tr("Issuer Organization: %1").arg(cert.issuerInfo(QSslCertificate::Organization).join(QLatin1Char(' ')))
- << tr("Issuer Unit Name: %1").arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName).join(QLatin1Char(' ')))
- << tr("Issuer Country: %1").arg(cert.issuerInfo(QSslCertificate::CountryName).join(QLatin1Char(' ')))
- << tr("Issuer Locality: %1").arg(cert.issuerInfo(QSslCertificate::LocalityName).join(QLatin1Char(' ')))
- << tr("Issuer State/Province: %1").arg(cert.issuerInfo(QSslCertificate::StateOrProvinceName).join(QLatin1Char(' ')))
- << tr("Issuer Common Name: %1").arg(cert.issuerInfo(QSslCertificate::CommonName).join(QLatin1Char(' ')));
+ << tr("Issuer Organization: %1").arg(cert.issuerInfo(QSslCertificate::Organization).join(u' '))
+ << tr("Issuer Unit Name: %1").arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName).join(u' '))
+ << tr("Issuer Country: %1").arg(cert.issuerInfo(QSslCertificate::CountryName).join(u' '))
+ << tr("Issuer Locality: %1").arg(cert.issuerInfo(QSslCertificate::LocalityName).join(u' '))
+ << tr("Issuer State/Province: %1").arg(cert.issuerInfo(QSslCertificate::StateOrProvinceName).join(u' '))
+ << tr("Issuer Common Name: %1").arg(cert.issuerInfo(QSslCertificate::CommonName).join(u' '));
for (const auto &line : lines)
form->certificateInfoView->addItem(line);
}
diff --git a/examples/network/securesocketclient/main.cpp b/examples/network/securesocketclient/main.cpp
index 5898bf0878..7a59e6f774 100644
--- a/examples/network/securesocketclient/main.cpp
+++ b/examples/network/securesocketclient/main.cpp
@@ -11,8 +11,6 @@ QT_REQUIRE_CONFIG(ssl);
int main(int argc, char **argv)
{
- Q_INIT_RESOURCE(securesocketclient);
-
QApplication app(argc, argv);
if (!QSslSocket::supportsSsl()) {
diff --git a/examples/network/securesocketclient/sslclient.cpp b/examples/network/securesocketclient/sslclient.cpp
index c21feaf473..413038ddd5 100644
--- a/examples/network/securesocketclient/sslclient.cpp
+++ b/examples/network/securesocketclient/sslclient.cpp
@@ -71,7 +71,7 @@ void SslClient::socketEncrypted()
const QSslCipher cipher = socket->sessionCipher();
const QString cipherInfo = QString("%1, %2 (%3/%4)").arg(cipher.authenticationMethod())
.arg(cipher.name()).arg(cipher.usedBits())
- .arg(cipher.supportedBits());;
+ .arg(cipher.supportedBits());
form->cipherLabel->setText(cipherInfo);
padLock->show();
}
diff --git a/examples/network/secureudpclient/CMakeLists.txt b/examples/network/secureudpclient/CMakeLists.txt
index 180bee5f21..53a8c1340e 100644
--- a/examples/network/secureudpclient/CMakeLists.txt
+++ b/examples/network/secureudpclient/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(secureudpclient LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/secureudpclient")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -34,7 +28,14 @@ target_link_libraries(secureudpclient PRIVATE
)
install(TARGETS secureudpclient
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET secureudpclient
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/secureudpserver/CMakeLists.txt b/examples/network/secureudpserver/CMakeLists.txt
index 767a71bb04..e92186b574 100644
--- a/examples/network/secureudpserver/CMakeLists.txt
+++ b/examples/network/secureudpserver/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(secureudpserver LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/secureudpserver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -34,7 +28,14 @@ target_link_libraries(secureudpserver PRIVATE
)
install(TARGETS secureudpserver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET secureudpserver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/threadedfortuneserver/CMakeLists.txt b/examples/network/threadedfortuneserver/CMakeLists.txt
index b67d10c828..8fc8cc416d 100644
--- a/examples/network/threadedfortuneserver/CMakeLists.txt
+++ b/examples/network/threadedfortuneserver/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(threadedfortuneserver LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/threadedfortuneserver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -34,7 +28,14 @@ target_link_libraries(threadedfortuneserver PRIVATE
)
install(TARGETS threadedfortuneserver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET threadedfortuneserver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/torrent/CMakeLists.txt b/examples/network/torrent/CMakeLists.txt
index 3a02f5def1..fbf974efef 100644
--- a/examples/network/torrent/CMakeLists.txt
+++ b/examples/network/torrent/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(torrent LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/torrent")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
@@ -44,14 +38,15 @@ target_link_libraries(torrent PRIVATE
# Resources:
set(icons_resource_files
- "icons/1downarrow.png"
- "icons/1uparrow.png"
- "icons/bottom.png"
- "icons/exit.png"
- "icons/peertopeer.png"
- "icons/player_pause.png"
- "icons/player_play.png"
- "icons/player_stop.png"
+ "icons/1downarrow.svg"
+ "icons/1uparrow.svg"
+ "icons/bottom.svg"
+ "icons/exit.svg"
+ "icons/peertopeer.svg"
+ "icons/player_pause.svg"
+ "icons/player_play.svg"
+ "icons/player_stop.svg"
+ "icons/about.svg"
)
qt_add_resources(torrent "icons"
@@ -62,7 +57,14 @@ qt_add_resources(torrent "icons"
)
install(TARGETS torrent
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET torrent
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/torrent/icons.qrc b/examples/network/torrent/icons.qrc
index 9541ef7600..5606275d92 100644
--- a/examples/network/torrent/icons.qrc
+++ b/examples/network/torrent/icons.qrc
@@ -1,12 +1,13 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
- <file>icons/peertopeer.png</file>
- <file>icons/1uparrow.png</file>
- <file>icons/1downarrow.png</file>
- <file>icons/bottom.png</file>
- <file>icons/player_pause.png</file>
- <file>icons/player_play.png</file>
- <file>icons/player_stop.png</file>
- <file>icons/exit.png</file>
-</qresource>
+<RCC>
+ <qresource prefix="/">
+ <file>icons/peertopeer.svg</file>
+ <file>icons/1uparrow.svg</file>
+ <file>icons/1downarrow.svg</file>
+ <file>icons/bottom.svg</file>
+ <file>icons/player_pause.svg</file>
+ <file>icons/player_play.svg</file>
+ <file>icons/player_stop.svg</file>
+ <file>icons/exit.svg</file>
+ <file>icons/about.svg</file>
+ </qresource>
</RCC>
diff --git a/examples/network/torrent/icons/1downarrow.png b/examples/network/torrent/icons/1downarrow.png
deleted file mode 100644
index 08403b82ba..0000000000
--- a/examples/network/torrent/icons/1downarrow.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/1downarrow.svg b/examples/network/torrent/icons/1downarrow.svg
new file mode 100644
index 0000000000..fc43085f59
--- /dev/null
+++ b/examples/network/torrent/icons/1downarrow.svg
@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M21.7071 7.29289C21.3166 6.90237 20.6834 6.90237 20.2929 7.29289L12 15.5858L3.70711 7.29289C3.31658 6.90237 2.68342 6.90237 2.29289 7.29289C1.90237 7.68342 1.90237 8.31658 2.29289 8.70711L11.2929 17.7071C11.6834 18.0976 12.3166 18.0976 12.7071 17.7071L21.7071 8.70711C22.0976 8.31658 22.0976 7.68342 21.7071 7.29289Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/network/torrent/icons/1uparrow.png b/examples/network/torrent/icons/1uparrow.png
deleted file mode 100644
index f044811787..0000000000
--- a/examples/network/torrent/icons/1uparrow.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/1uparrow.svg b/examples/network/torrent/icons/1uparrow.svg
new file mode 100644
index 0000000000..aaed789617
--- /dev/null
+++ b/examples/network/torrent/icons/1uparrow.svg
@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M21.7071 16.7071C21.3166 17.0976 20.6834 17.0976 20.2929 16.7071L12 8.41421L3.70711 16.7071C3.31658 17.0976 2.68342 17.0976 2.29289 16.7071C1.90237 16.3166 1.90237 15.6834 2.29289 15.2929L11.2929 6.29289C11.6834 5.90237 12.3166 5.90237 12.7071 6.29289L21.7071 15.2929C22.0976 15.6834 22.0976 16.3166 21.7071 16.7071Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/network/torrent/icons/about.svg b/examples/network/torrent/icons/about.svg
new file mode 100644
index 0000000000..2772c4fa31
--- /dev/null
+++ b/examples/network/torrent/icons/about.svg
@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M12 4C16.4183 4 20 7.58172 20 12C20 16.4183 16.4183 20 12 20C7.58172 20 4 16.4183 4 12C4 7.58172 7.58172 4 12 4ZM12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2Z" fill="#0D0D0D"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M11.8735 14C11.4243 14 11.0305 13.6404 11.0859 13.1913C11.1218 12.9004 11.1938 12.7598 11.2726 12.6061C11.2846 12.5827 11.2968 12.559 11.309 12.5344C11.4537 12.2427 11.8446 11.8125 12.4814 11.2438C12.742 11.025 12.9591 10.788 13.1328 10.5328C13.3065 10.2776 13.3933 10.0042 13.3933 9.7125C13.3933 9.40625 13.2775 9.12552 13.0459 8.87031C12.8143 8.6151 12.467 8.4875 12.0038 8.4875C11.4827 8.4875 11.0955 8.64062 10.8422 8.94687C10.7885 9.0118 10.7473 9.09933 10.7158 9.19697C10.5687 9.65217 10.2209 10.0625 9.74577 10.0625C9.26613 10.0625 8.88562 9.66512 9.03161 9.20479C9.18688 8.71516 9.47937 8.13493 9.99543 7.65625C10.5093 7.21875 11.1787 7 12.0038 7C12.8143 7 13.5164 7.21875 14.1098 7.65625C14.7033 8.09375 15 8.72083 15 9.5375C15 10.0188 14.8914 10.4307 14.6743 10.7734C14.4572 11.1161 14.1605 11.4771 13.7841 11.8562C13.2775 12.3375 12.9699 12.7167 12.8614 12.9938C12.834 13.0635 12.8088 13.1315 12.7863 13.2017C12.65 13.6271 12.3172 14 11.8735 14ZM12 15C12.5523 15 13 15.4477 13 16C13 16.5523 12.5523 17 12 17C11.4477 17 11 16.5523 11 16C11 15.4477 11.4477 15 12 15Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/network/torrent/icons/bottom.png b/examples/network/torrent/icons/bottom.png
deleted file mode 100644
index fe66b5d028..0000000000
--- a/examples/network/torrent/icons/bottom.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/bottom.svg b/examples/network/torrent/icons/bottom.svg
new file mode 100644
index 0000000000..44395cde25
--- /dev/null
+++ b/examples/network/torrent/icons/bottom.svg
@@ -0,0 +1,6 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="File /download_arrow_down">
+<path id="Layer01" fill-rule="evenodd" clip-rule="evenodd" d="M3 21C3 20.4477 3.44772 20 4 20H20C20.5523 20 21 20.4477 21 21C21 21.5523 20.5523 22 20 22H4C3.44772 22 3 21.5523 3 21Z" fill="#0D0D0D"/>
+<path id="Layer02" fill-rule="evenodd" clip-rule="evenodd" d="M12.7071 16.7071C12.3166 17.0976 11.6834 17.0976 11.2929 16.7071L7.93679 13.351C7.54626 12.9605 7.54626 12.3273 7.93679 11.9368C8.32731 11.5463 8.96047 11.5463 9.351 11.9368L11 13.5858L11 3.27208C11 2.71979 11.4477 2.27208 12 2.27208C12.5523 2.27208 13 2.71979 13 3.27208L13 13.5858L14.649 11.9368C15.0395 11.5463 15.6727 11.5463 16.0632 11.9368C16.4537 12.3273 16.4537 12.9605 16.0632 13.351L12.7071 16.7071Z" fill="#0D0D0D"/>
+</g>
+</svg>
diff --git a/examples/network/torrent/icons/edit_add.png b/examples/network/torrent/icons/edit_add.png
deleted file mode 100644
index 85b022e7a4..0000000000
--- a/examples/network/torrent/icons/edit_add.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/edit_add.svg b/examples/network/torrent/icons/edit_add.svg
new file mode 100644
index 0000000000..ec817193f5
--- /dev/null
+++ b/examples/network/torrent/icons/edit_add.svg
@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M11 17L11 7.00003L13 7.00003L13 17L11 17Z" fill="#0D0D0D"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M7 11L17 11L17 13L7 13L7 11Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/network/torrent/icons/edit_remove.png b/examples/network/torrent/icons/edit_remove.png
deleted file mode 100644
index 93361f5225..0000000000
--- a/examples/network/torrent/icons/edit_remove.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/edit_remove.svg b/examples/network/torrent/icons/edit_remove.svg
new file mode 100644
index 0000000000..ec18b7da64
--- /dev/null
+++ b/examples/network/torrent/icons/edit_remove.svg
@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M7 13V11H17V13H7Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/network/torrent/icons/exit.png b/examples/network/torrent/icons/exit.png
deleted file mode 100644
index 2f7ff43a71..0000000000
--- a/examples/network/torrent/icons/exit.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/exit.svg b/examples/network/torrent/icons/exit.svg
new file mode 100644
index 0000000000..94f5245c52
--- /dev/null
+++ b/examples/network/torrent/icons/exit.svg
@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M12 4C16.4183 4 20 7.58172 20 12C20 16.4183 16.4183 20 12 20C7.58172 20 4 16.4183 4 12C4 7.58172 7.58172 4 12 4ZM12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2Z" fill="#0D0D0D"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M8.4644 15.5355C8.07388 15.145 8.07388 14.5118 8.4644 14.1213L10.5857 12L8.46444 9.87868C8.07392 9.48815 8.07392 8.85499 8.46444 8.46446C8.85496 8.07394 9.48813 8.07394 9.87865 8.46446L12 10.5858L14.1213 8.46446C14.5118 8.07394 15.1449 8.07394 15.5355 8.46446C15.926 8.85499 15.926 9.48815 15.5355 9.87868L13.4142 12L15.5355 14.1213C15.926 14.5118 15.926 15.145 15.5355 15.5355C15.145 15.9261 14.5118 15.9261 14.1213 15.5355L12 13.4142L9.87862 15.5355C9.48809 15.9261 8.85493 15.9261 8.4644 15.5355Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/network/torrent/icons/peertopeer.png b/examples/network/torrent/icons/peertopeer.png
deleted file mode 100644
index f4856dcec5..0000000000
--- a/examples/network/torrent/icons/peertopeer.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/peertopeer.svg b/examples/network/torrent/icons/peertopeer.svg
new file mode 100644
index 0000000000..9498804cb8
--- /dev/null
+++ b/examples/network/torrent/icons/peertopeer.svg
@@ -0,0 +1,62 @@
+<svg width="128" height="128" viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="App Icon-Apple-1">
+<rect id="App Icon Bg" x="62" y="62" width="900" height="900" rx="180" fill="url(#paint0_linear_1432_187)"/>
+<g id="torrent client">
+<g id="laptop_mac">
+<mask id="mask0_1432_187" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="122" y="344" width="176" height="176">
+<rect id="Bounding box" x="122" y="344" width="176" height="176" fill="#D9D9D9"/>
+</mask>
+<g mask="url(#mask0_1432_187)">
+<path id="laptop_mac_2" d="M136.667 490.667C132.633 490.667 129.181 489.231 126.308 486.358C123.436 483.486 122 480.033 122 476H151.333C147.3 476 143.847 474.564 140.975 471.692C138.103 468.819 136.667 465.367 136.667 461.333V380.667C136.667 376.633 138.103 373.181 140.975 370.308C143.847 367.436 147.3 366 151.333 366H268.667C272.7 366 276.153 367.436 279.025 370.308C281.897 373.181 283.333 376.633 283.333 380.667V461.333C283.333 465.367 281.897 468.819 279.025 471.692C276.153 474.564 272.7 476 268.667 476H298C298 480.033 296.564 483.486 293.692 486.358C290.819 489.231 287.367 490.667 283.333 490.667H136.667ZM210 483.333C212.078 483.333 213.819 482.631 215.225 481.225C216.631 479.819 217.333 478.078 217.333 476C217.333 473.922 216.631 472.181 215.225 470.775C213.819 469.369 212.078 468.667 210 468.667C207.922 468.667 206.181 469.369 204.775 470.775C203.369 472.181 202.667 473.922 202.667 476C202.667 478.078 203.369 479.819 204.775 481.225C206.181 482.631 207.922 483.333 210 483.333ZM151.333 461.333H268.667V380.667H151.333V461.333Z" fill="white"/>
+</g>
+</g>
+<g id="laptop_mac_3">
+<mask id="mask1_1432_187" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="726" y="344" width="176" height="176">
+<rect id="Bounding box_2" x="726" y="344" width="176" height="176" fill="#D9D9D9"/>
+</mask>
+<g mask="url(#mask1_1432_187)">
+<path id="laptop_mac_4" d="M740.667 490.667C736.633 490.667 733.181 489.231 730.308 486.358C727.436 483.486 726 480.033 726 476H755.333C751.3 476 747.847 474.564 744.975 471.692C742.103 468.819 740.667 465.367 740.667 461.333V380.667C740.667 376.633 742.103 373.181 744.975 370.308C747.847 367.436 751.3 366 755.333 366H872.667C876.7 366 880.153 367.436 883.025 370.308C885.897 373.181 887.333 376.633 887.333 380.667V461.333C887.333 465.367 885.897 468.819 883.025 471.692C880.153 474.564 876.7 476 872.667 476H902C902 480.033 900.564 483.486 897.692 486.358C894.819 489.231 891.367 490.667 887.333 490.667H740.667ZM814 483.333C816.078 483.333 817.819 482.631 819.225 481.225C820.631 479.819 821.333 478.078 821.333 476C821.333 473.922 820.631 472.181 819.225 470.775C817.819 469.369 816.078 468.667 814 468.667C811.922 468.667 810.181 469.369 808.775 470.775C807.369 472.181 806.667 473.922 806.667 476C806.667 478.078 807.369 479.819 808.775 481.225C810.181 482.631 811.922 483.333 814 483.333ZM755.333 461.333H872.667V380.667H755.333V461.333Z" fill="white"/>
+</g>
+</g>
+<g id="laptop_mac_5">
+<mask id="mask2_1432_187" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="248" y="682" width="176" height="176">
+<rect id="Bounding box_3" x="248" y="682" width="176" height="176" fill="#D9D9D9"/>
+</mask>
+<g mask="url(#mask2_1432_187)">
+<path id="laptop_mac_6" d="M262.667 828.667C258.633 828.667 255.181 827.231 252.308 824.358C249.436 821.486 248 818.033 248 814H277.333C273.3 814 269.847 812.564 266.975 809.692C264.103 806.819 262.667 803.367 262.667 799.333V718.667C262.667 714.633 264.103 711.181 266.975 708.308C269.847 705.436 273.3 704 277.333 704H394.667C398.7 704 402.153 705.436 405.025 708.308C407.897 711.181 409.333 714.633 409.333 718.667V799.333C409.333 803.367 407.897 806.819 405.025 809.692C402.153 812.564 398.7 814 394.667 814H424C424 818.033 422.564 821.486 419.692 824.358C416.819 827.231 413.367 828.667 409.333 828.667H262.667ZM336 821.333C338.078 821.333 339.819 820.631 341.225 819.225C342.631 817.819 343.333 816.078 343.333 814C343.333 811.922 342.631 810.181 341.225 808.775C339.819 807.369 338.078 806.667 336 806.667C333.922 806.667 332.181 807.369 330.775 808.775C329.369 810.181 328.667 811.922 328.667 814C328.667 816.078 329.369 817.819 330.775 819.225C332.181 820.631 333.922 821.333 336 821.333ZM277.333 799.333H394.667V718.667H277.333V799.333Z" fill="white"/>
+</g>
+</g>
+<g id="laptop_mac_7">
+<mask id="mask3_1432_187" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="600" y="682" width="176" height="176">
+<rect id="Bounding box_4" x="600" y="682" width="176" height="176" fill="#D9D9D9"/>
+</mask>
+<g mask="url(#mask3_1432_187)">
+<path id="laptop_mac_8" d="M614.667 828.667C610.633 828.667 607.181 827.231 604.308 824.358C601.436 821.486 600 818.033 600 814H629.333C625.3 814 621.847 812.564 618.975 809.692C616.103 806.819 614.667 803.367 614.667 799.333V718.667C614.667 714.633 616.103 711.181 618.975 708.308C621.847 705.436 625.3 704 629.333 704H746.667C750.7 704 754.153 705.436 757.025 708.308C759.897 711.181 761.333 714.633 761.333 718.667V799.333C761.333 803.367 759.897 806.819 757.025 809.692C754.153 812.564 750.7 814 746.667 814H776C776 818.033 774.564 821.486 771.692 824.358C768.819 827.231 765.367 828.667 761.333 828.667H614.667ZM688 821.333C690.078 821.333 691.819 820.631 693.225 819.225C694.631 817.819 695.333 816.078 695.333 814C695.333 811.922 694.631 810.181 693.225 808.775C691.819 807.369 690.078 806.667 688 806.667C685.922 806.667 684.181 807.369 682.775 808.775C681.369 810.181 680.667 811.922 680.667 814C680.667 816.078 681.369 817.819 682.775 819.225C684.181 820.631 685.922 821.333 688 821.333ZM629.333 799.333H746.667V718.667H629.333V799.333Z" fill="white"/>
+</g>
+</g>
+<g id="laptop_mac_9">
+<mask id="mask4_1432_187" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="424" y="130" width="176" height="176">
+<rect id="Bounding box_5" x="424" y="130" width="176" height="176" fill="#D9D9D9"/>
+</mask>
+<g mask="url(#mask4_1432_187)">
+<path id="laptop_mac_10" d="M438.667 276.667C434.633 276.667 431.181 275.231 428.308 272.358C425.436 269.486 424 266.033 424 262H453.333C449.3 262 445.847 260.564 442.975 257.692C440.103 254.819 438.667 251.367 438.667 247.333V166.667C438.667 162.633 440.103 159.181 442.975 156.308C445.847 153.436 449.3 152 453.333 152H570.667C574.7 152 578.153 153.436 581.025 156.308C583.897 159.181 585.333 162.633 585.333 166.667V247.333C585.333 251.367 583.897 254.819 581.025 257.692C578.153 260.564 574.7 262 570.667 262H600C600 266.033 598.564 269.486 595.692 272.358C592.819 275.231 589.367 276.667 585.333 276.667H438.667ZM512 269.333C514.078 269.333 515.819 268.631 517.225 267.225C518.631 265.819 519.333 264.078 519.333 262C519.333 259.922 518.631 258.181 517.225 256.775C515.819 255.369 514.078 254.667 512 254.667C509.922 254.667 508.181 255.369 506.775 256.775C505.369 258.181 504.667 259.922 504.667 262C504.667 264.078 505.369 265.819 506.775 267.225C508.181 268.631 509.922 269.333 512 269.333ZM453.333 247.333H570.667V166.667H453.333V247.333Z" fill="white"/>
+</g>
+</g>
+<path id="netweork-big" fill-rule="evenodd" clip-rule="evenodd" d="M268.007 342C302.498 294.803 350.351 257.989 406 237.126V264.006C364.55 281.188 328.176 308.144 299.754 342H268.007ZM724.246 342C695.824 308.144 659.45 281.188 618 264.006V237.126C673.649 257.989 721.502 294.803 755.993 342H724.246ZM789 520C789 576.131 772.304 628.363 743.608 672H773.017C799.072 627.355 814 575.421 814 520H789ZM512 797C534.744 797 556.848 794.259 578 789.089V814.766C556.757 819.502 534.67 822 512 822C489.33 822 467.243 819.502 446 814.766V789.089C467.152 794.259 489.256 797 512 797ZM280.392 672C251.696 628.363 235 576.131 235 520H210C210 575.421 224.928 627.355 250.983 672H280.392Z" fill="white"/>
+<g id="network">
+<path id="Vector 6" d="M512.222 357.923L602.289 630.013C602.596 630.939 601.531 631.711 600.746 631.132L369.446 460.491C368.67 459.918 369.075 458.686 370.04 458.686H653.981C654.944 458.686 655.35 459.914 654.578 460.489L425.204 631.145C424.425 631.725 423.36 630.965 423.655 630.04L510.319 357.934C510.613 357.011 511.917 357.004 512.222 357.923Z" stroke="white" stroke-width="10"/>
+<circle id="Ellipse 3" cx="512" cy="355" r="22" fill="white"/>
+<circle id="Ellipse 4" cx="366" cy="461" r="22" fill="white"/>
+<circle id="Ellipse 5" cx="658" cy="461" r="22" fill="white"/>
+<circle id="Ellipse 6" cx="423" cy="633" r="22" fill="white"/>
+<circle id="Ellipse 7" cx="600" cy="633" r="22" fill="white"/>
+</g>
+</g>
+</g>
+<defs>
+<linearGradient id="paint0_linear_1432_187" x1="131.231" y1="96.0541" x2="967.084" y2="893.654" gradientUnits="userSpaceOnUse">
+<stop stop-color="#00414A"/>
+<stop offset="1" stop-color="#0C1C1F"/>
+</linearGradient>
+</defs>
+</svg>
diff --git a/examples/network/torrent/icons/player_pause.png b/examples/network/torrent/icons/player_pause.png
deleted file mode 100644
index 8c9bcc4556..0000000000
--- a/examples/network/torrent/icons/player_pause.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/player_pause.svg b/examples/network/torrent/icons/player_pause.svg
new file mode 100644
index 0000000000..6499480ea4
--- /dev/null
+++ b/examples/network/torrent/icons/player_pause.svg
@@ -0,0 +1,6 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Player / pause-symbol">
+<path id="Layer01" fill-rule="evenodd" clip-rule="evenodd" d="M8 7C8 6.44772 8.33579 6 8.75 6H10.25C10.6642 6 11 6.44772 11 7V17C11 17.5523 10.6642 18 10.25 18H8.75C8.33579 18 8 17.5523 8 17V7Z" fill="#0D0D0D"/>
+<path id="Layer02" fill-rule="evenodd" clip-rule="evenodd" d="M13 7C13 6.44772 13.3358 6 13.75 6H15.25C15.6642 6 16 6.44772 16 7V17C16 17.5523 15.6642 18 15.25 18H13.75C13.3358 18 13 17.5523 13 17V7Z" fill="#0D0D0D"/>
+</g>
+</svg>
diff --git a/examples/network/torrent/icons/player_play.png b/examples/network/torrent/icons/player_play.png
deleted file mode 100644
index 70daa339be..0000000000
--- a/examples/network/torrent/icons/player_play.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/player_play.svg b/examples/network/torrent/icons/player_play.svg
new file mode 100644
index 0000000000..a8cce6f422
--- /dev/null
+++ b/examples/network/torrent/icons/player_play.svg
@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M17.8182 12L7.89091 6.14985L7.89091 17.8501L17.8182 12ZM19.2 13.4143C20.2667 12.7857 20.2667 11.2143 19.2 10.5857L8.4 4.22123C7.33333 3.59264 6 4.37838 6 5.63555L6 18.3644C6 19.6216 7.33333 20.4074 8.4 19.7788L19.2 13.4143Z" fill="#0D0D0D"/>
+</svg>
diff --git a/examples/network/torrent/icons/player_stop.png b/examples/network/torrent/icons/player_stop.png
deleted file mode 100644
index ce6585ae84..0000000000
--- a/examples/network/torrent/icons/player_stop.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/icons/player_stop.svg b/examples/network/torrent/icons/player_stop.svg
new file mode 100644
index 0000000000..e220f5a790
--- /dev/null
+++ b/examples/network/torrent/icons/player_stop.svg
@@ -0,0 +1,5 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Player / stop-symbol">
+<path id="Layer01" fill-rule="evenodd" clip-rule="evenodd" d="M17 7H7L7 17H17V7ZM7 5C5.89543 5 5 5.89543 5 7V17C5 18.1046 5.89543 19 7 19H17C18.1046 19 19 18.1046 19 17V7C19 5.89543 18.1046 5 17 5H7Z" fill="#0D0D0D"/>
+</g>
+</svg>
diff --git a/examples/network/torrent/icons/stop.png b/examples/network/torrent/icons/stop.png
deleted file mode 100644
index 52e593ab21..0000000000
--- a/examples/network/torrent/icons/stop.png
+++ /dev/null
Binary files differ
diff --git a/examples/network/torrent/main.cpp b/examples/network/torrent/main.cpp
index a7a795fbcc..649f33436a 100644
--- a/examples/network/torrent/main.cpp
+++ b/examples/network/torrent/main.cpp
@@ -9,8 +9,6 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- Q_INIT_RESOURCE(icons);
-
MainWindow window;
window.show();
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp
index 4c898743ba..9bda5bb05e 100644
--- a/examples/network/torrent/mainwindow.cpp
+++ b/examples/network/torrent/mainwindow.cpp
@@ -26,17 +26,17 @@ protected:
};
// TorrentViewDelegate is used to draw the progress bars.
-class TorrentViewDelegate : public QItemDelegate
+class TorrentViewDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
- inline TorrentViewDelegate(MainWindow *mainWindow) : QItemDelegate(mainWindow) {}
+ inline TorrentViewDelegate(MainWindow *mainWindow) : QStyledItemDelegate(mainWindow) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index ) const override
{
if (index.column() != 2) {
- QItemDelegate::paint(painter, option, index);
+ QStyledItemDelegate::paint(painter, option, index);
return;
}
@@ -80,19 +80,19 @@ MainWindow::MainWindow(QWidget *parent)
setCentralWidget(torrentView);
// Set header resize modes and initial section sizes
- QFontMetrics fm = fontMetrics();
+ const QFontMetrics fm = torrentView->fontMetrics();
QHeaderView *header = torrentView->header();
header->resizeSection(0, fm.horizontalAdvance("typical-name-for-a-torrent.torrent"));
- header->resizeSection(1, fm.horizontalAdvance(headers.at(1) + " "));
- header->resizeSection(2, fm.horizontalAdvance(headers.at(2) + " "));
- header->resizeSection(3, qMax(fm.horizontalAdvance(headers.at(3) + " "), fm.horizontalAdvance(" 1234.0 KB/s ")));
- header->resizeSection(4, qMax(fm.horizontalAdvance(headers.at(4) + " "), fm.horizontalAdvance(" 1234.0 KB/s ")));
- header->resizeSection(5, qMax(fm.horizontalAdvance(headers.at(5) + " "), fm.horizontalAdvance(tr("Downloading") + " ")));
+ header->resizeSection(1, fm.horizontalAdvance(headers.at(1) + " "));
+ header->resizeSection(2, fm.horizontalAdvance(headers.at(2) + " "));
+ header->resizeSection(3, qMax(fm.horizontalAdvance(headers.at(3) + " "), fm.horizontalAdvance(" 1234.0 KB/s ")));
+ header->resizeSection(4, qMax(fm.horizontalAdvance(headers.at(4) + " "), fm.horizontalAdvance(" 1234.0 KB/s ")));
+ header->resizeSection(5, qMax(fm.horizontalAdvance(headers.at(5) + " "), fm.horizontalAdvance(tr("Downloading") + " ")));
// Create common actions
- QAction *newTorrentAction = new QAction(QIcon(":/icons/bottom.png"), tr("Add &new torrent"), this);
- pauseTorrentAction = new QAction(QIcon(":/icons/player_pause.png"), tr("&Pause torrent"), this);
- removeTorrentAction = new QAction(QIcon(":/icons/player_stop.png"), tr("&Remove torrent"), this);
+ QAction *newTorrentAction = new QAction(QIcon(":/icons/bottom.svg"), tr("Add &new torrent"), this);
+ pauseTorrentAction = new QAction(QIcon(":/icons/player_pause.svg"), tr("&Pause torrent"), this);
+ removeTorrentAction = new QAction(QIcon(":/icons/player_stop.svg"), tr("&Remove torrent"), this);
// File menu
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
@@ -100,12 +100,12 @@ MainWindow::MainWindow(QWidget *parent)
fileMenu->addAction(pauseTorrentAction);
fileMenu->addAction(removeTorrentAction);
fileMenu->addSeparator();
- fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, &MainWindow::close);
+ fileMenu->addAction(QIcon(":/icons/exit.svg"), tr("E&xit"), this, &MainWindow::close);
// Help menu
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- helpMenu->addAction(tr("About &Qt"), qApp, QApplication::aboutQt);
+ helpMenu->addAction(QIcon(":/icons/about.svg"), tr("&About"), this, &MainWindow::about);
+ helpMenu->addAction(QIcon(":/icons/about.svg"), tr("About &Qt"), qApp, QApplication::aboutQt);
// Top toolbar
QToolBar *topBar = new QToolBar(tr("Tools"));
@@ -115,8 +115,8 @@ MainWindow::MainWindow(QWidget *parent)
topBar->addAction(removeTorrentAction);
topBar->addAction(pauseTorrentAction);
topBar->addSeparator();
- downActionTool = topBar->addAction(QIcon(tr(":/icons/1downarrow.png")), tr("Move down"));
- upActionTool = topBar->addAction(QIcon(tr(":/icons/1uparrow.png")), tr("Move up"));
+ downActionTool = topBar->addAction(QIcon(tr(":/icons/1downarrow.svg")), tr("Move down"));
+ upActionTool = topBar->addAction(QIcon(tr(":/icons/1uparrow.svg")), tr("Move up"));
// Bottom toolbar
QToolBar *bottomBar = new QToolBar(tr("Rate control"));
@@ -462,10 +462,10 @@ void MainWindow::setActionsEnabled()
pauseTorrentAction->setEnabled(item && pauseEnabled);
if (client && client->state() == TorrentClient::Paused) {
- pauseTorrentAction->setIcon(QIcon(":/icons/player_play.png"));
+ pauseTorrentAction->setIcon(QIcon(":/icons/player_play.svg"));
pauseTorrentAction->setText(tr("Resume torrent"));
} else {
- pauseTorrentAction->setIcon(QIcon(":/icons/player_pause.png"));
+ pauseTorrentAction->setIcon(QIcon(":/icons/player_pause.svg"));
pauseTorrentAction->setText(tr("Pause torrent"));
}
@@ -575,7 +575,10 @@ void MainWindow::setDownloadLimit(int value)
void MainWindow::about()
{
QLabel *icon = new QLabel;
- icon->setPixmap(QPixmap(":/icons/peertopeer.png"));
+ QImage img(":/icons/peertopeer.svg");
+ QPixmap pm;
+ pm.convertFromImage(img);
+ icon->setPixmap(pm);
QLabel *text = new QLabel;
text->setWordWrap(true);
diff --git a/examples/opengl/2dpainting/CMakeLists.txt b/examples/opengl/2dpainting/CMakeLists.txt
index eeaa9cb726..b4ae3aa313 100644
--- a/examples/opengl/2dpainting/CMakeLists.txt
+++ b/examples/opengl/2dpainting/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(2dpainting LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/2dpainting")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
qt_standard_project_setup()
@@ -36,7 +30,14 @@ target_link_libraries(2dpainting PRIVATE
)
install(TARGETS 2dpainting
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET 2dpainting
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/CMakeLists.txt b/examples/opengl/CMakeLists.txt
index eb7e2d2782..09e31defe5 100644
--- a/examples/opengl/CMakeLists.txt
+++ b/examples/opengl/CMakeLists.txt
@@ -1,10 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(openglwindow)
qt_internal_add_example(hellogles3)
if(TARGET Qt6::Widgets)
- qt_internal_add_example(contextinfo)
qt_internal_add_example(2dpainting)
qt_internal_add_example(hellogl2)
qt_internal_add_example(cube)
diff --git a/examples/opengl/contextinfo/CMakeLists.txt b/examples/opengl/contextinfo/CMakeLists.txt
deleted file mode 100644
index 8dfd412408..0000000000
--- a/examples/opengl/contextinfo/CMakeLists.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(contextinfo LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/contextinfo")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(contextinfo
- main.cpp
- renderwindow.cpp renderwindow.h
- widget.cpp widget.h
-)
-
-set_target_properties(contextinfo PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(contextinfo PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::OpenGL
- Qt6::Widgets
-)
-
-install(TARGETS contextinfo
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/opengl/contextinfo/contextinfo.pro b/examples/opengl/contextinfo/contextinfo.pro
deleted file mode 100644
index ae8f4067b6..0000000000
--- a/examples/opengl/contextinfo/contextinfo.pro
+++ /dev/null
@@ -1,14 +0,0 @@
-TEMPLATE = app
-QT += widgets opengl
-requires(qtConfig(filedialog))
-
-SOURCES += main.cpp \
- widget.cpp \
- renderwindow.cpp
-
-HEADERS += widget.h \
- renderwindow.h
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/contextinfo
-INSTALLS += target
diff --git a/examples/opengl/contextinfo/main.cpp b/examples/opengl/contextinfo/main.cpp
deleted file mode 100644
index 253425ded9..0000000000
--- a/examples/opengl/contextinfo/main.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include "widget.h"
-
-int main(int argc, char **argv)
-{
- for (int i = 1; i < argc; ++i) {
- if (!qstrcmp(argv[i], "-g"))
- QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
- else if (!qstrcmp(argv[i], "-s"))
- QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
- else if (!qstrcmp(argv[i], "-d"))
- QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
- }
-
- QApplication app(argc, argv);
-
- Widget w;
- w.resize(700, 800);
- w.show();
-
- return app.exec();
-}
diff --git a/examples/opengl/contextinfo/renderwindow.cpp b/examples/opengl/contextinfo/renderwindow.cpp
deleted file mode 100644
index 64c0f47db9..0000000000
--- a/examples/opengl/contextinfo/renderwindow.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "renderwindow.h"
-#include <QTimer>
-#include <QMatrix4x4>
-#include <QOpenGLContext>
-#include <QtOpenGL/QOpenGLShaderProgram>
-#include <QOpenGLFunctions>
-
-RenderWindow::RenderWindow(const QSurfaceFormat &format)
- : m_context(nullptr),
- m_initialized(false),
- m_forceGLSL110(false),
- m_angle(0.0f)
-{
- setSurfaceType(QWindow::OpenGLSurface);
- setFormat(format);
- m_context = new QOpenGLContext(this);
- m_context->setFormat(requestedFormat());
- if (!m_context->create()) {
- delete m_context;
- m_context = nullptr;
- }
-}
-
-void RenderWindow::exposeEvent(QExposeEvent *)
-{
- if (isExposed())
- render();
-}
-
-// ES needs the precision qualifiers.
-// On desktop GL QOpenGLShaderProgram inserts dummy defines for highp/mediump/lowp.
-static const char *vertexShaderSource110 =
- "attribute highp vec4 posAttr;\n"
- "attribute lowp vec4 colAttr;\n"
- "varying lowp vec4 col;\n"
- "uniform highp mat4 matrix;\n"
- "void main() {\n"
- " col = colAttr;\n"
- " gl_Position = matrix * posAttr;\n"
- "}\n";
-
-static const char *fragmentShaderSource110 =
- "varying lowp vec4 col;\n"
- "void main() {\n"
- " gl_FragColor = col;\n"
- "}\n";
-
-static const char *vertexShaderSource =
- "#version 150\n"
- "in vec4 posAttr;\n"
- "in vec4 colAttr;\n"
- "out vec4 col;\n"
- "uniform mat4 matrix;\n"
- "void main() {\n"
- " col = colAttr;\n"
- " gl_Position = matrix * posAttr;\n"
- "}\n";
-
-static const char *fragmentShaderSource =
- "#version 150\n"
- "in vec4 col;\n"
- "out vec4 fragColor;\n"
- "void main() {\n"
- " fragColor = col;\n"
- "}\n";
-
-static GLfloat vertices[] = {
- 0.0f, 0.707f,
- -0.5f, -0.5f,
- 0.5f, -0.5f
-};
-
-static GLfloat colors[] = {
- 1.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 1.0f
-};
-
-void RenderWindow::init()
-{
- m_program = new QOpenGLShaderProgram(this);
-
- QSurfaceFormat format = m_context->format();
- bool useNewStyleShader = format.profile() == QSurfaceFormat::CoreProfile;
- // Try to handle 3.0 & 3.1 that do not have the core/compatibility profile concept 3.2+ has.
- // This may still fail since version 150 (3.2) is specified in the sources but it's worth a try.
- if (format.renderableType() == QSurfaceFormat::OpenGL && format.majorVersion() == 3 && format.minorVersion() <= 1)
- useNewStyleShader = !format.testOption(QSurfaceFormat::DeprecatedFunctions);
- if (m_forceGLSL110)
- useNewStyleShader = false;
-
- const char *vsrc = useNewStyleShader ? vertexShaderSource : vertexShaderSource110;
- const char *fsrc = useNewStyleShader ? fragmentShaderSource : fragmentShaderSource110;
- qDebug("Using version %s shader", useNewStyleShader ? "150" : "110");
-
- if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vsrc)) {
- emit error(m_program->log());
- return;
- }
- if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fsrc)) {
- emit error(m_program->log());
- return;
- }
- if (!m_program->link()) {
- emit error(m_program->log());
- return;
- }
-
- m_posAttr = m_program->attributeLocation("posAttr");
- m_colAttr = m_program->attributeLocation("colAttr");
- m_matrixUniform = m_program->uniformLocation("matrix");
-
- m_vbo.create();
- m_vbo.bind();
- m_vbo.allocate(vertices, sizeof(vertices) + sizeof(colors));
- m_vbo.write(sizeof(vertices), colors, sizeof(colors));
- m_vbo.release();
-
- QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
- if (m_vao.isCreated()) // have VAO support, use it
- setupVertexAttribs();
-}
-
-void RenderWindow::setupVertexAttribs()
-{
- m_vbo.bind();
- m_program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 2);
- m_program->setAttributeBuffer(m_colAttr, GL_FLOAT, sizeof(vertices), 3);
- m_program->enableAttributeArray(m_posAttr);
- m_program->enableAttributeArray(m_colAttr);
- m_vbo.release();
-}
-
-bool RenderWindow::event(QEvent *ev)
-{
- if (ev->type() == QEvent::UpdateRequest)
- render();
- return QWindow::event(ev);
-}
-
-void RenderWindow::render()
-{
- if (!m_context->makeCurrent(this)) {
- emit error(tr("makeCurrent() failed"));
- return;
- }
-
- QOpenGLFunctions *f = m_context->functions();
- if (!m_initialized) {
- m_initialized = true;
- f->glEnable(GL_DEPTH_TEST);
- f->glClearColor(0, 0, 0, 1);
- init();
- emit ready();
- }
-
- if (!m_vbo.isCreated()) // init() failed, don't bother with trying to render
- return;
-
- const qreal retinaScale = devicePixelRatio();
- f->glViewport(0, 0, width() * retinaScale, height() * retinaScale);
- f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- m_program->bind();
- QMatrix4x4 matrix;
- matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f);
- matrix.translate(0.0f, 0.0f, -2.0f);
- matrix.rotate(m_angle, 0.0f, 1.0f, 0.0f);
- m_program->setUniformValue(m_matrixUniform, matrix);
-
- if (m_vao.isCreated())
- m_vao.bind();
- else // no VAO support, set the vertex attribute arrays now
- setupVertexAttribs();
-
- f->glDrawArrays(GL_TRIANGLES, 0, 3);
-
- m_vao.release();
- m_program->release();
-
- // swapInterval is 1 by default which means that swapBuffers() will (hopefully) block
- // and wait for vsync.
- m_context->swapBuffers(this);
-
- m_angle += 1.0f;
-
- requestUpdate();
-}
diff --git a/examples/opengl/contextinfo/renderwindow.h b/examples/opengl/contextinfo/renderwindow.h
deleted file mode 100644
index 964dd601a6..0000000000
--- a/examples/opengl/contextinfo/renderwindow.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef RENDERWINDOW_H
-#define RENDERWINDOW_H
-
-#include <QWindow>
-#include <QOpenGLVertexArrayObject>
-#include <QOpenGLBuffer>
-
-QT_FORWARD_DECLARE_CLASS(QOpenGLContext)
-QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
-
-class RenderWindow : public QWindow
-{
- Q_OBJECT
-
-public:
- RenderWindow(const QSurfaceFormat &format);
- QOpenGLContext *context() { return m_context; }
- void exposeEvent(QExposeEvent *) override;
- void setForceGLSL110(bool enable) { m_forceGLSL110 = enable; }
-
-signals:
- void ready();
- void error(const QString &msg);
-
-protected:
- bool event(QEvent *ev) override;
-
-private slots:
- void render();
-
-private:
- void init();
- void setupVertexAttribs();
-
- QOpenGLContext *m_context;
- bool m_initialized;
- bool m_forceGLSL110;
- QOpenGLShaderProgram *m_program;
- int m_posAttr, m_colAttr, m_matrixUniform;
- QOpenGLVertexArrayObject m_vao;
- QOpenGLBuffer m_vbo;
- float m_angle;
-};
-
-#endif // RENDERWINDOW_H
diff --git a/examples/opengl/contextinfo/widget.cpp b/examples/opengl/contextinfo/widget.cpp
deleted file mode 100644
index bc31497039..0000000000
--- a/examples/opengl/contextinfo/widget.cpp
+++ /dev/null
@@ -1,360 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "widget.h"
-#include "renderwindow.h"
-#include <QVBoxLayout>
-#include <QComboBox>
-#include <QGroupBox>
-#include <QRadioButton>
-#include <QCheckBox>
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QList>
-#include <QByteArray>
-#include <QPushButton>
-#include <QTextEdit>
-#include <QSplitter>
-#include <QGuiApplication>
-#include <QSurfaceFormat>
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-#include <QDebug>
-#include <QTextStream>
-
-struct Version {
- const char *str;
- int major;
- int minor;
-};
-
-static struct Version versions[] = {
- { "1.0", 1, 0 },
- { "1.1", 1, 1 },
- { "1.2", 1, 2 },
- { "1.3", 1, 3 },
- { "1.4", 1, 4 },
- { "1.5", 1, 5 },
- { "2.0", 2, 0 },
- { "2.1", 2, 1 },
- { "3.0", 3, 0 },
- { "3.1", 3, 1 },
- { "3.2", 3, 2 },
- { "3.3", 3, 3 },
- { "4.0", 4, 0 },
- { "4.1", 4, 1 },
- { "4.2", 4, 2 },
- { "4.3", 4, 3 },
- { "4.4", 4, 4 },
- { "4.5", 4, 5 }
-};
-
-struct Profile {
- const char *str;
- QSurfaceFormat::OpenGLContextProfile profile;
-};
-
-static struct Profile profiles[] = {
- { "none", QSurfaceFormat::NoProfile },
- { "core", QSurfaceFormat::CoreProfile },
- { "compatibility", QSurfaceFormat::CompatibilityProfile }
-};
-
-struct Option {
- const char *str;
- QSurfaceFormat::FormatOption option;
-};
-
-static struct Option options[] = {
- { "deprecated functions (not forward compatible)", QSurfaceFormat::DeprecatedFunctions },
- { "debug context", QSurfaceFormat::DebugContext },
- { "stereo buffers", QSurfaceFormat::StereoBuffers },
- // This is not a QSurfaceFormat option but is helpful to determine if the driver
- // allows compiling old-style shaders with core profile.
- { "force version 110 shaders", QSurfaceFormat::FormatOption(0) }
-};
-
-struct Renderable {
- const char *str;
- QSurfaceFormat::RenderableType renderable;
-};
-
-static struct Renderable renderables[] = {
- { "default", QSurfaceFormat::DefaultRenderableType },
-#ifndef Q_OS_ANDROID
- { "OpenGL", QSurfaceFormat::OpenGL },
-#endif
- { "OpenGL ES", QSurfaceFormat::OpenGLES }
-};
-
-void Widget::addVersions(QLayout *layout)
-{
- QHBoxLayout *hbox = new QHBoxLayout;
- hbox->setSpacing(20);
- QLabel *label = new QLabel(tr("Context &version: "));
- hbox->addWidget(label);
- m_version = new QComboBox;
- m_version->setMinimumWidth(60);
- label->setBuddy(m_version);
- hbox->addWidget(m_version);
- for (size_t i = 0; i < sizeof(versions) / sizeof(Version); ++i) {
- m_version->addItem(QString::fromLatin1(versions[i].str));
- if (versions[i].major == 2 && versions[i].minor == 0)
- m_version->setCurrentIndex(m_version->count() - 1);
- }
-
- QPushButton *btn = new QPushButton(tr("Create context"));
- connect(btn, &QPushButton::clicked, this, &Widget::start);
- btn->setMinimumSize(120, 40);
- hbox->addWidget(btn);
-
- layout->addItem(hbox);
-}
-
-void Widget::addProfiles(QLayout *layout)
-{
- QGroupBox *groupBox = new QGroupBox(tr("Profile"));
- QVBoxLayout *vbox = new QVBoxLayout;
- for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
- vbox->addWidget(new QRadioButton(QString::fromLatin1(profiles[i].str)));
- static_cast<QRadioButton *>(vbox->itemAt(0)->widget())->setChecked(true);
- groupBox->setLayout(vbox);
- layout->addWidget(groupBox);
- m_profiles = vbox;
-}
-
-void Widget::addOptions(QLayout *layout)
-{
- QGroupBox *groupBox = new QGroupBox(tr("Options"));
- QVBoxLayout *vbox = new QVBoxLayout;
- for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
- vbox->addWidget(new QCheckBox(QString::fromLatin1(options[i].str)));
- groupBox->setLayout(vbox);
- layout->addWidget(groupBox);
- m_options = vbox;
-}
-
-void Widget::addRenderableTypes(QLayout *layout)
-{
- QGroupBox *groupBox = new QGroupBox(tr("Renderable type"));
- QVBoxLayout *vbox = new QVBoxLayout;
- for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
- vbox->addWidget(new QRadioButton(QString::fromLatin1(renderables[i].str)));
- static_cast<QRadioButton *>(vbox->itemAt(0)->widget())->setChecked(true);
- groupBox->setLayout(vbox);
- layout->addWidget(groupBox);
- m_renderables = vbox;
-}
-
-void Widget::addRenderWindow()
-{
- m_renderWindowLayout->addWidget(m_renderWindowContainer);
-}
-
-static QWidget *widgetWithLayout(QLayout *layout)
-{
- QWidget *w = new QWidget;
- w->setLayout(layout);
- return w;
-}
-
-Widget::Widget(QWidget *parent)
- : QWidget(parent)
-{
- QVBoxLayout *layout = new QVBoxLayout;
- QSplitter *vsplit = new QSplitter(Qt::Vertical);
- layout->addWidget(vsplit);
-
- QSplitter *hsplit = new QSplitter;
-
- QVBoxLayout *settingsLayout = new QVBoxLayout;
- addVersions(settingsLayout);
- addProfiles(settingsLayout);
- addOptions(settingsLayout);
- addRenderableTypes(settingsLayout);
- hsplit->addWidget(widgetWithLayout(settingsLayout));
-
- QVBoxLayout *outputLayout = new QVBoxLayout;
- m_output = new QTextEdit;
- m_output->setReadOnly(true);
- outputLayout->addWidget(m_output);
- m_extensions = new QTextEdit;
- m_extensions->setReadOnly(true);
- outputLayout->addWidget(m_extensions);
- hsplit->addWidget(widgetWithLayout(outputLayout));
-
- hsplit->setStretchFactor(0, 4);
- hsplit->setStretchFactor(1, 6);
- vsplit->addWidget(hsplit);
-
- m_renderWindowLayout = new QVBoxLayout;
- vsplit->addWidget(widgetWithLayout(m_renderWindowLayout));
- vsplit->setStretchFactor(1, 5);
-
- m_renderWindowContainer = new QWidget;
- addRenderWindow();
-
- QString description;
- QTextStream str(&description);
- str << "Qt " << QT_VERSION_STR << ' ' << QGuiApplication::platformName();
- const char *openGlVariables[] =
- {"QT_ANGLE_PLATFORM", "QT_OPENGL", "QT_OPENGL_BUGLIST", "QT_OPENGL_DLL"};
- const size_t variableCount = sizeof(openGlVariables) / sizeof(openGlVariables[0]);
- for (size_t v = 0; v < variableCount; ++v) {
- if (qEnvironmentVariableIsSet(openGlVariables[v]))
- str << ' ' << openGlVariables[v] << '=' << qgetenv(openGlVariables[v]);
- }
- if (QCoreApplication::testAttribute(Qt::AA_UseOpenGLES))
- str << " Qt::AA_UseOpenGLES";
- if (QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL))
- str << " Qt::AA_UseSoftwareOpenGL";
- if (QCoreApplication::testAttribute(Qt::AA_UseDesktopOpenGL))
- str << " Qt::AA_UseDesktopOpenGL";
- layout->addWidget(new QLabel(description));
-
- setLayout(layout);
-}
-
-void Widget::start()
-{
- QSurfaceFormat fmt;
-
- int idx = m_version->currentIndex();
- if (idx < 0)
- return;
- fmt.setVersion(versions[idx].major, versions[idx].minor);
-
- for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
- if (static_cast<QRadioButton *>(m_profiles->itemAt(int(i))->widget())->isChecked()) {
- fmt.setProfile(profiles[i].profile);
- break;
- }
-
- bool forceGLSL110 = false;
- for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
- if (static_cast<QCheckBox *>(m_options->itemAt(int(i))->widget())->isChecked()) {
- if (options[i].option)
- fmt.setOption(options[i].option);
- else if (i == 3)
- forceGLSL110 = true;
- }
-
- for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
- if (static_cast<QRadioButton *>(m_renderables->itemAt(int(i))->widget())->isChecked()) {
- fmt.setRenderableType(renderables[i].renderable);
- break;
- }
-
- // The example rendering will need a depth buffer.
- fmt.setDepthBufferSize(16);
-
- m_output->clear();
- m_extensions->clear();
- qDebug() << "Requesting surface format" << fmt;
-
- m_renderWindowLayout->removeWidget(m_renderWindowContainer);
- delete m_renderWindowContainer;
-
- RenderWindow *renderWindow = new RenderWindow(fmt);
- if (!renderWindow->context()) {
- m_output->append(tr("Failed to create context"));
- delete renderWindow;
- m_renderWindowContainer = new QWidget;
- addRenderWindow();
- return;
- }
- m_surface = renderWindow;
-
- renderWindow->setForceGLSL110(forceGLSL110);
- connect(renderWindow, &RenderWindow::ready, this, &Widget::renderWindowReady);
- connect(renderWindow, &RenderWindow::error, this, &Widget::renderWindowError);
-
- m_renderWindowContainer = QWidget::createWindowContainer(renderWindow);
- addRenderWindow();
-}
-
-void Widget::printFormat(const QSurfaceFormat &format)
-{
- m_output->append(tr("OpenGL version: %1.%2").arg(format.majorVersion()).arg(format.minorVersion()));
-
- for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
- if (profiles[i].profile == format.profile()) {
- m_output->append(tr("Profile: %1").arg(QString::fromLatin1(profiles[i].str)));
- break;
- }
-
- QString opts;
- for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
- if (format.testOption(options[i].option))
- opts += QString::fromLatin1(options[i].str) + QLatin1Char(' ');
- m_output->append(tr("Options: %1").arg(opts));
-
- for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
- if (renderables[i].renderable == format.renderableType()) {
- m_output->append(tr("Renderable type: %1").arg(QString::fromLatin1(renderables[i].str)));
- break;
- }
-
- m_output->append(tr("Depth buffer size: %1").arg(QString::number(format.depthBufferSize())));
- m_output->append(tr("Stencil buffer size: %1").arg(QString::number(format.stencilBufferSize())));
- m_output->append(tr("Samples: %1").arg(QString::number(format.samples())));
- m_output->append(tr("Red buffer size: %1").arg(QString::number(format.redBufferSize())));
- m_output->append(tr("Green buffer size: %1").arg(QString::number(format.greenBufferSize())));
- m_output->append(tr("Blue buffer size: %1").arg(QString::number(format.blueBufferSize())));
- m_output->append(tr("Alpha buffer size: %1").arg(QString::number(format.alphaBufferSize())));
- m_output->append(tr("Swap interval: %1").arg(QString::number(format.swapInterval())));
-}
-
-void Widget::renderWindowReady()
-{
- QOpenGLContext *context = QOpenGLContext::currentContext();
- Q_ASSERT(context);
-
- QString vendor, renderer, version, glslVersion;
- const GLubyte *p;
- QOpenGLFunctions *f = context->functions();
- if ((p = f->glGetString(GL_VENDOR)))
- vendor = QString::fromLatin1(reinterpret_cast<const char *>(p));
- if ((p = f->glGetString(GL_RENDERER)))
- renderer = QString::fromLatin1(reinterpret_cast<const char *>(p));
- if ((p = f->glGetString(GL_VERSION)))
- version = QString::fromLatin1(reinterpret_cast<const char *>(p));
- if ((p = f->glGetString(GL_SHADING_LANGUAGE_VERSION)))
- glslVersion = QString::fromLatin1(reinterpret_cast<const char *>(p));
-
- m_output->append(tr("*** Context information ***"));
- m_output->append(tr("Vendor: %1").arg(vendor));
- m_output->append(tr("Renderer: %1").arg(renderer));
- m_output->append(tr("OpenGL version: %1").arg(version));
- m_output->append(tr("GLSL version: %1").arg(glslVersion));
-
- m_output->append(tr("\n*** QSurfaceFormat from context ***"));
- printFormat(context->format());
-
- m_output->append(tr("\n*** QSurfaceFormat from window surface ***"));
- printFormat(m_surface->format());
-
- m_output->append(tr("\n*** Qt build information ***"));
- const char *gltype[] = { "Desktop", "GLES 2", "GLES 1" };
- m_output->append(tr("Qt OpenGL configuration: %1")
- .arg(QString::fromLatin1(gltype[QOpenGLContext::openGLModuleType()])));
-#if defined(Q_OS_WIN)
- using namespace QNativeInterface;
- m_output->append(tr("Qt OpenGL library handle: %1")
- .arg(QString::number(qintptr(QWGLContext::openGLModuleHandle()), 16)));
-#endif
-
- QList<QByteArray> extensionList = context->extensions().values();
- std::sort(extensionList.begin(), extensionList.end());
- m_extensions->append(tr("Found %1 extensions:").arg(extensionList.count()));
- for (const QByteArray &ext : std::as_const(extensionList))
- m_extensions->append(QString::fromLatin1(ext));
-
- m_output->moveCursor(QTextCursor::Start);
- m_extensions->moveCursor(QTextCursor::Start);
-}
-
-void Widget::renderWindowError(const QString &msg)
-{
- m_output->append(tr("An error has occurred:\n%1").arg(msg));
-}
diff --git a/examples/opengl/contextinfo/widget.h b/examples/opengl/contextinfo/widget.h
deleted file mode 100644
index e5c31fcaa7..0000000000
--- a/examples/opengl/contextinfo/widget.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WIDGET_H
-#define WIDGET_H
-
-#include <QWidget>
-
-QT_FORWARD_DECLARE_CLASS(QComboBox)
-QT_FORWARD_DECLARE_CLASS(QTextEdit)
-QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
-QT_FORWARD_DECLARE_CLASS(QSurfaceFormat)
-QT_FORWARD_DECLARE_CLASS(QSurface)
-
-class Widget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit Widget(QWidget *parent = nullptr);
-
-private slots:
- void start();
- void renderWindowReady();
- void renderWindowError(const QString &msg);
-
-private:
- void addVersions(QLayout *layout);
- void addProfiles(QLayout *layout);
- void addOptions(QLayout *layout);
- void addRenderableTypes(QLayout *layout);
- void addRenderWindow();
- void printFormat(const QSurfaceFormat &format);
-
- QComboBox *m_version;
- QLayout *m_profiles;
- QLayout *m_options;
- QLayout *m_renderables;
- QTextEdit *m_output;
- QTextEdit *m_extensions;
- QVBoxLayout *m_renderWindowLayout;
- QWidget *m_renderWindowContainer;
- QSurface *m_surface;
-};
-
-#endif // WIDGET_H
diff --git a/examples/opengl/cube/CMakeLists.txt b/examples/opengl/cube/CMakeLists.txt
index 0446a5d52e..7486d058a4 100644
--- a/examples/opengl/cube/CMakeLists.txt
+++ b/examples/opengl/cube/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(cube LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/cube")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
qt_standard_project_setup()
@@ -58,7 +52,14 @@ qt6_add_resources(cube "textures"
)
install(TARGETS cube
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET cube
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/cube/fshader.glsl b/examples/opengl/cube/fshader.glsl
index 18068cf0e6..0c056b6165 100644
--- a/examples/opengl/cube/fshader.glsl
+++ b/examples/opengl/cube/fshader.glsl
@@ -1,3 +1,5 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifdef GL_ES
// Set default precision to medium
precision mediump int;
diff --git a/examples/opengl/cube/vshader.glsl b/examples/opengl/cube/vshader.glsl
index cfdc061852..ac57d96285 100644
--- a/examples/opengl/cube/vshader.glsl
+++ b/examples/opengl/cube/vshader.glsl
@@ -1,3 +1,5 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifdef GL_ES
// Set default precision to medium
precision mediump int;
diff --git a/examples/opengl/doc/src/2dpainting.qdoc b/examples/opengl/doc/src/2dpainting.qdoc
index 934097f38e..5196c78937 100644
--- a/examples/opengl/doc/src/2dpainting.qdoc
+++ b/examples/opengl/doc/src/2dpainting.qdoc
@@ -5,6 +5,7 @@
\example 2dpainting
\title 2D Painting Example
\ingroup examples-widgets-opengl
+ \examplecategory {Graphics}
\brief The 2D Painting example shows how QPainter and QOpenGLWidget can be
used together to display accelerated 2D graphics on supported hardware.
diff --git a/examples/opengl/doc/src/cube.qdoc b/examples/opengl/doc/src/cube.qdoc
index 1a92985565..d01985701c 100644
--- a/examples/opengl/doc/src/cube.qdoc
+++ b/examples/opengl/doc/src/cube.qdoc
@@ -5,6 +5,7 @@
\example cube
\ingroup examples-widgets-opengl
\title Cube OpenGL ES 2.0 example
+ \examplecategory {3D}
\brief Shows how to manually rotate a textured 3D cube with user input.
diff --git a/examples/opengl/doc/src/hellogl2.qdoc b/examples/opengl/doc/src/hellogl2.qdoc
index 3a81b0dfad..29e8ef85cd 100644
--- a/examples/opengl/doc/src/hellogl2.qdoc
+++ b/examples/opengl/doc/src/hellogl2.qdoc
@@ -5,6 +5,7 @@
\example hellogl2
\title Hello GL2 Example
\ingroup examples-widgets-opengl
+ \examplecategory {3D}
\brief The Hello GL2 example demonstrates the basic use of the OpenGL-related classes
provided with Qt.
diff --git a/examples/opengl/doc/src/hellogles3.qdoc b/examples/opengl/doc/src/hellogles3.qdoc
index c83ecd50f7..d85f40a29f 100644
--- a/examples/opengl/doc/src/hellogles3.qdoc
+++ b/examples/opengl/doc/src/hellogles3.qdoc
@@ -5,6 +5,8 @@
\example hellogles3
\title Hello GLES3 Example
\ingroup examples-widgets-opengl
+ \examplecategory {Graphics}
+ \examplecategory {Mobile}
\brief Demonstrates OpenGL ES 3.0 functions via QOpenGLExtraFunctions.
diff --git a/examples/opengl/doc/src/openglwindow.qdoc b/examples/opengl/doc/src/openglwindow.qdoc
index 505ff20fbc..cade2f009a 100644
--- a/examples/opengl/doc/src/openglwindow.qdoc
+++ b/examples/opengl/doc/src/openglwindow.qdoc
@@ -4,6 +4,8 @@
/*!
\example openglwindow
\title OpenGL Window Example
+ \ingroup examples-widgets-opengl
+ \examplecategory {Graphics}
\brief This example shows how to create a minimal QWindow based application
for the purpose of using OpenGL.
diff --git a/examples/opengl/doc/src/stereoqopenglwidget.qdoc b/examples/opengl/doc/src/stereoqopenglwidget.qdoc
index c4e51f9cee..0cb45b9808 100644
--- a/examples/opengl/doc/src/stereoqopenglwidget.qdoc
+++ b/examples/opengl/doc/src/stereoqopenglwidget.qdoc
@@ -4,9 +4,17 @@
/*!
\example stereoqopenglwidget
\title QOpenGLWidget Stereoscopic Rendering Example
+ \examplecategory {Graphics}
+ \ingroup examples-widgets-opengl
+ \brief This example shows how to create a minimal QOpenGLWidget based
+ application with stereoscopic rendering support.
- \brief This example shows how to create a minimal QOpenGLWidget based application
- with stereoscopic rendering support.
+ \note Support for stereoscopic rendering has certain hardware requirements,
+ such as, a graphics card with stereo support, 3D glasses and specific
+ monitors.
+
+ \note This example renders two images to two separate buffers. When you
+ view the images through 3D glasses, they give a 3D holographic effect.
\image stereoexample-leftbuffer.png
@@ -16,9 +24,6 @@
The above image is what will be rendered to the right buffer.
- \note Support for stereoscopic rendering has certain hardware requirements, like
- your graphics card needs stereo support.
-
\section1 Setting the correct surface flag
To enable stereoscopic rendering you need to set the flag
QSurfaceFormat::StereoBuffers globally. Just doing it on the widget is not enough
diff --git a/examples/opengl/hellogl2/CMakeLists.txt b/examples/opengl/hellogl2/CMakeLists.txt
index 8846fcc23e..74ef4a8c24 100644
--- a/examples/opengl/hellogl2/CMakeLists.txt
+++ b/examples/opengl/hellogl2/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(hellogl2 LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/hellogl2")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
qt_standard_project_setup()
@@ -36,7 +30,14 @@ target_link_libraries(hellogl2 PRIVATE
)
install(TARGETS hellogl2
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET hellogl2
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/hellogl2/mainwindow.cpp b/examples/opengl/hellogl2/mainwindow.cpp
index 2416fd6057..5ee2b738c2 100644
--- a/examples/opengl/hellogl2/mainwindow.cpp
+++ b/examples/opengl/hellogl2/mainwindow.cpp
@@ -3,19 +3,19 @@
#include "mainwindow.h"
#include "window.h"
+#include <QApplication>
+#include <QKeySequence>
#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, &QAction::triggered, this, &MainWindow::onAddNew);
- setMenuBar(menuBar);
+ QMenu *menuWindow = menuBar()->addMenu(tr("&Window"));
+ menuWindow->addAction(tr("Add new"), QKeySequence(Qt::CTRL | Qt::Key_N),
+ this, &MainWindow::onAddNew);
+ menuWindow->addAction(tr("Quit"), QKeySequence(Qt::CTRL | Qt::Key_Q),
+ qApp, QApplication::closeAllWindows);
onAddNew();
}
@@ -23,8 +23,8 @@ MainWindow::MainWindow()
void MainWindow::onAddNew()
{
if (!centralWidget())
- setCentralWidget(new Window(this));
+ setCentralWidget(new Window);
else
- QMessageBox::information(nullptr, tr("Cannot add new window"),
+ QMessageBox::information(this, tr("Cannot Add New Window"),
tr("Already occupied. Undock first."));
}
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
index 055dd5b5e3..5a7ddf826f 100644
--- a/examples/opengl/hellogl2/window.cpp
+++ b/examples/opengl/hellogl2/window.cpp
@@ -1,9 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include "glwidget.h"
#include "window.h"
-#include "mainwindow.h"
+#include "glwidget.h"
#include <QSlider>
#include <QVBoxLayout>
#include <QHBoxLayout>
@@ -11,9 +10,18 @@
#include <QPushButton>
#include <QApplication>
#include <QMessageBox>
+#include <QMainWindow>
-Window::Window(MainWindow *mw)
- : mainWindow(mw)
+static QMainWindow *findMainWindow()
+{
+ for (auto *w : QApplication::topLevelWidgets()) {
+ if (auto *mw = qobject_cast<QMainWindow *>(w))
+ return mw;
+ }
+ return nullptr;
+}
+
+Window::Window()
{
glWidget = new GLWidget;
@@ -28,22 +36,19 @@ Window::Window(MainWindow *mw)
connect(zSlider, &QSlider::valueChanged, glWidget, &GLWidget::setZRotation);
connect(glWidget, &GLWidget::zRotationChanged, zSlider, &QSlider::setValue);
- QVBoxLayout *mainLayout = new QVBoxLayout;
- QHBoxLayout *container = new QHBoxLayout;
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ QWidget *w = new QWidget;
+ QHBoxLayout *container = new QHBoxLayout(w);
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, &QPushButton::clicked, this, &Window::dockUndock);
mainLayout->addWidget(dockBtn);
- setLayout(mainLayout);
-
xSlider->setValue(15 * 16);
ySlider->setValue(345 * 16);
zSlider->setValue(0 * 16);
@@ -64,7 +69,7 @@ QSlider *Window::createSlider()
void Window::keyPressEvent(QKeyEvent *e)
{
- if (e->key() == Qt::Key_Escape)
+ if (isWindow() && e->key() == Qt::Key_Escape)
close();
else
QWidget::keyPressEvent(e);
@@ -72,26 +77,37 @@ void Window::keyPressEvent(QKeyEvent *e)
void Window::dockUndock()
{
- if (parent()) {
- setParent(nullptr);
- setAttribute(Qt::WA_DeleteOnClose);
- move(QGuiApplication::primaryScreen()->size().width() / 2 - width() / 2,
- QGuiApplication::primaryScreen()->size().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(nullptr, tr("Cannot dock"),
- tr("Main window already closed"));
- }
- } else {
- QMessageBox::information(nullptr, tr("Cannot dock"),
- tr("Main window already occupied"));
- }
+ if (parent())
+ undock();
+ else
+ dock();
+}
+
+void Window::dock()
+{
+ auto *mainWindow = findMainWindow();
+ if (mainWindow == nullptr || !mainWindow->isVisible()) {
+ QMessageBox::information(this, tr("Cannot Dock"),
+ tr("Main window already closed"));
+ return;
}
+ if (mainWindow->centralWidget()) {
+ QMessageBox::information(this, tr("Cannot Dock"),
+ tr("Main window already occupied"));
+ return;
+ }
+ setAttribute(Qt::WA_DeleteOnClose, false);
+ dockBtn->setText(tr("Undock"));
+ mainWindow->setCentralWidget(this);
+}
+
+void Window::undock()
+{
+ setParent(nullptr);
+ setAttribute(Qt::WA_DeleteOnClose);
+ const auto geometry = screen()->availableGeometry();
+ move(geometry.x() + (geometry.width() - width()) / 2,
+ geometry.y() + (geometry.height() - height()) / 2);
+ dockBtn->setText(tr("Dock"));
+ show();
}
diff --git a/examples/opengl/hellogl2/window.h b/examples/opengl/hellogl2/window.h
index 2099bc119a..edbd643ae2 100644
--- a/examples/opengl/hellogl2/window.h
+++ b/examples/opengl/hellogl2/window.h
@@ -10,14 +10,13 @@ QT_FORWARD_DECLARE_CLASS(QSlider)
QT_FORWARD_DECLARE_CLASS(QPushButton)
class GLWidget;
-class MainWindow;
class Window : public QWidget
{
Q_OBJECT
public:
- Window(MainWindow *mw);
+ Window();
protected:
void keyPressEvent(QKeyEvent *event) override;
@@ -26,6 +25,8 @@ private slots:
void dockUndock();
private:
+ void dock();
+ void undock();
QSlider *createSlider();
GLWidget *glWidget;
@@ -33,7 +34,6 @@ private:
QSlider *ySlider;
QSlider *zSlider;
QPushButton *dockBtn;
- MainWindow *mainWindow;
};
#endif
diff --git a/examples/opengl/hellogles3/CMakeLists.txt b/examples/opengl/hellogles3/CMakeLists.txt
index 917f64568c..07df173a47 100644
--- a/examples/opengl/hellogles3/CMakeLists.txt
+++ b/examples/opengl/hellogles3/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(hellogles3 LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/hellogles3")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL)
qt_standard_project_setup()
@@ -44,7 +38,14 @@ qt_add_resources(hellogles3 "hellogles3"
)
install(TARGETS hellogles3
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET hellogles3
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro
index f33921a79b..6ee57c7018 100644
--- a/examples/opengl/opengl.pro
+++ b/examples/opengl/opengl.pro
@@ -4,8 +4,7 @@ SUBDIRS = openglwindow \
hellogles3
qtHaveModule(widgets) {
- SUBDIRS += contextinfo \
- 2dpainting \
+ SUBDIRS += 2dpainting \
hellogl2 \
cube \
textures \
diff --git a/examples/opengl/openglwindow/CMakeLists.txt b/examples/opengl/openglwindow/CMakeLists.txt
index 3558ce549d..0258a42822 100644
--- a/examples/opengl/openglwindow/CMakeLists.txt
+++ b/examples/opengl/openglwindow/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(openglwindow LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/openglwindow")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(openglwindow PRIVATE
)
install(TARGETS openglwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET openglwindow
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/openglwindow/main.cpp b/examples/opengl/openglwindow/main.cpp
index 6813dc9efd..89933fa379 100644
--- a/examples/opengl/openglwindow/main.cpp
+++ b/examples/opengl/openglwindow/main.cpp
@@ -6,10 +6,10 @@
#include <QGuiApplication>
#include <QMatrix4x4>
#include <QOpenGLShaderProgram>
+#include <QOpenGLBuffer>
#include <QScreen>
#include <QtMath>
-
//! [1]
class TriangleWindow : public OpenGLWindow
{
@@ -20,10 +20,8 @@ public:
void render() override;
private:
- GLint m_posAttr = 0;
- GLint m_colAttr = 0;
GLint m_matrixUniform = 0;
-
+ QOpenGLBuffer m_vbo;
QOpenGLShaderProgram *m_program = nullptr;
int m_frame = 0;
};
@@ -48,36 +46,48 @@ int main(int argc, char **argv)
}
//! [2]
-
//! [3]
-static const char *vertexShaderSource =
- "attribute highp vec4 posAttr;\n"
- "attribute lowp vec4 colAttr;\n"
- "varying lowp vec4 col;\n"
- "uniform highp mat4 matrix;\n"
- "void main() {\n"
- " col = colAttr;\n"
- " gl_Position = matrix * posAttr;\n"
- "}\n";
-
-static const char *fragmentShaderSource =
- "varying lowp vec4 col;\n"
- "void main() {\n"
- " gl_FragColor = col;\n"
- "}\n";
+static const char *vertexShaderSource = "attribute highp vec4 posAttr;\n"
+ "attribute lowp vec4 colAttr;\n"
+ "varying lowp vec4 col;\n"
+ "uniform highp mat4 matrix;\n"
+ "void main() {\n"
+ " col = colAttr;\n"
+ " gl_Position = matrix * posAttr;\n"
+ "}\n";
+
+static const char *fragmentShaderSource = "varying lowp vec4 col;\n"
+ "void main() {\n"
+ " gl_FragColor = col;\n"
+ "}\n";
//! [3]
//! [4]
void TriangleWindow::initialize()
{
+ static const GLfloat vertices_colors[] = { +0.0f, +0.707f, 1.0f, 0.0f, 0.0f,
+ -0.5f, -0.500f, 0.0f, 1.0f, 0.0f,
+ +0.5f, -0.500f, 0.0f, 0.0f, 1.0f };
+
+ m_vbo.create();
+ m_vbo.bind();
+ m_vbo.allocate(vertices_colors, sizeof(vertices_colors));
+
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), nullptr);
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat),
+ reinterpret_cast<void *>(2 * sizeof(GLfloat)));
+
m_program = new QOpenGLShaderProgram(this);
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
+ m_program->bindAttributeLocation("posAttr", 0);
+ m_program->bindAttributeLocation("colAttr", 1);
m_program->link();
- m_posAttr = m_program->attributeLocation("posAttr");
- Q_ASSERT(m_posAttr != -1);
- m_colAttr = m_program->attributeLocation("colAttr");
- Q_ASSERT(m_colAttr != -1);
+ m_program->bind();
+
m_matrixUniform = m_program->uniformLocation("matrix");
Q_ASSERT(m_matrixUniform != -1);
}
@@ -100,28 +110,13 @@ void TriangleWindow::render()
m_program->setUniformValue(m_matrixUniform, matrix);
- static const GLfloat vertices[] = {
- 0.0f, 0.707f,
- -0.5f, -0.5f,
- 0.5f, -0.5f
- };
-
- static const GLfloat colors[] = {
- 1.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 1.0f
- };
-
- glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
- glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors);
-
- glEnableVertexAttribArray(m_posAttr);
- glEnableVertexAttribArray(m_colAttr);
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(m_colAttr);
- glDisableVertexAttribArray(m_posAttr);
+ glDisableVertexAttribArray(0);
+ glDisableVertexAttribArray(1);
m_program->release();
diff --git a/examples/opengl/stereoqopenglwidget/CMakeLists.txt b/examples/opengl/stereoqopenglwidget/CMakeLists.txt
index 214b359c66..d0fb7a0345 100644
--- a/examples/opengl/stereoqopenglwidget/CMakeLists.txt
+++ b/examples/opengl/stereoqopenglwidget/CMakeLists.txt
@@ -1,17 +1,11 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(stereoqopenglwidget LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/stereoqopenglwidget")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
qt_add_executable(stereoqopenglwidget
@@ -35,7 +29,14 @@ target_link_libraries(stereoqopenglwidget PUBLIC
install(TARGETS stereoqopenglwidget
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET stereoqopenglwidget
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/textures/CMakeLists.txt b/examples/opengl/textures/CMakeLists.txt
index 5103782381..2765355c5a 100644
--- a/examples/opengl/textures/CMakeLists.txt
+++ b/examples/opengl/textures/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(textures LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/textures")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
qt_standard_project_setup()
@@ -51,7 +45,14 @@ qt6_add_resources(textures "textures"
)
install(TARGETS textures
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET textures
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/textures/main.cpp b/examples/opengl/textures/main.cpp
index c1e91e6257..7e5f0646cb 100644
--- a/examples/opengl/textures/main.cpp
+++ b/examples/opengl/textures/main.cpp
@@ -8,8 +8,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(textures);
-
QApplication app(argc, argv);
QSurfaceFormat format;
diff --git a/examples/qpa/CMakeLists.txt b/examples/qpa/CMakeLists.txt
deleted file mode 100644
index a2b115fdf3..0000000000
--- a/examples/qpa/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-if(NOT TARGET Qt6::Gui)
- return()
-endif()
-qt_internal_add_example(windows)
-qt_internal_add_example(qrasterwindow)
diff --git a/examples/qpa/qpa.pro b/examples/qpa/qpa.pro
deleted file mode 100644
index 85b51dc5f4..0000000000
--- a/examples/qpa/qpa.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-requires(qtHaveModule(gui))
-
-TEMPLATE = subdirs
-SUBDIRS = windows \
- qrasterwindow
diff --git a/examples/qpa/qrasterwindow/CMakeLists.txt b/examples/qpa/qrasterwindow/CMakeLists.txt
deleted file mode 100644
index 02ac691da7..0000000000
--- a/examples/qpa/qrasterwindow/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(qrasterwindow LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qpa/qrasterwindow")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui)
-
-qt_standard_project_setup()
-
-qt_add_executable(qrasterwindow
- main.cpp
-)
-
-set_target_properties(qrasterwindow PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(qrasterwindow PRIVATE
- Qt6::Core
- Qt6::Gui
-)
-
-install(TARGETS qrasterwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qpa/qrasterwindow/main.cpp b/examples/qpa/qrasterwindow/main.cpp
deleted file mode 100644
index 9c245bf8a1..0000000000
--- a/examples/qpa/qrasterwindow/main.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QRasterWindow>
-#include <QPainter>
-#include <QPainterPath>
-#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, &QTimer::timeout, this, qOverload<>(&PaintedWindow::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
deleted file mode 100644
index e5bf34f25c..0000000000
--- a/examples/qpa/qrasterwindow/qrasterwindow.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-SOURCES += main.cpp
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qpa/qrasterwindow
-INSTALLS += target
diff --git a/examples/qpa/windows/CMakeLists.txt b/examples/qpa/windows/CMakeLists.txt
deleted file mode 100644
index d8088c0f68..0000000000
--- a/examples/qpa/windows/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(windows LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qpa/windows")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui)
-
-qt_standard_project_setup()
-
-qt_add_executable(windows
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(windows PROPERTIES
- WIN32_EXECUTABLE FALSE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(windows PRIVATE
- Qt6::Core
- Qt6::CorePrivate
- Qt6::Gui
- Qt6::GuiPrivate
-)
-
-install(TARGETS windows
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qpa/windows/main.cpp b/examples/qpa/windows/main.cpp
deleted file mode 100644
index b2ce40c439..0000000000
--- a/examples/qpa/windows/main.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QGuiApplication>
-#include <QScreen>
-#include <QRect>
-#include <QSharedPointer>
-
-#include "window.h"
-
-int main(int argc, char **argv)
-{
- typedef QSharedPointer<QWindow> WindowPtr;
-
- QGuiApplication app(argc, argv);
-
- Window a;
- a.setFramePosition(QPoint(10, 10));
- a.setTitle(QStringLiteral("Window A"));
- a.setObjectName(a.title());
- a.setVisible(true);
-
- Window b;
- b.setFramePosition(QPoint(100, 100));
- b.setTitle(QStringLiteral("Window B"));
- b.setObjectName(b.title());
- b.setVisible(true);
-
- Window child(&b);
- child.setObjectName(QStringLiteral("ChildOfB"));
- child.setVisible(true);
-
- // create one window on each additional screen as well
-
- QList<WindowPtr> windows;
- const QList<QScreen *> screens = app.screens();
- for (QScreen *screen : screens) {
- if (screen == app.primaryScreen())
- continue;
- WindowPtr window(new Window(screen));
- QRect geometry = window->geometry();
- geometry.moveCenter(screen->availableGeometry().center());
- window->setGeometry(geometry);
- window->setVisible(true);
- window->setTitle(screen->name());
- window->setObjectName(window->title());
- windows.push_back(window);
- }
- return app.exec();
-}
diff --git a/examples/qpa/windows/window.cpp b/examples/qpa/windows/window.cpp
deleted file mode 100644
index e86a4f7cfd..0000000000
--- a/examples/qpa/windows/window.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-
-#include <private/qguiapplication_p.h>
-
-#include <QBackingStore>
-#include <QPainter>
-
-static int colorIndexId = 0;
-
-QColor colorTable[] =
-{
- QColor("#f09f8f"),
- QColor("#a2bff2"),
- QColor("#c0ef8f")
-};
-
-Window::Window(QScreen *screen)
- : QWindow(screen)
- , m_backgroundColorIndex(colorIndexId++)
-{
- initialize();
-}
-
-Window::Window(QWindow *parent)
- : QWindow(parent)
- , m_backgroundColorIndex(colorIndexId++)
-{
- initialize();
-}
-
-void Window::initialize()
-{
- if (parent())
- setGeometry(QRect(160, 120, 320, 240));
- else {
- setFlags(flags() | Qt::WindowTitleHint | Qt::WindowSystemMenuHint
- | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- const QSize baseSize = QSize(640, 480);
- setGeometry(QRect(geometry().topLeft(), baseSize));
-
- setSizeIncrement(QSize(10, 10));
- setBaseSize(baseSize);
- setMinimumSize(QSize(240, 160));
- setMaximumSize(QSize(800, 600));
- }
-
- create();
- m_backingStore = new QBackingStore(this);
-
- m_image = QImage(geometry().size(), QImage::Format_RGB32);
- m_image.fill(colorTable[m_backgroundColorIndex % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba());
-
- m_lastPos = QPoint(-1, -1);
- m_renderTimer = 0;
-}
-
-void Window::mousePressEvent(QMouseEvent *event)
-{
- m_lastPos = event->position().toPoint();
-}
-
-void Window::mouseMoveEvent(QMouseEvent *event)
-{
- if (m_lastPos != QPoint(-1, -1)) {
- QPainter p(&m_image);
- p.setRenderHint(QPainter::Antialiasing);
- p.drawLine(m_lastPos, event->position().toPoint());
- m_lastPos = event->position().toPoint();
-
- scheduleRender();
- }
-}
-
-void Window::mouseReleaseEvent(QMouseEvent *event)
-{
- if (m_lastPos != QPoint(-1, -1)) {
- QPainter p(&m_image);
- p.setRenderHint(QPainter::Antialiasing);
- p.drawLine(m_lastPos, event->position().toPoint());
- m_lastPos = QPoint(-1, -1);
-
- scheduleRender();
- }
-}
-
-void Window::exposeEvent(QExposeEvent *)
-{
- scheduleRender();
-}
-
-void Window::resizeEvent(QResizeEvent *)
-{
- QImage old = m_image;
-
- int width = qMax(geometry().width(), old.width());
- int height = qMax(geometry().height(), old.height());
-
- if (width > old.width() || height > old.height()) {
- m_image = QImage(width, height, QImage::Format_RGB32);
- m_image.fill(colorTable[(m_backgroundColorIndex) % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba());
-
- QPainter p(&m_image);
- p.drawImage(0, 0, old);
- }
- scheduleRender();
-}
-
-void Window::keyPressEvent(QKeyEvent *event)
-{
- switch (event->key()) {
- case Qt::Key_Backspace:
- m_text.chop(1);
- break;
- case Qt::Key_Enter:
- case Qt::Key_Return:
- m_text.append('\n');
- break;
- default:
- m_text.append(event->text());
- break;
- }
- scheduleRender();
-}
-
-void Window::scheduleRender()
-{
- if (!m_renderTimer)
- m_renderTimer = startTimer(1);
-}
-
-void Window::timerEvent(QTimerEvent *)
-{
- if (isExposed())
- render();
- killTimer(m_renderTimer);
- m_renderTimer = 0;
-}
-
-void Window::render()
-{
- QRect rect(QPoint(), geometry().size());
- m_backingStore->resize(rect.size());
-
- m_backingStore->beginPaint(rect);
-
- QPaintDevice *device = m_backingStore->paintDevice();
-
- QPainter p(device);
- p.drawImage(0, 0, m_image);
-
- QFont font;
- font.setPixelSize(32);
-
- p.setFont(font);
- p.drawText(rect, 0, m_text);
-
- m_backingStore->endPaint();
- m_backingStore->flush(rect);
-}
-
-
diff --git a/examples/qpa/windows/window.h b/examples/qpa/windows/window.h
deleted file mode 100644
index c7eae4028a..0000000000
--- a/examples/qpa/windows/window.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWindow>
-#include <QImage>
-
-class Window : public QWindow
-{
-public:
- Window(QWindow *parent = nullptr);
- Window(QScreen *screen);
-
-protected:
- void mousePressEvent(QMouseEvent *) override;
- void mouseMoveEvent(QMouseEvent *) override;
- void mouseReleaseEvent(QMouseEvent *) override;
-
- void keyPressEvent(QKeyEvent *) override;
-
- void exposeEvent(QExposeEvent *) override;
- void resizeEvent(QResizeEvent *) override;
-
- void timerEvent(QTimerEvent *) override;
-
-private:
- void render();
- void scheduleRender();
- void initialize();
-
- QString m_text;
- QImage m_image;
- QPoint m_lastPos;
- int m_backgroundColorIndex;
- QBackingStore *m_backingStore;
- int m_renderTimer;
-};
-
-#endif // WINDOW_H
diff --git a/examples/qpa/windows/windows.pro b/examples/qpa/windows/windows.pro
deleted file mode 100644
index cf2b7ab200..0000000000
--- a/examples/qpa/windows/windows.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-CONFIG += console
-QT += gui-private core-private
-
-HEADERS += window.h
-SOURCES += window.cpp main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/qpa/windows
-INSTALLS += target
diff --git a/examples/qtconcurrent/CMakeLists.txt b/examples/qtconcurrent/CMakeLists.txt
index 6a5ef9e8ce..13e78678d8 100644
--- a/examples/qtconcurrent/CMakeLists.txt
+++ b/examples/qtconcurrent/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2023 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Concurrent)
return()
diff --git a/examples/qtconcurrent/imagescaling/CMakeLists.txt b/examples/qtconcurrent/imagescaling/CMakeLists.txt
index 9c63667a61..d053d04fc1 100644
--- a/examples/qtconcurrent/imagescaling/CMakeLists.txt
+++ b/examples/qtconcurrent/imagescaling/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(imagescaling LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtconcurrent/imagescaling")
-
find_package(Qt6 REQUIRED COMPONENTS Concurrent Core Gui Network Widgets)
qt_standard_project_setup()
@@ -34,7 +28,14 @@ target_link_libraries(imagescaling PRIVATE
)
install(TARGETS imagescaling
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET imagescaling
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc b/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc
index 6e17d408ca..499cb165c8 100644
--- a/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc
+++ b/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc
@@ -6,6 +6,7 @@
\meta tags {widgets, threads, network}
\title Image Scaling
\ingroup qtconcurrentexamples
+ \examplecategory {Networking}
\brief Demonstrates how to asynchronously download and scale images.
This example shows how to use the QFuture, QPromise, and QFutureWatcher
diff --git a/examples/qtconcurrent/primecounter/CMakeLists.txt b/examples/qtconcurrent/primecounter/CMakeLists.txt
index de098df324..c8ac5f20e8 100644
--- a/examples/qtconcurrent/primecounter/CMakeLists.txt
+++ b/examples/qtconcurrent/primecounter/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2023 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(primecounter LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtconcurrent/primecounter")
-
find_package(Qt6 REQUIRED COMPONENTS Concurrent Core Gui Widgets)
qt_standard_project_setup()
@@ -34,7 +28,14 @@ target_link_libraries(primecounter PRIVATE
)
install(TARGETS primecounter
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET primecounter
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qtconcurrent/primecounter/doc/src/qtconcurrent-primecounter.qdoc b/examples/qtconcurrent/primecounter/doc/src/qtconcurrent-primecounter.qdoc
index 75877c5a12..de6c94b0cf 100644
--- a/examples/qtconcurrent/primecounter/doc/src/qtconcurrent-primecounter.qdoc
+++ b/examples/qtconcurrent/primecounter/doc/src/qtconcurrent-primecounter.qdoc
@@ -6,6 +6,7 @@
\meta tags {widgets, threads}
\title Prime Counter
\ingroup qtconcurrentexamples
+ \examplecategory {Data Processing & I/O}
\brief Demonstrates how to monitor the progress of concurrent operations.
The following example demonstrates how to create an interactive and
diff --git a/examples/qtconcurrent/wordcount/CMakeLists.txt b/examples/qtconcurrent/wordcount/CMakeLists.txt
index 7cb5063963..0be10c3f35 100644
--- a/examples/qtconcurrent/wordcount/CMakeLists.txt
+++ b/examples/qtconcurrent/wordcount/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(wordcount LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtconcurrent/wordcount")
-
find_package(Qt6 REQUIRED COMPONENTS Concurrent Core Gui Widgets)
qt_standard_project_setup()
@@ -26,7 +20,14 @@ target_link_libraries(wordcount PRIVATE
)
install(TARGETS wordcount
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET wordcount
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc b/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc
index 50b6fc2964..adefdfdc59 100644
--- a/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc
+++ b/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc
@@ -6,6 +6,7 @@
\meta tags {threads, console}
\title Word Count
\ingroup qtconcurrentexamples
+ \examplecategory {Data Processing & I/O}
\brief Demonstrates how to use the map-reduce algorithm.
The Qt Concurrent \e {Word Count} example demonstrates the use of the
diff --git a/examples/qtestlib/CMakeLists.txt b/examples/qtestlib/CMakeLists.txt
index 3ce21c9bbd..6f139c87dc 100644
--- a/examples/qtestlib/CMakeLists.txt
+++ b/examples/qtestlib/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Widgets)
return()
diff --git a/examples/qtestlib/tutorial1/CMakeLists.txt b/examples/qtestlib/tutorial1/CMakeLists.txt
index cd44433a2f..b4fc090e94 100644
--- a/examples/qtestlib/tutorial1/CMakeLists.txt
+++ b/examples/qtestlib/tutorial1/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(tutorial1 LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtestlib/tutorial1")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(tutorial1 PRIVATE
)
install(TARGETS tutorial1
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET tutorial1
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qtestlib/tutorial2/CMakeLists.txt b/examples/qtestlib/tutorial2/CMakeLists.txt
index bf9ead1693..ff4862e3c4 100644
--- a/examples/qtestlib/tutorial2/CMakeLists.txt
+++ b/examples/qtestlib/tutorial2/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(tutorial2 LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtestlib/tutorial2")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(tutorial2 PRIVATE
)
install(TARGETS tutorial2
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET tutorial2
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qtestlib/tutorial3/CMakeLists.txt b/examples/qtestlib/tutorial3/CMakeLists.txt
index efde9c5b29..be09e1d05b 100644
--- a/examples/qtestlib/tutorial3/CMakeLists.txt
+++ b/examples/qtestlib/tutorial3/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(tutorial3 LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtestlib/tutorial3")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(tutorial3 PRIVATE
)
install(TARGETS tutorial3
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET tutorial3
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qtestlib/tutorial4/CMakeLists.txt b/examples/qtestlib/tutorial4/CMakeLists.txt
index 9101a2ce70..6f13c7c2ba 100644
--- a/examples/qtestlib/tutorial4/CMakeLists.txt
+++ b/examples/qtestlib/tutorial4/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(tutorial4 LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtestlib/tutorial4")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(tutorial4 PRIVATE
)
install(TARGETS tutorial4
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET tutorial4
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qtestlib/tutorial5/CMakeLists.txt b/examples/qtestlib/tutorial5/CMakeLists.txt
index ffd4879fd8..55bb4fb251 100644
--- a/examples/qtestlib/tutorial5/CMakeLists.txt
+++ b/examples/qtestlib/tutorial5/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(tutorial5 LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qtestlib/tutorial5")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(tutorial5 PRIVATE
)
install(TARGETS tutorial5
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET tutorial5
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/CMakeLists.txt b/examples/sql/CMakeLists.txt
index ce1014a06a..06d7d532d7 100644
--- a/examples/sql/CMakeLists.txt
+++ b/examples/sql/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Widgets)
return()
diff --git a/examples/sql/books/CMakeLists.txt b/examples/sql/books/CMakeLists.txt
index 86ca051c3b..3fff917163 100644
--- a/examples/sql/books/CMakeLists.txt
+++ b/examples/sql/books/CMakeLists.txt
@@ -1,22 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(books LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/books")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
qt_add_executable(books
bookdelegate.cpp bookdelegate.h
- bookwindow.cpp bookwindow.h bookwindow.ui
+ bookwindow.cpp bookwindow.h
initdb.h
main.cpp
)
@@ -35,7 +29,8 @@ target_link_libraries(books PRIVATE
# Resources:
set(books_resource_files
- "images/star.png"
+ "images/star.svg"
+ "images/star-filled.svg"
)
qt_add_resources(books "books"
@@ -46,7 +41,14 @@ qt_add_resources(books "books"
)
install(TARGETS books
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET books
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/books/bookdelegate.cpp b/examples/sql/books/bookdelegate.cpp
index af2a284298..ead9f9e7db 100644
--- a/examples/sql/books/bookdelegate.cpp
+++ b/examples/sql/books/bookdelegate.cpp
@@ -3,15 +3,13 @@
#include "bookdelegate.h"
-#include <QtWidgets>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QSpinBox>
-BookDelegate::BookDelegate(QObject *parent)
- : QSqlRelationalDelegate(parent), star(QPixmap(":images/star.png"))
-{
-}
-
-void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const
+void BookDelegate::paint(QPainter *painter,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
{
if (index.column() != 5) {
QSqlRelationalDelegate::paint(painter, option, index);
@@ -28,31 +26,33 @@ void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
option.rect,
option.palette.color(cg, QPalette::Highlight));
- int rating = model->data(index, Qt::DisplayRole).toInt();
- int width = star.width();
- int height = star.height();
- int x = option.rect.x();
+ const int rating = model->data(index, Qt::DisplayRole).toInt();
+ const int width = iconDimension;
+ const int height = width;
+ // add cellPadding / 2 to center the stars in the cell
+ int x = option.rect.x() + cellPadding / 2;
int y = option.rect.y() + (option.rect.height() / 2) - (height / 2);
- for (int i = 0; i < rating; ++i) {
- painter->drawPixmap(x, y, star);
+
+ QIcon starIcon(QStringLiteral(":images/star.svg"));
+ QIcon starFilledIcon(QStringLiteral(":images/star-filled.svg"));
+
+ for (int i = 0; i < 5; ++i) {
+ if (i < rating)
+ starFilledIcon.paint(painter, QRect(x, y, width, height));
+ else
+ starIcon.paint(painter, QRect(x, y, width, height));
x += width;
}
}
-
- QPen pen = painter->pen();
- painter->setPen(option.palette.color(QPalette::Mid));
- painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
- painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
- painter->setPen(pen);
}
QSize BookDelegate::sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const
+ const QModelIndex &index) const
{
if (index.column() == 5)
- return QSize(5 * star.width(), star.height()) + QSize(1, 1);
+ return QSize(5 * iconDimension, iconDimension) + QSize(cellPadding, cellPadding);
// Since we draw the grid ourselves:
- return QSqlRelationalDelegate::sizeHint(option, index) + QSize(1, 1);
+ return QSqlRelationalDelegate::sizeHint(option, index) + QSize(cellPadding, cellPadding);
}
bool BookDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
@@ -64,8 +64,8 @@ bool BookDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
- int stars = qBound(0, int(0.7 + qreal(mouseEvent->position().toPoint().x()
- - option.rect.x()) / star.width()), 5);
+ int stars = qBound(0, int(0.7 + qreal(mouseEvent->position().x()
+ - option.rect.x()) / iconDimension), 5);
model->setData(index, QVariant(stars));
// So that the selection can change:
return false;
diff --git a/examples/sql/books/bookdelegate.h b/examples/sql/books/bookdelegate.h
index d0b157b395..b36cb371ac 100644
--- a/examples/sql/books/bookdelegate.h
+++ b/examples/sql/books/bookdelegate.h
@@ -5,7 +5,6 @@
#define BOOKDELEGATE_H
#include <QModelIndex>
-#include <QPixmap>
#include <QSize>
#include <QSqlRelationalDelegate>
@@ -14,7 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QPainter)
class BookDelegate : public QSqlRelationalDelegate
{
public:
- BookDelegate(QObject *parent);
+ using QSqlRelationalDelegate::QSqlRelationalDelegate;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
@@ -30,7 +29,8 @@ public:
const QModelIndex &index) const override;
private:
- QPixmap star;
+ const int cellPadding = 6;
+ const int iconDimension = 24;
};
#endif
diff --git a/examples/sql/books/books.pro b/examples/sql/books/books.pro
index 870e4a6c00..953945912e 100644
--- a/examples/sql/books/books.pro
+++ b/examples/sql/books/books.pro
@@ -4,7 +4,6 @@ INCLUDEPATH += .
HEADERS = bookdelegate.h bookwindow.h initdb.h
RESOURCES = books.qrc
SOURCES = bookdelegate.cpp main.cpp bookwindow.cpp
-FORMS = bookwindow.ui
QT += sql widgets widgets
requires(qtConfig(tableview))
diff --git a/examples/sql/books/books.qrc b/examples/sql/books/books.qrc
index 342638ecb0..1a4dac32cc 100644
--- a/examples/sql/books/books.qrc
+++ b/examples/sql/books/books.qrc
@@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
- <file>images/star.png</file>
+ <file>images/star.svg</file>
+ <file>images/star-filled.svg</file>
</qresource>
</RCC>
diff --git a/examples/sql/books/bookwindow.cpp b/examples/sql/books/bookwindow.cpp
index 2ec5459e1b..6de2d5e80a 100644
--- a/examples/sql/books/bookwindow.cpp
+++ b/examples/sql/books/bookwindow.cpp
@@ -5,18 +5,27 @@
#include "bookdelegate.h"
#include "initdb.h"
-#include <QtSql>
+#include <QApplication>
+#include <QComboBox>
+#include <QDataWidgetMapper>
+#include <QGridLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenu>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QPainter>
+#include <QScrollBar>
+#include <QSpinBox>
+#include <QSqlDatabase>
+#include <QTableView>
BookWindow::BookWindow()
{
- ui.setupUi(this);
-
if (!QSqlDatabase::drivers().contains("QSQLITE"))
- QMessageBox::critical(
- this,
- "Unable to load database",
- "This demo needs the SQLITE driver"
- );
+ QMessageBox::critical(this, tr("Unable to load database"),
+ tr("This demo needs the SQLITE driver"));
// Initialize the database:
QSqlError err = initDb();
@@ -25,20 +34,87 @@ BookWindow::BookWindow()
return;
}
- // Create the data model:
- model = new QSqlRelationalTableModel(ui.bookTable);
+ // create the central widget for the window
+ window = new QWidget(this);
+ setCentralWidget(window);
+
+ createLayout();
+
+ createModel();
+
+ // Populate the model
+ if (!model->select()) {
+ showError(model->lastError());
+ return;
+ }
+
+ configureWidgets();
+
+ // create the mappings between the UI elements and the SQL model
+ createMappings();
+
+ tableView->setCurrentIndex(model->index(0, 0));
+ tableView->selectRow(0);
+
+ createMenuBar();
+}
+
+void BookWindow::showError(const QSqlError &err)
+{
+ QMessageBox::critical(this, tr("Unable to initialize Database"),
+ tr("Error initializing database: %1").arg(err.text()));
+}
+
+void BookWindow::createLayout()
+{
+ tableView = new QTableView(window);
+
+ gridLayout = new QGridLayout(window);
+
+ titleLabel = new QLabel(tr("Title:"), window);
+ titleLineEdit = new QLineEdit(window);
+ authorLabel = new QLabel(tr("Author:"), window);
+ authorComboBox = new QComboBox(window);
+ genreLabel = new QLabel(tr("Genre:"), window);
+ genreComboBox = new QComboBox(window);
+ yearLabel = new QLabel(tr("Year:"), window);
+ yearSpinBox = new QSpinBox(window);
+ ratingLabel = new QLabel(tr("Rating:"), window);
+ ratingComboBox = new QComboBox(window);
+
+ gridLayout->addWidget(titleLabel, 0, 0, Qt::AlignRight);
+ gridLayout->addWidget(titleLineEdit, 0, 1, 1, 3);
+ gridLayout->addWidget(authorLabel, 1, 0, Qt::AlignRight);
+ gridLayout->addWidget(authorComboBox, 1, 1);
+ gridLayout->addWidget(yearLabel, 1, 2, Qt::AlignRight);
+ gridLayout->addWidget(yearSpinBox, 1, 3);
+ gridLayout->addWidget(genreLabel, 2, 0, Qt::AlignRight);
+ gridLayout->addWidget(genreComboBox, 2, 1);
+ gridLayout->addWidget(ratingLabel, 2, 2, Qt::AlignRight);
+ gridLayout->addWidget(ratingComboBox, 2, 3);
+ gridLayout->addWidget(tableView, 3, 0, 1, 4, Qt::AlignCenter);
+ gridLayout->setColumnStretch(1, 1000);
+ gridLayout->setColumnStretch(3, 1000);
+
+ gridLayout->setContentsMargins(18, 18, 18, 18);
+ gridLayout->setSpacing(18);
+ gridLayout->setAlignment(Qt::AlignHCenter);
+}
+
+void BookWindow::createModel()
+{
+ model = new QSqlRelationalTableModel(tableView);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setTable("books");
- // Remember the indexes of the columns:
authorIdx = model->fieldIndex("author");
genreIdx = model->fieldIndex("genre");
- // Set the relations to the other database tables:
+ // Set the relations to the other database tables
model->setRelation(authorIdx, QSqlRelation("authors", "id", "name"));
model->setRelation(genreIdx, QSqlRelation("genres", "id", "name"));
- // Set the localized header captions:
+ // Set the localised header captions
model->setHeaderData(authorIdx, Qt::Horizontal, tr("Author Name"));
model->setHeaderData(genreIdx, Qt::Horizontal, tr("Genre"));
model->setHeaderData(model->fieldIndex("title"),
@@ -46,56 +122,81 @@ BookWindow::BookWindow()
model->setHeaderData(model->fieldIndex("year"), Qt::Horizontal, tr("Year"));
model->setHeaderData(model->fieldIndex("rating"),
Qt::Horizontal, tr("Rating"));
+}
- // Populate the model:
- if (!model->select()) {
- showError(model->lastError());
- return;
+void BookWindow::configureWidgets()
+{
+ tableView->setModel(model);
+ tableView->setItemDelegate(new BookDelegate(tableView));
+ tableView->setColumnHidden(model->fieldIndex("id"), true);
+ tableView->verticalHeader()->setVisible(false);
+ tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
+
+ // Lock and prohibit resizing of the width of the columns
+ tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
+ tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
+ tableView->horizontalHeader()->setFixedHeight(tableView->rowHeight(0));
+
+ // increment by two to consider the frame
+ tableView->setFixedWidth(tableView->horizontalHeader()->length() +
+ tableView->verticalScrollBar()->sizeHint().width() + 2);
+ tableView->setMaximumHeight(tableView->verticalHeader()->length() +
+ tableView->horizontalHeader()->height() + 2);
+
+ authorComboBox->setModel(model->relationModel(authorIdx));
+ authorComboBox->setModelColumn(model->relationModel(authorIdx)->fieldIndex("name"));
+
+ genreComboBox->setModel(model->relationModel(genreIdx));
+ genreComboBox->setModelColumn(model->relationModel(genreIdx)->fieldIndex("name"));
+
+ yearSpinBox->setMaximum(9999);
+
+ const int width = 16;
+ const int height = width;
+ const int y = 2;
+ const int padding = 2;
+
+ QSize iconSize = QSize(width * 5 + padding * 2, width + padding * 2);
+ QIcon starIcon(QStringLiteral(":images/star.svg"));
+ QIcon starFilledIcon(QStringLiteral(":images/star-filled.svg"));
+
+ for (int row = 0; row < 6; ++row) {
+ QPixmap icon(iconSize);
+ icon.fill(Qt::transparent);
+ QPainter painter(&icon);
+ int x = 2;
+
+ for (int col = 0; col < 5; ++col) {
+ if (col < row) {
+ starFilledIcon.paint(&painter, QRect(x, y, width, height));
+ } else {
+ starIcon.paint(&painter, QRect(x, y, width, height));
+ }
+ x += width;
+ }
+ ratingComboBox->addItem(icon, "");
+ ratingComboBox->setItemData(row, QString::number(row + 1));
}
- // Set the model and hide the ID column:
- ui.bookTable->setModel(model);
- ui.bookTable->setItemDelegate(new BookDelegate(ui.bookTable));
- ui.bookTable->setColumnHidden(model->fieldIndex("id"), true);
- ui.bookTable->setSelectionMode(QAbstractItemView::SingleSelection);
-
- // Initialize the Author combo box:
- ui.authorEdit->setModel(model->relationModel(authorIdx));
- ui.authorEdit->setModelColumn(
- model->relationModel(authorIdx)->fieldIndex("name"));
-
- ui.genreEdit->setModel(model->relationModel(genreIdx));
- ui.genreEdit->setModelColumn(
- model->relationModel(genreIdx)->fieldIndex("name"));
-
- // Lock and prohibit resizing of the width of the rating column:
- ui.bookTable->horizontalHeader()->setSectionResizeMode(
- model->fieldIndex("rating"),
- QHeaderView::ResizeToContents);
+ ratingComboBox->setIconSize(iconSize);
+}
+void BookWindow::createMappings()
+{
QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->setItemDelegate(new BookDelegate(this));
- mapper->addMapping(ui.titleEdit, model->fieldIndex("title"));
- mapper->addMapping(ui.yearEdit, model->fieldIndex("year"));
- mapper->addMapping(ui.authorEdit, authorIdx);
- mapper->addMapping(ui.genreEdit, genreIdx);
- mapper->addMapping(ui.ratingEdit, model->fieldIndex("rating"));
-
- connect(ui.bookTable->selectionModel(),
+ mapper->addMapping(titleLineEdit, model->fieldIndex("title"));
+ mapper->addMapping(yearSpinBox, model->fieldIndex("year"));
+ mapper->addMapping(authorComboBox, authorIdx);
+ mapper->addMapping(genreComboBox, genreIdx);
+ mapper->addMapping(ratingComboBox, model->fieldIndex("rating"), "currentIndex");
+ connect(tableView->selectionModel(),
&QItemSelectionModel::currentRowChanged,
mapper,
&QDataWidgetMapper::setCurrentModelIndex
);
-
- ui.bookTable->setCurrentIndex(model->index(0, 0));
- createMenuBar();
-}
-
-void BookWindow::showError(const QSqlError &err)
-{
- QMessageBox::critical(this, "Unable to initialize Database",
- "Error initializing database: " + err.text());
}
void BookWindow::createMenuBar()
diff --git a/examples/sql/books/bookwindow.h b/examples/sql/books/bookwindow.h
index ba569292a6..46d3570df1 100644
--- a/examples/sql/books/bookwindow.h
+++ b/examples/sql/books/bookwindow.h
@@ -4,11 +4,15 @@
#ifndef BOOKWINDOW_H
#define BOOKWINDOW_H
-#include <QtWidgets>
-#include <QtSql>
-
-#include "ui_bookwindow.h"
-
+#include <QMainWindow>
+QT_FORWARD_DECLARE_CLASS(QComboBox)
+QT_FORWARD_DECLARE_CLASS(QGridLayout)
+QT_FORWARD_DECLARE_CLASS(QLabel)
+QT_FORWARD_DECLARE_CLASS(QLineEdit)
+QT_FORWARD_DECLARE_CLASS(QSpinBox)
+QT_FORWARD_DECLARE_CLASS(QSqlError)
+QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel)
+QT_FORWARD_DECLARE_CLASS(QTableView)
class BookWindow: public QMainWindow
{
@@ -21,11 +25,29 @@ private slots:
private:
void showError(const QSqlError &err);
- Ui::BookWindow ui;
- QSqlRelationalTableModel *model;
- int authorIdx, genreIdx;
+ QSqlRelationalTableModel *model = nullptr;
+ int authorIdx = 0, genreIdx = 0;
+ void createLayout();
+ void createModel();
+ void configureWidgets();
+ void createMappings();
void createMenuBar();
+
+ QWidget *window = nullptr;
+
+ QGridLayout *gridLayout = nullptr;
+ QTableView *tableView = nullptr;
+ QLabel *titleLabel = nullptr;
+ QLineEdit *titleLineEdit = nullptr;
+ QLabel *authorLabel = nullptr;
+ QComboBox *authorComboBox = nullptr;
+ QLabel *genreLabel = nullptr;
+ QComboBox *genreComboBox = nullptr;
+ QLabel *yearLabel = nullptr;
+ QSpinBox *yearSpinBox = nullptr;
+ QLabel *ratingLabel = nullptr;
+ QComboBox *ratingComboBox = nullptr;
};
#endif
diff --git a/examples/sql/books/bookwindow.ui b/examples/sql/books/bookwindow.ui
deleted file mode 100644
index ce8f9f933a..0000000000
--- a/examples/sql/books/bookwindow.ui
+++ /dev/null
@@ -1,164 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>BookWindow</class>
- <widget class="QMainWindow" name="BookWindow">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>601</width>
- <height>420</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Books</string>
- </property>
- <widget class="QWidget" name="centralWidget">
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="leftMargin">
- <number>9</number>
- </property>
- <property name="topMargin">
- <number>9</number>
- </property>
- <property name="rightMargin">
- <number>9</number>
- </property>
- <property name="bottomMargin">
- <number>9</number>
- </property>
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string/>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="leftMargin">
- <number>9</number>
- </property>
- <property name="topMargin">
- <number>9</number>
- </property>
- <property name="rightMargin">
- <number>9</number>
- </property>
- <property name="bottomMargin">
- <number>9</number>
- </property>
- <item>
- <widget class="QTableView" name="bookTable">
- <property name="selectionBehavior">
- <enum>QAbstractItemView::SelectRows</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="groupBox_2">
- <property name="title">
- <string>Details</string>
- </property>
- <layout class="QFormLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>&lt;b&gt;Title:&lt;/b&gt;</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="titleEdit">
- <property name="enabled">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>&lt;b&gt;Author: &lt;/b&gt;</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QComboBox" name="authorEdit">
- <property name="enabled">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>&lt;b&gt;Genre:&lt;/b&gt;</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QComboBox" name="genreEdit">
- <property name="enabled">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>&lt;b&gt;Year:&lt;/b&gt;</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QSpinBox" name="yearEdit">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="prefix">
- <string/>
- </property>
- <property name="minimum">
- <number>-1000</number>
- </property>
- <property name="maximum">
- <number>2100</number>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>&lt;b&gt;Rating:&lt;/b&gt;</string>
- </property>
- </widget>
- </item>
- <item row="4" column="1">
- <widget class="QSpinBox" name="ratingEdit">
- <property name="maximum">
- <number>5</number>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
- <tabstops>
- <tabstop>bookTable</tabstop>
- <tabstop>titleEdit</tabstop>
- <tabstop>authorEdit</tabstop>
- <tabstop>genreEdit</tabstop>
- <tabstop>yearEdit</tabstop>
- </tabstops>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/sql/books/images/star-filled.svg b/examples/sql/books/images/star-filled.svg
new file mode 100644
index 0000000000..8a2aee27fb
--- /dev/null
+++ b/examples/sql/books/images/star-filled.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#0d0d0d"><path d="M8.41 18.138L12 15.845l3.59 2.323-.94-4.345 3.162-2.897-4.159-.392L12 6.43l-1.652 4.073-4.159.392 3.162 2.927-.94 4.315zm-1.346 3.696a1.04 1.04 0 0 1-1.567-1.104l1.318-6.033-4.476-4.11c-.665-.611-.293-1.726.604-1.808l5.866-.539 2.229-5.587c.348-.872 1.575-.872 1.923 0l2.229 5.587 5.866.539c.897.082 1.269 1.197.604 1.808l-4.476 4.11 1.318 6.033a1.04 1.04 0 0 1-1.567 1.104L12 18.681l-4.935 3.153z"/><path d="M12 5l-1.796 5.528H4.392l4.702 3.416-1.796 5.528L12 16.056l4.702 3.416-1.796-5.528 4.702-3.416h-5.812L12 5z"/></svg>
diff --git a/examples/sql/books/images/star.png b/examples/sql/books/images/star.png
deleted file mode 100644
index 87f4464bd5..0000000000
--- a/examples/sql/books/images/star.png
+++ /dev/null
Binary files differ
diff --git a/examples/sql/books/images/star.svg b/examples/sql/books/images/star.svg
new file mode 100644
index 0000000000..d959abc182
--- /dev/null
+++ b/examples/sql/books/images/star.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path d="M8.41 18.138L12 15.845l3.59 2.323-.94-4.345 3.162-2.897-4.159-.392L12 6.43l-1.652 4.073-4.159.392 3.162 2.927-.94 4.315zm-1.346 3.696a1.04 1.04 0 0 1-1.567-1.104l1.318-6.033-4.476-4.11c-.665-.611-.293-1.726.604-1.808l5.866-.539 2.229-5.587c.348-.872 1.575-.872 1.923 0l2.229 5.587 5.866.539c.897.082 1.269 1.197.604 1.808l-4.476 4.11 1.318 6.033a1.04 1.04 0 0 1-1.567 1.104L12 18.681l-4.935 3.153z" fill="#0d0d0d"/></svg>
diff --git a/examples/sql/books/initdb.h b/examples/sql/books/initdb.h
index 38fc9aeb71..9de8845a2f 100644
--- a/examples/sql/books/initdb.h
+++ b/examples/sql/books/initdb.h
@@ -4,7 +4,9 @@
#ifndef INITDB_H
#define INITDB_H
-#include <QtSql>
+#include <QDate>
+#include <QSqlError>
+#include <QSqlQuery>
void addBook(QSqlQuery &q, const QString &title, int year, const QVariant &authorId,
const QVariant &genreId, int rating)
diff --git a/examples/sql/books/main.cpp b/examples/sql/books/main.cpp
index d06568ed36..76a05f1c39 100644
--- a/examples/sql/books/main.cpp
+++ b/examples/sql/books/main.cpp
@@ -3,12 +3,10 @@
#include "bookwindow.h"
-#include <QtWidgets>
+#include <QApplication>
int main(int argc, char * argv[])
{
- Q_INIT_RESOURCE(books);
-
QApplication app(argc, argv);
BookWindow win;
diff --git a/examples/sql/cachedtable/CMakeLists.txt b/examples/sql/cachedtable/CMakeLists.txt
index 4a19000fa7..af6843b734 100644
--- a/examples/sql/cachedtable/CMakeLists.txt
+++ b/examples/sql/cachedtable/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(cachedtable LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/cachedtable")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(cachedtable PRIVATE
)
install(TARGETS cachedtable
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET cachedtable
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/cachedtable/tableeditor.cpp b/examples/sql/cachedtable/tableeditor.cpp
index 97b3fa0d96..b92e256438 100644
--- a/examples/sql/cachedtable/tableeditor.cpp
+++ b/examples/sql/cachedtable/tableeditor.cpp
@@ -1,11 +1,16 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-#include <QtSql>
-
#include "tableeditor.h"
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QMessageBox>
+#include <QPushButton>
+#include <QSqlError>
+#include <QSqlTableModel>
+#include <QTableView>
+
//! [0]
TableEditor::TableEditor(const QString &tableName, QWidget *parent)
: QWidget(parent)
diff --git a/examples/sql/cachedtable/tableeditor.h b/examples/sql/cachedtable/tableeditor.h
index dfa50a8934..8c3c56b397 100644
--- a/examples/sql/cachedtable/tableeditor.h
+++ b/examples/sql/cachedtable/tableeditor.h
@@ -6,11 +6,9 @@
#include <QDialog>
-QT_BEGIN_NAMESPACE
-class QDialogButtonBox;
-class QPushButton;
-class QSqlTableModel;
-QT_END_NAMESPACE
+QT_FORWARD_DECLARE_CLASS(QDialogButtonBox)
+QT_FORWARD_DECLARE_CLASS(QPushButton)
+QT_FORWARD_DECLARE_CLASS(QSqlTableModel)
//! [0]
class TableEditor : public QWidget
diff --git a/examples/sql/doc/images/books-demo.png b/examples/sql/doc/images/books-demo.png
index 77b3b308c9..29f5c84473 100644
--- a/examples/sql/doc/images/books-demo.png
+++ b/examples/sql/doc/images/books-demo.png
Binary files differ
diff --git a/examples/sql/doc/images/drilldown-example.png b/examples/sql/doc/images/drilldown-example.png
index 39a4117637..b6cf443e7c 100644
--- a/examples/sql/doc/images/drilldown-example.png
+++ b/examples/sql/doc/images/drilldown-example.png
Binary files differ
diff --git a/examples/sql/doc/src/books.qdoc b/examples/sql/doc/src/books.qdoc
index c08d2f975a..b4ca8bdd2e 100644
--- a/examples/sql/doc/src/books.qdoc
+++ b/examples/sql/doc/src/books.qdoc
@@ -5,6 +5,7 @@
\example books
\title Books
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief Shows how to use Qt SQL classes with a model/view framework.
The Books example shows how Qt's SQL classes can be used with the model/view
diff --git a/examples/sql/doc/src/cachedtable.qdoc b/examples/sql/doc/src/cachedtable.qdoc
index 4b0d3ac1a1..ff60f7b1b7 100644
--- a/examples/sql/doc/src/cachedtable.qdoc
+++ b/examples/sql/doc/src/cachedtable.qdoc
@@ -5,7 +5,7 @@
\example cachedtable
\title Cached SQL Table
\ingroup sql_examples
- \examplecategory {Input/Output}
+ \examplecategory {Data Processing & I/O}
\brief The Cached Table example shows how a table view can be used to access a database,
caching any changes to the data until the user explicitly submits them using a
diff --git a/examples/sql/doc/src/drilldown.qdoc b/examples/sql/doc/src/drilldown.qdoc
index 4e432b7016..d334018b4a 100644
--- a/examples/sql/doc/src/drilldown.qdoc
+++ b/examples/sql/doc/src/drilldown.qdoc
@@ -5,6 +5,7 @@
\example drilldown
\title Drill Down Example
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief The Drill Down example shows how to read data from a database as
well as submit changes, using the QSqlRelationalTableModel and
@@ -45,8 +46,8 @@
\snippet drilldown/informationwindow.h 0
When we create an information window, we pass the associated
- item ID, a parent, and a pointer to the database, to the
- constructor. We will use the database pointer to populate our
+ item ID, a pointer to the model, and a parent to the
+ constructor. We will use the model pointer to populate our
window with data, while passing the parent parameter on to the
base class. The ID is stored for future reference.
@@ -153,10 +154,6 @@
We need to use lambdas for connecting the \c enableButtons slot
because its signature does not match \c QTextEdit::textChanged
and \c QComboBox::currentIndexChanged.
- Since the latter has another overload with the signature
- \c {const QString &} and the selected signal would be ambiguous,
- we need to use \c QOverload<int>::of to select a specific overload
- for \c currentIndexChanged.
We add all the widgets into a layout, store the item ID and the
name of the displayed image file for future reference, and set
diff --git a/examples/sql/doc/src/masterdetail.qdoc b/examples/sql/doc/src/masterdetail.qdoc
index 9fcf50870b..fec579a6a0 100644
--- a/examples/sql/doc/src/masterdetail.qdoc
+++ b/examples/sql/doc/src/masterdetail.qdoc
@@ -5,6 +5,7 @@
\example masterdetail
\title Master Detail Example
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief The Master Detail Example shows how to present data from different
data sources in the same application. The album titles, and the
diff --git a/examples/sql/doc/src/querymodel.qdoc b/examples/sql/doc/src/querymodel.qdoc
index 38f7acab5c..c9fa4cec96 100644
--- a/examples/sql/doc/src/querymodel.qdoc
+++ b/examples/sql/doc/src/querymodel.qdoc
@@ -5,6 +5,7 @@
\example querymodel
\title Query Model Example
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief The Query Model example shows how to make customized versions of
data obtained from a SQL query, using a model that encapsulates
diff --git a/examples/sql/doc/src/relationaltablemodel.qdoc b/examples/sql/doc/src/relationaltablemodel.qdoc
index cf95cb4aad..371fef8133 100644
--- a/examples/sql/doc/src/relationaltablemodel.qdoc
+++ b/examples/sql/doc/src/relationaltablemodel.qdoc
@@ -5,6 +5,7 @@
\example relationaltablemodel
\title Relational Table Model Example
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief The Relational Table Model example shows how to use table views with a relational
model to visualize the relations between items in a database.
diff --git a/examples/sql/doc/src/sqlbrowser.qdoc b/examples/sql/doc/src/sqlbrowser.qdoc
index 0cabea09aa..ad783f5760 100644
--- a/examples/sql/doc/src/sqlbrowser.qdoc
+++ b/examples/sql/doc/src/sqlbrowser.qdoc
@@ -5,6 +5,7 @@
\example sqlbrowser
\title SQL Browser
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief The SQL Browser example shows how a data browser can be used to visualize
the results of SQL statements on a live database.
diff --git a/examples/sql/doc/src/sqlwidgetmapper.qdoc b/examples/sql/doc/src/sqlwidgetmapper.qdoc
index 2e921f479c..0764e601c3 100644
--- a/examples/sql/doc/src/sqlwidgetmapper.qdoc
+++ b/examples/sql/doc/src/sqlwidgetmapper.qdoc
@@ -5,6 +5,7 @@
\example sqlwidgetmapper
\title SQL Widget Mapper Example
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief The SQL Widget Mapper example shows how to use a map information from a
database to widgets on a form.
@@ -101,8 +102,7 @@
As a result, the user is able to select an item from the combo box,
and the associated value is written back to the model.
- The rest of the constructor is very similar to that of the
- \l{Simple Widget Mapper Example}:
+ The rest of the constructor sets up connections and layouts:
\snippet sqlwidgetmapper/window.cpp Set up connections and layouts
@@ -115,7 +115,7 @@
\section1 Delegate Class Definition and Implementation
The delegate we use to mediate interaction between the widget mapper and
- the input widgets is a small QItemDelegate subclass:
+ the input widgets is a small QStyledItemDelegate subclass:
\snippet sqlwidgetmapper/delegate.h Delegate class definition
@@ -126,7 +126,7 @@
Since we only provide an empty implementation of the constructor, we
concentrate on the other two functions.
- The \l{QItemDelegate::}{setEditorData()} implementation takes the data
+ The \l{QStyledItemDelegate::}{setEditorData()} implementation takes the data
referred to by the model index supplied and processes it according to
the presence of a \c currentIndex property in the editor widget:
@@ -138,10 +138,10 @@
values needed for the \c currentIndex property.
As a result, instead of showing "0", "1" or "2" in the combo box, one of
- its predefined set of items is shown. We call QItemDelegate::setEditorData()
+ its predefined set of items is shown. We call QStyledItemDelegate::setEditorData()
for widgets without the \c currentIndex property.
- The \l{QItemDelegate::}{setModelData()} implementation performs the reverse
+ The \l{QStyledItemDelegate::}{setModelData()} implementation performs the reverse
process, taking the value stored in the widget's \c currentIndex property
and storing it back in the model:
diff --git a/examples/sql/doc/src/tablemodel.qdoc b/examples/sql/doc/src/tablemodel.qdoc
index 420c3cd943..1542d121aa 100644
--- a/examples/sql/doc/src/tablemodel.qdoc
+++ b/examples/sql/doc/src/tablemodel.qdoc
@@ -5,6 +5,7 @@
\example tablemodel
\title Table Model Example
\ingroup sql_examples
+ \examplecategory {Data Processing & I/O}
\brief The Table Model example shows how to use a specialized SQL table model with table
views to edit information in a database.
diff --git a/examples/sql/drilldown/CMakeLists.txt b/examples/sql/drilldown/CMakeLists.txt
index 19140080a2..fb9b441fa3 100644
--- a/examples/sql/drilldown/CMakeLists.txt
+++ b/examples/sql/drilldown/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(drilldown LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/drilldown")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
@@ -50,7 +44,14 @@ qt_add_resources(drilldown "drilldown"
)
install(TARGETS drilldown
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET drilldown
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/drilldown/imageitem.cpp b/examples/sql/drilldown/imageitem.cpp
index 59f1255f9f..4dfb5ee6e8 100644
--- a/examples/sql/drilldown/imageitem.cpp
+++ b/examples/sql/drilldown/imageitem.cpp
@@ -54,7 +54,7 @@ void ImageItem::setFrame(int frame)
QPointF center = boundingRect().center();
setTransform(QTransform::fromTranslate(center.x(), center.y()), true);
- setTransform(QTransform::fromScale(1 + frame / 330.0, 1 + frame / 330.0), true);
+ setTransform(QTransform::fromScale(1 + frame / 300.0, 1 + frame / 300.0), true);
setTransform(QTransform::fromTranslate(-center.x(), -center.y()), true);
}
//! [3]
@@ -62,8 +62,8 @@ void ImageItem::setFrame(int frame)
//! [4]
void ImageItem::adjust()
{
- setTransform(QTransform::fromScale(120 / boundingRect().width(),
- 120 / boundingRect().height()));
+ setTransform(QTransform::fromScale(120.0 / boundingRect().width(),
+ 120.0 / boundingRect().height()));
}
//! [4]
diff --git a/examples/sql/drilldown/imageitem.h b/examples/sql/drilldown/imageitem.h
index f6be4d50ab..23a41aa2f2 100644
--- a/examples/sql/drilldown/imageitem.h
+++ b/examples/sql/drilldown/imageitem.h
@@ -11,7 +11,6 @@
class ImageItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
-
public:
enum { Type = UserType + 1 };
@@ -25,7 +24,7 @@ protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
-private slots:
+private Q_SLOTS:
void setFrame(int frame);
void updateItemPosition();
diff --git a/examples/sql/drilldown/images/qt-creator.png b/examples/sql/drilldown/images/qt-creator.png
index 0602bdcad1..576f9f39ff 100644
--- a/examples/sql/drilldown/images/qt-creator.png
+++ b/examples/sql/drilldown/images/qt-creator.png
Binary files differ
diff --git a/examples/sql/drilldown/images/qt-logo.png b/examples/sql/drilldown/images/qt-logo.png
index 7603fa0c90..fb8b1686bd 100644
--- a/examples/sql/drilldown/images/qt-logo.png
+++ b/examples/sql/drilldown/images/qt-logo.png
Binary files differ
diff --git a/examples/sql/drilldown/images/qt-project.png b/examples/sql/drilldown/images/qt-project.png
index e066fbe3f9..8c20e3f0c2 100644
--- a/examples/sql/drilldown/images/qt-project.png
+++ b/examples/sql/drilldown/images/qt-project.png
Binary files differ
diff --git a/examples/sql/drilldown/images/qt-quick.png b/examples/sql/drilldown/images/qt-quick.png
index 90d9fd075d..a905f47c35 100644
--- a/examples/sql/drilldown/images/qt-quick.png
+++ b/examples/sql/drilldown/images/qt-quick.png
Binary files differ
diff --git a/examples/sql/drilldown/informationwindow.cpp b/examples/sql/drilldown/informationwindow.cpp
index 4f9896d74d..d69c91d0cb 100644
--- a/examples/sql/drilldown/informationwindow.cpp
+++ b/examples/sql/drilldown/informationwindow.cpp
@@ -9,9 +9,9 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items,
: QDialog(parent)
{
//! [0] //! [1]
- QLabel *itemLabel = new QLabel(tr("Item: "));
- QLabel *descriptionLabel = new QLabel(tr("Description: "));
- QLabel *imageFileLabel = new QLabel(tr("Image file: "));
+ QLabel *itemLabel = new QLabel(tr("Item:"));
+ QLabel *descriptionLabel = new QLabel(tr("Description:"));
+ QLabel *imageFileLabel = new QLabel(tr("Image file:"));
createButtons();
@@ -37,12 +37,8 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items,
//! [3]
//! [4]
- connect(descriptionEditor, &QTextEdit::textChanged, [=]() {
- enableButtons();
- });
- connect(imageFileEditor, &QComboBox::currentIndexChanged, [=]() {
- enableButtons();
- });
+ connect(descriptionEditor, &QTextEdit::textChanged, this, [this]() { enableButtons(true); });
+ connect(imageFileEditor, &QComboBox::currentIndexChanged, this, [this]() { enableButtons(true); });
QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(itemLabel, itemText);
diff --git a/examples/sql/drilldown/informationwindow.h b/examples/sql/drilldown/informationwindow.h
index 368d99c303..2380463785 100644
--- a/examples/sql/drilldown/informationwindow.h
+++ b/examples/sql/drilldown/informationwindow.h
@@ -11,22 +11,20 @@
class InformationWindow : public QDialog
{
Q_OBJECT
-
public:
InformationWindow(int id, QSqlRelationalTableModel *items,
QWidget *parent = nullptr);
-
int id() const;
-signals:
+Q_SIGNALS:
void imageChanged(int id, const QString &fileName);
//! [0]
//! [1]
-private slots:
+private Q_SLOTS:
void revert();
void submit();
- void enableButtons(bool enable = true);
+ void enableButtons(bool enable);
//! [1]
//! [2]
diff --git a/examples/sql/drilldown/main.cpp b/examples/sql/drilldown/main.cpp
index 5828a37aab..77b8725281 100644
--- a/examples/sql/drilldown/main.cpp
+++ b/examples/sql/drilldown/main.cpp
@@ -11,8 +11,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(drilldown);
-
QApplication app(argc, argv);
if (!createConnection())
diff --git a/examples/sql/drilldown/view.cpp b/examples/sql/drilldown/view.cpp
index f41d32f282..c2f7301a21 100644
--- a/examples/sql/drilldown/view.cpp
+++ b/examples/sql/drilldown/view.cpp
@@ -87,8 +87,8 @@ void View::showInformation(ImageItem *image)
if (!window) {
window = new InformationWindow(id, itemTable, this);
- connect(window, QOverload<int,const QString &>::of(&InformationWindow::imageChanged),
- this, QOverload<int,const QString &>::of(&View::updateImage));
+ connect(window, &InformationWindow::imageChanged,
+ this, &View::updateImage);
window->move(pos() + QPoint(20, 40));
window->show();
diff --git a/examples/sql/drilldown/view.h b/examples/sql/drilldown/view.h
index acbfeb1558..f44dedce99 100644
--- a/examples/sql/drilldown/view.h
+++ b/examples/sql/drilldown/view.h
@@ -14,7 +14,6 @@ class InformationWindow;
class View : public QGraphicsView
{
Q_OBJECT
-
public:
View(const QString &items, const QString &images, QWidget *parent = nullptr);
@@ -23,7 +22,7 @@ protected:
//! [0]
//! [1]
-private slots:
+private Q_SLOTS:
void updateImage(int id, const QString &fileName);
//! [1]
diff --git a/examples/sql/masterdetail/CMakeLists.txt b/examples/sql/masterdetail/CMakeLists.txt
index 7a77e6ffb7..558bf70ee2 100644
--- a/examples/sql/masterdetail/CMakeLists.txt
+++ b/examples/sql/masterdetail/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(masterdetail LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/masterdetail")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets Xml)
qt_standard_project_setup()
@@ -48,7 +42,14 @@ qt_add_resources(masterdetail "masterdetail"
)
install(TARGETS masterdetail
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET masterdetail
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/masterdetail/dialog.cpp b/examples/sql/masterdetail/dialog.cpp
index 19e941af30..0b8ed8a75b 100644
--- a/examples/sql/masterdetail/dialog.cpp
+++ b/examples/sql/masterdetail/dialog.cpp
@@ -3,10 +3,23 @@
#include "dialog.h"
-int uniqueAlbumId;
-int uniqueArtistId;
-
-Dialog::Dialog(QSqlRelationalTableModel *albums, QDomDocument details,
+#include <QDialogButtonBox>
+#include <QDate>
+#include <QDomDocument>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QSqlField>
+#include <QSqlRelationalTableModel>
+#include <QSqlRecord>
+#include <QVBoxLayout>
+
+int Dialog::s_artistId = 0;
+int Dialog::s_albumId = 0;
+Dialog::Dialog(QSqlRelationalTableModel *albums, const QDomDocument &details,
QFile *output, QWidget *parent)
: QDialog(parent)
{
@@ -25,6 +38,12 @@ Dialog::Dialog(QSqlRelationalTableModel *albums, QDomDocument details,
setWindowTitle(tr("Add Album"));
}
+void Dialog::setInitialAlbumAndArtistId(int albumId, int artistId)
+{
+ s_albumId = albumId;
+ s_artistId = artistId;
+}
+
void Dialog::submit()
{
QString artist = artistEditor->text();
@@ -145,7 +164,7 @@ void Dialog::addTracks(int albumId, const QStringList &tracks)
*/
}
-void Dialog::increaseAlbumCount(QModelIndex artistIndex)
+void Dialog::increaseAlbumCount(const QModelIndex &artistIndex)
{
QSqlTableModel *artistModel = model->relationModel(2);
@@ -219,7 +238,7 @@ QDialogButtonBox *Dialog::createButtons()
return buttonBox;
}
-QModelIndex Dialog::indexOfArtist(const QString &artist)
+QModelIndex Dialog::indexOfArtist(const QString &artist) const
{
QSqlTableModel *artistModel = model->relationModel(2);
@@ -234,12 +253,12 @@ QModelIndex Dialog::indexOfArtist(const QString &artist)
int Dialog::generateArtistId()
{
- uniqueArtistId += 1;
- return uniqueArtistId;
+ s_artistId += 1;
+ return s_artistId;
}
int Dialog::generateAlbumId()
{
- uniqueAlbumId += 1;
- return uniqueAlbumId;
+ s_albumId += 1;
+ return s_albumId;
}
diff --git a/examples/sql/masterdetail/dialog.h b/examples/sql/masterdetail/dialog.h
index 0c5a728ebb..2a4f5a0b8e 100644
--- a/examples/sql/masterdetail/dialog.h
+++ b/examples/sql/masterdetail/dialog.h
@@ -4,17 +4,25 @@
#ifndef DIALOG_H
#define DIALOG_H
-#include <QtWidgets>
-#include <QtSql>
-#include <QtXml>
+#include <QDialog>
+#include <QDomDocument>
+
+QT_FORWARD_DECLARE_CLASS(QDialogButtonBox)
+QT_FORWARD_DECLARE_CLASS(QFile)
+QT_FORWARD_DECLARE_CLASS(QGroupBox)
+QT_FORWARD_DECLARE_CLASS(QLineEdit)
+QT_FORWARD_DECLARE_CLASS(QModelIndex)
+QT_FORWARD_DECLARE_CLASS(QSpinBox)
+QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel)
class Dialog : public QDialog
{
Q_OBJECT
public:
- Dialog(QSqlRelationalTableModel *albums, QDomDocument details,
+ Dialog(QSqlRelationalTableModel *albums, const QDomDocument &details,
QFile *output, QWidget *parent = nullptr);
+ static void setInitialAlbumAndArtistId(int albumId, int artistId);
private slots:
void revert();
@@ -27,10 +35,8 @@ private:
QDialogButtonBox *createButtons();
QGroupBox *createInputWidgets();
int findArtistId(const QString &artist);
- static int generateAlbumId();
- static int generateArtistId();
- void increaseAlbumCount(QModelIndex artistIndex);
- QModelIndex indexOfArtist(const QString &artist);
+ void increaseAlbumCount(const QModelIndex &artistIndex);
+ QModelIndex indexOfArtist(const QString &artist) const;
QSqlRelationalTableModel *model;
QDomDocument albumDetails;
@@ -40,6 +46,11 @@ private:
QLineEdit *titleEditor;
QSpinBox *yearEditor;
QLineEdit *tracksEditor;
+
+ static int generateAlbumId();
+ static int generateArtistId();
+ static int s_artistId;
+ static int s_albumId;
};
#endif
diff --git a/examples/sql/masterdetail/main.cpp b/examples/sql/masterdetail/main.cpp
index 8b6ee61828..50d99cf24e 100644
--- a/examples/sql/masterdetail/main.cpp
+++ b/examples/sql/masterdetail/main.cpp
@@ -7,12 +7,8 @@
#include <QApplication>
#include <QFile>
-#include <stdlib.h>
-
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(masterdetail);
-
QApplication app(argc, argv);
if (!createConnection())
diff --git a/examples/sql/masterdetail/mainwindow.cpp b/examples/sql/masterdetail/mainwindow.cpp
index d720db1033..020a149b22 100644
--- a/examples/sql/masterdetail/mainwindow.cpp
+++ b/examples/sql/masterdetail/mainwindow.cpp
@@ -4,12 +4,20 @@
#include "mainwindow.h"
#include "dialog.h"
-#include <QtWidgets>
-#include <QtSql>
-#include <QtXml>
-
-extern int uniqueAlbumId;
-extern int uniqueArtistId;
+#include <QApplication>
+#include <QComboBox>
+#include <QHeaderView>
+#include <QFile>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QLabel>
+#include <QListWidget>
+#include <QMenu>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QSqlRecord>
+#include <QSqlRelationalTableModel>
+#include <QTableView>
MainWindow::MainWindow(const QString &artistTable, const QString &albumTable,
QFile *albumDetails, QWidget *parent)
@@ -28,13 +36,12 @@ MainWindow::MainWindow(const QString &artistTable, const QString &albumTable,
QGroupBox *details = createDetailsGroupBox();
artistView->setCurrentIndex(0);
- uniqueAlbumId = model->rowCount();
- uniqueArtistId = artistView->count();
+ Dialog::setInitialAlbumAndArtistId(model->rowCount(), artistView->count());
connect(model, &QSqlRelationalTableModel::rowsInserted,
- this, &MainWindow::updateHeader);
+ this, &MainWindow::adjustHeader);
connect(model, &QSqlRelationalTableModel::rowsRemoved,
- this, &MainWindow::updateHeader);
+ this, &MainWindow::adjustHeader);
QGridLayout *layout = new QGridLayout;
layout->addWidget(artists, 0, 0);
@@ -67,7 +74,7 @@ void MainWindow::changeArtist(int row)
}
}
-void MainWindow::showArtistProfile(QModelIndex index)
+void MainWindow::showArtistProfile(const QModelIndex &index)
{
QSqlRecord record = model->relationModel(2)->record(index.row());
@@ -84,7 +91,7 @@ void MainWindow::showArtistProfile(QModelIndex index)
imageLabel->hide();
}
-void MainWindow::showAlbumDetails(QModelIndex index)
+void MainWindow::showAlbumDetails(const QModelIndex &index)
{
QSqlRecord record = model->record(index.row());
@@ -113,14 +120,11 @@ void MainWindow::getTrackList(QDomNode album)
{
trackList->clear();
- QDomNodeList tracks = album.childNodes();
- QDomNode track;
- QString trackNumber;
-
+ const QDomNodeList tracks = album.childNodes();
for (int i = 0; i < tracks.count(); ++i) {
- track = tracks.item(i);
- trackNumber = track.toElement().attribute("number");
+ const QDomNode track = tracks.item(i);
+ const QString trackNumber = track.toElement().attribute("number");
QListWidgetItem *item = new QListWidgetItem(trackList);
item->setText(trackNumber + ": " + track.toElement().text());
@@ -132,7 +136,7 @@ void MainWindow::addAlbum()
Dialog *dialog = new Dialog(model, albumData, file, this);
int accepted = dialog->exec();
- if (accepted == 1) {
+ if (accepted == QDialog::Accepted) {
int lastRow = model->rowCount() - 1;
albumView->selectRow(lastRow);
albumView->scrollToBottom();
@@ -142,10 +146,10 @@ void MainWindow::addAlbum()
void MainWindow::deleteAlbum()
{
- QModelIndexList selection = albumView->selectionModel()->selectedRows(0);
+ const QModelIndexList selection = albumView->selectionModel()->selectedRows(0);
if (!selection.empty()) {
- QModelIndex idIndex = selection.at(0);
+ const QModelIndex &idIndex = selection.at(0);
int id = idIndex.data().toInt();
QString title = idIndex.sibling(idIndex.row(), 1).data().toString();
QString artist = idIndex.sibling(idIndex.row(), 2).data().toString();
@@ -172,9 +176,7 @@ void MainWindow::deleteAlbum()
void MainWindow::removeAlbumFromFile(int id)
{
-
QDomNodeList albums = albumData.elementsByTagName("album");
-
for (int i = 0; i < albums.count(); ++i) {
QDomNode node = albums.item(i);
if (node.toElement().attribute("id").toInt() == id) {
@@ -197,12 +199,12 @@ void MainWindow::removeAlbumFromFile(int id)
*/
}
-void MainWindow::removeAlbumFromDatabase(QModelIndex index)
+void MainWindow::removeAlbumFromDatabase(const QModelIndex &index)
{
model->removeRow(index.row());
}
-void MainWindow::decreaseAlbumCount(QModelIndex artistIndex)
+void MainWindow::decreaseAlbumCount(const QModelIndex &artistIndex)
{
int row = artistIndex.row();
QModelIndex albumCountIndex = artistIndex.sibling(row, 2);
@@ -358,7 +360,7 @@ void MainWindow::showImageLabel()
imageLabel->show();
}
-QModelIndex MainWindow::indexOfArtist(const QString &artist)
+QModelIndex MainWindow::indexOfArtist(const QString &artist) const
{
QSqlTableModel *artistModel = model->relationModel(2);
@@ -370,11 +372,6 @@ QModelIndex MainWindow::indexOfArtist(const QString &artist)
return QModelIndex();
}
-void MainWindow::updateHeader(QModelIndex, int, int)
-{
- adjustHeader();
-}
-
void MainWindow::adjustHeader()
{
albumView->hideColumn(0);
diff --git a/examples/sql/masterdetail/mainwindow.h b/examples/sql/masterdetail/mainwindow.h
index a5f9e70648..cc2a5c9f59 100644
--- a/examples/sql/masterdetail/mainwindow.h
+++ b/examples/sql/masterdetail/mainwindow.h
@@ -8,15 +8,13 @@
#include <QMainWindow>
#include <QModelIndex>
-QT_BEGIN_NAMESPACE
-class QComboBox;
-class QFile;
-class QGroupBox;
-class QLabel;
-class QListWidget;
-class QSqlRelationalTableModel;
-class QTableView;
-QT_END_NAMESPACE
+QT_FORWARD_DECLARE_CLASS(QComboBox)
+QT_FORWARD_DECLARE_CLASS(QFile)
+QT_FORWARD_DECLARE_CLASS(QGroupBox)
+QT_FORWARD_DECLARE_CLASS(QLabel)
+QT_FORWARD_DECLARE_CLASS(QListWidget)
+QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel)
+QT_FORWARD_DECLARE_CLASS(QTableView)
class MainWindow : public QMainWindow
{
@@ -31,21 +29,20 @@ private slots:
void addAlbum();
void changeArtist(int row);
void deleteAlbum();
- void showAlbumDetails(QModelIndex index);
- void showArtistProfile(QModelIndex index);
- void updateHeader(QModelIndex, int, int);
+ void showAlbumDetails(const QModelIndex &index);
+ void showArtistProfile(const QModelIndex &index);
+ void adjustHeader();
private:
- void adjustHeader();
QGroupBox *createAlbumGroupBox();
QGroupBox *createArtistGroupBox();
QGroupBox *createDetailsGroupBox();
void createMenuBar();
- void decreaseAlbumCount(QModelIndex artistIndex);
+ void decreaseAlbumCount(const QModelIndex &artistIndex);
void getTrackList(QDomNode album);
- QModelIndex indexOfArtist(const QString &artist);
+ QModelIndex indexOfArtist(const QString &artist) const;
void readAlbumData();
- void removeAlbumFromDatabase(QModelIndex album);
+ void removeAlbumFromDatabase(const QModelIndex &album);
void removeAlbumFromFile(int id);
void showImageLabel();
diff --git a/examples/sql/querymodel/CMakeLists.txt b/examples/sql/querymodel/CMakeLists.txt
index d6720c0f67..b7d863ab05 100644
--- a/examples/sql/querymodel/CMakeLists.txt
+++ b/examples/sql/querymodel/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(querymodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/querymodel")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
@@ -34,7 +28,14 @@ target_link_libraries(querymodel PRIVATE
)
install(TARGETS querymodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET querymodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/querymodel/customsqlmodel.cpp b/examples/sql/querymodel/customsqlmodel.cpp
index 9063911218..e87be12f09 100644
--- a/examples/sql/querymodel/customsqlmodel.cpp
+++ b/examples/sql/querymodel/customsqlmodel.cpp
@@ -1,10 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-
#include "customsqlmodel.h"
+#include <QColor>
+
CustomSqlModel::CustomSqlModel(QObject *parent)
: QSqlQueryModel(parent)
{
diff --git a/examples/sql/querymodel/editablesqlmodel.cpp b/examples/sql/querymodel/editablesqlmodel.cpp
index b7cb930020..dc91666c06 100644
--- a/examples/sql/querymodel/editablesqlmodel.cpp
+++ b/examples/sql/querymodel/editablesqlmodel.cpp
@@ -1,18 +1,17 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtSql>
-
#include "editablesqlmodel.h"
+#include <QSqlQuery>
+
EditableSqlModel::EditableSqlModel(QObject *parent)
: QSqlQueryModel(parent)
{
}
//! [0]
-Qt::ItemFlags EditableSqlModel::flags(
- const QModelIndex &index) const
+Qt::ItemFlags EditableSqlModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QSqlQueryModel::flags(index);
if (index.column() == 1 || index.column() == 2)
@@ -33,11 +32,10 @@ bool EditableSqlModel::setData(const QModelIndex &index, const QVariant &value,
clear();
bool ok;
- if (index.column() == 1) {
+ if (index.column() == 1)
ok = setFirstName(id, value.toString());
- } else {
+ else
ok = setLastName(id, value.toString());
- }
refresh();
return ok;
}
diff --git a/examples/sql/querymodel/main.cpp b/examples/sql/querymodel/main.cpp
index 8c5af768e3..a4680f7fe8 100644
--- a/examples/sql/querymodel/main.cpp
+++ b/examples/sql/querymodel/main.cpp
@@ -8,8 +8,6 @@
#include <QApplication>
#include <QTableView>
-#include <stdlib.h>
-
void initializeModel(QSqlQueryModel *model)
{
model->setQuery("select * from person");
diff --git a/examples/sql/relationaltablemodel/CMakeLists.txt b/examples/sql/relationaltablemodel/CMakeLists.txt
index cd19b75e07..fcca1f182b 100644
--- a/examples/sql/relationaltablemodel/CMakeLists.txt
+++ b/examples/sql/relationaltablemodel/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(relationaltablemodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/relationaltablemodel")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(relationaltablemodel PRIVATE
)
install(TARGETS relationaltablemodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET relationaltablemodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/sqlbrowser/CMakeLists.txt b/examples/sql/sqlbrowser/CMakeLists.txt
index 210a53125b..a124ae203c 100644
--- a/examples/sql/sqlbrowser/CMakeLists.txt
+++ b/examples/sql/sqlbrowser/CMakeLists.txt
@@ -1,17 +1,11 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(sqlbrowser LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/sqlbrowser")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
@@ -37,7 +31,14 @@ target_link_libraries(sqlbrowser PRIVATE
)
install(TARGETS sqlbrowser
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET sqlbrowser
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/sqlbrowser/browser.cpp b/examples/sql/sqlbrowser/browser.cpp
index 98270fd5b5..9a99999702 100644
--- a/examples/sql/sqlbrowser/browser.cpp
+++ b/examples/sql/sqlbrowser/browser.cpp
@@ -3,23 +3,49 @@
#include "browser.h"
#include "qsqlconnectiondialog.h"
-
-#include <QtWidgets>
-#include <QtSql>
+#include <ui_browserwidget.h>
+
+#include <QAction>
+#include <QMessageBox>
+#include <QStandardItemModel>
+#include <QSqlDriver>
+#include <QSqlError>
+#include <QSqlField>
+#include <QSqlQuery>
+#include <QSqlRecord>
+#include <QTextEdit>
+#include <QTimer>
Browser::Browser(QWidget *parent)
: QWidget(parent)
+ , m_ui(new Ui::Browser)
{
- setupUi(this);
-
- table->addAction(insertRowAction);
- table->addAction(deleteRowAction);
- table->addAction(fieldStrategyAction);
- table->addAction(rowStrategyAction);
- table->addAction(manualStrategyAction);
- table->addAction(submitAction);
- table->addAction(revertAction);
- table->addAction(selectAction);
+ m_ui->setupUi(this);
+
+ m_ui->table->addAction(m_ui->insertRowAction);
+ m_ui->table->addAction(m_ui->deleteRowAction);
+ m_ui->table->addAction(m_ui->fieldStrategyAction);
+ m_ui->table->addAction(m_ui->rowStrategyAction);
+ m_ui->table->addAction(m_ui->manualStrategyAction);
+ m_ui->table->addAction(m_ui->submitAction);
+ m_ui->table->addAction(m_ui->revertAction);
+ m_ui->table->addAction(m_ui->selectAction);
+
+ connect(m_ui->insertRowAction, &QAction::triggered, this, &Browser::insertRow);
+ connect(m_ui->deleteRowAction, &QAction::triggered, this, &Browser::deleteRow);
+ connect(m_ui->fieldStrategyAction, &QAction::triggered, this, &Browser::onFieldStrategyAction);
+ connect(m_ui->rowStrategyAction, &QAction::triggered, this, &Browser::onRowStrategyAction);
+ connect(m_ui->sqlEdit, &QTextEdit::textChanged, this, &Browser::updateActions);
+
+ connect(m_ui->connectionWidget, &ConnectionWidget::tableActivated,
+ this, &Browser::showTable);
+ connect(m_ui->connectionWidget, &ConnectionWidget::metaDataRequested,
+ this, &Browser::showMetaData);
+
+ connect(m_ui->submitButton, &QPushButton::clicked,
+ this, &Browser::onSubmitButton);
+ connect(m_ui->clearButton, &QPushButton::clicked,
+ this, &Browser::onClearButton);
if (QSqlDatabase::drivers().isEmpty())
QMessageBox::information(this, tr("No database drivers found"),
@@ -27,18 +53,22 @@ Browser::Browser(QWidget *parent)
"Please check the documentation how to build the "
"Qt SQL plugins."));
- emit statusMessage(tr("Ready."));
+ QTimer::singleShot(0, this, [this]() {
+ updateActions();
+ emit statusMessage(tr("Ready."));
+ });
}
Browser::~Browser()
{
+ delete m_ui;
}
void Browser::exec()
{
- QSqlQueryModel *model = new QSqlQueryModel(table);
- model->setQuery(QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase()));
- table->setModel(model);
+ QSqlQueryModel *model = new QSqlQueryModel(m_ui->table);
+ model->setQuery(QSqlQuery(m_ui->sqlEdit->toPlainText(), m_ui->connectionWidget->currentDatabase()));
+ m_ui->table->setModel(model);
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
@@ -52,7 +82,7 @@ void Browser::exec()
}
QSqlError Browser::addConnection(const QString &driver, const QString &dbName, const QString &host,
- const QString &user, const QString &passwd, int port)
+ const QString &user, const QString &passwd, int port)
{
static int cCount = 0;
@@ -66,12 +96,12 @@ QSqlError Browser::addConnection(const QString &driver, const QString &dbName, c
db = QSqlDatabase();
QSqlDatabase::removeDatabase(QString("Browser%1").arg(cCount));
}
- connectionWidget->refresh();
+ m_ui->connectionWidget->refresh();
return err;
}
-void Browser::addConnection()
+void Browser::openNewConnectionDialog()
{
QSqlConnectionDialog dialog(this);
if (dialog.exec() != QDialog::Accepted)
@@ -82,10 +112,14 @@ void Browser::addConnection()
QSqlDatabase::removeDatabase("in_mem_db");
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "in_mem_db");
db.setDatabaseName(":memory:");
- if (!db.open())
- QMessageBox::warning(this, tr("Unable to open database"), tr("An error occurred while "
- "opening the connection: ") + db.lastError().text());
- QSqlQuery q("", db);
+ if (!db.open()) {
+ QMessageBox::warning(this, tr("Unable to open database"),
+ tr("An error occurred while "
+ "opening the connection: %1") .arg(db.lastError().text()));
+ return;
+ }
+ db.transaction();
+ QSqlQuery q(db);
q.exec("drop table Movies");
q.exec("drop table Names");
q.exec("create table Movies (id integer primary key, Title varchar, Director varchar, Rating number)");
@@ -100,37 +134,43 @@ void Browser::addConnection()
q.exec("insert into Names values (2, 'Donald', 'Duck', 'Andeby')");
q.exec("insert into Names values (3, 'Buck', 'Rogers', 'Paris')");
q.exec("insert into Names values (4, 'Sherlock', 'Holmes', 'London')");
- connectionWidget->refresh();
+ db.commit();
+ m_ui->connectionWidget->refresh();
} else {
QSqlError err = addConnection(dialog.driverName(), dialog.databaseName(), dialog.hostName(),
- dialog.userName(), dialog.password(), dialog.port());
+ dialog.userName(), dialog.password(), dialog.port());
if (err.type() != QSqlError::NoError)
- QMessageBox::warning(this, tr("Unable to open database"), tr("An error occurred while "
- "opening the connection: ") + err.text());
+ QMessageBox::warning(this, tr("Unable to open database"),
+ tr("An error occurred while "
+ "opening the connection: %1").arg(err.text()));
}
}
void Browser::showTable(const QString &t)
{
- QSqlTableModel *model = new CustomModel(table, connectionWidget->currentDatabase());
+ QSqlTableModel *model = new CustomModel(m_ui->table, m_ui->connectionWidget->currentDatabase());
model->setEditStrategy(QSqlTableModel::OnRowChange);
- model->setTable(connectionWidget->currentDatabase().driver()->escapeIdentifier(t, QSqlDriver::TableName));
+ model->setTable(m_ui->connectionWidget->currentDatabase().driver()->escapeIdentifier(t, QSqlDriver::TableName));
model->select();
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
- table->setModel(model);
- table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
- connect(table->selectionModel(), &QItemSelectionModel::currentRowChanged,
- this, &Browser::currentChanged);
+ m_ui->table->setModel(model);
+ m_ui->table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
+ connect(m_ui->table->selectionModel(), &QItemSelectionModel::currentRowChanged,
+ this, &Browser::updateActions);
+
+ connect(m_ui->submitAction, &QAction::triggered, model, &QSqlTableModel::submitAll);
+ connect(m_ui->revertAction, &QAction::triggered, model, &QSqlTableModel::revertAll);
+ connect(m_ui->selectAction, &QAction::triggered, model, &QSqlTableModel::select);
updateActions();
}
void Browser::showMetaData(const QString &t)
{
- QSqlRecord rec = connectionWidget->currentDatabase().record(t);
- QStandardItemModel *model = new QStandardItemModel(table);
+ QSqlRecord rec = m_ui->connectionWidget->currentDatabase().record(t);
+ QStandardItemModel *model = new QStandardItemModel(m_ui->table);
model->insertRows(0, rec.count());
model->insertColumns(0, 7);
@@ -146,9 +186,7 @@ void Browser::showMetaData(const QString &t)
for (int i = 0; i < rec.count(); ++i) {
QSqlField fld = rec.field(i);
model->setData(model->index(i, 0), fld.name());
- model->setData(model->index(i, 1), fld.typeID() == -1
- ? QString(fld.metaType().name())
- : QString("%1 (%2)").arg(fld.metaType().name()).arg(fld.typeID()));
+ model->setData(model->index(i, 1), QString::fromUtf8(fld.metaType().name()));
model->setData(model->index(i, 2), fld.length());
model->setData(model->index(i, 3), fld.precision());
model->setData(model->index(i, 4), fld.requiredStatus() == -1 ? QVariant("?")
@@ -157,37 +195,37 @@ void Browser::showMetaData(const QString &t)
model->setData(model->index(i, 6), fld.defaultValue());
}
- table->setModel(model);
- table->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ m_ui->table->setModel(model);
+ m_ui->table->setEditTriggers(QAbstractItemView::NoEditTriggers);
updateActions();
}
void Browser::insertRow()
{
- QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *model = qobject_cast<QSqlTableModel *>(m_ui->table->model());
if (!model)
return;
- QModelIndex insertIndex = table->currentIndex();
+ QModelIndex insertIndex = m_ui->table->currentIndex();
int row = insertIndex.row() == -1 ? 0 : insertIndex.row();
model->insertRow(row);
insertIndex = model->index(row, 0);
- table->setCurrentIndex(insertIndex);
- table->edit(insertIndex);
+ m_ui->table->setCurrentIndex(insertIndex);
+ m_ui->table->edit(insertIndex);
}
void Browser::deleteRow()
{
- QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *model = qobject_cast<QSqlTableModel *>(m_ui->table->model());
if (!model)
return;
- QModelIndexList currentSelection = table->selectionModel()->selectedIndexes();
- for (int i = 0; i < currentSelection.count(); ++i) {
- if (currentSelection.at(i).column() != 0)
+ const QModelIndexList currentSelection = m_ui->table->selectionModel()->selectedIndexes();
+ for (const auto &idx : currentSelection) {
+ if (idx.column() != 0)
continue;
- model->removeRow(currentSelection.at(i).row());
+ model->removeRow(idx.row());
}
updateActions();
@@ -195,74 +233,70 @@ void Browser::deleteRow()
void Browser::updateActions()
{
- QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
- bool enableIns = tm;
- bool enableDel = enableIns && table->currentIndex().isValid();
+ QSqlTableModel *tm = qobject_cast<QSqlTableModel *>(m_ui->table->model());
+ bool enableIns = tm != nullptr;
+ bool enableDel = enableIns && m_ui->table->currentIndex().isValid();
- insertRowAction->setEnabled(enableIns);
- deleteRowAction->setEnabled(enableDel);
+ m_ui->insertRowAction->setEnabled(enableIns);
+ m_ui->deleteRowAction->setEnabled(enableDel);
- fieldStrategyAction->setEnabled(tm);
- rowStrategyAction->setEnabled(tm);
- manualStrategyAction->setEnabled(tm);
- submitAction->setEnabled(tm);
- revertAction->setEnabled(tm);
- selectAction->setEnabled(tm);
+ m_ui->submitAction->setEnabled(tm);
+ m_ui->revertAction->setEnabled(tm);
+ m_ui->selectAction->setEnabled(tm);
+
+ const bool isEmpty = m_ui->sqlEdit->toPlainText().isEmpty();
+ m_ui->submitButton->setEnabled(m_ui->connectionWidget->currentDatabase().isOpen() && !isEmpty);
+ m_ui->clearButton->setEnabled(!isEmpty);
if (tm) {
QSqlTableModel::EditStrategy es = tm->editStrategy();
- fieldStrategyAction->setChecked(es == QSqlTableModel::OnFieldChange);
- rowStrategyAction->setChecked(es == QSqlTableModel::OnRowChange);
- manualStrategyAction->setChecked(es == QSqlTableModel::OnManualSubmit);
+ m_ui->fieldStrategyAction->setChecked(es == QSqlTableModel::OnFieldChange);
+ m_ui->rowStrategyAction->setChecked(es == QSqlTableModel::OnRowChange);
+ m_ui->manualStrategyAction->setChecked(es == QSqlTableModel::OnManualSubmit);
+ } else {
+ m_ui->fieldStrategyAction->setEnabled(false);
+ m_ui->rowStrategyAction->setEnabled(false);
+ m_ui->manualStrategyAction->setEnabled(false);
}
}
void Browser::about()
{
- QMessageBox::about(this, tr("About"), tr("The SQL Browser demonstration "
- "shows how a data browser can be used to visualize the results of SQL"
- "statements on a live database"));
+ QMessageBox::about(this, tr("About"),
+ tr("The SQL Browser demonstration shows how a data browser "
+ "can be used to visualize the results of SQL "
+ "statements on a live database"));
}
-void Browser::on_fieldStrategyAction_triggered()
+void Browser::onFieldStrategyAction()
{
- QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *tm = qobject_cast<QSqlTableModel *>(m_ui->table->model());
if (tm)
tm->setEditStrategy(QSqlTableModel::OnFieldChange);
}
-void Browser::on_rowStrategyAction_triggered()
+void Browser::onRowStrategyAction()
{
- QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *tm = qobject_cast<QSqlTableModel *>(m_ui->table->model());
if (tm)
tm->setEditStrategy(QSqlTableModel::OnRowChange);
}
-void Browser::on_manualStrategyAction_triggered()
+void Browser::onManualStrategyAction()
{
- QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *tm = qobject_cast<QSqlTableModel *>(m_ui->table->model());
if (tm)
tm->setEditStrategy(QSqlTableModel::OnManualSubmit);
}
-void Browser::on_submitAction_triggered()
-{
- QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
- if (tm)
- tm->submitAll();
-}
-
-void Browser::on_revertAction_triggered()
+void Browser::onSubmitButton()
{
- QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
- if (tm)
- tm->revertAll();
+ exec();
+ m_ui->sqlEdit->setFocus();
}
-void Browser::on_selectAction_triggered()
+void Browser::onClearButton()
{
- QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
- if (tm)
- tm->select();
+ m_ui->sqlEdit->clear();
+ m_ui->sqlEdit->setFocus();
}
-
diff --git a/examples/sql/sqlbrowser/browser.h b/examples/sql/sqlbrowser/browser.h
index cf959703b3..c61048c84a 100644
--- a/examples/sql/sqlbrowser/browser.h
+++ b/examples/sql/sqlbrowser/browser.h
@@ -6,72 +6,58 @@
#include <QWidget>
#include <QSqlTableModel>
-#include "ui_browserwidget.h"
-class ConnectionWidget;
-QT_FORWARD_DECLARE_CLASS(QTableView)
-QT_FORWARD_DECLARE_CLASS(QPushButton)
-QT_FORWARD_DECLARE_CLASS(QTextEdit)
QT_FORWARD_DECLARE_CLASS(QSqlError)
-class Browser: public QWidget, private Ui::Browser
+QT_BEGIN_NAMESPACE
+namespace Ui
+{
+class Browser;
+}
+QT_END_NAMESPACE
+
+class Browser : public QWidget
{
Q_OBJECT
public:
Browser(QWidget *parent = nullptr);
- virtual ~Browser();
+ ~Browser();
QSqlError addConnection(const QString &driver, const QString &dbName, const QString &host,
- const QString &user, const QString &passwd, int port = -1);
+ const QString &user, const QString &passwd, int port);
+public slots:
+ void openNewConnectionDialog();
+ void about();
+
+protected:
void insertRow();
void deleteRow();
void updateActions();
-public slots:
+protected slots:
void exec();
void showTable(const QString &table);
void showMetaData(const QString &table);
- void addConnection();
- void currentChanged() { updateActions(); }
- void about();
- void on_insertRowAction_triggered()
- { insertRow(); }
- void on_deleteRowAction_triggered()
- { deleteRow(); }
- void on_fieldStrategyAction_triggered();
- void on_rowStrategyAction_triggered();
- void on_manualStrategyAction_triggered();
- void on_submitAction_triggered();
- void on_revertAction_triggered();
- void on_selectAction_triggered();
- void on_connectionWidget_tableActivated(const QString &table)
- { showTable(table); }
- void on_connectionWidget_metaDataRequested(const QString &table)
- { showMetaData(table); }
- void on_submitButton_clicked()
- {
- exec();
- sqlEdit->setFocus();
- }
- void on_clearButton_clicked()
- {
- sqlEdit->clear();
- sqlEdit->setFocus();
- }
+ void onFieldStrategyAction();
+ void onRowStrategyAction();
+ void onManualStrategyAction();
+ void onSubmitButton();
+ void onClearButton();
signals:
void statusMessage(const QString &message);
+
+private:
+ Ui::Browser *m_ui;
};
-class CustomModel: public QSqlTableModel
+class CustomModel : public QSqlTableModel
{
Q_OBJECT
public:
- explicit CustomModel(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase())
- : QSqlTableModel(parent, db) {}
-
+ using QSqlTableModel::QSqlTableModel;
QVariant data(const QModelIndex &idx, int role) const override
{
if (role == Qt::BackgroundRole && isDirty(idx))
diff --git a/examples/sql/sqlbrowser/connectionwidget.cpp b/examples/sql/sqlbrowser/connectionwidget.cpp
index 99ad537994..da6796d7e5 100644
--- a/examples/sql/sqlbrowser/connectionwidget.cpp
+++ b/examples/sql/sqlbrowser/connectionwidget.cpp
@@ -3,17 +3,19 @@
#include "connectionwidget.h"
-#include <QtWidgets>
-#include <QtSql>
+#include <QAction>
+#include <QHeaderView>
+#include <QSqlDatabase>
+#include <QTreeWidget>
+#include <QVBoxLayout>
ConnectionWidget::ConnectionWidget(QWidget *parent)
: QWidget(parent)
+ , tree(new QTreeWidget(this))
{
QVBoxLayout *layout = new QVBoxLayout(this);
- tree = new QTreeWidget(this);
- tree->setObjectName(QLatin1String("tree"));
- tree->setHeaderLabels(QStringList(tr("database")));
- tree->header()->setSectionResizeMode(QHeaderView::Stretch);
+ tree->setHeaderLabels(QStringList(tr("Database")));
+ tree->header()->setStretchLastSection(true);
QAction *refreshAction = new QAction(tr("Refresh"), tree);
metaDataAction = new QAction(tr("Show Schema"), tree);
connect(refreshAction, &QAction::triggered, this, &ConnectionWidget::refresh);
@@ -24,34 +26,37 @@ ConnectionWidget::ConnectionWidget(QWidget *parent)
layout->addWidget(tree);
- QMetaObject::connectSlotsByName(this);
+ connect(tree, &QTreeWidget::itemActivated,
+ this, &ConnectionWidget::onItemActivated);
+ connect(tree, &QTreeWidget::currentItemChanged,
+ this, &ConnectionWidget::onCurrentItemChanged);
}
ConnectionWidget::~ConnectionWidget()
{
}
-static QString qDBCaption(const QSqlDatabase &db)
-{
- QString nm = db.driverName();
- nm.append(QLatin1Char(':'));
- if (!db.userName().isEmpty())
- nm.append(db.userName()).append(QLatin1Char('@'));
- nm.append(db.databaseName());
- return nm;
-}
void ConnectionWidget::refresh()
{
+ const auto qDBCaption = [](const QSqlDatabase &db)
+ {
+ QString nm = db.driverName() + QLatin1Char(':');
+ if (!db.userName().isEmpty())
+ nm += db.userName() + QLatin1Char('@');
+ nm += db.databaseName();
+ return nm;
+ };
+
tree->clear();
- QStringList connectionNames = QSqlDatabase::connectionNames();
+ const QStringList connectionNames = QSqlDatabase::connectionNames();
bool gotActiveDb = false;
- for (int i = 0; i < connectionNames.count(); ++i) {
+ for (const auto &connectionName : connectionNames) {
QTreeWidgetItem *root = new QTreeWidgetItem(tree);
- QSqlDatabase db = QSqlDatabase::database(connectionNames.at(i), false);
+ QSqlDatabase db = QSqlDatabase::database(connectionName, false);
root->setText(0, qDBCaption(db));
- if (connectionNames.at(i) == activeDb) {
+ if (connectionName == activeDb) {
gotActiveDb = true;
setActive(root);
}
@@ -76,15 +81,15 @@ QSqlDatabase ConnectionWidget::currentDatabase() const
return QSqlDatabase::database(activeDb);
}
-static void qSetBold(QTreeWidgetItem *item, bool bold)
-{
- QFont font = item->font(0);
- font.setBold(bold);
- item->setFont(0, font);
-}
-
void ConnectionWidget::setActive(QTreeWidgetItem *item)
{
+ const auto qSetBold = [](QTreeWidgetItem *item, bool bold)
+ {
+ QFont font = item->font(0);
+ font.setBold(bold);
+ item->setFont(0, font);
+ };
+
for (int i = 0; i < tree->topLevelItemCount(); ++i) {
if (tree->topLevelItem(i)->font(0).bold())
qSetBold(tree->topLevelItem(i), false);
@@ -97,7 +102,7 @@ void ConnectionWidget::setActive(QTreeWidgetItem *item)
activeDb = QSqlDatabase::connectionNames().value(tree->indexOfTopLevelItem(item));
}
-void ConnectionWidget::on_tree_itemActivated(QTreeWidgetItem *item, int /* column */)
+void ConnectionWidget::onItemActivated(QTreeWidgetItem *item)
{
if (!item)
return;
@@ -119,7 +124,7 @@ void ConnectionWidget::showMetaData()
emit metaDataRequested(cItem->text(0));
}
-void ConnectionWidget::on_tree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *)
+void ConnectionWidget::onCurrentItemChanged(QTreeWidgetItem *current)
{
metaDataAction->setEnabled(current && current->parent());
}
diff --git a/examples/sql/sqlbrowser/connectionwidget.h b/examples/sql/sqlbrowser/connectionwidget.h
index a5b1edc7e3..a00296f3c5 100644
--- a/examples/sql/sqlbrowser/connectionwidget.h
+++ b/examples/sql/sqlbrowser/connectionwidget.h
@@ -9,14 +9,13 @@
QT_FORWARD_DECLARE_CLASS(QTreeWidget)
QT_FORWARD_DECLARE_CLASS(QTreeWidgetItem)
QT_FORWARD_DECLARE_CLASS(QSqlDatabase)
-QT_FORWARD_DECLARE_CLASS(QMenu)
-class ConnectionWidget: public QWidget
+class ConnectionWidget : public QWidget
{
Q_OBJECT
public:
ConnectionWidget(QWidget *parent = nullptr);
- virtual ~ConnectionWidget();
+ ~ConnectionWidget();
QSqlDatabase currentDatabase() const;
@@ -27,8 +26,8 @@ signals:
public slots:
void refresh();
void showMetaData();
- void on_tree_itemActivated(QTreeWidgetItem *item, int column);
- void on_tree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
+ void onItemActivated(QTreeWidgetItem *item);
+ void onCurrentItemChanged(QTreeWidgetItem *current);
private:
void setActive(QTreeWidgetItem *);
diff --git a/examples/sql/sqlbrowser/main.cpp b/examples/sql/sqlbrowser/main.cpp
index c6babea96f..b3fa8af142 100644
--- a/examples/sql/sqlbrowser/main.cpp
+++ b/examples/sql/sqlbrowser/main.cpp
@@ -3,16 +3,21 @@
#include "browser.h"
-#include <QtCore>
-#include <QtWidgets>
-#include <QtSql>
+#include <QApplication>
+#include <QMainWindow>
+#include <QMenu>
+#include <QMenuBar>
+#include <QSqlError>
+#include <QStatusBar>
+#include <QUrl>
void addConnectionsFromCommandline(const QStringList &args, Browser *browser)
{
- for (int i = 1; i < args.count(); ++i) {
- QUrl url(args.at(i), QUrl::TolerantMode);
+ for (qsizetype i = 1; i < args.count(); ++i) {
+ const auto &arg = args.at(i);
+ const QUrl url(arg, QUrl::TolerantMode);
if (!url.isValid()) {
- qWarning("Invalid URL: %s", qPrintable(args.at(i)));
+ qWarning("Invalid URL: %s", qPrintable(arg));
continue;
}
QSqlError err = browser->addConnection(url.scheme(), url.path().mid(1), url.host(),
@@ -27,29 +32,32 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QMainWindow mainWin;
- mainWin.setWindowTitle(QObject::tr("Qt SQL Browser"));
+ mainWin.setWindowTitle(QApplication::translate("MainWindow", "Qt SQL Browser"));
Browser browser(&mainWin);
mainWin.setCentralWidget(&browser);
QMenu *fileMenu = mainWin.menuBar()->addMenu(QObject::tr("&File"));
- fileMenu->addAction(QObject::tr("Add &Connection..."),
- [&]() { browser.addConnection(); });
+ fileMenu->addAction(QApplication::translate("MainWindow", "Add &Connection..."),
+ &browser, &Browser::openNewConnectionDialog);
fileMenu->addSeparator();
- fileMenu->addAction(QObject::tr("&Quit"), []() { qApp->quit(); });
+ fileMenu->addAction(QApplication::translate("MainWindow", "&Quit"),
+ qApp, &QApplication::quit);
QMenu *helpMenu = mainWin.menuBar()->addMenu(QObject::tr("&Help"));
- helpMenu->addAction(QObject::tr("About"), [&]() { browser.about(); });
- helpMenu->addAction(QObject::tr("About Qt"), []() { qApp->aboutQt(); });
+ helpMenu->addAction(QApplication::translate("MainWindow", "About"),
+ &browser, &Browser::about);
+ helpMenu->addAction(QApplication::translate("MainWindow", "About Qt"),
+ qApp, &QApplication::aboutQt);
- QObject::connect(&browser, &Browser::statusMessage, [&mainWin](const QString &text) {
- mainWin.statusBar()->showMessage(text);
- });
+ QObject::connect(&browser, &Browser::statusMessage,
+ &mainWin, [&mainWin](const QString &text) { mainWin.statusBar()->showMessage(text); });
addConnectionsFromCommandline(app.arguments(), &browser);
mainWin.show();
if (QSqlDatabase::connectionNames().isEmpty())
- QMetaObject::invokeMethod(&browser, "addConnection", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(&browser, &Browser::openNewConnectionDialog,
+ Qt::QueuedConnection);
return app.exec();
}
diff --git a/examples/sql/sqlbrowser/qsqlconnectiondialog.cpp b/examples/sql/sqlbrowser/qsqlconnectiondialog.cpp
index e3ab2b9c10..2b85e95805 100644
--- a/examples/sql/sqlbrowser/qsqlconnectiondialog.cpp
+++ b/examples/sql/sqlbrowser/qsqlconnectiondialog.cpp
@@ -2,69 +2,86 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "qsqlconnectiondialog.h"
-#include "ui_qsqlconnectiondialog.h"
+#include <ui_qsqlconnectiondialog.h>
+#include <QCheckBox>
+#include <QMessageBox>
+#include <QPushButton>
#include <QSqlDatabase>
QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
: QDialog(parent)
+ , m_ui(new Ui::QSqlConnectionDialogUi)
{
- ui.setupUi(this);
+ m_ui->setupUi(this);
QStringList drivers = QSqlDatabase::drivers();
if (!drivers.contains("QSQLITE"))
- ui.dbCheckBox->setEnabled(false);
+ m_ui->dbCheckBox->setEnabled(false);
- ui.comboDriver->addItems(drivers);
+ m_ui->comboDriver->addItems(drivers);
+
+ connect(m_ui->okButton, &QPushButton::clicked,
+ this, &QSqlConnectionDialog::onOkButton);
+ connect(m_ui->cancelButton, &QPushButton::clicked,
+ this, &QSqlConnectionDialog::reject);
+ connect(m_ui->dbCheckBox, &QCheckBox::stateChanged,
+ this, &QSqlConnectionDialog::onDbCheckBox);
}
QSqlConnectionDialog::~QSqlConnectionDialog()
{
+ delete m_ui;
}
QString QSqlConnectionDialog::driverName() const
{
- return ui.comboDriver->currentText();
+ return m_ui->comboDriver->currentText();
}
QString QSqlConnectionDialog::databaseName() const
{
- return ui.editDatabase->text();
+ return m_ui->editDatabase->text();
}
QString QSqlConnectionDialog::userName() const
{
- return ui.editUsername->text();
+ return m_ui->editUsername->text();
}
QString QSqlConnectionDialog::password() const
{
- return ui.editPassword->text();
+ return m_ui->editPassword->text();
}
QString QSqlConnectionDialog::hostName() const
{
- return ui.editHostname->text();
+ return m_ui->editHostname->text();
}
int QSqlConnectionDialog::port() const
{
- return ui.portSpinBox->value();
+ return m_ui->portSpinBox->value();
}
bool QSqlConnectionDialog::useInMemoryDatabase() const
{
- return ui.dbCheckBox->isChecked();
+ return m_ui->dbCheckBox->isChecked();
}
-void QSqlConnectionDialog::on_okButton_clicked()
+void QSqlConnectionDialog::onOkButton()
{
- if (ui.comboDriver->currentText().isEmpty()) {
+ if (m_ui->comboDriver->currentText().isEmpty()) {
QMessageBox::information(this, tr("No database driver selected"),
tr("Please select a database driver"));
- ui.comboDriver->setFocus();
+ m_ui->comboDriver->setFocus();
} else {
accept();
}
}
+
+void QSqlConnectionDialog::onDbCheckBox()
+{
+ m_ui->connGroupBox->setEnabled(!m_ui->dbCheckBox->isChecked());
+}
diff --git a/examples/sql/sqlbrowser/qsqlconnectiondialog.h b/examples/sql/sqlbrowser/qsqlconnectiondialog.h
index 0f7d9386e2..a6384bb5b7 100644
--- a/examples/sql/sqlbrowser/qsqlconnectiondialog.h
+++ b/examples/sql/sqlbrowser/qsqlconnectiondialog.h
@@ -5,11 +5,15 @@
#define QSQLCONNECTIONDIALOG_H
#include <QDialog>
-#include <QMessageBox>
-#include "ui_qsqlconnectiondialog.h"
+QT_BEGIN_NAMESPACE
+namespace Ui
+{
+class QSqlConnectionDialogUi;
+}
+QT_END_NAMESPACE
-class QSqlConnectionDialog: public QDialog
+class QSqlConnectionDialog : public QDialog
{
Q_OBJECT
public:
@@ -25,12 +29,11 @@ public:
bool useInMemoryDatabase() const;
private slots:
- void on_okButton_clicked();
- void on_cancelButton_clicked() { reject(); }
- void on_dbCheckBox_clicked() { ui.connGroupBox->setEnabled(!ui.dbCheckBox->isChecked()); }
+ void onOkButton();
+ void onDbCheckBox();
private:
- Ui::QSqlConnectionDialogUi ui;
+ Ui::QSqlConnectionDialogUi *m_ui;
};
#endif
diff --git a/examples/sql/sqlwidgetmapper/CMakeLists.txt b/examples/sql/sqlwidgetmapper/CMakeLists.txt
index e0bb4447d4..91ce3cf339 100644
--- a/examples/sql/sqlwidgetmapper/CMakeLists.txt
+++ b/examples/sql/sqlwidgetmapper/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(sqlwidgetmapper LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/sqlwidgetmapper")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(sqlwidgetmapper PRIVATE
)
install(TARGETS sqlwidgetmapper
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET sqlwidgetmapper
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/sqlwidgetmapper/window.cpp b/examples/sql/sqlwidgetmapper/window.cpp
index fee3bc78dd..cd44174f84 100644
--- a/examples/sql/sqlwidgetmapper/window.cpp
+++ b/examples/sql/sqlwidgetmapper/window.cpp
@@ -1,11 +1,20 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-#include <QtSql>
-
#include "window.h"
+#include <QComboBox>
+#include <QDataWidgetMapper>
+#include <QGridLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QPushButton>
+#include <QSqlQuery>
+#include <QSqlRelationalDelegate>
+#include <QSqlTableModel>
+#include <QTextEdit>
+
//! [Set up widgets]
Window::Window(QWidget *parent)
: QWidget(parent)
diff --git a/examples/sql/sqlwidgetmapper/window.h b/examples/sql/sqlwidgetmapper/window.h
index c3b01155af..9af9628b90 100644
--- a/examples/sql/sqlwidgetmapper/window.h
+++ b/examples/sql/sqlwidgetmapper/window.h
@@ -6,18 +6,16 @@
#include <QWidget>
-QT_BEGIN_NAMESPACE
-class QComboBox;
-class QDataWidgetMapper;
-class QItemSelectionModel;
-class QLabel;
-class QLineEdit;
-class QPushButton;
-class QSqlRelationalTableModel;
-class QStandardItemModel;
-class QStringListModel;
-class QTextEdit;
-QT_END_NAMESPACE
+QT_FORWARD_DECLARE_CLASS(QComboBox)
+QT_FORWARD_DECLARE_CLASS(QDataWidgetMapper)
+QT_FORWARD_DECLARE_CLASS(QItemSelectionModel)
+QT_FORWARD_DECLARE_CLASS(QLabel)
+QT_FORWARD_DECLARE_CLASS(QLineEdit)
+QT_FORWARD_DECLARE_CLASS(QPushButton)
+QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel)
+QT_FORWARD_DECLARE_CLASS(QStandardItemModel)
+QT_FORWARD_DECLARE_CLASS(QStringListModel)
+QT_FORWARD_DECLARE_CLASS(QTextEdit)
//! [Window definition]
class Window : public QWidget
diff --git a/examples/sql/tablemodel/CMakeLists.txt b/examples/sql/tablemodel/CMakeLists.txt
index 7b65d81029..28919bb69a 100644
--- a/examples/sql/tablemodel/CMakeLists.txt
+++ b/examples/sql/tablemodel/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(tablemodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sql/tablemodel")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(tablemodel PRIVATE
)
install(TARGETS tablemodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET tablemodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/sql/tablemodel/tablemodel.cpp b/examples/sql/tablemodel/tablemodel.cpp
index ae0aa17719..04c114dc63 100644
--- a/examples/sql/tablemodel/tablemodel.cpp
+++ b/examples/sql/tablemodel/tablemodel.cpp
@@ -6,8 +6,6 @@
#include <QSqlTableModel>
#include <QTableView>
-#include <stdlib.h>
-
void initializeModel(QSqlTableModel *model)
{
model->setTable("person");
diff --git a/examples/vulkan/CMakeLists.txt b/examples/vulkan/CMakeLists.txt
index 96c801c7e7..98b0a31b5e 100644
--- a/examples/vulkan/CMakeLists.txt
+++ b/examples/vulkan/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(hellovulkantriangle)
if(TARGET Qt6::Widgets)
diff --git a/examples/vulkan/doc/src/hellovulkancubes.qdoc b/examples/vulkan/doc/src/hellovulkancubes.qdoc
index dc60b8bb68..91149911df 100644
--- a/examples/vulkan/doc/src/hellovulkancubes.qdoc
+++ b/examples/vulkan/doc/src/hellovulkancubes.qdoc
@@ -7,6 +7,7 @@
\title Hello Vulkan Cubes Example
\ingroup examples-vulkan
\brief Shows the basics of using QVulkanWindow.
+ \examplecategory {Graphics}
The \e{Hello Vulkan Cubes Example} shows more advanced usage of QVulkanWindow.
diff --git a/examples/vulkan/doc/src/hellovulkantriangle.qdoc b/examples/vulkan/doc/src/hellovulkantriangle.qdoc
index 75b085109b..bafa026ccd 100644
--- a/examples/vulkan/doc/src/hellovulkantriangle.qdoc
+++ b/examples/vulkan/doc/src/hellovulkantriangle.qdoc
@@ -7,6 +7,7 @@
\ingroup examples-vulkan
\title Hello Vulkan Triangle Example
\brief Shows the basics of rendering with QVulkanWindow and the Vulkan API.
+ \examplecategory {Graphics}
The \e{Hello Vulkan Triangle Example} creates a full graphics pipeline,
including a vertex and fragment shader, to render a triangle.
diff --git a/examples/vulkan/doc/src/hellovulkanwidget.qdoc b/examples/vulkan/doc/src/hellovulkanwidget.qdoc
index 0166a361b1..2a71084fc4 100644
--- a/examples/vulkan/doc/src/hellovulkanwidget.qdoc
+++ b/examples/vulkan/doc/src/hellovulkanwidget.qdoc
@@ -7,6 +7,7 @@
\ingroup examples-vulkan
\title Hello Vulkan Widget Example
\brief Shows the usage of QVulkanWindow in QWidget applications.
+ \examplecategory {Graphics}
The \e{Hello Vulkan Widget Example} is a variant of \l hellovulkantriangle
that embeds the QVulkanWindow into a QWidget-based user interface using
diff --git a/examples/vulkan/hellovulkancubes/CMakeLists.txt b/examples/vulkan/hellovulkancubes/CMakeLists.txt
index 51729de44f..5debb4efaf 100644
--- a/examples/vulkan/hellovulkancubes/CMakeLists.txt
+++ b/examples/vulkan/hellovulkancubes/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(hellovulkancubes LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/vulkan/hellovulkancubes")
-
find_package(Qt6 REQUIRED COMPONENTS Concurrent Core Gui Widgets)
qt_standard_project_setup()
@@ -62,7 +56,14 @@ qt6_add_resources(hellovulkancubes "hellovulkancubes"
)
install(TARGETS hellovulkancubes
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET hellovulkancubes
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/vulkan/hellovulkancubes/mainwindow.cpp b/examples/vulkan/hellovulkancubes/mainwindow.cpp
index e84436bb1d..198a168bce 100644
--- a/examples/vulkan/hellovulkancubes/mainwindow.cpp
+++ b/examples/vulkan/hellovulkancubes/mainwindow.cpp
@@ -42,7 +42,7 @@ MainWindow::MainWindow(VulkanWindow *vulkanWindow)
pauseButton->setFocusPolicy(Qt::NoFocus);
connect(quitButton, &QPushButton::clicked, qApp, &QCoreApplication::quit);
- connect(newButton, &QPushButton::clicked, vulkanWindow, [=] {
+ connect(newButton, &QPushButton::clicked, vulkanWindow, [this, vulkanWindow] {
vulkanWindow->addNew();
m_count = vulkanWindow->instanceCount();
counterLcd->display(m_count);
diff --git a/examples/vulkan/hellovulkancubes/renderer.cpp b/examples/vulkan/hellovulkancubes/renderer.cpp
index 34023eefdb..037d97014c 100644
--- a/examples/vulkan/hellovulkancubes/renderer.cpp
+++ b/examples/vulkan/hellovulkancubes/renderer.cpp
@@ -38,7 +38,7 @@ Renderer::Renderer(VulkanWindow *w, int initialCount)
m_blockMesh.load(QStringLiteral(":/block.buf"));
m_logoMesh.load(QStringLiteral(":/qt_logo.buf"));
- QObject::connect(&m_frameWatcher, &QFutureWatcherBase::finished, [this] {
+ QObject::connect(&m_frameWatcher, &QFutureWatcherBase::finished, m_window, [this] {
if (m_framePending) {
m_framePending = false;
m_window->frameReady();
diff --git a/examples/vulkan/hellovulkantriangle/CMakeLists.txt b/examples/vulkan/hellovulkantriangle/CMakeLists.txt
index c040063097..23789d4717 100644
--- a/examples/vulkan/hellovulkantriangle/CMakeLists.txt
+++ b/examples/vulkan/hellovulkantriangle/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(hellovulkantriangle LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/vulkan/hellovulkantriangle")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui)
qt_standard_project_setup()
@@ -51,7 +45,14 @@ qt_add_resources(hellovulkantriangle "hellovulkantriangle"
)
install(TARGETS hellovulkantriangle
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET hellovulkantriangle
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/vulkan/hellovulkanwidget/CMakeLists.txt b/examples/vulkan/hellovulkanwidget/CMakeLists.txt
index f9e5cb79f6..aed510b6d1 100644
--- a/examples/vulkan/hellovulkanwidget/CMakeLists.txt
+++ b/examples/vulkan/hellovulkanwidget/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(hellovulkanwidget LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/vulkan/hellovulkanwidget")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -53,7 +47,14 @@ qt_add_resources(hellovulkanwidget "hellovulkanwidget"
)
install(TARGETS hellovulkanwidget
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET hellovulkanwidget
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/CMakeLists.txt b/examples/widgets/CMakeLists.txt
index 315865b841..42dc87a865 100644
--- a/examples/widgets/CMakeLists.txt
+++ b/examples/widgets/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Widgets)
return()
@@ -9,15 +9,14 @@ if(QT_FEATURE_animation)
endif()
add_subdirectory(desktop)
add_subdirectory(dialogs)
-add_subdirectory(effects)
qt_internal_add_example(gallery)
add_subdirectory(gestures)
add_subdirectory(graphicsview)
add_subdirectory(itemviews)
add_subdirectory(layouts)
add_subdirectory(painting)
+add_subdirectory(rhi)
add_subdirectory(richtext)
-add_subdirectory(scroller)
add_subdirectory(tools)
add_subdirectory(touch)
add_subdirectory(tutorials)
@@ -28,6 +27,3 @@ endif()
if(QT_FEATURE_cursor)
add_subdirectory(mainwindows)
endif()
-if(QT_FEATURE_opengl AND TARGET Qt6::Gui)
- qt_internal_add_example(windowcontainer)
-endif()
diff --git a/examples/widgets/animation/CMakeLists.txt b/examples/widgets/animation/CMakeLists.txt
index d9a18bb866..ed8ee0558c 100644
--- a/examples/widgets/animation/CMakeLists.txt
+++ b/examples/widgets/animation/CMakeLists.txt
@@ -1 +1,3 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(easing)
diff --git a/examples/widgets/animation/easing/CMakeLists.txt b/examples/widgets/animation/easing/CMakeLists.txt
index 7c42f910b4..8398f7d3e0 100644
--- a/examples/widgets/animation/easing/CMakeLists.txt
+++ b/examples/widgets/animation/easing/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(easing LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/animation/easing")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -45,7 +39,14 @@ qt_add_resources(easing "easing"
)
install(TARGETS easing
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET easing
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/animation/easing/main.cpp b/examples/widgets/animation/easing/main.cpp
index a1c01698d1..26009a6bf7 100644
--- a/examples/widgets/animation/easing/main.cpp
+++ b/examples/widgets/animation/easing/main.cpp
@@ -6,7 +6,6 @@
int main(int argc, char **argv)
{
- Q_INIT_RESOURCE(easing);
QApplication app(argc, argv);
Window w;
diff --git a/examples/widgets/desktop/CMakeLists.txt b/examples/widgets/desktop/CMakeLists.txt
index 169fa9ffac..0f4eda12aa 100644
--- a/examples/widgets/desktop/CMakeLists.txt
+++ b/examples/widgets/desktop/CMakeLists.txt
@@ -1,2 +1,4 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(screenshot)
qt_internal_add_example(systray)
diff --git a/examples/widgets/desktop/screenshot/CMakeLists.txt b/examples/widgets/desktop/screenshot/CMakeLists.txt
index cba4215afa..4d9b97d114 100644
--- a/examples/widgets/desktop/screenshot/CMakeLists.txt
+++ b/examples/widgets/desktop/screenshot/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(screenshot LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/desktop/screenshot")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(screenshot PRIVATE
)
install(TARGETS screenshot
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET screenshot
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/desktop/systray/CMakeLists.txt b/examples/widgets/desktop/systray/CMakeLists.txt
index 4aaed39edf..c42469bf59 100644
--- a/examples/widgets/desktop/systray/CMakeLists.txt
+++ b/examples/widgets/desktop/systray/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(systray LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/desktop/systray")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -45,7 +39,14 @@ qt_add_resources(systray "systray"
)
install(TARGETS systray
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET systray
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/desktop/systray/doc/images/systemtray-editor.png b/examples/widgets/desktop/systray/doc/images/systemtray-editor.png
index f7c23db28a..5537c09fde 100644
--- a/examples/widgets/desktop/systray/doc/images/systemtray-editor.png
+++ b/examples/widgets/desktop/systray/doc/images/systemtray-editor.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/doc/images/systemtray-example.png b/examples/widgets/desktop/systray/doc/images/systemtray-example.png
index 98b5c8133e..f2f9f73031 100644
--- a/examples/widgets/desktop/systray/doc/images/systemtray-example.png
+++ b/examples/widgets/desktop/systray/doc/images/systemtray-example.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/doc/src/systray.qdoc b/examples/widgets/desktop/systray/doc/src/systray.qdoc
index 5c4350383d..b0dff58e31 100644
--- a/examples/widgets/desktop/systray/doc/src/systray.qdoc
+++ b/examples/widgets/desktop/systray/doc/src/systray.qdoc
@@ -4,6 +4,7 @@
/*!
\example desktop/systray
\title System Tray Icon Example
+ \examplecategory {Desktop}
\ingroup examples-widgets
\brief The System Tray Icon example shows how to add an icon with a menu
and popup messages to a desktop environment's system tray.
diff --git a/examples/widgets/desktop/systray/images/bad.png b/examples/widgets/desktop/systray/images/bad.png
index c8701a241a..b09de85869 100644
--- a/examples/widgets/desktop/systray/images/bad.png
+++ b/examples/widgets/desktop/systray/images/bad.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/images/heart.png b/examples/widgets/desktop/systray/images/heart.png
index cee1302b7d..5d466b1b89 100644
--- a/examples/widgets/desktop/systray/images/heart.png
+++ b/examples/widgets/desktop/systray/images/heart.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/images/trash.png b/examples/widgets/desktop/systray/images/trash.png
index 4c24db926d..454074f9f2 100644
--- a/examples/widgets/desktop/systray/images/trash.png
+++ b/examples/widgets/desktop/systray/images/trash.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/main.cpp b/examples/widgets/desktop/systray/main.cpp
index d01f813d2f..d13bde11ce 100644
--- a/examples/widgets/desktop/systray/main.cpp
+++ b/examples/widgets/desktop/systray/main.cpp
@@ -10,8 +10,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(systray);
-
QApplication app(argc, argv);
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
diff --git a/examples/widgets/dialogs/CMakeLists.txt b/examples/widgets/dialogs/CMakeLists.txt
index b16cbc7f44..3148d3585f 100644
--- a/examples/widgets/dialogs/CMakeLists.txt
+++ b/examples/widgets/dialogs/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(QT_FEATURE_wizard)
qt_internal_add_example(trivialwizard)
diff --git a/examples/widgets/dialogs/licensewizard/CMakeLists.txt b/examples/widgets/dialogs/licensewizard/CMakeLists.txt
index a6cda7a74a..0cf2d61c8b 100644
--- a/examples/widgets/dialogs/licensewizard/CMakeLists.txt
+++ b/examples/widgets/dialogs/licensewizard/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(licensewizard LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/licensewizard")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui PrintSupport Widgets)
qt_standard_project_setup()
@@ -45,7 +39,14 @@ qt_add_resources(licensewizard "licensewizard"
)
install(TARGETS licensewizard
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET licensewizard
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/dialogs/licensewizard/main.cpp b/examples/widgets/dialogs/licensewizard/main.cpp
index 13e13f0e32..d16b5dc6d1 100644
--- a/examples/widgets/dialogs/licensewizard/main.cpp
+++ b/examples/widgets/dialogs/licensewizard/main.cpp
@@ -10,8 +10,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(licensewizard);
-
QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION
diff --git a/examples/widgets/dialogs/standarddialogs/CMakeLists.txt b/examples/widgets/dialogs/standarddialogs/CMakeLists.txt
index 3116603c98..07e22469ee 100644
--- a/examples/widgets/dialogs/standarddialogs/CMakeLists.txt
+++ b/examples/widgets/dialogs/standarddialogs/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(standarddialogs LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/standarddialogs")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(standarddialogs PRIVATE
)
install(TARGETS standarddialogs
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET standarddialogs
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index af8df344c7..67fb615794 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -191,6 +191,7 @@ Dialog::Dialog(QWidget *parent)
colorDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QColorDialog::DontUseNativeDialog);
colorDialogOptionsWidget->addCheckBox(tr("Show alpha channel") , QColorDialog::ShowAlphaChannel);
colorDialogOptionsWidget->addCheckBox(tr("No buttons") , QColorDialog::NoButtons);
+ colorDialogOptionsWidget->addCheckBox(tr("Hide Color Picker") , QColorDialog::NoEyeDropperButton);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0);
layout->addWidget(colorDialogOptionsWidget, 2, 0, 1 ,2);
@@ -454,13 +455,15 @@ void Dialog::warningMessage()
tr("Delete the only copy of your movie manuscript?"), { }, this);
msgBox.setInformativeText(tr("You've been working on this manuscript for 738 days now. Hang in there!"));
msgBox.setDetailedText("\"A long time ago in a galaxy far, far away....\"");
- msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole);
- msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole);
- if (msgBox.exec() == QMessageBox::AcceptRole)
+ auto *keepButton = msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole);
+ auto *deleteButton = msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole);
+ msgBox.exec();
+ if (msgBox.clickedButton() == keepButton)
warningLabel->setText(tr("Keep"));
- else
+ else if (msgBox.clickedButton() == deleteButton)
warningLabel->setText(tr("Delete"));
-
+ else
+ warningLabel->setText("");
}
void Dialog::errorMessage()
diff --git a/examples/widgets/dialogs/tabdialog/CMakeLists.txt b/examples/widgets/dialogs/tabdialog/CMakeLists.txt
index 6dfc49b294..b959a5c3e4 100644
--- a/examples/widgets/dialogs/tabdialog/CMakeLists.txt
+++ b/examples/widgets/dialogs/tabdialog/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(tabdialog LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/tabdialog")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(tabdialog PRIVATE
)
install(TARGETS tabdialog
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET tabdialog
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/dialogs/trivialwizard/CMakeLists.txt b/examples/widgets/dialogs/trivialwizard/CMakeLists.txt
index c8efc8b8c5..966d99a7aa 100644
--- a/examples/widgets/dialogs/trivialwizard/CMakeLists.txt
+++ b/examples/widgets/dialogs/trivialwizard/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(trivialwizard LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/trivialwizard")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(trivialwizard PRIVATE
)
install(TARGETS trivialwizard
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET trivialwizard
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc
index 5ebf0ff3a4..4c38ffc50d 100644
--- a/examples/widgets/doc/dropsite.qdoc
+++ b/examples/widgets/doc/dropsite.qdoc
@@ -4,6 +4,7 @@
/*!
\example draganddrop/dropsite
\title Drop Site Example
+ \examplecategory {User Interface Components}
\brief The example shows how to distinguish the various MIME formats available
in a drag and drop operation.
diff --git a/examples/widgets/doc/images/analogclock-viewport.png b/examples/widgets/doc/images/analogclock-viewport.png
index 31ce0c3c6e..40e0fc8bb6 100644
--- a/examples/widgets/doc/images/analogclock-viewport.png
+++ b/examples/widgets/doc/images/analogclock-viewport.png
Binary files differ
diff --git a/examples/widgets/doc/images/calendar-example.png b/examples/widgets/doc/images/calendar-example.png
deleted file mode 100644
index 895ce76b09..0000000000
--- a/examples/widgets/doc/images/calendar-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/draganddroppuzzle-example.png b/examples/widgets/doc/images/draganddroppuzzle-example.png
deleted file mode 100644
index ca6844581e..0000000000
--- a/examples/widgets/doc/images/draganddroppuzzle-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/echoplugin.png b/examples/widgets/doc/images/echoplugin.png
deleted file mode 100644
index 6c4fd2f6d8..0000000000
--- a/examples/widgets/doc/images/echoplugin.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/echopluginexample.png b/examples/widgets/doc/images/echopluginexample.png
deleted file mode 100644
index 24e039714f..0000000000
--- a/examples/widgets/doc/images/echopluginexample.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/fademessageeffect-example-faded.png b/examples/widgets/doc/images/fademessageeffect-example-faded.png
deleted file mode 100644
index ea66d2c7f0..0000000000
--- a/examples/widgets/doc/images/fademessageeffect-example-faded.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/fademessageeffect-example.png b/examples/widgets/doc/images/fademessageeffect-example.png
deleted file mode 100644
index 823c85101d..0000000000
--- a/examples/widgets/doc/images/fademessageeffect-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/fridgemagnets-example.png b/examples/widgets/doc/images/fridgemagnets-example.png
deleted file mode 100644
index 2a890aad4e..0000000000
--- a/examples/widgets/doc/images/fridgemagnets-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/graphicsflowlayout-example.png b/examples/widgets/doc/images/graphicsflowlayout-example.png
deleted file mode 100644
index 953d54086a..0000000000
--- a/examples/widgets/doc/images/graphicsflowlayout-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/imagegestures-example.jpg b/examples/widgets/doc/images/imagegestures-example.jpg
deleted file mode 100644
index c8484b4a71..0000000000
--- a/examples/widgets/doc/images/imagegestures-example.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/imagegestures-example.png b/examples/widgets/doc/images/imagegestures-example.png
new file mode 100644
index 0000000000..c83b71574f
--- /dev/null
+++ b/examples/widgets/doc/images/imagegestures-example.png
Binary files differ
diff --git a/examples/widgets/doc/images/imageviewer-fit_to_window_1.png b/examples/widgets/doc/images/imageviewer-fit_to_window_1.png
deleted file mode 100644
index 0fe1ba1c62..0000000000
--- a/examples/widgets/doc/images/imageviewer-fit_to_window_1.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/imageviewer-fit_to_window_2.png b/examples/widgets/doc/images/imageviewer-fit_to_window_2.png
deleted file mode 100644
index 29e3a93bc1..0000000000
--- a/examples/widgets/doc/images/imageviewer-fit_to_window_2.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/imageviewer-original_size.png b/examples/widgets/doc/images/imageviewer-original_size.png
deleted file mode 100644
index c0443eba25..0000000000
--- a/examples/widgets/doc/images/imageviewer-original_size.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/imageviewer-zoom_in_1.png b/examples/widgets/doc/images/imageviewer-zoom_in_1.png
deleted file mode 100644
index 05b0fffecb..0000000000
--- a/examples/widgets/doc/images/imageviewer-zoom_in_1.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/imageviewer-zoom_in_2.png b/examples/widgets/doc/images/imageviewer-zoom_in_2.png
deleted file mode 100644
index 0c36111c03..0000000000
--- a/examples/widgets/doc/images/imageviewer-zoom_in_2.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/itemviewspuzzle-example.png b/examples/widgets/doc/images/itemviewspuzzle-example.png
deleted file mode 100644
index aae6a953ca..0000000000
--- a/examples/widgets/doc/images/itemviewspuzzle-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/mainwindow-demo.png b/examples/widgets/doc/images/mainwindow-demo.png
deleted file mode 100644
index 0e146d156e..0000000000
--- a/examples/widgets/doc/images/mainwindow-demo.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/plugandpaint-plugindialog.png b/examples/widgets/doc/images/plugandpaint-plugindialog.png
deleted file mode 100644
index 4b601bd58b..0000000000
--- a/examples/widgets/doc/images/plugandpaint-plugindialog.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/plugandpaint.png b/examples/widgets/doc/images/plugandpaint.png
deleted file mode 100644
index bd5d001f91..0000000000
--- a/examples/widgets/doc/images/plugandpaint.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/settingseditor-example.png b/examples/widgets/doc/images/settingseditor-example.png
deleted file mode 100644
index 7a5be05fd0..0000000000
--- a/examples/widgets/doc/images/settingseditor-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/stylepluginexample.png b/examples/widgets/doc/images/stylepluginexample.png
deleted file mode 100644
index 9ff69c512b..0000000000
--- a/examples/widgets/doc/images/stylepluginexample.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/stylesheet-pagefold.png b/examples/widgets/doc/images/stylesheet-pagefold.png
deleted file mode 100644
index d1358f326b..0000000000
--- a/examples/widgets/doc/images/stylesheet-pagefold.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/images/textedit-demo.png b/examples/widgets/doc/images/textedit-demo.png
deleted file mode 100644
index 3cf2883a12..0000000000
--- a/examples/widgets/doc/images/textedit-demo.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/src/addressbook.qdoc b/examples/widgets/doc/src/addressbook.qdoc
index 24bcee5a26..8f2512298b 100644
--- a/examples/widgets/doc/src/addressbook.qdoc
+++ b/examples/widgets/doc/src/addressbook.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/addressbook
\title Address Book
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief The address book example shows how to use proxy models to display
different views onto data from a single model.
diff --git a/examples/widgets/doc/src/affine.qdoc b/examples/widgets/doc/src/affine.qdoc
index accbf9adfa..2ec3a4fc4d 100644
--- a/examples/widgets/doc/src/affine.qdoc
+++ b/examples/widgets/doc/src/affine.qdoc
@@ -4,8 +4,9 @@
/*!
\example painting/affine
\title Affine Transformations
+ \examplecategory {Graphics}
\ingroup examples-painting
- \brief Demonstrates how affine transformations in QPainter works.
+ \brief Demonstrates how affine transformations in QPainter work.
\brief In this example we show Qt's ability to perform affine transformations
on painting operations.
diff --git a/examples/widgets/doc/src/analogclock.qdoc b/examples/widgets/doc/src/analogclock.qdoc
index 27d14be809..8f98f4b7b0 100644
--- a/examples/widgets/doc/src/analogclock.qdoc
+++ b/examples/widgets/doc/src/analogclock.qdoc
@@ -20,8 +20,8 @@
\section1 AnalogClock Class Definition
- The \c AnalogClock class provides a clock widget with hour and minute
- hands that is automatically updated every few seconds.
+ The \c AnalogClock class provides a clock widget with hour, minute and
+ second hands that is automatically updated every second.
We subclass \l QWidget and reimplement the standard
\l{QWidget::paintEvent()}{paintEvent()} function to draw the clock face:
@@ -29,19 +29,14 @@
\section1 AnalogClock Class Implementation
- \snippet widgets/analogclock/analogclock.cpp 1
-
When the widget is constructed, we set up a one-second timer to
keep track of the current time, and we connect it to the standard
\l{QWidget::update()}{update()} slot so that the clock face is
updated when the timer emits the \l{QTimer::timeout()}{timeout()}
- signal.
-
- Finally, we resize the widget so that it is displayed at a
+ signal. Finally, we resize the widget so that it is displayed at a
reasonable size.
- \snippet widgets/analogclock/analogclock.cpp 8
- \snippet widgets/analogclock/analogclock.cpp 10
+ \snippet widgets/analogclock/analogclock.cpp 1
The \c paintEvent() function is called whenever the widget's
contents need to be updated. This happens when the widget is
@@ -49,31 +44,37 @@
executed when the widget's \l{QWidget::update()}{update()} slot
is called. Since we connected the timer's
\l{QTimer::timeout()}{timeout()} signal to this slot, it will be
- called at least once every five seconds.
+ called at least once per second.
Before we set up the painter and draw the clock, we first define
- two lists of \l {QPoint}s and two \l{QColor}s that will be used
- for the hour and minute hands. The minute hand's color has an
- alpha component of 191, meaning that it's 75% opaque.
+ three lists of \l {QPoint}s and three \l{QColor}s that will be used
+ for the hour, minute and second hands. We use the
+ \l{QWidget::palette()}{palette()} function to get appropriate colors
+ that fit into the rest of the window, both in light and dark mode.
+ The hour and minute hands are drawn in the foreground color, the
+ second hand is drawn in the accent color.
We also determine the length of the widget's shortest side so that we
can fit the clock face inside the widget. It is also useful to determine
the current time before we start drawing.
- \snippet widgets/analogclock/analogclock.cpp 11
- \snippet widgets/analogclock/analogclock.cpp 12
- \snippet widgets/analogclock/analogclock.cpp 13
- \snippet widgets/analogclock/analogclock.cpp 14
+ \snippet widgets/analogclock/analogclock.cpp 8
+ \snippet widgets/analogclock/analogclock.cpp 10
The contents of custom widgets are drawn with a QPainter.
Painters can be used to draw on any QPaintDevice, but they are
usually used with widgets, so we pass the widget instance to the
painter's constructor.
+ \snippet widgets/analogclock/analogclock.cpp 11
+ \snippet widgets/analogclock/analogclock.cpp 14
+
We call QPainter::setRenderHint() with QPainter::Antialiasing to
turn on antialiasing. This makes drawing of diagonal lines much
smoother.
+ \snippet widgets/analogclock/analogclock.cpp 12
+
The translation moves the origin to the center of the widget, and
the scale operation ensures that the following drawing operations
are scaled to fit within the widget. We use a scale factor that
@@ -81,6 +82,8 @@
ensures that these lie within the length of the widget's shortest
side.
+ \snippet widgets/analogclock/analogclock.cpp 13
+
To make our code simpler, we will draw a fixed size clock face that will
be positioned and scaled so that it lies in the center of the widget.
@@ -91,44 +94,47 @@
\image analogclock-viewport.png
- We draw the hour hand first, using a formula that rotates the coordinate
- system counterclockwise by a number of degrees determined by the current
- hour and minute. This means that the hand will be shown rotated clockwise
- by the required amount.
-
- \snippet widgets/analogclock/analogclock.cpp 15
- \snippet widgets/analogclock/analogclock.cpp 16
-
We set the pen to be Qt::NoPen because we don't want any outline,
and we use a solid brush with the color appropriate for
displaying hours. Brushes are used when filling in polygons and
other geometric shapes.
- \snippet widgets/analogclock/analogclock.cpp 17
- \snippet widgets/analogclock/analogclock.cpp 19
+ \snippet widgets/analogclock/analogclock.cpp 15
+ \snippet widgets/analogclock/analogclock.cpp 16
+ We draw the hour hand first, using a formula that rotates the coordinate
+ system counterclockwise by a number of degrees determined by the current
+ hour and minute. This means that the hand will be shown rotated clockwise
+ by the required amount.
We save and restore the transformation matrix before and after the
rotation because we want to place the minute hand without having to
take into account any previous rotations.
+ \snippet widgets/analogclock/analogclock.cpp 17
+ \snippet widgets/analogclock/analogclock.cpp 19
+
+ We draw markers around the edge of the clock for each hour in the same
+ color as the hour hand. We draw each marker then rotate the coordinate
+ system so that the painter is ready for the next one.
+
\snippet widgets/analogclock/analogclock.cpp 20
- \codeline
+
+ The minute hand is rotated and painted in a similar way to the hour hand.
+
\snippet widgets/analogclock/analogclock.cpp 21
- We draw markers around the edge of the clock for each hour. We
- draw each marker then rotate the coordinate system so that the
- painter is ready for the next one.
+ For the seconds hand we do the same and add two cicles as a visual highlight.
- \snippet widgets/analogclock/analogclock.cpp 22
\snippet widgets/analogclock/analogclock.cpp 23
+ \codeline
+ \snippet widgets/analogclock/analogclock.cpp 24
- The minute hand is rotated in a similar way to the hour hand.
+ Finally, we draw markers around the edge of the clock, indicating
+ minutes and seconds. This time we draw them as lines and therefore
+ set the pen to the respective color.
\snippet widgets/analogclock/analogclock.cpp 25
\codeline
- \snippet widgets/analogclock/analogclock.cpp 26
+ \snippet widgets/analogclock/analogclock.cpp 27
- Again, we draw markers around the edge of the clock, but this
- time to indicate minutes. We skip multiples of 5 to avoid drawing
- minute markers on top of hour markers.
*/
diff --git a/examples/widgets/doc/src/application.qdoc b/examples/widgets/doc/src/application.qdoc
deleted file mode 100644
index 43073a8152..0000000000
--- a/examples/widgets/doc/src/application.qdoc
+++ /dev/null
@@ -1,370 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example mainwindows/application
- \title Qt Widgets - Application Example
- \ingroup examples-mainwindow
-
- \brief The Application example shows how to implement a standard
- widget application with menus, toolbars, and a status bar. The example
- itself is a simple text editor program built around QPlainTextEdit.
-
- \image application.png Screenshot of the Application example
-
- Nearly all of the code for the Application example is in the \c
- MainWindow class, which inherits QMainWindow. QMainWindow
- provides the framework for windows that have menus, toolbars,
- dock windows, and a status bar. The application provides
- \uicontrol{File}, \uicontrol{Edit}, and \uicontrol{Help} entries in the menu
- bar, with the following popup menus:
-
- \image application-menus.png The Application example's menu system
-
- The status bar at the bottom of the main window shows a
- description of the menu item or toolbar button under the cursor.
-
- To keep the example simple, recently opened files aren't shown in
- the \uicontrol{File} menu, even though this feature is desired in 90%
- of applications. Furthermore, this example can only load one file at a
- time. The \l{mainwindows/mdi}{MDI} example shows how to lift these
- restrictions and how to implement recently opened files handling.
-
- \section1 MainWindow Class Definition
-
- Here's the class definition:
-
- \snippet mainwindows/application/mainwindow.h 0
-
- The public API is restricted to the constructor. In the \c
- protected section, we reimplement QWidget::closeEvent() to detect
- when the user attempts to close the window, and warn the user
- about unsaved changes. In the \c{private slots} section, we
- declare slots that correspond to menu entries, as well as a
- mysterious \c documentWasModified() slot. Finally, in the \c
- private section of the class, we have various members that will
- be explained in due time.
-
- \section1 MainWindow Class Implementation
-
- \snippet mainwindows/application/mainwindow.cpp 0
-
- We start by including \c <QtWidgets>, a header file that contains the
- definition of all classes in the Qt Core, Qt GUI and Qt Widgets
- modules. This saves us from the trouble of having to include
- every class individually. We also include \c mainwindow.h.
-
- You might wonder why we don't include \c <QtWidgets> in \c
- mainwindow.h and be done with it. The reason is that including
- such a large header from another header file can rapidly degrade
- performances. Here, it wouldn't do any harm, but it's still
- generally a good idea to include only the header files that are
- strictly necessary from another header file.
-
- \snippet mainwindows/application/mainwindow.cpp 1
- \snippet mainwindows/application/mainwindow.cpp 2
-
- In the constructor, we start by creating a QPlainTextEdit widget as a
- child of the main window (the \c this object). Then we call
- QMainWindow::setCentralWidget() to tell that this is going to be
- the widget that occupies the central area of the main window,
- between the toolbars and the status bar.
-
- Then we call \c createActions() and \c createStatusBar(), two private
- functions that set up the user interface. After that, we call \c
- readSettings() to restore the user's preferences.
-
- We establish a signal-slot connection between the QPlainTextEdit's
- document object and our \c documentWasModified() slot. Whenever
- the user modifies the text in the QPlainTextEdit, we want to update
- the title bar to show that the file was modified.
-
- At the end, we set the window title using the private
- \c setCurrentFile() function. We'll come back to this later.
-
- \target close event handler
- \snippet mainwindows/application/mainwindow.cpp 3
- \snippet mainwindows/application/mainwindow.cpp 4
-
- When the user attempts to close the window, we call the private
- function \c maybeSave() to give the user the possibility to save
- pending changes. The function returns true if the user wants the
- application to close; otherwise, it returns false. In the first
- case, we save the user's preferences to disk and accept the close
- event; in the second case, we ignore the close event, meaning
- that the application will stay up and running as if nothing
- happened.
-
- \snippet mainwindows/application/mainwindow.cpp 5
- \snippet mainwindows/application/mainwindow.cpp 6
-
- The \c newFile() slot is invoked when the user selects
- \uicontrol{File|New} from the menu. We call \c maybeSave() to save any
- pending changes and if the user accepts to go on, we clear the
- QPlainTextEdit and call the private function \c setCurrentFile() to
- update the window title and clear the
- \l{QWidget::windowModified}{windowModified} flag.
-
- \snippet mainwindows/application/mainwindow.cpp 7
- \snippet mainwindows/application/mainwindow.cpp 8
-
- The \c open() slot is invoked when the user clicks
- \uicontrol{File|Open}. We pop up a QFileDialog asking the user to
- choose a file. If the user chooses a file (i.e., \c fileName is
- not an empty string), we call the private function \c loadFile()
- to actually load the file.
-
- \snippet mainwindows/application/mainwindow.cpp 9
- \snippet mainwindows/application/mainwindow.cpp 10
-
- The \c save() slot is invoked when the user clicks
- \uicontrol{File|Save}. If the user hasn't provided a name for the file
- yet, we call \c saveAs(); otherwise, we call the private function
- \c saveFile() to actually save the file.
-
- \snippet mainwindows/application/mainwindow.cpp 11
- \snippet mainwindows/application/mainwindow.cpp 12
-
- In \c saveAs(), we start by popping up a QFileDialog asking the
- user to provide a name. If the user clicks \uicontrol{Cancel}, the
- returned file name is empty, and we do nothing.
-
- \snippet mainwindows/application/mainwindow.cpp 13
- \snippet mainwindows/application/mainwindow.cpp 14
-
- The application's About box is done using one statement, using
- the QMessageBox::about() static function and relying on its
- support for an HTML subset.
-
- The \l{QObject::tr()}{tr()} call around the literal string marks
- the string for translation. It is a good habit to call
- \l{QObject::tr()}{tr()} on all user-visible strings, in case you
- later decide to translate your application to other languages.
- The \l{Internationalization with Qt} overview covers
- \l{QObject::tr()}{tr()} in more detail.
-
- \snippet mainwindows/application/mainwindow.cpp 15
- \snippet mainwindows/application/mainwindow.cpp 16
-
- The \c documentWasModified() slot is invoked each time the text
- in the QPlainTextEdit changes because of user edits. We call
- QWidget::setWindowModified() to make the title bar show that the
- file was modified. How this is done varies on each platform.
-
- \snippet mainwindows/application/mainwindow.cpp 17
- \snippet mainwindows/application/mainwindow.cpp 18
- \dots
- \snippet mainwindows/application/mainwindow.cpp 22
-
- The \c createActions() private function, which is called from the
- \c MainWindow constructor, creates \l{QAction}s and populates
- the menus and two toolbars. The code is very
- repetitive, so we show only the actions corresponding to
- \uicontrol{File|New}, \uicontrol{File|Open}, and \uicontrol{Help|About Qt}.
-
- A QAction is an object that represents one user action, such as
- saving a file or invoking a dialog. An action can be put in a
- QMenu or a QToolBar, or both, or in any other widget that
- reimplements QWidget::actionEvent().
-
- An action has a text that is shown in the menu, an icon, a
- shortcut key, a tooltip, a status tip (shown in the status bar),
- a "What's This?" text, and more. It emits a
- \l{QAction::triggered()}{triggered()} signal whenever the user
- invokes the action (e.g., by clicking the associated menu item or
- toolbar button).
-
- Instances of QAction can be created by passing a parent QObject or
- by using one of the convenience functions of QMenu, QMenuBar or QToolBar.
- We create the actions that are in a menu as well as in a toolbar
- parented on the window to prevent ownership issues. For actions
- that are only in the menu, we use the convenience function
- QMenu::addAction(), which allows us to pass text, icon and the
- target object and its slot member function.
-
- Creating toolbars is very similar to creating menus. The same
- actions that we put in the menus can be reused in the toolbars.
- After creating the action, we add it to the toolbar using
- QToolBar::addAction().
-
- The code above contains one more idiom that must be explained.
- For some of the actions, we specify an icon as a QIcon to the
- QAction constructor. We use QIcon::fromTheme() to obtain
- the correct standard icon from the underlying window system.
- If that fails due to the platform not supporting it, we
- pass a file name as fallback. Here, the file name starts
- with \c{:}. Such file names aren't ordinary file names, but
- rather path in the executable's stored resources. We'll come back
- to this when we review the \c application.qrc file that's part of
- the project.
-
- \snippet mainwindows/application/mainwindow.cpp 23
- \snippet mainwindows/application/mainwindow.cpp 24
-
- The \uicontrol{Edit|Cut} and \uicontrol{Edit|Copy} actions must be available
- only when the QPlainTextEdit contains selected text. We disable them
- by default and connect the QPlainTextEdit::copyAvailable() signal to
- the QAction::setEnabled() slot, ensuring that the actions are
- disabled when the text editor has no selection.
-
- Just before we create the \uicontrol{Help} menu, we call
- QMenuBar::addSeparator(). This has no effect for most widget
- styles (e.g., Windows and \macos styles), but for some
- styles this makes sure that \uicontrol{Help} is pushed to the right
- side of the menu bar.
-
- \snippet mainwindows/application/mainwindow.cpp 32
- \snippet mainwindows/application/mainwindow.cpp 33
-
- QMainWindow::statusBar() returns a pointer to the main window's
- QStatusBar widget. Like with \l{QMainWindow::menuBar()}, the
- widget is automatically created the first time the function is
- called.
-
- \snippet mainwindows/application/mainwindow.cpp 34
- \snippet mainwindows/application/mainwindow.cpp 36
-
- The \c readSettings() function is called from the constructor to
- load the user's preferences and other application settings. The
- QSettings class provides a high-level interface for storing
- settings permanently on disk. On Windows, it uses the (in)famous
- Windows registry; on \macos, it uses the native XML-based
- CFPreferences API; on Unix/X11, it uses text files.
-
- The QSettings constructor takes arguments that identify your
- company and the name of the product. This ensures that the
- settings for different applications are kept separately.
-
- We use QSettings::value() to extract the value of the geometry setting.
- The second argument to QSettings::value() is
- optional and specifies a default value for the setting if there
- exists none. This value is used the first time the application is
- run.
-
- We use QWidget::saveGeometry() and Widget::restoreGeometry() to
- save the position. They use an opaque QByteArray to store
- screen number, geometry and window state.
-
- \snippet mainwindows/application/mainwindow.cpp 37
- \snippet mainwindows/application/mainwindow.cpp 39
-
- The \c writeSettings() function is called from \c closeEvent().
- Writing settings is similar to reading them, except simpler. The
- arguments to the QSettings constructor must be the same as in \c
- readSettings().
-
- \snippet mainwindows/application/mainwindow.cpp 40
- \snippet mainwindows/application/mainwindow.cpp 41
-
- The \c maybeSave() function is called to save pending changes. If
- there are pending changes, it pops up a QMessageBox giving the
- user to save the document. The options are QMessageBox::Yes,
- QMessageBox::No, and QMessageBox::Cancel. The \uicontrol{Yes} button is
- made the default button (the button that is invoked when the user
- presses \uicontrol{Return}) using the QMessageBox::Default flag; the
- \uicontrol{Cancel} button is made the escape button (the button that is
- invoked when the user presses \uicontrol{Esc}) using the
- QMessageBox::Escape flag.
-
- The \c maybeSave() function returns \c true in all cases, except
- when the user clicks \uicontrol{Cancel} or saving the file fails.
- The caller must check the return value and stop whatever it was
- doing if the return value is \c false.
-
- \snippet mainwindows/application/mainwindow.cpp 42
- \snippet mainwindows/application/mainwindow.cpp 43
-
- In \c loadFile(), we use QFile and QTextStream to read in the
- data. The QFile object provides access to the bytes stored in a
- file.
-
- We start by opening the file in read-only mode. The QFile::Text
- flag indicates that the file is a text file, not a binary file.
- On Unix and \macos, this makes no difference, but on Windows,
- it ensures that the "\\r\\n" end-of-line sequence is converted to
- "\\n" when reading.
-
- If we successfully opened the file, we use a QTextStream object
- to read in the data. QTextStream automatically converts the 8-bit
- data into a Unicode QString and supports various encodings. If no
- encoding is specified, QTextStream assumes the file is encoded in
- UTF-8.
-
- Since the call to QTextStream::readAll() might take some time, we
- set the cursor to be Qt::WaitCursor for the entire application
- while it goes on.
-
- At the end, we call the private \c setCurrentFile() function,
- which we'll cover in a moment, and we display the string "File
- loaded" in the status bar for 2 seconds (2000 milliseconds).
-
- \snippet mainwindows/application/mainwindow.cpp 44
- \snippet mainwindows/application/mainwindow.cpp 45
-
- Saving a file is similar to loading one. We use QSaveFile to ensure
- all data are safely written and existing files are not damaged
- should writing fail.
- We use the QFile::Text flag to make sure that on Windows, "\\n"
- is converted into "\\r\\n" to conform to the Windows convention.
-
-
- \snippet mainwindows/application/mainwindow.cpp 46
- \snippet mainwindows/application/mainwindow.cpp 47
-
- The \c setCurrentFile() function is called to reset the state of
- a few variables when a file is loaded or saved, or when the user
- starts editing a new file (in which case \c fileName is empty).
- We update the \c curFile variable, clear the
- QTextDocument::modified flag and the associated \c
- QWidget:windowModified flag, and update the window title to
- contain the new file name (or \c untitled.txt).
-
- The \c strippedName() function call around \c curFile in the
- QWidget::setWindowTitle() call shortens the file name to exclude
- the path. Here's the function:
-
- \snippet mainwindows/application/mainwindow.cpp 48
- \snippet mainwindows/application/mainwindow.cpp 49
-
- \section1 The main() Function
-
- The \c main() function for this application is typical of
- applications that contain one main window:
-
- \snippet mainwindows/application/main.cpp 0
-
- The main function uses QCommandLineParser to check whether some file
- argument was passed to the application and loads it via
- MainWindow::loadFile().
-
- \section1 The Resource File
-
- As you will probably recall, for some of the actions, we
- specified icons with file names starting with \c{:} and mentioned
- that such file names aren't ordinary file names, but path in the
- executable's stored resources. These resources are compiled
-
- The resources associated with an application are specified in a
- \c .qrc file, an XML-based file format that lists files on the
- disk. Here's the \c application.qrc file that's used by the
- Application example:
-
- \quotefile mainwindows/application/application.qrc
-
- The \c .png files listed in the \c application.qrc file are files
- that are part of the Application example's source tree. Paths are
- relative to the directory where the \c application.qrc file is
- located (the \c mainwindows/application directory).
-
- The resource file must be mentioned in the \c application.pro
- file so that \c qmake knows about it:
-
- \snippet mainwindows/application/application.pro 0
-
- \c qmake will produce make rules to generate a file called \c
- qrc_application.cpp that is linked into the application. This
- file contains all the data for the images and other resources as
- static C++ arrays of compressed binary data. See
- \l{resources.html}{The Qt Resource System} for more information
- about resources.
-*/
diff --git a/examples/widgets/doc/src/basicdrawing.qdoc b/examples/widgets/doc/src/basicdrawing.qdoc
index 7413dfc823..0882c0f32f 100644
--- a/examples/widgets/doc/src/basicdrawing.qdoc
+++ b/examples/widgets/doc/src/basicdrawing.qdoc
@@ -4,6 +4,7 @@
/*!
\example painting/basicdrawing
\title Basic Drawing Example
+ \examplecategory {Graphics}
\ingroup examples-painting
\brief The Basic Drawing example shows how to display basic
graphics primitives in a variety of styles using the QPainter
diff --git a/examples/widgets/doc/src/basicgraphicslayouts.qdoc b/examples/widgets/doc/src/basicgraphicslayouts.qdoc
index ce7176bf7f..1add587464 100644
--- a/examples/widgets/doc/src/basicgraphicslayouts.qdoc
+++ b/examples/widgets/doc/src/basicgraphicslayouts.qdoc
@@ -4,6 +4,7 @@
/*!
\example graphicsview/basicgraphicslayouts
\title Basic Graphics Layouts Example
+ \examplecategory {Graphics}
\ingroup examples-graphicsview-layout
\brief Demonstrates how to create basic graphics layout.
diff --git a/examples/widgets/doc/src/basiclayouts.qdoc b/examples/widgets/doc/src/basiclayouts.qdoc
index c55514689d..e6f1cab4d9 100644
--- a/examples/widgets/doc/src/basiclayouts.qdoc
+++ b/examples/widgets/doc/src/basiclayouts.qdoc
@@ -4,6 +4,7 @@
/*!
\example layouts/basiclayouts
\title Basic Layouts Example
+ \examplecategory {User Interface Components}
\brief Shows how to use the standard layout managers.
\e{Basic Layouts} shows how to use the standard layout managers that are
diff --git a/examples/widgets/doc/src/basicsortfiltermodel.qdoc b/examples/widgets/doc/src/basicsortfiltermodel.qdoc
index 969ee0a9d5..c0b8a5f426 100644
--- a/examples/widgets/doc/src/basicsortfiltermodel.qdoc
+++ b/examples/widgets/doc/src/basicsortfiltermodel.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/basicsortfiltermodel
\title Basic Sort/Filter Model Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief The Basic Sort/Filter Model example illustrates how to use
QSortFilterProxyModel to perform basic sorting and filtering.
diff --git a/examples/widgets/doc/src/blurpicker.qdoc b/examples/widgets/doc/src/blurpicker.qdoc
deleted file mode 100644
index 8c9458e51a..0000000000
--- a/examples/widgets/doc/src/blurpicker.qdoc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example effects/blurpicker
- \title Blur Picker Effect Example
- \ingroup examples-graphicsview-graphicseffects
- \brief Demonstrates how to apply graphical effects on items in the view.
-
- \image blurpickereffect-example.png
-
- The Blur Picker example displays a circle of application icons.
- All icons are blurred, except the one on the bottom left side of
- the screen, which is the one in focus.
- Clicking anywhere on the left side of the screen moves the icon
- circle clockwise to the next icon
- Clicking on the right side advances the circle counterclockwise.
-
- \sa QGraphicsBlurEffect
-*/
diff --git a/examples/widgets/doc/src/borderlayout.qdoc b/examples/widgets/doc/src/borderlayout.qdoc
deleted file mode 100644
index 9ec5e96d78..0000000000
--- a/examples/widgets/doc/src/borderlayout.qdoc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example layouts/borderlayout
- \title Border Layout Example
- \ingroup examples-layout
- \brief Shows how to arrange child widgets along a border.
-
- \e{Border Layout} implements a layout that arranges child widgets to
- surround the main area.
-
- \image borderlayout-example.png
-
- The constructor of the Window class creates a QTextBrowser object,
- to which a BorderLayout named \c layout is added. The declaration
- of the BorderLayout class is quoted at the end of this document.
-
- \quotefromfile layouts/borderlayout/window.cpp
- \skipto Window::Window()
- \printuntil BorderLayout
-
- Several labeled widgets are added to \c layout with the orientation
- \c {Center}, \c {North}, \c {West}, \c {East 1}, \c {East 2}, and
- \c {South}.
-
- \skipto layout->addWidget
- \printuntil setWindowTitle
-
- createLabel() in class \c Window sets the text of the labeled widgets
- and the style.
-
- \skipto QLabel *Window::createLabel
- \printuntil /^\}/
-
- Class BorderLayout contains all the utilitarian functions for formatting
- the widgets it contains.
-
- \quotefromfile layouts/borderlayout/borderlayout.h
- \skipto class
- \printuntil /^\}/
-
- For more information, visit the \l{Layout Management} page.
-
- \include examples-run.qdocinc
-*/
diff --git a/examples/widgets/doc/src/calculator.qdoc b/examples/widgets/doc/src/calculator.qdoc
index cc015e46a0..c59d3cd161 100644
--- a/examples/widgets/doc/src/calculator.qdoc
+++ b/examples/widgets/doc/src/calculator.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/calculator
\title Calculator Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\ingroup examples-layout
\brief The example shows how to use signals and slots to implement the
diff --git a/examples/widgets/doc/src/calendar.qdoc b/examples/widgets/doc/src/calendar.qdoc
deleted file mode 100644
index 218ea5ea0c..0000000000
--- a/examples/widgets/doc/src/calendar.qdoc
+++ /dev/null
@@ -1,202 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example richtext/calendar
- \title Calendar Example
- \ingroup examples-richtext
- \brief The Calendar example shows how to create rich text content
- and display it using a rich text editor.
-
- \brief The Calendar example shows how to create rich text content and display it using
- a rich text editor.
-
- \image calendar-example.png
-
- Specifically, the example demonstrates the following:
-
- \list
- \li Use of a text editor with a text document
- \li Insertion of tables and frames into a document
- \li Navigation within a table
- \li Insert text in different styles
- \endlist
-
- The rich text editor used to display the document is used within a main window
- application.
-
- \section1 MainWindow Class Definition
-
- The \c MainWindow class provides a text editor widget and some controls to
- allow the user to change the month and year shown. The font size used for the
- text can also be adjusted.
-
- \snippet richtext/calendar/mainwindow.h 0
-
- The private \c insertCalendar() function performs most of the work, relying on
- the \c fontSize and \c selectedDate variables to write useful information to
- the \c editor.
-
- \section1 MainWindow Class Implementation
-
- The \c MainWindow constructor sets up the user interface and initializes
- variables used to generate a calendar for each month.
-
- \snippet richtext/calendar/mainwindow.cpp 0
-
- We begin by setting default values for the selected date that will be highlighted
- in the calendar and the font size to be used. Since we are using a QMainWindow
- for the user interface, we construct a widget for use as the central widget.
-
- The user interface will include a line of controls above the generated calendar;
- we construct a label and a combobox to allow the month to be selected, and a
- spin box for the year. These widgets are configured to provide a reasonable range
- of values for the user to try:
-
- \snippet richtext/calendar/mainwindow.cpp 1
-
- We use the \c selectedDate object to obtain the current month and year, and we
- set these in the combobox and spin box:
-
- The font size is displayed in a spin box which we restrict to a sensible range
- of values:
-
- \snippet richtext/calendar/mainwindow.cpp 2
-
- We construct an editor and use the \c insertCalendar() function to create
- a calendar for it. Each calendar is displayed in the same text editor; in
- this example we use a QTextBrowser since we do not allow the calendar to be
- edited.
-
- The controls used to set the month, year, and font size will not have any
- effect on the appearance of the calendar unless we make some signal-slot
- connections:
-
- \snippet richtext/calendar/mainwindow.cpp 3
-
- The signals are connected to some simple slots in the \c MainWindow class
- which we will describe later.
-
- We create layouts to manage the widgets we constructed:
-
- \snippet richtext/calendar/mainwindow.cpp 4
-
- Finally, the central widget is set for the window.
-
- Each calendar is created for the editor by the \c insertCalendar() function
- which uses the date and font size, defined by the private \a selectedDate
- and \c fontSize variables, to produce a suitable plan for the specified
- month and year.
-
- \snippet richtext/calendar/mainwindow.cpp 5
-
- We begin by clearing the editor's rich text document, and obtain a text
- cursor from the editor that we will use to add content. We also create a
- QDate object based on the currently selected date.
-
- The calendar is made up of a table with a gray background color that contains
- seven columns: one for each day of the week. It is placed in the center of the
- page with equal space to the left and right of it. All of these properties are
- set in a QTextTableFormat object:
-
- \snippet richtext/calendar/mainwindow.cpp 6
-
- Each cell in the table will be padded and spaced to make the text easier to
- read.
-
- We want the columns to have equal widths, so we provide a list containing
- percentage widths for each of them and set the constraints in the
- QTextTableFormat:
-
- \snippet richtext/calendar/mainwindow.cpp 7
-
- The constraints used for the column widths are only useful if the table has
- an appropriate number of columns. With the format for the table defined, we
- construct a new table with one row and seven columns at the current cursor
- position:
-
- \snippet richtext/calendar/mainwindow.cpp 8
-
- We only need one row to start with; more can be added as we need them. Using
- this approach means that we do not need to perform any date calculations
- until we add cells to the table.
-
- When inserting objects into a document with the cursor's insertion functions,
- the cursor is automatically moved inside the newly inserted object. This means
- that we can immediately start modifying the table from within:
-
- \snippet richtext/calendar/mainwindow.cpp 9
-
- Since the table has an outer frame, we obtain the frame and its format so that
- we can customize it. After making the changes we want, we set the frame's format
- using the modified format object. We have given the table an outer border one
- pixel wide.
-
- \snippet richtext/calendar/mainwindow.cpp 10
-
- In a similar way, we obtain the cursor's current character format and
- create customized formats based on it.
-
- We do not set the format on the cursor because this would change the default
- character format; instead, we use the customized formats explicitly when we
- insert text. The following loop inserts the days of the week into the table
- as bold text:
-
- \snippet richtext/calendar/mainwindow.cpp 11
-
- For each day of the week, we obtain an existing table cell in the first row
- (row 0) using the table's \l{QTextTable::cellAt()}{cellAt()} function. Since
- we start counting the days of the week at day 1 (Monday), we subtract 1 from
- \c weekDay to ensure that we obtain the cell for the correct column of the
- table.
-
- Before text can be inserted into a cell, we must obtain a cursor with the
- correct position in the document. The cell provides a function for this
- purpose, and we use this cursor to insert text using the \c boldFormat
- character format that we created earlier:
-
- \snippet richtext/calendar/mainwindow.cpp 12
-
- Inserting text into document objects usually follows the same pattern.
- Each object can provide a new cursor that corresponds to the first valid
- position within itself, and this can be used to insert new content. We
- continue to use this pattern as we insert the days of the month into the
- table.
-
- Since every month has more than seven days, we insert a single row to begin
- and add days until we reach the end of the month. If the current date is
- encountered, it is inserted with a special format (created earlier) that
- makes it stand out:
-
- \snippet richtext/calendar/mainwindow.cpp 13
-
- We add a new row to the table at the end of each week only if the next week
- falls within the currently selected month.
-
- For each calendar that we create, we change the window title to reflect the
- currently selected month and year:
-
- \snippet richtext/calendar/mainwindow.cpp 14
-
- The \c insertCalendar() function relies on up-to-date values for the month,
- year, and font size. These are set in the following slots:
-
- \snippet richtext/calendar/mainwindow.cpp 15
-
- The \c setFontSize() function simply changes the private \c fontSize variable
- before updating the calendar.
-
- \snippet richtext/calendar/mainwindow.cpp 16
-
- The \c setMonth slot is called when the QComboBox used to select the month is
- updated. The value supplied is the currently selected row in the combobox.
- We add 1 to this value to obtain a valid month number, and create a new QDate
- based on the existing one. The calendar is then updated to use this new date.
-
- \snippet richtext/calendar/mainwindow.cpp 17
-
- The \c setYear() slot is called when the QDateTimeEdit used to select the
- year is updated. The value supplied is a QDate object; this makes
- the construction of a new value for \c selectedDate simple. We update the
- calendar afterwards to use this new date.
-*/
diff --git a/examples/widgets/doc/src/calendarwidget.qdoc b/examples/widgets/doc/src/calendarwidget.qdoc
index 6a91f5ef6e..01c6df6926 100644
--- a/examples/widgets/doc/src/calendarwidget.qdoc
+++ b/examples/widgets/doc/src/calendarwidget.qdoc
@@ -3,6 +3,7 @@
/*!
\title Calendar Widget Example
+ \examplecategory {User Interface Components}
\example widgets/calendarwidget
\ingroup examples-widgets
\ingroup examples-layout
diff --git a/examples/widgets/doc/src/charactermap.qdoc b/examples/widgets/doc/src/charactermap.qdoc
deleted file mode 100644
index ee6162302f..0000000000
--- a/examples/widgets/doc/src/charactermap.qdoc
+++ /dev/null
@@ -1,251 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
-\example widgets/charactermap
-\title Character Map Example
-\ingroup examples-widgets
-\brief The Character Map example shows how to create a custom widget that can
-both display its own content and respond to user input.
-
-The example displays an array of characters which the user can click on
-to enter text in a line edit. The contents of the line edit can then be
-copied into the clipboard, and pasted into other applications. The
-purpose behind this sort of tool is to allow users to enter characters
-that may be unavailable or difficult to locate on their keyboards.
-
-\borderedimage charactermap-example.png
-\caption Screenshot of the Character Map example
-
-The example consists of the following classes:
-
-\list
-\li \c CharacterWidget displays the available characters in the current
- font and style.
-\li \c MainWindow provides a standard main window that contains font and
- style information, a view onto the characters, a line edit, and a push
- button for submitting text to the clipboard.
-\endlist
-
-\section1 CharacterWidget Class Definition
-
-The \c CharacterWidget class is used to display an array of characters in
-a user-specified font and style. For flexibility, we subclass QWidget and
-reimplement only the functions that we need to provide basic rendering
-and interaction features.
-
-The class definition looks like this:
-
-\snippet widgets/charactermap/characterwidget.h 0
-
-The widget does not contain any other widgets, so it must provide its own
-size hint to allow its contents to be displayed correctly.
-We reimplement \l{QWidget::paintEvent()} to draw custom content. We also
-reimplement \l{QWidget::mousePressEvent()} to allow the user to interact
-with the widget.
-
-The updateFont() and updateStyle() slots are used to update the font and
-style of the characters in the widget whenever the user changes the
-settings in the application.
-The class defines the characterSelected() signal so that other parts
-of the application are informed whenever the user selects a character in
-the widget.
-As a courtesy, the widget provides a tooltip that shows the current
-character value. We reimplement the \l{QWidget::mouseMoveEvent()} event
-handler and define showToolTip() to enable this feature.
-
-The \c columns, \c displayFont and \c currentKey private data members
-are used to record the number of columns to be shown, the current font,
-and the currently highlighted character in the widget.
-
-\section1 CharacterWidget Class Implementation
-
-Since the widget is to be used as a simple canvas, the constructor just
-calls the base class constructor and defines some default values for
-private data members.
-
-\snippet widgets/charactermap/characterwidget.cpp 0
-
-We initialize \c currentKey with a value of -1 to indicate
-that no character is initially selected. We enable mouse tracking to
-allow us to follow the movement of the cursor across the widget.
-
-The class provides two functions to allow the font and style to be set up.
-Each of these modify the widget's display font and call update():
-
-\snippet widgets/charactermap/characterwidget.cpp 1
-\codeline
-\snippet widgets/charactermap/characterwidget.cpp 2
-
-We use a fixed size font for the display. Similarly, a fixed size hint is
-provided by the sizeHint() function:
-
-\snippet widgets/charactermap/characterwidget.cpp 3
-
-Three standard event functions are implemented so that the widget
-can respond to clicks, provide tooltips, and render the available
-characters. The paintEvent() shows how the contents of the widget are
-arranged and displayed:
-
-\snippet widgets/charactermap/characterwidget.cpp 6
-
-A QPainter is created for the widget and, in all cases, we ensure that the
-widget's background is painted. The painter's font is set to the
-user-specified display font.
-
-The area of the widget that needs to be redrawn is used to determine which
-characters need to be displayed:
-
-\snippet widgets/charactermap/characterwidget.cpp 7
-
-Using integer division, we obtain the row and column numbers of each
-characters that should be displayed, and we draw a square on the widget
-for each character displayed.
-
-\snippet widgets/charactermap/characterwidget.cpp 8
-\snippet widgets/charactermap/characterwidget.cpp 9
-
-The symbols for each character in the array are drawn within each square,
-with the symbol for the most recently selected character displayed in red:
-
-\snippet widgets/charactermap/characterwidget.cpp 10
-
-We do not need to take into account the difference between the area
-displayed in the viewport and the area we are drawing on because
-everything outside the visible area will be clipped.
-
-The mousePressEvent() defines how the widget responds to mouse clicks.
-
-\snippet widgets/charactermap/characterwidget.cpp 5
-
-We are only interested when the user clicks with the left mouse button
-over the widget. When this happens, we calculate which character was
-selected and emit the characterSelected() signal.
-The character's number is found by dividing the x and y-coordinates of
-the click by the size of each character's grid square. Since the number
-of columns in the widget is defined by the \c columns variable, we
-simply multiply the row index by that value and add the column number
-to obtain the character number.
-
-If any other mouse button is pressed, the event is passed on to the
-QWidget base class. This ensures that the event can be handled properly
-by any other interested widgets.
-
-The mouseMoveEvent() maps the mouse cursor's position in global
-coordinates to widget coordinates, and determines the character that
-was clicked by performing the calculation
-
-\snippet widgets/charactermap/characterwidget.cpp 4
-
-The tooltip is given a position defined in global coordinates.
-
-\section1 MainWindow Class Definition
-
-The \c MainWindow class provides a minimal user interface for the example,
-with only a constructor, slots that respond to signals emitted by standard
-widgets, and some convenience functions that are used to set up the user
-interface.
-
-The class definition looks like this:
-
-\snippet widgets/charactermap/mainwindow.h 0
-
-The main window contains various widgets that are used to control how
-the characters will be displayed, and defines the findFonts() function
-for clarity and convenience. The findStyles() slot is used by the widgets
-to determine the styles that are available, insertCharacter() inserts
-a user-selected character into the window's line edit, and
-updateClipboard() synchronizes the clipboard with the contents of the
-line edit.
-
-\section1 MainWindow Class Implementation
-
-In the constructor, we set up the window's central widget and fill it with
-some standard widgets (two comboboxes, a line edit, and a push button).
-We also construct a CharacterWidget custom widget, and add a QScrollArea
-so that we can view its contents:
-
-\snippet widgets/charactermap/mainwindow.cpp 0
-
-QScrollArea provides a viewport onto the \c CharacterWidget when we set
-its widget and handles much of the work needed to provide a scrolling
-viewport.
-
-The font combo box is automatically populated with a list of available
-fonts. We list the available styles for the current font in the style
-combobox using the following function:
-
-\snippet widgets/charactermap/mainwindow.cpp 1
-
-The line edit and push button are used to supply text to the clipboard:
-
-\snippet widgets/charactermap/mainwindow.cpp 2
-
-We also obtain a clipboard object so that we can send text entered by the
-user to other applications.
-
-Most of the signals emitted in the example come from standard widgets.
-We connect these signals to slots in this class, and to the slots provided
-by other widgets.
-
-\snippet widgets/charactermap/mainwindow.cpp 4
-
-The font combobox's
-\l{QFontComboBox::currentFontChanged()}{currentFontChanged()} signal is
-connected to the findStyles() function so that the list of available styles
-can be shown for each font that is used. Since both the font and the style
-can be changed by the user, the font combobox's currentFontChanged() signal
-and the style combobox's
-\l{QComboBox::currentIndexChanged()}{currentIndexChanged()} are connected
-directly to the character widget.
-
-The final two connections allow characters to be selected in the character
-widget, and text to be inserted into the clipboard:
-
-\snippet widgets/charactermap/mainwindow.cpp 5
-
-The character widget emits the characterSelected() custom signal when
-the user clicks on a character, and this is handled by the insertCharacter()
-function in this class. The clipboard is changed when the push button emits
-the clicked() signal, and we handle this with the updateClipboard() function.
-
-The remaining code in the constructor sets up the layout of the central widget,
-and provides a window title:
-
-\snippet widgets/charactermap/mainwindow.cpp 6
-
-The font combobox is automatically populated with a list of available font
-families. The styles that can be used with each font are found by the
-findStyles() function. This function is called whenever the user selects a
-different font in the font combobox.
-
-\snippet widgets/charactermap/mainwindow.cpp 7
-
-We begin by recording the currently selected style, and we clear the
-style combobox so that we can insert the styles associated with the
-current font family.
-
-\snippet widgets/charactermap/mainwindow.cpp 8
-
-We use the font database to collect the styles that are available for the
-current font, and insert them into the style combobox. The current item is
-reset if the original style is not available for this font.
-
-The last two functions are slots that respond to signals from the character
-widget and the main window's push button. The insertCharacter() function is
-used to insert characters from the character widget when the user clicks a
-character:
-
-\snippet widgets/charactermap/mainwindow.cpp 9
-
-The character is inserted into the line edit at the current cursor position.
-
-The main window's "To clipboard" push button is connected to the
-updateClipboard() function so that, when it is clicked, the clipboard is
-updated to contain the contents of the line edit:
-
-\snippet widgets/charactermap/mainwindow.cpp 10
-
-We copy all the text from the line edit to the clipboard, but we do not clear
-the line edit.
-*/
diff --git a/examples/widgets/doc/src/chart.qdoc b/examples/widgets/doc/src/chart.qdoc
deleted file mode 100644
index abb1b3ab7e..0000000000
--- a/examples/widgets/doc/src/chart.qdoc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/chart
- \title Chart Example
- \ingroup examples-itemviews
- \brief The Chart example shows how to create a custom view for the model/view framework.
-
- \image chart-example.png
-
- In this example, the items in a table model are represented as slices in a pie chart,
- relying on the flexibility of the model/view architecture to handle custom editing
- and selection features.
-
- \b{Note that you only need to create a new view class if your data requires a
- specialized representation.} You should first consider using a standard QListView,
- QTableView, or QTreeView with a custom QItemDelegate subclass if you need to
- represent data in a special way.
-
- \omit
- \section1 PieView Class Definition
-
- The \c PieView class is a subclass of QAbstractItemView. The base class provides
- much of the functionality required by view classes, so we only need to provide
- implementations for three public functions: visualRect(), scrollTo(), and
- indexAt(). However, the view needs to maintain strict control over its look and
- feel, so we also provide implementations for a number of other functions:
-
- \snippet itemviews/chart/pieview.h 0
-
-
-
- \section1 PieView Class Implementation
-
- The paint event renders the data from the standard item model as a pie chart.
- We interpret the data in the following way:
-
- \list
- \li Column 0 contains data in two different roles:
- The \l{Qt::ItemDataRole}{DisplayRole} contains a label, and the
- \l{Qt::ItemDataRole}{DecorationRole} contains the color of the pie slice.
- \li Column 1 contains a quantity which we will convert to the angular extent of
- the slice.
- \endlist
-
- The figure is always drawn with the chart on the left and the key on
- the right. This means that we must try and obtain an area that is wider
- than it is tall. We do this by imposing a particular aspect ratio on
- the chart and applying it to the available vertical space. This ensures
- that we always obtain the maximum horizontal space for the aspect ratio
- used.
- We also apply fixed size margin around the figure.
-
- We use logical coordinates to draw the chart and key, and position them
- on the view using viewports.
- \endomit
-*/
diff --git a/examples/widgets/doc/src/chip.qdoc b/examples/widgets/doc/src/chip.qdoc
index a76e11950e..2c69c10f39 100644
--- a/examples/widgets/doc/src/chip.qdoc
+++ b/examples/widgets/doc/src/chip.qdoc
@@ -4,6 +4,7 @@
/*!
\example graphicsview/chip
\title 40000 Chips
+ \examplecategory {Graphics}
\ingroup examples-graphicsview
\brief Visualizes a huge graphic view scene with 40000 chip items.
diff --git a/examples/widgets/doc/src/collidingmice-example.qdoc b/examples/widgets/doc/src/collidingmice-example.qdoc
index 4f6859406e..a1b8e0e141 100644
--- a/examples/widgets/doc/src/collidingmice-example.qdoc
+++ b/examples/widgets/doc/src/collidingmice-example.qdoc
@@ -4,6 +4,7 @@
/*!
\example graphicsview/collidingmice
\title Colliding Mice Example
+ \examplecategory {Graphics}
\brief Demonstrates how to animate items on a graphics view.
\ingroup examples-graphicsview
diff --git a/examples/widgets/doc/src/coloreditorfactory.qdoc b/examples/widgets/doc/src/coloreditorfactory.qdoc
deleted file mode 100644
index a7da4d6847..0000000000
--- a/examples/widgets/doc/src/coloreditorfactory.qdoc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/coloreditorfactory
- \title Color Editor Factory Example
- \ingroup examples-itemviews
- \brief This example shows how to create an editor that can be used by
- a QItemDelegate.
-
- \image coloreditorfactoryimage.png
-
- When editing data in a QListView, QTableView, or QTreeView,
- editors are created and displayed by a \l{Delegate
- Classes}{delegate}. QItemDelegate, which is the default delegate
- used by Qt's \l{View Classes}{item views}, uses a
- QItemEditorFactory to create editors for it. A unique instance
- provided by QItemEditorFactory is by default installed on all
- item delegates.
-
- An item editor factory contains a collection of
- QItemEditorCreatorBase instances, which are specialized factories
- that produce editors for one particular QVariant data type (all
- models in Qt store their data in \l{QVariant}s). An editor can be any
- Qt or custom widget.
-
- In this example, we will create an editor (implemented in the \c
- ColorListEditor class) that can edit the QColor data type and be
- used by \l{QItemDelegate}s. We do this by creating a new
- QItemEditorCreatorBase that produces \c ColorListEditors and
- register it with a new factory, which we set as the default editor
- item factory (the unique factory instance). To test our editor, we
- have implemented the \c Window class, which displays a
- QTableWidget in which \l{QColor}s can be edited.
-
- \section1 Window Class Implementation
-
- In the Window class, we create the item editor creator
- base for our color editor and add it to the default factory.
- We also create a QTableWidget in which our editor can be
- tested. It is filled with some data and displayed in a window.
-
- We take a closer look at the constructor:
-
- \snippet itemviews/coloreditorfactory/window.cpp 0
-
- The QStandardItemEditorCreator is a convenience class that
- inherits QItemEditorCreatorBase. Its constructor takes a template
- class, of which instances are returned from
- \l{QItemEditorCreatorBase::}{createWidget()}. The creator uses a
- constructor that takes a QWidget as its only parameter; the
- template class must provide this. This way, there is no need to
- subclass QStandardItemEditorCreator.
-
- After the new factory has been set, all standard item delegates
- will use it (i.e, also delegates that were created before the new
- default factory was set).
-
- The \c createGUI() function sets up the table and fills it
- with data.
-
- \section1 ColorListEditor Definition
-
- The ColorListEditor inherits QComboBox and lets the user
- select a QColor from its popup list.
-
- \snippet itemviews/coloreditorfactory/colorlisteditor.h 0
-
- QItemDelegate manages the interaction between the editor and
- the model, i.e., it retrieves data to edit from the model and
- store data from the editor in the model. The data that is edited
- by an editor is stored in the editor's user data property, and the
- delegate uses Qt's \l{Qt's Property System}{property system} to
- access it by name. We declare our user data property with the
- Q_PROPERTY macro. The property is set to be the user type with the
- USER keyword.
-
- \section1 ColorListEditor Implementation
-
- The constructor of \c ColorListEditor simply calls \c
- populateList(), which we will look at later. We move on to the
- \c color() function:
-
- \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 0
-
- We return the data that is selected in the combobox. The data
- is stored in the Qt::DecorationRole as the color is then also
- displayed in the popup list (as shown in the image above).
-
- \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 1
-
- The \c findData() function searches the items in the combobox
- and returns the index of the item that has \c color in the
- Qt::Decoration role.
-
- \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 2
-
- Qt knows some predefined colors by name. We simply loop
- through these to fill our editor with items.
-
- \section1 Further Customization of Item View Editors
-
- You can customize Qt's \l{Model/View Programming}{model view
- framework} in many ways. The procedure shown in this example is
- usually sufficient to provide custom editors. Further
- customization is achieved by subclassing QItemEditorFactory
- and QItemEditorCreatorBase. It is also possible to subclass
- QItemDelegate if you don't wish to use a factory at all.
-
- Possible suggestions are:
-
- \list
- \li If the editor widget has no user property defined, the delegate
- asks the factory for the property name, which it in turn
- asks the item editor creator for. In this case, you can use
- the QItemEditorCreator class, which takes the property
- name to use for editing as a constructor argument.
- \li If the editor requires other constructors or other
- initialization than provided by QItemEditorCreatorBase, you
- must reimplement
- QItemEditorCreatorBase::createWidget().
- \li You could also subclass QItemEditorFactory if you only want
- to provide editors for certain kinds of data or use another
- method of creating the editors than using creator bases.
- \endlist
-
- In this example, we use a standard QVariant data type. You can
- also use custom types. In the \l{Star Delegate Example}, we
- show how to store a custom data type in a QVariant and paint
- and edit it in a class that inherits QItemDelegate.
-*/
diff --git a/examples/widgets/doc/src/combowidgetmapper.qdoc b/examples/widgets/doc/src/combowidgetmapper.qdoc
index 2f53bfd11b..aae546005c 100644
--- a/examples/widgets/doc/src/combowidgetmapper.qdoc
+++ b/examples/widgets/doc/src/combowidgetmapper.qdoc
@@ -4,20 +4,14 @@
/*!
\example itemviews/combowidgetmapper
\title Combo Widget Mapper Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief The Combo Widget Mapper example shows how to use a custom delegate to
map information from a model to specific widgets on a form.
\image combowidgetmapper-example.png
- In the \l{Simple Widget Mapper Example}, we showed the basic use of a
- widget mapper to relate data exposed by a model to simple input widgets
- in a user interface. However, sometimes we want to use input widgets that
- expose data as choices to the user, such as QComboBox, and we need a way
- to relate their input to the values stored in the model.
-
- This example is very similar to the \l{Simple Widget Mapper Example}.
- Again, we create a \c Window class with an almost identical user interface,
+ We create a \c Window class with an almost identical user interface,
except that, instead of providing a spin box so that each person's age
can be entered, we provide a combo box to allow their addresses to be
classified as "Home", "Work" or "Other".
@@ -65,8 +59,7 @@
interfering with the other input widgets. The implementation is shown later.
\endomit
- The rest of the constructor is very similar to that of the
- \l{Simple Widget Mapper Example}:
+ The rest of the constructor sets up connections and layouts:
\snippet itemviews/combowidgetmapper/window.cpp Set up connections and layouts
@@ -95,7 +88,7 @@
\section1 Delegate Class Definition and Implementation
The delegate we use to mediate interaction between the widget mapper and
- the input widgets is a small QItemDelegate subclass:
+ the input widgets is a small QStyledItemDelegate subclass:
\snippet itemviews/combowidgetmapper/delegate.h Delegate class definition
@@ -106,7 +99,7 @@
Since we only provide an empty implementation of the constructor, we
concentrate on the other two functions.
- The \l{QItemDelegate::}{setEditorData()} implementation takes the data
+ The \l{QStyledItemDelegate::}{setEditorData()} implementation takes the data
referred to by the model index supplied and processes it according to
the presence of a \c currentIndex property in the editor widget:
@@ -118,10 +111,10 @@
values needed for the \c currentIndex property.
As a result, instead of showing "0", "1" or "2" in the combo box, one of
- its predefined set of items is shown. We call QItemDelegate::setEditorData()
+ its predefined set of items is shown. We call QStyledItemDelegate::setEditorData()
for widgets without the \c currentIndex property.
- The \l{QItemDelegate::}{setModelData()} implementation performs the reverse
+ The \l{QStyledItemDelegate::}{setModelData()} implementation performs the reverse
process, taking the value stored in the widget's \c currentIndex property
and storing it back in the model:
diff --git a/examples/widgets/doc/src/completer.qdoc b/examples/widgets/doc/src/completer.qdoc
index a64d7e1e79..f3e4fe8f0e 100644
--- a/examples/widgets/doc/src/completer.qdoc
+++ b/examples/widgets/doc/src/completer.qdoc
@@ -4,6 +4,7 @@
/*!
\example tools/completer
\title Completer Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets-tools
\brief The Completer example shows how to provide string-completion facilities
@@ -45,7 +46,7 @@
\snippet tools/completer/fsmodel.cpp 0
As mentioned earlier, the \c data() function is reimplemented in order to
- get it to return the entire file parth for the display role. For example,
+ get it to return the entire file path for the display role. For example,
with a QFileSystemModel, you will see "Program Files" in the view. However, with
\c FileSystemModel, you will see "C:\\Program Files".
@@ -201,7 +202,7 @@
\snippet tools/completer/mainwindow.cpp 14
- The \c changeMaxVisible() update the maximum number of visible items in
+ The \c changeMaxVisible() updates the maximum number of visible items in
the completer.
\snippet tools/completer/mainwindow.cpp 15
diff --git a/examples/widgets/doc/src/composition.qdoc b/examples/widgets/doc/src/composition.qdoc
index 99fc066110..a8adcd2549 100644
--- a/examples/widgets/doc/src/composition.qdoc
+++ b/examples/widgets/doc/src/composition.qdoc
@@ -4,6 +4,7 @@
/*!
\example painting/composition
\title Composition Modes
+ \examplecategory {Graphics}
\ingroup examples-painting
\brief Demonstrates how Composition Modes work in QPainter.
@@ -18,5 +19,5 @@
drawn on top of the destination.
In addition to these standard modes, Qt defines the complete set of composition modes
- as defined by X. Porter and Y. Duff. See the QPainter documentation for details.
+ as defined by T. Porter and T. Duff. See the QPainter documentation for details.
*/
diff --git a/examples/widgets/doc/src/concentriccircles.qdoc b/examples/widgets/doc/src/concentriccircles.qdoc
deleted file mode 100644
index ffdb09869f..0000000000
--- a/examples/widgets/doc/src/concentriccircles.qdoc
+++ /dev/null
@@ -1,209 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example painting/concentriccircles
- \title Concentric Circles Example
- \ingroup examples-painting
- \brief Demonstrates the improved quality that antialiasing and floating point precision gives.
-
- \brief The Concentric Circles example shows the improved rendering
- quality that can be obtained using floating point precision and
- anti-aliasing when drawing custom widgets. The example also shows
- how to do simple animations.
-
- The application's main window displays several widgets which are
- drawn using the various combinations of precision and
- anti-aliasing.
-
- \image concentriccircles-example.png
-
- Anti-aliasing is one of QPainter's render hints. The
- QPainter::RenderHints are used to specify flags to QPainter that
- may, or may not, be respected by any given
- engine. QPainter::Antialiasing indicates that the engine should
- anti-alias the edges of primitives if possible, i.e. put
- additional pixels around the original ones to smooth the edges.
-
- The difference between floating point precision and integer
- precision is a matter of accuracy, and is visible in the
- application's main window: Even though the logic that is
- calculating the circles' geometry is the same, floating points
- ensure that the white spaces between each circle are of the same
- size, while integers make two and two circles appear as if they
- belong together. The reason is that the integer based precision
- rely on rounding off non-integer calculations.
-
- The example consists of two classes:
-
- \list
- \li \c CircleWidget is a custom widget which renders several animated
- concentric circles.
- \li \c Window is the application's main window displaying four \c
- {CircleWidget}s drawn using different combinations of precision
- and aliasing.
- \endlist
-
- First we will review the CircleWidget class, then we will take a
- look at the Window class.
-
- \section1 CircleWidget Class Definition
-
- The CircleWidget class inherits QWidget, and is a custom widget
- which renders several animated concentric circles.
-
- \snippet painting/concentriccircles/circlewidget.h 0
-
- We declare the \c floatBased and \c antialiased variables to hold
- whether an instance of the class should be rendered with integer
- or float based precision, and whether the rendering should be
- anti-aliased or not. We also declare functions setting each of
- these variables.
-
- In addition we reimplement the QWidget::paintEvent() function to
- apply the various combinations of precision and anti-aliasing when
- rendering, and to support the animation. We reimplement the
- QWidget::minimumSizeHint() and QWidget::sizeHint() functions to
- give the widget a reasonable size within our application.
-
- We declare the private \c nextAnimationFrame() slot, and the
- associated \c frameNo variable holding the number of "animation
- frames" for the widget, to facilitate the animation.
-
- \section1 CircleWidget Class Implementation
-
- In the constructor we make the widget's rendering integer based
- and aliased by default:
-
- \snippet painting/concentriccircles/circlewidget.cpp 0
-
- We initialize the widget's \c frameNo variable, and set the
- widget's background color using the QWidget::setBackgroundColor()
- function which takes a \l {QPalette::ColorRole}{color role} as
- argument; the QPalette::Base color role is typically white.
-
- Then we set the widgets size policy using the
- QWidget::setSizePolicy() function. QSizePolicy::Expanding means
- that the widget's \l {QWidget::sizeHint()}{sizeHint()} is a
- sensible size, but that the widget can be shrunk and still be
- useful. The widget can also make use of extra space, so it should
- get as much space as possible.
-
- \snippet painting/concentriccircles/circlewidget.cpp 1
- \codeline
- \snippet painting/concentriccircles/circlewidget.cpp 2
-
- The public \c setFloatBased() and \c setAntialiased() functions
- update the widget's rendering preferences, i.e. whether the widget
- should be rendered with integer or float based precision, and
- whether the rendering should be anti-aliased or not.
-
- The functions also generate a paint event by calling the
- QWidget::update() function, forcing a repaint of the widget with
- the new rendering preferences.
-
- \snippet painting/concentriccircles/circlewidget.cpp 3
- \codeline
- \snippet painting/concentriccircles/circlewidget.cpp 4
-
- The default implementations of the QWidget::minimumSizeHint() and
- QWidget::sizeHint() functions return invalid sizes if there is no
- layout for the widget, otherwise they return the layout's minimum and
- preferred size, respectively.
-
- We reimplement the functions to give the widget minimum and
- preferred sizes which are reasonable within our application.
-
- \snippet painting/concentriccircles/circlewidget.cpp 5
-
- The nextAnimationFrame() slot simply increments the \c frameNo
- variable's value, and calls the QWidget::update() function which
- schedules a paint event for processing when Qt returns to the main
- event loop.
-
- \snippet painting/concentriccircles/circlewidget.cpp 6
-
- A paint event is a request to repaint all or part of the
- widget. The \c paintEvent() function is an event handler that can
- be reimplemented to receive the widget's paint events. We
- reimplement the event handler to apply the various combinations of
- precision and anti-aliasing when rendering the widget, and to
- support the animation.
-
- First, we create a QPainter for the widget, and set its
- antialiased flag to the widget's preferred aliasing. We also
- translate the painters coordinate system, preparing to draw the
- widget's cocentric circles. The translation ensures that the
- center of the circles will be equivalent to the widget's center.
-
- \snippet painting/concentriccircles/circlewidget.cpp 7
-
- When painting a circle, we use the number of "animation frames" to
- determine the alpha channel of the circle's color. The alpha
- channel specifies the color's transparency effect, 0 represents a
- fully transparent color, while 255 represents a fully opaque
- color.
-
- \snippet painting/concentriccircles/circlewidget.cpp 8
-
- If the calculated alpha channel is fully transparent, we don't
- draw anything since that would be equivalent to drawing a white
- circle on a white background. Instead we skip to the next circle
- still creating a white space. If the calculated alpha channel is
- fully opaque, we set the pen (the QColor passed to the QPen
- constructor is converted into the required QBrush by default) and
- draw the circle. If the widget's preferred precision is float
- based, we specify the circle's bounding rectangle using QRectF and
- double values, otherwise we use QRect and integers.
-
- The animation is controlled by the public \c nextAnimationFrame()
- slot: Whenever the \c nextAnimationFrame() slot is called the
- number of frames is incremented and a paint event is
- scheduled. Then, when the widget is repainted, the alpha-blending
- of the circles' colors change and the circles appear as animated.
-
- \section1 Window Class Definition
-
- The Window class inherits QWidget, and is the application's main
- window rendering four \c {CircleWidget}s using different
- combinations of precision and aliasing.
-
- \snippet painting/concentriccircles/window.h 0
-
- We declare the various components of the main window, i.e., the text
- labels and a double array that will hold reference to the four \c
- {CircleWidget}s. In addition we declare the private \c
- createLabel() function to simplify the constructor.
-
- \section1 Window Class Implementation
-
- \snippet painting/concentriccircles/window.cpp 0
-
- In the constructor, we first create the various labels and put
- them in a QGridLayout.
-
- \snippet painting/concentriccircles/window.cpp 1
-
- Then we create a QTimer. The QTimer class is a high-level
- programming interface for timers, and provides repetitive and
- single-shot timers.
-
- We create a timer to facilitate the animation of our concentric
- circles; when we create the four CircleWidget instances (and add
- them to the layout), we connect the QTimer::timeout() signal to
- each of the widgets' \c nextAnimationFrame() slots.
-
- \snippet painting/concentriccircles/window.cpp 2
-
- Before we set the layout and window title for our main window, we
- make the timer start with a timeout interval of 100 milliseconds,
- using the QTimer::start() function. That means that the
- QTimer::timeout() signal will be emitted, forcing a repaint of the
- four \c {CircleWidget}s, every 100 millisecond which is the reason
- the circles appear as animated.
-
- \snippet painting/concentriccircles/window.cpp 3
-
- The private \c createLabel() function is implemented to simlify
- the constructor.
-*/
diff --git a/examples/widgets/doc/src/cuberhiwidget.qdoc b/examples/widgets/doc/src/cuberhiwidget.qdoc
new file mode 100644
index 0000000000..d40459ecf1
--- /dev/null
+++ b/examples/widgets/doc/src/cuberhiwidget.qdoc
@@ -0,0 +1,170 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example rhi/cuberhiwidget
+ \title Cube RHI Widget Example
+ \examplecategory {Graphics}
+ \ingroup examples-widgets
+ \brief Shows how to render a textured cube and integrate with QPainter and widgets, using QRhi Qt's 3D API and shading language abstraction layer.
+
+ \image cuberhiwidget-example.jpg
+ \caption Screenshot of the Cube RHI Widget example
+
+ This example builds on the \l{Simple RHI Widget Example}. While the simple
+ example is intentionally minimal and as compact as possible, rendering only
+ a single triangle with no additional widgets in the window, this
+ application demonstrates:
+
+ \list
+
+ \li Having various widgets in the window, some of them controlling data
+ that is consumed by the QRhiWidget subclass.
+
+ \li Instead of continuously requesting updates, the QRhiWidget here only
+ updates the content in its backing texture when some related data changes.
+
+ \li The cube is textured using a \l QRhiTexture that sources its content
+ from a \l QImage that contains software-based rendering performed with
+ \l QPainter.
+
+ \li The contents of the QRhiWidget \l{QRhiWidget::grab()}{can be
+ read back} and saved to an image file (e.g. a PNG file).
+
+ \li 4x multisample antialiasing \l{QRhiWidget::sampleCount()}{can be toggled}
+ at run time. The QRhiWidget subclass is prepared to handle the changing
+ sample count correctly.
+
+ \li Forcing an \l{QRhiWidget::explicitSize}{explicitly specified backing
+ texture size} can be toggled dynamically and controlled with a slider
+ between 16x16 up to 512x512 pixels.
+
+ \li The QRhiWidget subclass deals with a changing \l QRhi correctly. This
+ can be seen in action when making the widget top-level (no parent; becomes
+ a separate window) and then reparenting it again into the main window's
+ child hierarchy.
+
+ \li Most importantly, some widgets, with semi-transparency even, can be
+ placed on top of the QRhiWidget, proving that correct stacking and blending
+ is feasible. This is a case where QRhiWidget is superior to embedding a
+ native window, i.e. a QRhi-based QWindow using
+ QWidget::createWindowContainer(), because it allows stacking and clipping
+ the same way as any ordinary, software-rendered QWidget, whereas native
+ window embedding may, depending on the platform, have various limitations,
+ e.g. often it can be difficult or inefficient to place additional controls
+ on top.
+
+ \endlist
+
+ In the reimplementation of \l{QRhiWidget::initialize()}{initialize()}, the
+ first thing to do is to check if the QRhi we last worked with is still
+ up-to-date, and if the sample count (for multisample antialiasing) has
+ changed. The former is important because all graphics resources must be
+ released when the QRhi changes, whereas with a dynamically changing sample
+ count a similar problem arises specifically for QRhiGraphicsPipeline
+ objects as those bake the sample count in. For simplicity, the application
+ handles all such changes the same way, by resetting its \c scene struct to
+ a default constructed one, which conveniently drops all graphics resources.
+ All resources are then recreated.
+
+ When the backing texture size (so the render target size) changes, no
+ special action is needed, but a signal is emitted for convenience, just so
+ that main() can reposition the overlay label. The 3D API name is also
+ exposed via a signal by querying \l QRhi::backendName() whenever the QRhi
+ changes.
+
+ The implementation has to be aware that multisample antialiasing implies
+ that \l{QRhiWidget::colorTexture()}{colorTexture()} is \nullptr, while
+ \l{QRhiWidget::msaaColorBuffer()}{msaaColorBuffer()} is valid. This is
+ the opposite of when MSAA is not in use. The reason for differentiating
+ and using different types (QRhiTexture, QRhiRenderBuffer) is to allow
+ using MSAA with 3D graphics APIs that do not have support for
+ multisample textures, but have support for multisample renderbuffers.
+ An example of this is OpenGL ES 3.0.
+
+ When checking the up-to-date pixel size and sample count, a convenient and
+ compact solution is to query via the QRhiRenderTarget, because this way one
+ does not need to check which of colorTexture() and msaaColorBuffer() are
+ valid.
+
+ \snippet rhi/cuberhiwidget/examplewidget.cpp init-1
+
+ The rest is quite self-explanatory. The buffers and pipelines are
+ (re)created, if necessary. The contents of the texture that is used to
+ texture the cube mesh is updated. The scene is rendered using a perspective
+ projection. The view is just a simple translation for now.
+
+ \snippet rhi/cuberhiwidget/examplewidget.cpp init-2
+
+ The function that performs the actual enqueuing of the uniform buffer write
+ is also taking the user-provided rotation into account, thus generating the
+ final modelview-projection matrix.
+
+ \snippet rhi/cuberhiwidget/examplewidget.cpp rotation-update
+
+ Updating the \l QRhiTexture that is sampled in the fragment shader when
+ rendering the cube, is quite simple, even though a lot is happening in
+ there: first a QPainter-based drawing is generated within a QImage. This
+ uses the user-provided text. Then the CPU-side pixel data is uploaded to a
+ texture (more precisely, the upload operation is recorded on a \l
+ QRhiResourceUpdateBatch, which is then submitted later in render()).
+
+ \snippet rhi/cuberhiwidget/examplewidget.cpp texture-update
+
+ The graphics resource initialization is simple. There is only a vertex
+ buffer, no index buffer, and a uniform buffer with only a 4x4 matrix in it
+ (16 floats).
+
+ The texture that contains the QPainter-generated drawing has a size of
+ 512x512. Note that all sizes (texture sizes, viewports, scissors, texture
+ upload regions, etc.) are always in pixels when working with QRhi. To
+ sample this texture in the shader, a \l{QRhiSampler}{sampler object} is
+ needed (irrespective of the fact that QRhi-based applications will
+ typically use combined image samplers in the GLSL shader code, which then
+ may be transpiled to separate texture and sampler objects with some shading
+ languages, or may stay a combined texture-sampler object with others,
+ meaning there may not actually be a native sampler object under the hood at
+ run time, depending on the 3D API, but this is all transparent to the
+ application)
+
+ The vertex shader reads from the uniform buffer at binding point 0,
+ therefore
+ \c{scene.ubuf} is exposed at that binding location. The fragment shader
+ samples a texture provided at binding point 1,
+ therefore a combined texture-sampler pair is specified for that binding location.
+
+ The QRhiGraphicsPipeline enables depth test/write, and culls backfaces. It
+ also relies on a number of defaults, e.g. the depth comparison function
+ defaults to \c Less, which is fine for us, and the front face mode is
+ counter-clockwise, which is also good as-is so does not need to be set
+ again.
+
+ \snippet rhi/cuberhiwidget/examplewidget.cpp setup-scene
+
+ In the reimplementation of \l{QRhiWidget::render()}{render()}, first the
+ user-provided data is checked. If the \l QSlider controlling the rotation
+ has provided a new value, or the \l QTextEdit with the cube text has
+ changed its text, the graphics resources the contents of which depend on
+ such data get updated.
+
+ Then, a single render pass with a single draw call is recorded. The cube
+ mesh data is provided in a non-interleaved format, hence the need for two
+ vertex input bindings, one is the positions (x, y, z) the other is the UVs
+ (u, v), with a start offset that corresponds to 36 x-y-z float pairs.
+
+ \snippet rhi/cuberhiwidget/examplewidget.cpp render
+
+ How is the user-provided data sent? Take the rotation for example. main()
+ connects to the QSlider's \l{QSlider::valueChanged}{valueChanged} signal.
+ When emitted, the connected lamda calls setCubeRotation() on the
+ ExampleRhiWidget. Here, if the value is different from before, it is
+ stored, and a dirty flag is set. Then, most importantly,
+ \l{QWidget::update()}{update()} is called on the ExampleRhiWidget. This is
+ what triggers rendering a new frame into the QRhiWidget's backing texture.
+ Without this the content of the ExampleRhiWidget would not update when
+ dragging the slider.
+
+ \snippet rhi/cuberhiwidget/examplewidget.h data-setters
+
+ \sa QRhi, {Simple RHI Widget Example}, {RHI Window Example}
+*/
diff --git a/examples/widgets/doc/src/customsortfiltermodel.qdoc b/examples/widgets/doc/src/customsortfiltermodel.qdoc
index 5ee98362ba..b6ff8e7b48 100644
--- a/examples/widgets/doc/src/customsortfiltermodel.qdoc
+++ b/examples/widgets/doc/src/customsortfiltermodel.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/customsortfiltermodel
\title Custom Sort/Filter Model Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief The Custom Sort/Filter Model example illustrates how to subclass
QSortFilterProxyModel to perform advanced sorting and filtering.
diff --git a/examples/widgets/doc/src/deform.qdoc b/examples/widgets/doc/src/deform.qdoc
index 371f1a41c7..f33522fa3b 100644
--- a/examples/widgets/doc/src/deform.qdoc
+++ b/examples/widgets/doc/src/deform.qdoc
@@ -4,6 +4,7 @@
/*!
\example painting/deform
\title Vector Deformation
+ \examplecategory {Graphics}
\ingroup examples-painting
\brief Demonstrates how to manipulate the elements of a QPainterPath.
diff --git a/examples/widgets/doc/src/diagramscene.qdoc b/examples/widgets/doc/src/diagramscene.qdoc
index 057031462d..6f307ef97c 100644
--- a/examples/widgets/doc/src/diagramscene.qdoc
+++ b/examples/widgets/doc/src/diagramscene.qdoc
@@ -4,6 +4,7 @@
/*!
\example graphicsview/diagramscene
\title Diagram Scene Example
+ \examplecategory {Graphics}
\ingroup examples-graphicsview
\brief Demonstrate how to use the Graphics View framework.
@@ -12,7 +13,7 @@
The Diagram Scene example is an application in which you can
create a flowchart diagram. It is possible to add flowchart shapes
and text and connect the shapes by arrows as shown in the image
- above. The shapes, arrows, and text can be given different
+ above. The shapes, arrows, and text can be given different
colors, and it is possible to change the font, style, and
underline of the text.
@@ -121,9 +122,7 @@
We show an example of the creation of an action. The
functionality the actions trigger is discussed in the slots we
- connect the actions to. You can see the \l{Qt Widgets - Application
- Example}{application example} if you need a high-level
- introduction to actions.
+ connect the actions to.
The is the \c createMenus() function:
diff --git a/examples/widgets/doc/src/digitalclock.qdoc b/examples/widgets/doc/src/digitalclock.qdoc
deleted file mode 100644
index d24277177f..0000000000
--- a/examples/widgets/doc/src/digitalclock.qdoc
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/digitalclock
- \title Digital Clock Example
- \ingroup examples-widgets
- \brief The Digital Clock example shows how to use QLCDNumber to display a
- number with LCD-like digits.
-
- \borderedimage digitalclock-example.png
- \caption Screenshot of the Digital Clock example
-
- This example also demonstrates how QTimer can be used to update a widget
- at regular intervals.
-
- \section1 DigitalClock Class Definition
-
- The \c DigitalClock class provides a clock widget showing the time with
- hours and minutes separated by a blinking colon. We subclass QLCDNumber
- and implement a private slot called \c showTime() to update the clock
- display:
-
- \snippet widgets/digitalclock/digitalclock.h 0
-
- \section1 DigitalClock Class Implementation
-
- \snippet widgets/digitalclock/digitalclock.cpp 0
-
- In the constructor, we first change the look of the LCD numbers. The
- QLCDNumber::Filled style produces raised segments filled with the
- foreground color (typically black). We also set up a one-second timer
- to keep track of the current time, and we connect
- its \l{QTimer::timeout()}{timeout()} signal to the private \c showTime() slot
- so that the display is updated every second. Then, we
- call the \c showTime() slot; without this call, there would be a one-second
- delay at startup before the time is shown.
-
- \snippet widgets/digitalclock/digitalclock.cpp 1
- \snippet widgets/digitalclock/digitalclock.cpp 2
-
- The \c showTime() slot is called whenever the clock display needs
- to be updated.
-
- The current time is converted into a string with the format "hh:mm".
- When QTime::second() is a even number, the colon in the string is
- replaced with a space. This makes the colon appear and vanish every
- other second.
-
- Finally, we call QLCDNumber::display() to update the widget.
-*/
diff --git a/examples/widgets/doc/src/dirview.qdoc b/examples/widgets/doc/src/dirview.qdoc
deleted file mode 100644
index 5c63d99eaa..0000000000
--- a/examples/widgets/doc/src/dirview.qdoc
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/dirview
- \title Dir View Example
- \ingroup examples-itemviews
- \brief This example demonstrates the usage of a tree view, and smooth flicking on a touchscreen.
-
- The Dir View example shows a tree view of the local file
- system. It uses the QFileSystemModel class to provide file
- and directory information.
-
- \borderedimage dirview-example.png
-
- \quotefromfile itemviews/dirview/main.cpp
- \skipto QCommandLineParser parser
- \printuntil parser.positionalArguments
-
- The example supports a number of command line options.
- These options include:
- \list
- \li Application description
- \li -help option
- \li -version option
- \li if the optionc {-c} is specified, the application will not
- use custom directory options
- \endlist
-
- \skipto QFileSystemModel
- \printuntil tree.setModel
-
- Declares \c model as data model for reading the local filesystem.
- \c model.setRootPath("") sets the current folder as the folder from
- which \c model will start reading.
- QTreeView object \c tree visualizes the filesystem in a tree structure.
-
- \skipto tree.setAnimated(false)
- \printuntil tree.setColumnWidth
-
- Sets layout options for animation, indentation, sorting, and sizing of the
- filesystem tree.
-
- \skipto QScroller::grabGesture
- \printuntil QScroller::grabGesture
-
- Creates a \l QScroller instance to recognize gestures on touchscreens,
- so that you can flick the tree view with your finger.
-*/
diff --git a/examples/widgets/doc/src/dockwidgets.qdoc b/examples/widgets/doc/src/dockwidgets.qdoc
deleted file mode 100644
index 9907cea2e2..0000000000
--- a/examples/widgets/doc/src/dockwidgets.qdoc
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example mainwindows/dockwidgets
- \title Dock Widgets Example
- \ingroup examples-mainwindow
-
- \brief The Dock Widgets example shows how to add dock windows to an
- application. It also shows how to use Qt's rich text engine.
-
- \image dockwidgets-example.png Screenshot of the Dock Widgets example
-
- The application presents a simple business letter template, and has
- a list of customer names and addresses and a list of standard
- phrases in two dock windows. The user can click a customer to have
- their name and address inserted into the template, and click one or
- more of the standard phrases. Errors can be corrected by clicking
- the Undo button. Once the letter has been prepared it can be printed
- or saved as HTML.
-
- \section1 MainWindow Class Definition
-
- Here's the class definition:
-
- \snippet mainwindows/dockwidgets/mainwindow.h 0
-
- We will now review each function in turn.
-
- \section1 MainWindow Class Implementation
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 0
-
- We start by including \c <QtWidgets>, a header file that contains the
- definition of all classes in the Qt Core, Qt GUI and Qt Widgets
- modules. This saves us from having to include
- every class individually and is especially convenient if we add new
- widgets. We also include \c mainwindow.h.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 1
-
- In the constructor, we start by creating a QTextEdit widget. Then we call
- QMainWindow::setCentralWidget(). This function passes ownership of
- the QTextEdit to the \c MainWindow and tells the \c MainWindow that
- the QTextEdit will occupy the \c MainWindow's central area.
-
- Then we call \c createActions(), \c createMenus(), \c
- createToolBars(), \c createStatusBar(), and \c createDockWindows()
- to set up the user interface. Finally we call \c setWindowTitle() to
- give the application a title, and \c newLetter() to create a new
- letter template.
-
- We won't quote the \c createActions(), \c createMenus(), \c
- createToolBars(), and \c createStatusBar() functions since they
- follow the same pattern as all the other Qt examples.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 9
-
- We create the customers dock window first, and in addition to a
- window title, we also pass it a \c this pointer so that it becomes a
- child of \c MainWindow. Normally we don't have to pass a parent
- because widgets are parented automatically when they are laid out:
- but dock windows aren't laid out using layouts.
-
- We've chosen to restrict the customers dock window to the left and
- right dock areas. (So the user cannot drag the dock window to the
- top or bottom dock areas.) The user can drag the dock window out of
- the dock areas entirely so that it becomes a free floating window.
- We can change this (and whether the dock window is moveable or
- closable) using QDockWidget::setFeatures().
-
- Once we've created the dock window we create a list widget with the
- dock window as parent, then we populate the list and make it the
- dock window's widget. Finally we add the dock widget to the \c
- MainWindow using \c addDockWidget(), choosing to put it in the right
- dock area.
-
- We undertake a similar process for the paragraphs dock window,
- except that we don't restrict which dock areas it can be dragged to.
-
- Finally we set up the signal-slot connections. If the user clicks a
- customer or a paragraph their \c currentTextChanged() signal will be
- emitted and we connect these to \c insertCustomer() and
- addParagraph() passing the text that was clicked.
-
- We briefly discuss the rest of the implementation, but have now
- covered everything relating to dock windows.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 2
-
- In this function we clear the QTextEdit so that it is empty. Next we
- create a QTextCursor on the QTextEdit. We move the cursor to the
- start of the document and create and format a frame. We then create
- some character formats and a table format. We insert a table into
- the document and insert the company's name and address into a table
- using the table and character formats we created earlier. Then we
- insert the skeleton of the letter including two markers \c NAME and
- \c ADDRESS. We will also use the \c{Yours sincerely,} text as a marker.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 6
-
- If the user clicks a customer we split the customer details into
- pieces. We then look for the \c NAME marker using the \c find()
- function. This function selects the text it finds, so when we call
- \c insertText() with the customer's name the name replaces the marker.
- We then look for the \c ADDRESS marker and replace it with each line
- of the customer's address. Notice that we wrapped all the insertions
- between a \c beginEditBlock() and \c endEditBlock() pair. This means
- that the entire name and address insertion is treated as a single
- operation by the QTextEdit, so a single undo will revert all the
- insertions.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 7
-
- This function works in a similar way to \c insertCustomer(). First
- we look for the marker, in this case, \c {Yours sincerely,}, and then
- replace it with the standard paragraph that the user clicked. Again
- we use a \c beginEditBlock() ... \c endEditBlock() pair so that the
- insertion can be undone as a single operation.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 3
-
- Qt's QTextDocument class makes printing documents easy. We simply
- take the QTextEdit's QTextDocument, set up the printer and print the
- document.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 4
-
- QTextEdit can output its contents in HTML format, so we prompt the
- user for the name of an HTML file and if they provide one we simply
- write the QTextEdit's contents in HTML format to the file.
-
- \snippet mainwindows/dockwidgets/mainwindow.cpp 5
-
- If the focus is in the QTextEdit, pressing \uicontrol Ctrl+Z undoes as
- expected. But for the user's convenience we provide an
- application-wide undo function that simply calls the QTextEdit's
- undo: this means that the user can undo regardless of where the
- focus is in the application.
-*/
diff --git a/examples/widgets/doc/src/draganddroppuzzle.qdoc b/examples/widgets/doc/src/draganddroppuzzle.qdoc
deleted file mode 100644
index c2504b245b..0000000000
--- a/examples/widgets/doc/src/draganddroppuzzle.qdoc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example draganddrop/puzzle
- \title Drag and Drop Puzzle Example
-
- \brief The Drag and Drop Puzzle example demonstrates a way of using the drag and drop system with
- item view widgets.
-
- \image draganddroppuzzle-example.png
-
- This example is an implementation of a simple jigsaw puzzle game using Qt's
- drag and drop API.
- The \l{Item Views Puzzle Example}{Item View Puzzle} example shows
- many of the same features, but takes an alternative approach that uses Qt's
- model/view framework to manage drag and drop operations.
-*/
diff --git a/examples/widgets/doc/src/dragdroprobot.qdoc b/examples/widgets/doc/src/dragdroprobot.qdoc
index ca62bf73df..c9ff04574b 100644
--- a/examples/widgets/doc/src/dragdroprobot.qdoc
+++ b/examples/widgets/doc/src/dragdroprobot.qdoc
@@ -4,6 +4,7 @@
/*!
\example graphicsview/dragdroprobot
\title Drag and Drop Robot Example
+ \examplecategory {Graphics}
\ingroup examples-graphicsview
\brief Demonstrates how to drag and drop items in a graphics view.
diff --git a/examples/widgets/doc/src/draggableicons.qdoc b/examples/widgets/doc/src/draggableicons.qdoc
index 9a0290c82f..fd4f9e69e3 100644
--- a/examples/widgets/doc/src/draggableicons.qdoc
+++ b/examples/widgets/doc/src/draggableicons.qdoc
@@ -4,6 +4,7 @@
/*!
\example draganddrop/draggableicons
\title Draggable Icons Example
+ \examplecategory {User Interface Components}
\brief The Draggable Icons example shows how to drag and drop image data between widgets
in the same application, and between different applications.
diff --git a/examples/widgets/doc/src/draggabletext.qdoc b/examples/widgets/doc/src/draggabletext.qdoc
index 3cc3560bb9..6e15e7f946 100644
--- a/examples/widgets/doc/src/draggabletext.qdoc
+++ b/examples/widgets/doc/src/draggabletext.qdoc
@@ -4,6 +4,7 @@
/*!
\example draganddrop/draggabletext
\title Draggable Text Example
+ \examplecategory {User Interface Components}
\brief Illustrates how to drag and drop text between widgets.
\brief The Draggable Text example shows how to drag and drop textual data between widgets
diff --git a/examples/widgets/doc/src/dynamiclayouts.qdoc b/examples/widgets/doc/src/dynamiclayouts.qdoc
deleted file mode 100644
index 5dea8a7f6a..0000000000
--- a/examples/widgets/doc/src/dynamiclayouts.qdoc
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example layouts/dynamiclayouts
- \title Dynamic Layouts Example
- \brief Shows how to re-orient widgets in running applications.
-
- \e{Dynamic Layouts} implements dynamically placed widgets within running
- applications. The widget placement depends on whether \c Horizontal or \c
- Vertical is chosen.
-
- \borderedimage dynamiclayouts-example.png
- For more information, visit the \l{Layout Management} page.
-
- \section1 Dialog Constructor
-
- To begin with, the application creates the UI components by calling the
- following methods:
-
- \list
- \li createRotatableGroupBox()
- \li createOptionsGroupBox()
- \li createButtonBox()
- \endlist
-
- It then adds the UI components to a GridLayout (\c mainLayout).
-
- Finally, \c Dialog::rotateWidgets() is called.
-
- \quotefromfile layouts/dynamiclayouts/dialog.cpp
- \skipuntil createRotatableGroupBox
- \printuntil setWindowTitle
-
- \section1 Creating the Main Widgets
-
- The \c createRotatableGroupBox() method creates a rotatable group box,
- then adds a series of widgets:
-
- \list
- \li QSpinBox
- \li QSlider
- \li QDial
- \li QProgressBar
- \endlist
-
- It goes on to add signals and slots to each widget, and assigns
- a QGridLayout called \a rotatableLayout.
-
- \skipto Dialog::createRotatableGroupBox
- \printuntil /^\}/
-
- \section1 Adding Options
-
- \c createOptionsGroupBox() creates the following widgets:
- \list
- \li \c optionsGroupBox
- \li \c buttonsOrientationLabel
- \li \c buttonsOrientationComboBox. The orientation of the ComboBox is either
- \c horizontal (default value) or \c vertical. These two values
- are added during the startup of the application. It is not possible
- to leave the option empty.
- \endlist
-
- \skipto Dialog::createOptionsGroupBox()
- \printuntil /^\}/
-
- \section1 Adding Buttons
-
- createButtonBox() constructs a QDialogButtonBox called \c buttonBox
- to which are added a \c closeButton, a \c helpButton and a
- \c rotateWidgetsButton.
- It then assigns a signal and a slot to each button in \c buttonBox.
-
- \skipto Dialog::createButtonBox()
- \printuntil /^\}/
-
-
- \section1 Rotating the Widgets
-
- Removes the current widgets and activates the next widget.
-
- \quotefromfile layouts/dynamiclayouts/dialog.cpp
- \skipto Dialog::rotateWidgets()
- \printuntil rotatableLayout->addWidget(rotatableWidgets[i]
- \printuntil }
- \printuntil }
-
- \include examples-run.qdocinc
-*/
-
diff --git a/examples/widgets/doc/src/easing.qdoc b/examples/widgets/doc/src/easing.qdoc
index c9f8752b93..79c985392c 100644
--- a/examples/widgets/doc/src/easing.qdoc
+++ b/examples/widgets/doc/src/easing.qdoc
@@ -4,6 +4,7 @@
/*!
\example animation/easing
\title Easing Curves Example
+ \examplecategory {Multimedia}
\brief The Easing Curves example shows how to use easing curves to
control the speed of an animation.
diff --git a/examples/widgets/doc/src/echoplugin.qdoc b/examples/widgets/doc/src/echoplugin.qdoc
deleted file mode 100644
index 4cdd700534..0000000000
--- a/examples/widgets/doc/src/echoplugin.qdoc
+++ /dev/null
@@ -1,181 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example tools/echoplugin
- \title Echo Plugin Example
- \ingroup examples-widgets-tools
- \ingroup examples-layout
-
- \brief This example shows how to create a Qt plugin.
-
- \image echopluginexample.png
-
- There are two kinds of plugins in Qt: plugins that extend Qt
- itself and plugins that extend applications written in Qt. In this
- example, we show the procedure of implementing plugins that extend
- applications. When you create a plugin you declare an interface,
- which is a class with only pure virtual functions. This interface
- is inherited by the class that implements the plugin. The class is
- stored in a shared library and can therefore be loaded by
- applications at run-time. When loaded, the plugin is dynamically
- cast to the interface using Qt's \l{Meta-Object
- System}{meta-object system}. The plugin \l{How to Create Qt
- Plugins}{overview document} gives a high-level introduction to
- plugins.
-
- We have implemented a plugin, the \c EchoPlugin, which implements
- the \c EchoInterface. The interface consists of \c echo(), which
- takes a QString as argument. The \c EchoPlugin returns the string
- unaltered (i.e., it works as the familiar echo command found in
- both Unix and Windows).
-
- We test the plugin in \c EchoWindow: when you push the QPushButton
- (as seen in the image above), the application sends the text in
- the QLineEdit to the plugin, which echoes it back to the
- application. The answer from the plugin is displayed in the
- QLabel.
-
-
- \section1 EchoWindow Class Definition
-
- The \c EchoWindow class lets us test the \c EchoPlugin through a
- GUI.
-
- \snippet tools/echoplugin/echowindow/echowindow.h 0
-
- We load the plugin in \c loadPlugin() and cast it to \c
- EchoInterface. When the user clicks the \c button we take the
- text in \c lineEdit and call the interface's \c echo() with it.
-
-
- \section1 EchoWindow Class Implementation
-
- We start with a look at the constructor:
-
- \snippet tools/echoplugin/echowindow/echowindow.cpp 0
-
- We create the widgets and set a title for the window. We then load
- the plugin. \c loadPlugin() returns false if the plugin could not
- be loaded, in which case we disable the widgets. If you wish a
- more detailed error message, you can use
- \l{QPluginLoader::}{errorString()}; we will look more closely at
- QPluginLoader later.
-
- Here is the implementation of \c sendEcho():
-
- \snippet tools/echoplugin/echowindow/echowindow.cpp 1
-
- This slot is called when the user pushes \c button or presses
- enter in \c lineEdit. We call \c echo() of the echo interface. In
- our example this is the \c EchoPlugin, but it could be any plugin
- that inherit the \c EchoInterface. We take the QString returned
- from \c echo() and display it in the \c label.
-
- Here is the implementation of \c createGUI():
-
- \snippet tools/echoplugin/echowindow/echowindow.cpp 2
-
- We create the widgets and lay them out in a grid layout. We
- connect the label and line edit to our \c sendEcho() slot.
-
- Here is the \c loadPlugin() function:
-
- \snippet tools/echoplugin/echowindow/echowindow.cpp 3
-
- Access to plugins at run-time is provided by QPluginLoader. You
- supply it with the filename of the shared library the plugin is
- stored in and call \l{QPluginLoader::}{instance()}, which loads
- and returns the root component of the plugin (i.e., it resolves
- the type of the plugin and creates a QObject instance of it). If
- the plugin was not successfully loaded, it will be null, so we
- return false. If it was loaded correctly, we can cast the plugin
- to our \c EchoInterface and return true. In the case that the
- plugin loaded does not implement the \c EchoInterface, \c
- instance() will return null, but this cannot happen in our
- example. Notice that the location of the plugin is not the same
- for all platforms.
-
-
- \section1 EchoInterface Class Definition
-
- The \c EchoInterface defines the functions that the plugin will
- provide. An interface is a class that only consists of pure
- virtual functions. If non virtual functions were present in the
- class you would get misleading compile errors in the moc files.
-
- \snippet tools/echoplugin/echowindow/echointerface.h 0
-
- We declare \c echo(). In our \c EchoPlugin we use this method to
- return, or echo, \a message.
-
- We use the Q_DECLARE_INTERFACE macro to let \l{Meta-Object
- System}{Qt's meta object system} aware of the interface. We do
- this so that it will be possible to identify plugins that
- implements the interface at run-time. The second argument is a
- string that must identify the interface in a unique way.
-
-
- \section1 EchoPlugin Class Definition
-
- We inherit both QObject and \c EchoInterface to make this class a
- plugin. The Q_INTERFACES macro tells Qt which interfaces the class
- implements. In our case we only implement the \c EchoInterface.
- If a class implements more than one interface, they are given as
- a space separated list. The Q_PLUGIN_METADATA macro is included next
- to the Q_OBJECT macro. It contains the plugins IID and a filename
- pointing to a json file containing the metadata for the plugin.
- The json file is compiled into the plugin and does not need to be installed.
-
- \snippet tools/echoplugin/plugin/echoplugin.h 0
-
- \section1 EchoPlugin Class Implementation
-
- Here is the implementation of \c echo():
-
- \snippet tools/echoplugin/plugin/echoplugin.cpp 0
-
- We simply return the functions parameter.
-
- \section1 The \c main() function
-
- \snippet tools/echoplugin/echowindow/main.cpp 0
-
- We create an \c EchoWindow and display it as a top-level window.
-
- \section1 The Profiles
-
- When creating plugins the profiles need to be adjusted.
- We show here what changes need to be done.
-
- The profile in the echoplugin directory uses the \c subdirs
- template and simply includes includes to directories in which
- the echo window and echo plugin lives:
-
- \snippet tools/echoplugin/echoplugin.pro 0
-
- The profile for the echo window does not need any plugin specific
- settings. We move on to the plugin profile:
-
- \snippet tools/echoplugin/plugin/plugin.pro 0
-
- We need to set the TEMPLATE as we now want to make a library
- instead of an executable. We also need to tell qmake that we are
- creating a plugin. The \c EchoInterface that the plugin implements
- lives in the \c echowindow directory, so we need to add that
- directory to the include path. We set the TARGET of the project,
- which is the name of the library file in which the plugin will be
- stored; qmake appends the appropriate file extension depending on
- the platform. By convention the target should have the same name
- as the plugin (set with Q_EXPORT_PLUGIN2)
-
- \section1 Further Reading and Examples
-
- The \l {qtplugin-defining-plugins}{Defining Plugins} page presents an overview of the macros needed to
- create plugins.
-
- We give an example of a plugin that extends Qt in the \l{Style
- Plugin Example}{style plugin} example. The \l{Plug & Paint
- Example}{plug and paint} example shows how to create static
- plugins.
-*/
diff --git a/examples/widgets/doc/src/editabletreemodel.qdoc b/examples/widgets/doc/src/editabletreemodel.qdoc
index 9616610758..15df678c87 100644
--- a/examples/widgets/doc/src/editabletreemodel.qdoc
+++ b/examples/widgets/doc/src/editabletreemodel.qdoc
@@ -4,9 +4,10 @@
/*!
\example itemviews/editabletreemodel
\title Editable Tree Model Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief This example shows how to implement a simple item-based tree model that can
- be used with other classes the model/view framework.
+ be used with other classes in the model/view framework.
\image itemviews-editabletreemodel.png
@@ -229,32 +230,30 @@
internal \c childItems member using the \c insertChildren() function
described later.
- The destructor ensures that each child added to the item is deleted
- when the item itself is deleted:
-
- \snippet itemviews/editabletreemodel/treeitem.cpp 1
+ The children are stored in std::unique_ptr to ensures that each child
+ added to the item is deleted when the item itself is deleted.
\target TreeItem::parent
Since each item stores a pointer to its parent, the \c parent() function
is trivial:
- \snippet itemviews/editabletreemodel/treeitem.cpp 9
+ \snippet itemviews/editabletreemodel/treeitem.cpp 8
\target TreeItem::child
Three functions provide information about the children of an item.
\c child() returns a specific child from the internal list of children:
- \snippet itemviews/editabletreemodel/treeitem.cpp 2
+ \snippet itemviews/editabletreemodel/treeitem.cpp 1
The \c childCount() function returns the total number of children:
- \snippet itemviews/editabletreemodel/treeitem.cpp 3
+ \snippet itemviews/editabletreemodel/treeitem.cpp 2
The \c childNumber() function is used to determine the index of the child
in its parent's list of children. It accesses the parent's \c childItems
member directly to obtain this information:
- \snippet itemviews/editabletreemodel/treeitem.cpp 4
+ \snippet itemviews/editabletreemodel/treeitem.cpp 3
The root item has no parent item; for this item, we return zero to be
consistent with the other items.
@@ -262,20 +261,20 @@
The \c columnCount() function simply returns the number of elements in
the internal \c itemData list of QVariant objects:
- \snippet itemviews/editabletreemodel/treeitem.cpp 5
+ \snippet itemviews/editabletreemodel/treeitem.cpp 4
\target TreeItem::data
Data is retrieved using the \c data() function, which accesses the
appropriate element in the \c itemData list:
- \snippet itemviews/editabletreemodel/treeitem.cpp 6
+ \snippet itemviews/editabletreemodel/treeitem.cpp 5
\target TreeItem::setData
Data is set using the \c setData() function, which only stores values
in the \c itemData list for valid list indexes, corresponding to column
values in the model:
- \snippet itemviews/editabletreemodel/treeitem.cpp 11
+ \snippet itemviews/editabletreemodel/treeitem.cpp 10
To make implementation of the model easier, we return true to indicate
that the data was set successfully.
@@ -285,20 +284,20 @@
in the model leads to the insertion of new child items in the corresponding
item, handled by the \c insertChildren() function:
- \snippet itemviews/editabletreemodel/treeitem.cpp 7
+ \snippet itemviews/editabletreemodel/treeitem.cpp 6
This ensures that new items are created with the required number of columns
and inserted at a valid position in the internal \c childItems list.
Items are removed with the \c removeChildren() function:
- \snippet itemviews/editabletreemodel/treeitem.cpp 10
+ \snippet itemviews/editabletreemodel/treeitem.cpp 9
As discussed above, the functions for inserting and removing columns are
used differently to those for inserting and removing child items because
they are expected to be called on every item in the tree. We do this by
recursively calling this function on each child of the item:
- \snippet itemviews/editabletreemodel/treeitem.cpp 8
+ \snippet itemviews/editabletreemodel/treeitem.cpp 7
\section1 TreeModel Class Definition
@@ -334,11 +333,12 @@
use with the model. Other models may be initialized with a ready-made
data structure, or use an API from a library that maintains its own data.
- The destructor only has to delete the root item, which will cause all child
- items to be recursively deleted.
-
\snippet itemviews/editabletreemodel/treemodel.cpp 1
+ The destructor only has to delete the root item, which will cause all child
+ items to be recursively deleted. This is done automatically by the default
+ destructor since the root item is stored inside an unique_ptr.
+
\target TreeModel::getItem
Since the model's interface to the other model/view components is based
on model indexes, and since the internal data structure is item-based,
@@ -419,4 +419,20 @@
\target TreeModel::data
\target TreeModel::setupModelData
+ \section1 Testing the model
+
+ Correctly implementing an item model can be challenging. The class
+ \l [QtTest] QAbstractItemModelTester from the \l [QtTest]{Qt Test} module
+ checks for model consistency, like the model index creation and
+ parent-child relationships.
+
+ You can test your model by just passing a model instance to the class
+ constructor, for instance as part of a Qt unit test:
+
+ \snippet itemviews/editabletreemodel/test.cpp 1
+
+ To create a test which can be run using the \c ctest executable,
+ \c add_test() is used:
+
+ \snippet itemviews/editabletreemodel/CMakeLists.txt 1
*/
diff --git a/examples/widgets/doc/src/elasticnodes.qdoc b/examples/widgets/doc/src/elasticnodes.qdoc
index 1d155adbec..c25fd68009 100644
--- a/examples/widgets/doc/src/elasticnodes.qdoc
+++ b/examples/widgets/doc/src/elasticnodes.qdoc
@@ -4,6 +4,7 @@
/*!
\example graphicsview/elasticnodes
\title Elastic Nodes Example
+ \examplecategory {Graphics}
\ingroup examples-graphicsview
\brief Demonstrates how to interact with graphical items in a scene.
diff --git a/examples/widgets/doc/src/embeddeddialogs.qdoc b/examples/widgets/doc/src/embeddeddialogs.qdoc
deleted file mode 100644
index 09df334c77..0000000000
--- a/examples/widgets/doc/src/embeddeddialogs.qdoc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example graphicsview/embeddeddialogs
- \title Embedded Dialogs
- \ingroup examples-graphicsview-layout
- \brief Demonstrates how to embed dialogs into a graphics view.
-
- This example shows how to embed standard dialogs into
- Graphics View. It also shows how you can customize the
- proxy class and add window shadows.
-
- \image embeddeddialogs-demo.png
-*/
diff --git a/examples/widgets/doc/src/fademessage.qdoc b/examples/widgets/doc/src/fademessage.qdoc
deleted file mode 100644
index bd46593ad3..0000000000
--- a/examples/widgets/doc/src/fademessage.qdoc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example effects/fademessage
- \title Fade Message Effect Example
- \ingroup examples-graphicsview-graphicseffects
- \brief Demonstrates how to apply effects on items in the view.
-
- \div { style="text-align: left"}
- \inlineimage fademessageeffect-example.png
- \inlineimage fademessageeffect-example-faded.png
- \enddiv
-
-*/
diff --git a/examples/widgets/doc/src/fetchmore.qdoc b/examples/widgets/doc/src/fetchmore.qdoc
index 1e80e803d5..d8dae18f33 100644
--- a/examples/widgets/doc/src/fetchmore.qdoc
+++ b/examples/widgets/doc/src/fetchmore.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/fetchmore
\title Fetch More Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief The Fetch More example shows how to add items to an item view
model on demand.
diff --git a/examples/widgets/doc/src/flowlayout.qdoc b/examples/widgets/doc/src/flowlayout.qdoc
index 5a3316b6e4..03dfc164d7 100644
--- a/examples/widgets/doc/src/flowlayout.qdoc
+++ b/examples/widgets/doc/src/flowlayout.qdoc
@@ -4,6 +4,7 @@
/*!
\example layouts/flowlayout
\title Flow Layout Example
+ \examplecategory {User Interface Components}
\ingroup examples-layout
\brief Shows how to arrange widgets for different window sizes.
diff --git a/examples/widgets/doc/src/fontsampler.qdoc b/examples/widgets/doc/src/fontsampler.qdoc
deleted file mode 100644
index 3b014b5713..0000000000
--- a/examples/widgets/doc/src/fontsampler.qdoc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example painting/fontsampler
- \title Font Sampler Example
- \ingroup examples-painting
- \brief The Font Sampler example shows how to preview and print multi-page documents.
-
- The Font Sampler example shows how to preview and print multi-page documents.
-
- \image fontsampler-example.png
-*/
diff --git a/examples/widgets/doc/src/fridgemagnets.qdoc b/examples/widgets/doc/src/fridgemagnets.qdoc
deleted file mode 100644
index 149cfe1351..0000000000
--- a/examples/widgets/doc/src/fridgemagnets.qdoc
+++ /dev/null
@@ -1,338 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example draganddrop/fridgemagnets
- \title Fridge Magnets Example
- \brief The Fridge Magnets example illustrates how to move around several types of
- MIME-encoded data with drag and drop.
-
- The Fridge Magnets example shows how to supply more than one type
- of MIME-encoded data with a drag and drop operation.
-
- \image fridgemagnets-example.png
-
- With this application the user can play around with a collection
- of fridge magnets, using drag and drop to form new sentences from
- the words on the magnets. The example consists of two classes:
-
- \list
- \li \c DragLabel is a custom widget representing one
- single fridge magnet.
- \li \c DragWidget provides the main application window.
- \endlist
-
- We will first take a look at the \c DragLabel class, then we will
- examine the \c DragWidget class.
-
- \section1 DragLabel Class Definition
-
- Each fridge magnet is represented by an instance of the \c
- DragLabel class:
-
- \snippet draganddrop/fridgemagnets/draglabel.h 0
-
- Each instance of this QLabel subclass will be used to display an
- pixmap generated from a text string. Since we cannot store both
- text and a pixmap in a standard label, we declare a private variable
- to hold the original text, and we define an additional member
- function to allow it to be accessed.
-
- \section1 DragLabel Class Implementation
-
- In the \c DragLabel constructor, we first create a QImage object
- on which we will draw the fridge magnet's text and frame:
-
- \snippet draganddrop/fridgemagnets/draglabel.cpp 0
-
- Its size depends on the current font size, and its format is
- QImage::Format_ARGB32_Premultiplied; i.e., the image is stored
- using a premultiplied 32-bit ARGB format (0xAARRGGBB).
-
- We then construct a font object that uses the application's
- default font, and set its style strategy. The style strategy tells
- the font matching algorithm what type of fonts should be used to
- find an appropriate default family. The QFont::ForceOutline forces
- the use of outline fonts.
-
- To draw the text and frame onto the image, we use the QPainter
- class. QPainter provides highly optimized methods to do most of
- the drawing GUI programs require. It can draw everything from
- simple lines to complex shapes like pies and chords. It can also
- draw aligned text and pixmaps.
-
- \snippet draganddrop/fridgemagnets/draglabel.cpp 1
-
- A painter can be activated by passing a paint device to the
- constructor, or by using the \l{QPainter::}{begin()} method as we
- do in this example. The \l{QPainter::}{end()} method deactivates
- it. Note that the latter function is called automatically upon
- destruction when the painter is activated by its constructor. The
- QPainter::Antialiasing render hint ensures that the paint engine
- will antialias the edges of primitives if possible.
-
- When the painting is done, we convert our image to a pixmap using
- QPixmap's \l {QPixmap::}{fromImage()} method. This method also
- takes an optional flags argument, and converts the given image to
- a pixmap using the specified flags to control the conversion (the
- flags argument is a bitwise-OR of the Qt::ImageConversionFlags;
- passing 0 for flags sets all the default options).
-
- \snippet draganddrop/fridgemagnets/draglabel.cpp 2
-
- Finally, we set the label's \l{QLabel::pixmap}{pixmap property}
- and store the label's text for later use.
-
- \e{Note that setting the pixmap clears any previous content, including
- any text previously set using QLabel::setText(), and disables
- the label widget's buddy shortcut, if any.}
-
- \section1 DragWidget Class Definition
-
- The \c DragWidget class inherits QWidget, providing support for
- drag and drop operations:
-
- \snippet draganddrop/fridgemagnets/dragwidget.h 0
-
- To make the widget responsive to drag and drop operations, we simply
- reimplement the \l{QWidget::}{dragEnterEvent()},
- \l{QWidget::}{dragMoveEvent()} and \l{QWidget::}{dropEvent()} event
- handlers inherited from QWidget.
-
- We also reimplement \l{QWidget::}{mousePressEvent()} to make the
- widget responsive to mouse clicks. This is where we will write code
- to start drag and drop operations.
-
- \section1 DragWidget Class Implementation
-
- In the constructor, we first open the file containing the words on
- our fridge magnets:
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 0
-
- QFile is an I/O device for reading and writing text and binary
- files and resources, and may be used by itself or in combination
- with QTextStream or QDataStream. We have chosen to read the
- contents of the file using the QTextStream class that provides a
- convenient interface for reading and writing text.
-
- We then create the fridge magnets. As long as there is data (the
- QTextStream::atEnd() method returns true if there is no more data
- to be read from the stream), we read one line at a time using
- QTextStream's \l {QTextStream::}{readLine()} method.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 1
-
- For each line, we create a \c DragLabel object using the read line
- as text, we calculate its position and ensure that it is visible by
- calling the QWidget::show() method. We set the Qt::WA_DeleteOnClose
- attribute on each label to ensure that any unused labels will be
- deleted; we will need to create new labels and delete old ones when
- they are dragged around, and this ensures that the example does not
- leak memory.
-
- We also set the \c FridgeMagnets widget's palette, minimum size
- and window title.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 2
-
- Finally, to enable our user to move the fridge magnets around, we
- must also set the \c FridgeMagnets widget's
- \l{QWidget::acceptDrops}{acceptDrops} property.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 3
-
- Setting this property to true announces to the system that this
- widget \e may be able to accept drop events (events that are sent
- when drag and drop actions are completed). Later, we will
- implement the functions that ensure that the widget accepts the
- drop events it is interested in.
-
- \section2 Dragging
-
- Let's take a look at the \l{QWidget::}{mousePressEvent()} event
- handler, where drag and drop operations begin:
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 13
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 14
-
- Mouse events occur when a mouse button is pressed or released
- inside a widget, or when the mouse cursor is moved. By
- reimplementing the \l{QWidget::}{mousePressEvent()} method we
- ensure that we will receive mouse press events for the widget
- containing the fridge magnets.
-
- Whenever we receive such an event, we first check to see if the
- position of the click coincides with one of the labels. If not,
- we simply return.
-
- If the user clicked a label, we determine the position of the
- \e{hot spot} (the position of the click relative to the top-left
- corner of the label). We create a byte array to store the label's
- text and the hot spot, and we use a QDataStream object to stream
- the data into the byte array.
-
- With all the information in place, we create a new QMimeData object.
- As mentioned above, QMimeData objects associate the data that they
- hold with the corresponding MIME types to ensure that information
- can be safely transferred between applications. The
- \l{QMimeData::}{setData()} method sets the data associated with a
- given MIME type. In our case, we associate our item data with the
- custom \c application/x-fridgemagnet type.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 15
-
- Note that we also associate the magnet's text with the
- \c text/plain MIME type using QMimeData's \l{QMimeData::}{setText()}
- method. Below, we will see how our widget detects both these MIME
- types with its event handlers.
-
- Finally, we create a QDrag object. It is the QDrag class that
- handles most of the details of a drag and drop operation,
- providing support for MIME-based drag and drop data transfer. The
- data to be transferred by the drag and drop operation is contained
- in a QMimeData object. When we call QDrag's
- \l{QDrag::}{setMimeData()} method the ownership of our item data is
- transferred to the QDrag object.
-
- We call the \l{QDrag::}{setPixmap()} function to set the pixmap used
- to represent the data during the drag and drop operation.
- Typically, this pixmap shows an icon that represents the MIME type
- of the data being transferred, but any pixmap can be used. In this
- example, we simply use the pixmap used by the label itself to make
- it look like the fridge magnet itself is being moved.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 16
-
- We also specify the cursor's hot spot, its position relative to the
- top-level corner of the drag pixmap, to be the point we calculated
- above. This makes the process of dragging the label feel more natural
- because the cursor always points to the same place on the label
- during the drag operation.
-
- We start the drag operation using QDrag's \l{QDrag::}{exec()} function,
- requesting that the magnet is copied when the drag is completed.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 17
-
- The function returns the drop action actually performed by the user
- (this can be either a copy or a move action in this case); if this
- action is equal to Qt::MoveAction we will close the activated
- fridge magnet widget because we will create a new one to replace it
- (see the \l{drop}{dropEvent()} implementation). Otherwise, if
- the drop is outside our main widget, we simply show the widget in
- its original position.
-
- \section2 Dropping
-
- When a drag and drop action enters our widget, we will receive a
- drag enter \e event. QDragEnterEvent inherits most of its
- functionality from QDragMoveEvent, which in turn inherits most of
- its functionality from QDropEvent. Note that we must accept this
- event in order to receive the drag move events that are sent while
- the drag and drop action is in progress. The drag enter event is
- always immediately followed by a drag move event.
-
- In our \c dragEnterEvent() implementation, we first determine
- whether we support the event's MIME type or not:
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 4
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 5
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 6
-
- If the type is \c application/x-fridgemagnet and the event
- origins from any of this application's fridge magnet widgets, we
- first set the event's drop action using the
- QDropEvent::setDropAction() method. An event's drop action is the
- action to be performed on the data by the target. Qt::MoveAction
- indicates that the data is moved from the source to the target.
-
- Then we call the event's \l {QDragMoveEvent::}{accept()} method to
- indicate that we have handled the event. In general, unaccepted
- events might be propagated to the parent widget. If the event
- origins from any other widget, we simply accept the proposed
- action.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 7
-
- We also accept the proposed action if the event's MIME type is \c
- text/plain, i.e., if QMimeData::hasText() returns true. If the
- event has any other type, on the other hand, we call the event's
- \l {QDragMoveEvent::}{ignore()} method allowing the event to be
- propagated further.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 8
-
- Drag move events occur when the cursor enters a widget, when it
- moves within the widget, and when a modifier key is pressed on the
- keyboard while the widget has focus. Our widget will receive drag
- move events repeatedly while a drag is within its boundaries. We
- reimplement the \l {QWidget::}{dragMoveEvent()} method, and
- examine the event in the exact same way as we did with drag enter
- events.
-
- Note that the \l{QWidget::}{dropEvent()} event handler behaves
- slightly differently: We first get hold of the event's MIME
- data.
-
- \target drop
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 9
-
- The QMimeData class provides a container for data that
- records information about its MIME type. QMimeData objects
- associate the data that they hold with the corresponding MIME
- types to ensure that information can be safely transferred between
- applications, and copied around within the same application.
-
- We retrieve the data associated with the \c application/x-fridgemagnet
- MIME type using a data stream in order to create a new \c DragLabel
- object.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 10
-
- The QDataStream class provides serialization of binary data to a
- QIODevice (a data stream is a binary stream of encoded information
- which is completely independent of the host computer's operating
- system, CPU or byte order).
-
- Finally, we create a label and move it to the event's position:
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 11
-
- If the source of the event is also the widget receiving the
- drop event, we set the event's drop action to Qt::MoveAction and
- call the event's \l{QDragMoveEvent::}{accept()}
- method. Otherwise, we simply accept the proposed action. This
- means that labels are moved rather than copied in the same
- window. However, if we drag a label to a second instance of the
- Fridge Magnets example, the default action is to copy it, leaving
- the original in the first instance.
-
- If the event's MIME type is \c text/plain (i.e., if
- QMimeData::hasText() returns true) we retrieve its text and split
- it into words. For each word we create a new \c DragLabel action,
- and show it at the event's position plus an offset depending on
- the number of words in the text. In the end we accept the proposed
- action. This lets the user drop selected text from a text editor or
- Web browser onto the widget to add more fridge magnets.
-
- \snippet draganddrop/fridgemagnets/dragwidget.cpp 12
-
- If the event has any other type, we call the event's
- \l{QDragMoveEvent::}{ignore()} method allowing the event to be
- propagated further.
-
- \section1 Summary
-
- We set our main widget's \l{QWidget::}{acceptDrops} property
- and reimplemented QWidget's \l{QWidget::}{dragEnterEvent()},
- \l{QWidget::}{dragMoveEvent()} and \l{QWidget::}{dropEvent()} event
- handlers to support content dropped on our widget.
-
- In addition, we reimplemented the \l{QWidget::}{mousePressEvent()}
- function to let the user pick up fridge magnets in the first place.
-
- Because data is communicated using drag and drop operations and
- encoded using MIME types, you can run more than one instance of this
- example, and transfer magnets between them.
-*/
diff --git a/examples/widgets/doc/src/frozencolumn.qdoc b/examples/widgets/doc/src/frozencolumn.qdoc
index 54040bc9e1..c213ba1779 100644
--- a/examples/widgets/doc/src/frozencolumn.qdoc
+++ b/examples/widgets/doc/src/frozencolumn.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/frozencolumn
\title Frozen Column Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief This example demonstrates how to freeze a column within a QTableView.
diff --git a/examples/widgets/doc/src/gallery.qdoc b/examples/widgets/doc/src/gallery.qdoc
index 5287fb5b53..36b76d8f63 100644
--- a/examples/widgets/doc/src/gallery.qdoc
+++ b/examples/widgets/doc/src/gallery.qdoc
@@ -5,6 +5,7 @@
\example gallery
\meta {tag} {gallery}
\title Widgets Gallery Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The Widgets Gallery example shows widgets relevant for designing UIs.
diff --git a/examples/widgets/doc/src/gradients.qdoc b/examples/widgets/doc/src/gradients.qdoc
index 5a951ffb95..e2ad68db1a 100644
--- a/examples/widgets/doc/src/gradients.qdoc
+++ b/examples/widgets/doc/src/gradients.qdoc
@@ -4,6 +4,7 @@
/*!
\example painting/gradients
\title Gradients
+ \examplecategory {Graphics}
\ingroup examples-painting
\brief Shows how gradients can be used with QPainter.
diff --git a/examples/widgets/doc/src/graphicsview-flowlayout.qdoc b/examples/widgets/doc/src/graphicsview-flowlayout.qdoc
deleted file mode 100644
index 179f3501df..0000000000
--- a/examples/widgets/doc/src/graphicsview-flowlayout.qdoc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example graphicsview/flowlayout
- \title Graphics View Flow Layout Example
- \ingroup examples-graphicsview-layout
- \brief Demonstrates flow layout on a graphics view scene.
-
- The Graphics View Flow Layout example shows the use of a flow layout
- in a Graphics View widget.
-
- \image graphicsflowlayout-example.png
-
- This example uses a Graphics View to display the widget, which is a more
- customizable approach than displaying the flow layout in the application
- window (See \l {Flow Layout Example}).
-
- Graphics View Flow Layout snippet:
-
- \snippet graphicsview/flowlayout/main.cpp 1
-
- Flow Layout Example snippet:
-
- \snippet layouts/flowlayout/main.cpp 1
-
-
-*/
diff --git a/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc b/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc
index 49301013ce..ce5fe8934a 100644
--- a/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc
+++ b/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc
@@ -4,6 +4,7 @@
/*!
\example graphicsview/simpleanchorlayout
\title Simple Anchor Layout Example
+ \examplecategory {Graphics}
\ingroup examples-graphicsview-layout
\brief Demonstrates anchor layout on a graphics view scene.
diff --git a/examples/widgets/doc/src/groupbox.qdoc b/examples/widgets/doc/src/groupbox.qdoc
deleted file mode 100644
index 5c565f1cb5..0000000000
--- a/examples/widgets/doc/src/groupbox.qdoc
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/groupbox
- \title Group Box Example
- \ingroup examples-widgets
- \brief The Group Box example shows how to use the different kinds of group
- boxes in Qt.
-
- Group boxes are container widgets that organize buttons into groups,
- both logically and on screen. They manage the interactions between
- the user and the application so that you do not have to enforce
- simple constraints.
-
- Group boxes are usually used to organize check boxes and radio
- buttons into exclusive groups.
-
- \borderedimage groupbox-example.png
-
- The Group Boxes example consists of a single \c Window class that
- is used to show four group boxes: an exclusive radio button group,
- a non-exclusive checkbox group, an exclusive radio button group
- with an enabling checkbox, and a group box with normal push buttons.
-
- \section1 Window Class Definition
-
- The \c Window class is a subclass of \c QWidget that is used to
- display a number of group boxes. The class definition contains
- functions to construct each group box and populate it with different
- selections of button widgets:
-
- \snippet widgets/groupbox/window.h 0
-
- In the example, the widget will be used as a top-level window, so
- the constructor is defined so that we do not have to specify a parent
- widget.
-
- \section1 Window Class Implementation
-
- The constructor creates a grid layout and fills it with each of the
- group boxes that are to be displayed:
-
- \snippet widgets/groupbox/window.cpp 0
-
- The functions used to create each group box each return a
- QGroupBox to be inserted into the grid layout.
-
- \snippet widgets/groupbox/window.cpp 1
-
- The first group box contains and manages three radio buttons. Since
- the group box contains only radio buttons, it is exclusive by
- default, so only one radio button can be checked at any given time.
- We check the first radio button to ensure that the button group
- contains one checked button.
-
- \snippet widgets/groupbox/window.cpp 3
-
- We use a vertical layout within the group box to present the
- buttons in the form of a vertical list, and return the group
- box to the constructor.
-
- The second group box is itself checkable, providing a convenient
- way to disable all the buttons inside it. Initially, it is
- unchecked, so the group box itself must be checked before any of
- the radio buttons inside can be checked.
-
- \snippet widgets/groupbox/window.cpp 4
-
- The group box contains three exclusive radio buttons, and an
- independent checkbox. For consistency, one radio button must be
- checked at all times, so we ensure that the first one is initially
- checked.
-
- \snippet widgets/groupbox/window.cpp 5
-
- The buttons are arranged in the same way as those in the first
- group box.
-
- \snippet widgets/groupbox/window.cpp 6
-
- The third group box is constructed with a "flat" style that is
- better suited to certain types of dialog.
-
- \snippet widgets/groupbox/window.cpp 7
-
- This group box contains only checkboxes, so it is non-exclusive by
- default. This means that each checkbox can be checked independently
- of the others.
-
- \snippet widgets/groupbox/window.cpp 8
-
- Again, we use a vertical layout within the group box to present
- the buttons in the form of a vertical list.
-
- \snippet widgets/groupbox/window.cpp 9
-
- The final group box contains only push buttons and, like the
- second group box, it is checkable.
-
- \snippet widgets/groupbox/window.cpp 10
-
- We create a normal button, a toggle button, and a flat push button:
-
- \snippet widgets/groupbox/window.cpp 11
-
- Push buttons can be used to display popup menus. We create one, and
- attach a simple menu to it:
-
- \snippet widgets/groupbox/window.cpp 12
-
- Finally, we lay out the widgets vertically, and return the group box
- that we created:
-
- \snippet widgets/groupbox/window.cpp 13
-*/
diff --git a/examples/widgets/doc/src/icons.qdoc b/examples/widgets/doc/src/icons.qdoc
deleted file mode 100644
index 8ec062ea43..0000000000
--- a/examples/widgets/doc/src/icons.qdoc
+++ /dev/null
@@ -1,805 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/icons
- \title Icons Example
- \ingroup examples-widgets
- \brief The Icons example shows how QIcon can generate pixmaps reflecting
- an icon's state, mode and size.
-
- These pixmaps are generated from the set of pixmaps made available to the
- icon, and are used by Qt widgets to show an icon representing a particular
- action.
-
- \image icons-example.png Screenshot of the Icons example
-
- Contents:
-
- \tableofcontents
-
- \section1 QIcon Overview
-
- The QIcon class provides scalable icons in different modes and
- states. An icon's state and mode are depending on the intended use
- of the icon. Qt currently defines four modes:
-
- \table
- \header \li Mode \li Description
- \row
- \li QIcon::Normal
- \li Display the pixmap when the user is not interacting with the
- icon, but the functionality represented by the icon is
- available.
- \row
- \li QIcon::Active
- \li Display the pixmap when the functionality represented by the
- icon is available and the user is interacting with the icon,
- for example, moving the mouse over it or clicking it.
- \row
- \li QIcon::Disabled
- \li Display the pixmap when the functionality represented by
- the icon is not available.
- \row
- \li QIcon::Selected
- \li Display the pixmap when the icon is selected.
- \endtable
-
- QIcon's states are QIcon::On and QIcon::Off, which will display
- the pixmap when the widget is in the respective state. The most
- common usage of QIcon's states are when displaying checkable tool
- buttons or menu entries (see QAbstractButton::setCheckable() and
- QAction::setCheckable()). When a tool button or menu entry is
- checked, the QIcon's state is \l{QIcon::}{On}, otherwise it's
- \l{QIcon::}{Off}. You can, for example, use the QIcon's states to
- display differing pixmaps depending on whether the tool button or
- menu entry is checked or not.
-
- A QIcon can generate smaller, larger, active, disabled, and
- selected pixmaps from the set of pixmaps it is given. Such
- pixmaps are used by Qt widgets to show an icon representing a
- particular action.
-
- \section1 Overview of the Icons Application
-
- With the Icons application you get a preview of an icon's
- generated pixmaps reflecting its different states, modes and size.
-
- When an image is loaded into the application, it is converted into
- a pixmap and becomes a part of the set of pixmaps available to the
- icon. An image can be excluded from this set by checking off the
- related checkbox. The application provides a sub directory
- containing sets of images explicitly designed to illustrate how Qt
- renders an icon in different modes and states.
-
- The application allows you to manipulate the icon size with some
- predefined sizes and a spin box. The predefined sizes are style
- dependent, but most of the styles have the same values. Only the
- \macos style differs by using 32 pixels instead of 16 pixels
- for toolbar buttons. You can navigate between the available styles
- using the \uicontrol View menu.
-
- \image icons-view-menu.png Screenshot of the View menu
-
- The \uicontrol View menu also provide the option to make the application
- guess the icon state and mode from an image's file name. The \uicontrol
- File menu provide the options of adding an image and removing all
- images. These last options are also available through a context
- menu that appears if you press the right mouse button within the
- table of image files. In addition, the \uicontrol File menu provide an
- \uicontrol Exit option, and the \uicontrol Help menu provide information about
- the example and about Qt.
-
- \image icons_find_normal.png Screenshot of the Find Files
-
- The screenshot above shows the application with one image file
- loaded. The \uicontrol {Guess Image Mode/State} is enabled and the
- style is Plastique.
-
- When QIcon is provided with only one available pixmap, that
- pixmap is used for all the states and modes. In this case the
- pixmap's icon mode is set to normal, and the generated pixmaps
- for the normal and active modes will look the same. But in
- disabled and selected mode, Qt will generate a slightly different
- pixmap.
-
- The next screenshot shows the application with an additional file
- loaded, providing QIcon with two available pixmaps. Note that the
- new image file's mode is set to disabled. When rendering the \uicontrol
- Disabled mode pixmaps, Qt will now use the new image. We can see
- the difference: The generated disabled pixmap in the first
- screenshot is slightly darker than the pixmap with the originally
- set disabled mode in the second screenshot.
-
- \image icons_find_normal_disabled.png Screenshot of the Find Files
-
- When Qt renders the icon's pixmaps it searches through the set of
- available pixmaps following a particular algorithm. The algorithm
- is documented in QIcon, but we will describe some particular cases
- below.
-
- \image icons_monkey_active.png Screenshot of the Find Files
-
- In the screenshot above, we have set \c monkey_on_32x32 to be an
- Active/On pixmap and \c monkey_off_64x64 to be Normal/Off. To
- render the other six mode/state combinations, QIcon uses the
- search algorithm described in the table below:
-
- \table 100%
- \header \li{2,1} Requested Pixmap \li {8,1} Preferred Alternatives (mode/state)
- \header \li Mode \li State \li 1 \li 2 \li 3 \li 4 \li 5 \li 6 \li 7 \li 8
- \row \li{1,2} Normal \li Off \li \b N0 \li A0 \li N1 \li A1 \li D0 \li S0 \li D1 \li S1
- \row \li On \li N1 \li \b A1 \li N0 \li A0 \li D1 \li S1 \li D0 \li S0
- \row \li{1,2} Active \li Off \li A0 \li \b N0 \li A1 \li N1 \li D0 \li S0 \li D1 \li S1
- \row \li On \li \b A1 \li N1 \li A0 \li N0 \li D1 \li S1 \li D0 \li S0
- \row \li{1,2} Disabled \li Off \li D0 \li \b {N0'} \li A0' \li D1 \li N1' \li A1' \li S0' \li S1'
- \row \li On \li D1 \li N1' \li \b {A1'} \li D0 \li N0' \li A0' \li S1' \li S0'
- \row \li{1,2} Selected \li Off \li S0 \li \b {N0''} \li A0'' \li S1 \li N1'' \li A1'' \li D0'' \li D1''
- \row \li On \li S1 \li N1'' \li \b {A1''} \li S0 \li N0'' \li A0'' \li D1'' \li D0''
- \endtable
-
- In the table, "0" and "1" stand for "Off" and "On", respectively.
- Single quotes indicates that QIcon generates a disabled ("grayed
- out") version of the pixmap; similarly, double quuote indicate
- that QIcon generates a selected ("blued out") version of the
- pixmap.
-
- The alternatives used in the screenshot above are shown in bold.
- For example, the Disabled/Off pixmap is derived by graying out
- the Normal/Off pixmap (\c monkey_off_64x64).
-
- In the next screenshots, we loaded the whole set of monkey
- images. By checking or unchecking file names from the image list,
- we get different results:
-
- \table
- \row
- \li \inlineimage icons_monkey.png Screenshot of the Monkey Files
- \li \inlineimage icons_monkey_mess.png Screenshot of the Monkey Files
- \endtable
-
- For any given mode/state combination, it is possible to specify
- several images at different resolutions. When rendering an
- icon, QIcon will automatically pick the most suitable image
- and scale it down if necessary. (QIcon never scales up images,
- because this rarely looks good.)
-
- The screenshots below shows what happens when we provide QIcon
- with three images (\c qt_extended_16x16.png, \c qt_extended_32x32.png, \c
- qt_extended_48x48.png) and try to render the QIcon at various
- resolutions:
-
- \table
- \row
- \li
- \li \inlineimage icons_qt_extended_8x8.png Qt Extended icon at 8 x 8
- \li \inlineimage icons_qt_extended_16x16.png Qt Extended icon at 16 x 16
- \li \inlineimage icons_qt_extended_17x17.png Qt Extended icon at 17 x 17
- \row
- \li
- \li 8 x 8
- \li \b {16 x 16}
- \li 17 x 17
- \row
- \li \inlineimage icons_qt_extended_32x32.png Qt Extended icon at 32 x 32
- \li \inlineimage icons_qt_extended_33x33.png Qt Extended icon at 33 x 33
- \li \inlineimage icons_qt_extended_48x48.png Qt Extended icon at 48 x 48
- \li \inlineimage icons_qt_extended_64x64.png Qt Extended icon at 64 x 64
- \row
- \li \b {32 x 32}
- \li 33 x 33
- \li \b {48 x 48}
- \li 64 x 64
- \endtable
-
- For sizes up to 16 x 16, QIcon uses \c qt_extended_16x16.png and
- scales it down if necessary. For sizes between 17 x 17 and 32 x
- 32, it uses \c qt_extended_32x32.png. For sizes above 32 x 32, it uses
- \c qt_extended_48x48.png.
-
- \section1 Line-by-Line Walkthrough
-
- The Icons example consists of four classes:
-
- \list
- \li \c MainWindow inherits QMainWindow and is the main application
- window.
- \li \c IconPreviewArea is a custom widget that displays all
- combinations of states and modes for a given icon.
- \li \c IconSizeSpinBox is a subclass of QSpinBox that lets the
- user enter icon sizes (e.g., "48 x 48").
- \li \c ImageDelegate is a subclass of QStyledItemDelegate that
- provides comboboxes for letting the user set the mode and state
- associated with an image.
- \endlist
-
- We will start by reviewing the \c IconPreviewArea class before we
- take a look at the \c MainWindow class. Finally, we will review the
- \c IconSizeSpinBox and \c ImageDelegate classes.
-
- \section2 IconPreviewArea Class Definition
-
- An \c IconPreviewArea widget consists of a group box containing a grid of
- QLabel widgets displaying headers and pixmaps.
-
- \image icons_preview_area.png Screenshot of IconPreviewArea.
-
- \snippet widgets/icons/iconpreviewarea.h 0
-
- The \c IconPreviewArea class inherits QWidget. It displays the
- generated pixmaps corresponding to an icon's possible states and
- modes at a given size.
-
- \snippet widgets/icons/iconpreviewarea.cpp 42
-
- We would like the table columns to be in the order QIcon::Normal,
- QIcon::Active, QIcon::Disabled, QIcon::Selected and the rows in the order
- QIcon::Off, QIcon::On, which does not match the enumeration. The above code
- provides arrays allowing to map from enumeration value to row/column
- (by using QList::indexOf()) and back by using the array index and lists
- of the matching strings. Qt's containers can be easily populated by
- using C++ 11 initializer lists.
-
- We need two public functions to set the current icon and the
- icon's size. In addition the class has three private functions: We
- use the \c createHeaderLabel() and \c createPixmapLabel()
- functions when constructing the preview area, and we need the \c
- updatePixmapLabels() function to update the preview area when
- the icon or the icon's size has changed.
-
- The \c NumModes and \c NumStates constants reflect \l{QIcon}'s
- number of currently defined modes and states.
-
- \section2 IconPreviewArea Class Implementation
-
- \snippet widgets/icons/iconpreviewarea.cpp 0
-
- In the constructor we create the labels displaying the headers and
- the icon's generated pixmaps, and add them to a grid layout.
-
- When creating the header labels, we make sure the enums \c
- NumModes and \c NumStates defined in the \c .h file, correspond
- with the number of labels that we create. Then if the enums at
- some point are changed, the \c Q_ASSERT() macro will alert that this
- part of the \c .cpp file needs to be updated as well.
-
- If the application is built in debug mode, the \c Q_ASSERT()
- macro will expand to
-
- \code
- if (!condition)
- qFatal("ASSERT: "condition" in file ...");
- \endcode
-
- In release mode, the macro simply disappear. The mode can be set
- in the application's \c .pro file. One way to do so is to add an
- option to \c qmake when building the application:
-
- \code
- qmake "CONFIG += debug" icons.pro
- \endcode
-
- or
-
- \code
- qmake "CONFIG += release" icons.pro
- \endcode
-
- Another approach is to add this line directly to the \c .pro
- file.
-
- \snippet widgets/icons/iconpreviewarea.cpp 1
- \codeline
- \snippet widgets/icons/iconpreviewarea.cpp 2
-
- The public \c setIcon() and \c setSize() functions change the icon
- or the icon size, and make sure that the generated pixmaps are
- updated.
-
- \snippet widgets/icons/iconpreviewarea.cpp 3
- \codeline
- \snippet widgets/icons/iconpreviewarea.cpp 4
-
- We use the \c createHeaderLabel() and \c createPixmapLabel()
- functions to create the preview area's labels displaying the
- headers and the icon's generated pixmaps. Both functions return
- the QLabel that is created.
-
- \snippet widgets/icons/iconpreviewarea.cpp 5
-
- We use the private \c updatePixmapLabel() function to update the
- generated pixmaps displayed in the preview area.
-
- For each mode, and for each state, we retrieve a pixmap using the
- QIcon::pixmap() function, which generates a pixmap corresponding
- to the given state, mode and size. We pass the QWindows instance
- obtained by calling QWidget::windowHandle() on the top level
- widget (QWidget::nativeParentWidget()) in order to retrieve
- the pixmap that matches best.
- We format a tooltip displaying size, actual size and device pixel
- ratio.
-
- \section2 MainWindow Class Definition
-
- The \c MainWindow widget consists of three main elements: an
- images group box, an icon size group box and a preview area.
-
- \image icons-example.png Screenshot of the Icons example
-
- \snippet widgets/icons/mainwindow.h 0
-
- The MainWindow class inherits from QMainWindow. We reimplement the
- constructor, and declare several private slots:
-
- \list
- \li The \c about() slot simply provides information about the example.
- \li The \c changeStyle() slot changes the application's GUI style and
- adjust the style dependent size options.
- \li The \c changeSize() slot changes the size of the preview area's icon.
- \li The \c changeIcon() slot updates the set of pixmaps available to the
- icon displayed in the preview area.
- \li The \c addSampleImages() slot allows the user to load a new image
- from the samples provided into the application.
- \li The \c addOtherImages() slot allows the user to load a new image from
- the directory obtained by calling
- QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).
- \li The \c screenChanged() updates the display in the \uicontrol{High DPI}
- group box to correctly display the parameters of the current screen
- the window is located on.
- \endlist
-
- In addition we declare several private functions to simplify the
- constructor.
-
- \section2 MainWindow Class Implementation
-
- \snippet widgets/icons/mainwindow.cpp 0
-
- In the constructor we first create the main window's central
- widget and its child widgets, and put them in a grid layout. Then
- we create the menus with their associated entries and actions.
-
- We set the window title and determine the current style for the
- application. We also enable the icon size spin box by clicking the
- associated radio button, making the current value of the spin box
- the icon's initial size.
-
- \snippet widgets/icons/mainwindow.cpp 1
-
- The \c about() slot displays a message box using the static
- QMessageBox::about() function. In this example it displays a
- simple box with information about the example.
-
- The \c about() function looks for a suitable icon in four
- locations: It prefers its parent's icon if that exists. If it
- doesn't, the function tries the top-level widget containing
- parent, and if that fails, it tries the active window. As a last
- resort it uses the QMessageBox's Information icon.
-
- \snippet widgets/icons/mainwindow.cpp 2
-
- In the \c changeStyle() slot we first check the slot's
- parameter. If it is false we immediately return, otherwise we find
- out which style to change to, i.e. which action that triggered the
- slot, using the QObject::sender() function.
-
- This function returns the sender as a QObject pointer. Since we
- know that the sender is a QAction object, we can safely cast the
- QObject. We could have used a C-style cast or a C++ \c
- static_cast(), but as a defensive programming technique we use a
- \l qobject_cast(). The advantage is that if the object has the
- wrong type, a null pointer is returned. Crashes due to null
- pointers are much easier to diagnose than crashes due to unsafe
- casts.
-
- \snippet widgets/icons/mainwindow.cpp 3
- \snippet widgets/icons/mainwindow.cpp 4
-
- Once we have the action, we extract the style name using
- QAction::data(). Then we create a QStyle object using the static
- QStyleFactory::create() function.
-
- Although we can assume that the style is supported by the
- QStyleFactory: To be on the safe side, we use the \c Q_ASSERT()
- macro to check if the created style is valid before we use the
- QApplication::setStyle() function to set the application's GUI
- style to the new style. QApplication will automatically delete
- the style object when a new style is set or when the application
- exits.
-
- The predefined icon size options provided in the application are
- style dependent, so we need to update the labels in the icon size
- group box and in the end call the \c changeSize() slot to update
- the icon's size.
-
- \snippet widgets/icons/mainwindow.cpp 5
-
- The \c changeSize() slot sets the size for the preview area's
- icon.
-
- It is invoked by the QButtonGroup whose members are radio buttons for
- controlling the icon size. In \c createIconSizeGroupBox(), each button is
- assigned a QStyle::PixelMetric value as an id, which is passed as a
- parameter to the slot.
-
- The special value \c OtherSize indicates that the spin box is
- enabled. If it is, we extract the extent of the new size from the
- box. If it's not, we query the style for the metric. Then we create
- a QSize object based on the extent, and use that object to set the
- size of the preview area's icon.
-
- \snippet widgets/icons/mainwindow.cpp 12
-
- The function \c addImages() is called by the slot addSampleImages()
- passing the samples directory, or by the slot addOtherImages()
- passing the directory obtained by querying
- QStandardPaths::standardLocations().
-
- The first thing we do is to show a file dialog to the user.
- We initialize it to show the filters returned by
- QImageReader::supportedMimeTypes().
-
- For each of the files the file dialog returns, we add a row to the
- table widget. The table widget is listing the images the user has
- loaded into the application.
-
- \snippet widgets/icons/mainwindow.cpp 13
-
- We retrieve the image name using the QFileInfo::baseName()
- function that returns the base name of the file without the path,
- and create the first table widget item in the row.
- We check if a high resolution version of the image exists (identified by
- the suffix \c @2x on the base name) and display that along with the size
- in the tooltip.
-
- We add the file's complete name to the item's data. Since an item can
- hold several information pieces, we need to assign the file name a role
- that will distinguish it from other data. This role can be Qt::UserRole
- or any value above it.
-
- We also make sure that the item is not editable by removing the
- Qt::ItemIsEditable flag. Table items are editable by default.
-
- \snippet widgets/icons/mainwindow.cpp 15
-
- Then we create the second and third items in the row making the
- default mode Normal and the default state Off. But if the \uicontrol
- {Guess Image Mode/State} option is checked, and the file name
- contains "_act", "_dis", or "_sel", the modes are changed to
- Active, Disabled, or Selected. And if the file name contains
- "_on", the state is changed to On. The sample files in the
- example's \c images subdirectory respect this naming convention.
-
- \snippet widgets/icons/mainwindow.cpp 18
-
- In the end we add the items to the associated row, and use the
- QTableWidget::openPersistentEditor() function to create
- comboboxes for the mode and state columns of the items.
-
- Due to the connection between the table widget's \l
- {QTableWidget::itemChanged()}{itemChanged()} signal and the \c
- changeIcon() slot, the new image is automatically converted into a
- pixmap and made part of the set of pixmaps available to the icon
- in the preview area. So, corresponding to this fact, we need to
- make sure that the new image's check box is enabled.
-
- \snippet widgets/icons/mainwindow.cpp 6
-
- The \c changeIcon() slot is called when the user alters the set
- of images listed in the QTableWidget, to update the QIcon object
- rendered by the \c IconPreviewArea.
-
- We first create a QIcon object, and then we run through the
- QTableWidget, which lists the images the user has loaded into the
- application.
-
- \snippet widgets/icons/mainwindow.cpp 8
-
- We also extract the image file's name using the
- QTableWidgetItem::data() function. This function takes a
- Qt::DataItemRole as an argument to retrieve the right data
- (remember that an item can hold several pieces of information)
- and returns it as a QVariant. Then we use the
- QVariant::toString() function to get the file name as a QString.
-
- To create a pixmap from the file, we need to first create an
- image and then convert this image into a pixmap using
- QPixmap::fromImage(). Once we have the final pixmap, we add it,
- with its associated mode and state, to the QIcon's set of
- available pixmaps.
-
- \snippet widgets/icons/mainwindow.cpp 11
-
- After running through the entire list of images, we change the
- icon of the preview area to the one we just created.
-
- \snippet widgets/icons/mainwindow.cpp 20
-
- In the \c removeAllImages() slot, we simply set the table widget's
- row count to zero, automatically removing all the images the user
- has loaded into the application. Then we update the set of pixmaps
- available to the preview area's icon using the \c changeIcon()
- slot.
-
- \image icons_images_groupbox.png Screenshot of the images group box
-
- The \c createImagesGroupBox() function is implemented to simplify
- the constructor. The main purpose of the function is to create a
- QTableWidget that will keep track of the images the user has
- loaded into the application.
-
- \snippet widgets/icons/mainwindow.cpp 21
-
- First we create a group box that will contain the table widget.
- Then we create a QTableWidget and customize it to suit our
- purposes.
-
- We call QAbstractItemView::setSelectionMode() to prevent the user
- from selecting items.
-
- The QAbstractItemView::setItemDelegate() call sets the item
- delegate for the table widget. We create a \c ImageDelegate that
- we make the item delegate for our view.
-
- The QStyledItemDelegate class can be used to provide an editor for an item view
- class that is subclassed from QAbstractItemView. Using a delegate
- for this purpose allows the editing mechanism to be customized and
- developed independently from the model and view.
-
- In this example we derive \c ImageDelegate from QStyledItemDelegate.
- QStyledItemDelegate usually provides line editors, while our subclass
- \c ImageDelegate, provides comboboxes for the mode and state
- fields.
-
- \snippet widgets/icons/mainwindow.cpp 22
-
- Then we customize the QTableWidget's horizontal header, and hide
- the vertical header.
-
- \snippet widgets/icons/mainwindow.cpp 24
-
- At the end, we connect the QTableWidget::itemChanged() signal to
- the \c changeIcon() slot to ensure that the preview area is in
- sync with the image table.
-
- \image icons_size_groupbox.png Screenshot of the icon size group box
-
- The \c createIconSizeGroupBox() function is called from the
- constructor. It creates the widgets controlling the size of the
- preview area's icon.
-
- \snippet widgets/icons/mainwindow.cpp 26
-
- First we create a group box that will contain all the widgets;
- then we create the radio buttons and the spin box. We add the
- radio buttons to an instance of QButtonGroup, using the value
- of the QStyle::PixelMetric they represent as an integer id.
-
- \snippet widgets/icons/mainwindow.cpp 40
-
- We introduce an enumeration constant \c OtherSize to represent
- a custom size.
-
- The spin box is not a regular QSpinBox but an \c IconSizeSpinBox.
- The \c IconSizeSpinBox class inherits QSpinBox and reimplements
- two functions: QSpinBox::textFromValue() and
- QSpinBox::valueFromText(). The \c IconSizeSpinBox is designed to
- handle icon sizes, e.g., "32 x 32", instead of plain integer
- values.
-
- \snippet widgets/icons/mainwindow.cpp 27
-
- Then we connect all of the radio buttons
- \l{QRadioButton::toggled()}{toggled()} signals and the spin box's
- \l {QSpinBox::valueChanged()}{valueChanged()} signal to the \c
- changeSize() slot to make sure that the size of the preview
- area's icon is updated whenever the user changes the icon size.
- In the end we put the widgets in a layout that we install on the
- group box.
-
- \snippet widgets/icons/mainwindow.cpp 28
-
- In the \c createActions() function we create and customize all the
- actions needed to implement the functionality associated with the
- menu entries in the application.
-
- In particular we create the \c styleActionGroup based on the
- currently available GUI styles using
- QStyleFactory. QStyleFactory::keys() returns a list of valid keys,
- typically including "windows" and "fusion". Depending on the platform,
- "windowsvista" and "macos" may be available.
-
- We create one action for each key, and adds the action to the
- action group. Also, for each action, we call QAction::setData()
- with the style name. We will retrieve it later using
- QAction::data().
-
- As we go along, we create the \uicontrol File, \uicontrol View and
- \uicontrol Help menus and add the actions to them.
-
- The QMenu class provides a menu widget for use in menu bars,
- context menus, and other popup menus. We put each menu in the
- application's menu bar, which we retrieve using
- QMainWindow::menuBar().
-
- \snippet widgets/icons/mainwindow.cpp 30
-
- QWidgets have a \l{QWidget::contextMenuPolicy}{contextMenuPolicy}
- property that controls how the widget should behave when the user
- requests a context menu (e.g., by right-clicking). We set the
- QTableWidget's context menu policy to Qt::ActionsContextMenu,
- meaning that the \l{QAction}s associated with the widget should
- appear in its context menu.
-
- Then we add the \uicontrol{Add Image} and \uicontrol{Remove All Images}
- actions to the table widget. They will then appear in the table
- widget's context menu.
-
- \snippet widgets/icons/mainwindow.cpp 31
-
- In the \c checkCurrentStyle() function we go through the group of
- style actions, looking for the current GUI style.
-
- For each action, we first extract the style name using
- QAction::data(). Since this is only a QStyleFactory key (e.g.,
- "macos"), we cannot compare it directly to the current
- style's class name. We need to create a QStyle object using the
- static QStyleFactory::create() function and compare the class
- name of the created QStyle object with that of the current style.
- As soon as we are done with a QStyle candidate, we delete it.
-
- For all QObject subclasses that use the \c Q_OBJECT macro, the
- class name of an object is available through its
- \l{QObject::metaObject()}{meta-object}.
-
- We can assume that the style is supported by
- QStyleFactory, but to be on the safe side we use the \c
- Q_ASSERT() macro to make sure that QStyleFactory::create()
- returned a valid pointer.
-
- \snippet widgets/icons/mainwindow.cpp 44
-
- We overload the show() function to set up the updating of the
- current screen in \c screenChanged(). After calling QWidget::show(),
- the QWindow associated with the QWidget is created and we can
- connect to its QWindow::screenChanged() signal.
-
- \section2 IconSizeSpinBox Class Definition
-
- \snippet widgets/icons/iconsizespinbox.h 0
-
- The \c IconSizeSpinBox class is a subclass of QSpinBox. A plain
- QSpinBox can only handle integers. But since we want to display
- the spin box's values in a more sophisticated way, we need to
- subclass QSpinBox and reimplement the QSpinBox::textFromValue()
- and QSpinBox::valueFromText() functions.
-
- \image icons_size_spinbox.png Screenshot of the icon size spinbox
-
- \section2 IconSizeSpinBox Class Implementation
-
- \snippet widgets/icons/iconsizespinbox.cpp 0
-
- The constructor is trivial.
-
- \snippet widgets/icons/iconsizespinbox.cpp 2
-
- QSpinBox::textFromValue() is used by the spin box whenever it
- needs to display a value. The default implementation returns a
- base 10 representation of the \c value parameter.
-
- Our reimplementation returns a QString of the form "32 x 32".
-
- \snippet widgets/icons/iconsizespinbox.cpp 1
-
- The QSpinBox::valueFromText() function is used by the spin box
- whenever it needs to interpret text typed in by the user. Since
- we reimplement the \c textFromValue() function we also need to
- reimplement the \c valueFromText() function to interpret the
- parameter text and return the associated int value.
-
- We parse the text using a regular expression (a QRegularExpression). We
- define an expression that matches one or several digits,
- optionally followed by whitespace, an "x" or the times symbol,
- whitespace and one or several digits again.
-
- The first digits of the regular expression are captured using
- parentheses. This enables us to use the QRegularExpressionMatch::captured()
- or QRegularExpressionMatch::capturedTexts() functions to extract the matched
- characters. If the first and second numbers of the spin box value
- differ (e.g., "16 x 24"), we use the first number.
-
- When the user presses \uicontrol Enter, QSpinBox first calls
- QSpinBox::valueFromText() to interpret the text typed by the
- user, then QSpinBox::textFromValue() to present it in a canonical
- format (e.g., "16 x 16").
-
- \section2 ImageDelegate Class Definition
-
- \snippet widgets/icons/imagedelegate.h 0
-
- The \c ImageDelegate class is a subclass of QStyledItemDelegate. The
- QStyledItemDelegate class provides display and editing facilities for
- data items from a model. A single QStyledItemDelegate object is
- responsible for all items displayed in a item view (in our case,
- a QTableWidget).
-
- A QStyledItemDelegate can be used to provide an editor for an item view
- class that is subclassed from QAbstractItemView. Using a delegate
- for this purpose allows the editing mechanism to be customized and
- developed independently from the model and view.
-
- \snippet widgets/icons/imagedelegate.h 1
-
- The default implementation of QStyledItemDelegate creates a QLineEdit.
- Since we want the editor to be a QComboBox, we need to subclass
- QStyledItemDelegate and reimplement the QStyledItemDelegate::createEditor(),
- QStyledItemDelegate::setEditorData() and QStyledItemDelegate::setModelData()
- functions.
-
- \snippet widgets/icons/imagedelegate.h 2
-
- The \c emitCommitData() slot is used to emit the
- QImageDelegate::commitData() signal with the appropriate
- argument.
-
- \section2 ImageDelegate Class Implementation
-
- \snippet widgets/icons/imagedelegate.cpp 0
-
- The constructor is trivial.
-
- \snippet widgets/icons/imagedelegate.cpp 1
-
- The default QStyledItemDelegate::createEditor() implementation returns
- the widget used to edit the item specified by the model and item
- index for editing. The parent widget and style option are used to
- control the appearance of the editor widget.
-
- Our reimplementation creates and populates a combobox instead of
- the default line edit. The contents of the combobox depends on
- the column in the table for which the editor is requested. Column
- 1 contains the QIcon modes, whereas column 2 contains the QIcon
- states.
-
- In addition, we connect the combobox's \l
- {QComboBox::activated()}{activated()} signal to the \c
- emitCommitData() slot to emit the
- QAbstractItemDelegate::commitData() signal whenever the user
- chooses an item using the combobox. This ensures that the rest of
- the application notices the change and updates itself.
-
- \snippet widgets/icons/imagedelegate.cpp 2
-
- The QStyledItemDelegate::setEditorData() function is used by
- QTableWidget to transfer data from a QTableWidgetItem to the
- editor. The data is stored as a string; we use
- QComboBox::findText() to locate it in the combobox.
-
- Delegates work in terms of models, not items. This makes it
- possible to use them with any item view class (e.g., QListView,
- QListWidget, QTreeView, etc.). The transition between model and
- items is done implicitly by QTableWidget; we don't need to worry
- about it.
-
- \snippet widgets/icons/imagedelegate.cpp 3
-
- The QStyledItemDelegate::setEditorData() function is used by QTableWidget
- to transfer data back from the editor to the \l{QTableWidgetItem}.
-
- \snippet widgets/icons/imagedelegate.cpp 4
-
- The \c emitCommitData() slot simply emit the
- QAbstractItemDelegate::commitData() signal for the editor that
- triggered the slot. This signal must be emitted when the editor
- widget has completed editing the data, and wants to write it back
- into the model.
-
- \section2 The Implementation of the Function main()
-
- \snippet widgets/icons/main.cpp 45
-
- We use QCommandLineParser to handle any command line options or parameters
- passed to the application. Then, we resize the main window according
- to the available screen geometry and show it.
-*/
diff --git a/examples/widgets/doc/src/imagecomposition.qdoc b/examples/widgets/doc/src/imagecomposition.qdoc
index 3b192f378e..9eec57ca88 100644
--- a/examples/widgets/doc/src/imagecomposition.qdoc
+++ b/examples/widgets/doc/src/imagecomposition.qdoc
@@ -4,6 +4,7 @@
/*!
\example painting/imagecomposition
\title Image Composition Example
+ \examplecategory {Graphics}
\ingroup examples-painting
\ingroup examples-layout
\brief Shows how composition modes work in QPainter.
diff --git a/examples/widgets/doc/src/imageviewer.qdoc b/examples/widgets/doc/src/imageviewer.qdoc
deleted file mode 100644
index aa6eec46d8..0000000000
--- a/examples/widgets/doc/src/imageviewer.qdoc
+++ /dev/null
@@ -1,320 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/imageviewer
- \title Image Viewer Example
- \ingroup examples-widgets
- \brief The example shows how to combine QLabel and QScrollArea to
- display an image.
-
- QLabel is typically used for displaying text,
- but it can also display an image. QScrollArea provides a
- scrolling view around another widget. If the child widget exceeds
- the size of the frame, QScrollArea automatically provides scroll
- bars.
-
- The example demonstrates how QLabel's ability to scale its
- contents (QLabel::scaledContents), and QScrollArea's ability to
- automatically resize its contents (QScrollArea::widgetResizable),
- can be used to implement zooming and scaling features. In
- addition the example shows how to use QPainter to print an image.
-
- \borderedimage imageviewer-example.png
- \caption Screenshot of the Image Viewer example
-
- With the Image Viewer application, the users can view an image of
- their choice. The \uicontrol File menu gives the user the possibility
- to:
-
- \list
- \li \uicontrol{Open...} - Open an image file
- \li \uicontrol{Print...} - Print an image
- \li \uicontrol{Exit} - Exit the application
- \endlist
-
- Once an image is loaded, the \uicontrol View menu allows the users to:
-
- \list
- \li \uicontrol{Zoom In} - Scale the image up by 25%
- \li \uicontrol{Zoom Out} - Scale the image down by 25%
- \li \uicontrol{Normal Size} - Show the image at its original size
- \li \uicontrol{Fit to Window} - Stretch the image to occupy the entire window
- \endlist
-
- In addition the \uicontrol Help menu provides the users with information
- about the Image Viewer example in particular, and about Qt in
- general.
-
- \section1 ImageViewer Class Definition
-
- \snippet widgets/imageviewer/imageviewer.h 0
-
- The \c ImageViewer class inherits from QMainWindow. We reimplement
- the constructor, and create several private slots to facilitate
- the menu entries. In addition we create four private functions.
-
- We use \c createActions() and \c createMenus() when constructing
- the \c ImageViewer widget. We use the \c updateActions() function
- to update the menu entries when a new image is loaded, or when
- the \uicontrol {Fit to Window} option is toggled. The zoom slots use \c
- scaleImage() to perform the zooming. In turn, \c
- scaleImage() uses \c adjustScrollBar() to preserve the focal point after
- scaling an image.
-
- \section1 ImageViewer Class Implementation
-
- \snippet widgets/imageviewer/imageviewer.cpp 0
-
- In the constructor we first create the label and the scroll area.
-
- We set \c {imageLabel}'s size policy to \l
- {QSizePolicy::Ignored}{ignored}, making the users able to scale
- the image to whatever size they want when the \uicontrol {Fit to Window}
- option is turned on. Otherwise, the default size polizy (\l
- {QSizePolicy::Preferred}{preferred}) will make scroll bars appear
- when the scroll area becomes smaller than the label's minimum size
- hint.
-
- We ensure that the label will scale its contents to fill all
- available space, to enable the image to scale properly when
- zooming. If we omitted to set the \c {imageLabel}'s \l
- {QLabel::scaledContents}{scaledContents} property, zooming in
- would enlarge the QLabel, but leave the pixmap at
- its original size, exposing the QLabel's background.
-
- We make \c imageLabel the scroll area's child widget, and we make
- \c scrollArea the central widget of the QMainWindow. At the end
- we create the associated actions and menus, and customize the \c
- {ImageViewer}'s appearance.
-
- \snippet widgets/imageviewer/imageviewer.cpp 1
-
- In the \c open() slot, we show a file dialog to the user. We compile
- a list of mime types for use as a filter by querying QImageReader
- for the available mime type names.
-
- We show the file dialog until a valid file name is entered or
- the user cancels.
-
- The function \c loadFile() is used to load the image.
-
- \snippet widgets/imageviewer/imageviewer.cpp 2
-
- In the \c loadFile() function, we instantiate a QImageReader
- and enable automatic transformations by calling
- QImageReader::setAutoTransform(). For files in JPEG format,
- this ensures that portrait mode images of digital cameras are shown
- correctly by applying the appropriate orientation read from the
- EXIF meta data stored in the image file.
-
- We then load the image using QImageReader::read(). If this returns
- a null image, indicating that the file is not an image file,
- we use a QMessageBox to alert the user.
-
- The QMessageBox class provides a modal dialog with a short
- message, an icon, and some buttons. As with QFileDialog the
- easiest way to create a QMessageBox is to use its static
- convenience functions. QMessageBox provides a range of different
- messages arranged along two axes: severity (question,
- information, warning and critical) and complexity (the number of
- necessary response buttons). In this particular example an
- information message with an \uicontrol OK button (the default) is
- sufficient, since the message is part of a normal operation.
-
- \snippet widgets/imageviewer/imageviewer.cpp 4
-
- If the format is supported, we display the image in \c imageLabel
- by setting the label's \l {QLabel::pixmap}{pixmap}. Then we enable
- the \uicontrol Print and \uicontrol {Fit to Window} menu entries and update
- the rest of the view menu entries. The \uicontrol Open and \uicontrol Exit
- entries are enabled by default.
-
- If the \uicontrol {Fit to Window} option is turned off, the
- QScrollArea::widgetResizable property is \c false and it is
- our responsibility (not QScrollArea's) to give the QLabel a
- reasonable size based on its contents. We call
- \{QWidget::adjustSize()}{adjustSize()} to achieve this, which is
- essentially the same as
-
- \code
- imageLabel->resize(imageLabel->pixmap()->size());
- \endcode
-
- In the \c print() slot, we first make sure that an image has been
- loaded into the application:
-
- \snippet widgets/imageviewer/imageviewer.cpp 5
- \snippet widgets/imageviewer/imageviewer.cpp 6
-
- If the application is built in debug mode, the \c Q_ASSERT() macro
- will expand to
-
- \code
- if (imageLabel->pixmap().isNull())
- qFatal("ASSERT: "imageLabel->pixmap().isNull()" in file ...");
- \endcode
-
- In release mode, the macro simply disappear. The mode can be set
- in the application's \c .pro file. One way to do so is to add an
- option to \uicontrol qmake when building the application:
-
- \code
- qmake "CONFIG += debug" foo.pro
- \endcode
-
- or
-
- \code
- qmake "CONFIG += release" foo.pro
- \endcode
-
- Another approach is to add this line directly to the \c .pro
- file.
-
- \snippet widgets/imageviewer/imageviewer.cpp 7
- \snippet widgets/imageviewer/imageviewer.cpp 8
-
- Then we present a print dialog allowing the user to choose a
- printer and to set a few options. We construct a painter with a
- QPrinter as the paint device. We set the painter's window
- and viewport in such a way that the image is as large as possible
- on the paper, but without altering its
- \l{Qt::KeepAspectRatio}{aspect ratio}.
-
- In the end we draw the pixmap at position (0, 0).
-
- \snippet widgets/imageviewer/imageviewer.cpp 9
- \snippet widgets/imageviewer/imageviewer.cpp 10
-
- We implement the zooming slots using the private \c scaleImage()
- function. We set the scaling factors to 1.25 and 0.8,
- respectively. These factor values ensure that a \uicontrol {Zoom In}
- action and a \uicontrol {Zoom Out} action will cancel each other (since
- 1.25 * 0.8 == 1), and in that way the normal image size can be
- restored using the zooming features.
-
- The screenshots below show an image in its normal size, and the
- same image after zooming in:
-
- \table
- \row
- \li \inlineimage imageviewer-original_size.png
- \li \inlineimage imageviewer-zoom_in_1.png
- \li \inlineimage imageviewer-zoom_in_2.png
- \endtable
-
- \snippet widgets/imageviewer/imageviewer.cpp 11
- \snippet widgets/imageviewer/imageviewer.cpp 12
-
- When zooming, we use the QLabel's ability to scale its contents.
- Such scaling doesn't change the actual size hint of the contents.
- And since the \l {QLabel::adjustSize()}{adjustSize()} function
- use those size hint, the only thing we need to do to restore the
- normal size of the currently displayed image is to call \c
- adjustSize() and reset the scale factor to 1.0.
-
- \snippet widgets/imageviewer/imageviewer.cpp 13
- \snippet widgets/imageviewer/imageviewer.cpp 14
-
- The \c fitToWindow() slot is called each time the user toggled
- the \uicontrol {Fit to Window} option. If the slot is called to turn on
- the option, we tell the scroll area to resize its child widget
- with the QScrollArea::setWidgetResizable() function. Then we
- disable the \uicontrol {Zoom In}, \uicontrol {Zoom Out} and \uicontrol {Normal
- Size} menu entries using the private \c updateActions() function.
-
- If the \l {QScrollArea::widgetResizable} property is set to \c
- false (the default), the scroll area honors the size of its child
- widget. If this property is set to \c true, the scroll area will
- automatically resize the widget in order to avoid scroll bars
- where they can be avoided, or to take advantage of extra space.
- But the scroll area will honor the minimum size hint of its child
- widget independent of the widget resizable property. So in this
- example we set \c {imageLabel}'s size policy to \l
- {QSizePolicy::Ignored}{ignored} in the constructor, to avoid that
- scroll bars appear when the scroll area becomes smaller than the
- label's minimum size hint.
-
- The screenshots below shows an image in its normal size, and the
- same image with the \uicontrol {Fit to window} option turned on.
- Enlarging the window will stretch the image further, as shown in
- the third screenshot.
-
- \table
- \row
- \li \inlineimage imageviewer-original_size.png
- \li \inlineimage imageviewer-fit_to_window_1.png
- \li \inlineimage imageviewer-fit_to_window_2.png
- \endtable
-
- If the slot is called to turn off the option, the
- {QScrollArea::setWidgetResizable} property is set to \c false. We
- also restore the image pixmap to its normal size by adjusting the
- label's size to its content. And in the end we update the view
- menu entries.
-
- \snippet widgets/imageviewer/imageviewer.cpp 15
- \snippet widgets/imageviewer/imageviewer.cpp 16
-
- We implement the \c about() slot to create a message box
- describing what the example is designed to show.
-
- \snippet widgets/imageviewer/imageviewer.cpp 17
- \snippet widgets/imageviewer/imageviewer.cpp 18
-
- In the private \c createAction() function, we create the
- actions providing the application features and populate
- a menu with them.
-
- We assign a short-cut key to each action and connect them to the
- appropriate slots. We only enable the \c openAct and \c exitAct at
- the time of creation, the others are updated once an image has
- been loaded into the application. In addition we make the \c
- fitToWindowAct \l {QAction::checkable}{checkable}.
-
- The QMenu class provides a menu widget for use in menu bars,
- context menus, and other popup menus. The QMenuBar class provides
- a horizontal menu bar that consists of a list of pull-down menu
- items. So we put the menus in the \c {ImageViewer}'s
- menu bar which we retrieve with the QMainWindow::menuBar()
- function.
-
- \snippet widgets/imageviewer/imageviewer.cpp 21
- \snippet widgets/imageviewer/imageviewer.cpp 22
-
- The private \c updateActions() function enables or disables the
- \uicontrol {Zoom In}, \uicontrol {Zoom Out} and \uicontrol {Normal Size} menu
- entries depending on whether the \uicontrol {Fit to Window} option is
- turned on or off.
-
- \snippet widgets/imageviewer/imageviewer.cpp 23
- \snippet widgets/imageviewer/imageviewer.cpp 24
-
- In \c scaleImage(), we use the \c factor parameter to calculate
- the new scaling factor for the displayed image, and resize \c
- imageLabel. Since we set the
- \l{QLabel::scaledContents}{scaledContents} property to \c true in
- the constructor, the call to QWidget::resize() will scale the
- image displayed in the label. We also adjust the scroll bars to
- preserve the focal point of the image.
-
- At the end, if the scale factor is less than 33.3% or greater
- than 300%, we disable the respective menu entry to prevent the
- image pixmap from becoming too large, consuming too much
- resources in the window system.
-
- \snippet widgets/imageviewer/imageviewer.cpp 25
- \snippet widgets/imageviewer/imageviewer.cpp 26
-
- Whenever we zoom in or out, we need to adjust the scroll bars in
- consequence. It would have been tempting to simply call
-
- \code
- scrollBar->setValue(int(factor * scrollBar->value()));
- \endcode
-
- but this would make the top-left corner the focal point, not the
- center. Therefore we need to take into account the scroll bar
- handle's size (the \l{QScrollBar::pageStep}{page step}).
-*/
diff --git a/examples/widgets/doc/src/interview.qdoc b/examples/widgets/doc/src/interview.qdoc
deleted file mode 100644
index 328e4fc92b..0000000000
--- a/examples/widgets/doc/src/interview.qdoc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/interview
- \title Interview
- \ingroup examples-itemviews
- \brief This example demonstrates the usage of the model/view framework.
-
- \brief The Interview example explores the flexibility and scalability of the
- model/view framework by presenting an infinitely deep data structure using a model
- and three different types of view.
-
- \image interview-demo.png
-*/
diff --git a/examples/widgets/doc/src/itemviewspuzzle.qdoc b/examples/widgets/doc/src/itemviewspuzzle.qdoc
deleted file mode 100644
index c1e0c361d6..0000000000
--- a/examples/widgets/doc/src/itemviewspuzzle.qdoc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/puzzle
- \title Item Views Puzzle Example
- \ingroup examples-itemviews
- \brief The Puzzle example shows how to enable drag and drop with a custom model
- to allow items to be transferred between a view and another widget.
-
- \image itemviewspuzzle-example.png
-
- This example is an implementation of a simple jigsaw puzzle game using the
- built-in support for drag and drop provided by Qt's model/view framework.
- The \l{Drag and Drop Puzzle Example}{Drag and Drop Puzzle} example shows
- many of the same features, but takes an alternative approach that uses Qt's
- drag and drop API at the application level to handle drag and drop
- operations.
-*/
diff --git a/examples/widgets/doc/src/licensewizard.qdoc b/examples/widgets/doc/src/licensewizard.qdoc
index 036572d679..66c822e421 100644
--- a/examples/widgets/doc/src/licensewizard.qdoc
+++ b/examples/widgets/doc/src/licensewizard.qdoc
@@ -4,6 +4,7 @@
/*!
\example dialogs/licensewizard
\title License Wizard Example
+ \examplecategory {User Interface Components}
\ingroup examples-dialogs
\brief The License Wizard example shows how to implement complex wizards in
diff --git a/examples/widgets/doc/src/lineedits.qdoc b/examples/widgets/doc/src/lineedits.qdoc
index c268f473e3..7065a5f425 100644
--- a/examples/widgets/doc/src/lineedits.qdoc
+++ b/examples/widgets/doc/src/lineedits.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/lineedits
\title Line Edits Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The Line Edits example demonstrates the many ways that QLineEdit
can be used, and shows the effects of various properties and validators
diff --git a/examples/widgets/doc/src/mainwindow.qdoc b/examples/widgets/doc/src/mainwindow.qdoc
deleted file mode 100644
index ca2840123d..0000000000
--- a/examples/widgets/doc/src/mainwindow.qdoc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example mainwindows/mainwindow
- \title Main Window
- \ingroup examples-mainwindow
-
- \brief The Main Window example shows Qt's extensive support for tool bars,
- dock windows, menus, and other standard application features.
-
- \image mainwindow-demo.png
-*/
diff --git a/examples/widgets/doc/src/mdi.qdoc b/examples/widgets/doc/src/mdi.qdoc
deleted file mode 100644
index 23daeeb9bd..0000000000
--- a/examples/widgets/doc/src/mdi.qdoc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example mainwindows/mdi
- \title MDI Example
- \ingroup examples-mainwindow
-
- \brief The MDI example shows how to implement a Multiple Document Interface using Qt's
- QMdiArea class.
-
- \image mdi-example.png
-
-*/
diff --git a/examples/widgets/doc/src/menus.qdoc b/examples/widgets/doc/src/menus.qdoc
index 2bffd17b6b..b78d394691 100644
--- a/examples/widgets/doc/src/menus.qdoc
+++ b/examples/widgets/doc/src/menus.qdoc
@@ -4,6 +4,7 @@
/*!
\example mainwindows/menus
\title Menus Example
+ \examplecategory {User Interface Components}
\ingroup examples-mainwindow
\ingroup examples-layout
@@ -119,7 +120,8 @@
using the provided convenience functions.
In the \c createActions() function, we first create a \c newAct
- action. We make \uicontrol Ctrl+N its shortcut using the
+ action, passing the text and and an icon using one of the theme
+ icon constants. We make \uicontrol Ctrl+N its shortcut using the
QAction::setShortcut() function, and we set its status tip using the
QAction::setStatusTip() function (the status tip is displayed on all
status bars provided by the action's top-level parent widget). We
diff --git a/examples/widgets/doc/src/movie.qdoc b/examples/widgets/doc/src/movie.qdoc
deleted file mode 100644
index d5aebc4156..0000000000
--- a/examples/widgets/doc/src/movie.qdoc
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/movie
- \title Movie Example
- \ingroup examples-widgets
- \brief The Movie example demonstrates how to use QMovie and QLabel to
- display animations.
-
- QMovie is mostly useful if one wants to play
- a simple animation without the added complexity of a multimedia
- framework to install and deploy.
-
- \borderedimage movie-example.png
-*/
diff --git a/examples/widgets/doc/src/orderform.qdoc b/examples/widgets/doc/src/orderform.qdoc
index 529ed6d24b..7ae89dfda8 100644
--- a/examples/widgets/doc/src/orderform.qdoc
+++ b/examples/widgets/doc/src/orderform.qdoc
@@ -4,6 +4,7 @@
/*!
\example richtext/orderform
\title Order Form Example
+ \examplecategory {User Interface Components}
\ingroup examples-richtext
\brief The Order Form example shows how to generate rich text
documents by combining a simple template with data input by the
diff --git a/examples/widgets/doc/src/painterpaths.qdoc b/examples/widgets/doc/src/painterpaths.qdoc
index 55e78c849d..305a7608e5 100644
--- a/examples/widgets/doc/src/painterpaths.qdoc
+++ b/examples/widgets/doc/src/painterpaths.qdoc
@@ -4,12 +4,10 @@
/*!
\example painting/painterpaths
\title Painter Paths Example
+ \examplecategory {Graphics}
\ingroup examples-painting
- \brief The Painter Paths example shows how painter paths can be
- used to beuild complex shapes for rendering.
-
- \brief The Painter Paths example shows how painter paths can be used to
- build complex shapes for rendering.
+ \brief The Painter Paths example shows how to use painter paths
+ to build complex shapes for rendering.
\image painterpaths-example.png
@@ -103,7 +101,7 @@
explicitly start a new subpath using the QPainterPath::moveTo()
function.
- QPainterPath also provide the QPainterPath::addRect() convenience
+ QPainterPath also provides the QPainterPath::addRect() convenience
function, which adds a given rectangle to the path as a closed
subpath. The rectangle is added as a clockwise set of lines. The
painter path's current position after the rect has been added is
@@ -151,7 +149,7 @@
Constructing a polygon is equivalent to constructing a rectangle.
- QPainterPath also provide the QPainterPath::addPolygon()
+ QPainterPath also provides the QPainterPath::addPolygon()
convenience function which adds the given polygon to the path as a
new subpath. Current position after the polygon has been added is
the last point in polygon.
diff --git a/examples/widgets/doc/src/pathstroke.qdoc b/examples/widgets/doc/src/pathstroke.qdoc
index 01c3771d24..bc4001ebb5 100644
--- a/examples/widgets/doc/src/pathstroke.qdoc
+++ b/examples/widgets/doc/src/pathstroke.qdoc
@@ -4,6 +4,7 @@
/*!
\example painting/pathstroke
\title Path Stroking
+ \examplecategory {Graphics}
\ingroup examples-painting
\brief The Path Stroking example shows various types of pens that
can be used with QPainter.
diff --git a/examples/widgets/doc/src/pixelator.qdoc b/examples/widgets/doc/src/pixelator.qdoc
deleted file mode 100644
index ab6f639d87..0000000000
--- a/examples/widgets/doc/src/pixelator.qdoc
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/pixelator
- \title Pixelator Example
- \ingroup examples-itemviews
- \brief The Pixelator example shows how delegates can be used to customize the way that
- items are rendered in standard item views.
-
- \image pixelator-example.png
-
- By default, QTreeView, QTableView, and QListView use a standard item delegate
- to display and edit a set of common data types that are sufficient for many
- applications. However, an application may need to represent items of data in a
- particular way, or provide support for rendering more specialized data types,
- and this often requires the use of a custom delegate.
-
- In this example, we show how to use custom delegates to modify the appearance
- of standard views. To do this, we implement the following components:
-
- \list
- \li A model which represents each pixel in an image as an item of data, where each
- item contains a value for the brightness of the corresponding pixel.
- \li A custom delegate that uses the information supplied by the model to represent
- each pixel as a black circle on a white background, where the radius of the
- circle corresponds to the darkness of the pixel.
- \endlist
-
- This example may be useful for developers who want to implement their own table
- models or custom delegates. The process of creating custom delegates for editing
- item data is covered in the \l{Spin Box Delegate Example}{Spin Box Delegate}
- example.
-
- \section1 ImageModel Class Definition
-
- The \c ImageModel class is defined as follows:
-
- \snippet itemviews/pixelator/imagemodel.h 0
-
- Since we only require a simple, read-only table model, we only need to implement
- functions to indicate the dimensions of the image and supply data to other
- components.
-
- \section1 ImageModel Class Implementation
-
- The constructor is trivial:
-
- \snippet itemviews/pixelator/imagemodel.cpp 0
-
- The \c setImage() function sets the image that will be used by the model:
-
- \snippet itemviews/pixelator/imagemodel.cpp 1
-
- The QAbstractItemModel::reset() call tells the view(s) that the model
- has changed.
-
- The \c rowCount() and \c columnCount() functions return the height and width of
- the image respectively:
-
- \snippet itemviews/pixelator/imagemodel.cpp 2
- \snippet itemviews/pixelator/imagemodel.cpp 3
-
- Since the image is a simple two-dimensional structure, the \c parent arguments
- to these functions are unused. They both simply return the relevant size from
- the underlying image object.
-
- The \c data() function returns data for the item that corresponds to a given
- model index in a format that is suitable for a particular role:
-
- \snippet itemviews/pixelator/imagemodel.cpp 4
-
- In this implementation, we only check that the model index is valid, and that
- the role requested is the \l{Qt::ItemDataRole}{DisplayRole}. If so, the function
- returns the grayscale value of the relevant pixel in the image; otherwise, a null
- model index is returned.
-
- This model can be used with QTableView to display the integer brightness values
- for the pixels in the image. However, we will implement a custom delegate to
- display this information in a more artistic way.
-
- The \c headerData() function is also reimplemented:
-
- \snippet itemviews/pixelator/imagemodel.cpp 5
-
- We return (1, 1) as the size hint for a header item. If we
- didn't, the headers would default to a larger size, preventing
- us from displaying really small items (which can be specified
- using the \uicontrol{Pixel size} combobox).
-
- \section1 PixelDelegate Class Definition
-
- The \c PixelDelegate class is defined as follows:
-
- \snippet itemviews/pixelator/pixeldelegate.h 0
-
- This class provides only basic features for a delegate so, unlike the
- \l{Spin Box Delegate Example}{Spin Box Delegate} example, we subclass
- QAbstractItemDelegate instead of QItemDelegate.
-
- We only need to reimplement \l{QAbstractItemDelegate::paint()}{paint()} and
- \l{QAbstractItemDelegate::sizeHint()}{sizeHint()} in this class.
- However, we also provide a delegate-specific \c setPixelSize() function so
- that we can change the delegate's behavior via the signals and slots mechanism.
-
- \section1 PixelDelegate Class Implementation
-
- The \c PixelDelegate constructor is used to set up a default value for
- the size of each "pixel" that it renders. The base class constructor is
- also called to ensure that the delegate is set up with a parent object,
- if one is supplied:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 0
-
- Each item is rendered by the delegate's
- \l{QAbstractItemDelegate::paint()}{paint()} function. The view calls this
- function with a ready-to-use QPainter object, style information that the
- delegate should use to correctly draw the item, and an index to the item in
- the model:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 1
-
- The first task the delegate has to perform is to draw the item's background
- correctly. Usually, selected items appear differently to non-selected items,
- so we begin by testing the state passed in the style option and filling the
- background if necessary.
-
- The radius of each circle is calculated in the following lines of code:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 3
- \snippet itemviews/pixelator/pixeldelegate.cpp 4
-
- First, the largest possible radius of the circle is determined by taking the
- smallest dimension of the style option's \c rect attribute.
- Using the model index supplied, we obtain a value for the brightness of the
- relevant pixel in the image. The radius of the circle is calculated by
- scaling the brightness to fit within the item and subtracting it from the
- largest possible radius.
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 5
- \snippet itemviews/pixelator/pixeldelegate.cpp 6
- \snippet itemviews/pixelator/pixeldelegate.cpp 7
-
- We save the painter's state, turn on antialiasing (to obtain smoother
- curves), and turn off the pen.
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 8
- \snippet itemviews/pixelator/pixeldelegate.cpp 9
-
- The foreground of the item (the circle representing a pixel) must be
- rendered using an appropriate brush. For unselected items, we will use a
- solid black brush; selected items are drawn using a predefined brush from
- the style option's palette.
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 10
-
- Finally, we paint the circle within the rectangle specified by the style
- option and we call \l{QPainter::}{restore()} on the painter.
-
- The \c paint() function does not have to be particularly complicated; it is
- only necessary to ensure that the state of the painter when the function
- returns is the same as it was when it was called. This usually
- means that any transformations applied to the painter must be preceded by
- a call to QPainter::save() and followed by a call to QPainter::restore().
-
- The delegate's \l{QAbstractItemDelegate::}{sizeHint()} function
- returns a size for the item based on the predefined pixel size, initially set
- up in the constructor:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 11
-
- The delegate's size is updated whenever the pixel size is changed.
- We provide a custom slot to do this:
-
- \snippet itemviews/pixelator/pixeldelegate.cpp 12
-
- \section1 Using The Custom Delegate
-
- In this example, we use a main window to display a table of data, using the
- custom delegate to render each cell in a particular way. Much of the
- \c MainWindow class performs tasks that are not related to item views. Here,
- we only quote the parts that are relevant. You can look at the rest of the
- implementation by following the links to the code at the top of this
- document.
-
- In the constructor, we set up a table view, turn off its grid, and hide its
- headers:
-
- \snippet itemviews/pixelator/mainwindow.cpp 0
- \dots
- \snippet itemviews/pixelator/mainwindow.cpp 1
-
- This enables the items to be drawn without any gaps between them. Removing
- the headers also prevents the user from adjusting the sizes of individual
- rows and columns.
-
- We also set the minimum section size to 1 on the headers. If we
- didn't, the headers would default to a larger size, preventing
- us from displaying really small items (which can be specified
- using the \uicontrol{Pixel size} combobox).
-
- The custom delegate is constructed with the main window as its parent, so
- that it will be deleted correctly later, and we set it on the table view.
-
- \snippet itemviews/pixelator/mainwindow.cpp 2
-
- Each item in the table view will be rendered by the \c PixelDelegate
- instance.
-
- We construct a spin box to allow the user to change the size of each "pixel"
- drawn by the delegate:
-
- \snippet itemviews/pixelator/mainwindow.cpp 3
-
- This spin box is connected to the custom slot we implemented in the
- \c PixelDelegate class. This ensures that the delegate always draws each
- pixel at the currently specified size:
-
- \snippet itemviews/pixelator/mainwindow.cpp 4
- \dots
- \snippet itemviews/pixelator/mainwindow.cpp 5
-
- We also connect the spin box to a slot in the \c MainWindow class. This
- forces the view to take into account the new size hints for each item;
- these are provided by the delegate in its \c sizeHint() function.
-
- \snippet itemviews/pixelator/mainwindow.cpp 6
-
- We explicitly resize the columns and rows to match the
- \uicontrol{Pixel size} combobox.
-*/
diff --git a/examples/widgets/doc/src/plugandpaint.qdoc b/examples/widgets/doc/src/plugandpaint.qdoc
deleted file mode 100644
index 2ee08311f2..0000000000
--- a/examples/widgets/doc/src/plugandpaint.qdoc
+++ /dev/null
@@ -1,527 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example tools/plugandpaint/app
- \title Plug & Paint Example
- \ingroup examples-widgets-tools
-
- \brief Demonstrates how to extend Qt applications using plugins.
-
- \image plugandpaint.png Screenshot of the Plug & Paint example
-
- A plugin is a dynamic library that can be loaded at run-time to
- extend an application. Qt makes it possible to create custom
- plugins and to load them using QPluginLoader. To ensure that
- plugins don't get lost, it is also possible to link them
- statically to the executable. The Plug & Paint example uses
- plugins to support custom brushes, shapes, and image filters. A
- single plugin can provide multiple brushes, shapes, and/or
- filters.
-
- If you want to learn how to make your own application extensible
- through plugins, we recommend that you start by reading this
- overview, which explains how to make an application use plugins.
- Afterwards, you can read the
- \l{tools/plugandpaint/plugins/basictools}{Basic Tools} and
- \l{tools/plugandpaint/plugins/extrafilters}{Extra Filters}
- overviews, which show how to implement static and dynamic
- plugins, respectively.
-
- Plug & Paint consists of the following classes:
-
- \list
- \li \c MainWindow is a QMainWindow subclass that provides the menu
- system and that contains a \c PaintArea as the central widget.
- \li \c PaintArea is a QWidget that allows the user to draw using a
- brush and to insert shapes.
- \li \c PluginDialog is a dialog that shows information about the
- plugins detected by the application.
- \li \c BrushInterface, \c ShapeInterface, and \c FilterInterface are
- abstract base classes that can be implemented by plugins to
- provide custom brushes, shapes, and image filters.
- \endlist
-
- \section1 The Plugin Interfaces
-
- We will start by reviewing the interfaces defined in \c
- interfaces.h. These interfaces are used by the Plug & Paint
- application to access extra functionality. They are implemented
- in the plugins.
-
-
- \snippet tools/plugandpaint/app/interfaces.h 0
-
- The \c BrushInterface class declares four pure virtual functions.
- The first pure virtual function, \c brushes(), returns a list of
- strings that identify the brushes provided by the plugin. By
- returning a QStringList instead of a QString, we make it possible
- for a single plugin to provide multiple brushes. The other
- functions have a \c brush parameter to identify which brush
- (among those returned by \c brushes()) is used.
-
- \c mousePress(), \c mouseMove(), and \c mouseRelease() take a
- QPainter and one or two \l{QPoint}s, and return a QRect
- identifying which portion of the image was altered by the brush.
-
- The class also has a virtual destructor. Interface classes
- usually don't need such a destructor (because it would make
- little sense to \c delete the object that implements the
- interface through a pointer to the interface), but some compilers
- emit a warning for classes that declare virtual functions but no
- virtual destructor. We provide the destructor to keep these
- compilers happy.
-
- \snippet tools/plugandpaint/app/interfaces.h 1
-
- The \c ShapeInterface class declares a \c shapes() function that
- works the same as \c{BrushInterface}'s \c brushes() function, and
- a \c generateShape() function that has a \c shape parameter.
- Shapes are represented by a QPainterPath, a data type that can
- represent arbitrary 2D shapes or combinations of shapes. The \c
- parent parameter can be used by the plugin to pop up a dialog
- asking the user to specify more information.
-
- \snippet tools/plugandpaint/app/interfaces.h 2
-
- The \c FilterInterface class declares a \c filters() function
- that returns a list of filter names, and a \c filterImage()
- function that applies a filter to an image.
-
- \snippet tools/plugandpaint/app/interfaces.h 4
-
- To make it possible to query at run-time whether a plugin
- implements a given interface, we must use the \c
- Q_DECLARE_INTERFACE() macro. The first argument is the name of
- the interface. The second argument is a string identifying the
- interface in a unique way. By convention, we use a "Java package
- name" syntax to identify interfaces. If we later change the
- interfaces, we must use a different string to identify the new
- interface; otherwise, the application might crash. It is therefore
- a good idea to include a version number in the string, as we did
- above.
-
- The \l{tools/plugandpaint/plugins/basictools}{Basic Tools} plugin
- and the \l{tools/plugandpaint/plugins/extrafilters}{Extra Filters}
- plugin shows how to derive from \c BrushInterface, \c
- ShapeInterface, and \c FilterInterface.
-
- A note on naming: It might have been tempting to give the \c
- brushes(), \c shapes(), and \c filters() functions a more generic
- name, such as \c keys() or \c features(). However, that would
- have made multiple inheritance impractical. When creating
- interfaces, we should always try to give unique names to the pure
- virtual functions.
-
- \section1 The MainWindow Class
-
- The \c MainWindow class is a standard QMainWindow subclass, as
- found in many of the other examples (e.g.,
- \l{mainwindows/application}{Application}). Here, we'll
- concentrate on the parts of the code that are related to plugins.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 4
-
- The \c loadPlugins() function is called from the \c MainWindow
- constructor to detect plugins and update the \uicontrol{Brush},
- \uicontrol{Shapes}, and \uicontrol{Filters} menus. We start by handling static
- plugins (available through QPluginLoader::staticInstances())
-
- To the application that uses the plugin, a Qt plugin is simply a
- QObject. That QObject implements plugin interfaces using multiple
- inheritance.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 5
-
- The next step is to load dynamic plugins. We initialize the \c
- pluginsDir member variable to refer to the \c plugins
- subdirectory of the Plug & Paint example. On Unix, this is just a
- matter of initializing the QDir variable with
- QApplication::applicationDirPath(), the path of the executable
- file, and to do a \l{QDir::cd()}{cd()}. On Windows and \macos,
- this file is usually located in a subdirectory, so we need to
- take this into account.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 6
- \snippet tools/plugandpaint/app/mainwindow.cpp 7
- \snippet tools/plugandpaint/app/mainwindow.cpp 8
-
- We use QDir::entryList() to get a list of all files in that
- directory. Then we iterate over the result using a range-based for loop
- and try to load the plugin using QPluginLoader.
-
- The QObject provided by the plugin is accessible through
- QPluginLoader::instance(). If the dynamic library isn't a Qt
- plugin, or if it was compiled against an incompatible version of
- the Qt library, QPluginLoader::instance() returns a null pointer.
-
- If QPluginLoader::instance() is non-null, we add it to the menus.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 9
-
- At the end, we enable or disable the \uicontrol{Brush}, \uicontrol{Shapes},
- and \uicontrol{Filters} menus based on whether they contain any items.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 10
-
- For each plugin (static or dynamic), we check which interfaces it
- implements using \l qobject_cast(). First, we try to cast the
- plugin instance to a \c BrushInterface; if it works, we call the
- private function \c addToMenu() with the list of brushes returned
- by \c brushes(). Then we do the same with the \c ShapeInterface
- and the \c FilterInterface.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 3
-
- The \c aboutPlugins() slot is called on startup and can be
- invoked at any time through the \uicontrol{About Plugins} action. It
- pops up a \c PluginDialog, providing information about the loaded
- plugins.
-
- \image plugandpaint-plugindialog.png Screenshot of the Plugin dialog
-
-
- The \c addToMenu() function is called from \c loadPlugin() to
- create \l{QAction}s for custom brushes, shapes, or filters and
- add them to the relevant menu. The QAction is created with the
- plugin from which it comes from as the parent; this makes it
- convenient to get access to the plugin later.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 0
-
- The \c changeBrush() slot is invoked when the user chooses one of
- the brushes from the \uicontrol{Brush} menu. We start by finding out
- which action invoked the slot using QObject::sender(). Then we
- get the \c BrushInterface out of the plugin (which we
- conveniently passed as the QAction's parent) and we call \c
- PaintArea::setBrush() with the \c BrushInterface and the string
- identifying the brush. Next time the user draws on the paint
- area, \c PaintArea will use this brush.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 1
-
- The \c insertShape() is invoked when the use chooses one of the
- shapes from the \uicontrol{Shapes} menu. We retrieve the QAction that
- invoked the slot, then the \c ShapeInterface associated with that
- QAction, and finally we call \c ShapeInterface::generateShape()
- to obtain a QPainterPath.
-
- \snippet tools/plugandpaint/app/mainwindow.cpp 2
-
- The \c applyFilter() slot is similar: We retrieve the QAction
- that invoked the slot, then the \c FilterInterface associated to
- that QAction, and finally we call \c
- FilterInterface::filterImage() to apply the filter onto the
- current image.
-
- \section1 The PaintArea Class
-
- The \c PaintArea class contains some code that deals with \c
- BrushInterface, so we'll review it briefly.
-
- \snippet tools/plugandpaint/app/paintarea.cpp 0
-
- In \c setBrush(), we simply store the \c BrushInterface and the
- brush that are given to us by \c MainWindow.
-
- \snippet tools/plugandpaint/app/paintarea.cpp 1
-
- In the \l{QWidget::mouseMoveEvent()}{mouse move event handler},
- we call the \c BrushInterface::mouseMove() function on the
- current \c BrushInterface, with the current brush. The mouse
- press and mouse release handlers are very similar.
-
- \section1 The PluginDialog Class
-
- The \c PluginDialog class provides information about the loaded
- plugins to the user. Its constructor takes a path to the plugins
- and a list of plugin file names. It calls \c findPlugins()
- to fill the QTreeWdiget with information about the plugins:
-
- \snippet tools/plugandpaint/app/plugindialog.cpp 0
-
- The \c findPlugins() is very similar to \c
- MainWindow::loadPlugins(). It uses QPluginLoader to access the
- static and dynamic plugins. Its helper function \c
- populateTreeWidget() uses \l qobject_cast() to find out which
- interfaces are implemented by the plugins:
-
- \snippet tools/plugandpaint/app/plugindialog.cpp 1
-
- \section1 Importing Static Plugins
-
- The \l{tools/plugandpaint/plugins/basictools}{Basic Tools} plugin
- is built as a static plugin, to ensure that it is always
- available to the application. This requires using the
- Q_IMPORT_PLUGIN() macro somewhere in the application (in a \c
- .cpp file) and specifying the plugin in the \c .pro file.
-
- For Plug & Paint, we have chosen to put Q_IMPORT_PLUGIN() in \c
- main.cpp:
-
- \snippet tools/plugandpaint/app/main.cpp 0
-
- The argument to Q_IMPORT_PLUGIN() is the plugin name, which corresponds
- with the name of the class that declares metadata for the plugin with
- Q_PLUGIN_METADATA().
-
- In the \c .pro file, we need to specify the static library.
- Here's the project file for building Plug & Paint:
-
- \snippet tools/plugandpaint/app/app.pro 0
-
- The \c LIBS line variable specifies the library \c pnp_basictools
- located in the \c ../plugandpaint/plugins/basictools directory.
- (Although the \c LIBS syntax has a distinct Unix flavor, \c qmake
- supports it on all platforms.)
-
- The \c CONFIG() code at the end is necessary for this example
- because the example is part of the Qt distribution and Qt can be
- configured to be built simultaneously in debug and in release
- modes. You don't need to for your own plugin applications.
-
- This completes our review of the Plug & Paint application. At
- this point, you might want to take a look at the
- \l{tools/plugandpaint/plugins/basictools}{Basic Tools} example
- plugin.
-*/
-
-/*!
- \example tools/plugandpaint/plugins/basictools
- \title Plug & Paint Basic Tools Example
- \brief A plugin providing the basic tools for painting functionality.
-
- \image plugandpaint.png Screenshot of the Plug & Paint example
-
- The Basic Tools example is a static plugin for the
- \l{tools/plugandpaint/app}{Plug & Paint} example. It provides a set
- of basic brushes, shapes, and filters. Through the Basic Tools
- example, we will review the four steps involved in writing a Qt
- plugin:
-
- \list 1
- \li Declare a plugin class.
- \li Implement the interfaces provided by the plugin.
- \li Export the plugin using the Q_PLUGIN_METADATA() macro.
- \li Build the plugin using an adequate \c .pro file.
- \endlist
-
- \section1 Declaration of the Plugin Class
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.h 0
-
- We start by including \c interfaces.h, which defines the plugin
- interfaces for the \l{tools/plugandpaint/app}{Plug & Paint}
- application. For the \c #include to work, we need to add an \c
- INCLUDEPATH entry to the \c .pro file with the path to the
- header file.
-
- The \c BasicToolsPlugin class is a QObject subclass that
- implements the \c BrushInterface, the \c ShapeInterface, and the
- \c FilterInterface. This is done through multiple inheritance.
- The \c Q_INTERFACES() macro is necessary to tell \l{moc}, Qt's
- meta-object compiler, that the base classes are plugin
- interfaces. Without the \c Q_INTERFACES() macro, we couldn't use
- \l qobject_cast() in the \l{tools/plugandpaint/app}{Plug & Paint}
- application to detect interfaces.
- For an explanation for the \c Q_PLUGIN_METADATA() macro see
- \l {Exporting the Plugin}.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.h 2
-
- In the \c public section of the class, we declare all the
- functions from the three interfaces.
-
- \section1 Implementation of the Brush Interface
-
- Let's now review the implementation of the \c BasicToolsPlugin
- member functions inherited from \c BrushInterface.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 0
-
- The \c brushes() function returns a list of brushes provided by
- this plugin. We provide three brushes: \uicontrol{Pencil}, \uicontrol{Air
- Brush}, and \uicontrol{Random Letters}.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 1
-
- On a mouse press event, we just call \c mouseMove() to draw the
- spot where the event occurred.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 2
-
- In \c mouseMove(), we start by saving the state of the QPainter
- and we compute a few variables that we'll need later.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 3
-
- Then comes the brush-dependent part of the code:
-
- \list
- \li If the brush is \uicontrol{Pencil}, we just call
- QPainter::drawLine() with the current QPen.
-
- \li If the brush is \uicontrol{Air Brush}, we start by setting the
- painter's QBrush to Qt::Dense6Pattern to obtain a dotted
- pattern. Then we draw a circle filled with that QBrush several
- times, resulting in a thick line.
-
- \li If the brush is \uicontrol{Random Letters}, we draw a random letter
- at the new cursor position. Most of the code is for setting
- the font to be bold and larger than the default font and for
- computing an appropriate bounding rect.
- \endlist
-
- At the end, we restore the painter state to what it was upon
- entering the function and we return the bounding rectangle.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 4
-
- When the user releases the mouse, we do nothing and return an
- empty QRect.
-
- \section1 Implementation of the Shape Interface
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 5
-
- The plugin provides three shapes: \uicontrol{Circle}, \uicontrol{Star}, and
- \uicontrol{Text...}. The three dots after \uicontrol{Text} are there because
- the shape pops up a dialog asking for more information. We know
- that the shape names will end up in a menu, so we include the
- three dots in the shape name.
-
- A cleaner but more complicated design would have been to
- distinguish between the internal shape name and the name used in
- the user interface.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 6
-
- The \c generateShape() creates a QPainterPath for the specified
- shape. If the shape is \uicontrol{Text}, we pop up a QInputDialog to
- let the user enter some text.
-
- \section1 Implementation of the Filter Interface
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 7
-
- The plugin provides three filters: \uicontrol{Invert Pixels}, \uicontrol{Swap
- RGB}, and \uicontrol{Grayscale}.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp 8
-
- The \c filterImage() function takes a filter name and a QImage as
- parameters and returns an altered QImage. The first thing we do
- is to convert the image to a 32-bit RGB format, to ensure that
- the algorithms will work as expected. For example,
- QImage::invertPixels(), which is used to implement the
- \uicontrol{Invert Pixels} filter, gives counterintuitive results for
- 8-bit images, because they invert the indices into the color
- table instead of inverting the color table's entries.
-
- \section1 Exporting the Plugin
-
- To finally export your plugin you just have to add the
- \c Q_PLUGIN_METADATA() macro right next to the \c Q_OBJECT() macro
- into the header file of the plugin.
- It must contain the plugins IID and optionally a filename pointing
- to a json file containing the metadata for the plugin.
-
- \snippet tools/plugandpaint/plugins/basictools/basictoolsplugin.h 4
-
- Within this example the json file does not need to export any metadata,
- so it just contains an empty json object.
-
- \code
- {}
- \endcode
-
- \section1 The .pro File
-
- Here's the project file for building the Basic Tools plugin:
-
- \snippet tools/plugandpaint/plugins/basictools/basictools.pro 0
-
- The \c .pro file differs from typical \c .pro files in many
- respects. First, it starts with a \c TEMPLATE entry specifying \c
- lib. (The default template is \c app.) It also adds \c plugin to
- the \c CONFIG variable. This is necessary on some platforms to
- avoid generating symbolic links with version numbers in the file
- name, which is appropriate for most dynamic libraries but not for
- plugins.
-
- To make the plugin a static plugin, all that is required is to
- specify \c static in addition to \c plugin. The
- \l{tools/plugandpaint/plugins/extrafilters}{Extra Filters} plugin,
- which is compiled as a dynamic plugin, doesn't specify \c static
- in its \c .pro file.
-
- The \c INCLUDEPATH variable sets the search paths for global
- headers (i.e., header files included using \c{#include <...>}).
- We add \c ../../app to the list, so that we can include
- \c <interfaces.h>.
-
- The \c TARGET variable specifies which name we want to give the
- target library. We use \c pnp_ as the prefix to show that the
- plugin is designed to work with Plug & Paint. On Unix, \c lib is
- also prepended to that name. On all platforms, a
- platform-specific suffix is appended (e.g., \c .dll on Windows,
- \c .a on Linux).
-
- The \c CONFIG() code at the end is necessary for this example
- because the example is part of the Qt distribution and Qt can be
- configured to be built simultaneously in debug and in release
- modes. You don't need to for your own plugins.
-*/
-
-/*!
- \example tools/plugandpaint/plugins/extrafilters
- \title Plug & Paint Extra Filters Example
- \brief A plugin providing the extra filters.
-
- \image plugandpaint.png Screenshot of the Plug & Paint example
-
- The Extra Filters example is a plugin for the
- \l{tools/plugandpaint/app}{Plug & Paint} example. It provides a set
- of filters in addition to those provided by the
- \l{tools/plugandpaint/plugins/basictools}{Basic Tools} plugin.
-
- Since the approach is identical to
- \l{tools/plugandpaint/plugins/basictools}{Basic Tools}, we won't
- review the code here. The only part of interest is the
- \c .pro file, since Extra Filters is a dynamic plugin
- (\l{tools/plugandpaint/plugins/basictools}{Basic Tools} is
- linked statically into the Plug & Paint executable).
-
- Here's the project file for building the Extra Filters plugin:
-
- \snippet tools/plugandpaint/plugins/extrafilters/extrafilters.pro 0
-
- The \c .pro file differs from typical \c .pro files in many
- respects. First, it starts with a \c TEMPLATE entry specifying \c
- lib. (The default template is \c app.) It also adds \c plugin to
- the \c CONFIG variable. This is necessary on some platforms to
- avoid generating symbolic links with version numbers in the file
- name, which is appropriate for most dynamic libraries but not for
- plugins.
-
- The \c INCLUDEPATH variable sets the search paths for global
- headers (i.e., header files included using \c{#include <...>}).
- We add \c ../../app to the list, so that we can include
- \c <interfaces.h>.
-
- The \c TARGET variable specifies which name we want to give the
- target library. We use \c pnp_ as the prefix to show that the
- plugin is designed to work with Plug & Paint. On Unix, \c lib is
- also prepended to that name. On all platforms, a
- platform-specific suffix is appended (e.g., \c .dll on Windows,
- \c .so on Linux).
-
- The \c DESTDIR variable specifies where we want to install the
- plugin. We put it in Plug & Paint's \c plugins subdirectory,
- since that's where the application looks for dynamic plugins.
-
- The \c CONFIG() code at the end is necessary for this example
- because the example is part of the Qt distribution and Qt can be
- configured to be built simultaneously in debug and in release
- modes. You don't need to for your own plugins.
-*/
diff --git a/examples/widgets/doc/src/regularexpression.qdoc b/examples/widgets/doc/src/regularexpression.qdoc
index 8d7aa61629..f6f1e87689 100644
--- a/examples/widgets/doc/src/regularexpression.qdoc
+++ b/examples/widgets/doc/src/regularexpression.qdoc
@@ -4,6 +4,7 @@
/*!
\example tools/regularexpression
\title QRegularExpression Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets-tools
\brief The QRegularExpression example shows how regular expressions in Qt are
diff --git a/examples/widgets/doc/src/screenshot.qdoc b/examples/widgets/doc/src/screenshot.qdoc
index 1f30ce99a3..2e2b3123ef 100644
--- a/examples/widgets/doc/src/screenshot.qdoc
+++ b/examples/widgets/doc/src/screenshot.qdoc
@@ -4,6 +4,7 @@
/*!
\example desktop/screenshot
\title Taking a Screenshot
+ \examplecategory {Desktop}
\ingroup examples-desktop
\brief The Screenshot example shows how to take a screenshot of the
desktop.
diff --git a/examples/widgets/doc/src/scribble.qdoc b/examples/widgets/doc/src/scribble.qdoc
index 1a87576e39..3cd7205397 100644
--- a/examples/widgets/doc/src/scribble.qdoc
+++ b/examples/widgets/doc/src/scribble.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/scribble
\title Scribble Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The Scribble example shows how to reimplement some of QWidget's
event handlers to receive the events generated for the
diff --git a/examples/widgets/doc/src/settingseditor.qdoc b/examples/widgets/doc/src/settingseditor.qdoc
deleted file mode 100644
index 55226a9846..0000000000
--- a/examples/widgets/doc/src/settingseditor.qdoc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example tools/settingseditor
- \title Settings Editor Example
- \ingroup examples-widgets-tools
-
- \brief The Settings Editor example shows how Qt's standard settings support is used in an
- application by providing an editor that enables the user to view the settings for
- installed applications, and modify those that can be edited.
-
- \image settingseditor-example.png
-*/
diff --git a/examples/widgets/doc/src/shapedclock.qdoc b/examples/widgets/doc/src/shapedclock.qdoc
index 8e69be1db4..4bcd04683c 100644
--- a/examples/widgets/doc/src/shapedclock.qdoc
+++ b/examples/widgets/doc/src/shapedclock.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/shapedclock
\title Translucent Background
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The example shows how to make a round window with a translucent
background.
diff --git a/examples/widgets/doc/src/shortcuteditor.qdoc b/examples/widgets/doc/src/shortcuteditor.qdoc
index 350609c962..9999a18421 100644
--- a/examples/widgets/doc/src/shortcuteditor.qdoc
+++ b/examples/widgets/doc/src/shortcuteditor.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/shortcuteditor
\title Shortcut Editor Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The Shortcut Editor example shows how to create a basic, read-write
hierarchical model to use with Qt's standard view and QKeySequenceEdit
diff --git a/examples/widgets/doc/src/simpledommodel.qdoc b/examples/widgets/doc/src/simpledommodel.qdoc
deleted file mode 100644
index 82bd5c5d54..0000000000
--- a/examples/widgets/doc/src/simpledommodel.qdoc
+++ /dev/null
@@ -1,256 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/simpledommodel
- \title Simple DOM Model Example
- \ingroup examples-itemviews
- \brief The Simple DOM Model example shows how an existing class can be adapted for use with
- the model/view framework.
-
- \image simpledommodel-example.png
-
- Qt provides two complementary sets of classes for reading XML files: The classes based
- around QXmlReader provide a SAX-style API for incremental reading of large files, and
- the classes based around QDomDocument enable developers to access the contents of XML
- files using a Document Object Model (DOM) API.
-
- In this example, we create a model that uses the DOM API to expose the structure and
- contents of XML documents to views via the standard QAbstractModel interface.
-
- \section1 Design and Concepts
-
- Reading an XML document with Qt's DOM classes is a straightforward process. Typically,
- the contents of a file are supplied to QDomDocument, and nodes are accessed using the
- functions provided by QDomNode and its subclasses.
-
- \omit
- For example, the following code
- snippet reads the contents of a file into a QDomDocument object and traverses the
- document, reading all the plain text that can be found:
-
- \snippet doc/src/snippets/code/doc_src_examples_simpledommodel.cpp 0
-
- In principle, the functions provided by QDomNode can be used to navigate from any
- given starting point in a document to the piece of data requested by another component.
- Since QDomDocument maintains information about the structure of a document, we can
- use this to implement the required virtual functions in a QAbstractItemModel subclass.
- \endomit
-
- The aim is to use the structure provided by QDomDocument by wrapping QDomNode objects
- in item objects similar to the \c TreeItem objects used in the
- \l{Simple Tree Model Example}{Simple Tree Model} example.
-
- \section1 DomModel Class Definition
-
- Let us begin by examining the \c DomModel class:
-
- \snippet itemviews/simpledommodel/dommodel.h 0
-
- The class definition contains all the basic functions that are needed for a
- read-only model. Only the constructor and \c document() function are specific to
- this model. The private \c domDocument variable is used to hold the document
- that is exposed by the model; the \c rootItem variable contains a pointer to
- the root item in the model.
-
- \section1 DomItem Class Definition
-
- The \c DomItem class is used to hold information about a specific QDomNode in
- the document:
-
- \snippet itemviews/simpledommodel/domitem.h 0
-
- Each \c DomItem provides a wrapper for a QDomNode obtained from the underlying
- document which contains a reference to the node, it's location in the parent node's
- list of child nodes, and a pointer to a parent wrapper item.
-
- The \c parent(), \c child(), and \c row() functions are convenience functions for
- the \c DomModel to use that provide basic information about the item to be discovered
- quickly. The node() function provides access to the underlying QDomNode object.
-
- As well as the information supplied in the constructor, the class maintains a cache
- of information about any child items. This is used to provide a collection of
- persistent item objects that the model can identify consistently and improve the
- performance of the model when accessing child items.
-
- \section1 DomItem Class Implementation
-
- Since the \c DomItem class is only a thin wrapper around QDomNode objects, with a
- few additional features to help improve performance and memory usage, we can provide
- a brief outline of the class before discussing the model itself.
-
- The constructor simply records details of the QDomNode that needs to be wrapped:
-
- \snippet itemviews/simpledommodel/domitem.cpp 0
- \snippet itemviews/simpledommodel/domitem.cpp 1
-
- As a result, functions to provide the parent wrapper, the row number occupied by
- the item in its parent's list of children, and the underlying QDomNode for each item
- are straightforward to write:
-
- \snippet itemviews/simpledommodel/domitem.cpp 4
- \codeline
- \snippet itemviews/simpledommodel/domitem.cpp 6
- \codeline
- \snippet itemviews/simpledommodel/domitem.cpp 3
-
- It is necessary to maintain a collection of items which can be consistently identified
- by the model. For that reason, we maintain a hash of child wrapper items that, to
- minimize memory usage, is initially empty. The model uses the item's \c child()
- function to help create model indexes, and this constructs wrappers for the children
- of the item's QDomNode, relating the row number of each child to the newly-constructed
- wrapper:
-
- \snippet itemviews/simpledommodel/domitem.cpp 5
-
- If a QDomNode was previously wrapped, the cached wrapper is returned; otherwise, a
- new wrapper is constructed and stored for valid children, and zero is returned for
- invalid ones.
-
- The class's destructor deletes all the child items of the wrapper:
-
- \snippet itemviews/simpledommodel/domitem.cpp 2
-
- These, in turn, will delete their children and free any QDomNode objects in use.
-
- \section1 DomModel Class Implementation
-
- The structure provided by the \c DomItem class makes the implementation of \c DomModel
- similar to the \c TreeModel shown in the
- \l{Simple Tree Model Example}{Simple Tree Model} example.
-
- The constructor accepts an existing document and a parent object for the model:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 0
-
- A shallow copy of the document is stored for future reference, and a root item is
- created to provide a wrapper around the document. We assign the root item a row
- number of zero only to be consistent since the root item will have no siblings.
-
- Since the model only contains information about the root item, the destructor only
- needs to delete this one item:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 1
-
- All of the child items in the tree will be deleted by the \c DomItem destructor as
- their parent items are deleted.
-
- \section2 Basic Properties of The Model
-
- Some aspects of the model do not depend on the structure of the underlying document,
- and these are simple to implement.
-
- The number of columns exposed by the model is returned by the \c columnCount()
- function:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 2
-
- This value is fixed, and does not depend on the location or type of the underlying
- node in the document. We will use these three columns to display different kinds of
- data from the underlying document.
-
- Since we only implement a read-only model, the \c flags() function is straightforward
- to write:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 5
-
- Since the model is intended for use in a tree view, the \c headerData() function only
- provides a horizontal header:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 6
-
- The model presents the names of nodes in the first column, element attributes in the
- second, and any node values in the third.
-
- \section2 Navigating The Document
-
- The index() function creates a model index for the item with the given row, column,
- and parent in the model:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 7
-
- The function first has to relate the parent index to an item that contains a node
- from the underlying document. If the parent index is invalid, it refers to the root
- node in the document, so we retrieve the root item that wraps it; otherwise, we
- obtain a pointer to the relevant item using the QModelIndex::internalPointer()
- function. We are able to extract a pointer in this way because any valid model index
- will have been created by this function, and we store pointers to item objects in
- any new indexes that we create with QAbstractItemModel::createIndex():
-
- \snippet itemviews/simpledommodel/dommodel.cpp 8
-
- A child item for the given row is provided by the parent item's \c child() function.
- If a suitable child item was found then we call
- \l{QAbstractItemModel::createIndex()}{createIndex()} to produce a model index for the
- requested row and column, passing a pointer to the child item for it to store
- internally. If no suitable child item is found, an invalid model index is returned.
-
- Note that the items themselves maintain ownership of their child items. This means
- that the model does not need to keep track of the child items that have been created,
- and can let the items themselves tidy up when they are deleted.
-
- The number of rows beneath a given item in the model is returned by the \c rowCount()
- function, and is the number of child nodes contained by the node that corresponds to
- the specified model index:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 10
-
- To obtain the relevant node in the underlying document, we access the item via the
- internal pointer stored in the model index. If an invalid index is supplied, the
- root item is used instead. We use the item's \c node() function to access the node
- itself, and simply count the number of child nodes it contains.
-
- Since the model is used to represent a hierarchical data structure, it needs to
- provide an implementation for the \c parent() function. This returns a model index
- that corresponds to the parent of a child model index supplied as its argument:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 9
-
- For valid indexes other than the index corresponding to the root item, we obtain
- a pointer to the relevant item using the method described in the \c index() function,
- and use the item's \c parent() function to obtain a pointer to the parent item.
-
- If no valid parent item exists, or if the parent item is the root item, we can simply
- follow convention and return an invalid model index. For all other parent items, we
- create a model index containing the appropriate row and column numbers, and a pointer
- to the parent item we just obtained.
-
- Data is provided by the \c data() function. For simplicity, we only provide data for
- the \l{Qt::DisplayRole}{display role}, returning an invalid variant for all other
- requests:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 3
-
- As before, we obtain an item pointer for the index supplied, and use it to obtain
- the underlying document node. Depending on the column specified, the data we return
- is obtained in different ways:
-
- \snippet itemviews/simpledommodel/dommodel.cpp 4
-
- For the first column, we return the node's name. For the second column, we read any
- attributes that the node may have, and return a string that contains a space-separated
- list of attribute-value assignments. For the third column, we return any value that
- the node may have; this allows the contents of text nodes to be displayed in a view.
-
- If data from any other column is requested, an invalid variant is returned.
-
- \section1 Implementation Notes
-
- Ideally, we would rely on the structure provided by QDomDocument to help us write
- the \l{QAbstractItemModel::parent()}{parent()} and
- \l{QAbstractItemModel::index()}{index()} functions that are required when subclassing
- QAbstractItemModel. However, since Qt's DOM classes use their own system for
- dynamically allocating memory for DOM nodes, we cannot guarantee that the QDomNode
- objects returned for a given piece of information will be the same for subsequent
- accesses to the document.
-
- We use item wrappers for each QDomNode to provide consistent pointers that the model
- can use to navigate the document structure.
- \omit
- Since these items contain value references to the QDomNode objects themselves, this
- has the side effect that the DOM nodes themselves can be used to reliably navigate
- the document [not sure about this - QDom* may return different QDomNode objects for
- the same piece of information]. However, this advantage is redundant since we need to
- use wrapper items to obtain it. [Possible use of QDomNode cache in the model itself.]
- \endomit
-*/
diff --git a/examples/widgets/doc/src/simplerhiwidget.qdoc b/examples/widgets/doc/src/simplerhiwidget.qdoc
new file mode 100644
index 0000000000..e53302218e
--- /dev/null
+++ b/examples/widgets/doc/src/simplerhiwidget.qdoc
@@ -0,0 +1,204 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example rhi/simplerhiwidget
+ \title Simple RHI Widget Example
+ \examplecategory {Graphics}
+ \ingroup examples-widgets
+ \brief Shows how to render a triangle using QRhi, Qt's 3D API and shading language abstraction layer.
+
+ \image simplerhiwidget-example.jpg
+ \caption Screenshot of the Simple RHI Widget example
+
+ This example is, in many ways, the counterpart of the \l{RHI Window
+ Example} in the \l QWidget world. The \l QRhiWidget subclass in this
+ applications renders a single triangle, using a simple graphics pipeline
+ with basic vertex and fragment shaders. Unlike the plain QWindow-based
+ application, this example does not need to worry about lower level details,
+ such as setting up the window and the QRhi, or dealing with swapchain and
+ window events, as that is taken care of by the QWidget framework here. The
+ instance of the \l QRhiWidget subclass is added to a QVBoxLayout. To keep
+ the example minimal and compact, there are no further widgets or 3D content
+ introduced.
+
+ Once an instance of \c ExampleRhiWidget, a \l QRhiWidget subclass, is added
+ to a top-level widget's child hierarchy, the corresponding window
+ automatically becomes a Direct 3D, Vulkan, Metal, or OpenGL-rendered
+ window. The QPainter-rendered widget content, i.e. everything that is not a
+ QRhiWidget, QOpenGLWidget, or QQuickWidget, is then uploaded to a texture,
+ whereas the mentioned special widgets each render to a texture. The
+ resulting set of \l{QRhiTexture}{textures} is composited together by the
+ top-level widget's backingstore.
+
+ \section1 Structure and main()
+
+ The \c{main()} function is quite simple. The top-level widget defaults to a
+ size of 720p (this size is in logical units, the actual pixel size may be
+ different, depending on the \l{QWidget::devicePixelRatio()}{scale factor}.
+ The window is resizable. QRhiWidget makes it simple to implement subclasses
+ that correctly deal with the resizing of the widget due to window size or
+ layout changes.
+
+ \snippet rhi/simplerhiwidget/main.cpp 0
+
+ The QRhiWidget subclass reimplements the two virtuals:
+ \l{QRhiWidget::initialize()}{initialize()} and
+ \l{QRhiWidget::render()}{render()}.
+ initialize() is called at least once before render(),
+ but is also invoked upon a number of important changes, such as when the
+ widget's backing texture is recreated due to a changing widget size, when
+ render target parameters change, or when the widget changes to a new QRhi
+ due to moving to a new top-level window.
+
+ \note Unlike QOpenGLWidget's legacy \c initializeGL - \c resizeGL - \c
+ paintGL model, there are only two virtuals in QRhiWidget. This is because
+ there are more special events that possible need taking care of than just
+ resizing, e.g. when reparenting to a different top-level window. (robust
+ QOpenGLWidget implementations had to deal with this by performing
+ additional bookkeeping, e.g. by tracking the associated QOpenGLContext
+ lifetime, meaning the three virtuals were not actually sufficient) A
+ simpler pair of \c initialize - \c render, where \c initialize is
+ re-invoked upon important changes is better suited for this.
+
+ The \l QRhi instance is not owned by the widget. It is going to be queried
+ in \c initialize() \l{QRhiWidget::rhi()}{from the base class}. Storing it
+ as a member allows recognizing changes when \c initialize() is invoked
+ again. Graphics resources, such as the vertex and uniform buffers, or the
+ graphics pipeline are however under the control of \c ExampleRhiWidget.
+
+ \snippet rhi/simplerhiwidget/examplewidget.h 0
+
+ For the \c{#include <rhi/qrhi.h>} statement to work, the application must
+ link to \c GuiPrivate (or \c{gui-private} with qmake). See \l QRhi for more
+ details about the compatibility promise of the QRhi family of APIs.
+
+ \c CMakeLists.txt
+
+ \badcode
+ target_link_libraries(simplerhiwidget PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::GuiPrivate
+ Qt6::Widgets
+ )
+ \endcode
+
+ \section1 Rendering Setup
+
+ In \c examplewidget.cpp the widget implementation uses a helper function to
+ load up a \l QShader object from a \c{.qsb} file. This application ships
+ pre-conditioned \c{.qsb} files embedded in to the executable via the Qt
+ Resource System. Due to module dependencies (and due to still supporting
+ qmake), this example does not use the convenient CMake function
+ \c{qt_add_shaders()}, but rather comes with the \c{.qsb} files as part of
+ the source tree. Real world applications are encouraged to avoid this and
+ rather use the Qt Shader Tools module's CMake integration features (\c
+ qt_add_shaders). Regardless of the approach, in the C++ code the loading
+ of the bundled/generated \c{.qsb} files is the same.
+
+ \snippet rhi/simplerhiwidget/examplewidget.cpp get-shader
+
+ Let's look at the initialize() implementation. First, the \l QRhi object is
+ queried and stored for later use, and also to allow comparison in future
+ invocations of the function. When there is a mismatch (e.g. when the widget
+ is moved between windows), recreation of graphics resources need to be
+ recreated is triggered by destroying and nulling out a suitable object, in
+ this case the \c m_pipeline. The example does not actively demonstrate
+ reparenting between windows, but it is prepared to handle it. It is also
+ prepared to handle a changing widget size that can happen when resizing the
+ window. That needs no special handling since \c{initialize()} is invoked
+ every time that happens, and so querying
+ \c{renderTarget()->pixelSize()} or \c{colorTexture()->pixelSize()}
+ always gives the latest, up-to-date size in pixels. What this example is
+ not prepared for is changing
+ \l{QRhiWidget::textureFormat}{texture formats} and
+ \l{QRhiWidget::sampleCount}{multisample settings}
+ since it only ever uses the defaults (RGBA8 and no multisample antialiasing).
+
+ \snippet rhi/simplerhiwidget/examplewidget.cpp init-1
+
+ When the graphics resources need to be (re)created, \c{initialize()} does
+ this using quite typical QRhi-based code. A single vertex buffer with the
+ interleaved position - color vertex data is sufficient, whereas the
+ modelview-projection matrix is exposed via a uniform buffer of 64 bytes (16
+ floats). The uniform buffer is the only shader visible resource, and it is
+ only used in the vertex shader. The graphics pipeline relies on a lot of
+ defaults (for example, depth test off, blending disabled, color write
+ enabled, face culling disabled, the default topology of triangles, etc.)
+ The vertex data layout is \c x, \c y, \c r, \c g, \c b, hence the stride is
+ 5 floats, whereas the second vertex input attribute (the color) has an
+ offset of 2 floats (skipping \c x and \c y). Each graphics pipeline has to
+ be associated with a \l QRhiRenderPassDescriptor. This can be retrieved
+ from the \l QRhiRenderTarget managed by the base class.
+
+ \note This example relies on the QRhiWidget's default of
+ \l{QRhiWidget::autoRenderTarget}{autoRenderTarget} set to \c true.
+ That is why it does not need to manage the render target, but can just
+ query the existing one by calling
+ \l{QRhiWidget::renderTarget()}{renderTarget()}.
+
+ \snippet rhi/simplerhiwidget/examplewidget.cpp init-pipeline
+
+ Finally, the projection matrix is calculated. This depends on the widget
+ size and is thus done unconditionally in every invocation of the functions.
+
+ \note Any size and viewport calculations should only ever rely on the pixel
+ size queried from the resource serving as the color buffer since that is
+ the actual render target. Avoid manually calculating sizes, viewports,
+ scissors, etc. based on the QWidget-reported size or device pixel ratio.
+
+ \note The projection matrix includes the
+ \l{QRhi::clipSpaceCorrMatrix()}{correction matrix} from QRhi in order to
+ cater for 3D API differences in normalized device coordinates.
+ (for example, Y down vs. Y up)
+
+ A translation of \c{-4} is applied just to make sure the triangle with \c z
+ values of 0 will be visible.
+
+ \snippet rhi/simplerhiwidget/examplewidget.cpp init-matrix
+
+ \section1 Rendering
+
+ The widget records a single render pass, which contains a single draw call.
+
+ The view-projection matrix calculated in the initialize step gets combined
+ with the model matrix, which in this case happens to be a simple rotation.
+ The resulting matrix is then written to the uniform buffer. Note how
+ \c resourceUpdates is passed to
+ \l{QRhiCommandBuffer::beginPass()}{beginPass()}, which is a shortcut to not
+ having to invoke \l{QRhiCommandBuffer::resourceUpdate()}{resourceUpdate()}
+ manually.
+
+ \snippet rhi/simplerhiwidget/examplewidget.cpp render-1
+
+ In the render pass, a single draw call with 3 vertices is recorded. The
+ graphics pipeline created in the initialize step is bound on the command
+ buffer, and the viewport is set to cover the entire widget. To make the
+ uniform buffer visible to the (vertex) shader,
+ \l{QRhiCommandBuffer::setShaderResources()}{setShaderResources()} is called
+ with no argument, which means using the \c m_srb since that was associated
+ with the pipeline at pipeline creation time. In more complex renderers it
+ is not unusual to pass in a different \l QRhiShaderResourceBindings object,
+ as long as that is
+ \l{QRhiShaderResourceBindings::isLayoutCompatible()}{layout-compatible}
+ with the one given at pipeline creation time.
+ There is no index buffer, and there is a single vertex buffer binding (the
+ single element in \c vbufBinding refers to the single entry in the binding
+ list of the \l QRhiVertexInputLayout that was specified when creating
+ pipeline).
+
+ \snippet rhi/simplerhiwidget/examplewidget.cpp render-pass
+
+ Once the render pass is recorded, \l{QWidget::update()}{update()} is
+ called. This requests a new frame, and is used to ensure the widget
+ continuously updates, and the triangle appears rotating. The rendering
+ thread (the main thread in this case) is throttled by the presentation rate
+ by default. There is no proper animation system in this example, and so the
+ rotation will increase in every frame, meaning the triangle will rotate at
+ different speeds on displays with different refresh rates.
+
+ \snippet rhi/simplerhiwidget/examplewidget.cpp render-2
+
+ \sa QRhi, {Cube RHI Widget Example}, {RHI Window Example}
+*/
diff --git a/examples/widgets/doc/src/simpletreemodel.qdoc b/examples/widgets/doc/src/simpletreemodel.qdoc
index 5892d05244..d8e5a6faa8 100644
--- a/examples/widgets/doc/src/simpletreemodel.qdoc
+++ b/examples/widgets/doc/src/simpletreemodel.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/simpletreemodel
\title Simple Tree Model Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\ingroup examples-layout
\brief The Simple Tree Model example shows how to use a hierarchical model
@@ -104,16 +105,14 @@
\snippet itemviews/simpletreemodel/treeitem.cpp 0
A pointer to each of the child items belonging to this item will be
- stored in the \c childItems private member variable. When the class's
- destructor is called, it must delete each of these to ensure that
- their memory is reused:
-
- \snippet itemviews/simpletreemodel/treeitem.cpp 1
+ stored in the \c childItems private member variable as an std::unique_ptr.
+ When the class's destructor is called, the child items will be automatically
+ deleted to ensure that their memory is reused:
Since each of the child items are constructed when the model is initially
populated with data, the function to add child items is straightforward:
- \snippet itemviews/simpletreemodel/treeitem.cpp 2
+ \snippet itemviews/simpletreemodel/treeitem.cpp 1
Each item is able to return any of its child items when given a suitable
row number. For example, in the \l{#SimpleTreeModelStructure}{above diagram},
@@ -124,11 +123,11 @@
The \c child() function returns the child that corresponds to
the specified row number in the item's list of child items:
- \snippet itemviews/simpletreemodel/treeitem.cpp 3
+ \snippet itemviews/simpletreemodel/treeitem.cpp 2
The number of child items held can be found with \c childCount():
- \snippet itemviews/simpletreemodel/treeitem.cpp 4
+ \snippet itemviews/simpletreemodel/treeitem.cpp 3
The \c TreeModel uses this function to determine the number of rows that
exist for a given parent item.
@@ -136,7 +135,7 @@
The \c row() function reports the item's location within its parent's
list of items:
- \snippet itemviews/simpletreemodel/treeitem.cpp 8
+ \snippet itemviews/simpletreemodel/treeitem.cpp 7
Note that, although the root item (with no parent item) is automatically
assigned a row number of 0, this information is never used by the model.
@@ -144,16 +143,17 @@
The number of columns of data in the item is trivially returned by the
\c columnCount() function.
- \snippet itemviews/simpletreemodel/treeitem.cpp 5
+ \snippet itemviews/simpletreemodel/treeitem.cpp 4
- Column data is returned by the \c data() function. The bounds are checked
- before accessing the container with the data:
+ Column data is returned by the \c data() function. We use
+ the QList::value() convenience function which checks the bounds
+ and returns a default-constructed QVariant in case they are violated:
- \snippet itemviews/simpletreemodel/treeitem.cpp 6
+ \snippet itemviews/simpletreemodel/treeitem.cpp 5
The item's parent is found with \c parent():
- \snippet itemviews/simpletreemodel/treeitem.cpp 7
+ \snippet itemviews/simpletreemodel/treeitem.cpp 6
Note that, since the root item in the model will not have a parent, this
function will return zero in that case. We need to ensure that the model
@@ -183,14 +183,16 @@
item only contains vertical header data for convenience. We also use it
to reference the internal data structure that contains the model data,
and it is used to represent an imaginary parent of top-level items in
- the model.
+ the model. The root item is managed with a std::unique_ptr to ensure the
+ entire tree of item is deleted when the model is deleted.
The model's internal data structure is populated with items by the
\c setupModelData() function. We will examine this function separately
at the end of this document.
The destructor ensures that the root item and all of its descendants
- are deleted when the model is destroyed:
+ are deleted when the model is destroyed. This is done automatically
+ since the root item is stored in a unique_ptr.
\snippet itemviews/simpletreemodel/treemodel.cpp 1
@@ -293,14 +295,14 @@
We begin with a text file in the following format:
\code
- Getting Started How to familiarize yourself with Qt Designer
- Launching Designer Running the Qt Designer application
- The User Interface How to interact with Qt Designer
+ Getting Started How to familiarize yourself with Qt Widgets Designer
+ Launching Designer Running the Qt Widgets Designer application
+ The User Interface How to interact with Qt Widgets Designer
\endcode
\dots
\code
Connection Editing Mode Connecting widgets together with signals and slots
- Connecting Objects Making connections in Qt Designer
+ Connecting Objects Making connections in Qt Widgets Designer
Editing Connections Changing existing connections
\endcode
@@ -317,4 +319,21 @@
To ensure that the model works correctly, it is only necessary to
create instances of \c TreeItem with the correct data and parent item.
+
+ \section1 Testing the model
+
+ Correctly implementing an item model can be challenging. The class
+ \l [QtTest] QAbstractItemModelTester from the \l [QtTest] {Qt Test} module
+ checks for model consistency, like the model index creation and
+ parent-child relationships.
+
+ You can test your model by just passing a model instance to the class
+ constructor, for instance as part of a Qt unit test:
+
+ \snippet itemviews/simpletreemodel/test.cpp 1
+
+ To create a test which can be run using the \c ctest executable,
+ \c add_test() is used:
+
+ \snippet itemviews/simpletreemodel/CMakeLists.txt 1
*/
diff --git a/examples/widgets/doc/src/simplewidgetmapper.qdoc b/examples/widgets/doc/src/simplewidgetmapper.qdoc
deleted file mode 100644
index 508f9d201f..0000000000
--- a/examples/widgets/doc/src/simplewidgetmapper.qdoc
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/simplewidgetmapper
- \title Simple Widget Mapper Example
- \ingroup examples-itemviews
- \brief The Simple Widget Mapper example shows how to use a widget mapper to display
- data from a model in a collection of widgets.
-
- \image simplewidgetmapper-example.png
-
- The QDataWidgetMapper class allows information obtained from a
- \l{Model Classes}{model} to be viewed and edited in a collection of
- widgets instead of in an \l{View Classes}{item view}.
- Any model derived from QAbstractItemModel can be used as the source of
- data and almost any input widget can be used to display it.
-
- The example itself is very simple: we create \c Window, a QWidget subclass
- that we use to hold the widgets used to present the data, and show it. The
- \c Window class will provide buttons that the user can click to show
- different records from the model.
-
- \section1 Window Class Definition
-
- The class provides a constructor, a slot to keep the buttons up to date,
- and a private function to set up the model:
-
- \snippet itemviews/simplewidgetmapper/window.h Window definition
-
- In addition to the QDataWidgetMapper object and the controls used to make
- up the user interface, we use a QStandardItemModel to hold our data.
- We could use a custom model, but this standard implementation is sufficient
- for our purposes.
-
- \section1 Window Class Implementation
-
- The constructor of the \c Window class can be explained in three parts.
- In the first part, we set up the widgets used for the user interface:
-
- \snippet itemviews/simplewidgetmapper/window.cpp Set up widgets
-
- We also set up the buddy relationships between various labels and the
- corresponding input widgets.
-
- Next, we set up the widget mapper, relating each input widget to a column
- in the model specified by the call to \l{QDataWidgetMapper::}{setModel()}:
-
- \snippet itemviews/simplewidgetmapper/window.cpp Set up the mapper
-
- We also connect the mapper to the \uicontrol{Next} and \uicontrol{Previous} buttons
- via its \l{QDataWidgetMapper::}{toNext()} and
- \l{QDataWidgetMapper::}{toPrevious()} slots. The mapper's
- \l{QDataWidgetMapper::}{currentIndexChanged()} signal is connected to the
- \c{updateButtons()} slot in the window which we'll show later.
-
- In the final part of the constructor, we set up the layout, placing each
- of the widgets in a grid (we could also use a QFormLayout for this):
-
- \snippet itemviews/simplewidgetmapper/window.cpp Set up the layout
-
- Lastly, we set the window title and initialize the mapper by setting it to
- refer to the first row in the model.
-
- The model is initialized in the window's \c{setupModel()} function. Here,
- we create a standard model with 5 rows and 3 columns, and we insert some
- sample names, addresses and ages into each row:
-
- \snippet itemviews/simplewidgetmapper/window.cpp Set up the model
-
- As a result, each row can be treated like a record in a database, and the
- widget mapper will read the data from each row, using the column numbers
- specified earlier to access the correct data for each widget. This is
- shown in the following diagram:
-
- \image widgetmapper-simple-mapping.png
-
- Since the user can navigate using the buttons in the user interface, the
- example is fully-functional at this point, but to make it a bit more
- user-friendly, we implement the \c{updateButtons()} slot to show when the
- user is viewing the first or last records:
-
- \snippet itemviews/simplewidgetmapper/window.cpp Slot for updating the buttons
-
- If the mapper is referring to the first row in the model, the \uicontrol{Previous}
- button is disabled. Similarly, the \uicontrol{Next} button is disabled if the
- mapper reaches the last row in the model.
-
- \section1 More Complex Mappings
-
- The QDataWidgetMapper class makes it easy to relate information from a
- model to widgets in a user interface. However, it is sometimes necessary
- to use input widgets which offer choices to the user, such as QComboBox,
- in conjunction with a widget mapper.
-
- In these situations, although the mapping to input widgets remains simple,
- more work needs to be done to expose additional data to the widget mapper.
- This is covered by the \l{Combo Widget Mapper Example}{Combo Widget Mapper}
- and \l{SQL Widget Mapper Example}{SQL Widget Mapper}
- examples.
-*/
diff --git a/examples/widgets/doc/src/sliders.qdoc b/examples/widgets/doc/src/sliders.qdoc
index 26bfd44131..9bfb4abdc4 100644
--- a/examples/widgets/doc/src/sliders.qdoc
+++ b/examples/widgets/doc/src/sliders.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/sliders
\title Sliders Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The Sliders example shows how to use the different types of sliders
available in Qt: QSlider, QScrollBar and QDial.
@@ -17,7 +18,8 @@
manipulated through their properties.
The example also demonstrates how signals and slots can be used to
- synchronize the behavior of two or more widgets.
+ synchronize the behavior of two or more widgets, and how to override
+ \l{QWidget::}{resizeEvent()} to implement a responsive layout.
\borderedimage sliders-example.png
\caption Screenshot of the Sliders example
@@ -30,10 +32,8 @@
QScrollBar and a QDial.
\li \c Window is the main widget combining a QGroupBox and a
- QStackedWidget. In this example, the QStackedWidget provides a
- stack of two \c SlidersGroup widgets. The QGroupBox contain
- several widgets that control the behavior of the slider-like
- widgets.
+ SlidersGroup. The QGroupBox contains several widgets that control
+ the behavior of the slider-like widgets.
\endlist
@@ -55,28 +55,14 @@
\snippet widgets/sliders/window.cpp 0
- In the constructor we first create the two \c SlidersGroup
- widgets that display the slider widgets horizontally and
- vertically, and add them to the QStackedWidget. QStackedWidget
- provides a stack of widgets where only the top widget is visible.
- With \c createControls() we create a connection from a
- controlling widget to the QStackedWidget, making the user able to
- choose between horizontal and vertical orientation of the slider
- widgets. The rest of the controlling mechanisms is implemented by
- the same function call.
+ In the constructor we first create the \c SlidersGroup widget
+ that displays the slider widgets. With \c createControls() we
+ create the controlling widgets, and connect those to to the
+ sliders.
\snippet widgets/sliders/window.cpp 1
- \snippet widgets/sliders/window.cpp 2
-
- Then we connect the \c horizontalSliders, \c verticalSliders and
- \c valueSpinBox to each other, so that the slider widgets and the
- control widget will behave synchronized when the current value of
- one of them changes. The \c valueChanged() signal is emitted with
- the new value as argument. The \c setValue() slot sets the
- current value of the widget to the new value, and emits \c
- valueChanged() if the new value is different from the old one.
- We put the group of control widgets and the stacked widget in a
+ We put the groups of control widgets and the sliders in a
horizontal layout before we initialize the minimum, maximum and
current values. The initialization of the current value will
propagate to the slider widgets through the connection we made
@@ -84,15 +70,14 @@
minimum and maximum values propagate through the connections we
created with \c createControls().
+ \snippet widgets/sliders/window.cpp 2
\snippet widgets/sliders/window.cpp 3
- \snippet widgets/sliders/window.cpp 4
In the private \c createControls() function, we let a QGroupBox
(\c controlsGroup) display the control widgets. A group box can
provide a frame, a title and a keyboard shortcut, and displays
various other widgets inside itself. The group of control widgets
- is composed by two checkboxes, three spin boxes (with labels) and
- one combobox.
+ is composed by two checkboxes, and three spin boxes with labels.
After creating the labels, we create the two checkboxes.
Checkboxes are typically used to represent features in an
@@ -130,8 +115,8 @@
bindings are inverted by default: \uicontrol PageDown increases the
current value, and \uicontrol PageUp decreases it.
+ \snippet widgets/sliders/window.cpp 4
\snippet widgets/sliders/window.cpp 5
- \snippet widgets/sliders/window.cpp 6
Then we create the spin boxes. QSpinBox allows the user to choose
a value by clicking the up and down buttons or pressing the \uicontrol
@@ -140,14 +125,15 @@
manually. The spin boxes control the minimum, maximum and current
values for the QSlider, QScrollBar, and QDial widgets.
- We create a QComboBox that allows the user to choose the
- orientation of the slider widgets. The QComboBox widget is a
- combined button and popup list. It provides a means of presenting
- a list of options to the user in a way that takes up the minimum
- amount of screen space.
+ \snippet widgets/sliders/window.cpp 6
- \snippet widgets/sliders/window.cpp 7
- \snippet widgets/sliders/window.cpp 8
+ Then we connect the \c slidersGroup and the \c valueSpinBox to each
+ other, so that the slider widgets and the control widget will behave
+ synchronized when the current value of one of them changes.
+ The \c valueChanged() signal is emitted with the new value as
+ argument. The \c setValue() slot sets the current value of the
+ widget to the new value, and emits \c valueChanged() if the new
+ value is different from the old one.
We synchronize the behavior of the control widgets and the slider
widgets through their signals and slots. We connect each control
@@ -157,6 +143,17 @@
lay out the control widgets in a QGridLayout within the \c
controlsGroup group box.
+ \snippet widgets/sliders/window.cpp 7
+
+ Lastly, we override resizeEvent() from QWidget. We guard against
+ dividing by zero, and otherwise compute the aspect ratio of the
+ widget. If the window has a portrait format, then we set the
+ layout to organize the groups of control widgets and sliders
+ vertically, and we give the sliders a horizontal orientation.
+ If the window has a landscape format, then we change the layout
+ to show the sliders and controlling widgets side by side, and
+ give the sliders a vertical orientation.
+
\section1 SlidersGroup Class Definition
\snippet widgets/sliders/slidersgroup.h 0
@@ -169,7 +166,8 @@
slot with equivalent functionality to the ones in QAbstractSlider
and QSpinBox. In addition, we implement several other public
slots to set the minimum and maximum value, and invert the slider
- widgets' appearance as well as key bindings.
+ widgets' appearance as well as key bindings, and set the
+ orientation.
\section1 SlidersGroup Class Implementation
@@ -182,24 +180,21 @@
focus. The Qt::StrongFocus policy means that the widget accepts
focus by both tabbing and clicking.
+ \snippet widgets/sliders/slidersgroup.cpp 1
+
Then we connect the widgets with each other, so that they will
stay synchronized when the current value of one of them changes.
- \snippet widgets/sliders/slidersgroup.cpp 1
- \snippet widgets/sliders/slidersgroup.cpp 2
-
We connect \c {dial}'s \c valueChanged() signal to the
\c{SlidersGroup}'s \c valueChanged() signal, to notify the other
widgets in the application (i.e., the control widgets) of the
changed value.
- \snippet widgets/sliders/slidersgroup.cpp 3
\codeline
\snippet widgets/sliders/slidersgroup.cpp 4
- Finally, depending on the \l {Qt::Orientation}{orientation} given
- at the time of construction, we choose and create the layout for
- the slider widgets within the group box.
+ Finally, we create the layout for the slider widgets within the
+ group box. We start with a horizontal arrangement of the sliders.
\snippet widgets/sliders/slidersgroup.cpp 5
\snippet widgets/sliders/slidersgroup.cpp 6
@@ -232,4 +227,12 @@
\l{QAbstractSlider::invertedAppearance}{invertedAppearance} and
\l{QAbstractSlider::invertedControls}{invertedControls}
properties.
+
+ \snippet widgets/sliders/slidersgroup.cpp 15
+
+ The setOrientation() slot controls the direction of the layout
+ and the orientation of the sliders. In a horizontal group, the
+ sliders have a horizontal orientation, and are laid out on top
+ of each other. In a vertical group, the sliders have a vertical
+ orientation, and are laid out next to each other.
*/
diff --git a/examples/widgets/doc/src/spinboxdelegate.qdoc b/examples/widgets/doc/src/spinboxdelegate.qdoc
deleted file mode 100644
index 025c502113..0000000000
--- a/examples/widgets/doc/src/spinboxdelegate.qdoc
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example itemviews/spinboxdelegate
- \title Spin Box Delegate Example
- \ingroup examples-itemviews
- \brief The Spin Box Delegate example shows how to create an editor for a custom delegate in
- the model/view framework by reusing a standard Qt editor widget.
-
- The model/view framework provides a standard delegate that is used by default
- with the standard view classes. For most purposes, the selection of editor
- widgets available through this delegate is sufficient for editing text, boolean
- values, and other simple data types. However, for specific data types, it is
- sometimes necessary to use a custom delegate to either display the data in a
- specific way, or allow the user to edit it with a custom control.
-
- \image spinboxdelegate-example.png
-
- This concepts behind this example are covered in the
- \l{Model/View Programming#Delegate Classes}{Delegate Classes} chapter
- of the \l{Model/View Programming} overview.
-
- \section1 SpinBoxDelegate Class Definition
-
- The definition of the delegate is as follows:
-
- \snippet itemviews/spinboxdelegate/delegate.h 0
-
- The delegate class declares only those functions that are needed to
- create an editor widget, display it at the correct location in a view,
- and communicate with a model. Custom delegates can also provide their
- own painting code by reimplementing the \c paintEvent() function.
- Furthermore it is also possible to reuse (and avoid deleting) the editor
- widget by reimplementing the \a destroyEditor() function. A reused widget
- could be a mutable member created in the constructor and deleted in
- the destructor.
-
- \section1 SpinBoxDelegate Class Implementation
-
- Delegates are often stateless. The constructor only needs to
- call the base class's constructor with the parent QObject as its
- argument:
-
- \snippet itemviews/spinboxdelegate/delegate.cpp 0
-
- Since the delegate is a subclass of QStyledItemDelegate, the data it retrieves
- from the model is displayed in a default style, and we do not need to
- provide a custom \c paintEvent().
-
- The \c createEditor() function returns an editor widget, in this case a
- spin box that restricts values from the model to integers from 0 to 100
- inclusive.
-
- \snippet itemviews/spinboxdelegate/delegate.cpp 1
-
- We install an event filter on the spin box to ensure that it behaves in
- a way that is consistent with other delegates. The implementation for
- the event filter is provided by the base class.
-
- The \c setEditorData() function reads data from the model, converts it
- to an integer value, and writes it to the editor widget.
-
- \snippet itemviews/spinboxdelegate/delegate.cpp 2
-
- Since the view treats delegates as ordinary QWidget instances, we have
- to use a static cast before we can set the value in the spin box.
-
- The \c setModelData() function reads the contents of the spin box, and
- writes it to the model.
-
- \snippet itemviews/spinboxdelegate/delegate.cpp 3
-
- We call \l{QSpinBox::interpretText()}{interpretText()} to make sure that
- we obtain the most up-to-date value in the spin box.
-
- The \c updateEditorGeometry() function updates the editor widget's
- geometry using the information supplied in the style option. This is the
- minimum that the delegate must do in this case.
-
- \snippet itemviews/spinboxdelegate/delegate.cpp 4
-
- More complex editor widgets may divide the rectangle available in
- \c{option.rect} between different child widgets if required.
-
- \section1 The Main Function
-
- This example is written in a slightly different way to many of the
- other examples supplied with Qt. To demonstrate the use of a custom
- editor widget in a standard view, it is necessary to set up a model
- containing some arbitrary data and a view to display it.
-
- We set up the application in the normal way, construct a standard item
- model to hold some data, set up a table view to use the data in the
- model, and construct a custom delegate to use for editing:
-
- \snippet itemviews/spinboxdelegate/main.cpp 0
-
- The table view is informed about the delegate, and will use it to
- display each of the items. Since the delegate is a subclass of
- QStyledItemDelegate, each cell in the table will be rendered using standard
- painting operations.
-
- We insert some arbitrary data into the model for demonstration purposes:
-
- \snippet itemviews/spinboxdelegate/main.cpp 1
- \snippet itemviews/spinboxdelegate/main.cpp 2
-
- Finally, the table view is displayed with a window title, and we start
- the application's event loop:
-
- \snippet itemviews/spinboxdelegate/main.cpp 3
-
- Each of the cells in the table can now be edited in the usual way, but
- the spin box ensures that the data returned to the model is always
- constrained by the values allowed by the spin box delegate.
-*/
diff --git a/examples/widgets/doc/src/spinboxes.qdoc b/examples/widgets/doc/src/spinboxes.qdoc
index 263fee91a4..eb42696c48 100644
--- a/examples/widgets/doc/src/spinboxes.qdoc
+++ b/examples/widgets/doc/src/spinboxes.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/spinboxes
\title Spin Boxes Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The Spin Boxes example shows how to use the many different types of
spin boxes available in Qt, from a simple QSpinBox widget to more complex
diff --git a/examples/widgets/doc/src/spreadsheet.qdoc b/examples/widgets/doc/src/spreadsheet.qdoc
index 9d7c89d6ec..02d5e0a957 100644
--- a/examples/widgets/doc/src/spreadsheet.qdoc
+++ b/examples/widgets/doc/src/spreadsheet.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/spreadsheet
\title Spreadsheet
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief The Spreadsheet example shows how to create a simple spreadsheet application.
diff --git a/examples/widgets/doc/src/standarddialogs.qdoc b/examples/widgets/doc/src/standarddialogs.qdoc
index 6770c918c8..396f1d1044 100644
--- a/examples/widgets/doc/src/standarddialogs.qdoc
+++ b/examples/widgets/doc/src/standarddialogs.qdoc
@@ -4,6 +4,7 @@
/*!
\example dialogs/standarddialogs
\title Standard Dialogs Example
+ \examplecategory {User Interface Components}
\ingroup examples-dialogs
\brief The Standard Dialogs example shows the standard dialogs that are provided by Qt.
diff --git a/examples/widgets/doc/src/stardelegate.qdoc b/examples/widgets/doc/src/stardelegate.qdoc
index 5d45577cb2..44d75e64f4 100644
--- a/examples/widgets/doc/src/stardelegate.qdoc
+++ b/examples/widgets/doc/src/stardelegate.qdoc
@@ -4,6 +4,7 @@
/*!
\example itemviews/stardelegate
\title Star Delegate Example
+ \examplecategory {User Interface Components}
\ingroup examples-itemviews
\brief The Star Delegate example shows how to create a delegate that
can paint itself and that supports editing.
diff --git a/examples/widgets/doc/src/styleplugin.qdoc b/examples/widgets/doc/src/styleplugin.qdoc
deleted file mode 100644
index d7a1faf2ca..0000000000
--- a/examples/widgets/doc/src/styleplugin.qdoc
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example tools/styleplugin
- \title Style Plugin Example
- \ingroup examples-widgets-tools
-
- \brief This example shows how to create a plugin that extends Qt with a new
- GUI look and feel.
-
- \image stylepluginexample.png
-
- A plugin in Qt is a class stored in a shared library that can be
- loaded by a QPluginLoader at run-time. When you create plugins in
- Qt, they either extend a Qt application or Qt itself. Writing a
- plugin that extends Qt itself is achieved by inheriting one of the
- plugin \l{Plugin Classes}{base classes}, reimplementing functions
- from that class, and adding a macro. In this example we extend Qt
- by adding a new GUI look and feel (i.e., making a new QStyle
- available). A high-level introduction to plugins is given in the
- plugin \l{How to Create Qt Plugins}{overview document}.
-
- Plugins that provide new styles inherit the QStylePlugin base
- class. Style plugins are loaded by Qt and made available through
- QStyleFactory; we will look at this later. We have implemented \c
- SimpleStylePlugin, which provides \c SimpleStyle. The new style
- contributes to widget styling by changing the text color of the
- text edit widget to red - not a major contribution, but it still
- makes a new style.
-
- The new style is platform agnostic in the sense that it is not
- based on any specific style implementation, but uses QProxyStyle
- to merely tweak the looks in the current application style that
- defaults to the native system style.
-
- \note On some platforms, the native style may overwrite some custom
- stylings, e.g., button background color. In that case, try to run
- your application in another style (e.g., fusion). You may do this
- by passing \c{-style fusion} as a command line argument to your
- application.
-
- We test the plugin with \c StyleWindow, in which we display a
- QTextEdit. The \c SimpleStyle and \c StyleWindow classes do not
- contain any plugin specific functionality and their implementations
- are trivial; we will therefore leap past them and head on to the \c
- SimpleStylePlugin and the \c main() function. After we have looked
- at that, we examine the plugin's \c{.pro} file.
-
-
- \section1 SimpleStylePlugin Class Definition
-
- \c SimpleStylePlugin inherits QStylePlugin and is the plugin
- class.
-
- \snippet tools/styleplugin/plugin/simplestyleplugin.h 0
-
- \c keys() returns a list of style names that this plugin can
- create, while \c create() takes such a string and returns the
- QStyle corresponding to the key. Both functions are pure virtual
- functions reimplemented from QStylePlugin. When an application
- requests an instance of the \c SimpleStyle style, which this
- plugin creates, Qt will create it with this plugin.
-
-
- \section1 SimpleStylePlugin Class Implementation
-
- Here is the implementation of \c keys():
-
- \snippet tools/styleplugin/plugin/simplestyleplugin.cpp 0
-
- Since this plugin only supports one style, we return a QStringList
- with the class name of that style.
-
- Here is the \c create() function:
-
- \snippet tools/styleplugin/plugin/simplestyleplugin.cpp 1
-
- Note that the key for style plugins are case insensitive.
- The case sensitivity varies from plugin to plugin, so you need to
- check this when implementing new plugins.
-
- \section1 The \c main() function
-
- \snippet tools/styleplugin/stylewindow/main.cpp 0
-
- Qt loads the available style plugins when the QApplication object
- is initialized. The QStyleFactory class knows about all styles and
- produces them with \l{QStyleFactory::}{create()} (it is a
- wrapper around all the style plugins).
-
- \section1 The Simple Style Plugin's QMake Project File
-
- The \c SimpleStylePlugin lives in its own directory and has
- its own \c{.pro} file:
-
- \snippet tools/styleplugin/plugin/plugin.pro 0
-
- In the plugin \c{.pro} file we need to set the lib template as we are
- building a shared library instead of an executable. We must also
- set the config to plugin. We set the library to be stored in the
- \c{styles} folder next to the main executable because this is a path
- in which Qt will search for style plugins.
-
- \section2 Using CMake to Set up the Simple Style Plugin
-
- When using CMake, we use \l{qt6_add_plugin}{qt_add_plugin}
- to create the \c simplestyleplugin plugin:
-
- \snippet tools/styleplugin/plugin/CMakeLists.txt 0
-
- On Windows and Linux, we place the plugin into the \c{styles} folder
- next to the main executable, i.e., \c{styleplugin.exe}:
-
- \snippet tools/styleplugin/plugin/CMakeLists.txt 2
-
- And on macOS, we store the \c simplestyleplugin into the
- \c{Contents/PlugIns/styles} folder of the App Bundle.
-
- \snippet tools/styleplugin/plugin/CMakeLists.txt 1
-
- \note On macOS, when creating an App Bundle, store the plugins in
- the \c PlugIns folder and not next to the main executable in
- the \c MacOS folder as the latter will cause issues during signing
- and distribution of the app.
-
- \section1 Related Articles and Examples
-
- In addition to the plugin \l{How to Create Qt Plugins}{overview
- document}, we have other examples and articles that concern
- plugins.
-
- In the \l{Echo Plugin Example}{echo plugin example} we show how to
- implement plugins that extends Qt applications rather than Qt
- itself, which is the case with the style plugin of this example.
- The \l{Plug & Paint Example}{plug & paint} example shows how to
- implement a static plugin as well as being a more involved example
- on plugins that extend applications.
-*/
diff --git a/examples/widgets/doc/src/styles.qdoc b/examples/widgets/doc/src/styles.qdoc
deleted file mode 100644
index 19ac0ee452..0000000000
--- a/examples/widgets/doc/src/styles.qdoc
+++ /dev/null
@@ -1,448 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/styles
- \title Styles Example
- \ingroup examples-widgets
- \brief The Styles example illustrates how to create custom widget
- drawing styles using Qt, and demonstrates Qt's predefined styles.
-
- \borderedimage styles-enabledwood.png
- \caption Screenshot of the Styles example
-
- A style in Qt is a subclass of QStyle or of one of its
- subclasses. Styles perform drawing on behalf of widgets. Qt
- provides a whole range of predefined styles, either built into
- the Qt Widgets module or found in plugins. Styles are usually
- customized by subclassing QProxyStyle and reimplementing a few
- virtual functions. While QProxyStyle provides a transparent way
- to customize either a specific style or the appropriate platform's
- default style, Qt also provides QCommonStyle as a convenient base
- for full custom style implementations.
-
- In this example, the custom style is called \c NorwegianWoodStyle
- and derives from QProxyStyle. Its main features are the wooden
- textures used for filling most of the widgets and its round
- buttons and comboboxes.
-
- To implement the style, we use some advanced features provided by
- QPainter, such as \l{QPainter::Antialiasing}{antialiasing} (to
- obtain smoother button edges), \l{QColor::alpha()}{alpha blending}
- (to make the buttons appeared raised or sunken), and
- \l{QPainterPath}{painter paths} (to fill the buttons and draw the
- outline). We also use many features of QBrush and QPalette.
-
- The example consists of the following classes:
-
- \list
- \li \c NorwegianWoodStyle inherits from QProxyStyle and implements
- the Norwegian Wood style.
- \li \c WidgetGallery is a \c QDialog subclass that shows the most
- common widgets and allows the user to switch style
- dynamically.
- \endlist
-
- \section1 NorwegianWoodStyle Class Definition
-
- Here's the definition of the \c NorwegianWoodStyle class:
-
- \snippet widgets/styles/norwegianwoodstyle.h 0
-
- The public functions are all declared in QStyle (QProxyStyle's
- grandparent class) and reimplemented here to override the Windows
- look and feel. The private functions are helper functions.
-
- \section1 NorwegianWoodStyle Class Implementation
-
- We will now review the implementation of the \c
- NorwegianWoodStyle class.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 0
-
- The \c standardPalette() function is reimplemented from QStyle.
- It returns a QPalette with the style's preferred colors and textures.
- Most styles don't need to reimplement that function. The
- Norwegian Wood style reimplements it to set a "wooden" palette.
-
- We start by defining a few \l{QColor}s that we'll need. Then we
- load two PNG images. The \c : prefix in the file path indicates
- that the PNG files are \l{The Qt Resource System}{embedded
- resources}.
-
- \table
- \row \li \inlineimage widgets/styles/images/woodbackground.png
-
- \li \b{woodbackground.png}
-
- This texture is used as the background of most widgets.
- The wood pattern is horizontal.
-
- \row \li \inlineimage widgets/styles/images/woodbutton.png
-
- \li \b{woodbutton.png}
-
- This texture is used for filling push buttons and
- comboboxes. The wood pattern is vertical and more reddish
- than the texture used for the background.
- \endtable
-
- The \c midImage variable is initialized to be the same as \c
- buttonImage, but then we use a QPainter and fill it with a 25%
- opaque black color (a black with an \l{QColor::alpha()}{alpha
- channel} of 63). The result is a somewhat darker image than \c
- buttonImage. This image will be used for filling buttons that the
- user is holding down.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 1
-
- We initialize the palette. Palettes have various
- \l{QPalette::ColorRole}{color roles}, such as QPalette::Base
- (used for filling text editors, item views, etc.), QPalette::Text
- (used for foreground text), and QPalette::Window (used for
- the background of most widgets). Each role has its own QBrush,
- which usually is a plain color but can also be a brush pattern or
- even a texture (a QPixmap).
-
- In addition to the roles, palettes have several
- \l{QPalette::ColorGroup}{color groups}: active, disabled, and
- inactive. The active color group is used for painting widgets in
- the active window. The disabled group is used for disabled
- widgets. The inactive group is used for all other widgets. Most
- palettes have identical active and inactive groups, while the
- disabled group uses darker shades.
-
- We initialize the QPalette object with a brown color. Qt
- automatically derivates all color roles for all color groups from
- that single color. We then override some of the default values. For
- example, we use Qt::darkGreen instead of the default
- (Qt::darkBlue) for the QPalette::Highlight role. The
- QPalette::setBrush() overload that we use here sets the same
- color or brush for all three color groups.
-
- The \c setTexture() function is a private function that sets the
- texture for a certain color role, while preserving the existing
- color in the QBrush. A QBrush can hold both a solid color and a
- texture at the same time. The solid color is used for drawing
- text and other graphical elements where textures don't look good.
-
- At the end, we set the brush for the disabled color group of the
- palette. We use \c woodbackground.png as the texture for all
- disabled widgets, including buttons, and use a darker color to
- accompany the texture.
-
- \image styles-disabledwood.png The Norwegian Wood style with disabled widgets
-
- Let's move on to the other functions reimplemented from
- QProxyStyle:
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 3
- \snippet widgets/styles/norwegianwoodstyle.cpp 4
-
- This QStyle::polish() overload is called once on every widget
- drawn using the style. We reimplement it to set the Qt::WA_Hover
- attribute on \l{QPushButton}s and \l{QComboBox}es. When this
- attribute is set, Qt generates paint events when the mouse
- pointer enters or leaves the widget. This makes it possible to
- render push buttons and comboboxes differently when the mouse
- pointer is over them.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 5
- \snippet widgets/styles/norwegianwoodstyle.cpp 6
-
- This QStyle::unpolish() overload is called to undo any
- modification done to the widget in \c polish(). For simplicity,
- we assume that the flag wasn't set before \c polish() was called.
- In an ideal world, we would remember the original state for each
- widgets (e.g., using a QMap<QWidget *, bool>) and restore it in
- \c unpolish().
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 7
- \snippet widgets/styles/norwegianwoodstyle.cpp 8
-
- The \l{QStyle::pixelMetric()}{pixelMetric()} function returns the
- size in pixels for a certain user interface element. By
- reimplementing this function, we can affect the way certain
- widgets are drawn and their size hint. Here, we return 8 as the
- width around a shown in a QComboBox, ensuring that there is
- enough place around the text and the arrow for the Norwegian Wood
- round corners. The default value for this setting in the Windows
- style is 2.
-
- We also change the extent of \l{QScrollBar}s, i.e., the height
- for a horizontal scroll bar and the width for a vertical scroll
- bar, to be 4 pixels more than in the Windows style. This makes the
- style a bit more distinctive.
-
- For all other QStyle::PixelMetric elements, we use the Windows
- settings.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 9
- \snippet widgets/styles/norwegianwoodstyle.cpp 10
-
- The \l{QStyle::styleHint()}{styleHint()} function returns some
- hints to widgets or to the base style (in our case QProxyStyle)
- about how to draw the widgets. The Windows style returns \c true
- for the QStyle::SH_DitherDisabledText hint, resulting in a most
- unpleasing visual effect. We override this behavior and return \c
- false instead. We also return \c true for the
- QStyle::SH_EtchDisabledText hint, meaning that disabled text is
- rendered with an embossed look.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 11
- \snippet widgets/styles/norwegianwoodstyle.cpp 12
-
- The \l{QStyle::drawPrimitive()}{drawPrimitive()} function is
- called by Qt widgets to draw various fundamental graphical
- elements. Here we reimplement it to draw QPushButton and
- QComboBox with round corners. The button part of these widgets is
- drawn using the QStyle::PE_PanelButtonCommand primitive element.
-
- The \c option parameter, of type QStyleOption, contains
- everything we need to know about the widget we want to draw on.
- In particular, \c option->rect gives the rectangle within which
- to draw the primitive element. The \c painter parameter is a
- QPainter object that we can use to draw on the widget.
-
- The \c widget parameter is the widget itself. Normally, all the
- information we need is available in \c option and \c painter, so
- we don't need \c widget. We can use it to perform special
- effects; for example, QMacStyle uses it to animate default
- buttons. If you use it, be aware that the caller is allowed to
- pass a null pointer.
-
- We start by defining three \l{QColor}s that we'll need later on.
- We also put the x, y, width, and height components of the
- widget's rectangle in local variables. The value used for the \c
- semiTransparentWhite and for the \c semiTransparentBlack color's
- alpha channel depends on whether the mouse cursor is over the
- widget or not. Since we set the Qt::WA_Hover attribute on
- \l{QPushButton}s and \l{QComboBox}es, we can rely on the
- QStyle::State_MouseOver flag to be set when the mouse is over the
- widget.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 13
- \snippet widgets/styles/norwegianwoodstyle.cpp 14
-
- The \c roundRect variable is a QPainterPath. A QPainterPath is
- a vectorial specification of a shape. Any shape (rectangle,
- ellipse, spline, etc.) or combination of shapes can be expressed
- as a path. We will use \c roundRect both for filling the button
- background with a wooden texture and for drawing the outline. The
- \c roundRectPath() function is a private function; we will come
- back to it later.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 15
- \snippet widgets/styles/norwegianwoodstyle.cpp 16
- \snippet widgets/styles/norwegianwoodstyle.cpp 17
- \snippet widgets/styles/norwegianwoodstyle.cpp 18
-
- We define two variables, \c brush and \c darker, and initialize
- them based on the state of the button:
-
- \list
- \li If the button is a \l{QPushButton::flat}{flat button}, we use
- the \l{QPalette::Window}{Window} brush. We set \c
- darker to \c true if the button is
- \l{QAbstractButton::down}{down} or
- \l{QAbstractButton::checked}{checked}.
- \li If the button is currently held down by the user or in the
- \l{QAbstractButton::checked}{checked} state, we use the
- \l{QPalette::Mid}{Mid} component of the palette. We set
- \c darker to \c true if the button is
- \l{QAbstractButton::checked}{checked}.
- \li Otherwise, we use the \l{QPalette::Button}{Button} component
- of the palette.
- \endlist
-
- The screenshot below illustrates how \l{QPushButton}s are
- rendered based on their state:
-
- \image styles-woodbuttons.png Norwegian Wood buttons in different states
-
- To discover whether the button is flat or not, we need to cast
- the \c option parameter to QStyleOptionButton and check if the
- \l{QStyleOptionButton::features}{features} member specifies the
- QStyleOptionButton::Flat flag. The qstyleoption_cast() function
- performs a dynamic cast; if \c option is not a
- QStyleOptionButton, qstyleoption_cast() returns a null pointer.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 19
- \snippet widgets/styles/norwegianwoodstyle.cpp 20
- \snippet widgets/styles/norwegianwoodstyle.cpp 21
- \snippet widgets/styles/norwegianwoodstyle.cpp 22
- \snippet widgets/styles/norwegianwoodstyle.cpp 23
-
- We turn on antialiasing on QPainter. Antialiasing is a technique
- that reduces the visual distortion that occurs when the edges of
- a shape are converted into pixels. For the Norwegian Wood style,
- we use it to obtain smoother edges for the round buttons.
-
- \image styles-aliasing.png Norwegian wood buttons with and without antialiasing
-
- The first call to QPainter::fillPath() draws the background of
- the button with a wooden texture. The second call to
- \l{QPainter::fillPath()}{fillPath()} paints the same area with a
- semi-transparent black color (a black color with an alpha channel
- of 63) to make the area darker if \c darker is true.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 24
- \snippet widgets/styles/norwegianwoodstyle.cpp 25
-
- Next, we draw the outline. The top-left half of the outline and
- the bottom-right half of the outline are drawn using different
- \l{QPen}s to produce a 3D effect. Normally, the top-left half of
- the outline is drawn lighter whereas the bottom-right half is
- drawn darker, but if the button is
- \l{QAbstractButton::down}{down} or
- \l{QAbstractButton::checked}{checked}, we invert the two
- \l{QPen}s to give a sunken look to the button.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 26
-
- We draw the top-left part of the outline by calling
- QPainter::drawPath() with an appropriate
- \l{QPainter::setClipRegion()}{clip region}. If the
- \l{QStyleOption::direction}{layout direction} is right-to-left
- instead of left-to-right, we swap the \c x1, \c x2, \c x3, and \c
- x4 variables to obtain correct results. On right-to-left desktop,
- the "light" comes from the top-right corner of the screen instead
- of the top-left corner; raised and sunken widgets must be drawn
- accordingly.
-
- The diagram below illustrates how 3D effects are drawn according
- to the layout direction. The area in red on the diagram
- corresponds to the \c topHalf polygon:
-
- \image styles-3d.png
-
- An easy way to test how a style looks in right-to-left mode is to
- pass the \c -reverse command-line option to the application. This
- option is recognized by the QApplication constructor.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 32
- \snippet widgets/styles/norwegianwoodstyle.cpp 33
- \snippet widgets/styles/norwegianwoodstyle.cpp 34
-
- The bottom-right part of the outline is drawn in a similar
- fashion. Then we draw a one-pixel wide outline around the entire
- button, using the \l{QPalette::WindowText}{WindowText} component
- of the QPalette.
-
- This completes the QStyle::PE_PanelButtonCommand case of the \c
- switch statement. Other primitive elements are handled by the
- base style. Let's now turn to the other \c NorwegianWoodStyle
- member functions:
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 35
- \snippet widgets/styles/norwegianwoodstyle.cpp 36
-
- We reimplement QStyle::drawControl() to draw the text on a
- QPushButton in a bright color when the button is
- \l{QAbstractButton::down}{down} or
- \l{QAbstractButton::checked}{checked}.
-
- If the \c option parameter points to a QStyleOptionButton object
- (it normally should), we take a copy of the object and modify its
- \l{QStyleOption::palette}{palette} member to make the
- QPalette::ButtonText be the same as the QPalette::BrightText
- component (unless the widget is disabled).
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 37
- \snippet widgets/styles/norwegianwoodstyle.cpp 38
-
- The \c setTexture() function is a private function that sets the
- \l{QBrush::texture()}{texture} component of the \l{QBrush}es for
- a certain \l{QPalette::ColorRole}{color role}, for all three
- \l{QPalette::ColorGroup}{color groups} (active, disabled,
- inactive). We used it to initialize the Norwegian Wood palette in
- \c standardPalette.
-
- \snippet widgets/styles/norwegianwoodstyle.cpp 39
- \snippet widgets/styles/norwegianwoodstyle.cpp 40
-
- The \c roundRectPath() function is a private function that
- constructs a QPainterPath object for round buttons. The path
- consists of eight segments: four arc segments for the corners and
- four lines for the sides.
-
- With around 250 lines of code, we have a fully functional custom
- style based on one of the predefined styles. Custom styles can be
- used to provide a distinct look to an application or family of
- applications.
-
- \section1 WidgetGallery Class
-
- For completeness, we will quickly review the \c WidgetGallery
- class, which contains the most common Qt widgets and allows the
- user to change style dynamically. Here's the class definition:
-
- \snippet widgets/styles/widgetgallery.h 0
- \dots
- \snippet widgets/styles/widgetgallery.h 1
-
- Here's the \c WidgetGallery constructor:
-
- \snippet widgets/styles/widgetgallery.cpp 0
-
- We start by creating child widgets. The \uicontrol Style combobox is
- initialized with all the styles known to QStyleFactory, in
- addition to \c NorwegianWood. The \c create...() functions are
- private functions that set up the various parts of the \c
- WidgetGallery.
-
- \snippet widgets/styles/widgetgallery.cpp 1
- \snippet widgets/styles/widgetgallery.cpp 2
-
- We connect the \uicontrol Style combobox to the \c changeStyle()
- private slot, the \uicontrol{Use style's standard palette} check box to
- the \c changePalette() slot, and the \uicontrol{Disable widgets} check
- box to the child widgets'
- \l{QWidget::setDisabled()}{setDisabled()} slot.
-
- \snippet widgets/styles/widgetgallery.cpp 3
- \snippet widgets/styles/widgetgallery.cpp 4
-
- Finally, we put the child widgets in layouts.
-
- \snippet widgets/styles/widgetgallery.cpp 5
- \snippet widgets/styles/widgetgallery.cpp 6
-
- When the user changes the style in the combobox, we call
- QApplication::setStyle() to dynamically change the style of the
- application.
-
- \snippet widgets/styles/widgetgallery.cpp 7
- \snippet widgets/styles/widgetgallery.cpp 8
-
- If the user turns the \uicontrol{Use style's standard palette} on, the
- current style's \l{QStyle::standardPalette()}{standard palette}
- is used; otherwise, the system's default palette is honored.
-
- \snippet widgets/styles/widgetgallery.cpp 9
- \snippet widgets/styles/widgetgallery.cpp 10
-
- The \c advanceProgressBar() slot is called at regular intervals
- to advance the progress bar. Since we don't know how long the
- user will keep the Styles application running, we use a
- logarithmic formula: The closer the progress bar gets to 100%,
- the slower it advances.
-
- We will review \c createProgressBar() in a moment.
-
- \snippet widgets/styles/widgetgallery.cpp 11
- \snippet widgets/styles/widgetgallery.cpp 12
-
- The \c createTopLeftGroupBox() function creates the QGroupBox
- that occupies the top-left corner of the \c WidgetGallery. We
- skip the \c createTopRightGroupBox(), \c
- createBottomLeftTabWidget(), and \c createBottomRightGroupBox()
- functions, which are very similar.
-
- \snippet widgets/styles/widgetgallery.cpp 13
-
- In \c createProgressBar(), we create a QProgressBar at the bottom
- of the \c WidgetGallery and connect its
- \l{QTimer::timeout()}{timeout()} signal to the \c
- advanceProgressBar() slot.
-*/
diff --git a/examples/widgets/doc/src/stylesheet.qdoc b/examples/widgets/doc/src/stylesheet.qdoc
deleted file mode 100644
index b85ccdb015..0000000000
--- a/examples/widgets/doc/src/stylesheet.qdoc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/stylesheet
- \title Style Sheet Example
- \ingroup examples-widgets
- \brief The Style Sheet Example shows how to use style sheets.
-
- \borderedimage stylesheet-pagefold.png
- \caption Screen Shot of the Pagefold style sheet
-
- The Style Sheet example shows how widgets can be styled using Qt Style Sheets.
- You can open the style editor by selecting \uicontrol File > \uicontrol Edit Style Sheet,
- to select an existing style sheet or design your own style and load it.
-
- The Style Sheet example consists of 2 classes:
- \list
- \li \c MainWindow
- \li \c StyleSheetEditor
- \endlist
-
-
- \section1 MainWindow Class
-
- \c MainWindow inherits QWidget, and is the application's main window defined in
- \c mainwindow.ui. The style of \c MainWindow can be modified with \c StyleSheetEditor.
-
-
- \section1 StyleSheetEditor Class
-
- \c StyleSheetEditor enables you to open an editor where you can load an existing style sheet.
- It is also possible to define a new stylesheet and load it. Its layout is defined in
- \c stylesheeteditor.ui.
-
- \quotefromfile widgets/stylesheet/stylesheeteditor.cpp
- \skipto setStyleName
- \printline setStyleName
-
- Sets the specified \a styleName and grays the \c applyButton.
-
- \skipto setStyleSheetName
- \printline setStyleSheetName
-
- Loads the stylesheet from \c styleSheetName.
-
- \skipto setModified()
- \printline setModified()
-
- Enables the \c applyButton when the text in the buffer has changed.
-
- \skipto apply()
- \printline apply()
-
- Sets the stylesheet properties in \l qApp and disables the \c applyButton.
-
- \skipto loadStyleSheet(const QString &sheetName)
- \printline loadStyleSheet(const QString &sheetName)
-
- Loads the specified \a sheetName, and sets its properties in
- \l qApp.
-
-*/
-
diff --git a/examples/widgets/doc/src/syntaxhighlighter.qdoc b/examples/widgets/doc/src/syntaxhighlighter.qdoc
index bdd13abdf3..17bcc1fa06 100644
--- a/examples/widgets/doc/src/syntaxhighlighter.qdoc
+++ b/examples/widgets/doc/src/syntaxhighlighter.qdoc
@@ -4,6 +4,7 @@
/*!
\example richtext/syntaxhighlighter
\title Syntax Highlighter Example
+ \examplecategory {User Interface Components}
\ingroup examples-richtext
\brief The Syntax Highlighter example shows how to perform
simple syntax highlighting.
diff --git a/examples/widgets/doc/src/tabdialog.qdoc b/examples/widgets/doc/src/tabdialog.qdoc
index f3887c94c8..fb45bbae04 100644
--- a/examples/widgets/doc/src/tabdialog.qdoc
+++ b/examples/widgets/doc/src/tabdialog.qdoc
@@ -4,6 +4,7 @@
/*!
\example dialogs/tabdialog
\title Tab Dialog Example
+ \examplecategory {User Interface Components}
\ingroup examples-dialogs
\brief The Tab Dialog example shows how to construct a tab dialog using the
diff --git a/examples/widgets/doc/src/tablet.qdoc b/examples/widgets/doc/src/tablet.qdoc
index efbb769e64..9d49d8dec8 100644
--- a/examples/widgets/doc/src/tablet.qdoc
+++ b/examples/widgets/doc/src/tablet.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/tablet
\title Tablet Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief This example shows how to use a Wacom tablet in Qt applications.
@@ -13,7 +14,7 @@
generated. You need to reimplement the \l{QWidget::}{tabletEvent()} event
handler if you want to handle tablet events. Events are generated when the
tool (stylus) used for drawing enters and leaves the proximity of the
- tablet (i.e., when it is close but not pressed down on it), when the tool
+ tablet (i.e., when it is closed but not pressed down on it), when the tool
is pressed down and released from it, when the tool is moved across the
tablet, and when one of the buttons on the tool is pressed or released.
@@ -31,7 +32,7 @@
draw on the tablet as you use a pencil on paper. When you draw with the
airbrush you get a spray of virtual paint; the finger wheel is used to
change the density of the spray. When you draw with the art pen, you get a
- a line whose width and endpoint angle depend on the rotation of the pen.
+ line whose width and endpoint angle depend on the rotation of the pen.
The pressure and tilt can also be assigned to change the alpha and
saturation values of the color and the width of the stroke.
@@ -88,8 +89,6 @@
in a submenu of the \b Tablet menu, for selecting which property of each
QTabletEvent will be used to vary the translucency (alpha channel) of the
line being drawn or color being airbrushed.
- (See the \l{Qt Widgets - Application Example}{application example} if you want
- a high-level introduction to QActions.)
\snippet widgets/tablet/mainwindow.cpp 9
diff --git a/examples/widgets/doc/src/tetrix.qdoc b/examples/widgets/doc/src/tetrix.qdoc
deleted file mode 100644
index 1f6ed76047..0000000000
--- a/examples/widgets/doc/src/tetrix.qdoc
+++ /dev/null
@@ -1,407 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/tetrix
- \title Tetrix Example
- \ingroup examples-widgets
- \brief The Tetrix example is a Qt version of the classic Tetrix game.
-
- \borderedimage tetrix-example.png
-
- The object of the game is to stack pieces dropped from the top of the
- playing area so that they fill entire rows at the bottom of the playing area.
-
- When a row is filled, all the blocks on that row are removed, the player earns
- a number of points, and the pieces above are moved down to occupy that row.
- If more than one row is filled, the blocks on each row are removed, and the
- player earns extra points.
-
- The \uicontrol{Left} cursor key moves the current piece one space to the left, the
- \uicontrol{Right} cursor key moves it one space to the right, the \uicontrol{Up} cursor
- key rotates the piece counter-clockwise by 90 degrees, and the \uicontrol{Down}
- cursor key rotates the piece clockwise by 90 degrees.
-
- To avoid waiting for a piece to fall to the bottom of the board, press \uicontrol{D}
- to immediately move the piece down by one row, or press the \uicontrol{Space} key to
- drop it as close to the bottom of the board as possible.
-
- This example shows how a simple game can be created using only three classes:
-
- \list
- \li The \c TetrixWindow class is used to display the player's score, number of
- lives, and information about the next piece to appear.
- \li The \c TetrixBoard class contains the game logic, handles keyboard input, and
- displays the pieces on the playing area.
- \li The \c TetrixPiece class contains information about each piece.
- \endlist
-
- In this approach, the \c TetrixBoard class is the most complex class, since it
- handles the game logic and rendering. One benefit of this is that the
- \c TetrixWindow and \c TetrixPiece classes are very simple and contain only a
- minimum of code.
-
- \section1 TetrixWindow Class Definition
-
- The \c TetrixWindow class is used to display the game information and contains
- the playing area:
-
- \snippet widgets/tetrix/tetrixwindow.h 0
-
- We use private member variables for the board, various display widgets, and
- buttons to allow the user to start a new game, pause the current game, and quit.
-
- Although the window inherits QWidget, the constructor does not provide an
- argument to allow a parent widget to be specified. This is because the window
- will always be used as a top-level widget.
-
- \section1 TetrixWindow Class Implementation
-
- The constructor sets up the user interface elements for the game:
-
- \snippet widgets/tetrix/tetrixwindow.cpp 0
-
- We begin by constructing a \c TetrixBoard instance for the playing area and a
- label that shows the next piece to be dropped into the playing area; the label
- is initially empty.
-
- Three QLCDNumber objects are used to display the score, number of lives, and
- lines removed. These initially show default values, and will be filled in
- when a game begins:
-
- \snippet widgets/tetrix/tetrixwindow.cpp 1
-
- Three buttons with shortcuts are constructed so that the user can start a
- new game, pause the current game, and quit the application:
-
- \snippet widgets/tetrix/tetrixwindow.cpp 2
- \snippet widgets/tetrix/tetrixwindow.cpp 3
-
- These buttons are configured so that they never receive the keyboard focus;
- we want the keyboard focus to remain with the \c TetrixBoard instance so that
- it receives all the keyboard events. Nonetheless, the buttons will still respond
- to \uicontrol{Alt} key shortcuts.
-
- We connect \l{QAbstractButton::}{clicked()} signals from the \uicontrol{Start}
- and \uicontrol{Pause} buttons to the board, and from the \uicontrol{Quit} button to the
- application's \l{QCoreApplication::quit()} slot.
-
- \snippet widgets/tetrix/tetrixwindow.cpp 4
- \snippet widgets/tetrix/tetrixwindow.cpp 5
-
- Signals from the board are also connected to the LCD widgets for the purpose of
- updating the score, number of lives, and lines removed from the playing area.
-
- We place the label, LCD widgets, and the board into a QGridLayout
- along with some labels that we create with the \c createLabel() convenience
- function:
-
- \snippet widgets/tetrix/tetrixwindow.cpp 6
-
- Finally, we set the grid layout on the widget, give the window a title, and
- resize it to an appropriate size.
-
- The \c createLabel() convenience function simply creates a new label on the
- heap, gives it an appropriate alignment, and returns it to the caller:
-
- \snippet widgets/tetrix/tetrixwindow.cpp 7
-
- Since each label will be used in the widget's layout, it will become a child
- of the \c TetrixWindow widget and, as a result, it will be deleted when the
- window is deleted.
-
- \section1 TetrixPiece Class Definition
-
- The \c TetrixPiece class holds information about a piece in the game's
- playing area, including its shape, position, and the range of positions it can
- occupy on the board:
-
- \snippet widgets/tetrix/tetrixpiece.h 0
-
- Each shape contains four blocks, and these are defined by the \c coords private
- member variable. Additionally, each piece has a high-level description that is
- stored internally in the \c pieceShape variable.
-
- The constructor is written inline in the definition, and simply ensures that
- each piece is initially created with no shape. The \c shape() function simply
- returns the contents of the \c pieceShape variable, and the \c x() and \c y()
- functions return the x and y-coordinates of any given block in the shape.
-
- \section1 TetrixPiece Class Implementation
-
- The \c setRandomShape() function is used to select a random shape for a piece:
-
- \snippet widgets/tetrix/tetrixpiece.cpp 0
-
- For convenience, it simply chooses a random shape from the \c TetrixShape enum
- and calls the \c setShape() function to perform the task of positioning the
- blocks.
-
- The \c setShape() function uses a look-up table of pieces to associate each
- shape with an array of block positions:
-
- \snippet widgets/tetrix/tetrixpiece.cpp 1
- \snippet widgets/tetrix/tetrixpiece.cpp 2
-
- These positions are read from the table into the piece's own array of positions,
- and the piece's internal shape information is updated to use the new shape.
-
- The \c x() and \c y() functions are implemented inline in the class definition,
- returning positions defined on a grid that extends horizontally and vertically
- with coordinates from -2 to 2. Although the predefined coordinates for each
- piece only vary horizontally from -1 to 1 and vertically from -1 to 2, each
- piece can be rotated by 90, 180, and 270 degrees.
-
- The \c minX() and \c maxX() functions return the minimum and maximum horizontal
- coordinates occupied by the blocks that make up the piece:
-
- \snippet widgets/tetrix/tetrixpiece.cpp 3
- \snippet widgets/tetrix/tetrixpiece.cpp 4
-
- Similarly, the \c minY() and \c maxY() functions return the minimum and maximum
- vertical coordinates occupied by the blocks:
-
- \snippet widgets/tetrix/tetrixpiece.cpp 5
- \snippet widgets/tetrix/tetrixpiece.cpp 6
-
- The \c rotatedLeft() function returns a new piece with the same shape as an
- existing piece, but rotated counter-clockwise by 90 degrees:
-
- \snippet widgets/tetrix/tetrixpiece.cpp 7
-
- Similarly, the \c rotatedRight() function returns a new piece with the same
- shape as an existing piece, but rotated clockwise by 90 degrees:
-
- \snippet widgets/tetrix/tetrixpiece.cpp 9
-
- These last two functions enable each piece to create rotated copies of itself.
-
- \section1 TetrixBoard Class Definition
-
- The \c TetrixBoard class inherits from QFrame and contains the game logic and display features:
-
- \snippet widgets/tetrix/tetrixboard.h 0
-
- Apart from the \c setNextPieceLabel() function and the \c start() and \c pause()
- public slots, we only provide public functions to reimplement QWidget::sizeHint()
- and QWidget::minimumSizeHint(). The signals are used to communicate changes to
- the player's information to the \c TetrixWindow instance.
-
- The rest of the functionality is provided by reimplementations of protected event
- handlers and private functions:
-
- \snippet widgets/tetrix/tetrixboard.h 1
-
- The board is composed of a fixed-size array whose elements correspond to
- spaces for individual blocks. Each element in the array contains a \c TetrixShape
- value corresponding to the type of shape that occupies that element.
-
- Each shape on the board will occupy four elements in the array, and these will
- all contain the enum value that corresponds to the type of the shape.
-
- We use a QBasicTimer to control the rate at which pieces fall toward the bottom
- of the playing area. This allows us to provide an implementation of
- \l{QObject::}{timerEvent()} that we can use to update the widget.
-
- \section1 TetrixBoard Class Implementation
-
- In the constructor, we customize the frame style of the widget, ensure that
- keyboard input will be received by the widget by using Qt::StrongFocus for the
- focus policy, and initialize the game state:
-
- \snippet widgets/tetrix/tetrixboard.cpp 0
-
- The first (next) piece is also set up with a random shape.
-
- The \c setNextPieceLabel() function is used to pass in an externally-constructed
- label to the board, so that it can be shown alongside the playing area:
-
- \snippet widgets/tetrix/tetrixboard.cpp 1
-
- We provide a reasonable size hint and minimum size hint for the board, based on
- the size of the space for each block in the playing area:
-
- \snippet widgets/tetrix/tetrixboard.cpp 2
- \snippet widgets/tetrix/tetrixboard.cpp 3
-
- By using a minimum size hint, we indicate to the layout in the parent widget
- that the board should not shrink below a minimum size.
-
- A new game is started when the \c start() slot is called. This resets the
- game's state, the player's score and level, and the contents of the board:
-
- \snippet widgets/tetrix/tetrixboard.cpp 4
-
- We also emit signals to inform other components of these changes before creating
- a new piece that is ready to be dropped into the playing area. We start the
- timer that determines how often the piece drops down one row on the board.
-
- The \c pause() slot is used to temporarily stop the current game by stopping the
- internal timer:
-
- \snippet widgets/tetrix/tetrixboard.cpp 5
- \snippet widgets/tetrix/tetrixboard.cpp 6
-
- We perform checks to ensure that the game can only be paused if it is already
- running and not already paused.
-
- The \c paintEvent() function is straightforward to implement. We begin by
- calling the base class's implementation of \l{QWidget::}{paintEvent()} before
- constructing a QPainter for use on the board:
-
- \snippet widgets/tetrix/tetrixboard.cpp 7
-
- Since the board is a subclass of QFrame, we obtain a QRect that covers the area
- \e inside the frame decoration before drawing our own content.
-
- If the game is paused, we want to hide the existing state of the board and
- show some text. We achieve this by painting text onto the widget and returning
- early from the function. The rest of the painting is performed after this point.
-
- The position of the top of the board is found by subtracting the total height
- of each space on the board from the bottom of the frame's internal rectangle.
- For each space on the board that is occupied by a piece, we call the
- \c drawSquare() function to draw a block at that position.
-
- \snippet widgets/tetrix/tetrixboard.cpp 8
- \snippet widgets/tetrix/tetrixboard.cpp 9
-
- Spaces that are not occupied by blocks are left blank.
-
- Unlike the existing pieces on the board, the current piece is drawn
- block-by-block at its current position:
-
- \snippet widgets/tetrix/tetrixboard.cpp 10
- \snippet widgets/tetrix/tetrixboard.cpp 11
- \snippet widgets/tetrix/tetrixboard.cpp 12
-
- The \c keyPressEvent() handler is called whenever the player presses a key while
- the \c TetrixBoard widget has the keyboard focus.
-
- \snippet widgets/tetrix/tetrixboard.cpp 13
-
- If there is no current game, the game is running but paused, or if there is no
- current shape to control, we simply pass on the event to the base class.
-
- We check whether the event is about any of the keys that the player uses to
- control the current piece and, if so, we call the relevant function to handle
- the input:
-
- \snippet widgets/tetrix/tetrixboard.cpp 14
-
- In the case where the player presses a key that we are not interested in, we
- again pass on the event to the base class's implementation of
- \l{QWidget::}{keyPressEvent()}.
-
- The \c timerEvent() handler is called every time the class's QBasicTimer
- instance times out. We need to check that the event we receive corresponds to
- our timer. If it does, we can update the board:
-
- \snippet widgets/tetrix/tetrixboard.cpp 15
- \snippet widgets/tetrix/tetrixboard.cpp 16
- \snippet widgets/tetrix/tetrixboard.cpp 17
-
- If a row (or line) has just been filled, we create a new piece and reset the
- timer; otherwise we move the current piece down by one row. We let the base
- class handle other timer events that we receive.
-
- The \c clearBoard() function simply fills the board with the
- \c TetrixShape::NoShape value:
-
- \snippet widgets/tetrix/tetrixboard.cpp 18
-
- The \c dropDown() function moves the current piece down as far as possible on
- the board, either until it is touching the bottom of the playing area or it is
- stacked on top of another piece:
-
- \snippet widgets/tetrix/tetrixboard.cpp 19
- \snippet widgets/tetrix/tetrixboard.cpp 20
-
- The number of rows the piece has dropped is recorded and passed to the
- \c pieceDropped() function so that the player's score can be updated.
-
- The \c oneLineDown() function is used to move the current piece down by one row
- (line), either when the user presses the \uicontrol{D} key or when the piece is
- scheduled to move:
-
- \snippet widgets/tetrix/tetrixboard.cpp 21
-
- If the piece cannot drop down by one line, we call the \c pieceDropped() function
- with zero as the argument to indicate that it cannot fall any further, and that
- the player should receive no extra points for the fall.
-
- The \c pieceDropped() function itself is responsible for awarding points to the
- player for positioning the current piece, checking for full rows on the board
- and, if no lines have been removed, creating a new piece to replace the current
- one:
-
- \snippet widgets/tetrix/tetrixboard.cpp 22
- \snippet widgets/tetrix/tetrixboard.cpp 23
-
- We call \c removeFullLines() each time a piece has been dropped. This scans
- the board from bottom to top, looking for blank spaces on each row.
-
- \snippet widgets/tetrix/tetrixboard.cpp 24
- \snippet widgets/tetrix/tetrixboard.cpp 25
- \snippet widgets/tetrix/tetrixboard.cpp 26
- \snippet widgets/tetrix/tetrixboard.cpp 27
-
- If a row contains no blank spaces, the rows above it are copied down by one row
- to compress the stack of pieces, the top row on the board is cleared, and the
- number of full lines found is incremented.
-
- \snippet widgets/tetrix/tetrixboard.cpp 28
- \snippet widgets/tetrix/tetrixboard.cpp 29
-
- If some lines have been removed, the player's score and the total number of lines
- removed are updated. The \c linesRemoved() and \c scoreChanged() signals are
- emitted to send these new values to other widgets in the window.
-
- Additionally, we set the timer to elapse after half a second, set the
- \c isWaitingAfterLine flag to indicate that lines have been removed, unset
- the piece's shape to ensure that it is not drawn, and update the widget.
- The next time that the \c timerEvent() handler is called, a new piece will be
- created and the game will continue.
-
- The \c newPiece() function places the next available piece at the top of the
- board, and creates a new piece with a random shape:
-
- \snippet widgets/tetrix/tetrixboard.cpp 30
- \snippet widgets/tetrix/tetrixboard.cpp 31
-
- We place a new piece in the middle of the board at the top. The game is over if
- the piece can't move, so we unset its shape to prevent it from being drawn, stop
- the timer, and unset the \c isStarted flag.
-
- The \c showNextPiece() function updates the label that shows the next piece to
- be dropped:
-
- \snippet widgets/tetrix/tetrixboard.cpp 32
- \snippet widgets/tetrix/tetrixboard.cpp 33
-
- We draw the piece's component blocks onto a pixmap that is then set on the label.
-
- The \c tryMove() function is used to determine whether a piece can be positioned
- at the specified coordinates:
-
- \snippet widgets/tetrix/tetrixboard.cpp 34
-
- We examine the spaces on the board that the piece needs to occupy and, if they
- are already occupied by other pieces, we return \c false to indicate that the
- move has failed.
-
- \snippet widgets/tetrix/tetrixboard.cpp 35
-
- If the piece could be placed on the board at the desired location, we update the
- current piece and its position, update the widget, and return \c true to indicate
- success.
-
- The \c drawSquare() function draws the blocks (normally squares) that make up
- each piece using different colors for pieces with different shapes:
-
- \snippet widgets/tetrix/tetrixboard.cpp 36
-
- We obtain the color to use from a look-up table that relates each shape to an
- RGB value, and use the painter provided to draw the block at the specified
- coordinates.
-*/
diff --git a/examples/widgets/doc/src/textedit.qdoc b/examples/widgets/doc/src/textedit.qdoc
deleted file mode 100644
index f41a58fe90..0000000000
--- a/examples/widgets/doc/src/textedit.qdoc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example richtext/textedit
- \title Text Edit
- \ingroup examples-richtext
- \brief The Text Edit example shows Qt's rich text editing facilities
- in action.
-
- \brief The Text Edit example shows Qt's rich text editing facilities in action,
- providing an example document for you to experiment with.
-
- \image textedit-demo.png
-*/
diff --git a/examples/widgets/doc/src/tooltips.qdoc b/examples/widgets/doc/src/tooltips.qdoc
deleted file mode 100644
index 3af3768f00..0000000000
--- a/examples/widgets/doc/src/tooltips.qdoc
+++ /dev/null
@@ -1,374 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/tooltips
- \title Tool Tips Example
- \ingroup examples-widgets
- \brief The Tool Tips example shows how to provide static and dynamic tool
- tips for an application's widgets.
-
- The simplest and most common way to set a widget's tool tip is by
- calling its QWidget::setToolTip() function (static tool
- tips). Then the tool tip is shown whenever the cursor points at
- the widget. We show how to do this with our application's tool
- buttons. But it is also possible to show different tool tips
- depending on the cursor's position (dynamic tooltips). This
- approach uses mouse tracking and event handling to determine what
- widgets are located under the cursor at any point in time, and
- displays their tool tips. The tool tips for the shape items in our
- application are implemented using the latter approach.
-
- \image tooltips-example.png
-
- With the \c Tooltips application the user can create new shape
- items with the provided tool buttons, and move the items around
- using the mouse. Tooltips are provided whenever the cursor is
- pointing to a shape item or one of the buttons.
-
- The Tooltips example consists of two classes:
-
- \list
- \li \c ShapeItem is a custom widget representing one single shape item.
- \li \c SortingBox inherits from QWidget and is the application's main
- widget.
- \endlist
-
- First we will review the \c SortingBox class, then we will take a
- look at the \c ShapeItem class.
-
- \section1 SortingBox Class Definition
-
- \snippet widgets/tooltips/sortingbox.h 0
-
- The \c SortingBox class inherits QWidget, and it is the Tooltips
- application's main widget. We reimplement several of the event
- handlers.
-
- The \c event() function provides tooltips, the \c resize()
- function makes sure the application appears consistently when the
- user resizes the main widget, and the \c paintEvent() function
- displays the shape items within the \c SortingBox widget. The
- mouse event handlers are reimplemented to make the user able to
- move the items around.
-
- In addition we need three private slots to make the user able to
- create new shape items.
-
- \snippet widgets/tooltips/sortingbox.h 1
-
- We also create several private functions: We use the \c
- initialItemPosition(), \c initialItemColor() and \c
- createToolButton() functions when we are constructing the widget,
- and we use the \c updateButtonGeometry() function whenever the
- user is resizing the application's main widget.
-
- The \c itemAt() function determines if there is a shape item at a
- particular position, and the \c moveItemTo() function moves an
- item to a new position. We use the \c createShapeItem(), \c
- randomItemPosition() and \c randomItemColor() functions to create
- new shape items.
-
- \snippet widgets/tooltips/sortingbox.h 2
-
- We keep all the shape items in a QList, and we keep three
- QPainterPath objects holding the shapes of a circle, a square and
- a triangle. We also need to have a pointer to an item when it is
- moving, and we need to know its previous position.
-
- \section1 SortingBox Class Implementation
-
- \snippet widgets/tooltips/sortingbox.cpp 0
-
- In the constructor, we first set the Qt::WA_StaticContents
- attribute on the widget. This attribute indicates that the widget
- contents are north-west aligned and static. On resize, such a
- widget will receive paint events only for the newly visible part
- of itself.
-
- \snippet widgets/tooltips/sortingbox.cpp 1
-
- To be able to show the appropriate tooltips while the user is
- moving the cursor around, we need to enable mouse tracking for the
- widget.
-
- If mouse tracking is disabled (the default), the widget only
- receives mouse move events when at least one mouse button is
- pressed while the mouse is being moved. If mouse tracking is
- enabled, the widget receives mouse move events even if no buttons
- are pressed.
-
- \snippet widgets/tooltips/sortingbox.cpp 2
-
- A widget's background role defines the brush from the widget's
- palette that is used to render the background, and QPalette::Base
- is typically white.
-
- \snippet widgets/tooltips/sortingbox.cpp 3
-
- After creating the application's tool buttons using the private \c
- createToolButton() function, we construct the shapes of a circle,
- a square and a triangle using QPainterPath.
-
- The QPainterPath class provides a container for painting
- operations, enabling graphical shapes to be constructed and
- reused. The main advantage of painter paths over normal drawing
- operations is that complex shapes only need to be created once,
- but they can be drawn many times using only calls to
- QPainter::drawPath().
-
- \snippet widgets/tooltips/sortingbox.cpp 4
-
- Then we set the window title, resize the widget to a suitable
- size, and finally create three initial shape items using the
- private \c createShapeItem(), \c initialItemPosition() and \c
- initialItemColor() functions.
-
- \snippet widgets/tooltips/sortingbox.cpp 27
-
- In the destructor, we delete all shape items.
-
- \snippet widgets/tooltips/sortingbox.cpp 5
-
- QWidget::event() is the main event handler and receives all the
- widget's events. Normally, we recommend reimplementing one of the
- specialized event handlers instead of this function. But here we
- want to catch the QEvent::ToolTip events, and since these are
- rather rare, there exists no specific event handler. For that
- reason we reimplement the main event handler, and the first thing
- we need to do is to determine the event's type:
-
- \snippet widgets/tooltips/sortingbox.cpp 6
-
- If the type is QEvent::ToolTip, we cast the event to a QHelpEvent,
- otherwise we propagate the event using the QWidget::event()
- function.
-
- The QHelpEvent class provides an event that is used to request
- helpful information about a particular point in a widget.
-
- For example, the QHelpEvent::pos() function returns the event's
- position relative to the widget to which the event is dispatched.
- Here we use this information to determine if the position of the
- event is contained within the area of any of the shape items. If
- it is, we display the shape item's tooltip at the position of the
- event. If not, we hide the tooltip and explicitly ignore the event.
- This makes sure that the calling code does not start any tooltip
- specific modes as a result of the event. Note that the
- QToolTip::showText() function needs the event's position in global
- coordinates provided by QHelpEvent::globalPos().
-
- \snippet widgets/tooltips/sortingbox.cpp 7
-
- The \c resizeEvent() function is reimplemented to receive the
- resize events dispatched to the widget. It makes sure that the
- tool buttons keep their position relative to the main widget when
- the widget is resized. We want the buttons to always be vertically
- aligned in the application's bottom right corner, so each time the
- main widget is resized we update the buttons geometry.
-
- \snippet widgets/tooltips/sortingbox.cpp 8
-
- The \c paintEvent() function is reimplemented to receive paint
- events for the widget. We create a QPainter for the \c SortingBox
- widget, and run through the list of created shape items, drawing
- each item at its defined position.
-
- \snippet widgets/tooltips/sortingbox.cpp 9
-
- The painter will by default draw all the shape items at position
- (0,0) in the \c SortingBox widget. The QPainter::translate()
- function translates the coordinate system by the given offset,
- making each shape item appear at its defined position. But
- remember to translate the coordinate system back when the item is
- drawn, otherwise the next shape item will appear at a position
- relative to the item drawn last.
-
- \snippet widgets/tooltips/sortingbox.cpp 10
-
- The QPainter::setBrush() function sets the current brush used by
- the painter. When the provided argument is a QColor, the function
- calls the appropriate QBrush constructor which creates a brush with
- the specified color and Qt::SolidPattern style. The
- QPainter::drawPath() function draws the given path using the
- current pen for outline and the current brush for filling.
-
- \snippet widgets/tooltips/sortingbox.cpp 11
-
- The \c mousePressEvent() function is reimplemented to receive the
- mouse press events dispatched to the widget. It determines if an
- event's position is contained within the area of any of the shape
- items, using the private \c itemAt() function.
-
- If an item covers the position, we store a pointer to that item
- and the event's position. If several of the shape items cover the
- position, we store the pointer to the uppermost item. Finally, we
- move the shape item's pointer to the end of the list, and make
- a call to the QWidget::update() function to make the item appear
- on top.
-
- The QWidget::update() function does not cause an immediate
- repaint; instead it schedules a paint event for processing when Qt
- returns to the main event loop.
-
- \snippet widgets/tooltips/sortingbox.cpp 12
-
- The \c mouseMoveEvent() function is reimplemented to receive mouse
- move events for the widget. If the left mouse button is pressed
- and there exists a shape item in motion, we use the private \c
- moveItemTo() function to move the item with an offset
- corresponding to the offset between the positions of the current
- mouse event and the previous one.
-
- \snippet widgets/tooltips/sortingbox.cpp 13
-
- The \c mouseReleaseEvent() function is reimplemented to receive
- the mouse release events dispatched to the widget. If the left
- mouse button is pressed and there exists a shape item in motion,
- we use the private \c moveItemTo() function to move the item like
- we did in \c mouseMoveEvent(). But then we remove the pointer to
- the item in motion, making the shape item's position final for
- now. To move the item further, the user will need to press the
- left mouse button again.
-
- \snippet widgets/tooltips/sortingbox.cpp 14
- \codeline
- \snippet widgets/tooltips/sortingbox.cpp 15
- \codeline
- \snippet widgets/tooltips/sortingbox.cpp 16
-
- The \c createNewCircle(), \c createNewSquare() and \c
- createNewTriangle() slots simply create new shape items, using the
- private \c createShapeItem(), \c randomItemPosition() and \c
- randomItemColor() functions.
-
- \snippet widgets/tooltips/sortingbox.cpp 17
-
- In the \c itemAt() function, we run through the list of created
- shape items to check if the given position is contained within the
- area of any of the shape items.
-
- For each shape item we use the QPainterPath::contains() function
- to find out if the item's painter path contains the position. If
- it does we return the index of the item, otherwise we return
- -1. We run through the list backwards to get the index of the
- uppermost shape item in case several items cover the position.
-
- \snippet widgets/tooltips/sortingbox.cpp 18
-
- The \c moveItemTo() function moves the shape item in motion, and
- the parameter \c pos is the position of a mouse event. First we
- calculate the offset between the parameter \c pos and the previous
- mouse event position. Then we add the offset to the current
- position of the item in motion.
-
- It is tempting to simply set the position of the item to be the
- parameter \c pos. But an item's position defines the top left
- corner of the item's bounding rectangle, and the parameter \c pos
- can be any point; The suggested shortcut would cause the item to
- jump to a position where the cursor is pointing to the bounding
- rectangle's top left corner, regardless of the item's previous
- position.
-
- \snippet widgets/tooltips/sortingbox.cpp 19
-
- Finally, we update the previous mouse event position, and make a
- call to the QWidget::update() function to make the item appear at
- its new position.
-
- \snippet widgets/tooltips/sortingbox.cpp 20
-
- In the \c updateButtonGeometry() function we set the geometry for
- the given button. The parameter coordinates define the bottom
- right corner of the button. We use these coordinates and the
- button's size hint to determine the position of the upper left
- corner. This position, and the button's width and height, are the
- arguments required by the QWidget::setGeometry() function.
-
- In the end, we calculate and return the y-coordinate of the bottom
- right corner of the next button. We use the QWidget::style()
- function to retrieve the widget's GUI style, and then
- QStyle::pixelMetric() to determine the widget's preferred default
- spacing between its child widgets.
-
- \snippet widgets/tooltips/sortingbox.cpp 21
-
- The \c createShapeItem() function creates a single shape item. It
- sets the path, tooltip, position and color, using the item's own
- functions. In the end, the function appends the new item's pointer
- to the list of shape items, and calls QWidget::update() to make
- it appear with the other items within the \c SortingBox widget.
-
- \snippet widgets/tooltips/sortingbox.cpp 22
-
- The \c createToolButton() function is called from the \c
- SortingBox constructor. We create a tool button with the given
- tooltip and icon. The button's parent is the \c SortingBox widget,
- and its size is 32 x 32 pixels. Before we return the button, we
- connect it to the given slot.
-
- \snippet widgets/tooltips/sortingbox.cpp 23
-
- The \c initialItemPosition() function is also called from the
- constructor. We want the three first items to initially be
- centered in the middle of the \c SortingBox widget, and we use
- this function to calculate their positions.
-
- \snippet widgets/tooltips/sortingbox.cpp 24
-
- Whenever the user creates a new shape item, we want the new item
- to appear at a random position, and we use the \c
- randomItemPosition() function to calculate such a position. We
- make sure that the item appears within the visible area of the
- \c SortingBox widget, using the widget's current width and height
- when calculating the random coordinates.
-
- \snippet widgets/tooltips/sortingbox.cpp 25
-
- As with \c initialItemPosition(), the \c initialItemColor()
- function is called from the constructor. The purposes of both
- functions are purely cosmetic: We want to control the initial
- position and color of the three first items.
-
- \snippet widgets/tooltips/sortingbox.cpp 26
-
- Finally the \c randomItemColor() function is implemented to give
- the shape items the user creates, a random color.
-
- \section1 ShapeItem Class Definition
-
- \snippet widgets/tooltips/shapeitem.h 0
-
- The \c ShapeItem class is a custom widget representing one single
- shape item. The widget has a path, a position, a color and a
- tooltip. We need functions to set or modify these objects, as well
- as functions that return them. We make the latter functions \c
- const to prohibit any modifications of the objects,
- i.e. prohibiting unauthorized manipulation of the shape items
- appearance.
-
- \section1 ShapeItem Class Implementation
-
- \snippet widgets/tooltips/shapeitem.cpp 0
- \codeline
- \snippet widgets/tooltips/shapeitem.cpp 1
- \codeline
- \snippet widgets/tooltips/shapeitem.cpp 2
- \codeline
- \snippet widgets/tooltips/shapeitem.cpp 3
-
- This first group of functions simply return the objects that are
- requested. The objects are returned as constants, i.e. they cannot
- be modified.
-
- \snippet widgets/tooltips/shapeitem.cpp 4
- \codeline
- \snippet widgets/tooltips/shapeitem.cpp 5
- \codeline
- \snippet widgets/tooltips/shapeitem.cpp 6
- \codeline
- \snippet widgets/tooltips/shapeitem.cpp 7
-
- The last group of functions set or modify the shape item's path,
- position, color and tooltip, respectively.
-*/
diff --git a/examples/widgets/doc/src/transformations.qdoc b/examples/widgets/doc/src/transformations.qdoc
index aabb672b86..d90708340c 100644
--- a/examples/widgets/doc/src/transformations.qdoc
+++ b/examples/widgets/doc/src/transformations.qdoc
@@ -4,6 +4,7 @@
/*!
\example painting/transformations
\title Transformations Example
+ \examplecategory {Graphics}
\ingroup examples-painting
\brief The Transformations example shows how transformations
influence the way that QPainter renders graphics primitives.
diff --git a/examples/widgets/doc/src/treemodelcompleter.qdoc b/examples/widgets/doc/src/treemodelcompleter.qdoc
index 9734c3bc7c..ae7c18f442 100644
--- a/examples/widgets/doc/src/treemodelcompleter.qdoc
+++ b/examples/widgets/doc/src/treemodelcompleter.qdoc
@@ -4,6 +4,7 @@
/*!
\example tools/treemodelcompleter
\title Tree Model Completer Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets-tools
\brief The Tree Model Completer example shows how to provide completion
diff --git a/examples/widgets/doc/src/trivialwizard.qdoc b/examples/widgets/doc/src/trivialwizard.qdoc
index 9ce22ec383..75d007f388 100644
--- a/examples/widgets/doc/src/trivialwizard.qdoc
+++ b/examples/widgets/doc/src/trivialwizard.qdoc
@@ -4,6 +4,7 @@
/*!
\example dialogs/trivialwizard
\title Trivial Wizard Example
+ \examplecategory {User Interface Components}
\ingroup examples-dialogs
\brief The Trivial Wizard example illustrates how to create a linear three-page
diff --git a/examples/widgets/doc/src/undoframework.qdoc b/examples/widgets/doc/src/undoframework.qdoc
index 6ca2b4b138..e8d895b7f0 100644
--- a/examples/widgets/doc/src/undoframework.qdoc
+++ b/examples/widgets/doc/src/undoframework.qdoc
@@ -4,6 +4,7 @@
/*!
\example tools/undoframework
\title Undo Framework Example
+ \examplecategory {Data Processing & I/O}
\ingroup examples-widgets-tools
\brief This example shows how to implement undo/redo functionality
diff --git a/examples/widgets/doc/src/validators.qdoc b/examples/widgets/doc/src/validators.qdoc
deleted file mode 100644
index a0b88617b5..0000000000
--- a/examples/widgets/doc/src/validators.qdoc
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example widgets/validators
- \title Validators Example
- \brief The Validators example shows the signal emission behavior of input
- validators.
-
- \borderedimage validators.png
-*/
diff --git a/examples/widgets/doc/src/windowflags.qdoc b/examples/widgets/doc/src/windowflags.qdoc
index d521894a17..10b0496728 100644
--- a/examples/widgets/doc/src/windowflags.qdoc
+++ b/examples/widgets/doc/src/windowflags.qdoc
@@ -4,6 +4,7 @@
/*!
\example widgets/windowflags
\title Window Flags Example
+ \examplecategory {User Interface Components}
\ingroup examples-widgets
\brief The Window Flags example shows how to use the window flags
available in Qt.
diff --git a/examples/widgets/draganddrop/CMakeLists.txt b/examples/widgets/draganddrop/CMakeLists.txt
index c75600f660..bdc6480790 100644
--- a/examples/widgets/draganddrop/CMakeLists.txt
+++ b/examples/widgets/draganddrop/CMakeLists.txt
@@ -1,8 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(draggableicons)
qt_internal_add_example(draggabletext)
qt_internal_add_example(dropsite)
-qt_internal_add_example(fridgemagnets)
-qt_internal_add_example(puzzle)
diff --git a/examples/widgets/draganddrop/draganddrop.pro b/examples/widgets/draganddrop/draganddrop.pro
index 1ecafd33a1..ad56f3f677 100644
--- a/examples/widgets/draganddrop/draganddrop.pro
+++ b/examples/widgets/draganddrop/draganddrop.pro
@@ -1,6 +1,4 @@
TEMPLATE = subdirs
SUBDIRS = draggableicons \
draggabletext \
- dropsite \
- fridgemagnets \
- puzzle
+ dropsite
diff --git a/examples/widgets/draganddrop/draggableicons/CMakeLists.txt b/examples/widgets/draganddrop/draggableicons/CMakeLists.txt
index 44dbcc0fc9..c1fac8da6b 100644
--- a/examples/widgets/draganddrop/draggableicons/CMakeLists.txt
+++ b/examples/widgets/draganddrop/draggableicons/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(draggableicons LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/draggableicons")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,6 +24,11 @@ target_link_libraries(draggableicons PRIVATE
Qt6::Widgets
)
+if(EMSCRIPTEN)
+ target_link_options(draggableicons PUBLIC -sASYNCIFY -Os)
+endif()
+
+
# Resources:
set(draggableicons_resource_files
"images/boat.png"
@@ -45,7 +44,14 @@ qt_add_resources(draggableicons "draggableicons"
)
install(TARGETS draggableicons
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET draggableicons
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.pro b/examples/widgets/draganddrop/draggableicons/draggableicons.pro
index f87ec4ad60..e43df790b4 100644
--- a/examples/widgets/draganddrop/draggableicons/draggableicons.pro
+++ b/examples/widgets/draganddrop/draggableicons/draggableicons.pro
@@ -4,7 +4,9 @@ HEADERS = dragwidget.h
RESOURCES = draggableicons.qrc
SOURCES = dragwidget.cpp \
main.cpp
-
+wasm {
+ QMAKE_LFLAGS += -sASYNCIFY -Os
+}
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/draggableicons
INSTALLS += target
diff --git a/examples/widgets/draganddrop/draggableicons/main.cpp b/examples/widgets/draganddrop/draggableicons/main.cpp
index cd22e4e394..fe92708594 100644
--- a/examples/widgets/draganddrop/draggableicons/main.cpp
+++ b/examples/widgets/draganddrop/draggableicons/main.cpp
@@ -8,8 +8,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(draggableicons);
-
QApplication app(argc, argv);
QWidget mainWidget;
diff --git a/examples/widgets/draganddrop/draggabletext/CMakeLists.txt b/examples/widgets/draganddrop/draggabletext/CMakeLists.txt
index a876f3fe8a..bc1e72db80 100644
--- a/examples/widgets/draganddrop/draggabletext/CMakeLists.txt
+++ b/examples/widgets/draganddrop/draggabletext/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(draggabletext LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/draggabletext")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,6 +24,10 @@ target_link_libraries(draggabletext PRIVATE
Qt6::Widgets
)
+if(EMSCRIPTEN)
+ target_link_options(draggabletext PUBLIC -sASYNCIFY -Os)
+endif()
+
# Resources:
set(draggabletext_resource_files
"words.txt"
@@ -43,7 +41,14 @@ qt_add_resources(draggabletext "draggabletext"
)
install(TARGETS draggabletext
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET draggabletext
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.pro b/examples/widgets/draganddrop/draggabletext/draggabletext.pro
index 1add2a270e..007b9d834e 100644
--- a/examples/widgets/draganddrop/draggabletext/draggabletext.pro
+++ b/examples/widgets/draganddrop/draggabletext/draggabletext.pro
@@ -4,6 +4,9 @@ HEADERS = dragwidget.h
RESOURCES = draggabletext.qrc
SOURCES = dragwidget.cpp \
main.cpp
+wasm {
+ QMAKE_LFLAGS += -sASYNCIFY -Os
+}
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/draggabletext
diff --git a/examples/widgets/draganddrop/draggabletext/main.cpp b/examples/widgets/draganddrop/draggabletext/main.cpp
index f6ab39aee1..ebfd481e62 100644
--- a/examples/widgets/draganddrop/draggabletext/main.cpp
+++ b/examples/widgets/draganddrop/draggabletext/main.cpp
@@ -7,8 +7,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(draggabletext);
-
QApplication app(argc, argv);
DragWidget window;
window.show();
diff --git a/examples/widgets/draganddrop/draggabletext/words.txt b/examples/widgets/draganddrop/draggabletext/words.txt
index 19b8b0325b..78bf304fa9 100644
--- a/examples/widgets/draganddrop/draggabletext/words.txt
+++ b/examples/widgets/draganddrop/draggabletext/words.txt
@@ -1,41 +1,35 @@
Qt
-Quarterly
+Academy
is
-a
-paper
-based
-newsletter
-exclusively
-available
-to
+where
+you
+begin
+your
+journey
+into
Qt
-customers
-Every
-quarter
-we
-mail
-out
-an
-issue
+It
+is
+a
+learning
+platform
that
-we
-hope
-will
-bring
-added
-insight
+can
+teach
+you
+everything
+from
+the
+basics
+to
+the
+details
and
-pleasure
+is
+open
to
-your
-Qt
-programming
-with
-high
-quality
-technical
-articles
-written
-by
-Qt
-experts
+students
+and
+experienced
+programmers
+alike
diff --git a/examples/widgets/draganddrop/dropsite/CMakeLists.txt b/examples/widgets/draganddrop/dropsite/CMakeLists.txt
index dd46483c10..ae8d00eb91 100644
--- a/examples/widgets/draganddrop/dropsite/CMakeLists.txt
+++ b/examples/widgets/draganddrop/dropsite/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(dropsite LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/dropsite")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(dropsite PRIVATE
)
install(TARGETS dropsite
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET dropsite
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt b/examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt
deleted file mode 100644
index e1b7eda112..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(fridgemagnets LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/fridgemagnets")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(fridgemagnets
- draglabel.cpp draglabel.h
- dragwidget.cpp dragwidget.h
- main.cpp
-)
-
-set_target_properties(fridgemagnets PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(fridgemagnets PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(fridgemagnets_resource_files
- "words.txt"
-)
-
-qt_add_resources(fridgemagnets "fridgemagnets"
- PREFIX
- "/dictionary"
- FILES
- ${fridgemagnets_resource_files}
-)
-
-install(TARGETS fridgemagnets
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp b/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp
deleted file mode 100644
index 952faae8fe..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "draglabel.h"
-
-#include <QtWidgets>
-
-//! [0]
-DragLabel::DragLabel(const QString &text, QWidget *parent)
- : QLabel(parent)
-{
- QFontMetrics metric(font());
- QSize size = metric.size(Qt::TextSingleLine, text);
-
- QImage image(size.width() + 12, size.height() + 12, QImage::Format_ARGB32_Premultiplied);
- image.fill(qRgba(0, 0, 0, 0));
-
- QFont font;
- font.setStyleStrategy(QFont::ForceOutline);
-//! [0]
-
-//! [1]
- QLinearGradient gradient(0, 0, 0, image.height()-1);
- gradient.setColorAt(0.0, Qt::white);
- gradient.setColorAt(0.2, QColor(200, 200, 255));
- gradient.setColorAt(0.8, QColor(200, 200, 255));
- gradient.setColorAt(1.0, QColor(127, 127, 200));
-
- QPainter painter;
- painter.begin(&image);
- painter.setRenderHint(QPainter::Antialiasing);
- painter.setBrush(gradient);
- painter.drawRoundedRect(QRectF(0.5, 0.5, image.width()-1, image.height()-1),
- 25, 25, Qt::RelativeSize);
-
- painter.setFont(font);
- painter.setBrush(Qt::black);
- painter.drawText(QRect(QPoint(6, 6), size), Qt::AlignCenter, text);
- painter.end();
-//! [1]
-
-//! [2]
- setPixmap(QPixmap::fromImage(image));
- m_labelText = text;
-}
-//! [2]
-
-QString DragLabel::labelText() const
-{
- return m_labelText;
-}
diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.h b/examples/widgets/draganddrop/fridgemagnets/draglabel.h
deleted file mode 100644
index e734a9ff78..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/draglabel.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef DRAGLABEL_H
-#define DRAGLABEL_H
-
-#include <QLabel>
-
-QT_BEGIN_NAMESPACE
-class QDragEnterEvent;
-class QDragMoveEvent;
-class QFrame;
-QT_END_NAMESPACE
-
-//! [0]
-class DragLabel : public QLabel
-{
-public:
- DragLabel(const QString &text, QWidget *parent);
- QString labelText() const;
-
-private:
- QString m_labelText;
-};
-//! [0]
-
-#endif // DRAGLABEL_H
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
deleted file mode 100644
index a883e7c58a..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "draglabel.h"
-#include "dragwidget.h"
-
-#include <QtWidgets>
-
-static inline QString fridgetMagnetsMimeType() { return QStringLiteral("application/x-fridgemagnet"); }
-
-//! [0]
-DragWidget::DragWidget(QWidget *parent)
- : QWidget(parent)
-{
- QFile dictionaryFile(QStringLiteral(":/dictionary/words.txt"));
- dictionaryFile.open(QFile::ReadOnly);
- QTextStream inputStream(&dictionaryFile);
-//! [0]
-
-//! [1]
- int x = 5;
- int y = 5;
-
- while (!inputStream.atEnd()) {
- QString word;
- inputStream >> word;
- if (!word.isEmpty()) {
- DragLabel *wordLabel = new DragLabel(word, this);
- wordLabel->move(x, y);
- wordLabel->show();
- wordLabel->setAttribute(Qt::WA_DeleteOnClose);
- x += wordLabel->width() + 2;
- if (x >= 245) {
- x = 5;
- y += wordLabel->height() + 2;
- }
- }
- }
-//! [1]
-
-//! [2]
- QPalette newPalette = palette();
- newPalette.setColor(QPalette::Window, Qt::white);
- setPalette(newPalette);
-
- setMinimumSize(400, qMax(200, y));
- setWindowTitle(tr("Fridge Magnets"));
-//! [2] //! [3]
- setAcceptDrops(true);
-}
-//! [3]
-
-//! [4]
-void DragWidget::dragEnterEvent(QDragEnterEvent *event)
-{
-//! [4] //! [5]
- if (event->mimeData()->hasFormat(fridgetMagnetsMimeType())) {
- if (children().contains(event->source())) {
- event->setDropAction(Qt::MoveAction);
- event->accept();
- } else {
- event->acceptProposedAction();
-//! [5] //! [6]
- }
-//! [6] //! [7]
- } else if (event->mimeData()->hasText()) {
- event->acceptProposedAction();
- } else {
- event->ignore();
- }
-}
-//! [7]
-
-//! [8]
-void DragWidget::dragMoveEvent(QDragMoveEvent *event)
-{
- if (event->mimeData()->hasFormat(fridgetMagnetsMimeType())) {
- if (children().contains(event->source())) {
- event->setDropAction(Qt::MoveAction);
- event->accept();
- } else {
- event->acceptProposedAction();
- }
- } else if (event->mimeData()->hasText()) {
- event->acceptProposedAction();
- } else {
- event->ignore();
- }
-}
-//! [8]
-
-//! [9]
-void DragWidget::dropEvent(QDropEvent *event)
-{
- if (event->mimeData()->hasFormat(fridgetMagnetsMimeType())) {
- const QMimeData *mime = event->mimeData();
-//! [9] //! [10]
- QByteArray itemData = mime->data(fridgetMagnetsMimeType());
- QDataStream dataStream(&itemData, QIODevice::ReadOnly);
-
- QString text;
- QPoint offset;
- dataStream >> text >> offset;
-//! [10]
-//! [11]
- DragLabel *newLabel = new DragLabel(text, this);
- newLabel->move(event->position().toPoint() - offset);
- newLabel->show();
- newLabel->setAttribute(Qt::WA_DeleteOnClose);
-
- if (event->source() == this) {
- event->setDropAction(Qt::MoveAction);
- event->accept();
- } else {
- event->acceptProposedAction();
- }
-//! [11] //! [12]
- } else if (event->mimeData()->hasText()) {
- QStringList pieces = event->mimeData()->text().split(
- QRegularExpression(QStringLiteral("\\s+")), Qt::SkipEmptyParts);
- QPoint position = event->position().toPoint();
-
- for (const QString &piece : pieces) {
- DragLabel *newLabel = new DragLabel(piece, this);
- newLabel->move(position);
- newLabel->show();
- newLabel->setAttribute(Qt::WA_DeleteOnClose);
-
- position += QPoint(newLabel->width(), 0);
- }
-
- event->acceptProposedAction();
- } else {
- event->ignore();
- }
-}
-//! [12]
-
-//! [13]
-void DragWidget::mousePressEvent(QMouseEvent *event)
-{
-//! [13]
-//! [14]
- DragLabel *child = static_cast<DragLabel*>(childAt(event->position().toPoint()));
- if (!child)
- return;
-
- QPoint hotSpot = event->position().toPoint() - child->pos();
-
- QByteArray itemData;
- QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << child->labelText() << QPoint(hotSpot);
-//! [14]
-
-//! [15]
- QMimeData *mimeData = new QMimeData;
- mimeData->setData(fridgetMagnetsMimeType(), itemData);
- mimeData->setText(child->labelText());
-//! [15]
-
-//! [16]
- QDrag *drag = new QDrag(this);
- drag->setMimeData(mimeData);
- drag->setPixmap(child->pixmap());
- drag->setHotSpot(hotSpot);
-
- child->hide();
-//! [16]
-
-//! [17]
- if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction)
- child->close();
- else
- child->show();
-}
-//! [17]
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
deleted file mode 100644
index 9614a3b76a..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef DRAGWIDGET_H
-#define DRAGWIDGET_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QDragEnterEvent;
-class QDropEvent;
-QT_END_NAMESPACE
-
-//! [0]
-class DragWidget : public QWidget
-{
-public:
- explicit DragWidget(QWidget *parent = nullptr);
-
-protected:
- void dragEnterEvent(QDragEnterEvent *event) override;
- void dragMoveEvent(QDragMoveEvent *event) override;
- void dropEvent(QDropEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
-};
-//! [0]
-
-#endif // DRAGWIDGET_H
diff --git a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro
deleted file mode 100644
index 2c3165d1c5..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-
-HEADERS = draglabel.h \
- dragwidget.h
-RESOURCES = fridgemagnets.qrc
-SOURCES = draglabel.cpp \
- dragwidget.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/fridgemagnets
-INSTALLS += target
diff --git a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc
deleted file mode 100644
index b72217d701..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/dictionary">
- <file>words.txt</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/draganddrop/fridgemagnets/main.cpp b/examples/widgets/draganddrop/fridgemagnets/main.cpp
deleted file mode 100644
index d2b2e5dbed..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/main.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "dragwidget.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(fridgemagnets);
-
- QApplication app(argc, argv);
-#ifdef QT_KEYPAD_NAVIGATION
- QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
-#endif
- DragWidget window;
-
- bool smallScreen = QApplication::arguments().contains(QStringLiteral("-small-screen"));
- if (smallScreen)
- window.showFullScreen();
- else
- window.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/draganddrop/fridgemagnets/words.txt b/examples/widgets/draganddrop/fridgemagnets/words.txt
deleted file mode 100644
index a7e1632b09..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/words.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-Colorless
-green
-ideas
-sleep
-furiously
-A
-colorless
-green
-idea
-is
-a
-new
-untried
-idea
-that
-is
-without
-vividness
-dull
-and
-unexciting
-To
-sleep
-furiously
-may
-seem
-a
-puzzling
-turn
-of
-phrase
-but
-the
-mind
-in
-sleep
-often
-indeed
-moves
-furiously
-with
-ideas
-and
-images
-flickering
-in
-and
-out
diff --git a/examples/widgets/draganddrop/puzzle/CMakeLists.txt b/examples/widgets/draganddrop/puzzle/CMakeLists.txt
deleted file mode 100644
index 13c6717551..0000000000
--- a/examples/widgets/draganddrop/puzzle/CMakeLists.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(puzzle LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop_puzzle")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(draganddrop_puzzle
- main.cpp
- mainwindow.cpp mainwindow.h
- pieceslist.cpp pieceslist.h
- puzzlewidget.cpp puzzlewidget.h
-)
-
-set_target_properties(draganddrop_puzzle PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(draganddrop_puzzle PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(puzzle_resource_files
- "example.jpg"
-)
-
-qt_add_resources(draganddrop_puzzle "puzzle"
- PREFIX
- "/images"
- FILES
- ${puzzle_resource_files}
-)
-
-install(TARGETS draganddrop_puzzle
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/draganddrop/puzzle/example.jpg b/examples/widgets/draganddrop/puzzle/example.jpg
deleted file mode 100644
index 023203c57a..0000000000
--- a/examples/widgets/draganddrop/puzzle/example.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/draganddrop/puzzle/main.cpp b/examples/widgets/draganddrop/puzzle/main.cpp
deleted file mode 100644
index 73fdd6513b..0000000000
--- a/examples/widgets/draganddrop/puzzle/main.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-
-#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(puzzle);
-
- QApplication app(argc, argv);
- MainWindow window;
- window.loadImage(QStringLiteral(":/images/example.jpg"));
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.cpp b/examples/widgets/draganddrop/puzzle/mainwindow.cpp
deleted file mode 100644
index b34bc24201..0000000000
--- a/examples/widgets/draganddrop/puzzle/mainwindow.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "pieceslist.h"
-#include "puzzlewidget.h"
-
-#include <QtWidgets>
-#include <stdlib.h>
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
-{
- setupMenus();
- setupWidgets();
-
- setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
- setWindowTitle(tr("Puzzle"));
-}
-
-void MainWindow::openImage()
-{
- const QString directory =
- QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::homePath());
- QFileDialog dialog(this, tr("Open Image"), directory);
- dialog.setAcceptMode(QFileDialog::AcceptOpen);
- dialog.setFileMode(QFileDialog::ExistingFile);
- QStringList mimeTypeFilters;
- for (const QByteArray &mimeTypeName : QImageReader::supportedMimeTypes())
- mimeTypeFilters.append(mimeTypeName);
- mimeTypeFilters.sort();
- dialog.setMimeTypeFilters(mimeTypeFilters);
- dialog.selectMimeTypeFilter("image/jpeg");
- if (dialog.exec() == QDialog::Accepted)
- loadImage(dialog.selectedFiles().constFirst());
-}
-
-void MainWindow::loadImage(const QString &fileName)
-{
- QPixmap newImage;
- if (!newImage.load(fileName)) {
- QMessageBox::warning(this, tr("Open Image"),
- tr("The image file could not be loaded."),
- QMessageBox::Close);
- return;
- }
- puzzleImage = newImage;
- setupPuzzle();
-}
-
-void MainWindow::setCompleted()
-{
- QMessageBox::information(this, tr("Puzzle Completed"),
- tr("Congratulations! You have completed the puzzle!\n"
- "Click OK to start again."),
- QMessageBox::Ok);
-
- setupPuzzle();
-}
-
-void MainWindow::setupPuzzle()
-{
- int size = qMin(puzzleImage.width(), puzzleImage.height());
- puzzleImage = puzzleImage.copy((puzzleImage.width() - size) / 2,
- (puzzleImage.height() - size) / 2, size, size).scaled(puzzleWidget->width(),
- puzzleWidget->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-
- piecesList->clear();
-
- for (int y = 0; y < 5; ++y) {
- for (int x = 0; x < 5; ++x) {
- int pieceSize = puzzleWidget->pieceSize();
- QPixmap pieceImage = puzzleImage.copy(x * pieceSize, y * pieceSize, pieceSize, pieceSize);
- piecesList->addPiece(pieceImage, QPoint(x, y));
- }
- }
-
- for (int i = 0; i < piecesList->count(); ++i) {
- if (QRandomGenerator::global()->bounded(2) == 1) {
- QListWidgetItem *item = piecesList->takeItem(i);
- piecesList->insertItem(0, item);
- }
- }
-
- puzzleWidget->clear();
-}
-
-void MainWindow::setupMenus()
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
-
- QAction *openAction = fileMenu->addAction(tr("&Open..."), this, &MainWindow::openImage);
- openAction->setShortcuts(QKeySequence::Open);
-
- QAction *exitAction = fileMenu->addAction(tr("E&xit"), qApp, &QCoreApplication::quit);
- exitAction->setShortcuts(QKeySequence::Quit);
-
- QMenu *gameMenu = menuBar()->addMenu(tr("&Game"));
-
- gameMenu->addAction(tr("&Restart"), this, &MainWindow::setupPuzzle);
-}
-
-void MainWindow::setupWidgets()
-{
- QFrame *frame = new QFrame;
- QHBoxLayout *frameLayout = new QHBoxLayout(frame);
- puzzleWidget = new PuzzleWidget(400);
-
- piecesList = new PiecesList(puzzleWidget->pieceSize(), this);
-
-
- connect(puzzleWidget, &PuzzleWidget::puzzleCompleted,
- this, &MainWindow::setCompleted, Qt::QueuedConnection);
-
- frameLayout->addWidget(piecesList);
- frameLayout->addWidget(puzzleWidget);
- setCentralWidget(frame);
-}
diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.h b/examples/widgets/draganddrop/puzzle/mainwindow.h
deleted file mode 100644
index 83a441c722..0000000000
--- a/examples/widgets/draganddrop/puzzle/mainwindow.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QPixmap>
-
-class PiecesList;
-class PuzzleWidget;
-QT_BEGIN_NAMESPACE
-class QListWidgetItem;
-QT_END_NAMESPACE
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- explicit MainWindow(QWidget *parent = nullptr);
- void loadImage(const QString &path);
-
-public slots:
- void openImage();
- void setupPuzzle();
-
-private slots:
- void setCompleted();
-
-private:
- void setupMenus();
- void setupWidgets();
-
- QPixmap puzzleImage;
- PiecesList *piecesList;
- PuzzleWidget *puzzleWidget;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.cpp b/examples/widgets/draganddrop/puzzle/pieceslist.cpp
deleted file mode 100644
index 0c7e771e42..0000000000
--- a/examples/widgets/draganddrop/puzzle/pieceslist.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "pieceslist.h"
-
-#include <QDrag>
-#include <QDragEnterEvent>
-#include <QMimeData>
-
-PiecesList::PiecesList(int pieceSize, QWidget *parent)
- : QListWidget(parent), m_PieceSize(pieceSize)
-{
- setDragEnabled(true);
- setViewMode(QListView::IconMode);
- setIconSize(QSize(m_PieceSize, m_PieceSize));
- setSpacing(10);
- setAcceptDrops(true);
- setDropIndicatorShown(true);
-}
-
-void PiecesList::dragEnterEvent(QDragEnterEvent *event)
-{
- if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType()))
- event->accept();
- else
- event->ignore();
-}
-
-void PiecesList::dragMoveEvent(QDragMoveEvent *event)
-{
- if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())) {
- event->setDropAction(Qt::MoveAction);
- event->accept();
- } else {
- event->ignore();
- }
-}
-
-void PiecesList::dropEvent(QDropEvent *event)
-{
- if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())) {
- QByteArray pieceData = event->mimeData()->data(PiecesList::puzzleMimeType());
- QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
- QPixmap pixmap;
- QPoint location;
- dataStream >> pixmap >> location;
-
- addPiece(pixmap, location);
-
- event->setDropAction(Qt::MoveAction);
- event->accept();
- } else {
- event->ignore();
- }
-}
-
-void PiecesList::addPiece(const QPixmap &pixmap, const QPoint &location)
-{
- QListWidgetItem *pieceItem = new QListWidgetItem(this);
- pieceItem->setIcon(QIcon(pixmap));
- pieceItem->setData(Qt::UserRole, QVariant(pixmap));
- pieceItem->setData(Qt::UserRole+1, location);
- pieceItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
-}
-
-void PiecesList::startDrag(Qt::DropActions /*supportedActions*/)
-{
- QListWidgetItem *item = currentItem();
-
- QByteArray itemData;
- QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- QPixmap pixmap = qvariant_cast<QPixmap>(item->data(Qt::UserRole));
- QPoint location = item->data(Qt::UserRole+1).toPoint();
-
- dataStream << pixmap << location;
-
- QMimeData *mimeData = new QMimeData;
- mimeData->setData(PiecesList::puzzleMimeType(), itemData);
-
- QDrag *drag = new QDrag(this);
- drag->setMimeData(mimeData);
- drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2));
- drag->setPixmap(pixmap);
-
- if (drag->exec(Qt::MoveAction) == Qt::MoveAction)
- delete takeItem(row(item));
-}
diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.h b/examples/widgets/draganddrop/puzzle/pieceslist.h
deleted file mode 100644
index 4c617e7006..0000000000
--- a/examples/widgets/draganddrop/puzzle/pieceslist.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PIECESLIST_H
-#define PIECESLIST_H
-
-#include <QListWidget>
-
-class PiecesList : public QListWidget
-{
- Q_OBJECT
-
-public:
- explicit PiecesList(int pieceSize, QWidget *parent = nullptr);
- void addPiece(const QPixmap &pixmap, const QPoint &location);
-
- static QString puzzleMimeType() { return QStringLiteral("image/x-puzzle-piece"); }
-
-protected:
- void dragEnterEvent(QDragEnterEvent *event) override;
- void dragMoveEvent(QDragMoveEvent *event) override;
- void dropEvent(QDropEvent *event) override;
- void startDrag(Qt::DropActions supportedActions) override;
-
- int m_PieceSize;
-};
-
-#endif // PIECESLIST_H
diff --git a/examples/widgets/draganddrop/puzzle/puzzle.pro b/examples/widgets/draganddrop/puzzle/puzzle.pro
deleted file mode 100644
index c462ba1bb8..0000000000
--- a/examples/widgets/draganddrop/puzzle/puzzle.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-
-HEADERS = mainwindow.h \
- pieceslist.h \
- puzzlewidget.h
-RESOURCES = puzzle.qrc
-SOURCES = main.cpp \
- mainwindow.cpp \
- pieceslist.cpp \
- puzzlewidget.cpp
-
-QMAKE_PROJECT_NAME = dndpuzzle
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/puzzle
-INSTALLS += target
diff --git a/examples/widgets/draganddrop/puzzle/puzzle.qrc b/examples/widgets/draganddrop/puzzle/puzzle.qrc
deleted file mode 100644
index 4076cec026..0000000000
--- a/examples/widgets/draganddrop/puzzle/puzzle.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/images">
- <file>example.jpg</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
deleted file mode 100644
index 7c3f12f7d8..0000000000
--- a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "puzzlewidget.h"
-#include "pieceslist.h"
-
-#include <QDrag>
-#include <QDragEnterEvent>
-#include <QMimeData>
-#include <QPainter>
-
-PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent)
- : QWidget(parent), m_ImageSize(imageSize)
-{
- setAcceptDrops(true);
- setMinimumSize(m_ImageSize, m_ImageSize);
- setMaximumSize(m_ImageSize, m_ImageSize);
-}
-
-void PuzzleWidget::clear()
-{
- pieces.clear();
- highlightedRect = QRect();
- inPlace = 0;
- update();
-}
-
-void PuzzleWidget::dragEnterEvent(QDragEnterEvent *event)
-{
- if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType()))
- event->accept();
- else
- event->ignore();
-}
-
-void PuzzleWidget::dragLeaveEvent(QDragLeaveEvent *event)
-{
- QRect updateRect = highlightedRect;
- highlightedRect = QRect();
- update(updateRect);
- event->accept();
-}
-
-void PuzzleWidget::dragMoveEvent(QDragMoveEvent *event)
-{
- QRect updateRect = highlightedRect.united(targetSquare(event->position().toPoint()));
-
- if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())
- && findPiece(targetSquare(event->position().toPoint())) == -1) {
-
- highlightedRect = targetSquare(event->position().toPoint());
- event->setDropAction(Qt::MoveAction);
- event->accept();
- } else {
- highlightedRect = QRect();
- event->ignore();
- }
-
- update(updateRect);
-}
-
-void PuzzleWidget::dropEvent(QDropEvent *event)
-{
- if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())
- && findPiece(targetSquare(event->position().toPoint())) == -1) {
-
- QByteArray pieceData = event->mimeData()->data(PiecesList::puzzleMimeType());
- QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
- Piece piece;
- piece.rect = targetSquare(event->position().toPoint());
- dataStream >> piece.pixmap >> piece.location;
-
- pieces.append(piece);
-
- highlightedRect = QRect();
- update(piece.rect);
-
- event->setDropAction(Qt::MoveAction);
- event->accept();
-
- if (piece.location == piece.rect.topLeft() / pieceSize()) {
- inPlace++;
- if (inPlace == 25)
- emit puzzleCompleted();
- }
- } else {
- highlightedRect = QRect();
- event->ignore();
- }
-}
-
-int PuzzleWidget::findPiece(const QRect &pieceRect) const
-{
- for (int i = 0, size = pieces.size(); i < size; ++i) {
- if (pieces.at(i).rect == pieceRect)
- return i;
- }
- return -1;
-}
-
-void PuzzleWidget::mousePressEvent(QMouseEvent *event)
-{
- QRect square = targetSquare(event->position().toPoint());
- const int found = findPiece(square);
-
- if (found == -1)
- return;
-
- Piece piece = pieces.takeAt(found);
-
- if (piece.location == square.topLeft() / pieceSize())
- inPlace--;
-
- update(square);
-
- QByteArray itemData;
- QDataStream dataStream(&itemData, QIODevice::WriteOnly);
-
- dataStream << piece.pixmap << piece.location;
-
- QMimeData *mimeData = new QMimeData;
- mimeData->setData(PiecesList::puzzleMimeType(), itemData);
-
- QDrag *drag = new QDrag(this);
- drag->setMimeData(mimeData);
- drag->setHotSpot(event->position().toPoint() - square.topLeft());
- drag->setPixmap(piece.pixmap);
-
- if (drag->exec(Qt::MoveAction) != Qt::MoveAction) {
- pieces.insert(found, piece);
- update(targetSquare(event->position().toPoint()));
-
- if (piece.location == square.topLeft() / pieceSize())
- inPlace++;
- }
-}
-
-void PuzzleWidget::paintEvent(QPaintEvent *event)
-{
- QPainter painter(this);
- painter.fillRect(event->rect(), Qt::white);
-
- if (highlightedRect.isValid()) {
- painter.setBrush(QColor("#ffcccc"));
- painter.setPen(Qt::NoPen);
- painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
- }
-
- for (const Piece &piece : pieces)
- painter.drawPixmap(piece.rect, piece.pixmap);
-}
-
-const QRect PuzzleWidget::targetSquare(const QPoint &position) const
-{
- QPoint topLeft = QPoint(position.x() / pieceSize(), position.y() / pieceSize()) * pieceSize();
- return QRect(topLeft, QSize(pieceSize(), pieceSize()));
-}
-
-int PuzzleWidget::pieceSize() const
-{
- return m_ImageSize / 5;
-}
-
-int PuzzleWidget::imageSize() const
-{
- return m_ImageSize;
-}
diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.h b/examples/widgets/draganddrop/puzzle/puzzlewidget.h
deleted file mode 100644
index d1c00872ec..0000000000
--- a/examples/widgets/draganddrop/puzzle/puzzlewidget.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PUZZLEWIDGET_H
-#define PUZZLEWIDGET_H
-
-#include <QPoint>
-#include <QPixmap>
-#include <QList>
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QDragEnterEvent;
-class QDropEvent;
-class QMouseEvent;
-QT_END_NAMESPACE
-
-class PuzzleWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit PuzzleWidget(int imageSize, QWidget *parent = nullptr);
- void clear();
-
- int pieceSize() const;
- int imageSize() const;
-
-signals:
- void puzzleCompleted();
-
-protected:
- void dragEnterEvent(QDragEnterEvent *event) override;
- void dragLeaveEvent(QDragLeaveEvent *event) override;
- void dragMoveEvent(QDragMoveEvent *event) override;
- void dropEvent(QDropEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
-
-private:
- struct Piece {
- QPixmap pixmap;
- QRect rect;
- QPoint location;
- };
-
- int findPiece(const QRect &pieceRect) const;
- const QRect targetSquare(const QPoint &position) const;
-
- QList<Piece> pieces;
- QRect highlightedRect;
- int inPlace;
- int m_ImageSize;
-};
-
-#endif // PUZZLEWIDGET_H
diff --git a/examples/widgets/effects/CMakeLists.txt b/examples/widgets/effects/CMakeLists.txt
deleted file mode 100644
index 8b1471d1c2..0000000000
--- a/examples/widgets/effects/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-qt_internal_add_example(blurpicker)
-qt_internal_add_example(fademessage)
diff --git a/examples/widgets/effects/blurpicker/CMakeLists.txt b/examples/widgets/effects/blurpicker/CMakeLists.txt
deleted file mode 100644
index 977769d105..0000000000
--- a/examples/widgets/effects/blurpicker/CMakeLists.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(blurpicker LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/effects/blurpicker")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(blurpicker
- blureffect.cpp blureffect.h
- blurpicker.cpp blurpicker.h
- main.cpp
-)
-
-set_target_properties(blurpicker PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(blurpicker PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(blurpicker_resource_files
- "images/accessories-calculator.png"
- "images/accessories-text-editor.png"
- "images/background.jpg"
- "images/help-browser.png"
- "images/internet-group-chat.png"
- "images/internet-mail.png"
- "images/internet-web-browser.png"
- "images/office-calendar.png"
- "images/system-users.png"
-)
-
-qt_add_resources(blurpicker "blurpicker"
- PREFIX
- "/"
- FILES
- ${blurpicker_resource_files}
-)
-
-install(TARGETS blurpicker
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/effects/blurpicker/blureffect.cpp b/examples/widgets/effects/blurpicker/blureffect.cpp
deleted file mode 100644
index 2e2b8c8d6b..0000000000
--- a/examples/widgets/effects/blurpicker/blureffect.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "blureffect.h"
-
-#include <QDebug>
-
-BlurEffect::BlurEffect(QGraphicsItem *item)
- : QGraphicsBlurEffect()
- , m_baseLine(200), item(item)
-{
-}
-
-void BlurEffect::adjustForItem()
-{
- qreal y = m_baseLine - item->pos().y();
- qreal radius = qBound(qreal(0.0), y / 32, qreal(16.0));
- setBlurRadius(radius);
-}
-
-QRectF BlurEffect::boundingRect() const
-{
- const_cast<BlurEffect *>(this)->adjustForItem();
- return QGraphicsBlurEffect::boundingRect();
-}
-
-void BlurEffect::draw(QPainter *painter)
-{
- adjustForItem();
- QGraphicsBlurEffect::draw(painter);
-}
diff --git a/examples/widgets/effects/blurpicker/blureffect.h b/examples/widgets/effects/blurpicker/blureffect.h
deleted file mode 100644
index a39261fc5a..0000000000
--- a/examples/widgets/effects/blurpicker/blureffect.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BLUREFFECT_H
-#define BLUREFFECT_H
-
-#include <QGraphicsEffect>
-#include <QGraphicsItem>
-
-class BlurEffect: public QGraphicsBlurEffect
-{
-public:
- BlurEffect(QGraphicsItem *item);
-
- void setBaseLine(qreal y) { m_baseLine = y; }
-
- QRectF boundingRect() const;
-
- void draw(QPainter *painter) override;
-
-private:
- void adjustForItem();
-
-private:
- qreal m_baseLine;
- QGraphicsItem *item;
-};
-
-#endif // BLUREFFECT_H
diff --git a/examples/widgets/effects/blurpicker/blurpicker.cpp b/examples/widgets/effects/blurpicker/blurpicker.cpp
deleted file mode 100644
index 00269c8fe3..0000000000
--- a/examples/widgets/effects/blurpicker/blurpicker.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "blurpicker.h"
-
-#include <QtWidgets>
-#include <QtCore/qmath.h>
-#include <qmath.h>
-#include "blureffect.h"
-
-BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index")
-{
- setBackgroundBrush(QPixmap(":/images/background.jpg"));
- setScene(new QGraphicsScene(this));
-
- setupScene();
- setIndex(0);
-
- m_animation.setDuration(400);
- m_animation.setEasingCurve(QEasingCurve::InOutSine);
-
- setRenderHint(QPainter::Antialiasing, true);
- setFrameStyle(QFrame::NoFrame);
-}
-
-qreal BlurPicker::index() const
-{
- return m_index;
-}
-
-void BlurPicker::setIndex(qreal index)
-{
- m_index = index;
-
- qreal baseline = 0;
- const qreal iconAngle = 2 * M_PI / m_icons.count();
- for (int i = 0; i < m_icons.count(); ++i) {
- QGraphicsItem *icon = m_icons[i];
- qreal a = (i + m_index) * iconAngle;
- qreal xs = 170 * qSin(a);
- qreal ys = 100 * qCos(a);
- QPointF pos(xs, ys);
- pos = QTransform().rotate(-20).map(pos);
- pos -= QPointF(40, 40);
- icon->setPos(pos);
- baseline = qMax(baseline, ys);
- static_cast<BlurEffect *>(icon->graphicsEffect())->setBaseLine(baseline);
- }
-
- scene()->update();
-}
-
-void BlurPicker::setupScene()
-{
- scene()->setSceneRect(-200, -120, 400, 240);
-
- QStringList names;
- names << ":/images/accessories-calculator.png";
- names << ":/images/accessories-text-editor.png";
- names << ":/images/help-browser.png";
- names << ":/images/internet-group-chat.png";
- names << ":/images/internet-mail.png";
- names << ":/images/internet-web-browser.png";
- names << ":/images/office-calendar.png";
- names << ":/images/system-users.png";
-
- for (int i = 0; i < names.count(); i++) {
- QPixmap pixmap(names[i]);
- QGraphicsPixmapItem *icon = scene()->addPixmap(pixmap);
- icon->setZValue(1);
- icon->setGraphicsEffect(new BlurEffect(icon));
- m_icons << icon;
- }
-
- QGraphicsPixmapItem *bg = scene()->addPixmap(QPixmap(":/images/background.jpg"));
- bg->setZValue(0);
- bg->setPos(-200, -150);
-}
-
-void BlurPicker::keyPressEvent(QKeyEvent *event)
-{
- int delta = 0;
- switch (event->key())
- {
- case Qt::Key_Left:
- delta = -1;
- break;
- case Qt::Key_Right:
- delta = 1;
- break;
- default:
- break;
- }
- if (m_animation.state() == QAbstractAnimation::Stopped && delta) {
- m_animation.setEndValue(m_index + delta);
- m_animation.start();
- event->accept();
- }
-}
-
-void BlurPicker::resizeEvent(QResizeEvent * /* event */)
-{
-}
-
-void BlurPicker::mousePressEvent(QMouseEvent *event)
-{
- int delta = 0;
- if (event->position().x() > (width() / 2))
- {
- delta = 1;
- }
- else
- {
- delta = -1;
- }
-
- if (m_animation.state() == QAbstractAnimation::Stopped && delta) {
- m_animation.setEndValue(m_index + delta);
- m_animation.start();
- event->accept();
- }
-}
diff --git a/examples/widgets/effects/blurpicker/blurpicker.h b/examples/widgets/effects/blurpicker/blurpicker.h
deleted file mode 100644
index 6e4ac84e56..0000000000
--- a/examples/widgets/effects/blurpicker/blurpicker.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BLURPICKER_H
-#define BLURPICKER_H
-
-#include <QGraphicsEffect>
-#include <QGraphicsView>
-#include <QPropertyAnimation>
-
-#include "blureffect.h"
-
-class BlurPicker: public QGraphicsView
-{
- Q_OBJECT
- Q_PROPERTY(qreal index READ index WRITE setIndex)
-
-public:
- BlurPicker(QWidget *parent = nullptr);
-
- qreal index() const;
- void setIndex(qreal);
-
-protected:
- void keyPressEvent(QKeyEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
-
-private:
- void setupScene();
-
-private:
- qreal m_index;
- QList<QGraphicsItem*> m_icons;
- QPropertyAnimation m_animation;
-};
-
-#endif // BLURPICKER_H
diff --git a/examples/widgets/effects/blurpicker/blurpicker.pro b/examples/widgets/effects/blurpicker/blurpicker.pro
deleted file mode 100644
index c570ac3b98..0000000000
--- a/examples/widgets/effects/blurpicker/blurpicker.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-QT += widgets
-
-SOURCES += main.cpp blurpicker.cpp blureffect.cpp
-HEADERS += blurpicker.h blureffect.h
-RESOURCES += blurpicker.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/effects/blurpicker
-INSTALLS += target
diff --git a/examples/widgets/effects/blurpicker/blurpicker.qrc b/examples/widgets/effects/blurpicker/blurpicker.qrc
deleted file mode 100644
index e88eaca966..0000000000
--- a/examples/widgets/effects/blurpicker/blurpicker.qrc
+++ /dev/null
@@ -1,14 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>images/background.jpg</file>
- <file>images/accessories-calculator.png</file>
- <file>images/accessories-text-editor.png</file>
- <file>images/help-browser.png</file>
- <file>images/internet-group-chat.png</file>
- <file>images/internet-mail.png</file>
- <file>images/internet-web-browser.png</file>
- <file>images/office-calendar.png</file>
- <file>images/system-users.png</file>
- </qresource>
-</RCC>
-
diff --git a/examples/widgets/effects/blurpicker/images/README.txt b/examples/widgets/effects/blurpicker/images/README.txt
deleted file mode 100644
index 0927e177d2..0000000000
--- a/examples/widgets/effects/blurpicker/images/README.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-The background is taken from a public domain photo at:
-http://www.photos8.com/view/computer_board2-800x600.html
-
-All other icons are from the Tango Desktop project:
-http://tango.freedesktop.org/Tango_Desktop_Project
diff --git a/examples/widgets/effects/blurpicker/images/accessories-calculator.png b/examples/widgets/effects/blurpicker/images/accessories-calculator.png
deleted file mode 100644
index 4e7661f65c..0000000000
--- a/examples/widgets/effects/blurpicker/images/accessories-calculator.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/accessories-text-editor.png b/examples/widgets/effects/blurpicker/images/accessories-text-editor.png
deleted file mode 100644
index 33bef0bc17..0000000000
--- a/examples/widgets/effects/blurpicker/images/accessories-text-editor.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/background.jpg b/examples/widgets/effects/blurpicker/images/background.jpg
deleted file mode 100644
index e75b38899d..0000000000
--- a/examples/widgets/effects/blurpicker/images/background.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/help-browser.png b/examples/widgets/effects/blurpicker/images/help-browser.png
deleted file mode 100644
index 8ef4fae91b..0000000000
--- a/examples/widgets/effects/blurpicker/images/help-browser.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/internet-group-chat.png b/examples/widgets/effects/blurpicker/images/internet-group-chat.png
deleted file mode 100644
index dd92d93947..0000000000
--- a/examples/widgets/effects/blurpicker/images/internet-group-chat.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/internet-mail.png b/examples/widgets/effects/blurpicker/images/internet-mail.png
deleted file mode 100644
index 7e6b93be83..0000000000
--- a/examples/widgets/effects/blurpicker/images/internet-mail.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/internet-web-browser.png b/examples/widgets/effects/blurpicker/images/internet-web-browser.png
deleted file mode 100644
index a979a92b4f..0000000000
--- a/examples/widgets/effects/blurpicker/images/internet-web-browser.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/office-calendar.png b/examples/widgets/effects/blurpicker/images/office-calendar.png
deleted file mode 100644
index e09590682b..0000000000
--- a/examples/widgets/effects/blurpicker/images/office-calendar.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/system-users.png b/examples/widgets/effects/blurpicker/images/system-users.png
deleted file mode 100644
index a7f630a5bd..0000000000
--- a/examples/widgets/effects/blurpicker/images/system-users.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/main.cpp b/examples/widgets/effects/blurpicker/main.cpp
deleted file mode 100644
index 4d5bf158c9..0000000000
--- a/examples/widgets/effects/blurpicker/main.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "blurpicker.h"
-#include <QApplication>
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
-
- BlurPicker blurPicker;
- blurPicker.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Application Picker"));
-
- blurPicker.setFixedSize(400, 300);
- blurPicker.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/effects/effects.pro b/examples/widgets/effects/effects.pro
deleted file mode 100644
index 05911979b9..0000000000
--- a/examples/widgets/effects/effects.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-TEMPLATE = \
- subdirs
-SUBDIRS = \
- blurpicker \
- fademessage
diff --git a/examples/widgets/effects/fademessage/CMakeLists.txt b/examples/widgets/effects/fademessage/CMakeLists.txt
deleted file mode 100644
index b55f9154bb..0000000000
--- a/examples/widgets/effects/fademessage/CMakeLists.txt
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(fademessage LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/effects/fademessage")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(fademessage
- fademessage.cpp fademessage.h
- main.cpp
-)
-
-set_target_properties(fademessage PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(fademessage PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(fademessage_resource_files
- "background.jpg"
-)
-
-qt_add_resources(fademessage "fademessage"
- PREFIX
- "/"
- FILES
- ${fademessage_resource_files}
-)
-
-install(TARGETS fademessage
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/effects/fademessage/README b/examples/widgets/effects/fademessage/README
deleted file mode 100644
index f639e76508..0000000000
--- a/examples/widgets/effects/fademessage/README
+++ /dev/null
@@ -1,2 +0,0 @@
-The background is taken from a public domain photo at:
-http://www.photos8.com/view/windows_problem_blue-800x600.html
diff --git a/examples/widgets/effects/fademessage/background.jpg b/examples/widgets/effects/fademessage/background.jpg
deleted file mode 100644
index 9884233a29..0000000000
--- a/examples/widgets/effects/fademessage/background.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/effects/fademessage/fademessage.cpp b/examples/widgets/effects/fademessage/fademessage.cpp
deleted file mode 100644
index 3d8385020b..0000000000
--- a/examples/widgets/effects/fademessage/fademessage.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "fademessage.h"
-
-#include <QtWidgets>
-
-FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent)
-{
- setScene(&m_scene);
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
- setupScene();
-
- m_animation = new QPropertyAnimation(m_effect, "strength", this);
- m_animation->setDuration(500);
- m_animation->setEasingCurve(QEasingCurve::InOutSine);
- m_animation->setStartValue(0);
- m_animation->setEndValue(1);
-
- setRenderHint(QPainter::Antialiasing, true);
- setFrameStyle(QFrame::NoFrame);
-}
-
-void FadeMessage::togglePopup()
-{
- if (m_message->isVisible()) {
- m_message->setVisible(false);
- m_animation->setDirection(QAbstractAnimation::Backward);
- } else {
- m_message->setVisible(true);
- m_animation->setDirection(QAbstractAnimation::Forward);
- }
- m_animation->start();
-}
-
-void FadeMessage::setupScene()
-{
- QGraphicsRectItem *parent = m_scene.addRect(0, 0, 800, 600);
- parent->setPen(Qt::NoPen);
- parent->setZValue(0);
-
- QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/background.jpg"));
- bg->setParentItem(parent);
- bg->setZValue(-1);
-
- for (int i = 1; i < 5; ++i)
- for (int j = 2; j < 5; ++j) {
- QGraphicsRectItem *item = m_scene.addRect(i * 50, (j - 1) * 50, 38, 38);
- item->setParentItem(parent);
- item->setZValue(1);
- int hue = 12 * (i * 5 + j);
- item->setBrush(QColor::fromHsv(hue, 128, 128));
- }
-
- QFont font;
- font.setPointSize(font.pointSize() * 2);
- font.setBold(true);
- QFontMetrics fontMetrics(font);
- int fh = fontMetrics.height();
-
- QString sceneText = "Qt Everywhere!";
- int sceneTextWidth = fontMetrics.horizontalAdvance(sceneText);
-
- QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
- block->setPen(Qt::NoPen);
- block->setBrush(QColor(102, 153, 51));
-
- QGraphicsTextItem *text = m_scene.addText(sceneText, font);
- text->setDefaultTextColor(Qt::white);
- text->setPos(50, 300);
- block->setZValue(2);
- block->hide();
-
- text->setParentItem(block);
- m_message = block;
-
- m_effect = new QGraphicsColorizeEffect;
- m_effect->setColor(QColor(122, 193, 66));
- m_effect->setStrength(0);
- m_effect->setEnabled(true);
- parent->setGraphicsEffect(m_effect);
-
- QPushButton *press = new QPushButton;
- press->setText(tr("Press me"));
- connect(press, &QAbstractButton::clicked, this, &FadeMessage::togglePopup);
- m_scene.addWidget(press);
-
- press->move(300, 500);
-}
diff --git a/examples/widgets/effects/fademessage/fademessage.h b/examples/widgets/effects/fademessage/fademessage.h
deleted file mode 100644
index 49923016cd..0000000000
--- a/examples/widgets/effects/fademessage/fademessage.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef FADEMESSAGE_H
-#define FADEMESSAGE_H
-
-#include <QGraphicsEffect>
-#include <QGraphicsView>
-#include <QPropertyAnimation>
-
-#include "fademessage.h"
-
-class FadeMessage: public QGraphicsView
-{
- Q_OBJECT
-
-public:
- FadeMessage(QWidget *parent = nullptr);
-
-private:
- void setupScene();
-
-private slots:
- void togglePopup();
-
-private:
- QGraphicsScene m_scene;
- QGraphicsColorizeEffect *m_effect;
- QGraphicsItem *m_message;
- QPropertyAnimation *m_animation;
-};
-
-#endif // FADEMESSAGE_H
diff --git a/examples/widgets/effects/fademessage/fademessage.pro b/examples/widgets/effects/fademessage/fademessage.pro
deleted file mode 100644
index 0beff1999a..0000000000
--- a/examples/widgets/effects/fademessage/fademessage.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-QT += widgets
-
-SOURCES += main.cpp fademessage.cpp
-HEADERS += fademessage.h
-RESOURCES += fademessage.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/effects/fademessage
-INSTALLS += target
diff --git a/examples/widgets/effects/fademessage/fademessage.qrc b/examples/widgets/effects/fademessage/fademessage.qrc
deleted file mode 100644
index 9efea6a67d..0000000000
--- a/examples/widgets/effects/fademessage/fademessage.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>background.jpg</file>
- </qresource>
-</RCC>
diff --git a/examples/widgets/effects/fademessage/main.cpp b/examples/widgets/effects/fademessage/main.cpp
deleted file mode 100644
index 66504bc432..0000000000
--- a/examples/widgets/effects/fademessage/main.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "fademessage.h"
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
-
- FadeMessage widget;
- widget.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Popup Message with Effect"));
- widget.setFixedSize(400, 600);
- widget.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/gallery/CMakeLists.txt b/examples/widgets/gallery/CMakeLists.txt
index 3a2d2924d4..e0c87afb0b 100644
--- a/examples/widgets/gallery/CMakeLists.txt
+++ b/examples/widgets/gallery/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(gallery LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/gallery")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(gallery PRIVATE
)
install(TARGETS gallery
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET gallery
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/gallery/main.cpp b/examples/widgets/gallery/main.cpp
index cfac821209..2677b3708c 100644
--- a/examples/widgets/gallery/main.cpp
+++ b/examples/widgets/gallery/main.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
+#include <QStyleHints>
#include "widgetgallery.h"
diff --git a/examples/widgets/gallery/widgetgallery.cpp b/examples/widgets/gallery/widgetgallery.cpp
index 2de46419d9..d38dcbd5e8 100644
--- a/examples/widgets/gallery/widgetgallery.cpp
+++ b/examples/widgets/gallery/widgetgallery.cpp
@@ -26,6 +26,7 @@
#include <QSpinBox>
#include <QStandardItemModel>
#include <QStyle>
+#include <QStyleHints>
#include <QStyleFactory>
#include <QTextBrowser>
#include <QTreeView>
@@ -135,6 +136,21 @@ WidgetGallery::WidgetGallery(QWidget *parent)
auto styleLabel = createWidget1<QLabel>(tr("&Style:"), "styleLabel");
styleLabel->setBuddy(styleComboBox);
+ auto colorSchemeComboBox = createWidget<QComboBox>("colorSchemeComboBox");
+ colorSchemeComboBox->addItem(tr("Auto"));
+ colorSchemeComboBox->addItem(tr("Light"));
+ colorSchemeComboBox->addItem(tr("Dark"));
+ // override the color scheme to dark
+ qApp->styleHints()->setColorScheme(Qt::ColorScheme::Dark);
+ colorSchemeComboBox->setCurrentIndex(2);
+
+ auto colorSchemeLabel = createWidget1<QLabel>(tr("&Color Scheme:"), "colorSchemeLabel");
+ colorSchemeLabel->setBuddy(colorSchemeComboBox);
+
+ connect(colorSchemeComboBox, &QComboBox::currentIndexChanged, this, [](int index){
+ QGuiApplication::styleHints()->setColorScheme(static_cast<Qt::ColorScheme>(index));
+ });
+
auto helpLabel = createWidget1<QLabel>(tr("Press F1 over a widget to see Documentation"), "helpLabel");
auto disableWidgetsCheckBox = createWidget1<QCheckBox>(tr("&Disable widgets"), "disableWidgetsCheckBox");
@@ -156,8 +172,12 @@ WidgetGallery::WidgetGallery(QWidget *parent)
simpleInputWidgetsGroupBox, &QWidget::setDisabled);
auto topLayout = new QHBoxLayout;
- topLayout->addWidget(styleLabel);
- topLayout->addWidget(styleComboBox);
+ auto appearanceLayout = new QGridLayout;
+ appearanceLayout->addWidget(styleLabel, 0, 0);
+ appearanceLayout->addWidget(styleComboBox, 0, 1);
+ appearanceLayout->addWidget(colorSchemeLabel, 1, 0);
+ appearanceLayout->addWidget(colorSchemeComboBox, 1, 1);
+ topLayout->addLayout(appearanceLayout);
topLayout->addStretch(1);
topLayout->addWidget(helpLabel);
topLayout->addStretch(1);
diff --git a/examples/widgets/gestures/CMakeLists.txt b/examples/widgets/gestures/CMakeLists.txt
index c345cfed11..0110ca90a6 100644
--- a/examples/widgets/gestures/CMakeLists.txt
+++ b/examples/widgets/gestures/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Widgets)
return()
diff --git a/examples/widgets/gestures/imagegestures/CMakeLists.txt b/examples/widgets/gestures/imagegestures/CMakeLists.txt
index d773e926f1..1e173dc63f 100644
--- a/examples/widgets/gestures/imagegestures/CMakeLists.txt
+++ b/examples/widgets/gestures/imagegestures/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(imagegestures LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/gestures/imagegestures")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(imagegestures PRIVATE
)
install(TARGETS imagegestures
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET imagegestures
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc b/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc
index 7722da680a..46053566ab 100644
--- a/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc
+++ b/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc
@@ -4,12 +4,13 @@
/*!
\example gestures/imagegestures
\title Image Gestures Example
+ \examplecategory {User Interface Components}
\brief Demonstrates the use of simple gestures in a widget.
This example shows how to enable gestures for a widget and use gesture input
to perform actions.
- \image imagegestures-example.jpg
+ \image imagegestures-example.png
We use two classes to create the user interface for the application: \c MainWidget
and \c ImageWidget. The \c MainWidget class is simply used as a container for the
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp
index e17bf3c0c0..189281cc11 100644
--- a/examples/widgets/gestures/imagegestures/imagewidget.cpp
+++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp
@@ -41,6 +41,12 @@ void ImageWidget::paintEvent(QPaintEvent*)
{
QPainter p(this);
+ if (files.isEmpty() && !path.isEmpty()) {
+ p.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap,
+ tr("No supported image formats found"));
+ return;
+ }
+
const qreal iw = currentImage.width();
const qreal ih = currentImage.height();
const qreal wh = height();
@@ -144,20 +150,32 @@ void ImageWidget::resizeEvent(QResizeEvent*)
update();
}
-void ImageWidget::openDirectory(const QString &path)
+void ImageWidget::openDirectory(const QString &url)
{
- this->path = path;
+ path = url;
QDir dir(path);
- const QStringList nameFilters{"*.jpg", "*.png"};
- files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
+
+ QStringList nameFilters;
+ const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
+ for (const QByteArray &format : supportedFormats)
+ nameFilters.append(QLatin1String("*.") + QString::fromLatin1(format));
+ files = dir.entryInfoList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
position = 0;
goToImage(0);
update();
}
-QImage ImageWidget::loadImage(const QString &fileName) const
+/*
+ With Android's content scheme paths, it might not be possible to simply
+ append a file name to the chosen directory path to be able to open the image,
+ because usually paths are returned by an Android file provider and handling those
+ paths manually is not guaranteed to work. For that reason, it's better to keep
+ around QFileInfo objects and use absoluteFilePath().
+*/
+QImage ImageWidget::loadImage(const QFileInfo &fileInfo) const
{
+ const QString fileName = fileInfo.absoluteFilePath();
QImageReader reader(fileName);
reader.setAutoTransform(true);
qCDebug(lcExample) << "loading" << QDir::toNativeSeparators(fileName) << position << '/' << files.size();
@@ -187,7 +205,7 @@ void ImageWidget::goNextImage()
prevImage = currentImage;
currentImage = nextImage;
if (position+1 < files.size())
- nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1));
+ nextImage = loadImage(files.at(position + 1));
else
nextImage = QImage();
}
@@ -204,7 +222,7 @@ void ImageWidget::goPrevImage()
nextImage = currentImage;
currentImage = prevImage;
if (position > 0)
- prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1));
+ prevImage = loadImage(files.at(position - 1));
else
prevImage = QImage();
}
@@ -234,12 +252,12 @@ void ImageWidget::goToImage(int index)
position = index;
if (index > 0)
- prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1));
+ prevImage = loadImage(files.at(position - 1));
else
prevImage = QImage();
- currentImage = loadImage(path + QLatin1Char('/') + files.at(position));
+ currentImage = loadImage(files.at(position));
if (position+1 < files.size())
- nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1));
+ nextImage = loadImage(files.at(position + 1));
else
nextImage = QImage();
update();
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.h b/examples/widgets/gestures/imagegestures/imagewidget.h
index 7e8142442a..1f4010baac 100644
--- a/examples/widgets/gestures/imagegestures/imagewidget.h
+++ b/examples/widgets/gestures/imagegestures/imagewidget.h
@@ -4,6 +4,7 @@
#ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H
+#include <QFileInfo>
#include <QImage>
#include <QLoggingCategory>
#include <QWidget>
@@ -24,7 +25,7 @@ class ImageWidget : public QWidget
public:
ImageWidget(QWidget *parent = nullptr);
- void openDirectory(const QString &path);
+ void openDirectory(const QString &url);
void grabGestures(const QList<Qt::GestureType> &gestures);
protected:
@@ -40,14 +41,14 @@ private:
void swipeTriggered(QSwipeGesture*);
//! [class definition begin]
- QImage loadImage(const QString &fileName) const;
+ QImage loadImage(const QFileInfo &fileInfo) const;
void loadImage();
void goNextImage();
void goPrevImage();
void goToImage(int index);
QString path;
- QStringList files;
+ QFileInfoList files;
int position;
QImage prevImage, nextImage;
diff --git a/examples/widgets/graphicsview/CMakeLists.txt b/examples/widgets/graphicsview/CMakeLists.txt
index e0d291312e..7e287f0f42 100644
--- a/examples/widgets/graphicsview/CMakeLists.txt
+++ b/examples/widgets/graphicsview/CMakeLists.txt
@@ -1,13 +1,11 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(chip)
qt_internal_add_example(elasticnodes)
-qt_internal_add_example(embeddeddialogs)
qt_internal_add_example(collidingmice)
qt_internal_add_example(basicgraphicslayouts)
qt_internal_add_example(diagramscene)
-qt_internal_add_example(flowlayout)
qt_internal_add_example(simpleanchorlayout)
if(QT_FEATURE_cursor AND QT_FEATURE_draganddrop)
qt_internal_add_example(dragdroprobot)
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/CMakeLists.txt b/examples/widgets/graphicsview/basicgraphicslayouts/CMakeLists.txt
index 6ee7426ace..dae3884e8b 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/CMakeLists.txt
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(basicgraphicslayouts LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/basicgraphicslayouts")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -44,7 +38,14 @@ qt_add_resources(basicgraphicslayouts "basicgraphicslayouts"
)
install(TARGETS basicgraphicslayouts
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET basicgraphicslayouts
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/graphicsview/chip/CMakeLists.txt b/examples/widgets/graphicsview/chip/CMakeLists.txt
index 03305cf92c..81b2e19552 100644
--- a/examples/widgets/graphicsview/chip/CMakeLists.txt
+++ b/examples/widgets/graphicsview/chip/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chip LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/chip")
-
find_package(Qt6
REQUIRED COMPONENTS Core Gui Widgets
OPTIONAL_COMPONENTS PrintSupport
@@ -57,7 +51,14 @@ if(TARGET Qt6::PrintSupport)
endif()
install(TARGETS chip
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET chip
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/graphicsview/chip/main.cpp b/examples/widgets/graphicsview/chip/main.cpp
index bf75db6a93..4ccd66bbb9 100644
--- a/examples/widgets/graphicsview/chip/main.cpp
+++ b/examples/widgets/graphicsview/chip/main.cpp
@@ -7,8 +7,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(images);
-
QApplication app(argc, argv);
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
diff --git a/examples/widgets/graphicsview/collidingmice/CMakeLists.txt b/examples/widgets/graphicsview/collidingmice/CMakeLists.txt
index ec31b3bcbf..226b72b051 100644
--- a/examples/widgets/graphicsview/collidingmice/CMakeLists.txt
+++ b/examples/widgets/graphicsview/collidingmice/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(collidingmice LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/collidingmice")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -43,7 +37,14 @@ qt_add_resources(collidingmice "mice"
)
install(TARGETS collidingmice
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET collidingmice
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/graphicsview/diagramscene/CMakeLists.txt b/examples/widgets/graphicsview/diagramscene/CMakeLists.txt
index 16c797c455..9db835478d 100644
--- a/examples/widgets/graphicsview/diagramscene/CMakeLists.txt
+++ b/examples/widgets/graphicsview/diagramscene/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(diagramscene LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/diagramscene")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -61,7 +55,14 @@ qt_add_resources(diagramscene "diagramscene"
)
install(TARGETS diagramscene
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET diagramscene
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/graphicsview/diagramscene/main.cpp b/examples/widgets/graphicsview/diagramscene/main.cpp
index 56310b1751..699c33f079 100644
--- a/examples/widgets/graphicsview/diagramscene/main.cpp
+++ b/examples/widgets/graphicsview/diagramscene/main.cpp
@@ -7,8 +7,6 @@
int main(int argv, char *args[])
{
- Q_INIT_RESOURCE(diagramscene);
-
QApplication app(argv, args);
MainWindow mainWindow;
mainWindow.setGeometry(100, 100, 800, 500);
diff --git a/examples/widgets/graphicsview/dragdroprobot/CMakeLists.txt b/examples/widgets/graphicsview/dragdroprobot/CMakeLists.txt
index b6a39c4bce..df2425260e 100644
--- a/examples/widgets/graphicsview/dragdroprobot/CMakeLists.txt
+++ b/examples/widgets/graphicsview/dragdroprobot/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(dragdroprobot LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/dragdroprobot")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -44,7 +38,14 @@ qt_add_resources(dragdroprobot "robot"
)
install(TARGETS dragdroprobot
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET dragdroprobot
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/graphicsview/elasticnodes/CMakeLists.txt b/examples/widgets/graphicsview/elasticnodes/CMakeLists.txt
index b0378b3146..07299cd5a7 100644
--- a/examples/widgets/graphicsview/elasticnodes/CMakeLists.txt
+++ b/examples/widgets/graphicsview/elasticnodes/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(elasticnodes LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/elasticnodes")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(elasticnodes PRIVATE
)
install(TARGETS elasticnodes
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET elasticnodes
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt b/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt
deleted file mode 100644
index 78883a0a89..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(embeddeddialogs LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/embeddeddialogs")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(embeddeddialogs
- customproxy.cpp customproxy.h
- embeddeddialog.cpp embeddeddialog.h embeddeddialog.ui
- main.cpp
-)
-
-set_target_properties(embeddeddialogs PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(embeddeddialogs PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(embeddeddialogs_resource_files
- "No-Ones-Laughing-3.jpg"
-)
-
-qt_add_resources(embeddeddialogs "embeddeddialogs"
- PREFIX
- "/"
- FILES
- ${embeddeddialogs_resource_files}
-)
-
-install(TARGETS embeddeddialogs
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg b/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg
deleted file mode 100644
index 445567fbda..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
deleted file mode 100644
index 57a104f57d..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "customproxy.h"
-
-#include <QGraphicsScene>
-#include <QPainter>
-#include <QStyleOptionGraphicsItem>
-
-CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
- : QGraphicsProxyWidget(parent, wFlags), timeLine(new QTimeLine(250, this))
-{
- connect(timeLine, &QTimeLine::valueChanged,
- this, &CustomProxy::updateStep);
- connect(timeLine, &QTimeLine::stateChanged,
- this, &CustomProxy::stateChanged);
-}
-
-QRectF CustomProxy::boundingRect() const
-{
- return QGraphicsProxyWidget::boundingRect().adjusted(0, 0, 10, 10);
-}
-
-void CustomProxy::paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget)
-{
- const QColor color(0, 0, 0, 64);
-
- QRectF r = windowFrameRect();
- QRectF right(r.right(), r.top() + 10, 10, r.height() - 10);
- QRectF bottom(r.left() + 10, r.bottom(), r.width(), 10);
- bool intersectsRight = right.intersects(option->exposedRect);
- bool intersectsBottom = bottom.intersects(option->exposedRect);
- if (intersectsRight && intersectsBottom) {
- QPainterPath path;
- path.addRect(right);
- path.addRect(bottom);
- painter->setPen(Qt::NoPen);
- painter->setBrush(color);
- painter->drawPath(path);
- } else if (intersectsBottom) {
- painter->fillRect(bottom, color);
- } else if (intersectsRight) {
- painter->fillRect(right, color);
- }
-
- QGraphicsProxyWidget::paintWindowFrame(painter, option, widget);
-}
-
-void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
-{
- QGraphicsProxyWidget::hoverEnterEvent(event);
- scene()->setActiveWindow(this);
- if (qFuzzyCompare(timeLine->currentValue(), 1))
- zoomIn();
-}
-
-void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
-{
- QGraphicsProxyWidget::hoverLeaveEvent(event);
- if (!popupShown
- && (timeLine->direction() != QTimeLine::Backward || qFuzzyIsNull(timeLine->currentValue()))) {
- zoomOut();
- }
-}
-
-bool CustomProxy::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
-{
- if (watched->isWindow()
- && (event->type() == QEvent::UngrabMouse || event->type() == QEvent::GrabMouse)) {
- popupShown = watched->isVisible();
- if (!popupShown && !isUnderMouse())
- zoomOut();
- }
- return QGraphicsProxyWidget::sceneEventFilter(watched, event);
-}
-
-QVariant CustomProxy::itemChange(GraphicsItemChange change, const QVariant &value)
-{
- if (change == ItemChildAddedChange || change == ItemChildRemovedChange) {
- if (change == ItemChildAddedChange) {
- currentPopup = qvariant_cast<QGraphicsItem *>(value);
- currentPopup->setCacheMode(ItemCoordinateCache);
- if (scene())
- currentPopup->installSceneEventFilter(this);
- } else if (scene()) {
- currentPopup->removeSceneEventFilter(this);
- currentPopup = nullptr;
- }
- } else if (currentPopup && change == ItemSceneHasChanged) {
- currentPopup->installSceneEventFilter(this);
- }
- return QGraphicsProxyWidget::itemChange(change, value);
-}
-
-void CustomProxy::updateStep(qreal step)
-{
- QRectF r = boundingRect();
- setTransform(QTransform()
- .translate(r.width() / 2, r.height() / 2)
- .rotate(step * 30, Qt::XAxis)
- .rotate(step * 10, Qt::YAxis)
- .rotate(step * 5, Qt::ZAxis)
- .scale(1 + 1.5 * step, 1 + 1.5 * step)
- .translate(-r.width() / 2, -r.height() / 2));
-}
-
-void CustomProxy::stateChanged(QTimeLine::State state)
-{
- if (state == QTimeLine::Running) {
- if (timeLine->direction() == QTimeLine::Forward)
- setCacheMode(ItemCoordinateCache);
- } else if (state == QTimeLine::NotRunning) {
- if (timeLine->direction() == QTimeLine::Backward)
- setCacheMode(DeviceCoordinateCache);
- }
-}
-
-void CustomProxy::zoomIn()
-{
- if (timeLine->direction() != QTimeLine::Forward)
- timeLine->setDirection(QTimeLine::Forward);
- if (timeLine->state() == QTimeLine::NotRunning)
- timeLine->start();
-}
-
-void CustomProxy::zoomOut()
-{
- if (timeLine->direction() != QTimeLine::Backward)
- timeLine->setDirection(QTimeLine::Backward);
- if (timeLine->state() == QTimeLine::NotRunning)
- timeLine->start();
-}
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
deleted file mode 100644
index 444d39e73e..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef CUSTOMPROXY_H
-#define CUSTOMPROXY_H
-
-#include <QTimeLine>
-#include <QGraphicsProxyWidget>
-
-class CustomProxy : public QGraphicsProxyWidget
-{
- Q_OBJECT
-
-public:
- explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { });
-
- QRectF boundingRect() const override;
- void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget) override;
-
-protected:
- void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
- QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
-
-private slots:
- void updateStep(qreal step);
- void stateChanged(QTimeLine::State);
- void zoomIn();
- void zoomOut();
-
-private:
- QTimeLine *timeLine;
- QGraphicsItem *currentPopup = nullptr;
- bool popupShown = false;
-};
-
-#endif // CUSTOMPROXY_H
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
deleted file mode 100644
index 43d7fbf1e9..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "embeddeddialog.h"
-#include "ui_embeddeddialog.h"
-
-#include <QStyleFactory>
-
-EmbeddedDialog::EmbeddedDialog(QWidget *parent)
- : QDialog(parent)
- , ui(new Ui::EmbeddedDialog)
-{
- ui->setupUi(this);
- ui->layoutDirection->setCurrentIndex(layoutDirection() != Qt::LeftToRight);
-
- const QStringList styleKeys = QStyleFactory::keys();
- for (const QString &styleName : styleKeys) {
- ui->style->addItem(styleName);
- if (style()->objectName().toLower() == styleName.toLower())
- ui->style->setCurrentIndex(ui->style->count() - 1);
- }
-
- connect(ui->layoutDirection, &QComboBox::activated,
- this, &EmbeddedDialog::layoutDirectionChanged);
- connect(ui->spacing, &QSlider::valueChanged,
- this, &EmbeddedDialog::spacingChanged);
- connect(ui->fontComboBox, &QFontComboBox::currentFontChanged,
- this, &EmbeddedDialog::fontChanged);
- connect(ui->style, &QComboBox::textActivated,
- this, &EmbeddedDialog::styleChanged);
-}
-
-EmbeddedDialog::~EmbeddedDialog()
-{
- delete ui;
-}
-
-void EmbeddedDialog::layoutDirectionChanged(int index)
-{
- setLayoutDirection(index == 0 ? Qt::LeftToRight : Qt::RightToLeft);
-}
-
-void EmbeddedDialog::spacingChanged(int spacing)
-{
- layout()->setSpacing(spacing);
- adjustSize();
-}
-
-void EmbeddedDialog::fontChanged(const QFont &font)
-{
- setFont(font);
-}
-
-static void setStyleHelper(QWidget *widget, QStyle *style)
-{
- widget->setStyle(style);
- widget->setPalette(style->standardPalette());
- const QObjectList children = widget->children();
- for (QObject *child : children) {
- if (QWidget *childWidget = qobject_cast<QWidget *>(child))
- setStyleHelper(childWidget, style);
- }
-}
-
-void EmbeddedDialog::styleChanged(const QString &styleName)
-{
- QStyle *style = QStyleFactory::create(styleName);
- if (style)
- setStyleHelper(this, style);
-}
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
deleted file mode 100644
index d4c561799e..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef EMBEDDEDDIALOG_H
-#define EMBEDDEDDIALOG_H
-
-#include <QDialog>
-
-QT_BEGIN_NAMESPACE
-namespace Ui {
-class EmbeddedDialog;
-}
-QT_END_NAMESPACE
-
-class EmbeddedDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- EmbeddedDialog(QWidget *parent = nullptr);
- ~EmbeddedDialog();
-
-private slots:
- void layoutDirectionChanged(int index);
- void spacingChanged(int spacing);
- void fontChanged(const QFont &font);
- void styleChanged(const QString &styleName);
-
-private:
- Ui::EmbeddedDialog *ui;
-};
-
-#endif // EMBEDDEDDIALOG_H
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui
deleted file mode 100644
index 82aa5d7be3..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui
+++ /dev/null
@@ -1,88 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>EmbeddedDialog</class>
- <widget class="QDialog" name="EmbeddedDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>407</width>
- <height>134</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Embedded Dialog</string>
- </property>
- <layout class="QFormLayout" name="formLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Layout Direction:</string>
- </property>
- <property name="buddy">
- <cstring>layoutDirection</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QComboBox" name="layoutDirection">
- <item>
- <property name="text">
- <string>Left to Right</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Right to Left</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Select Font:</string>
- </property>
- <property name="buddy">
- <cstring>fontComboBox</cstring>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QFontComboBox" name="fontComboBox"/>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Style:</string>
- </property>
- <property name="buddy">
- <cstring>style</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QComboBox" name="style"/>
- </item>
- <item row="3" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>Layout spacing:</string>
- </property>
- <property name="buddy">
- <cstring>spacing</cstring>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QSlider" name="spacing">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
deleted file mode 100644
index 60c507fc3d..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-QT += widgets
-requires(qtConfig(fontcombobox))
-
-SOURCES += main.cpp
-SOURCES += customproxy.cpp embeddeddialog.cpp
-HEADERS += customproxy.h embeddeddialog.h
-
-FORMS += embeddeddialog.ui
-RESOURCES += embeddeddialogs.qrc
-
-build_all:!build_pass {
- CONFIG -= build_all
- CONFIG += release
-}
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/graphicsview/embeddeddialogs
-INSTALLS += target
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc
deleted file mode 100644
index 33be5038da..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource>
- <file>No-Ones-Laughing-3.jpg</file>
- </qresource>
-</RCC>
diff --git a/examples/widgets/graphicsview/embeddeddialogs/main.cpp b/examples/widgets/graphicsview/embeddeddialogs/main.cpp
deleted file mode 100644
index f022b74814..0000000000
--- a/examples/widgets/graphicsview/embeddeddialogs/main.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "customproxy.h"
-#include "embeddeddialog.h"
-
-#include <QApplication>
-#include <QGraphicsScene>
-#include <QGraphicsView>
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(embeddeddialogs);
- QApplication app(argc, argv);
-
- QGraphicsScene scene;
- scene.setStickyFocus(true);
- const int gridSize = 10;
-
- for (int y = 0; y < gridSize; ++y) {
- for (int x = 0; x < gridSize; ++x) {
- CustomProxy *proxy = new CustomProxy(nullptr, Qt::Window);
- proxy->setWidget(new EmbeddedDialog);
-
- QRectF rect = proxy->boundingRect();
-
- proxy->setPos(x * rect.width() * 1.05, y * rect.height() * 1.05);
- proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
-
- scene.addItem(proxy);
- }
- }
- scene.setSceneRect(scene.itemsBoundingRect());
-
- QGraphicsView view(&scene);
- view.scale(0.5, 0.5);
- view.setRenderHints(view.renderHints() | QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
- view.setBackgroundBrush(QPixmap(":/No-Ones-Laughing-3.jpg"));
- view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
- view.show();
- view.setWindowTitle("Embedded Dialogs Example");
- return app.exec();
-}
diff --git a/examples/widgets/graphicsview/flowlayout/CMakeLists.txt b/examples/widgets/graphicsview/flowlayout/CMakeLists.txt
deleted file mode 100644
index b15af3d02d..0000000000
--- a/examples/widgets/graphicsview/flowlayout/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(flowlayout LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview_flowlayout")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(graphicsview_flowlayout
- flowlayout.cpp flowlayout.h
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(graphicsview_flowlayout PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(graphicsview_flowlayout PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS graphicsview_flowlayout
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
deleted file mode 100644
index ab5f4717b3..0000000000
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "flowlayout.h"
-
-#include <QtMath>
-
-FlowLayout::FlowLayout(QGraphicsLayoutItem *parent) : QGraphicsLayout(parent)
-{
- QSizePolicy sp = sizePolicy();
- sp.setHeightForWidth(true);
- setSizePolicy(sp);
-}
-
-void FlowLayout::insertItem(int index, QGraphicsLayoutItem *item)
-{
- item->setParentLayoutItem(this);
- if (index > m_items.count() || index < 0)
- index = m_items.count();
- m_items.insert(index, item);
- invalidate();
-}
-
-int FlowLayout::count() const
-{
- return m_items.count();
-}
-
-QGraphicsLayoutItem *FlowLayout::itemAt(int index) const
-{
- return m_items.value(index);
-}
-
-void FlowLayout::removeAt(int index)
-{
- m_items.removeAt(index);
- invalidate();
-}
-
-qreal FlowLayout::spacing(Qt::Orientation o) const
-{
- return m_spacing[int(o) - 1];
-}
-
-void FlowLayout::setSpacing(Qt::Orientations o, qreal spacing)
-{
- if (o & Qt::Horizontal)
- m_spacing[0] = spacing;
- if (o & Qt::Vertical)
- m_spacing[1] = spacing;
-}
-
-void FlowLayout::setGeometry(const QRectF &geom)
-{
- QGraphicsLayout::setGeometry(geom);
- doLayout(geom, true);
-}
-
-qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
-{
- qreal left, top, right, bottom;
- getContentsMargins(&left, &top, &right, &bottom);
- const qreal maxw = geom.width() - left - right;
-
- qreal x = 0;
- qreal y = 0;
- qreal maxRowHeight = 0;
- QSizeF pref;
- for (QGraphicsLayoutItem *item : m_items) {
- pref = item->effectiveSizeHint(Qt::PreferredSize);
- maxRowHeight = qMax(maxRowHeight, pref.height());
-
- qreal next_x;
- next_x = x + pref.width();
- if (next_x > maxw) {
- if (qFuzzyIsNull(x)) {
- pref.setWidth(maxw);
- } else {
- x = 0;
- next_x = pref.width();
- }
- y += maxRowHeight + spacing(Qt::Vertical);
- maxRowHeight = 0;
- }
-
- if (applyNewGeometry)
- item->setGeometry(QRectF(QPointF(left + x, top + y), pref));
- x = next_x + spacing(Qt::Horizontal);
- }
- maxRowHeight = qMax(maxRowHeight, pref.height());
- return top + y + maxRowHeight + bottom;
-}
-
-QSizeF FlowLayout::minSize(const QSizeF &constraint) const
-{
- QSizeF size(0, 0);
- qreal left, top, right, bottom;
- getContentsMargins(&left, &top, &right, &bottom);
- if (constraint.width() >= 0) { // height for width
- const qreal height = doLayout(QRectF(QPointF(0,0), constraint), false);
- size = QSizeF(constraint.width(), height);
- } else if (constraint.height() >= 0) { // width for height?
- // not supported
- } else {
- for (const QGraphicsLayoutItem *item : std::as_const(m_items))
- size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
- size += QSizeF(left + right, top + bottom);
- }
- return size;
-}
-
-QSizeF FlowLayout::prefSize() const
-{
- qreal left, right;
- getContentsMargins(&left, nullptr, &right, nullptr);
-
- qreal maxh = 0;
- qreal totalWidth = 0;
- for (const QGraphicsLayoutItem *item : std::as_const(m_items)) {
- if (totalWidth > 0)
- totalWidth += spacing(Qt::Horizontal);
- QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize);
- totalWidth += pref.width();
- maxh = qMax(maxh, pref.height());
- }
- maxh += spacing(Qt::Vertical);
-
- const qreal goldenAspectRatio = 1.61803399;
- qreal w = qSqrt(totalWidth * maxh * goldenAspectRatio) + left + right;
-
- return minSize(QSizeF(w, -1));
-}
-
-QSizeF FlowLayout::maxSize() const
-{
- qreal totalWidth = 0;
- qreal totalHeight = 0;
- for (const QGraphicsLayoutItem *item : std::as_const(m_items)) {
- if (totalWidth > 0)
- totalWidth += spacing(Qt::Horizontal);
- if (totalHeight > 0)
- totalHeight += spacing(Qt::Vertical);
- QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize);
- totalWidth += pref.width();
- totalHeight += pref.height();
- }
-
- qreal left, top, right, bottom;
- getContentsMargins(&left, &top, &right, &bottom);
- return QSizeF(left + totalWidth + right, top + totalHeight + bottom);
-}
-
-QSizeF FlowLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
-{
- QSizeF sh = constraint;
- switch (which) {
- case Qt::PreferredSize:
- sh = prefSize();
- break;
- case Qt::MinimumSize:
- sh = minSize(constraint);
- break;
- case Qt::MaximumSize:
- sh = maxSize();
- break;
- default:
- break;
- }
- return sh;
-}
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.h b/examples/widgets/graphicsview/flowlayout/flowlayout.h
deleted file mode 100644
index 028394827a..0000000000
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef FLOWLAYOUT_H
-#define FLOWLAYOUT_H
-
-#include <QGraphicsLayout>
-
-class FlowLayout : public QGraphicsLayout
-{
-public:
- FlowLayout(QGraphicsLayoutItem *parent = nullptr);
- inline void addItem(QGraphicsLayoutItem *item);
- void insertItem(int index, QGraphicsLayoutItem *item);
- void setSpacing(Qt::Orientations o, qreal spacing);
- qreal spacing(Qt::Orientation o) const;
-
- // inherited functions
- void setGeometry(const QRectF &geom) override;
-
- int count() const override;
- QGraphicsLayoutItem *itemAt(int index) const override;
- void removeAt(int index) override;
-
-protected:
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
-
-private:
- qreal doLayout(const QRectF &geom, bool applyNewGeometry) const;
- QSizeF minSize(const QSizeF &constraint) const;
- QSizeF prefSize() const;
- QSizeF maxSize() const;
-
- QList<QGraphicsLayoutItem *> m_items;
- qreal m_spacing[2] = {6, 6};
-};
-
-
-inline void FlowLayout::addItem(QGraphicsLayoutItem *item)
-{
- insertItem(-1, item);
-}
-
-#endif // FLOWLAYOUT_H
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.pro b/examples/widgets/graphicsview/flowlayout/flowlayout.pro
deleted file mode 100644
index 7830e3a008..0000000000
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-QT += widgets
-
-QMAKE_PROJECT_NAME = flowlayout_graphicsview
-
-HEADERS += flowlayout.h window.h
-SOURCES += flowlayout.cpp main.cpp window.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/graphicsview/flowlayout
-INSTALLS += target
diff --git a/examples/widgets/graphicsview/flowlayout/main.cpp b/examples/widgets/graphicsview/flowlayout/main.cpp
deleted file mode 100644
index 118b404870..0000000000
--- a/examples/widgets/graphicsview/flowlayout/main.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [1]
-#include "window.h"
-
-#include <QApplication>
-#include <QGraphicsView>
-
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- QGraphicsScene scene;
- QGraphicsView view(&scene);
- Window *w = new Window;
- scene.addItem(w);
-
- view.resize(400, 300);
- view.show();
-
- return app.exec();
-}
-//! [1]
diff --git a/examples/widgets/graphicsview/flowlayout/window.cpp b/examples/widgets/graphicsview/flowlayout/window.cpp
deleted file mode 100644
index ed9a5720d3..0000000000
--- a/examples/widgets/graphicsview/flowlayout/window.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-#include "flowlayout.h"
-
-#include <QGraphicsProxyWidget>
-#include <QLabel>
-
-Window::Window(QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Window)
-{
- FlowLayout *lay = new FlowLayout;
- const QString sentence(QLatin1String("I am not bothered by the fact that I am unknown."
- " I am bothered when I do not know others. (Confucius)"));
- const QList<QStringView> words = QStringView{ sentence }.split(QLatin1Char(' '), Qt::SkipEmptyParts);
- for (const QStringView &word : words) {
- QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
- QLabel *label = new QLabel(word.toString());
- label->setFrameStyle(QFrame::Box | QFrame::Plain);
- proxy->setWidget(label);
- lay->addItem(proxy);
- }
- setLayout(lay);
-}
diff --git a/examples/widgets/graphicsview/flowlayout/window.h b/examples/widgets/graphicsview/flowlayout/window.h
deleted file mode 100644
index 2fc5570406..0000000000
--- a/examples/widgets/graphicsview/flowlayout/window.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QGraphicsWidget>
-
-class Window : public QGraphicsWidget
-{
- Q_OBJECT
-public:
- Window(QGraphicsItem *parent = nullptr);
-};
-
-#endif // WINDOW_H
diff --git a/examples/widgets/graphicsview/graphicsview.pro b/examples/widgets/graphicsview/graphicsview.pro
index b3e49050ba..d50f0b1adc 100644
--- a/examples/widgets/graphicsview/graphicsview.pro
+++ b/examples/widgets/graphicsview/graphicsview.pro
@@ -2,12 +2,10 @@ TEMPLATE = subdirs
SUBDIRS = \
chip \
elasticnodes \
- embeddeddialogs \
collidingmice \
basicgraphicslayouts \
diagramscene \
dragdroprobot \
- flowlayout \
simpleanchorlayout
contains(DEFINES, QT_NO_CURSOR)|!qtConfig(draganddrop): SUBDIRS -= dragdroprobot
diff --git a/examples/widgets/graphicsview/simpleanchorlayout/CMakeLists.txt b/examples/widgets/graphicsview/simpleanchorlayout/CMakeLists.txt
index 532fffd4d6..2f31e12bbf 100644
--- a/examples/widgets/graphicsview/simpleanchorlayout/CMakeLists.txt
+++ b/examples/widgets/graphicsview/simpleanchorlayout/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(simpleanchorlayout LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/simpleanchorlayout")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(simpleanchorlayout PRIVATE
)
install(TARGETS simpleanchorlayout
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET simpleanchorlayout
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/CMakeLists.txt b/examples/widgets/itemviews/CMakeLists.txt
index 96af14b567..e80d90160b 100644
--- a/examples/widgets/itemviews/CMakeLists.txt
+++ b/examples/widgets/itemviews/CMakeLists.txt
@@ -1,28 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(addressbook)
qt_internal_add_example(basicsortfiltermodel)
-qt_internal_add_example(chart)
-qt_internal_add_example(coloreditorfactory)
qt_internal_add_example(combowidgetmapper)
qt_internal_add_example(customsortfiltermodel)
-qt_internal_add_example(dirview)
qt_internal_add_example(editabletreemodel)
qt_internal_add_example(fetchmore)
-qt_internal_add_example(flattreeview)
qt_internal_add_example(frozencolumn)
-qt_internal_add_example(interview)
-qt_internal_add_example(pixelator)
-qt_internal_add_example(simpletreemodel)
-qt_internal_add_example(simplewidgetmapper)
-qt_internal_add_example(spinboxdelegate)
qt_internal_add_example(spreadsheet)
qt_internal_add_example(stardelegate)
-qt_internal_add_example(storageview)
-if(QT_FEATURE_draganddrop)
- qt_internal_add_example(puzzle)
-endif()
-if(TARGET Qt6::Xml)
- qt_internal_add_example(simpledommodel)
-endif()
diff --git a/examples/widgets/itemviews/addressbook/CMakeLists.txt b/examples/widgets/itemviews/addressbook/CMakeLists.txt
index 0a025047d0..91e9cd03c9 100644
--- a/examples/widgets/itemviews/addressbook/CMakeLists.txt
+++ b/examples/widgets/itemviews/addressbook/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(addressbook LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/addressbook")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -35,7 +29,14 @@ target_link_libraries(addressbook PRIVATE
)
install(TARGETS addressbook
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET addressbook
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp
index bde1cdc334..5b226793e4 100644
--- a/examples/widgets/itemviews/addressbook/addresswidget.cpp
+++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp
@@ -34,7 +34,10 @@ void AddressWidget::showAddEntryDialog()
//! [3]
void AddressWidget::addEntry(const QString &name, const QString &address)
{
- if (!table->getContacts().contains({ name, address })) {
+ if (!name.front().isLetter()) {
+ QMessageBox::information(this, tr("Invalid name"),
+ tr("The name must start with a letter."));
+ } else if (!table->getContacts().contains({ name, address })) {
table->insertRows(0, 1, QModelIndex());
QModelIndex index = table->index(0, 0, QModelIndex());
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/CMakeLists.txt b/examples/widgets/itemviews/basicsortfiltermodel/CMakeLists.txt
index 2b23188812..da15c4c196 100644
--- a/examples/widgets/itemviews/basicsortfiltermodel/CMakeLists.txt
+++ b/examples/widgets/itemviews/basicsortfiltermodel/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(basicsortfiltermodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/basicsortfiltermodel")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(basicsortfiltermodel PRIVATE
)
install(TARGETS basicsortfiltermodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET basicsortfiltermodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/chart/CMakeLists.txt b/examples/widgets/itemviews/chart/CMakeLists.txt
deleted file mode 100644
index 78e1fc7c7a..0000000000
--- a/examples/widgets/itemviews/chart/CMakeLists.txt
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(chart LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/chart")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(chart
- main.cpp
- mainwindow.cpp mainwindow.h
- pieview.cpp pieview.h
-)
-
-set_target_properties(chart PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(chart PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(chart_resource_files
- "qtdata.cht"
-)
-
-qt_add_resources(chart "chart"
- PREFIX
- "/Charts"
- FILES
- ${chart_resource_files}
-)
-
-if(UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY AND NOT VXWORKS)
- target_link_libraries(chart PRIVATE
- m
- )
-endif()
-
-install(TARGETS chart
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/chart/chart.pro b/examples/widgets/itemviews/chart/chart.pro
deleted file mode 100644
index 323f6202e4..0000000000
--- a/examples/widgets/itemviews/chart/chart.pro
+++ /dev/null
@@ -1,14 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-
-HEADERS = mainwindow.h \
- pieview.h
-RESOURCES = chart.qrc
-SOURCES = main.cpp \
- mainwindow.cpp \
- pieview.cpp
-unix:!mac:!vxworks:!integrity:!haiku:LIBS += -lm
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/chart
-INSTALLS += target
diff --git a/examples/widgets/itemviews/chart/chart.qrc b/examples/widgets/itemviews/chart/chart.qrc
deleted file mode 100644
index 7401d4d2f8..0000000000
--- a/examples/widgets/itemviews/chart/chart.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/Charts" >
- <file>qtdata.cht</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/itemviews/chart/main.cpp b/examples/widgets/itemviews/chart/main.cpp
deleted file mode 100644
index 14c3348099..0000000000
--- a/examples/widgets/itemviews/chart/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(chart);
-
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/chart/mainwindow.cpp b/examples/widgets/itemviews/chart/mainwindow.cpp
deleted file mode 100644
index 450f2e3a56..0000000000
--- a/examples/widgets/itemviews/chart/mainwindow.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "pieview.h"
-#include "mainwindow.h"
-
-#include <QtWidgets>
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
-{
- QMenu *fileMenu = new QMenu(tr("&File"), this);
- QAction *openAction = fileMenu->addAction(tr("&Open..."));
- openAction->setShortcuts(QKeySequence::Open);
- QAction *saveAction = fileMenu->addAction(tr("&Save As..."));
- saveAction->setShortcuts(QKeySequence::SaveAs);
- QAction *quitAction = fileMenu->addAction(tr("E&xit"));
- quitAction->setShortcuts(QKeySequence::Quit);
-
- setupModel();
- setupViews();
-
- connect(openAction, &QAction::triggered, this, &MainWindow::openFile);
- connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile);
- connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
-
- menuBar()->addMenu(fileMenu);
- statusBar();
-
- loadFile(":/Charts/qtdata.cht");
-
- setWindowTitle(tr("Chart"));
- resize(870, 550);
-}
-
-void MainWindow::setupModel()
-{
- model = new QStandardItemModel(8, 2, this);
- model->setHeaderData(0, Qt::Horizontal, tr("Label"));
- model->setHeaderData(1, Qt::Horizontal, tr("Quantity"));
-}
-
-void MainWindow::setupViews()
-{
- QSplitter *splitter = new QSplitter;
- QTableView *table = new QTableView;
- pieChart = new PieView;
- splitter->addWidget(table);
- splitter->addWidget(pieChart);
- splitter->setStretchFactor(0, 0);
- splitter->setStretchFactor(1, 1);
-
- table->setModel(model);
- pieChart->setModel(model);
-
- QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
- table->setSelectionModel(selectionModel);
- pieChart->setSelectionModel(selectionModel);
-
- QHeaderView *headerView = table->horizontalHeader();
- headerView->setStretchLastSection(true);
-
- setCentralWidget(splitter);
-}
-
-void MainWindow::openFile()
-{
- const QString fileName =
- QFileDialog::getOpenFileName(this, tr("Choose a data file"), "", "*.cht");
- if (!fileName.isEmpty())
- loadFile(fileName);
-}
-
-void MainWindow::loadFile(const QString &fileName)
-{
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly | QFile::Text))
- return;
-
- QTextStream stream(&file);
-
- model->removeRows(0, model->rowCount(QModelIndex()), QModelIndex());
-
- int row = 0;
- while (!stream.atEnd()) {
- const QString line = stream.readLine();
- if (!line.isEmpty()) {
- model->insertRows(row, 1, QModelIndex());
-
- const QStringList pieces = line.split(QLatin1Char(','), Qt::SkipEmptyParts);
- if (pieces.size() < 3)
- continue;
- model->setData(model->index(row, 0, QModelIndex()),
- pieces.value(0));
- model->setData(model->index(row, 1, QModelIndex()),
- pieces.value(1));
- model->setData(model->index(row, 0, QModelIndex()),
- QColor(pieces.value(2)), Qt::DecorationRole);
- row++;
- }
- };
-
- file.close();
- statusBar()->showMessage(tr("Loaded %1").arg(fileName), 2000);
-}
-
-void MainWindow::saveFile()
-{
- QString fileName = QFileDialog::getSaveFileName(this,
- tr("Save file as"), "", "*.cht");
-
- if (fileName.isEmpty())
- return;
-
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text))
- return;
-
- QTextStream stream(&file);
- for (int row = 0; row < model->rowCount(QModelIndex()); ++row) {
-
- QStringList pieces;
-
- pieces.append(model->data(model->index(row, 0, QModelIndex()),
- Qt::DisplayRole).toString());
- pieces.append(model->data(model->index(row, 1, QModelIndex()),
- Qt::DisplayRole).toString());
- pieces.append(model->data(model->index(row, 0, QModelIndex()),
- Qt::DecorationRole).toString());
-
- stream << pieces.join(',') << "\n";
- }
-
- file.close();
- statusBar()->showMessage(tr("Saved %1").arg(fileName), 2000);
-}
diff --git a/examples/widgets/itemviews/chart/mainwindow.h b/examples/widgets/itemviews/chart/mainwindow.h
deleted file mode 100644
index f2a639c952..0000000000
--- a/examples/widgets/itemviews/chart/mainwindow.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QAbstractItemModel;
-class QAbstractItemView;
-QT_END_NAMESPACE
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow(QWidget *parent = nullptr);
-
-private slots:
- void openFile();
- void saveFile();
-
-private:
- void setupModel();
- void setupViews();
- void loadFile(const QString &path);
-
- QAbstractItemModel *model = nullptr;
- QAbstractItemView *pieChart = nullptr;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp
deleted file mode 100644
index e681207f38..0000000000
--- a/examples/widgets/itemviews/chart/pieview.cpp
+++ /dev/null
@@ -1,506 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "pieview.h"
-
-#include <QtWidgets>
-
-PieView::PieView(QWidget *parent)
- : QAbstractItemView(parent)
-{
- horizontalScrollBar()->setRange(0, 0);
- verticalScrollBar()->setRange(0, 0);
-}
-
-void PieView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
- const QList<int> &roles)
-{
- QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
-
- if (!roles.contains(Qt::DisplayRole))
- return;
-
- validItems = 0;
- totalValue = 0.0;
-
- for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
-
- QModelIndex index = model()->index(row, 1, rootIndex());
- double value = model()->data(index, Qt::DisplayRole).toDouble();
-
- if (value > 0.0) {
- totalValue += value;
- validItems++;
- }
- }
- viewport()->update();
-}
-
-bool PieView::edit(const QModelIndex &index, EditTrigger trigger, QEvent *event)
-{
- if (index.column() == 0)
- return QAbstractItemView::edit(index, trigger, event);
- else
- return false;
-}
-
-/*
- Returns the item that covers the coordinate given in the view.
-*/
-
-QModelIndex PieView::indexAt(const QPoint &point) const
-{
- if (validItems == 0)
- return QModelIndex();
-
- // Transform the view coordinates into contents widget coordinates.
- int wx = point.x() + horizontalScrollBar()->value();
- int wy = point.y() + verticalScrollBar()->value();
-
- if (wx < totalSize) {
- double cx = wx - totalSize / 2;
- double cy = totalSize / 2 - wy; // positive cy for items above the center
-
- // Determine the distance from the center point of the pie chart.
- double d = std::sqrt(std::pow(cx, 2) + std::pow(cy, 2));
-
- if (d == 0 || d > pieSize / 2)
- return QModelIndex();
-
- // Determine the angle of the point.
- double angle = qRadiansToDegrees(std::atan2(cy, cx));
- if (angle < 0)
- angle = 360 + angle;
-
- // Find the relevant slice of the pie.
- double startAngle = 0.0;
-
- for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
-
- QModelIndex index = model()->index(row, 1, rootIndex());
- double value = model()->data(index).toDouble();
-
- if (value > 0.0) {
- double sliceAngle = 360 * value / totalValue;
-
- if (angle >= startAngle && angle < (startAngle + sliceAngle))
- return model()->index(row, 1, rootIndex());
-
- startAngle += sliceAngle;
- }
- }
- } else {
- QStyleOptionViewItem option;
- initViewItemOption(&option);
- double itemHeight = QFontMetrics(option.font).height();
- int listItem = int((wy - margin) / itemHeight);
- int validRow = 0;
-
- for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
-
- QModelIndex index = model()->index(row, 1, rootIndex());
- if (model()->data(index).toDouble() > 0.0) {
-
- if (listItem == validRow)
- return model()->index(row, 0, rootIndex());
-
- // Update the list index that corresponds to the next valid row.
- ++validRow;
- }
- }
- }
-
- return QModelIndex();
-}
-
-bool PieView::isIndexHidden(const QModelIndex & /*index*/) const
-{
- return false;
-}
-
-/*
- Returns the rectangle of the item at position \a index in the
- model. The rectangle is in contents coordinates.
-*/
-
-QRect PieView::itemRect(const QModelIndex &index) const
-{
- if (!index.isValid())
- return QRect();
-
- // Check whether the index's row is in the list of rows represented
- // by slices.
- QModelIndex valueIndex;
-
- if (index.column() != 1)
- valueIndex = model()->index(index.row(), 1, rootIndex());
- else
- valueIndex = index;
-
- if (model()->data(valueIndex).toDouble() <= 0.0)
- return QRect();
-
- int listItem = 0;
- for (int row = index.row()-1; row >= 0; --row) {
- if (model()->data(model()->index(row, 1, rootIndex())).toDouble() > 0.0)
- listItem++;
- }
-
- switch (index.column()) {
- case 0: {
- QStyleOptionViewItem option;
- initViewItemOption(&option);
- const qreal itemHeight = QFontMetricsF(option.font).height();
- return QRect(totalSize,
- qRound(margin + listItem * itemHeight),
- totalSize - margin, qRound(itemHeight));
- }
- case 1:
- return viewport()->rect();
- }
- return QRect();
-}
-
-QRegion PieView::itemRegion(const QModelIndex &index) const
-{
- if (!index.isValid())
- return QRegion();
-
- if (index.column() != 1)
- return itemRect(index);
-
- if (model()->data(index).toDouble() <= 0.0)
- return QRegion();
-
- double startAngle = 0.0;
- for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
-
- QModelIndex sliceIndex = model()->index(row, 1, rootIndex());
- double value = model()->data(sliceIndex).toDouble();
-
- if (value > 0.0) {
- double angle = 360 * value / totalValue;
-
- if (sliceIndex == index) {
- QPainterPath slicePath;
- slicePath.moveTo(totalSize / 2, totalSize / 2);
- slicePath.arcTo(margin, margin, margin + pieSize, margin + pieSize,
- startAngle, angle);
- slicePath.closeSubpath();
-
- return QRegion(slicePath.toFillPolygon().toPolygon());
- }
-
- startAngle += angle;
- }
- }
-
- return QRegion();
-}
-
-int PieView::horizontalOffset() const
-{
- return horizontalScrollBar()->value();
-}
-
-void PieView::mousePressEvent(QMouseEvent *event)
-{
- QAbstractItemView::mousePressEvent(event);
- origin = event->position().toPoint();
- if (!rubberBand)
- rubberBand = new QRubberBand(QRubberBand::Rectangle, viewport());
- rubberBand->setGeometry(QRect(origin, QSize()));
- rubberBand->show();
-}
-
-void PieView::mouseMoveEvent(QMouseEvent *event)
-{
- if (rubberBand)
- rubberBand->setGeometry(QRect(origin, event->position().toPoint()).normalized());
- QAbstractItemView::mouseMoveEvent(event);
-}
-
-void PieView::mouseReleaseEvent(QMouseEvent *event)
-{
- QAbstractItemView::mouseReleaseEvent(event);
- if (rubberBand)
- rubberBand->hide();
- viewport()->update();
-}
-
-QModelIndex PieView::moveCursor(QAbstractItemView::CursorAction cursorAction,
- Qt::KeyboardModifiers /*modifiers*/)
-{
- QModelIndex current = currentIndex();
-
- switch (cursorAction) {
- case MoveLeft:
- case MoveUp:
- if (current.row() > 0)
- current = model()->index(current.row() - 1, current.column(),
- rootIndex());
- else
- current = model()->index(0, current.column(), rootIndex());
- break;
- case MoveRight:
- case MoveDown:
- if (current.row() < rows(current) - 1)
- current = model()->index(current.row() + 1, current.column(),
- rootIndex());
- else
- current = model()->index(rows(current) - 1, current.column(),
- rootIndex());
- break;
- default:
- break;
- }
-
- viewport()->update();
- return current;
-}
-
-void PieView::paintEvent(QPaintEvent *event)
-{
- QItemSelectionModel *selections = selectionModel();
- QStyleOptionViewItem option;
- initViewItemOption(&option);
-
- QBrush background = option.palette.base();
- QPen foreground(option.palette.color(QPalette::WindowText));
-
- QPainter painter(viewport());
- painter.setRenderHint(QPainter::Antialiasing);
-
- painter.fillRect(event->rect(), background);
- painter.setPen(foreground);
-
- // Viewport rectangles
- QRect pieRect = QRect(margin, margin, pieSize, pieSize);
-
- if (validItems <= 0)
- return;
-
- painter.save();
- painter.translate(pieRect.x() - horizontalScrollBar()->value(),
- pieRect.y() - verticalScrollBar()->value());
- painter.drawEllipse(0, 0, pieSize, pieSize);
- double startAngle = 0.0;
- int row;
-
- for (row = 0; row < model()->rowCount(rootIndex()); ++row) {
- QModelIndex index = model()->index(row, 1, rootIndex());
- double value = model()->data(index).toDouble();
-
- if (value > 0.0) {
- double angle = 360 * value / totalValue;
-
- QModelIndex colorIndex = model()->index(row, 0, rootIndex());
- QColor color = QColor(model()->data(colorIndex, Qt::DecorationRole).toString());
-
- if (currentIndex() == index)
- painter.setBrush(QBrush(color, Qt::Dense4Pattern));
- else if (selections->isSelected(index))
- painter.setBrush(QBrush(color, Qt::Dense3Pattern));
- else
- painter.setBrush(QBrush(color));
-
- painter.drawPie(0, 0, pieSize, pieSize, int(startAngle*16), int(angle*16));
-
- startAngle += angle;
- }
- }
- painter.restore();
-
- for (row = 0; row < model()->rowCount(rootIndex()); ++row) {
- QModelIndex index = model()->index(row, 1, rootIndex());
- double value = model()->data(index).toDouble();
-
- if (value > 0.0) {
- QModelIndex labelIndex = model()->index(row, 0, rootIndex());
-
- QStyleOptionViewItem option;
- initViewItemOption(&option);
-
- option.rect = visualRect(labelIndex);
- if (selections->isSelected(labelIndex))
- option.state |= QStyle::State_Selected;
- if (currentIndex() == labelIndex)
- option.state |= QStyle::State_HasFocus;
- itemDelegate()->paint(&painter, option, labelIndex);
- }
- }
-}
-
-void PieView::resizeEvent(QResizeEvent * /* event */)
-{
- updateGeometries();
-}
-
-int PieView::rows(const QModelIndex &index) const
-{
- return model()->rowCount(model()->parent(index));
-}
-
-void PieView::rowsInserted(const QModelIndex &parent, int start, int end)
-{
- for (int row = start; row <= end; ++row) {
- QModelIndex index = model()->index(row, 1, rootIndex());
- double value = model()->data(index).toDouble();
-
- if (value > 0.0) {
- totalValue += value;
- ++validItems;
- }
- }
-
- QAbstractItemView::rowsInserted(parent, start, end);
-}
-
-void PieView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
-{
- for (int row = start; row <= end; ++row) {
- QModelIndex index = model()->index(row, 1, rootIndex());
- double value = model()->data(index).toDouble();
- if (value > 0.0) {
- totalValue -= value;
- --validItems;
- }
- }
-
- QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);
-}
-
-void PieView::scrollContentsBy(int dx, int dy)
-{
- viewport()->scroll(dx, dy);
-}
-
-void PieView::scrollTo(const QModelIndex &index, ScrollHint)
-{
- QRect area = viewport()->rect();
- QRect rect = visualRect(index);
-
- if (rect.left() < area.left()) {
- horizontalScrollBar()->setValue(
- horizontalScrollBar()->value() + rect.left() - area.left());
- } else if (rect.right() > area.right()) {
- horizontalScrollBar()->setValue(
- horizontalScrollBar()->value() + qMin(
- rect.right() - area.right(), rect.left() - area.left()));
- }
-
- if (rect.top() < area.top()) {
- verticalScrollBar()->setValue(
- verticalScrollBar()->value() + rect.top() - area.top());
- } else if (rect.bottom() > area.bottom()) {
- verticalScrollBar()->setValue(
- verticalScrollBar()->value() + qMin(
- rect.bottom() - area.bottom(), rect.top() - area.top()));
- }
-
- update();
-}
-
-/*
- Find the indices corresponding to the extent of the selection.
-*/
-
-void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
-{
- // Use content widget coordinates because we will use the itemRegion()
- // function to check for intersections.
-
- QRect contentsRect = rect.translated(
- horizontalScrollBar()->value(),
- verticalScrollBar()->value()).normalized();
-
- int rows = model()->rowCount(rootIndex());
- int columns = model()->columnCount(rootIndex());
- QModelIndexList indexes;
-
- for (int row = 0; row < rows; ++row) {
- for (int column = 0; column < columns; ++column) {
- QModelIndex index = model()->index(row, column, rootIndex());
- QRegion region = itemRegion(index);
- if (region.intersects(contentsRect))
- indexes.append(index);
- }
- }
-
- if (indexes.size() > 0) {
- int firstRow = indexes.at(0).row();
- int lastRow = firstRow;
- int firstColumn = indexes.at(0).column();
- int lastColumn = firstColumn;
-
- for (int i = 1; i < indexes.size(); ++i) {
- firstRow = qMin(firstRow, indexes.at(i).row());
- lastRow = qMax(lastRow, indexes.at(i).row());
- firstColumn = qMin(firstColumn, indexes.at(i).column());
- lastColumn = qMax(lastColumn, indexes.at(i).column());
- }
-
- QItemSelection selection(
- model()->index(firstRow, firstColumn, rootIndex()),
- model()->index(lastRow, lastColumn, rootIndex()));
- selectionModel()->select(selection, command);
- } else {
- QModelIndex noIndex;
- QItemSelection selection(noIndex, noIndex);
- selectionModel()->select(selection, command);
- }
-
- update();
-}
-
-void PieView::updateGeometries()
-{
- horizontalScrollBar()->setPageStep(viewport()->width());
- horizontalScrollBar()->setRange(0, qMax(0, 2 * totalSize - viewport()->width()));
- verticalScrollBar()->setPageStep(viewport()->height());
- verticalScrollBar()->setRange(0, qMax(0, totalSize - viewport()->height()));
-}
-
-int PieView::verticalOffset() const
-{
- return verticalScrollBar()->value();
-}
-
-/*
- Returns the position of the item in viewport coordinates.
-*/
-
-QRect PieView::visualRect(const QModelIndex &index) const
-{
- QRect rect = itemRect(index);
- if (!rect.isValid())
- return rect;
-
- return QRect(rect.left() - horizontalScrollBar()->value(),
- rect.top() - verticalScrollBar()->value(),
- rect.width(), rect.height());
-}
-
-/*
- Returns a region corresponding to the selection in viewport coordinates.
-*/
-
-QRegion PieView::visualRegionForSelection(const QItemSelection &selection) const
-{
- int ranges = selection.count();
-
- if (ranges == 0)
- return QRect();
-
- QRegion region;
- for (int i = 0; i < ranges; ++i) {
- const QItemSelectionRange &range = selection.at(i);
- for (int row = range.top(); row <= range.bottom(); ++row) {
- for (int col = range.left(); col <= range.right(); ++col) {
- QModelIndex index = model()->index(row, col, rootIndex());
- region += visualRect(index);
- }
- }
- }
- return region;
-}
diff --git a/examples/widgets/itemviews/chart/pieview.h b/examples/widgets/itemviews/chart/pieview.h
deleted file mode 100644
index 19c4a18ed0..0000000000
--- a/examples/widgets/itemviews/chart/pieview.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PIEVIEW_H
-#define PIEVIEW_H
-
-#include <QAbstractItemView>
-
-//! [0]
-class PieView : public QAbstractItemView
-{
- Q_OBJECT
-
-public:
- PieView(QWidget *parent = nullptr);
-
- QRect visualRect(const QModelIndex &index) const override;
- void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
- QModelIndex indexAt(const QPoint &point) const override;
-
-protected slots:
- void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
- const QList<int> &roles = QList<int>()) override;
- void rowsInserted(const QModelIndex &parent, int start, int end) override;
- void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
-
-protected:
- bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) override;
- QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction,
- Qt::KeyboardModifiers modifiers) override;
-
- int horizontalOffset() const override;
- int verticalOffset() const override;
-
- bool isIndexHidden(const QModelIndex &index) const override;
-
- void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command) override;
-
- void mousePressEvent(QMouseEvent *event) override;
-
- void mouseMoveEvent(QMouseEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
-
- void paintEvent(QPaintEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
- void scrollContentsBy(int dx, int dy) override;
-
- QRegion visualRegionForSelection(const QItemSelection &selection) const override;
-
-private:
- QRect itemRect(const QModelIndex &item) const;
- QRegion itemRegion(const QModelIndex &index) const;
- int rows(const QModelIndex &index = QModelIndex()) const;
- void updateGeometries() override;
-
- int margin = 0;
- int totalSize = 300;
- int pieSize = totalSize - 2 * margin;
- int validItems = 0;
- double totalValue = 0.0;
- QRubberBand *rubberBand = nullptr;
- QPoint origin;
-};
-//! [0]
-
-#endif // PIEVIEW_H
diff --git a/examples/widgets/itemviews/chart/qtdata.cht b/examples/widgets/itemviews/chart/qtdata.cht
deleted file mode 100644
index 6386246c4b..0000000000
--- a/examples/widgets/itemviews/chart/qtdata.cht
+++ /dev/null
@@ -1,14 +0,0 @@
-Scientific Research,21,#99e600
-Engineering & Design,18,#99cc00
-Automotive,14,#99b300
-Aerospace,13,#9f991a
-Automation & Machine Tools,13,#a48033
-Medical & Bioinformatics,13,#a9664d
-Imaging & Special Effects,12,#ae4d66
-Defense,11,#b33380
-Test & Measurement Systems,9,#a64086
-Oil & Gas,9,#994d8d
-Entertainment & Broadcasting,7,#8d5a93
-Financial,6,#806699
-Consumer Electronics,4,#8073a6
-Other,38,#8080b3
diff --git a/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt b/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt
deleted file mode 100644
index 883ae64888..0000000000
--- a/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(coloreditorfactory LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/coloreditorfactory")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(coloreditorfactory
- colorlisteditor.cpp colorlisteditor.h
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(coloreditorfactory PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(coloreditorfactory PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS coloreditorfactory
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro
deleted file mode 100644
index 2d16ab5e2b..0000000000
--- a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = colorlisteditor.h \
- window.h
-SOURCES = colorlisteditor.cpp \
- window.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/coloreditorfactory
-INSTALLS += target
diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp
deleted file mode 100644
index 44ce168c93..0000000000
--- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "colorlisteditor.h"
-
-#include <QtWidgets>
-
-ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget)
-{
- populateList();
-}
-
-//! [0]
-QColor ColorListEditor::color() const
-{
- return qvariant_cast<QColor>(itemData(currentIndex(), Qt::DecorationRole));
-}
-//! [0]
-
-//! [1]
-void ColorListEditor::setColor(const QColor &color)
-{
- setCurrentIndex(findData(color, Qt::DecorationRole));
-}
-//! [1]
-
-//! [2]
-void ColorListEditor::populateList()
-{
- const QStringList colorNames = QColor::colorNames();
-
- for (int i = 0; i < colorNames.size(); ++i) {
- QColor color(colorNames[i]);
-
- insertItem(i, colorNames[i]);
- setItemData(i, color, Qt::DecorationRole);
- }
-}
-//! [2]
diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h
deleted file mode 100644
index 8dfa9d9f05..0000000000
--- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef COLORLISTEDITOR_H
-#define COLORLISTEDITOR_H
-
-#include <QComboBox>
-
-QT_BEGIN_NAMESPACE
-class QColor;
-class QWidget;
-QT_END_NAMESPACE
-
-//! [0]
-class ColorListEditor : public QComboBox
-{
- Q_OBJECT
- Q_PROPERTY(QColor color READ color WRITE setColor USER true)
-
-public:
- ColorListEditor(QWidget *widget = nullptr);
-
-public:
- QColor color() const;
- void setColor(const QColor &color);
-
-private:
- void populateList();
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/itemviews/coloreditorfactory/main.cpp b/examples/widgets/itemviews/coloreditorfactory/main.cpp
deleted file mode 100644
index c4339e22c1..0000000000
--- a/examples/widgets/itemviews/coloreditorfactory/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-
-#include "window.h"
-
-int main(int argv, char **args)
-{
- QApplication app(argv, args);
-
- Window window;
- window.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp
deleted file mode 100644
index 31c8c1ae13..0000000000
--- a/examples/widgets/itemviews/coloreditorfactory/window.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-#include "colorlisteditor.h"
-
-#include <QtWidgets>
-
-//! [0]
-Window::Window()
-{
- QItemEditorFactory *factory = new QItemEditorFactory;
-
- QItemEditorCreatorBase *colorListCreator =
- new QStandardItemEditorCreator<ColorListEditor>();
-
- factory->registerEditor(QMetaType::QColor, colorListCreator);
-
- QItemEditorFactory::setDefaultFactory(factory);
-
- createGUI();
-}
-//! [0]
-
-void Window::createGUI()
-{
- const QList<QPair<QString, QColor>> list = { { tr("Alice"), QColor("aliceblue") },
- { tr("Neptun"), QColor("aquamarine") },
- { tr("Ferdinand"), QColor("springgreen") } };
-
- QTableWidget *table = new QTableWidget(3, 2);
- table->setHorizontalHeaderLabels({ tr("Name"), tr("Hair Color") });
- table->verticalHeader()->setVisible(false);
- table->resize(150, 50);
-
- for (int i = 0; i < 3; ++i) {
- const QPair<QString, QColor> &pair = list.at(i);
-
- QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first);
- QTableWidgetItem *colorItem = new QTableWidgetItem;
- colorItem->setData(Qt::DisplayRole, pair.second);
-
- table->setItem(i, 0, nameItem);
- table->setItem(i, 1, colorItem);
- }
- table->resizeColumnToContents(0);
- table->horizontalHeader()->setStretchLastSection(true);
-
- QGridLayout *layout = new QGridLayout;
- layout->addWidget(table, 0, 0);
-
- setLayout(layout);
-
- setWindowTitle(tr("Color Editor Factory"));
-}
diff --git a/examples/widgets/itemviews/coloreditorfactory/window.h b/examples/widgets/itemviews/coloreditorfactory/window.h
deleted file mode 100644
index 4130b2d4ac..0000000000
--- a/examples/widgets/itemviews/coloreditorfactory/window.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWidget>
-
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window();
-
-private:
- void createGUI();
-};
-
-#endif
diff --git a/examples/widgets/itemviews/combowidgetmapper/CMakeLists.txt b/examples/widgets/itemviews/combowidgetmapper/CMakeLists.txt
index 9059f8657b..f95031b260 100644
--- a/examples/widgets/itemviews/combowidgetmapper/CMakeLists.txt
+++ b/examples/widgets/itemviews/combowidgetmapper/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(combowidgetmapper LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/combowidgetmapper")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(combowidgetmapper PRIVATE
)
install(TARGETS combowidgetmapper
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET combowidgetmapper
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/customsortfiltermodel/CMakeLists.txt b/examples/widgets/itemviews/customsortfiltermodel/CMakeLists.txt
index e56a239ec3..a1b2c41cf6 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/CMakeLists.txt
+++ b/examples/widgets/itemviews/customsortfiltermodel/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(customsortfiltermodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/customsortfiltermodel")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -45,7 +39,14 @@ qt_add_resources(customsortfiltermodel "customsortfiltermodel"
)
install(TARGETS customsortfiltermodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET customsortfiltermodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/dirview/CMakeLists.txt b/examples/widgets/itemviews/dirview/CMakeLists.txt
deleted file mode 100644
index 2dffda4462..0000000000
--- a/examples/widgets/itemviews/dirview/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(dirview LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/dirview")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(dirview
- main.cpp
-)
-
-set_target_properties(dirview PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(dirview PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS dirview
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/dirview/dirview.pro b/examples/widgets/itemviews/dirview/dirview.pro
deleted file mode 100644
index 981a64a7d6..0000000000
--- a/examples/widgets/itemviews/dirview/dirview.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-QT += widgets
-requires(qtConfig(treeview))
-
-SOURCES = main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/dirview
-INSTALLS += target
diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp
deleted file mode 100644
index 5db9338b67..0000000000
--- a/examples/widgets/itemviews/dirview/main.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include <QFileSystemModel>
-#include <QFileIconProvider>
-#include <QScreen>
-#include <QScroller>
-#include <QTreeView>
-#include <QCommandLineParser>
-#include <QCommandLineOption>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser parser;
- parser.setApplicationDescription("Qt Dir View Example");
- parser.addHelpOption();
- parser.addVersionOption();
- QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons");
- parser.addOption(dontUseCustomDirectoryIconsOption);
- QCommandLineOption dontWatchOption("w", "Set QFileSystemModel::DontWatch");
- parser.addOption(dontWatchOption);
- parser.addPositionalArgument("directory", "The directory to start in.");
- parser.process(app);
- const QString rootPath = parser.positionalArguments().isEmpty()
- ? QString() : parser.positionalArguments().first();
-
- QFileSystemModel model;
- QFileIconProvider iconProvider;
- model.setIconProvider(&iconProvider);
- model.setRootPath("");
- if (parser.isSet(dontUseCustomDirectoryIconsOption))
- model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons);
- if (parser.isSet(dontWatchOption))
- model.setOption(QFileSystemModel::DontWatchForChanges);
- QTreeView tree;
- tree.setModel(&model);
- if (!rootPath.isEmpty()) {
- const QModelIndex rootIndex = model.index(QDir::cleanPath(rootPath));
- if (rootIndex.isValid())
- tree.setRootIndex(rootIndex);
- }
-
- // Demonstrating look and feel features
- tree.setAnimated(false);
- tree.setIndentation(20);
- tree.setSortingEnabled(true);
- const QSize availableSize = tree.screen()->availableGeometry().size();
- tree.resize(availableSize / 2);
- tree.setColumnWidth(0, tree.width() / 3);
-
- // Make it flickable on touchscreens
- QScroller::grabGesture(&tree, QScroller::TouchGesture);
-
- tree.setWindowTitle(QObject::tr("Dir View"));
- tree.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/editabletreemodel/CMakeLists.txt b/examples/widgets/itemviews/editabletreemodel/CMakeLists.txt
index eb616b9f85..e255cdbc63 100644
--- a/examples/widgets/itemviews/editabletreemodel/CMakeLists.txt
+++ b/examples/widgets/itemviews/editabletreemodel/CMakeLists.txt
@@ -1,16 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(editabletreemodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/editabletreemodel")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets)
qt_standard_project_setup()
@@ -45,7 +39,46 @@ qt_add_resources(editabletreemodel "editabletreemodel"
)
install(TARGETS editabletreemodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
+
+qt_generate_deploy_app_script(
+ TARGET editabletreemodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
+
+#! [1]
+# Unit Test
+
+include(CTest)
+
+qt_add_executable(editabletreemodel_tester
+ test.cpp
+ treeitem.cpp treeitem.h
+ treemodel.cpp treemodel.h)
+
+target_link_libraries(editabletreemodel_tester PRIVATE
+ Qt6::Core
+ Qt6::Test
+)
+
+if(ANDROID)
+ target_link_libraries(editabletreemodel_tester PRIVATE
+ Qt6::Gui
+ )
+endif()
+
+qt_add_resources(editabletreemodel_tester "editabletreemodel_tester"
+ PREFIX
+ "/"
+ FILES
+ ${editabletreemodel_resource_files}
+)
+
+add_test(NAME editabletreemodel_tester
+ COMMAND editabletreemodel_tester)
+#! [1]
diff --git a/examples/widgets/itemviews/editabletreemodel/default.txt b/examples/widgets/itemviews/editabletreemodel/default.txt
index 2b2fb579ae..c3ea35257c 100644
--- a/examples/widgets/itemviews/editabletreemodel/default.txt
+++ b/examples/widgets/itemviews/editabletreemodel/default.txt
@@ -1,6 +1,6 @@
-Getting Started How to familiarize yourself with Qt Designer
- Launching Designer Running the Qt Designer application
- The User Interface How to interact with Qt Designer
+Getting Started How to familiarize yourself with Qt Widgets Designer
+ Launching Designer Running the Qt Widgets Designer application
+ The User Interface How to interact with Qt Widgets Designer
Designing a Component Creating a GUI for your application
Creating a Dialog How to create a dialog
@@ -16,7 +16,7 @@ Using a Component in Your Application Generating code from forms
A Dialog Without Auto-Connect How to connect widgets without a naming scheme
A Dialog With Auto-Connect Using automatic connections
-Form Editing Mode How to edit a form in Qt Designer
+Form Editing Mode How to edit a form in Qt Widgets Designer
Managing Forms Loading and saving forms
Editing a Form Basic editing techniques
The Property Editor Changing widget properties
@@ -36,5 +36,5 @@ Using Containers How to group widgets together
Toolbox Widgets QToolBox
Connection Editing Mode Connecting widgets together with signals and slots
- Connecting Objects Making connections in Qt Designer
+ Connecting Objects Making connections in Qt Widgets Designer
Editing Connections Changing existing connections
diff --git a/examples/widgets/itemviews/editabletreemodel/main.cpp b/examples/widgets/itemviews/editabletreemodel/main.cpp
index b7e7b3de1c..7ed4cf1dc4 100644
--- a/examples/widgets/itemviews/editabletreemodel/main.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/main.cpp
@@ -4,13 +4,14 @@
#include "mainwindow.h"
#include <QApplication>
+#include <QScreen>
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(editabletreemodel);
-
QApplication app(argc, argv);
MainWindow window;
+ const auto screenSize = window.screen()->availableSize();
+ window.resize({screenSize.width() / 2, screenSize.height() * 2 / 3});
window.show();
- return app.exec();
+ return QCoreApplication::exec();
}
diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
index fa7b31746a..cf88932cdb 100644
--- a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
@@ -6,6 +6,8 @@
#include <QFile>
+using namespace Qt::StringLiterals;
+
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
@@ -13,14 +15,15 @@ MainWindow::MainWindow(QWidget *parent)
const QStringList headers({tr("Title"), tr("Description")});
- QFile file(":/default.txt");
- file.open(QIODevice::ReadOnly);
- TreeModel *model = new TreeModel(headers, file.readAll(), this);
+ QFile file(":/default.txt"_L1);
+ file.open(QIODevice::ReadOnly | QIODevice::Text);
+ auto *model = new TreeModel(headers, QString::fromUtf8(file.readAll()), this);
file.close();
view->setModel(model);
for (int column = 0; column < model->columnCount(); ++column)
view->resizeColumnToContents(column);
+ view->expandAll();
connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
diff --git a/examples/widgets/itemviews/editabletreemodel/test.cpp b/examples/widgets/itemviews/editabletreemodel/test.cpp
new file mode 100644
index 0000000000..c041fe9402
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/test.cpp
@@ -0,0 +1,37 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "treemodel.h"
+
+#include <QAbstractItemModelTester>
+#include <QObject>
+#include <QTest>
+
+using namespace Qt::StringLiterals;
+
+//! [1]
+class TestEditableTreeModel : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testTreeModel();
+};
+
+void TestEditableTreeModel::testTreeModel()
+{
+ constexpr auto fileName = ":/default.txt"_L1;
+ QFile file(fileName);
+ QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text),
+ qPrintable(fileName + " cannot be opened: "_L1 + file.errorString()));
+
+ const QStringList headers{"column1"_L1, "column2"_L1};
+ TreeModel model(headers, QString::fromUtf8(file.readAll()));
+
+ QAbstractItemModelTester tester(&model);
+}
+
+QTEST_APPLESS_MAIN(TestEditableTreeModel)
+
+#include "test.moc"
+//! [1]
diff --git a/examples/widgets/itemviews/editabletreemodel/treeitem.cpp b/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
index 942ba277a3..42d911823d 100644
--- a/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
@@ -10,76 +10,74 @@
#include "treeitem.h"
//! [0]
-TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
- : itemData(data), parentItem(parent)
+TreeItem::TreeItem(QVariantList data, TreeItem *parent)
+ : itemData(std::move(data)), m_parentItem(parent)
{}
//! [0]
//! [1]
-TreeItem::~TreeItem()
+TreeItem *TreeItem::child(int number)
{
- qDeleteAll(childItems);
+ return (number >= 0 && number < childCount())
+ ? m_childItems.at(number).get() : nullptr;
}
//! [1]
//! [2]
-TreeItem *TreeItem::child(int number)
+int TreeItem::childCount() const
{
- if (number < 0 || number >= childItems.size())
- return nullptr;
- return childItems.at(number);
+ return int(m_childItems.size());
}
//! [2]
//! [3]
-int TreeItem::childCount() const
+int TreeItem::row() const
{
- return childItems.count();
+ if (!m_parentItem)
+ return 0;
+ const auto it = std::find_if(m_parentItem->m_childItems.cbegin(), m_parentItem->m_childItems.cend(),
+ [this](const std::unique_ptr<TreeItem> &treeItem) {
+ return treeItem.get() == this;
+ });
+
+ if (it != m_parentItem->m_childItems.cend())
+ return std::distance(m_parentItem->m_childItems.cbegin(), it);
+ Q_ASSERT(false); // should not happen
+ return -1;
}
//! [3]
//! [4]
-int TreeItem::childNumber() const
+int TreeItem::columnCount() const
{
- if (parentItem)
- return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
- return 0;
+ return int(itemData.count());
}
//! [4]
//! [5]
-int TreeItem::columnCount() const
+QVariant TreeItem::data(int column) const
{
- return itemData.count();
+ return itemData.value(column);
}
//! [5]
//! [6]
-QVariant TreeItem::data(int column) const
-{
- if (column < 0 || column >= itemData.size())
- return QVariant();
- return itemData.at(column);
-}
-//! [6]
-
-//! [7]
bool TreeItem::insertChildren(int position, int count, int columns)
{
- if (position < 0 || position > childItems.size())
+ if (position < 0 || position > qsizetype(m_childItems.size()))
return false;
for (int row = 0; row < count; ++row) {
- QList<QVariant> data(columns);
- TreeItem *item = new TreeItem(data, this);
- childItems.insert(position, item);
+ QVariantList data(columns);
+ m_childItems.insert(m_childItems.cbegin() + position,
+ std::make_unique<TreeItem>(data, this));
}
return true;
}
-//! [7]
+//! [6]
-//! [8]
+//! [7]
bool TreeItem::insertColumns(int position, int columns)
{
if (position < 0 || position > itemData.size())
@@ -88,32 +86,32 @@ bool TreeItem::insertColumns(int position, int columns)
for (int column = 0; column < columns; ++column)
itemData.insert(position, QVariant());
- for (TreeItem *child : std::as_const(childItems))
+ for (auto &child : std::as_const(m_childItems))
child->insertColumns(position, columns);
return true;
}
-//! [8]
+//! [7]
-//! [9]
+//! [8]
TreeItem *TreeItem::parent()
{
- return parentItem;
+ return m_parentItem;
}
-//! [9]
+//! [8]
-//! [10]
+//! [9]
bool TreeItem::removeChildren(int position, int count)
{
- if (position < 0 || position + count > childItems.size())
+ if (position < 0 || position + count > qsizetype(m_childItems.size()))
return false;
for (int row = 0; row < count; ++row)
- delete childItems.takeAt(position);
+ m_childItems.erase(m_childItems.cbegin() + position);
return true;
}
-//! [10]
+//! [9]
bool TreeItem::removeColumns(int position, int columns)
{
@@ -123,13 +121,13 @@ bool TreeItem::removeColumns(int position, int columns)
for (int column = 0; column < columns; ++column)
itemData.remove(position);
- for (TreeItem *child : std::as_const(childItems))
+ for (auto &child : std::as_const(m_childItems))
child->removeColumns(position, columns);
return true;
}
-//! [11]
+//! [10]
bool TreeItem::setData(int column, const QVariant &value)
{
if (column < 0 || column >= itemData.size())
@@ -138,4 +136,4 @@ bool TreeItem::setData(int column, const QVariant &value)
itemData[column] = value;
return true;
}
-//! [11]
+//! [10]
diff --git a/examples/widgets/itemviews/editabletreemodel/treeitem.h b/examples/widgets/itemviews/editabletreemodel/treeitem.h
index cbc818c081..8910312ade 100644
--- a/examples/widgets/itemviews/editabletreemodel/treeitem.h
+++ b/examples/widgets/itemviews/editabletreemodel/treeitem.h
@@ -11,8 +11,7 @@
class TreeItem
{
public:
- explicit TreeItem(const QList<QVariant> &data, TreeItem *parent = nullptr);
- ~TreeItem();
+ explicit TreeItem(QVariantList data, TreeItem *parent = nullptr);
TreeItem *child(int number);
int childCount() const;
@@ -23,13 +22,13 @@ public:
TreeItem *parent();
bool removeChildren(int position, int count);
bool removeColumns(int position, int columns);
- int childNumber() const;
+ int row() const;
bool setData(int column, const QVariant &value);
private:
- QList<TreeItem *> childItems;
- QList<QVariant> itemData;
- TreeItem *parentItem;
+ std::vector<std::unique_ptr<TreeItem>> m_childItems;
+ QVariantList itemData;
+ TreeItem *m_parentItem;
};
//! [0]
diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
index 290ec186a8..6511b06780 100644
--- a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
@@ -4,26 +4,23 @@
#include "treemodel.h"
#include "treeitem.h"
-#include <QtWidgets>
+using namespace Qt::StringLiterals;
//! [0]
TreeModel::TreeModel(const QStringList &headers, const QString &data, QObject *parent)
: QAbstractItemModel(parent)
{
- QList<QVariant> rootData;
+ QVariantList rootData;
for (const QString &header : headers)
rootData << header;
- rootItem = new TreeItem(rootData);
- setupModelData(data.split('\n'), rootItem);
+ rootItem = std::make_unique<TreeItem>(rootData);
+ setupModelData(QStringView{data}.split(u'\n'));
}
//! [0]
//! [1]
-TreeModel::~TreeModel()
-{
- delete rootItem;
-}
+TreeModel::~TreeModel() = default;
//! [1]
//! [2]
@@ -37,10 +34,10 @@ int TreeModel::columnCount(const QModelIndex &parent) const
QVariant TreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
- return QVariant();
+ return {};
if (role != Qt::DisplayRole && role != Qt::EditRole)
- return QVariant();
+ return {};
TreeItem *item = getItem(index);
@@ -61,39 +58,35 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
TreeItem *TreeModel::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
- TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
- if (item)
+ if (auto *item = static_cast<TreeItem*>(index.internalPointer()))
return item;
}
- return rootItem;
+ return rootItem.get();
}
//! [4]
QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
- return rootItem->data(section);
-
- return QVariant();
+ return (orientation == Qt::Horizontal && role == Qt::DisplayRole)
+ ? rootItem->data(section) : QVariant{};
}
//! [5]
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
- return QModelIndex();
+ return {};
//! [5]
//! [6]
TreeItem *parentItem = getItem(parent);
if (!parentItem)
- return QModelIndex();
+ return {};
- TreeItem *childItem = parentItem->child(row);
- if (childItem)
+ if (auto *childItem = parentItem->child(row))
return createIndex(row, column, childItem);
- return QModelIndex();
+ return {};
}
//! [6]
@@ -125,15 +118,13 @@ bool TreeModel::insertRows(int position, int rows, const QModelIndex &parent)
QModelIndex TreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
- return QModelIndex();
+ return {};
TreeItem *childItem = getItem(index);
TreeItem *parentItem = childItem ? childItem->parent() : nullptr;
- if (parentItem == rootItem || !parentItem)
- return QModelIndex();
-
- return createIndex(parentItem->childNumber(), 0, parentItem);
+ return (parentItem != rootItem.get() && parentItem != nullptr)
+ ? createIndex(parentItem->row(), 0, parentItem) : QModelIndex{};
}
//! [7]
@@ -202,55 +193,46 @@ bool TreeModel::setHeaderData(int section, Qt::Orientation orientation,
return result;
}
-void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
+void TreeModel::setupModelData(const QList<QStringView> &lines)
{
- QList<TreeItem *> parents;
- QList<int> indentations;
- parents << parent;
- indentations << 0;
-
- int number = 0;
-
- while (number < lines.count()) {
- int position = 0;
- while (position < lines[number].length()) {
- if (lines[number].at(position) != ' ')
- break;
- ++position;
- }
+ struct ParentIndentation
+ {
+ TreeItem *parent;
+ qsizetype indentation;
+ };
- const QString lineData = lines[number].mid(position).trimmed();
+ QList<ParentIndentation> state{{rootItem.get(), 0}};
+ for (const auto &line : lines) {
+ qsizetype position = 0;
+ for ( ; position < line.length() && line.at(position).isSpace(); ++position) {
+ }
+
+ const QStringView lineData = line.sliced(position).trimmed();
if (!lineData.isEmpty()) {
// Read the column data from the rest of the line.
- const QStringList columnStrings =
- lineData.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
- QList<QVariant> columnData;
- columnData.reserve(columnStrings.size());
- for (const QString &columnString : columnStrings)
- columnData << columnString;
-
- if (position > indentations.last()) {
+ const auto columnStrings = lineData.split(u'\t', Qt::SkipEmptyParts);
+ QVariantList columnData;
+ columnData.reserve(columnStrings.count());
+ for (const auto &columnString : columnStrings)
+ columnData << columnString.toString();
+
+ if (position > state.constLast().indentation) {
// The last child of the current parent is now the new parent
// unless the current parent has no children.
-
- if (parents.last()->childCount() > 0) {
- parents << parents.last()->child(parents.last()->childCount()-1);
- indentations << position;
- }
+ auto *lastParent = state.constLast().parent;
+ if (lastParent->childCount() > 0)
+ state.append({lastParent->child(lastParent->childCount() - 1), position});
} else {
- while (position < indentations.last() && parents.count() > 0) {
- parents.pop_back();
- indentations.pop_back();
- }
+ while (position < state.constLast().indentation && !state.isEmpty())
+ state.removeLast();
}
// Append a new item to the current parent's list of children.
- TreeItem *parent = parents.last();
+ auto *parent = state.constLast().parent;
parent->insertChildren(parent->childCount(), 1, rootItem->columnCount());
for (int column = 0; column < columnData.size(); ++column)
- parent->child(parent->childCount() - 1)->setData(column, columnData[column]);
+ parent->child(parent->childCount() - 1)->setData(column, columnData.at(column));
}
- ++number;
}
}
diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.h b/examples/widgets/itemviews/editabletreemodel/treemodel.h
index 1482846c29..4f781c8144 100644
--- a/examples/widgets/itemviews/editabletreemodel/treemodel.h
+++ b/examples/widgets/itemviews/editabletreemodel/treemodel.h
@@ -16,9 +16,11 @@ class TreeModel : public QAbstractItemModel
Q_OBJECT
public:
+ Q_DISABLE_COPY_MOVE(TreeModel)
+
TreeModel(const QStringList &headers, const QString &data,
QObject *parent = nullptr);
- ~TreeModel();
+ ~TreeModel() override;
//! [0] //! [1]
QVariant data(const QModelIndex &index, int role) const override;
@@ -26,11 +28,11 @@ public:
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const override;
+ const QModelIndex &parent = {}) const override;
QModelIndex parent(const QModelIndex &index) const override;
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
+ int rowCount(const QModelIndex &parent = {}) const override;
+ int columnCount(const QModelIndex &parent = {}) const override;
//! [1]
//! [2]
@@ -41,19 +43,19 @@ public:
const QVariant &value, int role = Qt::EditRole) override;
bool insertColumns(int position, int columns,
- const QModelIndex &parent = QModelIndex()) override;
+ const QModelIndex &parent = {}) override;
bool removeColumns(int position, int columns,
- const QModelIndex &parent = QModelIndex()) override;
+ const QModelIndex &parent = {}) override;
bool insertRows(int position, int rows,
- const QModelIndex &parent = QModelIndex()) override;
+ const QModelIndex &parent = {}) override;
bool removeRows(int position, int rows,
- const QModelIndex &parent = QModelIndex()) override;
+ const QModelIndex &parent = {}) override;
private:
- void setupModelData(const QStringList &lines, TreeItem *parent);
+ void setupModelData(const QList<QStringView> &lines);
TreeItem *getItem(const QModelIndex &index) const;
- TreeItem *rootItem;
+ std::unique_ptr<TreeItem> rootItem;
};
//! [2]
diff --git a/examples/widgets/itemviews/fetchmore/CMakeLists.txt b/examples/widgets/itemviews/fetchmore/CMakeLists.txt
index da7c0f151b..856b0cc3ba 100644
--- a/examples/widgets/itemviews/fetchmore/CMakeLists.txt
+++ b/examples/widgets/itemviews/fetchmore/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(fetchmore LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/fetchmore")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(fetchmore PRIVATE
)
install(TARGETS fetchmore
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET fetchmore
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/flattreeview/CMakeLists.txt b/examples/widgets/itemviews/flattreeview/CMakeLists.txt
deleted file mode 100644
index 2d9871487d..0000000000
--- a/examples/widgets/itemviews/flattreeview/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(flattreeview LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/flattreeview")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(flattreeview
- main.cpp
-)
-
-set_target_properties(flattreeview PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(flattreeview PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS flattreeview
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/flattreeview/flattreeview.pro b/examples/widgets/itemviews/flattreeview/flattreeview.pro
deleted file mode 100644
index 05a6573d33..0000000000
--- a/examples/widgets/itemviews/flattreeview/flattreeview.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-QT += widgets
-
-SOURCES = main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/flattreeview
-INSTALLS += target
diff --git a/examples/widgets/itemviews/flattreeview/main.cpp b/examples/widgets/itemviews/flattreeview/main.cpp
deleted file mode 100644
index f51e24da86..0000000000
--- a/examples/widgets/itemviews/flattreeview/main.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (C) 2017 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-/*
- main.cpp
-
- A simple example that shows a multi-column list using QTreeView.
- The data is not a tree, so the first column was made movable.
-*/
-
-#include <QApplication>
-#include <QHeaderView>
-#include <QStandardItemModel>
-#include <QTreeView>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- QStandardItemModel model(4, 2);
- QTreeView treeView;
- treeView.setModel(&model);
- treeView.setRootIsDecorated(false);
- treeView.header()->setFirstSectionMovable(true);
- treeView.header()->setStretchLastSection(true);
-
- for (int row = 0; row < 4; ++row) {
- for (int column = 0; column < 2; ++column) {
- QModelIndex index = model.index(row, column, QModelIndex());
- model.setData(index, QVariant((row + 1) * (column + 1)));
- }
- }
-
- treeView.setWindowTitle(QObject::tr("Flat Tree View"));
- treeView.show();
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/frozencolumn/CMakeLists.txt b/examples/widgets/itemviews/frozencolumn/CMakeLists.txt
index bee8dd986c..4801dbffd6 100644
--- a/examples/widgets/itemviews/frozencolumn/CMakeLists.txt
+++ b/examples/widgets/itemviews/frozencolumn/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(frozencolumn LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/frozencolumn")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -43,7 +37,14 @@ qt_add_resources(frozencolumn "grades"
)
install(TARGETS frozencolumn
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET frozencolumn
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/frozencolumn/main.cpp b/examples/widgets/itemviews/frozencolumn/main.cpp
index 901db76dd8..8cc4a1d774 100644
--- a/examples/widgets/itemviews/frozencolumn/main.cpp
+++ b/examples/widgets/itemviews/frozencolumn/main.cpp
@@ -10,8 +10,6 @@
int main(int argc, char* argv[])
{
- Q_INIT_RESOURCE(grades);
-
QApplication app( argc, argv );
QStandardItemModel *model=new QStandardItemModel();
@@ -46,4 +44,3 @@ int main(int argc, char* argv[])
tableView->show();
return app.exec();
}
-
diff --git a/examples/widgets/itemviews/interview/CMakeLists.txt b/examples/widgets/itemviews/interview/CMakeLists.txt
deleted file mode 100644
index 8104b26e90..0000000000
--- a/examples/widgets/itemviews/interview/CMakeLists.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(interview LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/interview")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(interview
- main.cpp
- model.cpp model.h
-)
-
-set_target_properties(interview PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(interview PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(interview_resource_files
- "images/folder.png"
- "images/interview.png"
- "images/services.png"
-)
-
-qt_add_resources(interview "interview"
- PREFIX
- "/"
- FILES
- ${interview_resource_files}
-)
-
-install(TARGETS interview
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/interview/README b/examples/widgets/itemviews/interview/README
deleted file mode 100644
index 50894428f6..0000000000
--- a/examples/widgets/itemviews/interview/README
+++ /dev/null
@@ -1,2 +0,0 @@
-The interview example shows the same model and selection being shared
-between three different views.
diff --git a/examples/widgets/itemviews/interview/images/folder.png b/examples/widgets/itemviews/interview/images/folder.png
deleted file mode 100644
index 589fd2df59..0000000000
--- a/examples/widgets/itemviews/interview/images/folder.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/itemviews/interview/images/interview.png b/examples/widgets/itemviews/interview/images/interview.png
deleted file mode 100644
index 0c3d690258..0000000000
--- a/examples/widgets/itemviews/interview/images/interview.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/itemviews/interview/images/services.png b/examples/widgets/itemviews/interview/images/services.png
deleted file mode 100644
index 6b2ad969d4..0000000000
--- a/examples/widgets/itemviews/interview/images/services.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/itemviews/interview/interview.pro b/examples/widgets/itemviews/interview/interview.pro
deleted file mode 100644
index 6d64f23eb9..0000000000
--- a/examples/widgets/itemviews/interview/interview.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-TEMPLATE = app
-QT += widgets
-requires(qtConfig(treeview))
-
-HEADERS += model.h
-SOURCES += model.cpp main.cpp
-RESOURCES += interview.qrc
-
-build_all:!build_pass {
- CONFIG -= build_all
- CONFIG += release
-}
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/interview
-INSTALLS += target
diff --git a/examples/widgets/itemviews/interview/interview.qrc b/examples/widgets/itemviews/interview/interview.qrc
deleted file mode 100644
index b28ea34d8a..0000000000
--- a/examples/widgets/itemviews/interview/interview.qrc
+++ /dev/null
@@ -1,7 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
- <file>images/folder.png</file>
- <file>images/services.png</file>
- <file>images/interview.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/itemviews/interview/main.cpp b/examples/widgets/itemviews/interview/main.cpp
deleted file mode 100644
index 4707c9d2c8..0000000000
--- a/examples/widgets/itemviews/interview/main.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "model.h"
-
-#include <QApplication>
-#include <QHeaderView>
-#include <QListView>
-#include <QSplitter>
-#include <QTableView>
-#include <QTreeView>
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(interview);
-
- QApplication app(argc, argv);
- QSplitter page;
-
- QAbstractItemModel *data = new Model(1000, 10, &page);
- QItemSelectionModel *selections = new QItemSelectionModel(data);
-
- QTableView *table = new QTableView;
- table->setModel(data);
- table->setSelectionModel(selections);
- table->horizontalHeader()->setSectionsMovable(true);
- table->verticalHeader()->setSectionsMovable(true);
- // Set StaticContents to enable minimal repaints on resizes.
- table->viewport()->setAttribute(Qt::WA_StaticContents);
- page.addWidget(table);
-
- QTreeView *tree = new QTreeView;
- tree->setModel(data);
- tree->setSelectionModel(selections);
- tree->setUniformRowHeights(true);
- tree->header()->setStretchLastSection(false);
- tree->viewport()->setAttribute(Qt::WA_StaticContents);
- // Disable the focus rect to get minimal repaints when scrolling on Mac.
- tree->setAttribute(Qt::WA_MacShowFocusRect, false);
- page.addWidget(tree);
-
- QListView *list = new QListView;
- list->setModel(data);
- list->setSelectionModel(selections);
- list->setViewMode(QListView::IconMode);
- list->setSelectionMode(QAbstractItemView::ExtendedSelection);
- list->setAlternatingRowColors(false);
- list->viewport()->setAttribute(Qt::WA_StaticContents);
- list->setAttribute(Qt::WA_MacShowFocusRect, false);
- page.addWidget(list);
-
- page.setWindowIcon(QPixmap(":/images/interview.png"));
- page.setWindowTitle("Interview");
- page.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/interview/model.cpp b/examples/widgets/itemviews/interview/model.cpp
deleted file mode 100644
index 9050ae6cc1..0000000000
--- a/examples/widgets/itemviews/interview/model.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "model.h"
-
-#include <QPixmap>
-
-Model::Model(int rows, int columns, QObject *parent)
- : QAbstractItemModel(parent),
- services(QPixmap(":/images/services.png")),
- rc(rows),
- cc(columns),
- tree(new QList<Node>(rows, Node()))
-{
-
-}
-
-Model::~Model()
-{
- delete tree;
-}
-
-QModelIndex Model::index(int row, int column, const QModelIndex &parent) const
-{
- if (row < rc && row >= 0 && column < cc && column >= 0) {
- Node *parentNode = static_cast<Node*>(parent.internalPointer());
- Node *childNode = node(row, parentNode);
- if (childNode)
- return createIndex(row, column, childNode);
- }
- return QModelIndex();
-}
-
-QModelIndex Model::parent(const QModelIndex &child) const
-{
- if (child.isValid()) {
- Node *childNode = static_cast<Node*>(child.internalPointer());
- Node *parentNode = parent(childNode);
- if (parentNode)
- return createIndex(row(parentNode), 0, parentNode);
- }
- return QModelIndex();
-}
-
-int Model::rowCount(const QModelIndex &parent) const
-{
- return (parent.isValid() && parent.column() != 0) ? 0 : rc;
-}
-
-int Model::columnCount(const QModelIndex &parent) const
-{
- Q_UNUSED(parent);
- return cc;
-}
-
-QVariant Model::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
- if (role == Qt::DisplayRole)
- return QVariant("Item " + QString::number(index.row()) + ':' + QString::number(index.column()));
- if (role == Qt::DecorationRole) {
- if (index.column() == 0)
- return iconProvider.icon(QFileIconProvider::Folder);
- return iconProvider.icon(QFileIconProvider::File);
- }
- return QVariant();
-}
-
-QVariant Model::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if (role == Qt::DisplayRole)
- return QString::number(section);
- if (role == Qt::DecorationRole)
- return QVariant::fromValue(services);
- return QAbstractItemModel::headerData(section, orientation, role);
-}
-
-bool Model::hasChildren(const QModelIndex &parent) const
-{
- if (parent.isValid() && parent.column() != 0)
- return false;
- return rc > 0 && cc > 0;
-}
-
-Qt::ItemFlags Model::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return {};
- return Qt::ItemIsDragEnabled|QAbstractItemModel::flags(index);
-}
-
-Model::Node *Model::node(int row, Node *parent) const
-{
- if (parent && !parent->children)
- parent->children = new QList<Node>(rc, Node(parent));
- QList<Node> *v = parent ? parent->children : tree;
- return const_cast<Node*>(&(v->at(row)));
-}
-
-Model::Node *Model::parent(Node *child) const
-{
- return child ? child->parent : nullptr;
-}
-
-int Model::row(Node *node) const
-{
- const Node *first = node->parent ? &(node->parent->children->at(0)) : &(tree->at(0));
- return node - first;
-}
diff --git a/examples/widgets/itemviews/interview/model.h b/examples/widgets/itemviews/interview/model.h
deleted file mode 100644
index 87ee740792..0000000000
--- a/examples/widgets/itemviews/interview/model.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MODEL_H
-#define MODEL_H
-
-#include <QAbstractItemModel>
-#include <QFileIconProvider>
-#include <QIcon>
-#include <QList>
-
-class Model : public QAbstractItemModel
-{
- Q_OBJECT
-
-public:
- Model(int rows, int columns, QObject *parent = nullptr);
- ~Model();
-
- QModelIndex index(int row, int column, const QModelIndex &parent) const override;
- QModelIndex parent(const QModelIndex &child) const override;
-
- int rowCount(const QModelIndex &parent) const override;
- int columnCount(const QModelIndex &parent) const override;
-
- QVariant data(const QModelIndex &index, int role) const override;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
-
- bool hasChildren(const QModelIndex &parent) const override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
-
-private:
-
- struct Node
- {
- Node(Node *parent = nullptr) : parent(parent), children(nullptr) {}
- ~Node() { delete children; }
- Node *parent;
- QList<Node> *children;
- };
-
- Node *node(int row, Node *parent) const;
- Node *parent(Node *child) const;
- int row(Node *node) const;
-
- QIcon services;
- int rc;
- int cc;
- QList<Node> *tree;
- QFileIconProvider iconProvider;
-};
-
-#endif // MODEL_H
diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro
index b4a002c156..db06874ba5 100644
--- a/examples/widgets/itemviews/itemviews.pro
+++ b/examples/widgets/itemviews/itemviews.pro
@@ -1,24 +1,11 @@
TEMPLATE = subdirs
SUBDIRS = addressbook \
basicsortfiltermodel \
- chart \
- coloreditorfactory \
combowidgetmapper \
customsortfiltermodel \
- dirview \
editabletreemodel \
fetchmore \
- flattreeview \
frozencolumn \
- interview \
- pixelator \
- puzzle \
- simpledommodel \
simpletreemodel \
- simplewidgetmapper \
- spinboxdelegate \
spreadsheet \
- stardelegate \
- storageview
-!qtConfig(draganddrop): SUBDIRS -= puzzle
-!qtHaveModule(xml): SUBDIRS -= simpledommodel
+ stardelegate
diff --git a/examples/widgets/itemviews/pixelator/CMakeLists.txt b/examples/widgets/itemviews/pixelator/CMakeLists.txt
deleted file mode 100644
index 956599973e..0000000000
--- a/examples/widgets/itemviews/pixelator/CMakeLists.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(pixelator LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/pixelator")
-
-find_package(Qt6
- REQUIRED COMPONENTS Core Gui Widgets
- OPTIONAL_COMPONENTS PrintSupport
-)
-
-qt_standard_project_setup()
-
-qt_add_executable(pixelator
- imagemodel.cpp imagemodel.h
- main.cpp
- mainwindow.cpp mainwindow.h
- pixeldelegate.cpp pixeldelegate.h
-)
-
-set_target_properties(pixelator PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(pixelator PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if(TARGET Qt6::PrintSupport)
- target_link_libraries(pixelator PRIVATE Qt6::PrintSupport)
-endif()
-
-# Resources:
-set(images_resource_files
- "images/qt.png"
-)
-
-qt_add_resources(pixelator "images"
- PREFIX
- "/"
- FILES
- ${images_resource_files}
-)
-
-install(TARGETS pixelator
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/pixelator/imagemodel.cpp b/examples/widgets/itemviews/pixelator/imagemodel.cpp
deleted file mode 100644
index 6b5b866522..0000000000
--- a/examples/widgets/itemviews/pixelator/imagemodel.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "imagemodel.h"
-
-//! [0]
-ImageModel::ImageModel(QObject *parent)
- : QAbstractTableModel(parent)
-{
-}
-//! [0]
-
-//! [1]
-void ImageModel::setImage(const QImage &image)
-{
- beginResetModel();
- modelImage = image;
- endResetModel();
-}
-//! [1]
-
-//! [2]
-int ImageModel::rowCount(const QModelIndex & /* parent */) const
-{
- return modelImage.height();
-}
-
-int ImageModel::columnCount(const QModelIndex & /* parent */) const
-//! [2] //! [3]
-{
- return modelImage.width();
-}
-//! [3]
-
-//! [4]
-QVariant ImageModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid() || role != Qt::DisplayRole)
- return QVariant();
- return qGray(modelImage.pixel(index.column(), index.row()));
-}
-//! [4]
-
-//! [5]
-QVariant ImageModel::headerData(int /* section */,
- Qt::Orientation /* orientation */,
- int role) const
-{
- if (role == Qt::SizeHintRole)
- return QSize(1, 1);
- return QVariant();
-}
-//! [5]
diff --git a/examples/widgets/itemviews/pixelator/imagemodel.h b/examples/widgets/itemviews/pixelator/imagemodel.h
deleted file mode 100644
index 050ac6b790..0000000000
--- a/examples/widgets/itemviews/pixelator/imagemodel.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef IMAGEMODEL_H
-#define IMAGEMODEL_H
-
-#include <QAbstractTableModel>
-#include <QImage>
-
-//! [0]
-class ImageModel : public QAbstractTableModel
-{
- Q_OBJECT
-
-public:
- ImageModel(QObject *parent = nullptr);
-
- void setImage(const QImage &image);
-
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
-
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
-
-private:
- QImage modelImage;
-};
-//! [0]
-
-#endif // IMAGEMODEL_H
diff --git a/examples/widgets/itemviews/pixelator/images.qrc b/examples/widgets/itemviews/pixelator/images.qrc
deleted file mode 100644
index c105e13895..0000000000
--- a/examples/widgets/itemviews/pixelator/images.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/qt.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/itemviews/pixelator/images/qt.png b/examples/widgets/itemviews/pixelator/images/qt.png
deleted file mode 100644
index dd197cb59c..0000000000
--- a/examples/widgets/itemviews/pixelator/images/qt.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/itemviews/pixelator/main.cpp b/examples/widgets/itemviews/pixelator/main.cpp
deleted file mode 100644
index b5967311ab..0000000000
--- a/examples/widgets/itemviews/pixelator/main.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(images);
-
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- window.openImage(":/images/qt.png");
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp
deleted file mode 100644
index 42f0a43844..0000000000
--- a/examples/widgets/itemviews/pixelator/mainwindow.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "imagemodel.h"
-#include "pixeldelegate.h"
-
-#include <QtWidgets>
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#if QT_CONFIG(printdialog)
-#include <QPrinter>
-#include <QPrintDialog>
-#endif
-#endif
-
-//! [0]
-MainWindow::MainWindow()
-{
-//! [0]
- currentPath = QDir::homePath();
- model = new ImageModel(this);
-
- QWidget *centralWidget = new QWidget;
-
-//! [1]
- view = new QTableView;
- view->setShowGrid(false);
- view->horizontalHeader()->hide();
- view->verticalHeader()->hide();
- view->horizontalHeader()->setMinimumSectionSize(1);
- view->verticalHeader()->setMinimumSectionSize(1);
- view->setModel(model);
-//! [1]
-
-//! [2]
- PixelDelegate *delegate = new PixelDelegate(this);
- view->setItemDelegate(delegate);
-//! [2]
-
-//! [3]
- QLabel *pixelSizeLabel = new QLabel(tr("Pixel size:"));
- QSpinBox *pixelSizeSpinBox = new QSpinBox;
- pixelSizeSpinBox->setMinimum(4);
- pixelSizeSpinBox->setMaximum(32);
- pixelSizeSpinBox->setValue(12);
-//! [3]
-
- QMenu *fileMenu = new QMenu(tr("&File"), this);
- QAction *openAction = fileMenu->addAction(tr("&Open..."));
- openAction->setShortcuts(QKeySequence::Open);
-
- printAction = fileMenu->addAction(tr("&Print..."));
- printAction->setEnabled(false);
- printAction->setShortcut(QKeySequence::Print);
-
- QAction *quitAction = fileMenu->addAction(tr("E&xit"));
- quitAction->setShortcuts(QKeySequence::Quit);
-
- QMenu *helpMenu = new QMenu(tr("&Help"), this);
- QAction *aboutAction = helpMenu->addAction(tr("&About"));
-
- menuBar()->addMenu(fileMenu);
- menuBar()->addSeparator();
- menuBar()->addMenu(helpMenu);
-
- connect(openAction, &QAction::triggered, this, &MainWindow::chooseImage);
- connect(printAction, &QAction::triggered, this, &MainWindow::printImage);
- connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
- connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutBox);
-//! [4]
- connect(pixelSizeSpinBox, &QSpinBox::valueChanged,
- delegate, &PixelDelegate::setPixelSize);
- connect(pixelSizeSpinBox, &QSpinBox::valueChanged,
- this, &MainWindow::updateView);
-//! [4]
-
- QHBoxLayout *controlsLayout = new QHBoxLayout;
- controlsLayout->addWidget(pixelSizeLabel);
- controlsLayout->addWidget(pixelSizeSpinBox);
- controlsLayout->addStretch(1);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(view);
- mainLayout->addLayout(controlsLayout);
- centralWidget->setLayout(mainLayout);
-
- setCentralWidget(centralWidget);
-
- setWindowTitle(tr("Pixelator"));
- resize(640, 480);
-//! [5]
-}
-//! [5]
-
-void MainWindow::chooseImage()
-{
- QString fileName = QFileDialog::getOpenFileName(this,
- tr("Choose an image"), currentPath, "*");
-
- if (!fileName.isEmpty())
- openImage(fileName);
-}
-
-void MainWindow::openImage(const QString &fileName)
-{
- QImage image;
-
- if (image.load(fileName)) {
- model->setImage(image);
- if (!fileName.startsWith(":/")) {
- currentPath = fileName;
- setWindowTitle(tr("%1 - Pixelator").arg(currentPath));
- }
-
- printAction->setEnabled(true);
- updateView();
- }
-}
-
-void MainWindow::printImage()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- if (model->rowCount(QModelIndex())*model->columnCount(QModelIndex()) > 90000) {
- QMessageBox::StandardButton answer;
- answer = QMessageBox::question(this, tr("Large Image Size"),
- tr("The printed image may be very large. Are you sure that "
- "you want to print it?"),
- QMessageBox::Yes | QMessageBox::No);
- if (answer == QMessageBox::No)
- return;
- }
-
- QPrinter printer(QPrinter::HighResolution);
-
- QPrintDialog dlg(&printer, this);
- dlg.setWindowTitle(tr("Print Image"));
-
- if (dlg.exec() != QDialog::Accepted) {
- return;
- }
-
- QPainter painter;
- painter.begin(&printer);
-
- int rows = model->rowCount(QModelIndex());
- int columns = model->columnCount(QModelIndex());
- int sourceWidth = (columns + 1) * ItemSize;
- int sourceHeight = (rows + 1) * ItemSize;
-
- painter.save();
-
- double xscale = printer.pageRect(QPrinter::DevicePixel).width() / double(sourceWidth);
- double yscale = printer.pageRect(QPrinter::DevicePixel).height() / double(sourceHeight);
- double scale = qMin(xscale, yscale);
-
- painter.translate(printer.paperRect(QPrinter::DevicePixel).x() + printer.pageRect(QPrinter::DevicePixel).width() / 2,
- printer.paperRect(QPrinter::DevicePixel).y() + printer.pageRect(QPrinter::DevicePixel).height() / 2);
- painter.scale(scale, scale);
- painter.translate(-sourceWidth / 2, -sourceHeight / 2);
-
- QStyleOptionViewItem option;
- QModelIndex parent = QModelIndex();
-
- QProgressDialog progress(tr("Printing..."), tr("Cancel"), 0, rows, this);
- progress.setWindowModality(Qt::ApplicationModal);
- float y = ItemSize / 2;
-
- for (int row = 0; row < rows; ++row) {
- progress.setValue(row);
- qApp->processEvents();
- if (progress.wasCanceled())
- break;
-
- float x = ItemSize / 2;
-
- for (int column = 0; column < columns; ++column) {
- option.rect = QRect(int(x), int(y), ItemSize, ItemSize);
- view->itemDelegate()->paint(&painter, option,
- model->index(row, column, parent));
- x = x + ItemSize;
- }
- y = y + ItemSize;
- }
- progress.setValue(rows);
-
- painter.restore();
- painter.end();
-
- if (progress.wasCanceled()) {
- QMessageBox::information(this, tr("Printing canceled"),
- tr("The printing process was canceled."), QMessageBox::Cancel);
- }
-#else
- QMessageBox::information(this, tr("Printing canceled"),
- tr("Printing is not supported on this Qt build"), QMessageBox::Cancel);
-#endif
-}
-
-void MainWindow::showAboutBox()
-{
- QMessageBox::about(this, tr("About the Pixelator example"),
- tr("This example demonstrates how a standard view and a custom\n"
- "delegate can be used to produce a specialized representation\n"
- "of data in a simple custom model."));
-}
-
-//! [6]
-void MainWindow::updateView()
-{
- view->resizeColumnsToContents();
- view->resizeRowsToContents();
-}
-//! [6]
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.h b/examples/widgets/itemviews/pixelator/mainwindow.h
deleted file mode 100644
index 9929e2f5af..0000000000
--- a/examples/widgets/itemviews/pixelator/mainwindow.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-class ImageModel;
-QT_BEGIN_NAMESPACE
-class QAction;
-class QTableView;
-QT_END_NAMESPACE
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
- void openImage(const QString &fileName);
-
-public slots:
- void chooseImage();
- void printImage();
- void showAboutBox();
- void updateView();
-
-private:
- ImageModel *model;
- QAction *printAction;
- QString currentPath;
- QTableView *view;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/itemviews/pixelator/pixelator.pro b/examples/widgets/itemviews/pixelator/pixelator.pro
deleted file mode 100644
index 421f626e28..0000000000
--- a/examples/widgets/itemviews/pixelator/pixelator.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-QT += widgets
-requires(qtConfig(tableview))
-qtHaveModule(printsupport): QT += printsupport
-
-HEADERS = imagemodel.h \
- mainwindow.h \
- pixeldelegate.h
-SOURCES = imagemodel.cpp \
- main.cpp \
- mainwindow.cpp \
- pixeldelegate.cpp
-RESOURCES += images.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/pixelator
-INSTALLS += target
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.cpp b/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
deleted file mode 100644
index 3a104cd2c2..0000000000
--- a/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "pixeldelegate.h"
-
-#include <QPainter>
-
-//! [0]
-PixelDelegate::PixelDelegate(QObject *parent)
- : QAbstractItemDelegate(parent), pixelSize(12)
-{}
-//! [0]
-
-//! [1]
-void PixelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const
-{
-//! [2]
- if (option.state & QStyle::State_Selected)
- painter->fillRect(option.rect, option.palette.highlight());
-//! [1]
-
-//! [3]
- const int size = qMin(option.rect.width(), option.rect.height());
-//! [3] //! [4]
- const int brightness = index.model()->data(index, Qt::DisplayRole).toInt();
- const double radius = (size / 2.0) - (brightness / 255.0 * size / 2.0);
- if (qFuzzyIsNull(radius))
- return;
-//! [4]
-
-//! [5]
- painter->save();
-//! [5] //! [6]
- painter->setRenderHint(QPainter::Antialiasing, true);
-//! [6] //! [7]
- painter->setPen(Qt::NoPen);
-//! [7] //! [8]
- if (option.state & QStyle::State_Selected)
-//! [8] //! [9]
- painter->setBrush(option.palette.highlightedText());
- else
-//! [2]
- painter->setBrush(option.palette.text());
-//! [9]
-
-//! [10]
- painter->drawEllipse(QRectF(option.rect.x() + option.rect.width() / 2 - radius,
- option.rect.y() + option.rect.height() / 2 - radius,
- 2 * radius, 2 * radius));
- painter->restore();
-}
-//! [10]
-
-//! [11]
-QSize PixelDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
- const QModelIndex & /* index */) const
-{
- return QSize(pixelSize, pixelSize);
-}
-//! [11]
-
-//! [12]
-void PixelDelegate::setPixelSize(int size)
-{
- pixelSize = size;
-}
-//! [12]
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.h b/examples/widgets/itemviews/pixelator/pixeldelegate.h
deleted file mode 100644
index a4c435ce69..0000000000
--- a/examples/widgets/itemviews/pixelator/pixeldelegate.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PIXELDELEGATE_H
-#define PIXELDELEGATE_H
-
-#include <QAbstractItemDelegate>
-#include <QModelIndex>
-#include <QSize>
-
-QT_BEGIN_NAMESPACE
-class QAbstractItemModel;
-class QObject;
-class QPainter;
-QT_END_NAMESPACE
-
-static constexpr int ItemSize = 256;
-
-//! [0]
-class PixelDelegate : public QAbstractItemDelegate
-{
- Q_OBJECT
-
-public:
- PixelDelegate(QObject *parent = nullptr);
-
- void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
-
- QSize sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
-
-public slots:
- void setPixelSize(int size);
-
-private:
- int pixelSize;
-};
-//! [0]
-
-#endif // PIXELDELEGATE_H
diff --git a/examples/widgets/itemviews/puzzle/CMakeLists.txt b/examples/widgets/itemviews/puzzle/CMakeLists.txt
deleted file mode 100644
index e411e0c6e3..0000000000
--- a/examples/widgets/itemviews/puzzle/CMakeLists.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(puzzle LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/puzzle")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(itemviews_puzzle
- main.cpp
- mainwindow.cpp mainwindow.h
- piecesmodel.cpp piecesmodel.h
- puzzlewidget.cpp puzzlewidget.h
-)
-
-set_target_properties(itemviews_puzzle PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(itemviews_puzzle PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(puzzle_resource_files
- "example.jpg"
-)
-
-qt_add_resources(itemviews_puzzle "puzzle"
- PREFIX
- "/images"
- FILES
- ${puzzle_resource_files}
-)
-
-install(TARGETS itemviews_puzzle
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/puzzle/example.jpg b/examples/widgets/itemviews/puzzle/example.jpg
deleted file mode 100644
index 023203c57a..0000000000
--- a/examples/widgets/itemviews/puzzle/example.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/itemviews/puzzle/main.cpp b/examples/widgets/itemviews/puzzle/main.cpp
deleted file mode 100644
index 73fdd6513b..0000000000
--- a/examples/widgets/itemviews/puzzle/main.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-
-#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(puzzle);
-
- QApplication app(argc, argv);
- MainWindow window;
- window.loadImage(QStringLiteral(":/images/example.jpg"));
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/puzzle/mainwindow.cpp b/examples/widgets/itemviews/puzzle/mainwindow.cpp
deleted file mode 100644
index f4b221df20..0000000000
--- a/examples/widgets/itemviews/puzzle/mainwindow.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "piecesmodel.h"
-#include "puzzlewidget.h"
-
-#include <QtWidgets>
-#include <stdlib.h>
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
-{
- setupMenus();
- setupWidgets();
- model = new PiecesModel(puzzleWidget->pieceSize(), this);
- piecesList->setModel(model);
-
- setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
- setWindowTitle(tr("Puzzle"));
-}
-
-void MainWindow::openImage()
-{
- const QString directory =
- QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::homePath());
- QFileDialog dialog(this, tr("Open Image"), directory);
- dialog.setAcceptMode(QFileDialog::AcceptOpen);
- dialog.setFileMode(QFileDialog::ExistingFile);
- QStringList mimeTypeFilters;
- for (const QByteArray &mimeTypeName : QImageReader::supportedMimeTypes())
- mimeTypeFilters.append(mimeTypeName);
- mimeTypeFilters.sort();
- dialog.setMimeTypeFilters(mimeTypeFilters);
- dialog.selectMimeTypeFilter("image/jpeg");
- if (dialog.exec() == QDialog::Accepted)
- loadImage(dialog.selectedFiles().constFirst());
-}
-
-void MainWindow::loadImage(const QString &fileName)
-{
- QPixmap newImage;
- if (!newImage.load(fileName)) {
- QMessageBox::warning(this, tr("Open Image"),
- tr("The image file could not be loaded."),
- QMessageBox::Close);
- return;
- }
- puzzleImage = newImage;
- setupPuzzle();
-}
-
-void MainWindow::setCompleted()
-{
- QMessageBox::information(this, tr("Puzzle Completed"),
- tr("Congratulations! You have completed the puzzle!\n"
- "Click OK to start again."),
- QMessageBox::Ok);
-
- setupPuzzle();
-}
-
-void MainWindow::setupPuzzle()
-{
- int size = qMin(puzzleImage.width(), puzzleImage.height());
- puzzleImage = puzzleImage.copy((puzzleImage.width() - size) / 2,
- (puzzleImage.height() - size) / 2, size, size).scaled(puzzleWidget->imageSize(),
- puzzleWidget->imageSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-
- model->addPieces(puzzleImage);
- puzzleWidget->clear();
-}
-
-void MainWindow::setupMenus()
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
-
- QAction *openAction = fileMenu->addAction(tr("&Open..."), this, &MainWindow::openImage);
- openAction->setShortcuts(QKeySequence::Open);
-
- QAction *exitAction = fileMenu->addAction(tr("E&xit"), qApp, &QCoreApplication::quit);
- exitAction->setShortcuts(QKeySequence::Quit);
-
- QMenu *gameMenu = menuBar()->addMenu(tr("&Game"));
-
- gameMenu->addAction(tr("&Restart"), this, &MainWindow::setupPuzzle);
-}
-
-void MainWindow::setupWidgets()
-{
- QFrame *frame = new QFrame;
- QHBoxLayout *frameLayout = new QHBoxLayout(frame);
-
- puzzleWidget = new PuzzleWidget(400);
-
- piecesList = new QListView;
- piecesList->setDragEnabled(true);
- piecesList->setViewMode(QListView::IconMode);
- piecesList->setIconSize(QSize(puzzleWidget->pieceSize() - 20, puzzleWidget->pieceSize() - 20));
- piecesList->setGridSize(QSize(puzzleWidget->pieceSize(), puzzleWidget->pieceSize()));
- piecesList->setSpacing(10);
- piecesList->setMovement(QListView::Snap);
- piecesList->setAcceptDrops(true);
- piecesList->setDropIndicatorShown(true);
-
- PiecesModel *model = new PiecesModel(puzzleWidget->pieceSize(), this);
- piecesList->setModel(model);
-
- connect(puzzleWidget, &PuzzleWidget::puzzleCompleted,
- this, &MainWindow::setCompleted, Qt::QueuedConnection);
-
- frameLayout->addWidget(piecesList);
- frameLayout->addWidget(puzzleWidget);
- setCentralWidget(frame);
-}
diff --git a/examples/widgets/itemviews/puzzle/mainwindow.h b/examples/widgets/itemviews/puzzle/mainwindow.h
deleted file mode 100644
index 56a59b805c..0000000000
--- a/examples/widgets/itemviews/puzzle/mainwindow.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QPixmap>
-
-class PuzzleWidget;
-class PiecesModel;
-QT_BEGIN_NAMESPACE
-class QListView;
-QT_END_NAMESPACE
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- explicit MainWindow(QWidget *parent = nullptr);
-
-public slots:
- void openImage();
- void loadImage(const QString &path);
- void setupPuzzle();
-
-private slots:
- void setCompleted();
-
-private:
- void setupMenus();
- void setupWidgets();
-
- QPixmap puzzleImage;
- QListView *piecesList;
- PuzzleWidget *puzzleWidget;
- PiecesModel *model;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
deleted file mode 100644
index 8e3ccf4aa3..0000000000
--- a/examples/widgets/itemviews/puzzle/piecesmodel.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "piecesmodel.h"
-
-#include <QIcon>
-#include <QMimeData>
-#include <QRandomGenerator>
-
-PiecesModel::PiecesModel(int pieceSize, QObject *parent)
- : QAbstractListModel(parent), m_PieceSize(pieceSize)
-{
-}
-
-QVariant PiecesModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- if (role == Qt::DecorationRole)
- return QIcon(pixmaps.value(index.row()).scaled(m_PieceSize, m_PieceSize,
- Qt::KeepAspectRatio, Qt::SmoothTransformation));
- else if (role == Qt::UserRole)
- return pixmaps.value(index.row());
- else if (role == Qt::UserRole + 1)
- return locations.value(index.row());
-
- return QVariant();
-}
-
-void PiecesModel::addPiece(const QPixmap &pixmap, const QPoint &location)
-{
- int row;
- if (QRandomGenerator::global()->bounded(2) == 1)
- row = 0;
- else
- row = pixmaps.size();
-
- beginInsertRows(QModelIndex(), row, row);
- pixmaps.insert(row, pixmap);
- locations.insert(row, location);
- endInsertRows();
-}
-
-Qt::ItemFlags PiecesModel::flags(const QModelIndex &index) const
-{
- if (index.isValid())
- return (QAbstractListModel::flags(index)|Qt::ItemIsDragEnabled);
-
- return Qt::ItemIsDropEnabled;
-}
-
-bool PiecesModel::removeRows(int row, int count, const QModelIndex &parent)
-{
- if (parent.isValid())
- return false;
-
- if (row >= pixmaps.size() || row + count <= 0)
- return false;
-
- int beginRow = qMax(0, row);
- int endRow = qMin(row + count - 1, pixmaps.size() - 1);
-
- beginRemoveRows(parent, beginRow, endRow);
-
- while (beginRow <= endRow) {
- pixmaps.removeAt(beginRow);
- locations.removeAt(beginRow);
- ++beginRow;
- }
-
- endRemoveRows();
- return true;
-}
-
-QStringList PiecesModel::mimeTypes() const
-{
- QStringList types;
- types << "image/x-puzzle-piece";
- return types;
-}
-
-QMimeData *PiecesModel::mimeData(const QModelIndexList &indexes) const
-{
- QMimeData *mimeData = new QMimeData();
- QByteArray encodedData;
-
- QDataStream stream(&encodedData, QDataStream::WriteOnly);
-
- for (const QModelIndex &index : indexes) {
- if (index.isValid()) {
- QPixmap pixmap = qvariant_cast<QPixmap>(data(index, Qt::UserRole));
- QPoint location = data(index, Qt::UserRole+1).toPoint();
- stream << pixmap << location;
- }
- }
-
- mimeData->setData("image/x-puzzle-piece", encodedData);
- return mimeData;
-}
-
-bool PiecesModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent)
-{
- if (!data->hasFormat("image/x-puzzle-piece"))
- return false;
-
- if (action == Qt::IgnoreAction)
- return true;
-
- if (column > 0)
- return false;
-
- int endRow;
-
- if (!parent.isValid()) {
- if (row < 0)
- endRow = pixmaps.size();
- else
- endRow = qMin(row, pixmaps.size());
- } else {
- endRow = parent.row();
- }
-
- QByteArray encodedData = data->data("image/x-puzzle-piece");
- QDataStream stream(&encodedData, QDataStream::ReadOnly);
-
- while (!stream.atEnd()) {
- QPixmap pixmap;
- QPoint location;
- stream >> pixmap >> location;
-
- beginInsertRows(QModelIndex(), endRow, endRow);
- pixmaps.insert(endRow, pixmap);
- locations.insert(endRow, location);
- endInsertRows();
-
- ++endRow;
- }
-
- return true;
-}
-
-int PiecesModel::rowCount(const QModelIndex &parent) const
-{
- return parent.isValid() ? 0 : pixmaps.size();
-}
-
-Qt::DropActions PiecesModel::supportedDropActions() const
-{
- return Qt::CopyAction | Qt::MoveAction;
-}
-
-void PiecesModel::addPieces(const QPixmap &pixmap)
-{
- if (!pixmaps.isEmpty()) {
- beginRemoveRows(QModelIndex(), 0, pixmaps.size() - 1);
- pixmaps.clear();
- locations.clear();
- endRemoveRows();
- }
- for (int y = 0; y < 5; ++y) {
- for (int x = 0; x < 5; ++x) {
- QPixmap pieceImage = pixmap.copy(x*m_PieceSize, y*m_PieceSize, m_PieceSize, m_PieceSize);
- addPiece(pieceImage, QPoint(x, y));
- }
- }
-}
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.h b/examples/widgets/itemviews/puzzle/piecesmodel.h
deleted file mode 100644
index 878ed73a70..0000000000
--- a/examples/widgets/itemviews/puzzle/piecesmodel.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PIECESLIST_H
-#define PIECESLIST_H
-
-#include <QAbstractListModel>
-#include <QPixmap>
-#include <QPoint>
-#include <QStringList>
-#include <QList>
-
-QT_BEGIN_NAMESPACE
-class QMimeData;
-QT_END_NAMESPACE
-
-class PiecesModel : public QAbstractListModel
-{
- Q_OBJECT
-
-public:
- explicit PiecesModel(int pieceSize, QObject *parent = nullptr);
-
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
- bool removeRows(int row, int count, const QModelIndex &parent) override;
-
- bool dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent) override;
- QMimeData *mimeData(const QModelIndexList &indexes) const override;
- QStringList mimeTypes() const override;
- int rowCount(const QModelIndex &parent) const override;
- Qt::DropActions supportedDropActions() const override;
-
- void addPiece(const QPixmap &pixmap, const QPoint &location);
- void addPieces(const QPixmap &pixmap);
-
-private:
- QList<QPoint> locations;
- QList<QPixmap> pixmaps;
-
- int m_PieceSize;
-};
-
-#endif // PIECESLIST_H
diff --git a/examples/widgets/itemviews/puzzle/puzzle.pro b/examples/widgets/itemviews/puzzle/puzzle.pro
deleted file mode 100644
index dcc27aae6a..0000000000
--- a/examples/widgets/itemviews/puzzle/puzzle.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-QT += widgets
-requires(qtConfig(listview))
-
-HEADERS = mainwindow.h \
- piecesmodel.h \
- puzzlewidget.h
-RESOURCES = puzzle.qrc
-SOURCES = main.cpp \
- mainwindow.cpp \
- piecesmodel.cpp \
- puzzlewidget.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/puzzle
-INSTALLS += target
diff --git a/examples/widgets/itemviews/puzzle/puzzle.qrc b/examples/widgets/itemviews/puzzle/puzzle.qrc
deleted file mode 100644
index 4076cec026..0000000000
--- a/examples/widgets/itemviews/puzzle/puzzle.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/images">
- <file>example.jpg</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/itemviews/puzzle/puzzlewidget.cpp b/examples/widgets/itemviews/puzzle/puzzlewidget.cpp
deleted file mode 100644
index 15aa6ac94f..0000000000
--- a/examples/widgets/itemviews/puzzle/puzzlewidget.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "puzzlewidget.h"
-
-#include <QtWidgets>
-
-PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent)
- : QWidget(parent), m_ImageSize(imageSize)
-{
- setAcceptDrops(true);
- setMinimumSize(m_ImageSize, m_ImageSize);
- setMaximumSize(m_ImageSize, m_ImageSize);
-}
-
-void PuzzleWidget::clear()
-{
- pieces.clear();
- highlightedRect = QRect();
- inPlace = 0;
- update();
-}
-
-void PuzzleWidget::dragEnterEvent(QDragEnterEvent *event)
-{
- if (event->mimeData()->hasFormat("image/x-puzzle-piece"))
- event->accept();
- else
- event->ignore();
-}
-
-void PuzzleWidget::dragLeaveEvent(QDragLeaveEvent *event)
-{
- QRect updateRect = highlightedRect;
- highlightedRect = QRect();
- update(updateRect);
- event->accept();
-}
-
-void PuzzleWidget::dragMoveEvent(QDragMoveEvent *event)
-{
- QRect updateRect = highlightedRect.united(targetSquare(event->position().toPoint()));
-
- if (event->mimeData()->hasFormat("image/x-puzzle-piece")
- && findPiece(targetSquare(event->position().toPoint())) == -1) {
-
- highlightedRect = targetSquare(event->position().toPoint());
- event->setDropAction(Qt::MoveAction);
- event->accept();
- } else {
- highlightedRect = QRect();
- event->ignore();
- }
-
- update(updateRect);
-}
-
-void PuzzleWidget::dropEvent(QDropEvent *event)
-{
- if (event->mimeData()->hasFormat("image/x-puzzle-piece")
- && findPiece(targetSquare(event->position().toPoint())) == -1) {
-
- QByteArray pieceData = event->mimeData()->data("image/x-puzzle-piece");
- QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
- Piece piece;
- piece.rect = targetSquare(event->position().toPoint());
- dataStream >> piece.pixmap >> piece.location;
-
- pieces.append(piece);
-
- highlightedRect = QRect();
- update(piece.rect);
-
- event->setDropAction(Qt::MoveAction);
- event->accept();
-
- if (piece.location == piece.rect.topLeft() / pieceSize()) {
- inPlace++;
- if (inPlace == 25)
- emit puzzleCompleted();
- }
- } else {
- highlightedRect = QRect();
- event->ignore();
- }
-}
-
-int PuzzleWidget::findPiece(const QRect &pieceRect) const
-{
- for (int i = 0, size = pieces.size(); i < size; ++i) {
- if (pieces.at(i).rect == pieceRect)
- return i;
- }
- return -1;
-}
-
-void PuzzleWidget::mousePressEvent(QMouseEvent *event)
-{
- QRect square = targetSquare(event->position().toPoint());
- int found = findPiece(square);
-
- if (found == -1)
- return;
-
- Piece piece = pieces.takeAt(found);
-
- if (piece.location == square.topLeft() / pieceSize())
- inPlace--;
-
- update(square);
-
- QByteArray itemData;
- QDataStream dataStream(&itemData, QIODevice::WriteOnly);
-
- dataStream << piece.pixmap << piece.location;
-
- QMimeData *mimeData = new QMimeData;
- mimeData->setData("image/x-puzzle-piece", itemData);
-
- QDrag *drag = new QDrag(this);
- drag->setMimeData(mimeData);
- drag->setHotSpot(event->position().toPoint() - square.topLeft());
- drag->setPixmap(piece.pixmap);
-
- if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction) {
- pieces.insert(found, piece);
- update(targetSquare(event->position().toPoint()));
-
- if (piece.location == QPoint(square.x() / pieceSize(), square.y() / pieceSize()))
- inPlace++;
- }
-}
-
-void PuzzleWidget::paintEvent(QPaintEvent *event)
-{
- QPainter painter(this);
- painter.fillRect(event->rect(), Qt::white);
-
- if (highlightedRect.isValid()) {
- painter.setBrush(QColor("#ffcccc"));
- painter.setPen(Qt::NoPen);
- painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
- }
-
- for (const Piece &piece : pieces)
- painter.drawPixmap(piece.rect, piece.pixmap);
-}
-
-const QRect PuzzleWidget::targetSquare(const QPoint &position) const
-{
- QPoint topLeft = QPoint(position.x() / pieceSize(), position.y() / pieceSize()) * pieceSize();
- return QRect(topLeft, QSize(pieceSize(), pieceSize()));
-}
-
-int PuzzleWidget::pieceSize() const
-{
- return m_ImageSize / 5;
-}
-
-int PuzzleWidget::imageSize() const
-{
- return m_ImageSize;
-}
diff --git a/examples/widgets/itemviews/puzzle/puzzlewidget.h b/examples/widgets/itemviews/puzzle/puzzlewidget.h
deleted file mode 100644
index d1c00872ec..0000000000
--- a/examples/widgets/itemviews/puzzle/puzzlewidget.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PUZZLEWIDGET_H
-#define PUZZLEWIDGET_H
-
-#include <QPoint>
-#include <QPixmap>
-#include <QList>
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QDragEnterEvent;
-class QDropEvent;
-class QMouseEvent;
-QT_END_NAMESPACE
-
-class PuzzleWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit PuzzleWidget(int imageSize, QWidget *parent = nullptr);
- void clear();
-
- int pieceSize() const;
- int imageSize() const;
-
-signals:
- void puzzleCompleted();
-
-protected:
- void dragEnterEvent(QDragEnterEvent *event) override;
- void dragLeaveEvent(QDragLeaveEvent *event) override;
- void dragMoveEvent(QDragMoveEvent *event) override;
- void dropEvent(QDropEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
-
-private:
- struct Piece {
- QPixmap pixmap;
- QRect rect;
- QPoint location;
- };
-
- int findPiece(const QRect &pieceRect) const;
- const QRect targetSquare(const QPoint &position) const;
-
- QList<Piece> pieces;
- QRect highlightedRect;
- int inPlace;
- int m_ImageSize;
-};
-
-#endif // PUZZLEWIDGET_H
diff --git a/examples/widgets/itemviews/simpledommodel/CMakeLists.txt b/examples/widgets/itemviews/simpledommodel/CMakeLists.txt
deleted file mode 100644
index 0817fd1078..0000000000
--- a/examples/widgets/itemviews/simpledommodel/CMakeLists.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(simpledommodel LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/simpledommodel")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Xml)
-
-qt_standard_project_setup()
-
-qt_add_executable(simpledommodel
- domitem.cpp domitem.h
- dommodel.cpp dommodel.h
- main.cpp
- mainwindow.cpp mainwindow.h
-)
-
-set_target_properties(simpledommodel PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(simpledommodel PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
- Qt6::Xml
-)
-
-install(TARGETS simpledommodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/simpledommodel/domitem.cpp b/examples/widgets/itemviews/simpledommodel/domitem.cpp
deleted file mode 100644
index b3e197b3db..0000000000
--- a/examples/widgets/itemviews/simpledommodel/domitem.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "domitem.h"
-
-#include <QtXml>
-
-//! [0]
-DomItem::DomItem(const QDomNode &node, int row, DomItem *parent)
- : domNode(node),
-//! [0]
- // Record the item's location within its parent.
-//! [1]
- parentItem(parent),
- rowNumber(row)
-{}
-//! [1]
-
-//! [2]
-DomItem::~DomItem()
-{
- qDeleteAll(childItems);
-}
-//! [2]
-
-//! [3]
-QDomNode DomItem::node() const
-{
- return domNode;
-}
-//! [3]
-
-//! [4]
-DomItem *DomItem::parent()
-{
- return parentItem;
-}
-//! [4]
-
-//! [5]
-DomItem *DomItem::child(int i)
-{
- DomItem *childItem = childItems.value(i);
- if (childItem)
- return childItem;
-
- // if child does not yet exist, create it
- if (i >= 0 && i < domNode.childNodes().count()) {
- QDomNode childNode = domNode.childNodes().item(i);
- childItem = new DomItem(childNode, i, this);
- childItems[i] = childItem;
- }
- return childItem;
-}
-//! [5]
-
-//! [6]
-int DomItem::row() const
-{
- return rowNumber;
-}
-//! [6]
diff --git a/examples/widgets/itemviews/simpledommodel/domitem.h b/examples/widgets/itemviews/simpledommodel/domitem.h
deleted file mode 100644
index 9b02d8e88c..0000000000
--- a/examples/widgets/itemviews/simpledommodel/domitem.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef DOMITEM_H
-#define DOMITEM_H
-
-#include <QDomNode>
-#include <QHash>
-
-//! [0]
-class DomItem
-{
-public:
- DomItem(const QDomNode &node, int row, DomItem *parent = nullptr);
- ~DomItem();
- DomItem *child(int i);
- DomItem *parent();
- QDomNode node() const;
- int row() const;
-
-private:
- QDomNode domNode;
- QHash<int, DomItem *> childItems;
- DomItem *parentItem;
- int rowNumber;
-};
-//! [0]
-
-#endif // DOMITEM_H
diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.cpp b/examples/widgets/itemviews/simpledommodel/dommodel.cpp
deleted file mode 100644
index 17f05c8be3..0000000000
--- a/examples/widgets/itemviews/simpledommodel/dommodel.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "dommodel.h"
-#include "domitem.h"
-
-#include <QtXml>
-
-//! [0]
-DomModel::DomModel(const QDomDocument &document, QObject *parent)
- : QAbstractItemModel(parent),
- domDocument(document),
- rootItem(new DomItem(domDocument, 0))
-{
-}
-//! [0]
-
-//! [1]
-DomModel::~DomModel()
-{
- delete rootItem;
-}
-//! [1]
-
-//! [2]
-int DomModel::columnCount(const QModelIndex &parent) const
-{
- Q_UNUSED(parent);
- return 3;
-}
-//! [2]
-
-//! [3]
-QVariant DomModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- if (role != Qt::DisplayRole)
- return QVariant();
-
- const DomItem *item = static_cast<DomItem*>(index.internalPointer());
-
- const QDomNode node = item->node();
-//! [3] //! [4]
-
- switch (index.column()) {
- case 0:
- return node.nodeName();
- case 1:
- {
- const QDomNamedNodeMap attributeMap = node.attributes();
- QStringList attributes;
- for (int i = 0; i < attributeMap.count(); ++i) {
- QDomNode attribute = attributeMap.item(i);
- attributes << attribute.nodeName() + "=\""
- + attribute.nodeValue() + '"';
- }
- return attributes.join(' ');
- }
- case 2:
- return node.nodeValue().split('\n').join(' ');
- default:
- break;
- }
- return QVariant();
-}
-//! [4]
-
-//! [5]
-Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return Qt::NoItemFlags;
-
- return QAbstractItemModel::flags(index);
-}
-//! [5]
-
-//! [6]
-QVariant DomModel::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
- switch (section) {
- case 0:
- return tr("Name");
- case 1:
- return tr("Attributes");
- case 2:
- return tr("Value");
- default:
- break;
- }
- }
- return QVariant();
-}
-//! [6]
-
-//! [7]
-QModelIndex DomModel::index(int row, int column, const QModelIndex &parent) const
-{
- if (!hasIndex(row, column, parent))
- return QModelIndex();
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-//! [7]
-
-//! [8]
- DomItem *childItem = parentItem->child(row);
- if (childItem)
- return createIndex(row, column, childItem);
- return QModelIndex();
-}
-//! [8]
-
-//! [9]
-QModelIndex DomModel::parent(const QModelIndex &child) const
-{
- if (!child.isValid())
- return QModelIndex();
-
- DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
- DomItem *parentItem = childItem->parent();
-
- if (!parentItem || parentItem == rootItem)
- return QModelIndex();
-
- return createIndex(parentItem->row(), 0, parentItem);
-}
-//! [9]
-
-//! [10]
-int DomModel::rowCount(const QModelIndex &parent) const
-{
- if (parent.column() > 0)
- return 0;
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-
- return parentItem->node().childNodes().count();
-}
-//! [10]
diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.h b/examples/widgets/itemviews/simpledommodel/dommodel.h
deleted file mode 100644
index 109ab33e58..0000000000
--- a/examples/widgets/itemviews/simpledommodel/dommodel.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef DOMMODEL_H
-#define DOMMODEL_H
-
-#include <QAbstractItemModel>
-#include <QDomDocument>
-#include <QModelIndex>
-
-class DomItem;
-
-//! [0]
-class DomModel : public QAbstractItemModel
-{
- Q_OBJECT
-
-public:
- explicit DomModel(const QDomDocument &document, QObject *parent = nullptr);
- ~DomModel();
-
- QVariant data(const QModelIndex &index, int role) const override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const override;
- QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const override;
- QModelIndex parent(const QModelIndex &child) const override;
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
-
-private:
- QDomDocument domDocument;
- DomItem *rootItem;
-};
-//! [0]
-
-#endif // DOMMODEL_H
diff --git a/examples/widgets/itemviews/simpledommodel/main.cpp b/examples/widgets/itemviews/simpledommodel/main.cpp
deleted file mode 100644
index 2ea03356f2..0000000000
--- a/examples/widgets/itemviews/simpledommodel/main.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-
-#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.resize(640, 480);
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp
deleted file mode 100644
index ad64863fbb..0000000000
--- a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "dommodel.h"
-
-#include <QDomDocument>
-#include <QTreeView>
-#include <QMenuBar>
-#include <QFileDialog>
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent),
- model(new DomModel(QDomDocument(), this)),
- view(new QTreeView(this))
-{
- fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(tr("&Open..."), QKeySequence::Open, this, &MainWindow::openFile);
- fileMenu->addAction(tr("E&xit"), QKeySequence::Quit, this, &QWidget::close);
-
- view->setModel(model);
-
- setCentralWidget(view);
- setWindowTitle(tr("Simple DOM Model"));
-}
-
-void MainWindow::openFile()
-{
- QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"),
- xmlPath, tr("XML files (*.xml);;HTML files (*.html);;"
- "SVG files (*.svg);;User Interface files (*.ui)"));
-
- if (!filePath.isEmpty()) {
- QFile file(filePath);
- if (file.open(QIODevice::ReadOnly)) {
- QDomDocument document;
- if (document.setContent(&file)) {
- DomModel *newModel = new DomModel(document, this);
- view->setModel(newModel);
- delete model;
- model = newModel;
- xmlPath = filePath;
- }
- file.close();
- }
- }
-}
diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.h b/examples/widgets/itemviews/simpledommodel/mainwindow.h
deleted file mode 100644
index a82f3956c8..0000000000
--- a/examples/widgets/itemviews/simpledommodel/mainwindow.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QString>
-
-class DomModel;
-QT_BEGIN_NAMESPACE
-class QMenu;
-class QTreeView;
-QT_END_NAMESPACE
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow(QWidget *parent = nullptr);
-
-public slots:
- void openFile();
-
-private:
- DomModel *model;
- QMenu *fileMenu;
- QString xmlPath;
- QTreeView *view;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/itemviews/simpledommodel/simpledommodel.pro b/examples/widgets/itemviews/simpledommodel/simpledommodel.pro
deleted file mode 100644
index 3d45920e36..0000000000
--- a/examples/widgets/itemviews/simpledommodel/simpledommodel.pro
+++ /dev/null
@@ -1,14 +0,0 @@
-HEADERS = domitem.h \
- dommodel.h \
- mainwindow.h
-SOURCES = domitem.cpp \
- dommodel.cpp \
- main.cpp \
- mainwindow.cpp
-QT += xml widgets
-requires(qtConfig(filedialog))
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/simpledommodel
-INSTALLS += target
-
diff --git a/examples/widgets/itemviews/simpletreemodel/CMakeLists.txt b/examples/widgets/itemviews/simpletreemodel/CMakeLists.txt
index 519810f70f..2fd31fae43 100644
--- a/examples/widgets/itemviews/simpletreemodel/CMakeLists.txt
+++ b/examples/widgets/itemviews/simpletreemodel/CMakeLists.txt
@@ -1,16 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(simpletreemodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/simpletreemodel")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets)
qt_standard_project_setup()
@@ -44,7 +38,46 @@ qt_add_resources(simpletreemodel "simpletreemodel"
)
install(TARGETS simpletreemodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
+
+qt_generate_deploy_app_script(
+ TARGET simpletreemodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
+
+#! [1]
+# Unit Test
+
+include(CTest)
+
+qt_add_executable(simpletreemodel_tester
+ test.cpp
+ treeitem.cpp treeitem.h
+ treemodel.cpp treemodel.h)
+
+target_link_libraries(simpletreemodel_tester PRIVATE
+ Qt6::Core
+ Qt6::Test
+)
+
+if(ANDROID)
+ target_link_libraries(simpletreemodel_tester PRIVATE
+ Qt6::Gui
+ )
+endif()
+
+qt_add_resources(simpletreemodel_tester "simpletreemodel"
+ PREFIX
+ "/"
+ FILES
+ ${simpletreemodel_resource_files}
+)
+
+add_test(NAME simpletreemodel_tester
+ COMMAND simpletreemodel_tester)
+#! [1]
diff --git a/examples/widgets/itemviews/simpletreemodel/default.txt b/examples/widgets/itemviews/simpletreemodel/default.txt
index 2b2fb579ae..c3ea35257c 100644
--- a/examples/widgets/itemviews/simpletreemodel/default.txt
+++ b/examples/widgets/itemviews/simpletreemodel/default.txt
@@ -1,6 +1,6 @@
-Getting Started How to familiarize yourself with Qt Designer
- Launching Designer Running the Qt Designer application
- The User Interface How to interact with Qt Designer
+Getting Started How to familiarize yourself with Qt Widgets Designer
+ Launching Designer Running the Qt Widgets Designer application
+ The User Interface How to interact with Qt Widgets Designer
Designing a Component Creating a GUI for your application
Creating a Dialog How to create a dialog
@@ -16,7 +16,7 @@ Using a Component in Your Application Generating code from forms
A Dialog Without Auto-Connect How to connect widgets without a naming scheme
A Dialog With Auto-Connect Using automatic connections
-Form Editing Mode How to edit a form in Qt Designer
+Form Editing Mode How to edit a form in Qt Widgets Designer
Managing Forms Loading and saving forms
Editing a Form Basic editing techniques
The Property Editor Changing widget properties
@@ -36,5 +36,5 @@ Using Containers How to group widgets together
Toolbox Widgets QToolBox
Connection Editing Mode Connecting widgets together with signals and slots
- Connecting Objects Making connections in Qt Designer
+ Connecting Objects Making connections in Qt Widgets Designer
Editing Connections Changing existing connections
diff --git a/examples/widgets/itemviews/simpletreemodel/main.cpp b/examples/widgets/itemviews/simpletreemodel/main.cpp
index 10075a18e5..5800c595c8 100644
--- a/examples/widgets/itemviews/simpletreemodel/main.cpp
+++ b/examples/widgets/itemviews/simpletreemodel/main.cpp
@@ -5,22 +5,28 @@
#include <QApplication>
#include <QFile>
+#include <QScreen>
#include <QTreeView>
+using namespace Qt::StringLiterals;
+
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(simpletreemodel);
-
QApplication app(argc, argv);
- QFile file(":/default.txt");
- file.open(QIODevice::ReadOnly);
- TreeModel model(file.readAll());
+ QFile file(":/default.txt"_L1);
+ file.open(QIODevice::ReadOnly | QIODevice::Text);
+ TreeModel model(QString::fromUtf8(file.readAll()));
file.close();
QTreeView view;
view.setModel(&model);
- view.setWindowTitle(QObject::tr("Simple Tree Model"));
+ view.setWindowTitle(TreeModel::tr("Simple Tree Model"));
+ for (int c = 0; c < model.columnCount(); ++c)
+ view.resizeColumnToContents(c);
+ view.expandAll();
+ const auto screenSize = view.screen()->availableSize();
+ view.resize({screenSize.width() / 2, screenSize.height() * 2 / 3});
view.show();
- return app.exec();
+ return QCoreApplication::exec();
}
diff --git a/examples/widgets/itemviews/simpletreemodel/test.cpp b/examples/widgets/itemviews/simpletreemodel/test.cpp
new file mode 100644
index 0000000000..7e9479a396
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/test.cpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "treemodel.h"
+
+#include <QObject>
+#include <QAbstractItemModelTester>
+#include <QTest>
+
+using namespace Qt::StringLiterals;
+
+//! [1]
+class TestSimpleTreeModel : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testTreeModel();
+};
+
+void TestSimpleTreeModel::testTreeModel()
+{
+ constexpr auto fileName = ":/default.txt"_L1;
+ QFile file(fileName);
+ QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text),
+ qPrintable(fileName + " cannot be opened: "_L1 + file.errorString()));
+ TreeModel model(QString::fromUtf8(file.readAll()));
+
+ QAbstractItemModelTester tester(&model);
+}
+
+QTEST_APPLESS_MAIN(TestSimpleTreeModel)
+
+#include "test.moc"
+//! [1]
diff --git a/examples/widgets/itemviews/simpletreemodel/treeitem.cpp b/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
index 59292bbbca..67e021d622 100644
--- a/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
+++ b/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
@@ -10,70 +10,66 @@
#include "treeitem.h"
//! [0]
-TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
- : m_itemData(data), m_parentItem(parent)
+TreeItem::TreeItem(QVariantList data, TreeItem *parent)
+ : m_itemData(std::move(data)), m_parentItem(parent)
{}
//! [0]
//! [1]
-TreeItem::~TreeItem()
+void TreeItem::appendChild(std::unique_ptr<TreeItem> &&child)
{
- qDeleteAll(m_childItems);
+ m_childItems.push_back(std::move(child));
}
//! [1]
//! [2]
-void TreeItem::appendChild(TreeItem *item)
+TreeItem *TreeItem::child(int row)
{
- m_childItems.append(item);
+ return row >= 0 && row < childCount() ? m_childItems.at(row).get() : nullptr;
}
//! [2]
//! [3]
-TreeItem *TreeItem::child(int row)
+int TreeItem::childCount() const
{
- if (row < 0 || row >= m_childItems.size())
- return nullptr;
- return m_childItems.at(row);
+ return int(m_childItems.size());
}
//! [3]
//! [4]
-int TreeItem::childCount() const
+int TreeItem::columnCount() const
{
- return m_childItems.count();
+ return int(m_itemData.count());
}
//! [4]
//! [5]
-int TreeItem::columnCount() const
+QVariant TreeItem::data(int column) const
{
- return m_itemData.count();
+ return m_itemData.value(column);
}
//! [5]
//! [6]
-QVariant TreeItem::data(int column) const
-{
- if (column < 0 || column >= m_itemData.size())
- return QVariant();
- return m_itemData.at(column);
-}
-//! [6]
-
-//! [7]
TreeItem *TreeItem::parentItem()
{
return m_parentItem;
}
-//! [7]
+//! [6]
-//! [8]
+//! [7]
int TreeItem::row() const
{
- if (m_parentItem)
- return m_parentItem->m_childItems.indexOf(const_cast<TreeItem*>(this));
+ if (m_parentItem == nullptr)
+ return 0;
+ const auto it = std::find_if(m_parentItem->m_childItems.cbegin(), m_parentItem->m_childItems.cend(),
+ [this](const std::unique_ptr<TreeItem> &treeItem) {
+ return treeItem.get() == this;
+ });
- return 0;
+ if (it != m_parentItem->m_childItems.cend())
+ return std::distance(m_parentItem->m_childItems.cbegin(), it);
+ Q_ASSERT(false); // should not happen
+ return -1;
}
-//! [8]
+//! [7]
diff --git a/examples/widgets/itemviews/simpletreemodel/treeitem.h b/examples/widgets/itemviews/simpletreemodel/treeitem.h
index b2508b9058..b9002f06fd 100644
--- a/examples/widgets/itemviews/simpletreemodel/treeitem.h
+++ b/examples/widgets/itemviews/simpletreemodel/treeitem.h
@@ -11,10 +11,9 @@
class TreeItem
{
public:
- explicit TreeItem(const QList<QVariant> &data, TreeItem *parentItem = nullptr);
- ~TreeItem();
+ explicit TreeItem(QVariantList data, TreeItem *parentItem = nullptr);
- void appendChild(TreeItem *child);
+ void appendChild(std::unique_ptr<TreeItem> &&child);
TreeItem *child(int row);
int childCount() const;
@@ -24,8 +23,8 @@ public:
TreeItem *parentItem();
private:
- QList<TreeItem *> m_childItems;
- QList<QVariant> m_itemData;
+ std::vector<std::unique_ptr<TreeItem>> m_childItems;
+ QVariantList m_itemData;
TreeItem *m_parentItem;
};
//! [0]
diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
index 1665f18ebe..8538d99629 100644
--- a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
+++ b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
@@ -13,20 +13,19 @@
#include <QStringList>
+using namespace Qt::StringLiterals;
+
//! [0]
TreeModel::TreeModel(const QString &data, QObject *parent)
: QAbstractItemModel(parent)
+ , rootItem(std::make_unique<TreeItem>(QVariantList{tr("Title"), tr("Summary")}))
{
- rootItem = new TreeItem({tr("Title"), tr("Summary")});
- setupModelData(data.split('\n'), rootItem);
+ setupModelData(QStringView{data}.split(u'\n'), rootItem.get());
}
//! [0]
//! [1]
-TreeModel::~TreeModel()
-{
- delete rootItem;
-}
+TreeModel::~TreeModel() = default;
//! [1]
//! [2]
@@ -41,14 +40,10 @@ int TreeModel::columnCount(const QModelIndex &parent) const
//! [3]
QVariant TreeModel::data(const QModelIndex &index, int role) const
{
- if (!index.isValid())
- return QVariant();
-
- if (role != Qt::DisplayRole)
- return QVariant();
-
- TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
+ if (!index.isValid() || role != Qt::DisplayRole)
+ return {};
+ const auto *item = static_cast<const TreeItem*>(index.internalPointer());
return item->data(index.column());
}
//! [3]
@@ -56,10 +51,8 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
//! [4]
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
{
- if (!index.isValid())
- return Qt::NoItemFlags;
-
- return QAbstractItemModel::flags(index);
+ return index.isValid()
+ ? QAbstractItemModel::flags(index) : Qt::ItemFlags(Qt::NoItemFlags);
}
//! [4]
@@ -67,10 +60,8 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
- return rootItem->data(section);
-
- return QVariant();
+ return orientation == Qt::Horizontal && role == Qt::DisplayRole
+ ? rootItem->data(section) : QVariant{};
}
//! [5]
@@ -78,19 +69,15 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
- return QModelIndex();
-
- TreeItem *parentItem;
+ return {};
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<TreeItem*>(parent.internalPointer());
+ TreeItem *parentItem = parent.isValid()
+ ? static_cast<TreeItem*>(parent.internalPointer())
+ : rootItem.get();
- TreeItem *childItem = parentItem->child(row);
- if (childItem)
+ if (auto *childItem = parentItem->child(row))
return createIndex(row, column, childItem);
- return QModelIndex();
+ return {};
}
//! [6]
@@ -98,80 +85,68 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) con
QModelIndex TreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
- return QModelIndex();
+ return {};
- TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
+ auto *childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem *parentItem = childItem->parentItem();
- if (parentItem == rootItem)
- return QModelIndex();
-
- return createIndex(parentItem->row(), 0, parentItem);
+ return parentItem != rootItem.get()
+ ? createIndex(parentItem->row(), 0, parentItem) : QModelIndex{};
}
//! [7]
//! [8]
int TreeModel::rowCount(const QModelIndex &parent) const
{
- TreeItem *parentItem;
if (parent.column() > 0)
return 0;
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<TreeItem*>(parent.internalPointer());
+ const TreeItem *parentItem = parent.isValid()
+ ? static_cast<const TreeItem*>(parent.internalPointer())
+ : rootItem.get();
return parentItem->childCount();
}
//! [8]
-void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
+void TreeModel::setupModelData(const QList<QStringView> &lines, TreeItem *parent)
{
- QList<TreeItem *> parents;
- QList<int> indentations;
- parents << parent;
- indentations << 0;
-
- int number = 0;
-
- while (number < lines.count()) {
- int position = 0;
- while (position < lines[number].length()) {
- if (lines[number].at(position) != ' ')
- break;
- position++;
- }
+ struct ParentIndentation
+ {
+ TreeItem *parent;
+ qsizetype indentation;
+ };
- const QString lineData = lines[number].mid(position).trimmed();
+ QList<ParentIndentation> state{{parent, 0}};
+ for (const auto &line : lines) {
+ qsizetype position = 0;
+ for ( ; position < line.length() && line.at(position).isSpace(); ++position) {
+ }
+
+ const QStringView lineData = line.sliced(position).trimmed();
if (!lineData.isEmpty()) {
// Read the column data from the rest of the line.
- const QStringList columnStrings =
- lineData.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
- QList<QVariant> columnData;
+ const auto columnStrings = lineData.split(u'\t', Qt::SkipEmptyParts);
+ QVariantList columnData;
columnData.reserve(columnStrings.count());
- for (const QString &columnString : columnStrings)
- columnData << columnString;
+ for (const auto &columnString : columnStrings)
+ columnData << columnString.toString();
- if (position > indentations.last()) {
+ if (position > state.constLast().indentation) {
// The last child of the current parent is now the new parent
// unless the current parent has no children.
-
- if (parents.last()->childCount() > 0) {
- parents << parents.last()->child(parents.last()->childCount()-1);
- indentations << position;
- }
+ auto *lastParent = state.constLast().parent;
+ if (lastParent->childCount() > 0)
+ state.append({lastParent->child(lastParent->childCount() - 1), position});
} else {
- while (position < indentations.last() && parents.count() > 0) {
- parents.pop_back();
- indentations.pop_back();
- }
+ while (position < state.constLast().indentation && !state.isEmpty())
+ state.removeLast();
}
// Append a new item to the current parent's list of children.
- parents.last()->appendChild(new TreeItem(columnData, parents.last()));
+ auto *lastParent = state.constLast().parent;
+ lastParent->appendChild(std::make_unique<TreeItem>(columnData, lastParent));
}
- ++number;
}
}
diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.h b/examples/widgets/itemviews/simpletreemodel/treemodel.h
index aa93c33494..1a42fa585f 100644
--- a/examples/widgets/itemviews/simpletreemodel/treemodel.h
+++ b/examples/widgets/itemviews/simpletreemodel/treemodel.h
@@ -16,23 +16,25 @@ class TreeModel : public QAbstractItemModel
Q_OBJECT
public:
+ Q_DISABLE_COPY_MOVE(TreeModel)
+
explicit TreeModel(const QString &data, QObject *parent = nullptr);
- ~TreeModel();
+ ~TreeModel() override;
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const override;
+ const QModelIndex &parent = {}) const override;
QModelIndex parent(const QModelIndex &index) const override;
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
+ int rowCount(const QModelIndex &parent = {}) const override;
+ int columnCount(const QModelIndex &parent = {}) const override;
private:
- void setupModelData(const QStringList &lines, TreeItem *parent);
+ static void setupModelData(const QList<QStringView> &lines, TreeItem *parent);
- TreeItem *rootItem;
+ std::unique_ptr<TreeItem> rootItem;
};
//! [0]
diff --git a/examples/widgets/itemviews/simplewidgetmapper/CMakeLists.txt b/examples/widgets/itemviews/simplewidgetmapper/CMakeLists.txt
deleted file mode 100644
index ced0741e44..0000000000
--- a/examples/widgets/itemviews/simplewidgetmapper/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(simplewidgetmapper LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/simplewidgetmapper")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(simplewidgetmapper
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(simplewidgetmapper PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(simplewidgetmapper PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS simplewidgetmapper
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/simplewidgetmapper/main.cpp b/examples/widgets/itemviews/simplewidgetmapper/main.cpp
deleted file mode 100644
index 2709c948f9..0000000000
--- a/examples/widgets/itemviews/simplewidgetmapper/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-
-#include <QApplication>
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
- Window window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro b/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro
deleted file mode 100644
index f86a16bd3f..0000000000
--- a/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-QT += widgets
-requires(qtConfig(datawidgetmapper))
-
-HEADERS = window.h
-SOURCES = main.cpp \
- window.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/simplewidgetmapper
-INSTALLS += target
diff --git a/examples/widgets/itemviews/simplewidgetmapper/window.cpp b/examples/widgets/itemviews/simplewidgetmapper/window.cpp
deleted file mode 100644
index f7ef05dbd5..0000000000
--- a/examples/widgets/itemviews/simplewidgetmapper/window.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-
-#include <QtWidgets>
-
-//! [Set up widgets]
-Window::Window(QWidget *parent)
- : QWidget(parent)
-{
- setupModel();
-
- nameLabel = new QLabel(tr("Na&me:"));
- nameEdit = new QLineEdit();
- addressLabel = new QLabel(tr("&Address:"));
- addressEdit = new QTextEdit();
- ageLabel = new QLabel(tr("A&ge (in years):"));
- ageSpinBox = new QSpinBox();
- nextButton = new QPushButton(tr("&Next"));
- previousButton = new QPushButton(tr("&Previous"));
-
- nameLabel->setBuddy(nameEdit);
- addressLabel->setBuddy(addressEdit);
- ageLabel->setBuddy(ageSpinBox);
-//! [Set up widgets]
-
-//! [Set up the mapper]
- mapper = new QDataWidgetMapper(this);
- mapper->setModel(model);
- mapper->addMapping(nameEdit, 0);
- mapper->addMapping(addressEdit, 1);
- mapper->addMapping(ageSpinBox, 2);
-
- connect(previousButton, &QAbstractButton::clicked, mapper, &QDataWidgetMapper::toPrevious);
- connect(nextButton, &QAbstractButton::clicked, mapper, &QDataWidgetMapper::toNext);
- connect(mapper, &QDataWidgetMapper::currentIndexChanged, this, &Window::updateButtons);
-//! [Set up the mapper]
-
-//! [Set up the layout]
- QGridLayout *layout = new QGridLayout();
- layout->addWidget(nameLabel, 0, 0, 1, 1);
- layout->addWidget(nameEdit, 0, 1, 1, 1);
- layout->addWidget(previousButton, 0, 2, 1, 1);
- layout->addWidget(addressLabel, 1, 0, 1, 1);
- layout->addWidget(addressEdit, 1, 1, 2, 1);
- layout->addWidget(nextButton, 1, 2, 1, 1);
- layout->addWidget(ageLabel, 3, 0, 1, 1);
- layout->addWidget(ageSpinBox, 3, 1, 1, 1);
- setLayout(layout);
-
- setWindowTitle(tr("Simple Widget Mapper"));
- mapper->toFirst();
-}
-//! [Set up the layout]
-
-//! [Set up the model]
-void Window::setupModel()
-{
- model = new QStandardItemModel(5, 3, this);
-
- QStringList names;
- names << "Alice" << "Bob" << "Carol" << "Donald" << "Emma";
-
- QStringList addresses;
- addresses << "<qt>123 Main Street<br/>Market Town</qt>"
- << "<qt>PO Box 32<br/>Mail Handling Service"
- "<br/>Service City</qt>"
- << "<qt>The Lighthouse<br/>Remote Island</qt>"
- << "<qt>47338 Park Avenue<br/>Big City</qt>"
- << "<qt>Research Station<br/>Base Camp<br/>Big Mountain</qt>";
-
- QStringList ages;
- ages << "20" << "31" << "32" << "19" << "26";
-
- for (int row = 0; row < 5; ++row) {
- QStandardItem *item = new QStandardItem(names[row]);
- model->setItem(row, 0, item);
- item = new QStandardItem(addresses[row]);
- model->setItem(row, 1, item);
- item = new QStandardItem(ages[row]);
- model->setItem(row, 2, item);
- }
-}
-//! [Set up the model]
-
-//! [Slot for updating the buttons]
-void Window::updateButtons(int row)
-{
- previousButton->setEnabled(row > 0);
- nextButton->setEnabled(row < model->rowCount() - 1);
-}
-//! [Slot for updating the buttons]
diff --git a/examples/widgets/itemviews/simplewidgetmapper/window.h b/examples/widgets/itemviews/simplewidgetmapper/window.h
deleted file mode 100644
index 1502c00df1..0000000000
--- a/examples/widgets/itemviews/simplewidgetmapper/window.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QDataWidgetMapper;
-class QLabel;
-class QLineEdit;
-class QPushButton;
-class QSpinBox;
-class QStandardItemModel;
-class QTextEdit;
-QT_END_NAMESPACE
-
-//! [Window definition]
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window(QWidget *parent = nullptr);
-
-private slots:
- void updateButtons(int row);
-
-private:
- void setupModel();
-
- QLabel *nameLabel;
- QLabel *addressLabel;
- QLabel *ageLabel;
- QLineEdit *nameEdit;
- QTextEdit *addressEdit;
- QSpinBox *ageSpinBox;
- QPushButton *nextButton;
- QPushButton *previousButton;
-
- QStandardItemModel *model;
- QDataWidgetMapper *mapper;
-};
-//! [Window definition]
-
-#endif // WINDOW_H
diff --git a/examples/widgets/itemviews/spinboxdelegate/CMakeLists.txt b/examples/widgets/itemviews/spinboxdelegate/CMakeLists.txt
deleted file mode 100644
index 98d6579dd3..0000000000
--- a/examples/widgets/itemviews/spinboxdelegate/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(spinboxdelegate LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/spinboxdelegate")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(spinboxdelegate
- delegate.cpp delegate.h
- main.cpp
-)
-
-set_target_properties(spinboxdelegate PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(spinboxdelegate PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS spinboxdelegate
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/spinboxdelegate/delegate.cpp b/examples/widgets/itemviews/spinboxdelegate/delegate.cpp
deleted file mode 100644
index 6aa2b9be42..0000000000
--- a/examples/widgets/itemviews/spinboxdelegate/delegate.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-/*
- delegate.cpp
-
- A delegate that allows the user to change integer values from the model
- using a spin box widget.
-*/
-
-#include "delegate.h"
-
-#include <QSpinBox>
-
-//! [0]
-SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
- : QStyledItemDelegate(parent)
-{
-}
-//! [0]
-
-//! [1]
-QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
- const QStyleOptionViewItem &/* option */,
- const QModelIndex &/* index */) const
-{
- QSpinBox *editor = new QSpinBox(parent);
- editor->setFrame(false);
- editor->setMinimum(0);
- editor->setMaximum(100);
-
- return editor;
-}
-//! [1]
-
-//! [2]
-void SpinBoxDelegate::setEditorData(QWidget *editor,
- const QModelIndex &index) const
-{
- int value = index.model()->data(index, Qt::EditRole).toInt();
-
- QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
- spinBox->setValue(value);
-}
-//! [2]
-
-//! [3]
-void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const
-{
- QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
- spinBox->interpretText();
- int value = spinBox->value();
-
- model->setData(index, value, Qt::EditRole);
-}
-//! [3]
-
-//! [4]
-void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
- const QStyleOptionViewItem &option,
- const QModelIndex &/* index */) const
-{
- editor->setGeometry(option.rect);
-}
-//! [4]
diff --git a/examples/widgets/itemviews/spinboxdelegate/delegate.h b/examples/widgets/itemviews/spinboxdelegate/delegate.h
deleted file mode 100644
index 8f1130a1d2..0000000000
--- a/examples/widgets/itemviews/spinboxdelegate/delegate.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef DELEGATE_H
-#define DELEGATE_H
-
-#include <QStyledItemDelegate>
-
-//! [0]
-class SpinBoxDelegate : public QStyledItemDelegate
-{
- Q_OBJECT
-
-public:
- SpinBoxDelegate(QObject *parent = nullptr);
-
- QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
-
- void setEditorData(QWidget *editor, const QModelIndex &index) const override;
- void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const override;
-
- void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/itemviews/spinboxdelegate/main.cpp b/examples/widgets/itemviews/spinboxdelegate/main.cpp
deleted file mode 100644
index 51277036bc..0000000000
--- a/examples/widgets/itemviews/spinboxdelegate/main.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-/*
- main.cpp
-
- A simple example that shows how a view can use a custom delegate to edit
- data obtained from a model.
-*/
-
-#include "delegate.h"
-
-#include <QApplication>
-#include <QHeaderView>
-#include <QStandardItemModel>
-#include <QTableView>
-
-//! [0]
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- QStandardItemModel model(4, 2);
- QTableView tableView;
- tableView.setModel(&model);
-
- SpinBoxDelegate delegate;
- tableView.setItemDelegate(&delegate);
-//! [0]
-
- tableView.horizontalHeader()->setStretchLastSection(true);
-
-//! [1]
- for (int row = 0; row < 4; ++row) {
- for (int column = 0; column < 2; ++column) {
- QModelIndex index = model.index(row, column, QModelIndex());
- model.setData(index, QVariant((row + 1) * (column + 1)));
- }
-//! [1] //! [2]
- }
-//! [2]
-
-//! [3]
- tableView.setWindowTitle(QObject::tr("Spin Box Delegate"));
- tableView.show();
- return app.exec();
-}
-//! [3]
diff --git a/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro b/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro
deleted file mode 100644
index 2a6fed223a..0000000000
--- a/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-QT += widgets
-requires(qtConfig(tableview))
-
-HEADERS = delegate.h
-SOURCES = delegate.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/spinboxdelegate
-INSTALLS += target
diff --git a/examples/widgets/itemviews/spreadsheet/CMakeLists.txt b/examples/widgets/itemviews/spreadsheet/CMakeLists.txt
index 840dfd125d..b6521f0c2f 100644
--- a/examples/widgets/itemviews/spreadsheet/CMakeLists.txt
+++ b/examples/widgets/itemviews/spreadsheet/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(spreadsheet LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/spreadsheet")
-
find_package(Qt6
REQUIRED COMPONENTS Core Gui Widgets
OPTIONAL_COMPONENTS PrintSupport
@@ -53,7 +47,14 @@ qt_add_resources(spreadsheet "spreadsheet"
)
install(TARGETS spreadsheet
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET spreadsheet
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/spreadsheet/main.cpp b/examples/widgets/itemviews/spreadsheet/main.cpp
index 13bd0c93fc..3c2d676e88 100644
--- a/examples/widgets/itemviews/spreadsheet/main.cpp
+++ b/examples/widgets/itemviews/spreadsheet/main.cpp
@@ -8,8 +8,6 @@
int main(int argc, char **argv)
{
- Q_INIT_RESOURCE(spreadsheet);
-
QApplication app(argc, argv);
SpreadSheet sheet(10, 6);
sheet.setWindowIcon(QPixmap(":/images/interview.png"));
@@ -17,5 +15,3 @@ int main(int argc, char **argv)
sheet.layout()->setSizeConstraint(QLayout::SetFixedSize);
return app.exec();
}
-
-
diff --git a/examples/widgets/itemviews/stardelegate/CMakeLists.txt b/examples/widgets/itemviews/stardelegate/CMakeLists.txt
index 3b3656ca00..500a03f59b 100644
--- a/examples/widgets/itemviews/stardelegate/CMakeLists.txt
+++ b/examples/widgets/itemviews/stardelegate/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(stardelegate LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/stardelegate")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(stardelegate PRIVATE
)
install(TARGETS stardelegate
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET stardelegate
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/itemviews/storageview/CMakeLists.txt b/examples/widgets/itemviews/storageview/CMakeLists.txt
deleted file mode 100644
index a2ac260938..0000000000
--- a/examples/widgets/itemviews/storageview/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(storageview LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/storageview")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(storageview
- main.cpp
- storagemodel.cpp storagemodel.h
-)
-
-set_target_properties(storageview PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(storageview PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS storageview
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/itemviews/storageview/main.cpp b/examples/widgets/itemviews/storageview/main.cpp
deleted file mode 100644
index 3bd5392736..0000000000
--- a/examples/widgets/itemviews/storageview/main.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// Copyright (C) 2016 Ivan Komissarov
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include <QShortcut>
-#include <QTreeView>
-
-#include "storagemodel.h"
-
-int main(int argc, char *argv[])
-{
- QApplication a(argc, argv);
-
- QTreeView view;
- view.resize(640, 480);
- view.setWindowTitle("Storage View");
- view.setSelectionBehavior(QAbstractItemView::SelectRows);
-
- StorageModel *model = new StorageModel(&view);
- model->refresh();
- QShortcut *refreshShortcut = new QShortcut(QKeySequence::Refresh, &view);
- QObject::connect(refreshShortcut, &QShortcut::activated, model, &StorageModel::refresh);
- view.setModel(model);
-
- 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
deleted file mode 100644
index 194f8723f6..0000000000
--- a/examples/widgets/itemviews/storageview/storagemodel.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// Copyright (C) 2016 Ivan Komissarov
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "storagemodel.h"
-
-#include <QDir>
-#include <QLocale>
-
-void StorageModel::refresh()
-{
- beginResetModel();
- m_volumes = QStorageInfo::mountedVolumes();
- std::sort(m_volumes.begin(), m_volumes.end(),
- [](const QStorageInfo &st1, const QStorageInfo &st2) {
- static const QString rootSortString = QStringLiteral(" ");
- return (st1.isRoot() ? rootSortString : st1.rootPath())
- < (st2.isRoot() ? rootSortString : st2.rootPath());
- });
- endResetModel();
-}
-
-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();
-}
-
-Qt::ItemFlags StorageModel::flags(const QModelIndex &index) const
-{
- Qt::ItemFlags result = QAbstractTableModel::flags(index);
- switch (index.column()) {
- case ColumnAvailable:
- case ColumnIsReady:
- case ColumnIsReadOnly:
- case ColumnIsValid:
- result |= Qt::ItemIsUserCheckable;
- break;
- default:
- break;
- }
- return result;
-}
-
-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 QLocale().formattedDataSize(volume.bytesTotal());
- case ColumnFree:
- return QLocale().formattedDataSize(volume.bytesFree());
- case ColumnAvailable:
- return QLocale().formattedDataSize(volume.bytesAvailable());
- default:
- break;
- }
- } else if (role == Qt::CheckStateRole) {
- const QStorageInfo &volume = m_volumes.at(index.row());
- switch (index.column()) {
- case ColumnIsReady:
- return volume.isReady();
- case ColumnIsReadOnly:
- return volume.isReadOnly();
- case ColumnIsValid:
- return volume.isValid();
- default:
- break;
- }
- } else if (role == Qt::TextAlignmentRole) {
- switch (index.column()) {
- case ColumnTotal:
- case ColumnFree:
- case ColumnAvailable:
- return Qt::AlignTrailing;
- default:
- break;
- }
- return Qt::AlignLeading;
- } else if (role == Qt::ToolTipRole) {
- QLocale locale;
- 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(locale.formattedDataSize(volume.bytesTotal())).
- arg(locale.formattedDataSize(volume.bytesFree())).
- arg(locale.formattedDataSize(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
deleted file mode 100644
index f8cc3289c8..0000000000
--- a/examples/widgets/itemviews/storageview/storagemodel.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// Copyright (C) 2016 Ivan Komissarov
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#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
- };
-
- using QAbstractTableModel::QAbstractTableModel;
-
- int columnCount(const QModelIndex &parent) const override;
- int rowCount(const QModelIndex &parent) const override;
-
- QVariant data(const QModelIndex &index, int role) const override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
-
-public slots:
- void refresh();
-
-private:
- QList<QStorageInfo> m_volumes;
-};
-
-#endif // STORAGEMODEL_H
diff --git a/examples/widgets/itemviews/storageview/storageview.pro b/examples/widgets/itemviews/storageview/storageview.pro
deleted file mode 100644
index 2fdb78e7b8..0000000000
--- a/examples/widgets/itemviews/storageview/storageview.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += core gui widgets
-requires(qtConfig(treeview))
-TARGET = storageview
-TEMPLATE = app
-SOURCES += storagemodel.cpp \
- main.cpp
-HEADERS += \
- storagemodel.h
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/storageview
-INSTALLS += target
diff --git a/examples/widgets/layouts/CMakeLists.txt b/examples/widgets/layouts/CMakeLists.txt
index 60299638c4..7e679fadd3 100644
--- a/examples/widgets/layouts/CMakeLists.txt
+++ b/examples/widgets/layouts/CMakeLists.txt
@@ -1,7 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(basiclayouts)
-qt_internal_add_example(borderlayout)
-qt_internal_add_example(dynamiclayouts)
qt_internal_add_example(flowlayout)
diff --git a/examples/widgets/layouts/basiclayouts/CMakeLists.txt b/examples/widgets/layouts/basiclayouts/CMakeLists.txt
index 0f303091ab..5f126c308a 100644
--- a/examples/widgets/layouts/basiclayouts/CMakeLists.txt
+++ b/examples/widgets/layouts/basiclayouts/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(basiclayouts LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/layouts/basiclayouts")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(basiclayouts PRIVATE
)
install(TARGETS basiclayouts
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET basiclayouts
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/layouts/borderlayout/CMakeLists.txt b/examples/widgets/layouts/borderlayout/CMakeLists.txt
deleted file mode 100644
index 73722fb811..0000000000
--- a/examples/widgets/layouts/borderlayout/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(borderlayout LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/layouts/borderlayout")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(borderlayout
- borderlayout.cpp borderlayout.h
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(borderlayout PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(borderlayout PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS borderlayout
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.cpp b/examples/widgets/layouts/borderlayout/borderlayout.cpp
deleted file mode 100644
index 4dad24da0d..0000000000
--- a/examples/widgets/layouts/borderlayout/borderlayout.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "borderlayout.h"
-
-BorderLayout::BorderLayout(QWidget *parent, const QMargins &margins, int spacing)
- : QLayout(parent)
-{
- setContentsMargins(margins);
- setSpacing(spacing);
-}
-
-BorderLayout::BorderLayout(int spacing)
-{
- setSpacing(spacing);
-}
-
-
-BorderLayout::~BorderLayout()
-{
- QLayoutItem *l;
- while ((l = takeAt(0)))
- delete l;
-}
-
-void BorderLayout::addItem(QLayoutItem *item)
-{
- add(item, West);
-}
-
-void BorderLayout::addWidget(QWidget *widget, Position position)
-{
- add(new QWidgetItem(widget), position);
-}
-
-Qt::Orientations BorderLayout::expandingDirections() const
-{
- return Qt::Horizontal | Qt::Vertical;
-}
-
-bool BorderLayout::hasHeightForWidth() const
-{
- return false;
-}
-
-int BorderLayout::count() const
-{
- return list.size();
-}
-
-QLayoutItem *BorderLayout::itemAt(int index) const
-{
- ItemWrapper *wrapper = list.value(index);
- return wrapper ? wrapper->item : nullptr;
-}
-
-QSize BorderLayout::minimumSize() const
-{
- return calculateSize(MinimumSize);
-}
-
-void BorderLayout::setGeometry(const QRect &rect)
-{
- ItemWrapper *center = nullptr;
- int eastWidth = 0;
- int westWidth = 0;
- int northHeight = 0;
- int southHeight = 0;
- int centerHeight = 0;
- int i;
-
- QLayout::setGeometry(rect);
-
- for (i = 0; i < list.size(); ++i) {
- ItemWrapper *wrapper = list.at(i);
- QLayoutItem *item = wrapper->item;
- Position position = wrapper->position;
-
- if (position == North) {
- item->setGeometry(QRect(rect.x(), northHeight, rect.width(),
- item->sizeHint().height()));
-
- northHeight += item->geometry().height() + spacing();
- } else if (position == South) {
- item->setGeometry(QRect(item->geometry().x(),
- item->geometry().y(), rect.width(),
- item->sizeHint().height()));
-
- southHeight += item->geometry().height() + spacing();
-
- item->setGeometry(QRect(rect.x(),
- rect.y() + rect.height() - southHeight + spacing(),
- item->geometry().width(),
- item->geometry().height()));
- } else if (position == Center) {
- center = wrapper;
- }
- }
-
- centerHeight = rect.height() - northHeight - southHeight;
-
- for (i = 0; i < list.size(); ++i) {
- ItemWrapper *wrapper = list.at(i);
- QLayoutItem *item = wrapper->item;
- Position position = wrapper->position;
-
- if (position == West) {
- item->setGeometry(QRect(rect.x() + westWidth, northHeight,
- item->sizeHint().width(), centerHeight));
-
- westWidth += item->geometry().width() + spacing();
- } else if (position == East) {
- item->setGeometry(QRect(item->geometry().x(), item->geometry().y(),
- item->sizeHint().width(), centerHeight));
-
- eastWidth += item->geometry().width() + spacing();
-
- item->setGeometry(QRect(
- rect.x() + rect.width() - eastWidth + spacing(),
- northHeight, item->geometry().width(),
- item->geometry().height()));
- }
- }
-
- if (center)
- center->item->setGeometry(QRect(westWidth, northHeight,
- rect.width() - eastWidth - westWidth,
- centerHeight));
-}
-
-QSize BorderLayout::sizeHint() const
-{
- return calculateSize(SizeHint);
-}
-
-QLayoutItem *BorderLayout::takeAt(int index)
-{
- if (index >= 0 && index < list.size()) {
- ItemWrapper *layoutStruct = list.takeAt(index);
- return layoutStruct->item;
- }
- return nullptr;
-}
-
-void BorderLayout::add(QLayoutItem *item, Position position)
-{
- list.append(new ItemWrapper(item, position));
-}
-
-QSize BorderLayout::calculateSize(SizeType sizeType) const
-{
- QSize totalSize;
-
- for (int i = 0; i < list.size(); ++i) {
- ItemWrapper *wrapper = list.at(i);
- Position position = wrapper->position;
- QSize itemSize;
-
- if (sizeType == MinimumSize)
- itemSize = wrapper->item->minimumSize();
- else // (sizeType == SizeHint)
- itemSize = wrapper->item->sizeHint();
-
- if (position == North || position == South || position == Center)
- totalSize.rheight() += itemSize.height();
-
- if (position == West || position == East || position == Center)
- totalSize.rwidth() += itemSize.width();
- }
- return totalSize;
-}
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.h b/examples/widgets/layouts/borderlayout/borderlayout.h
deleted file mode 100644
index c1d3ae7204..0000000000
--- a/examples/widgets/layouts/borderlayout/borderlayout.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BORDERLAYOUT_H
-#define BORDERLAYOUT_H
-
-#include <QLayout>
-#include <QRect>
-
-class BorderLayout : public QLayout
-{
-public:
- enum Position { West, North, South, East, Center };
-
- explicit BorderLayout(QWidget *parent, const QMargins &margins = QMargins(), int spacing = -1);
- BorderLayout(int spacing = -1);
- ~BorderLayout();
-
- void addItem(QLayoutItem *item) override;
- void addWidget(QWidget *widget, Position position);
- Qt::Orientations expandingDirections() const override;
- bool hasHeightForWidth() const override;
- int count() const override;
- QLayoutItem *itemAt(int index) const override;
- QSize minimumSize() const override;
- void setGeometry(const QRect &rect) override;
- QSize sizeHint() const override;
- QLayoutItem *takeAt(int index) override;
-
- void add(QLayoutItem *item, Position position);
-
-private:
- struct ItemWrapper
- {
- ItemWrapper(QLayoutItem *i, Position p) {
- item = i;
- position = p;
- }
-
- QLayoutItem *item;
- Position position;
- };
-
- enum SizeType { MinimumSize, SizeHint };
- QSize calculateSize(SizeType sizeType) const;
-
- QList<ItemWrapper *> list;
-};
-
-#endif // BORDERLAYOUT_H
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.pro b/examples/widgets/layouts/borderlayout/borderlayout.pro
deleted file mode 100644
index 53c9647bd7..0000000000
--- a/examples/widgets/layouts/borderlayout/borderlayout.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-QT += widgets
-
-HEADERS = borderlayout.h \
- window.h
-SOURCES = borderlayout.cpp \
- main.cpp \
- window.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/layouts/borderlayout
-INSTALLS += target
diff --git a/examples/widgets/layouts/borderlayout/main.cpp b/examples/widgets/layouts/borderlayout/main.cpp
deleted file mode 100644
index 27409403a5..0000000000
--- a/examples/widgets/layouts/borderlayout/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "window.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Window window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/layouts/borderlayout/window.cpp b/examples/widgets/layouts/borderlayout/window.cpp
deleted file mode 100644
index ea3b6a6fe8..0000000000
--- a/examples/widgets/layouts/borderlayout/window.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "borderlayout.h"
-#include "window.h"
-#include <QTextBrowser>
-#include <QLabel>
-
-Window::Window()
-{
- QTextBrowser *centralWidget = new QTextBrowser;
- centralWidget->setPlainText(tr("Central widget"));
-
- BorderLayout *layout = new BorderLayout;
- layout->addWidget(centralWidget, BorderLayout::Center);
- layout->addWidget(createLabel("North"), BorderLayout::North);
- layout->addWidget(createLabel("West"), BorderLayout::West);
- layout->addWidget(createLabel("East 1"), BorderLayout::East);
- layout->addWidget(createLabel("East 2") , BorderLayout::East);
- layout->addWidget(createLabel("South"), BorderLayout::South);
- setLayout(layout);
-
- setWindowTitle(tr("Border Layout"));
-}
-
-QLabel *Window::createLabel(const QString &text)
-{
- QLabel *label = new QLabel(text);
- label->setFrameStyle(QFrame::Box | QFrame::Raised);
- return label;
-}
diff --git a/examples/widgets/layouts/borderlayout/window.h b/examples/widgets/layouts/borderlayout/window.h
deleted file mode 100644
index 9e97d0e8fb..0000000000
--- a/examples/widgets/layouts/borderlayout/window.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-QT_END_NAMESPACE
-
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window();
-
-private:
- QLabel *createLabel(const QString &text);
-};
-
-#endif // WINDOW_H
diff --git a/examples/widgets/layouts/dynamiclayouts/CMakeLists.txt b/examples/widgets/layouts/dynamiclayouts/CMakeLists.txt
deleted file mode 100644
index 5fe39bfb5f..0000000000
--- a/examples/widgets/layouts/dynamiclayouts/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(dynamiclayouts LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/layouts/dynamiclayouts")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(dynamiclayouts
- dialog.cpp dialog.h
- main.cpp
-)
-
-set_target_properties(dynamiclayouts PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(dynamiclayouts PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS dynamiclayouts
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.cpp b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
deleted file mode 100644
index 28b4fc2f7f..0000000000
--- a/examples/widgets/layouts/dynamiclayouts/dialog.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-
-#include "dialog.h"
-
-Dialog::Dialog(QWidget *parent)
- : QDialog(parent)
-{
- createRotatableGroupBox();
- createOptionsGroupBox();
- createButtonBox();
-
- mainLayout = new QGridLayout;
- mainLayout->addWidget(rotatableGroupBox, 0, 0);
- mainLayout->addWidget(optionsGroupBox, 1, 0);
- mainLayout->addWidget(buttonBox, 2, 0);
- setLayout(mainLayout);
-
- mainLayout->setSizeConstraint(QLayout::SetMinimumSize);
-
- setWindowTitle(tr("Dynamic Layouts"));
-}
-
-void Dialog::buttonsOrientationChanged(int index)
-{
- mainLayout->setSizeConstraint(QLayout::SetNoConstraint);
- setMinimumSize(0, 0);
-
- Qt::Orientation orientation = Qt::Orientation(
- buttonsOrientationComboBox->itemData(index).toInt());
-
- if (orientation == buttonBox->orientation())
- return;
-
- mainLayout->removeWidget(buttonBox);
-
- int spacing = mainLayout->spacing();
-
- QSize oldSizeHint = buttonBox->sizeHint() + QSize(spacing, spacing);
- buttonBox->setOrientation(orientation);
- QSize newSizeHint = buttonBox->sizeHint() + QSize(spacing, spacing);
-
- if (orientation == Qt::Horizontal) {
- mainLayout->addWidget(buttonBox, 2, 0);
- resize(size() + QSize(-oldSizeHint.width(), newSizeHint.height()));
- } else {
- mainLayout->addWidget(buttonBox, 0, 3, 2, 1);
- resize(size() + QSize(newSizeHint.width(), -oldSizeHint.height()));
- }
-
- mainLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
-}
-
-void Dialog::rotateWidgets()
-{
- Q_ASSERT(rotatableWidgets.count() % 2 == 0);
-
- for (QWidget *widget : std::as_const(rotatableWidgets))
- rotatableLayout->removeWidget(widget);
-
- rotatableWidgets.enqueue(rotatableWidgets.dequeue());
-
- const int n = rotatableWidgets.count();
- for (int i = 0; i < n / 2; ++i) {
- rotatableLayout->addWidget(rotatableWidgets[n - i - 1], 0, i);
- rotatableLayout->addWidget(rotatableWidgets[i], 1, i);
- }
-}
-
-void Dialog::help()
-{
- QMessageBox::information(this, tr("Dynamic Layouts Help"),
- tr("This example shows how to change layouts "
- "dynamically."));
-}
-
-void Dialog::createRotatableGroupBox()
-{
- rotatableGroupBox = new QGroupBox(tr("Rotatable Widgets"));
-
- rotatableWidgets.enqueue(new QSpinBox);
- rotatableWidgets.enqueue(new QSlider);
- rotatableWidgets.enqueue(new QDial);
- rotatableWidgets.enqueue(new QProgressBar);
-
- int n = rotatableWidgets.count();
- for (int i = 0; i < n; ++i) {
- connect(rotatableWidgets[i], SIGNAL(valueChanged(int)),
- rotatableWidgets[(i + 1) % n], SLOT(setValue(int)));
- }
-
- rotatableLayout = new QGridLayout;
- rotatableGroupBox->setLayout(rotatableLayout);
-
- rotateWidgets();
-}
-
-void Dialog::createOptionsGroupBox()
-{
- optionsGroupBox = new QGroupBox(tr("Options"));
-
- buttonsOrientationLabel = new QLabel(tr("Orientation of buttons:"));
-
- buttonsOrientationComboBox = new QComboBox;
- buttonsOrientationComboBox->addItem(tr("Horizontal"), Qt::Horizontal);
- buttonsOrientationComboBox->addItem(tr("Vertical"), Qt::Vertical);
-
- connect(buttonsOrientationComboBox,
- &QComboBox::currentIndexChanged,
- this,
- &Dialog::buttonsOrientationChanged);
-
- optionsLayout = new QGridLayout;
- optionsLayout->addWidget(buttonsOrientationLabel, 0, 0);
- optionsLayout->addWidget(buttonsOrientationComboBox, 0, 1);
- optionsLayout->setColumnStretch(2, 1);
- optionsGroupBox->setLayout(optionsLayout);
-}
-
-void Dialog::createButtonBox()
-{
- buttonBox = new QDialogButtonBox;
-
- closeButton = buttonBox->addButton(QDialogButtonBox::Close);
- helpButton = buttonBox->addButton(QDialogButtonBox::Help);
- rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),
- QDialogButtonBox::ActionRole);
-
- connect(rotateWidgetsButton, &QPushButton::clicked, this, &Dialog::rotateWidgets);
- connect(closeButton, &QPushButton::clicked, this, &Dialog::close);
- connect(helpButton, &QPushButton::clicked, this, &Dialog::help);
-}
-
-
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.h b/examples/widgets/layouts/dynamiclayouts/dialog.h
deleted file mode 100644
index 89424cee8a..0000000000
--- a/examples/widgets/layouts/dynamiclayouts/dialog.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef DIALOG_H
-#define DIALOG_H
-
-#include <QDialog>
-#include <QQueue>
-
-QT_BEGIN_NAMESPACE
-class QComboBox;
-class QDialogButtonBox;
-class QGridLayout;
-class QGroupBox;
-class QLabel;
-class QPushButton;
-QT_END_NAMESPACE
-
-class Dialog : public QDialog
-{
- Q_OBJECT
-
-public:
- Dialog(QWidget *parent = nullptr);
-
-private slots:
- void buttonsOrientationChanged(int index);
- void rotateWidgets();
- void help();
-
-private:
- void createRotatableGroupBox();
- void createOptionsGroupBox();
- void createButtonBox();
-
- QGroupBox *rotatableGroupBox;
- QQueue<QWidget *> rotatableWidgets;
-
- QGroupBox *optionsGroupBox;
- QLabel *buttonsOrientationLabel;
- QComboBox *buttonsOrientationComboBox;
-
- QDialogButtonBox *buttonBox;
- QPushButton *closeButton;
- QPushButton *helpButton;
- QPushButton *rotateWidgetsButton;
-
- QGridLayout *mainLayout;
- QGridLayout *rotatableLayout;
- QGridLayout *optionsLayout;
-};
-
-#endif // DIALOG_H
diff --git a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro
deleted file mode 100644
index dcd4288698..0000000000
--- a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = dialog.h
-SOURCES = dialog.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/layouts/dynamiclayouts
-INSTALLS += target
diff --git a/examples/widgets/layouts/dynamiclayouts/main.cpp b/examples/widgets/layouts/dynamiclayouts/main.cpp
deleted file mode 100644
index 865e0d1579..0000000000
--- a/examples/widgets/layouts/dynamiclayouts/main.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "dialog.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Dialog dialog;
- dialog.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/layouts/flowlayout/CMakeLists.txt b/examples/widgets/layouts/flowlayout/CMakeLists.txt
index d47dbd4c8c..9693d409b7 100644
--- a/examples/widgets/layouts/flowlayout/CMakeLists.txt
+++ b/examples/widgets/layouts/flowlayout/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(flowlayout LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/layouts/flowlayout")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(flowlayout PRIVATE
)
install(TARGETS flowlayout
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET flowlayout
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/layouts/layouts.pro b/examples/widgets/layouts/layouts.pro
index c641e8cf7f..c0b5453f02 100644
--- a/examples/widgets/layouts/layouts.pro
+++ b/examples/widgets/layouts/layouts.pro
@@ -1,5 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = basiclayouts \
- borderlayout \
- dynamiclayouts \
flowlayout
diff --git a/examples/widgets/mainwindows/CMakeLists.txt b/examples/widgets/mainwindows/CMakeLists.txt
index f8457d50a7..5b7079ed04 100644
--- a/examples/widgets/mainwindows/CMakeLists.txt
+++ b/examples/widgets/mainwindows/CMakeLists.txt
@@ -1,8 +1,4 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-qt_internal_add_example(application)
-qt_internal_add_example(dockwidgets)
-qt_internal_add_example(mainwindow)
-qt_internal_add_example(mdi)
qt_internal_add_example(menus)
diff --git a/examples/widgets/mainwindows/application/CMakeLists.txt b/examples/widgets/mainwindows/application/CMakeLists.txt
deleted file mode 100644
index 545d1cfca0..0000000000
--- a/examples/widgets/mainwindows/application/CMakeLists.txt
+++ /dev/null
@@ -1,54 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(application LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/mainwindows/application")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(application
- main.cpp
- mainwindow.cpp mainwindow.h
-)
-
-set_target_properties(application PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(application PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(application_resource_files
- "images/copy.png"
- "images/cut.png"
- "images/new.png"
- "images/open.png"
- "images/paste.png"
- "images/save.png"
-)
-
-qt_add_resources(application "application"
- PREFIX
- "/"
- FILES
- ${application_resource_files}
-)
-
-install(TARGETS application
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/mainwindows/application/application.pro b/examples/widgets/mainwindows/application/application.pro
deleted file mode 100644
index e55655a934..0000000000
--- a/examples/widgets/mainwindows/application/application.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-
-HEADERS = mainwindow.h
-SOURCES = main.cpp \
- mainwindow.cpp
-#! [0]
-RESOURCES = application.qrc
-#! [0]
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/mainwindows/application
-INSTALLS += target
diff --git a/examples/widgets/mainwindows/application/application.qrc b/examples/widgets/mainwindows/application/application.qrc
deleted file mode 100644
index 0a776fab4d..0000000000
--- a/examples/widgets/mainwindows/application/application.qrc
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/copy.png</file>
- <file>images/cut.png</file>
- <file>images/new.png</file>
- <file>images/open.png</file>
- <file>images/paste.png</file>
- <file>images/save.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/mainwindows/application/images/copy.png b/examples/widgets/mainwindows/application/images/copy.png
deleted file mode 100644
index 2aeb28288f..0000000000
--- a/examples/widgets/mainwindows/application/images/copy.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/cut.png b/examples/widgets/mainwindows/application/images/cut.png
deleted file mode 100644
index 54638e9386..0000000000
--- a/examples/widgets/mainwindows/application/images/cut.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/new.png b/examples/widgets/mainwindows/application/images/new.png
deleted file mode 100644
index 12131b0100..0000000000
--- a/examples/widgets/mainwindows/application/images/new.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/open.png b/examples/widgets/mainwindows/application/images/open.png
deleted file mode 100644
index 45fa2883a7..0000000000
--- a/examples/widgets/mainwindows/application/images/open.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/paste.png b/examples/widgets/mainwindows/application/images/paste.png
deleted file mode 100644
index c14425cad1..0000000000
--- a/examples/widgets/mainwindows/application/images/paste.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/save.png b/examples/widgets/mainwindows/application/images/save.png
deleted file mode 100644
index e65a29d5f1..0000000000
--- a/examples/widgets/mainwindows/application/images/save.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/application/main.cpp b/examples/widgets/mainwindows/application/main.cpp
deleted file mode 100644
index 0437f91f73..0000000000
--- a/examples/widgets/mainwindows/application/main.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-//! [0]
-#include <QApplication>
-#include <QCommandLineParser>
-#include <QCommandLineOption>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(application);
-
- QApplication app(argc, argv);
- QCoreApplication::setOrganizationName("QtProject");
- QCoreApplication::setApplicationName("Application Example");
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser parser;
- parser.setApplicationDescription(QCoreApplication::applicationName());
- parser.addHelpOption();
- parser.addVersionOption();
- parser.addPositionalArgument("file", "The file to open.");
- parser.process(app);
-
- MainWindow mainWin;
- if (!parser.positionalArguments().isEmpty())
- mainWin.loadFile(parser.positionalArguments().first());
- mainWin.show();
- return app.exec();
-}
-//! [0]
diff --git a/examples/widgets/mainwindows/application/mainwindow.cpp b/examples/widgets/mainwindows/application/mainwindow.cpp
deleted file mode 100644
index d49060e9b6..0000000000
--- a/examples/widgets/mainwindows/application/mainwindow.cpp
+++ /dev/null
@@ -1,370 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-//! [0]
-#include <QtWidgets>
-
-#include "mainwindow.h"
-//! [0]
-
-//! [1]
-MainWindow::MainWindow()
- : textEdit(new QPlainTextEdit)
-//! [1] //! [2]
-{
- setCentralWidget(textEdit);
-
- createActions();
- createStatusBar();
-
- readSettings();
-
- connect(textEdit->document(), &QTextDocument::contentsChanged,
- this, &MainWindow::documentWasModified);
-
-#ifndef QT_NO_SESSIONMANAGER
- connect(qApp, &QGuiApplication::commitDataRequest,
- this, &MainWindow::commitData);
-#endif
-
- setCurrentFile(QString());
- setUnifiedTitleAndToolBarOnMac(true);
-}
-//! [2]
-
-//! [3]
-void MainWindow::closeEvent(QCloseEvent *event)
-//! [3] //! [4]
-{
- if (maybeSave()) {
- writeSettings();
- event->accept();
- } else {
- event->ignore();
- }
-}
-//! [4]
-
-//! [5]
-void MainWindow::newFile()
-//! [5] //! [6]
-{
- if (maybeSave()) {
- textEdit->clear();
- setCurrentFile(QString());
- }
-}
-//! [6]
-
-//! [7]
-void MainWindow::open()
-//! [7] //! [8]
-{
- if (maybeSave()) {
- QString fileName = QFileDialog::getOpenFileName(this);
- if (!fileName.isEmpty())
- loadFile(fileName);
- }
-}
-//! [8]
-
-//! [9]
-bool MainWindow::save()
-//! [9] //! [10]
-{
- if (curFile.isEmpty()) {
- return saveAs();
- } else {
- return saveFile(curFile);
- }
-}
-//! [10]
-
-//! [11]
-bool MainWindow::saveAs()
-//! [11] //! [12]
-{
- QFileDialog dialog(this);
- dialog.setWindowModality(Qt::WindowModal);
- dialog.setAcceptMode(QFileDialog::AcceptSave);
- if (dialog.exec() != QDialog::Accepted)
- return false;
- return saveFile(dialog.selectedFiles().first());
-}
-//! [12]
-
-//! [13]
-void MainWindow::about()
-//! [13] //! [14]
-{
- QMessageBox::about(this, tr("About Application"),
- tr("The <b>Application</b> example demonstrates how to "
- "write modern GUI applications using Qt, with a menu bar, "
- "toolbars, and a status bar."));
-}
-//! [14]
-
-//! [15]
-void MainWindow::documentWasModified()
-//! [15] //! [16]
-{
- setWindowModified(textEdit->document()->isModified());
-}
-//! [16]
-
-//! [17]
-void MainWindow::createActions()
-//! [17] //! [18]
-{
-
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- QToolBar *fileToolBar = addToolBar(tr("File"));
- const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/images/new.png"));
- QAction *newAct = new QAction(newIcon, tr("&New"), this);
- newAct->setShortcuts(QKeySequence::New);
- newAct->setStatusTip(tr("Create a new file"));
- connect(newAct, &QAction::triggered, this, &MainWindow::newFile);
- fileMenu->addAction(newAct);
- fileToolBar->addAction(newAct);
-
-//! [19]
- const QIcon openIcon = QIcon::fromTheme("document-open", QIcon(":/images/open.png"));
- QAction *openAct = new QAction(openIcon, tr("&Open..."), this);
- openAct->setShortcuts(QKeySequence::Open);
- openAct->setStatusTip(tr("Open an existing file"));
- connect(openAct, &QAction::triggered, this, &MainWindow::open);
- fileMenu->addAction(openAct);
- fileToolBar->addAction(openAct);
-//! [18] //! [19]
-
- const QIcon saveIcon = QIcon::fromTheme("document-save", QIcon(":/images/save.png"));
- QAction *saveAct = new QAction(saveIcon, tr("&Save"), this);
- saveAct->setShortcuts(QKeySequence::Save);
- saveAct->setStatusTip(tr("Save the document to disk"));
- connect(saveAct, &QAction::triggered, this, &MainWindow::save);
- fileMenu->addAction(saveAct);
- fileToolBar->addAction(saveAct);
-
- const QIcon saveAsIcon = QIcon::fromTheme("document-save-as");
- QAction *saveAsAct = fileMenu->addAction(saveAsIcon, tr("Save &As..."), this, &MainWindow::saveAs);
- saveAsAct->setShortcuts(QKeySequence::SaveAs);
- saveAsAct->setStatusTip(tr("Save the document under a new name"));
-
-//! [20]
-
- fileMenu->addSeparator();
-
- const QIcon exitIcon = QIcon::fromTheme("application-exit");
- QAction *exitAct = fileMenu->addAction(exitIcon, tr("E&xit"), this, &QWidget::close);
- exitAct->setShortcuts(QKeySequence::Quit);
-//! [20]
- exitAct->setStatusTip(tr("Exit the application"));
-
-//! [21]
- QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
- QToolBar *editToolBar = addToolBar(tr("Edit"));
-//!
-#ifndef QT_NO_CLIPBOARD
- const QIcon cutIcon = QIcon::fromTheme("edit-cut", QIcon(":/images/cut.png"));
- QAction *cutAct = new QAction(cutIcon, tr("Cu&t"), this);
-//! [21]
- cutAct->setShortcuts(QKeySequence::Cut);
- cutAct->setStatusTip(tr("Cut the current selection's contents to the "
- "clipboard"));
- connect(cutAct, &QAction::triggered, textEdit, &QPlainTextEdit::cut);
- editMenu->addAction(cutAct);
- editToolBar->addAction(cutAct);
-
- const QIcon copyIcon = QIcon::fromTheme("edit-copy", QIcon(":/images/copy.png"));
- QAction *copyAct = new QAction(copyIcon, tr("&Copy"), this);
- copyAct->setShortcuts(QKeySequence::Copy);
- copyAct->setStatusTip(tr("Copy the current selection's contents to the "
- "clipboard"));
- connect(copyAct, &QAction::triggered, textEdit, &QPlainTextEdit::copy);
- editMenu->addAction(copyAct);
- editToolBar->addAction(copyAct);
-
- const QIcon pasteIcon = QIcon::fromTheme("edit-paste", QIcon(":/images/paste.png"));
- QAction *pasteAct = new QAction(pasteIcon, tr("&Paste"), this);
- pasteAct->setShortcuts(QKeySequence::Paste);
- pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
- "selection"));
- connect(pasteAct, &QAction::triggered, textEdit, &QPlainTextEdit::paste);
- editMenu->addAction(pasteAct);
- editToolBar->addAction(pasteAct);
-
- menuBar()->addSeparator();
-
-#endif // !QT_NO_CLIPBOARD
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- QAction *aboutAct = helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- aboutAct->setStatusTip(tr("Show the application's About box"));
-
-//! [22]
-
- QAction *aboutQtAct = helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
- aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
-//! [22]
-
-//! [23]
-#ifndef QT_NO_CLIPBOARD
- cutAct->setEnabled(false);
-//! [23] //! [24]
- copyAct->setEnabled(false);
- connect(textEdit, &QPlainTextEdit::copyAvailable, cutAct, &QAction::setEnabled);
- connect(textEdit, &QPlainTextEdit::copyAvailable, copyAct, &QAction::setEnabled);
-#endif // !QT_NO_CLIPBOARD
-}
-//! [24]
-
-//! [32]
-void MainWindow::createStatusBar()
-//! [32] //! [33]
-{
- statusBar()->showMessage(tr("Ready"));
-}
-//! [33]
-
-//! [34] //! [35]
-void MainWindow::readSettings()
-//! [34] //! [36]
-{
- QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
- const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
- if (geometry.isEmpty()) {
- const QRect availableGeometry = screen()->availableGeometry();
- resize(availableGeometry.width() / 3, availableGeometry.height() / 2);
- move((availableGeometry.width() - width()) / 2,
- (availableGeometry.height() - height()) / 2);
- } else {
- restoreGeometry(geometry);
- }
-}
-//! [35] //! [36]
-
-//! [37] //! [38]
-void MainWindow::writeSettings()
-//! [37] //! [39]
-{
- QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
- settings.setValue("geometry", saveGeometry());
-}
-//! [38] //! [39]
-
-//! [40]
-bool MainWindow::maybeSave()
-//! [40] //! [41]
-{
- if (!textEdit->document()->isModified())
- return true;
- const QMessageBox::StandardButton ret
- = QMessageBox::warning(this, tr("Application"),
- tr("The document has been modified.\n"
- "Do you want to save your changes?"),
- QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
- switch (ret) {
- case QMessageBox::Save:
- return save();
- case QMessageBox::Cancel:
- return false;
- default:
- break;
- }
- return true;
-}
-//! [41]
-
-//! [42]
-void MainWindow::loadFile(const QString &fileName)
-//! [42] //! [43]
-{
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("Application"),
- tr("Cannot read file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString()));
- return;
- }
-
- QTextStream in(&file);
-#ifndef QT_NO_CURSOR
- QGuiApplication::setOverrideCursor(Qt::WaitCursor);
-#endif
- textEdit->setPlainText(in.readAll());
-#ifndef QT_NO_CURSOR
- QGuiApplication::restoreOverrideCursor();
-#endif
-
- setCurrentFile(fileName);
- statusBar()->showMessage(tr("File loaded"), 2000);
-}
-//! [43]
-
-//! [44]
-bool MainWindow::saveFile(const QString &fileName)
-//! [44] //! [45]
-{
- QString errorMessage;
-
- QGuiApplication::setOverrideCursor(Qt::WaitCursor);
- QSaveFile file(fileName);
- if (file.open(QFile::WriteOnly | QFile::Text)) {
- QTextStream out(&file);
- out << textEdit->toPlainText();
- if (!file.commit()) {
- errorMessage = tr("Cannot write file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString());
- }
- } else {
- errorMessage = tr("Cannot open file %1 for writing:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString());
- }
- QGuiApplication::restoreOverrideCursor();
-
- if (!errorMessage.isEmpty()) {
- QMessageBox::warning(this, tr("Application"), errorMessage);
- return false;
- }
-
- setCurrentFile(fileName);
- statusBar()->showMessage(tr("File saved"), 2000);
- return true;
-}
-//! [45]
-
-//! [46]
-void MainWindow::setCurrentFile(const QString &fileName)
-//! [46] //! [47]
-{
- curFile = fileName;
- textEdit->document()->setModified(false);
- setWindowModified(false);
-
- QString shownName = curFile;
- if (curFile.isEmpty())
- shownName = "untitled.txt";
- setWindowFilePath(shownName);
-}
-//! [47]
-
-//! [48]
-QString MainWindow::strippedName(const QString &fullFileName)
-//! [48] //! [49]
-{
- return QFileInfo(fullFileName).fileName();
-}
-//! [49]
-#ifndef QT_NO_SESSIONMANAGER
-void MainWindow::commitData(QSessionManager &manager)
-{
- if (manager.allowsInteraction()) {
- if (!maybeSave())
- manager.cancel();
- } else {
- // Non-interactive: save without asking
- if (textEdit->document()->isModified())
- save();
- }
-}
-#endif
diff --git a/examples/widgets/mainwindows/application/mainwindow.h b/examples/widgets/mainwindows/application/mainwindow.h
deleted file mode 100644
index caeaf70400..0000000000
--- a/examples/widgets/mainwindows/application/mainwindow.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QMenu;
-class QPlainTextEdit;
-class QSessionManager;
-QT_END_NAMESPACE
-
-//! [0]
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
- void loadFile(const QString &fileName);
-
-protected:
- void closeEvent(QCloseEvent *event) override;
-
-private slots:
- void newFile();
- void open();
- bool save();
- bool saveAs();
- void about();
- void documentWasModified();
-#ifndef QT_NO_SESSIONMANAGER
- void commitData(QSessionManager &);
-#endif
-
-private:
- void createActions();
- void createStatusBar();
- void readSettings();
- void writeSettings();
- bool maybeSave();
- bool saveFile(const QString &fileName);
- void setCurrentFile(const QString &fileName);
- QString strippedName(const QString &fullFileName);
-
- QPlainTextEdit *textEdit;
- QString curFile;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/mainwindows/dockwidgets/CMakeLists.txt b/examples/widgets/mainwindows/dockwidgets/CMakeLists.txt
deleted file mode 100644
index a82cb55471..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/CMakeLists.txt
+++ /dev/null
@@ -1,59 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(dockwidgets LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/mainwindows/dockwidgets")
-
-find_package(Qt6
- REQUIRED COMPONENTS Core Gui Widgets
- OPTIONAL_COMPONENTS PrintSupport
-)
-
-qt_standard_project_setup()
-
-qt_add_executable(dockwidgets
- main.cpp
- mainwindow.cpp mainwindow.h
-)
-
-set_target_properties(dockwidgets PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(dockwidgets PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if (TARGET Qt6::PrintSupport)
- target_link_libraries(dockwidgets PRIVATE Qt6::PrintSupport)
-endif()
-
-# Resources:
-set(dockwidgets_resource_files
- "images/new.png"
- "images/print.png"
- "images/save.png"
- "images/undo.png"
-)
-
-qt_add_resources(dockwidgets "dockwidgets"
- PREFIX
- "/"
- FILES
- ${dockwidgets_resource_files}
-)
-
-install(TARGETS dockwidgets
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro b/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro
deleted file mode 100644
index 3acded5ed3..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-requires(qtConfig(listwidget))
-qtHaveModule(printsupport): QT += printsupport
-
-HEADERS = mainwindow.h
-SOURCES = main.cpp \
- mainwindow.cpp
-RESOURCES = dockwidgets.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/mainwindows/dockwidgets
-INSTALLS += target
diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc b/examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc
deleted file mode 100644
index 968feac7ea..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/new.png</file>
- <file>images/print.png</file>
- <file>images/save.png</file>
- <file>images/undo.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/mainwindows/dockwidgets/images/new.png b/examples/widgets/mainwindows/dockwidgets/images/new.png
deleted file mode 100644
index dd795cfffc..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/images/new.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/images/print.png b/examples/widgets/mainwindows/dockwidgets/images/print.png
deleted file mode 100644
index 2afb769ee2..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/images/print.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/images/save.png b/examples/widgets/mainwindows/dockwidgets/images/save.png
deleted file mode 100644
index 46eac82ad1..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/images/save.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/images/undo.png b/examples/widgets/mainwindows/dockwidgets/images/undo.png
deleted file mode 100644
index eee23d24a3..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/images/undo.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/main.cpp b/examples/widgets/mainwindows/dockwidgets/main.cpp
deleted file mode 100644
index 35ed609035..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/main.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Q_INIT_RESOURCE(dockwidgets);
- MainWindow mainWin;
- mainWin.show();
- return app.exec();
-}
diff --git a/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp b/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp
deleted file mode 100644
index 3493a66a67..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-//! [0]
-#include <QtWidgets>
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#if QT_CONFIG(printdialog)
-#include <QtPrintSupport>
-#endif
-#endif
-
-#include "mainwindow.h"
-//! [0]
-
-//! [1]
-MainWindow::MainWindow()
- : textEdit(new QTextEdit)
-{
- setCentralWidget(textEdit);
-
- createActions();
- createStatusBar();
- createDockWindows();
-
- setWindowTitle(tr("Dock Widgets"));
-
- newLetter();
- setUnifiedTitleAndToolBarOnMac(true);
-}
-//! [1]
-
-//! [2]
-void MainWindow::newLetter()
-{
- textEdit->clear();
-
- QTextCursor cursor(textEdit->textCursor());
- cursor.movePosition(QTextCursor::Start);
- QTextFrame *topFrame = cursor.currentFrame();
- QTextFrameFormat topFrameFormat = topFrame->frameFormat();
- topFrameFormat.setPadding(16);
- topFrame->setFrameFormat(topFrameFormat);
-
- QTextCharFormat textFormat;
- QTextCharFormat boldFormat;
- boldFormat.setFontWeight(QFont::Bold);
- QTextCharFormat italicFormat;
- italicFormat.setFontItalic(true);
-
- QTextTableFormat tableFormat;
- tableFormat.setBorder(1);
- tableFormat.setCellPadding(16);
- tableFormat.setAlignment(Qt::AlignRight);
- cursor.insertTable(1, 1, tableFormat);
- cursor.insertText("The Firm", boldFormat);
- cursor.insertBlock();
- cursor.insertText("321 City Street", textFormat);
- cursor.insertBlock();
- cursor.insertText("Industry Park");
- cursor.insertBlock();
- cursor.insertText("Some Country");
- cursor.setPosition(topFrame->lastPosition());
- cursor.insertText(QDate::currentDate().toString("d MMMM yyyy"), textFormat);
- cursor.insertBlock();
- cursor.insertBlock();
- cursor.insertText("Dear ", textFormat);
- cursor.insertText("NAME", italicFormat);
- cursor.insertText(",", textFormat);
- for (int i = 0; i < 3; ++i)
- cursor.insertBlock();
- cursor.insertText(tr("Yours sincerely,"), textFormat);
- for (int i = 0; i < 3; ++i)
- cursor.insertBlock();
- cursor.insertText("The Boss", textFormat);
- cursor.insertBlock();
- cursor.insertText("ADDRESS", italicFormat);
-}
-//! [2]
-
-//! [3]
-void MainWindow::print()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- QTextDocument *document = textEdit->document();
- QPrinter printer;
-
- QPrintDialog dlg(&printer, this);
- if (dlg.exec() != QDialog::Accepted) {
- return;
- }
-
- document->print(&printer);
- statusBar()->showMessage(tr("Ready"), 2000);
-#endif
-}
-//! [3]
-
-//! [4]
-void MainWindow::save()
-{
- QMimeDatabase mimeDatabase;
- QString fileName = QFileDialog::getSaveFileName(this,
- tr("Choose a file name"), ".",
- mimeDatabase.mimeTypeForName("text/html").filterString());
- if (fileName.isEmpty())
- return;
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("Dock Widgets"),
- tr("Cannot write file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString()));
- return;
- }
-
- QTextStream out(&file);
- QGuiApplication::setOverrideCursor(Qt::WaitCursor);
- out << textEdit->toHtml();
- QGuiApplication::restoreOverrideCursor();
-
- statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000);
-}
-//! [4]
-
-//! [5]
-void MainWindow::undo()
-{
- QTextDocument *document = textEdit->document();
- document->undo();
-}
-//! [5]
-
-//! [6]
-void MainWindow::insertCustomer(const QString &customer)
-{
- if (customer.isEmpty())
- return;
- QStringList customerList = customer.split(", ");
- QTextDocument *document = textEdit->document();
- QTextCursor cursor = document->find("NAME");
- if (!cursor.isNull()) {
- cursor.beginEditBlock();
- cursor.insertText(customerList.at(0));
- QTextCursor oldcursor = cursor;
- cursor = document->find("ADDRESS");
- if (!cursor.isNull()) {
- for (int i = 1; i < customerList.size(); ++i) {
- cursor.insertBlock();
- cursor.insertText(customerList.at(i));
- }
- cursor.endEditBlock();
- }
- else
- oldcursor.endEditBlock();
- }
-}
-//! [6]
-
-//! [7]
-void MainWindow::addParagraph(const QString &paragraph)
-{
- if (paragraph.isEmpty())
- return;
- QTextDocument *document = textEdit->document();
- QTextCursor cursor = document->find(tr("Yours sincerely,"));
- if (cursor.isNull())
- return;
- cursor.beginEditBlock();
- cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor, 2);
- cursor.insertBlock();
- cursor.insertText(paragraph);
- cursor.insertBlock();
- cursor.endEditBlock();
-
-}
-//! [7]
-
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About Dock Widgets"),
- tr("The <b>Dock Widgets</b> example demonstrates how to "
- "use Qt's dock widgets. You can enter your own text, "
- "click a customer to add a customer name and "
- "address, and click standard paragraphs to add them."));
-}
-
-void MainWindow::createActions()
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- QToolBar *fileToolBar = addToolBar(tr("File"));
-
- const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/images/new.png"));
- QAction *newLetterAct = new QAction(newIcon, tr("&New Letter"), this);
- newLetterAct->setShortcuts(QKeySequence::New);
- newLetterAct->setStatusTip(tr("Create a new form letter"));
- connect(newLetterAct, &QAction::triggered, this, &MainWindow::newLetter);
- fileMenu->addAction(newLetterAct);
- fileToolBar->addAction(newLetterAct);
-
- const QIcon saveIcon = QIcon::fromTheme("document-save", QIcon(":/images/save.png"));
- QAction *saveAct = new QAction(saveIcon, tr("&Save..."), this);
- saveAct->setShortcuts(QKeySequence::Save);
- saveAct->setStatusTip(tr("Save the current form letter"));
- connect(saveAct, &QAction::triggered, this, &MainWindow::save);
- fileMenu->addAction(saveAct);
- fileToolBar->addAction(saveAct);
-
- const QIcon printIcon = QIcon::fromTheme("document-print", QIcon(":/images/print.png"));
- QAction *printAct = new QAction(printIcon, tr("&Print..."), this);
- printAct->setShortcuts(QKeySequence::Print);
- printAct->setStatusTip(tr("Print the current form letter"));
- connect(printAct, &QAction::triggered, this, &MainWindow::print);
- fileMenu->addAction(printAct);
- fileToolBar->addAction(printAct);
-
- fileMenu->addSeparator();
-
- QAction *quitAct = fileMenu->addAction(tr("&Quit"), qApp, &QCoreApplication::quit);
- quitAct->setShortcuts(QKeySequence::Quit);
- quitAct->setStatusTip(tr("Quit the application"));
-
- QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
- QToolBar *editToolBar = addToolBar(tr("Edit"));
- const QIcon undoIcon = QIcon::fromTheme("edit-undo", QIcon(":/images/undo.png"));
- QAction *undoAct = new QAction(undoIcon, tr("&Undo"), this);
- undoAct->setShortcuts(QKeySequence::Undo);
- undoAct->setStatusTip(tr("Undo the last editing action"));
- connect(undoAct, &QAction::triggered, this, &MainWindow::undo);
- editMenu->addAction(undoAct);
- editToolBar->addAction(undoAct);
-
- viewMenu = menuBar()->addMenu(tr("&View"));
-
- menuBar()->addSeparator();
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
-
- QAction *aboutAct = helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- aboutAct->setStatusTip(tr("Show the application's About box"));
-
- QAction *aboutQtAct = helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
- aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
-}
-
-//! [8]
-void MainWindow::createStatusBar()
-{
- statusBar()->showMessage(tr("Ready"));
-}
-//! [8]
-
-//! [9]
-void MainWindow::createDockWindows()
-{
- QDockWidget *dock = new QDockWidget(tr("Customers"), this);
- dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
- customerList = new QListWidget(dock);
- customerList->addItems(QStringList()
- << "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
- << "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
- << "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
- << "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
- << "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
- << "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
- dock->setWidget(customerList);
- addDockWidget(Qt::RightDockWidgetArea, dock);
- viewMenu->addAction(dock->toggleViewAction());
-
- dock = new QDockWidget(tr("Paragraphs"), this);
- paragraphsList = new QListWidget(dock);
- paragraphsList->addItems(QStringList()
- << "Thank you for your payment which we have received today."
- << "Your order has been dispatched and should be with you "
- "within 28 days."
- << "We have dispatched those items that were in stock. The "
- "rest of your order will be dispatched once all the "
- "remaining items have arrived at our warehouse. No "
- "additional shipping charges will be made."
- << "You made a small overpayment (less than $5) which we "
- "will keep on account for you, or return at your request."
- << "You made a small underpayment (less than $1), but we have "
- "sent your order anyway. We'll add this underpayment to "
- "your next bill."
- << "Unfortunately you did not send enough money. Please remit "
- "an additional $. Your order will be dispatched as soon as "
- "the complete amount has been received."
- << "You made an overpayment (more than $5). Do you wish to "
- "buy more items, or should we return the excess to you?");
- dock->setWidget(paragraphsList);
- addDockWidget(Qt::RightDockWidgetArea, dock);
- viewMenu->addAction(dock->toggleViewAction());
-
- connect(customerList, &QListWidget::currentTextChanged,
- this, &MainWindow::insertCustomer);
- connect(paragraphsList, &QListWidget::currentTextChanged,
- this, &MainWindow::addParagraph);
-}
-//! [9]
diff --git a/examples/widgets/mainwindows/dockwidgets/mainwindow.h b/examples/widgets/mainwindows/dockwidgets/mainwindow.h
deleted file mode 100644
index 67890e8a61..0000000000
--- a/examples/widgets/mainwindows/dockwidgets/mainwindow.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QListWidget;
-class QMenu;
-class QTextEdit;
-QT_END_NAMESPACE
-
-//! [0]
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
-private slots:
- void newLetter();
- void save();
- void print();
- void undo();
- void about();
- void insertCustomer(const QString &customer);
- void addParagraph(const QString &paragraph);
-
-private:
- void createActions();
- void createStatusBar();
- void createDockWindows();
-
- QTextEdit *textEdit;
- QListWidget *customerList;
- QListWidget *paragraphsList;
-
- QMenu *viewMenu;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/mainwindows/mainwindow/CMakeLists.txt b/examples/widgets/mainwindows/mainwindow/CMakeLists.txt
deleted file mode 100644
index 0924c24b8f..0000000000
--- a/examples/widgets/mainwindows/mainwindow/CMakeLists.txt
+++ /dev/null
@@ -1,54 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(mainwindow LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/mainwindows/mainwindow")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(mainwindow
- colorswatch.cpp colorswatch.h
- main.cpp
- mainwindow.cpp mainwindow.h
- toolbar.cpp toolbar.h
-)
-
-set_target_properties(mainwindow PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(mainwindow PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(mainwindow_resource_files
- "qt.png"
- "titlebarCenter.png"
- "titlebarLeft.png"
- "titlebarRight.png"
-)
-
-qt_add_resources(mainwindow "mainwindow"
- PREFIX
- "/res"
- FILES
- ${mainwindow_resource_files}
-)
-
-install(TARGETS mainwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
deleted file mode 100644
index 678f00054c..0000000000
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
+++ /dev/null
@@ -1,685 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "colorswatch.h"
-
-#include <QActionGroup>
-#include <QtEvents>
-#include <QFrame>
-#include <QMainWindow>
-#include <QMenu>
-#include <QPainter>
-#include <QImage>
-#include <QColor>
-#include <QDialog>
-#include <QDialogButtonBox>
-#include <QGridLayout>
-#include <QSignalBlocker>
-#include <QSpinBox>
-#include <QLabel>
-#include <QPainterPath>
-#include <QPushButton>
-#include <QHBoxLayout>
-#include <QBitmap>
-#include <QtDebug>
-
-#undef DEBUG_SIZEHINTS
-
-QColor bgColorForName(const QString &name)
-{
- if (name == "Black")
- return QColor("#D8D8D8");
- if (name == "White")
- return QColor("#F1F1F1");
- if (name == "Red")
- return QColor("#F1D8D8");
- if (name == "Green")
- return QColor("#D8E4D8");
- if (name == "Blue")
- return QColor("#D8D8F1");
- if (name == "Yellow")
- return QColor("#F1F0D8");
- return QColor(name).lighter(110);
-}
-
-QColor fgColorForName(const QString &name)
-{
- if (name == "Black")
- return QColor("#6C6C6C");
- if (name == "White")
- return QColor("#F8F8F8");
- if (name == "Red")
- return QColor("#F86C6C");
- if (name == "Green")
- return QColor("#6CB26C");
- if (name == "Blue")
- return QColor("#6C6CF8");
- if (name == "Yellow")
- return QColor("#F8F76C");
- return QColor(name);
-}
-
-class ColorDock : public QFrame
-{
- Q_OBJECT
-public:
- explicit ColorDock(const QString &c, QWidget *parent);
-
- QSize sizeHint() const override { return szHint; }
- QSize minimumSizeHint() const override { return minSzHint; }
-
- void setCustomSizeHint(const QSize &size);
-
-public slots:
- void changeSizeHints();
-
-protected:
- void paintEvent(QPaintEvent *) override;
-
-private:
- const QString color;
- QSize szHint;
- QSize minSzHint;
-};
-
-ColorDock::ColorDock(const QString &c, QWidget *parent)
- : QFrame(parent)
- , color(c)
- , szHint(-1, -1)
- , minSzHint(125, 75)
-{
- QFont font = this->font();
- font.setPointSize(8);
- setFont(font);
-}
-
-void ColorDock::paintEvent(QPaintEvent *)
-{
- QPainter p(this);
- p.setRenderHint(QPainter::Antialiasing);
- p.fillRect(rect(), bgColorForName(color));
-
- p.save();
-
- extern void render_qt_text(QPainter *, int, int, const QColor &);
- render_qt_text(&p, width(), height(), fgColorForName(color));
-
- p.restore();
-
-#ifdef DEBUG_SIZEHINTS
- p.setRenderHint(QPainter::Antialiasing, false);
-
- QSize sz = size();
- QSize szHint = sizeHint();
- QSize minSzHint = minimumSizeHint();
- QSize maxSz = maximumSize();
- QString text = QString::fromLatin1("sz: %1x%2\nszHint: %3x%4\nminSzHint: %5x%6\n"
- "maxSz: %8x%9")
- .arg(sz.width()).arg(sz.height())
- .arg(szHint.width()).arg(szHint.height())
- .arg(minSzHint.width()).arg(minSzHint.height())
- .arg(maxSz.width()).arg(maxSz.height());
-
- QRect r = fontMetrics().boundingRect(rect(), Qt::AlignLeft|Qt::AlignTop, text);
- r.adjust(-2, -2, 1, 1);
- p.translate(4, 4);
- QColor bg = Qt::yellow;
- bg.setAlpha(120);
- p.setBrush(bg);
- p.setPen(Qt::black);
- p.drawRect(r);
- p.drawText(rect(), Qt::AlignLeft|Qt::AlignTop, text);
-#endif // DEBUG_SIZEHINTS
-}
-
-static QSpinBox *createSpinBox(int value, QWidget *parent, int max = 1000)
-{
- QSpinBox *result = new QSpinBox(parent);
- result->setMinimum(-1);
- result->setMaximum(max);
- result->setValue(value);
- return result;
-}
-
-void ColorDock::changeSizeHints()
-{
- QDialog dialog(this);
- dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
- dialog.setWindowTitle(color);
-
- QVBoxLayout *topLayout = new QVBoxLayout(&dialog);
-
- QGridLayout *inputLayout = new QGridLayout();
- topLayout->addLayout(inputLayout);
-
- inputLayout->addWidget(new QLabel(tr("Size Hint:"), &dialog), 0, 0);
- inputLayout->addWidget(new QLabel(tr("Min Size Hint:"), &dialog), 1, 0);
- inputLayout->addWidget(new QLabel(tr("Max Size:"), &dialog), 2, 0);
- inputLayout->addWidget(new QLabel(tr("Dock Widget Max Size:"), &dialog), 3, 0);
-
- QSpinBox *szHintW = createSpinBox(szHint.width(), &dialog);
- inputLayout->addWidget(szHintW, 0, 1);
- QSpinBox *szHintH = createSpinBox(szHint.height(), &dialog);
- inputLayout->addWidget(szHintH, 0, 2);
-
- QSpinBox *minSzHintW = createSpinBox(minSzHint.width(), &dialog);
- inputLayout->addWidget(minSzHintW, 1, 1);
- QSpinBox *minSzHintH = createSpinBox(minSzHint.height(), &dialog);
- inputLayout->addWidget(minSzHintH, 1, 2);
-
- QSize maxSz = maximumSize();
- QSpinBox *maxSzW = createSpinBox(maxSz.width(), &dialog, QWIDGETSIZE_MAX);
- inputLayout->addWidget(maxSzW, 2, 1);
- QSpinBox *maxSzH = createSpinBox(maxSz.height(), &dialog, QWIDGETSIZE_MAX);
- inputLayout->addWidget(maxSzH, 2, 2);
-
- QSize dwMaxSz = parentWidget()->maximumSize();
- QSpinBox *dwMaxSzW = createSpinBox(dwMaxSz.width(), &dialog, QWIDGETSIZE_MAX);
- inputLayout->addWidget(dwMaxSzW, 3, 1);
- QSpinBox *dwMaxSzH = createSpinBox(dwMaxSz.height(), &dialog, QWIDGETSIZE_MAX);
- inputLayout->addWidget(dwMaxSzH, 3, 2);
-
- inputLayout->setColumnStretch(1, 1);
- inputLayout->setColumnStretch(2, 1);
-
- topLayout->addStretch();
-
- QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
- connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
- connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
-
- topLayout->addWidget(buttonBox);
-
- if (dialog.exec() != QDialog::Accepted)
- return;
-
- szHint = QSize(szHintW->value(), szHintH->value());
- minSzHint = QSize(minSzHintW->value(), minSzHintH->value());
- maxSz = QSize(maxSzW->value(), maxSzH->value());
- setMaximumSize(maxSz);
- dwMaxSz = QSize(dwMaxSzW->value(), dwMaxSzH->value());
- parentWidget()->setMaximumSize(dwMaxSz);
- updateGeometry();
- update();
-}
-
-void ColorDock::setCustomSizeHint(const QSize &size)
-{
- if (szHint != size) {
- szHint = size;
- updateGeometry();
- }
-}
-
-ColorSwatch::ColorSwatch(const QString &colorName, QMainWindow *parent, Qt::WindowFlags flags)
- : QDockWidget(parent, flags), mainWindow(parent)
-{
- setObjectName(colorName + QLatin1String(" Dock Widget"));
- setWindowTitle(objectName() + QLatin1String(" [*]"));
-
- ColorDock *swatch = new ColorDock(colorName, this);
- swatch->setFrameStyle(QFrame::Box | QFrame::Sunken);
-
- setWidget(swatch);
-
- closableAction = new QAction(tr("Closable"), this);
- closableAction->setCheckable(true);
- connect(closableAction, &QAction::triggered, this, &ColorSwatch::changeClosable);
-
- movableAction = new QAction(tr("Movable"), this);
- movableAction->setCheckable(true);
- connect(movableAction, &QAction::triggered, this, &ColorSwatch::changeMovable);
-
- floatableAction = new QAction(tr("Floatable"), this);
- floatableAction->setCheckable(true);
- connect(floatableAction, &QAction::triggered, this, &ColorSwatch::changeFloatable);
-
- verticalTitleBarAction = new QAction(tr("Vertical title bar"), this);
- verticalTitleBarAction->setCheckable(true);
- connect(verticalTitleBarAction, &QAction::triggered,
- this, &ColorSwatch::changeVerticalTitleBar);
-
- floatingAction = new QAction(tr("Floating"), this);
- floatingAction->setCheckable(true);
- connect(floatingAction, &QAction::triggered, this, &ColorSwatch::changeFloating);
-
- allowedAreasActions = new QActionGroup(this);
- allowedAreasActions->setExclusive(false);
-
- allowLeftAction = new QAction(tr("Allow on Left"), this);
- allowLeftAction->setCheckable(true);
- connect(allowLeftAction, &QAction::triggered, this, &ColorSwatch::allowLeft);
-
- allowRightAction = new QAction(tr("Allow on Right"), this);
- allowRightAction->setCheckable(true);
- connect(allowRightAction, &QAction::triggered, this, &ColorSwatch::allowRight);
-
- allowTopAction = new QAction(tr("Allow on Top"), this);
- allowTopAction->setCheckable(true);
- connect(allowTopAction, &QAction::triggered, this, &ColorSwatch::allowTop);
-
- allowBottomAction = new QAction(tr("Allow on Bottom"), this);
- allowBottomAction->setCheckable(true);
- connect(allowBottomAction, &QAction::triggered, this, &ColorSwatch::allowBottom);
-
- allowedAreasActions->addAction(allowLeftAction);
- allowedAreasActions->addAction(allowRightAction);
- allowedAreasActions->addAction(allowTopAction);
- allowedAreasActions->addAction(allowBottomAction);
-
- areaActions = new QActionGroup(this);
- areaActions->setExclusive(true);
-
- leftAction = new QAction(tr("Place on Left") , this);
- leftAction->setCheckable(true);
- connect(leftAction, &QAction::triggered, this, &ColorSwatch::placeLeft);
-
- rightAction = new QAction(tr("Place on Right") , this);
- rightAction->setCheckable(true);
- connect(rightAction, &QAction::triggered, this, &ColorSwatch::placeRight);
-
- topAction = new QAction(tr("Place on Top") , this);
- topAction->setCheckable(true);
- connect(topAction, &QAction::triggered, this, &ColorSwatch::placeTop);
-
- bottomAction = new QAction(tr("Place on Bottom") , this);
- bottomAction->setCheckable(true);
- connect(bottomAction, &QAction::triggered, this, &ColorSwatch::placeBottom);
-
- areaActions->addAction(leftAction);
- areaActions->addAction(rightAction);
- areaActions->addAction(topAction);
- areaActions->addAction(bottomAction);
-
- connect(movableAction, &QAction::triggered, areaActions, &QActionGroup::setEnabled);
-
- connect(movableAction, &QAction::triggered, allowedAreasActions, &QActionGroup::setEnabled);
-
- connect(floatableAction, &QAction::triggered, floatingAction, &QAction::setEnabled);
-
- connect(floatingAction, &QAction::triggered, floatableAction, &QAction::setDisabled);
- connect(movableAction, &QAction::triggered, floatableAction, &QAction::setEnabled);
-
- tabMenu = new QMenu(this);
- tabMenu->setTitle(tr("Tab into"));
- connect(tabMenu, &QMenu::triggered, this, &ColorSwatch::tabInto);
-
- splitHMenu = new QMenu(this);
- splitHMenu->setTitle(tr("Split horizontally into"));
- connect(splitHMenu, &QMenu::triggered, this, &ColorSwatch::splitInto);
-
- splitVMenu = new QMenu(this);
- splitVMenu->setTitle(tr("Split vertically into"));
- connect(splitVMenu, &QMenu::triggered, this, &ColorSwatch::splitInto);
-
- QAction *windowModifiedAction = new QAction(tr("Modified"), this);
- windowModifiedAction->setCheckable(true);
- windowModifiedAction->setChecked(false);
- connect(windowModifiedAction, &QAction::toggled, this, &QWidget::setWindowModified);
-
- menu = new QMenu(colorName, this);
- menu->addAction(toggleViewAction());
- menu->addAction(tr("Raise"), this, &QWidget::raise);
- menu->addAction(tr("Change Size Hints..."), swatch, &ColorDock::changeSizeHints);
-
- menu->addSeparator();
- menu->addAction(closableAction);
- menu->addAction(movableAction);
- menu->addAction(floatableAction);
- menu->addAction(floatingAction);
- menu->addAction(verticalTitleBarAction);
- menu->addSeparator();
- menu->addActions(allowedAreasActions->actions());
- menu->addSeparator();
- menu->addActions(areaActions->actions());
- menu->addSeparator();
- menu->addMenu(splitHMenu);
- menu->addMenu(splitVMenu);
- menu->addMenu(tabMenu);
- menu->addSeparator();
- menu->addAction(windowModifiedAction);
-
- connect(menu, &QMenu::aboutToShow, this, &ColorSwatch::updateContextMenu);
-
- if (colorName == QLatin1String("Black")) {
- leftAction->setShortcut(Qt::CTRL | Qt::Key_W);
- rightAction->setShortcut(Qt::CTRL | Qt::Key_E);
- toggleViewAction()->setShortcut(Qt::CTRL | Qt::Key_R);
- }
-}
-
-void ColorSwatch::updateContextMenu()
-{
- const Qt::DockWidgetArea area = mainWindow->dockWidgetArea(this);
- const Qt::DockWidgetAreas areas = allowedAreas();
-
- closableAction->setChecked(features() & QDockWidget::DockWidgetClosable);
- if (windowType() == Qt::Drawer) {
- floatableAction->setEnabled(false);
- floatingAction->setEnabled(false);
- movableAction->setEnabled(false);
- verticalTitleBarAction->setChecked(false);
- } else {
- floatableAction->setChecked(features() & QDockWidget::DockWidgetFloatable);
- floatingAction->setChecked(isWindow());
- // done after floating, to get 'floatable' correctly initialized
- movableAction->setChecked(features() & QDockWidget::DockWidgetMovable);
- verticalTitleBarAction
- ->setChecked(features() & QDockWidget::DockWidgetVerticalTitleBar);
- }
-
- allowLeftAction->setChecked(isAreaAllowed(Qt::LeftDockWidgetArea));
- allowRightAction->setChecked(isAreaAllowed(Qt::RightDockWidgetArea));
- allowTopAction->setChecked(isAreaAllowed(Qt::TopDockWidgetArea));
- allowBottomAction->setChecked(isAreaAllowed(Qt::BottomDockWidgetArea));
-
- if (allowedAreasActions->isEnabled()) {
- allowLeftAction->setEnabled(area != Qt::LeftDockWidgetArea);
- allowRightAction->setEnabled(area != Qt::RightDockWidgetArea);
- allowTopAction->setEnabled(area != Qt::TopDockWidgetArea);
- allowBottomAction->setEnabled(area != Qt::BottomDockWidgetArea);
- }
-
- {
- const QSignalBlocker blocker(leftAction);
- leftAction->setChecked(area == Qt::LeftDockWidgetArea);
- }
- {
- const QSignalBlocker blocker(rightAction);
- rightAction->setChecked(area == Qt::RightDockWidgetArea);
- }
- {
- const QSignalBlocker blocker(topAction);
- topAction->setChecked(area == Qt::TopDockWidgetArea);
- }
- {
- const QSignalBlocker blocker(bottomAction);
- bottomAction->setChecked(area == Qt::BottomDockWidgetArea);
- }
-
- if (areaActions->isEnabled()) {
- leftAction->setEnabled(areas & Qt::LeftDockWidgetArea);
- rightAction->setEnabled(areas & Qt::RightDockWidgetArea);
- topAction->setEnabled(areas & Qt::TopDockWidgetArea);
- bottomAction->setEnabled(areas & Qt::BottomDockWidgetArea);
- }
-
- tabMenu->clear();
- splitHMenu->clear();
- splitVMenu->clear();
- const QList<ColorSwatch *> dockList = mainWindow->findChildren<ColorSwatch*>();
- for (const ColorSwatch *dock : dockList) {
- tabMenu->addAction(dock->objectName());
- splitHMenu->addAction(dock->objectName());
- splitVMenu->addAction(dock->objectName());
- }
-}
-
-static ColorSwatch *findByName(const QMainWindow *mainWindow, const QString &name)
-{
- const QList<ColorSwatch *> dockList = mainWindow->findChildren<ColorSwatch*>();
- for (ColorSwatch *dock : dockList) {
- if (name == dock->objectName())
- return dock;
- }
- return nullptr;
-}
-
-void ColorSwatch::splitInto(QAction *action)
-{
- ColorSwatch *target = findByName(mainWindow, action->text());
- if (!target)
- return;
-
- const Qt::Orientation o = action->parent() == splitHMenu
- ? Qt::Horizontal : Qt::Vertical;
- mainWindow->splitDockWidget(target, this, o);
-}
-
-void ColorSwatch::tabInto(QAction *action)
-{
- if (ColorSwatch *target = findByName(mainWindow, action->text()))
- mainWindow->tabifyDockWidget(target, this);
-}
-
-#ifndef QT_NO_CONTEXTMENU
-void ColorSwatch::contextMenuEvent(QContextMenuEvent *event)
-{
- event->accept();
- menu->popup(event->globalPos());
-}
-#endif // QT_NO_CONTEXTMENU
-
-void ColorSwatch::resizeEvent(QResizeEvent *e)
-{
- if (BlueTitleBar *btb = qobject_cast<BlueTitleBar*>(titleBarWidget()))
- btb->updateMask();
-
- QDockWidget::resizeEvent(e);
-}
-
-void ColorSwatch::allow(Qt::DockWidgetArea area, bool a)
-{
- Qt::DockWidgetAreas areas = allowedAreas();
- areas = a ? areas | area : areas & ~area;
- setAllowedAreas(areas);
-
- if (areaActions->isEnabled()) {
- leftAction->setEnabled(areas & Qt::LeftDockWidgetArea);
- rightAction->setEnabled(areas & Qt::RightDockWidgetArea);
- topAction->setEnabled(areas & Qt::TopDockWidgetArea);
- bottomAction->setEnabled(areas & Qt::BottomDockWidgetArea);
- }
-}
-
-void ColorSwatch::place(Qt::DockWidgetArea area, bool p)
-{
- if (!p)
- return;
-
- mainWindow->addDockWidget(area, this);
-
- if (allowedAreasActions->isEnabled()) {
- allowLeftAction->setEnabled(area != Qt::LeftDockWidgetArea);
- allowRightAction->setEnabled(area != Qt::RightDockWidgetArea);
- allowTopAction->setEnabled(area != Qt::TopDockWidgetArea);
- allowBottomAction->setEnabled(area != Qt::BottomDockWidgetArea);
- }
-}
-
-void ColorSwatch::setCustomSizeHint(const QSize &size)
-{
- if (ColorDock *dock = qobject_cast<ColorDock*>(widget()))
- dock->setCustomSizeHint(size);
-}
-
-void ColorSwatch::changeClosable(bool on)
-{ setFeatures(on ? features() | DockWidgetClosable : features() & ~DockWidgetClosable); }
-
-void ColorSwatch::changeMovable(bool on)
-{ setFeatures(on ? features() | DockWidgetMovable : features() & ~DockWidgetMovable); }
-
-void ColorSwatch::changeFloatable(bool on)
-{ setFeatures(on ? features() | DockWidgetFloatable : features() & ~DockWidgetFloatable); }
-
-void ColorSwatch::changeFloating(bool floating)
-{ setFloating(floating); }
-
-void ColorSwatch::allowLeft(bool a)
-{ allow(Qt::LeftDockWidgetArea, a); }
-
-void ColorSwatch::allowRight(bool a)
-{ allow(Qt::RightDockWidgetArea, a); }
-
-void ColorSwatch::allowTop(bool a)
-{ allow(Qt::TopDockWidgetArea, a); }
-
-void ColorSwatch::allowBottom(bool a)
-{ allow(Qt::BottomDockWidgetArea, a); }
-
-void ColorSwatch::placeLeft(bool p)
-{ place(Qt::LeftDockWidgetArea, p); }
-
-void ColorSwatch::placeRight(bool p)
-{ place(Qt::RightDockWidgetArea, p); }
-
-void ColorSwatch::placeTop(bool p)
-{ place(Qt::TopDockWidgetArea, p); }
-
-void ColorSwatch::placeBottom(bool p)
-{ place(Qt::BottomDockWidgetArea, p); }
-
-void ColorSwatch::changeVerticalTitleBar(bool on)
-{
- setFeatures(on ? features() | DockWidgetVerticalTitleBar
- : features() & ~DockWidgetVerticalTitleBar);
-}
-
-QSize BlueTitleBar::minimumSizeHint() const
-{
- QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
- Q_ASSERT(dw);
- QSize result(leftPm.width() + rightPm.width(), centerPm.height());
- if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar)
- result.transpose();
- return result;
-}
-
-BlueTitleBar::BlueTitleBar(QWidget *parent)
- : QWidget(parent)
- , leftPm(QPixmap(":/res/titlebarLeft.png"))
- , centerPm(QPixmap(":/res/titlebarCenter.png"))
- , rightPm(QPixmap(":/res/titlebarRight.png"))
-{
-}
-
-void BlueTitleBar::paintEvent(QPaintEvent*)
-{
- QPainter painter(this);
- QRect rect = this->rect();
-
- QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
- Q_ASSERT(dw);
-
- if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
- QSize s = rect.size();
- s.transpose();
- rect.setSize(s);
-
- painter.translate(rect.left(), rect.top() + rect.width());
- painter.rotate(-90);
- painter.translate(-rect.left(), -rect.top());
- }
-
- painter.drawPixmap(rect.topLeft(), leftPm);
- painter.drawPixmap(rect.topRight() - QPoint(rightPm.width() - 1, 0), rightPm);
- QBrush brush(centerPm);
- painter.fillRect(rect.left() + leftPm.width(), rect.top(),
- rect.width() - leftPm.width() - rightPm.width(),
- centerPm.height(), centerPm);
-}
-
-void BlueTitleBar::mouseReleaseEvent(QMouseEvent *event)
-{
- QPoint pos = event->position().toPoint();
-
- QRect rect = this->rect();
-
- QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
- Q_ASSERT(dw);
-
- if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
- QPoint p = pos;
- pos.setX(rect.left() + rect.bottom() - p.y());
- pos.setY(rect.top() + p.x() - rect.left());
-
- QSize s = rect.size();
- s.transpose();
- rect.setSize(s);
- }
-
- const int buttonRight = 7;
- const int buttonWidth = 20;
- int right = rect.right() - pos.x();
- int button = (right - buttonRight)/buttonWidth;
- switch (button) {
- case 0:
- event->accept();
- dw->close();
- break;
- case 1:
- event->accept();
- dw->setFloating(!dw->isFloating());
- break;
- case 2: {
- event->accept();
- QDockWidget::DockWidgetFeatures features = dw->features();
- if (features & QDockWidget::DockWidgetVerticalTitleBar)
- features &= ~QDockWidget::DockWidgetVerticalTitleBar;
- else
- features |= QDockWidget::DockWidgetVerticalTitleBar;
- dw->setFeatures(features);
- break;
- }
- default:
- event->ignore();
- break;
- }
-}
-
-void BlueTitleBar::updateMask()
-{
- QDockWidget *dw = qobject_cast<QDockWidget*>(parent());
- Q_ASSERT(dw);
-
- QRect rect = dw->rect();
- QBitmap bitmap(dw->size());
-
- {
- QPainter painter(&bitmap);
-
- // initialize to transparent
- painter.fillRect(rect, Qt::color0);
-
- QRect contents = rect;
- contents.setTopLeft(geometry().bottomLeft());
- contents.setRight(geometry().right());
- contents.setBottom(contents.bottom()-y());
- painter.fillRect(contents, Qt::color1);
-
- // let's paint the titlebar
- QRect titleRect = this->geometry();
-
- if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
- QSize s = rect.size();
- s.transpose();
- rect.setSize(s);
-
- QSize s2 = size();
- s2.transpose();
- titleRect.setSize(s2);
-
- painter.translate(rect.left(), rect.top() + rect.width());
- painter.rotate(-90);
- painter.translate(-rect.left(), -rect.top());
- }
-
- contents.setTopLeft(titleRect.bottomLeft());
- contents.setRight(titleRect.right());
- contents.setBottom(rect.bottom()-y());
-
- QRect rect = titleRect;
-
- painter.drawPixmap(rect.topLeft(), leftPm.mask());
- painter.fillRect(rect.left() + leftPm.width(), rect.top(),
- rect.width() - leftPm.width() - rightPm.width(),
- centerPm.height(), Qt::color1);
- painter.drawPixmap(rect.topRight() - QPoint(rightPm.width() - 1, 0), rightPm.mask());
-
- painter.fillRect(contents, Qt::color1);
- }
-
- dw->setMask(bitmap);
-}
-
-#include "colorswatch.moc"
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h
deleted file mode 100644
index 5b144bd428..0000000000
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.h
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef COLORSWATCH_H
-#define COLORSWATCH_H
-
-#include <QDockWidget>
-
-QT_FORWARD_DECLARE_CLASS(QAction)
-QT_FORWARD_DECLARE_CLASS(QActionGroup)
-QT_FORWARD_DECLARE_CLASS(QMenu)
-
-class ColorSwatch : public QDockWidget
-{
- Q_OBJECT
-
-public:
- explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = { });
-
- void setCustomSizeHint(const QSize &size);
- QMenu *colorSwatchMenu() const { return menu; }
-
-protected:
-#ifndef QT_NO_CONTEXTMENU
- void contextMenuEvent(QContextMenuEvent *event) override;
-#endif // QT_NO_CONTEXTMENU
- void resizeEvent(QResizeEvent *e) override;
-
-private slots:
- void changeClosable(bool on);
- void changeMovable(bool on);
- void changeFloatable(bool on);
- void changeFloating(bool on);
- void changeVerticalTitleBar(bool on);
- void updateContextMenu();
-
- void allowLeft(bool a);
- void allowRight(bool a);
- void allowTop(bool a);
- void allowBottom(bool a);
-
- void placeLeft(bool p);
- void placeRight(bool p);
- void placeTop(bool p);
- void placeBottom(bool p);
-
- void splitInto(QAction *action);
- void tabInto(QAction *action);
-
-private:
- void allow(Qt::DockWidgetArea area, bool allow);
- void place(Qt::DockWidgetArea area, bool place);
-
- QAction *closableAction;
- QAction *movableAction;
- QAction *floatableAction;
- QAction *floatingAction;
- QAction *verticalTitleBarAction;
-
- QActionGroup *allowedAreasActions;
- QAction *allowLeftAction;
- QAction *allowRightAction;
- QAction *allowTopAction;
- QAction *allowBottomAction;
-
- QActionGroup *areaActions;
- QAction *leftAction;
- QAction *rightAction;
- QAction *topAction;
- QAction *bottomAction;
-
- QMenu *tabMenu;
- QMenu *splitHMenu;
- QMenu *splitVMenu;
- QMenu *menu;
-
- QMainWindow *mainWindow;
-};
-
-class BlueTitleBar : public QWidget
-{
- Q_OBJECT
-public:
- explicit BlueTitleBar(QWidget *parent = nullptr);
-
- QSize sizeHint() const override { return minimumSizeHint(); }
- QSize minimumSizeHint() const override;
-
-protected:
- void paintEvent(QPaintEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
-
-public slots:
- void updateMask();
-
-private:
- const QPixmap leftPm;
- const QPixmap centerPm;
- const QPixmap rightPm;
-};
-
-#endif // COLORSWATCH_H
diff --git a/examples/widgets/mainwindows/mainwindow/main.cpp b/examples/widgets/mainwindows/mainwindow/main.cpp
deleted file mode 100644
index a64d2f5843..0000000000
--- a/examples/widgets/mainwindows/mainwindow/main.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-
-#include <QApplication>
-#include <QPainterPath>
-#include <QPainter>
-#include <QMap>
-#include <QDebug>
-
-void render_qt_text(QPainter *painter, int w, int h, const QColor &color)
-{
- QPainterPath path;
- path.moveTo(-0.083695, 0.283849);
- path.cubicTo(-0.049581, 0.349613, -0.012720, 0.397969, 0.026886, 0.428917);
- path.cubicTo(0.066493, 0.459865, 0.111593, 0.477595, 0.162186, 0.482108);
- path.lineTo(0.162186, 0.500000);
- path.cubicTo(0.115929, 0.498066, 0.066565, 0.487669, 0.014094, 0.468810);
- path.cubicTo(-0.038378, 0.449952, -0.088103, 0.423839, -0.135082, 0.390474);
- path.cubicTo(-0.182061, 0.357108, -0.222608, 0.321567, -0.256722, 0.283849);
- path.cubicTo(-0.304712, 0.262250, -0.342874, 0.239362, -0.371206, 0.215184);
- path.cubicTo(-0.411969, 0.179078, -0.443625, 0.134671, -0.466175, 0.081963);
- path.cubicTo(-0.488725, 0.029255, -0.500000, -0.033043, -0.500000, -0.104932);
- path.cubicTo(-0.500000, -0.218407, -0.467042, -0.312621, -0.401127, -0.387573);
- path.cubicTo(-0.335212, -0.462524, -0.255421, -0.500000, -0.161752, -0.500000);
- path.cubicTo(-0.072998, -0.500000, 0.003903, -0.462444, 0.068951, -0.387331);
- path.cubicTo(0.133998, -0.312218, 0.166522, -0.217440, 0.166522, -0.102998);
- path.cubicTo(0.166522, -0.010155, 0.143394, 0.071325, 0.097138, 0.141441);
- path.cubicTo(0.050882, 0.211557, -0.009396, 0.259026, -0.083695, 0.283849);
- path.moveTo(-0.167823, -0.456963);
- path.cubicTo(-0.228823, -0.456963, -0.277826, -0.432624, -0.314831, -0.383946);
- path.cubicTo(-0.361665, -0.323340, -0.385082, -0.230335, -0.385082, -0.104932);
- path.cubicTo(-0.385082, 0.017569, -0.361376, 0.112025, -0.313964, 0.178433);
- path.cubicTo(-0.277248, 0.229368, -0.228534, 0.254836, -0.167823, 0.254836);
- path.cubicTo(-0.105088, 0.254836, -0.054496, 0.229368, -0.016045, 0.178433);
- path.cubicTo(0.029055, 0.117827, 0.051605, 0.028691, 0.051605, -0.088975);
- path.cubicTo(0.051605, -0.179562, 0.039318, -0.255803, 0.014744, -0.317698);
- path.cubicTo(-0.004337, -0.365409, -0.029705, -0.400548, -0.061362, -0.423114);
- path.cubicTo(-0.093018, -0.445680, -0.128505, -0.456963, -0.167823, -0.456963);
- path.moveTo(0.379011, -0.404739);
- path.lineTo(0.379011, -0.236460);
- path.lineTo(0.486123, -0.236460);
- path.lineTo(0.486123, -0.197292);
- path.lineTo(0.379011, -0.197292);
- path.lineTo(0.379011, 0.134913);
- path.cubicTo(0.379011, 0.168117, 0.383276, 0.190442, 0.391804, 0.201886);
- path.cubicTo(0.400332, 0.213330, 0.411246, 0.219052, 0.424545, 0.219052);
- path.cubicTo(0.435531, 0.219052, 0.446227, 0.215264, 0.456635, 0.207689);
- path.cubicTo(0.467042, 0.200113, 0.474993, 0.188910, 0.480486, 0.174081);
- path.lineTo(0.500000, 0.174081);
- path.cubicTo(0.488436, 0.210509, 0.471957, 0.237911, 0.450564, 0.256286);
- path.cubicTo(0.429170, 0.274662, 0.407054, 0.283849, 0.384215, 0.283849);
- path.cubicTo(0.368893, 0.283849, 0.353859, 0.279094, 0.339115, 0.269584);
- path.cubicTo(0.324371, 0.260074, 0.313530, 0.246534, 0.306592, 0.228965);
- path.cubicTo(0.299653, 0.211396, 0.296184, 0.184075, 0.296184, 0.147002);
- path.lineTo(0.296184, -0.197292);
- path.lineTo(0.223330, -0.197292);
- path.lineTo(0.223330, -0.215667);
- path.cubicTo(0.241833, -0.224049, 0.260697, -0.237992, 0.279922, -0.257495);
- path.cubicTo(0.299147, -0.276999, 0.316276, -0.300129, 0.331310, -0.326886);
- path.cubicTo(0.338826, -0.341070, 0.349523, -0.367021, 0.363400, -0.404739);
- path.lineTo(0.379011, -0.404739);
- path.moveTo(-0.535993, 0.275629);
-
- painter->translate(w / 2, h / 2);
- double scale = qMin(w, h) * 8 / 10.0;
- painter->scale(scale, scale);
-
- painter->setRenderHint(QPainter::Antialiasing);
-
- painter->save();
- painter->translate(.1, .1);
- painter->fillPath(path, QColor(0, 0, 0, 63));
- painter->restore();
-
- painter->setBrush(color);
- painter->setPen(QPen(Qt::black, 0.02, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin));
- painter->drawPath(path);
-}
-
-static void usage()
-{
- qWarning() << "Usage: mainwindow [-SizeHint<color> <width>x<height>] ...";
- exit(1);
-}
-
-enum ParseCommandLineArgumentsResult {
- CommandLineArgumentsOk,
- CommandLineArgumentsError,
- HelpRequested
-};
-
-static ParseCommandLineArgumentsResult
- parseCustomSizeHints(const QStringList &arguments, MainWindow::CustomSizeHintMap *result)
-{
- result->clear();
- const auto argumentCount = arguments.size();
- for (int i = 1; i < argumentCount; ++i) {
- const QString &arg = arguments.at(i);
- if (arg.startsWith(QLatin1String("-SizeHint"))) {
- const QString name = arg.mid(9);
- if (name.isEmpty())
- return CommandLineArgumentsError;
- if (++i == argumentCount)
- return CommandLineArgumentsError;
- const QStringView sizeStr{ arguments.at(i) };
- const auto idx = sizeStr.indexOf(QLatin1Char('x'));
- if (idx == -1)
- return CommandLineArgumentsError;
- bool ok;
- const int w = sizeStr.left(idx).toInt(&ok);
- if (!ok)
- return CommandLineArgumentsError;
- const int h = sizeStr.mid(idx + 1).toInt(&ok);
- if (!ok)
- return CommandLineArgumentsError;
- result->insert(name, QSize(w, h));
- } else if (arg == QLatin1String("-h") || arg == QLatin1String("--help")) {
- return HelpRequested;
- } else {
- return CommandLineArgumentsError;
- }
- }
-
- return CommandLineArgumentsOk;
-}
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
- MainWindow::CustomSizeHintMap customSizeHints;
- switch (parseCustomSizeHints(QCoreApplication::arguments(), &customSizeHints)) {
- case CommandLineArgumentsOk:
- break;
- case CommandLineArgumentsError:
- usage();
- return -1;
- case HelpRequested:
- usage();
- return 0;
- }
- MainWindow mainWin(customSizeHints);
- mainWin.resize(800, 600);
- mainWin.show();
- return app.exec();
-}
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
deleted file mode 100644
index 2f989ab97c..0000000000
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
+++ /dev/null
@@ -1,444 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "colorswatch.h"
-#include "toolbar.h"
-
-#include <QActionGroup>
-#include <QLayout>
-#include <QMenu>
-#include <QMenuBar>
-#include <QStatusBar>
-#include <QTextEdit>
-#include <QFile>
-#include <QDataStream>
-#include <QFileDialog>
-#include <QDialogButtonBox>
-#include <QMessageBox>
-#include <QApplication>
-#include <QPainter>
-#include <QMouseEvent>
-#include <QLineEdit>
-#include <QComboBox>
-#include <QLabel>
-#include <QPushButton>
-#include <QTextEdit>
-#include <QDebug>
-
-static const char message[] =
- "<p><b>Qt Main Window Example</b></p>"
-
- "<p>This is a demonstration of the QMainWindow, QToolBar and "
- "QDockWidget classes.</p>"
-
- "<p>The tool bar and dock widgets can be dragged around and rearranged "
- "using the mouse or via the menu.</p>"
-
- "<p>Each dock widget contains a colored frame and a context "
- "(right-click) menu.</p>"
-
-#ifdef Q_OS_MAC
- "<p>On OS X, the \"Black\" dock widget has been created as a "
- "<em>Drawer</em>, which is a special kind of QDockWidget.</p>"
-#endif
- ;
-
-Q_DECLARE_METATYPE(QDockWidget::DockWidgetFeatures)
-
-MainWindow::MainWindow(const CustomSizeHintMap &customSizeHints,
- QWidget *parent, Qt::WindowFlags flags)
- : QMainWindow(parent, flags)
-{
- Q_UNUSED(message);
- setObjectName("MainWindow");
- setWindowTitle("Qt Main Window Example");
-
- QTextEdit *center = new QTextEdit(this);
- center->setReadOnly(true);
- center->setMinimumSize(400, 205);
- setCentralWidget(center);
-
- setupToolBar();
- setupMenuBar();
- setupDockWidgets(customSizeHints);
-
- statusBar()->showMessage(tr("Status Bar"));
-}
-
-void MainWindow::actionTriggered(QAction *action)
-{
- qDebug("action '%s' triggered", action->text().toLocal8Bit().data());
-}
-
-void MainWindow::setupToolBar()
-{
-#ifdef Q_OS_MACOS
- 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);
- addToolBar(tb);
- }
-}
-
-void MainWindow::setupMenuBar()
-{
- QMenu *menu = menuBar()->addMenu(tr("&File"));
-
- menu->addAction(tr("Save layout..."), this, &MainWindow::saveLayout);
- menu->addAction(tr("Load layout..."), this, &MainWindow::loadLayout);
- menu->addAction(tr("Switch layout direction"),this, &MainWindow::switchLayoutDirection);
-
- menu->addSeparator();
- menu->addAction(tr("&Quit"), qApp, &QCoreApplication::quit);
-
- mainWindowMenu = menuBar()->addMenu(tr("Main window"));
-
- QAction *action = mainWindowMenu->addAction(tr("Animated docks"));
- action->setCheckable(true);
- action->setChecked(dockOptions() & AnimatedDocks);
- connect(action, &QAction::toggled, this, &MainWindow::setDockOptions);
-
- action = mainWindowMenu->addAction(tr("Allow nested docks"));
- action->setCheckable(true);
- action->setChecked(dockOptions() & AllowNestedDocks);
- connect(action, &QAction::toggled, this, &MainWindow::setDockOptions);
-
- action = mainWindowMenu->addAction(tr("Allow tabbed docks"));
- action->setCheckable(true);
- action->setChecked(dockOptions() & AllowTabbedDocks);
- connect(action, &QAction::toggled, this, &MainWindow::setDockOptions);
-
- action = mainWindowMenu->addAction(tr("Force tabbed docks"));
- action->setCheckable(true);
- action->setChecked(dockOptions() & ForceTabbedDocks);
- connect(action, &QAction::toggled, this, &MainWindow::setDockOptions);
-
- action = mainWindowMenu->addAction(tr("Vertical tabs"));
- action->setCheckable(true);
- action->setChecked(dockOptions() & VerticalTabs);
- connect(action, &QAction::toggled, this, &MainWindow::setDockOptions);
-
- action = mainWindowMenu->addAction(tr("Grouped dragging"));
- action->setCheckable(true);
- action->setChecked(dockOptions() & GroupedDragging);
- connect(action, &QAction::toggled, this, &MainWindow::setDockOptions);
-
- QMenu *toolBarMenu = menuBar()->addMenu(tr("Tool bars"));
- for (int i = 0; i < toolBars.count(); ++i)
- toolBarMenu->addMenu(toolBars.at(i)->toolbarMenu());
-
-#ifdef Q_OS_MACOS
- toolBarMenu->addSeparator();
-
- action = toolBarMenu->addAction(tr("Unified"));
- action->setCheckable(true);
- action->setChecked(unifiedTitleAndToolBarOnMac());
- connect(action, &QAction::toggled, this, &QMainWindow::setUnifiedTitleAndToolBarOnMac);
-#endif
-
- dockWidgetMenu = menuBar()->addMenu(tr("&Dock Widgets"));
-
- QMenu *aboutMenu = menuBar()->addMenu(tr("About"));
- QAction *aboutAct = aboutMenu->addAction(tr("&About"), this, &MainWindow::about);
- aboutAct->setStatusTip(tr("Show the application's About box"));
-
- QAction *aboutQtAct = aboutMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
- aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
-}
-
-void MainWindow::setDockOptions()
-{
- DockOptions opts;
- QList<QAction*> actions = mainWindowMenu->actions();
-
- if (actions.at(0)->isChecked())
- opts |= AnimatedDocks;
- if (actions.at(1)->isChecked())
- opts |= AllowNestedDocks;
- if (actions.at(2)->isChecked())
- opts |= AllowTabbedDocks;
- if (actions.at(3)->isChecked())
- opts |= ForceTabbedDocks;
- if (actions.at(4)->isChecked())
- opts |= VerticalTabs;
- if (actions.at(5)->isChecked())
- opts |= GroupedDragging;
-
- QMainWindow::setDockOptions(opts);
-}
-
-void MainWindow::saveLayout()
-{
- QString fileName
- = QFileDialog::getSaveFileName(this, tr("Save layout"));
- if (fileName.isEmpty())
- return;
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly)) {
- QString msg = tr("Failed to open %1\n%2")
- .arg(QDir::toNativeSeparators(fileName), file.errorString());
- QMessageBox::warning(this, tr("Error"), msg);
- return;
- }
-
- QByteArray geo_data = saveGeometry();
- QByteArray layout_data = saveState();
-
- bool ok = file.putChar((uchar)geo_data.size());
- if (ok)
- ok = file.write(geo_data) == geo_data.size();
- if (ok)
- ok = file.write(layout_data) == layout_data.size();
-
- if (!ok) {
- QString msg = tr("Error writing to %1\n%2")
- .arg(QDir::toNativeSeparators(fileName), file.errorString());
- QMessageBox::warning(this, tr("Error"), msg);
- return;
- }
-}
-
-void MainWindow::loadLayout()
-{
- QString fileName
- = QFileDialog::getOpenFileName(this, tr("Load layout"));
- if (fileName.isEmpty())
- return;
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly)) {
- QString msg = tr("Failed to open %1\n%2")
- .arg(QDir::toNativeSeparators(fileName), file.errorString());
- QMessageBox::warning(this, tr("Error"), msg);
- return;
- }
-
- uchar geo_size;
- QByteArray geo_data;
- QByteArray layout_data;
-
- bool ok = file.getChar((char*)&geo_size);
- if (ok) {
- geo_data = file.read(geo_size);
- ok = geo_data.size() == geo_size;
- }
- if (ok) {
- layout_data = file.readAll();
- ok = layout_data.size() > 0;
- }
-
- if (ok)
- ok = restoreGeometry(geo_data);
- if (ok)
- ok = restoreState(layout_data);
-
- if (!ok) {
- QString msg = tr("Error reading %1").arg(QDir::toNativeSeparators(fileName));
- QMessageBox::warning(this, tr("Error"), msg);
- return;
- }
-}
-
-static QAction *addCornerAction(const QString &text, QMainWindow *mw, QMenu *menu, QActionGroup *group,
- Qt::Corner c, Qt::DockWidgetArea a)
-{
- QAction *result = menu->addAction(text, mw, [=]() { mw->setCorner(c, a); });
- result->setCheckable(true);
- group->addAction(result);
- return result;
-}
-
-void MainWindow::setupDockWidgets(const CustomSizeHintMap &customSizeHints)
-{
- qRegisterMetaType<QDockWidget::DockWidgetFeatures>();
-
- QMenu *cornerMenu = dockWidgetMenu->addMenu(tr("Top left corner"));
- QActionGroup *group = new QActionGroup(this);
- group->setExclusive(true);
- QAction *cornerAction = addCornerAction(tr("Top dock area"), this, cornerMenu, group, Qt::TopLeftCorner, Qt::TopDockWidgetArea);
- cornerAction->setChecked(true);
- addCornerAction(tr("Left dock area"), this, cornerMenu, group, Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
-
- cornerMenu = dockWidgetMenu->addMenu(tr("Top right corner"));
- group = new QActionGroup(this);
- group->setExclusive(true);
- cornerAction = addCornerAction(tr("Top dock area"), this, cornerMenu, group, Qt::TopRightCorner, Qt::TopDockWidgetArea);
- cornerAction->setChecked(true);
- addCornerAction(tr("Right dock area"), this, cornerMenu, group, Qt::TopRightCorner, Qt::RightDockWidgetArea);
-
- cornerMenu = dockWidgetMenu->addMenu(tr("Bottom left corner"));
- group = new QActionGroup(this);
- group->setExclusive(true);
- cornerAction = addCornerAction(tr("Bottom dock area"), this, cornerMenu, group, Qt::BottomLeftCorner, Qt::BottomDockWidgetArea);
- cornerAction->setChecked(true);
- addCornerAction(tr("Left dock area"), this, cornerMenu, group, Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
-
- cornerMenu = dockWidgetMenu->addMenu(tr("Bottom right corner"));
- group = new QActionGroup(this);
- group->setExclusive(true);
- cornerAction = addCornerAction(tr("Bottom dock area"), this, cornerMenu, group, Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
- cornerAction->setChecked(true);
- addCornerAction(tr("Right dock area"), this, cornerMenu, group, Qt::BottomRightCorner, Qt::RightDockWidgetArea);
-
- dockWidgetMenu->addSeparator();
-
- static const struct Set {
- const char * name;
- uint flags;
- Qt::DockWidgetArea area;
- } sets [] = {
-#ifndef Q_OS_MAC
- { "Black", 0, Qt::LeftDockWidgetArea },
-#else
- { "Black", Qt::Drawer, Qt::LeftDockWidgetArea },
-#endif
- { "White", 0, Qt::RightDockWidgetArea },
- { "Red", 0, Qt::TopDockWidgetArea },
- { "Green", 0, Qt::TopDockWidgetArea },
- { "Blue", 0, Qt::BottomDockWidgetArea },
- { "Yellow", 0, Qt::BottomDockWidgetArea }
- };
- const int setCount = sizeof(sets) / sizeof(Set);
-
- const QIcon qtIcon(QPixmap(":/res/qt.png"));
- for (int i = 0; i < setCount; ++i) {
- ColorSwatch *swatch = new ColorSwatch(tr(sets[i].name), this, Qt::WindowFlags(sets[i].flags));
- if (i % 2)
- swatch->setWindowIcon(qtIcon);
- if (qstrcmp(sets[i].name, "Blue") == 0) {
- BlueTitleBar *titlebar = new BlueTitleBar(swatch);
- swatch->setTitleBarWidget(titlebar);
- connect(swatch, &QDockWidget::topLevelChanged, titlebar, &BlueTitleBar::updateMask);
- connect(swatch, &QDockWidget::featuresChanged, titlebar, &BlueTitleBar::updateMask, Qt::QueuedConnection);
- }
-
- QString name = QString::fromLatin1(sets[i].name);
- if (customSizeHints.contains(name))
- swatch->setCustomSizeHint(customSizeHints.value(name));
-
- addDockWidget(sets[i].area, swatch);
- dockWidgetMenu->addMenu(swatch->colorSwatchMenu());
- }
-
- destroyDockWidgetMenu = new QMenu(tr("Destroy dock widget"), this);
- destroyDockWidgetMenu->setEnabled(false);
- connect(destroyDockWidgetMenu, &QMenu::triggered, this, &MainWindow::destroyDockWidget);
-
- dockWidgetMenu->addSeparator();
- dockWidgetMenu->addAction(tr("Add dock widget..."), this, &MainWindow::createDockWidget);
- dockWidgetMenu->addMenu(destroyDockWidgetMenu);
-}
-
-void MainWindow::switchLayoutDirection()
-{
- if (layoutDirection() == Qt::LeftToRight)
- QApplication::setLayoutDirection(Qt::RightToLeft);
- else
- QApplication::setLayoutDirection(Qt::LeftToRight);
-}
-
-class CreateDockWidgetDialog : public QDialog
-{
-public:
- explicit CreateDockWidgetDialog(QWidget *parent = nullptr);
-
- QString enteredObjectName() const { return m_objectName->text(); }
- Qt::DockWidgetArea location() const;
-
-private:
- QLineEdit *m_objectName;
- QComboBox *m_location;
-};
-
-CreateDockWidgetDialog::CreateDockWidgetDialog(QWidget *parent)
- : QDialog(parent)
- , m_objectName(new QLineEdit(this))
- , m_location(new QComboBox(this))
-{
- setWindowTitle(tr("Add Dock Widget"));
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- QGridLayout *layout = new QGridLayout(this);
-
- layout->addWidget(new QLabel(tr("Object name:")), 0, 0);
- layout->addWidget(m_objectName, 0, 1);
-
- layout->addWidget(new QLabel(tr("Location:")), 1, 0);
- m_location->setEditable(false);
- m_location->addItem(tr("Top"));
- m_location->addItem(tr("Left"));
- m_location->addItem(tr("Right"));
- m_location->addItem(tr("Bottom"));
- m_location->addItem(tr("Restore"));
- layout->addWidget(m_location, 1, 1);
-
- QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
- connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
- connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
- layout->addWidget(buttonBox, 2, 0, 1, 2);
-}
-
-Qt::DockWidgetArea CreateDockWidgetDialog::location() const
-{
- switch (m_location->currentIndex()) {
- case 0: return Qt::TopDockWidgetArea;
- case 1: return Qt::LeftDockWidgetArea;
- case 2: return Qt::RightDockWidgetArea;
- case 3: return Qt::BottomDockWidgetArea;
- default:
- break;
- }
- return Qt::NoDockWidgetArea;
-}
-
-void MainWindow::createDockWidget()
-{
- CreateDockWidgetDialog dialog(this);
- if (dialog.exec() == QDialog::Rejected)
- return;
-
- QDockWidget *dw = new QDockWidget;
- const QString name = dialog.enteredObjectName();
- dw->setObjectName(name);
- dw->setWindowTitle(name);
- dw->setWidget(new QTextEdit);
-
- Qt::DockWidgetArea area = dialog.location();
- switch (area) {
- case Qt::LeftDockWidgetArea:
- case Qt::RightDockWidgetArea:
- case Qt::TopDockWidgetArea:
- case Qt::BottomDockWidgetArea:
- addDockWidget(area, dw);
- break;
- default:
- if (!restoreDockWidget(dw)) {
- QMessageBox::warning(this, QString(), tr("Failed to restore dock widget"));
- delete dw;
- return;
- }
- break;
- }
-
- extraDockWidgets.append(dw);
- destroyDockWidgetMenu->setEnabled(true);
- destroyDockWidgetMenu->addAction(new QAction(name, this));
-}
-
-void MainWindow::destroyDockWidget(QAction *action)
-{
- auto index = destroyDockWidgetMenu->actions().indexOf(action);
- delete extraDockWidgets.takeAt(index);
- destroyDockWidgetMenu->removeAction(action);
- action->deleteLater();
-
- if (destroyDockWidgetMenu->isEmpty())
- destroyDockWidgetMenu->setEnabled(false);
-}
-
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About MainWindows"), message);
-}
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.h b/examples/widgets/mainwindows/mainwindow/mainwindow.h
deleted file mode 100644
index ec522d1a51..0000000000
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QMap>
-#include <QString>
-#include <QSize>
-
-class ToolBar;
-QT_FORWARD_DECLARE_CLASS(QMenu)
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- typedef QMap<QString, QSize> CustomSizeHintMap;
-
- explicit MainWindow(const CustomSizeHintMap &customSizeHints,
- QWidget *parent = nullptr,
- Qt::WindowFlags flags = { });
-
-public slots:
- void actionTriggered(QAction *action);
- void saveLayout();
- void loadLayout();
- void switchLayoutDirection();
- void setDockOptions();
-
- void createDockWidget();
- void destroyDockWidget(QAction *action);
-
- void about();
-
-private:
- void setupToolBar();
- void setupMenuBar();
- void setupDockWidgets(const CustomSizeHintMap &customSizeHints);
-
- QList<ToolBar*> toolBars;
- QMenu *dockWidgetMenu;
- QMenu *mainWindowMenu;
- QList<QDockWidget *> extraDockWidgets;
- QMenu *destroyDockWidgetMenu;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.pro b/examples/widgets/mainwindows/mainwindow/mainwindow.pro
deleted file mode 100644
index 446d07ee6e..0000000000
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-TEMPLATE = app
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS += colorswatch.h mainwindow.h toolbar.h
-SOURCES += colorswatch.cpp mainwindow.cpp toolbar.cpp main.cpp
-build_all:!build_pass {
- CONFIG -= build_all
- CONFIG += release
-}
-
-RESOURCES += mainwindow.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/mainwindows/mainwindow
-INSTALLS += target
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.qrc b/examples/widgets/mainwindows/mainwindow/mainwindow.qrc
deleted file mode 100644
index 47ff22a3e4..0000000000
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.qrc
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/res">
- <file>qt.png</file>
- <file>titlebarLeft.png</file>
- <file>titlebarCenter.png</file>
- <file>titlebarRight.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/mainwindows/mainwindow/qt.png b/examples/widgets/mainwindows/mainwindow/qt.png
deleted file mode 100644
index 4f68e162de..0000000000
--- a/examples/widgets/mainwindows/mainwindow/qt.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/titlebarCenter.png b/examples/widgets/mainwindows/mainwindow/titlebarCenter.png
deleted file mode 100644
index 5cc141355c..0000000000
--- a/examples/widgets/mainwindows/mainwindow/titlebarCenter.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/titlebarLeft.png b/examples/widgets/mainwindows/mainwindow/titlebarLeft.png
deleted file mode 100644
index 315166202b..0000000000
--- a/examples/widgets/mainwindows/mainwindow/titlebarLeft.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/titlebarRight.png b/examples/widgets/mainwindows/mainwindow/titlebarRight.png
deleted file mode 100644
index a4505268ec..0000000000
--- a/examples/widgets/mainwindows/mainwindow/titlebarRight.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
deleted file mode 100644
index d73c12f50d..0000000000
--- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp
+++ /dev/null
@@ -1,308 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "toolbar.h"
-
-#include <QRandomGenerator>
-
-#include <QActionGroup>
-#include <QMainWindow>
-#include <QMenu>
-#include <QPainter>
-#include <QPainterPath>
-#include <QSpinBox>
-#include <QLabel>
-#include <QToolTip>
-
-#include <stdlib.h>
-
-static QPixmap genIcon(const QSize &iconSize, const QString &, const QColor &color, qreal pixelRatio)
-{
- int w = qRound(iconSize.width() * pixelRatio);
- int h = qRound(iconSize.height() * pixelRatio);
-
- QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
- image.fill(0);
-
- QPainter p(&image);
-
- extern void render_qt_text(QPainter *, int, int, const QColor &);
- render_qt_text(&p, w, h, color);
-
- QPixmap pm = QPixmap::fromImage(image, Qt::DiffuseDither | Qt::DiffuseAlphaDither);
- pm.setDevicePixelRatio(pixelRatio);
- return pm;
-}
-
-static QPixmap genIcon(const QSize &iconSize, int number, const QColor &color, qreal pixelRatio)
-{ return genIcon(iconSize, QString::number(number), color, pixelRatio); }
-
-ToolBar::ToolBar(const QString &title, QMainWindow *mainWindow)
- : QToolBar(mainWindow)
- , mainWindow(mainWindow)
- , spinbox(nullptr)
- , spinboxAction(nullptr)
-{
- setWindowTitle(title);
- setObjectName(title);
-
- setIconSize(QSize(32, 32));
-
- qreal dpr = devicePixelRatio();
- menu = new QMenu("One", this);
- menu->setIcon(genIcon(iconSize(), 1, Qt::black, dpr));
- menu->addAction(genIcon(iconSize(), "A", Qt::blue, dpr), "A");
- menu->addAction(genIcon(iconSize(), "B", Qt::blue, dpr), "B");
- menu->addAction(genIcon(iconSize(), "C", Qt::blue, dpr), "C");
- addAction(menu->menuAction());
-
- QAction *two = addAction(genIcon(iconSize(), 2, Qt::white, dpr), "Two");
- QFont boldFont;
- boldFont.setBold(true);
- two->setFont(boldFont);
-
- addAction(genIcon(iconSize(), 3, Qt::red, dpr), "Three");
- addAction(genIcon(iconSize(), 4, Qt::green, dpr), "Four");
- addAction(genIcon(iconSize(), 5, Qt::blue, dpr), "Five");
- addAction(genIcon(iconSize(), 6, Qt::yellow, dpr), "Six");
- orderAction = new QAction(this);
- orderAction->setText(tr("Order Items in Tool Bar"));
- connect(orderAction, &QAction::triggered, this, &ToolBar::order);
-
- randomizeAction = new QAction(this);
- randomizeAction->setText(tr("Randomize Items in Tool Bar"));
- connect(randomizeAction, &QAction::triggered, this, &ToolBar::randomize);
-
- addSpinBoxAction = new QAction(this);
- addSpinBoxAction->setText(tr("Add Spin Box"));
- connect(addSpinBoxAction, &QAction::triggered, this, &ToolBar::addSpinBox);
-
- removeSpinBoxAction = new QAction(this);
- removeSpinBoxAction->setText(tr("Remove Spin Box"));
- removeSpinBoxAction->setEnabled(false);
- connect(removeSpinBoxAction, &QAction::triggered, this, &ToolBar::removeSpinBox);
-
- movableAction = new QAction(tr("Movable"), this);
- movableAction->setCheckable(true);
- connect(movableAction, &QAction::triggered, this, &ToolBar::changeMovable);
-
- allowedAreasActions = new QActionGroup(this);
- allowedAreasActions->setExclusive(false);
-
- allowLeftAction = new QAction(tr("Allow on Left"), this);
- allowLeftAction->setCheckable(true);
- connect(allowLeftAction, &QAction::triggered, this, &ToolBar::allowLeft);
-
- allowRightAction = new QAction(tr("Allow on Right"), this);
- allowRightAction->setCheckable(true);
- connect(allowRightAction, &QAction::triggered, this, &ToolBar::allowRight);
-
- allowTopAction = new QAction(tr("Allow on Top"), this);
- allowTopAction->setCheckable(true);
- connect(allowTopAction, &QAction::triggered, this, &ToolBar::allowTop);
-
- allowBottomAction = new QAction(tr("Allow on Bottom"), this);
- allowBottomAction->setCheckable(true);
- connect(allowBottomAction, &QAction::triggered, this, &ToolBar::allowBottom);
-
- allowedAreasActions->addAction(allowLeftAction);
- allowedAreasActions->addAction(allowRightAction);
- allowedAreasActions->addAction(allowTopAction);
- allowedAreasActions->addAction(allowBottomAction);
-
- areaActions = new QActionGroup(this);
- areaActions->setExclusive(true);
-
- leftAction = new QAction(tr("Place on Left") , this);
- leftAction->setCheckable(true);
- connect(leftAction, &QAction::triggered, this, &ToolBar::placeLeft);
-
- rightAction = new QAction(tr("Place on Right") , this);
- rightAction->setCheckable(true);
- connect(rightAction, &QAction::triggered, this, &ToolBar::placeRight);
-
- topAction = new QAction(tr("Place on Top") , this);
- topAction->setCheckable(true);
- connect(topAction, &QAction::triggered, this, &ToolBar::placeTop);
-
- bottomAction = new QAction(tr("Place on Bottom") , this);
- bottomAction->setCheckable(true);
- connect(bottomAction, &QAction::triggered, this, &ToolBar::placeBottom);
-
- areaActions->addAction(leftAction);
- areaActions->addAction(rightAction);
- areaActions->addAction(topAction);
- areaActions->addAction(bottomAction);
-
- connect(movableAction, &QAction::triggered, areaActions, &QActionGroup::setEnabled);
-
- connect(movableAction, &QAction::triggered, allowedAreasActions, &QActionGroup::setEnabled);
-
- menu = new QMenu(title, this);
- menu->addAction(toggleViewAction());
- menu->addSeparator();
- menu->addAction(orderAction);
- menu->addAction(randomizeAction);
- menu->addSeparator();
- menu->addAction(addSpinBoxAction);
- menu->addAction(removeSpinBoxAction);
- menu->addSeparator();
- menu->addAction(movableAction);
- menu->addSeparator();
- menu->addActions(allowedAreasActions->actions());
- menu->addSeparator();
- menu->addActions(areaActions->actions());
- menu->addSeparator();
- menu->addAction(tr("Insert break"), this, &ToolBar::insertToolBarBreak);
-
- connect(menu, &QMenu::aboutToShow, this, &ToolBar::updateMenu);
-
- randomize();
-}
-
-void ToolBar::updateMenu()
-{
- const Qt::ToolBarArea area = mainWindow->toolBarArea(this);
- const Qt::ToolBarAreas areas = allowedAreas();
-
- movableAction->setChecked(isMovable());
-
- allowLeftAction->setChecked(isAreaAllowed(Qt::LeftToolBarArea));
- allowRightAction->setChecked(isAreaAllowed(Qt::RightToolBarArea));
- allowTopAction->setChecked(isAreaAllowed(Qt::TopToolBarArea));
- allowBottomAction->setChecked(isAreaAllowed(Qt::BottomToolBarArea));
-
- if (allowedAreasActions->isEnabled()) {
- allowLeftAction->setEnabled(area != Qt::LeftToolBarArea);
- allowRightAction->setEnabled(area != Qt::RightToolBarArea);
- allowTopAction->setEnabled(area != Qt::TopToolBarArea);
- allowBottomAction->setEnabled(area != Qt::BottomToolBarArea);
- }
-
- leftAction->setChecked(area == Qt::LeftToolBarArea);
- rightAction->setChecked(area == Qt::RightToolBarArea);
- topAction->setChecked(area == Qt::TopToolBarArea);
- bottomAction->setChecked(area == Qt::BottomToolBarArea);
-
- if (areaActions->isEnabled()) {
- leftAction->setEnabled(areas & Qt::LeftToolBarArea);
- rightAction->setEnabled(areas & Qt::RightToolBarArea);
- topAction->setEnabled(areas & Qt::TopToolBarArea);
- bottomAction->setEnabled(areas & Qt::BottomToolBarArea);
- }
-}
-
-void ToolBar::order()
-{
- QList<QAction *> ordered;
- QList<QAction *> actions1 = actions();
- const QList<QAction *> childActions = findChildren<QAction *>();
- for (QAction *action : childActions) {
- if (!actions1.contains(action))
- continue;
- actions1.removeAll(action);
- ordered.append(action);
- }
-
- clear();
- addActions(ordered);
-
- orderAction->setEnabled(false);
-}
-
-void ToolBar::randomize()
-{
- QList<QAction *> randomized;
- QList<QAction *> actions = this->actions();
- while (!actions.isEmpty()) {
- QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(actions.size()));
- randomized.append(action);
- }
- clear();
- addActions(randomized);
-
- orderAction->setEnabled(true);
-}
-
-void ToolBar::addSpinBox()
-{
- if (!spinbox)
- spinbox = new QSpinBox(this);
- if (!spinboxAction)
- spinboxAction = addWidget(spinbox);
- else
- addAction(spinboxAction);
-
- addSpinBoxAction->setEnabled(false);
- removeSpinBoxAction->setEnabled(true);
-}
-
-void ToolBar::removeSpinBox()
-{
- if (spinboxAction)
- removeAction(spinboxAction);
-
- addSpinBoxAction->setEnabled(true);
- removeSpinBoxAction->setEnabled(false);
-}
-
-void ToolBar::allow(Qt::ToolBarArea area, bool a)
-{
- Qt::ToolBarAreas areas = allowedAreas();
- areas = a ? areas | area : areas & ~area;
- setAllowedAreas(areas);
-
- if (areaActions->isEnabled()) {
- leftAction->setEnabled(areas & Qt::LeftToolBarArea);
- rightAction->setEnabled(areas & Qt::RightToolBarArea);
- topAction->setEnabled(areas & Qt::TopToolBarArea);
- bottomAction->setEnabled(areas & Qt::BottomToolBarArea);
- }
-}
-
-void ToolBar::place(Qt::ToolBarArea area, bool p)
-{
- if (!p)
- return;
-
- mainWindow->addToolBar(area, this);
-
- if (allowedAreasActions->isEnabled()) {
- allowLeftAction->setEnabled(area != Qt::LeftToolBarArea);
- allowRightAction->setEnabled(area != Qt::RightToolBarArea);
- allowTopAction->setEnabled(area != Qt::TopToolBarArea);
- allowBottomAction->setEnabled(area != Qt::BottomToolBarArea);
- }
-}
-
-void ToolBar::changeMovable(bool movable)
-{ setMovable(movable); }
-
-void ToolBar::allowLeft(bool a)
-{ allow(Qt::LeftToolBarArea, a); }
-
-void ToolBar::allowRight(bool a)
-{ allow(Qt::RightToolBarArea, a); }
-
-void ToolBar::allowTop(bool a)
-{ allow(Qt::TopToolBarArea, a); }
-
-void ToolBar::allowBottom(bool a)
-{ allow(Qt::BottomToolBarArea, a); }
-
-void ToolBar::placeLeft(bool p)
-{ place(Qt::LeftToolBarArea, p); }
-
-void ToolBar::placeRight(bool p)
-{ place(Qt::RightToolBarArea, p); }
-
-void ToolBar::placeTop(bool p)
-{ place(Qt::TopToolBarArea, p); }
-
-void ToolBar::placeBottom(bool p)
-{ place(Qt::BottomToolBarArea, p); }
-
-void ToolBar::insertToolBarBreak()
-{
- mainWindow->insertToolBarBreak(this);
-}
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.h b/examples/widgets/mainwindows/mainwindow/toolbar.h
deleted file mode 100644
index 0030adbe23..0000000000
--- a/examples/widgets/mainwindows/mainwindow/toolbar.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef TOOLBAR_H
-#define TOOLBAR_H
-
-#include <QToolBar>
-
-QT_FORWARD_DECLARE_CLASS(QAction)
-QT_FORWARD_DECLARE_CLASS(QActionGroup)
-QT_FORWARD_DECLARE_CLASS(QMenu)
-QT_FORWARD_DECLARE_CLASS(QSpinBox)
-
-class ToolBar : public QToolBar
-{
- Q_OBJECT
-
-public:
- explicit ToolBar(const QString &title, QMainWindow *mainWindow);
-
- QMenu *toolbarMenu() const { return menu; }
-
-private slots:
- void order();
- void randomize();
- void addSpinBox();
- void removeSpinBox();
-
- void changeMovable(bool movable);
-
- void allowLeft(bool a);
- void allowRight(bool a);
- void allowTop(bool a);
- void allowBottom(bool a);
-
- void placeLeft(bool p);
- void placeRight(bool p);
- void placeTop(bool p);
- void placeBottom(bool p);
-
- void updateMenu();
- void insertToolBarBreak();
-
-private:
- void allow(Qt::ToolBarArea area, bool allow);
- void place(Qt::ToolBarArea area, bool place);
-
- QMainWindow *mainWindow;
-
- QSpinBox *spinbox;
- QAction *spinboxAction;
-
- QMenu *menu;
- QAction *orderAction;
- QAction *randomizeAction;
- QAction *addSpinBoxAction;
- QAction *removeSpinBoxAction;
-
- QAction *movableAction;
-
- QActionGroup *allowedAreasActions;
- QAction *allowLeftAction;
- QAction *allowRightAction;
- QAction *allowTopAction;
- QAction *allowBottomAction;
-
- QActionGroup *areaActions;
- QAction *leftAction;
- QAction *rightAction;
- QAction *topAction;
- QAction *bottomAction;
-};
-
-#endif // TOOLBAR_H
diff --git a/examples/widgets/mainwindows/mainwindows.pro b/examples/widgets/mainwindows/mainwindows.pro
index 7a53cc6fa7..75f664f6ec 100644
--- a/examples/widgets/mainwindows/mainwindows.pro
+++ b/examples/widgets/mainwindows/mainwindows.pro
@@ -1,6 +1,2 @@
TEMPLATE = subdirs
-SUBDIRS = application \
- dockwidgets \
- mainwindow \
- mdi \
- menus
+SUBDIRS = menus
diff --git a/examples/widgets/mainwindows/mdi/CMakeLists.txt b/examples/widgets/mainwindows/mdi/CMakeLists.txt
deleted file mode 100644
index 0af9873284..0000000000
--- a/examples/widgets/mainwindows/mdi/CMakeLists.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(mdi LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/mainwindows/mdi")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(mdi
- main.cpp
- mainwindow.cpp mainwindow.h
- mdichild.cpp mdichild.h
-)
-
-set_target_properties(mdi PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(mdi PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(mdi_resource_files
- "images/copy.png"
- "images/cut.png"
- "images/new.png"
- "images/open.png"
- "images/paste.png"
- "images/save.png"
-)
-
-qt_add_resources(mdi "mdi"
- PREFIX
- "/"
- FILES
- ${mdi_resource_files}
-)
-
-install(TARGETS mdi
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/mainwindows/mdi/images/copy.png b/examples/widgets/mainwindows/mdi/images/copy.png
deleted file mode 100644
index 2aeb28288f..0000000000
--- a/examples/widgets/mainwindows/mdi/images/copy.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/cut.png b/examples/widgets/mainwindows/mdi/images/cut.png
deleted file mode 100644
index 54638e9386..0000000000
--- a/examples/widgets/mainwindows/mdi/images/cut.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/new.png b/examples/widgets/mainwindows/mdi/images/new.png
deleted file mode 100644
index 12131b0100..0000000000
--- a/examples/widgets/mainwindows/mdi/images/new.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/open.png b/examples/widgets/mainwindows/mdi/images/open.png
deleted file mode 100644
index 45fa2883a7..0000000000
--- a/examples/widgets/mainwindows/mdi/images/open.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/paste.png b/examples/widgets/mainwindows/mdi/images/paste.png
deleted file mode 100644
index c14425cad1..0000000000
--- a/examples/widgets/mainwindows/mdi/images/paste.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/save.png b/examples/widgets/mainwindows/mdi/images/save.png
deleted file mode 100644
index e65a29d5f1..0000000000
--- a/examples/widgets/mainwindows/mdi/images/save.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/main.cpp b/examples/widgets/mainwindows/mdi/main.cpp
deleted file mode 100644
index 09f3082201..0000000000
--- a/examples/widgets/mainwindows/mdi/main.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include <QCommandLineParser>
-#include <QCommandLineOption>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(mdi);
-
- QApplication app(argc, argv);
- QCoreApplication::setApplicationName("MDI Example");
- QCoreApplication::setOrganizationName("QtProject");
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser parser;
- parser.setApplicationDescription("Qt MDI Example");
- parser.addHelpOption();
- parser.addVersionOption();
- parser.addPositionalArgument("file", "The file to open.");
- parser.process(app);
-
- MainWindow mainWin;
- const QStringList posArgs = parser.positionalArguments();
- for (const QString &fileName : posArgs)
- mainWin.openFile(fileName);
- mainWin.show();
- return app.exec();
-}
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.cpp b/examples/widgets/mainwindows/mdi/mainwindow.cpp
deleted file mode 100644
index 250ee786fb..0000000000
--- a/examples/widgets/mainwindows/mdi/mainwindow.cpp
+++ /dev/null
@@ -1,461 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-
-#include "mainwindow.h"
-#include "mdichild.h"
-
-MainWindow::MainWindow()
- : mdiArea(new QMdiArea)
-{
- mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- setCentralWidget(mdiArea);
- connect(mdiArea, &QMdiArea::subWindowActivated,
- this, &MainWindow::updateMenus);
-
- createActions();
- createStatusBar();
- updateMenus();
-
- readSettings();
-
- setWindowTitle(tr("MDI"));
- setUnifiedTitleAndToolBarOnMac(true);
-}
-
-void MainWindow::closeEvent(QCloseEvent *event)
-{
- mdiArea->closeAllSubWindows();
- if (mdiArea->currentSubWindow()) {
- event->ignore();
- } else {
- writeSettings();
- event->accept();
- }
-}
-
-void MainWindow::newFile()
-{
- MdiChild *child = createMdiChild();
- child->newFile();
- child->show();
-}
-
-void MainWindow::open()
-{
- const QString fileName = QFileDialog::getOpenFileName(this);
- if (!fileName.isEmpty())
- openFile(fileName);
-}
-
-bool MainWindow::openFile(const QString &fileName)
-{
- if (QMdiSubWindow *existing = findMdiChild(fileName)) {
- mdiArea->setActiveSubWindow(existing);
- return true;
- }
- const bool succeeded = loadFile(fileName);
- if (succeeded)
- statusBar()->showMessage(tr("File loaded"), 2000);
- return succeeded;
-}
-
-bool MainWindow::loadFile(const QString &fileName)
-{
- MdiChild *child = createMdiChild();
- const bool succeeded = child->loadFile(fileName);
- if (succeeded)
- child->show();
- else
- child->close();
- MainWindow::prependToRecentFiles(fileName);
- return succeeded;
-}
-
-static inline QString recentFilesKey() { return QStringLiteral("recentFileList"); }
-static inline QString fileKey() { return QStringLiteral("file"); }
-
-static QStringList readRecentFiles(QSettings &settings)
-{
- QStringList result;
- const int count = settings.beginReadArray(recentFilesKey());
- for (int i = 0; i < count; ++i) {
- settings.setArrayIndex(i);
- result.append(settings.value(fileKey()).toString());
- }
- settings.endArray();
- return result;
-}
-
-static void writeRecentFiles(const QStringList &files, QSettings &settings)
-{
- const int count = files.size();
- settings.beginWriteArray(recentFilesKey());
- for (int i = 0; i < count; ++i) {
- settings.setArrayIndex(i);
- settings.setValue(fileKey(), files.at(i));
- }
- settings.endArray();
-}
-
-bool MainWindow::hasRecentFiles()
-{
- QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
- const int count = settings.beginReadArray(recentFilesKey());
- settings.endArray();
- return count > 0;
-}
-
-void MainWindow::prependToRecentFiles(const QString &fileName)
-{
- QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
-
- const QStringList oldRecentFiles = readRecentFiles(settings);
- QStringList recentFiles = oldRecentFiles;
- recentFiles.removeAll(fileName);
- recentFiles.prepend(fileName);
- if (oldRecentFiles != recentFiles)
- writeRecentFiles(recentFiles, settings);
-
- setRecentFilesVisible(!recentFiles.isEmpty());
-}
-
-void MainWindow::setRecentFilesVisible(bool visible)
-{
- recentFileSubMenuAct->setVisible(visible);
- recentFileSeparator->setVisible(visible);
-}
-
-void MainWindow::updateRecentFileActions()
-{
- QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
-
- const QStringList recentFiles = readRecentFiles(settings);
- const int count = qMin(int(MaxRecentFiles), recentFiles.size());
- int i = 0;
- for ( ; i < count; ++i) {
- const QString fileName = QFileInfo(recentFiles.at(i)).fileName();
- recentFileActs[i]->setText(tr("&%1 %2").arg(i + 1).arg(fileName));
- recentFileActs[i]->setData(recentFiles.at(i));
- recentFileActs[i]->setVisible(true);
- }
- for ( ; i < MaxRecentFiles; ++i)
- recentFileActs[i]->setVisible(false);
-}
-
-void MainWindow::openRecentFile()
-{
- if (const QAction *action = qobject_cast<const QAction *>(sender()))
- openFile(action->data().toString());
-}
-
-void MainWindow::save()
-{
- if (activeMdiChild() && activeMdiChild()->save())
- statusBar()->showMessage(tr("File saved"), 2000);
-}
-
-void MainWindow::saveAs()
-{
- MdiChild *child = activeMdiChild();
- if (child && child->saveAs()) {
- statusBar()->showMessage(tr("File saved"), 2000);
- MainWindow::prependToRecentFiles(child->currentFile());
- }
-}
-
-#ifndef QT_NO_CLIPBOARD
-void MainWindow::cut()
-{
- if (activeMdiChild())
- activeMdiChild()->cut();
-}
-
-void MainWindow::copy()
-{
- if (activeMdiChild())
- activeMdiChild()->copy();
-}
-
-void MainWindow::paste()
-{
- if (activeMdiChild())
- activeMdiChild()->paste();
-}
-#endif
-
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About MDI"),
- tr("The <b>MDI</b> example demonstrates how to write multiple "
- "document interface applications using Qt."));
-}
-
-void MainWindow::updateMenus()
-{
- bool hasMdiChild = (activeMdiChild() != nullptr);
- saveAct->setEnabled(hasMdiChild);
- saveAsAct->setEnabled(hasMdiChild);
-#ifndef QT_NO_CLIPBOARD
- pasteAct->setEnabled(hasMdiChild);
-#endif
- closeAct->setEnabled(hasMdiChild);
- closeAllAct->setEnabled(hasMdiChild);
- tileAct->setEnabled(hasMdiChild);
- cascadeAct->setEnabled(hasMdiChild);
- nextAct->setEnabled(hasMdiChild);
- previousAct->setEnabled(hasMdiChild);
- windowMenuSeparatorAct->setVisible(hasMdiChild);
-
-#ifndef QT_NO_CLIPBOARD
- bool hasSelection = (activeMdiChild() &&
- activeMdiChild()->textCursor().hasSelection());
- cutAct->setEnabled(hasSelection);
- copyAct->setEnabled(hasSelection);
-#endif
-}
-
-void MainWindow::updateWindowMenu()
-{
- windowMenu->clear();
- windowMenu->addAction(closeAct);
- windowMenu->addAction(closeAllAct);
- windowMenu->addSeparator();
- windowMenu->addAction(tileAct);
- windowMenu->addAction(cascadeAct);
- windowMenu->addSeparator();
- windowMenu->addAction(nextAct);
- windowMenu->addAction(previousAct);
- windowMenu->addAction(windowMenuSeparatorAct);
-
- QList<QMdiSubWindow *> windows = mdiArea->subWindowList();
- windowMenuSeparatorAct->setVisible(!windows.isEmpty());
-
- for (int i = 0; i < windows.size(); ++i) {
- QMdiSubWindow *mdiSubWindow = windows.at(i);
- MdiChild *child = qobject_cast<MdiChild *>(mdiSubWindow->widget());
-
- QString text;
- if (i < 9) {
- text = tr("&%1 %2").arg(i + 1)
- .arg(child->userFriendlyCurrentFile());
- } else {
- text = tr("%1 %2").arg(i + 1)
- .arg(child->userFriendlyCurrentFile());
- }
- QAction *action = windowMenu->addAction(text, mdiSubWindow, [this, mdiSubWindow]() {
- mdiArea->setActiveSubWindow(mdiSubWindow);
- });
- action->setCheckable(true);
- action ->setChecked(child == activeMdiChild());
- }
-}
-
-MdiChild *MainWindow::createMdiChild()
-{
- MdiChild *child = new MdiChild;
- mdiArea->addSubWindow(child);
-
-#ifndef QT_NO_CLIPBOARD
- connect(child, &QTextEdit::copyAvailable, cutAct, &QAction::setEnabled);
- connect(child, &QTextEdit::copyAvailable, copyAct, &QAction::setEnabled);
-#endif
-
- return child;
-}
-
-void MainWindow::createActions()
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- QToolBar *fileToolBar = addToolBar(tr("File"));
-
- const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/images/new.png"));
- newAct = new QAction(newIcon, tr("&New"), this);
- newAct->setShortcuts(QKeySequence::New);
- newAct->setStatusTip(tr("Create a new file"));
- connect(newAct, &QAction::triggered, this, &MainWindow::newFile);
- fileMenu->addAction(newAct);
- fileToolBar->addAction(newAct);
-
- const QIcon openIcon = QIcon::fromTheme("document-open", QIcon(":/images/open.png"));
- QAction *openAct = new QAction(openIcon, tr("&Open..."), this);
- openAct->setShortcuts(QKeySequence::Open);
- openAct->setStatusTip(tr("Open an existing file"));
- connect(openAct, &QAction::triggered, this, &MainWindow::open);
- fileMenu->addAction(openAct);
- fileToolBar->addAction(openAct);
-
- const QIcon saveIcon = QIcon::fromTheme("document-save", QIcon(":/images/save.png"));
- saveAct = new QAction(saveIcon, tr("&Save"), this);
- saveAct->setShortcuts(QKeySequence::Save);
- saveAct->setStatusTip(tr("Save the document to disk"));
- connect(saveAct, &QAction::triggered, this, &MainWindow::save);
- fileToolBar->addAction(saveAct);
-
- const QIcon saveAsIcon = QIcon::fromTheme("document-save-as");
- saveAsAct = new QAction(saveAsIcon, tr("Save &As..."), this);
- saveAsAct->setShortcuts(QKeySequence::SaveAs);
- saveAsAct->setStatusTip(tr("Save the document under a new name"));
- connect(saveAsAct, &QAction::triggered, this, &MainWindow::saveAs);
- fileMenu->addAction(saveAsAct);
-
- fileMenu->addSeparator();
-
- QMenu *recentMenu = fileMenu->addMenu(tr("Recent..."));
- connect(recentMenu, &QMenu::aboutToShow, this, &MainWindow::updateRecentFileActions);
- recentFileSubMenuAct = recentMenu->menuAction();
-
- for (int i = 0; i < MaxRecentFiles; ++i) {
- recentFileActs[i] = recentMenu->addAction(QString(), this, &MainWindow::openRecentFile);
- recentFileActs[i]->setVisible(false);
- }
-
- recentFileSeparator = fileMenu->addSeparator();
-
- setRecentFilesVisible(MainWindow::hasRecentFiles());
-
- fileMenu->addAction(tr("Switch layout direction"), this, &MainWindow::switchLayoutDirection);
-
- fileMenu->addSeparator();
-
-//! [0]
- const QIcon exitIcon = QIcon::fromTheme("application-exit");
- QAction *exitAct = fileMenu->addAction(exitIcon, tr("E&xit"), qApp, &QApplication::quit);
- exitAct->setShortcuts(QKeySequence::Quit);
- exitAct->setStatusTip(tr("Exit the application"));
- fileMenu->addAction(exitAct);
-//! [0]
-
-#ifndef QT_NO_CLIPBOARD
- QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
- QToolBar *editToolBar = addToolBar(tr("Edit"));
-
- const QIcon cutIcon = QIcon::fromTheme("edit-cut", QIcon(":/images/cut.png"));
- cutAct = new QAction(cutIcon, tr("Cu&t"), this);
- cutAct->setShortcuts(QKeySequence::Cut);
- cutAct->setStatusTip(tr("Cut the current selection's contents to the "
- "clipboard"));
- connect(cutAct, &QAction::triggered, this, &MainWindow::cut);
- editMenu->addAction(cutAct);
- editToolBar->addAction(cutAct);
-
- const QIcon copyIcon = QIcon::fromTheme("edit-copy", QIcon(":/images/copy.png"));
- copyAct = new QAction(copyIcon, tr("&Copy"), this);
- copyAct->setShortcuts(QKeySequence::Copy);
- copyAct->setStatusTip(tr("Copy the current selection's contents to the "
- "clipboard"));
- connect(copyAct, &QAction::triggered, this, &MainWindow::copy);
- editMenu->addAction(copyAct);
- editToolBar->addAction(copyAct);
-
- const QIcon pasteIcon = QIcon::fromTheme("edit-paste", QIcon(":/images/paste.png"));
- pasteAct = new QAction(pasteIcon, tr("&Paste"), this);
- pasteAct->setShortcuts(QKeySequence::Paste);
- pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
- "selection"));
- connect(pasteAct, &QAction::triggered, this, &MainWindow::paste);
- editMenu->addAction(pasteAct);
- editToolBar->addAction(pasteAct);
-#endif
-
- windowMenu = menuBar()->addMenu(tr("&Window"));
- connect(windowMenu, &QMenu::aboutToShow, this, &MainWindow::updateWindowMenu);
-
- closeAct = new QAction(tr("Cl&ose"), this);
- closeAct->setStatusTip(tr("Close the active window"));
- connect(closeAct, &QAction::triggered,
- mdiArea, &QMdiArea::closeActiveSubWindow);
-
- closeAllAct = new QAction(tr("Close &All"), this);
- closeAllAct->setStatusTip(tr("Close all the windows"));
- connect(closeAllAct, &QAction::triggered, mdiArea, &QMdiArea::closeAllSubWindows);
-
- tileAct = new QAction(tr("&Tile"), this);
- tileAct->setStatusTip(tr("Tile the windows"));
- connect(tileAct, &QAction::triggered, mdiArea, &QMdiArea::tileSubWindows);
-
- cascadeAct = new QAction(tr("&Cascade"), this);
- cascadeAct->setStatusTip(tr("Cascade the windows"));
- connect(cascadeAct, &QAction::triggered, mdiArea, &QMdiArea::cascadeSubWindows);
-
- nextAct = new QAction(tr("Ne&xt"), this);
- nextAct->setShortcuts(QKeySequence::NextChild);
- nextAct->setStatusTip(tr("Move the focus to the next window"));
- connect(nextAct, &QAction::triggered, mdiArea, &QMdiArea::activateNextSubWindow);
-
- previousAct = new QAction(tr("Pre&vious"), this);
- previousAct->setShortcuts(QKeySequence::PreviousChild);
- previousAct->setStatusTip(tr("Move the focus to the previous "
- "window"));
- connect(previousAct, &QAction::triggered, mdiArea, &QMdiArea::activatePreviousSubWindow);
-
- windowMenuSeparatorAct = new QAction(this);
- windowMenuSeparatorAct->setSeparator(true);
-
- updateWindowMenu();
-
- menuBar()->addSeparator();
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
-
- QAction *aboutAct = helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- aboutAct->setStatusTip(tr("Show the application's About box"));
-
- QAction *aboutQtAct = helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
- aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
-}
-
-void MainWindow::createStatusBar()
-{
- statusBar()->showMessage(tr("Ready"));
-}
-
-void MainWindow::readSettings()
-{
- QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
- const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
- if (geometry.isEmpty()) {
- const QRect availableGeometry = screen()->availableGeometry();
- resize(availableGeometry.width() / 3, availableGeometry.height() / 2);
- move((availableGeometry.width() - width()) / 2,
- (availableGeometry.height() - height()) / 2);
- } else {
- restoreGeometry(geometry);
- }
-}
-
-void MainWindow::writeSettings()
-{
- QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
- settings.setValue("geometry", saveGeometry());
-}
-
-MdiChild *MainWindow::activeMdiChild() const
-{
- if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
- return qobject_cast<MdiChild *>(activeSubWindow->widget());
- return nullptr;
-}
-
-QMdiSubWindow *MainWindow::findMdiChild(const QString &fileName) const
-{
- QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
-
- const QList<QMdiSubWindow *> subWindows = mdiArea->subWindowList();
- for (QMdiSubWindow *window : subWindows) {
- MdiChild *mdiChild = qobject_cast<MdiChild *>(window->widget());
- if (mdiChild->currentFile() == canonicalFilePath)
- return window;
- }
- return nullptr;
-}
-
-void MainWindow::switchLayoutDirection()
-{
- if (layoutDirection() == Qt::LeftToRight)
- QGuiApplication::setLayoutDirection(Qt::RightToLeft);
- else
- QGuiApplication::setLayoutDirection(Qt::LeftToRight);
-}
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.h b/examples/widgets/mainwindows/mdi/mainwindow.h
deleted file mode 100644
index 8fec975c6e..0000000000
--- a/examples/widgets/mainwindows/mdi/mainwindow.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-class MdiChild;
-QT_BEGIN_NAMESPACE
-class QAction;
-class QMenu;
-class QMdiArea;
-class QMdiSubWindow;
-QT_END_NAMESPACE
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
- bool openFile(const QString &fileName);
-
-protected:
- void closeEvent(QCloseEvent *event) override;
-
-private slots:
- void newFile();
- void open();
- void save();
- void saveAs();
- void updateRecentFileActions();
- void openRecentFile();
-#ifndef QT_NO_CLIPBOARD
- void cut();
- void copy();
- void paste();
-#endif
- void about();
- void updateMenus();
- void updateWindowMenu();
- MdiChild *createMdiChild();
- void switchLayoutDirection();
-
-private:
- enum { MaxRecentFiles = 5 };
-
- void createActions();
- void createStatusBar();
- void readSettings();
- void writeSettings();
- bool loadFile(const QString &fileName);
- static bool hasRecentFiles();
- void prependToRecentFiles(const QString &fileName);
- void setRecentFilesVisible(bool visible);
- MdiChild *activeMdiChild() const;
- QMdiSubWindow *findMdiChild(const QString &fileName) const;
-
- QMdiArea *mdiArea;
-
- QMenu *windowMenu;
- QAction *newAct;
- QAction *saveAct;
- QAction *saveAsAct;
- QAction *recentFileActs[MaxRecentFiles];
- QAction *recentFileSeparator;
- QAction *recentFileSubMenuAct;
-#ifndef QT_NO_CLIPBOARD
- QAction *cutAct;
- QAction *copyAct;
- QAction *pasteAct;
-#endif
- QAction *closeAct;
- QAction *closeAllAct;
- QAction *tileAct;
- QAction *cascadeAct;
- QAction *nextAct;
- QAction *previousAct;
- QAction *windowMenuSeparatorAct;
-};
-
-#endif
diff --git a/examples/widgets/mainwindows/mdi/mdi.pro b/examples/widgets/mainwindows/mdi/mdi.pro
deleted file mode 100644
index f2c236f7e2..0000000000
--- a/examples/widgets/mainwindows/mdi/mdi.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-
-HEADERS = mainwindow.h \
- mdichild.h
-SOURCES = main.cpp \
- mainwindow.cpp \
- mdichild.cpp
-RESOURCES = mdi.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/mainwindows/mdi
-INSTALLS += target
diff --git a/examples/widgets/mainwindows/mdi/mdi.qrc b/examples/widgets/mainwindows/mdi/mdi.qrc
deleted file mode 100644
index 0a776fab4d..0000000000
--- a/examples/widgets/mainwindows/mdi/mdi.qrc
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/copy.png</file>
- <file>images/cut.png</file>
- <file>images/new.png</file>
- <file>images/open.png</file>
- <file>images/paste.png</file>
- <file>images/save.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/mainwindows/mdi/mdichild.cpp b/examples/widgets/mainwindows/mdi/mdichild.cpp
deleted file mode 100644
index 8f96ec623d..0000000000
--- a/examples/widgets/mainwindows/mdi/mdichild.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-
-#include "mdichild.h"
-
-MdiChild::MdiChild()
-{
- setAttribute(Qt::WA_DeleteOnClose);
- isUntitled = true;
-}
-
-void MdiChild::newFile()
-{
- static int sequenceNumber = 1;
-
- isUntitled = true;
- curFile = tr("document%1.txt").arg(sequenceNumber++);
- setWindowTitle(curFile + "[*]");
-
- connect(document(), &QTextDocument::contentsChanged,
- this, &MdiChild::documentWasModified);
-}
-
-bool MdiChild::loadFile(const QString &fileName)
-{
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("MDI"),
- tr("Cannot read file %1:\n%2.")
- .arg(fileName)
- .arg(file.errorString()));
- return false;
- }
-
- QTextStream in(&file);
- QGuiApplication::setOverrideCursor(Qt::WaitCursor);
- setPlainText(in.readAll());
- QGuiApplication::restoreOverrideCursor();
-
- setCurrentFile(fileName);
-
- connect(document(), &QTextDocument::contentsChanged,
- this, &MdiChild::documentWasModified);
-
- return true;
-}
-
-bool MdiChild::save()
-{
- if (isUntitled) {
- return saveAs();
- } else {
- return saveFile(curFile);
- }
-}
-
-bool MdiChild::saveAs()
-{
- QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
- curFile);
- if (fileName.isEmpty())
- return false;
-
- return saveFile(fileName);
-}
-
-bool MdiChild::saveFile(const QString &fileName)
-{
- QString errorMessage;
-
- QGuiApplication::setOverrideCursor(Qt::WaitCursor);
- QSaveFile file(fileName);
- if (file.open(QFile::WriteOnly | QFile::Text)) {
- QTextStream out(&file);
- out << toPlainText();
- if (!file.commit()) {
- errorMessage = tr("Cannot write file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString());
- }
- } else {
- errorMessage = tr("Cannot open file %1 for writing:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString());
- }
- QGuiApplication::restoreOverrideCursor();
-
- if (!errorMessage.isEmpty()) {
- QMessageBox::warning(this, tr("MDI"), errorMessage);
- return false;
- }
-
- setCurrentFile(fileName);
- return true;
-}
-
-QString MdiChild::userFriendlyCurrentFile()
-{
- return strippedName(curFile);
-}
-
-void MdiChild::closeEvent(QCloseEvent *event)
-{
- if (maybeSave()) {
- event->accept();
- } else {
- event->ignore();
- }
-}
-
-void MdiChild::documentWasModified()
-{
- setWindowModified(document()->isModified());
-}
-
-bool MdiChild::maybeSave()
-{
- if (!document()->isModified())
- return true;
- const QMessageBox::StandardButton ret
- = QMessageBox::warning(this, tr("MDI"),
- tr("'%1' has been modified.\n"
- "Do you want to save your changes?")
- .arg(userFriendlyCurrentFile()),
- QMessageBox::Save | QMessageBox::Discard
- | QMessageBox::Cancel);
- switch (ret) {
- case QMessageBox::Save:
- return save();
- case QMessageBox::Cancel:
- return false;
- default:
- break;
- }
- return true;
-}
-
-void MdiChild::setCurrentFile(const QString &fileName)
-{
- curFile = QFileInfo(fileName).canonicalFilePath();
- isUntitled = false;
- document()->setModified(false);
- setWindowModified(false);
- setWindowTitle(userFriendlyCurrentFile() + "[*]");
-}
-
-QString MdiChild::strippedName(const QString &fullFileName)
-{
- return QFileInfo(fullFileName).fileName();
-}
diff --git a/examples/widgets/mainwindows/mdi/mdichild.h b/examples/widgets/mainwindows/mdi/mdichild.h
deleted file mode 100644
index ba9c3d8f1c..0000000000
--- a/examples/widgets/mainwindows/mdi/mdichild.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MDICHILD_H
-#define MDICHILD_H
-
-#include <QTextEdit>
-
-class MdiChild : public QTextEdit
-{
- Q_OBJECT
-
-public:
- MdiChild();
-
- void newFile();
- bool loadFile(const QString &fileName);
- bool save();
- bool saveAs();
- bool saveFile(const QString &fileName);
- QString userFriendlyCurrentFile();
- QString currentFile() { return curFile; }
-
-protected:
- void closeEvent(QCloseEvent *event) override;
-
-private slots:
- void documentWasModified();
-
-private:
- bool maybeSave();
- void setCurrentFile(const QString &fileName);
- QString strippedName(const QString &fullFileName);
-
- QString curFile;
- bool isUntitled;
-};
-
-#endif
diff --git a/examples/widgets/mainwindows/menus/CMakeLists.txt b/examples/widgets/mainwindows/menus/CMakeLists.txt
index 311d2dbf03..9b3735eff8 100644
--- a/examples/widgets/mainwindows/menus/CMakeLists.txt
+++ b/examples/widgets/mainwindows/menus/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(menus LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/mainwindows/menus")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(menus PRIVATE
)
install(TARGETS menus
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET menus
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/mainwindows/menus/mainwindow.cpp b/examples/widgets/mainwindows/menus/mainwindow.cpp
index 114eb7d27b..c003d9f568 100644
--- a/examples/widgets/mainwindows/menus/mainwindow.cpp
+++ b/examples/widgets/mainwindows/menus/mainwindow.cpp
@@ -160,62 +160,73 @@ void MainWindow::aboutQt()
void MainWindow::createActions()
{
//! [5]
- newAct = new QAction(tr("&New"), this);
+ newAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::DocumentNew),
+ tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Create a new file"));
connect(newAct, &QAction::triggered, this, &MainWindow::newFile);
//! [4]
- openAct = new QAction(tr("&Open..."), this);
+ openAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen),
+ tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, &QAction::triggered, this, &MainWindow::open);
//! [5]
- saveAct = new QAction(tr("&Save"), this);
+ saveAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::DocumentSave),
+ tr("&Save"), this);
saveAct->setShortcuts(QKeySequence::Save);
saveAct->setStatusTip(tr("Save the document to disk"));
connect(saveAct, &QAction::triggered, this, &MainWindow::save);
- printAct = new QAction(tr("&Print..."), this);
+ printAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::DocumentPrint),
+ tr("&Print..."), this);
printAct->setShortcuts(QKeySequence::Print);
printAct->setStatusTip(tr("Print the document"));
connect(printAct, &QAction::triggered, this, &MainWindow::print);
- exitAct = new QAction(tr("E&xit"), this);
+ exitAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::ApplicationExit),
+ tr("E&xit"), this);
exitAct->setShortcuts(QKeySequence::Quit);
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, &QAction::triggered, this, &QWidget::close);
- undoAct = new QAction(tr("&Undo"), this);
+ undoAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::EditUndo),
+ tr("&Undo"), this);
undoAct->setShortcuts(QKeySequence::Undo);
undoAct->setStatusTip(tr("Undo the last operation"));
connect(undoAct, &QAction::triggered, this, &MainWindow::undo);
- redoAct = new QAction(tr("&Redo"), this);
+ redoAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::EditRedo),
+ tr("&Redo"), this);
redoAct->setShortcuts(QKeySequence::Redo);
redoAct->setStatusTip(tr("Redo the last operation"));
connect(redoAct, &QAction::triggered, this, &MainWindow::redo);
- cutAct = new QAction(tr("Cu&t"), this);
+ cutAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::EditCut),
+ tr("Cu&t"), this);
cutAct->setShortcuts(QKeySequence::Cut);
cutAct->setStatusTip(tr("Cut the current selection's contents to the "
"clipboard"));
connect(cutAct, &QAction::triggered, this, &MainWindow::cut);
- copyAct = new QAction(tr("&Copy"), this);
+ copyAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::EditCopy),
+ tr("&Copy"), this);
copyAct->setShortcuts(QKeySequence::Copy);
copyAct->setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"));
connect(copyAct, &QAction::triggered, this, &MainWindow::copy);
- pasteAct = new QAction(tr("&Paste"), this);
+ pasteAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::EditPaste),
+ tr("&Paste"), this);
pasteAct->setShortcuts(QKeySequence::Paste);
pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
"selection"));
connect(pasteAct, &QAction::triggered, this, &MainWindow::paste);
- boldAct = new QAction(tr("&Bold"), this);
+ boldAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FormatTextBold),
+ tr("&Bold"), this);
boldAct->setCheckable(true);
boldAct->setShortcut(QKeySequence::Bold);
boldAct->setStatusTip(tr("Make the text bold"));
@@ -225,7 +236,8 @@ void MainWindow::createActions()
boldFont.setBold(true);
boldAct->setFont(boldFont);
- italicAct = new QAction(tr("&Italic"), this);
+ italicAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FormatTextItalic),
+ tr("&Italic"), this);
italicAct->setCheckable(true);
italicAct->setShortcut(QKeySequence::Italic);
italicAct->setStatusTip(tr("Make the text italic"));
@@ -245,7 +257,8 @@ void MainWindow::createActions()
connect(setParagraphSpacingAct, &QAction::triggered,
this, &MainWindow::setParagraphSpacing);
- aboutAct = new QAction(tr("&About"), this);
+ aboutAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::HelpAbout),
+ tr("&About"), this);
aboutAct->setStatusTip(tr("Show the application's About box"));
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
@@ -254,25 +267,29 @@ void MainWindow::createActions()
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
connect(aboutQtAct, &QAction::triggered, this, &MainWindow::aboutQt);
- leftAlignAct = new QAction(tr("&Left Align"), this);
+ leftAlignAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FormatJustifyLeft),
+ tr("&Left Align"), this);
leftAlignAct->setCheckable(true);
leftAlignAct->setShortcut(tr("Ctrl+L"));
leftAlignAct->setStatusTip(tr("Left align the selected text"));
connect(leftAlignAct, &QAction::triggered, this, &MainWindow::leftAlign);
- rightAlignAct = new QAction(tr("&Right Align"), this);
+ rightAlignAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FormatJustifyRight),
+ tr("&Right Align"), this);
rightAlignAct->setCheckable(true);
rightAlignAct->setShortcut(tr("Ctrl+R"));
rightAlignAct->setStatusTip(tr("Right align the selected text"));
connect(rightAlignAct, &QAction::triggered, this, &MainWindow::rightAlign);
- justifyAct = new QAction(tr("&Justify"), this);
+ justifyAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FormatJustifyFill),
+ tr("&Justify"), this);
justifyAct->setCheckable(true);
justifyAct->setShortcut(tr("Ctrl+J"));
justifyAct->setStatusTip(tr("Justify the selected text"));
connect(justifyAct, &QAction::triggered, this, &MainWindow::justify);
- centerAct = new QAction(tr("&Center"), this);
+ centerAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FormatJustifyCenter),
+ tr("&Center"), this);
centerAct->setCheckable(true);
centerAct->setShortcut(tr("Ctrl+E"));
centerAct->setStatusTip(tr("Center the selected text"));
diff --git a/examples/widgets/painting/CMakeLists.txt b/examples/widgets/painting/CMakeLists.txt
index df0bfe9007..8a0b625e4d 100644
--- a/examples/widgets/painting/CMakeLists.txt
+++ b/examples/widgets/painting/CMakeLists.txt
@@ -1,14 +1,12 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(basicdrawing)
-qt_internal_add_example(concentriccircles)
qt_internal_add_example(affine)
-# qt_internal_add_example(composition) # FIXME: Seems buggy wrt. usesOpenGL function
+qt_internal_add_example(composition)
qt_internal_add_example(deform)
qt_internal_add_example(gradients)
qt_internal_add_example(pathstroke)
qt_internal_add_example(imagecomposition)
qt_internal_add_example(painterpaths)
qt_internal_add_example(transformations)
-qt_internal_add_example(fontsampler)
diff --git a/examples/widgets/painting/affine/CMakeLists.txt b/examples/widgets/painting/affine/CMakeLists.txt
index 1fbf9e4e0c..dd39086620 100644
--- a/examples/widgets/painting/affine/CMakeLists.txt
+++ b/examples/widgets/painting/affine/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(affine LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/affine")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -97,7 +91,14 @@ qt_add_resources(affine "affine"
)
install(TARGETS affine
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET affine
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/affine/main.cpp b/examples/widgets/painting/affine/main.cpp
index 3efd2125ac..1f9c2399c9 100644
--- a/examples/widgets/painting/affine/main.cpp
+++ b/examples/widgets/painting/affine/main.cpp
@@ -7,8 +7,6 @@
int main(int argc, char **argv)
{
- Q_INIT_RESOURCE(affine);
-
QApplication app(argc, argv);
XFormWidget xformWidget(nullptr);
diff --git a/examples/widgets/painting/affine/xform.cpp b/examples/widgets/painting/affine/xform.cpp
index 87d653acd3..5754490eed 100644
--- a/examples/widgets/painting/affine/xform.cpp
+++ b/examples/widgets/painting/affine/xform.cpp
@@ -777,12 +777,6 @@ XFormWidget::XFormWidget(QWidget *parent)
QPushButton *showSourceButton = new QPushButton(mainGroup);
showSourceButton->setText(tr("Show Source"));
-#if QT_CONFIG(opengl)
- QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
- enableOpenGLButton->setText(tr("Use OpenGL"));
- enableOpenGLButton->setCheckable(true);
- enableOpenGLButton->setChecked(view->usesOpenGL());
-#endif
QPushButton *whatsThisButton = new QPushButton(mainGroup);
whatsThisButton->setText(tr("What's This?"));
whatsThisButton->setCheckable(true);
@@ -812,9 +806,6 @@ XFormWidget::XFormWidget(QWidget *parent)
mainGroupLayout->addWidget(resetButton);
mainGroupLayout->addWidget(animateButton);
mainGroupLayout->addWidget(showSourceButton);
-#if QT_CONFIG(opengl)
- mainGroupLayout->addWidget(enableOpenGLButton);
-#endif
mainGroupLayout->addWidget(whatsThisButton);
mainGroup->setLayout(mainGroupLayout);
@@ -852,9 +843,6 @@ XFormWidget::XFormWidget(QWidget *parent)
connect(view, &XFormView::descriptionEnabledChanged, view->hoverPoints(), &HoverPoints::setDisabled);
connect(view, &XFormView::descriptionEnabledChanged, whatsThisButton, &QPushButton::setChecked);
connect(showSourceButton, &QPushButton::clicked, view, &XFormView::showSource);
-#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, &QPushButton::clicked, view, &XFormView::enableOpenGL);
-#endif
view->loadSourceFile(":res/affine/xform.cpp");
view->loadDescription(":res/affine/xform.html");
diff --git a/examples/widgets/painting/basicdrawing/CMakeLists.txt b/examples/widgets/painting/basicdrawing/CMakeLists.txt
index 1065ecb8b0..c3fb855709 100644
--- a/examples/widgets/painting/basicdrawing/CMakeLists.txt
+++ b/examples/widgets/painting/basicdrawing/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(basicdrawing LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/basicdrawing")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -45,7 +39,14 @@ qt_add_resources(basicdrawing "basicdrawing"
)
install(TARGETS basicdrawing
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET basicdrawing
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/basicdrawing/main.cpp b/examples/widgets/painting/basicdrawing/main.cpp
index 67a6d84562..1d8fd919b2 100644
--- a/examples/widgets/painting/basicdrawing/main.cpp
+++ b/examples/widgets/painting/basicdrawing/main.cpp
@@ -7,8 +7,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(basicdrawing);
-
QApplication app(argc, argv);
Window window;
window.show();
diff --git a/examples/widgets/painting/composition/CMakeLists.txt b/examples/widgets/painting/composition/CMakeLists.txt
index a27d59670a..b88ee42e41 100644
--- a/examples/widgets/painting/composition/CMakeLists.txt
+++ b/examples/widgets/painting/composition/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(composition LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/composition")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -98,7 +92,14 @@ qt_add_resources(composition "composition"
)
install(TARGETS composition
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET composition
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp
index b902498b2d..b4fb4fa3f7 100644
--- a/examples/widgets/painting/composition/composition.cpp
+++ b/examples/widgets/painting/composition/composition.cpp
@@ -10,11 +10,6 @@
#include <QMouseEvent>
#include <qmath.h>
-#if QT_CONFIG(opengl)
-#include <QOpenGLFunctions>
-#include <QOpenGLWindow>
-#endif
-
const int animationInterval = 15; // update every 16 ms = ~60FPS
CompositionWidget::CompositionWidget(QWidget *parent)
@@ -94,12 +89,6 @@ CompositionWidget::CompositionWidget(QWidget *parent)
QPushButton *showSourceButton = new QPushButton(mainGroup);
showSourceButton->setText(tr("Show Source"));
-#if QT_CONFIG(opengl)
- QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
- enableOpenGLButton->setText(tr("Use OpenGL"));
- enableOpenGLButton->setCheckable(true);
- enableOpenGLButton->setChecked(view->usesOpenGL());
-#endif
QPushButton *whatsThisButton = new QPushButton(mainGroup);
whatsThisButton->setText(tr("What's This?"));
whatsThisButton->setCheckable(true);
@@ -121,9 +110,6 @@ CompositionWidget::CompositionWidget(QWidget *parent)
mainGroupLayout->addWidget(animateButton);
mainGroupLayout->addWidget(whatsThisButton);
mainGroupLayout->addWidget(showSourceButton);
-#if QT_CONFIG(opengl)
- mainGroupLayout->addWidget(enableOpenGLButton);
-#endif
QGridLayout *modesLayout = new QGridLayout(modesGroup);
modesLayout->addWidget(rbClear, 0, 0);
@@ -165,9 +151,6 @@ CompositionWidget::CompositionWidget(QWidget *parent)
connect(whatsThisButton, &QAbstractButton::clicked, view, &ArthurFrame::setDescriptionEnabled);
connect(view, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked);
connect(showSourceButton, &QAbstractButton::clicked, view, &ArthurFrame::showSource);
-#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, &QAbstractButton::clicked, view, &ArthurFrame::enableOpenGL);
-#endif
connect(animateButton, &QAbstractButton::toggled, view, &CompositionRenderer::setAnimationEnabled);
circleColorSlider->setValue(270);
@@ -217,10 +200,6 @@ CompositionRenderer::CompositionRenderer(QWidget *parent)
m_circle_pos = QPoint(200, 100);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-#if QT_CONFIG(opengl)
- m_pbuffer_size = 1024;
- m_base_tex = 0;
-#endif
}
CompositionRenderer::~CompositionRenderer()
@@ -313,89 +292,25 @@ void CompositionRenderer::drawSource(QPainter &p)
void CompositionRenderer::paint(QPainter *painter)
{
-#if QT_CONFIG(opengl)
- if (usesOpenGL() && glWindow()->isValid()) {
- auto *funcs = QOpenGLContext::currentContext()->functions();
-
- if (!m_blitter.isCreated())
- m_blitter.create();
-
- int new_pbuf_size = m_pbuffer_size;
- while (size().width() > new_pbuf_size || size().height() > new_pbuf_size)
- new_pbuf_size *= 2;
-
- while (size().width() < new_pbuf_size/2 && size().height() < new_pbuf_size/2)
- new_pbuf_size /= 2;
-
- if (!m_fbo || new_pbuf_size != m_pbuffer_size) {
- m_fbo.reset(new QFboPaintDevice(QSize(new_pbuf_size, new_pbuf_size), false, false));
- m_pbuffer_size = new_pbuf_size;
- }
-
- if (size() != m_previous_size) {
- m_previous_size = size();
- QPainter p(m_fbo.get());
- p.setCompositionMode(QPainter::CompositionMode_Source);
- p.fillRect(QRect(QPoint(0, 0), size()), Qt::transparent);
- p.setCompositionMode(QPainter::CompositionMode_SourceOver);
- drawBase(p);
- p.end();
- if (m_base_tex)
- funcs->glDeleteTextures(1, &m_base_tex);
- m_base_tex = m_fbo->takeTexture();
- }
-
- painter->beginNativePainting();
- uint compositingTex;
- {
- QPainter p(m_fbo.get());
- p.beginNativePainting();
- m_blitter.bind();
- const QRect targetRect(QPoint(0, 0), m_fbo->size());
- const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), m_fbo->size()));
- m_blitter.blit(m_base_tex, target, QOpenGLTextureBlitter::OriginBottomLeft);
- m_blitter.release();
- p.endNativePainting();
- drawSource(p);
- p.end();
- compositingTex = m_fbo->texture();
- }
- painter->endNativePainting();
-
- painter->beginNativePainting();
- funcs->glEnable(GL_BLEND);
- funcs->glBlendEquation(GL_FUNC_ADD);
- funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- m_blitter.bind();
- const QRect targetRect(QPoint(0, 0), m_fbo->size());
- const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size()));
- m_blitter.blit(compositingTex, target, QOpenGLTextureBlitter::OriginBottomLeft);
- m_blitter.release();
- painter->endNativePainting();
- } else
-#endif
- {
- // using a QImage
- if (m_buffer.size() != size()) {
- m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
- m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+ if (m_buffer.size() != size()) {
+ m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+ m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
- m_base_buffer.fill(0);
+ m_base_buffer.fill(0);
- QPainter p(&m_base_buffer);
+ QPainter p(&m_base_buffer);
- drawBase(p);
- }
-
- memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes());
+ drawBase(p);
+ }
- {
- QPainter p(&m_buffer);
- drawSource(p);
- }
+ memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes());
- painter->drawImage(0, 0, m_buffer);
+ {
+ QPainter p(&m_buffer);
+ drawSource(p);
}
+
+ painter->drawImage(0, 0, m_buffer);
}
void CompositionRenderer::mousePressEvent(QMouseEvent *e)
@@ -443,12 +358,6 @@ 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 QT_CONFIG(opengl)
- if (usesOpenGL()) {
- update();
- return;
- }
-#endif
update(oldRect | newRect);
}
diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h
index 0745eb41b9..6a5206da08 100644
--- a/examples/widgets/painting/composition/composition.h
+++ b/examples/widgets/painting/composition/composition.h
@@ -6,11 +6,6 @@
#include "arthurwidgets.h"
-#if QT_CONFIG(opengl)
-#include "fbopaintdevice.h"
-#include <QOpenGLTextureBlitter>
-#endif
-
#include <QPainter>
#include <QEvent>
@@ -143,14 +138,6 @@ private:
ObjectType m_current_object;
bool m_animation_enabled;
int m_animationTimer;
-
-#if QT_CONFIG(opengl)
- std::unique_ptr<QFboPaintDevice> m_fbo;
- int m_pbuffer_size; // width==height==size of pbuffer
- uint m_base_tex;
- QSize m_previous_size;
- QOpenGLTextureBlitter m_blitter;
-#endif
};
#endif // COMPOSITION_H
diff --git a/examples/widgets/painting/concentriccircles/CMakeLists.txt b/examples/widgets/painting/concentriccircles/CMakeLists.txt
deleted file mode 100644
index 995a974b25..0000000000
--- a/examples/widgets/painting/concentriccircles/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(concentriccircles LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/concentriccircles")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(concentriccircles
- circlewidget.cpp circlewidget.h
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(concentriccircles PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(concentriccircles PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS concentriccircles
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/painting/concentriccircles/circlewidget.cpp b/examples/widgets/painting/concentriccircles/circlewidget.cpp
deleted file mode 100644
index febaa5d709..0000000000
--- a/examples/widgets/painting/concentriccircles/circlewidget.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "circlewidget.h"
-
-#include <QPainter>
-
-#include <stdlib.h>
-
-//! [0]
-CircleWidget::CircleWidget(QWidget *parent)
- : QWidget(parent)
-{
- floatBased = false;
- antialiased = false;
- frameNo = 0;
-
- setBackgroundRole(QPalette::Base);
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-}
-//! [0]
-
-//! [1]
-void CircleWidget::setFloatBased(bool floatBased)
-{
- this->floatBased = floatBased;
- update();
-}
-//! [1]
-
-//! [2]
-void CircleWidget::setAntialiased(bool antialiased)
-{
- this->antialiased = antialiased;
- update();
-}
-//! [2]
-
-//! [3]
-QSize CircleWidget::minimumSizeHint() const
-{
- return QSize(50, 50);
-}
-//! [3]
-
-//! [4]
-QSize CircleWidget::sizeHint() const
-{
- return QSize(180, 180);
-}
-//! [4]
-
-//! [5]
-void CircleWidget::nextAnimationFrame()
-{
- ++frameNo;
- update();
-}
-//! [5]
-
-//! [6]
-void CircleWidget::paintEvent(QPaintEvent *)
-{
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing, antialiased);
- painter.translate(width() / 2, height() / 2);
-//! [6]
-
-//! [7]
- for (int diameter = 0; diameter < 256; diameter += 9) {
- int delta = abs((frameNo % 128) - diameter / 2);
- int alpha = 255 - (delta * delta) / 4 - diameter;
-//! [7] //! [8]
- if (alpha > 0) {
- painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3));
-
- if (floatBased)
- painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0, diameter, diameter));
- else
- painter.drawEllipse(QRect(-diameter / 2, -diameter / 2, diameter, diameter));
- }
- }
-}
-//! [8]
diff --git a/examples/widgets/painting/concentriccircles/circlewidget.h b/examples/widgets/painting/concentriccircles/circlewidget.h
deleted file mode 100644
index 5632ee1d72..0000000000
--- a/examples/widgets/painting/concentriccircles/circlewidget.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef CIRCLEWIDGET_H
-#define CIRCLEWIDGET_H
-
-#include <QWidget>
-
-//! [0]
-class CircleWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- CircleWidget(QWidget *parent = nullptr);
-
- void setFloatBased(bool floatBased);
- void setAntialiased(bool antialiased);
-
- QSize minimumSizeHint() const override;
- QSize sizeHint() const override;
-
-public slots:
- void nextAnimationFrame();
-
-protected:
- void paintEvent(QPaintEvent *event) override;
-
-private:
- bool floatBased;
- bool antialiased;
- int frameNo;
-};
-//! [0]
-
-#endif // CIRCLEWIDGET_H
diff --git a/examples/widgets/painting/concentriccircles/concentriccircles.pro b/examples/widgets/painting/concentriccircles/concentriccircles.pro
deleted file mode 100644
index 844c01a9c2..0000000000
--- a/examples/widgets/painting/concentriccircles/concentriccircles.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-QT += widgets
-
-HEADERS = circlewidget.h \
- window.h
-SOURCES = circlewidget.cpp \
- main.cpp \
- window.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/painting/concentriccircles
-INSTALLS += target
diff --git a/examples/widgets/painting/concentriccircles/main.cpp b/examples/widgets/painting/concentriccircles/main.cpp
deleted file mode 100644
index 1d8fd919b2..0000000000
--- a/examples/widgets/painting/concentriccircles/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-
-#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Window window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/painting/concentriccircles/window.cpp b/examples/widgets/painting/concentriccircles/window.cpp
deleted file mode 100644
index 9f25c2fcde..0000000000
--- a/examples/widgets/painting/concentriccircles/window.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "circlewidget.h"
-#include "window.h"
-
-#include <QtWidgets>
-
-//! [0]
-Window::Window()
-{
- aliasedLabel = createLabel(tr("Aliased"));
- antialiasedLabel = createLabel(tr("Antialiased"));
- intLabel = createLabel(tr("Int"));
- floatLabel = createLabel(tr("Float"));
-
- QGridLayout *layout = new QGridLayout;
- layout->addWidget(aliasedLabel, 0, 1);
- layout->addWidget(antialiasedLabel, 0, 2);
- layout->addWidget(intLabel, 1, 0);
- layout->addWidget(floatLabel, 2, 0);
-//! [0]
-
-//! [1]
- QTimer *timer = new QTimer(this);
-
- for (int i = 0; i < 2; ++i) {
- for (int j = 0; j < 2; ++j) {
- circleWidgets[i][j] = new CircleWidget;
- circleWidgets[i][j]->setAntialiased(j != 0);
- circleWidgets[i][j]->setFloatBased(i != 0);
-
- connect(timer, &QTimer::timeout,
- circleWidgets[i][j], &CircleWidget::nextAnimationFrame);
-
- layout->addWidget(circleWidgets[i][j], i + 1, j + 1);
- }
- }
-//! [1] //! [2]
- timer->start(100);
- setLayout(layout);
-
- setWindowTitle(tr("Concentric Circles"));
-}
-//! [2]
-
-//! [3]
-QLabel *Window::createLabel(const QString &text)
-{
- QLabel *label = new QLabel(text);
- label->setAlignment(Qt::AlignCenter);
- label->setMargin(2);
- label->setFrameStyle(QFrame::Box | QFrame::Sunken);
- return label;
-}
-//! [3]
diff --git a/examples/widgets/painting/concentriccircles/window.h b/examples/widgets/painting/concentriccircles/window.h
deleted file mode 100644
index a111ffbe58..0000000000
--- a/examples/widgets/painting/concentriccircles/window.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-QT_END_NAMESPACE
-class CircleWidget;
-
-//! [0]
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window();
-
-private:
- QLabel *createLabel(const QString &text);
-
- QLabel *aliasedLabel;
- QLabel *antialiasedLabel;
- QLabel *intLabel;
- QLabel *floatLabel;
- CircleWidget *circleWidgets[2][2];
-};
-//! [0]
-
-#endif // WINDOW_H
diff --git a/examples/widgets/painting/deform/CMakeLists.txt b/examples/widgets/painting/deform/CMakeLists.txt
index 779d814172..1038df03ad 100644
--- a/examples/widgets/painting/deform/CMakeLists.txt
+++ b/examples/widgets/painting/deform/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(deform LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/deform")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -96,7 +90,14 @@ qt_add_resources(deform "deform"
)
install(TARGETS deform
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET deform
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/deform/main.cpp b/examples/widgets/painting/deform/main.cpp
index b81adc09b4..5ac5b4cc3f 100644
--- a/examples/widgets/painting/deform/main.cpp
+++ b/examples/widgets/painting/deform/main.cpp
@@ -7,8 +7,6 @@
int main(int argc, char **argv)
{
- Q_INIT_RESOURCE(deform);
-
QApplication app(argc, argv);
bool smallScreen = QApplication::arguments().contains("-small-screen");
diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp
index fead0e3c13..f2c67c1587 100644
--- a/examples/widgets/painting/deform/pathdeform.cpp
+++ b/examples/widgets/painting/deform/pathdeform.cpp
@@ -61,13 +61,6 @@ void PathDeformControls::layoutForDesktop()
QPushButton *showSourceButton = new QPushButton(mainGroup);
showSourceButton->setText(tr("Show Source"));
-#if QT_CONFIG(opengl)
- QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
- enableOpenGLButton->setText(tr("Use OpenGL"));
- enableOpenGLButton->setCheckable(true);
- enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
-#endif
-
QPushButton *whatsThisButton = new QPushButton(mainGroup);
whatsThisButton->setText(tr("What's This?"));
whatsThisButton->setCheckable(true);
@@ -82,9 +75,6 @@ void PathDeformControls::layoutForDesktop()
mainGroupLayout->addWidget(textGroup);
mainGroupLayout->addWidget(animateButton);
mainGroupLayout->addStretch(1);
-#if QT_CONFIG(opengl)
- mainGroupLayout->addWidget(enableOpenGLButton);
-#endif
mainGroupLayout->addWidget(showSourceButton);
mainGroupLayout->addWidget(whatsThisButton);
@@ -108,9 +98,6 @@ void PathDeformControls::layoutForDesktop()
connect(deformSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setIntensity);
connect(fontSizeSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setFontSize);
connect(animateButton, &QAbstractButton::clicked, m_renderer, &PathDeformRenderer::setAnimated);
-#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
-#endif
connect(textInput, &QLineEdit::textChanged, m_renderer, &PathDeformRenderer::setText);
connect(m_renderer, &ArthurFrame::descriptionEnabledChanged,
@@ -151,13 +138,6 @@ void PathDeformControls::layoutForSmallScreen()
QPushButton *animateButton = new QPushButton(tr("Animated"), mainGroup);
animateButton->setCheckable(true);
-#if QT_CONFIG(opengl)
- QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
- enableOpenGLButton->setText(tr("Use OpenGL"));
- enableOpenGLButton->setCheckable(mainGroup);
- enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
-#endif
-
QPushButton *quitButton = new QPushButton(tr("Quit"), mainGroup);
QPushButton *okButton = new QPushButton(tr("OK"), mainGroup);
@@ -171,9 +151,6 @@ void PathDeformControls::layoutForSmallScreen()
mainGroupLayout->addWidget(fontSizeLabel, 2, 0, Qt::AlignRight);
mainGroupLayout->addWidget(fontSizeSlider, 2, 1);
mainGroupLayout->addWidget(animateButton, 3,0, 1,2);
-#if QT_CONFIG(opengl)
- mainGroupLayout->addWidget(enableOpenGLButton, 4,0, 1,2);
-#endif
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(mainGroup);
@@ -187,10 +164,6 @@ void PathDeformControls::layoutForSmallScreen()
connect(deformSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setIntensity);
connect(fontSizeSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setFontSize);
connect(animateButton, &QAbstractButton::clicked, m_renderer, &PathDeformRenderer::setAnimated);
-#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
-#endif
-
animateButton->animateClick();
deformSlider->setValue(80);
@@ -380,7 +353,6 @@ void PathDeformRenderer::setAnimated(bool animated)
void PathDeformRenderer::timerEvent(QTimerEvent *e)
{
-
if (e->timerId() == m_repaintTimer.timerId()) {
if (QLineF(QPointF(0,0), m_direction).length() > 1)
@@ -414,22 +386,9 @@ void PathDeformRenderer::timerEvent(QTimerEvent *e)
m_pos.setY(height() - m_radius);
}
-#if QT_CONFIG(opengl)
- if (usesOpenGL()) {
- update();
- } else
-#endif
- {
- QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
- update(rectAfter | rectBefore);
- }
+ QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
+ update(rectAfter | rectBefore);
}
-// else if (e->timerId() == m_fpsTimer.timerId()) {
-// printf("fps: %d\n", m_fpsCounter);
-// emit frameRate(m_fpsCounter);
-// m_fpsCounter = 0;
-
-// }
}
void PathDeformRenderer::mousePressEvent(QMouseEvent *e)
@@ -478,15 +437,8 @@ void PathDeformRenderer::mouseMoveEvent(QMouseEvent *e)
m_direction = (m_direction + dir) / 2;
}
m_pos = e->position().toPoint() + m_offset;
-#if QT_CONFIG(opengl)
- if (usesOpenGL()) {
- update();
- } else
-#endif
- {
- QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
- update(rectBefore | rectAfter);
- }
+ QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
+ update(rectBefore | rectAfter);
}
}
@@ -570,27 +522,13 @@ void PathDeformRenderer::setRadius(int radius)
qreal max = qMax(m_radius, (qreal)radius);
m_radius = radius;
generateLensPixmap();
- if (!m_animated || m_radius < max) {
-#if QT_CONFIG(opengl)
- if (usesOpenGL()){
- update();
- return;
- }
-#endif
+ if (!m_animated || m_radius < max)
update(circle_bounds(m_pos, max, m_fontSize));
- }
}
void PathDeformRenderer::setIntensity(int intensity)
{
m_intensity = intensity;
- if (!m_animated) {
-#if QT_CONFIG(opengl)
- if (usesOpenGL()) {
- update();
- return;
- }
-#endif
+ if (!m_animated)
update(circle_bounds(m_pos, m_radius, m_fontSize));
- }
}
diff --git a/examples/widgets/painting/fontsampler/CMakeLists.txt b/examples/widgets/painting/fontsampler/CMakeLists.txt
deleted file mode 100644
index faaf510c0f..0000000000
--- a/examples/widgets/painting/fontsampler/CMakeLists.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(fontsampler LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/fontsampler")
-
-find_package(Qt6
- REQUIRED COMPONENTS Core Gui Widgets
- OPTIONAL_COMPONENTS PrintSupport
-)
-
-qt_standard_project_setup()
-
-qt_add_executable(fontsampler
- main.cpp
- mainwindow.cpp mainwindow.h
- mainwindowbase.ui
-)
-
-set_target_properties(fontsampler PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(fontsampler PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if(TARGET Qt6::PrintSupport)
- target_link_libraries(fontsampler PRIVATE Qt6::PrintSupport)
-endif()
-
-install(TARGETS fontsampler
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/painting/fontsampler/fontsampler.pro b/examples/widgets/painting/fontsampler/fontsampler.pro
deleted file mode 100644
index 5d3461f4b8..0000000000
--- a/examples/widgets/painting/fontsampler/fontsampler.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-qtHaveModule(printsupport): QT += printsupport
-
-FORMS = mainwindowbase.ui
-HEADERS = mainwindow.h
-SOURCES = main.cpp \
- mainwindow.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/painting/fontsampler
-INSTALLS += target
diff --git a/examples/widgets/painting/fontsampler/main.cpp b/examples/widgets/painting/fontsampler/main.cpp
deleted file mode 100644
index 7d7cf3e573..0000000000
--- a/examples/widgets/painting/fontsampler/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp
deleted file mode 100644
index e2bd768f79..0000000000
--- a/examples/widgets/painting/fontsampler/mainwindow.cpp
+++ /dev/null
@@ -1,314 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#if QT_CONFIG(printdialog)
-#include <QPrinter>
-#include <QPrintDialog>
-#if QT_CONFIG(printpreviewdialog)
-#include <QPrintPreviewDialog>
-#endif
-#endif
-#endif
-
-#include "mainwindow.h"
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
-{
- setupUi(this);
-
- sampleSizes << 32 << 24 << 16 << 14 << 12 << 8 << 4 << 2 << 1;
- markedCount = 0;
- setupFontTree();
-
- connect(quitAction, &QAction::triggered,
- qApp, &QApplication::quit);
- connect(fontTree, &QTreeWidget::currentItemChanged,
- this, &MainWindow::showFont);
- connect(fontTree, &QTreeWidget::itemChanged,
- this, &MainWindow::updateStyles);
-
- fontTree->topLevelItem(0)->setSelected(true);
- showFont(fontTree->topLevelItem(0));
-}
-
-void MainWindow::setupFontTree()
-{
- fontTree->setColumnCount(1);
- fontTree->setHeaderLabels({ tr("Font") });
-
- const QStringList fontFamilies = QFontDatabase::families();
- for (const QString &family : fontFamilies) {
- const QStringList styles = QFontDatabase::styles(family);
- if (styles.isEmpty())
- continue;
-
- QTreeWidgetItem *familyItem = new QTreeWidgetItem(fontTree);
- familyItem->setText(0, family);
- familyItem->setCheckState(0, Qt::Unchecked);
- familyItem->setFlags(familyItem->flags() | Qt::ItemIsAutoTristate);
-
- for (const QString &style : styles) {
- QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
- styleItem->setText(0, style);
- styleItem->setCheckState(0, Qt::Unchecked);
- styleItem->setData(0, Qt::UserRole, QVariant(QFontDatabase::weight(family, style)));
- styleItem->setData(0, Qt::UserRole + 1, QVariant(QFontDatabase::italic(family, style)));
- }
- }
-}
-
-void MainWindow::on_clearAction_triggered()
-{
- const QList<QTreeWidgetItem *> items = fontTree->selectedItems();
- for (QTreeWidgetItem *item : items)
- item->setSelected(false);
- fontTree->currentItem()->setSelected(true);
-}
-
-void MainWindow::on_markAction_triggered()
-{
- markUnmarkFonts(Qt::Checked);
-}
-
-void MainWindow::on_unmarkAction_triggered()
-{
- markUnmarkFonts(Qt::Unchecked);
-}
-
-void MainWindow::markUnmarkFonts(Qt::CheckState state)
-{
- const QList<QTreeWidgetItem *> items = fontTree->selectedItems();
- for (QTreeWidgetItem *item : items) {
- if (item->checkState(0) != state)
- item->setCheckState(0, state);
- }
-}
-
-void MainWindow::showFont(QTreeWidgetItem *item)
-{
- if (!item)
- return;
-
- QString family;
- QString style;
- int weight;
- bool italic;
-
- if (item->parent()) {
- family = item->parent()->text(0);
- style = item->text(0);
- weight = item->data(0, Qt::UserRole).toInt();
- italic = item->data(0, Qt::UserRole + 1).toBool();
- } else {
- family = item->text(0);
- style = item->child(0)->text(0);
- weight = item->child(0)->data(0, Qt::UserRole).toInt();
- italic = item->child(0)->data(0, Qt::UserRole + 1).toBool();
- }
-
- QString oldText = textEdit->toPlainText().trimmed();
- bool modified = textEdit->document()->isModified();
- textEdit->clear();
- QFont font(family, 32, weight, italic);
- font.setStyleName(style);
- textEdit->document()->setDefaultFont(font);
-
- QTextCursor cursor = textEdit->textCursor();
- QTextBlockFormat blockFormat;
- blockFormat.setAlignment(Qt::AlignCenter);
- cursor.insertBlock(blockFormat);
-
- if (modified)
- cursor.insertText(QString(oldText));
- else
- cursor.insertText(QString("%1 %2").arg(family).arg(style));
-
- textEdit->document()->setModified(modified);
-}
-
-void MainWindow::updateStyles(QTreeWidgetItem *item, int column)
-{
- if (!item || column != 0)
- return;
-
- Qt::CheckState state = item->checkState(0);
- QTreeWidgetItem *parent = item->parent();
-
- if (parent) {
- // Only count style items.
- if (state == Qt::Checked)
- ++markedCount;
- else
- --markedCount;
- }
-
- printAction->setEnabled(markedCount > 0);
- printPreviewAction->setEnabled(markedCount > 0);
-}
-
-QMap<QString, StyleItems> MainWindow::currentPageMap()
-{
- QMap<QString, StyleItems> pageMap;
-
- for (int row = 0; row < fontTree->topLevelItemCount(); ++row) {
- QTreeWidgetItem *familyItem = fontTree->topLevelItem(row);
- QString family;
-
- if (familyItem->checkState(0) == Qt::Checked) {
- family = familyItem->text(0);
- pageMap[family] = StyleItems();
- }
-
- for (int childRow = 0; childRow < familyItem->childCount(); ++childRow) {
- QTreeWidgetItem *styleItem = familyItem->child(childRow);
- if (styleItem->checkState(0) == Qt::Checked)
- pageMap[family].append(styleItem);
- }
- }
-
- return pageMap;
-}
-
-void MainWindow::on_printAction_triggered()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- pageMap = currentPageMap();
-
- if (pageMap.count() == 0)
- return;
-
- QPrinter printer(QPrinter::HighResolution);
- QPrintDialog dialog(&printer, this);
- if (dialog.exec() != QDialog::Accepted)
- return;
-
- int from = printer.fromPage();
- int to = printer.toPage();
- if (from <= 0 && to <= 0)
- printer.setFromTo(1, pageMap.keys().count());
-
- printDocument(&printer);
-#endif
-}
-
-void MainWindow::printDocument(QPrinter *printer)
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- printer->setFromTo(1, pageMap.count());
-
- QProgressDialog progress(tr("Preparing font samples..."), tr("&Cancel"),
- 0, pageMap.count(), this);
- progress.setWindowModality(Qt::ApplicationModal);
- progress.setWindowTitle(tr("Font Sampler"));
- progress.setMinimum(printer->fromPage() - 1);
- progress.setMaximum(printer->toPage());
-
- QPainter painter;
- painter.begin(printer);
- bool firstPage = true;
-
- for (int page = printer->fromPage(); page <= printer->toPage(); ++page) {
-
- if (!firstPage)
- printer->newPage();
-
- qApp->processEvents();
- if (progress.wasCanceled())
- break;
-
- printPage(page - 1, &painter, printer);
- progress.setValue(page);
- firstPage = false;
- }
-
- painter.end();
-#endif
-}
-
-void MainWindow::on_printPreviewAction_triggered()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printpreviewdialog)
- pageMap = currentPageMap();
-
- if (pageMap.count() == 0)
- return;
-
- QPrinter printer(QPrinter::HighResolution);
- QPrintPreviewDialog preview(&printer, this);
- connect(&preview, &QPrintPreviewDialog::paintRequested,
- this, &MainWindow::printDocument);
- preview.exec();
-#endif
-}
-
-void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer)
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- const QString family = std::next(pageMap.begin(), index).key();
- const StyleItems items = pageMap.value(family);
-
- // Find the dimensions of the text on each page.
- qreal width = 0.0;
- qreal height = 0.0;
- for (const QTreeWidgetItem *item : items) {
- QString style = item->text(0);
- int weight = item->data(0, Qt::UserRole).toInt();
- bool italic = item->data(0, Qt::UserRole + 1).toBool();
-
- // Calculate the maximum width and total height of the text.
- for (int size : std::as_const(sampleSizes)) {
- QFont font(family, size, weight, italic);
- font.setStyleName(style);
- font = QFont(font, painter->device());
- QFontMetricsF fontMetrics(font);
- QRectF rect = fontMetrics.boundingRect(
- QString("%1 %2").arg(family).arg(style));
- width = qMax(rect.width(), width);
- height += rect.height();
- }
- }
-
- qreal xScale = printer->pageRect(QPrinter::DevicePixel).width() / width;
- qreal yScale = printer->pageRect(QPrinter::DevicePixel).height() / height;
- qreal scale = qMin(xScale, yScale);
-
- qreal remainingHeight = printer->pageRect(QPrinter::DevicePixel).height()/scale - height;
- qreal spaceHeight = (remainingHeight / 4.0) / (items.count() + 1);
- qreal interLineHeight = (remainingHeight / 4.0) / (sampleSizes.count() * items.count());
-
- painter->save();
- painter->translate(printer->pageRect(QPrinter::DevicePixel).width() / 2.0, printer->pageRect(QPrinter::DevicePixel).height() / 2.0);
- painter->scale(scale, scale);
- painter->setBrush(QBrush(Qt::black));
-
- qreal x = -width / 2.0;
- qreal y = -height / 2.0 - remainingHeight / 4.0 + spaceHeight;
-
- for (const QTreeWidgetItem *item : items) {
- QString style = item->text(0);
- int weight = item->data(0, Qt::UserRole).toInt();
- bool italic = item->data(0, Qt::UserRole + 1).toBool();
-
- // Draw each line of text.
- for (int size : std::as_const(sampleSizes)) {
- QFont font(family, size, weight, italic);
- font.setStyleName(style);
- font = QFont(font, painter->device());
- QFontMetricsF fontMetrics(font);
- QRectF rect = fontMetrics.boundingRect(QString("%1 %2").arg(
- font.family()).arg(style));
- y += rect.height();
- painter->setFont(font);
- painter->drawText(QPointF(x, y), QString("%1 %2").arg(family).arg(style));
- y += interLineHeight;
- }
- y += spaceHeight;
- }
-
- painter->restore();
-#endif
-}
diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h
deleted file mode 100644
index 131fb06312..0000000000
--- a/examples/widgets/painting/fontsampler/mainwindow.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include "ui_mainwindowbase.h"
-
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#endif
-
-#include <QList>
-#include <QMap>
-#include <QString>
-
-QT_BEGIN_NAMESPACE
-class QPrinter;
-class QTextEdit;
-class QTreeWidget;
-class QTreeWidgetItem;
-QT_END_NAMESPACE
-
-typedef QList<QTreeWidgetItem *> StyleItems;
-
-class MainWindow : public QMainWindow, private Ui::MainWindowBase
-{
- Q_OBJECT
-
-public:
- MainWindow(QWidget *parent = nullptr);
-
-public slots:
- void on_clearAction_triggered();
- void on_markAction_triggered();
- void on_unmarkAction_triggered();
- void on_printAction_triggered();
- void on_printPreviewAction_triggered();
- void printDocument(QPrinter *printer);
- void printPage(int index, QPainter *painter, QPrinter *printer);
- void showFont(QTreeWidgetItem *item);
- void updateStyles(QTreeWidgetItem *item, int column);
-
-private:
- QMap<QString, StyleItems> currentPageMap();
- void markUnmarkFonts(Qt::CheckState state);
- void setupFontTree();
-
- QList<int> sampleSizes;
- QMap<QString, StyleItems> pageMap;
- int markedCount;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/painting/fontsampler/mainwindowbase.ui b/examples/widgets/painting/fontsampler/mainwindowbase.ui
deleted file mode 100644
index 1a95ebd6d1..0000000000
--- a/examples/widgets/painting/fontsampler/mainwindowbase.ui
+++ /dev/null
@@ -1,142 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>MainWindowBase</class>
- <widget class="QMainWindow" name="MainWindowBase">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>800</width>
- <height>345</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Font Sampler</string>
- </property>
- <widget class="QWidget" name="centralwidget">
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>9</number>
- </property>
- <item>
- <widget class="QTextEdit" name="textEdit"/>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menubar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>800</width>
- <height>18</height>
- </rect>
- </property>
- <widget class="QMenu" name="menu_Selection">
- <property name="title">
- <string>&amp;Selection</string>
- </property>
- <addaction name="markAction"/>
- <addaction name="unmarkAction"/>
- <addaction name="clearAction"/>
- </widget>
- <widget class="QMenu" name="menu_File">
- <property name="title">
- <string>&amp;File</string>
- </property>
- <addaction name="printPreviewAction"/>
- <addaction name="printAction"/>
- <addaction name="quitAction"/>
- </widget>
- <addaction name="menu_File"/>
- <addaction name="menu_Selection"/>
- </widget>
- <widget class="QStatusBar" name="statusbar"/>
- <widget class="QDockWidget" name="dockWidget">
- <property name="features">
- <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
- </property>
- <property name="windowTitle">
- <string>Available Fonts</string>
- </property>
- <attribute name="dockWidgetArea">
- <number>1</number>
- </attribute>
- <widget class="QWidget" name="dockWidgetContents">
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>9</number>
- </property>
- <item>
- <widget class="QTreeWidget" name="fontTree">
- <property name="selectionMode">
- <enum>QAbstractItemView::ExtendedSelection</enum>
- </property>
- <column>
- <property name="text">
- <string notr="true">1</string>
- </property>
- </column>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
- <action name="printAction">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>&amp;Print...</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+P</string>
- </property>
- </action>
- <action name="quitAction">
- <property name="text">
- <string>E&amp;xit</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+Q</string>
- </property>
- </action>
- <action name="markAction">
- <property name="text">
- <string>&amp;Mark</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+M</string>
- </property>
- </action>
- <action name="unmarkAction">
- <property name="text">
- <string>&amp;Unmark</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+U</string>
- </property>
- </action>
- <action name="clearAction">
- <property name="text">
- <string>&amp;Clear</string>
- </property>
- </action>
- <action name="printPreviewAction">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Print Preview...</string>
- </property>
- </action>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/widgets/painting/gradients/CMakeLists.txt b/examples/widgets/painting/gradients/CMakeLists.txt
index ed8f0082cb..39cc44ed8f 100644
--- a/examples/widgets/painting/gradients/CMakeLists.txt
+++ b/examples/widgets/painting/gradients/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(gradients LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/gradients")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -96,7 +90,14 @@ qt_add_resources(gradients "gradients"
)
install(TARGETS gradients
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET gradients
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
index 538d851eb8..5ed3d764d1 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -273,12 +273,6 @@ GradientWidget::GradientWidget(QWidget *parent)
QPushButton *showSourceButton = new QPushButton(mainGroup);
showSourceButton->setText(tr("Show Source"));
-#if QT_CONFIG(opengl)
- QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
- enableOpenGLButton->setText(tr("Use OpenGL"));
- enableOpenGLButton->setCheckable(true);
- enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
-#endif
QPushButton *whatsThisButton = new QPushButton(mainGroup);
whatsThisButton->setText(tr("What's This?"));
whatsThisButton->setCheckable(true);
@@ -292,9 +286,6 @@ GradientWidget::GradientWidget(QWidget *parent)
mainGroupLayout->addWidget(defaultsGroup);
mainGroupLayout->addStretch(1);
mainGroupLayout->addWidget(showSourceButton);
-#if QT_CONFIG(opengl)
- mainGroupLayout->addWidget(enableOpenGLButton);
-#endif
mainGroupLayout->addWidget(whatsThisButton);
QVBoxLayout *editorGroupLayout = new QVBoxLayout(editorGroup);
@@ -370,11 +361,6 @@ GradientWidget::GradientWidget(QWidget *parent)
connect(showSourceButton, &QPushButton::clicked,
m_renderer, &GradientRenderer::showSource);
-#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, QOverload<bool>::of(&QPushButton::clicked),
- m_renderer, &ArthurFrame::enableOpenGL);
-#endif
-
connect(whatsThisButton, QOverload<bool>::of(&QPushButton::clicked),
m_renderer, &ArthurFrame::setDescriptionEnabled);
connect(whatsThisButton, QOverload<bool>::of(&QPushButton::clicked),
diff --git a/examples/widgets/painting/gradients/main.cpp b/examples/widgets/painting/gradients/main.cpp
index f3b75a749c..c1e2297512 100644
--- a/examples/widgets/painting/gradients/main.cpp
+++ b/examples/widgets/painting/gradients/main.cpp
@@ -7,8 +7,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(gradients);
-
QApplication app(argc, argv);
GradientWidget gradientWidget;
diff --git a/examples/widgets/painting/imagecomposition/CMakeLists.txt b/examples/widgets/painting/imagecomposition/CMakeLists.txt
index 1cfb2a6732..eea0c24173 100644
--- a/examples/widgets/painting/imagecomposition/CMakeLists.txt
+++ b/examples/widgets/painting/imagecomposition/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(imagecomposition LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/imagecomposition")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -44,7 +38,14 @@ qt_add_resources(imagecomposition "imagecomposition"
)
install(TARGETS imagecomposition
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET imagecomposition
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/imagecomposition/main.cpp b/examples/widgets/painting/imagecomposition/main.cpp
index cd5468f088..a3cf65a344 100644
--- a/examples/widgets/painting/imagecomposition/main.cpp
+++ b/examples/widgets/painting/imagecomposition/main.cpp
@@ -8,8 +8,6 @@
//! [0]
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(imagecomposition);
-
QApplication app(argc, argv);
ImageComposer composer;
composer.show();
diff --git a/examples/widgets/painting/painterpaths/CMakeLists.txt b/examples/widgets/painting/painterpaths/CMakeLists.txt
index 0a701d82ab..46f7948277 100644
--- a/examples/widgets/painting/painterpaths/CMakeLists.txt
+++ b/examples/widgets/painting/painterpaths/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(painterpaths LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/painterpaths")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -38,7 +32,14 @@ if(UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY AND NOT VXWORKS)
endif()
install(TARGETS painterpaths
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET painterpaths
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/painting.pro b/examples/widgets/painting/painting.pro
index a9749a560d..1dfd660f77 100644
--- a/examples/widgets/painting/painting.pro
+++ b/examples/widgets/painting/painting.pro
@@ -1,6 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = basicdrawing \
- concentriccircles \
affine \
composition \
deform \
@@ -8,8 +7,7 @@ SUBDIRS = basicdrawing \
pathstroke \
imagecomposition \
painterpaths \
- transformations \
- fontsampler
+ transformations
EXAMPLE_FILES = \
shared
diff --git a/examples/widgets/painting/pathstroke/CMakeLists.txt b/examples/widgets/painting/pathstroke/CMakeLists.txt
index 88208d0489..5c995617eb 100644
--- a/examples/widgets/painting/pathstroke/CMakeLists.txt
+++ b/examples/widgets/painting/pathstroke/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(pathstroke LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/pathstroke")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -96,7 +90,14 @@ qt_add_resources(pathstroke "pathstroke"
)
install(TARGETS pathstroke
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET pathstroke
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/painting/pathstroke/main.cpp b/examples/widgets/painting/pathstroke/main.cpp
index a5ceb9e3c6..4f991e8a0a 100644
--- a/examples/widgets/painting/pathstroke/main.cpp
+++ b/examples/widgets/painting/pathstroke/main.cpp
@@ -7,8 +7,6 @@
int main(int argc, char **argv)
{
- Q_INIT_RESOURCE(pathstroke);
-
QApplication app(argc, argv);
bool smallScreen = QApplication::arguments().contains("-small-screen");
diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp
index 8c0548bdf0..cd54a7a8aa 100644
--- a/examples/widgets/painting/pathstroke/pathstroke.cpp
+++ b/examples/widgets/painting/pathstroke/pathstroke.cpp
@@ -177,12 +177,6 @@ void PathStrokeControls::layoutForDesktop()
QPushButton *showSourceButton = new QPushButton(mainGroup);
showSourceButton->setText(tr("Show Source"));
-#if QT_CONFIG(opengl)
- QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
- enableOpenGLButton->setText(tr("Use OpenGL"));
- enableOpenGLButton->setCheckable(true);
- enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
-#endif
QPushButton *whatsThisButton = new QPushButton(mainGroup);
whatsThisButton->setText(tr("What's This?"));
whatsThisButton->setCheckable(true);
@@ -206,9 +200,6 @@ void PathStrokeControls::layoutForDesktop()
mainGroupLayout->addWidget(animated);
mainGroupLayout->addStretch(1);
mainGroupLayout->addWidget(showSourceButton);
-#if QT_CONFIG(opengl)
- mainGroupLayout->addWidget(enableOpenGLButton);
-#endif
mainGroupLayout->addWidget(whatsThisButton);
@@ -221,10 +212,6 @@ void PathStrokeControls::layoutForDesktop()
connect(showSourceButton, &QAbstractButton::clicked,
m_renderer, &ArthurFrame::showSource);
-#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, &QAbstractButton::clicked,
- m_renderer, &ArthurFrame::enableOpenGL);
-#endif
connect(whatsThisButton, &QAbstractButton::clicked,
m_renderer, &ArthurFrame::setDescriptionEnabled);
connect(m_renderer, &ArthurFrame::descriptionEnabledChanged,
@@ -259,13 +246,6 @@ void PathStrokeControls::layoutForSmallScreens()
penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
penWidth->setRange(0, 500);
-#if QT_CONFIG(opengl)
- QPushButton *enableOpenGLButton = new QPushButton(this);
- enableOpenGLButton->setText(tr("Use OpenGL"));
- enableOpenGLButton->setCheckable(true);
- enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
-#endif
-
// Layouts:
QHBoxLayout *penWidthLayout = new QHBoxLayout;
penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight);
@@ -274,9 +254,6 @@ void PathStrokeControls::layoutForSmallScreens()
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(m_capGroup);
leftLayout->addWidget(m_joinGroup);
-#if QT_CONFIG(opengl)
- leftLayout->addWidget(enableOpenGLButton);
-#endif
leftLayout->addLayout(penWidthLayout);
QVBoxLayout *rightLayout = new QVBoxLayout;
@@ -297,10 +274,6 @@ void PathStrokeControls::layoutForSmallScreens()
mainLayout->addWidget(quitBtn, 2, 1, Qt::AlignHCenter | Qt::AlignTop);
mainLayout->addWidget(okBtn, 2, 2, Qt::AlignHCenter | Qt::AlignTop);
-#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
-#endif
-
connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth);
connect(quitBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitQuitSignal);
connect(okBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitOkSignal);
diff --git a/examples/widgets/painting/shared/CMakeLists.txt b/examples/widgets/painting/shared/CMakeLists.txt
index fbd356e162..5eaa3b42e1 100644
--- a/examples/widgets/painting/shared/CMakeLists.txt
+++ b/examples/widgets/painting/shared/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
add_library(painting_shared OBJECT)
add_library(painting_shared::painting_shared ALIAS painting_shared)
@@ -15,15 +15,3 @@ set_target_properties(painting_shared PROPERTIES UNITY_BUILD OFF)
target_link_libraries(painting_shared PUBLIC Qt6::Widgets)
target_include_directories(painting_shared PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
-
-## Scopes:
-#####################################################################
-
-if (TARGET Qt6::OpenGL OR QT_FEATURE_opengles2)
- target_compile_definitions(painting_shared PRIVATE QT_OPENGL_SUPPORT)
- target_link_libraries(painting_shared PUBLIC
- Qt6::OpenGL
- )
- qt6_wrap_cpp(moc_files_gl fbopaintdevice.h) # no automoc for OBJECT libs
- target_sources(painting_shared PRIVATE fbopaintdevice.cpp fbopaintdevice.h ${moc_files_gl})
-endif()
diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp
index 7f3e50f5e6..4ff435783b 100644
--- a/examples/widgets/painting/shared/arthurwidgets.cpp
+++ b/examples/widgets/painting/shared/arthurwidgets.cpp
@@ -14,11 +14,6 @@
#include <QBoxLayout>
#include <QRegularExpression>
#include <QOffscreenSurface>
-#include <QOpenGLContext>
-#if QT_CONFIG(opengl)
-#include <QtOpenGL/QOpenGLPaintDevice>
-#include <QtOpenGL/QOpenGLWindow>
-#endif
extern QPixmap cached(const QString &img);
@@ -34,61 +29,13 @@ ArthurFrame::ArthurFrame(QWidget *parent)
pt.end();
}
-
-#if QT_CONFIG(opengl)
-void ArthurFrame::enableOpenGL(bool use_opengl)
-{
- if (m_use_opengl == use_opengl)
- return;
-
- m_use_opengl = use_opengl;
-
- if (!m_glWindow && use_opengl) {
- createGlWindow();
- QApplication::postEvent(this, new QResizeEvent(size(), size()));
- }
-
- if (use_opengl) {
- m_glWidget->show();
- } else {
- if (m_glWidget)
- m_glWidget->hide();
- }
-
- update();
-}
-
-void ArthurFrame::createGlWindow()
-{
- Q_ASSERT(m_use_opengl);
-
- m_glWindow = new QOpenGLWindow();
- QSurfaceFormat f = QSurfaceFormat::defaultFormat();
- f.setSamples(4);
- f.setAlphaBufferSize(8);
- f.setStencilBufferSize(8);
- m_glWindow->setFormat(f);
- m_glWindow->setFlags(Qt::WindowTransparentForInput);
- m_glWindow->resize(width(), height());
- m_glWidget = QWidget::createWindowContainer(m_glWindow, this);
- // create() must be called after createWindowContainer() otherwise
- // an incorrect offsetting of the position will occur.
- m_glWindow->create();
-}
-#endif
-
-
void ArthurFrame::paintEvent(QPaintEvent *e)
{
static QImage *static_image = nullptr;
QPainter painter;
- if (preferImage()
-#if QT_CONFIG(opengl)
- && !m_use_opengl
-#endif
- ) {
+ if (preferImage()) {
if (!static_image || static_image->size() != size()) {
delete static_image;
static_image = new QImage(size(), QImage::Format_RGB32);
@@ -103,18 +50,7 @@ void ArthurFrame::paintEvent(QPaintEvent *e)
painter.fillRect(0, height() - o, o, o, bg);
painter.fillRect(width() - o, height() - o, o, o, bg);
} else {
-#if QT_CONFIG(opengl)
- if (m_use_opengl && m_glWindow->isValid()) {
- m_glWindow->makeCurrent();
-
- painter.begin(m_glWindow);
- painter.fillRect(QRectF(0, 0, m_glWindow->width(), m_glWindow->height()), palette().color(backgroundRole()));
- } else {
- painter.begin(this);
- }
-#else
painter.begin(this);
-#endif
}
painter.setClipRect(e->rect());
@@ -158,27 +94,15 @@ void ArthurFrame::paintEvent(QPaintEvent *e)
painter.setBrush(Qt::NoBrush);
painter.drawPath(clipPath);
- if (preferImage()
-#if QT_CONFIG(opengl)
- && !m_use_opengl
-#endif
- ) {
+ if (preferImage()) {
painter.end();
painter.begin(this);
painter.drawImage(e->rect(), *static_image, e->rect());
}
-#if QT_CONFIG(opengl)
- if (m_use_opengl)
- m_glWindow->update();
-#endif
}
void ArthurFrame::resizeEvent(QResizeEvent *e)
{
-#if QT_CONFIG(opengl)
- if (m_glWidget)
- m_glWidget->setGeometry(0, 0, e->size().width(), e->size().height());
-#endif
QWidget::resizeEvent(e);
}
diff --git a/examples/widgets/painting/shared/arthurwidgets.h b/examples/widgets/painting/shared/arthurwidgets.h
index bf50b24346..e508e811cb 100644
--- a/examples/widgets/painting/shared/arthurwidgets.h
+++ b/examples/widgets/painting/shared/arthurwidgets.h
@@ -9,7 +9,6 @@
#include <QPushButton>
#include <QGroupBox>
-QT_FORWARD_DECLARE_CLASS(QOpenGLWindow)
QT_FORWARD_DECLARE_CLASS(QTextDocument)
QT_FORWARD_DECLARE_CLASS(QTextEdit)
QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
@@ -30,20 +29,12 @@ public:
void loadSourceFile(const QString &fileName);
bool preferImage() const { return m_preferImage; }
-#if QT_CONFIG(opengl)
- QOpenGLWindow *glWindow() const { return m_glWindow; }
-#endif
public slots:
void setPreferImage(bool pi) { m_preferImage = pi; }
void setDescriptionEnabled(bool enabled);
void showSource();
-#if QT_CONFIG(opengl)
- void enableOpenGL(bool use_opengl);
- bool usesOpenGL() { return m_use_opengl; }
-#endif
-
signals:
void descriptionEnabledChanged(bool);
@@ -51,17 +42,11 @@ protected:
void paintEvent(QPaintEvent *) override;
void resizeEvent(QResizeEvent *) override;
-#if QT_CONFIG(opengl)
- virtual void createGlWindow();
- QOpenGLWindow *m_glWindow = nullptr;
- QWidget *m_glWidget = nullptr;
- bool m_use_opengl = false;
-#endif
QPixmap m_tile;
bool m_showDoc = false;
bool m_preferImage = false;
- QTextDocument *m_document = nullptr;;
+ QTextDocument *m_document = nullptr;
QString m_sourceFileName;
};
diff --git a/examples/widgets/painting/shared/fbopaintdevice.cpp b/examples/widgets/painting/shared/fbopaintdevice.cpp
deleted file mode 100644
index 5875e6574b..0000000000
--- a/examples/widgets/painting/shared/fbopaintdevice.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "fbopaintdevice.h"
-
-#include <QOffscreenSurface>
-#include <QOpenGLFunctions>
-
-QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnInit,
- QOpenGLFramebufferObject::Attachment attachment)
- : QOpenGLPaintDevice(size)
-{
- QOpenGLFramebufferObjectFormat format;
- format.setAttachment(attachment);
- format.setSamples(4);
- m_framebufferObject = new QOpenGLFramebufferObject(size, format);
- QOffscreenSurface *surface = new QOffscreenSurface();
- surface->create();
- m_surface = surface;
- setPaintFlipped(flipped);
- if (clearOnInit) {
- m_framebufferObject->bind();
-
- context()->functions()->glClearColor(0, 0, 0, 0);
- context()->functions()->glClear(GL_COLOR_BUFFER_BIT);
- }
- m_resolvedFbo = new QOpenGLFramebufferObject(m_framebufferObject->size(), m_framebufferObject->attachment());
-}
-
-QFboPaintDevice::~QFboPaintDevice()
-{
- delete m_framebufferObject;
- delete m_resolvedFbo;
- delete m_surface;
-}
-
-void QFboPaintDevice::ensureActiveTarget()
-{
- if (QOpenGLContext::currentContext() != context())
- context()->makeCurrent(m_surface);
-
- m_framebufferObject->bind();
-}
-
-GLuint QFboPaintDevice::texture()
-{
- m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
- QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
- return m_resolvedFbo->texture();
-}
-
-GLuint QFboPaintDevice::takeTexture()
-{
- m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
- // We have multisamples so we can't just forward takeTexture(), have to resolve first.
- QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
- return m_resolvedFbo->takeTexture();
-}
-
-QImage QFboPaintDevice::toImage() const
-{
- QOpenGLContext *currentContext = QOpenGLContext::currentContext();
- QSurface *currentSurface = currentContext ? currentContext->surface() : nullptr;
-
- context()->makeCurrent(m_surface);
-
- QImage image = m_framebufferObject->toImage(!paintFlipped());
-
- if (currentContext)
- currentContext->makeCurrent(currentSurface);
- else
- context()->doneCurrent();
-
- return image;
-}
diff --git a/examples/widgets/painting/shared/fbopaintdevice.h b/examples/widgets/painting/shared/fbopaintdevice.h
deleted file mode 100644
index b2e77a228a..0000000000
--- a/examples/widgets/painting/shared/fbopaintdevice.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef QFBOPAINTDEVICE_H
-#define QFBOPAINTDEVICE_H
-
-#ifndef QT_NO_OPENGL
-
-#include <QImage>
-#include <QOpenGLFramebufferObject>
-#include <QOpenGLPaintDevice>
-#include <QSurface>
-
-class QFboPaintDevice : public QOpenGLPaintDevice {
-public:
- QFboPaintDevice(const QSize &size, bool flipped = false, bool clearOnInit = true,
- QOpenGLFramebufferObject::Attachment = QOpenGLFramebufferObject::CombinedDepthStencil);
- ~QFboPaintDevice();
-
- // QOpenGLPaintDevice:
- void ensureActiveTarget() override;
-
- bool isValid() const { return m_framebufferObject->isValid(); }
- GLuint handle() const { return m_framebufferObject->handle(); }
- GLuint texture();
- GLuint takeTexture();
- QImage toImage() const;
-
- bool bind() { return m_framebufferObject->bind(); }
- bool release() { return m_framebufferObject->release(); }
- QSize size() const { return m_framebufferObject->size(); }
-
- QOpenGLFramebufferObject* framebufferObject() { return m_framebufferObject; }
- const QOpenGLFramebufferObject* framebufferObject() const { return m_framebufferObject; }
-
- static bool isSupported() { return QOpenGLFramebufferObject::hasOpenGLFramebufferObjects(); }
-
-private:
- QOpenGLFramebufferObject *m_framebufferObject;
- QOpenGLFramebufferObject *m_resolvedFbo;
- QSurface *m_surface;
-};
-
-#endif // QT_NO_OPENGL
-
-#endif // QFBOPAINTDEVICE_H
diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp
index a9f76084e1..a917139613 100644
--- a/examples/widgets/painting/shared/hoverpoints.cpp
+++ b/examples/widgets/painting/shared/hoverpoints.cpp
@@ -6,10 +6,6 @@
#include <algorithm>
-#if QT_CONFIG(opengl)
-#include <QtOpenGL/QOpenGLWindow>
-#endif
-
HoverPoints::HoverPoints(QWidget *widget, PointShape shape)
: QObject(widget),
m_widget(widget),
@@ -131,6 +127,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
const int id = point.id();
switch (point.state()) {
case QEventPoint::Pressed:
+ case QEventPoint::Stationary:
{
// find the point, move it
const auto mappedPoints = m_fingerPointMapping.values();
@@ -155,7 +152,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
}
}
if (activePoint != -1) {
- m_fingerPointMapping.insert(point.id(), activePoint);
+ m_fingerPointMapping.insert(id, activePoint);
movePoint(activePoint, point.position());
}
}
@@ -164,8 +161,10 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
{
// move the point and release
const auto it = m_fingerPointMapping.constFind(id);
- movePoint(it.value(), point.position());
- m_fingerPointMapping.erase(it);
+ if (it != m_fingerPointMapping.constEnd()) {
+ movePoint(it.value(), point.position());
+ m_fingerPointMapping.erase(it);
+ }
}
break;
case QEventPoint::Updated:
@@ -230,17 +229,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
void HoverPoints::paintPoints()
{
QPainter p;
-#if QT_CONFIG(opengl)
- ArthurFrame *af = qobject_cast<ArthurFrame *>(m_widget);
- if (af && af->usesOpenGL() && af->glWindow()->isValid()) {
- af->glWindow()->makeCurrent();
- p.begin(af->glWindow());
- } else {
- p.begin(m_widget);
- }
-#else
p.begin(m_widget);
-#endif
p.setRenderHint(QPainter::Antialiasing);
diff --git a/examples/widgets/painting/shared/shared.pri b/examples/widgets/painting/shared/shared.pri
index 7e2b4df8cb..77881b03cc 100644
--- a/examples/widgets/painting/shared/shared.pri
+++ b/examples/widgets/painting/shared/shared.pri
@@ -1,11 +1,5 @@
INCLUDEPATH += $$PWD
-qtConfig(opengl) {
- QT += opengl
- SOURCES += $$PWD/fbopaintdevice.cpp
- HEADERS += $$PWD/fbopaintdevice.h
-}
-
SOURCES += \
$$PWD/arthurstyle.cpp\
$$PWD/arthurwidgets.cpp \
diff --git a/examples/widgets/painting/shared/use_lib.cmake b/examples/widgets/painting/shared/use_lib.cmake
index dc17fff3c0..84684a3444 100644
--- a/examples/widgets/painting/shared/use_lib.cmake
+++ b/examples/widgets/painting/shared/use_lib.cmake
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
# Include this file in your example project to use the library defined in this directory.
# This avoids find_package calls in a directory scope different from the directory scope of the
@@ -9,8 +9,4 @@ if(NOT TARGET Qt::Widgets)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
endif()
-if(NOT TARGET Qt::OpenGL)
- find_package(Qt6 OPTIONAL_COMPONENTS OpenGL)
-endif()
-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}" painting_shared)
diff --git a/examples/widgets/painting/transformations/CMakeLists.txt b/examples/widgets/painting/transformations/CMakeLists.txt
index bb522223a9..dfc35b2551 100644
--- a/examples/widgets/painting/transformations/CMakeLists.txt
+++ b/examples/widgets/painting/transformations/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(transformations LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/transformations")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(transformations PRIVATE
)
install(TARGETS transformations
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET transformations
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/qnx/foreignwindows/collector.cpp b/examples/widgets/qnx/foreignwindows/collector.cpp
index 6717488dfa..8831aab3aa 100644
--- a/examples/widgets/qnx/foreignwindows/collector.cpp
+++ b/examples/widgets/qnx/foreignwindows/collector.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 QNX Software Systems. All rights reserved.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
#include <QDebug>
diff --git a/examples/widgets/qnx/foreignwindows/collector.h b/examples/widgets/qnx/foreignwindows/collector.h
index a6cd00f9a8..4ee93cbc51 100644
--- a/examples/widgets/qnx/foreignwindows/collector.h
+++ b/examples/widgets/qnx/foreignwindows/collector.h
@@ -1,5 +1,5 @@
// Copyright (C) 2018 QNX Software Systems. All rights reserved.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef COLLECTOR_H_
#define COLLECTOR_H_
diff --git a/examples/widgets/qnx/foreignwindows/main.cpp b/examples/widgets/qnx/foreignwindows/main.cpp
index e5cc0ea362..55dfc98f01 100644
--- a/examples/widgets/qnx/foreignwindows/main.cpp
+++ b/examples/widgets/qnx/foreignwindows/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 QNX Software Systems. All rights reserved.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
diff --git a/examples/widgets/rhi/CMakeLists.txt b/examples/widgets/rhi/CMakeLists.txt
new file mode 100644
index 0000000000..6734a13c9e
--- /dev/null
+++ b/examples/widgets/rhi/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+if(NOT TARGET Qt6::Widgets)
+ return()
+endif()
+qt_internal_add_example(simplerhiwidget)
+qt_internal_add_example(cuberhiwidget)
diff --git a/examples/widgets/rhi/cuberhiwidget/CMakeLists.txt b/examples/widgets/rhi/cuberhiwidget/CMakeLists.txt
new file mode 100644
index 0000000000..effa9a5a73
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/CMakeLists.txt
@@ -0,0 +1,48 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(cuberhiwidget LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(cuberhiwidget
+ examplewidget.cpp examplewidget.h cube.h
+ main.cpp
+)
+
+set_target_properties(cuberhiwidget PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+# needs GuiPrivate to be able to include <rhi/qrhi.h>
+target_link_libraries(cuberhiwidget PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::GuiPrivate
+ Qt6::Widgets
+)
+
+qt_add_resources(cuberhiwidget "cuberhiwidget"
+ PREFIX
+ "/"
+ FILES
+ "shader_assets/texture.vert.qsb"
+ "shader_assets/texture.frag.qsb"
+)
+
+install(TARGETS cuberhiwidget
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET cuberhiwidget
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/rhi/cuberhiwidget/cube.h b/examples/widgets/rhi/cuberhiwidget/cube.h
new file mode 100644
index 0000000000..9d55eede92
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/cube.h
@@ -0,0 +1,139 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef CUBE_H
+#define CUBE_H
+
+// clang-format off
+static const float cube[] = {
+ -1.0f, -1.0f, -1.0f, // -X
+ -1.0f, -1.0f, 1.0f,
+ -1.0f, 1.0f, 1.0f,
+ -1.0f, 1.0f, 1.0f,
+ -1.0f, 1.0f, -1.0f,
+ -1.0f, -1.0f, -1.0f,
+
+ -1.0f, -1.0f, -1.0f, // -Z
+ 1.0f, 1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f,
+ -1.0f, -1.0f, -1.0f,
+ -1.0f, 1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+
+ -1.0f, -1.0f, -1.0f, // -Y
+ 1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, 1.0f,
+ -1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, 1.0f,
+ -1.0f, -1.0f, 1.0f,
+
+ -1.0f, 1.0f, -1.0f, // +Y
+ -1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f,
+ -1.0f, 1.0f, -1.0f,
+ 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, -1.0f,
+
+ 1.0f, 1.0f, -1.0f, // +X
+ 1.0f, 1.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f,
+ 1.0f, -1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+
+ -1.0f, 1.0f, 1.0f, // +Z
+ -1.0f, -1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f,
+ -1.0f, -1.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f,
+
+ // UVs
+ 0.0f, 1.0f, // -X
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 0.0f,
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+
+ 1.0f, 1.0f, // -Z
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 0.0f,
+
+ 1.0f, 0.0f, // -Y
+ 1.0f, 1.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 0.0f, 0.0f,
+
+ 1.0f, 0.0f, // +Y
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+
+ 1.0f, 0.0f, // +X
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+
+ 0.0f, 0.0f, // +Z
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+
+ // normals
+ -1.0, 0.0, 0.0, // -X
+ -1.0, 0.0, 0.0,
+ -1.0, 0.0, 0.0,
+ -1.0, 0.0, 0.0,
+ -1.0, 0.0, 0.0,
+ -1.0, 0.0, 0.0,
+
+ 0.0, 0.0, -1.0, // -Z
+ 0.0, 0.0, -1.0,
+ 0.0, 0.0, -1.0,
+ 0.0, 0.0, -1.0,
+ 0.0, 0.0, -1.0,
+ 0.0, 0.0, -1.0,
+
+ 0.0, -1.0, 0.0, // -Y
+ 0.0, -1.0, 0.0,
+ 0.0, -1.0, 0.0,
+ 0.0, -1.0, 0.0,
+ 0.0, -1.0, 0.0,
+ 0.0, -1.0, 0.0,
+
+ 0.0, 1.0, 0.0, // +Y
+ 0.0, 1.0, 0.0,
+ 0.0, 1.0, 0.0,
+ 0.0, 1.0, 0.0,
+ 0.0, 1.0, 0.0,
+ 0.0, 1.0, 0.0,
+
+ 1.0, 0.0, 0.0, // +X
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+
+ 0.0, 0.0, 1.0, // +Z
+ 0.0, 0.0, 1.0,
+ 0.0, 0.0, 1.0,
+ 0.0, 0.0, 1.0,
+ 0.0, 0.0, 1.0,
+ 0.0, 0.0, 1.0
+};
+// clang-format on
+
+#endif
diff --git a/examples/widgets/rhi/cuberhiwidget/cuberhiwidget.pro b/examples/widgets/rhi/cuberhiwidget/cuberhiwidget.pro
new file mode 100644
index 0000000000..94abd29e08
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/cuberhiwidget.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+
+# needs gui-private to be able to include <rhi/qrhi.h>
+QT += gui-private widgets
+
+HEADERS += examplewidget.h
+SOURCES += examplewidget.cpp main.cpp
+
+RESOURCES += cuberhiwidget.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/rhi/cuberhiwidget
+INSTALLS += target
diff --git a/examples/widgets/rhi/cuberhiwidget/cuberhiwidget.qrc b/examples/widgets/rhi/cuberhiwidget/cuberhiwidget.qrc
new file mode 100644
index 0000000000..33ca81dbde
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/cuberhiwidget.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>shader_assets/texture.vert.qsb</file>
+ <file>shader_assets/texture.frag.qsb</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/rhi/cuberhiwidget/examplewidget.cpp b/examples/widgets/rhi/cuberhiwidget/examplewidget.cpp
new file mode 100644
index 0000000000..fe39d904dd
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/examplewidget.cpp
@@ -0,0 +1,172 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "examplewidget.h"
+#include "cube.h"
+#include <QFile>
+#include <QPainter>
+
+static const QSize CUBE_TEX_SIZE(512, 512);
+
+ExampleRhiWidget::ExampleRhiWidget(QWidget *parent)
+ : QRhiWidget(parent)
+{
+}
+
+//![init-1]
+void ExampleRhiWidget::initialize(QRhiCommandBuffer *)
+{
+ if (m_rhi != rhi()) {
+ m_rhi = rhi();
+ scene = {};
+ emit rhiChanged(QString::fromUtf8(m_rhi->backendName()));
+ }
+ if (m_pixelSize != renderTarget()->pixelSize()) {
+ m_pixelSize = renderTarget()->pixelSize();
+ emit resized();
+ }
+ if (m_sampleCount != renderTarget()->sampleCount()) {
+ m_sampleCount = renderTarget()->sampleCount();
+ scene = {};
+ }
+//![init-1]
+
+//![init-2]
+ if (!scene.vbuf) {
+ initScene();
+ updateCubeTexture();
+ }
+
+ scene.mvp = m_rhi->clipSpaceCorrMatrix();
+ scene.mvp.perspective(45.0f, m_pixelSize.width() / (float) m_pixelSize.height(), 0.01f, 1000.0f);
+ scene.mvp.translate(0, 0, -4);
+ updateMvp();
+}
+//![init-2]
+
+//![rotation-update]
+void ExampleRhiWidget::updateMvp()
+{
+ QMatrix4x4 mvp = scene.mvp * QMatrix4x4(QQuaternion::fromEulerAngles(QVector3D(30, itemData.cubeRotation, 0)).toRotationMatrix());
+ if (!scene.resourceUpdates)
+ scene.resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ scene.resourceUpdates->updateDynamicBuffer(scene.ubuf.get(), 0, 64, mvp.constData());
+}
+//![rotation-update]
+
+//![texture-update]
+void ExampleRhiWidget::updateCubeTexture()
+{
+ QImage image(CUBE_TEX_SIZE, QImage::Format_RGBA8888);
+ const QRect r(QPoint(0, 0), CUBE_TEX_SIZE);
+ QPainter p(&image);
+ p.fillRect(r, QGradient::DeepBlue);
+ QFont font;
+ font.setPointSize(24);
+ p.setFont(font);
+ p.drawText(r, itemData.cubeText);
+ p.end();
+
+ if (!scene.resourceUpdates)
+ scene.resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ scene.resourceUpdates->uploadTexture(scene.cubeTex.get(), image);
+}
+//![texture-update]
+
+static QShader getShader(const QString &name)
+{
+ QFile f(name);
+ return f.open(QIODevice::ReadOnly) ? QShader::fromSerialized(f.readAll()) : QShader();
+}
+
+void ExampleRhiWidget::initScene()
+{
+//![setup-scene]
+ scene.vbuf.reset(m_rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(cube)));
+ scene.vbuf->create();
+
+ scene.resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ scene.resourceUpdates->uploadStaticBuffer(scene.vbuf.get(), cube);
+
+ scene.ubuf.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64));
+ scene.ubuf->create();
+
+ scene.cubeTex.reset(m_rhi->newTexture(QRhiTexture::RGBA8, CUBE_TEX_SIZE));
+ scene.cubeTex->create();
+
+ scene.sampler.reset(m_rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ scene.sampler->create();
+
+ scene.srb.reset(m_rhi->newShaderResourceBindings());
+ scene.srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, scene.ubuf.get()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, scene.cubeTex.get(), scene.sampler.get())
+ });
+ scene.srb->create();
+
+ scene.ps.reset(m_rhi->newGraphicsPipeline());
+ scene.ps->setDepthTest(true);
+ scene.ps->setDepthWrite(true);
+ scene.ps->setCullMode(QRhiGraphicsPipeline::Back);
+ scene.ps->setShaderStages({
+ { QRhiShaderStage::Vertex, getShader(QLatin1String(":/shader_assets/texture.vert.qsb")) },
+ { QRhiShaderStage::Fragment, getShader(QLatin1String(":/shader_assets/texture.frag.qsb")) }
+ });
+ QRhiVertexInputLayout inputLayout;
+ // The cube is provided as non-interleaved sets of positions, UVs, normals.
+ // Normals are not interesting here, only need the positions and UVs.
+ inputLayout.setBindings({
+ { 3 * sizeof(float) },
+ { 2 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
+ { 1, 1, QRhiVertexInputAttribute::Float2, 0 }
+ });
+ scene.ps->setSampleCount(m_sampleCount);
+ scene.ps->setVertexInputLayout(inputLayout);
+ scene.ps->setShaderResourceBindings(scene.srb.get());
+ scene.ps->setRenderPassDescriptor(renderTarget()->renderPassDescriptor());
+ scene.ps->create();
+//![setup-scene]
+}
+
+//![render]
+void ExampleRhiWidget::render(QRhiCommandBuffer *cb)
+{
+ if (itemData.cubeRotationDirty) {
+ itemData.cubeRotationDirty = false;
+ updateMvp();
+ }
+
+ if (itemData.cubeTextDirty) {
+ itemData.cubeTextDirty = false;
+ updateCubeTexture();
+ }
+
+ QRhiResourceUpdateBatch *resourceUpdates = scene.resourceUpdates;
+ if (resourceUpdates)
+ scene.resourceUpdates = nullptr;
+
+ const QColor clearColor = QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f);
+ cb->beginPass(renderTarget(), clearColor, { 1.0f, 0 }, resourceUpdates);
+
+ cb->setGraphicsPipeline(scene.ps.get());
+ cb->setViewport(QRhiViewport(0, 0, m_pixelSize.width(), m_pixelSize.height()));
+ cb->setShaderResources();
+ const QRhiCommandBuffer::VertexInput vbufBindings[] = {
+ { scene.vbuf.get(), 0 },
+ { scene.vbuf.get(), quint32(36 * 3 * sizeof(float)) }
+ };
+ cb->setVertexInput(0, 2, vbufBindings);
+ cb->draw(36);
+
+ cb->endPass();
+}
+//![render]
+
+void ExampleRhiWidget::releaseResources()
+{
+ scene = {}; // a subsequent initialize() will recreate everything
+}
diff --git a/examples/widgets/rhi/cuberhiwidget/examplewidget.h b/examples/widgets/rhi/cuberhiwidget/examplewidget.h
new file mode 100644
index 0000000000..9cc554b3fb
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/examplewidget.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef EXAMPLEWIDGET_H
+#define EXAMPLEWIDGET_H
+
+#include <QRhiWidget>
+#include <rhi/qrhi.h>
+
+class ExampleRhiWidget : public QRhiWidget
+{
+ Q_OBJECT
+
+public:
+ ExampleRhiWidget(QWidget *parent = nullptr);
+
+ void initialize(QRhiCommandBuffer *cb) override;
+ void render(QRhiCommandBuffer *cb) override;
+ void releaseResources() override;
+//![data-setters]
+ void setCubeTextureText(const QString &s)
+ {
+ if (itemData.cubeText == s)
+ return;
+ itemData.cubeText = s;
+ itemData.cubeTextDirty = true;
+ update();
+ }
+
+ void setCubeRotation(float r)
+ {
+ if (itemData.cubeRotation == r)
+ return;
+ itemData.cubeRotation = r;
+ itemData.cubeRotationDirty = true;
+ update();
+ }
+//![data-setters]
+
+signals:
+ void resized();
+ void rhiChanged(const QString &apiName);
+
+private:
+ QRhi *m_rhi = nullptr;
+ int m_sampleCount = 1;
+ QSize m_pixelSize;
+
+ struct {
+ QRhiResourceUpdateBatch *resourceUpdates = nullptr;
+ std::unique_ptr<QRhiBuffer> vbuf;
+ std::unique_ptr<QRhiBuffer> ubuf;
+ std::unique_ptr<QRhiShaderResourceBindings> srb;
+ std::unique_ptr<QRhiGraphicsPipeline> ps;
+ std::unique_ptr<QRhiSampler> sampler;
+ std::unique_ptr<QRhiTexture> cubeTex;
+ QMatrix4x4 mvp;
+ } scene;
+
+ struct {
+ QString cubeText;
+ bool cubeTextDirty = false;
+ float cubeRotation = 0.0f;
+ bool cubeRotationDirty = false;
+ } itemData;
+
+ void initScene();
+ void updateMvp();
+ void updateCubeTexture();
+};
+
+#endif
diff --git a/examples/widgets/rhi/cuberhiwidget/main.cpp b/examples/widgets/rhi/cuberhiwidget/main.cpp
new file mode 100644
index 0000000000..95a29feee5
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/main.cpp
@@ -0,0 +1,166 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QApplication>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QSlider>
+#include <QTextEdit>
+#include <QPushButton>
+#include <QLabel>
+#include <QCheckBox>
+#include <QFileDialog>
+#include <QFontInfo>
+#include <QMouseEvent>
+#include <QDrag>
+#include <QMimeData>
+#include "examplewidget.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+
+ ExampleRhiWidget *rhiWidget = new ExampleRhiWidget;
+ QLabel *overlayLabel = new QLabel(rhiWidget);
+ overlayLabel->setText(QObject::tr("This is a\nsemi-transparent\n overlay widget\n"
+ "placed on top of\nthe QRhiWidget."));
+ overlayLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
+ overlayLabel->setAutoFillBackground(true);
+ QPalette semiTransparent(QColor(255, 0, 0, 64));
+ semiTransparent.setBrush(QPalette::Text, Qt::white);
+ semiTransparent.setBrush(QPalette::WindowText, Qt::white);
+ overlayLabel->setPalette(semiTransparent);
+ QFont f = overlayLabel->font();
+ f.setPixelSize(QFontInfo(f).pixelSize() * 2);
+ f.setWeight(QFont::Bold);
+ overlayLabel->setFont(f);
+ overlayLabel->resize(320, 320);
+ overlayLabel->hide();
+ QObject::connect(rhiWidget, &ExampleRhiWidget::resized, rhiWidget, [rhiWidget, overlayLabel] {
+ const int w = overlayLabel->width();
+ const int h = overlayLabel->height();
+ overlayLabel->setGeometry(rhiWidget->width() / 2 - w / 2, rhiWidget->height() / 2 - h / 2, w, h);
+ });
+
+ QTextEdit *edit = new QTextEdit(QObject::tr("QRhiWidget!<br><br>"
+ "The cube is textured with QPainter-generated content.<br><br>"
+ "Regular, non-native widgets on top work just fine."));
+ QObject::connect(edit, &QTextEdit::textChanged, edit, [edit, rhiWidget] {
+ rhiWidget->setCubeTextureText(edit->toPlainText());
+ });
+ edit->setMaximumHeight(100);
+ layout->addWidget(edit);
+
+ QSlider *slider = new QSlider(Qt::Horizontal);
+ slider->setMinimum(0);
+ slider->setMaximum(360);
+ QObject::connect(slider, &QSlider::valueChanged, slider, [slider, rhiWidget] {
+ rhiWidget->setCubeRotation(slider->value());
+ });
+
+ QHBoxLayout *sliderLayout = new QHBoxLayout;
+ sliderLayout->addWidget(new QLabel(QObject::tr("Cube rotation")));
+ sliderLayout->addWidget(slider);
+ layout->addLayout(sliderLayout);
+
+ QHBoxLayout *btnLayout = new QHBoxLayout;
+
+ QLabel *apiLabel = new QLabel;
+ btnLayout->addWidget(apiLabel);
+ QObject::connect(rhiWidget, &ExampleRhiWidget::rhiChanged, rhiWidget, [apiLabel](const QString &apiName) {
+ apiLabel->setText(QObject::tr("Using QRhi on ") + apiName);
+ });
+
+ QPushButton *btnMakeWindow = new QPushButton(QObject::tr("Make top-level window"));
+ QObject::connect(btnMakeWindow, &QPushButton::clicked, btnMakeWindow, [rhiWidget, btnMakeWindow, layout] {
+ if (rhiWidget->parentWidget()) {
+ rhiWidget->setParent(nullptr);
+ rhiWidget->setAttribute(Qt::WA_DeleteOnClose, true);
+ rhiWidget->show();
+ btnMakeWindow->setText(QObject::tr("Make child widget"));
+ } else {
+ rhiWidget->setAttribute(Qt::WA_DeleteOnClose, false);
+ layout->addWidget(rhiWidget);
+ btnMakeWindow->setText(QObject::tr("Make top-level window"));
+ }
+ });
+ btnLayout->addWidget(btnMakeWindow);
+
+ QPushButton *btn = new QPushButton(QObject::tr("Grab to image"));
+ QObject::connect(btn, &QPushButton::clicked, btn, [rhiWidget] {
+ QImage image = rhiWidget->grabFramebuffer();
+ qDebug() << "Got image" << image;
+ if (!image.isNull()) {
+ QFileDialog fd(rhiWidget->parentWidget());
+ fd.setAcceptMode(QFileDialog::AcceptSave);
+ fd.setDefaultSuffix("png");
+ fd.selectFile("test.png");
+ if (fd.exec() == QDialog::Accepted)
+ image.save(fd.selectedFiles().first());
+ }
+ });
+ btnLayout->addWidget(btn);
+
+ QCheckBox *cbMsaa = new QCheckBox(QObject::tr("Use 4x MSAA"));
+ QObject::connect(cbMsaa, &QCheckBox::stateChanged, cbMsaa, [cbMsaa, rhiWidget] {
+ if (cbMsaa->isChecked())
+ rhiWidget->setSampleCount(4);
+ else
+ rhiWidget->setSampleCount(1);
+ });
+ btnLayout->addWidget(cbMsaa);
+
+ QCheckBox *cbOvberlay = new QCheckBox(QObject::tr("Show overlay widget"));
+ QObject::connect(cbOvberlay, &QCheckBox::stateChanged, cbOvberlay, [cbOvberlay, overlayLabel] {
+ if (cbOvberlay->isChecked())
+ overlayLabel->setVisible(true);
+ else
+ overlayLabel->setVisible(false);
+ });
+ btnLayout->addWidget(cbOvberlay);
+
+ QCheckBox *cbFlip = new QCheckBox(QObject::tr("Flip"));
+ QObject::connect(cbFlip, &QCheckBox::stateChanged, cbOvberlay, [cbFlip, rhiWidget] {
+ rhiWidget->setMirrorVertically(cbFlip->isChecked());
+ });
+ btnLayout->addWidget(cbFlip);
+
+ QCheckBox *cbFixedSize = new QCheckBox(QObject::tr("Use fixed color buffer size"));
+ btnLayout->addWidget(cbFixedSize);
+ QSlider *fixedSizeSlider = new QSlider(Qt::Horizontal);
+ fixedSizeSlider->setMinimum(16);
+ fixedSizeSlider->setMaximum(512);
+ btnLayout->addWidget(fixedSizeSlider);
+
+ QObject::connect(cbFixedSize, &QCheckBox::stateChanged, cbFixedSize, [cbFixedSize, fixedSizeSlider, rhiWidget] {
+ if (cbFixedSize->isChecked())
+ rhiWidget->setFixedColorBufferSize(QSize(fixedSizeSlider->value(), fixedSizeSlider->value()));
+ else
+ rhiWidget->setFixedColorBufferSize(QSize());
+ });
+ QObject::connect(fixedSizeSlider, &QSlider::valueChanged, fixedSizeSlider, [fixedSizeSlider, cbFixedSize, rhiWidget] {
+ if (cbFixedSize->isChecked())
+ rhiWidget->setFixedColorBufferSize(QSize(fixedSizeSlider->value(), fixedSizeSlider->value()));
+ });
+
+ // Exit when the detached window is closed; there is not much we can do
+ // with the controls in the main window then.
+ QObject::connect(rhiWidget, &QObject::destroyed, rhiWidget, [rhiWidget] {
+ if (!rhiWidget->parentWidget())
+ qGuiApp->quit();
+ });
+
+ layout->addLayout(btnLayout);
+ layout->addWidget(rhiWidget);
+
+ rhiWidget->setCubeTextureText(edit->toPlainText());
+
+ QWidget w;
+ w.setLayout(layout);
+ w.resize(1280, 720);
+ w.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/rhi/cuberhiwidget/shader_assets/texture.frag.qsb b/examples/widgets/rhi/cuberhiwidget/shader_assets/texture.frag.qsb
new file mode 100644
index 0000000000..dc440d8067
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/shader_assets/texture.frag.qsb
Binary files differ
diff --git a/examples/widgets/rhi/cuberhiwidget/shader_assets/texture.vert.qsb b/examples/widgets/rhi/cuberhiwidget/shader_assets/texture.vert.qsb
new file mode 100644
index 0000000000..84aed7fee2
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/shader_assets/texture.vert.qsb
Binary files differ
diff --git a/examples/widgets/rhi/cuberhiwidget/shaders/texture.frag b/examples/widgets/rhi/cuberhiwidget/shaders/texture.frag
new file mode 100644
index 0000000000..9a14dc6eeb
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/shaders/texture.frag
@@ -0,0 +1,12 @@
+#version 440
+
+layout(location = 0) in vec2 v_texcoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D tex;
+
+void main()
+{
+ vec4 c = texture(tex, v_texcoord);
+ fragColor = vec4(c.rgb * c.a, c.a);
+}
diff --git a/examples/widgets/rhi/cuberhiwidget/shaders/texture.vert b/examples/widgets/rhi/cuberhiwidget/shaders/texture.vert
new file mode 100644
index 0000000000..a58a932abc
--- /dev/null
+++ b/examples/widgets/rhi/cuberhiwidget/shaders/texture.vert
@@ -0,0 +1,15 @@
+#version 440
+
+layout(location = 0) in vec4 position;
+layout(location = 1) in vec2 texcoord;
+layout(location = 0) out vec2 v_texcoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 mvp;
+};
+
+void main()
+{
+ v_texcoord = vec2(texcoord.x, texcoord.y);
+ gl_Position = mvp * position;
+}
diff --git a/examples/widgets/rhi/rhi.pro b/examples/widgets/rhi/rhi.pro
new file mode 100644
index 0000000000..9248e5e0e3
--- /dev/null
+++ b/examples/widgets/rhi/rhi.pro
@@ -0,0 +1,4 @@
+requires(qtHaveModule(widgets))
+TEMPLATE = subdirs
+SUBDIRS = simplerhiwidget \
+ cuberhiwidget
diff --git a/examples/widgets/rhi/simplerhiwidget/CMakeLists.txt b/examples/widgets/rhi/simplerhiwidget/CMakeLists.txt
new file mode 100644
index 0000000000..cf471f1f8a
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/CMakeLists.txt
@@ -0,0 +1,48 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(simplerhiwidget LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(simplerhiwidget
+ examplewidget.cpp examplewidget.h
+ main.cpp
+)
+
+set_target_properties(simplerhiwidget PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+# needs GuiPrivate to be able to include <rhi/qrhi.h>
+target_link_libraries(simplerhiwidget PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::GuiPrivate
+ Qt6::Widgets
+)
+
+qt_add_resources(simplerhiwidget "simplerhiwidget"
+ PREFIX
+ "/"
+ FILES
+ "shader_assets/color.vert.qsb"
+ "shader_assets/color.frag.qsb"
+)
+
+install(TARGETS simplerhiwidget
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET simplerhiwidget
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/rhi/simplerhiwidget/examplewidget.cpp b/examples/widgets/rhi/simplerhiwidget/examplewidget.cpp
new file mode 100644
index 0000000000..7de33059a3
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/examplewidget.cpp
@@ -0,0 +1,102 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "examplewidget.h"
+#include <QFile>
+
+static float vertexData[] = {
+ 0.0f, 0.5f, 1.0f, 0.0f, 0.0f,
+ -0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
+ 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
+};
+
+//![get-shader]
+static QShader getShader(const QString &name)
+{
+ QFile f(name);
+ return f.open(QIODevice::ReadOnly) ? QShader::fromSerialized(f.readAll()) : QShader();
+}
+//![get-shader]
+
+//![init-1]
+void ExampleRhiWidget::initialize(QRhiCommandBuffer *cb)
+{
+ if (m_rhi != rhi()) {
+ m_pipeline.reset();
+ m_rhi = rhi();
+ }
+//![init-1]
+//![init-pipeline]
+ if (!m_pipeline) {
+ m_vbuf.reset(m_rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData)));
+ m_vbuf->create();
+
+ m_ubuf.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64));
+ m_ubuf->create();
+
+ m_srb.reset(m_rhi->newShaderResourceBindings());
+ m_srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, m_ubuf.get()),
+ });
+ m_srb->create();
+
+ m_pipeline.reset(m_rhi->newGraphicsPipeline());
+ m_pipeline->setShaderStages({
+ { QRhiShaderStage::Vertex, getShader(QLatin1String(":/shader_assets/color.vert.qsb")) },
+ { QRhiShaderStage::Fragment, getShader(QLatin1String(":/shader_assets/color.frag.qsb")) }
+ });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 5 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float3, 2 * sizeof(float) }
+ });
+ m_pipeline->setVertexInputLayout(inputLayout);
+ m_pipeline->setShaderResourceBindings(m_srb.get());
+ m_pipeline->setRenderPassDescriptor(renderTarget()->renderPassDescriptor());
+ m_pipeline->create();
+
+ QRhiResourceUpdateBatch *resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ resourceUpdates->uploadStaticBuffer(m_vbuf.get(), vertexData);
+ cb->resourceUpdate(resourceUpdates);
+ }
+//![init-pipeline]
+
+//![init-matrix]
+ const QSize outputSize = renderTarget()->pixelSize();
+ m_viewProjection = m_rhi->clipSpaceCorrMatrix();
+ m_viewProjection.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
+ m_viewProjection.translate(0, 0, -4);
+}
+//![init-matrix]
+
+//![render-1]
+void ExampleRhiWidget::render(QRhiCommandBuffer *cb)
+{
+ QRhiResourceUpdateBatch *resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ m_rotation += 1.0f;
+ QMatrix4x4 modelViewProjection = m_viewProjection;
+ modelViewProjection.rotate(m_rotation, 0, 1, 0);
+ resourceUpdates->updateDynamicBuffer(m_ubuf.get(), 0, 64, modelViewProjection.constData());
+//![render-1]
+//![render-pass]
+ const QColor clearColor = QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f);
+ cb->beginPass(renderTarget(), clearColor, { 1.0f, 0 }, resourceUpdates);
+
+ cb->setGraphicsPipeline(m_pipeline.get());
+ const QSize outputSize = renderTarget()->pixelSize();
+ cb->setViewport(QRhiViewport(0, 0, outputSize.width(), outputSize.height()));
+ cb->setShaderResources();
+ const QRhiCommandBuffer::VertexInput vbufBinding(m_vbuf.get(), 0);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(3);
+
+ cb->endPass();
+//![render-pass]
+
+//![render-2]
+ update();
+}
+//![render-2]
diff --git a/examples/widgets/rhi/simplerhiwidget/examplewidget.h b/examples/widgets/rhi/simplerhiwidget/examplewidget.h
new file mode 100644
index 0000000000..efd3b90d91
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/examplewidget.h
@@ -0,0 +1,30 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef EXAMPLEWIDGET_H
+#define EXAMPLEWIDGET_H
+
+//![0]
+#include <QRhiWidget>
+#include <rhi/qrhi.h>
+
+class ExampleRhiWidget : public QRhiWidget
+{
+public:
+ ExampleRhiWidget(QWidget *parent = nullptr) : QRhiWidget(parent) { }
+
+ void initialize(QRhiCommandBuffer *cb) override;
+ void render(QRhiCommandBuffer *cb) override;
+
+private:
+ QRhi *m_rhi = nullptr;
+ std::unique_ptr<QRhiBuffer> m_vbuf;
+ std::unique_ptr<QRhiBuffer> m_ubuf;
+ std::unique_ptr<QRhiShaderResourceBindings> m_srb;
+ std::unique_ptr<QRhiGraphicsPipeline> m_pipeline;
+ QMatrix4x4 m_viewProjection;
+ float m_rotation = 0.0f;
+};
+//![0]
+
+#endif
diff --git a/examples/widgets/rhi/simplerhiwidget/main.cpp b/examples/widgets/rhi/simplerhiwidget/main.cpp
new file mode 100644
index 0000000000..b9cf848125
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/main.cpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QApplication>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include "examplewidget.h"
+
+//![0]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ ExampleRhiWidget *rhiWidget = new ExampleRhiWidget;
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(rhiWidget);
+
+ QWidget w;
+ w.setLayout(layout);
+ w.resize(1280, 720);
+ w.show();
+
+ return app.exec();
+}
+//![0]
diff --git a/examples/widgets/rhi/simplerhiwidget/shader_assets/color.frag.qsb b/examples/widgets/rhi/simplerhiwidget/shader_assets/color.frag.qsb
new file mode 100644
index 0000000000..32bd2d5953
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/shader_assets/color.frag.qsb
Binary files differ
diff --git a/examples/widgets/rhi/simplerhiwidget/shader_assets/color.vert.qsb b/examples/widgets/rhi/simplerhiwidget/shader_assets/color.vert.qsb
new file mode 100644
index 0000000000..bf97035d7e
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/shader_assets/color.vert.qsb
Binary files differ
diff --git a/examples/widgets/rhi/simplerhiwidget/shaders/color.frag b/examples/widgets/rhi/simplerhiwidget/shaders/color.frag
new file mode 100644
index 0000000000..375587662f
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/shaders/color.frag
@@ -0,0 +1,10 @@
+#version 440
+
+layout(location = 0) in vec3 v_color;
+
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ fragColor = vec4(v_color, 1.0);
+}
diff --git a/examples/widgets/rhi/simplerhiwidget/shaders/color.vert b/examples/widgets/rhi/simplerhiwidget/shaders/color.vert
new file mode 100644
index 0000000000..e876f290e7
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/shaders/color.vert
@@ -0,0 +1,16 @@
+#version 440
+
+layout(location = 0) in vec4 position;
+layout(location = 1) in vec3 color;
+
+layout(location = 0) out vec3 v_color;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 mvp;
+};
+
+void main()
+{
+ v_color = color;
+ gl_Position = mvp * position;
+}
diff --git a/examples/widgets/rhi/simplerhiwidget/simplerhiwidget.pro b/examples/widgets/rhi/simplerhiwidget/simplerhiwidget.pro
new file mode 100644
index 0000000000..2477d7f368
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/simplerhiwidget.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+
+# needs gui-private to be able to include <rhi/qrhi.h>
+QT += gui-private widgets
+
+HEADERS += examplewidget.h
+SOURCES += examplewidget.cpp main.cpp
+
+RESOURCES += simplerhiwidget.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/rhi/simplerhiwidget
+INSTALLS += target
diff --git a/examples/widgets/rhi/simplerhiwidget/simplerhiwidget.qrc b/examples/widgets/rhi/simplerhiwidget/simplerhiwidget.qrc
new file mode 100644
index 0000000000..ddc6dfbe5a
--- /dev/null
+++ b/examples/widgets/rhi/simplerhiwidget/simplerhiwidget.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>shader_assets/color.vert.qsb</file>
+ <file>shader_assets/color.frag.qsb</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/richtext/CMakeLists.txt b/examples/widgets/richtext/CMakeLists.txt
index ea4165b764..d62e88b3e8 100644
--- a/examples/widgets/richtext/CMakeLists.txt
+++ b/examples/widgets/richtext/CMakeLists.txt
@@ -1,7 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-qt_internal_add_example(calendar)
qt_internal_add_example(orderform)
qt_internal_add_example(syntaxhighlighter)
-qt_internal_add_example(textedit)
diff --git a/examples/widgets/richtext/calendar/CMakeLists.txt b/examples/widgets/richtext/calendar/CMakeLists.txt
deleted file mode 100644
index 569e508af4..0000000000
--- a/examples/widgets/richtext/calendar/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(calendar LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/richtext/calendar")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(calendar
- main.cpp
- mainwindow.cpp mainwindow.h
-)
-
-set_target_properties(calendar PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(calendar PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS calendar
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/richtext/calendar/calendar.pro b/examples/widgets/richtext/calendar/calendar.pro
deleted file mode 100644
index 199c1dbb8d..0000000000
--- a/examples/widgets/richtext/calendar/calendar.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = mainwindow.h
-SOURCES = main.cpp \
- mainwindow.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/richtext/calendar
-INSTALLS += target
diff --git a/examples/widgets/richtext/calendar/main.cpp b/examples/widgets/richtext/calendar/main.cpp
deleted file mode 100644
index 5641ae527a..0000000000
--- a/examples/widgets/richtext/calendar/main.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.resize(640, 256);
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/richtext/calendar/mainwindow.cpp b/examples/widgets/richtext/calendar/mainwindow.cpp
deleted file mode 100644
index 0b44c96d46..0000000000
--- a/examples/widgets/richtext/calendar/mainwindow.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-
-#include <QtWidgets>
-
-//! [0]
-MainWindow::MainWindow()
-{
- selectedDate = QDate::currentDate();
- fontSize = 10;
-
- QWidget *centralWidget = new QWidget;
-//! [0]
-
-//! [1]
- QLabel *dateLabel = new QLabel(tr("Date:"));
- QComboBox *monthCombo = new QComboBox;
-
- for (int month = 1; month <= 12; ++month)
- monthCombo->addItem(QLocale::system().monthName(month));
-
- QDateTimeEdit *yearEdit = new QDateTimeEdit;
- yearEdit->setDisplayFormat("yyyy");
- yearEdit->setDateRange(QDate(1753, 1, 1), QDate(8000, 1, 1));
-//! [1]
-
- monthCombo->setCurrentIndex(selectedDate.month() - 1);
- yearEdit->setDate(selectedDate);
-
-//! [2]
- QLabel *fontSizeLabel = new QLabel(tr("Font size:"));
- QSpinBox *fontSizeSpinBox = new QSpinBox;
- fontSizeSpinBox->setRange(1, 64);
-
- editor = new QTextBrowser;
- insertCalendar();
-//! [2]
-
-//! [3]
- connect(monthCombo, &QComboBox::activated,
- this, &MainWindow::setMonth);
- connect(yearEdit, &QDateTimeEdit::dateChanged,
- this, &MainWindow::setYear);
- connect(fontSizeSpinBox, &QSpinBox::valueChanged,
- this, &MainWindow::setFontSize);
-//! [3]
-
- fontSizeSpinBox->setValue(10);
-
-//! [4]
- QHBoxLayout *controlsLayout = new QHBoxLayout;
- controlsLayout->addWidget(dateLabel);
- controlsLayout->addWidget(monthCombo);
- controlsLayout->addWidget(yearEdit);
- controlsLayout->addSpacing(24);
- controlsLayout->addWidget(fontSizeLabel);
- controlsLayout->addWidget(fontSizeSpinBox);
- controlsLayout->addStretch(1);
-
- QVBoxLayout *centralLayout = new QVBoxLayout;
- centralLayout->addLayout(controlsLayout);
- centralLayout->addWidget(editor, 1);
- centralWidget->setLayout(centralLayout);
-
- setCentralWidget(centralWidget);
-//! [4]
-}
-
-//! [5]
-void MainWindow::insertCalendar()
-{
- editor->clear();
- QTextCursor cursor = editor->textCursor();
- cursor.beginEditBlock();
-
- QDate date(selectedDate.year(), selectedDate.month(), 1);
-//! [5]
-
-//! [6]
- QTextTableFormat tableFormat;
- tableFormat.setAlignment(Qt::AlignHCenter);
- tableFormat.setBackground(QColor("#e0e0e0"));
- tableFormat.setCellPadding(2);
- tableFormat.setCellSpacing(4);
-//! [6] //! [7]
- QList<QTextLength> constraints;
- constraints << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14)
- << QTextLength(QTextLength::PercentageLength, 14);
- tableFormat.setColumnWidthConstraints(constraints);
-//! [7]
-
-//! [8]
- QTextTable *table = cursor.insertTable(1, 7, tableFormat);
-//! [8]
-
-//! [9]
- QTextFrame *frame = cursor.currentFrame();
- QTextFrameFormat frameFormat = frame->frameFormat();
- frameFormat.setBorder(1);
- frame->setFrameFormat(frameFormat);
-//! [9]
-
-//! [10]
- QTextCharFormat format = cursor.charFormat();
- format.setFontPointSize(fontSize);
-
- QTextCharFormat boldFormat = format;
- boldFormat.setFontWeight(QFont::Bold);
-
- QTextCharFormat highlightedFormat = boldFormat;
- highlightedFormat.setBackground(Qt::yellow);
-//! [10]
-
-//! [11]
- for (int weekDay = 1; weekDay <= 7; ++weekDay) {
- QTextTableCell cell = table->cellAt(0, weekDay-1);
-//! [11] //! [12]
- QTextCursor cellCursor = cell.firstCursorPosition();
- cellCursor.insertText(QLocale::system().dayName(weekDay), boldFormat);
- }
-//! [12]
-
-//! [13]
- table->insertRows(table->rows(), 1);
-//! [13]
-
- while (date.month() == selectedDate.month()) {
- int weekDay = date.dayOfWeek();
- QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
- QTextCursor cellCursor = cell.firstCursorPosition();
-
- if (date == QDate::currentDate())
- cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat);
- else
- cellCursor.insertText(QString("%1").arg(date.day()), format);
-
- date = date.addDays(1);
- if (weekDay == 7 && date.month() == selectedDate.month())
- table->insertRows(table->rows(), 1);
- }
-
- cursor.endEditBlock();
-//! [14]
- setWindowTitle(tr("Calendar for %1 %2"
- ).arg(QLocale::system().monthName(selectedDate.month())
- ).arg(selectedDate.year()));
-}
-//! [14]
-
-//! [15]
-void MainWindow::setFontSize(int size)
-{
- fontSize = size;
- insertCalendar();
-}
-//! [15]
-
-//! [16]
-void MainWindow::setMonth(int month)
-{
- selectedDate = QDate(selectedDate.year(), month + 1, selectedDate.day());
- insertCalendar();
-}
-//! [16]
-
-//! [17]
-void MainWindow::setYear(QDate date)
-{
- selectedDate = QDate(date.year(), selectedDate.month(), selectedDate.day());
- insertCalendar();
-}
-//! [17]
diff --git a/examples/widgets/richtext/calendar/mainwindow.h b/examples/widgets/richtext/calendar/mainwindow.h
deleted file mode 100644
index 76632820d6..0000000000
--- a/examples/widgets/richtext/calendar/mainwindow.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QDate>
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QTextBrowser;
-QT_END_NAMESPACE
-
-//! [0]
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
-public slots:
- void setFontSize(int size);
- void setMonth(int month);
- void setYear(QDate date);
-
-private:
- void insertCalendar();
-
- int fontSize;
- QDate selectedDate;
- QTextBrowser *editor;
-};
-//! [0]
-
-#endif // MAINWINDOW_H
diff --git a/examples/widgets/richtext/orderform/CMakeLists.txt b/examples/widgets/richtext/orderform/CMakeLists.txt
index 75d6931954..eacf41fd1f 100644
--- a/examples/widgets/richtext/orderform/CMakeLists.txt
+++ b/examples/widgets/richtext/orderform/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(orderform LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/richtext/orderform")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -36,7 +30,14 @@ if(TARGET Qt6::PrintSupport)
endif()
install(TARGETS orderform
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET orderform
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/richtext/richtext.pro b/examples/widgets/richtext/richtext.pro
index 499733ecec..0d7f6c942a 100644
--- a/examples/widgets/richtext/richtext.pro
+++ b/examples/widgets/richtext/richtext.pro
@@ -1,5 +1,3 @@
TEMPLATE = subdirs
-SUBDIRS = calendar \
- orderform \
- syntaxhighlighter \
- textedit
+SUBDIRS = orderform \
+ syntaxhighlighter
diff --git a/examples/widgets/richtext/syntaxhighlighter/CMakeLists.txt b/examples/widgets/richtext/syntaxhighlighter/CMakeLists.txt
index 8298582d37..13fd37ba1b 100644
--- a/examples/widgets/richtext/syntaxhighlighter/CMakeLists.txt
+++ b/examples/widgets/richtext/syntaxhighlighter/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(syntaxhighlighter LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/richtext/syntaxhighlighter")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(syntaxhighlighter PRIVATE
)
install(TARGETS syntaxhighlighter
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET syntaxhighlighter
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/richtext/textedit/CMakeLists.txt b/examples/widgets/richtext/textedit/CMakeLists.txt
deleted file mode 100644
index e648ee2597..0000000000
--- a/examples/widgets/richtext/textedit/CMakeLists.txt
+++ /dev/null
@@ -1,105 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(textedit LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/richtext/textedit")
-
-find_package(Qt6
- REQUIRED COMPONENTS Core Gui Widgets
- OPTIONAL_COMPONENTS PrintSupport
-)
-
-qt_standard_project_setup()
-
-qt_add_executable(textedit
- main.cpp
- textedit.cpp textedit.h
-)
-
-set_target_properties(textedit PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(textedit PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if (TARGET Qt6::PrintSupport)
- target_link_libraries(textedit PRIVATE Qt6::PrintSupport)
-endif()
-
-# Resources:
-set(textedit_resource_files
- "example.html"
- "images/logo32.png"
- "images/mac/checkbox-checked.png"
- "images/mac/checkbox.png"
- "images/mac/editcopy.png"
- "images/mac/editcut.png"
- "images/mac/editpaste.png"
- "images/mac/editredo.png"
- "images/mac/editundo.png"
- "images/mac/exportpdf.png"
- "images/mac/filenew.png"
- "images/mac/fileopen.png"
- "images/mac/fileprint.png"
- "images/mac/filesave.png"
- "images/mac/format-indent-less.png"
- "images/mac/format-indent-more.png"
- "images/mac/textbold.png"
- "images/mac/textcenter.png"
- "images/mac/textitalic.png"
- "images/mac/textjustify.png"
- "images/mac/textleft.png"
- "images/mac/textright.png"
- "images/mac/textunder.png"
- "images/mac/textundercolor.png"
- "images/mac/zoomin.png"
- "images/mac/zoomout.png"
- "images/win/checkbox-checked.png"
- "images/win/checkbox.png"
- "images/win/editcopy.png"
- "images/win/editcut.png"
- "images/win/editpaste.png"
- "images/win/editredo.png"
- "images/win/editundo.png"
- "images/win/exportpdf.png"
- "images/win/filenew.png"
- "images/win/fileopen.png"
- "images/win/fileprint.png"
- "images/win/filesave.png"
- "images/win/format-indent-less.png"
- "images/win/format-indent-more.png"
- "images/win/textbold.png"
- "images/win/textcenter.png"
- "images/win/textitalic.png"
- "images/win/textjustify.png"
- "images/win/textleft.png"
- "images/win/textright.png"
- "images/win/textunder.png"
- "images/win/textundercolor.png"
- "images/win/zoomin.png"
- "images/win/zoomout.png"
-)
-
-qt_add_resources(textedit "textedit"
- PREFIX
- "/"
- FILES
- ${textedit_resource_files}
-)
-
-install(TARGETS textedit
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/richtext/textedit/example.html b/examples/widgets/richtext/textedit/example.html
deleted file mode 100644
index ebae3362e9..0000000000
--- a/examples/widgets/richtext/textedit/example.html
+++ /dev/null
@@ -1,84 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
-<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><title>QTextEdit Example</title><style type="text/css">
-p, li { white-space: pre-wrap; }
-hr { height: 1px; border-width: 0; }
-</style></head><body style=" font-family:'Helvetica'; font-size:9pt; font-weight:400; font-style:normal;">
-<h1 align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">QTextEdit</span></h1>
-<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>
-<h2 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></h2>
-<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>
-<h2 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></h2>
-<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Different kinds of lists can be included in rich text documents. Standard bullet lists can be nested, using different symbols for each level of the list: </span></p>
-<ul style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Disc symbols are typically used for top-level list items. </li></ul>
-<ul type=circle style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Circle symbols can be used to distinguish between items in lower-level lists.</li></ul>
-<ul type=square style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Square symbols provide a reasonable alternative to discs and circles. </li></ul>
-<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Ordered lists can be created that can be used for tables of contents. Different characters can be used to enumerate items, and we can use both Roman and Arabic numerals in the same list structure: </p>
-<ol style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction</li>
-<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Tools </li></ol>
-<ol type=a style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Assistant</li>
-<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Designer</li>
-<ol type=A style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Form Editor</li>
-<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Component Architecture</li></ol>
-<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Linguist</li></ol>
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">The list will automatically be renumbered if you add or remove items. <span style=" font-style:italic;">Try adding new sections to the above list or removing existing item to see the numbers change.</span> </p>
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
-<h2 style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Images</span></h2>
-<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Inline images are treated like ordinary ranges of characters in the text editor, so they flow with the surrounding text. Images can also be selected in the same way as text, making it easy to cut, copy, and paste them. </span></p>
-<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><img src=":/images/logo32.png" /><span style=" font-style:italic;"> Try to select this image by clicking and dragging over it with the mouse, or use the text cursor to select it by holding down Shift and using the arrow keys. You can then cut or copy it, and paste it into different parts of this document.</span></p>
-<h2 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;">Horizontal Rule</span></h2>
-<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Here is an example:</p>
-<hr width="50%" style=" background-color:green;"/>
-<h2 align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Tables</span></h2>
-<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns. </span></p>
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
-<table border="1" align="center" width="90%" cellspacing="0" cellpadding="4">
-<tr>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Development Tools </span></p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Programming Techniques </span></p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Graphical User Interfaces </span></p></td></tr>
-<tr>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">9:00 - 11:00 </span></p></td>
-<td colspan="3">
-<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction to <span style=" font-style:italic;">Qt </span></p></td></tr>
-<tr>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">11:00 - 13:00 </span></p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Using <span style=" font-style:italic;">qmake</span> </p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Object-oriented Programming </p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Layouts in <span style=" font-style:italic;">Qt</span> </p></td></tr>
-<tr>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">13:00 - 15:00 </span></p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Designer</span> Tutorial </p></td>
-<td rowspan="2">
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Extreme Programming </p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Writing Custom Styles </p></td></tr>
-<tr>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">15:00 - 17:00 </span></p></td>
-<td>
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Linguist</span> and Internationalization </p></td>
-<td></td></tr></table>
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
-<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; font-style:italic;">Try adding text to the cells in the table and experiment with the alignment of the paragraphs.</p>
-<h2 style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Hyperlinks</span></h2>
-<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in </span><span style=" font-size:11pt; font-style:italic;">Qt Assistant</span><span style=" font-size:11pt;">. Hyperlinks are automatically created when an HTML file is imported into an editor. Since the rich text framework supports hyperlinks natively, they can also be created programmatically.</span></p>
-<h2 style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Undo and Redo</span></h2>
-<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Full support for undo and redo operations is built into QTextEdit and the underlying rich text framework. Operations on a document can be packaged together to make editing a more comfortable experience for the user.</p>
-<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.</span> </p></body></html>
diff --git a/examples/widgets/richtext/textedit/example.md b/examples/widgets/richtext/textedit/example.md
deleted file mode 100644
index 15f3c3cacf..0000000000
--- a/examples/widgets/richtext/textedit/example.md
+++ /dev/null
@@ -1,104 +0,0 @@
-# QTextEdit
-
-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.
-
-If you are viewing this document in the textedit 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.
-
-## Font and Paragraph Styles
-
-QTextEdit supports **bold**, *italic*, _underline_ &amp; ~~strikethrough~~ font
-styles, and can display
-<span style="font-size:10pt; font-weight:600; color:#00007f;"> multicolored</span>
-text. Font families such as
-<span style="font-family:Times New Roman">Times New Roman</span> and
-<span style="font-family:Courier">Courier</span>
-can also be used directly. *If you place the cursor in a region of styled text,
-the controls in the tool bars will change to reflect the current style.*
-
-Paragraphs can be formatted so that the text is left-aligned, right-aligned,
-centered, or fully justified.
-
-*Try changing the alignment of some text and resize the editor to see how the
-text layout changes.*
-
-## Lists
-
-Different kinds of lists can be included in rich text documents. Standard
-bullet lists can be nested, using different symbols for each level of the list:
-
-- Disc symbols are typically used for top-level list items.
- * Circle symbols can be used to distinguish between items in lower-level
- lists.
- + Square symbols provide a reasonable alternative to discs and circles.
-
-Ordered lists can be created that can be used for tables of contents. Different
-characters can be used to enumerate items, and we can use both Roman and Arabic
-numerals in the same list structure:
-
-1. Introduction
-2. Qt Tools
- 1) Qt Assistant
- 2) Qt Designer
- 1. Form Editor
- 2. Component Architecture
- 3) Qt Linguist
-
-The list will automatically be renumbered if you add or remove items. *Try
-adding new sections to the above list or removing existing item to see the
-numbers change.*
-
-Task lists can be used to track progress on projects:
-
-- [ ] This is not yet done
-- This is just a bullet point
-- [x] This is done
-
-## Images
-
-Inline images are treated like ordinary ranges of characters in the text
-editor, so they flow with the surrounding text. Images can also be selected in
-the same way as text, making it easy to cut, copy, and paste them.
-
-![logo](images/logo32.png "logo") *Try to select this image by clicking and
-dragging over it with the mouse, or use the text cursor to select it by holding
-down Shift and using the arrow keys. You can then cut or copy it, and paste it
-into different parts of this document.*
-
-## Tables
-
-QTextEdit can arrange and format tables, supporting features such as row and
-column spans, text formatting within cells, and size constraints for columns.
-
-| | Development Tools | Programming Techniques | Graphical User Interfaces |
-| ------------: | ----------------- | ---------------------- | ------------------------- |
-| 9:00 - 11:00 | Introduction to Qt |||
-| 11:00 - 13:00 | Using qmake | Object-oriented Programming | Layouts in Qt |
-| 13:00 - 15:00 | Qt Designer Tutorial | Extreme Programming | Writing Custom Styles |
-| 15:00 - 17:00 | Qt Linguist and Internationalization | &nbsp; | &nbsp; |
-
-*Try adding text to the cells in the table and experiment with the alignment of
-the paragraphs.*
-
-## Hyperlinks
-
-QTextEdit is designed to support hyperlinks between documents, and this feature
-is used extensively in
-[Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html). Hyperlinks are
-automatically created when an HTML file is imported into an editor. Since the
-rich text framework supports hyperlinks natively, they can also be created
-programmatically.
-
-## Undo and Redo
-
-Full support for undo and redo operations is built into QTextEdit and the
-underlying rich text framework. Operations on a document can be packaged
-together to make editing a more comfortable experience for the user.
-
-*Try making changes to this document and press `Ctrl+Z` to undo them. You can
-always recover the original contents of the document.*
-
diff --git a/examples/widgets/richtext/textedit/images/logo32.png b/examples/widgets/richtext/textedit/images/logo32.png
deleted file mode 100644
index 5f91e9873b..0000000000
--- a/examples/widgets/richtext/textedit/images/logo32.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png
deleted file mode 100644
index a072d7fb5c..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox.png b/examples/widgets/richtext/textedit/images/mac/checkbox.png
deleted file mode 100644
index 4064909712..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/checkbox.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editcopy.png b/examples/widgets/richtext/textedit/images/mac/editcopy.png
deleted file mode 100644
index f551364464..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/editcopy.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editcut.png b/examples/widgets/richtext/textedit/images/mac/editcut.png
deleted file mode 100644
index a784fd5709..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/editcut.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editpaste.png b/examples/widgets/richtext/textedit/images/mac/editpaste.png
deleted file mode 100644
index 64c0b2d6ab..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/editpaste.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editredo.png b/examples/widgets/richtext/textedit/images/mac/editredo.png
deleted file mode 100644
index 8875bf246c..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/editredo.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editundo.png b/examples/widgets/richtext/textedit/images/mac/editundo.png
deleted file mode 100644
index a3bd5e0bf2..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/editundo.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/exportpdf.png b/examples/widgets/richtext/textedit/images/mac/exportpdf.png
deleted file mode 100644
index 9e199407af..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/exportpdf.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/filenew.png b/examples/widgets/richtext/textedit/images/mac/filenew.png
deleted file mode 100644
index d3882c7b3f..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/filenew.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/fileopen.png b/examples/widgets/richtext/textedit/images/mac/fileopen.png
deleted file mode 100644
index fc06c5ec63..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/fileopen.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/fileprint.png b/examples/widgets/richtext/textedit/images/mac/fileprint.png
deleted file mode 100644
index 10ca56c82a..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/fileprint.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/filesave.png b/examples/widgets/richtext/textedit/images/mac/filesave.png
deleted file mode 100644
index e65a29d5f1..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/filesave.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-less.png b/examples/widgets/richtext/textedit/images/mac/format-indent-less.png
deleted file mode 100644
index e38074e78b..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/format-indent-less.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-more.png b/examples/widgets/richtext/textedit/images/mac/format-indent-more.png
deleted file mode 100644
index 1bdeabd354..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/format-indent-more.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textbold.png b/examples/widgets/richtext/textedit/images/mac/textbold.png
deleted file mode 100644
index 38400bd1f6..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textbold.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textcenter.png b/examples/widgets/richtext/textedit/images/mac/textcenter.png
deleted file mode 100644
index 2ef5b2ee6f..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textcenter.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textitalic.png b/examples/widgets/richtext/textedit/images/mac/textitalic.png
deleted file mode 100644
index 0170ee26a6..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textitalic.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textjustify.png b/examples/widgets/richtext/textedit/images/mac/textjustify.png
deleted file mode 100644
index 39cd6c1a9d..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textjustify.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textleft.png b/examples/widgets/richtext/textedit/images/mac/textleft.png
deleted file mode 100644
index 83a66d5535..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textleft.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textright.png b/examples/widgets/richtext/textedit/images/mac/textright.png
deleted file mode 100644
index e7c04645cf..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textright.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textunder.png b/examples/widgets/richtext/textedit/images/mac/textunder.png
deleted file mode 100644
index 968bac5e90..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textunder.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textundercolor.png b/examples/widgets/richtext/textedit/images/mac/textundercolor.png
deleted file mode 100644
index 30e24e61c3..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/textundercolor.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/zoomin.png b/examples/widgets/richtext/textedit/images/mac/zoomin.png
deleted file mode 100644
index d46f5aff0d..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/zoomin.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/zoomout.png b/examples/widgets/richtext/textedit/images/mac/zoomout.png
deleted file mode 100644
index 46326566d1..0000000000
--- a/examples/widgets/richtext/textedit/images/mac/zoomout.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/checkbox-checked.png b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png
deleted file mode 100644
index a072d7fb5c..0000000000
--- a/examples/widgets/richtext/textedit/images/win/checkbox-checked.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/checkbox.png b/examples/widgets/richtext/textedit/images/win/checkbox.png
deleted file mode 100644
index 4064909712..0000000000
--- a/examples/widgets/richtext/textedit/images/win/checkbox.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editcopy.png b/examples/widgets/richtext/textedit/images/win/editcopy.png
deleted file mode 100644
index 1121b47d8b..0000000000
--- a/examples/widgets/richtext/textedit/images/win/editcopy.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editcut.png b/examples/widgets/richtext/textedit/images/win/editcut.png
deleted file mode 100644
index 38e55f7420..0000000000
--- a/examples/widgets/richtext/textedit/images/win/editcut.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editpaste.png b/examples/widgets/richtext/textedit/images/win/editpaste.png
deleted file mode 100644
index ffab15aaf8..0000000000
--- a/examples/widgets/richtext/textedit/images/win/editpaste.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editredo.png b/examples/widgets/richtext/textedit/images/win/editredo.png
deleted file mode 100644
index 9d679fe6fc..0000000000
--- a/examples/widgets/richtext/textedit/images/win/editredo.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editundo.png b/examples/widgets/richtext/textedit/images/win/editundo.png
deleted file mode 100644
index eee23d24a3..0000000000
--- a/examples/widgets/richtext/textedit/images/win/editundo.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/exportpdf.png b/examples/widgets/richtext/textedit/images/win/exportpdf.png
deleted file mode 100644
index ebb44e6b88..0000000000
--- a/examples/widgets/richtext/textedit/images/win/exportpdf.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/filenew.png b/examples/widgets/richtext/textedit/images/win/filenew.png
deleted file mode 100644
index af5d122141..0000000000
--- a/examples/widgets/richtext/textedit/images/win/filenew.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/fileopen.png b/examples/widgets/richtext/textedit/images/win/fileopen.png
deleted file mode 100644
index fc6f17e977..0000000000
--- a/examples/widgets/richtext/textedit/images/win/fileopen.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/fileprint.png b/examples/widgets/richtext/textedit/images/win/fileprint.png
deleted file mode 100644
index ba7c02dc18..0000000000
--- a/examples/widgets/richtext/textedit/images/win/fileprint.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/filesave.png b/examples/widgets/richtext/textedit/images/win/filesave.png
deleted file mode 100644
index 8feec99bee..0000000000
--- a/examples/widgets/richtext/textedit/images/win/filesave.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-less.png b/examples/widgets/richtext/textedit/images/win/format-indent-less.png
deleted file mode 100644
index e38074e78b..0000000000
--- a/examples/widgets/richtext/textedit/images/win/format-indent-less.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-more.png b/examples/widgets/richtext/textedit/images/win/format-indent-more.png
deleted file mode 100644
index 1bdeabd354..0000000000
--- a/examples/widgets/richtext/textedit/images/win/format-indent-more.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textbold.png b/examples/widgets/richtext/textedit/images/win/textbold.png
deleted file mode 100644
index 9cbc7138b9..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textbold.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textcenter.png b/examples/widgets/richtext/textedit/images/win/textcenter.png
deleted file mode 100644
index 11efb4b852..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textcenter.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textitalic.png b/examples/widgets/richtext/textedit/images/win/textitalic.png
deleted file mode 100644
index b30ce14c14..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textitalic.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textjustify.png b/examples/widgets/richtext/textedit/images/win/textjustify.png
deleted file mode 100644
index 9de0c88085..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textjustify.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textleft.png b/examples/widgets/richtext/textedit/images/win/textleft.png
deleted file mode 100644
index 16f80bc325..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textleft.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textright.png b/examples/widgets/richtext/textedit/images/win/textright.png
deleted file mode 100644
index 16872df62a..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textright.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textunder.png b/examples/widgets/richtext/textedit/images/win/textunder.png
deleted file mode 100644
index c72eff53fb..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textunder.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textundercolor.png b/examples/widgets/richtext/textedit/images/win/textundercolor.png
deleted file mode 100644
index 30e24e61c3..0000000000
--- a/examples/widgets/richtext/textedit/images/win/textundercolor.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/zoomin.png b/examples/widgets/richtext/textedit/images/win/zoomin.png
deleted file mode 100644
index 2e586fc7bf..0000000000
--- a/examples/widgets/richtext/textedit/images/win/zoomin.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/zoomout.png b/examples/widgets/richtext/textedit/images/win/zoomout.png
deleted file mode 100644
index a736d39343..0000000000
--- a/examples/widgets/richtext/textedit/images/win/zoomout.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/richtext/textedit/main.cpp b/examples/widgets/richtext/textedit/main.cpp
deleted file mode 100644
index 076d5df8ae..0000000000
--- a/examples/widgets/richtext/textedit/main.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "textedit.h"
-
-#include <QApplication>
-#include <QCommandLineParser>
-#include <QCommandLineOption>
-#include <QScreen>
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(textedit);
-
- QApplication a(argc, argv);
- QCoreApplication::setOrganizationName("QtProject");
- QCoreApplication::setApplicationName("Rich Text");
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser parser;
- parser.setApplicationDescription(QCoreApplication::applicationName());
- parser.addHelpOption();
- parser.addVersionOption();
- parser.addPositionalArgument("file", "The file to open.");
- parser.process(a);
-
- TextEdit mw;
-
- const QRect availableGeometry = mw.screen()->availableGeometry();
- mw.resize(availableGeometry.width() / 2, (availableGeometry.height() * 2) / 3);
- mw.move((availableGeometry.width() - mw.width()) / 2,
- (availableGeometry.height() - mw.height()) / 2);
-
- if (!mw.load(parser.positionalArguments().value(0, QLatin1String(":/example.html"))))
- mw.fileNew();
-
- mw.show();
- return a.exec();
-}
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
deleted file mode 100644
index fd2d4a8a16..0000000000
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ /dev/null
@@ -1,851 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "textedit.h"
-
-#include <QActionGroup>
-#include <QApplication>
-#include <QClipboard>
-#include <QColorDialog>
-#include <QComboBox>
-#include <QFontComboBox>
-#include <QFile>
-#include <QFileDialog>
-#include <QFileInfo>
-#include <QFontDatabase>
-#include <QMenu>
-#include <QMenuBar>
-#include <QTextEdit>
-#include <QStatusBar>
-#include <QToolBar>
-#include <QTextCursor>
-#include <QTextDocumentWriter>
-#include <QTextList>
-#include <QtDebug>
-#include <QCloseEvent>
-#include <QMessageBox>
-#include <QMimeData>
-#include <QMimeDatabase>
-#include <QStringDecoder>
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#if QT_CONFIG(printer)
-#if QT_CONFIG(printdialog)
-#include <QPrintDialog>
-#endif
-#include <QPrinter>
-#if QT_CONFIG(printpreviewdialog)
-#include <QPrintPreviewDialog>
-#endif
-#endif
-#endif
-
-#ifdef Q_OS_MAC
-const QString rsrcPath = ":/images/mac";
-#else
-const QString rsrcPath = ":/images/win";
-#endif
-
-TextEdit::TextEdit(QWidget *parent)
- : QMainWindow(parent)
-{
-#ifdef Q_OS_MACOS
- setUnifiedTitleAndToolBarOnMac(true);
-#endif
- setWindowTitle(QCoreApplication::applicationName());
-
- textEdit = new QTextEdit(this);
- connect(textEdit, &QTextEdit::currentCharFormatChanged,
- this, &TextEdit::currentCharFormatChanged);
- connect(textEdit, &QTextEdit::cursorPositionChanged,
- this, &TextEdit::cursorPositionChanged);
- setCentralWidget(textEdit);
-
- setToolButtonStyle(Qt::ToolButtonFollowStyle);
- setupFileActions();
- setupEditActions();
- setupTextActions();
-
- {
- QMenu *helpMenu = menuBar()->addMenu(tr("Help"));
- helpMenu->addAction(tr("About"), this, &TextEdit::about);
- helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
- }
-
- QFont textFont("Helvetica");
- textFont.setStyleHint(QFont::SansSerif);
- textEdit->setFont(textFont);
- fontChanged(textEdit->font());
- colorChanged(textEdit->textColor());
- alignmentChanged(textEdit->alignment());
-
- auto *document = textEdit->document();
- connect(document, &QTextDocument::modificationChanged,
- actionSave, &QAction::setEnabled);
- connect(document, &QTextDocument::modificationChanged,
- this, &QWidget::setWindowModified);
- connect(document, &QTextDocument::undoAvailable,
- actionUndo, &QAction::setEnabled);
- connect(document, &QTextDocument::redoAvailable,
- actionRedo, &QAction::setEnabled);
-
- setWindowModified(document->isModified());
- actionSave->setEnabled(document->isModified());
- actionUndo->setEnabled(document->isUndoAvailable());
- actionRedo->setEnabled(document->isRedoAvailable());
-
-#ifndef QT_NO_CLIPBOARD
- actionCut->setEnabled(false);
- connect(textEdit, &QTextEdit::copyAvailable, actionCut, &QAction::setEnabled);
- actionCopy->setEnabled(false);
- connect(textEdit, &QTextEdit::copyAvailable, actionCopy, &QAction::setEnabled);
-
- connect(QGuiApplication::clipboard(), &QClipboard::dataChanged,
- this, &TextEdit::clipboardDataChanged);
-#endif
-
- textEdit->setFocus();
- setCurrentFileName(QString());
-
-#ifdef Q_OS_MACOS
- // Use dark text on light background on macOS, also in dark mode.
- QPalette pal = textEdit->palette();
- pal.setColor(QPalette::Base, QColor(Qt::white));
- pal.setColor(QPalette::Text, QColor(Qt::black));
- textEdit->setPalette(pal);
-#endif
-}
-
-void TextEdit::closeEvent(QCloseEvent *e)
-{
- if (maybeSave())
- e->accept();
- else
- e->ignore();
-}
-
-void TextEdit::setupFileActions()
-{
- QToolBar *tb = addToolBar(tr("File Actions"));
- QMenu *menu = menuBar()->addMenu(tr("&File"));
-
- const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(rsrcPath + "/filenew.png"));
- QAction *a = menu->addAction(newIcon, tr("&New"), this, &TextEdit::fileNew);
- tb->addAction(a);
- a->setPriority(QAction::LowPriority);
- a->setShortcut(QKeySequence::New);
-
- const QIcon openIcon = QIcon::fromTheme("document-open", QIcon(rsrcPath + "/fileopen.png"));
- a = menu->addAction(openIcon, tr("&Open..."), this, &TextEdit::fileOpen);
- a->setShortcut(QKeySequence::Open);
- tb->addAction(a);
-
- menu->addSeparator();
-
- const QIcon saveIcon = QIcon::fromTheme("document-save", QIcon(rsrcPath + "/filesave.png"));
- actionSave = menu->addAction(saveIcon, tr("&Save"), this, &TextEdit::fileSave);
- actionSave->setShortcut(QKeySequence::Save);
- actionSave->setEnabled(false);
- tb->addAction(actionSave);
-
- a = menu->addAction(tr("Save &As..."), this, &TextEdit::fileSaveAs);
- a->setPriority(QAction::LowPriority);
- menu->addSeparator();
-
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
- const QIcon printIcon = QIcon::fromTheme("document-print", QIcon(rsrcPath + "/fileprint.png"));
- a = menu->addAction(printIcon, tr("&Print..."), this, &TextEdit::filePrint);
- a->setPriority(QAction::LowPriority);
- a->setShortcut(QKeySequence::Print);
- tb->addAction(a);
-
- const QIcon filePrintIcon = QIcon::fromTheme("fileprint", QIcon(rsrcPath + "/fileprint.png"));
- menu->addAction(filePrintIcon, tr("Print Preview..."), this, &TextEdit::filePrintPreview);
-
- const QIcon exportPdfIcon = QIcon::fromTheme("exportpdf", QIcon(rsrcPath + "/exportpdf.png"));
- a = menu->addAction(exportPdfIcon, tr("&Export PDF..."), this, &TextEdit::filePrintPdf);
- a->setPriority(QAction::LowPriority);
- a->setShortcut(Qt::CTRL | Qt::Key_D);
- tb->addAction(a);
-
- menu->addSeparator();
-#endif
-
- a = menu->addAction(tr("&Quit"), qApp, &QCoreApplication::quit);
- a->setShortcut(Qt::CTRL | Qt::Key_Q);
-}
-
-void TextEdit::setupEditActions()
-{
- QToolBar *tb = addToolBar(tr("Edit Actions"));
- QMenu *menu = menuBar()->addMenu(tr("&Edit"));
-
- const QIcon undoIcon = QIcon::fromTheme("edit-undo", QIcon(rsrcPath + "/editundo.png"));
- actionUndo = menu->addAction(undoIcon, tr("&Undo"), textEdit, &QTextEdit::undo);
- actionUndo->setShortcut(QKeySequence::Undo);
- tb->addAction(actionUndo);
-
- const QIcon redoIcon = QIcon::fromTheme("edit-redo", QIcon(rsrcPath + "/editredo.png"));
- actionRedo = menu->addAction(redoIcon, tr("&Redo"), textEdit, &QTextEdit::redo);
- actionRedo->setPriority(QAction::LowPriority);
- actionRedo->setShortcut(QKeySequence::Redo);
- tb->addAction(actionRedo);
- menu->addSeparator();
-
-#ifndef QT_NO_CLIPBOARD
- const QIcon cutIcon = QIcon::fromTheme("edit-cut", QIcon(rsrcPath + "/editcut.png"));
- actionCut = menu->addAction(cutIcon, tr("Cu&t"), textEdit, &QTextEdit::cut);
- actionCut->setPriority(QAction::LowPriority);
- actionCut->setShortcut(QKeySequence::Cut);
- tb->addAction(actionCut);
-
- const QIcon copyIcon = QIcon::fromTheme("edit-copy", QIcon(rsrcPath + "/editcopy.png"));
- actionCopy = menu->addAction(copyIcon, tr("&Copy"), textEdit, &QTextEdit::copy);
- actionCopy->setPriority(QAction::LowPriority);
- actionCopy->setShortcut(QKeySequence::Copy);
- tb->addAction(actionCopy);
-
- const QIcon pasteIcon = QIcon::fromTheme("edit-paste", QIcon(rsrcPath + "/editpaste.png"));
- actionPaste = menu->addAction(pasteIcon, tr("&Paste"), textEdit, &QTextEdit::paste);
- actionPaste->setPriority(QAction::LowPriority);
- actionPaste->setShortcut(QKeySequence::Paste);
- tb->addAction(actionPaste);
- if (const QMimeData *md = QGuiApplication::clipboard()->mimeData())
- actionPaste->setEnabled(md->hasText());
-#endif
-}
-
-void TextEdit::setupTextActions()
-{
- QToolBar *tb = addToolBar(tr("Format Actions"));
- QMenu *menu = menuBar()->addMenu(tr("F&ormat"));
-
- const QIcon boldIcon = QIcon::fromTheme("format-text-bold", QIcon(rsrcPath + "/textbold.png"));
- actionTextBold = menu->addAction(boldIcon, tr("&Bold"), this, &TextEdit::textBold);
- actionTextBold->setShortcut(Qt::CTRL | Qt::Key_B);
- actionTextBold->setPriority(QAction::LowPriority);
- QFont bold;
- bold.setBold(true);
- actionTextBold->setFont(bold);
- tb->addAction(actionTextBold);
- actionTextBold->setCheckable(true);
-
- const QIcon italicIcon = QIcon::fromTheme("format-text-italic", QIcon(rsrcPath + "/textitalic.png"));
- actionTextItalic = menu->addAction(italicIcon, tr("&Italic"), this, &TextEdit::textItalic);
- actionTextItalic->setPriority(QAction::LowPriority);
- actionTextItalic->setShortcut(Qt::CTRL | Qt::Key_I);
- QFont italic;
- italic.setItalic(true);
- actionTextItalic->setFont(italic);
- tb->addAction(actionTextItalic);
- actionTextItalic->setCheckable(true);
-
- const QIcon underlineIcon = QIcon::fromTheme("format-text-underline", QIcon(rsrcPath + "/textunder.png"));
- actionTextUnderline = menu->addAction(underlineIcon, tr("&Underline"), this, &TextEdit::textUnderline);
- actionTextUnderline->setShortcut(Qt::CTRL | Qt::Key_U);
- actionTextUnderline->setPriority(QAction::LowPriority);
- QFont underline;
- underline.setUnderline(true);
- actionTextUnderline->setFont(underline);
- tb->addAction(actionTextUnderline);
- actionTextUnderline->setCheckable(true);
-
- menu->addSeparator();
-
- const QIcon leftIcon = QIcon::fromTheme("format-justify-left", QIcon(rsrcPath + "/textleft.png"));
- actionAlignLeft = new QAction(leftIcon, tr("&Left"), this);
- actionAlignLeft->setShortcut(Qt::CTRL | Qt::Key_L);
- actionAlignLeft->setCheckable(true);
- actionAlignLeft->setPriority(QAction::LowPriority);
- const QIcon centerIcon = QIcon::fromTheme("format-justify-center", QIcon(rsrcPath + "/textcenter.png"));
- actionAlignCenter = new QAction(centerIcon, tr("C&enter"), this);
- actionAlignCenter->setShortcut(Qt::CTRL | Qt::Key_E);
- actionAlignCenter->setCheckable(true);
- actionAlignCenter->setPriority(QAction::LowPriority);
- const QIcon rightIcon = QIcon::fromTheme("format-justify-right", QIcon(rsrcPath + "/textright.png"));
- actionAlignRight = new QAction(rightIcon, tr("&Right"), this);
- actionAlignRight->setShortcut(Qt::CTRL | Qt::Key_R);
- actionAlignRight->setCheckable(true);
- actionAlignRight->setPriority(QAction::LowPriority);
- const QIcon fillIcon = QIcon::fromTheme("format-justify-fill", QIcon(rsrcPath + "/textjustify.png"));
- actionAlignJustify = new QAction(fillIcon, tr("&Justify"), this);
- actionAlignJustify->setShortcut(Qt::CTRL | Qt::Key_J);
- actionAlignJustify->setCheckable(true);
- actionAlignJustify->setPriority(QAction::LowPriority);
- const QIcon indentMoreIcon = QIcon::fromTheme("format-indent-more", QIcon(rsrcPath + "/format-indent-more.png"));
- actionIndentMore = menu->addAction(indentMoreIcon, tr("&Indent"), this, &TextEdit::indent);
- actionIndentMore->setShortcut(Qt::CTRL | Qt::Key_BracketRight);
- actionIndentMore->setPriority(QAction::LowPriority);
- const QIcon indentLessIcon = QIcon::fromTheme("format-indent-less", QIcon(rsrcPath + "/format-indent-less.png"));
- actionIndentLess = menu->addAction(indentLessIcon, tr("&Unindent"), this, &TextEdit::unindent);
- actionIndentLess->setShortcut(Qt::CTRL | Qt::Key_BracketLeft);
- actionIndentLess->setPriority(QAction::LowPriority);
-
- // Make sure the alignLeft is always left of the alignRight
- QActionGroup *alignGroup = new QActionGroup(this);
- connect(alignGroup, &QActionGroup::triggered, this, &TextEdit::textAlign);
-
- if (QGuiApplication::isLeftToRight()) {
- alignGroup->addAction(actionAlignLeft);
- alignGroup->addAction(actionAlignCenter);
- alignGroup->addAction(actionAlignRight);
- } else {
- alignGroup->addAction(actionAlignRight);
- alignGroup->addAction(actionAlignCenter);
- alignGroup->addAction(actionAlignLeft);
- }
- alignGroup->addAction(actionAlignJustify);
-
- tb->addActions(alignGroup->actions());
- menu->addActions(alignGroup->actions());
- tb->addAction(actionIndentMore);
- tb->addAction(actionIndentLess);
- menu->addAction(actionIndentMore);
- menu->addAction(actionIndentLess);
-
- menu->addSeparator();
-
- QPixmap pix(16, 16);
- pix.fill(Qt::black);
- actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor);
- tb->addAction(actionTextColor);
-
- const QIcon underlineColorIcon(rsrcPath + "/textundercolor.png");
- actionUnderlineColor = menu->addAction(underlineColorIcon, tr("Underline color..."), this, &TextEdit::underlineColor);
- tb->addAction(actionUnderlineColor);
-
- menu->addSeparator();
-
- const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png"));
- actionToggleCheckState = menu->addAction(checkboxIcon, tr("Chec&ked"), this, &TextEdit::setChecked);
- actionToggleCheckState->setShortcut(Qt::CTRL | Qt::Key_K);
- actionToggleCheckState->setCheckable(true);
- actionToggleCheckState->setPriority(QAction::LowPriority);
- tb->addAction(actionToggleCheckState);
-
- tb = addToolBar(tr("Format Actions"));
- tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
- addToolBarBreak(Qt::TopToolBarArea);
- addToolBar(tb);
-
- comboStyle = new QComboBox(tb);
- tb->addWidget(comboStyle);
- comboStyle->addItems({"Standard",
- "Bullet List (Disc)",
- "Bullet List (Circle)",
- "Bullet List (Square)",
- "Task List (Unchecked)",
- "Task List (Checked)",
- "Ordered List (Decimal)",
- "Ordered List (Alpha lower)",
- "Ordered List (Alpha upper)",
- "Ordered List (Roman lower)",
- "Ordered List (Roman upper)",
- "Heading 1",
- "Heading 2",
- "Heading 3",
- "Heading 4",
- "Heading 5",
- "Heading 6"}),
-
- connect(comboStyle, &QComboBox::activated, this, &TextEdit::textStyle);
-
- comboFont = new QFontComboBox(tb);
- tb->addWidget(comboFont);
- connect(comboFont, &QComboBox::textActivated, this, &TextEdit::textFamily);
-
- comboSize = new QComboBox(tb);
- comboSize->setObjectName("comboSize");
- tb->addWidget(comboSize);
- comboSize->setEditable(true);
-
- const QList<int> standardSizes = QFontDatabase::standardSizes();
- for (int size : standardSizes)
- comboSize->addItem(QString::number(size));
- comboSize->setCurrentIndex(standardSizes.indexOf(QApplication::font().pointSize()));
-
- connect(comboSize, &QComboBox::textActivated, this, &TextEdit::textSize);
-}
-
-bool TextEdit::load(const QString &f)
-{
- if (!QFile::exists(f))
- return false;
- QFile file(f);
- if (!file.open(QFile::ReadOnly))
- return false;
-
- QByteArray data = file.readAll();
- QMimeDatabase db;
- const QString &mimeTypeName = db.mimeTypeForFileNameAndData(f, data).name();
- if (mimeTypeName == u"text/html") {
- auto encoding = QStringDecoder::encodingForHtml(data);
- QString str = QStringDecoder(encoding ? *encoding : QStringDecoder::Utf8)(data);
- QUrl fileUrl = f.startsWith(u':') ? QUrl(f) : QUrl::fromLocalFile(f);
- textEdit->document()->setBaseUrl(fileUrl.adjusted(QUrl::RemoveFilename));
- textEdit->setHtml(str);
-#if QT_CONFIG(textmarkdownreader)
- } else if (mimeTypeName == u"text/markdown") {
- textEdit->setMarkdown(QString::fromUtf8(data));
-#endif
- } else {
- textEdit->setPlainText(QString::fromUtf8(data));
- }
-
- setCurrentFileName(f);
- return true;
-}
-
-bool TextEdit::maybeSave()
-{
- if (!textEdit->document()->isModified())
- return true;
-
- const QMessageBox::StandardButton ret =
- QMessageBox::warning(this, QCoreApplication::applicationName(),
- tr("The document has been modified.\n"
- "Do you want to save your changes?"),
- QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
- if (ret == QMessageBox::Save)
- return fileSave();
- if (ret == QMessageBox::Cancel)
- return false;
- return true;
-}
-
-void TextEdit::setCurrentFileName(const QString &fileName)
-{
- this->fileName = fileName;
- textEdit->document()->setModified(false);
-
- QString shownName;
- if (fileName.isEmpty())
- shownName = "untitled.txt";
- else
- shownName = QFileInfo(fileName).fileName();
-
- setWindowTitle(tr("%1[*] - %2").arg(shownName, QCoreApplication::applicationName()));
- setWindowModified(false);
-}
-
-void TextEdit::fileNew()
-{
- if (maybeSave()) {
- textEdit->clear();
- setCurrentFileName({});
- }
-}
-
-void TextEdit::fileOpen()
-{
- QFileDialog fileDialog(this, tr("Open File..."));
- fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
- fileDialog.setFileMode(QFileDialog::ExistingFile);
- fileDialog.setMimeTypeFilters({
-#if QT_CONFIG(texthtmlparser)
- "text/html",
-#endif
-#if QT_CONFIG(textmarkdownreader)
-
- "text/markdown",
-#endif
- "text/plain"});
- if (fileDialog.exec() != QDialog::Accepted)
- return;
- const QString fn = fileDialog.selectedFiles().constFirst();
- if (load(fn))
- statusBar()->showMessage(tr("Opened \"%1\"").arg(QDir::toNativeSeparators(fn)));
- else
- statusBar()->showMessage(tr("Could not open \"%1\"").arg(QDir::toNativeSeparators(fn)));
-}
-
-bool TextEdit::fileSave()
-{
- if (fileName.isEmpty() || fileName.startsWith(u":/"))
- return fileSaveAs();
-
- QTextDocumentWriter writer(fileName);
- bool success = writer.write(textEdit->document());
- if (success) {
- textEdit->document()->setModified(false);
- statusBar()->showMessage(tr("Wrote \"%1\"").arg(QDir::toNativeSeparators(fileName)));
- } else {
- statusBar()->showMessage(tr("Could not write to file \"%1\"")
- .arg(QDir::toNativeSeparators(fileName)));
- }
- return success;
-}
-
-bool TextEdit::fileSaveAs()
-{
- QFileDialog fileDialog(this, tr("Save as..."));
- fileDialog.setAcceptMode(QFileDialog::AcceptSave);
- QStringList mimeTypes{"text/plain",
-#if QT_CONFIG(textodfwriter)
- "application/vnd.oasis.opendocument.text",
-#endif
-#if QT_CONFIG(textmarkdownwriter)
- "text/markdown",
-#endif
- "text/html"};
- fileDialog.setMimeTypeFilters(mimeTypes);
-#if QT_CONFIG(textodfwriter)
- fileDialog.setDefaultSuffix("odt");
-#endif
- if (fileDialog.exec() != QDialog::Accepted)
- return false;
- const QString fn = fileDialog.selectedFiles().constFirst();
- setCurrentFileName(fn);
- return fileSave();
-}
-
-void TextEdit::filePrint()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- QPrinter printer(QPrinter::HighResolution);
- QPrintDialog dlg(&printer, this);
- if (textEdit->textCursor().hasSelection())
- dlg.setOption(QAbstractPrintDialog::PrintSelection);
- dlg.setWindowTitle(tr("Print Document"));
- if (dlg.exec() == QDialog::Accepted)
- textEdit->print(&printer);
-#endif
-}
-
-void TextEdit::filePrintPreview()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printpreviewdialog)
- QPrinter printer(QPrinter::HighResolution);
- QPrintPreviewDialog preview(&printer, this);
- connect(&preview, &QPrintPreviewDialog::paintRequested, textEdit, &QTextEdit::print);
- preview.exec();
-#endif
-}
-
-void TextEdit::filePrintPdf()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
-//! [0]
- QFileDialog fileDialog(this, tr("Export PDF"));
- fileDialog.setAcceptMode(QFileDialog::AcceptSave);
- fileDialog.setMimeTypeFilters(QStringList("application/pdf"));
- fileDialog.setDefaultSuffix("pdf");
- if (fileDialog.exec() != QDialog::Accepted)
- return;
- QString pdfFileName = fileDialog.selectedFiles().constFirst();
- QPrinter printer(QPrinter::HighResolution);
- printer.setOutputFormat(QPrinter::PdfFormat);
- printer.setOutputFileName(pdfFileName);
- textEdit->document()->print(&printer);
- statusBar()->showMessage(tr("Exported \"%1\"")
- .arg(QDir::toNativeSeparators(pdfFileName)));
-//! [0]
-#endif
-}
-
-void TextEdit::textBold()
-{
- QTextCharFormat fmt;
- fmt.setFontWeight(actionTextBold->isChecked() ? QFont::Bold : QFont::Normal);
- mergeFormatOnWordOrSelection(fmt);
-}
-
-void TextEdit::textUnderline()
-{
- QTextCharFormat fmt;
- fmt.setFontUnderline(actionTextUnderline->isChecked());
- mergeFormatOnWordOrSelection(fmt);
-}
-
-void TextEdit::textItalic()
-{
- QTextCharFormat fmt;
- fmt.setFontItalic(actionTextItalic->isChecked());
- mergeFormatOnWordOrSelection(fmt);
-}
-
-void TextEdit::textFamily(const QString &f)
-{
- QTextCharFormat fmt;
- fmt.setFontFamilies({f});
- mergeFormatOnWordOrSelection(fmt);
-}
-
-void TextEdit::textSize(const QString &p)
-{
- qreal pointSize = p.toFloat();
- if (pointSize > 0) {
- QTextCharFormat fmt;
- fmt.setFontPointSize(pointSize);
- mergeFormatOnWordOrSelection(fmt);
- }
-}
-
-void TextEdit::textStyle(int styleIndex)
-{
- QTextCursor cursor = textEdit->textCursor();
- QTextListFormat::Style style = QTextListFormat::ListStyleUndefined;
- QTextBlockFormat::MarkerType marker = QTextBlockFormat::MarkerType::NoMarker;
-
- switch (styleIndex) {
- case 1:
- style = QTextListFormat::ListDisc;
- break;
- case 2:
- style = QTextListFormat::ListCircle;
- break;
- case 3:
- style = QTextListFormat::ListSquare;
- break;
- case 4:
- if (cursor.currentList())
- style = cursor.currentList()->format().style();
- else
- style = QTextListFormat::ListDisc;
- marker = QTextBlockFormat::MarkerType::Unchecked;
- break;
- case 5:
- if (cursor.currentList())
- style = cursor.currentList()->format().style();
- else
- style = QTextListFormat::ListDisc;
- marker = QTextBlockFormat::MarkerType::Checked;
- break;
- case 6:
- style = QTextListFormat::ListDecimal;
- break;
- case 7:
- style = QTextListFormat::ListLowerAlpha;
- break;
- case 8:
- style = QTextListFormat::ListUpperAlpha;
- break;
- case 9:
- style = QTextListFormat::ListLowerRoman;
- break;
- case 10:
- style = QTextListFormat::ListUpperRoman;
- break;
- default:
- break;
- }
-
- cursor.beginEditBlock();
-
- QTextBlockFormat blockFmt = cursor.blockFormat();
-
- if (style == QTextListFormat::ListStyleUndefined) {
- blockFmt.setObjectIndex(-1);
- int headingLevel = styleIndex >= 11 ? styleIndex - 11 + 1 : 0; // H1 to H6, or Standard
- blockFmt.setHeadingLevel(headingLevel);
- cursor.setBlockFormat(blockFmt);
-
- int sizeAdjustment = headingLevel ? 4 - headingLevel : 0; // H1 to H6: +3 to -2
- QTextCharFormat fmt;
- fmt.setFontWeight(headingLevel ? QFont::Bold : QFont::Normal);
- fmt.setProperty(QTextFormat::FontSizeAdjustment, sizeAdjustment);
- cursor.select(QTextCursor::LineUnderCursor);
- cursor.mergeCharFormat(fmt);
- textEdit->mergeCurrentCharFormat(fmt);
- } else {
- blockFmt.setMarker(marker);
- cursor.setBlockFormat(blockFmt);
- QTextListFormat listFmt;
- if (cursor.currentList()) {
- listFmt = cursor.currentList()->format();
- } else {
- listFmt.setIndent(blockFmt.indent() + 1);
- blockFmt.setIndent(0);
- cursor.setBlockFormat(blockFmt);
- }
- listFmt.setStyle(style);
- cursor.createList(listFmt);
- }
-
- cursor.endEditBlock();
-}
-
-void TextEdit::textColor()
-{
- QColor col = QColorDialog::getColor(textEdit->textColor(), this);
- if (!col.isValid())
- return;
- QTextCharFormat fmt;
- fmt.setForeground(col);
- mergeFormatOnWordOrSelection(fmt);
- colorChanged(col);
-}
-
-void TextEdit::underlineColor()
-{
- QColor col = QColorDialog::getColor(Qt::black, this);
- if (!col.isValid())
- return;
- QTextCharFormat fmt;
- fmt.setUnderlineColor(col);
- mergeFormatOnWordOrSelection(fmt);
- colorChanged(col);
-}
-
-void TextEdit::textAlign(QAction *a)
-{
- if (a == actionAlignLeft)
- textEdit->setAlignment(Qt::AlignLeft | Qt::AlignAbsolute);
- else if (a == actionAlignCenter)
- textEdit->setAlignment(Qt::AlignHCenter);
- else if (a == actionAlignRight)
- textEdit->setAlignment(Qt::AlignRight | Qt::AlignAbsolute);
- else if (a == actionAlignJustify)
- textEdit->setAlignment(Qt::AlignJustify);
-}
-
-void TextEdit::setChecked(bool checked)
-{
- textStyle(checked ? 5 : 4);
-}
-
-void TextEdit::indent()
-{
- modifyIndentation(1);
-}
-
-void TextEdit::unindent()
-{
- modifyIndentation(-1);
-}
-
-void TextEdit::modifyIndentation(int amount)
-{
- QTextCursor cursor = textEdit->textCursor();
- cursor.beginEditBlock();
- if (cursor.currentList()) {
- QTextListFormat listFmt = cursor.currentList()->format();
- // See whether the line above is the list we want to move this item into,
- // or whether we need a new list.
- QTextCursor above(cursor);
- above.movePosition(QTextCursor::Up);
- if (above.currentList() && listFmt.indent() + amount == above.currentList()->format().indent()) {
- above.currentList()->add(cursor.block());
- } else {
- listFmt.setIndent(listFmt.indent() + amount);
- cursor.createList(listFmt);
- }
- } else {
- QTextBlockFormat blockFmt = cursor.blockFormat();
- blockFmt.setIndent(blockFmt.indent() + amount);
- cursor.setBlockFormat(blockFmt);
- }
- cursor.endEditBlock();
-}
-
-void TextEdit::currentCharFormatChanged(const QTextCharFormat &format)
-{
- fontChanged(format.font());
- colorChanged(format.foreground().color());
-}
-
-void TextEdit::cursorPositionChanged()
-{
- alignmentChanged(textEdit->alignment());
- QTextList *list = textEdit->textCursor().currentList();
- if (list) {
- switch (list->format().style()) {
- case QTextListFormat::ListDisc:
- comboStyle->setCurrentIndex(1);
- break;
- case QTextListFormat::ListCircle:
- comboStyle->setCurrentIndex(2);
- break;
- case QTextListFormat::ListSquare:
- comboStyle->setCurrentIndex(3);
- break;
- case QTextListFormat::ListDecimal:
- comboStyle->setCurrentIndex(6);
- break;
- case QTextListFormat::ListLowerAlpha:
- comboStyle->setCurrentIndex(7);
- break;
- case QTextListFormat::ListUpperAlpha:
- comboStyle->setCurrentIndex(8);
- break;
- case QTextListFormat::ListLowerRoman:
- comboStyle->setCurrentIndex(9);
- break;
- case QTextListFormat::ListUpperRoman:
- comboStyle->setCurrentIndex(10);
- break;
- default:
- comboStyle->setCurrentIndex(-1);
- break;
- }
- switch (textEdit->textCursor().block().blockFormat().marker()) {
- case QTextBlockFormat::MarkerType::NoMarker:
- actionToggleCheckState->setChecked(false);
- break;
- case QTextBlockFormat::MarkerType::Unchecked:
- comboStyle->setCurrentIndex(4);
- actionToggleCheckState->setChecked(false);
- break;
- case QTextBlockFormat::MarkerType::Checked:
- comboStyle->setCurrentIndex(5);
- actionToggleCheckState->setChecked(true);
- break;
- }
- } else {
- int headingLevel = textEdit->textCursor().blockFormat().headingLevel();
- comboStyle->setCurrentIndex(headingLevel ? headingLevel + 10 : 0);
- }
-}
-
-void TextEdit::clipboardDataChanged()
-{
-#ifndef QT_NO_CLIPBOARD
- if (const QMimeData *md = QGuiApplication::clipboard()->mimeData())
- actionPaste->setEnabled(md->hasText());
-#endif
-}
-
-void TextEdit::about()
-{
- QMessageBox::about(this, tr("About"), tr("This example demonstrates Qt's "
- "rich text editing facilities in action, providing an example "
- "document for you to experiment with."));
-}
-
-void TextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
-{
- QTextCursor cursor = textEdit->textCursor();
- if (!cursor.hasSelection())
- cursor.select(QTextCursor::WordUnderCursor);
- cursor.mergeCharFormat(format);
- textEdit->mergeCurrentCharFormat(format);
-}
-
-void TextEdit::fontChanged(const QFont &f)
-{
- comboFont->setCurrentIndex(comboFont->findText(QFontInfo(f).family()));
- comboSize->setCurrentIndex(comboSize->findText(QString::number(f.pointSize())));
- actionTextBold->setChecked(f.bold());
- actionTextItalic->setChecked(f.italic());
- actionTextUnderline->setChecked(f.underline());
-}
-
-void TextEdit::colorChanged(const QColor &c)
-{
- QPixmap pix(16, 16);
- pix.fill(c);
- actionTextColor->setIcon(pix);
-}
-
-void TextEdit::alignmentChanged(Qt::Alignment a)
-{
- if (a.testFlag(Qt::AlignLeft))
- actionAlignLeft->setChecked(true);
- else if (a.testFlag(Qt::AlignHCenter))
- actionAlignCenter->setChecked(true);
- else if (a.testFlag(Qt::AlignRight))
- actionAlignRight->setChecked(true);
- else if (a.testFlag(Qt::AlignJustify))
- actionAlignJustify->setChecked(true);
-}
-
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
deleted file mode 100644
index 2184863edc..0000000000
--- a/examples/widgets/richtext/textedit/textedit.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef TEXTEDIT_H
-#define TEXTEDIT_H
-
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QComboBox;
-class QFontComboBox;
-class QTextEdit;
-class QTextCharFormat;
-class QMenu;
-class QPrinter;
-QT_END_NAMESPACE
-
-class TextEdit : public QMainWindow
-{
- Q_OBJECT
-
-public:
- TextEdit(QWidget *parent = nullptr);
-
- bool load(const QString &f);
-
-public slots:
- void fileNew();
-
-protected:
- void closeEvent(QCloseEvent *e) override;
-
-private slots:
- void fileOpen();
- bool fileSave();
- bool fileSaveAs();
- void filePrint();
- void filePrintPreview();
- void filePrintPdf();
-
- void textBold();
- void textUnderline();
- void textItalic();
- void textFamily(const QString &f);
- void textSize(const QString &p);
- void textStyle(int styleIndex);
- void textColor();
- void underlineColor();
- void textAlign(QAction *a);
- void setChecked(bool checked);
- void indent();
- void unindent();
-
- void currentCharFormatChanged(const QTextCharFormat &format);
- void cursorPositionChanged();
-
- void clipboardDataChanged();
- void about();
-
-private:
- void setupFileActions();
- void setupEditActions();
- void setupTextActions();
- bool maybeSave();
- void setCurrentFileName(const QString &fileName);
- void modifyIndentation(int amount);
-
- void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
- void fontChanged(const QFont &f);
- void colorChanged(const QColor &c);
- void alignmentChanged(Qt::Alignment a);
-
- QAction *actionSave;
- QAction *actionTextBold;
- QAction *actionTextUnderline;
- QAction *actionTextItalic;
- QAction *actionTextColor;
- QAction *actionUnderlineColor;
- QAction *actionAlignLeft;
- QAction *actionAlignCenter;
- QAction *actionAlignRight;
- QAction *actionAlignJustify;
- QAction *actionIndentLess;
- QAction *actionIndentMore;
- QAction *actionToggleCheckState;
- QAction *actionUndo;
- QAction *actionRedo;
-#ifndef QT_NO_CLIPBOARD
- QAction *actionCut;
- QAction *actionCopy;
- QAction *actionPaste;
-#endif
-
- QComboBox *comboStyle;
- QFontComboBox *comboFont;
- QComboBox *comboSize;
-
- QString fileName;
- QTextEdit *textEdit;
-};
-
-#endif // TEXTEDIT_H
diff --git a/examples/widgets/richtext/textedit/textedit.pro b/examples/widgets/richtext/textedit/textedit.pro
deleted file mode 100644
index b7a2155b0b..0000000000
--- a/examples/widgets/richtext/textedit/textedit.pro
+++ /dev/null
@@ -1,22 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-qtHaveModule(printsupport): QT += printsupport
-
-TEMPLATE = app
-TARGET = textedit
-
-HEADERS = textedit.h
-SOURCES = textedit.cpp \
- main.cpp
-
-RESOURCES += textedit.qrc
-build_all:!build_pass {
- CONFIG -= build_all
- CONFIG += release
-}
-
-EXAMPLE_FILES = textedit.qdoc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/richtext/textedit
-INSTALLS += target
diff --git a/examples/widgets/richtext/textedit/textedit.qdoc b/examples/widgets/richtext/textedit/textedit.qdoc
deleted file mode 100644
index 938fad36c8..0000000000
--- a/examples/widgets/richtext/textedit/textedit.qdoc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*! \page textedit-example.html
-
- \ingroup examples
- \title Text Edit Example
-
- \brief This example displays a text editor with the user interface written
- in pure C++.
-
- A similar example which uses Qt Designer to produce the user
- interface is in the \l {Qt Designer Manual}.
-
-
- See \c{$QTDIR/examples/textedit} for the source code.
-
-*/
-
-
diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc
deleted file mode 100644
index a30d50fdbf..0000000000
--- a/examples/widgets/richtext/textedit/textedit.qrc
+++ /dev/null
@@ -1,54 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
- <file>images/logo32.png</file>
- <file>images/mac/checkbox.png</file>
- <file>images/mac/checkbox-checked.png</file>
- <file>images/mac/editcopy.png</file>
- <file>images/mac/editcut.png</file>
- <file>images/mac/editpaste.png</file>
- <file>images/mac/editredo.png</file>
- <file>images/mac/editundo.png</file>
- <file>images/mac/exportpdf.png</file>
- <file>images/mac/filenew.png</file>
- <file>images/mac/fileopen.png</file>
- <file>images/mac/fileprint.png</file>
- <file>images/mac/filesave.png</file>
- <file>images/mac/format-indent-less.png</file>
- <file>images/mac/format-indent-more.png</file>
- <file>images/mac/textbold.png</file>
- <file>images/mac/textcenter.png</file>
- <file>images/mac/textitalic.png</file>
- <file>images/mac/textjustify.png</file>
- <file>images/mac/textleft.png</file>
- <file>images/mac/textright.png</file>
- <file>images/mac/textunder.png</file>
- <file>images/mac/textundercolor.png</file>
- <file>images/mac/zoomin.png</file>
- <file>images/mac/zoomout.png</file>
- <file>images/win/checkbox.png</file>
- <file>images/win/checkbox-checked.png</file>
- <file>images/win/editcopy.png</file>
- <file>images/win/editcut.png</file>
- <file>images/win/editpaste.png</file>
- <file>images/win/editredo.png</file>
- <file>images/win/editundo.png</file>
- <file>images/win/exportpdf.png</file>
- <file>images/win/filenew.png</file>
- <file>images/win/fileopen.png</file>
- <file>images/win/fileprint.png</file>
- <file>images/win/filesave.png</file>
- <file>images/win/format-indent-less.png</file>
- <file>images/win/format-indent-more.png</file>
- <file>images/win/textbold.png</file>
- <file>images/win/textcenter.png</file>
- <file>images/win/textitalic.png</file>
- <file>images/win/textjustify.png</file>
- <file>images/win/textleft.png</file>
- <file>images/win/textright.png</file>
- <file>images/win/textunder.png</file>
- <file>images/win/textundercolor.png</file>
- <file>images/win/zoomin.png</file>
- <file>images/win/zoomout.png</file>
- <file>example.html</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/scroller/CMakeLists.txt b/examples/widgets/scroller/CMakeLists.txt
deleted file mode 100644
index fb9ebc2848..0000000000
--- a/examples/widgets/scroller/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-qt_internal_add_example(graphicsview)
diff --git a/examples/widgets/scroller/graphicsview/CMakeLists.txt b/examples/widgets/scroller/graphicsview/CMakeLists.txt
deleted file mode 100644
index bef281d48a..0000000000
--- a/examples/widgets/scroller/graphicsview/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(graphicsview LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/scroller/graphicsview")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(graphicsview
- main.cpp
-)
-
-set_target_properties(graphicsview PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(graphicsview PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS graphicsview
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/scroller/graphicsview/graphicsview.pro b/examples/widgets/scroller/graphicsview/graphicsview.pro
deleted file mode 100644
index 39bdb2bc2c..0000000000
--- a/examples/widgets/scroller/graphicsview/graphicsview.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-QT += widgets
-
-TEMPLATE = app
-SOURCES = main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/scroller/graphicsview
-INSTALLS += target
diff --git a/examples/widgets/scroller/graphicsview/main.cpp b/examples/widgets/scroller/graphicsview/main.cpp
deleted file mode 100644
index b8df2b1b2e..0000000000
--- a/examples/widgets/scroller/graphicsview/main.cpp
+++ /dev/null
@@ -1,255 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore>
-#include <QtWidgets>
-
-#define NUM_ITEMS 100
-#define NUM_LISTS 10
-
-/*!
- \class RectObject
- Note that it needs to be a QGraphicsObject or else the gestures will not work correctly.
-*/
-class RectObject : public QGraphicsObject
-{
- Q_OBJECT
-
-public:
-
- RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = nullptr)
- : QGraphicsObject(parent)
- , m_text(text)
- , m_rect(x, y, width, height)
- , m_pen(brush.color().lighter(), 3.0)
- , m_brush(brush)
- {
- setFlag(QGraphicsItem::ItemClipsToShape, true);
- }
-
- QRectF boundingRect() const 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;
- QRectF rect = m_rect;
- if (halfpw > 0.0)
- rect.adjust(-halfpw, -halfpw, halfpw, halfpw);
-
- return rect;
- }
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
- {
- Q_UNUSED(option);
- Q_UNUSED(widget);
- painter->setPen(m_pen);
- painter->setBrush(m_brush);
- painter->drawRect(m_rect);
-
- painter->setPen(Qt::black);
- QFont f;
- f.setPixelSize(m_rect.height());
- painter->setFont(f);
- painter->drawText(m_rect, Qt::AlignCenter, m_text);
- }
-
- QString m_text;
- QRectF m_rect;
- QPen m_pen;
- QBrush m_brush;
-};
-
-class ViewObject : public QGraphicsObject
-{
- Q_OBJECT
-public:
- ViewObject(QGraphicsObject *parent)
- : QGraphicsObject(parent)
- { }
-
- QRectF boundingRect() const override
- {
- QRectF rect;
- const auto items = childItems();
- for (const QGraphicsItem *item : items)
- rect |= item->boundingRect().translated(item->pos());
- return rect;
- }
-
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
- { }
-};
-
-class ListObject : public QGraphicsObject
-{
- Q_OBJECT
-
-public:
- ListObject(const QSizeF &size, bool useTouch)
- {
- m_size = size;
- setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
- // grab gesture via Touch or Mouse events
- QScroller::grabGesture(this, useTouch ? QScroller::TouchGesture : QScroller::LeftMouseButtonGesture);
-
- // this needs to be QGraphicsOBJECT - otherwise gesture recognition
- // will not work for the parent of the viewport (in this case the
- // list)
- m_viewport = new ViewObject(this);
-
- }
-
- QGraphicsObject *viewport() const
- {
- return m_viewport;
- }
-
- bool event(QEvent *e) override
- {
- switch (e->type()) {
-// ![2]
- case QEvent::ScrollPrepare: {
- QScrollPrepareEvent *se = static_cast<QScrollPrepareEvent *>(e);
- se->setViewportSize(m_size);
- QRectF br = m_viewport->boundingRect();
- se->setContentPosRange(QRectF(0, 0,
- qMax(qreal(0), br.width() - m_size.width()),
- qMax(qreal(0), br.height() - m_size.height())));
- se->setContentPos(-m_viewport->pos());
- se->accept();
- return true;
- }
-// ![1]
-// ![2]
- case QEvent::Scroll: {
- QScrollEvent *se = static_cast<QScrollEvent *>(e);
- m_viewport->setPos(-se->contentPos() - se->overshootDistance());
- return true;
- }
-// ![2]
- default:
- break;
- }
- return QGraphicsObject::event(e);
- }
-
- bool sceneEvent(QEvent *e) override
- {
- switch (e->type()) {
- case QEvent::TouchBegin: {
- // We need to return true for the TouchBegin here in the
- // top-most graphics object - otherwise gestures in our parent
- // objects will NOT work at all (the accept() flag is already
- // set due to our setAcceptTouchEvents(true) call in the c'tor
- return true;
-
- }
- case QEvent::GraphicsSceneMousePress: {
- // We need to return true for the MousePress here in the
- // top-most graphics object - otherwise gestures in our parent
- // objects will NOT work at all (the accept() flag is already
- // set to true by Qt)
- return true;
-
- }
- default:
- break;
- }
- return QGraphicsObject::sceneEvent(e);
- }
-
- QRectF boundingRect() const override
- {
- return QRectF(0, 0, m_size.width() + 3, m_size.height());
- }
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
- {
- Q_UNUSED(option);
- Q_UNUSED(widget);
- painter->setPen(QPen(QColor(100, 100, 100), 3.0));
- painter->drawRect(QRectF(1.5, 1.5, m_size.width() - 3, m_size.height() - 3));
- }
-
- QSizeF m_size;
- ViewObject *m_viewport;
-};
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow(bool useTouch)
- {
- m_scene = new QGraphicsScene();
-
- // -- make the main list
- ListObject *mainList = new ListObject(QSizeF(780, 400), useTouch);
- mainList->setObjectName(QLatin1String("MainList"));
- m_scene->addItem(mainList);
-// ![3]
- for (int i=0; i<NUM_LISTS; i++) {
- ListObject *childList = new ListObject(QSizeF(mainList->m_size.width()/3, mainList->m_size.height()), useTouch);
- childList->setObjectName(QString("ChildList %1").arg(i));
- fillList(childList);
- childList->setParentItem(mainList->viewport());
- childList->setPos(i*mainList->m_size.width()/3, 0);
- }
- mainList->viewport()->setPos(0, 0);
-
-
- /*
- list1->setTransformOriginPoint(200, 200);
- list1->setRotation(135);
- list1->setPos(20 + 200 * .41, 20 + 200 * .41);
- */
-// ![3]
-
- m_view = new QGraphicsView(m_scene);
- setCentralWidget(m_view);
- setWindowTitle(tr("Gesture example"));
- m_scene->setSceneRect(0, 0, m_view->viewport()->width(), m_view->viewport()->height());
- }
-
- /**
- * Fills the list object \a list with RectObjects.
- */
- void fillList(ListObject *list)
- {
- qreal h = list->m_size.height() / 10;
- for (int i=0; i<NUM_ITEMS; i++) {
- QColor color = QColor(255*i/NUM_ITEMS, 255*(NUM_ITEMS-i)/NUM_ITEMS, 127*(i%2)+64*(i/2%2));
- QString text = QLatin1String("Item #") + QString::number(i);
- QGraphicsItem *rect = new RectObject(text, 0, 0, list->m_size.width() - 6, h - 3, QBrush(color), list->viewport());
- rect->setPos(3, h*i+3);
- }
- list->viewport()->setPos(0, 0);
- }
-
-
-protected:
- void resizeEvent(QResizeEvent *e) 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());
- QMainWindow::resizeEvent(e);
- }
-
- QGraphicsScene *m_scene;
- QGraphicsView *m_view;
-};
-
-int main(int argc, char *argv[])
-{
- QApplication a(argc, argv);
- bool touch = (a.arguments().contains(QLatin1String("--touch")));
- MainWindow mw(touch);
- mw.show();
-#ifdef Q_OS_MAC
- mw.raise();
-#endif
- return a.exec();
-}
-
-#include "main.moc"
diff --git a/examples/widgets/scroller/scroller.pro b/examples/widgets/scroller/scroller.pro
deleted file mode 100644
index bac3f26554..0000000000
--- a/examples/widgets/scroller/scroller.pro
+++ /dev/null
@@ -1,2 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS += graphicsview
diff --git a/examples/widgets/tools/CMakeLists.txt b/examples/widgets/tools/CMakeLists.txt
index edf951fe18..a5ec5c4a3e 100644
--- a/examples/widgets/tools/CMakeLists.txt
+++ b/examples/widgets/tools/CMakeLists.txt
@@ -1,18 +1,8 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(completer)
qt_internal_add_example(customcompleter)
qt_internal_add_example(regularexpression)
-qt_internal_add_example(settingseditor)
-qt_internal_add_example(styleplugin)
qt_internal_add_example(treemodelcompleter)
qt_internal_add_example(undoframework)
-
-if(QT_FEATURE_library)
- qt_internal_add_example(echoplugin)
-
- if(QT_FEATURE_inputdialog)
- qt_internal_add_example(plugandpaint)
- endif()
-endif()
diff --git a/examples/widgets/tools/completer/CMakeLists.txt b/examples/widgets/tools/completer/CMakeLists.txt
index 0af779388f..a4ad8055b9 100644
--- a/examples/widgets/tools/completer/CMakeLists.txt
+++ b/examples/widgets/tools/completer/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(completer LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/completer")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -45,7 +39,14 @@ qt_add_resources(completer "completer"
)
install(TARGETS completer
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET completer
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tools/completer/main.cpp b/examples/widgets/tools/completer/main.cpp
index 4ea6bc1ac9..060dfe5bd8 100644
--- a/examples/widgets/tools/completer/main.cpp
+++ b/examples/widgets/tools/completer/main.cpp
@@ -7,8 +7,6 @@
//! [0]
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(completer);
-
QApplication app(argc, argv);
MainWindow window;
window.show();
diff --git a/examples/widgets/tools/customcompleter/CMakeLists.txt b/examples/widgets/tools/customcompleter/CMakeLists.txt
index 9e1ee1222a..8340f2cfdf 100644
--- a/examples/widgets/tools/customcompleter/CMakeLists.txt
+++ b/examples/widgets/tools/customcompleter/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(customcompleter LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/customcompleter")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -44,7 +38,14 @@ qt_add_resources(customcompleter "customcompleter"
)
install(TARGETS customcompleter
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET customcompleter
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tools/customcompleter/main.cpp b/examples/widgets/tools/customcompleter/main.cpp
index 13e8544b90..060dfe5bd8 100644
--- a/examples/widgets/tools/customcompleter/main.cpp
+++ b/examples/widgets/tools/customcompleter/main.cpp
@@ -7,8 +7,6 @@
//! [0]
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(customcompleter);
-
QApplication app(argc, argv);
MainWindow window;
window.show();
diff --git a/examples/widgets/tools/echoplugin/CMakeLists.txt b/examples/widgets/tools/echoplugin/CMakeLists.txt
deleted file mode 100644
index cfe76f4a73..0000000000
--- a/examples/widgets/tools/echoplugin/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(plugandpaint LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/echoplugin")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-add_subdirectory(plugin)
-add_subdirectory(echowindow)
diff --git a/examples/widgets/tools/echoplugin/echoplugin.pro b/examples/widgets/tools/echoplugin/echoplugin.pro
deleted file mode 100644
index 1e3d625b2f..0000000000
--- a/examples/widgets/tools/echoplugin/echoplugin.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-#! [0]
-TEMPLATE = subdirs
-SUBDIRS = echowindow \
- plugin
-#! [0]
diff --git a/examples/widgets/tools/echoplugin/echowindow/CMakeLists.txt b/examples/widgets/tools/echoplugin/echowindow/CMakeLists.txt
deleted file mode 100644
index a362604018..0000000000
--- a/examples/widgets/tools/echoplugin/echowindow/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-qt_add_executable(echopluginwindow
- echointerface.h
- echowindow.cpp echowindow.h
- main.cpp
-)
-
-set_target_properties(echopluginwindow PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(echopluginwindow PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if(QT6_IS_SHARED_LIBS_BUILD)
- # Build the shared plugin too when building this example target.
- add_dependencies(echopluginwindow echoplugin)
-else()
- # Link the echoplugin if Qt is built statically.
- target_link_libraries(echopluginwindow PRIVATE
- echoplugin
- )
-endif()
-
-install(TARGETS echopluginwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/echoplugin/echowindow/echointerface.h b/examples/widgets/tools/echoplugin/echowindow/echointerface.h
deleted file mode 100644
index c36578fd21..0000000000
--- a/examples/widgets/tools/echoplugin/echowindow/echointerface.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef ECHOINTERFACE_H
-#define ECHOINTERFACE_H
-
-#include <QObject>
-#include <QString>
-
-//! [0]
-class EchoInterface
-{
-public:
- virtual ~EchoInterface() = default;
- virtual QString echo(const QString &message) = 0;
-};
-
-
-QT_BEGIN_NAMESPACE
-
-#define EchoInterface_iid "org.qt-project.Qt.Examples.EchoInterface"
-
-Q_DECLARE_INTERFACE(EchoInterface, EchoInterface_iid)
-QT_END_NAMESPACE
-
-//! [0]
-#endif
diff --git a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
deleted file mode 100644
index 718c412c33..0000000000
--- a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "echowindow.h"
-
-#include <QCoreApplication>
-#include <QDir>
-#include <QLabel>
-#include <QLayout>
-#include <QLineEdit>
-#include <QMessageBox>
-#include <QPluginLoader>
-#include <QPushButton>
-
-//! [0]
-EchoWindow::EchoWindow()
-{
- createGUI();
- setLayout(layout);
- setWindowTitle("Echo Plugin Example");
-
- if (!loadPlugin()) {
- QMessageBox::information(this, "Error", "Could not load the plugin");
- lineEdit->setEnabled(false);
- button->setEnabled(false);
- }
-}
-//! [0]
-
-//! [1]
-void EchoWindow::sendEcho()
-{
- QString text = echoInterface->echo(lineEdit->text());
- label->setText(text);
-}
-//! [1]
-
-//! [2]
-void EchoWindow::createGUI()
-{
- lineEdit = new QLineEdit;
- label = new QLabel;
- label->setFrameStyle(QFrame::Box | QFrame::Plain);
- button = new QPushButton(tr("Send Message"));
-
- connect(lineEdit, &QLineEdit::editingFinished,
- this, &EchoWindow::sendEcho);
- connect(button, &QPushButton::clicked,
- this, &EchoWindow::sendEcho);
-
- layout = new QGridLayout;
- layout->addWidget(new QLabel(tr("Message:")), 0, 0);
- layout->addWidget(lineEdit, 0, 1);
- layout->addWidget(new QLabel(tr("Answer:")), 1, 0);
- layout->addWidget(label, 1, 1);
- layout->addWidget(button, 2, 1, Qt::AlignRight);
- layout->setSizeConstraint(QLayout::SetFixedSize);
-}
-//! [2]
-
-//! [3]
-bool EchoWindow::loadPlugin()
-{
- QDir pluginsDir(QCoreApplication::applicationDirPath());
-#if defined(Q_OS_WIN)
- if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
- pluginsDir.cdUp();
-#elif defined(Q_OS_MAC)
- if (pluginsDir.dirName() == "MacOS") {
- pluginsDir.cdUp();
- pluginsDir.cdUp();
- pluginsDir.cdUp();
- }
-#endif
- pluginsDir.cd("plugins");
- const QStringList entries = pluginsDir.entryList(QDir::Files);
- for (const QString &fileName : entries) {
- QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
- QObject *plugin = pluginLoader.instance();
- if (plugin) {
- echoInterface = qobject_cast<EchoInterface *>(plugin);
- if (echoInterface)
- return true;
- pluginLoader.unload();
- }
- }
-
- return false;
-}
-//! [3]
diff --git a/examples/widgets/tools/echoplugin/echowindow/echowindow.h b/examples/widgets/tools/echoplugin/echowindow/echowindow.h
deleted file mode 100644
index 25d08162a9..0000000000
--- a/examples/widgets/tools/echoplugin/echowindow/echowindow.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef ECHODIALOG_H
-#define ECHODIALOG_H
-
-#include <QWidget>
-
-#include "echointerface.h"
-
-QT_BEGIN_NAMESPACE
-class QString;
-class QLineEdit;
-class QLabel;
-class QPushButton;
-class QGridLayout;
-QT_END_NAMESPACE
-
-//! [0]
-class EchoWindow : public QWidget
-{
- Q_OBJECT
-
-public:
- EchoWindow();
-
-private slots:
- void sendEcho();
-
-private:
- void createGUI();
- bool loadPlugin();
-
- EchoInterface *echoInterface;
- QLineEdit *lineEdit;
- QLabel *label;
- QPushButton *button;
- QGridLayout *layout;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/tools/echoplugin/echowindow/echowindow.pro b/examples/widgets/tools/echoplugin/echowindow/echowindow.pro
deleted file mode 100644
index 092258dd30..0000000000
--- a/examples/widgets/tools/echoplugin/echowindow/echowindow.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-QT += widgets
-
-HEADERS = echowindow.h \
- echointerface.h
-SOURCES = echowindow.cpp \
- main.cpp
-
-TARGET = echoplugin
-QMAKE_PROJECT_NAME = echopluginwindow
-win32 {
- CONFIG(debug, release|debug):DESTDIR = ../debug/
- CONFIG(release, release|debug):DESTDIR = ../release/
-} else {
- DESTDIR = ../
-}
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/echoplugin
-INSTALLS += target
-
-CONFIG += install_ok # Do not cargo-cult this!
diff --git a/examples/widgets/tools/echoplugin/echowindow/main.cpp b/examples/widgets/tools/echoplugin/echowindow/main.cpp
deleted file mode 100644
index c48af33773..0000000000
--- a/examples/widgets/tools/echoplugin/echowindow/main.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "echowindow.h"
-#include "echointerface.h"
-
-//! [0]
-int main(int argv, char *args[])
-{
- QApplication app(argv, args);
-
- EchoWindow window;
- window.show();
-
- return app.exec();
-}
-//! [0]
diff --git a/examples/widgets/tools/echoplugin/plugin/CMakeLists.txt b/examples/widgets/tools/echoplugin/plugin/CMakeLists.txt
deleted file mode 100644
index d691eb4735..0000000000
--- a/examples/widgets/tools/echoplugin/plugin/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-qt_add_plugin(echoplugin
- CLASS_NAME EchoPlugin
- echoplugin.cpp echoplugin.h
-)
-
-set_target_properties(echoplugin PROPERTIES
- LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/echowindow"
-)
-
-target_include_directories(echoplugin PRIVATE
- ../echowindow
-)
-
-target_link_libraries(echoplugin PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS echoplugin
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp b/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
deleted file mode 100644
index 55ccedb39e..0000000000
--- a/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "echoplugin.h"
-
-//! [0]
-QString EchoPlugin::echo(const QString &message)
-{
- return message;
-}
-//! [0]
diff --git a/examples/widgets/tools/echoplugin/plugin/echoplugin.h b/examples/widgets/tools/echoplugin/plugin/echoplugin.h
deleted file mode 100644
index 13e630da03..0000000000
--- a/examples/widgets/tools/echoplugin/plugin/echoplugin.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef ECHOPLUGIN_H
-#define ECHOPLUGIN_H
-
-#include <QObject>
-#include <QtPlugin>
-#include "echointerface.h"
-
-//! [0]
-class EchoPlugin : public QObject, EchoInterface
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.EchoInterface" FILE "echoplugin.json")
- Q_INTERFACES(EchoInterface)
-
-public:
- QString echo(const QString &message) override;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/tools/echoplugin/plugin/echoplugin.json b/examples/widgets/tools/echoplugin/plugin/echoplugin.json
deleted file mode 100644
index 0967ef424b..0000000000
--- a/examples/widgets/tools/echoplugin/plugin/echoplugin.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/examples/widgets/tools/echoplugin/plugin/plugin.pro b/examples/widgets/tools/echoplugin/plugin/plugin.pro
deleted file mode 100644
index a4b54b18f6..0000000000
--- a/examples/widgets/tools/echoplugin/plugin/plugin.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-#! [0]
-TEMPLATE = lib
-CONFIG += plugin
-QT += widgets
-INCLUDEPATH += ../echowindow
-HEADERS = echoplugin.h
-SOURCES = echoplugin.cpp
-TARGET = $$qtLibraryTarget(echoplugin)
-DESTDIR = ../plugins
-#! [0]
-
-EXAMPLE_FILES = echoplugin.json
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/echoplugin/plugins
-INSTALLS += target
-
-CONFIG += install_ok # Do not cargo-cult this!
diff --git a/examples/widgets/tools/plugandpaint/CMakeLists.txt b/examples/widgets/tools/plugandpaint/CMakeLists.txt
deleted file mode 100644
index 61b7ad728e..0000000000
--- a/examples/widgets/tools/plugandpaint/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(plugandpaint LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/plugandpaint")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-add_subdirectory(plugins)
-add_subdirectory(app)
diff --git a/examples/widgets/tools/plugandpaint/app/CMakeLists.txt b/examples/widgets/tools/plugandpaint/app/CMakeLists.txt
deleted file mode 100644
index c0368e7ba2..0000000000
--- a/examples/widgets/tools/plugandpaint/app/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-qt_add_executable(plugandpaint
- interfaces.h
- main.cpp
- mainwindow.cpp mainwindow.h
- paintarea.cpp paintarea.h
- plugindialog.cpp plugindialog.h
-)
-
-set_target_properties(plugandpaint PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(plugandpaint PRIVATE
- Qt6::Widgets
- pnp_basictools
-)
-
-if(QT6_IS_SHARED_LIBS_BUILD)
- # Build the shared plugin too when building this example target.
- add_dependencies(plugandpaint pnp_extrafilters)
-else()
- # Link the extrafilters plugin if Qt is built statically.
- target_link_libraries(plugandpaint PRIVATE
- pnp_extrafilters
- )
-endif()
-
-install(TARGETS plugandpaint
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/plugandpaint/app/app.pro b/examples/widgets/tools/plugandpaint/app/app.pro
deleted file mode 100644
index e5ff02ecf2..0000000000
--- a/examples/widgets/tools/plugandpaint/app/app.pro
+++ /dev/null
@@ -1,37 +0,0 @@
-#! [0]
-TARGET = plugandpaint
-DESTDIR = ..
-
-QT += widgets
-
-HEADERS = interfaces.h \
- mainwindow.h \
- paintarea.h \
- plugindialog.h
-SOURCES = main.cpp \
- mainwindow.cpp \
- paintarea.cpp \
- plugindialog.cpp
-
-LIBS = -L../plugins
-
-macx-xcode {
- LIBS += -lpnp_basictools$($${QMAKE_XCODE_LIBRARY_SUFFIX_SETTING})
-} else {
- android {
- LIBS += -lpnp_basictools_$${QT_ARCH}
- } else {
- LIBS += -lpnp_basictools
- }
- if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
- mac:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)_debug
- win32:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)d
- }
-}
-#! [0]
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/plugandpaint
-INSTALLS += target
-
-CONFIG += install_ok # Do not cargo-cult this!
diff --git a/examples/widgets/tools/plugandpaint/app/interfaces.h b/examples/widgets/tools/plugandpaint/app/interfaces.h
deleted file mode 100644
index 9cd0e34fda..0000000000
--- a/examples/widgets/tools/plugandpaint/app/interfaces.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef INTERFACES_H
-#define INTERFACES_H
-
-#include <QtPlugin>
-
-QT_BEGIN_NAMESPACE
-class QImage;
-class QPainter;
-class QWidget;
-class QPainterPath;
-class QPoint;
-class QRect;
-class QString;
-QT_END_NAMESPACE
-
-//! [0]
-class BrushInterface
-{
-public:
- virtual ~BrushInterface() = default;
-
- virtual QStringList brushes() const = 0;
- virtual QRect mousePress(const QString &brush, QPainter &painter,
- const QPoint &pos) = 0;
- virtual QRect mouseMove(const QString &brush, QPainter &painter,
- const QPoint &oldPos, const QPoint &newPos) = 0;
- virtual QRect mouseRelease(const QString &brush, QPainter &painter,
- const QPoint &pos) = 0;
-};
-//! [0]
-
-//! [1]
-class ShapeInterface
-{
-public:
- virtual ~ShapeInterface() = default;
-
- virtual QStringList shapes() const = 0;
- virtual QPainterPath generateShape(const QString &shape,
- QWidget *parent) = 0;
-};
-//! [1]
-
-//! [2]
-class FilterInterface
-{
-public:
- virtual ~FilterInterface() = default;
-
- virtual QStringList filters() const = 0;
- virtual QImage filterImage(const QString &filter, const QImage &image,
- QWidget *parent) = 0;
-};
-//! [2]
-
-QT_BEGIN_NAMESPACE
-//! [3] //! [4]
-#define BrushInterface_iid "org.qt-project.Qt.Examples.PlugAndPaint.BrushInterface/1.0"
-
-Q_DECLARE_INTERFACE(BrushInterface, BrushInterface_iid)
-//! [3]
-
-#define ShapeInterface_iid "org.qt-project.Qt.Examples.PlugAndPaint.ShapeInterface/1.0"
-
-Q_DECLARE_INTERFACE(ShapeInterface, ShapeInterface_iid)
-//! [5]
-#define FilterInterface_iid "org.qt-project.Qt.Examples.PlugAndPaint.FilterInterface/1.0"
-
-Q_DECLARE_INTERFACE(FilterInterface, FilterInterface_iid)
-//! [4] //! [5]
-QT_END_NAMESPACE
-
-#endif
diff --git a/examples/widgets/tools/plugandpaint/app/main.cpp b/examples/widgets/tools/plugandpaint/app/main.cpp
deleted file mode 100644
index 3fc647dcca..0000000000
--- a/examples/widgets/tools/plugandpaint/app/main.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-//! [0]
-#include "mainwindow.h"
-
-#include <QApplication>
-#include <QtPlugin>
-
-Q_IMPORT_PLUGIN(BasicToolsPlugin)
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- return app.exec();
-}
-//! [0]
diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
deleted file mode 100644
index 8e58ae4ba8..0000000000
--- a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
+++ /dev/null
@@ -1,282 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-
-#include "mainwindow.h"
-#include "interfaces.h"
-#include "paintarea.h"
-#include "plugindialog.h"
-
-#include <QAction>
-#include <QActionGroup>
-#include <QApplication>
-#include <QColorDialog>
-#include <QFileDialog>
-#include <QInputDialog>
-#include <QMenu>
-#include <QMenuBar>
-#include <QMessageBox>
-#include <QPluginLoader>
-#include <QScrollArea>
-#include <QTimer>
-
-MainWindow::MainWindow() : paintArea(new PaintArea)
- , scrollArea(new QScrollArea)
-{
- scrollArea->setBackgroundRole(QPalette::Dark);
- scrollArea->setWidget(paintArea);
- setCentralWidget(scrollArea);
-
- createActions();
- createMenus();
- loadPlugins();
-
- setWindowTitle(tr("Plug & Paint"));
-
- if (!brushActionGroup->actions().isEmpty())
- brushActionGroup->actions().first()->trigger();
-
- QTimer::singleShot(500, this, &MainWindow::aboutPlugins);
-}
-
-void MainWindow::open()
-{
- const QString fileName = QFileDialog::getOpenFileName(this,
- tr("Open File"),
- QDir::currentPath());
- if (!fileName.isEmpty()) {
- if (!paintArea->openImage(fileName)) {
- QMessageBox::information(this, tr("Plug & Paint"),
- tr("Cannot load %1.").arg(fileName));
- return;
- }
- paintArea->adjustSize();
- }
-}
-
-bool MainWindow::saveAs()
-{
- const QString initialPath = QDir::currentPath() + "/untitled.png";
-
- const QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
- initialPath);
- if (fileName.isEmpty())
- return false;
-
- return paintArea->saveImage(fileName, "png");
-}
-
-void MainWindow::brushColor()
-{
- const QColor newColor = QColorDialog::getColor(paintArea->brushColor());
- if (newColor.isValid())
- paintArea->setBrushColor(newColor);
-}
-
-void MainWindow::brushWidth()
-{
- bool ok;
- const int newWidth = QInputDialog::getInt(this, tr("Plug & Paint"),
- tr("Select brush width:"),
- paintArea->brushWidth(),
- 1, 50, 1, &ok);
- if (ok)
- paintArea->setBrushWidth(newWidth);
-}
-
-//! [0]
-void MainWindow::changeBrush()
-{
- auto action = qobject_cast<QAction *>(sender());
- if (!action)
- return;
- auto iBrush = qobject_cast<BrushInterface *>(action->parent());
- if (!iBrush)
- return;
- const QString brush = action->text();
-
- paintArea->setBrush(iBrush, brush);
-}
-//! [0]
-
-//! [1]
-void MainWindow::insertShape()
-{
- auto action = qobject_cast<QAction *>(sender());
- if (!action)
- return;
- auto iShape = qobject_cast<ShapeInterface *>(action->parent());
- if (!iShape)
- return;
-
- const QPainterPath path = iShape->generateShape(action->text(), this);
- if (!path.isEmpty())
- paintArea->insertShape(path);
-}
-//! [1]
-
-//! [2]
-void MainWindow::applyFilter()
-{
- auto action = qobject_cast<QAction *>(sender());
- if (!action)
- return;
- auto iFilter = qobject_cast<FilterInterface *>(action->parent());
- if (!iFilter)
- return;
-
- const QImage image = iFilter->filterImage(action->text(), paintArea->image(),
- this);
- paintArea->setImage(image);
-}
-//! [2]
-
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About Plug & Paint"),
- tr("The <b>Plug & Paint</b> example demonstrates how to write Qt "
- "applications that can be extended through plugins."));
-}
-
-//! [3]
-void MainWindow::aboutPlugins()
-{
- PluginDialog dialog(pluginsDir.path(), pluginFileNames, this);
- dialog.exec();
-}
-//! [3]
-
-void MainWindow::createActions()
-{
- openAct = new QAction(tr("&Open..."), this);
- openAct->setShortcuts(QKeySequence::Open);
- connect(openAct, &QAction::triggered, this, &MainWindow::open);
-
- saveAsAct = new QAction(tr("&Save As..."), this);
- saveAsAct->setShortcuts(QKeySequence::SaveAs);
- connect(saveAsAct, &QAction::triggered, this, &MainWindow::saveAs);
-
- exitAct = new QAction(tr("E&xit"), this);
- exitAct->setShortcuts(QKeySequence::Quit);
- connect(exitAct, &QAction::triggered, this, &MainWindow::close);
-
- brushColorAct = new QAction(tr("&Brush Color..."), this);
- connect(brushColorAct, &QAction::triggered, this, &MainWindow::brushColor);
-
- brushWidthAct = new QAction(tr("&Brush Width..."), this);
- connect(brushWidthAct, &QAction::triggered, this, &MainWindow::brushWidth);
-
- brushActionGroup = new QActionGroup(this);
-
- aboutAct = new QAction(tr("&About"), this);
- connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
-
- aboutQtAct = new QAction(tr("About &Qt"), this);
- connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
-
- aboutPluginsAct = new QAction(tr("About &Plugins"), this);
- connect(aboutPluginsAct, &QAction::triggered, this, &MainWindow::aboutPlugins);
-}
-
-void MainWindow::createMenus()
-{
- fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(openAct);
- fileMenu->addAction(saveAsAct);
- fileMenu->addSeparator();
- fileMenu->addAction(exitAct);
-
- brushMenu = menuBar()->addMenu(tr("&Brush"));
- brushMenu->addAction(brushColorAct);
- brushMenu->addAction(brushWidthAct);
- brushMenu->addSeparator();
-
- shapesMenu = menuBar()->addMenu(tr("&Shapes"));
-
- filterMenu = menuBar()->addMenu(tr("&Filter"));
-
- menuBar()->addSeparator();
-
- helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(aboutAct);
- helpMenu->addAction(aboutQtAct);
- helpMenu->addAction(aboutPluginsAct);
-}
-
-//! [4]
-void MainWindow::loadPlugins()
-{
- const auto staticInstances = QPluginLoader::staticInstances();
- for (QObject *plugin : staticInstances)
- populateMenus(plugin);
-//! [4] //! [5]
-
- pluginsDir = QDir(QCoreApplication::applicationDirPath());
-
-#if defined(Q_OS_WIN)
- if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
- pluginsDir.cdUp();
-#elif defined(Q_OS_MAC)
- if (pluginsDir.dirName() == "MacOS") {
- pluginsDir.cdUp();
- pluginsDir.cdUp();
- pluginsDir.cdUp();
- }
-#endif
- pluginsDir.cd("plugins");
-//! [5]
-
-//! [6]
- const auto entryList = pluginsDir.entryList(QDir::Files);
- for (const QString &fileName : entryList) {
- QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
- QObject *plugin = loader.instance();
- if (plugin) {
- populateMenus(plugin);
- pluginFileNames += fileName;
-//! [6] //! [7]
- }
-//! [7] //! [8]
- }
-//! [8]
-
-//! [9]
- brushMenu->setEnabled(!brushActionGroup->actions().isEmpty());
- shapesMenu->setEnabled(!shapesMenu->actions().isEmpty());
- filterMenu->setEnabled(!filterMenu->actions().isEmpty());
-}
-//! [9]
-
-//! [10]
-void MainWindow::populateMenus(QObject *plugin)
-{
- auto iBrush = qobject_cast<BrushInterface *>(plugin);
- if (iBrush)
- addToMenu(plugin, iBrush->brushes(), brushMenu, &MainWindow::changeBrush,
- brushActionGroup);
-
- auto iShape = qobject_cast<ShapeInterface *>(plugin);
- if (iShape)
- addToMenu(plugin, iShape->shapes(), shapesMenu, &MainWindow::insertShape);
-
- auto iFilter = qobject_cast<FilterInterface *>(plugin);
- if (iFilter)
- addToMenu(plugin, iFilter->filters(), filterMenu, &MainWindow::applyFilter);
-}
-//! [10]
-
-void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
- QMenu *menu, Member member,
- QActionGroup *actionGroup)
-{
- for (const QString &text : texts) {
- auto action = new QAction(text, plugin);
- connect(action, &QAction::triggered, this, member);
- menu->addAction(action);
-
- if (actionGroup) {
- action->setCheckable(true);
- actionGroup->addAction(action);
- }
- }
-}
diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.h b/examples/widgets/tools/plugandpaint/app/mainwindow.h
deleted file mode 100644
index bc09471ba5..0000000000
--- a/examples/widgets/tools/plugandpaint/app/mainwindow.h
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QDir>
-#include <QMainWindow>
-#include <QStringList>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QActionGroup;
-class QMenu;
-class QScrollArea;
-QT_END_NAMESPACE
-class PaintArea;
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
-private slots:
- void open();
- bool saveAs();
- void brushColor();
- void brushWidth();
- void changeBrush();
- void insertShape();
- void applyFilter();
- void about();
- void aboutPlugins();
-
-private:
- typedef void (MainWindow::*Member)();
-
- void createActions();
- void createMenus();
- void loadPlugins();
- void populateMenus(QObject *plugin);
- void addToMenu(QObject *plugin, const QStringList &texts, QMenu *menu,
- Member member, QActionGroup *actionGroup = nullptr);
-
- PaintArea *paintArea = nullptr;
- QScrollArea *scrollArea = nullptr;
- QDir pluginsDir;
- QStringList pluginFileNames;
-
- QMenu *fileMenu = nullptr;
- QMenu *brushMenu = nullptr;
- QMenu *shapesMenu = nullptr;
- QMenu *filterMenu = nullptr;
- QMenu *helpMenu = nullptr;
- QActionGroup *brushActionGroup = nullptr;
- QAction *openAct = nullptr;
- QAction *saveAsAct = nullptr;
- QAction *exitAct = nullptr;
- QAction *brushWidthAct = nullptr;
- QAction *brushColorAct = nullptr;
- QAction *aboutAct = nullptr;
- QAction *aboutQtAct = nullptr;
- QAction *aboutPluginsAct = nullptr;
-};
-
-#endif
diff --git a/examples/widgets/tools/plugandpaint/app/paintarea.cpp b/examples/widgets/tools/plugandpaint/app/paintarea.cpp
deleted file mode 100644
index 3596f7979c..0000000000
--- a/examples/widgets/tools/plugandpaint/app/paintarea.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-
-#include "paintarea.h"
-#include "interfaces.h"
-
-#include <QMouseEvent>
-#include <QPainter>
-
-PaintArea::PaintArea(QWidget *parent) : QWidget(parent)
-{
- setAttribute(Qt::WA_StaticContents);
- setAttribute(Qt::WA_OpaquePaintEvent);
-
- theImage.fill(qRgb(255, 255, 255));
-}
-
-bool PaintArea::openImage(const QString &fileName)
-{
- QImage image;
- if (!image.load(fileName))
- return false;
-
- setImage(image);
- return true;
-}
-
-bool PaintArea::saveImage(const QString &fileName, const char *fileFormat)
-{
- return theImage.save(fileName, fileFormat);
-}
-
-void PaintArea::setImage(const QImage &image)
-{
- theImage = image.convertToFormat(QImage::Format_RGB32);
- update();
- updateGeometry();
-}
-
-void PaintArea::insertShape(const QPainterPath &path)
-{
- pendingPath = path;
-#ifndef QT_NO_CURSOR
- setCursor(Qt::CrossCursor);
-#endif
-}
-
-void PaintArea::setBrushColor(const QColor &color)
-{
- this->color = color;
-}
-
-void PaintArea::setBrushWidth(int width)
-{
- thickness = width;
-}
-
-//! [0]
-void PaintArea::setBrush(BrushInterface *brushInterface, const QString &brush)
-{
- this->brushInterface = brushInterface;
- this->brush = brush;
-}
-//! [0]
-
-QSize PaintArea::sizeHint() const
-{
- return theImage.size();
-}
-
-void PaintArea::paintEvent(QPaintEvent * /* event */)
-{
- QPainter painter(this);
- painter.drawImage(QPoint(0, 0), theImage);
-}
-
-void PaintArea::mousePressEvent(QMouseEvent *event)
-{
- if (event->button() == Qt::LeftButton) {
- if (!pendingPath.isEmpty()) {
- QPainter painter(&theImage);
- setupPainter(painter);
-
- const QRectF boundingRect = pendingPath.boundingRect();
- QLinearGradient gradient(boundingRect.topRight(),
- boundingRect.bottomLeft());
- gradient.setColorAt(0.0, QColor(color.red(), color.green(),
- color.blue(), 63));
- gradient.setColorAt(1.0, QColor(color.red(), color.green(),
- color.blue(), 191));
- painter.setBrush(gradient);
- painter.translate(event->position().toPoint() - boundingRect.center());
- painter.drawPath(pendingPath);
-
- pendingPath = QPainterPath();
-#ifndef QT_NO_CURSOR
- unsetCursor();
-#endif
- update();
- } else {
- if (brushInterface) {
- QPainter painter(&theImage);
- setupPainter(painter);
- const QRect rect = brushInterface->mousePress(brush, painter,
- event->position().toPoint());
- update(rect);
- }
-
- lastPos = event->position().toPoint();
- }
- }
-}
-
-//! [1]
-void PaintArea::mouseMoveEvent(QMouseEvent *event)
-{
- if ((event->buttons() & Qt::LeftButton) && lastPos != QPoint(-1, -1)) {
- if (brushInterface) {
- QPainter painter(&theImage);
- setupPainter(painter);
- const QRect rect = brushInterface->mouseMove(brush, painter, lastPos,
- event->position().toPoint());
- update(rect);
- }
-
- lastPos = event->position().toPoint();
- }
-}
-//! [1]
-
-void PaintArea::mouseReleaseEvent(QMouseEvent *event)
-{
- if (event->button() == Qt::LeftButton && lastPos != QPoint(-1, -1)) {
- if (brushInterface) {
- QPainter painter(&theImage);
- setupPainter(painter);
- QRect rect = brushInterface->mouseRelease(brush, painter,
- event->position().toPoint());
- update(rect);
- }
-
- lastPos = QPoint(-1, -1);
- }
-}
-
-void PaintArea::setupPainter(QPainter &painter)
-{
- painter.setRenderHint(QPainter::Antialiasing, true);
- painter.setPen(QPen(color, thickness, Qt::SolidLine, Qt::RoundCap,
- Qt::RoundJoin));
-}
diff --git a/examples/widgets/tools/plugandpaint/app/paintarea.h b/examples/widgets/tools/plugandpaint/app/paintarea.h
deleted file mode 100644
index f24db0ba89..0000000000
--- a/examples/widgets/tools/plugandpaint/app/paintarea.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PAINTAREA_H
-#define PAINTAREA_H
-
-#include <QColor>
-#include <QImage>
-#include <QPainterPath>
-#include <QWidget>
-
-class BrushInterface;
-
-class PaintArea : public QWidget
-{
- Q_OBJECT
-
-public:
- PaintArea(QWidget *parent = nullptr);
-
- bool openImage(const QString &fileName);
- bool saveImage(const QString &fileName, const char *fileFormat);
- void setImage(const QImage &image);
- void insertShape(const QPainterPath &path);
- void setBrushColor(const QColor &color);
- void setBrushWidth(int width);
- void setBrush(BrushInterface *brushInterface, const QString &brush);
-
- QImage image() const { return theImage; }
- QColor brushColor() const { return color; }
- int brushWidth() const { return thickness; }
- QSize sizeHint() const override;
-
-protected:
- void paintEvent(QPaintEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
-
-private:
- void setupPainter(QPainter &painter);
-
- QImage theImage = {500, 400, QImage::Format_RGB32};
- QColor color = Qt::blue;
- int thickness = 3;
-
- BrushInterface *brushInterface = nullptr;
- QString brush;
- QPoint lastPos = {-1, -1};
-
- QPainterPath pendingPath;
-};
-
-#endif
diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
deleted file mode 100644
index 2ff5c4b1e3..0000000000
--- a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-
-#include "plugindialog.h"
-#include "interfaces.h"
-
-#include <QDir>
-#include <QGridLayout>
-#include <QHeaderView>
-#include <QLabel>
-#include <QPluginLoader>
-#include <QPushButton>
-#include <QStringList>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-
-PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames,
- QWidget *parent) :
- QDialog(parent),
- label(new QLabel),
- treeWidget(new QTreeWidget),
- okButton(new QPushButton(tr("OK")))
-{
- treeWidget->setAlternatingRowColors(false);
- treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
- treeWidget->setColumnCount(1);
- treeWidget->header()->hide();
-
- okButton->setDefault(true);
-
- connect(okButton, &QAbstractButton::clicked, this, &QWidget::close);
-
- QGridLayout *mainLayout = new QGridLayout;
- mainLayout->setColumnStretch(0, 1);
- mainLayout->setColumnStretch(2, 1);
- mainLayout->addWidget(label, 0, 0, 1, 3);
- mainLayout->addWidget(treeWidget, 1, 0, 1, 3);
- mainLayout->addWidget(okButton, 2, 1);
- setLayout(mainLayout);
-
- interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
- QIcon::Normal, QIcon::On);
- interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
- QIcon::Normal, QIcon::Off);
- featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
-
- setWindowTitle(tr("Plugin Information"));
- findPlugins(path, fileNames);
-}
-
-//! [0]
-void PluginDialog::findPlugins(const QString &path,
- const QStringList &fileNames)
-{
- label->setText(tr("Plug & Paint found the following plugins\n"
- "(looked in %1):")
- .arg(QDir::toNativeSeparators(path)));
-
- const QDir dir(path);
-
- const auto staticInstances = QPluginLoader::staticInstances();
- for (QObject *plugin : staticInstances)
- populateTreeWidget(plugin, tr("%1 (Static Plugin)")
- .arg(plugin->metaObject()->className()));
-
- for (const QString &fileName : fileNames) {
- QPluginLoader loader(dir.absoluteFilePath(fileName));
- QObject *plugin = loader.instance();
- if (plugin)
- populateTreeWidget(plugin, fileName);
- }
-}
-//! [0]
-
-//! [1]
-void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text)
-{
- auto pluginItem = new QTreeWidgetItem(treeWidget);
- pluginItem->setText(0, text);
- pluginItem->setExpanded(true);
-
- QFont boldFont = pluginItem->font(0);
- boldFont.setBold(true);
- pluginItem->setFont(0, boldFont);
-
- if (plugin) {
- auto iBrush = qobject_cast<BrushInterface *>(plugin);
- if (iBrush)
- addItems(pluginItem, "BrushInterface", iBrush->brushes());
-
- auto iShape = qobject_cast<ShapeInterface *>(plugin);
- if (iShape)
- addItems(pluginItem, "ShapeInterface", iShape->shapes());
-
- auto iFilter = qobject_cast<FilterInterface *>(plugin);
- if (iFilter)
- addItems(pluginItem, "FilterInterface", iFilter->filters());
- }
-}
-//! [1]
-
-void PluginDialog::addItems(QTreeWidgetItem *pluginItem,
- const char *interfaceName,
- const QStringList &features)
-{
- auto interfaceItem = new QTreeWidgetItem(pluginItem);
- interfaceItem->setText(0, interfaceName);
- interfaceItem->setIcon(0, interfaceIcon);
-
- for (QString feature : features) {
- if (feature.endsWith("..."))
- feature.chop(3);
- auto featureItem = new QTreeWidgetItem(interfaceItem);
- featureItem->setText(0, feature);
- featureItem->setIcon(0, featureIcon);
- }
-}
diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.h b/examples/widgets/tools/plugandpaint/app/plugindialog.h
deleted file mode 100644
index 32b8aa6fe0..0000000000
--- a/examples/widgets/tools/plugandpaint/app/plugindialog.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PLUGINDIALOG_H
-#define PLUGINDIALOG_H
-
-#include <QDialog>
-#include <QIcon>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QPushButton;
-class QTreeWidget;
-class QTreeWidgetItem;
-QT_END_NAMESPACE
-
-class PluginDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- PluginDialog(const QString &path, const QStringList &fileNames,
- QWidget *parent = nullptr);
-
-private:
- void findPlugins(const QString &path, const QStringList &fileNames);
- void populateTreeWidget(QObject *plugin, const QString &text);
- void addItems(QTreeWidgetItem *pluginItem, const char *interfaceName,
- const QStringList &features);
-
- QLabel *label = nullptr;
- QTreeWidget *treeWidget = nullptr;
- QPushButton *okButton = nullptr;
- QIcon interfaceIcon;
- QIcon featureIcon;
-};
-
-#endif
diff --git a/examples/widgets/tools/plugandpaint/plugandpaint.pro b/examples/widgets/tools/plugandpaint/plugandpaint.pro
deleted file mode 100644
index 58c4dbbb6e..0000000000
--- a/examples/widgets/tools/plugandpaint/plugandpaint.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-QT_FOR_CONFIG += widgets
-requires(qtConfig(inputdialog))
-
-TEMPLATE = subdirs
-SUBDIRS = plugins app
-
-app.depends = plugins
diff --git a/examples/widgets/tools/plugandpaint/plugins/CMakeLists.txt b/examples/widgets/tools/plugandpaint/plugins/CMakeLists.txt
deleted file mode 100644
index 9a2d66d99e..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-add_subdirectory(basictools)
-add_subdirectory(extrafilters)
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt b/examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt
deleted file mode 100644
index 86d58b9f08..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-qt_add_plugin(pnp_basictools
- STATIC
- CLASS_NAME BasicToolsPlugin
- basictoolsplugin.cpp basictoolsplugin.h
-)
-
-target_include_directories(pnp_basictools PRIVATE
- ../../app
-)
-
-target_link_libraries(pnp_basictools PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.json b/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.json
deleted file mode 100644
index 0967ef424b..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro b/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro
deleted file mode 100644
index f5ba95252c..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-#! [0]
-TEMPLATE = lib
-CONFIG += plugin static
-QT += widgets
-INCLUDEPATH += ../../app
-HEADERS = basictoolsplugin.h
-SOURCES = basictoolsplugin.cpp
-TARGET = $$qtLibraryTarget(pnp_basictools)
-DESTDIR = ../../plugins
-#! [0]
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/plugandpaint/plugins
-INSTALLS += target
-
-CONFIG += install_ok # Do not cargo-cult this!
-uikit: CONFIG += debug_and_release
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
deleted file mode 100644
index 6a350f38a4..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "basictoolsplugin.h"
-
-#include <QInputDialog>
-#include <QPainter>
-#include <QRandomGenerator>
-#include <QtMath>
-
-//! [0]
-QStringList BasicToolsPlugin::brushes() const
-{
- return {tr("Pencil"), tr("Air Brush"), tr("Random Letters")};
-}
-//! [0]
-
-//! [1]
-QRect BasicToolsPlugin::mousePress(const QString &brush, QPainter &painter,
- const QPoint &pos)
-{
- return mouseMove(brush, painter, pos, pos);
-}
-//! [1]
-
-//! [2]
-QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
- const QPoint &oldPos, const QPoint &newPos)
-{
- painter.save();
-
- int rad = painter.pen().width() / 2;
- QRect boundingRect = QRect(oldPos, newPos).normalized()
- .adjusted(-rad, -rad, +rad, +rad);
- QColor color = painter.pen().color();
- int thickness = painter.pen().width();
- QColor transparentColor(color.red(), color.green(), color.blue(), 0);
-//! [2] //! [3]
-
- if (brush == tr("Pencil")) {
- painter.drawLine(oldPos, newPos);
- } else if (brush == tr("Air Brush")) {
- int numSteps = 2 + (newPos - oldPos).manhattanLength() / 2;
-
- painter.setBrush(QBrush(color, Qt::Dense6Pattern));
- painter.setPen(Qt::NoPen);
-
- for (int i = 0; i < numSteps; ++i) {
- int x = oldPos.x() + i * (newPos.x() - oldPos.x()) / (numSteps - 1);
- int y = oldPos.y() + i * (newPos.y() - oldPos.y()) / (numSteps - 1);
-
- painter.drawEllipse(x - (thickness / 2), y - (thickness / 2),
- thickness, thickness);
- }
- } else if (brush == tr("Random Letters")) {
- QChar ch(QRandomGenerator::global()->bounded('A', 'Z' + 1));
-
- QFont biggerFont = painter.font();
- biggerFont.setBold(true);
- biggerFont.setPointSize(biggerFont.pointSize() + thickness);
- painter.setFont(biggerFont);
-
- painter.drawText(newPos, QString(ch));
-
- QFontMetrics metrics(painter.font());
- boundingRect = metrics.boundingRect(ch);
- boundingRect.translate(newPos);
- boundingRect.adjust(-10, -10, +10, +10);
- }
- painter.restore();
- return boundingRect;
-}
-//! [3]
-
-//! [4]
-QRect BasicToolsPlugin::mouseRelease(const QString & /* brush */,
- QPainter & /* painter */,
- const QPoint & /* pos */)
-{
- return QRect(0, 0, 0, 0);
-}
-//! [4]
-
-//! [5]
-QStringList BasicToolsPlugin::shapes() const
-{
- return {tr("Circle"), tr("Star"), tr("Text...")};
-}
-//! [5]
-
-//! [6]
-QPainterPath BasicToolsPlugin::generateShape(const QString &shape,
- QWidget *parent)
-{
- QPainterPath path;
-
- if (shape == tr("Circle")) {
- path.addEllipse(0, 0, 50, 50);
- } else if (shape == tr("Star")) {
- path.moveTo(90, 50);
- for (int i = 1; i < 5; ++i) {
- path.lineTo(50 + 40 * std::cos(0.8 * i * M_PI),
- 50 + 40 * std::sin(0.8 * i * M_PI));
- }
- path.closeSubpath();
- } else if (shape == tr("Text...")) {
- QString text = QInputDialog::getText(parent, tr("Text Shape"),
- tr("Enter text:"),
- QLineEdit::Normal, tr("Qt"));
- if (!text.isEmpty()) {
- QFont timesFont("Times", 50);
- timesFont.setStyleStrategy(QFont::ForceOutline);
- path.addText(0, 0, timesFont, text);
- }
- }
-
- return path;
-}
-//! [6]
-
-//! [7]
-QStringList BasicToolsPlugin::filters() const
-{
- return {tr("Invert Pixels"), tr("Swap RGB"), tr("Grayscale")};
-}
-//! [7]
-
-//! [8]
-QImage BasicToolsPlugin::filterImage(const QString &filter, const QImage &image,
- QWidget * /* parent */)
-{
- QImage result = image.convertToFormat(QImage::Format_RGB32);
-
- if (filter == tr("Invert Pixels")) {
- result.invertPixels();
- } else if (filter == tr("Swap RGB")) {
- result = result.rgbSwapped();
- } else if (filter == tr("Grayscale")) {
- for (int y = 0; y < result.height(); ++y) {
- for (int x = 0; x < result.width(); ++x) {
- QRgb pixel = result.pixel(x, y);
- int gray = qGray(pixel);
- int alpha = qAlpha(pixel);
- result.setPixel(x, y, qRgba(gray, gray, gray, alpha));
- }
- }
- }
- return result;
-}
-//! [8]
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
deleted file mode 100644
index 9fb3295bf5..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BASICTOOLSPLUGIN_H
-#define BASICTOOLSPLUGIN_H
-
-//! [0]
-#include <interfaces.h>
-
-#include <QImage>
-#include <QObject>
-#include <QPainterPath>
-#include <QRect>
-#include <QStringList>
-#include <QtPlugin>
-
-//! [1]
-class BasicToolsPlugin : public QObject,
- public BrushInterface,
- public ShapeInterface,
- public FilterInterface
-{
- Q_OBJECT
-//! [4]
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.PlugAndPaint.BrushInterface" FILE "basictools.json")
-//! [4]
- Q_INTERFACES(BrushInterface ShapeInterface FilterInterface)
-//! [0]
-
-//! [2]
-public:
-//! [1]
- // BrushInterface
- QStringList brushes() const override;
- QRect mousePress(const QString &brush, QPainter &painter,
- const QPoint &pos) override;
- QRect mouseMove(const QString &brush, QPainter &painter,
- const QPoint &oldPos, const QPoint &newPos) override;
- QRect mouseRelease(const QString &brush, QPainter &painter,
- const QPoint &pos) override;
-
- // ShapeInterface
- QStringList shapes() const override;
- QPainterPath generateShape(const QString &shape, QWidget *parent) override;
-
- // FilterInterface
- QStringList filters() const override;
- QImage filterImage(const QString &filter, const QImage &image,
- QWidget *parent) override;
-//! [3]
-};
-//! [2] //! [3]
-
-#endif
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt b/examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt
deleted file mode 100644
index cc883df049..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-qt_add_plugin(pnp_extrafilters
- CLASS_NAME ExtraFiltersPlugin
- extrafiltersplugin.cpp extrafiltersplugin.h
-)
-
-set_target_properties(pnp_extrafilters PROPERTIES
- LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/app"
-)
-
-target_include_directories(pnp_extrafilters PRIVATE
- ../../app
-)
-
-target_link_libraries(pnp_extrafilters PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS pnp_extrafilters
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}/plugins"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}/plugins"
-)
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.json b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.json
deleted file mode 100644
index 0967ef424b..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro
deleted file mode 100644
index e137b04823..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-#! [0]
-TEMPLATE = lib
-CONFIG += plugin
-QT += widgets
-INCLUDEPATH += ../../app
-HEADERS = extrafiltersplugin.h
-SOURCES = extrafiltersplugin.cpp
-TARGET = $$qtLibraryTarget(pnp_extrafilters)
-DESTDIR = ../../plugins
-
-#! [0]
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/plugandpaint/plugins
-INSTALLS += target
-
-CONFIG += install_ok # Do not cargo-cult this!
-uikit: CONFIG += debug_and_release
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
deleted file mode 100644
index 5356efc328..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "extrafiltersplugin.h"
-
-#include <QInputDialog>
-
-QStringList ExtraFiltersPlugin::filters() const
-{
- return {tr("Flip Horizontally"), tr("Flip Vertically"),
- tr("Smudge..."), tr("Threshold...")};
-}
-
-QImage ExtraFiltersPlugin::filterImage(const QString &filter,
- const QImage &image, QWidget *parent)
-{
- QImage original = image.convertToFormat(QImage::Format_RGB32);
- QImage result = original;
-
- if (filter == tr("Flip Horizontally")) {
- for (int y = 0; y < original.height(); ++y) {
- for (int x = 0; x < original.width(); ++x) {
- QRgb pixel = original.pixel(original.width() - x - 1, y);
- result.setPixel(x, y, pixel);
- }
- }
- } else if (filter == tr("Flip Vertically")) {
- for (int y = 0; y < original.height(); ++y) {
- for (int x = 0; x < original.width(); ++x) {
- QRgb pixel = original.pixel(x, original.height() - y - 1);
- result.setPixel(x, y, pixel);
- }
- }
- } else if (filter == tr("Smudge...")) {
- bool ok;
- int numIters = QInputDialog::getInt(parent, tr("Smudge Filter"),
- tr("Enter number of iterations:"),
- 5, 1, 20, 1, &ok);
- if (ok) {
- for (int i = 0; i < numIters; ++i) {
- for (int y = 1; y < original.height() - 1; ++y) {
- for (int x = 1; x < original.width() - 1; ++x) {
- QRgb p1 = original.pixel(x, y);
- QRgb p2 = original.pixel(x, y + 1);
- QRgb p3 = original.pixel(x, y - 1);
- QRgb p4 = original.pixel(x + 1, y);
- QRgb p5 = original.pixel(x - 1, y);
-
- int red = (qRed(p1) + qRed(p2) + qRed(p3) + qRed(p4)
- + qRed(p5)) / 5;
- int green = (qGreen(p1) + qGreen(p2) + qGreen(p3)
- + qGreen(p4) + qGreen(p5)) / 5;
- int blue = (qBlue(p1) + qBlue(p2) + qBlue(p3)
- + qBlue(p4) + qBlue(p5)) / 5;
- int alpha = (qAlpha(p1) + qAlpha(p2) + qAlpha(p3)
- + qAlpha(p4) + qAlpha(p5)) / 5;
-
- result.setPixel(x, y, qRgba(red, green, blue, alpha));
- }
- }
- }
- }
- } else if (filter == tr("Threshold...")) {
- bool ok;
- int threshold = QInputDialog::getInt(parent, tr("Threshold Filter"),
- tr("Enter threshold:"),
- 10, 1, 256, 1, &ok);
- if (ok) {
- int factor = 256 / threshold;
- for (int y = 0; y < original.height(); ++y) {
- for (int x = 0; x < original.width(); ++x) {
- QRgb pixel = original.pixel(x, y);
- result.setPixel(x, y, qRgba(qRed(pixel) / factor * factor,
- qGreen(pixel) / factor * factor,
- qBlue(pixel) / factor * factor,
- qAlpha(pixel)));
- }
- }
- }
- }
- return result;
-}
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.h b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.h
deleted file mode 100644
index 0fc50d2fd0..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef EXTRAFILTERSPLUGIN_H
-#define EXTRAFILTERSPLUGIN_H
-
-//! [0]
-#include <interfaces.h>
-
-#include <QObject>
-#include <QtPlugin>
-#include <QStringList>
-#include <QImage>
-
-class ExtraFiltersPlugin : public QObject, public FilterInterface
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.PlugAndPaint.FilterInterface" FILE "extrafilters.json")
- Q_INTERFACES(FilterInterface)
-
-public:
- QStringList filters() const override;
- QImage filterImage(const QString &filter, const QImage &image,
- QWidget *parent) override;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/tools/plugandpaint/plugins/plugins.pro b/examples/widgets/tools/plugandpaint/plugins/plugins.pro
deleted file mode 100644
index e15220c621..0000000000
--- a/examples/widgets/tools/plugandpaint/plugins/plugins.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = basictools \
- extrafilters
diff --git a/examples/widgets/tools/regularexpression/CMakeLists.txt b/examples/widgets/tools/regularexpression/CMakeLists.txt
index 0ba29861fc..af7701f1cf 100644
--- a/examples/widgets/tools/regularexpression/CMakeLists.txt
+++ b/examples/widgets/tools/regularexpression/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(regularexpression LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/regularexpression")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -43,7 +37,14 @@ qt_add_resources(regularexpression "regularexpression"
)
install(TARGETS regularexpression
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET regularexpression
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tools/settingseditor/CMakeLists.txt b/examples/widgets/tools/settingseditor/CMakeLists.txt
deleted file mode 100644
index 7ffa732f2b..0000000000
--- a/examples/widgets/tools/settingseditor/CMakeLists.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(settingseditor LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/settingseditor")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(settingseditor
- locationdialog.cpp locationdialog.h
- main.cpp
- mainwindow.cpp mainwindow.h
- settingstree.cpp settingstree.h
- variantdelegate.cpp variantdelegate.h
-)
-
-set_target_properties(settingseditor PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(settingseditor PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS settingseditor
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/settingseditor/inifiles/licensepage.ini b/examples/widgets/tools/settingseditor/inifiles/licensepage.ini
deleted file mode 100644
index 608d1b7885..0000000000
--- a/examples/widgets/tools/settingseditor/inifiles/licensepage.ini
+++ /dev/null
@@ -1,46 +0,0 @@
-[Field%201]
-Bottom=89
-Flags=MULTILINE|VSCROLL|READONLY
-Left=4
-Right=296
-State=No license agreement file found. Please contact support.
-Top=14
-Type=Text
-
-[Field%202]
-Bottom=8
-Left=4
-Right=294
-Text=Press Page Down to see the rest of the agreement.
-Top=0
-Type=Label
-
-[Field%203]
-Bottom=111
-Left=4
-Right=297
-Text=If you accept the terms of the agreement, select the first option below. You must accept the agreement to install this software. Click Next to continue.
-Top=92
-Type=Label
-
-[Field%204]
-Bottom=129
-Flags=GROUP|NOTIFY
-Left=4
-Right=299
-Text=I &accept the terms in the License Agreement
-Top=120
-Type=RadioButton
-
-[Field%205]
-Bottom=140
-Flags=NOTIFY
-Left=4
-Right=300
-State=1
-Text=I &do not accept the terms in the License Agreement
-Top=129
-Type=RadioButton
-
-[Settings]
-NumFields=5
diff --git a/examples/widgets/tools/settingseditor/inifiles/qsa.ini b/examples/widgets/tools/settingseditor/inifiles/qsa.ini
deleted file mode 100644
index 56a2964ee5..0000000000
--- a/examples/widgets/tools/settingseditor/inifiles/qsa.ini
+++ /dev/null
@@ -1,26 +0,0 @@
-[Field%201]
-Bottom=65
-Left=0
-Right=299
-Text=QSA Build Options
-Top=9
-Type=Groupbox
-
-[Field%202]
-Bottom=37
-Left=20
-Right=284
-Text=Don't compile QSA Workbench into QSA.
-Top=27
-Type=Checkbox
-
-[Field%203]
-Bottom=56
-Left=20
-Right=247
-Text=Don't compile QSA Workbench nor QSA Editor into QSA.
-Top=45
-Type=Checkbox
-
-[Settings]
-NumFields=3
diff --git a/examples/widgets/tools/settingseditor/locationdialog.cpp b/examples/widgets/tools/settingseditor/locationdialog.cpp
deleted file mode 100644
index cef83c0e49..0000000000
--- a/examples/widgets/tools/settingseditor/locationdialog.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "locationdialog.h"
-
-#include <QBoxLayout>
-#include <QComboBox>
-#include <QDialogButtonBox>
-#include <QDir>
-#include <QPushButton>
-#include <QGroupBox>
-#include <QHeaderView>
-#include <QLabel>
-#include <QLineEdit>
-#include <QTableWidget>
-#include <QTableWidgetItem>
-
-LocationDialog::LocationDialog(QWidget *parent)
- : QDialog(parent)
-{
- formatComboBox = new QComboBox;
- formatComboBox->addItem(tr("Native"));
- formatComboBox->addItem(tr("INI"));
-
- scopeComboBox = new QComboBox;
- scopeComboBox->addItem(tr("User"));
- scopeComboBox->addItem(tr("System"));
-
- organizationComboBox = new QComboBox;
- organizationComboBox->addItem(tr("QtProject"));
- organizationComboBox->setEditable(true);
-
- applicationComboBox = new QComboBox;
- applicationComboBox->addItem(tr("Any"));
- applicationComboBox->addItem(tr("Qt Creator"));
- applicationComboBox->addItem(tr("Application Example"));
- applicationComboBox->addItem(tr("Assistant"));
- applicationComboBox->addItem(tr("Designer"));
- applicationComboBox->addItem(tr("Linguist"));
- applicationComboBox->setEditable(true);
- applicationComboBox->setCurrentIndex(1);
-
- formatLabel = new QLabel(tr("&Format:"));
- formatLabel->setBuddy(formatComboBox);
-
- scopeLabel = new QLabel(tr("&Scope:"));
- scopeLabel->setBuddy(scopeComboBox);
-
- organizationLabel = new QLabel(tr("&Organization:"));
- organizationLabel->setBuddy(organizationComboBox);
-
- applicationLabel = new QLabel(tr("&Application:"));
- applicationLabel->setBuddy(applicationComboBox);
-
- locationsGroupBox = new QGroupBox(tr("Setting Locations"));
-
- const QStringList labels{tr("Location"), tr("Access")};
-
- locationsTable = new QTableWidget;
- locationsTable->setSelectionMode(QAbstractItemView::SingleSelection);
- locationsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
- locationsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
- locationsTable->setColumnCount(2);
- locationsTable->setHorizontalHeaderLabels(labels);
- locationsTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
- locationsTable->horizontalHeader()->resizeSection(1, 180);
- connect(locationsTable, &QTableWidget::itemActivated, this, &LocationDialog::itemActivated);
-
- buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
-
- connect(formatComboBox, &QComboBox::activated,
- this, &LocationDialog::updateLocationsTable);
- connect(scopeComboBox, &QComboBox::activated,
- this, &LocationDialog::updateLocationsTable);
- connect(organizationComboBox->lineEdit(),
- &QLineEdit::editingFinished,
- this, &LocationDialog::updateLocationsTable);
- connect(applicationComboBox->lineEdit(),
- &QLineEdit::editingFinished,
- this, &LocationDialog::updateLocationsTable);
- connect(applicationComboBox, &QComboBox::activated,
- this, &LocationDialog::updateLocationsTable);
- connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
- connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
-
- QVBoxLayout *locationsLayout = new QVBoxLayout(locationsGroupBox);
- locationsLayout->addWidget(locationsTable);
-
- QGridLayout *mainLayout = new QGridLayout(this);
- mainLayout->addWidget(formatLabel, 0, 0);
- mainLayout->addWidget(formatComboBox, 0, 1);
- mainLayout->addWidget(scopeLabel, 1, 0);
- mainLayout->addWidget(scopeComboBox, 1, 1);
- mainLayout->addWidget(organizationLabel, 2, 0);
- mainLayout->addWidget(organizationComboBox, 2, 1);
- mainLayout->addWidget(applicationLabel, 3, 0);
- mainLayout->addWidget(applicationComboBox, 3, 1);
- mainLayout->addWidget(locationsGroupBox, 4, 0, 1, 2);
- mainLayout->addWidget(buttonBox, 5, 0, 1, 2);
-
- updateLocationsTable();
-
- setWindowTitle(tr("Open Application Settings"));
- resize(650, 400);
-}
-
-QSettings::Format LocationDialog::format() const
-{
- if (formatComboBox->currentIndex() == 0)
- return QSettings::NativeFormat;
- else
- return QSettings::IniFormat;
-}
-
-QSettings::Scope LocationDialog::scope() const
-{
- if (scopeComboBox->currentIndex() == 0)
- return QSettings::UserScope;
- else
- return QSettings::SystemScope;
-}
-
-QString LocationDialog::organization() const
-{
- return organizationComboBox->currentText();
-}
-
-QString LocationDialog::application() const
-{
- if (applicationComboBox->currentText() == tr("Any"))
- return QString();
- else
- return applicationComboBox->currentText();
-}
-
-void LocationDialog::itemActivated(QTableWidgetItem *)
-{
- buttonBox->button(QDialogButtonBox::Ok)->animateClick();
-}
-
-void LocationDialog::updateLocationsTable()
-{
- locationsTable->setUpdatesEnabled(false);
- locationsTable->setRowCount(0);
-
- for (int i = 0; i < 2; ++i) {
- if (i == 0 && scope() == QSettings::SystemScope)
- continue;
-
- QSettings::Scope actualScope = (i == 0) ? QSettings::UserScope
- : QSettings::SystemScope;
- for (int j = 0; j < 2; ++j) {
- if (j == 0 && application().isEmpty())
- continue;
-
- QString actualApplication;
- if (j == 0)
- actualApplication = application();
- QSettings settings(format(), actualScope, organization(),
- actualApplication);
-
- int row = locationsTable->rowCount();
- locationsTable->setRowCount(row + 1);
-
- QTableWidgetItem *item0 = new QTableWidgetItem(QDir::toNativeSeparators(settings.fileName()));
-
- QTableWidgetItem *item1 = new QTableWidgetItem;
- bool disable = (settings.childKeys().isEmpty()
- && settings.childGroups().isEmpty());
-
- if (row == 0) {
- if (settings.isWritable()) {
- item1->setText(tr("Read-write"));
- disable = false;
- } else {
- item1->setText(tr("Read-only"));
- }
- buttonBox->button(QDialogButtonBox::Ok)->setDisabled(disable);
- } else {
- item1->setText(tr("Read-only fallback"));
- }
-
- if (disable) {
- item0->setFlags(item0->flags() & ~Qt::ItemIsEnabled);
- item1->setFlags(item1->flags() & ~Qt::ItemIsEnabled);
- }
-
- locationsTable->setItem(row, 0, item0);
- locationsTable->setItem(row, 1, item1);
- }
- }
- locationsTable->setUpdatesEnabled(true);
-}
diff --git a/examples/widgets/tools/settingseditor/locationdialog.h b/examples/widgets/tools/settingseditor/locationdialog.h
deleted file mode 100644
index 4bcef76ce7..0000000000
--- a/examples/widgets/tools/settingseditor/locationdialog.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef LOCATIONDIALOG_H
-#define LOCATIONDIALOG_H
-
-#include <QDialog>
-#include <QSettings>
-
-QT_BEGIN_NAMESPACE
-class QComboBox;
-class QDialogButtonBox;
-class QGroupBox;
-class QLabel;
-class QTableWidget;
-class QTableWidgetItem;
-QT_END_NAMESPACE
-
-class LocationDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- LocationDialog(QWidget *parent = nullptr);
-
- QSettings::Format format() const;
- QSettings::Scope scope() const;
- QString organization() const;
- QString application() const;
-
-private slots:
- void updateLocationsTable();
- void itemActivated(QTableWidgetItem *);
-
-private:
- QLabel *formatLabel;
- QLabel *scopeLabel;
- QLabel *organizationLabel;
- QLabel *applicationLabel;
- QComboBox *formatComboBox;
- QComboBox *scopeComboBox;
- QComboBox *organizationComboBox;
- QComboBox *applicationComboBox;
- QGroupBox *locationsGroupBox;
- QTableWidget *locationsTable;
- QDialogButtonBox *buttonBox;
-};
-
-#endif
diff --git a/examples/widgets/tools/settingseditor/main.cpp b/examples/widgets/tools/settingseditor/main.cpp
deleted file mode 100644
index f49701be5c..0000000000
--- a/examples/widgets/tools/settingseditor/main.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- QCoreApplication::setApplicationName("Settings Editor");
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
-
- MainWindow mainWin;
- mainWin.show();
- return app.exec();
-}
diff --git a/examples/widgets/tools/settingseditor/mainwindow.cpp b/examples/widgets/tools/settingseditor/mainwindow.cpp
deleted file mode 100644
index 68178a3747..0000000000
--- a/examples/widgets/tools/settingseditor/mainwindow.cpp
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "locationdialog.h"
-#include "mainwindow.h"
-#include "settingstree.h"
-
-#include <QAction>
-#include <QApplication>
-#include <QFileDialog>
-#include <QInputDialog>
-#include <QLineEdit>
-#include <QMenuBar>
-#include <QMessageBox>
-#include <QScreen>
-#include <QStandardPaths>
-#include <QStatusBar>
-
-MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
- , settingsTree(new SettingsTree)
-{
- setCentralWidget(settingsTree);
-
- createActions();
-
- autoRefreshAct->setChecked(true);
- fallbacksAct->setChecked(true);
-
- setWindowTitle(QCoreApplication::applicationName());
- const QRect availableGeometry = screen()->availableGeometry();
- adjustSize();
- move((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2);
-}
-
-void MainWindow::openSettings()
-{
- if (!locationDialog)
- locationDialog = new LocationDialog(this);
-
- if (locationDialog->exec() != QDialog::Accepted)
- return;
-
- SettingsPtr settings(new QSettings(locationDialog->format(),
- locationDialog->scope(),
- locationDialog->organization(),
- locationDialog->application()));
-
- setSettingsObject(settings);
- fallbacksAct->setEnabled(true);
-}
-
-void MainWindow::openIniFile()
-{
- const QString directory = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
- const QString fileName =
- QFileDialog::getOpenFileName(this, tr("Open INI File"),
- directory, tr("INI Files (*.ini *.conf)"));
- if (fileName.isEmpty())
- return;
-
- SettingsPtr settings(new QSettings(fileName, QSettings::IniFormat));
-
- setSettingsObject(settings);
- fallbacksAct->setEnabled(false);
-}
-
-void MainWindow::openPropertyList()
-{
- const QString directory = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
- const QString fileName =
- QFileDialog::getOpenFileName(this, tr("Open Property List"),
- directory, tr("Property List Files (*.plist)"));
- if (fileName.isEmpty())
- return;
-
- SettingsPtr settings(new QSettings(fileName, QSettings::NativeFormat));
- setSettingsObject(settings);
- fallbacksAct->setEnabled(false);
-}
-
-void MainWindow::openRegistryPath()
-{
- const QString path =
- QInputDialog::getText(this, tr("Open Registry Path"),
- tr("Enter the path in the Windows registry:"),
- QLineEdit::Normal, "HKEY_CURRENT_USER\\");
- if (path.isEmpty())
- return;
-
- SettingsPtr settings(new QSettings(path, QSettings::NativeFormat));
-
- setSettingsObject(settings);
- fallbacksAct->setEnabled(false);
-}
-
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About Settings Editor"),
- tr("The <b>Settings Editor</b> example shows how to access "
- "application settings using Qt."));
-}
-
-void MainWindow::createActions()
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
-
- QAction *openSettingsAct = fileMenu->addAction(tr("&Open Application Settings..."), this, &MainWindow::openSettings);
- openSettingsAct->setShortcuts(QKeySequence::Open);
-
- QAction *openIniFileAct = fileMenu->addAction(tr("Open I&NI File..."), this, &MainWindow::openIniFile);
- openIniFileAct->setShortcut(tr("Ctrl+N"));
-
-#ifdef Q_OS_MACOS
- QAction *openPropertyListAct = fileMenu->addAction(tr("Open Apple &Property List..."), this, &MainWindow::openPropertyList);
- openPropertyListAct->setShortcut(tr("Ctrl+P"));
-#endif // Q_OS_MACOS
-
-#ifdef Q_OS_WIN
- QAction *openRegistryPathAct = fileMenu->addAction(tr("Open Windows &Registry Path..."), this, &MainWindow::openRegistryPath);
- openRegistryPathAct->setShortcut(tr("Ctrl+G"));
-#endif // Q_OS_WIN
-
- fileMenu->addSeparator();
-
- refreshAct = fileMenu->addAction(tr("&Refresh"), settingsTree, &SettingsTree::refresh);
- refreshAct->setShortcut(tr("Ctrl+R"));
- refreshAct->setEnabled(false);
-
- fileMenu->addSeparator();
-
- QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
- exitAct->setShortcuts(QKeySequence::Quit);
-
- QMenu *optionsMenu = menuBar()->addMenu(tr("&Options"));
-
- autoRefreshAct = optionsMenu->addAction(tr("&Auto-Refresh"));
- autoRefreshAct->setShortcut(tr("Ctrl+A"));
- autoRefreshAct->setCheckable(true);
- autoRefreshAct->setEnabled(false);
- connect(autoRefreshAct, &QAction::triggered,
- settingsTree, &SettingsTree::setAutoRefresh);
- connect(autoRefreshAct, &QAction::triggered,
- refreshAct, &QAction::setDisabled);
-
- fallbacksAct = optionsMenu->addAction(tr("&Fallbacks"));
- fallbacksAct->setShortcut(tr("Ctrl+F"));
- fallbacksAct->setCheckable(true);
- fallbacksAct->setEnabled(false);
- connect(fallbacksAct, &QAction::triggered,
- settingsTree, &SettingsTree::setFallbacksEnabled);
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- helpMenu->addAction(tr("About &Qt"), qApp, &QCoreApplication::quit);
-}
-
-void MainWindow::setSettingsObject(const SettingsPtr &settings)
-{
- settings->setFallbacksEnabled(fallbacksAct->isChecked());
- settingsTree->setSettingsObject(settings);
-
- refreshAct->setEnabled(true);
- autoRefreshAct->setEnabled(true);
-
- QString niceName = QDir::cleanPath(settings->fileName());
- int pos = niceName.lastIndexOf(QLatin1Char('/'));
- if (pos != -1)
- niceName.remove(0, pos + 1);
-
- if (!settings->isWritable())
- niceName = tr("%1 (read only)").arg(niceName);
-
- setWindowTitle(tr("%1 - %2").arg(niceName, QCoreApplication::applicationName()));
- statusBar()->showMessage(tr("Opened \"%1\"").arg(QDir::toNativeSeparators(settings->fileName())));
-}
diff --git a/examples/widgets/tools/settingseditor/mainwindow.h b/examples/widgets/tools/settingseditor/mainwindow.h
deleted file mode 100644
index 84bdaef966..0000000000
--- a/examples/widgets/tools/settingseditor/mainwindow.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QSharedPointer>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QSettings;
-QT_END_NAMESPACE
-class LocationDialog;
-class SettingsTree;
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- typedef QSharedPointer<QSettings> SettingsPtr;
-
- MainWindow(QWidget *parent = nullptr);
-
-private slots:
- void openSettings();
- void openIniFile();
- void openPropertyList();
- void openRegistryPath();
- void about();
-
-private:
- void createActions();
- void setSettingsObject(const SettingsPtr &settings);
-
- SettingsTree *settingsTree = nullptr;
- LocationDialog *locationDialog = nullptr;
- QAction *refreshAct = nullptr;
- QAction *autoRefreshAct = nullptr;
- QAction *fallbacksAct = nullptr;
-};
-
-#endif
diff --git a/examples/widgets/tools/settingseditor/settingseditor.pro b/examples/widgets/tools/settingseditor/settingseditor.pro
deleted file mode 100644
index 4880b7e582..0000000000
--- a/examples/widgets/tools/settingseditor/settingseditor.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-QT += widgets
-requires(qtConfig(tablewidget))
-
-HEADERS = locationdialog.h \
- mainwindow.h \
- settingstree.h \
- variantdelegate.h
-SOURCES = locationdialog.cpp \
- main.cpp \
- mainwindow.cpp \
- settingstree.cpp \
- variantdelegate.cpp
-
-EXAMPLE_FILES = inifiles
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/settingseditor
-INSTALLS += target
diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp
deleted file mode 100644
index 5de2a8cff1..0000000000
--- a/examples/widgets/tools/settingseditor/settingstree.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "settingstree.h"
-#include "variantdelegate.h"
-
-#include <QApplication>
-#include <QHeaderView>
-#include <QScreen>
-#include <QSettings>
-
-SettingsTree::SettingsTree(QWidget *parent)
- : QTreeWidget(parent),
- m_typeChecker(new TypeChecker)
-{
- setItemDelegate(new VariantDelegate(m_typeChecker, this));
-
- setHeaderLabels({tr("Setting"), tr("Type"), tr("Value")});
- header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
- header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
- header()->setSectionResizeMode(2, QHeaderView::Stretch);
-
- refreshTimer.setInterval(2000);
-
- groupIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
- QIcon::Normal, QIcon::Off);
- groupIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
- QIcon::Normal, QIcon::On);
- keyIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
-
- connect(&refreshTimer, &QTimer::timeout, this, &SettingsTree::maybeRefresh);
-}
-
-SettingsTree::~SettingsTree() = default;
-
-void SettingsTree::setSettingsObject(const SettingsPtr &newSettings)
-{
- settings = newSettings;
- clear();
-
- if (settings.isNull()) {
- refreshTimer.stop();
- } else {
- refresh();
- if (autoRefresh)
- refreshTimer.start();
- }
-}
-
-QSize SettingsTree::sizeHint() const
-{
- const QRect availableGeometry = screen()->availableGeometry();
- return QSize(availableGeometry.width() * 2 / 3, availableGeometry.height() * 2 / 3);
-}
-
-void SettingsTree::setAutoRefresh(bool autoRefresh)
-{
- this->autoRefresh = autoRefresh;
- if (!settings.isNull()) {
- if (autoRefresh) {
- maybeRefresh();
- refreshTimer.start();
- } else {
- refreshTimer.stop();
- }
- }
-}
-
-void SettingsTree::setFallbacksEnabled(bool enabled)
-{
- if (!settings.isNull()) {
- settings->setFallbacksEnabled(enabled);
- refresh();
- }
-}
-
-void SettingsTree::maybeRefresh()
-{
- if (state() != EditingState)
- refresh();
-}
-
-void SettingsTree::refresh()
-{
- if (settings.isNull())
- return;
-
- disconnect(this, &QTreeWidget::itemChanged,
- this, &SettingsTree::updateSetting);
-
- settings->sync();
- updateChildItems(nullptr);
-
- connect(this, &QTreeWidget::itemChanged,
- this, &SettingsTree::updateSetting);
-}
-
-bool SettingsTree::event(QEvent *event)
-{
- if (event->type() == QEvent::WindowActivate) {
- if (isActiveWindow() && autoRefresh)
- maybeRefresh();
- }
- return QTreeWidget::event(event);
-}
-
-void SettingsTree::updateSetting(QTreeWidgetItem *item)
-{
- QString key = item->text(0);
- QTreeWidgetItem *ancestor = item->parent();
- while (ancestor) {
- key.prepend(ancestor->text(0) + QLatin1Char('/'));
- ancestor = ancestor->parent();
- }
-
- settings->setValue(key, item->data(2, Qt::UserRole));
- if (autoRefresh)
- refresh();
-}
-
-void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
-{
- int dividerIndex = 0;
-
- const QStringList childGroups = settings->childGroups();
- for (const QString &group : childGroups) {
- QTreeWidgetItem *child;
- int childIndex = findChild(parent, group, dividerIndex);
- if (childIndex != -1) {
- child = childAt(parent, childIndex);
- child->setText(1, QString());
- child->setText(2, QString());
- child->setData(2, Qt::UserRole, QVariant());
- moveItemForward(parent, childIndex, dividerIndex);
- } else {
- child = createItem(group, parent, dividerIndex);
- }
- child->setIcon(0, groupIcon);
- ++dividerIndex;
-
- settings->beginGroup(group);
- updateChildItems(child);
- settings->endGroup();
- }
-
- const QStringList childKeys = settings->childKeys();
- for (const QString &key : childKeys) {
- QTreeWidgetItem *child;
- int childIndex = findChild(parent, key, 0);
-
- if (childIndex == -1 || childIndex >= dividerIndex) {
- if (childIndex != -1) {
- child = childAt(parent, childIndex);
- for (int i = 0; i < child->childCount(); ++i)
- delete childAt(child, i);
- moveItemForward(parent, childIndex, dividerIndex);
- } else {
- child = createItem(key, parent, dividerIndex);
- }
- child->setIcon(0, keyIcon);
- ++dividerIndex;
- } else {
- child = childAt(parent, childIndex);
- }
-
- QVariant value = settings->value(key);
- if (value.userType() == QMetaType::UnknownType) {
- child->setText(1, "Invalid");
- } else {
- if (value.typeId() == QMetaType::QString) {
- const QString stringValue = value.toString();
- if (m_typeChecker->boolExp.match(stringValue).hasMatch()) {
- value.setValue(stringValue.compare("true", Qt::CaseInsensitive) == 0);
- } else if (m_typeChecker->signedIntegerExp.match(stringValue).hasMatch())
- value.setValue(stringValue.toInt());
- }
-
- child->setText(1, value.typeName());
- }
- child->setText(2, VariantDelegate::displayText(value));
- child->setData(2, Qt::UserRole, value);
- }
-
- while (dividerIndex < childCount(parent))
- delete childAt(parent, dividerIndex);
-}
-
-QTreeWidgetItem *SettingsTree::createItem(const QString &text,
- QTreeWidgetItem *parent, int index)
-{
- QTreeWidgetItem *after = nullptr;
- if (index != 0)
- after = childAt(parent, index - 1);
-
- QTreeWidgetItem *item;
- if (parent)
- item = new QTreeWidgetItem(parent, after);
- else
- item = new QTreeWidgetItem(this, after);
-
- item->setText(0, text);
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- return item;
-}
-
-QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index) const
-{
- return (parent ? parent->child(index) : topLevelItem(index));
-}
-
-int SettingsTree::childCount(QTreeWidgetItem *parent) const
-{
- return (parent ? parent->childCount() : topLevelItemCount());
-}
-
-int SettingsTree::findChild(QTreeWidgetItem *parent, const QString &text,
- int startIndex) const
-{
- for (int i = startIndex; i < childCount(parent); ++i) {
- if (childAt(parent, i)->text(0) == text)
- return i;
- }
- return -1;
-}
-
-void SettingsTree::moveItemForward(QTreeWidgetItem *parent, int oldIndex,
- int newIndex)
-{
- for (int i = 0; i < oldIndex - newIndex; ++i)
- delete childAt(parent, newIndex);
-}
diff --git a/examples/widgets/tools/settingseditor/settingstree.h b/examples/widgets/tools/settingseditor/settingstree.h
deleted file mode 100644
index 8dfa52113f..0000000000
--- a/examples/widgets/tools/settingseditor/settingstree.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SETTINGSTREE_H
-#define SETTINGSTREE_H
-
-#include <QIcon>
-#include <QTimer>
-#include <QTreeWidget>
-#include <QSharedPointer>
-
-QT_BEGIN_NAMESPACE
-class QSettings;
-QT_END_NAMESPACE
-
-struct TypeChecker;
-
-class SettingsTree : public QTreeWidget
-{
- Q_OBJECT
-
-public:
- using SettingsPtr = QSharedPointer<QSettings>;
- using TypeCheckerPtr = QSharedPointer<TypeChecker>;
-
- SettingsTree(QWidget *parent = nullptr);
- ~SettingsTree();
-
- void setSettingsObject(const SettingsPtr &settings);
- QSize sizeHint() const override;
-
-public slots:
- void setAutoRefresh(bool autoRefresh);
- void setFallbacksEnabled(bool enabled);
- void maybeRefresh();
- void refresh();
-
-protected:
- bool event(QEvent *event) override;
-
-private slots:
- void updateSetting(QTreeWidgetItem *item);
-
-private:
- void updateChildItems(QTreeWidgetItem *parent);
- QTreeWidgetItem *createItem(const QString &text, QTreeWidgetItem *parent,
- int index);
- QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index) const;
- int childCount(QTreeWidgetItem *parent) const;
- int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex) const;
- void moveItemForward(QTreeWidgetItem *parent, int oldIndex, int newIndex);
-
- SettingsPtr settings;
- TypeCheckerPtr m_typeChecker;
- QTimer refreshTimer;
- QIcon groupIcon;
- QIcon keyIcon;
- bool autoRefresh = false;
-};
-
-#endif
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp
deleted file mode 100644
index ed51a1645b..0000000000
--- a/examples/widgets/tools/settingseditor/variantdelegate.cpp
+++ /dev/null
@@ -1,377 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "variantdelegate.h"
-
-#include <QCheckBox>
-#include <QDateTime>
-#include <QLineEdit>
-#include <QSpinBox>
-#include <QRegularExpressionValidator>
-#include <QTextStream>
-
-#include <algorithm>
-
-static bool isPrintableChar(char c)
-{
- return uchar(c) >= 32 && uchar(c) < 128;
-}
-
-static bool isPrintable(const QByteArray &ba)
-{
- return std::all_of(ba.cbegin(), ba.cend(), isPrintableChar);
-}
-
-static QString byteArrayToString(const QByteArray &ba)
-{
- if (isPrintable(ba))
- return QString::fromLatin1(ba);
- QString result;
- for (char c : ba) {
- if (isPrintableChar(c)) {
- if (c == '\\')
- result += QLatin1Char(c);
- result += QLatin1Char(c);
- } else {
- const uint uc = uchar(c);
- result += "\\x";
- if (uc < 16)
- result += '0';
- result += QString::number(uc, 16);
- }
- }
- return result;
-}
-
-TypeChecker::TypeChecker()
-{
- boolExp.setPattern("^(true)|(false)$");
- boolExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
- Q_ASSERT(boolExp.isValid());
-
- byteArrayExp.setPattern(R"RX(^[\x00-\xff]*$)RX");
- charExp.setPattern("^.$");
- Q_ASSERT(charExp.isValid());
- colorExp.setPattern(R"RX(^\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\)$)RX");
- Q_ASSERT(colorExp.isValid());
- doubleExp.setPattern("");
- pointExp.setPattern(R"RX(^\((-?[0-9]*),(-?[0-9]*)\)$)RX");
- Q_ASSERT(pointExp.isValid());
- rectExp.setPattern(R"RX(^\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\)$)RX");
- Q_ASSERT(rectExp.isValid());
- signedIntegerExp.setPattern("^-?[0-9]*$");
- Q_ASSERT(signedIntegerExp.isValid());
- sizeExp = pointExp;
- unsignedIntegerExp.setPattern("^[0-9]+$");
- Q_ASSERT(unsignedIntegerExp.isValid());
-
- const QString datePattern = "([0-9]{,4})-([0-9]{,2})-([0-9]{,2})";
- dateExp.setPattern('^' + datePattern + '$');
- Q_ASSERT(dateExp.isValid());
- const QString timePattern = "([0-9]{,2}):([0-9]{,2}):([0-9]{,2})";
- timeExp.setPattern('^' + timePattern + '$');
- Q_ASSERT(timeExp.isValid());
- dateTimeExp.setPattern('^' + datePattern + 'T' + timePattern + '$');
- Q_ASSERT(dateTimeExp.isValid());
-}
-
-VariantDelegate::VariantDelegate(const QSharedPointer<TypeChecker> &typeChecker,
- QObject *parent)
- : QStyledItemDelegate(parent),
- m_typeChecker(typeChecker)
-{
-}
-
-void VariantDelegate::paint(QPainter *painter,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const
-{
- if (index.column() == 2) {
- QVariant value = index.model()->data(index, Qt::UserRole);
- if (!isSupportedType(value.userType())) {
- QStyleOptionViewItem myOption = option;
- myOption.state &= ~QStyle::State_Enabled;
- QStyledItemDelegate::paint(painter, myOption, index);
- return;
- }
- }
-
- QStyledItemDelegate::paint(painter, option, index);
-}
-
-QWidget *VariantDelegate::createEditor(QWidget *parent,
- const QStyleOptionViewItem & /* option */,
- const QModelIndex &index) const
-{
- if (index.column() != 2)
- return nullptr;
-
- QVariant originalValue = index.model()->data(index, Qt::UserRole);
- if (!isSupportedType(originalValue.userType()))
- return nullptr;
-
- switch (originalValue.userType()) {
- case QMetaType::Bool:
- return new QCheckBox(parent);
- break;
- case QMetaType::Int:
- case QMetaType::LongLong: {
- auto spinBox = new QSpinBox(parent);
- spinBox->setRange(-32767, 32767);
- return spinBox;
- }
- case QMetaType::UInt:
- case QMetaType::ULongLong: {
- auto spinBox = new QSpinBox(parent);
- spinBox->setRange(0, 63335);
- return spinBox;
- }
- default:
- break;
- }
-
- QLineEdit *lineEdit = new QLineEdit(parent);
- lineEdit->setFrame(false);
-
- QRegularExpression regExp;
-
- switch (originalValue.userType()) {
- case QMetaType::Bool:
- regExp = m_typeChecker->boolExp;
- break;
- case QMetaType::QByteArray:
- regExp = m_typeChecker->byteArrayExp;
- break;
- case QMetaType::QChar:
- regExp = m_typeChecker->charExp;
- break;
- case QMetaType::QColor:
- regExp = m_typeChecker->colorExp;
- break;
- case QMetaType::QDate:
- regExp = m_typeChecker->dateExp;
- break;
- case QMetaType::QDateTime:
- regExp = m_typeChecker->dateTimeExp;
- break;
- case QMetaType::Double:
- regExp = m_typeChecker->doubleExp;
- break;
- case QMetaType::Int:
- case QMetaType::LongLong:
- regExp = m_typeChecker->signedIntegerExp;
- break;
- case QMetaType::QPoint:
- regExp = m_typeChecker->pointExp;
- break;
- case QMetaType::QRect:
- regExp = m_typeChecker->rectExp;
- break;
- case QMetaType::QSize:
- regExp = m_typeChecker->sizeExp;
- break;
- case QMetaType::QTime:
- regExp = m_typeChecker->timeExp;
- break;
- case QMetaType::UInt:
- case QMetaType::ULongLong:
- regExp = m_typeChecker->unsignedIntegerExp;
- break;
- default:
- break;
- }
-
- if (regExp.isValid()) {
- QValidator *validator = new QRegularExpressionValidator(regExp, lineEdit);
- lineEdit->setValidator(validator);
- }
-
- return lineEdit;
-}
-
-void VariantDelegate::setEditorData(QWidget *editor,
- const QModelIndex &index) const
-{
- QVariant value = index.model()->data(index, Qt::UserRole);
- if (auto spinBox = qobject_cast<QSpinBox *>(editor)) {
- const auto userType = value.userType();
- if (userType == QMetaType::UInt || userType == QMetaType::ULongLong)
- spinBox->setValue(value.toUInt());
- else
- spinBox->setValue(value.toInt());
- } else if (auto checkBox = qobject_cast<QCheckBox *>(editor)) {
- checkBox->setChecked(value.toBool());
- } else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor)) {
- if (value.userType() == QMetaType::QByteArray
- && !isPrintable(value.toByteArray())) {
- lineEdit->setReadOnly(true);
- }
- lineEdit->setText(displayText(value));
- }
-}
-
-void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const
-{
- const QVariant originalValue = index.model()->data(index, Qt::UserRole);
- QVariant value;
-
- if (auto spinBox = qobject_cast<QSpinBox *>(editor)) {
- value.setValue(spinBox->value());
- } else if (auto checkBox = qobject_cast<QCheckBox *>(editor)) {
- value.setValue(checkBox->isChecked());
- } else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor)) {
- if (!lineEdit->isModified())
- return;
-
- QString text = lineEdit->text();
- const QValidator *validator = lineEdit->validator();
- if (validator) {
- int pos;
- if (validator->validate(text, pos) != QValidator::Acceptable)
- return;
- }
-
- QRegularExpressionMatch match;
-
- switch (originalValue.userType()) {
- case QMetaType::QChar:
- value = text.at(0);
- break;
- case QMetaType::QColor:
- match = m_typeChecker->colorExp.match(text);
- value = QColor(qMin(match.captured(1).toInt(), 255),
- qMin(match.captured(2).toInt(), 255),
- qMin(match.captured(3).toInt(), 255),
- qMin(match.captured(4).toInt(), 255));
- break;
- case QMetaType::QDate:
- {
- QDate date = QDate::fromString(text, Qt::ISODate);
- if (!date.isValid())
- return;
- value = date;
- }
- break;
- case QMetaType::QDateTime:
- {
- QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate);
- if (!dateTime.isValid())
- return;
- value = dateTime;
- }
- break;
- case QMetaType::QPoint:
- match = m_typeChecker->pointExp.match(text);
- value = QPoint(match.captured(1).toInt(), match.captured(2).toInt());
- break;
- case QMetaType::QRect:
- match = m_typeChecker->rectExp.match(text);
- value = QRect(match.captured(1).toInt(), match.captured(2).toInt(),
- match.captured(3).toInt(), match.captured(4).toInt());
- break;
- case QMetaType::QSize:
- match = m_typeChecker->sizeExp.match(text);
- value = QSize(match.captured(1).toInt(), match.captured(2).toInt());
- break;
- case QMetaType::QStringList:
- value = text.split(',');
- break;
- case QMetaType::QTime:
- {
- QTime time = QTime::fromString(text, Qt::ISODate);
- if (!time.isValid())
- return;
- value = time;
- }
- break;
- default:
- value = text;
- value.convert(originalValue.metaType());
- }
- }
-
- model->setData(index, displayText(value), Qt::DisplayRole);
- model->setData(index, value, Qt::UserRole);
-}
-
-bool VariantDelegate::isSupportedType(int type)
-{
- switch (type) {
- case QMetaType::Bool:
- case QMetaType::QByteArray:
- case QMetaType::QChar:
- case QMetaType::QColor:
- case QMetaType::QDate:
- case QMetaType::QDateTime:
- case QMetaType::Double:
- case QMetaType::Int:
- case QMetaType::LongLong:
- case QMetaType::QPoint:
- case QMetaType::QRect:
- case QMetaType::QSize:
- case QMetaType::QString:
- case QMetaType::QStringList:
- case QMetaType::QTime:
- case QMetaType::UInt:
- case QMetaType::ULongLong:
- return true;
- default:
- return false;
- }
-}
-
-QString VariantDelegate::displayText(const QVariant &value)
-{
- switch (value.userType()) {
- case QMetaType::Bool:
- return value.toBool() ? "✓" : "☐";
- case QMetaType::QByteArray:
- return byteArrayToString(value.toByteArray());
- case QMetaType::QChar:
- case QMetaType::Double:
- case QMetaType::Int:
- case QMetaType::LongLong:
- case QMetaType::QString:
- case QMetaType::UInt:
- case QMetaType::ULongLong:
- return value.toString();
- case QMetaType::QColor:
- {
- QColor color = qvariant_cast<QColor>(value);
- return QString("(%1,%2,%3,%4)")
- .arg(color.red()).arg(color.green())
- .arg(color.blue()).arg(color.alpha());
- }
- case QMetaType::QDate:
- return value.toDate().toString(Qt::ISODate);
- case QMetaType::QDateTime:
- return value.toDateTime().toString(Qt::ISODate);
- case QMetaType::UnknownType:
- return "<Invalid>";
- case QMetaType::QPoint:
- {
- QPoint point = value.toPoint();
- return QString("(%1,%2)").arg(point.x()).arg(point.y());
- }
- case QMetaType::QRect:
- {
- QRect rect = value.toRect();
- return QString("(%1,%2,%3,%4)")
- .arg(rect.x()).arg(rect.y())
- .arg(rect.width()).arg(rect.height());
- }
- case QMetaType::QSize:
- {
- QSize size = value.toSize();
- return QString("(%1,%2)").arg(size.width()).arg(size.height());
- }
- case QMetaType::QStringList:
- return value.toStringList().join(',');
- case QMetaType::QTime:
- return value.toTime().toString(Qt::ISODate);
- default:
- break;
- }
- return QString("<%1>").arg(value.typeName());
-}
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h
deleted file mode 100644
index dc06d51bbc..0000000000
--- a/examples/widgets/tools/settingseditor/variantdelegate.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef VARIANTDELEGATE_H
-#define VARIANTDELEGATE_H
-
-#include <QStyledItemDelegate>
-#include <QRegularExpression>
-#include <QSharedPointer>
-
-struct TypeChecker
-{
- TypeChecker();
-
- QRegularExpression boolExp;
- QRegularExpression byteArrayExp;
- QRegularExpression charExp;
- QRegularExpression colorExp;
- QRegularExpression dateExp;
- QRegularExpression dateTimeExp;
- QRegularExpression doubleExp;
- QRegularExpression pointExp;
- QRegularExpression rectExp;
- QRegularExpression signedIntegerExp;
- QRegularExpression sizeExp;
- QRegularExpression timeExp;
- QRegularExpression unsignedIntegerExp;
-};
-
-class VariantDelegate : public QStyledItemDelegate
-{
- Q_OBJECT
-
-public:
- explicit VariantDelegate(const QSharedPointer<TypeChecker> &typeChecker,
- QObject *parent = nullptr);
-
- void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
- QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
- void setEditorData(QWidget *editor, const QModelIndex &index) const override;
- void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const override;
-
- static bool isSupportedType(int type);
- static QString displayText(const QVariant &value);
-
-private:
- QSharedPointer<TypeChecker> m_typeChecker;
-};
-
-#endif
diff --git a/examples/widgets/tools/styleplugin/CMakeLists.txt b/examples/widgets/tools/styleplugin/CMakeLists.txt
deleted file mode 100644
index 7e46a7b2af..0000000000
--- a/examples/widgets/tools/styleplugin/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(styleplugin LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/styleplugin")
-
-find_package(Qt6 REQUIRED COMPONENTS Widgets)
-
-qt_standard_project_setup()
-
-add_subdirectory(stylewindow)
-add_subdirectory(plugin)
diff --git a/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt b/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt
deleted file mode 100644
index 494a4a90f6..0000000000
--- a/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt
+++ /dev/null
@@ -1,41 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-#! [0]
-qt_add_plugin(simplestyleplugin
- CLASS_NAME SimpleStylePlugin
- simplestyle.cpp simplestyle.h
- simplestyleplugin.cpp simplestyleplugin.h
-)
-#! [0]
-
-if(QT_FEATURE_debug AND APPLE)
- set_property(TARGET simplestyleplugin
- APPEND_STRING PROPERTY OUTPUT_NAME "_debug")
-endif()
-
-get_target_property(is_bundle styleplugin MACOSX_BUNDLE)
-if(APPLE AND is_bundle)
-#! [1]
- set_target_properties(simplestyleplugin PROPERTIES
- LIBRARY_OUTPUT_DIRECTORY "$<TARGET_BUNDLE_CONTENT_DIR:styleplugin>/PlugIns/styles"
- )
-#! [1]
-else()
-#! [2]
- set_target_properties(simplestyleplugin PROPERTIES
- LIBRARY_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:styleplugin>/styles"
- )
-#! [2]
-endif()
-
-target_link_libraries(simplestyleplugin PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS simplestyleplugin
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/styleplugin/plugin/plugin.pro b/examples/widgets/tools/styleplugin/plugin/plugin.pro
deleted file mode 100644
index 5ab00016ca..0000000000
--- a/examples/widgets/tools/styleplugin/plugin/plugin.pro
+++ /dev/null
@@ -1,34 +0,0 @@
-#! [0]
-TEMPLATE = lib
-CONFIG += plugin
-QT += widgets
-HEADERS = simplestyle.h \
- simplestyleplugin.h
-SOURCES = simplestyle.cpp \
- simplestyleplugin.cpp
-TARGET = simplestyleplugin
-#! [0]
-win32 {
- CONFIG(debug, release|debug):DESTDIR = ../debug/styles/
- CONFIG(release, release|debug):DESTDIR = ../release/styles/
-} else {
- macos {
- # The non-app-bundle case is not supported with qmake, because
- # the plugin project cannot know whether the app is built
- # as a bundle or not.
- DESTDIR = ../styleplugin.app/Contents/PlugIns/styles/
- contains(QT_CONFIG, debug) {
- TARGET = $$join(TARGET,,,_debug)
- }
- } else {
- DESTDIR = ../styles/
- }
-}
-
-EXAMPLE_FILES += simplestyle.json
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/styleplugin/styles
-INSTALLS += target
-
-CONFIG += install_ok # Do not cargo-cult this!
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp b/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
deleted file mode 100644
index fa60d50140..0000000000
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "simplestyle.h"
-
-void SimpleStyle::polish(QPalette &palette)
-{
- palette.setBrush(QPalette::Text, Qt::red);
-}
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.h b/examples/widgets/tools/styleplugin/plugin/simplestyle.h
deleted file mode 100644
index 315c4d836c..0000000000
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SIMPLESTYLE_H
-#define SIMPLESTYLE_H
-
-#include <QProxyStyle>
-
-class SimpleStyle : public QProxyStyle
-{
- Q_OBJECT
-
-public:
- SimpleStyle() = default;
-
- void polish(QPalette &palette) override;
-};
-
-#endif
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.json b/examples/widgets/tools/styleplugin/plugin/simplestyle.json
deleted file mode 100644
index a708e2aafe..0000000000
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": [ "simplestyle" ]
-}
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
deleted file mode 100644
index f28d22ccc9..0000000000
--- a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "simplestyleplugin.h"
-#include "simplestyle.h"
-
-//! [0]
-QStringList SimpleStylePlugin::keys() const
-{
- return {"SimpleStyle"};
-}
-//! [0]
-
-//! [1]
-QStyle *SimpleStylePlugin::create(const QString &key)
-{
- if (key.toLower() == "simplestyle")
- return new SimpleStyle;
- return nullptr;
-}
-//! [1]
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
deleted file mode 100644
index 8a3dc45210..0000000000
--- a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SIMPLESTYLEPLUGIN_H
-#define SIMPLESTYLEPLUGIN_H
-
-#include <QStylePlugin>
-
-//! [0]
-class SimpleStylePlugin : public QStylePlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "simplestyle.json")
-
-public:
- SimpleStylePlugin() = default;
-
- QStringList keys() const;
- QStyle *create(const QString &key) override;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/tools/styleplugin/styleplugin.pro b/examples/widgets/tools/styleplugin/styleplugin.pro
deleted file mode 100644
index 4f120637b0..0000000000
--- a/examples/widgets/tools/styleplugin/styleplugin.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = stylewindow \
- plugin
diff --git a/examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt b/examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt
deleted file mode 100644
index 3c1ac7670f..0000000000
--- a/examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-qt_add_executable(styleplugin
- main.cpp
- stylewindow.cpp stylewindow.h
-)
-
-set_target_properties(styleplugin PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(styleplugin PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if(NOT QT6_IS_SHARED_LIBS_BUILD)
- target_link_libraries(styleplugin PRIVATE
- simplestyleplugin
- )
-endif()
-
-install(TARGETS styleplugin
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/styleplugin/stylewindow/main.cpp b/examples/widgets/tools/styleplugin/stylewindow/main.cpp
deleted file mode 100644
index 0b0a295410..0000000000
--- a/examples/widgets/tools/styleplugin/stylewindow/main.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include <QStyleFactory>
-
-#include "stylewindow.h"
-
-//! [0]
-int main(int argv, char *args[])
-{
- QApplication app(argv, args);
-
- QStyle *style = QStyleFactory::create("simplestyle");
- if (!style)
- qFatal("Cannot load the 'simplestyle' plugin.");
-
- QApplication::setStyle(style);
-
- StyleWindow window;
- window.resize(350, 50);
- window.show();
-
- return app.exec();
-}
-//! [0]
diff --git a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
deleted file mode 100644
index 9268666c21..0000000000
--- a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QGridLayout>
-#include <QGroupBox>
-#include <QTextEdit>
-
-#include "stylewindow.h"
-
-StyleWindow::StyleWindow()
-{
- QTextEdit *styledTextEdit = new QTextEdit(tr("The quick brown fox jumps over the lazy dog"));
-
- QGridLayout *layout = new QGridLayout;
- layout->addWidget(styledTextEdit);
-
- QGroupBox *styleBox = new QGroupBox(tr("A simple styled text edit"));
- styleBox->setLayout(layout);
-
- QGridLayout *outerLayout = new QGridLayout;
- outerLayout->addWidget(styleBox, 0, 0);
- setLayout(outerLayout);
-
- setWindowTitle(tr("Style Plugin Example"));
-}
diff --git a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.h b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.h
deleted file mode 100644
index 50fa6b29f7..0000000000
--- a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef STYLEWINDOW_H
-#define STYLEWINDOW_H
-
-#include <QWidget>
-
-class StyleWindow : public QWidget
-{
- Q_OBJECT
-
-public:
- StyleWindow();
-};
-
-#endif
diff --git a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.pro b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.pro
deleted file mode 100644
index cdc1bd2fda..0000000000
--- a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-QT += widgets
-
-HEADERS = stylewindow.h
-SOURCES = stylewindow.cpp \
- main.cpp
-
-TARGET = styleplugin
-win32 {
- debug:DESTDIR = ../debug/
- release:DESTDIR = ../release/
-} else {
- DESTDIR = ../
-}
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/styleplugin
-INSTALLS += target
-
-CONFIG += install_ok # Do not cargo-cult this!
diff --git a/examples/widgets/tools/tools.pro b/examples/widgets/tools/tools.pro
index 4a9dce3412..a6d483f7e2 100644
--- a/examples/widgets/tools/tools.pro
+++ b/examples/widgets/tools/tools.pro
@@ -2,16 +2,7 @@ TEMPLATE = subdirs
SUBDIRS = \
completer \
customcompleter \
- echoplugin \
- plugandpaint \
regularexpression \
- settingseditor \
- styleplugin \
treemodelcompleter \
undoframework
-!qtConfig(library) {
- SUBDIRS -= \
- echoplugin \
- plugandpaint
-}
diff --git a/examples/widgets/tools/treemodelcompleter/CMakeLists.txt b/examples/widgets/tools/treemodelcompleter/CMakeLists.txt
index 42b3ed7aea..4f512db3ee 100644
--- a/examples/widgets/tools/treemodelcompleter/CMakeLists.txt
+++ b/examples/widgets/tools/treemodelcompleter/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(treemodelcompleter LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/treemodelcompleter")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -44,7 +38,14 @@ qt_add_resources(treemodelcompleter "treemodelcompleter"
)
install(TARGETS treemodelcompleter
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET treemodelcompleter
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tools/treemodelcompleter/main.cpp b/examples/widgets/tools/treemodelcompleter/main.cpp
index 50ca573129..060dfe5bd8 100644
--- a/examples/widgets/tools/treemodelcompleter/main.cpp
+++ b/examples/widgets/tools/treemodelcompleter/main.cpp
@@ -7,8 +7,6 @@
//! [0]
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(treemodelcompleter);
-
QApplication app(argc, argv);
MainWindow window;
window.show();
diff --git a/examples/widgets/tools/undoframework/CMakeLists.txt b/examples/widgets/tools/undoframework/CMakeLists.txt
index 753d4205dc..27912f04c7 100644
--- a/examples/widgets/tools/undoframework/CMakeLists.txt
+++ b/examples/widgets/tools/undoframework/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(undoframework LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/undoframework")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -51,7 +45,14 @@ qt_add_resources(undoframework "undoframework"
)
install(TARGETS undoframework
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET undoframework
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tools/undoframework/main.cpp b/examples/widgets/tools/undoframework/main.cpp
index c43b2fccd7..8dfa3ffb4b 100644
--- a/examples/widgets/tools/undoframework/main.cpp
+++ b/examples/widgets/tools/undoframework/main.cpp
@@ -8,8 +8,6 @@
//! [0]
int main(int argv, char *args[])
{
- Q_INIT_RESOURCE(undoframework);
-
QApplication app(argv, args);
MainWindow mainWindow;
diff --git a/examples/widgets/touch/CMakeLists.txt b/examples/widgets/touch/CMakeLists.txt
index 4cf7878963..6b5aebb98a 100644
--- a/examples/widgets/touch/CMakeLists.txt
+++ b/examples/widgets/touch/CMakeLists.txt
@@ -1,10 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Widgets)
return()
endif()
-qt_internal_add_example(pinchzoom)
-qt_internal_add_example(fingerpaint)
qt_internal_add_example(knobs)
-qt_internal_add_example(dials)
diff --git a/examples/widgets/touch/dials/CMakeLists.txt b/examples/widgets/touch/dials/CMakeLists.txt
deleted file mode 100644
index d206c1f543..0000000000
--- a/examples/widgets/touch/dials/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(dials LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/touch/dials")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(dials
- dials.ui
- main.cpp
-)
-
-set_target_properties(dials PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(dials PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS dials
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/touch/dials/dials.pro b/examples/widgets/touch/dials/dials.pro
deleted file mode 100644
index 0e823551cc..0000000000
--- a/examples/widgets/touch/dials/dials.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-QT += widgets
-
-SOURCES += main.cpp
-FORMS += dials.ui
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/touch/dials
-INSTALLS += target
diff --git a/examples/widgets/touch/dials/dials.ui b/examples/widgets/touch/dials/dials.ui
deleted file mode 100644
index 8ca7ae9475..0000000000
--- a/examples/widgets/touch/dials/dials.ui
+++ /dev/null
@@ -1,77 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>Dials</class>
- <widget class="QWidget" name="Dials">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>300</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QDial" name="dial_1">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QDial" name="dial_2">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="0" column="2">
- <widget class="QDial" name="dial_3">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="0" column="3">
- <widget class="QDial" name="dial_4">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QDial" name="dial_5">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QDial" name="dial_6">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QDial" name="dial_7">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="3">
- <widget class="QDial" name="dial_8">
- <property name="notchesVisible">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/widgets/touch/dials/doc/images/touch-dials-example.png b/examples/widgets/touch/dials/doc/images/touch-dials-example.png
deleted file mode 100644
index 60e1776fc3..0000000000
--- a/examples/widgets/touch/dials/doc/images/touch-dials-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/touch/dials/doc/src/touch-dials.qdoc b/examples/widgets/touch/dials/doc/src/touch-dials.qdoc
deleted file mode 100644
index 448430ed79..0000000000
--- a/examples/widgets/touch/dials/doc/src/touch-dials.qdoc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example touch/dials
- \title Touch Dials Example
- \ingroup touchinputexamples
- \brief Shows how to apply touch to a set of standard Qt widgets.
-
- The Touch Dials example shows how to apply touch to a set of
- standard Qt widgets.
-
- \image touch-dials-example.png
-*/
diff --git a/examples/widgets/touch/dials/main.cpp b/examples/widgets/touch/dials/main.cpp
deleted file mode 100644
index 63fdb7db3b..0000000000
--- a/examples/widgets/touch/dials/main.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include <QWidget>
-#include <QDial>
-
-#include "ui_dials.h"
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
- QWidget window;
- Ui::Dials dialsUi;
- dialsUi.setupUi(&window);
- const QList<QAbstractSlider *> sliders = window.findChildren<QAbstractSlider *>();
- for (QAbstractSlider *slider : sliders)
- slider->setAttribute(Qt::WA_AcceptTouchEvents);
- window.showMaximized();
- return app.exec();
-}
diff --git a/examples/widgets/touch/fingerpaint/CMakeLists.txt b/examples/widgets/touch/fingerpaint/CMakeLists.txt
deleted file mode 100644
index 98e8cc6979..0000000000
--- a/examples/widgets/touch/fingerpaint/CMakeLists.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(fingerpaint LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/touch/fingerpaint")
-
-find_package(Qt6
- REQUIRED COMPONENTS Core Gui Widgets
- OPTIONAL_COMPONENTS PrintSupport
-)
-
-qt_standard_project_setup()
-
-qt_add_executable(fingerpaint
- main.cpp
- mainwindow.cpp mainwindow.h
- scribblearea.cpp scribblearea.h
-)
-
-set_target_properties(fingerpaint PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(fingerpaint PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if (TARGET Qt6::PrintSupport)
- target_link_libraries(fingerpaint PRIVATE Qt6::PrintSupport)
-endif()
-
-install(TARGETS fingerpaint
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/touch/fingerpaint/doc/src/fingerpaint.qdoc b/examples/widgets/touch/fingerpaint/doc/src/fingerpaint.qdoc
deleted file mode 100644
index 0e3319004c..0000000000
--- a/examples/widgets/touch/fingerpaint/doc/src/fingerpaint.qdoc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example touch/fingerpaint
- \title Finger Paint Example
- \ingroup touchinputexamples
- \brief Shows the use of a touchscreen to make a simple painting application.
-
- The Finger Paint example shows the use of a touchscreen with a custom widget
- to create a simple painting application.
-
- \image touch-fingerpaint-example.png
-
- This example was specifically designed to work with a touchscreen, using
- QTouchEvent instead of QMouseEvent to handle user input over the custom
- widget. As a result, it is not possible to draw with the mouse cursor.
-*/
diff --git a/examples/widgets/touch/fingerpaint/fingerpaint.pro b/examples/widgets/touch/fingerpaint/fingerpaint.pro
deleted file mode 100644
index 6370da6607..0000000000
--- a/examples/widgets/touch/fingerpaint/fingerpaint.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-qtHaveModule(printsupport): QT += printsupport
-
-HEADERS = mainwindow.h \
- scribblearea.h
-SOURCES = main.cpp \
- mainwindow.cpp \
- scribblearea.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/touch/fingerpaint
-INSTALLS += target
diff --git a/examples/widgets/touch/fingerpaint/main.cpp b/examples/widgets/touch/fingerpaint/main.cpp
deleted file mode 100644
index d283c7b85c..0000000000
--- a/examples/widgets/touch/fingerpaint/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.showMaximized();
- return app.exec();
-}
diff --git a/examples/widgets/touch/fingerpaint/mainwindow.cpp b/examples/widgets/touch/fingerpaint/mainwindow.cpp
deleted file mode 100644
index b9109fceeb..0000000000
--- a/examples/widgets/touch/fingerpaint/mainwindow.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-
-#include "mainwindow.h"
-#include "scribblearea.h"
-
-//! [0]
-MainWindow::MainWindow()
-{
- scribbleArea = new ScribbleArea;
- setCentralWidget(scribbleArea);
-
- createActions();
- createMenus();
-
- setWindowTitle(tr("Finger Paint"));
- resize(500, 500);
-}
-//! [0]
-
-//! [1]
-void MainWindow::closeEvent(QCloseEvent *event)
-//! [1] //! [2]
-{
- if (maybeSave()) {
- event->accept();
- } else {
- event->ignore();
- }
-}
-//! [2]
-
-//! [3]
-void MainWindow::open()
-//! [3] //! [4]
-{
- if (maybeSave()) {
- QString fileName = QFileDialog::getOpenFileName(this,
- tr("Open File"), QDir::currentPath());
- if (!fileName.isEmpty())
- scribbleArea->openImage(fileName);
- }
-}
-//! [4]
-
-//! [5]
-void MainWindow::save()
-//! [5] //! [6]
-{
- QAction *action = qobject_cast<QAction *>(sender());
- QByteArray fileFormat = action->data().toByteArray();
- saveFile(fileFormat);
-}
-//! [6]
-
-//! [11]
-void MainWindow::about()
-//! [11] //! [12]
-{
- QMessageBox::about(this, tr("About Scribble"),
- tr("<p>The <b>Scribble</b> example shows how to use QMainWindow as the "
- "base widget for an application, and how to reimplement some of "
- "QWidget's event handlers to receive the events generated for "
- "the application's widgets:</p><p> We reimplement the mouse event "
- "handlers to facilitate drawing, the paint event handler to "
- "update the application and the resize event handler to optimize "
- "the application's appearance. In addition we reimplement the "
- "close event handler to intercept the close events before "
- "terminating the application.</p><p> The example also demonstrates "
- "how to use QPainter to draw an image in real time, as well as "
- "to repaint widgets.</p>"));
-}
-//! [12]
-
-//! [13]
-void MainWindow::createActions()
-//! [13] //! [14]
-{
- openAct = new QAction(tr("&Open..."), this);
- openAct->setShortcut(tr("Ctrl+O"));
- connect(openAct, &QAction::triggered, this, &MainWindow::open);
-
- const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats();
- for (const QByteArray &format : imageFormats) {
- QString text = tr("%1...").arg(QString(format).toUpper());
-
- QAction *action = new QAction(text, this);
- action->setData(format);
- connect(action, &QAction::triggered, this, &MainWindow::save);
- saveAsActs.append(action);
- }
-
- printAct = new QAction(tr("&Print..."), this);
- connect(printAct, &QAction::triggered, scribbleArea, &ScribbleArea::print);
-
- exitAct = new QAction(tr("E&xit"), this);
- exitAct->setShortcut(tr("Ctrl+Q"));
- connect(exitAct, &QAction::triggered, this, &QWidget::close);
-
- clearScreenAct = new QAction(tr("&Clear Screen"), this);
- clearScreenAct->setShortcut(tr("Ctrl+L"));
- connect(clearScreenAct, &QAction::triggered,
- scribbleArea, &ScribbleArea::clearImage);
-
- aboutAct = new QAction(tr("&About"), this);
- connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
-
- aboutQtAct = new QAction(tr("About &Qt"), this);
- connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
-}
-//! [14]
-
-//! [15]
-void MainWindow::createMenus()
-//! [15] //! [16]
-{
- saveAsMenu = new QMenu(tr("&Save As"), this);
- saveAsMenu->addActions(saveAsActs);
-
- fileMenu = new QMenu(tr("&File"), this);
- fileMenu->addAction(openAct);
- fileMenu->addMenu(saveAsMenu);
- fileMenu->addAction(printAct);
- fileMenu->addSeparator();
- fileMenu->addAction(exitAct);
-
- optionMenu = new QMenu(tr("&Options"), this);
- optionMenu->addAction(clearScreenAct);
-
- helpMenu = new QMenu(tr("&Help"), this);
- helpMenu->addAction(aboutAct);
- helpMenu->addAction(aboutQtAct);
-
- menuBar()->addMenu(fileMenu);
- menuBar()->addMenu(optionMenu);
- menuBar()->addMenu(helpMenu);
-}
-//! [16]
-
-//! [17]
-bool MainWindow::maybeSave()
-//! [17] //! [18]
-{
- if (scribbleArea->isModified()) {
- QMessageBox::StandardButton ret;
- ret = QMessageBox::warning(this, tr("Scribble"),
- tr("The image has been modified.\n"
- "Do you want to save your changes?"),
- QMessageBox::Save | QMessageBox::Discard
- | QMessageBox::Cancel);
- if (ret == QMessageBox::Save) {
- return saveFile("png");
- } else if (ret == QMessageBox::Cancel) {
- return false;
- }
- }
- return true;
-}
-//! [18]
-
-//! [19]
-bool MainWindow::saveFile(const QByteArray &fileFormat)
-//! [19] //! [20]
-{
- QString initialPath = QDir::currentPath() + "/untitled." + fileFormat;
-
- QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
- initialPath,
- tr("%1 Files (*.%2);;All Files (*)")
- .arg(QString::fromLatin1(fileFormat.toUpper()))
- .arg(QString::fromLatin1(fileFormat)));
- if (fileName.isEmpty()) {
- return false;
- } else {
- return scribbleArea->saveImage(fileName, fileFormat.constData());
- }
-}
-//! [20]
diff --git a/examples/widgets/touch/fingerpaint/mainwindow.h b/examples/widgets/touch/fingerpaint/mainwindow.h
deleted file mode 100644
index a4aac1e36b..0000000000
--- a/examples/widgets/touch/fingerpaint/mainwindow.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QList>
-#include <QMainWindow>
-
-class ScribbleArea;
-
-//! [0]
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
-protected:
- void closeEvent(QCloseEvent *event) override;
-
-private slots:
- void open();
- void save();
- void about();
-
-private:
- void createActions();
- void createMenus();
- bool maybeSave();
- bool saveFile(const QByteArray &fileFormat);
-
- ScribbleArea *scribbleArea;
-
- QMenu *saveAsMenu;
- QMenu *fileMenu;
- QMenu *optionMenu;
- QMenu *helpMenu;
-
- QAction *openAct;
- QList<QAction *> saveAsActs;
- QAction *exitAct;
- QAction *printAct;
- QAction *clearScreenAct;
- QAction *aboutAct;
- QAction *aboutQtAct;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/touch/fingerpaint/scribblearea.cpp b/examples/widgets/touch/fingerpaint/scribblearea.cpp
deleted file mode 100644
index fb5e62906b..0000000000
--- a/examples/widgets/touch/fingerpaint/scribblearea.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtWidgets>
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#if QT_CONFIG(printdialog)
-#include <QPrinter>
-#include <QPrintDialog>
-#endif
-#endif
-
-#include "scribblearea.h"
-
-static const qreal MinimumDiameter = 3.0;
-static const qreal MaximumDiameter = 50.0;
-
-//! [0]
-ScribbleArea::ScribbleArea(QWidget *parent)
- : QWidget(parent)
-{
- setAttribute(Qt::WA_AcceptTouchEvents);
- setAttribute(Qt::WA_StaticContents);
- modified = false;
-
- myPenColors
- << QColor("green")
- << QColor("purple")
- << QColor("red")
- << QColor("blue")
- << QColor("yellow")
-
- << QColor("pink")
- << QColor("orange")
- << QColor("brown")
- << QColor("grey")
- << QColor("black");
-}
-//! [0]
-
-//! [1]
-bool ScribbleArea::openImage(const QString &fileName)
-//! [1] //! [2]
-{
- QImage loadedImage;
- if (!loadedImage.load(fileName))
- return false;
-
- QSize newSize = loadedImage.size().expandedTo(size());
- resizeImage(&loadedImage, newSize);
- image = loadedImage;
- modified = false;
- update();
- return true;
-}
-//! [2]
-
-//! [3]
-bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat)
-//! [3] //! [4]
-{
- QImage visibleImage = image;
- resizeImage(&visibleImage, size());
-
- if (visibleImage.save(fileName, fileFormat)) {
- modified = false;
- return true;
- } else {
- return false;
- }
-}
-//! [4]
-
-//! [9]
-void ScribbleArea::clearImage()
-//! [9] //! [10]
-{
- image.fill(qRgb(255, 255, 255));
- modified = true;
- update();
-}
-//! [10]
-
-//! [12] //! [13]
-void ScribbleArea::paintEvent(QPaintEvent *event)
-//! [13] //! [14]
-{
- QPainter painter(this);
- const QRect rect = event->rect();
- painter.drawImage(rect.topLeft(), image, rect);
-}
-//! [14]
-
-//! [15]
-void ScribbleArea::resizeEvent(QResizeEvent *event)
-//! [15] //! [16]
-{
- if (width() > image.width() || height() > image.height()) {
- int newWidth = qMax(width() + 128, image.width());
- int newHeight = qMax(height() + 128, image.height());
- resizeImage(&image, QSize(newWidth, newHeight));
- update();
- }
- QWidget::resizeEvent(event);
-}
-//! [16]
-
-//! [19]
-void ScribbleArea::resizeImage(QImage *image, const QSize &newSize)
-//! [19] //! [20]
-{
- if (image->size() == newSize)
- return;
-
- QImage newImage(newSize, QImage::Format_RGB32);
- newImage.fill(qRgb(255, 255, 255));
- QPainter painter(&newImage);
- painter.drawImage(QPoint(0, 0), *image);
- *image = newImage;
-}
-//! [20]
-
-//! [21]
-void ScribbleArea::print()
-{
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
- QPrinter printer(QPrinter::HighResolution);
-
- QPrintDialog printDialog(&printer, this);
-//! [21] //! [22]
- if (printDialog.exec() == QDialog::Accepted) {
- QPainter painter(&printer);
- QRect rect = painter.viewport();
- QSize size = image.size();
- size.scale(rect.size(), Qt::KeepAspectRatio);
- painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
- painter.setWindow(image.rect());
- painter.drawImage(0, 0, image);
- }
-#endif // QT_CONFIG(printdialog)
-}
-//! [22]
-
-bool ScribbleArea::event(QEvent *event)
-{
- switch (event->type()) {
- case QEvent::TouchBegin:
- case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
- {
- const QTouchEvent *touch = static_cast<QTouchEvent *>(event);
- const auto touchPoints = static_cast<QTouchEvent *>(event)->points();
- for (const QTouchEvent::TouchPoint &touchPoint : touchPoints) {
- switch (touchPoint.state()) {
- case QEventPoint::Stationary:
- case QEventPoint::Released:
- // don't do anything if this touch point hasn't moved or has been released
- continue;
- default:
- {
- QSizeF diams = touchPoint.ellipseDiameters();
- if (diams.isEmpty()) {
- qreal diameter = MaximumDiameter;
- if (touch->pointingDevice()->capabilities().testFlag(QPointingDevice::Capability::Pressure))
- diameter = MinimumDiameter + (MaximumDiameter - MinimumDiameter) * touchPoint.pressure();
- diams = QSizeF(diameter, diameter);
- }
-
- QPainter painter(&image);
- painter.setPen(Qt::NoPen);
- painter.setBrush(myPenColors.at(touchPoint.id() % myPenColors.count()));
- painter.drawEllipse(touchPoint.position(), diams.width() / 2, diams.height() / 2);
- painter.end();
-
- modified = true;
- const int rad = 2;
- QRectF rect(QPointF(), diams);
- rect.moveCenter(touchPoint.position());
- update(rect.toRect().adjusted(-rad,-rad, +rad, +rad));
- }
- break;
- }
- }
- break;
- }
- default:
- return QWidget::event(event);
- }
- return true;
-}
diff --git a/examples/widgets/touch/fingerpaint/scribblearea.h b/examples/widgets/touch/fingerpaint/scribblearea.h
deleted file mode 100644
index 624f07074a..0000000000
--- a/examples/widgets/touch/fingerpaint/scribblearea.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SCRIBBLEAREA_H
-#define SCRIBBLEAREA_H
-
-#include <QColor>
-#include <QImage>
-#include <QPoint>
-#include <QWidget>
-
-//! [0]
-class ScribbleArea : public QWidget
-{
- Q_OBJECT
-
-public:
- ScribbleArea(QWidget *parent = nullptr);
-
- bool openImage(const QString &fileName);
- bool saveImage(const QString &fileName, const char *fileFormat);
-
- bool isModified() const { return modified; }
-
-public slots:
- void clearImage();
- void print();
-
-protected:
- void paintEvent(QPaintEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
- bool event(QEvent *event) override;
-
-private:
- void resizeImage(QImage *image, const QSize &newSize);
-
- bool modified;
- QList<QColor> myPenColors;
- QImage image;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/touch/knobs/CMakeLists.txt b/examples/widgets/touch/knobs/CMakeLists.txt
index a3bf201285..eae0e58b36 100644
--- a/examples/widgets/touch/knobs/CMakeLists.txt
+++ b/examples/widgets/touch/knobs/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(knobs LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/touch/knobs")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(knobs PRIVATE
)
install(TARGETS knobs
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET knobs
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/touch/knobs/doc/images/touch-knobs-example.png b/examples/widgets/touch/knobs/doc/images/touch-knobs-example.png
index 1cbd90d101..7b75ff377c 100644
--- a/examples/widgets/touch/knobs/doc/images/touch-knobs-example.png
+++ b/examples/widgets/touch/knobs/doc/images/touch-knobs-example.png
Binary files differ
diff --git a/examples/widgets/touch/knobs/doc/src/touch-knobs.qdoc b/examples/widgets/touch/knobs/doc/src/touch-knobs.qdoc
index 3a41c5005b..fc6daa3732 100644
--- a/examples/widgets/touch/knobs/doc/src/touch-knobs.qdoc
+++ b/examples/widgets/touch/knobs/doc/src/touch-knobs.qdoc
@@ -4,6 +4,7 @@
/*!
\example touch/knobs
\title Touch Knobs Example
+ \examplecategory {User Interface Components}
\ingroup touchinputexamples
\brief Shows how to create custom controls that accept touch input.
diff --git a/examples/widgets/touch/knobs/main.cpp b/examples/widgets/touch/knobs/main.cpp
index 6f6910b4ae..74b64a99eb 100644
--- a/examples/widgets/touch/knobs/main.cpp
+++ b/examples/widgets/touch/knobs/main.cpp
@@ -12,6 +12,7 @@ int main(int argc, char **argv)
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setRenderHints(QPainter::Antialiasing);
Knob *knob1 = new Knob;
knob1->setPos(-110, 0);
diff --git a/examples/widgets/touch/pinchzoom/CMakeLists.txt b/examples/widgets/touch/pinchzoom/CMakeLists.txt
deleted file mode 100644
index deccfd0643..0000000000
--- a/examples/widgets/touch/pinchzoom/CMakeLists.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(pinchzoom LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/touch/pinchzoom")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(pinchzoom
- graphicsview.cpp graphicsview.h
- main.cpp
- mouse.cpp mouse.h
-)
-
-set_target_properties(pinchzoom PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(pinchzoom PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(mice_resource_files
- "images/cheese.jpg"
-)
-
-qt_add_resources(pinchzoom "mice"
- PREFIX
- "/"
- FILES
- ${mice_resource_files}
-)
-
-install(TARGETS pinchzoom
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/touch/pinchzoom/doc/images/pinch-zoom-example.png b/examples/widgets/touch/pinchzoom/doc/images/pinch-zoom-example.png
deleted file mode 100644
index 7db51fbf55..0000000000
--- a/examples/widgets/touch/pinchzoom/doc/images/pinch-zoom-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/touch/pinchzoom/doc/src/pinchzoom.qdoc b/examples/widgets/touch/pinchzoom/doc/src/pinchzoom.qdoc
deleted file mode 100644
index aef5c59407..0000000000
--- a/examples/widgets/touch/pinchzoom/doc/src/pinchzoom.qdoc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example touch/pinchzoom
- \title Pinch Zoom Example
- \ingroup touchinputexamples
- \brief Shows how to recognize a gesture.
-
- The Pinch Zoom example shows how to use low-level touch information
- to recognize a gesture.
-
- \image touch-pinchzoom-example.png
-*/
diff --git a/examples/widgets/touch/pinchzoom/graphicsview.cpp b/examples/widgets/touch/pinchzoom/graphicsview.cpp
deleted file mode 100644
index 61042e7e02..0000000000
--- a/examples/widgets/touch/pinchzoom/graphicsview.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "graphicsview.h"
-
-#include <QScrollBar>
-#include <QTouchEvent>
-
-GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent)
- : QGraphicsView(scene, parent)
-{
- viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
- setDragMode(ScrollHandDrag);
-}
-
-bool GraphicsView::viewportEvent(QEvent *event)
-{
- switch (event->type()) {
- case QEvent::TouchBegin:
- case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
- {
- QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- const auto touchPoints = touchEvent->points();
- if (touchPoints.count() == 2) {
- // determine scale factor
- const QEventPoint &touchPoint0 = touchPoints.first();
- const QEventPoint &touchPoint1 = touchPoints.last();
- qreal currentScaleFactor =
- QLineF(touchPoint0.position(), touchPoint1.position()).length()
- / QLineF(touchPoint0.pressPosition(), touchPoint1.pressPosition()).length();
- if (touchEvent->touchPointStates() & QEventPoint::Released) {
- // if one of the fingers is released, remember the current scale
- // factor so that adding another finger later will continue zooming
- // by adding new scale factor to the existing remembered value.
- totalScaleFactor *= currentScaleFactor;
- currentScaleFactor = 1;
- }
- setTransform(QTransform::fromScale(totalScaleFactor * currentScaleFactor,
- totalScaleFactor * currentScaleFactor));
- }
- return true;
- }
- default:
- break;
- }
- return QGraphicsView::viewportEvent(event);
-}
diff --git a/examples/widgets/touch/pinchzoom/graphicsview.h b/examples/widgets/touch/pinchzoom/graphicsview.h
deleted file mode 100644
index e6a300f418..0000000000
--- a/examples/widgets/touch/pinchzoom/graphicsview.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#pragma once
-#include <QGraphicsView>
-
-class GraphicsView : public QGraphicsView
-{
- Q_OBJECT
-
-public:
- GraphicsView(QGraphicsScene *scene = nullptr, QWidget *parent = nullptr);
-
- bool viewportEvent(QEvent *event) override;
-
-private:
- qreal totalScaleFactor = 1;
-};
diff --git a/examples/widgets/touch/pinchzoom/images/cheese.jpg b/examples/widgets/touch/pinchzoom/images/cheese.jpg
deleted file mode 100644
index dea5795fd0..0000000000
--- a/examples/widgets/touch/pinchzoom/images/cheese.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/touch/pinchzoom/main.cpp b/examples/widgets/touch/pinchzoom/main.cpp
deleted file mode 100644
index 85b5cad1f8..0000000000
--- a/examples/widgets/touch/pinchzoom/main.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "graphicsview.h"
-#include "mouse.h"
-
-#include <QApplication>
-#include <cmath>
-
-static constexpr int MouseCount = 7;
-
-//! [0]
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
-//! [0]
-
-//! [1]
- QGraphicsScene scene;
- scene.setSceneRect(-300, -300, 600, 600);
-//! [1] //! [2]
- scene.setItemIndexMethod(QGraphicsScene::NoIndex);
-//! [2]
-
-//! [3]
- for (int i = 0; i < MouseCount; ++i) {
- Mouse *mouse = new Mouse;
- mouse->setPos(::sin((i * 6.28) / MouseCount) * 200,
- ::cos((i * 6.28) / MouseCount) * 200);
- scene.addItem(mouse);
- }
-//! [3]
-
-//! [4]
- GraphicsView view(&scene);
- view.setRenderHint(QPainter::Antialiasing);
- view.setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
-//! [4] //! [5]
- view.setCacheMode(QGraphicsView::CacheBackground);
- view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
-//! [5] //! [6]
- view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
- view.showMaximized();
-
- return app.exec();
-}
-//! [6]
diff --git a/examples/widgets/touch/pinchzoom/mice.qrc b/examples/widgets/touch/pinchzoom/mice.qrc
deleted file mode 100644
index accdb4d0a6..0000000000
--- a/examples/widgets/touch/pinchzoom/mice.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>images/cheese.jpg</file>
- </qresource>
-</RCC>
diff --git a/examples/widgets/touch/pinchzoom/mouse.cpp b/examples/widgets/touch/pinchzoom/mouse.cpp
deleted file mode 100644
index ae0d497833..0000000000
--- a/examples/widgets/touch/pinchzoom/mouse.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mouse.h"
-
-#include <QGraphicsScene>
-#include <QPainter>
-#include <QRandomGenerator>
-#include <QStyleOption>
-#include <qmath.h>
-
-constexpr qreal Pi = M_PI;
-constexpr qreal TwoPi = 2 * M_PI;
-
-static qreal normalizeAngle(qreal angle)
-{
- while (angle < 0)
- angle += TwoPi;
- while (angle > TwoPi)
- angle -= TwoPi;
- return angle;
-}
-
-//! [0]
-Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256),
- QRandomGenerator::global()->bounded(256),
- QRandomGenerator::global()->bounded(256))
-{
- setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(360 * 16)), true);
- startTimer(1000 / 33);
-}
-//! [0]
-
-//! [1]
-QRectF Mouse::boundingRect() const
-{
- qreal adjust = 0.5;
- return QRectF(-18 - adjust, -22 - adjust,
- 36 + adjust, 60 + adjust);
-}
-//! [1]
-
-//! [2]
-QPainterPath Mouse::shape() const
-{
- QPainterPath path;
- path.addRect(-10, -20, 20, 40);
- return path;
-}
-//! [2]
-
-//! [3]
-void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
-{
- // Body
- painter->setBrush(color);
- painter->drawEllipse(-10, -20, 20, 40);
-
- // Eyes
- painter->setBrush(Qt::white);
- painter->drawEllipse(-10, -17, 8, 8);
- painter->drawEllipse(2, -17, 8, 8);
-
- // Nose
- painter->setBrush(Qt::black);
- painter->drawEllipse(QRectF(-2, -22, 4, 4));
-
- // Pupils
- painter->drawEllipse(QRectF(-8.0 + mouseEyeDirection, -17, 4, 4));
- painter->drawEllipse(QRectF(4.0 + mouseEyeDirection, -17, 4, 4));
-
- // Ears
- painter->setBrush(scene()->collidingItems(this).isEmpty() ? Qt::darkYellow : Qt::red);
- painter->drawEllipse(-17, -12, 16, 16);
- painter->drawEllipse(1, -12, 16, 16);
-
- // Tail
- QPainterPath path(QPointF(0, 20));
- path.cubicTo(-5, 22, -5, 22, 0, 25);
- path.cubicTo(5, 27, 5, 32, 0, 30);
- path.cubicTo(-5, 32, -5, 42, 0, 35);
- painter->setBrush(Qt::NoBrush);
- painter->drawPath(path);
-}
-//! [3]
-
-//! [4]
-void Mouse::timerEvent(QTimerEvent *)
-{
-//! [4]
- // Don't move too far away
-//! [5]
- QLineF lineToCenter(QPointF(0, 0), mapFromScene(0, 0));
- if (lineToCenter.length() > 150) {
- qreal angleToCenter = std::atan2(lineToCenter.dy(), lineToCenter.dx());
- angleToCenter = normalizeAngle((Pi - angleToCenter) + Pi / 2);
-
- if (angleToCenter < Pi && angleToCenter > Pi / 4) {
- // Rotate left
- angle += (angle < -Pi / 2) ? 0.25 : -0.25;
- } else if (angleToCenter >= Pi && angleToCenter < (Pi + Pi / 2 + Pi / 4)) {
- // Rotate right
- angle += (angle < Pi / 2) ? 0.25 : -0.25;
- }
- } else if (::sin(angle) < 0) {
- angle += 0.25;
- } else if (::sin(angle) > 0) {
- angle -= 0.25;
-//! [5] //! [6]
- }
-//! [6]
-
- // Try not to crash with any other mice
-//! [7]
- QList<QGraphicsItem *> dangerMice = scene()->items(QPolygonF()
- << mapToScene(0, 0)
- << mapToScene(-30, -50)
- << mapToScene(30, -50));
- for (QGraphicsItem *item : dangerMice) {
- if (item == this)
- continue;
-
- QLineF lineToMouse(QPointF(0, 0), mapFromItem(item, 0, 0));
- qreal angleToMouse = std::atan2(lineToMouse.dy(), lineToMouse.dx());
- angleToMouse = normalizeAngle((Pi - angleToMouse) + Pi / 2);
-
- if (angleToMouse >= 0 && angleToMouse < Pi / 2) {
- // Rotate right
- angle += 0.5;
- } else if (angleToMouse <= TwoPi && angleToMouse > (TwoPi - Pi / 2)) {
- // Rotate left
- angle -= 0.5;
-//! [7] //! [8]
- }
-//! [8] //! [9]
- }
-//! [9]
-
- // Add some random movement
-//! [10]
- if (dangerMice.size() > 1 && QRandomGenerator::global()->bounded(10) == 0) {
- if (QRandomGenerator::global()->bounded(1))
- angle += QRandomGenerator::global()->bounded(1 / 500.0);
- else
- angle -= QRandomGenerator::global()->bounded(1 / 500.0);
- }
-//! [10]
-
-//! [11]
- speed += (-50 + QRandomGenerator::global()->bounded(100)) / 100.0;
-
- qreal dx = ::sin(angle) * 10;
- mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5;
-
- setTransform(QTransform().rotate(dx), true);
- setPos(mapToParent(0, -(3 + sin(speed) * 3)));
-}
-//! [11]
diff --git a/examples/widgets/touch/pinchzoom/mouse.h b/examples/widgets/touch/pinchzoom/mouse.h
deleted file mode 100644
index 6b3ef98c22..0000000000
--- a/examples/widgets/touch/pinchzoom/mouse.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MOUSE_H
-#define MOUSE_H
-
-#include <QGraphicsObject>
-
-//! [0]
-class Mouse : public QGraphicsObject
-{
- Q_OBJECT
-
-public:
- Mouse();
-
- QRectF boundingRect() const override;
- QPainterPath shape() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget) override;
-
-protected:
- void timerEvent(QTimerEvent *event) override;
-
-private:
- qreal angle = 0;
- qreal speed = 0;
- qreal mouseEyeDirection = 0;
- QColor color;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/touch/pinchzoom/pinchzoom.pro b/examples/widgets/touch/pinchzoom/pinchzoom.pro
deleted file mode 100644
index ebbc7ddf1f..0000000000
--- a/examples/widgets/touch/pinchzoom/pinchzoom.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-QT += widgets
-
-HEADERS += \
- mouse.h \
- graphicsview.h
-SOURCES += \
- main.cpp \
- mouse.cpp \
- graphicsview.cpp
-
-RESOURCES += \
- mice.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/touch/pinchzoom
-INSTALLS += target
diff --git a/examples/widgets/touch/touch.pro b/examples/widgets/touch/touch.pro
index 018ec134eb..4fff58e074 100644
--- a/examples/widgets/touch/touch.pro
+++ b/examples/widgets/touch/touch.pro
@@ -1,4 +1,4 @@
requires(qtHaveModule(widgets))
TEMPLATE = subdirs
-SUBDIRS = pinchzoom fingerpaint knobs dials
+SUBDIRS = knobs
diff --git a/examples/widgets/tutorials/CMakeLists.txt b/examples/widgets/tutorials/CMakeLists.txt
index 548c96270a..e1192d9c6f 100644
--- a/examples/widgets/tutorials/CMakeLists.txt
+++ b/examples/widgets/tutorials/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
add_subdirectory(widgets)
add_subdirectory(modelview)
diff --git a/examples/widgets/tutorials/modelview/1_readonly/CMakeLists.txt b/examples/widgets/tutorials/modelview/1_readonly/CMakeLists.txt
index d3aa1e7b05..3ff7f06721 100644
--- a/examples/widgets/tutorials/modelview/1_readonly/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/1_readonly/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mv_readonly LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/1_readonly")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(mv_readonly PRIVATE
)
install(TARGETS mv_readonly
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mv_readonly
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/modelview/2_formatting/CMakeLists.txt b/examples/widgets/tutorials/modelview/2_formatting/CMakeLists.txt
index 8a9053667d..a758b6eaa5 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/2_formatting/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mv_formatting LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/2_formatting")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(mv_formatting PRIVATE
)
install(TARGETS mv_formatting
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mv_formatting
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/CMakeLists.txt b/examples/widgets/tutorials/modelview/3_changingmodel/CMakeLists.txt
index 554f75838a..1b8dd84c92 100644
--- a/examples/widgets/tutorials/modelview/3_changingmodel/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/3_changingmodel/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mv_changingmodel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/3_changingmodel")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(mv_changingmodel PRIVATE
)
install(TARGETS mv_changingmodel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mv_changingmodel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/modelview/4_headers/CMakeLists.txt b/examples/widgets/tutorials/modelview/4_headers/CMakeLists.txt
index bbf4bc178b..b0c05e4212 100644
--- a/examples/widgets/tutorials/modelview/4_headers/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/4_headers/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mv_headers LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/4_headers")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(mv_headers PRIVATE
)
install(TARGETS mv_headers
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mv_headers
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/modelview/5_edit/CMakeLists.txt b/examples/widgets/tutorials/modelview/5_edit/CMakeLists.txt
index f7d74ed2bf..f0269ac2bc 100644
--- a/examples/widgets/tutorials/modelview/5_edit/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/5_edit/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mv_edit LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/5_edit")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(mv_edit PRIVATE
)
install(TARGETS mv_edit
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mv_edit
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/modelview/6_treeview/CMakeLists.txt b/examples/widgets/tutorials/modelview/6_treeview/CMakeLists.txt
index b9035feb23..2a47ebc24a 100644
--- a/examples/widgets/tutorials/modelview/6_treeview/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/6_treeview/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mv_tree LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/6_treeview")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(mv_tree PRIVATE
)
install(TARGETS mv_tree
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mv_tree
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/modelview/7_selections/CMakeLists.txt b/examples/widgets/tutorials/modelview/7_selections/CMakeLists.txt
index dc8d8bc136..0eda358808 100644
--- a/examples/widgets/tutorials/modelview/7_selections/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/7_selections/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(mv_selections LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/7_selections")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(mv_selections PRIVATE
)
install(TARGETS mv_selections
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET mv_selections
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/modelview/CMakeLists.txt b/examples/widgets/tutorials/modelview/CMakeLists.txt
index feaacbcc2d..cbf36834cb 100644
--- a/examples/widgets/tutorials/modelview/CMakeLists.txt
+++ b/examples/widgets/tutorials/modelview/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(1_readonly)
qt_internal_add_example(2_formatting)
diff --git a/examples/widgets/tutorials/notepad/CMakeLists.txt b/examples/widgets/tutorials/notepad/CMakeLists.txt
index 5c1592feef..43048830c2 100644
--- a/examples/widgets/tutorials/notepad/CMakeLists.txt
+++ b/examples/widgets/tutorials/notepad/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(notepad LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/notepad")
-
find_package(Qt6
REQUIRED COMPONENTS Core Gui Widgets
OPTIONAL_COMPONENTS PrintSupport
@@ -67,7 +61,14 @@ qt_add_resources(notepad "notepad"
)
install(TARGETS notepad
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET notepad
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/notepad/gettingstartedqt.qdoc b/examples/widgets/tutorials/notepad/gettingstartedqt.qdoc
index 152bf8c114..0979cecb18 100644
--- a/examples/widgets/tutorials/notepad/gettingstartedqt.qdoc
+++ b/examples/widgets/tutorials/notepad/gettingstartedqt.qdoc
@@ -4,6 +4,7 @@
/*!
\example tutorials/notepad
\title Getting Started Programming with Qt Widgets
+ \examplecategory {User Interface Components}
\brief A tutorial for Qt Widgets based notepad application.
In this topic, we teach basic Qt knowledge by implementing a simple
@@ -142,25 +143,25 @@
The wizard generates a user interface definition in XML format: notepad.ui.
When you open the notepad.ui file in Qt Creator, it automatically
- opens in the integrated Qt Designer.
+ opens in the integrated \QD.
When you build the application, Qt Creator launches the Qt
\l{User Interface Compiler (uic)} that reads the .ui file and creates
a corresponding C++ header file, ui_notepad.h.
- \section2 Using Qt Designer
+ \section2 Using \QD
The wizard creates an application that uses a QMainWindow. It has
its own layout to which you can add a menu bar, dock widgets, toolbars,
and a status bar. The center area can be occupied by any kind of widget.
The wizard places the Notepad widget there.
- To add widgets in Qt Designer:
+ To add widgets in \QD:
\list 1
\li In the Qt Creator \uicontrol Edit mode, double-click the notepad.ui
file in the \uicontrol Projects view to launch the file in the integrated
- Qt Designer.
+ \QD.
\li Drag and drop widgets Text Edit (QTextEdit) to the form.
\li Press \key {Ctrl+A} (or \key {Cmd+A}) to select the widgets and click
\uicontrol {Lay out Vertically} (or press \key {Ctrl+L}) to apply a vertical
@@ -168,7 +169,7 @@
\li Press \key {Ctrl+S} (or \key {Cmd+S}) to save your changes.
\endlist
- The UI now looks as follows in Qt Designer:
+ The UI now looks as follows in \QD:
\image notepad4.png
@@ -316,8 +317,8 @@
\li About
\li Here
\row
- \li Using Qt Designer
- \li \l{Qt Designer Manual}
+ \li Using \QD
+ \li \l{Qt Widgets Designer Manual}
\row
\li Layouts
\li \l{Layout Management},
@@ -487,10 +488,6 @@
\li About
\li Here
\row
- \li MDI applications
- \li QMdiArea,
- \l{MDI Example}
- \row
\li Files and I/O devices
\li QFile, QIODevice
\row
diff --git a/examples/widgets/tutorials/widgets/CMakeLists.txt b/examples/widgets/tutorials/widgets/CMakeLists.txt
index 6e8d3fa3e4..40590745a9 100644
--- a/examples/widgets/tutorials/widgets/CMakeLists.txt
+++ b/examples/widgets/tutorials/widgets/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(toplevel)
qt_internal_add_example(childwidget)
diff --git a/examples/widgets/tutorials/widgets/childwidget/CMakeLists.txt b/examples/widgets/tutorials/widgets/childwidget/CMakeLists.txt
index ce5a7f7327..a4f8b5b8a2 100644
--- a/examples/widgets/tutorials/widgets/childwidget/CMakeLists.txt
+++ b/examples/widgets/tutorials/widgets/childwidget/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(childwidget LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/widgets/childwidget")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(childwidget PRIVATE
)
install(TARGETS childwidget
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET childwidget
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/widgets/nestedlayouts/CMakeLists.txt b/examples/widgets/tutorials/widgets/nestedlayouts/CMakeLists.txt
index d1190f7085..cb6db0ec48 100644
--- a/examples/widgets/tutorials/widgets/nestedlayouts/CMakeLists.txt
+++ b/examples/widgets/tutorials/widgets/nestedlayouts/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(nestedlayouts LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/widgets/nestedlayouts")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(nestedlayouts PRIVATE
)
install(TARGETS nestedlayouts
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET nestedlayouts
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/widgets/toplevel/CMakeLists.txt b/examples/widgets/tutorials/widgets/toplevel/CMakeLists.txt
index ae7c582b8f..2d241556f9 100644
--- a/examples/widgets/tutorials/widgets/toplevel/CMakeLists.txt
+++ b/examples/widgets/tutorials/widgets/toplevel/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(toplevel LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/widgets/toplevel")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(toplevel PRIVATE
)
install(TARGETS toplevel
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET toplevel
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/tutorials/widgets/windowlayout/CMakeLists.txt b/examples/widgets/tutorials/widgets/windowlayout/CMakeLists.txt
index 7ad79cd31a..ea6e21e968 100644
--- a/examples/widgets/tutorials/widgets/windowlayout/CMakeLists.txt
+++ b/examples/widgets/tutorials/widgets/windowlayout/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(windowlayout LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/widgets/windowlayout")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(windowlayout PRIVATE
)
install(TARGETS windowlayout
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET windowlayout
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro
index 2dbbefa141..e8ac9d83bd 100644
--- a/examples/widgets/widgets.pro
+++ b/examples/widgets/widgets.pro
@@ -8,7 +8,6 @@ SUBDIRS = \
desktop \
dialogs \
draganddrop \
- effects \
gallery \
gestures \
graphicsview \
@@ -16,16 +15,13 @@ SUBDIRS = \
layouts \
mainwindows \
painting \
+ rhi \
richtext \
- scroller \
tools \
touch \
tutorials \
widgets
-qtHaveModule(gui):qtConfig(opengl): \
- SUBDIRS += windowcontainer
-
contains(DEFINES, QT_NO_CURSOR): SUBDIRS -= mainwindows
!qtConfig(draganddrop): SUBDIRS -= draganddrop
!qtConfig(animation): SUBDIRS -= animation
diff --git a/examples/widgets/widgets/CMakeLists.txt b/examples/widgets/widgets/CMakeLists.txt
index d852233c8d..feb3067727 100644
--- a/examples/widgets/widgets/CMakeLists.txt
+++ b/examples/widgets/widgets/CMakeLists.txt
@@ -1,27 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(analogclock)
qt_internal_add_example(calculator)
qt_internal_add_example(calendarwidget)
-qt_internal_add_example(charactermap)
-qt_internal_add_example(digitalclock)
-qt_internal_add_example(groupbox)
-qt_internal_add_example(icons)
-qt_internal_add_example(imageviewer)
qt_internal_add_example(lineedits)
-if(QT_FEATURE_movie)
- qt_internal_add_example(movie)
-endif()
qt_internal_add_example(scribble)
qt_internal_add_example(shapedclock)
qt_internal_add_example(shortcuteditor)
qt_internal_add_example(sliders)
qt_internal_add_example(spinboxes)
-qt_internal_add_example(styles)
-qt_internal_add_example(stylesheet)
qt_internal_add_example(tablet)
-qt_internal_add_example(tetrix)
-qt_internal_add_example(tooltips)
-qt_internal_add_example(validators)
qt_internal_add_example(windowflags)
diff --git a/examples/widgets/widgets/analogclock/CMakeLists.txt b/examples/widgets/widgets/analogclock/CMakeLists.txt
index 63e53d6717..82b9ef3928 100644
--- a/examples/widgets/widgets/analogclock/CMakeLists.txt
+++ b/examples/widgets/widgets/analogclock/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(analogclock LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/analogclock")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(analogclock PRIVATE
)
install(TARGETS analogclock
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET analogclock
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/analogclock/analogclock.cpp b/examples/widgets/widgets/analogclock/analogclock.cpp
index ad94a16bab..feb7f4e8b5 100644
--- a/examples/widgets/widgets/analogclock/analogclock.cpp
+++ b/examples/widgets/widgets/analogclock/analogclock.cpp
@@ -31,19 +31,29 @@ AnalogClock::AnalogClock(QWidget *parent)
void AnalogClock::paintEvent(QPaintEvent *)
//! [8] //! [10]
{
- static const QPoint hourHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -40)
+ static const QPoint hourHand[4] = {
+ QPoint(5, 14),
+ QPoint(-5, 14),
+ QPoint(-4, -71),
+ QPoint(4, -71)
};
- static const QPoint minuteHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -70)
+ static const QPoint minuteHand[4] = {
+ QPoint(4, 14),
+ QPoint(-4, 14),
+ QPoint(-3, -89),
+ QPoint(3, -89)
};
- QColor hourColor(127, 0, 127);
- QColor minuteColor(0, 127, 127, 191);
+ static const QPoint secondsHand[4] = {
+ QPoint(1, 14),
+ QPoint(-1, 14),
+ QPoint(-1, -89),
+ QPoint(1, -89)
+ };
+
+ const QColor hourColor(palette().color(QPalette::Text));
+ const QColor minuteColor(palette().color(QPalette::Text));
+ const QColor secondsColor(palette().color(QPalette::Accent));
int side = qMin(width(), height());
//! [10]
@@ -54,9 +64,12 @@ void AnalogClock::paintEvent(QPaintEvent *)
painter.setRenderHint(QPainter::Antialiasing);
//! [12] //! [13]
painter.translate(width() / 2, height() / 2);
-//! [13] //! [14]
painter.scale(side / 200.0, side / 200.0);
-//! [9] //! [14]
+//! [9] //! [13]
+
+//! [14]
+ QTime time = QTime::currentTime();
+//! [14]
//! [15]
painter.setPen(Qt::NoPen);
@@ -64,36 +77,45 @@ void AnalogClock::paintEvent(QPaintEvent *)
painter.setBrush(hourColor);
//! [16]
//! [18]
- QTime time = QTime::currentTime();
+
//! [17]
painter.save();
//! [17] //! [19]
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
- painter.drawConvexPolygon(hourHand, 3);
+ painter.drawConvexPolygon(hourHand, 4);
painter.restore();
//! [18] //! [19]
//! [20]
- painter.setPen(hourColor);
-//! [20] //! [21]
-
for (int i = 0; i < 12; ++i) {
- painter.drawLine(88, 0, 96, 0);
+ painter.drawRect(73, -3, 16, 6);
painter.rotate(30.0);
}
+//! [20]
+
//! [21]
+ painter.setBrush(minuteColor);
//! [22]
- painter.setPen(Qt::NoPen);
-//! [22] //! [23]
- painter.setBrush(minuteColor);
+ painter.save();
+ painter.rotate(6.0 * time.minute());
+ painter.drawConvexPolygon(minuteHand, 4);
+ painter.restore();
+//! [21] //! [22]
+
+
+//! [23]
+ painter.setBrush(secondsColor);
+//! [23]
//! [24]
painter.save();
- painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
- painter.drawConvexPolygon(minuteHand, 3);
+ painter.rotate(6.0 * time.second());
+ painter.drawConvexPolygon(secondsHand, 4);
+ painter.drawEllipse(-3, -3, 6, 6);
+ painter.drawEllipse(-5, -68, 10, 10);
painter.restore();
-//! [23] //! [24]
+//! [24]
//! [25]
painter.setPen(minuteColor);
@@ -101,10 +123,10 @@ void AnalogClock::paintEvent(QPaintEvent *)
//! [27]
for (int j = 0; j < 60; ++j) {
- if ((j % 5) != 0)
- painter.drawLine(92, 0, 96, 0);
+ painter.drawLine(92, 0, 96, 0);
painter.rotate(6.0);
}
//! [27]
+
}
//! [26]
diff --git a/examples/widgets/widgets/calculator/CMakeLists.txt b/examples/widgets/widgets/calculator/CMakeLists.txt
index bcf69700c8..abf12d5663 100644
--- a/examples/widgets/widgets/calculator/CMakeLists.txt
+++ b/examples/widgets/widgets/calculator/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(calculator LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/calculator")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(calculator PRIVATE
)
install(TARGETS calculator
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET calculator
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/calendarwidget/CMakeLists.txt b/examples/widgets/widgets/calendarwidget/CMakeLists.txt
index 77ac2d08bc..9e8f7681ca 100644
--- a/examples/widgets/widgets/calendarwidget/CMakeLists.txt
+++ b/examples/widgets/widgets/calendarwidget/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(calendarwidget LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/calendarwidget")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(calendarwidget PRIVATE
)
install(TARGETS calendarwidget
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET calendarwidget
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/charactermap/CMakeLists.txt b/examples/widgets/widgets/charactermap/CMakeLists.txt
deleted file mode 100644
index f4ab35d614..0000000000
--- a/examples/widgets/widgets/charactermap/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(charactermap LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/charactermap")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(charactermap
- characterwidget.cpp characterwidget.h
- main.cpp
- mainwindow.cpp mainwindow.h
-)
-
-set_target_properties(charactermap PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(charactermap PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS charactermap
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/charactermap/charactermap.pro b/examples/widgets/widgets/charactermap/charactermap.pro
deleted file mode 100644
index 373aabca73..0000000000
--- a/examples/widgets/widgets/charactermap/charactermap.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = characterwidget.h \
- mainwindow.h
-SOURCES = characterwidget.cpp \
- mainwindow.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/charactermap
-INSTALLS += target
diff --git a/examples/widgets/widgets/charactermap/characterwidget.cpp b/examples/widgets/widgets/charactermap/characterwidget.cpp
deleted file mode 100644
index 6287a44e80..0000000000
--- a/examples/widgets/widgets/charactermap/characterwidget.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "characterwidget.h"
-
-#include <QFontDatabase>
-#include <QMouseEvent>
-#include <QPainter>
-#include <QToolTip>
-
-//! [0]
-CharacterWidget::CharacterWidget(QWidget *parent)
- : QWidget(parent)
-{
- calculateSquareSize();
- setMouseTracking(true);
-}
-//! [0]
-
-//! [1]
-void CharacterWidget::updateFont(const QFont &font)
-{
- displayFont.setFamily(font.family());
- calculateSquareSize();
- adjustSize();
- update();
-}
-//! [1]
-
-//! [2]
-void CharacterWidget::updateSize(const QString &fontSize)
-{
- displayFont.setPointSize(fontSize.toInt());
- calculateSquareSize();
- adjustSize();
- update();
-}
-//! [2]
-
-void CharacterWidget::updateStyle(const QString &fontStyle)
-{
- const QFont::StyleStrategy oldStrategy = displayFont.styleStrategy();
- displayFont = QFontDatabase::font(displayFont.family(), fontStyle, displayFont.pointSize());
- displayFont.setStyleStrategy(oldStrategy);
- calculateSquareSize();
- adjustSize();
- update();
-}
-
-void CharacterWidget::updateFontMerging(bool enable)
-{
- if (enable)
- displayFont.setStyleStrategy(QFont::PreferDefault);
- else
- displayFont.setStyleStrategy(QFont::NoFontMerging);
- adjustSize();
- update();
-}
-
-void CharacterWidget::calculateSquareSize()
-{
- squareSize = qMax(16, 4 + QFontMetrics(displayFont, this).height());
-}
-
-//! [3]
-QSize CharacterWidget::sizeHint() const
-{
- return QSize(columns*squareSize, (65536 / columns) * squareSize);
-}
-//! [3]
-
-//! [4]
-void CharacterWidget::mouseMoveEvent(QMouseEvent *event)
-{
- QPoint widgetPosition = mapFromGlobal(event->globalPosition().toPoint());
- uint key = (widgetPosition.y() / squareSize) * columns + widgetPosition.x() / squareSize;
-
- QString text = QString::fromLatin1("<p>Character: <span style=\"font-size: 24pt; font-family: %1\">").arg(displayFont.family())
- + QChar(key)
- + QString::fromLatin1("</span><p>Value: 0x")
- + QString::number(key, 16);
- QToolTip::showText(event->globalPosition().toPoint(), text, this);
-}
-//! [4]
-
-//! [5]
-void CharacterWidget::mousePressEvent(QMouseEvent *event)
-{
- if (event->button() == Qt::LeftButton) {
- lastKey = (event->position().toPoint().y() / squareSize) * columns + event->position().toPoint().x() / squareSize;
- if (QChar(lastKey).category() != QChar::Other_NotAssigned)
- emit characterSelected(QString(QChar(lastKey)));
- update();
- }
- else
- QWidget::mousePressEvent(event);
-}
-//! [5]
-
-//! [6]
-void CharacterWidget::paintEvent(QPaintEvent *event)
-{
- QPainter painter(this);
- painter.fillRect(event->rect(), QBrush(Qt::white));
- painter.setFont(displayFont);
-//! [6]
-
-//! [7]
- QRect redrawRect = event->rect();
- int beginRow = redrawRect.top() / squareSize;
- int endRow = redrawRect.bottom() / squareSize;
- int beginColumn = redrawRect.left() / squareSize;
- int endColumn = redrawRect.right() / squareSize;
-//! [7]
-
-//! [8]
- painter.setPen(QPen(Qt::gray));
- for (int row = beginRow; row <= endRow; ++row) {
- for (int column = beginColumn; column <= endColumn; ++column) {
- painter.drawRect(column * squareSize, row * squareSize, squareSize, squareSize);
- }
-//! [8] //! [9]
- }
-//! [9]
-
-//! [10]
- QFontMetrics fontMetrics(displayFont);
- painter.setPen(QPen(Qt::black));
- for (int row = beginRow; row <= endRow; ++row) {
- for (int column = beginColumn; column <= endColumn; ++column) {
- int key = row * columns + column;
- painter.setClipRect(column * squareSize, row * squareSize, squareSize, squareSize);
-
- if (key == lastKey)
- painter.fillRect(column * squareSize + 1, row * squareSize + 1,
- squareSize, squareSize, QBrush(Qt::red));
-
- painter.drawText(column * squareSize + (squareSize / 2) -
- fontMetrics.horizontalAdvance(QChar(key)) / 2,
- row * squareSize + 4 + fontMetrics.ascent(),
- QString(QChar(key)));
- }
- }
-}
-//! [10]
diff --git a/examples/widgets/widgets/charactermap/characterwidget.h b/examples/widgets/widgets/charactermap/characterwidget.h
deleted file mode 100644
index b8aa76d111..0000000000
--- a/examples/widgets/widgets/charactermap/characterwidget.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef CHARACTERWIDGET_H
-#define CHARACTERWIDGET_H
-
-#include <QFont>
-#include <QSize>
-#include <QString>
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QMouseEvent;
-class QPaintEvent;
-QT_END_NAMESPACE
-
-//! [0]
-class CharacterWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- CharacterWidget(QWidget *parent = nullptr);
- QSize sizeHint() const override;
-
-public slots:
- void updateFont(const QFont &font);
- void updateSize(const QString &fontSize);
- void updateStyle(const QString &fontStyle);
- void updateFontMerging(bool enable);
-
-signals:
- void characterSelected(const QString &character);
-
-protected:
- void mouseMoveEvent(QMouseEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
-
-private:
- void calculateSquareSize();
-
- QFont displayFont;
- int columns = 16;
- int lastKey = -1;
- int squareSize = 0;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/charactermap/main.cpp b/examples/widgets/widgets/charactermap/main.cpp
deleted file mode 100644
index 7d7cf3e573..0000000000
--- a/examples/widgets/widgets/charactermap/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
deleted file mode 100644
index fcc00f9642..0000000000
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "characterwidget.h"
-
-#include <QApplication>
-#include <QBoxLayout>
-#include <QCheckBox>
-#include <QClipboard>
-#include <QDialog>
-#include <QDialogButtonBox>
-#include <QFontComboBox>
-#include <QLabel>
-#include <QLineEdit>
-#include <QMenuBar>
-#include <QPlainTextEdit>
-#include <QPushButton>
-#include <QScreen>
-#include <QScrollArea>
-#include <QStatusBar>
-#include <QTextStream>
-
-//! [0]
-Q_DECLARE_METATYPE(QFontComboBox::FontFilter)
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("File"));
- fileMenu->addAction(tr("Quit"), this, &QWidget::close);
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(tr("Show Font Info"), this, &MainWindow::showInfo);
- helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
-
- QWidget *centralWidget = new QWidget;
-
- QLabel *filterLabel = new QLabel(tr("Filter:"));
- filterCombo = new QComboBox;
- filterCombo->addItem(tr("All"), QVariant::fromValue(QFontComboBox::AllFonts));
- filterCombo->addItem(tr("Scalable"), QVariant::fromValue(QFontComboBox::ScalableFonts));
- filterCombo->addItem(tr("Monospaced"), QVariant::fromValue(QFontComboBox::MonospacedFonts));
- filterCombo->addItem(tr("Proportional"), QVariant::fromValue(QFontComboBox::ProportionalFonts));
- filterCombo->setCurrentIndex(0);
- connect(filterCombo, &QComboBox::currentIndexChanged,
- this, &MainWindow::filterChanged);
-
- QLabel *fontLabel = new QLabel(tr("Font:"));
- fontCombo = new QFontComboBox;
- QLabel *sizeLabel = new QLabel(tr("Size:"));
- sizeCombo = new QComboBox;
- QLabel *styleLabel = new QLabel(tr("Style:"));
- styleCombo = new QComboBox;
- QLabel *fontMergingLabel = new QLabel(tr("Automatic Font Merging:"));
- fontMerging = new QCheckBox;
- fontMerging->setChecked(true);
-
- scrollArea = new QScrollArea;
- characterWidget = new CharacterWidget;
- scrollArea->setWidget(characterWidget);
-//! [0]
-
-//! [1]
- findStyles(fontCombo->currentFont());
-//! [1]
- findSizes(fontCombo->currentFont());
-
-//! [2]
- lineEdit = new QLineEdit;
- lineEdit->setClearButtonEnabled(true);
-#ifndef QT_NO_CLIPBOARD
- QPushButton *clipboardButton = new QPushButton(tr("&To clipboard"));
-//! [2]
-
-#endif
-
-//! [4]
- connect(fontCombo, &QFontComboBox::currentFontChanged,
- this, &MainWindow::findStyles);
- connect(fontCombo, &QFontComboBox::currentFontChanged,
- this, &MainWindow::findSizes);
- connect(fontCombo, &QFontComboBox::currentFontChanged,
- characterWidget, &CharacterWidget::updateFont);
- connect(sizeCombo, &QComboBox::currentTextChanged,
- characterWidget, &CharacterWidget::updateSize);
- connect(styleCombo, &QComboBox::currentTextChanged,
- characterWidget, &CharacterWidget::updateStyle);
-//! [4] //! [5]
- connect(characterWidget, &CharacterWidget::characterSelected,
- this, &MainWindow::insertCharacter);
-
-#ifndef QT_NO_CLIPBOARD
- connect(clipboardButton, &QAbstractButton::clicked, this, &MainWindow::updateClipboard);
-#endif
-//! [5]
- connect(fontMerging, &QAbstractButton::toggled, characterWidget, &CharacterWidget::updateFontMerging);
-
-//! [6]
- QHBoxLayout *controlsLayout = new QHBoxLayout;
- controlsLayout->addWidget(filterLabel);
- controlsLayout->addWidget(filterCombo, 1);
- controlsLayout->addWidget(fontLabel);
- controlsLayout->addWidget(fontCombo, 1);
- controlsLayout->addWidget(sizeLabel);
- controlsLayout->addWidget(sizeCombo, 1);
- controlsLayout->addWidget(styleLabel);
- controlsLayout->addWidget(styleCombo, 1);
- controlsLayout->addWidget(fontMergingLabel);
- controlsLayout->addWidget(fontMerging, 1);
- controlsLayout->addStretch(1);
-
- QHBoxLayout *lineLayout = new QHBoxLayout;
- lineLayout->addWidget(lineEdit, 1);
- lineLayout->addSpacing(12);
-#ifndef QT_NO_CLIPBOARD
- lineLayout->addWidget(clipboardButton);
-#endif
-
- QVBoxLayout *centralLayout = new QVBoxLayout;
- centralLayout->addLayout(controlsLayout);
- centralLayout->addWidget(scrollArea, 1);
- centralLayout->addSpacing(4);
- centralLayout->addLayout(lineLayout);
- centralWidget->setLayout(centralLayout);
-
- setCentralWidget(centralWidget);
- setWindowTitle(tr("Character Map"));
-}
-//! [6]
-
-//! [7]
-void MainWindow::findStyles(const QFont &font)
-{
- QString currentItem = styleCombo->currentText();
- styleCombo->clear();
-//! [7]
-
-//! [8]
- const QStringList styles = QFontDatabase::styles(font.family());
- for (const QString &style : styles)
- styleCombo->addItem(style);
-
- int styleIndex = styleCombo->findText(currentItem);
-
- if (styleIndex == -1)
- styleCombo->setCurrentIndex(0);
- else
- styleCombo->setCurrentIndex(styleIndex);
-}
-//! [8]
-
-void MainWindow::filterChanged(int f)
-{
- const QFontComboBox::FontFilter filter =
- qvariant_cast<QFontComboBox::FontFilter>(filterCombo->itemData(f));
- fontCombo->setFontFilters(filter);
- statusBar()->showMessage(tr("%n font(s) found", nullptr, fontCombo->count()));
-}
-
-void MainWindow::findSizes(const QFont &font)
-{
- QString currentSize = sizeCombo->currentText();
-
- {
- const QSignalBlocker blocker(sizeCombo);
- // sizeCombo signals are now blocked until end of scope
- sizeCombo->clear();
-
- if (QFontDatabase::isSmoothlyScalable(font.family(), QFontDatabase::styleString(font))) {
- const QList<int> sizes = QFontDatabase::standardSizes();
- for (const int size : sizes) {
- sizeCombo->addItem(QVariant(size).toString());
- sizeCombo->setEditable(true);
- }
-
- } else {
- const QList<int> sizes = QFontDatabase::smoothSizes(font.family(), QFontDatabase::styleString(font));
- for (const int size : sizes ) {
- sizeCombo->addItem(QVariant(size).toString());
- sizeCombo->setEditable(false);
- }
- }
- }
-
- int sizeIndex = sizeCombo->findText(currentSize);
-
- if(sizeIndex == -1)
- sizeCombo->setCurrentIndex(qMax(0, sizeCombo->count() / 3));
- else
- sizeCombo->setCurrentIndex(sizeIndex);
-}
-
-//! [9]
-void MainWindow::insertCharacter(const QString &character)
-{
- lineEdit->insert(character);
-}
-//! [9]
-
-//! [10]
-#ifndef QT_NO_CLIPBOARD
-void MainWindow::updateClipboard()
-{
-//! [11]
- QGuiApplication::clipboard()->setText(lineEdit->text(), QClipboard::Clipboard);
-//! [11]
- QGuiApplication::clipboard()->setText(lineEdit->text(), QClipboard::Selection);
-}
-#endif
-
-class FontInfoDialog : public QDialog
-{
-public:
- explicit FontInfoDialog(QWidget *parent = nullptr);
-
-private:
- QString text() const;
-};
-
-FontInfoDialog::FontInfoDialog(QWidget *parent) : QDialog(parent)
-{
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- QVBoxLayout *mainLayout = new QVBoxLayout(this);
- QPlainTextEdit *textEdit = new QPlainTextEdit(text(), this);
- textEdit->setReadOnly(true);
- textEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
- mainLayout->addWidget(textEdit);
- QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
- connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
- mainLayout->addWidget(buttonBox);
-}
-
-QString FontInfoDialog::text() const
-{
- QString text;
- QTextStream str(&text);
- const QFont defaultFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
- const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
- const QFont titleFont = QFontDatabase::systemFont(QFontDatabase::TitleFont);
- const QFont smallestReadableFont = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
-
- str << "Qt " << QT_VERSION_STR << " on " << QGuiApplication::platformName()
- << ", " << logicalDpiX() << "DPI";
- if (!qFuzzyCompare(devicePixelRatio(), qreal(1)))
- str << ", device pixel ratio: " << devicePixelRatio();
- str << "\n\nDefault font : " << defaultFont.family() << ", " << defaultFont.pointSizeF() << "pt\n"
- << "Fixed font : " << fixedFont.family() << ", " << fixedFont.pointSizeF() << "pt\n"
- << "Title font : " << titleFont.family() << ", " << titleFont.pointSizeF() << "pt\n"
- << "Smallest font: " << smallestReadableFont.family() << ", " << smallestReadableFont.pointSizeF() << "pt\n";
-
- return text;
-}
-
-void MainWindow::showInfo()
-{
- const QRect screenGeometry = screen()->geometry();
- FontInfoDialog *dialog = new FontInfoDialog(this);
- dialog->setWindowTitle(tr("Fonts"));
- dialog->setAttribute(Qt::WA_DeleteOnClose);
- dialog->resize(screenGeometry.width() / 4, screenGeometry.height() / 4);
- dialog->show();
-}
-
-//! [10]
diff --git a/examples/widgets/widgets/charactermap/mainwindow.h b/examples/widgets/widgets/charactermap/mainwindow.h
deleted file mode 100644
index b8f3c166eb..0000000000
--- a/examples/widgets/widgets/charactermap/mainwindow.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QString>
-
-QT_BEGIN_NAMESPACE
-class QClipboard;
-class QComboBox;
-class QFontComboBox;
-class QLineEdit;
-class QScrollArea;
-class QCheckBox;
-QT_END_NAMESPACE
-class CharacterWidget;
-
-//! [0]
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow(QWidget *parent = nullptr);
-
-public slots:
- void filterChanged(int);
- void findStyles(const QFont &font);
- void findSizes(const QFont &font);
- void insertCharacter(const QString &character);
-#ifndef QT_NO_CLIPBOARD
- void updateClipboard();
-#endif
- void showInfo();
-
-private:
- CharacterWidget *characterWidget;
- QComboBox *filterCombo;
- QComboBox *styleCombo;
- QComboBox *sizeCombo;
- QFontComboBox *fontCombo;
- QLineEdit *lineEdit;
- QScrollArea *scrollArea;
- QCheckBox *fontMerging;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/digitalclock/CMakeLists.txt b/examples/widgets/widgets/digitalclock/CMakeLists.txt
deleted file mode 100644
index 57cd80c492..0000000000
--- a/examples/widgets/widgets/digitalclock/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(digitalclock LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/digitalclock")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(digitalclock
- digitalclock.cpp digitalclock.h
- main.cpp
-)
-
-set_target_properties(digitalclock PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(digitalclock PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS digitalclock
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/digitalclock/digitalclock.cpp b/examples/widgets/widgets/digitalclock/digitalclock.cpp
deleted file mode 100644
index 4eec982c25..0000000000
--- a/examples/widgets/widgets/digitalclock/digitalclock.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "digitalclock.h"
-
-#include <QTime>
-#include <QTimer>
-
-//! [0]
-DigitalClock::DigitalClock(QWidget *parent)
- : QLCDNumber(parent)
-{
- setSegmentStyle(Filled);
-
- QTimer *timer = new QTimer(this);
- connect(timer, &QTimer::timeout, this, &DigitalClock::showTime);
- timer->start(1000);
-
- showTime();
-
- setWindowTitle(tr("Digital Clock"));
- resize(150, 60);
-}
-//! [0]
-
-//! [1]
-void DigitalClock::showTime()
-//! [1] //! [2]
-{
- QTime time = QTime::currentTime();
- QString text = time.toString("hh:mm");
- if ((time.second() % 2) == 0)
- text[2] = ' ';
- display(text);
-}
-//! [2]
diff --git a/examples/widgets/widgets/digitalclock/digitalclock.h b/examples/widgets/widgets/digitalclock/digitalclock.h
deleted file mode 100644
index 7b028cb06e..0000000000
--- a/examples/widgets/widgets/digitalclock/digitalclock.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef DIGITALCLOCK_H
-#define DIGITALCLOCK_H
-
-#include <QLCDNumber>
-
-//! [0]
-class DigitalClock : public QLCDNumber
-{
- Q_OBJECT
-
-public:
- DigitalClock(QWidget *parent = nullptr);
-
-private slots:
- void showTime();
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/digitalclock/digitalclock.pro b/examples/widgets/widgets/digitalclock/digitalclock.pro
deleted file mode 100644
index 4e4bc0f557..0000000000
--- a/examples/widgets/widgets/digitalclock/digitalclock.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-QT += widgets
-
-HEADERS = digitalclock.h
-SOURCES = digitalclock.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/digitalclock
-INSTALLS += target
diff --git a/examples/widgets/widgets/digitalclock/main.cpp b/examples/widgets/widgets/digitalclock/main.cpp
deleted file mode 100644
index d930e72f23..0000000000
--- a/examples/widgets/widgets/digitalclock/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "digitalclock.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- DigitalClock clock;
- clock.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/groupbox/CMakeLists.txt b/examples/widgets/widgets/groupbox/CMakeLists.txt
deleted file mode 100644
index 72fc5f98ea..0000000000
--- a/examples/widgets/widgets/groupbox/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(groupbox LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/groupbox")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(groupbox
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(groupbox PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(groupbox PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS groupbox
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/groupbox/groupbox.pro b/examples/widgets/widgets/groupbox/groupbox.pro
deleted file mode 100644
index 5fb6a14835..0000000000
--- a/examples/widgets/widgets/groupbox/groupbox.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-QT += widgets
-
-HEADERS = window.h
-SOURCES = window.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/groupbox
-INSTALLS += target
diff --git a/examples/widgets/widgets/groupbox/main.cpp b/examples/widgets/widgets/groupbox/main.cpp
deleted file mode 100644
index 27409403a5..0000000000
--- a/examples/widgets/widgets/groupbox/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "window.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Window window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/groupbox/window.cpp b/examples/widgets/widgets/groupbox/window.cpp
deleted file mode 100644
index 16ea8cc94f..0000000000
--- a/examples/widgets/widgets/groupbox/window.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-
-#include <QCheckBox>
-#include <QGridLayout>
-#include <QGroupBox>
-#include <QMenu>
-#include <QPushButton>
-#include <QRadioButton>
-
-//! [0]
-Window::Window(QWidget *parent)
- : QWidget(parent)
-{
- QGridLayout *grid = new QGridLayout;
- grid->addWidget(createFirstExclusiveGroup(), 0, 0);
- grid->addWidget(createSecondExclusiveGroup(), 1, 0);
- grid->addWidget(createNonExclusiveGroup(), 0, 1);
- grid->addWidget(createPushButtonGroup(), 1, 1);
- setLayout(grid);
-
- setWindowTitle(tr("Group Boxes"));
- resize(480, 320);
-}
-//! [0]
-
-//! [1]
-QGroupBox *Window::createFirstExclusiveGroup()
-{
-//! [2]
- QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));
-
- QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
- QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
- QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
-
- radio1->setChecked(true);
-//! [1] //! [3]
-
- QVBoxLayout *vbox = new QVBoxLayout;
- vbox->addWidget(radio1);
- vbox->addWidget(radio2);
- vbox->addWidget(radio3);
- vbox->addStretch(1);
- groupBox->setLayout(vbox);
-//! [2]
-
- return groupBox;
-}
-//! [3]
-
-//! [4]
-QGroupBox *Window::createSecondExclusiveGroup()
-{
- QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons"));
- groupBox->setCheckable(true);
- groupBox->setChecked(false);
-//! [4]
-
-//! [5]
- QRadioButton *radio1 = new QRadioButton(tr("Rad&io button 1"));
- QRadioButton *radio2 = new QRadioButton(tr("Radi&o button 2"));
- QRadioButton *radio3 = new QRadioButton(tr("Radio &button 3"));
- radio1->setChecked(true);
- QCheckBox *checkBox = new QCheckBox(tr("Ind&ependent checkbox"));
- checkBox->setChecked(true);
-//! [5]
-
-//! [6]
- QVBoxLayout *vbox = new QVBoxLayout;
- vbox->addWidget(radio1);
- vbox->addWidget(radio2);
- vbox->addWidget(radio3);
- vbox->addWidget(checkBox);
- vbox->addStretch(1);
- groupBox->setLayout(vbox);
-
- return groupBox;
-}
-//! [6]
-
-//! [7]
-QGroupBox *Window::createNonExclusiveGroup()
-{
- QGroupBox *groupBox = new QGroupBox(tr("Non-Exclusive Checkboxes"));
- groupBox->setFlat(true);
-//! [7]
-
-//! [8]
- QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1"));
- QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2"));
- checkBox2->setChecked(true);
- QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button"));
- tristateBox->setTristate(true);
-//! [8]
- tristateBox->setCheckState(Qt::PartiallyChecked);
-
-//! [9]
- QVBoxLayout *vbox = new QVBoxLayout;
- vbox->addWidget(checkBox1);
- vbox->addWidget(checkBox2);
- vbox->addWidget(tristateBox);
- vbox->addStretch(1);
- groupBox->setLayout(vbox);
-
- return groupBox;
-}
-//! [9]
-
-//! [10]
-QGroupBox *Window::createPushButtonGroup()
-{
- QGroupBox *groupBox = new QGroupBox(tr("&Push Buttons"));
- groupBox->setCheckable(true);
- groupBox->setChecked(true);
-//! [10]
-
-//! [11]
- QPushButton *pushButton = new QPushButton(tr("&Normal Button"));
- QPushButton *toggleButton = new QPushButton(tr("&Toggle Button"));
- toggleButton->setCheckable(true);
- toggleButton->setChecked(true);
- QPushButton *flatButton = new QPushButton(tr("&Flat Button"));
- flatButton->setFlat(true);
-//! [11]
-
-//! [12]
- QPushButton *popupButton = new QPushButton(tr("Pop&up Button"));
- QMenu *menu = new QMenu(this);
- menu->addAction(tr("&First Item"));
- menu->addAction(tr("&Second Item"));
- menu->addAction(tr("&Third Item"));
- menu->addAction(tr("F&ourth Item"));
- popupButton->setMenu(menu);
-//! [12]
-
- QMenu *subMenu = menu->addMenu(tr("Submenu"));
- subMenu->addAction(tr("Item 1"));
- subMenu->addAction(tr("Item 2"));
- subMenu->addAction(tr("Item 3"));
-
-//! [13]
- QVBoxLayout *vbox = new QVBoxLayout;
- vbox->addWidget(pushButton);
- vbox->addWidget(toggleButton);
- vbox->addWidget(flatButton);
- vbox->addWidget(popupButton);
- vbox->addStretch(1);
- groupBox->setLayout(vbox);
-
- return groupBox;
-}
-//! [13]
diff --git a/examples/widgets/widgets/groupbox/window.h b/examples/widgets/widgets/groupbox/window.h
deleted file mode 100644
index 714f22b756..0000000000
--- a/examples/widgets/widgets/groupbox/window.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QGroupBox;
-QT_END_NAMESPACE
-
-//! [0]
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window(QWidget *parent = nullptr);
-
-private:
- QGroupBox *createFirstExclusiveGroup();
- QGroupBox *createSecondExclusiveGroup();
- QGroupBox *createNonExclusiveGroup();
- QGroupBox *createPushButtonGroup();
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/icons/CMakeLists.txt b/examples/widgets/widgets/icons/CMakeLists.txt
deleted file mode 100644
index 4dc3fb09ee..0000000000
--- a/examples/widgets/widgets/icons/CMakeLists.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(icons LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/icons")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(icons
- iconpreviewarea.cpp iconpreviewarea.h
- iconsizespinbox.cpp iconsizespinbox.h
- imagedelegate.cpp imagedelegate.h
- main.cpp
- mainwindow.cpp mainwindow.h
-)
-
-set_target_properties(icons PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_compile_definitions(icons PRIVATE
- SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}"
-)
-
-target_link_libraries(icons PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS icons
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/icons/iconpreviewarea.cpp b/examples/widgets/widgets/icons/iconpreviewarea.cpp
deleted file mode 100644
index 42a5fa7914..0000000000
--- a/examples/widgets/widgets/icons/iconpreviewarea.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "iconpreviewarea.h"
-
-#include <QGridLayout>
-#include <QLabel>
-#include <QWindow>
-
-//! [0]
-IconPreviewArea::IconPreviewArea(QWidget *parent)
- : QWidget(parent)
-{
- QGridLayout *mainLayout = new QGridLayout(this);
-
- for (int row = 0; row < NumStates; ++row) {
- stateLabels[row] = createHeaderLabel(IconPreviewArea::iconStateNames().at(row));
- mainLayout->addWidget(stateLabels[row], row + 1, 0);
- }
- Q_ASSERT(NumStates == 2);
-
- for (int column = 0; column < NumModes; ++column) {
- modeLabels[column] = createHeaderLabel(IconPreviewArea::iconModeNames().at(column));
- mainLayout->addWidget(modeLabels[column], 0, column + 1);
- }
- Q_ASSERT(NumModes == 4);
-
- for (int column = 0; column < NumModes; ++column) {
- for (int row = 0; row < NumStates; ++row) {
- pixmapLabels[column][row] = createPixmapLabel();
- mainLayout->addWidget(pixmapLabels[column][row], row + 1, column + 1);
- }
- }
-}
-//! [0]
-
-//! [42]
-QList<QIcon::Mode> IconPreviewArea::iconModes()
-{
- static const QList<QIcon::Mode> result = { QIcon::Normal, QIcon::Active, QIcon::Disabled,
- QIcon::Selected };
- return result;
-}
-
-QList<QIcon::State> IconPreviewArea::iconStates()
-{
- static const QList<QIcon::State> result = { QIcon::Off, QIcon::On };
- return result;
-}
-
-QStringList IconPreviewArea::iconModeNames()
-{
- static const QStringList result = {tr("Normal"), tr("Active"), tr("Disabled"), tr("Selected")};
- return result;
-}
-
-QStringList IconPreviewArea::iconStateNames()
-{
- static const QStringList result = {tr("Off"), tr("On")};
- return result;
-}
-//! [42]
-
-//! [1]
-void IconPreviewArea::setIcon(const QIcon &icon)
-{
- this->icon = icon;
- updatePixmapLabels();
-}
-//! [1]
-
-//! [2]
-void IconPreviewArea::setSize(const QSize &size)
-{
- if (size != this->size) {
- this->size = size;
- updatePixmapLabels();
- }
-}
-//! [2]
-
-//! [3]
-QLabel *IconPreviewArea::createHeaderLabel(const QString &text)
-{
- QLabel *label = new QLabel(tr("<b>%1</b>").arg(text));
- label->setAlignment(Qt::AlignCenter);
- return label;
-}
-//! [3]
-
-//! [4]
-QLabel *IconPreviewArea::createPixmapLabel()
-{
- QLabel *label = new QLabel;
- label->setEnabled(false);
- label->setAlignment(Qt::AlignCenter);
- label->setFrameShape(QFrame::Box);
- label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- label->setBackgroundRole(QPalette::Base);
- label->setAutoFillBackground(true);
- label->setMinimumSize(132, 132);
- return label;
-}
-//! [4]
-
-//! [5]
-void IconPreviewArea::updatePixmapLabels()
-{
- for (int column = 0; column < NumModes; ++column) {
- for (int row = 0; row < NumStates; ++row) {
- const QPixmap pixmap =
- icon.pixmap(size, devicePixelRatio(), IconPreviewArea::iconModes().at(column),
- IconPreviewArea::iconStates().at(row));
- QLabel *pixmapLabel = pixmapLabels[column][row];
- pixmapLabel->setPixmap(pixmap);
- pixmapLabel->setEnabled(!pixmap.isNull());
- QString toolTip;
- if (!pixmap.isNull()) {
- const QSize actualSize = icon.actualSize(size);
- toolTip =
- tr("Size: %1x%2\nActual size: %3x%4\nDevice pixel ratio: %5")
- .arg(size.width()).arg(size.height())
- .arg(actualSize.width()).arg(actualSize.height())
- .arg(pixmap.devicePixelRatio());
- }
- pixmapLabel->setToolTip(toolTip);
- }
- }
-}
-//! [5]
diff --git a/examples/widgets/widgets/icons/iconpreviewarea.h b/examples/widgets/widgets/icons/iconpreviewarea.h
deleted file mode 100644
index c59ebc42ba..0000000000
--- a/examples/widgets/widgets/icons/iconpreviewarea.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef ICONPREVIEWAREA_H
-#define ICONPREVIEWAREA_H
-
-#include <QIcon>
-#include <QWidget>
-#include <QStringList>
-#include <QList>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-QT_END_NAMESPACE
-
-//! [0]
-class IconPreviewArea : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit IconPreviewArea(QWidget *parent = nullptr);
-
- void setIcon(const QIcon &icon);
- void setSize(const QSize &size);
-
- static QList<QIcon::Mode> iconModes();
- static QList<QIcon::State> iconStates();
- static QStringList iconModeNames();
- static QStringList iconStateNames();
-
-private:
- QLabel *createHeaderLabel(const QString &text);
- QLabel *createPixmapLabel();
- void updatePixmapLabels();
-
- enum { NumModes = 4, NumStates = 2 };
-
- QIcon icon;
- QSize size;
- QLabel *stateLabels[NumStates];
- QLabel *modeLabels[NumModes];
- QLabel *pixmapLabels[NumModes][NumStates];
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/icons/icons.pro b/examples/widgets/widgets/icons/icons.pro
deleted file mode 100644
index 243ce6b092..0000000000
--- a/examples/widgets/widgets/icons/icons.pro
+++ /dev/null
@@ -1,20 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = iconpreviewarea.h \
- iconsizespinbox.h \
- imagedelegate.h \
- mainwindow.h
-SOURCES = iconpreviewarea.cpp \
- iconsizespinbox.cpp \
- imagedelegate.cpp \
- main.cpp \
- mainwindow.cpp
-
-DEFINES += SRCDIR=\\\"$$PWD/\\\"
-
-EXAMPLE_FILES = images/*
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/icons
-INSTALLS += target
diff --git a/examples/widgets/widgets/icons/iconsizespinbox.cpp b/examples/widgets/widgets/icons/iconsizespinbox.cpp
deleted file mode 100644
index 16c88f4dd0..0000000000
--- a/examples/widgets/widgets/icons/iconsizespinbox.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "iconsizespinbox.h"
-
-#include <QRegularExpression>
-
-//! [0]
-IconSizeSpinBox::IconSizeSpinBox(QWidget *parent)
- : QSpinBox(parent)
-{
-}
-//! [0]
-
-//! [1]
-int IconSizeSpinBox::valueFromText(const QString &text) const
-{
- static const QRegularExpression regExp(tr("(\\d+)(\\s*[xx]\\s*\\d+)?"));
- Q_ASSERT(regExp.isValid());
-
- const QRegularExpressionMatch match = regExp.match(text);
- if (match.isValid())
- return match.captured(1).toInt();
- return 0;
-}
-//! [1]
-
-//! [2]
-QString IconSizeSpinBox::textFromValue(int value) const
-{
- return tr("%1 x %1").arg(value);
-}
-//! [2]
diff --git a/examples/widgets/widgets/icons/iconsizespinbox.h b/examples/widgets/widgets/icons/iconsizespinbox.h
deleted file mode 100644
index ac304b4794..0000000000
--- a/examples/widgets/widgets/icons/iconsizespinbox.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef ICONSIZESPINBOX_H
-#define ICONSIZESPINBOX_H
-
-#include <QSpinBox>
-
-//! [0]
-class IconSizeSpinBox : public QSpinBox
-{
- Q_OBJECT
-
-public:
- explicit IconSizeSpinBox(QWidget *parent = nullptr);
-
- int valueFromText(const QString &text) const override;
- QString textFromValue(int value) const override;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp
deleted file mode 100644
index ec3c227c71..0000000000
--- a/examples/widgets/widgets/icons/imagedelegate.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "imagedelegate.h"
-#include "iconpreviewarea.h"
-
-#include <QComboBox>
-
-//! [0]
-ImageDelegate::ImageDelegate(QObject *parent)
- : QStyledItemDelegate(parent)
-{}
-//! [0]
-
-//! [1]
-QWidget *ImageDelegate::createEditor(QWidget *parent,
- const QStyleOptionViewItem & /* option */,
- const QModelIndex &index) const
-{
- QComboBox *comboBox = new QComboBox(parent);
- if (index.column() == 1)
- comboBox->addItems(IconPreviewArea::iconModeNames());
- else if (index.column() == 2)
- comboBox->addItems(IconPreviewArea::iconStateNames());
-
- connect(comboBox, &QComboBox::activated,
- this, &ImageDelegate::emitCommitData);
-
- return comboBox;
-}
-//! [1]
-
-//! [2]
-void ImageDelegate::setEditorData(QWidget *editor,
- const QModelIndex &index) const
-{
- QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
- if (!comboBox)
- return;
-
- int pos = comboBox->findText(index.model()->data(index).toString(),
- Qt::MatchExactly);
- comboBox->setCurrentIndex(pos);
-}
-//! [2]
-
-//! [3]
-void ImageDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const
-{
- QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
- if (!comboBox)
- return;
-
- model->setData(index, comboBox->currentText());
-}
-//! [3]
-
-//! [4]
-void ImageDelegate::emitCommitData()
-{
- emit commitData(qobject_cast<QWidget *>(sender()));
-}
-//! [4]
diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h
deleted file mode 100644
index 29707e68c6..0000000000
--- a/examples/widgets/widgets/icons/imagedelegate.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef IMAGEDELEGATE_H
-#define IMAGEDELEGATE_H
-
-#include <QStyledItemDelegate>
-
-//! [0]
-class ImageDelegate : public QStyledItemDelegate
-{
- Q_OBJECT
-
-public:
- explicit ImageDelegate(QObject *parent = nullptr);
-//! [0]
-
-//! [1]
- QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
- void setEditorData(QWidget *editor, const QModelIndex &index) const override;
- void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const override;
-
-//! [1] //! [2]
-private slots:
- void emitCommitData();
-//! [2]
-};
-
-#endif
diff --git a/examples/widgets/widgets/icons/images/designer.png b/examples/widgets/widgets/icons/images/designer.png
deleted file mode 100644
index 9f8578b49e..0000000000
--- a/examples/widgets/widgets/icons/images/designer.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/find_disabled.png b/examples/widgets/widgets/icons/images/find_disabled.png
deleted file mode 100644
index e85e33fe05..0000000000
--- a/examples/widgets/widgets/icons/images/find_disabled.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/find_normal.png b/examples/widgets/widgets/icons/images/find_normal.png
deleted file mode 100644
index 728c27f905..0000000000
--- a/examples/widgets/widgets/icons/images/find_normal.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_off_128x128.png b/examples/widgets/widgets/icons/images/monkey_off_128x128.png
deleted file mode 100644
index f878267287..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_off_128x128.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_off_16x16.png b/examples/widgets/widgets/icons/images/monkey_off_16x16.png
deleted file mode 100644
index 0ac57d7d4f..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_off_16x16.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_off_32x32.png b/examples/widgets/widgets/icons/images/monkey_off_32x32.png
deleted file mode 100644
index 1f7fab694c..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_off_32x32.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_off_64x64.png b/examples/widgets/widgets/icons/images/monkey_off_64x64.png
deleted file mode 100644
index 47d8f6de35..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_off_64x64.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_on_128x128.png b/examples/widgets/widgets/icons/images/monkey_on_128x128.png
deleted file mode 100644
index 8e1c7468bf..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_on_128x128.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_on_16x16.png b/examples/widgets/widgets/icons/images/monkey_on_16x16.png
deleted file mode 100644
index 082e8527f1..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_on_16x16.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_on_32x32.png b/examples/widgets/widgets/icons/images/monkey_on_32x32.png
deleted file mode 100644
index bf9acc6cae..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_on_32x32.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/monkey_on_64x64.png b/examples/widgets/widgets/icons/images/monkey_on_64x64.png
deleted file mode 100644
index 990f604d98..0000000000
--- a/examples/widgets/widgets/icons/images/monkey_on_64x64.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/qt_extended_16x16.png b/examples/widgets/widgets/icons/images/qt_extended_16x16.png
deleted file mode 100644
index 30bcb45ed2..0000000000
--- a/examples/widgets/widgets/icons/images/qt_extended_16x16.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/qt_extended_32x32.png b/examples/widgets/widgets/icons/images/qt_extended_32x32.png
deleted file mode 100644
index d609c1e1e5..0000000000
--- a/examples/widgets/widgets/icons/images/qt_extended_32x32.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/qt_extended_48x48.png b/examples/widgets/widgets/icons/images/qt_extended_48x48.png
deleted file mode 100644
index 0e524fed5f..0000000000
--- a/examples/widgets/widgets/icons/images/qt_extended_48x48.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/icons/main.cpp b/examples/widgets/widgets/icons/main.cpp
deleted file mode 100644
index b7ed18ff94..0000000000
--- a/examples/widgets/widgets/icons/main.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include <QCommandLineParser>
-#include <QScreen>
-
-#include "mainwindow.h"
-
-//! [45]
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- QCoreApplication::setApplicationName(MainWindow::tr("Icons"));
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser commandLineParser;
- commandLineParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
- commandLineParser.addHelpOption();
- commandLineParser.addVersionOption();
- commandLineParser.addPositionalArgument(MainWindow::tr("[file]"), MainWindow::tr("Icon file(s) to open."));
- commandLineParser.process(QCoreApplication::arguments());
-
- MainWindow mainWin;
- if (!commandLineParser.positionalArguments().isEmpty())
- mainWin.loadImages(commandLineParser.positionalArguments());
-
- const QRect availableGeometry = mainWin.screen()->availableGeometry();
- mainWin.resize(availableGeometry.width() / 2, availableGeometry.height() * 2 / 3);
- mainWin.move((availableGeometry.width() - mainWin.width()) / 2, (availableGeometry.height() - mainWin.height()) / 2);
-
- mainWin.show();
- return app.exec();
-}
-//! [45]
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
deleted file mode 100644
index f893575f76..0000000000
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ /dev/null
@@ -1,478 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "iconpreviewarea.h"
-#include "iconsizespinbox.h"
-#include "imagedelegate.h"
-
-#include <QActionGroup>
-#include <QApplication>
-#include <QButtonGroup>
-#include <QCheckBox>
-#include <QFileDialog>
-#include <QHeaderView>
-#include <QFormLayout>
-#include <QGridLayout>
-#include <QGroupBox>
-#include <QImageReader>
-#include <QLabel>
-#include <QMenuBar>
-#include <QMessageBox>
-#include <QRadioButton>
-#include <QScreen>
-#include <QStandardPaths>
-#include <QStyleFactory>
-#include <QTableWidget>
-#include <QWindow>
-
-//! [40]
-enum { OtherSize = QStyle::PM_CustomBase };
-//! [40]
-
-//! [0]
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
-{
- QWidget *centralWidget = new QWidget(this);
- setCentralWidget(centralWidget);
-
- createActions();
-
- QGridLayout *mainLayout = new QGridLayout(centralWidget);
-
- QGroupBox *previewGroupBox = new QGroupBox(tr("Preview"));
- previewArea = new IconPreviewArea(previewGroupBox);
- QVBoxLayout *previewLayout = new QVBoxLayout(previewGroupBox);
- previewLayout->addWidget(previewArea);
-
- mainLayout->addWidget(previewGroupBox, 0, 0, 1, 2);
- mainLayout->addWidget(createImagesGroupBox(), 1, 0);
- QVBoxLayout *vBox = new QVBoxLayout;
- vBox->addWidget(createIconSizeGroupBox());
- vBox->addWidget(createHighDpiIconSizeGroupBox());
- vBox->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
- mainLayout->addLayout(vBox, 1, 1);
- createContextMenu();
-
- setWindowTitle(tr("Icons"));
- checkCurrentStyle();
- sizeButtonGroup->button(OtherSize)->click();
-}
-//! [0]
-
-//! [44]
-void MainWindow::show()
-{
- QMainWindow::show();
- connect(windowHandle(), &QWindow::screenChanged, this, &MainWindow::screenChanged);
- screenChanged();
-}
-//! [44]
-
-//! [1]
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About Icons"),
- tr("The <b>Icons</b> example illustrates how Qt renders an icon in "
- "different modes (active, normal, disabled, and selected) and "
- "states (on and off) based on a set of images."));
-}
-//! [1]
-
-//! [2]
-void MainWindow::changeStyle(bool checked)
-{
- if (!checked)
- return;
-
- const QAction *action = qobject_cast<QAction *>(sender());
-//! [2] //! [3]
- QStyle *style = QStyleFactory::create(action->data().toString());
-//! [3] //! [4]
- Q_ASSERT(style);
- QApplication::setStyle(style);
-
- const QList<QAbstractButton*> buttons = sizeButtonGroup->buttons();
- for (QAbstractButton *button : buttons) {
- const QStyle::PixelMetric metric = static_cast<QStyle::PixelMetric>(sizeButtonGroup->id(button));
- const int value = style->pixelMetric(metric);
- switch (metric) {
- case QStyle::PM_SmallIconSize:
- button->setText(tr("Small (%1 x %1)").arg(value));
- break;
- case QStyle::PM_LargeIconSize:
- button->setText(tr("Large (%1 x %1)").arg(value));
- break;
- case QStyle::PM_ToolBarIconSize:
- button->setText(tr("Toolbars (%1 x %1)").arg(value));
- break;
- case QStyle::PM_ListViewIconSize:
- button->setText(tr("List views (%1 x %1)").arg(value));
- break;
- case QStyle::PM_IconViewIconSize:
- button->setText(tr("Icon views (%1 x %1)").arg(value));
- break;
- case QStyle::PM_TabBarIconSize:
- button->setText(tr("Tab bars (%1 x %1)").arg(value));
- break;
- default:
- break;
- }
- }
-
- triggerChangeSize();
-}
-//! [4]
-
-//! [5]
-void MainWindow::changeSize(QAbstractButton *button, bool checked)
-{
- if (!checked)
- return;
-
- const int index = sizeButtonGroup->id(button);
- const bool other = index == int(OtherSize);
- const int extent = other
- ? otherSpinBox->value()
- : QApplication::style()->pixelMetric(static_cast<QStyle::PixelMetric>(index));
-
- previewArea->setSize(QSize(extent, extent));
- otherSpinBox->setEnabled(other);
-}
-
-void MainWindow::triggerChangeSize()
-{
- changeSize(sizeButtonGroup->checkedButton(), true);
-}
-//! [5]
-
-//! [6]
-void MainWindow::changeIcon()
-{
- QIcon icon;
-
- for (int row = 0; row < imagesTable->rowCount(); ++row) {
- const QTableWidgetItem *fileItem = imagesTable->item(row, 0);
- const QTableWidgetItem *modeItem = imagesTable->item(row, 1);
- const QTableWidgetItem *stateItem = imagesTable->item(row, 2);
-
- if (fileItem->checkState() == Qt::Checked) {
- const int modeIndex = IconPreviewArea::iconModeNames().indexOf(modeItem->text());
- Q_ASSERT(modeIndex >= 0);
- const int stateIndex = IconPreviewArea::iconStateNames().indexOf(stateItem->text());
- Q_ASSERT(stateIndex >= 0);
- const QIcon::Mode mode = IconPreviewArea::iconModes().at(modeIndex);
- const QIcon::State state = IconPreviewArea::iconStates().at(stateIndex);
-//! [6]
-
-//! [8]
- const QString fileName = fileItem->data(Qt::UserRole).toString();
- QImage image(fileName);
- if (!image.isNull())
- icon.addPixmap(QPixmap::fromImage(image), mode, state);
-//! [8]
- }
- }
-//! [11]
- previewArea->setIcon(icon);
-//! [11]
-}
-
-void MainWindow::addSampleImages()
-{
- addImages(QLatin1String(SRCDIR) + QLatin1String("/images"));
-}
-
-void MainWindow::addOtherImages()
-{
- static bool firstInvocation = true;
- QString directory;
- if (firstInvocation) {
- firstInvocation = false;
- directory = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QString());
- }
- addImages(directory);
-}
-
-//! [12]
-void MainWindow::addImages(const QString &directory)
-{
- QFileDialog fileDialog(this, tr("Open Images"), directory);
- QStringList mimeTypeFilters;
- const QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes();
- for (const QByteArray &mimeTypeName : mimeTypes)
- mimeTypeFilters.append(mimeTypeName);
- mimeTypeFilters.sort();
- fileDialog.setMimeTypeFilters(mimeTypeFilters);
- fileDialog.selectMimeTypeFilter(QLatin1String("image/png"));
- fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
- fileDialog.setFileMode(QFileDialog::ExistingFiles);
- if (!nativeFileDialogAct->isChecked())
- fileDialog.setOption(QFileDialog::DontUseNativeDialog);
- if (fileDialog.exec() == QDialog::Accepted)
- loadImages(fileDialog.selectedFiles());
-//! [12]
-}
-
-void MainWindow::loadImages(const QStringList &fileNames)
-{
- for (const QString &fileName : fileNames) {
- const int row = imagesTable->rowCount();
- imagesTable->setRowCount(row + 1);
-//! [13]
- const QFileInfo fileInfo(fileName);
- const QString imageName = fileInfo.baseName();
- const QString fileName2x = fileInfo.absolutePath()
- + QLatin1Char('/') + imageName + QLatin1String("@2x.") + fileInfo.suffix();
- const QFileInfo fileInfo2x(fileName2x);
- const QImage image(fileName);
- const QString toolTip =
- tr("Directory: %1\nFile: %2\nFile@2x: %3\nSize: %4x%5")
- .arg(QDir::toNativeSeparators(fileInfo.absolutePath()), fileInfo.fileName())
- .arg(fileInfo2x.exists() ? fileInfo2x.fileName() : tr("<None>"))
- .arg(image.width()).arg(image.height());
- QTableWidgetItem *fileItem = new QTableWidgetItem(imageName);
- fileItem->setData(Qt::UserRole, fileName);
- fileItem->setIcon(QPixmap::fromImage(image));
- fileItem->setFlags((fileItem->flags() | Qt::ItemIsUserCheckable) & ~Qt::ItemIsEditable);
- fileItem->setToolTip(toolTip);
-//! [13]
-
-//! [15]
- QIcon::Mode mode = QIcon::Normal;
- QIcon::State state = QIcon::Off;
- if (guessModeStateAct->isChecked()) {
- if (imageName.contains(QLatin1String("_act"), Qt::CaseInsensitive))
- mode = QIcon::Active;
- else if (imageName.contains(QLatin1String("_dis"), Qt::CaseInsensitive))
- mode = QIcon::Disabled;
- else if (imageName.contains(QLatin1String("_sel"), Qt::CaseInsensitive))
- mode = QIcon::Selected;
-
- if (imageName.contains(QLatin1String("_on"), Qt::CaseInsensitive))
- state = QIcon::On;
-//! [15]
- }
-
-//! [18]
- imagesTable->setItem(row, 0, fileItem);
- QTableWidgetItem *modeItem =
- new QTableWidgetItem(IconPreviewArea::iconModeNames().at(IconPreviewArea::iconModes().indexOf(mode)));
- modeItem->setToolTip(toolTip);
- imagesTable->setItem(row, 1, modeItem);
- QTableWidgetItem *stateItem =
- new QTableWidgetItem(IconPreviewArea::iconStateNames().at(IconPreviewArea::iconStates().indexOf(state)));
- stateItem->setToolTip(toolTip);
- imagesTable->setItem(row, 2, stateItem);
- imagesTable->openPersistentEditor(modeItem);
- imagesTable->openPersistentEditor(stateItem);
-
- fileItem->setCheckState(Qt::Checked);
-//! [18]
- }
-}
-
-//! [20]
-void MainWindow::removeAllImages()
-{
- imagesTable->setRowCount(0);
- changeIcon();
-}
-//! [20]
-
-//! [21]
-QWidget *MainWindow::createImagesGroupBox()
-{
- QGroupBox *imagesGroupBox = new QGroupBox(tr("Images"));
-
- imagesTable = new QTableWidget;
- imagesTable->setSelectionMode(QAbstractItemView::NoSelection);
- imagesTable->setItemDelegate(new ImageDelegate(this));
-//! [21]
-
-//! [22]
- const QStringList labels({tr("Image"), tr("Mode"), tr("State")});
-
- imagesTable->horizontalHeader()->setDefaultSectionSize(90);
- imagesTable->setColumnCount(3);
- imagesTable->setHorizontalHeaderLabels(labels);
- imagesTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
- imagesTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
- imagesTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
- imagesTable->verticalHeader()->hide();
-//! [22]
-
-//! [24]
- connect(imagesTable, &QTableWidget::itemChanged,
- this, &MainWindow::changeIcon);
-
- QVBoxLayout *layout = new QVBoxLayout(imagesGroupBox);
- layout->addWidget(imagesTable);
- return imagesGroupBox;
-//! [24]
-}
-
-//! [26]
-QWidget *MainWindow::createIconSizeGroupBox()
-{
- QGroupBox *iconSizeGroupBox = new QGroupBox(tr("Icon Size"));
-
- sizeButtonGroup = new QButtonGroup(this);
- sizeButtonGroup->setExclusive(true);
-
- connect(sizeButtonGroup, &QButtonGroup::buttonToggled,
- this, &MainWindow::changeSize);
-
- QRadioButton *smallRadioButton = new QRadioButton;
- sizeButtonGroup->addButton(smallRadioButton, QStyle::PM_SmallIconSize);
- QRadioButton *largeRadioButton = new QRadioButton;
- sizeButtonGroup->addButton(largeRadioButton, QStyle::PM_LargeIconSize);
- QRadioButton *toolBarRadioButton = new QRadioButton;
- sizeButtonGroup->addButton(toolBarRadioButton, QStyle::PM_ToolBarIconSize);
- QRadioButton *listViewRadioButton = new QRadioButton;
- sizeButtonGroup->addButton(listViewRadioButton, QStyle::PM_ListViewIconSize);
- QRadioButton *iconViewRadioButton = new QRadioButton;
- sizeButtonGroup->addButton(iconViewRadioButton, QStyle::PM_IconViewIconSize);
- QRadioButton *tabBarRadioButton = new QRadioButton;
- sizeButtonGroup->addButton(tabBarRadioButton, QStyle::PM_TabBarIconSize);
- QRadioButton *otherRadioButton = new QRadioButton(tr("Other:"));
- sizeButtonGroup->addButton(otherRadioButton, OtherSize);
- otherSpinBox = new IconSizeSpinBox;
- otherSpinBox->setRange(8, 256);
- const QString spinBoxToolTip =
- tr("Enter a custom size within %1..%2")
- .arg(otherSpinBox->minimum()).arg(otherSpinBox->maximum());
- otherSpinBox->setValue(64);
- otherSpinBox->setToolTip(spinBoxToolTip);
- otherRadioButton->setToolTip(spinBoxToolTip);
-//! [26]
-
-//! [27]
- connect(otherSpinBox, &QSpinBox::valueChanged,
- this, &MainWindow::triggerChangeSize);
-
- QHBoxLayout *otherSizeLayout = new QHBoxLayout;
- otherSizeLayout->addWidget(otherRadioButton);
- otherSizeLayout->addWidget(otherSpinBox);
- otherSizeLayout->addStretch();
-
- QGridLayout *layout = new QGridLayout(iconSizeGroupBox);
- layout->addWidget(smallRadioButton, 0, 0);
- layout->addWidget(largeRadioButton, 1, 0);
- layout->addWidget(toolBarRadioButton, 2, 0);
- layout->addWidget(listViewRadioButton, 0, 1);
- layout->addWidget(iconViewRadioButton, 1, 1);
- layout->addWidget(tabBarRadioButton, 2, 1);
- layout->addLayout(otherSizeLayout, 3, 0, 1, 2);
- layout->setRowStretch(4, 1);
- return iconSizeGroupBox;
-//! [27]
-}
-
-void MainWindow::screenChanged()
-{
- devicePixelRatioLabel->setText(QString::number(devicePixelRatio()));
- if (const QWindow *window = windowHandle()) {
- const QScreen *screen = window->screen();
- const QString screenDescription =
- tr("\"%1\" (%2x%3)").arg(screen->name())
- .arg(screen->geometry().width()).arg(screen->geometry().height());
- screenNameLabel->setText(screenDescription);
- }
- changeIcon();
-}
-
-QWidget *MainWindow::createHighDpiIconSizeGroupBox()
-{
- QGroupBox *highDpiGroupBox = new QGroupBox(tr("High DPI Scaling"));
- QFormLayout *layout = new QFormLayout(highDpiGroupBox);
- devicePixelRatioLabel = new QLabel(highDpiGroupBox);
- screenNameLabel = new QLabel(highDpiGroupBox);
- layout->addRow(tr("Screen:"), screenNameLabel);
- layout->addRow(tr("Device pixel ratio:"), devicePixelRatioLabel);
- return highDpiGroupBox;
-}
-
-//! [28]
-void MainWindow::createActions()
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
-
- addSampleImagesAct = new QAction(tr("Add &Sample Images..."), this);
- addSampleImagesAct->setShortcut(tr("Ctrl+A"));
- connect(addSampleImagesAct, &QAction::triggered, this, &MainWindow::addSampleImages);
- fileMenu->addAction(addSampleImagesAct);
-
- addOtherImagesAct = new QAction(tr("&Add Images..."), this);
- addOtherImagesAct->setShortcut(QKeySequence::Open);
- connect(addOtherImagesAct, &QAction::triggered, this, &MainWindow::addOtherImages);
- fileMenu->addAction(addOtherImagesAct);
-
- removeAllImagesAct = new QAction(tr("&Remove All Images"), this);
- removeAllImagesAct->setShortcut(tr("Ctrl+R"));
- connect(removeAllImagesAct, &QAction::triggered,
- this, &MainWindow::removeAllImages);
- fileMenu->addAction(removeAllImagesAct);
-
- fileMenu->addSeparator();
-
- QAction *exitAct = fileMenu->addAction(tr("&Quit"), qApp, &QCoreApplication::quit);
- exitAct->setShortcuts(QKeySequence::Quit);
-
- QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
-
- styleActionGroup = new QActionGroup(this);
- const QStringList styleKeys = QStyleFactory::keys();
- for (const QString &styleName : styleKeys) {
- QAction *action = new QAction(tr("%1 Style").arg(styleName), styleActionGroup);
- action->setData(styleName);
- action->setCheckable(true);
- connect(action, &QAction::triggered, this, &MainWindow::changeStyle);
- viewMenu->addAction(action);
- }
-
- QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings"));
-
- guessModeStateAct = new QAction(tr("&Guess Image Mode/State"), this);
- guessModeStateAct->setCheckable(true);
- guessModeStateAct->setChecked(true);
- settingsMenu->addAction(guessModeStateAct);
-
- nativeFileDialogAct = new QAction(tr("&Use Native File Dialog"), this);
- nativeFileDialogAct->setCheckable(true);
- nativeFileDialogAct->setChecked(true);
- settingsMenu->addAction(nativeFileDialogAct);
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
-}
-//! [28]
-
-//! [30]
-void MainWindow::createContextMenu()
-{
- imagesTable->setContextMenuPolicy(Qt::ActionsContextMenu);
- imagesTable->addAction(addSampleImagesAct);
- imagesTable->addAction(addOtherImagesAct);
- imagesTable->addAction(removeAllImagesAct);
-}
-//! [30]
-
-//! [31]
-void MainWindow::checkCurrentStyle()
-{
- const QList<QAction *> actions = styleActionGroup->actions();
- for (QAction *action : actions) {
- const QString styleName = action->data().toString();
- const std::unique_ptr<QStyle> candidate{QStyleFactory::create(styleName)};
- Q_ASSERT(candidate);
- if (candidate->metaObject()->className()
- == QApplication::style()->metaObject()->className()) {
- action->trigger();
- return;
- }
- }
-}
-//! [31]
diff --git a/examples/widgets/widgets/icons/mainwindow.h b/examples/widgets/widgets/icons/mainwindow.h
deleted file mode 100644
index fb6e0493f7..0000000000
--- a/examples/widgets/widgets/icons/mainwindow.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QIcon>
-#include <QList>
-#include <QMainWindow>
-#include <QPixmap>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QActionGroup;
-class QLabel;
-class QButtonGroup;
-class QTableWidget;
-class QAbstractButton;
-QT_END_NAMESPACE
-class IconPreviewArea;
-class IconSizeSpinBox;
-
-//! [0]
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow(QWidget *parent = nullptr);
-
- void loadImages(const QStringList &fileNames);
-
- void show();
-
-private slots:
- void about();
- void changeStyle(bool checked);
- void changeSize(QAbstractButton *button, bool);
- void triggerChangeSize();
- void changeIcon();
- void addSampleImages();
- void addOtherImages();
- void removeAllImages();
- void screenChanged();
-
-private:
- QWidget *createImagesGroupBox();
- QWidget *createIconSizeGroupBox();
- QWidget *createHighDpiIconSizeGroupBox();
- void createActions();
- void createContextMenu();
- void checkCurrentStyle();
- void addImages(const QString &directory);
-
- IconPreviewArea *previewArea;
-
- QTableWidget *imagesTable;
-
- QButtonGroup *sizeButtonGroup;
- IconSizeSpinBox *otherSpinBox;
-
- QLabel *devicePixelRatioLabel;
- QLabel *screenNameLabel;
-
- QAction *addOtherImagesAct;
- QAction *addSampleImagesAct;
- QAction *removeAllImagesAct;
- QAction *guessModeStateAct;
- QAction *nativeFileDialogAct;
- QActionGroup *styleActionGroup;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/imageviewer/CMakeLists.txt b/examples/widgets/widgets/imageviewer/CMakeLists.txt
deleted file mode 100644
index 34f524e1f7..0000000000
--- a/examples/widgets/widgets/imageviewer/CMakeLists.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(imageviewer LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/imageviewer")
-
-find_package(Qt6
- REQUIRED COMPONENTS Core Gui Widgets
- OPTIONAL_COMPONENTS PrintSupport
-)
-
-qt_standard_project_setup()
-
-qt_add_executable(imageviewer
- imageviewer.cpp imageviewer.h
- main.cpp
-)
-
-set_target_properties(imageviewer PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(imageviewer PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-if (TARGET Qt6::PrintSupport)
- target_link_libraries(imageviewer PRIVATE Qt6::PrintSupport)
-endif()
-
-install(TARGETS imageviewer
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
deleted file mode 100644
index fd8fbaf2b8..0000000000
--- a/examples/widgets/widgets/imageviewer/imageviewer.cpp
+++ /dev/null
@@ -1,363 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "imageviewer.h"
-
-#include <QApplication>
-#include <QClipboard>
-#include <QColorSpace>
-#include <QDir>
-#include <QFileDialog>
-#include <QImageReader>
-#include <QImageWriter>
-#include <QLabel>
-#include <QMenuBar>
-#include <QMessageBox>
-#include <QMimeData>
-#include <QPainter>
-#include <QScreen>
-#include <QScrollArea>
-#include <QScrollBar>
-#include <QStandardPaths>
-#include <QStatusBar>
-
-#if defined(QT_PRINTSUPPORT_LIB)
-# include <QtPrintSupport/qtprintsupportglobal.h>
-
-# if QT_CONFIG(printdialog)
-# include <QPrintDialog>
-# endif
-#endif
-
-//! [0]
-ImageViewer::ImageViewer(QWidget *parent)
- : QMainWindow(parent), imageLabel(new QLabel)
- , scrollArea(new QScrollArea)
-{
- imageLabel->setBackgroundRole(QPalette::Base);
- imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
- imageLabel->setScaledContents(true);
-
- scrollArea->setBackgroundRole(QPalette::Dark);
- scrollArea->setWidget(imageLabel);
- scrollArea->setVisible(false);
- setCentralWidget(scrollArea);
-
- createActions();
-
- resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
-}
-
-//! [0]
-//! [2]
-
-bool ImageViewer::loadFile(const QString &fileName)
-{
- QImageReader reader(fileName);
- reader.setAutoTransform(true);
- const QImage newImage = reader.read();
- if (newImage.isNull()) {
- QMessageBox::information(this, QGuiApplication::applicationDisplayName(),
- tr("Cannot load %1: %2")
- .arg(QDir::toNativeSeparators(fileName), reader.errorString()));
- return false;
- }
-//! [2]
-
- setImage(newImage);
-
- setWindowFilePath(fileName);
-
- const QString description = image.colorSpace().isValid()
- ? image.colorSpace().description() : tr("unknown");
- const QString message = tr("Opened \"%1\", %2x%3, Depth: %4 (%5)")
- .arg(QDir::toNativeSeparators(fileName)).arg(image.width()).arg(image.height())
- .arg(image.depth()).arg(description);
- statusBar()->showMessage(message);
- return true;
-}
-
-void ImageViewer::setImage(const QImage &newImage)
-{
- image = newImage;
- if (image.colorSpace().isValid())
- image.convertToColorSpace(QColorSpace::SRgb);
- imageLabel->setPixmap(QPixmap::fromImage(image));
-//! [4]
- scaleFactor = 1.0;
-
- scrollArea->setVisible(true);
- printAct->setEnabled(true);
- fitToWindowAct->setEnabled(true);
- updateActions();
-
- if (!fitToWindowAct->isChecked())
- imageLabel->adjustSize();
-}
-
-//! [4]
-
-bool ImageViewer::saveFile(const QString &fileName)
-{
- QImageWriter writer(fileName);
-
- if (!writer.write(image)) {
- QMessageBox::information(this, QGuiApplication::applicationDisplayName(),
- tr("Cannot write %1: %2")
- .arg(QDir::toNativeSeparators(fileName), writer.errorString()));
- return false;
- }
- const QString message = tr("Wrote \"%1\"").arg(QDir::toNativeSeparators(fileName));
- statusBar()->showMessage(message);
- return true;
-}
-
-//! [1]
-
-static void initializeImageFileDialog(QFileDialog &dialog, QFileDialog::AcceptMode acceptMode)
-{
- static bool firstDialog = true;
-
- if (firstDialog) {
- firstDialog = false;
- const QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
- dialog.setDirectory(picturesLocations.isEmpty() ? QDir::currentPath() : picturesLocations.last());
- }
-
- QStringList mimeTypeFilters;
- const QByteArrayList supportedMimeTypes = acceptMode == QFileDialog::AcceptOpen
- ? QImageReader::supportedMimeTypes() : QImageWriter::supportedMimeTypes();
- for (const QByteArray &mimeTypeName : supportedMimeTypes)
- mimeTypeFilters.append(mimeTypeName);
- mimeTypeFilters.sort();
- dialog.setMimeTypeFilters(mimeTypeFilters);
- dialog.selectMimeTypeFilter("image/jpeg");
- dialog.setAcceptMode(acceptMode);
- if (acceptMode == QFileDialog::AcceptSave)
- dialog.setDefaultSuffix("jpg");
-}
-
-void ImageViewer::open()
-{
- QFileDialog dialog(this, tr("Open File"));
- initializeImageFileDialog(dialog, QFileDialog::AcceptOpen);
-
- while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().constFirst())) {}
-}
-//! [1]
-
-void ImageViewer::saveAs()
-{
- QFileDialog dialog(this, tr("Save File As"));
- initializeImageFileDialog(dialog, QFileDialog::AcceptSave);
-
- while (dialog.exec() == QDialog::Accepted && !saveFile(dialog.selectedFiles().constFirst())) {}
-}
-
-//! [5]
-void ImageViewer::print()
-//! [5] //! [6]
-{
- Q_ASSERT(!imageLabel->pixmap().isNull());
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
-//! [6] //! [7]
- QPrintDialog dialog(&printer, this);
-//! [7] //! [8]
- if (dialog.exec()) {
- QPainter painter(&printer);
- QPixmap pixmap = imageLabel->pixmap();
- QRect rect = painter.viewport();
- QSize size = pixmap.size();
- size.scale(rect.size(), Qt::KeepAspectRatio);
- painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
- painter.setWindow(pixmap.rect());
- painter.drawPixmap(0, 0, pixmap);
- }
-#endif
-}
-//! [8]
-
-void ImageViewer::copy()
-{
-#ifndef QT_NO_CLIPBOARD
- QGuiApplication::clipboard()->setImage(image);
-#endif // !QT_NO_CLIPBOARD
-}
-
-#ifndef QT_NO_CLIPBOARD
-static QImage clipboardImage()
-{
- if (const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData()) {
- if (mimeData->hasImage()) {
- const QImage image = qvariant_cast<QImage>(mimeData->imageData());
- if (!image.isNull())
- return image;
- }
- }
- return QImage();
-}
-#endif // !QT_NO_CLIPBOARD
-
-void ImageViewer::paste()
-{
-#ifndef QT_NO_CLIPBOARD
- const QImage newImage = clipboardImage();
- if (newImage.isNull()) {
- statusBar()->showMessage(tr("No image in clipboard"));
- } else {
- setImage(newImage);
- setWindowFilePath(QString());
- const QString message = tr("Obtained image from clipboard, %1x%2, Depth: %3")
- .arg(newImage.width()).arg(newImage.height()).arg(newImage.depth());
- statusBar()->showMessage(message);
- }
-#endif // !QT_NO_CLIPBOARD
-}
-
-//! [9]
-void ImageViewer::zoomIn()
-//! [9] //! [10]
-{
- scaleImage(1.25);
-}
-
-void ImageViewer::zoomOut()
-{
- scaleImage(0.8);
-}
-
-//! [10] //! [11]
-void ImageViewer::normalSize()
-//! [11] //! [12]
-{
- imageLabel->adjustSize();
- scaleFactor = 1.0;
-}
-//! [12]
-
-//! [13]
-void ImageViewer::fitToWindow()
-//! [13] //! [14]
-{
- bool fitToWindow = fitToWindowAct->isChecked();
- scrollArea->setWidgetResizable(fitToWindow);
- if (!fitToWindow)
- normalSize();
- updateActions();
-}
-//! [14]
-
-
-//! [15]
-void ImageViewer::about()
-//! [15] //! [16]
-{
- QMessageBox::about(this, tr("About Image Viewer"),
- tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel "
- "and QScrollArea to display an image. QLabel is typically used "
- "for displaying a text, but it can also display an image. "
- "QScrollArea provides a scrolling view around another widget. "
- "If the child widget exceeds the size of the frame, QScrollArea "
- "automatically provides scroll bars. </p><p>The example "
- "demonstrates how QLabel's ability to scale its contents "
- "(QLabel::scaledContents), and QScrollArea's ability to "
- "automatically resize its contents "
- "(QScrollArea::widgetResizable), can be used to implement "
- "zooming and scaling features. </p><p>In addition the example "
- "shows how to use QPainter to print an image.</p>"));
-}
-//! [16]
-
-//! [17]
-void ImageViewer::createActions()
-//! [17] //! [18]
-{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
-
- QAction *openAct = fileMenu->addAction(tr("&Open..."), this, &ImageViewer::open);
- openAct->setShortcut(QKeySequence::Open);
-
- saveAsAct = fileMenu->addAction(tr("&Save As..."), this, &ImageViewer::saveAs);
- saveAsAct->setEnabled(false);
-
- printAct = fileMenu->addAction(tr("&Print..."), this, &ImageViewer::print);
- printAct->setShortcut(QKeySequence::Print);
- printAct->setEnabled(false);
-
- fileMenu->addSeparator();
-
- QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
- exitAct->setShortcut(tr("Ctrl+Q"));
-
- QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
-
- copyAct = editMenu->addAction(tr("&Copy"), this, &ImageViewer::copy);
- copyAct->setShortcut(QKeySequence::Copy);
- copyAct->setEnabled(false);
-
- QAction *pasteAct = editMenu->addAction(tr("&Paste"), this, &ImageViewer::paste);
- pasteAct->setShortcut(QKeySequence::Paste);
-
- QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
-
- zoomInAct = viewMenu->addAction(tr("Zoom &In (25%)"), this, &ImageViewer::zoomIn);
- zoomInAct->setShortcut(QKeySequence::ZoomIn);
- zoomInAct->setEnabled(false);
-
- zoomOutAct = viewMenu->addAction(tr("Zoom &Out (25%)"), this, &ImageViewer::zoomOut);
- zoomOutAct->setShortcut(QKeySequence::ZoomOut);
- zoomOutAct->setEnabled(false);
-
- normalSizeAct = viewMenu->addAction(tr("&Normal Size"), this, &ImageViewer::normalSize);
- normalSizeAct->setShortcut(tr("Ctrl+S"));
- normalSizeAct->setEnabled(false);
-
- viewMenu->addSeparator();
-
- fitToWindowAct = viewMenu->addAction(tr("&Fit to Window"), this, &ImageViewer::fitToWindow);
- fitToWindowAct->setEnabled(false);
- fitToWindowAct->setCheckable(true);
- fitToWindowAct->setShortcut(tr("Ctrl+F"));
-
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
-
- helpMenu->addAction(tr("&About"), this, &ImageViewer::about);
- helpMenu->addAction(tr("About &Qt"), this, &QApplication::aboutQt);
-}
-//! [18]
-
-//! [21]
-void ImageViewer::updateActions()
-//! [21] //! [22]
-{
- saveAsAct->setEnabled(!image.isNull());
- copyAct->setEnabled(!image.isNull());
- zoomInAct->setEnabled(!fitToWindowAct->isChecked());
- zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
- normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
-}
-//! [22]
-
-//! [23]
-void ImageViewer::scaleImage(double factor)
-//! [23] //! [24]
-{
- scaleFactor *= factor;
- imageLabel->resize(scaleFactor * imageLabel->pixmap().size());
-
- adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
- adjustScrollBar(scrollArea->verticalScrollBar(), factor);
-
- zoomInAct->setEnabled(scaleFactor < 3.0);
- zoomOutAct->setEnabled(scaleFactor > 0.333);
-}
-//! [24]
-
-//! [25]
-void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor)
-//! [25] //! [26]
-{
- scrollBar->setValue(int(factor * scrollBar->value()
- + ((factor - 1) * scrollBar->pageStep()/2)));
-}
-//! [26]
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.h b/examples/widgets/widgets/imageviewer/imageviewer.h
deleted file mode 100644
index e9e6858c74..0000000000
--- a/examples/widgets/widgets/imageviewer/imageviewer.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef IMAGEVIEWER_H
-#define IMAGEVIEWER_H
-
-#include <QMainWindow>
-#include <QImage>
-#if defined(QT_PRINTSUPPORT_LIB)
-# include <QtPrintSupport/qtprintsupportglobal.h>
-
-# if QT_CONFIG(printer)
-# include <QPrinter>
-# endif
-#endif
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QLabel;
-class QMenu;
-class QScrollArea;
-class QScrollBar;
-QT_END_NAMESPACE
-
-//! [0]
-class ImageViewer : public QMainWindow
-{
- Q_OBJECT
-
-public:
- ImageViewer(QWidget *parent = nullptr);
- bool loadFile(const QString &);
-
-private slots:
- void open();
- void saveAs();
- void print();
- void copy();
- void paste();
- void zoomIn();
- void zoomOut();
- void normalSize();
- void fitToWindow();
- void about();
-
-private:
- void createActions();
- void createMenus();
- void updateActions();
- bool saveFile(const QString &fileName);
- void setImage(const QImage &newImage);
- void scaleImage(double factor);
- void adjustScrollBar(QScrollBar *scrollBar, double factor);
-
- QImage image;
- QLabel *imageLabel;
- QScrollArea *scrollArea;
- double scaleFactor = 1;
-
-#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
- QPrinter printer;
-#endif
-
- QAction *saveAsAct;
- QAction *printAct;
- QAction *copyAct;
- QAction *zoomInAct;
- QAction *zoomOutAct;
- QAction *normalSizeAct;
- QAction *fitToWindowAct;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.pro b/examples/widgets/widgets/imageviewer/imageviewer.pro
deleted file mode 100644
index d3db63ec20..0000000000
--- a/examples/widgets/widgets/imageviewer/imageviewer.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-qtHaveModule(printsupport): QT += printsupport
-
-HEADERS = imageviewer.h
-SOURCES = imageviewer.cpp \
- main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/imageviewer
-INSTALLS += target
diff --git a/examples/widgets/widgets/imageviewer/main.cpp b/examples/widgets/widgets/imageviewer/main.cpp
deleted file mode 100644
index 013f7d8689..0000000000
--- a/examples/widgets/widgets/imageviewer/main.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-#include <QCommandLineParser>
-
-#include "imageviewer.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- QGuiApplication::setApplicationDisplayName(ImageViewer::tr("Image Viewer"));
- QCommandLineParser commandLineParser;
- commandLineParser.addHelpOption();
- commandLineParser.addPositionalArgument(ImageViewer::tr("[file]"), ImageViewer::tr("Image file to open."));
- commandLineParser.process(QCoreApplication::arguments());
- ImageViewer imageViewer;
- if (!commandLineParser.positionalArguments().isEmpty()
- && !imageViewer.loadFile(commandLineParser.positionalArguments().constFirst())) {
- return -1;
- }
- imageViewer.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/lineedits/CMakeLists.txt b/examples/widgets/widgets/lineedits/CMakeLists.txt
index c226c5ebda..9cfaa784c8 100644
--- a/examples/widgets/widgets/lineedits/CMakeLists.txt
+++ b/examples/widgets/widgets/lineedits/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(lineedits LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/lineedits")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(lineedits PRIVATE
)
install(TARGETS lineedits
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET lineedits
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/movie/CMakeLists.txt b/examples/widgets/widgets/movie/CMakeLists.txt
deleted file mode 100644
index f5165e15f6..0000000000
--- a/examples/widgets/widgets/movie/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(movie LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/movie")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(movie
- main.cpp
- movieplayer.cpp movieplayer.h
-)
-
-set_target_properties(movie PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(movie PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS movie
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/movie/animation.gif b/examples/widgets/widgets/movie/animation.gif
deleted file mode 100644
index f674369efc..0000000000
--- a/examples/widgets/widgets/movie/animation.gif
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/movie/main.cpp b/examples/widgets/widgets/movie/main.cpp
deleted file mode 100644
index e5d4d3f040..0000000000
--- a/examples/widgets/widgets/movie/main.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "movieplayer.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MoviePlayer player;
- player.show();
- player.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/movie/movie.pro b/examples/widgets/widgets/movie/movie.pro
deleted file mode 100644
index f9f89109e4..0000000000
--- a/examples/widgets/widgets/movie/movie.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-requires(qtConfig(filedialog))
-
-HEADERS = movieplayer.h
-SOURCES = main.cpp \
- movieplayer.cpp
-
-EXAMPLE_FILES = animation.gif
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/movie
-INSTALLS += target
diff --git a/examples/widgets/widgets/movie/movieplayer.cpp b/examples/widgets/widgets/movie/movieplayer.cpp
deleted file mode 100644
index 6f6ec14bb1..0000000000
--- a/examples/widgets/widgets/movie/movieplayer.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "movieplayer.h"
-
-#include <QCheckBox>
-#include <QFileDialog>
-#include <QLabel>
-#include <QMovie>
-#include <QSlider>
-#include <QSpinBox>
-#include <QStyle>
-#include <QToolButton>
-#include <QVBoxLayout>
-
-MoviePlayer::MoviePlayer(QWidget *parent)
- : QWidget(parent)
-{
- movie = new QMovie(this);
- movie->setCacheMode(QMovie::CacheAll);
-
- movieLabel = new QLabel(tr("No movie loaded"));
- movieLabel->setAlignment(Qt::AlignCenter);
- movieLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
- movieLabel->setBackgroundRole(QPalette::Dark);
- movieLabel->setAutoFillBackground(true);
-
- currentMovieDirectory = "movies";
-
- createControls();
- createButtons();
-
- connect(movie, &QMovie::frameChanged, this, &MoviePlayer::updateFrameSlider);
- connect(movie, &QMovie::stateChanged, this, &MoviePlayer::updateButtons);
- connect(fitCheckBox, &QCheckBox::clicked, this, &MoviePlayer::fitToWindow);
- connect(frameSlider, &QSlider::valueChanged, this, &MoviePlayer::goToFrame);
- connect(speedSpinBox, &QSpinBox::valueChanged,
- movie, &QMovie::setSpeed);
-
- mainLayout = new QVBoxLayout;
- mainLayout->addWidget(movieLabel);
- mainLayout->addLayout(controlsLayout);
- mainLayout->addLayout(buttonsLayout);
- setLayout(mainLayout);
-
- updateFrameSlider();
- updateButtons();
-
- setWindowTitle(tr("Movie Player"));
- resize(400, 400);
-}
-
-void MoviePlayer::open()
-{
- QString fileName = QFileDialog::getOpenFileName(this, tr("Open a Movie"),
- currentMovieDirectory);
- if (!fileName.isEmpty())
- openFile(fileName);
-}
-
-void MoviePlayer::openFile(const QString &fileName)
-{
- currentMovieDirectory = QFileInfo(fileName).path();
-
- movie->stop();
- movieLabel->setMovie(movie);
- movie->setFileName(fileName);
- movie->start();
-
- updateFrameSlider();
- updateButtons();
-}
-
-void MoviePlayer::goToFrame(int frame)
-{
- movie->jumpToFrame(frame);
-}
-
-void MoviePlayer::fitToWindow()
-{
- movieLabel->setScaledContents(fitCheckBox->isChecked());
-}
-
-void MoviePlayer::updateFrameSlider()
-{
- bool hasFrames = (movie->currentFrameNumber() >= 0);
-
- if (hasFrames) {
- if (movie->frameCount() > 0) {
- frameSlider->setMaximum(movie->frameCount() - 1);
- } else {
- if (movie->currentFrameNumber() > frameSlider->maximum())
- frameSlider->setMaximum(movie->currentFrameNumber());
- }
- frameSlider->setValue(movie->currentFrameNumber());
- } else {
- frameSlider->setMaximum(0);
- }
- frameLabel->setEnabled(hasFrames);
- frameSlider->setEnabled(hasFrames);
-}
-
-void MoviePlayer::updateButtons()
-{
- playButton->setEnabled(movie->isValid() && movie->frameCount() != 1
- && movie->state() == QMovie::NotRunning);
- pauseButton->setEnabled(movie->state() != QMovie::NotRunning);
- pauseButton->setChecked(movie->state() == QMovie::Paused);
- stopButton->setEnabled(movie->state() != QMovie::NotRunning);
-}
-
-void MoviePlayer::createControls()
-{
- fitCheckBox = new QCheckBox(tr("Fit to Window"));
-
- frameLabel = new QLabel(tr("Current frame:"));
-
- frameSlider = new QSlider(Qt::Horizontal);
- frameSlider->setTickPosition(QSlider::TicksBelow);
- frameSlider->setTickInterval(10);
-
- speedLabel = new QLabel(tr("Speed:"));
-
- speedSpinBox = new QSpinBox;
- speedSpinBox->setRange(1, 9999);
- speedSpinBox->setValue(100);
- speedSpinBox->setSuffix(tr("%"));
-
- controlsLayout = new QGridLayout;
- controlsLayout->addWidget(fitCheckBox, 0, 0, 1, 2);
- controlsLayout->addWidget(frameLabel, 1, 0);
- controlsLayout->addWidget(frameSlider, 1, 1, 1, 2);
- controlsLayout->addWidget(speedLabel, 2, 0);
- controlsLayout->addWidget(speedSpinBox, 2, 1);
-}
-
-void MoviePlayer::createButtons()
-{
- QSize iconSize(36, 36);
-
- openButton = new QToolButton;
- openButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
- openButton->setIconSize(iconSize);
- openButton->setToolTip(tr("Open File"));
- connect(openButton, &QToolButton::clicked, this, &MoviePlayer::open);
-
- playButton = new QToolButton;
- playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
- playButton->setIconSize(iconSize);
- playButton->setToolTip(tr("Play"));
- connect(playButton, &QToolButton::clicked, movie, &QMovie::start);
-
- pauseButton = new QToolButton;
- pauseButton->setCheckable(true);
- pauseButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
- pauseButton->setIconSize(iconSize);
- pauseButton->setToolTip(tr("Pause"));
- connect(pauseButton, &QToolButton::clicked, movie, &QMovie::setPaused);
-
- stopButton = new QToolButton;
- stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
- stopButton->setIconSize(iconSize);
- stopButton->setToolTip(tr("Stop"));
- connect(stopButton, &QToolButton::clicked, movie, &QMovie::stop);
-
- quitButton = new QToolButton;
- quitButton->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
- quitButton->setIconSize(iconSize);
- quitButton->setToolTip(tr("Quit"));
- connect(quitButton, &QToolButton::clicked, this, &MoviePlayer::close);
-
- buttonsLayout = new QHBoxLayout;
- buttonsLayout->addStretch();
- buttonsLayout->addWidget(openButton);
- buttonsLayout->addWidget(playButton);
- buttonsLayout->addWidget(pauseButton);
- buttonsLayout->addWidget(stopButton);
- buttonsLayout->addWidget(quitButton);
- buttonsLayout->addStretch();
-}
diff --git a/examples/widgets/widgets/movie/movieplayer.h b/examples/widgets/widgets/movie/movieplayer.h
deleted file mode 100644
index 362fd50535..0000000000
--- a/examples/widgets/widgets/movie/movieplayer.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MOVIEPLAYER_H
-#define MOVIEPLAYER_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QCheckBox;
-class QGridLayout;
-class QHBoxLayout;
-class QLabel;
-class QMovie;
-class QSlider;
-class QSpinBox;
-class QToolButton;
-class QVBoxLayout;
-QT_END_NAMESPACE
-
-class MoviePlayer : public QWidget
-{
- Q_OBJECT
-
-public:
- MoviePlayer(QWidget *parent = nullptr);
- void openFile(const QString &fileName);
-
-private slots:
- void open();
- void goToFrame(int frame);
- void fitToWindow();
- void updateButtons();
- void updateFrameSlider();
-
-private:
- void createControls();
- void createButtons();
-
- QString currentMovieDirectory;
- QLabel *movieLabel;
- QMovie *movie;
- QToolButton *openButton;
- QToolButton *playButton;
- QToolButton *pauseButton;
- QToolButton *stopButton;
- QToolButton *quitButton;
- QCheckBox *fitCheckBox;
- QSlider *frameSlider;
- QSpinBox *speedSpinBox;
- QLabel *frameLabel;
- QLabel *speedLabel;
-
- QGridLayout *controlsLayout;
- QHBoxLayout *buttonsLayout;
- QVBoxLayout *mainLayout;
-};
-
-#endif
diff --git a/examples/widgets/widgets/scribble/CMakeLists.txt b/examples/widgets/widgets/scribble/CMakeLists.txt
index a7bfb089ab..ec78b1ece8 100644
--- a/examples/widgets/widgets/scribble/CMakeLists.txt
+++ b/examples/widgets/widgets/scribble/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(scribble LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/scribble")
-
find_package(Qt6
REQUIRED COMPONENTS Core Gui Widgets
OPTIONAL_COMPONENTS PrintSupport
@@ -39,7 +33,14 @@ if (TARGET Qt6::PrintSupport)
endif()
install(TARGETS scribble
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET scribble
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/shapedclock/CMakeLists.txt b/examples/widgets/widgets/shapedclock/CMakeLists.txt
index 80a1186137..dd8dc217ef 100644
--- a/examples/widgets/widgets/shapedclock/CMakeLists.txt
+++ b/examples/widgets/widgets/shapedclock/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(shapedclock LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/shapedclock")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(shapedclock PRIVATE
)
install(TARGETS shapedclock
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET shapedclock
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/shapedclock/shapedclock.cpp b/examples/widgets/widgets/shapedclock/shapedclock.cpp
index 25225eb5b6..106b3454a6 100644
--- a/examples/widgets/widgets/shapedclock/shapedclock.cpp
+++ b/examples/widgets/widgets/shapedclock/shapedclock.cpp
@@ -54,23 +54,30 @@ void ShapedClock::mouseMoveEvent(QMouseEvent *event)
//! [3]
void ShapedClock::paintEvent(QPaintEvent *)
{
- static const QPoint hourHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -40)
+ static const QPoint hourHand[4] = {
+ QPoint(5, 14),
+ QPoint(-5, 14),
+ QPoint(-4, -71),
+ QPoint(4, -71)
};
- static const QPoint minuteHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -70)
+ static const QPoint minuteHand[4] = {
+ QPoint(4, 14),
+ QPoint(-4, 14),
+ QPoint(-3, -89),
+ QPoint(3, -89)
+ };
+ static const QPoint secondsHand[4] = {
+ QPoint(1, 14),
+ QPoint(-1, 14),
+ QPoint(-1, -89),
+ QPoint(1, -89)
};
- QColor hourColor(127, 0, 127);
- QColor minuteColor(0, 127, 127, 191);
+ const QColor hourColor(palette().color(QPalette::Text));
+ const QColor minuteColor(palette().color(QPalette::Text));
+ const QColor secondsColor(palette().color(QPalette::Accent));
int side = qMin(width(), height());
- QTime time = QTime::currentTime();
-
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
@@ -82,34 +89,40 @@ void ShapedClock::paintEvent(QPaintEvent *)
painter.drawEllipse(QPoint(0, 0), 98, 98);
painter.setOpacity(1.0);
+ QTime time = QTime::currentTime();
painter.setPen(Qt::NoPen);
painter.setBrush(hourColor);
painter.save();
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
- painter.drawConvexPolygon(hourHand, 3);
+ painter.drawConvexPolygon(hourHand, 4);
painter.restore();
- painter.setPen(hourColor);
-
for (int i = 0; i < 12; ++i) {
- painter.drawLine(88, 0, 96, 0);
+ painter.drawRect(73, -3, 16, 6);
painter.rotate(30.0);
}
- painter.setPen(Qt::NoPen);
painter.setBrush(minuteColor);
painter.save();
- painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
- painter.drawConvexPolygon(minuteHand, 3);
+ painter.rotate(6.0 * time.minute());
+ painter.drawConvexPolygon(minuteHand, 4);
+ painter.restore();
+
+ painter.setBrush(secondsColor);
+
+ painter.save();
+ painter.rotate(6.0 * time.second());
+ painter.drawConvexPolygon(secondsHand, 4);
+ painter.drawEllipse(-3, -3, 6, 6);
+ painter.drawEllipse(-5, -68, 10, 10);
painter.restore();
painter.setPen(minuteColor);
for (int j = 0; j < 60; ++j) {
- if ((j % 5) != 0)
- painter.drawLine(92, 0, 96, 0);
+ painter.drawLine(92, 0, 96, 0);
painter.rotate(6.0);
}
}
diff --git a/examples/widgets/widgets/shortcuteditor/CMakeLists.txt b/examples/widgets/widgets/shortcuteditor/CMakeLists.txt
index c85b18f3e2..d10248fbd7 100644
--- a/examples/widgets/widgets/shortcuteditor/CMakeLists.txt
+++ b/examples/widgets/widgets/shortcuteditor/CMakeLists.txt
@@ -1,12 +1,8 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(shortcuteditor LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/shortcuteditor")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -33,7 +29,14 @@ target_link_libraries(shortcuteditor PRIVATE
)
install(TARGETS shortcuteditor
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET shortcuteditor
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/sliders/CMakeLists.txt b/examples/widgets/widgets/sliders/CMakeLists.txt
index 543e278391..c4c9d11e03 100644
--- a/examples/widgets/widgets/sliders/CMakeLists.txt
+++ b/examples/widgets/widgets/sliders/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(sliders LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/sliders")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(sliders PRIVATE
)
install(TARGETS sliders
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET sliders
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/sliders/slidersgroup.cpp b/examples/widgets/widgets/sliders/slidersgroup.cpp
index c5d01cdb37..87841c43f9 100644
--- a/examples/widgets/widgets/sliders/slidersgroup.cpp
+++ b/examples/widgets/widgets/sliders/slidersgroup.cpp
@@ -9,39 +9,28 @@
#include <QSlider>
//! [0]
-SlidersGroup::SlidersGroup(Qt::Orientation orientation, const QString &title,
- QWidget *parent)
+SlidersGroup::SlidersGroup(const QString &title, QWidget *parent)
: QGroupBox(title, parent)
{
- slider = new QSlider(orientation);
+ slider = new QSlider;
slider->setFocusPolicy(Qt::StrongFocus);
slider->setTickPosition(QSlider::TicksBothSides);
slider->setTickInterval(10);
slider->setSingleStep(1);
- scrollBar = new QScrollBar(orientation);
+ scrollBar = new QScrollBar;
scrollBar->setFocusPolicy(Qt::StrongFocus);
dial = new QDial;
dial->setFocusPolicy(Qt::StrongFocus);
+//! [0] //! [1]
connect(slider, &QSlider::valueChanged, scrollBar, &QScrollBar::setValue);
connect(scrollBar, &QScrollBar::valueChanged, dial, &QDial::setValue);
connect(dial, &QDial::valueChanged, slider, &QSlider::setValue);
-//! [0] //! [1]
connect(dial, &QDial::valueChanged, this, &SlidersGroup::valueChanged);
-//! [1] //! [2]
-
-//! [2] //! [3]
- QBoxLayout::Direction direction;
-//! [3] //! [4]
-
- if (orientation == Qt::Horizontal)
- direction = QBoxLayout::TopToBottom;
- else
- direction = QBoxLayout::LeftToRight;
-
- QBoxLayout *slidersLayout = new QBoxLayout(direction);
+//! [1] //! [4]
+ slidersLayout = new QBoxLayout(QBoxLayout::LeftToRight);
slidersLayout->addWidget(slider);
slidersLayout->addWidget(scrollBar);
slidersLayout->addWidget(dial);
@@ -96,3 +85,14 @@ void SlidersGroup::invertKeyBindings(bool invert)
dial->setInvertedControls(invert);
}
//! [14]
+
+//! [15]
+void SlidersGroup::setOrientation(Qt::Orientation orientation)
+{
+ slidersLayout->setDirection(orientation == Qt::Horizontal
+ ? QBoxLayout::TopToBottom
+ : QBoxLayout::LeftToRight);
+ scrollBar->setOrientation(orientation);
+ slider->setOrientation(orientation);
+}
+//! [15]
diff --git a/examples/widgets/widgets/sliders/slidersgroup.h b/examples/widgets/widgets/sliders/slidersgroup.h
index 66821ca558..7e7d887018 100644
--- a/examples/widgets/widgets/sliders/slidersgroup.h
+++ b/examples/widgets/widgets/sliders/slidersgroup.h
@@ -10,6 +10,7 @@ QT_BEGIN_NAMESPACE
class QDial;
class QScrollBar;
class QSlider;
+class QBoxLayout;
QT_END_NAMESPACE
//! [0]
@@ -18,8 +19,7 @@ class SlidersGroup : public QGroupBox
Q_OBJECT
public:
- SlidersGroup(Qt::Orientation orientation, const QString &title,
- QWidget *parent = nullptr);
+ SlidersGroup(const QString &title, QWidget *parent = nullptr);
signals:
void valueChanged(int value);
@@ -30,11 +30,13 @@ public slots:
void setMaximum(int value);
void invertAppearance(bool invert);
void invertKeyBindings(bool invert);
+ void setOrientation(Qt::Orientation orientation);
private:
QSlider *slider;
QScrollBar *scrollBar;
QDial *dial;
+ QBoxLayout *slidersLayout;
};
//! [0]
diff --git a/examples/widgets/widgets/sliders/window.cpp b/examples/widgets/widgets/sliders/window.cpp
index a2c2fe89eb..c62c3b83f5 100644
--- a/examples/widgets/widgets/sliders/window.cpp
+++ b/examples/widgets/widgets/sliders/window.cpp
@@ -13,29 +13,15 @@
Window::Window(QWidget *parent)
: QWidget(parent)
{
- horizontalSliders = new SlidersGroup(Qt::Horizontal, tr("Horizontal"));
- verticalSliders = new SlidersGroup(Qt::Vertical, tr("Vertical"));
-
- stackedWidget = new QStackedWidget;
- stackedWidget->addWidget(horizontalSliders);
- stackedWidget->addWidget(verticalSliders);
+ slidersGroup = new SlidersGroup(tr("Sliders"));
createControls(tr("Controls"));
//! [0]
//! [1]
- connect(horizontalSliders, &SlidersGroup::valueChanged,
-//! [1] //! [2]
- verticalSliders, &SlidersGroup::setValue);
- connect(verticalSliders, &SlidersGroup::valueChanged,
- valueSpinBox, &QSpinBox::setValue);
- connect(valueSpinBox, &QSpinBox::valueChanged,
- horizontalSliders, &SlidersGroup::setValue);
-
- layout = new QGridLayout;
- layout->addWidget(stackedWidget, 0, 1);
- layout->addWidget(controlsGroup, 0, 0);
-
+ layout = new QBoxLayout(QBoxLayout::LeftToRight);
+ layout->addWidget(controlsGroup);
+ layout->addWidget(slidersGroup);
setLayout(layout);
minimumSpinBox->setValue(0);
@@ -44,11 +30,11 @@ Window::Window(QWidget *parent)
setWindowTitle(tr("Sliders"));
}
-//! [2]
+//! [1]
-//! [3]
+//! [2]
void Window::createControls(const QString &title)
-//! [3] //! [4]
+//! [2] //! [3]
{
controlsGroup = new QGroupBox(title);
@@ -59,9 +45,9 @@ void Window::createControls(const QString &title)
invertedAppearance = new QCheckBox(tr("Inverted appearance"));
invertedKeyBindings = new QCheckBox(tr("Inverted key bindings"));
-//! [4] //! [5]
+//! [3] //! [4]
minimumSpinBox = new QSpinBox;
-//! [5] //! [6]
+//! [4] //! [5]
minimumSpinBox->setRange(-100, 100);
minimumSpinBox->setSingleStep(1);
@@ -73,30 +59,19 @@ void Window::createControls(const QString &title)
valueSpinBox->setRange(-100, 100);
valueSpinBox->setSingleStep(1);
- orientationCombo = new QComboBox;
- orientationCombo->addItem(tr("Horizontal slider-like widgets"));
- orientationCombo->addItem(tr("Vertical slider-like widgets"));
-
-//! [6] //! [7]
- connect(orientationCombo, &QComboBox::activated,
-//! [7] //! [8]
- stackedWidget, &QStackedWidget::setCurrentIndex);
- connect(minimumSpinBox, &QSpinBox::valueChanged,
- horizontalSliders, &SlidersGroup::setMinimum);
+//! [5] //! [6]
+ connect(slidersGroup, &SlidersGroup::valueChanged,
+ valueSpinBox, &QSpinBox::setValue);
+ connect(valueSpinBox, &QSpinBox::valueChanged,
+ slidersGroup, &SlidersGroup::setValue);
connect(minimumSpinBox, &QSpinBox::valueChanged,
- verticalSliders, &SlidersGroup::setMinimum);
- connect(maximumSpinBox, &QSpinBox::valueChanged,
- horizontalSliders, &SlidersGroup::setMaximum);
+ slidersGroup, &SlidersGroup::setMinimum);
connect(maximumSpinBox, &QSpinBox::valueChanged,
- verticalSliders, &SlidersGroup::setMaximum);
+ slidersGroup, &SlidersGroup::setMaximum);
connect(invertedAppearance, &QCheckBox::toggled,
- horizontalSliders, &SlidersGroup::invertAppearance);
- connect(invertedAppearance, &QCheckBox::toggled,
- verticalSliders, &SlidersGroup::invertAppearance);
- connect(invertedKeyBindings, &QCheckBox::toggled,
- horizontalSliders, &SlidersGroup::invertKeyBindings);
+ slidersGroup, &SlidersGroup::invertAppearance);
connect(invertedKeyBindings, &QCheckBox::toggled,
- verticalSliders, &SlidersGroup::invertKeyBindings);
+ slidersGroup, &SlidersGroup::invertKeyBindings);
QGridLayout *controlsLayout = new QGridLayout;
controlsLayout->addWidget(minimumLabel, 0, 0);
@@ -107,40 +82,26 @@ void Window::createControls(const QString &title)
controlsLayout->addWidget(valueSpinBox, 2, 1);
controlsLayout->addWidget(invertedAppearance, 0, 2);
controlsLayout->addWidget(invertedKeyBindings, 1, 2);
- controlsLayout->addWidget(orientationCombo, 3, 0, 1, 3);
controlsGroup->setLayout(controlsLayout);
}
-//! [8]
+//! [6]
-void Window::resizeEvent(QResizeEvent *e)
+//! [7]
+void Window::resizeEvent(QResizeEvent *)
{
- Q_UNUSED(e);
if (width() == 0 || height() == 0)
return;
- const double aspectRatio = double(width()) / double(height());
-
- if ((aspectRatio < 1.0) && (oldAspectRatio > 1.0)) {
- layout->removeWidget(controlsGroup);
- layout->removeWidget(stackedWidget);
+ const double aspectRatio = double(width()) / double(height());
- layout->addWidget(stackedWidget, 1, 0);
- layout->addWidget(controlsGroup, 0, 0);
-
- oldAspectRatio = aspectRatio;
- }
- else if ((aspectRatio > 1.0) && (oldAspectRatio < 1.0)) {
- layout->removeWidget(controlsGroup);
- layout->removeWidget(stackedWidget);
-
- layout->addWidget(stackedWidget, 0, 1);
- layout->addWidget(controlsGroup, 0, 0);
-
- oldAspectRatio = aspectRatio;
+ if (aspectRatio < 1.0) {
+ layout->setDirection(QBoxLayout::TopToBottom);
+ slidersGroup->setOrientation(Qt::Horizontal);
+ } else if (aspectRatio > 1.0) {
+ layout->setDirection(QBoxLayout::LeftToRight);
+ slidersGroup->setOrientation(Qt::Vertical);
}
}
-
-
-
+//! [7]
diff --git a/examples/widgets/widgets/sliders/window.h b/examples/widgets/widgets/sliders/window.h
index fa627eabd3..8d7338f27c 100644
--- a/examples/widgets/widgets/sliders/window.h
+++ b/examples/widgets/widgets/sliders/window.h
@@ -29,9 +29,7 @@ private:
void createControls(const QString &title);
void resizeEvent(QResizeEvent *e);
- SlidersGroup *horizontalSliders;
- SlidersGroup *verticalSliders;
- QStackedWidget *stackedWidget;
+ SlidersGroup *slidersGroup;
QGroupBox *controlsGroup;
QLabel *minimumLabel;
@@ -42,9 +40,7 @@ private:
QSpinBox *minimumSpinBox;
QSpinBox *maximumSpinBox;
QSpinBox *valueSpinBox;
- QComboBox *orientationCombo;
- QGridLayout *layout;
- double oldAspectRatio;
+ QBoxLayout *layout;
};
//! [0]
diff --git a/examples/widgets/widgets/spinboxes/CMakeLists.txt b/examples/widgets/widgets/spinboxes/CMakeLists.txt
index fa1c395c07..83e54166bb 100644
--- a/examples/widgets/widgets/spinboxes/CMakeLists.txt
+++ b/examples/widgets/widgets/spinboxes/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(spinboxes LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/spinboxes")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -31,7 +25,14 @@ target_link_libraries(spinboxes PRIVATE
)
install(TARGETS spinboxes
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET spinboxes
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/styles/CMakeLists.txt b/examples/widgets/widgets/styles/CMakeLists.txt
deleted file mode 100644
index 9632f01a89..0000000000
--- a/examples/widgets/widgets/styles/CMakeLists.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(styles LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/styles")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(styles
- main.cpp
- norwegianwoodstyle.cpp norwegianwoodstyle.h
- widgetgallery.cpp widgetgallery.h
-)
-
-set_target_properties(styles PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(styles PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(styles_resource_files
- "images/woodbackground.png"
- "images/woodbutton.png"
-)
-
-qt_add_resources(styles "styles"
- PREFIX
- "/"
- FILES
- ${styles_resource_files}
-)
-
-install(TARGETS styles
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/styles/images/woodbackground.png b/examples/widgets/widgets/styles/images/woodbackground.png
deleted file mode 100644
index 8be3366bb4..0000000000
--- a/examples/widgets/widgets/styles/images/woodbackground.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/styles/images/woodbutton.png b/examples/widgets/widgets/styles/images/woodbutton.png
deleted file mode 100644
index adb59ef633..0000000000
--- a/examples/widgets/widgets/styles/images/woodbutton.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/styles/main.cpp b/examples/widgets/widgets/styles/main.cpp
deleted file mode 100644
index 936e01e77f..0000000000
--- a/examples/widgets/widgets/styles/main.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "norwegianwoodstyle.h"
-#include "widgetgallery.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(styles);
-
- QApplication::setStyle(new NorwegianWoodStyle);
-
- QApplication app(argc, argv);
- WidgetGallery gallery;
- gallery.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
deleted file mode 100644
index a8969dfd54..0000000000
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
+++ /dev/null
@@ -1,310 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "norwegianwoodstyle.h"
-
-#include <QComboBox>
-#include <QPainter>
-#include <QPainterPath>
-#include <QPushButton>
-#include <QStyleFactory>
-
-NorwegianWoodStyle::NorwegianWoodStyle() :
- QProxyStyle(QStyleFactory::create("windows"))
-{
- setObjectName("NorwegianWood");
-}
-
-//! [0]
-QPalette NorwegianWoodStyle::standardPalette() const
-{
- if (!m_standardPalette.isBrushSet(QPalette::Disabled, QPalette::Mid)) {
- QColor brown(212, 140, 95);
- QColor beige(236, 182, 120);
- QColor slightlyOpaqueBlack(0, 0, 0, 63);
-
- QImage backgroundImage(":/images/woodbackground.png");
- QImage buttonImage(":/images/woodbutton.png");
- QImage midImage = buttonImage.convertToFormat(QImage::Format_RGB32);
-
- QPainter painter;
- painter.begin(&midImage);
- painter.setPen(Qt::NoPen);
- painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
- painter.end();
- //! [0]
-
- //! [1]
- QPalette palette(brown);
-
- palette.setBrush(QPalette::BrightText, Qt::white);
- palette.setBrush(QPalette::Base, beige);
- palette.setBrush(QPalette::Highlight, Qt::darkGreen);
- setTexture(palette, QPalette::Button, buttonImage);
- setTexture(palette, QPalette::Mid, midImage);
- setTexture(palette, QPalette::Window, backgroundImage);
-
- QBrush brush = palette.window();
- brush.setColor(brush.color().darker());
-
- palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
- palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);
-
- m_standardPalette = palette;
- }
-
- return m_standardPalette;
-}
-//! [1]
-
-//! [3]
-void NorwegianWoodStyle::polish(QWidget *widget)
-//! [3] //! [4]
-{
- if (qobject_cast<QPushButton *>(widget)
- || qobject_cast<QComboBox *>(widget))
- widget->setAttribute(Qt::WA_Hover, true);
-}
-//! [4]
-
-//! [5]
-void NorwegianWoodStyle::unpolish(QWidget *widget)
-//! [5] //! [6]
-{
- if (qobject_cast<QPushButton *>(widget)
- || qobject_cast<QComboBox *>(widget))
- widget->setAttribute(Qt::WA_Hover, false);
-}
-//! [6]
-
-//! [7]
-int NorwegianWoodStyle::pixelMetric(PixelMetric metric,
-//! [7] //! [8]
- const QStyleOption *option,
- const QWidget *widget) const
-{
- switch (metric) {
- case PM_ComboBoxFrameWidth:
- return 8;
- case PM_ScrollBarExtent:
- return QProxyStyle::pixelMetric(metric, option, widget) + 4;
- default:
- return QProxyStyle::pixelMetric(metric, option, widget);
- }
-}
-//! [8]
-
-//! [9]
-int NorwegianWoodStyle::styleHint(StyleHint hint, const QStyleOption *option,
-//! [9] //! [10]
- const QWidget *widget,
- QStyleHintReturn *returnData) const
-{
- switch (hint) {
- case SH_DitherDisabledText:
- return int(false);
- case SH_EtchDisabledText:
- return int(true);
- default:
- return QProxyStyle::styleHint(hint, option, widget, returnData);
- }
-}
-//! [10]
-
-//! [11]
-void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element,
-//! [11] //! [12]
- const QStyleOption *option,
- QPainter *painter,
- const QWidget *widget) const
-{
- switch (element) {
- case PE_PanelButtonCommand:
- {
- int delta = (option->state & State_MouseOver) ? 64 : 0;
- QColor slightlyOpaqueBlack(0, 0, 0, 63);
- QColor semiTransparentWhite(255, 255, 255, 127 + delta);
- QColor semiTransparentBlack(0, 0, 0, 127 - delta);
-
- int x, y, width, height;
- option->rect.getRect(&x, &y, &width, &height);
-//! [12]
-
-//! [13]
- QPainterPath roundRect = roundRectPath(option->rect);
-//! [13] //! [14]
- int radius = qMin(width, height) / 2;
-//! [14]
-
-//! [15]
- QBrush brush;
-//! [15] //! [16]
- bool darker;
-
- const QStyleOptionButton *buttonOption =
- qstyleoption_cast<const QStyleOptionButton *>(option);
- if (buttonOption
- && (buttonOption->features & QStyleOptionButton::Flat)) {
- brush = option->palette.window();
- darker = (option->state & (State_Sunken | State_On));
- } else {
- if (option->state & (State_Sunken | State_On)) {
- brush = option->palette.mid();
- darker = !(option->state & State_Sunken);
- } else {
- brush = option->palette.button();
- darker = false;
-//! [16] //! [17]
- }
-//! [17] //! [18]
- }
-//! [18]
-
-//! [19]
- painter->save();
-//! [19] //! [20]
- painter->setRenderHint(QPainter::Antialiasing, true);
-//! [20] //! [21]
- painter->fillPath(roundRect, brush);
-//! [21] //! [22]
- if (darker)
-//! [22] //! [23]
- painter->fillPath(roundRect, slightlyOpaqueBlack);
-//! [23]
-
-//! [24]
- int penWidth;
-//! [24] //! [25]
- if (radius < 10)
- penWidth = 3;
- else if (radius < 20)
- penWidth = 5;
- else
- penWidth = 7;
-
- QPen topPen(semiTransparentWhite, penWidth);
- QPen bottomPen(semiTransparentBlack, penWidth);
-
- if (option->state & (State_Sunken | State_On))
- qSwap(topPen, bottomPen);
-//! [25]
-
-//! [26]
- int x1 = x;
- int x2 = x + radius;
- int x3 = x + width - radius;
- int x4 = x + width;
-
- if (option->direction == Qt::RightToLeft) {
- qSwap(x1, x4);
- qSwap(x2, x3);
- }
-
- QPolygon topHalf;
- topHalf << QPoint(x1, y)
- << QPoint(x4, y)
- << QPoint(x3, y + radius)
- << QPoint(x2, y + height - radius)
- << QPoint(x1, y + height);
-
- painter->setClipPath(roundRect);
- painter->setClipRegion(topHalf, Qt::IntersectClip);
- painter->setPen(topPen);
- painter->drawPath(roundRect);
-//! [26] //! [32]
-
- QPolygon bottomHalf = topHalf;
- bottomHalf[0] = QPoint(x4, y + height);
-
- painter->setClipPath(roundRect);
- painter->setClipRegion(bottomHalf, Qt::IntersectClip);
- painter->setPen(bottomPen);
- painter->drawPath(roundRect);
-
- painter->setPen(option->palette.windowText().color());
- painter->setClipping(false);
- painter->drawPath(roundRect);
-
- painter->restore();
- }
- break;
-//! [32] //! [33]
- default:
-//! [33] //! [34]
- QProxyStyle::drawPrimitive(element, option, painter, widget);
- }
-}
-//! [34]
-
-//! [35]
-void NorwegianWoodStyle::drawControl(ControlElement element,
-//! [35] //! [36]
- const QStyleOption *option,
- QPainter *painter,
- const QWidget *widget) const
-{
- switch (element) {
- case CE_PushButtonLabel:
- {
- QStyleOptionButton myButtonOption;
- const QStyleOptionButton *buttonOption =
- qstyleoption_cast<const QStyleOptionButton *>(option);
- if (buttonOption) {
- myButtonOption = *buttonOption;
- if (myButtonOption.palette.currentColorGroup()
- != QPalette::Disabled) {
- if (myButtonOption.state & (State_Sunken | State_On)) {
- myButtonOption.palette.setBrush(QPalette::ButtonText,
- myButtonOption.palette.brightText());
- }
- }
- }
- QProxyStyle::drawControl(element, &myButtonOption, painter, widget);
- }
- break;
- default:
- QProxyStyle::drawControl(element, option, painter, widget);
- }
-}
-//! [36]
-
-//! [37]
-void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role,
-//! [37] //! [38]
- const QImage &image)
-{
- for (int i = 0; i < QPalette::NColorGroups; ++i) {
- QBrush brush(image);
- brush.setColor(palette.brush(QPalette::ColorGroup(i), role).color());
- palette.setBrush(QPalette::ColorGroup(i), role, brush);
- }
-}
-//! [38]
-
-//! [39]
-QPainterPath NorwegianWoodStyle::roundRectPath(const QRect &rect)
-//! [39] //! [40]
-{
- int radius = qMin(rect.width(), rect.height()) / 2;
- int diam = 2 * radius;
-
- int x1, y1, x2, y2;
- rect.getCoords(&x1, &y1, &x2, &y2);
-
- QPainterPath path;
- path.moveTo(x2, y1 + radius);
- path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0);
- path.lineTo(x1 + radius, y1);
- path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0);
- path.lineTo(x1, y2 - radius);
- path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0);
- path.lineTo(x1 + radius, y2);
- path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0);
- path.closeSubpath();
- return path;
-}
-//! [40]
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.h b/examples/widgets/widgets/styles/norwegianwoodstyle.h
deleted file mode 100644
index 5af2171f35..0000000000
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef NORWEGIANWOODSTYLE_H
-#define NORWEGIANWOODSTYLE_H
-
-#include <QProxyStyle>
-#include <QPalette>
-
-QT_BEGIN_NAMESPACE
-class QPainterPath;
-QT_END_NAMESPACE
-
-//! [0]
-class NorwegianWoodStyle : public QProxyStyle
-{
- Q_OBJECT
-
-public:
- NorwegianWoodStyle();
-
- QPalette standardPalette() const override;
-
- void polish(QWidget *widget) override;
- void unpolish(QWidget *widget) override;
- int pixelMetric(PixelMetric metric, const QStyleOption *option,
- const QWidget *widget) const override;
- int styleHint(StyleHint hint, const QStyleOption *option,
- const QWidget *widget, QStyleHintReturn *returnData) const override;
- void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
- QPainter *painter, const QWidget *widget) const override;
- void drawControl(ControlElement control, const QStyleOption *option,
- QPainter *painter, const QWidget *widget) const override;
-
-private:
- static void setTexture(QPalette &palette, QPalette::ColorRole role,
- const QImage &image);
- static QPainterPath roundRectPath(const QRect &rect);
- mutable QPalette m_standardPalette;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/styles/styles.pro b/examples/widgets/widgets/styles/styles.pro
deleted file mode 100644
index 87dee7e04c..0000000000
--- a/examples/widgets/widgets/styles/styles.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = norwegianwoodstyle.h \
- widgetgallery.h
-SOURCES = main.cpp \
- norwegianwoodstyle.cpp \
- widgetgallery.cpp
-RESOURCES = styles.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/styles
-INSTALLS += target
diff --git a/examples/widgets/widgets/styles/styles.qrc b/examples/widgets/widgets/styles/styles.qrc
deleted file mode 100644
index 4fdad8d914..0000000000
--- a/examples/widgets/widgets/styles/styles.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/woodbutton.png</file>
- <file>images/woodbackground.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/widgets/styles/widgetgallery.cpp b/examples/widgets/widgets/styles/widgetgallery.cpp
deleted file mode 100644
index 83cb99a52c..0000000000
--- a/examples/widgets/widgets/styles/widgetgallery.cpp
+++ /dev/null
@@ -1,277 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "widgetgallery.h"
-#include "norwegianwoodstyle.h"
-
-#include <QApplication>
-#include <QCheckBox>
-#include <QComboBox>
-#include <QDateTimeEdit>
-#include <QDial>
-#include <QGridLayout>
-#include <QGroupBox>
-#include <QLabel>
-#include <QLineEdit>
-#include <QProgressBar>
-#include <QPushButton>
-#include <QRadioButton>
-#include <QScrollBar>
-#include <QSpinBox>
-#include <QStyle>
-#include <QStyleFactory>
-#include <QTableWidget>
-#include <QTextEdit>
-#include <QTimer>
-
-//! [0]
-WidgetGallery::WidgetGallery(QWidget *parent)
- : QDialog(parent)
-{
- styleComboBox = new QComboBox;
- const QString defaultStyleName = QApplication::style()->objectName();
- QStringList styleNames = QStyleFactory::keys();
- styleNames.append("NorwegianWood");
- for (int i = 1, size = styleNames.size(); i < size; ++i) {
- if (defaultStyleName.compare(styleNames.at(i), Qt::CaseInsensitive) == 0) {
- styleNames.swapItemsAt(0, i);
- break;
- }
- }
- styleComboBox->addItems(styleNames);
-
- styleLabel = new QLabel(tr("&Style:"));
- styleLabel->setBuddy(styleComboBox);
-
- useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette"));
- useStylePaletteCheckBox->setChecked(true);
-
- disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets"));
-
- createTopLeftGroupBox();
- createTopRightGroupBox();
- createBottomLeftTabWidget();
- createBottomRightGroupBox();
- createProgressBar();
-//! [0]
-
-//! [1]
- connect(styleComboBox, &QComboBox::textActivated,
-//! [1] //! [2]
- this, &WidgetGallery::changeStyle);
- connect(useStylePaletteCheckBox, &QCheckBox::toggled,
- this, &WidgetGallery::changePalette);
- connect(disableWidgetsCheckBox, &QCheckBox::toggled,
- topLeftGroupBox, &QGroupBox::setDisabled);
- connect(disableWidgetsCheckBox, &QCheckBox::toggled,
- topRightGroupBox, &QGroupBox::setDisabled);
- connect(disableWidgetsCheckBox, &QCheckBox::toggled,
- bottomLeftTabWidget, &QGroupBox::setDisabled);
- connect(disableWidgetsCheckBox, &QCheckBox::toggled,
- bottomRightGroupBox, &QGroupBox::setDisabled);
-//! [2]
-
-//! [3]
- QHBoxLayout *topLayout = new QHBoxLayout;
-//! [3] //! [4]
- topLayout->addWidget(styleLabel);
- topLayout->addWidget(styleComboBox);
- topLayout->addStretch(1);
- topLayout->addWidget(useStylePaletteCheckBox);
- topLayout->addWidget(disableWidgetsCheckBox);
-
- QGridLayout *mainLayout = new QGridLayout;
- mainLayout->addLayout(topLayout, 0, 0, 1, 2);
- mainLayout->addWidget(topLeftGroupBox, 1, 0);
- mainLayout->addWidget(topRightGroupBox, 1, 1);
- mainLayout->addWidget(bottomLeftTabWidget, 2, 0);
- mainLayout->addWidget(bottomRightGroupBox, 2, 1);
- mainLayout->addWidget(progressBar, 3, 0, 1, 2);
- mainLayout->setRowStretch(1, 1);
- mainLayout->setRowStretch(2, 1);
- mainLayout->setColumnStretch(0, 1);
- mainLayout->setColumnStretch(1, 1);
- setLayout(mainLayout);
-
- setWindowTitle(tr("Styles"));
- styleChanged();
-}
-//! [4]
-
-//! [5]
-void WidgetGallery::changeStyle(const QString &styleName)
-//! [5] //! [6]
-{
- if (styleName == "NorwegianWood")
- QApplication::setStyle(new NorwegianWoodStyle);
- else
- QApplication::setStyle(QStyleFactory::create(styleName));
-}
-//! [6]
-
-//! [7]
-void WidgetGallery::changePalette()
-//! [7] //! [8]
-{
- QApplication::setPalette(useStylePaletteCheckBox->isChecked() ?
- QApplication::style()->standardPalette() : QPalette());
-}
-//! [8]
-
-void WidgetGallery::changeEvent(QEvent *event)
-{
- if (event->type() == QEvent::StyleChange)
- styleChanged();
-}
-
-void WidgetGallery::styleChanged()
-{
- auto styleName = QApplication::style()->objectName();
- for (int i = 0; i < styleComboBox->count(); ++i) {
- if (QString::compare(styleComboBox->itemText(i), styleName, Qt::CaseInsensitive) == 0) {
- styleComboBox->setCurrentIndex(i);
- break;
- }
- }
-
- changePalette();
-}
-
-//! [9]
-void WidgetGallery::advanceProgressBar()
-//! [9] //! [10]
-{
- int curVal = progressBar->value();
- int maxVal = progressBar->maximum();
- progressBar->setValue(curVal + (maxVal - curVal) / 100);
-}
-//! [10]
-
-//! [11]
-void WidgetGallery::createTopLeftGroupBox()
-//! [11] //! [12]
-{
- topLeftGroupBox = new QGroupBox(tr("Group 1"));
-
- radioButton1 = new QRadioButton(tr("Radio button 1"));
- radioButton2 = new QRadioButton(tr("Radio button 2"));
- radioButton3 = new QRadioButton(tr("Radio button 3"));
- radioButton1->setChecked(true);
-
- checkBox = new QCheckBox(tr("Tri-state check box"));
- checkBox->setTristate(true);
- checkBox->setCheckState(Qt::PartiallyChecked);
-
- QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(radioButton1);
- layout->addWidget(radioButton2);
- layout->addWidget(radioButton3);
- layout->addWidget(checkBox);
- layout->addStretch(1);
- topLeftGroupBox->setLayout(layout);
-}
-//! [12]
-
-void WidgetGallery::createTopRightGroupBox()
-{
- topRightGroupBox = new QGroupBox(tr("Group 2"));
-
- defaultPushButton = new QPushButton(tr("Default Push Button"));
- defaultPushButton->setDefault(true);
-
- togglePushButton = new QPushButton(tr("Toggle Push Button"));
- togglePushButton->setCheckable(true);
- togglePushButton->setChecked(true);
-
- flatPushButton = new QPushButton(tr("Flat Push Button"));
- flatPushButton->setFlat(true);
-
- QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(defaultPushButton);
- layout->addWidget(togglePushButton);
- layout->addWidget(flatPushButton);
- layout->addStretch(1);
- topRightGroupBox->setLayout(layout);
-}
-
-void WidgetGallery::createBottomLeftTabWidget()
-{
- bottomLeftTabWidget = new QTabWidget;
- bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Ignored);
-
- QWidget *tab1 = new QWidget;
- tableWidget = new QTableWidget(10, 10);
-
- QHBoxLayout *tab1hbox = new QHBoxLayout;
- tab1hbox->setContentsMargins(5,5, 5, 5);
- tab1hbox->addWidget(tableWidget);
- tab1->setLayout(tab1hbox);
-
- QWidget *tab2 = new QWidget;
- textEdit = new QTextEdit;
-
- textEdit->setPlainText(tr("Twinkle, twinkle, little star,\n"
- "How I wonder what you are.\n"
- "Up above the world so high,\n"
- "Like a diamond in the sky.\n"
- "Twinkle, twinkle, little star,\n"
- "How I wonder what you are!\n"));
-
- QHBoxLayout *tab2hbox = new QHBoxLayout;
- tab2hbox->setContentsMargins(5, 5, 5, 5);
- tab2hbox->addWidget(textEdit);
- tab2->setLayout(tab2hbox);
-
- bottomLeftTabWidget->addTab(tab1, tr("&Table"));
- bottomLeftTabWidget->addTab(tab2, tr("Text &Edit"));
-}
-
-void WidgetGallery::createBottomRightGroupBox()
-{
- bottomRightGroupBox = new QGroupBox(tr("Group 3"));
- bottomRightGroupBox->setCheckable(true);
- bottomRightGroupBox->setChecked(true);
-
- lineEdit = new QLineEdit("s3cRe7");
- lineEdit->setEchoMode(QLineEdit::Password);
-
- spinBox = new QSpinBox(bottomRightGroupBox);
- spinBox->setValue(50);
-
- dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox);
- dateTimeEdit->setDateTime(QDateTime::currentDateTime());
-
- slider = new QSlider(Qt::Horizontal, bottomRightGroupBox);
- slider->setValue(40);
-
- scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox);
- scrollBar->setValue(60);
-
- dial = new QDial(bottomRightGroupBox);
- dial->setValue(30);
- dial->setNotchesVisible(true);
-
- QGridLayout *layout = new QGridLayout;
- layout->addWidget(lineEdit, 0, 0, 1, 2);
- layout->addWidget(spinBox, 1, 0, 1, 2);
- layout->addWidget(dateTimeEdit, 2, 0, 1, 2);
- layout->addWidget(slider, 3, 0);
- layout->addWidget(scrollBar, 4, 0);
- layout->addWidget(dial, 3, 1, 2, 1);
- layout->setRowStretch(5, 1);
- bottomRightGroupBox->setLayout(layout);
-}
-
-//! [13]
-void WidgetGallery::createProgressBar()
-{
- progressBar = new QProgressBar;
- progressBar->setRange(0, 10000);
- progressBar->setValue(0);
-
- QTimer *timer = new QTimer(this);
- connect(timer, &QTimer::timeout, this, &WidgetGallery::advanceProgressBar);
- timer->start(1000);
-}
-//! [13]
diff --git a/examples/widgets/widgets/styles/widgetgallery.h b/examples/widgets/widgets/styles/widgetgallery.h
deleted file mode 100644
index f4c43e7b4f..0000000000
--- a/examples/widgets/widgets/styles/widgetgallery.h
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WIDGETGALLERY_H
-#define WIDGETGALLERY_H
-
-#include <QDialog>
-
-QT_BEGIN_NAMESPACE
-class QCheckBox;
-class QComboBox;
-class QDateTimeEdit;
-class QDial;
-class QGroupBox;
-class QLabel;
-class QLineEdit;
-class QProgressBar;
-class QPushButton;
-class QRadioButton;
-class QScrollBar;
-class QSlider;
-class QSpinBox;
-class QTabWidget;
-class QTableWidget;
-class QTextEdit;
-QT_END_NAMESPACE
-
-//! [0]
-class WidgetGallery : public QDialog
-{
- Q_OBJECT
-
-public:
- WidgetGallery(QWidget *parent = nullptr);
-
-protected:
- void changeEvent(QEvent *) override;
-
-private slots:
- void changeStyle(const QString &styleName);
- void styleChanged();
- void changePalette();
- void advanceProgressBar();
-
-private:
- void createTopLeftGroupBox();
- void createTopRightGroupBox();
- void createBottomLeftTabWidget();
- void createBottomRightGroupBox();
- void createProgressBar();
-
- QLabel *styleLabel;
- QComboBox *styleComboBox;
- QCheckBox *useStylePaletteCheckBox;
- QCheckBox *disableWidgetsCheckBox;
-//! [0]
-
- QGroupBox *topLeftGroupBox;
- QRadioButton *radioButton1;
- QRadioButton *radioButton2;
- QRadioButton *radioButton3;
- QCheckBox *checkBox;
-
- QGroupBox *topRightGroupBox;
- QPushButton *defaultPushButton;
- QPushButton *togglePushButton;
- QPushButton *flatPushButton;
-
- QTabWidget *bottomLeftTabWidget;
- QTableWidget *tableWidget;
- QTextEdit *textEdit;
-
- QGroupBox *bottomRightGroupBox;
- QLineEdit *lineEdit;
- QSpinBox *spinBox;
- QDateTimeEdit *dateTimeEdit;
- QSlider *slider;
- QScrollBar *scrollBar;
- QDial *dial;
-
- QProgressBar *progressBar;
-//! [1]
-};
-//! [1]
-
-#endif
diff --git a/examples/widgets/widgets/stylesheet/CMakeLists.txt b/examples/widgets/widgets/stylesheet/CMakeLists.txt
deleted file mode 100644
index a6b7fbeb1e..0000000000
--- a/examples/widgets/widgets/stylesheet/CMakeLists.txt
+++ /dev/null
@@ -1,84 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(stylesheet LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/stylesheet")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(stylesheet
- main.cpp
- mainwindow.cpp mainwindow.h mainwindow.ui
- stylesheeteditor.cpp stylesheeteditor.h stylesheeteditor.ui
-)
-
-set_target_properties(stylesheet PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(stylesheet PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(stylesheet_resource_files
- "images/checkbox_checked.png"
- "images/checkbox_checked_hover.png"
- "images/checkbox_checked_pressed.png"
- "images/checkbox_unchecked.png"
- "images/checkbox_unchecked_hover.png"
- "images/checkbox_unchecked_pressed.png"
- "images/down_arrow.png"
- "images/down_arrow_disabled.png"
- "images/frame.png"
- "images/pagefold.png"
- "images/pushbutton.png"
- "images/pushbutton_hover.png"
- "images/pushbutton_pressed.png"
- "images/radiobutton_checked.png"
- "images/radiobutton_checked_hover.png"
- "images/radiobutton_checked_pressed.png"
- "images/radiobutton_unchecked.png"
- "images/radiobutton_unchecked_hover.png"
- "images/radiobutton_unchecked_pressed.png"
- "images/sizegrip.png"
- "images/spindown.png"
- "images/spindown_hover.png"
- "images/spindown_off.png"
- "images/spindown_pressed.png"
- "images/spinup.png"
- "images/spinup_hover.png"
- "images/spinup_off.png"
- "images/spinup_pressed.png"
- "images/up_arrow.png"
- "images/up_arrow_disabled.png"
- "layouts/default.ui"
- "layouts/pagefold.ui"
- "qss/coffee.qss"
- "qss/default.qss"
- "qss/pagefold.qss"
-)
-
-qt_add_resources(stylesheet "stylesheet"
- PREFIX
- "/"
- FILES
- ${stylesheet_resource_files}
-)
-
-install(TARGETS stylesheet
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/stylesheet/images/checkbox_checked.png b/examples/widgets/widgets/stylesheet/images/checkbox_checked.png
deleted file mode 100644
index cbf06f6513..0000000000
--- a/examples/widgets/widgets/stylesheet/images/checkbox_checked.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/checkbox_checked_hover.png b/examples/widgets/widgets/stylesheet/images/checkbox_checked_hover.png
deleted file mode 100644
index fb4d4d3fdb..0000000000
--- a/examples/widgets/widgets/stylesheet/images/checkbox_checked_hover.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/checkbox_checked_pressed.png b/examples/widgets/widgets/stylesheet/images/checkbox_checked_pressed.png
deleted file mode 100644
index 852fcc0306..0000000000
--- a/examples/widgets/widgets/stylesheet/images/checkbox_checked_pressed.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/checkbox_unchecked.png b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked.png
deleted file mode 100644
index 5f5465582a..0000000000
--- a/examples/widgets/widgets/stylesheet/images/checkbox_unchecked.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_hover.png b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_hover.png
deleted file mode 100644
index 687364497e..0000000000
--- a/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_hover.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_pressed.png b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_pressed.png
deleted file mode 100644
index 6a768c44de..0000000000
--- a/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_pressed.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/down_arrow.png b/examples/widgets/widgets/stylesheet/images/down_arrow.png
deleted file mode 100644
index 85004aeaf6..0000000000
--- a/examples/widgets/widgets/stylesheet/images/down_arrow.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/down_arrow_disabled.png b/examples/widgets/widgets/stylesheet/images/down_arrow_disabled.png
deleted file mode 100644
index d9eefed4c8..0000000000
--- a/examples/widgets/widgets/stylesheet/images/down_arrow_disabled.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/frame.png b/examples/widgets/widgets/stylesheet/images/frame.png
deleted file mode 100644
index 05a600502e..0000000000
--- a/examples/widgets/widgets/stylesheet/images/frame.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/pagefold.png b/examples/widgets/widgets/stylesheet/images/pagefold.png
deleted file mode 100644
index 69be8f2a38..0000000000
--- a/examples/widgets/widgets/stylesheet/images/pagefold.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/pushbutton.png b/examples/widgets/widgets/stylesheet/images/pushbutton.png
deleted file mode 100644
index c7529ba02d..0000000000
--- a/examples/widgets/widgets/stylesheet/images/pushbutton.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/pushbutton_hover.png b/examples/widgets/widgets/stylesheet/images/pushbutton_hover.png
deleted file mode 100644
index af0ef9d561..0000000000
--- a/examples/widgets/widgets/stylesheet/images/pushbutton_hover.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/pushbutton_pressed.png b/examples/widgets/widgets/stylesheet/images/pushbutton_pressed.png
deleted file mode 100644
index f7381f752a..0000000000
--- a/examples/widgets/widgets/stylesheet/images/pushbutton_pressed.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/radiobutton_checked.png b/examples/widgets/widgets/stylesheet/images/radiobutton_checked.png
deleted file mode 100644
index 8ab9157578..0000000000
--- a/examples/widgets/widgets/stylesheet/images/radiobutton_checked.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/radiobutton_checked_hover.png b/examples/widgets/widgets/stylesheet/images/radiobutton_checked_hover.png
deleted file mode 100644
index d68cb009a7..0000000000
--- a/examples/widgets/widgets/stylesheet/images/radiobutton_checked_hover.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/radiobutton_checked_pressed.png b/examples/widgets/widgets/stylesheet/images/radiobutton_checked_pressed.png
deleted file mode 100644
index e3cd5a59e4..0000000000
--- a/examples/widgets/widgets/stylesheet/images/radiobutton_checked_pressed.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked.png b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked.png
deleted file mode 100644
index 321a9a1558..0000000000
--- a/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_hover.png b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_hover.png
deleted file mode 100644
index 666a3b0bdd..0000000000
--- a/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_hover.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_pressed.png b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_pressed.png
deleted file mode 100644
index c4b0567aa9..0000000000
--- a/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_pressed.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/sizegrip.png b/examples/widgets/widgets/stylesheet/images/sizegrip.png
deleted file mode 100644
index 350583aaac..0000000000
--- a/examples/widgets/widgets/stylesheet/images/sizegrip.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spindown.png b/examples/widgets/widgets/stylesheet/images/spindown.png
deleted file mode 100644
index 7ff3c64926..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spindown.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spindown_hover.png b/examples/widgets/widgets/stylesheet/images/spindown_hover.png
deleted file mode 100644
index 1486c4dfe4..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spindown_hover.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spindown_off.png b/examples/widgets/widgets/stylesheet/images/spindown_off.png
deleted file mode 100644
index a90ab3f038..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spindown_off.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spindown_pressed.png b/examples/widgets/widgets/stylesheet/images/spindown_pressed.png
deleted file mode 100644
index f6271cbde2..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spindown_pressed.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spinup.png b/examples/widgets/widgets/stylesheet/images/spinup.png
deleted file mode 100644
index 1069dd00df..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spinup.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spinup_hover.png b/examples/widgets/widgets/stylesheet/images/spinup_hover.png
deleted file mode 100644
index 884c8d77c5..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spinup_hover.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spinup_off.png b/examples/widgets/widgets/stylesheet/images/spinup_off.png
deleted file mode 100644
index 02dad1fb29..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spinup_off.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/spinup_pressed.png b/examples/widgets/widgets/stylesheet/images/spinup_pressed.png
deleted file mode 100644
index b1843e2a1f..0000000000
--- a/examples/widgets/widgets/stylesheet/images/spinup_pressed.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/up_arrow.png b/examples/widgets/widgets/stylesheet/images/up_arrow.png
deleted file mode 100644
index e7f7ddb3a6..0000000000
--- a/examples/widgets/widgets/stylesheet/images/up_arrow.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/images/up_arrow_disabled.png b/examples/widgets/widgets/stylesheet/images/up_arrow_disabled.png
deleted file mode 100644
index 4d2c27770f..0000000000
--- a/examples/widgets/widgets/stylesheet/images/up_arrow_disabled.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/stylesheet/layouts/default.ui b/examples/widgets/widgets/stylesheet/layouts/default.ui
deleted file mode 100644
index 431a40956e..0000000000
--- a/examples/widgets/widgets/stylesheet/layouts/default.ui
+++ /dev/null
@@ -1,329 +0,0 @@
-<ui version="4.0" >
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>388</width>
- <height>413</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>MainWindow</string>
- </property>
- <widget class="QWidget" name="centralwidget" >
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="0" column="0" >
- <widget class="QLabel" name="nameLabel" >
- <property name="text" >
- <string>&amp;Name:</string>
- </property>
- <property name="buddy" >
- <cstring>nameCombo</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="1" colspan="3" >
- <widget class="QComboBox" name="nameCombo" >
- <property name="toolTip" >
- <string>Specify your name</string>
- </property>
- <property name="editable" >
- <bool>true</bool>
- </property>
- <property name="currentIndex" >
- <number>-1</number>
- </property>
- <item>
- <property name="text" >
- <string>Girish</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Jasmin</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Simon</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Zack</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="1" column="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="1" column="2" >
- <widget class="QRadioButton" name="femaleRadioButton" >
- <property name="toolTip" >
- <string>Check this if you are female</string>
- </property>
- <property name="text" >
- <string>&amp;Female</string>
- </property>
- </widget>
- </item>
- <item row="6" column="0" colspan="4" >
- <widget class="QCheckBox" name="agreeCheckBox" >
- <property name="toolTip" >
- <string>Please read the license before checking this</string>
- </property>
- <property name="text" >
- <string>I &amp;accept the terms and conditions</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="QRadioButton" name="maleRadioButton" >
- <property name="toolTip" >
- <string>Check this if you are male</string>
- </property>
- <property name="text" >
- <string>&amp;Male</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QLabel" name="genderLabel" >
- <property name="text" >
- <string>Gender:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1" colspan="3" >
- <widget class="QSpinBox" name="ageSpinBox" >
- <property name="toolTip" >
- <string>Specify your age</string>
- </property>
- <property name="statusTip" >
- <string>Specify your age here</string>
- </property>
- <property name="minimum" >
- <number>12</number>
- </property>
- <property name="value" >
- <number>22</number>
- </property>
- </widget>
- </item>
- <item row="7" column="2" colspan="2" >
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- <item row="2" column="0" >
- <widget class="QLabel" name="ageLabel" >
- <property name="text" >
- <string>&amp;Age:</string>
- </property>
- <property name="buddy" >
- <cstring>ageSpinBox</cstring>
- </property>
- </widget>
- </item>
- <item row="3" column="0" >
- <widget class="QLabel" name="passwordLabel" >
- <property name="text" >
- <string>&amp;Password:</string>
- </property>
- <property name="buddy" >
- <cstring>passwordEdit</cstring>
- </property>
- </widget>
- </item>
- <item row="3" column="1" colspan="3" >
- <widget class="QLineEdit" name="passwordEdit" >
- <property name="toolTip" >
- <string>Specify your password</string>
- </property>
- <property name="statusTip" >
- <string>Specify your password here</string>
- </property>
- <property name="text" >
- <string>Password</string>
- </property>
- <property name="echoMode" >
- <enum>QLineEdit::Password</enum>
- </property>
- </widget>
- </item>
- <item row="5" column="0" >
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>Profession</string>
- </property>
- <property name="buddy" >
- <cstring>professionList</cstring>
- </property>
- </widget>
- </item>
- <item row="4" column="0" >
- <widget class="QLabel" name="countryLabel" >
- <property name="text" >
- <string>&amp;Country</string>
- </property>
- <property name="buddy" >
- <cstring>professionList</cstring>
- </property>
- </widget>
- </item>
- <item row="5" column="1" colspan="3" >
- <widget class="QListWidget" name="professionList" >
- <property name="toolTip" >
- <string>Select your profession</string>
- </property>
- <property name="statusTip" >
- <string>Select your profession</string>
- </property>
- <property name="whatsThis" >
- <string>Select your profession</string>
- </property>
- <property name="currentRow" >
- <number>1</number>
- </property>
- <item>
- <property name="text" >
- <string>Developer</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Student</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Fisherman</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="4" column="1" colspan="3" >
- <widget class="QComboBox" name="countryCombo" >
- <property name="toolTip" >
- <string>Specify your country</string>
- </property>
- <property name="statusTip" >
- <string>Specify your country here</string>
- </property>
- <property name="currentIndex" >
- <number>2</number>
- </property>
- <item>
- <property name="text" >
- <string>Germany</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>India</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Norway</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>United States Of America</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>United Kingdom</string>
- </property>
- </item>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menubar" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>388</width>
- <height>21</height>
- </rect>
- </property>
- <widget class="QMenu" name="menu_File" >
- <property name="title" >
- <string>&amp;File</string>
- </property>
- <addaction name="editStyleAction" />
- <addaction name="separator" />
- <addaction name="exitAction" />
- </widget>
- <widget class="QMenu" name="menu_Help" >
- <property name="title" >
- <string>&amp;Help</string>
- </property>
- <addaction name="aboutAction" />
- <addaction name="separator" />
- <addaction name="aboutQtAction" />
- </widget>
- <addaction name="menu_File" />
- <addaction name="menu_Help" />
- </widget>
- <widget class="QStatusBar" name="statusbar" />
- <action name="exitAction" >
- <property name="text" >
- <string>&amp;Exit</string>
- </property>
- </action>
- <action name="aboutQtAction" >
- <property name="text" >
- <string>About Qt</string>
- </property>
- </action>
- <action name="editStyleAction" >
- <property name="text" >
- <string>Edit &amp;Style</string>
- </property>
- </action>
- <action name="aboutAction" >
- <property name="text" >
- <string>About</string>
- </property>
- </action>
- </widget>
- <tabstops>
- <tabstop>maleRadioButton</tabstop>
- <tabstop>femaleRadioButton</tabstop>
- <tabstop>ageSpinBox</tabstop>
- <tabstop>passwordEdit</tabstop>
- <tabstop>professionList</tabstop>
- <tabstop>agreeCheckBox</tabstop>
- </tabstops>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/widgets/widgets/stylesheet/layouts/pagefold.ui b/examples/widgets/widgets/stylesheet/layouts/pagefold.ui
deleted file mode 100644
index 7ae313c331..0000000000
--- a/examples/widgets/widgets/stylesheet/layouts/pagefold.ui
+++ /dev/null
@@ -1,349 +0,0 @@
-<ui version="4.0" >
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>392</width>
- <height>412</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>MainWindow</string>
- </property>
- <widget class="QWidget" name="centralwidget" >
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QFrame" name="mainFrame" >
- <property name="frameShape" >
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow" >
- <enum>QFrame::Raised</enum>
- </property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="0" column="1" colspan="3" >
- <widget class="QComboBox" name="nameCombo" >
- <property name="toolTip" >
- <string>Specify your name</string>
- </property>
- <property name="editable" >
- <bool>true</bool>
- </property>
- <property name="currentIndex" >
- <number>-1</number>
- </property>
- <item>
- <property name="text" >
- <string>Girish</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Jasmin</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Simon</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Zack</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="1" column="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="1" column="2" >
- <widget class="QRadioButton" name="femaleRadioButton" >
- <property name="styleSheet" >
- <string>Check this if you are female</string>
- </property>
- <property name="text" >
- <string>&amp;Female</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QLabel" name="genderLabel" >
- <property name="text" >
- <string>Gender:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0" >
- <widget class="QLabel" name="ageLabel" >
- <property name="text" >
- <string>&amp;Age:</string>
- </property>
- <property name="buddy" >
- <cstring>ageSpinBox</cstring>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="QRadioButton" name="maleRadioButton" >
- <property name="toolTip" >
- <string>Check this if you are male</string>
- </property>
- <property name="text" >
- <string>&amp;Male</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0" >
- <widget class="QLabel" name="nameLabel" >
- <property name="text" >
- <string>&amp;Name:</string>
- </property>
- <property name="buddy" >
- <cstring>nameCombo</cstring>
- </property>
- </widget>
- </item>
- <item row="3" column="0" >
- <widget class="QLabel" name="passwordLabel" >
- <property name="text" >
- <string>&amp;Password:</string>
- </property>
- <property name="buddy" >
- <cstring>passwordEdit</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="1" colspan="3" >
- <widget class="QSpinBox" name="ageSpinBox" >
- <property name="toolTip" >
- <string>Specify your age</string>
- </property>
- <property name="statusTip" >
- <string>Specify your age</string>
- </property>
- <property name="minimum" >
- <number>12</number>
- </property>
- <property name="value" >
- <number>22</number>
- </property>
- </widget>
- </item>
- <item row="7" column="2" colspan="2" >
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- <item row="6" column="0" colspan="4" >
- <widget class="QCheckBox" name="agreeCheckBox" >
- <property name="toolTip" >
- <string>Please read the LICENSE file before checking</string>
- </property>
- <property name="text" >
- <string>I &amp;accept the terms and &amp;conditions</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1" colspan="3" >
- <widget class="QLineEdit" name="passwordEdit" >
- <property name="toolTip" >
- <string>Specify your password</string>
- </property>
- <property name="statusTip" >
- <string>Specify your password</string>
- </property>
- <property name="text" >
- <string>Password</string>
- </property>
- <property name="echoMode" >
- <enum>QLineEdit::Password</enum>
- </property>
- </widget>
- </item>
- <item row="5" column="1" colspan="3" >
- <widget class="QListWidget" name="professionList" >
- <property name="toolTip" >
- <string>Select your profession</string>
- </property>
- <property name="statusTip" >
- <string>Specify your name here</string>
- </property>
- <property name="whatsThis" >
- <string>Specify your name here</string>
- </property>
- <property name="currentRow" >
- <number>0</number>
- </property>
- <item>
- <property name="text" >
- <string>Developer</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Student</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Fisherman</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="5" column="0" >
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>Profession:</string>
- </property>
- <property name="buddy" >
- <cstring>professionList</cstring>
- </property>
- </widget>
- </item>
- <item row="4" column="1" colspan="3" >
- <widget class="QComboBox" name="countryCombo" >
- <property name="toolTip" >
- <string>Specify country of origin</string>
- </property>
- <property name="statusTip" >
- <string>Specify country of origin</string>
- </property>
- <property name="currentIndex" >
- <number>6</number>
- </property>
- <item>
- <property name="text" >
- <string>Egypt</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>France</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Germany</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>India</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Italy</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Korea</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Norway</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="4" column="0" >
- <widget class="QLabel" name="countryLabel" >
- <property name="text" >
- <string>Pro&amp;fession</string>
- </property>
- <property name="buddy" >
- <cstring>professionList</cstring>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menubar" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>392</width>
- <height>25</height>
- </rect>
- </property>
- <widget class="QMenu" name="menu_File" >
- <property name="title" >
- <string>&amp;File</string>
- </property>
- <addaction name="editStyleAction" />
- <addaction name="separator" />
- <addaction name="exitAction" />
- </widget>
- <widget class="QMenu" name="menu_Help" >
- <property name="title" >
- <string>&amp;Help</string>
- </property>
- <addaction name="aboutAction" />
- <addaction name="separator" />
- <addaction name="aboutQtAction" />
- </widget>
- <addaction name="menu_File" />
- <addaction name="menu_Help" />
- </widget>
- <widget class="QStatusBar" name="statusbar" />
- <action name="exitAction" >
- <property name="text" >
- <string>&amp;Exit</string>
- </property>
- </action>
- <action name="aboutQtAction" >
- <property name="text" >
- <string>About Qt</string>
- </property>
- </action>
- <action name="editStyleAction" >
- <property name="text" >
- <string>Edit &amp;Style</string>
- </property>
- </action>
- <action name="aboutAction" >
- <property name="text" >
- <string>About</string>
- </property>
- </action>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/widgets/widgets/stylesheet/main.cpp b/examples/widgets/widgets/stylesheet/main.cpp
deleted file mode 100644
index 9afdefc939..0000000000
--- a/examples/widgets/widgets/stylesheet/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(stylesheet);
-
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.cpp b/examples/widgets/widgets/stylesheet/mainwindow.cpp
deleted file mode 100644
index a43613c757..0000000000
--- a/examples/widgets/widgets/stylesheet/mainwindow.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "mainwindow.h"
-#include "stylesheeteditor.h"
-
-#include <QMessageBox>
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
-{
- ui.setupUi(this);
-
- ui.nameLabel->setProperty("class", "mandatory QLabel");
- ui.nameCombo->lineEdit()->setPlaceholderText(tr("Last, First"));
-
- styleSheetEditor = new StyleSheetEditor(this);
-
- statusBar()->addWidget(new QLabel(tr("Ready")));
-
- connect(ui.exitAction, &QAction::triggered, qApp, &QApplication::quit);
- connect(ui.aboutQtAction, &QAction::triggered, qApp, &QApplication::aboutQt);
-}
-
-void MainWindow::on_editStyleAction_triggered()
-{
- styleSheetEditor->show();
- styleSheetEditor->activateWindow();
-}
-
-void MainWindow::on_aboutAction_triggered()
-{
- const QString url = QStringLiteral("http://doc.qt.io/qt-%1/stylesheet.html")
- .arg(QT_VERSION_MAJOR);
- QMessageBox::about(this, tr("About Style sheet"),
- tr("The <b>Style Sheet</b> example shows how widgets can be styled "
- "using <a href=\"%1\">Qt "
- "Style Sheets</a>. Click <b>File|Edit Style Sheet</b> to pop up the "
- "style editor, and either choose an existing style sheet or design "
- "your own.").arg(url));
-}
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.h b/examples/widgets/widgets/stylesheet/mainwindow.h
deleted file mode 100644
index 877636bddf..0000000000
--- a/examples/widgets/widgets/stylesheet/mainwindow.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-#include "ui_mainwindow.h"
-
-class StyleSheetEditor;
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow(QWidget *parent = nullptr);
-
-private slots:
- void on_editStyleAction_triggered();
- void on_aboutAction_triggered();
-
-private:
- StyleSheetEditor *styleSheetEditor;
- Ui::MainWindow ui;
-};
-
-#endif
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.ui b/examples/widgets/widgets/stylesheet/mainwindow.ui
deleted file mode 100644
index cc29257afb..0000000000
--- a/examples/widgets/widgets/stylesheet/mainwindow.ui
+++ /dev/null
@@ -1,356 +0,0 @@
-<ui version="4.0" >
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>413</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>Style Sheet</string>
- </property>
- <widget class="QWidget" name="centralwidget" >
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QFrame" name="mainFrame" >
- <property name="frameShape" >
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow" >
- <enum>QFrame::Raised</enum>
- </property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="6" column="0" colspan="5" >
- <widget class="QCheckBox" name="agreeCheckBox" >
- <property name="toolTip" >
- <string>Please read the LICENSE file before checking</string>
- </property>
- <property name="text" >
- <string>I accept the terms and &amp;conditions</string>
- </property>
- </widget>
- </item>
- <item row="5" column="0" >
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>Profession:</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
- </property>
- <property name="buddy" >
- <cstring>professionList</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="0" >
- <widget class="QLabel" name="nameLabel" >
- <property name="text" >
- <string>&amp;Name:</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- <property name="buddy" >
- <cstring>nameCombo</cstring>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="QRadioButton" name="maleRadioButton" >
- <property name="toolTip" >
- <string>Check this if you are male</string>
- </property>
- <property name="text" >
- <string>&amp;Male</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0" >
- <widget class="QLabel" name="passwordLabel" >
- <property name="text" >
- <string>&amp;Password:</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- <property name="buddy" >
- <cstring>passwordEdit</cstring>
- </property>
- </widget>
- </item>
- <item row="4" column="1" colspan="4" >
- <widget class="QComboBox" name="countryCombo" >
- <property name="toolTip" >
- <string>Specify country of origin</string>
- </property>
- <property name="statusTip" >
- <string>Specify country of origin</string>
- </property>
- <property name="currentIndex" >
- <number>6</number>
- </property>
- <item>
- <property name="text" >
- <string>Egypt</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>France</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Germany</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>India</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Italy</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Norway</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Pakistan</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="2" column="0" >
- <widget class="QLabel" name="ageLabel" >
- <property name="text" >
- <string>&amp;Age:</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- <property name="buddy" >
- <cstring>ageSpinBox</cstring>
- </property>
- </widget>
- </item>
- <item row="4" column="0" >
- <widget class="QLabel" name="countryLabel" >
- <property name="text" >
- <string>Country:</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- <property name="buddy" >
- <cstring>countryCombo</cstring>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QLabel" name="genderLabel" >
- <property name="text" >
- <string>Gender:</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="3" column="1" colspan="4" >
- <widget class="QLineEdit" name="passwordEdit" >
- <property name="toolTip" >
- <string>Specify your password</string>
- </property>
- <property name="statusTip" >
- <string>Specify your password</string>
- </property>
- <property name="text" >
- <string>Password</string>
- </property>
- <property name="echoMode" >
- <enum>QLineEdit::Password</enum>
- </property>
- </widget>
- </item>
- <item row="1" column="2" colspan="2" >
- <widget class="QRadioButton" name="femaleRadioButton" >
- <property name="toolTip">
- <string>Check this if you are female</string>
- </property>
- <property name="text" >
- <string>&amp;Female</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1" colspan="2" >
- <widget class="QSpinBox" name="ageSpinBox" >
- <property name="toolTip" >
- <string>Specify your age</string>
- </property>
- <property name="statusTip" >
- <string>Specify your age</string>
- </property>
- <property name="minimum" >
- <number>12</number>
- </property>
- <property name="value" >
- <number>22</number>
- </property>
- </widget>
- </item>
- <item row="0" column="1" colspan="4" >
- <widget class="QComboBox" name="nameCombo" >
- <property name="toolTip" >
- <string>Specify your name</string>
- </property>
- <property name="editable" >
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="4" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="2" column="3" colspan="2" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>61</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="7" column="3" colspan="2" >
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- <item row="5" column="1" colspan="4" >
- <widget class="QListWidget" name="professionList" >
- <property name="toolTip" >
- <string>Select your profession</string>
- </property>
- <property name="statusTip" >
- <string>Specify your name here</string>
- </property>
- <property name="whatsThis" >
- <string>Specify your name here</string>
- </property>
- <property name="currentRow" >
- <number>0</number>
- </property>
- <item>
- <property name="text" >
- <string>Developer</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Student</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Fisherman</string>
- </property>
- </item>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menubar" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>29</height>
- </rect>
- </property>
- <widget class="QMenu" name="menu_File" >
- <property name="title" >
- <string>&amp;File</string>
- </property>
- <addaction name="editStyleAction" />
- <addaction name="separator" />
- <addaction name="exitAction" />
- </widget>
- <widget class="QMenu" name="menu_Help" >
- <property name="title" >
- <string>&amp;Help</string>
- </property>
- <addaction name="aboutAction" />
- <addaction name="aboutQtAction" />
- </widget>
- <addaction name="menu_File" />
- <addaction name="menu_Help" />
- </widget>
- <widget class="QStatusBar" name="statusbar" />
- <action name="exitAction" >
- <property name="text" >
- <string>&amp;Exit</string>
- </property>
- </action>
- <action name="aboutQtAction" >
- <property name="text" >
- <string>About Qt</string>
- </property>
- </action>
- <action name="editStyleAction" >
- <property name="text" >
- <string>Edit &amp;Style...</string>
- </property>
- </action>
- <action name="aboutAction" >
- <property name="text" >
- <string>About</string>
- </property>
- </action>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/widgets/widgets/stylesheet/qss/coffee.qss b/examples/widgets/widgets/stylesheet/qss/coffee.qss
deleted file mode 100644
index 8f72a15ee5..0000000000
--- a/examples/widgets/widgets/stylesheet/qss/coffee.qss
+++ /dev/null
@@ -1,117 +0,0 @@
-.QWidget {
- background-color: beige;
-}
-
-/* Nice Windows-XP-style password character. */
-QLineEdit[echoMode="2"] {
- lineedit-password-character: 9679;
-}
-
-/* We provide a min-width and min-height for push buttons
- so that they look elegant regardless of the width of the text. */
-QPushButton {
- background-color: palegoldenrod;
- border-width: 2px;
- border-color: darkkhaki;
- border-style: solid;
- border-radius: 5;
- padding: 3px;
- min-width: 9ex;
- min-height: 2.5ex;
-}
-
-QPushButton:hover {
- background-color: khaki;
-}
-
-/* Increase the padding, so the text is shifted when the button is
- pressed. */
-QPushButton:pressed {
- padding-left: 5px;
- padding-top: 5px;
- background-color: #d0d67c;
-}
-
-QLabel, QAbstractButton {
- font: bold;
-}
-
-/* Mark mandatory fields with a brownish color. */
-.mandatory {
- color: brown;
-}
-
-/* Bold text on status bar looks awful. */
-QStatusBar QLabel {
- font: normal;
-}
-
-QStatusBar::item {
- border-width: 1;
- border-color: darkkhaki;
- border-style: solid;
- border-radius: 2;
-}
-
-QComboBox, QLineEdit, QSpinBox, QTextEdit, QListView {
- background-color: cornsilk;
- selection-color: #0a214c;
- selection-background-color: #C19A6B;
-}
-
-/* Make placeholder text a matching semi-transparent color */
-QComboBox, QLineEdit {
- placeholder-text-color: #80C19A6B;
-}
-
-QListView {
- show-decoration-selected: 1;
-}
-
-QListView::item:hover {
- background-color: wheat;
-}
-
-/* We reserve 1 pixel space in padding. When we get the focus,
- we kill the padding and enlarge the border. This makes the items
- glow. */
-QLineEdit, QFrame {
- border-width: 2px;
- padding: 1px;
- border-style: solid;
- border-color: darkkhaki;
- border-radius: 5px;
-}
-
-/* As mentioned above, eliminate the padding and increase the border. */
-QLineEdit:focus, QFrame:focus {
- border-width: 3px;
- padding: 0px;
-}
-
-/* A QLabel is a QFrame ... */
-QLabel {
- border: none;
- padding: 0;
- background: none;
-}
-
-/* A QToolTip is a QLabel ... */
-QToolTip {
- border: 2px solid darkkhaki;
- padding: 5px;
- border-radius: 3px;
- opacity: 200;
-}
-
-/* Nice to have the background color change when hovered. */
-QRadioButton:hover, QCheckBox:hover {
- background-color: wheat;
-}
-
-/* Force the dialog's buttons to follow the Windows guidelines. */
-QDialogButtonBox {
- button-layout: 0;
-}
-
-
diff --git a/examples/widgets/widgets/stylesheet/qss/default.qss b/examples/widgets/widgets/stylesheet/qss/default.qss
deleted file mode 100644
index 84eb5e0bc2..0000000000
--- a/examples/widgets/widgets/stylesheet/qss/default.qss
+++ /dev/null
@@ -1 +0,0 @@
-/* empty stylesheet */
diff --git a/examples/widgets/widgets/stylesheet/qss/pagefold.qss b/examples/widgets/widgets/stylesheet/qss/pagefold.qss
deleted file mode 100644
index 3701fc713c..0000000000
--- a/examples/widgets/widgets/stylesheet/qss/pagefold.qss
+++ /dev/null
@@ -1,299 +0,0 @@
-/* Customize any plain widget that is a child of a QMainWindow. */
-QMainWindow > .QWidget {
- background-color: gainsboro;
- background-image: url(:/images/pagefold.png);
- background-position: top right;
- background-repeat: no-repeat
-}
-
-/* Provide a padding for the layout inside the frame. The frame
- exists only to provide a padding for the top-right image, so we
- explicitly disable the border. */
-#mainFrame {
- padding-right: 30px;
- border-style: none;
- border-image: none; /* since we set a border-image below */
-}
-
-/* mainFrame won't have this border-image since we have
- explicitly set it to 'none' using a more specific selector. */
-QFrame, QLineEdit, QComboBox[editable="true"], QSpinBox {
- border-image: url(:/images/frame.png) 4;
- border-width: 3;
-}
-
-QLabel {
- border: none;
- border-image: none;
- padding: 0;
- background: none;
-}
-
-/* Make text in message boxes selectable. */
-QMessageBox {
- /* LinksAccessibleByMouse | TextSelectableByMouse */
- messagebox-text-interaction-flags: 5;
-}
-
-/* Set the selection colors for all widgets. */
-QWidget {
- selection-color: black;
- selection-background-color: Silver;
- color: black;
-}
-
-/* Make the entire row selected in item views. */
-QAbstractItemView {
- show-decoration-selected: 1;
-}
-
-/* Nice WindowsXP-style password character for password line edits. */
-QLineEdit[echoMode="2"] {
- lineedit-password-character: 9679;
-}
-
-/* Customize tooltips. */
-QToolTip {
- background-color: rgb(200,200,255);
- border-color: darkslategray;
- border-width: 1px;
- border-style: solid;
- padding: 3px;
- font: bold;
- border-radius: 3px;
- opacity: 200;
-}
-
-/* Customize radio buttons. */
-
-QRadioButton {
- spacing: 5px;
-}
-
-QRadioButton::indicator {
- width: 13px;
- height: 13px;
-}
-
-QRadioButton::indicator::unchecked {
- image: url(:/images/radiobutton_unchecked.png);
-}
-
-QRadioButton::indicator:unchecked:hover {
- image: url(:/images/radiobutton_unchecked_hover.png);
-}
-
-QRadioButton::indicator:unchecked:pressed {
- image: url(:/images/radiobutton_unchecked_pressed.png);
-}
-
-QRadioButton::indicator::checked {
- image: url(:/images/radiobutton_checked.png);
-}
-
-QRadioButton::indicator:checked:hover {
- image: url(:/images/radiobutton_checked_hover.png);
-}
-
-QRadioButton::indicator:checked:pressed {
- image: url(:/images/radiobutton_checked_pressed.png);
-}
-
-/* Customize arrows. */
-
-*::down-arrow, *::menu-indicator {
- image: url(:/images/down_arrow.png);
- width: 7px;
- height: 7px;
-}
-
-*::down-arrow:disabled, *::down-arrow:off {
- image: url(:/images/down_arrow_disabled.png);
-}
-
-*::up-arrow {
- image: url(:/images/up_arrow.png);
- width: 7px;
- height: 7px;
-}
-
-*::up-arrow:disabled, *::up-arrow:off {
- image: url(:/images/up_arrow_disabled.png);
-}
-
-/* Customize push buttons and comboboxes. Our read-only combobox
- is very similar to a push button, so they share the same border image. */
-
-QPushButton {
- min-width: 4em;
-}
-
-QPushButton, QComboBox[editable="false"],
-QComboBox[editable="true"]::drop-down {
- border-image: url(:/images/pushbutton.png) 5;
- border-width: 5;
-}
-
-QPushButton:hover, QComboBox[editable="false"]:hover,
-QComboBox[editable="true"]::drop-down:hover, QMenuBar::item:hover {
- border-image: url(:/images/pushbutton_hover.png) 5;
- border-width: 5;
-}
-
-QPushButton:pressed, QComboBox[editable="false"]:on,
-QComboBox[editable="true"]::drop-down:on, QMenuBar::item:on {
- border-image: url(:/images/pushbutton_pressed.png) 5;
- border-width: 5;
-}
-
-/* Customize read-only comboboxes. */
-
-QComboBox[editable="false"] {
- padding-left: 3px;
- padding-right: 20px; /* space for the arrow */
-}
-
-QComboBox[editable="false"]::drop-down {
- subcontrol-origin: padding;
- subcontrol-position: top right;
- width: 15px;
- border-left-style: solid;
- border-left-color: darkgray;
- border-left-width: 1px;
-}
-
-QComboBox[editable="false"]::down-arrow {
- subcontrol-origin: content;
- subcontrol-position: center;
- position: relative;
- left: 1px; /* 1 pixel dropdown border */
-}
-
-/* The combobox arrow is on when the popup is open. */
-QComboBox[editable="false"]::down-arrow:on {
- position: relative;
- top: 1px;
- left: 2px;
-}
-
-/* Customize editable comboboxes. */
-
-QComboBox[editable="true"] {
- padding-right: 16px;
-}
-
-QComboBox[editable="true"]::drop-down {
- subcontrol-origin: border;
- subcontrol-position: top right;
- width: 13px;
- position: absolute;
- top: 2px;
- bottom: 2px;
- right: 2px;
-}
-
-QComboBox[editable="true"]::drop-down,
-QComboBox[editable="true"]::drop-down:hover,
-QComboBox[editable="true"]::drop-down:on {
- border-width: 0px;
- border-left-width: 3px; /* we need only left and center part */
-}
-
-/* Shift the arrow when it's open. */
-QComboBox[editable="true"]::down-arrow:on {
- position: relative;
- top: 1px;
- left: 1px;
-}
-
-/* Customize check boxes. */
-QCheckBox {
- spacing: 5px;
-}
-
-QCheckBox::indicator {
- width: 13px;
- height: 13px;
-}
-
-QCheckBox::indicator:unchecked {
- image: url(:/images/checkbox_unchecked.png);
-}
-
-QCheckBox::indicator:unchecked:hover {
- image: url(:/images/checkbox_unchecked_hover.png);
-}
-
-QCheckBox::indicator:unchecked:pressed {
- image: url(:/images/checkbox_unchecked_pressed.png);
-}
-
-QCheckBox::indicator:checked {
- image: url(:/images/checkbox_checked.png);
-}
-
-QCheckBox::indicator:checked:hover {
- image: url(:/images/checkbox_checked_hover.png);
-}
-
-QCheckBox::indicator:checked:pressed {
- image: url(:/images/checkbox_checked_pressed.png);
-}
-
-/* Customize the size grip. */
-QSizeGrip {
- image: url(:/images/sizegrip.png);
- width: 16px;
- height: 16px;
-}
-
-/* Customize the menu bar. */
-QMenuBar {
- border-image: none;
- border-style: none;
- border-width: 1px;
- border-bottom-style: solid;
- border-bottom-color: darkslategray;
- padding: 2px;
-}
-
-/* Customize spin boxes. */
-
-QSpinBox {
- padding-right: 15px;
-}
-
-QSpinBox::up-button {
- subcontrol-origin: border;
- subcontrol-position: top right;
-
- width: 16px; /* 16 + 2*1px border-width = 15px padding + 3px parent border */
- border-image: url(:/images/spinup.png) 1;
- border-width: 1px;
-}
-
-QSpinBox::up-button:hover {
- border-image: url(:/images/spinup_hover.png) 1;
-}
-
-QSpinBox::up-button:pressed {
- border-image: url(:/images/spinup_pressed.png) 1;
-}
-
-QSpinBox::down-button {
- subcontrol-origin: border;
- subcontrol-position: bottom right;
-
- width: 16px;
- border-image: url(:/images/spindown.png) 1;
- border-width: 1px;
- border-top-width: 0;
-}
-
-QSpinBox::down-button:hover {
- border-image: url(:/images/spindown_hover.png) 1;
-}
-
-QSpinBox::down-button:pressed {
- border-image: url(:/images/spindown_pressed.png) 1;
-}
diff --git a/examples/widgets/widgets/stylesheet/stylesheet.pro b/examples/widgets/widgets/stylesheet/stylesheet.pro
deleted file mode 100644
index 0fe3187f63..0000000000
--- a/examples/widgets/widgets/stylesheet/stylesheet.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-HEADERS = mainwindow.h \
- stylesheeteditor.h
-FORMS = mainwindow.ui \
- stylesheeteditor.ui
-RESOURCES = stylesheet.qrc
-SOURCES = main.cpp \
- mainwindow.cpp \
- stylesheeteditor.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/stylesheet
-INSTALLS += target
diff --git a/examples/widgets/widgets/stylesheet/stylesheet.qrc b/examples/widgets/widgets/stylesheet/stylesheet.qrc
deleted file mode 100644
index e1e61a920a..0000000000
--- a/examples/widgets/widgets/stylesheet/stylesheet.qrc
+++ /dev/null
@@ -1,39 +0,0 @@
-<RCC>
-<qresource prefix="/">
- <file>layouts/default.ui</file>
- <file>layouts/pagefold.ui</file>
- <file>qss/coffee.qss</file>
- <file>qss/default.qss</file>
- <file>qss/pagefold.qss</file>
- <file>images/pagefold.png</file>
- <file>images/frame.png</file>
- <file>images/radiobutton_unchecked.png</file>
- <file>images/radiobutton_unchecked_pressed.png</file>
- <file>images/radiobutton_unchecked_hover.png</file>
- <file>images/radiobutton_checked.png</file>
- <file>images/radiobutton_checked_pressed.png</file>
- <file>images/radiobutton_checked_hover.png</file>
- <file>images/pushbutton.png</file>
- <file>images/pushbutton_hover.png</file>
- <file>images/pushbutton_pressed.png</file>
- <file>images/checkbox_unchecked.png</file>
- <file>images/checkbox_unchecked_pressed.png</file>
- <file>images/checkbox_unchecked_hover.png</file>
- <file>images/checkbox_checked.png</file>
- <file>images/checkbox_checked_pressed.png</file>
- <file>images/checkbox_checked_hover.png</file>
- <file>images/down_arrow.png</file>
- <file>images/down_arrow_disabled.png</file>
- <file>images/up_arrow.png</file>
- <file>images/up_arrow_disabled.png</file>
- <file>images/sizegrip.png</file>
- <file>images/spinup.png</file>
- <file>images/spinup_off.png</file>
- <file>images/spinup_hover.png</file>
- <file>images/spinup_pressed.png</file>
- <file>images/spindown.png</file>
- <file>images/spindown_off.png</file>
- <file>images/spindown_hover.png</file>
- <file>images/spindown_pressed.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp
deleted file mode 100644
index 84fda79a16..0000000000
--- a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "stylesheeteditor.h"
-
-#include <QFile>
-#include <QRegularExpression>
-#include <QStyleFactory>
-
-StyleSheetEditor::StyleSheetEditor(QWidget *parent)
- : QDialog(parent)
-{
- ui.setupUi(this);
-
- connect(ui.styleCombo, &QComboBox::textActivated, this, &StyleSheetEditor::setStyleName);
- connect(ui.styleSheetCombo, &QComboBox::textActivated, this, &StyleSheetEditor::setStyleSheetName);
- connect(ui.styleTextEdit, &QTextEdit::textChanged, this, &StyleSheetEditor::setModified);
- connect(ui.applyButton, &QAbstractButton::clicked, this, &StyleSheetEditor::apply);
-
- QRegularExpression regExp("^.(.*)\\+?Style$");
- QString defaultStyle = QApplication::style()->metaObject()->className();
- QRegularExpressionMatch match = regExp.match(defaultStyle);
-
- if (match.hasMatch())
- defaultStyle = match.captured(1);
-
- ui.styleCombo->addItems(QStyleFactory::keys());
- ui.styleCombo->setCurrentIndex(ui.styleCombo->findText(defaultStyle, Qt::MatchContains));
- ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Coffee"));
- loadStyleSheet("Coffee");
-}
-
-void StyleSheetEditor::setStyleName(const QString &styleName)
-{
- qApp->setStyle(styleName);
- ui.applyButton->setEnabled(false);
-}
-
-void StyleSheetEditor::setStyleSheetName(const QString &sheetName)
-{
- loadStyleSheet(sheetName);
-}
-
-void StyleSheetEditor::setModified()
-{
- ui.applyButton->setEnabled(true);
-}
-
-void StyleSheetEditor::apply()
-{
- qApp->setStyleSheet(ui.styleTextEdit->toPlainText());
- ui.applyButton->setEnabled(false);
-}
-
-void StyleSheetEditor::loadStyleSheet(const QString &sheetName)
-{
- QFile file(":/qss/" + sheetName.toLower() + ".qss");
- file.open(QFile::ReadOnly);
- QString styleSheet = QString::fromLatin1(file.readAll());
-
- ui.styleTextEdit->setPlainText(styleSheet);
- qApp->setStyleSheet(styleSheet);
- ui.applyButton->setEnabled(false);
-}
diff --git a/examples/widgets/widgets/stylesheet/stylesheeteditor.h b/examples/widgets/widgets/stylesheet/stylesheeteditor.h
deleted file mode 100644
index e61534a4f9..0000000000
--- a/examples/widgets/widgets/stylesheet/stylesheeteditor.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef STYLESHEETEDITOR_H
-#define STYLESHEETEDITOR_H
-
-#include <QDialog>
-
-#include "ui_stylesheeteditor.h"
-
-class StyleSheetEditor : public QDialog
-{
- Q_OBJECT
-
-public:
- StyleSheetEditor(QWidget *parent = nullptr);
-
-private slots:
- void setStyleName(const QString &styleName);
- void setStyleSheetName(const QString &styleSheetName);
- void setModified();
- void apply();
-
-private:
- void loadStyleSheet(const QString &sheetName);
-
- Ui::StyleSheetEditor ui;
-};
-
-#endif
diff --git a/examples/widgets/widgets/stylesheet/stylesheeteditor.ui b/examples/widgets/widgets/stylesheet/stylesheeteditor.ui
deleted file mode 100644
index 34cd7f6d04..0000000000
--- a/examples/widgets/widgets/stylesheet/stylesheeteditor.ui
+++ /dev/null
@@ -1,171 +0,0 @@
-<ui version="4.0" >
- <class>StyleSheetEditor</class>
- <widget class="QWidget" name="StyleSheetEditor" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>445</width>
- <height>289</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>Style Editor</string>
- </property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="0" column="6" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::MinimumExpanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>32</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="0" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::MinimumExpanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>32</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="5" >
- <widget class="QComboBox" name="styleSheetCombo" >
- <item>
- <property name="text" >
- <string>Default</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Coffee</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Pagefold</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="0" column="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>10</width>
- <height>16</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="2" >
- <widget class="QComboBox" name="styleCombo" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>5</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- <item row="0" column="1" >
- <widget class="QLabel" name="label_7" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>0</hsizetype>
- <vsizetype>5</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Style:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0" colspan="7" >
- <layout class="QHBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>321</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="applyButton" >
- <property name="enabled" >
- <bool>false</bool>
- </property>
- <property name="text" >
- <string>&amp;Apply</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="1" column="0" colspan="7" >
- <widget class="QTextEdit" name="styleTextEdit" />
- </item>
- <item row="0" column="4" >
- <widget class="QLabel" name="label_8" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>0</hsizetype>
- <vsizetype>5</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Style Sheet:</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/examples/widgets/widgets/tablet/CMakeLists.txt b/examples/widgets/widgets/tablet/CMakeLists.txt
index 1f58252dfe..caf9922741 100644
--- a/examples/widgets/widgets/tablet/CMakeLists.txt
+++ b/examples/widgets/widgets/tablet/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(qttablet LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/tablet")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -48,7 +42,14 @@ qt_add_resources(qttablet "images"
)
install(TARGETS qttablet
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET qttablet
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/tetrix/CMakeLists.txt b/examples/widgets/widgets/tetrix/CMakeLists.txt
deleted file mode 100644
index 4b649e1d8e..0000000000
--- a/examples/widgets/widgets/tetrix/CMakeLists.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(tetrix LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/tetrix")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(tetrix
- main.cpp
- tetrixboard.cpp tetrixboard.h
- tetrixpiece.cpp tetrixpiece.h
- tetrixwindow.cpp tetrixwindow.h
-)
-
-set_target_properties(tetrix PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(tetrix PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS tetrix
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/tetrix/main.cpp b/examples/widgets/widgets/tetrix/main.cpp
deleted file mode 100644
index 24791bde26..0000000000
--- a/examples/widgets/widgets/tetrix/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "tetrixwindow.h"
-
-#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- TetrixWindow window;
- window.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/tetrix/tetrix.pro b/examples/widgets/widgets/tetrix/tetrix.pro
deleted file mode 100644
index bb9f855fb0..0000000000
--- a/examples/widgets/widgets/tetrix/tetrix.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-QT += widgets
-
-HEADERS = tetrixboard.h \
- tetrixpiece.h \
- tetrixwindow.h
-SOURCES = main.cpp \
- tetrixboard.cpp \
- tetrixpiece.cpp \
- tetrixwindow.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/tetrix
-INSTALLS += target
diff --git a/examples/widgets/widgets/tetrix/tetrixboard.cpp b/examples/widgets/widgets/tetrix/tetrixboard.cpp
deleted file mode 100644
index 0c5771ad89..0000000000
--- a/examples/widgets/widgets/tetrix/tetrixboard.cpp
+++ /dev/null
@@ -1,371 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "tetrixboard.h"
-
-#include <QKeyEvent>
-#include <QLabel>
-#include <QPainter>
-
-//! [0]
-TetrixBoard::TetrixBoard(QWidget *parent)
- : QFrame(parent), isStarted(false), isPaused(false)
-{
- setFrameStyle(QFrame::Panel | QFrame::Sunken);
- setFocusPolicy(Qt::StrongFocus);
- clearBoard();
-
- nextPiece.setRandomShape();
-}
-//! [0]
-
-//! [1]
-void TetrixBoard::setNextPieceLabel(QLabel *label)
-{
- nextPieceLabel = label;
-}
-//! [1]
-
-//! [2]
-QSize TetrixBoard::sizeHint() const
-{
- return QSize(BoardWidth * 15 + frameWidth() * 2,
- BoardHeight * 15 + frameWidth() * 2);
-}
-
-QSize TetrixBoard::minimumSizeHint() const
-//! [2] //! [3]
-{
- return QSize(BoardWidth * 5 + frameWidth() * 2,
- BoardHeight * 5 + frameWidth() * 2);
-}
-//! [3]
-
-//! [4]
-void TetrixBoard::start()
-{
- if (isPaused)
- return;
-
- isStarted = true;
- isWaitingAfterLine = false;
- numLinesRemoved = 0;
- numPiecesDropped = 0;
- score = 0;
- level = 1;
- clearBoard();
-
- emit linesRemovedChanged(numLinesRemoved);
- emit scoreChanged(score);
- emit levelChanged(level);
-
- newPiece();
- timer.start(timeoutTime(), this);
-}
-//! [4]
-
-//! [5]
-void TetrixBoard::pause()
-{
- if (!isStarted)
- return;
-
- isPaused = !isPaused;
- if (isPaused) {
- timer.stop();
- } else {
- timer.start(timeoutTime(), this);
- }
- update();
-//! [5] //! [6]
-}
-//! [6]
-
-//! [7]
-void TetrixBoard::paintEvent(QPaintEvent *event)
-{
- QFrame::paintEvent(event);
-
- QPainter painter(this);
- QRect rect = contentsRect();
-//! [7]
-
- if (isPaused) {
- painter.drawText(rect, Qt::AlignCenter, tr("Pause"));
- return;
- }
-
-//! [8]
- int boardTop = rect.bottom() - BoardHeight*squareHeight();
-
- for (int i = 0; i < BoardHeight; ++i) {
- for (int j = 0; j < BoardWidth; ++j) {
- TetrixShape shape = shapeAt(j, BoardHeight - i - 1);
- if (shape != NoShape)
- drawSquare(painter, rect.left() + j * squareWidth(),
- boardTop + i * squareHeight(), shape);
- }
-//! [8] //! [9]
- }
-//! [9]
-
-//! [10]
- if (curPiece.shape() != NoShape) {
- for (int i = 0; i < 4; ++i) {
- int x = curX + curPiece.x(i);
- int y = curY - curPiece.y(i);
- drawSquare(painter, rect.left() + x * squareWidth(),
- boardTop + (BoardHeight - y - 1) * squareHeight(),
- curPiece.shape());
- }
-//! [10] //! [11]
- }
-//! [11] //! [12]
-}
-//! [12]
-
-//! [13]
-void TetrixBoard::keyPressEvent(QKeyEvent *event)
-{
- if (!isStarted || isPaused || curPiece.shape() == NoShape) {
- QFrame::keyPressEvent(event);
- return;
- }
-//! [13]
-
-//! [14]
- switch (event->key()) {
- case Qt::Key_Left:
- tryMove(curPiece, curX - 1, curY);
- break;
- case Qt::Key_Right:
- tryMove(curPiece, curX + 1, curY);
- break;
- case Qt::Key_Down:
- tryMove(curPiece.rotatedRight(), curX, curY);
- break;
- case Qt::Key_Up:
- tryMove(curPiece.rotatedLeft(), curX, curY);
- break;
- case Qt::Key_Space:
- dropDown();
- break;
- case Qt::Key_D:
- oneLineDown();
- break;
- default:
- QFrame::keyPressEvent(event);
- }
-//! [14]
-}
-
-//! [15]
-void TetrixBoard::timerEvent(QTimerEvent *event)
-{
- if (event->timerId() == timer.timerId()) {
- if (isWaitingAfterLine) {
- isWaitingAfterLine = false;
- newPiece();
- timer.start(timeoutTime(), this);
- } else {
- oneLineDown();
- }
- } else {
- QFrame::timerEvent(event);
-//! [15] //! [16]
- }
-//! [16] //! [17]
-}
-//! [17]
-
-//! [18]
-void TetrixBoard::clearBoard()
-{
- for (int i = 0; i < BoardHeight * BoardWidth; ++i)
- board[i] = NoShape;
-}
-//! [18]
-
-//! [19]
-void TetrixBoard::dropDown()
-{
- int dropHeight = 0;
- int newY = curY;
- while (newY > 0) {
- if (!tryMove(curPiece, curX, newY - 1))
- break;
- --newY;
- ++dropHeight;
- }
- pieceDropped(dropHeight);
-//! [19] //! [20]
-}
-//! [20]
-
-//! [21]
-void TetrixBoard::oneLineDown()
-{
- if (!tryMove(curPiece, curX, curY - 1))
- pieceDropped(0);
-}
-//! [21]
-
-//! [22]
-void TetrixBoard::pieceDropped(int dropHeight)
-{
- for (int i = 0; i < 4; ++i) {
- int x = curX + curPiece.x(i);
- int y = curY - curPiece.y(i);
- shapeAt(x, y) = curPiece.shape();
- }
-
- ++numPiecesDropped;
- if (numPiecesDropped % 25 == 0) {
- ++level;
- timer.start(timeoutTime(), this);
- emit levelChanged(level);
- }
-
- score += dropHeight + 7;
- emit scoreChanged(score);
- removeFullLines();
-
- if (!isWaitingAfterLine)
- newPiece();
-//! [22] //! [23]
-}
-//! [23]
-
-//! [24]
-void TetrixBoard::removeFullLines()
-{
- int numFullLines = 0;
-
- for (int i = BoardHeight - 1; i >= 0; --i) {
- bool lineIsFull = true;
-
- for (int j = 0; j < BoardWidth; ++j) {
- if (shapeAt(j, i) == NoShape) {
- lineIsFull = false;
- break;
- }
- }
-
- if (lineIsFull) {
-//! [24] //! [25]
- ++numFullLines;
- for (int k = i; k < BoardHeight - 1; ++k) {
- for (int j = 0; j < BoardWidth; ++j)
- shapeAt(j, k) = shapeAt(j, k + 1);
- }
-//! [25] //! [26]
- for (int j = 0; j < BoardWidth; ++j)
- shapeAt(j, BoardHeight - 1) = NoShape;
- }
-//! [26] //! [27]
- }
-//! [27]
-
-//! [28]
- if (numFullLines > 0) {
- numLinesRemoved += numFullLines;
- score += 10 * numFullLines;
- emit linesRemovedChanged(numLinesRemoved);
- emit scoreChanged(score);
-
- timer.start(500, this);
- isWaitingAfterLine = true;
- curPiece.setShape(NoShape);
- update();
- }
-//! [28] //! [29]
-}
-//! [29]
-
-//! [30]
-void TetrixBoard::newPiece()
-{
- curPiece = nextPiece;
- nextPiece.setRandomShape();
- showNextPiece();
- curX = BoardWidth / 2 + 1;
- curY = BoardHeight - 1 + curPiece.minY();
-
- if (!tryMove(curPiece, curX, curY)) {
- curPiece.setShape(NoShape);
- timer.stop();
- isStarted = false;
- }
-//! [30] //! [31]
-}
-//! [31]
-
-//! [32]
-void TetrixBoard::showNextPiece()
-{
- if (!nextPieceLabel)
- return;
-
- int dx = nextPiece.maxX() - nextPiece.minX() + 1;
- int dy = nextPiece.maxY() - nextPiece.minY() + 1;
-
- QPixmap pixmap(dx * squareWidth(), dy * squareHeight());
- QPainter painter(&pixmap);
- painter.fillRect(pixmap.rect(), nextPieceLabel->palette().window());
-
- for (int i = 0; i < 4; ++i) {
- int x = nextPiece.x(i) - nextPiece.minX();
- int y = nextPiece.y(i) - nextPiece.minY();
- drawSquare(painter, x * squareWidth(), y * squareHeight(),
- nextPiece.shape());
- }
- nextPieceLabel->setPixmap(pixmap);
-//! [32] //! [33]
-}
-//! [33]
-
-//! [34]
-bool TetrixBoard::tryMove(const TetrixPiece &newPiece, int newX, int newY)
-{
- for (int i = 0; i < 4; ++i) {
- int x = newX + newPiece.x(i);
- int y = newY - newPiece.y(i);
- if (x < 0 || x >= BoardWidth || y < 0 || y >= BoardHeight)
- return false;
- if (shapeAt(x, y) != NoShape)
- return false;
- }
-//! [34]
-
-//! [35]
- curPiece = newPiece;
- curX = newX;
- curY = newY;
- update();
- return true;
-}
-//! [35]
-
-//! [36]
-void TetrixBoard::drawSquare(QPainter &painter, int x, int y, TetrixShape shape)
-{
- static constexpr QRgb colorTable[8] = {
- 0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
- 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00
- };
-
- QColor color = colorTable[int(shape)];
- painter.fillRect(x + 1, y + 1, squareWidth() - 2, squareHeight() - 2,
- color);
-
- painter.setPen(color.lighter());
- painter.drawLine(x, y + squareHeight() - 1, x, y);
- painter.drawLine(x, y, x + squareWidth() - 1, y);
-
- painter.setPen(color.darker());
- painter.drawLine(x + 1, y + squareHeight() - 1,
- x + squareWidth() - 1, y + squareHeight() - 1);
- painter.drawLine(x + squareWidth() - 1, y + squareHeight() - 1,
- x + squareWidth() - 1, y + 1);
-}
-//! [36]
diff --git a/examples/widgets/widgets/tetrix/tetrixboard.h b/examples/widgets/widgets/tetrix/tetrixboard.h
deleted file mode 100644
index c2fe3fd01e..0000000000
--- a/examples/widgets/widgets/tetrix/tetrixboard.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef TETRIXBOARD_H
-#define TETRIXBOARD_H
-
-#include <QBasicTimer>
-#include <QFrame>
-#include <QPointer>
-
-#include "tetrixpiece.h"
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-QT_END_NAMESPACE
-
-//! [0]
-class TetrixBoard : public QFrame
-{
- Q_OBJECT
-
-public:
- TetrixBoard(QWidget *parent = nullptr);
-
- void setNextPieceLabel(QLabel *label);
- QSize sizeHint() const override;
- QSize minimumSizeHint() const override;
-
-public slots:
- void start();
- void pause();
-
-signals:
- void scoreChanged(int score);
- void levelChanged(int level);
- void linesRemovedChanged(int numLines);
-
-protected:
- void paintEvent(QPaintEvent *event) override;
- void keyPressEvent(QKeyEvent *event) override;
- void timerEvent(QTimerEvent *event) override;
-//! [0]
-
-//! [1]
-private:
- enum { BoardWidth = 10, BoardHeight = 22 };
-
- TetrixShape &shapeAt(int x, int y) { return board[(y * BoardWidth) + x]; }
- int timeoutTime() { return 1000 / (1 + level); }
- int squareWidth() { return contentsRect().width() / BoardWidth; }
- int squareHeight() { return contentsRect().height() / BoardHeight; }
- void clearBoard();
- void dropDown();
- void oneLineDown();
- void pieceDropped(int dropHeight);
- void removeFullLines();
- void newPiece();
- void showNextPiece();
- bool tryMove(const TetrixPiece &newPiece, int newX, int newY);
- void drawSquare(QPainter &painter, int x, int y, TetrixShape shape);
-
- QBasicTimer timer;
- QPointer<QLabel> nextPieceLabel;
- bool isStarted;
- bool isPaused;
- bool isWaitingAfterLine;
- TetrixPiece curPiece;
- TetrixPiece nextPiece;
- int curX;
- int curY;
- int numLinesRemoved;
- int numPiecesDropped;
- int score;
- int level;
- TetrixShape board[BoardWidth * BoardHeight];
-};
-//! [1]
-
-#endif
diff --git a/examples/widgets/widgets/tetrix/tetrixpiece.cpp b/examples/widgets/widgets/tetrix/tetrixpiece.cpp
deleted file mode 100644
index 5dc9e11c49..0000000000
--- a/examples/widgets/widgets/tetrix/tetrixpiece.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "tetrixpiece.h"
-
-#include <QtCore>
-
-//! [0]
-void TetrixPiece::setRandomShape()
-{
- setShape(TetrixShape(QRandomGenerator::global()->bounded(7) + 1));
-}
-//! [0]
-
-//! [1]
-void TetrixPiece::setShape(TetrixShape shape)
-{
- static constexpr int coordsTable[8][4][2] = {
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
- { { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } },
- { { 0, -1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } },
- { { 0, -1 }, { 0, 0 }, { 0, 1 }, { 0, 2 } },
- { { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 } },
- { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } },
- { { -1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } },
- { { 1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } }
- };
-
- for (int i = 0; i < 4 ; i++) {
- for (int j = 0; j < 2; ++j)
- coords[i][j] = coordsTable[shape][i][j];
- }
- pieceShape = shape;
-//! [1] //! [2]
-}
-//! [2]
-
-//! [3]
-int TetrixPiece::minX() const
-{
- int min = coords[0][0];
- for (int i = 1; i < 4; ++i)
- min = qMin(min, coords[i][0]);
- return min;
-}
-
-int TetrixPiece::maxX() const
-//! [3] //! [4]
-{
- int max = coords[0][0];
- for (int i = 1; i < 4; ++i)
- max = qMax(max, coords[i][0]);
- return max;
-}
-//! [4]
-
-//! [5]
-int TetrixPiece::minY() const
-{
- int min = coords[0][1];
- for (int i = 1; i < 4; ++i)
- min = qMin(min, coords[i][1]);
- return min;
-}
-
-int TetrixPiece::maxY() const
-//! [5] //! [6]
-{
- int max = coords[0][1];
- for (int i = 1; i < 4; ++i)
- max = qMax(max, coords[i][1]);
- return max;
-}
-//! [6]
-
-//! [7]
-TetrixPiece TetrixPiece::rotatedLeft() const
-{
- if (pieceShape == SquareShape)
- return *this;
-
- TetrixPiece result;
- result.pieceShape = pieceShape;
- for (int i = 0; i < 4; ++i) {
- result.setX(i, y(i));
- result.setY(i, -x(i));
- }
-//! [7]
- return result;
-}
-
-//! [9]
-TetrixPiece TetrixPiece::rotatedRight() const
-{
- if (pieceShape == SquareShape)
- return *this;
-
- TetrixPiece result;
- result.pieceShape = pieceShape;
- for (int i = 0; i < 4; ++i) {
- result.setX(i, -y(i));
- result.setY(i, x(i));
- }
-//! [9]
- return result;
-}
diff --git a/examples/widgets/widgets/tetrix/tetrixpiece.h b/examples/widgets/widgets/tetrix/tetrixpiece.h
deleted file mode 100644
index 86a513a76e..0000000000
--- a/examples/widgets/widgets/tetrix/tetrixpiece.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef TETRIXPIECE_H
-#define TETRIXPIECE_H
-
-enum TetrixShape { NoShape, ZShape, SShape, LineShape, TShape, SquareShape,
- LShape, MirroredLShape };
-
-//! [0]
-class TetrixPiece
-{
-public:
- TetrixPiece() { setShape(NoShape); }
-
- void setRandomShape();
- void setShape(TetrixShape shape);
-
- TetrixShape shape() const { return pieceShape; }
- int x(int index) const { return coords[index][0]; }
- int y(int index) const { return coords[index][1]; }
- int minX() const;
- int maxX() const;
- int minY() const;
- int maxY() const;
- TetrixPiece rotatedLeft() const;
- TetrixPiece rotatedRight() const;
-
-private:
- void setX(int index, int x) { coords[index][0] = x; }
- void setY(int index, int y) { coords[index][1] = y; }
-
- TetrixShape pieceShape;
- int coords[4][2];
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/tetrix/tetrixwindow.cpp b/examples/widgets/widgets/tetrix/tetrixwindow.cpp
deleted file mode 100644
index ae10a778e7..0000000000
--- a/examples/widgets/widgets/tetrix/tetrixwindow.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "tetrixboard.h"
-#include "tetrixwindow.h"
-
-#include <QCoreApplication>
-#include <QGridLayout>
-#include <QLabel>
-#include <QLCDNumber>
-#include <QPushButton>
-
-//! [0]
-TetrixWindow::TetrixWindow(QWidget *parent)
- : QWidget(parent), board(new TetrixBoard)
-{
-//! [0]
- nextPieceLabel = new QLabel;
- nextPieceLabel->setFrameStyle(QFrame::Box | QFrame::Raised);
- nextPieceLabel->setAlignment(Qt::AlignCenter);
- board->setNextPieceLabel(nextPieceLabel);
-//! [1]
- scoreLcd = new QLCDNumber(5);
- scoreLcd->setSegmentStyle(QLCDNumber::Filled);
-//! [1]
- levelLcd = new QLCDNumber(2);
- levelLcd->setSegmentStyle(QLCDNumber::Filled);
- linesLcd = new QLCDNumber(5);
- linesLcd->setSegmentStyle(QLCDNumber::Filled);
-
-//! [2]
- startButton = new QPushButton(tr("&Start"));
- startButton->setFocusPolicy(Qt::NoFocus);
- quitButton = new QPushButton(tr("&Quit"));
- quitButton->setFocusPolicy(Qt::NoFocus);
- pauseButton = new QPushButton(tr("&Pause"));
-//! [2] //! [3]
- pauseButton->setFocusPolicy(Qt::NoFocus);
-//! [3] //! [4]
-
- connect(startButton, &QPushButton::clicked, board, &TetrixBoard::start);
-//! [4] //! [5]
- connect(quitButton , &QPushButton::clicked, qApp, &QCoreApplication::quit);
- connect(pauseButton, &QPushButton::clicked, board, &TetrixBoard::pause);
- connect(board, &TetrixBoard::scoreChanged,
- scoreLcd, qOverload<int>(&QLCDNumber::display));
- connect(board, &TetrixBoard::levelChanged,
- levelLcd, qOverload<int>(&QLCDNumber::display));
- connect(board, &TetrixBoard::linesRemovedChanged,
- linesLcd, qOverload<int>(&QLCDNumber::display));
-//! [5]
-
-//! [6]
- QGridLayout *layout = new QGridLayout;
- layout->addWidget(createLabel(tr("NEXT")), 0, 0);
- layout->addWidget(nextPieceLabel, 1, 0);
- layout->addWidget(createLabel(tr("LEVEL")), 2, 0);
- layout->addWidget(levelLcd, 3, 0);
- layout->addWidget(startButton, 4, 0);
- layout->addWidget(board, 0, 1, 6, 1);
- layout->addWidget(createLabel(tr("SCORE")), 0, 2);
- layout->addWidget(scoreLcd, 1, 2);
- layout->addWidget(createLabel(tr("LINES REMOVED")), 2, 2);
- layout->addWidget(linesLcd, 3, 2);
- layout->addWidget(quitButton, 4, 2);
- layout->addWidget(pauseButton, 5, 2);
- setLayout(layout);
-
- setWindowTitle(tr("Tetrix"));
- resize(550, 370);
-}
-//! [6]
-
-//! [7]
-QLabel *TetrixWindow::createLabel(const QString &text)
-{
- QLabel *label = new QLabel(text);
- label->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
- return label;
-}
-//! [7]
-
diff --git a/examples/widgets/widgets/tetrix/tetrixwindow.h b/examples/widgets/widgets/tetrix/tetrixwindow.h
deleted file mode 100644
index 2ed468717d..0000000000
--- a/examples/widgets/widgets/tetrix/tetrixwindow.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef TETRIXWINDOW_H
-#define TETRIXWINDOW_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QLCDNumber;
-class QLabel;
-class QPushButton;
-QT_END_NAMESPACE
-class TetrixBoard;
-
-//! [0]
-class TetrixWindow : public QWidget
-{
- Q_OBJECT
-
-public:
- TetrixWindow(QWidget *parent = nullptr);
-
-private:
- QLabel *createLabel(const QString &text);
-
- TetrixBoard *board;
- QLabel *nextPieceLabel;
- QLCDNumber *scoreLcd;
- QLCDNumber *levelLcd;
- QLCDNumber *linesLcd;
- QPushButton *startButton;
- QPushButton *quitButton;
- QPushButton *pauseButton;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/tooltips/CMakeLists.txt b/examples/widgets/widgets/tooltips/CMakeLists.txt
deleted file mode 100644
index f3d00a7056..0000000000
--- a/examples/widgets/widgets/tooltips/CMakeLists.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(tooltips LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/tooltips")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(tooltips
- main.cpp
- shapeitem.cpp shapeitem.h
- sortingbox.cpp sortingbox.h
-)
-
-set_target_properties(tooltips PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(tooltips PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(tooltips_resource_files
- "images/circle.png"
- "images/square.png"
- "images/triangle.png"
-)
-
-qt_add_resources(tooltips "tooltips"
- PREFIX
- "/"
- FILES
- ${tooltips_resource_files}
-)
-
-install(TARGETS tooltips
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/tooltips/images/circle.png b/examples/widgets/widgets/tooltips/images/circle.png
deleted file mode 100644
index dc392cb3f7..0000000000
--- a/examples/widgets/widgets/tooltips/images/circle.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/tooltips/images/square.png b/examples/widgets/widgets/tooltips/images/square.png
deleted file mode 100644
index c0fd2d540a..0000000000
--- a/examples/widgets/widgets/tooltips/images/square.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/tooltips/images/triangle.png b/examples/widgets/widgets/tooltips/images/triangle.png
deleted file mode 100644
index 2ee15f8f1f..0000000000
--- a/examples/widgets/widgets/tooltips/images/triangle.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/tooltips/main.cpp b/examples/widgets/widgets/tooltips/main.cpp
deleted file mode 100644
index 677d9ecd15..0000000000
--- a/examples/widgets/widgets/tooltips/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QApplication>
-
-#include "sortingbox.h"
-
-int main(int argc, char *argv[])
-{
- Q_INIT_RESOURCE(tooltips);
-
- QApplication app(argc, argv);
- SortingBox sortingBox;
- sortingBox.show();
- return app.exec();
-}
diff --git a/examples/widgets/widgets/tooltips/shapeitem.cpp b/examples/widgets/widgets/tooltips/shapeitem.cpp
deleted file mode 100644
index c66c7ab958..0000000000
--- a/examples/widgets/widgets/tooltips/shapeitem.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "shapeitem.h"
-
-//! [0]
-QPainterPath ShapeItem::path() const
-{
- return myPath;
-}
-//! [0]
-
-//! [1]
-QPoint ShapeItem::position() const
-{
- return myPosition;
-}
-//! [1]
-
-//! [2]
-QColor ShapeItem::color() const
-{
- return myColor;
-}
-//! [2]
-
-//! [3]
-QString ShapeItem::toolTip() const
-{
- return myToolTip;
-}
-//! [3]
-
-//! [4]
-void ShapeItem::setPath(const QPainterPath &path)
-{
- myPath = path;
-}
-//! [4]
-
-//! [5]
-void ShapeItem::setToolTip(const QString &toolTip)
-{
- myToolTip = toolTip;
-}
-//! [5]
-
-//! [6]
-void ShapeItem::setPosition(const QPoint &position)
-{
- myPosition = position;
-}
-//! [6]
-
-//! [7]
-void ShapeItem::setColor(const QColor &color)
-{
- myColor = color;
-}
-//! [7]
diff --git a/examples/widgets/widgets/tooltips/shapeitem.h b/examples/widgets/widgets/tooltips/shapeitem.h
deleted file mode 100644
index 6c0643fa89..0000000000
--- a/examples/widgets/widgets/tooltips/shapeitem.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SHAPEITEM_H
-#define SHAPEITEM_H
-
-#include <QColor>
-#include <QPainterPath>
-#include <QPoint>
-
-//! [0]
-class ShapeItem
-{
-public:
- void setPath(const QPainterPath &path);
- void setToolTip(const QString &toolTip);
- void setPosition(const QPoint &position);
- void setColor(const QColor &color);
-
- QPainterPath path() const;
- QPoint position() const;
- QColor color() const;
- QString toolTip() const;
-
-private:
- QPainterPath myPath;
- QPoint myPosition;
- QColor myColor;
- QString myToolTip;
-};
-//! [0]
-
-#endif
diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
deleted file mode 100644
index ee588eea56..0000000000
--- a/examples/widgets/widgets/tooltips/sortingbox.cpp
+++ /dev/null
@@ -1,277 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "sortingbox.h"
-
-#include <QMouseEvent>
-#include <QIcon>
-#include <QPainter>
-#include <QRandomGenerator>
-#include <QStyle>
-#include <QToolButton>
-#include <QToolTip>
-
-//! [0]
-SortingBox::SortingBox(QWidget *parent)
- : QWidget(parent)
-{
-//! [0] //! [1]
- setMouseTracking(true);
-//! [1] //! [2]
- setBackgroundRole(QPalette::Base);
-//! [2]
-
- itemInMotion = nullptr;
-
-//! [3]
- newCircleButton = createToolButton(tr("New Circle"),
- QIcon(":/images/circle.png"),
- &SortingBox::createNewCircle);
-
- newSquareButton = createToolButton(tr("New Square"),
- QIcon(":/images/square.png"),
- &SortingBox::createNewSquare);
-
- newTriangleButton = createToolButton(tr("New Triangle"),
- QIcon(":/images/triangle.png"),
- &SortingBox::createNewTriangle);
-
- circlePath.addEllipse(QRect(0, 0, 100, 100));
- squarePath.addRect(QRect(0, 0, 100, 100));
-
- qreal x = trianglePath.currentPosition().x();
- qreal y = trianglePath.currentPosition().y();
- trianglePath.moveTo(x + 120 / 2, y);
- trianglePath.lineTo(0, 100);
- trianglePath.lineTo(120, 100);
- trianglePath.lineTo(x + 120 / 2, y);
-
-//! [3] //! [4]
- setWindowTitle(tr("Tool Tips"));
- resize(500, 300);
-
- createShapeItem(circlePath, tr("Circle"), initialItemPosition(circlePath),
- initialItemColor());
- createShapeItem(squarePath, tr("Square"), initialItemPosition(squarePath),
- initialItemColor());
- createShapeItem(trianglePath, tr("Triangle"),
- initialItemPosition(trianglePath), initialItemColor());
-}
-//! [4]
-
-//! [27]
-SortingBox::~SortingBox()
-{
- qDeleteAll(shapeItems);
-}
-//! [27]
-
-//! [5]
-bool SortingBox::event(QEvent *event)
-{
-//! [5] //! [6]
- if (event->type() == QEvent::ToolTip) {
- QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
- int index = itemAt(helpEvent->pos());
- if (index != -1) {
- QToolTip::showText(helpEvent->globalPos(), shapeItems[index]->toolTip());
- } else {
- QToolTip::hideText();
- event->ignore();
- }
-
- return true;
- }
- return QWidget::event(event);
-}
-//! [6]
-
-//! [7]
-void SortingBox::resizeEvent(QResizeEvent * /* event */)
-{
- int margin = style()->pixelMetric(QStyle::PM_LayoutTopMargin);
- int x = width() - margin;
- int y = height() - margin;
-
- y = updateButtonGeometry(newCircleButton, x, y);
- y = updateButtonGeometry(newSquareButton, x, y);
- updateButtonGeometry(newTriangleButton, x, y);
-}
-//! [7]
-
-//! [8]
-void SortingBox::paintEvent(QPaintEvent * /* event */)
-{
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
- for (const ShapeItem *shapeItem : std::as_const(shapeItems)) {
-//! [8] //! [9]
- painter.translate(shapeItem->position());
-//! [9] //! [10]
- painter.setBrush(shapeItem->color());
- painter.drawPath(shapeItem->path());
- painter.translate(-shapeItem->position());
- }
-}
-//! [10]
-
-//! [11]
-void SortingBox::mousePressEvent(QMouseEvent *event)
-{
- if (event->button() == Qt::LeftButton) {
- int index = itemAt(event->position().toPoint());
- if (index != -1) {
- itemInMotion = shapeItems[index];
- previousPosition = event->position().toPoint();
- shapeItems.move(index, shapeItems.size() - 1);
- update();
- }
- }
-}
-//! [11]
-
-//! [12]
-void SortingBox::mouseMoveEvent(QMouseEvent *event)
-{
- if ((event->buttons() & Qt::LeftButton) && itemInMotion)
- moveItemTo(event->position().toPoint());
-}
-//! [12]
-
-//! [13]
-void SortingBox::mouseReleaseEvent(QMouseEvent *event)
-{
- if (event->button() == Qt::LeftButton && itemInMotion) {
- moveItemTo(event->position().toPoint());
- itemInMotion = nullptr;
- }
-}
-//! [13]
-
-//! [14]
-void SortingBox::createNewCircle()
-{
- static int count = 1;
- createShapeItem(circlePath, tr("Circle <%1>").arg(++count),
- randomItemPosition(), randomItemColor());
-}
-//! [14]
-
-//! [15]
-void SortingBox::createNewSquare()
-{
- static int count = 1;
- createShapeItem(squarePath, tr("Square <%1>").arg(++count),
- randomItemPosition(), randomItemColor());
-}
-//! [15]
-
-//! [16]
-void SortingBox::createNewTriangle()
-{
- static int count = 1;
- createShapeItem(trianglePath, tr("Triangle <%1>").arg(++count),
- randomItemPosition(), randomItemColor());
-}
-//! [16]
-
-//! [17]
-qsizetype SortingBox::itemAt(const QPoint &pos)
-{
- for (qsizetype i = shapeItems.size() - 1; i >= 0; --i) {
- const ShapeItem *item = shapeItems[i];
- if (item->path().contains(pos - item->position()))
- return i;
- }
- return -1;
-}
-//! [17]
-
-//! [18]
-void SortingBox::moveItemTo(const QPoint &pos)
-{
- QPoint offset = pos - previousPosition;
- itemInMotion->setPosition(itemInMotion->position() + offset);
-//! [18] //! [19]
- previousPosition = pos;
- update();
-}
-//! [19]
-
-//! [20]
-int SortingBox::updateButtonGeometry(QToolButton *button, int x, int y)
-{
- QSize size = button->sizeHint();
- button->setGeometry(x - size.rwidth(), y - size.rheight(),
- size.rwidth(), size.rheight());
-
- return y - size.rheight()
- - style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing);
-}
-//! [20]
-
-//! [21]
-void SortingBox::createShapeItem(const QPainterPath &path,
- const QString &toolTip, const QPoint &pos,
- const QColor &color)
-{
- ShapeItem *shapeItem = new ShapeItem;
- shapeItem->setPath(path);
- shapeItem->setToolTip(toolTip);
- shapeItem->setPosition(pos);
- shapeItem->setColor(color);
- shapeItems.append(shapeItem);
- update();
-}
-//! [21]
-
-//! [22]
-template<typename PointerToMemberFunction>
-QToolButton *SortingBox::createToolButton(const QString &toolTip,
- const QIcon &icon, const PointerToMemberFunction &member)
-{
- QToolButton *button = new QToolButton(this);
- button->setToolTip(toolTip);
- button->setIcon(icon);
- button->setIconSize(QSize(32, 32));
- connect(button, &QToolButton::clicked, this, member);
-
- return button;
-}
-//! [22]
-
-//! [23]
-QPoint SortingBox::initialItemPosition(const QPainterPath &path)
-{
- int x;
- int y = (height() - qRound(path.controlPointRect().height()) / 2);
- if (shapeItems.size() == 0)
- x = ((3 * width()) / 2 - qRound(path.controlPointRect().width())) / 2;
- else
- x = (width() / shapeItems.size()
- - qRound(path.controlPointRect().width())) / 2;
-
- return QPoint(x, y);
-}
-//! [23]
-
-//! [24]
-QPoint SortingBox::randomItemPosition()
-{
- return QPoint(QRandomGenerator::global()->bounded(width() - 120), QRandomGenerator::global()->bounded(height() - 120));
-}
-//! [24]
-
-//! [25]
-QColor SortingBox::initialItemColor()
-{
- return QColor::fromHsv(((shapeItems.size() + 1) * 85) % 256, 255, 190);
-}
-//! [25]
-
-//! [26]
-QColor SortingBox::randomItemColor()
-{
- return QColor::fromHsv(QRandomGenerator::global()->bounded(256), 255, 190);
-}
-//! [26]
diff --git a/examples/widgets/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h
deleted file mode 100644
index 9f34cf7ada..0000000000
--- a/examples/widgets/widgets/tooltips/sortingbox.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SORTINGBOX_H
-#define SORTINGBOX_H
-
-#include "shapeitem.h"
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QAction;
-class QPoint;
-class QToolButton;
-QT_END_NAMESPACE
-
-//! [0]
-class SortingBox : public QWidget
-{
- Q_OBJECT
-
-public:
- SortingBox(QWidget *parent = nullptr);
- ~SortingBox();
-
-protected:
- bool event(QEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
-
-private slots:
- void createNewCircle();
- void createNewSquare();
- void createNewTriangle();
-//! [0]
-
-//! [1]
-private:
- int updateButtonGeometry(QToolButton *button, int x, int y);
- void createShapeItem(const QPainterPath &path, const QString &toolTip,
- const QPoint &pos, const QColor &color);
- qsizetype itemAt(const QPoint &pos);
- void moveItemTo(const QPoint &pos);
- QPoint initialItemPosition(const QPainterPath &path);
- QPoint randomItemPosition();
- QColor initialItemColor();
- QColor randomItemColor();
- template<typename PointerToMemberFunction>
- QToolButton *createToolButton(const QString &toolTip, const QIcon &icon,
-//! [1]
- const PointerToMemberFunction &member);
-
-//! [2]
- QList<ShapeItem *> shapeItems;
- QPainterPath circlePath;
- QPainterPath squarePath;
- QPainterPath trianglePath;
-
- QPoint previousPosition;
- ShapeItem *itemInMotion;
-
- QToolButton *newCircleButton;
- QToolButton *newSquareButton;
- QToolButton *newTriangleButton;
-};
-//! [2]
-
-#endif
diff --git a/examples/widgets/widgets/tooltips/tooltips.pro b/examples/widgets/widgets/tooltips/tooltips.pro
deleted file mode 100644
index d14b8295ba..0000000000
--- a/examples/widgets/widgets/tooltips/tooltips.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-
-HEADERS = shapeitem.h \
- sortingbox.h
-SOURCES = main.cpp \
- shapeitem.cpp \
- sortingbox.cpp
-RESOURCES = tooltips.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/tooltips
-INSTALLS += target
diff --git a/examples/widgets/widgets/tooltips/tooltips.qrc b/examples/widgets/widgets/tooltips/tooltips.qrc
deleted file mode 100644
index dabc894e9b..0000000000
--- a/examples/widgets/widgets/tooltips/tooltips.qrc
+++ /dev/null
@@ -1,7 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/circle.png</file>
- <file>images/square.png</file>
- <file>images/triangle.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/widgets/validators/CMakeLists.txt b/examples/widgets/widgets/validators/CMakeLists.txt
deleted file mode 100644
index 6a742c4666..0000000000
--- a/examples/widgets/widgets/validators/CMakeLists.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(validators LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/validators")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(validators
- ledwidget.cpp ledwidget.h
- localeselector.cpp localeselector.h
- main.cpp
- validators.ui
- validatorwidget.cpp validatorwidget.h
-)
-
-set_target_properties(validators PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(validators PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-# Resources:
-set(validators_resource_files
- "ledoff.png"
- "ledon.png"
-)
-
-qt_add_resources(validators "validators"
- PREFIX
- "/"
- FILES
- ${validators_resource_files}
-)
-
-install(TARGETS validators
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/widgets/validators/ledoff.png b/examples/widgets/widgets/validators/ledoff.png
deleted file mode 100644
index 8b1f2ed123..0000000000
--- a/examples/widgets/widgets/validators/ledoff.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/validators/ledon.png b/examples/widgets/widgets/validators/ledon.png
deleted file mode 100644
index 601c34d5a8..0000000000
--- a/examples/widgets/widgets/validators/ledon.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/widgets/validators/ledwidget.cpp b/examples/widgets/widgets/validators/ledwidget.cpp
deleted file mode 100644
index 5b95595a75..0000000000
--- a/examples/widgets/widgets/validators/ledwidget.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "ledwidget.h"
-
-LEDWidget::LEDWidget(QWidget *parent)
- : QLabel(parent), onPixmap(":/ledon.png"), offPixmap(":/ledoff.png")
-{
- setPixmap(offPixmap);
- flashTimer.setInterval(200);
- flashTimer.setSingleShot(true);
- connect(&flashTimer, &QTimer::timeout, this, &LEDWidget::extinguish);
-};
-
-void LEDWidget::extinguish()
-{
- setPixmap(offPixmap);
-}
-
-void LEDWidget::flash()
-{
- setPixmap(onPixmap);
- flashTimer.start();
-}
-
diff --git a/examples/widgets/widgets/validators/ledwidget.h b/examples/widgets/widgets/validators/ledwidget.h
deleted file mode 100644
index 81215b668f..0000000000
--- a/examples/widgets/widgets/validators/ledwidget.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef LEDWIDGET_H
-#define LEDWIDGET_H
-
-#include <QLabel>
-#include <QPixmap>
-#include <QTimer>
-
-class LEDWidget : public QLabel
-{
- Q_OBJECT
-public:
- LEDWidget(QWidget *parent = nullptr);
-public slots:
- void flash();
-
-private slots:
- void extinguish();
-
-private:
- QPixmap onPixmap, offPixmap;
- QTimer flashTimer;
-};
-
-#endif // LEDWIDGET_H
diff --git a/examples/widgets/widgets/validators/localeselector.cpp b/examples/widgets/widgets/validators/localeselector.cpp
deleted file mode 100644
index c74faa8c9d..0000000000
--- a/examples/widgets/widgets/validators/localeselector.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "localeselector.h"
-
-#include <QLocale>
-
-LocaleSelector::LocaleSelector(QWidget *parent)
- : QComboBox(parent)
-{
- int curIndex = -1;
- int index = 0;
- for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
- QLocale::Language lang = static_cast<QLocale::Language>(_lang);
- const QList<QLocale> locales =
- QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyTerritory);
- for (const QLocale &l : locales) {
- QString label = QLocale::languageToString(l.language());
- label += QLatin1Char('/');
- label += QLocale::territoryToString(l.territory());
- // distinguish locales by script, if there are more than one script for a language/territory pair
- if (QLocale::matchingLocales(l.language(), QLocale::AnyScript, l.territory()).size() > 1)
- label += QLatin1String(" (") + QLocale::scriptToString(l.script()) + QLatin1Char(')');
-
- addItem(label, QVariant::fromValue(l));
-
- if (l.language() == locale().language() && l.territory() == locale().territory()
- && (locale().script() == QLocale::AnyScript || l.script() == locale().script())) {
- curIndex = index;
- }
- ++index;
- }
- }
- if (curIndex != -1)
- setCurrentIndex(curIndex);
-
- connect(this, QOverload<int>::of(&LocaleSelector::activated),
- this, &LocaleSelector::emitLocaleSelected);
-}
-
-void LocaleSelector::emitLocaleSelected(int index)
-{
- QVariant v = itemData(index);
- if (!v.isValid())
- return;
- const QLocale l = qvariant_cast<QLocale>(v);
- emit localeSelected(l);
-}
diff --git a/examples/widgets/widgets/validators/localeselector.h b/examples/widgets/widgets/validators/localeselector.h
deleted file mode 100644
index c684e18d40..0000000000
--- a/examples/widgets/widgets/validators/localeselector.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef LOCALESELECTOR_H
-#define LOCALESELECTOR_H
-
-#include <QComboBox>
-
-class LocaleSelector : public QComboBox
-{
- Q_OBJECT
-
-public:
- LocaleSelector(QWidget *parent = nullptr);
-
-signals:
- void localeSelected(const QLocale &locale);
-
-private slots:
- void emitLocaleSelected(int index);
-};
-
-#endif //LOCALESELECTOR_H
diff --git a/examples/widgets/widgets/validators/main.cpp b/examples/widgets/widgets/validators/main.cpp
deleted file mode 100644
index b5a685e850..0000000000
--- a/examples/widgets/widgets/validators/main.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "validatorwidget.h"
-
-#include <QApplication>
-
-int main(int argc, char **argv)
-{
- Q_INIT_RESOURCE(validators);
-
- QApplication app(argc, argv);
-
- ValidatorWidget w;
- w.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/widgets/validators/validators.pro b/examples/widgets/widgets/validators/validators.pro
deleted file mode 100644
index 029cf95aca..0000000000
--- a/examples/widgets/widgets/validators/validators.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-requires(qtConfig(combobox))
-
-FORMS += validators.ui
-RESOURCES += validators.qrc
-
-SOURCES += main.cpp ledwidget.cpp localeselector.cpp validatorwidget.cpp
-HEADERS += ledwidget.h localeselector.h validatorwidget.h
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/validators
-INSTALLS += target
diff --git a/examples/widgets/widgets/validators/validators.qrc b/examples/widgets/widgets/validators/validators.qrc
deleted file mode 100644
index 94874317a8..0000000000
--- a/examples/widgets/widgets/validators/validators.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>ledoff.png</file>
- <file>ledon.png</file>
- </qresource>
-</RCC>
diff --git a/examples/widgets/widgets/validators/validators.ui b/examples/widgets/widgets/validators/validators.ui
deleted file mode 100644
index cd984e6b97..0000000000
--- a/examples/widgets/widgets/validators/validators.ui
+++ /dev/null
@@ -1,468 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>ValidatorsForm</class>
- <widget class="QWidget" name="ValidatorsForm">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>526</width>
- <height>443</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Validators</string>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>9</number>
- </property>
- <item>
- <layout class="QHBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>0</number>
- </property>
- <item>
- <widget class="LocaleSelector" name="localeSelector"/>
- </item>
- <item>
- <spacer>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>QIntValidator</string>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>9</number>
- </property>
- <item>
- <layout class="QHBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>0</number>
- </property>
- <item>
- <layout class="QGridLayout">
- <property name="margin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>6</number>
- </property>
- <item row="0" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Min:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QSpinBox" name="minVal">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimum">
- <number>-1000000</number>
- </property>
- <property name="maximum">
- <number>1000000</number>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Max:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QSpinBox" name="maxVal">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimum">
- <number>-1000000</number>
- </property>
- <property name="maximum">
- <number>1000000</number>
- </property>
- <property name="value">
- <number>1000</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QFrame" name="frame">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Sunken</enum>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>9</number>
- </property>
- <item>
- <widget class="LEDWidget" name="ledWidget">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="pixmap">
- <pixmap resource="validators.qrc">:/ledoff.png</pixmap>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_7">
- <property name="text">
- <string>editingFinished()</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <spacer>
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QLineEdit" name="editor"/>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="groupBox_2">
- <property name="title">
- <string>QDoubleValidator</string>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>9</number>
- </property>
- <item>
- <layout class="QHBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>0</number>
- </property>
- <item>
- <layout class="QGridLayout">
- <property name="margin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>6</number>
- </property>
- <item row="0" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Min:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QDoubleSpinBox" name="doubleMinVal">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimum">
- <double>-100000.000000000000000</double>
- </property>
- <property name="maximum">
- <double>100000.000000000000000</double>
- </property>
- <property name="value">
- <double>0.000000000000000</double>
- </property>
- </widget>
- </item>
- <item row="0" column="2">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>Format:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="0" column="3">
- <widget class="QComboBox" name="doubleFormat">
- <item>
- <property name="text">
- <string>Standard</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Scientific</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>Max:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QDoubleSpinBox" name="doubleMaxVal">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimum">
- <double>-100000.000000000000000</double>
- </property>
- <property name="maximum">
- <double>100000.000000000000000</double>
- </property>
- <property name="value">
- <double>1000.000000000000000</double>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QLabel" name="label_6">
- <property name="text">
- <string>Decimals:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="1" column="3">
- <widget class="QSpinBox" name="doubleDecimals">
- <property name="value">
- <number>2</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QFrame" name="frame_2">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Sunken</enum>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>9</number>
- </property>
- <item>
- <widget class="LEDWidget" name="doubleLedWidget">
- <property name="text">
- <string/>
- </property>
- <property name="pixmap">
- <pixmap resource="validators.qrc">:/ledoff.png</pixmap>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_8">
- <property name="text">
- <string>editingFinished()</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <spacer>
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QLineEdit" name="doubleEditor"/>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <spacer>
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>111</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <layout class="QHBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <property name="margin">
- <number>0</number>
- </property>
- <item>
- <spacer>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton">
- <property name="text">
- <string>Quit</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <customwidgets>
- <customwidget>
- <class>LEDWidget</class>
- <extends>QLabel</extends>
- <header>ledwidget.h</header>
- </customwidget>
- <customwidget>
- <class>LocaleSelector</class>
- <extends>QComboBox</extends>
- <header>localeselector.h</header>
- </customwidget>
- </customwidgets>
- <resources>
- <include location="validators.qrc"/>
- </resources>
- <connections>
- <connection>
- <sender>pushButton</sender>
- <signal>clicked()</signal>
- <receiver>ValidatorsForm</receiver>
- <slot>close()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>94</x>
- <y>274</y>
- </hint>
- <hint type="destinationlabel">
- <x>131</x>
- <y>260</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/examples/widgets/widgets/validators/validatorwidget.cpp b/examples/widgets/widgets/validators/validatorwidget.cpp
deleted file mode 100644
index 7782342221..0000000000
--- a/examples/widgets/widgets/validators/validatorwidget.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "validatorwidget.h"
-
-#include <QIntValidator>
-
-ValidatorWidget::ValidatorWidget(QWidget *parent)
- : QWidget(parent)
-{
- setupUi(this);
-
- connect(localeSelector, &LocaleSelector::localeSelected,
- this, &ValidatorWidget::setLocale);
- connect(localeSelector, &LocaleSelector::localeSelected,
- this, &ValidatorWidget::updateValidator);
- connect(localeSelector, &LocaleSelector::localeSelected,
- this, &ValidatorWidget::updateDoubleValidator);
-
- connect(minVal, &QSpinBox::editingFinished,
- this, &ValidatorWidget::updateValidator);
- connect(maxVal, &QSpinBox::editingFinished,
- this, &ValidatorWidget::updateValidator);
- connect(editor, &QLineEdit::editingFinished,
- ledWidget, &LEDWidget::flash);
-
- connect(doubleMaxVal, &QDoubleSpinBox::editingFinished,
- this, &ValidatorWidget::updateDoubleValidator);
- connect(doubleMinVal, &QDoubleSpinBox::editingFinished,
- this, &ValidatorWidget::updateDoubleValidator);
- connect(doubleDecimals, &QSpinBox::valueChanged,
- this, &ValidatorWidget::updateDoubleValidator);
- connect(doubleFormat, &QComboBox::activated,
- this, &ValidatorWidget::updateDoubleValidator);
- connect(doubleEditor, &QLineEdit::editingFinished,
- doubleLedWidget, &LEDWidget::flash);
-
- updateValidator();
- updateDoubleValidator();
-}
-
-void ValidatorWidget::updateValidator()
-{
- QIntValidator *v = new QIntValidator(minVal->value(), maxVal->value(), this);
- v->setLocale(locale());
- delete editor->validator();
- editor->setValidator(v);
-
- QString s = editor->text();
- int i = 0;
- if (v->validate(s, i) == QValidator::Invalid) {
- editor->clear();
- } else {
- editor->setText(s);
- }
-}
-
-void ValidatorWidget::updateDoubleValidator()
-{
- QDoubleValidator *v
- = new QDoubleValidator(doubleMinVal->value(), doubleMaxVal->value(),
- doubleDecimals->value(), this);
- v->setNotation(static_cast<QDoubleValidator::Notation>(doubleFormat->currentIndex()));
- v->setLocale(locale());
- delete doubleEditor->validator();
- doubleEditor->setValidator(v);
-
- QString s = doubleEditor->text();
- int i = 0;
- if (v->validate(s, i) == QValidator::Invalid) {
- doubleEditor->clear();
- } else {
- doubleEditor->setText(s);
- }
-}
diff --git a/examples/widgets/widgets/validators/validatorwidget.h b/examples/widgets/widgets/validators/validatorwidget.h
deleted file mode 100644
index d186c5863b..0000000000
--- a/examples/widgets/widgets/validators/validatorwidget.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef VALIDATORWIDGET_H
-#define VALIDATORWIDGET_H
-
-#include <QWidget>
-
-#include "ui_validators.h"
-
-class ValidatorWidget : public QWidget, public Ui::ValidatorsForm
-{
- Q_OBJECT
-public:
- ValidatorWidget(QWidget *parent = nullptr);
-
-private slots:
- void updateValidator();
- void updateDoubleValidator();
-};
-
-#endif // VALIDATORWIDGET_H
diff --git a/examples/widgets/widgets/widgets.pro b/examples/widgets/widgets/widgets.pro
index 36d428429c..5dd8f5eedc 100644
--- a/examples/widgets/widgets/widgets.pro
+++ b/examples/widgets/widgets/widgets.pro
@@ -2,21 +2,10 @@ TEMPLATE = subdirs
SUBDIRS = analogclock \
calculator \
calendarwidget \
- charactermap \
- digitalclock \
- groupbox \
- icons \
- imageviewer \
lineedits \
- movie \
scribble \
shapedclock \
sliders \
spinboxes \
- styles \
- stylesheet \
tablet \
- tetrix \
- tooltips \
- validators \
windowflags
diff --git a/examples/widgets/widgets/windowflags/CMakeLists.txt b/examples/widgets/widgets/windowflags/CMakeLists.txt
index 9263cde104..fbc1bf217b 100644
--- a/examples/widgets/widgets/windowflags/CMakeLists.txt
+++ b/examples/widgets/widgets/windowflags/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(windowflags LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/windowflags")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
@@ -32,7 +26,14 @@ target_link_libraries(windowflags PRIVATE
)
install(TARGETS windowflags
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET windowflags
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/windowcontainer/CMakeLists.txt b/examples/widgets/windowcontainer/CMakeLists.txt
deleted file mode 100644
index 925dbfc366..0000000000
--- a/examples/widgets/windowcontainer/CMakeLists.txt
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(windowcontainer LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/windowcontainer")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(windowcontainer
- ../../opengl/openglwindow/openglwindow.cpp ../../opengl/openglwindow/openglwindow.h
- windowcontainer.cpp
-)
-
-set_target_properties(windowcontainer PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_include_directories(windowcontainer PRIVATE
- ../../opengl/openglwindow
-)
-
-target_link_libraries(windowcontainer PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::OpenGL
- Qt6::Widgets
-)
-
-install(TARGETS windowcontainer
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/windowcontainer/windowcontainer.cpp b/examples/widgets/windowcontainer/windowcontainer.cpp
deleted file mode 100644
index fa66684294..0000000000
--- a/examples/widgets/windowcontainer/windowcontainer.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "openglwindow.h"
-
-#include <QApplication>
-#include <QFocusEvent>
-#include <QHBoxLayout>
-#include <QKeyEvent>
-#include <QLineEdit>
-#include <QMouseEvent>
-#include <QPainter>
-#include <QWidget>
-
-
-// Making use of the class from the openglwindow example
-class Window : public OpenGLWindow
-{
- Q_OBJECT
-public:
- using OpenGLWindow::OpenGLWindow;
-
- void render(QPainter *p) override
- {
- QLinearGradient g(0, 0, 0, height());
- g.setColorAt(0, QColor("lightsteelblue"));
- g.setColorAt(1, Qt::black);
- p->fillRect(0, 0, width(), height(), g);
-
- p->setPen(Qt::white);
-
- p->drawText(20, 30, QLatin1String("This is an OpenGL based QWindow"));
-
- if (m_key.trimmed().length() > 0) {
- QRect bounds = p->boundingRect(QRect(0, 0, width(), height()), Qt::AlignTop | Qt::AlignLeft, m_key);
- p->save();
- p->translate(width() / 2.0, height() / 2.0);
- p->scale(10, 10);
- p->translate(-bounds.width() / 2.0, -bounds.height() / 2.0);
- p->drawText(bounds, Qt::AlignCenter, m_key);
- p->restore();
- }
-
- if (m_focus)
- p->drawText(20, height() - 20, QLatin1String("Window has focus!"));
-
- p->setRenderHint(QPainter::Antialiasing);
- p->drawPolyline(m_polygon);
- }
-
- void mousePressEvent(QMouseEvent *e) override
- {
- if (!m_mouseDown) {
- m_mouseDown = true;
- m_polygon.clear();
- m_polygon.append(e->position().toPoint());
- renderLater();
- }
- }
-
- void mouseMoveEvent(QMouseEvent *e) override
- {
- if (m_mouseDown) {
- m_polygon.append(e->position().toPoint());
- renderLater();
- }
- }
-
- void mouseReleaseEvent(QMouseEvent *e) override
- {
- if (m_mouseDown) {
- m_mouseDown = false;
- m_polygon.append(e->position().toPoint());
- renderLater();
- }
- }
-
- void focusInEvent(QFocusEvent *) override
- {
- m_focus = true;
- renderLater();
- }
-
- void focusOutEvent(QFocusEvent *) override
- {
- m_focus = false;
- m_polygon.clear();
- renderLater();
- }
-
- void keyPressEvent(QKeyEvent *e) override
- {
- m_key = e->text();
- renderLater();
- }
-
- void keyReleaseEvent(QKeyEvent *) override
- {
- m_key = QString();
- renderLater();
- }
-private:
- QPolygon m_polygon;
- QString m_key;
- bool m_mouseDown = false;
- bool m_focus = false;
-};
-
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- QWidget *widget = new QWidget;
- QHBoxLayout *layout = new QHBoxLayout(widget);
-
- Window *window = new Window;
-
- QWidget *container = QWidget::createWindowContainer(window);
- container->setMinimumSize(300, 300);
- container->setMaximumSize(600, 600);
- container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- container->setFocusPolicy(Qt::StrongFocus);
-
- window->setGeometry(100, 100, 300, 200);
-
- layout->addWidget(new QLineEdit(QLatin1String("A QLineEdit")));
- layout->addWidget(container);
- layout->addWidget(new QLineEdit(QLatin1String("A QLabel")));
-
- widget->show();
-
- return app.exec();
-}
-
-#include "windowcontainer.moc"
diff --git a/examples/widgets/windowcontainer/windowcontainer.pro b/examples/widgets/windowcontainer/windowcontainer.pro
deleted file mode 100644
index 664ac938a2..0000000000
--- a/examples/widgets/windowcontainer/windowcontainer.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-SOURCES = windowcontainer.cpp
-
-QT += widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/windowcontainer
-INSTALLS += target
-
-include(../../opengl/openglwindow/openglwindow.pri)
diff --git a/examples/xml/CMakeLists.txt b/examples/xml/CMakeLists.txt
index da1dde9acb..aca12accfe 100644
--- a/examples/xml/CMakeLists.txt
+++ b/examples/xml/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(TARGET Qt6::Widgets)
qt_internal_add_example(dombookmarks)
diff --git a/examples/xml/dombookmarks/CMakeLists.txt b/examples/xml/dombookmarks/CMakeLists.txt
index d8277bc2e4..58efd94a55 100644
--- a/examples/xml/dombookmarks/CMakeLists.txt
+++ b/examples/xml/dombookmarks/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(dombookmarks LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/xml/dombookmarks")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Xml)
qt_standard_project_setup()
@@ -33,7 +27,14 @@ target_link_libraries(dombookmarks PRIVATE
)
install(TARGETS dombookmarks
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET dombookmarks
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/xml/dombookmarks/doc/images/dombookmarks-example.png b/examples/xml/dombookmarks/doc/images/dombookmarks-example.png
deleted file mode 100644
index abacacbbfc..0000000000
--- a/examples/xml/dombookmarks/doc/images/dombookmarks-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/xml/dombookmarks/doc/images/screenshot.png b/examples/xml/dombookmarks/doc/images/screenshot.png
new file mode 100644
index 0000000000..462052ce8a
--- /dev/null
+++ b/examples/xml/dombookmarks/doc/images/screenshot.png
Binary files differ
diff --git a/examples/xml/dombookmarks/doc/src/dombookmarks.qdoc b/examples/xml/dombookmarks/doc/src/dombookmarks.qdoc
index eff9dccb3d..0b3ca2f47d 100644
--- a/examples/xml/dombookmarks/doc/src/dombookmarks.qdoc
+++ b/examples/xml/dombookmarks/doc/src/dombookmarks.qdoc
@@ -4,23 +4,23 @@
/*!
\example dombookmarks
\title DOM Bookmarks Application
- \examplecategory {Input/Output}
+ \examplecategory {Data Processing & I/O}
\ingroup xml-examples
\meta tag {xml}
\brief Provides a reader for XML Bookmark Exchange Language files.
The DOM Bookmarks Application provides a reader for XML Bookmark Exchange
Language (XBEL) files that uses Qt's DOM-based XML API to read and parse
- the files. The {QXmlStream Bookmarks Example} provides an alternative
+ the files. The \l {QXmlStream Bookmarks Example} provides an alternative
way to read this type of file.
- \image dombookmarks-example.png
+ \image screenshot.png
\section1 The XbelTree Class Definition
The XbelTree class has functions for reading and writing to the filesystem.
It inherits from the QTreeWidget class, contains the model for the
- dispalying of the bookmarks, and allows it to be edited.
+ displaying of the bookmarks, and allows it to be edited.
\snippet dombookmarks/xbeltree.h 0
@@ -68,23 +68,22 @@
\snippet dombookmarks/mainwindow.cpp 0
- The \c createMenus() function poulates the menus and sets keyboard
+ The \c createMenus() function populates the menus and sets keyboard
shortcuts.
\snippet dombookmarks/mainwindow.cpp 4
The \c open() function enables the user to open an XBEL file using
- QFileDialog::getOpenFileName(). A warning message is displayed along
+ QFileDialog. A warning message is displayed along
with the \c fileName and \c errorString if the file cannot be read or
if there is a parse error. If it succeeds it calls \c XbelTree::read().
\snippet dombookmarks/mainwindow.cpp 1
The \c saveAs() function displays a QFileDialog, prompting the user for
- a \c fileName using QFileDialog::getSaveFileName(). Similar to the
- \c open() function, this function also displays a warning message if
- the file cannot be written to. IF this succeeds it calls \c
- XbelTree::write().
+ a \c fileName. Similar to the \c open() function, this function also
+ displays a warning message if the file cannot be written to. If this
+ succeeds it calls \c XbelTree::write().
\snippet dombookmarks/mainwindow.cpp 2
diff --git a/examples/xml/dombookmarks/dombookmarks.pro b/examples/xml/dombookmarks/dombookmarks.pro
index 280207eebb..f6cf6ffc6d 100644
--- a/examples/xml/dombookmarks/dombookmarks.pro
+++ b/examples/xml/dombookmarks/dombookmarks.pro
@@ -6,7 +6,7 @@ SOURCES = main.cpp \
QT += xml widgets
requires(qtConfig(filedialog))
-EXAMPLE_FILES = frank.xbel jennifer.xbel
+EXAMPLE_FILES = jennifer.xbel
# install
target.path = $$[QT_INSTALL_EXAMPLES]/xml/dombookmarks
diff --git a/examples/xml/dombookmarks/jennifer.xbel b/examples/xml/dombookmarks/jennifer.xbel
index 2501c118af..d504236830 100644
--- a/examples/xml/dombookmarks/jennifer.xbel
+++ b/examples/xml/dombookmarks/jennifer.xbel
@@ -3,66 +3,66 @@
<xbel version="1.0">
<folder folded="no">
<title>Qt Resources</title>
- <bookmark href="http://qt.io/">
+ <bookmark href="https://www.qt.io/">
<title>Qt home page</title>
</bookmark>
- <bookmark href="https://www.qt.io/partners/">
+ <bookmark href="https://www.qt.io/contact-us/partners">
<title>Qt Partners</title>
</bookmark>
- <bookmark href="https://www.qt.io/qt-training/">
- <title>Training</title>
+ <bookmark href="https://www.qt.io/qt-professional-services">
+ <title>Professional Services</title>
</bookmark>
- <bookmark href="http://doc.qt.io/">
- <title>Qt 5 documentation</title>
- </bookmark>
- <bookmark href="http://qt-project.org/faq/">
- <title>Frequently Asked Questions</title>
+ <bookmark href="https://doc.qt.io/">
+ <title>Qt Documentation</title>
</bookmark>
<folder folded="yes">
<title>Community Resources</title>
- <bookmark href="http://www.qtcentre.org/content/">
+ <bookmark href="https://contribute.qt-project.org">
+ <title>The Qt Project</title>
+ </bookmark>
+ <bookmark href="https://www.qtcentre.org/content/">
<title>Qt Centre</title>
</bookmark>
- <bookmark href="http://www.qtforum.org/">
- <title>QtForum.org</title>
+ <bookmark href="https://forum.qt.io/">
+ <title>Forum.Qt.org</title>
</bookmark>
- <bookmark href="http://digitalfanatics.org/projects/qt_tutorial/">
+ <bookmark href="https://digitalfanatics.org/projects/qt_tutorial/">
<title>The Independent Qt Tutorial</title>
</bookmark>
- <bookmark href="http://www.qtforum.de/">
+ <bookmark href="https://www.qtforum.de/">
<title>German Qt Forum</title>
</bookmark>
- <bookmark href="http://www.korone.net/">
+ <bookmark href="https://www.qt-dev.com/">
<title>Korean Qt Community Site</title>
</bookmark>
- <bookmark href="http://prog.org.ru/">
+ <bookmark href="http://www.prog.org.ru/">
<title>Russian Qt Forum</title>
</bookmark>
</folder>
</folder>
<folder folded="no">
<title>Online Dictionaries</title>
- <bookmark href="http://www.dictionary.com/">
+ <bookmark href="https://www.dictionary.com/">
<title>Dictionary.com</title>
</bookmark>
- <bookmark href="http://www.m-w.com/">
+ <bookmark href="https://www.merriam-webster.com/">
<title>Merriam-Webster Online</title>
</bookmark>
- <bookmark href="http://dictionary.cambridge.org/">
+ <bookmark href="https://dictionary.cambridge.org/">
<title>Cambridge Dictionaries Online</title>
</bookmark>
- <bookmark href="http://www.onelook.com/">
+ <bookmark href="https://www.onelook.com/">
<title>OneLook Dictionary Search</title>
</bookmark>
<separator/>
- <bookmark href="http://dict.tu-chemnitz.de/">
- <title>TU Chemnitz German-English Dictionary</title>
+ <bookmark href="https://dict.tu-chemnitz.de/">
+ <title>BEOLINGUS, a service of TU Chemnitz</title>
</bookmark>
<separator/>
<bookmark href="http://atilf.atilf.fr/tlf.htm">
<title>Trésor de la Langue Française informatisé</title>
</bookmark>
- <bookmark href="http://dictionnaires.atilf.fr/dictionnaires/ACADEMIE/">
+ <bookmark href="https://www.dictionnaire-academie.fr/">
<title>Dictionnaire de l'Académie Française</title>
</bookmark>
</folder>
diff --git a/examples/xml/dombookmarks/mainwindow.cpp b/examples/xml/dombookmarks/mainwindow.cpp
index 66156a2ff1..5e6c68ce8d 100644
--- a/examples/xml/dombookmarks/mainwindow.cpp
+++ b/examples/xml/dombookmarks/mainwindow.cpp
@@ -1,11 +1,20 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "xbeltree.h"
+#include <QApplication>
+#include <QFileDialog>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStatusBar>
+
+#include <QAction>
+#include <QScreen>
+
+using namespace Qt::StringLiterals;
+
//! [0]
MainWindow::MainWindow()
{
@@ -25,16 +34,15 @@ MainWindow::MainWindow()
//! [1]
void MainWindow::open()
{
- QString fileName =
- QFileDialog::getOpenFileName(this, tr("Open Bookmark File"),
- QDir::currentPath(),
- tr("XBEL Files (*.xbel *.xml)"));
- if (fileName.isEmpty())
+ QFileDialog fileDialog(this, tr("Open Bookmark File"), QDir::currentPath());
+ fileDialog.setMimeTypeFilters({"application/x-xbel"_L1});
+ if (fileDialog.exec() != QDialog::Accepted)
return;
+ const QString fileName = fileDialog.selectedFiles().constFirst();
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("SAX Bookmarks"),
+ QMessageBox::warning(this, tr("DOM Bookmarks"),
tr("Cannot read file %1:\n%2.")
.arg(QDir::toNativeSeparators(fileName),
file.errorString()));
@@ -49,16 +57,17 @@ void MainWindow::open()
//! [2]
void MainWindow::saveAs()
{
- QString fileName =
- QFileDialog::getSaveFileName(this, tr("Save Bookmark File"),
- QDir::currentPath(),
- tr("XBEL Files (*.xbel *.xml)"));
- if (fileName.isEmpty())
+ QFileDialog fileDialog(this, tr("Save Bookmark File"), QDir::currentPath());
+ fileDialog.setAcceptMode(QFileDialog::AcceptSave);
+ fileDialog.setDefaultSuffix("xbel"_L1);
+ fileDialog.setMimeTypeFilters({"application/x-xbel"_L1});
+ if (fileDialog.exec() != QDialog::Accepted)
return;
+ const QString fileName = fileDialog.selectedFiles().constFirst();
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("SAX Bookmarks"),
+ QMessageBox::warning(this, tr("DOM Bookmarks"),
tr("Cannot write file %1:\n%2.")
.arg(QDir::toNativeSeparators(fileName),
file.errorString()));
@@ -97,6 +106,6 @@ void MainWindow::createMenus()
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(tr("&About"), this, &MainWindow::about);
- helpMenu->addAction(tr("About &Qt"), qApp, &QCoreApplication::quit);
+ helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
}
//! [4]
diff --git a/examples/xml/dombookmarks/xbeltree.cpp b/examples/xml/dombookmarks/xbeltree.cpp
index ce6fb20a12..eff2fea8f0 100644
--- a/examples/xml/dombookmarks/xbeltree.cpp
+++ b/examples/xml/dombookmarks/xbeltree.cpp
@@ -1,31 +1,41 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-
#include "xbeltree.h"
+#include <QHeaderView>
+#include <QMenu>
+#include <QMessageBox>
+
+#include <QDesktopServices>
+#include <QGuiApplication>
+#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
+# include <QClipboard>
+# include <QContextMenuEvent>
+#endif
+
+#include <QUrl>
+
+using namespace Qt::StringLiterals;
+
enum { DomElementRole = Qt::UserRole + 1 };
Q_DECLARE_METATYPE(QDomElement)
-static inline QString titleElement() { return QStringLiteral("title"); }
-static inline QString folderElement() { return QStringLiteral("folder"); }
-static inline QString bookmarkElement() { return QStringLiteral("bookmark"); }
+static const auto titleElement = u"title"_s;
+static const auto folderElement = u"folder"_s;
+static const auto bookmarkElement = u"bookmark"_s;
-static inline QString versionAttribute() { return QStringLiteral("version"); }
-static inline QString hrefAttribute() { return QStringLiteral("href"); }
-static inline QString foldedAttribute() { return QStringLiteral("folded"); }
+static const auto versionAttribute = u"version"_s;
+static const auto hrefAttribute = u"href"_s;
+static const auto foldedAttribute = u"folded"_s;
//! [0]
XbelTree::XbelTree(QWidget *parent)
: QTreeWidget(parent)
{
- QStringList labels;
- labels << tr("Title") << tr("Location");
-
header()->setSectionResizeMode(QHeaderView::Stretch);
- setHeaderLabels(labels);
+ setHeaderLabels({tr("Title"), tr("Location")});
folderIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
QIcon::Normal, QIcon::Off);
@@ -35,7 +45,7 @@ XbelTree::XbelTree(QWidget *parent)
}
//! [0]
-#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD)
+#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
void XbelTree::contextMenuEvent(QContextMenuEvent *event)
{
const QTreeWidgetItem *item = itemAt(event->pos());
@@ -51,7 +61,7 @@ void XbelTree::contextMenuEvent(QContextMenuEvent *event)
else if (action == openAction)
QDesktopServices::openUrl(QUrl(url));
}
-#endif // !QT_NO_CONTEXTMENU && !QT_NO_CLIPBOARD
+#endif // QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
//! [1]
bool XbelTree::read(QIODevice *device)
@@ -72,8 +82,8 @@ bool XbelTree::read(QIODevice *device)
QMessageBox::information(window(), tr("DOM Bookmarks"),
tr("The file is not an XBEL file."));
return false;
- } else if (root.hasAttribute(versionAttribute())
- && root.attribute(versionAttribute()) != QLatin1String("1.0")) {
+ } else if (root.hasAttribute(versionAttribute)
+ && root.attribute(versionAttribute) != "1.0"_L1) {
QMessageBox::information(window(), tr("DOM Bookmarks"),
tr("The file is not an XBEL version 1.0 "
"file."));
@@ -84,10 +94,10 @@ bool XbelTree::read(QIODevice *device)
disconnect(this, &QTreeWidget::itemChanged, this, &XbelTree::updateDomElement);
- QDomElement child = root.firstChildElement(folderElement());
+ QDomElement child = root.firstChildElement(folderElement);
while (!child.isNull()) {
parseFolderElement(child);
- child = child.nextSiblingElement(folderElement());
+ child = child.nextSiblingElement(folderElement);
}
connect(this, &QTreeWidget::itemChanged, this, &XbelTree::updateDomElement);
@@ -112,16 +122,16 @@ void XbelTree::updateDomElement(const QTreeWidgetItem *item, int column)
QDomElement element = qvariant_cast<QDomElement>(item->data(0, DomElementRole));
if (!element.isNull()) {
if (column == 0) {
- QDomElement oldTitleElement = element.firstChildElement(titleElement());
- QDomElement newTitleElement = domDocument.createElement(titleElement());
+ QDomElement oldTitleElement = element.firstChildElement(titleElement);
+ QDomElement newTitleElement = domDocument.createElement(titleElement);
QDomText newTitleText = domDocument.createTextNode(item->text(0));
newTitleElement.appendChild(newTitleText);
element.replaceChild(newTitleElement, oldTitleElement);
} else {
- if (element.tagName() == bookmarkElement())
- element.setAttribute(hrefAttribute(), item->text(1));
+ if (element.tagName() == bookmarkElement)
+ element.setAttribute(hrefAttribute, item->text(1));
}
}
}
@@ -132,36 +142,38 @@ void XbelTree::parseFolderElement(const QDomElement &element,
{
QTreeWidgetItem *item = createItem(element, parentItem);
- QString title = element.firstChildElement(titleElement()).text();
+ QString title = element.firstChildElement(titleElement).text();
if (title.isEmpty())
- title = QObject::tr("Folder");
+ title = tr("Folder");
item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setIcon(0, folderIcon);
item->setText(0, title);
- bool folded = (element.attribute(foldedAttribute()) != QLatin1String("no"));
+ bool folded = (element.attribute(foldedAttribute) != "no"_L1);
item->setExpanded(!folded);
+ constexpr char16_t midDot = u'\xB7';
+ static const QString dots = QString(30, midDot);
QDomElement child = element.firstChildElement();
while (!child.isNull()) {
- if (child.tagName() == folderElement()) {
+ if (child.tagName() == folderElement) {
parseFolderElement(child, item);
- } else if (child.tagName() == bookmarkElement()) {
+ } else if (child.tagName() == bookmarkElement) {
QTreeWidgetItem *childItem = createItem(child, item);
- QString title = child.firstChildElement(titleElement()).text();
+ QString title = child.firstChildElement(titleElement).text();
if (title.isEmpty())
- title = QObject::tr("Folder");
+ title = tr("Folder");
childItem->setFlags(item->flags() | Qt::ItemIsEditable);
childItem->setIcon(0, bookmarkIcon);
childItem->setText(0, title);
- childItem->setText(1, child.attribute(hrefAttribute()));
- } else if (child.tagName() == QLatin1String("separator")) {
+ childItem->setText(1, child.attribute(hrefAttribute));
+ } else if (child.tagName() == "separator"_L1) {
QTreeWidgetItem *childItem = createItem(child, item);
childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable));
- childItem->setText(0, QString(30, u'\xB7'));
+ childItem->setText(0, dots);
}
child = child.nextSiblingElement();
}
diff --git a/examples/xml/dombookmarks/xbeltree.h b/examples/xml/dombookmarks/xbeltree.h
index 0788c4c8ab..caaf4c0062 100644
--- a/examples/xml/dombookmarks/xbeltree.h
+++ b/examples/xml/dombookmarks/xbeltree.h
@@ -14,13 +14,13 @@ class XbelTree : public QTreeWidget
Q_OBJECT
public:
- XbelTree(QWidget *parent = nullptr);
+ explicit XbelTree(QWidget *parent = nullptr);
bool read(QIODevice *device);
bool write(QIODevice *device) const;
protected:
-#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD)
+#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
void contextMenuEvent(QContextMenuEvent *event) override;
#endif