├── Chapter03 └── Qt GUI Programming │ └── tictactoe │ ├── tictactoe ver1 │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ └── tictactoe ver1.pro │ ├── tictactoe ver2 │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ └── tictactoe ver2.pro │ ├── tictactoe ver3 │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── tictactoe ver3.pro │ ├── tictactoewidget.cpp │ └── tictactoewidget.h │ ├── tictactoe ver4 │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── tictactoe ver4.pro │ ├── tictactoewidget.cpp │ └── tictactoewidget.h │ ├── tictactoe ver5 │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── tictactoe ver5.pro │ ├── tictactoewidget.cpp │ └── tictactoewidget.h │ ├── tictactoe ver6 │ ├── configurationdialog.cpp │ ├── configurationdialog.h │ ├── configurationdialog.ui │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── tictactoe ver6.pro │ ├── tictactoewidget.cpp │ └── tictactoewidget.h │ └── tictactoe ver7 │ ├── configurationdialog.cpp │ ├── configurationdialog.h │ ├── configurationdialog.ui │ ├── icons │ ├── application-exit.png │ └── newgame.png │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── resources.qrc │ ├── tictactoe ver7.pro │ ├── tictactoewidget.cpp │ └── tictactoewidget.h ├── Chapter04 └── Graphics View │ ├── 1. First demo │ ├── graphics_view_demo.pro │ └── main.cpp │ ├── 2. Transformation origin │ ├── graphics_view_demo.pro │ └── main.cpp │ ├── 3. Custom rectangle │ ├── graphics_view_demo.pro │ └── main.cpp │ ├── 4. Custom rectangle with antialiasing │ ├── graphics_view_demo.pro │ └── main.cpp │ ├── 5. Painter path │ ├── graphics_view_demo.pro │ └── main.cpp │ ├── 6. Z values │ ├── graphics_view_demo.pro │ └── main.cpp │ ├── 7. Custom rectangle with numbers │ ├── graphics_view_demo.pro │ └── main.cpp │ ├── 8. Custom rectangle with numbers - alternative │ ├── graphics_view_demo.pro │ └── main.cpp │ └── 9. Sine graph │ ├── main.cpp │ ├── sine_graph.pro │ ├── sineitem.cpp │ ├── sineitem.h │ ├── view.cpp │ └── view.h ├── Chapter05 └── Animations in Graphics View │ └── jrgame │ ├── backgrounditem.cpp │ ├── backgrounditem.h │ ├── bushes.svg │ ├── coin.cpp │ ├── coin.h │ ├── elephant.png │ ├── elephant.svg │ ├── grass.png │ ├── ground.png │ ├── ground.svg │ ├── jrgame.pro │ ├── jrgame.qrc │ ├── main.cpp │ ├── myscene.cpp │ ├── myscene.h │ ├── player.cpp │ ├── player.h │ ├── sky.png │ ├── sky.svg │ ├── trees.png │ └── trees.svg ├── Chapter06 └── Qt Core Essentials │ ├── caesarcipherdevice │ ├── caesarcipherdevice.cpp │ ├── caesarcipherdevice.h │ ├── caesarcipherdevice.pro │ └── main.cpp │ ├── json_serializer │ ├── main.cpp │ ├── playerinfo.cpp │ ├── playerinfo.h │ ├── playerinfojson.cpp │ ├── playerinfojson.h │ └── serializer.pro │ ├── regularexpression │ ├── main.cpp │ └── regularexpression.pro │ ├── serialization │ ├── main.cpp │ ├── player.cpp │ ├── player.h │ └── serialization.pro │ └── xmlreader │ ├── main.cpp │ ├── playerinfo.cpp │ ├── playerinfo.h │ ├── playerinfo.xml │ ├── playerinforeader.cpp │ ├── playerinforeader.h │ ├── resources.qrc │ └── xmlreader.pro ├── Chapter07 └── Networking │ ├── FileDownload │ ├── FileDownload.pro │ ├── filedownload.cpp │ ├── filedownload.h │ └── main.cpp │ ├── Navigation │ ├── Navigation.pro │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ └── mainwindow.ui │ ├── ReplyFinished │ ├── ReplyFinished.pro │ ├── main.cpp │ ├── widget.cpp │ ├── widget.h │ └── widget.ui │ ├── TcpClient │ ├── TcpClient.pro │ ├── main.cpp │ ├── tcpclient.cpp │ ├── tcpclient.h │ └── tcpclient.ui │ └── TcpServer │ ├── TcpServer.pro │ ├── main.cpp │ ├── tcpserver.cpp │ ├── tcpserver.h │ └── tcpserver.ui ├── Chapter08 └── Custom Widgets │ ├── chess │ ├── ver1 │ │ ├── chess_ver1.pro │ │ ├── chessalgorithm.cpp │ │ ├── chessalgorithm.h │ │ ├── chessboard.cpp │ │ ├── chessboard.h │ │ ├── chessview.cpp │ │ ├── chessview.h │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ └── mainwindow.ui │ ├── ver2 │ │ ├── chess_ver2.pro │ │ ├── chessalgorithm.cpp │ │ ├── chessalgorithm.h │ │ ├── chessboard.cpp │ │ ├── chessboard.h │ │ ├── chessview.cpp │ │ ├── chessview.h │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ └── mainwindow.ui │ ├── ver3 │ │ ├── chess_ver3.pro │ │ ├── chessalgorithm.cpp │ │ ├── chessalgorithm.h │ │ ├── chessboard.cpp │ │ ├── chessboard.h │ │ ├── chessview.cpp │ │ ├── chessview.h │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ └── mainwindow.ui │ ├── ver4 │ │ ├── chess_ver4.pro │ │ ├── chessalgorithm.cpp │ │ ├── chessalgorithm.h │ │ ├── chessboard.cpp │ │ ├── chessboard.h │ │ ├── chessview.cpp │ │ ├── chessview.h │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ ├── mainwindow.ui │ │ ├── pieces.qrc │ │ └── pieces │ │ │ ├── Chess_bdt45.svg │ │ │ ├── Chess_blt45.svg │ │ │ ├── Chess_kdt45.svg │ │ │ ├── Chess_klt45.svg │ │ │ ├── Chess_ndt45.svg │ │ │ ├── Chess_nlt45.svg │ │ │ ├── Chess_pdt45.svg │ │ │ ├── Chess_plt45.svg │ │ │ ├── Chess_qdt45.svg │ │ │ ├── Chess_qlt45.svg │ │ │ ├── Chess_rdt45.svg │ │ │ ├── Chess_rlt45.svg │ │ │ └── LICENSE.txt │ ├── ver5 │ │ ├── chess_ver5.pro │ │ ├── chessalgorithm.cpp │ │ ├── chessalgorithm.h │ │ ├── chessboard.cpp │ │ ├── chessboard.h │ │ ├── chessview.cpp │ │ ├── chessview.h │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ ├── mainwindow.ui │ │ ├── pieces.qrc │ │ └── pieces │ │ │ ├── Chess_bdt45.svg │ │ │ ├── Chess_blt45.svg │ │ │ ├── Chess_kdt45.svg │ │ │ ├── Chess_klt45.svg │ │ │ ├── Chess_ndt45.svg │ │ │ ├── Chess_nlt45.svg │ │ │ ├── Chess_pdt45.svg │ │ │ ├── Chess_plt45.svg │ │ │ ├── Chess_qdt45.svg │ │ │ ├── Chess_qlt45.svg │ │ │ ├── Chess_rdt45.svg │ │ │ ├── Chess_rlt45.svg │ │ │ └── LICENSE.txt │ └── ver6 │ │ ├── chess_ver6.pro │ │ ├── chessalgorithm.cpp │ │ ├── chessalgorithm.h │ │ ├── chessboard.cpp │ │ ├── chessboard.h │ │ ├── chessview.cpp │ │ ├── chessview.h │ │ ├── foxandhounds.cpp │ │ ├── foxandhounds.h │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ ├── mainwindow.ui │ │ ├── pieces.qrc │ │ └── pieces │ │ ├── Chess_bdt45.svg │ │ ├── Chess_blt45.svg │ │ ├── Chess_kdt45.svg │ │ ├── Chess_klt45.svg │ │ ├── Chess_ndt45.svg │ │ ├── Chess_nlt45.svg │ │ ├── Chess_pdt45.svg │ │ ├── Chess_plt45.svg │ │ ├── Chess_qdt45.svg │ │ ├── Chess_qlt45.svg │ │ ├── Chess_rdt45.svg │ │ ├── Chess_rlt45.svg │ │ └── LICENSE.txt │ └── painting │ ├── ver1 │ ├── customwidget_ver1.pro │ ├── main.cpp │ ├── widget.cpp │ └── widget.h │ ├── ver2 │ ├── customwidget_ver2.pro │ ├── main.cpp │ ├── widget.cpp │ └── widget.h │ ├── ver3 │ ├── customwidget_ver3.pro │ ├── main.cpp │ ├── widget.cpp │ └── widget.h │ ├── ver4 │ ├── customwidget_ver4.pro │ ├── main.cpp │ ├── widget.cpp │ └── widget.h │ └── ver5 │ ├── customwidget_ver5.pro │ ├── main.cpp │ ├── widget.cpp │ └── widget.h ├── Chapter09 └── OpenGL and Vulkan in Qt applications │ ├── 1. triangle │ ├── main.cpp │ ├── simpleglwindow.cpp │ ├── simpleglwindow.h │ └── triangle.pro │ ├── 2. scene │ ├── abstractglscene.cpp │ ├── abstractglscene.h │ ├── main.cpp │ ├── scene.pro │ ├── sceneglwindow.cpp │ └── sceneglwindow.h │ ├── 3. cube │ ├── abstractglscene.cpp │ ├── abstractglscene.h │ ├── cube.pro │ ├── cubeglscene.cpp │ ├── cubeglscene.h │ ├── main.cpp │ ├── sceneglwindow.cpp │ ├── sceneglwindow.h │ ├── texture.jpg │ └── texture.qrc │ ├── 3a. animated cube │ ├── abstractglscene.cpp │ ├── abstractglscene.h │ ├── animated_cube.pro │ ├── cubeglscene.cpp │ ├── cubeglscene.h │ ├── main.cpp │ ├── sceneglwindow.cpp │ ├── sceneglwindow.h │ ├── texture.jpg │ └── texture.qrc │ ├── 4. shaders │ ├── abstractglscene.cpp │ ├── abstractglscene.h │ ├── main.cpp │ ├── monkey.ply │ ├── phong.frag │ ├── phong.vert │ ├── plyreader.cpp │ ├── plyreader.h │ ├── resources.qrc │ ├── sceneglwindow.cpp │ ├── sceneglwindow.h │ ├── shaderglscene.cpp │ ├── shaderglscene.h │ └── shaders.pro │ ├── 4a. shaders_and_buffers │ ├── abstractglscene.cpp │ ├── abstractglscene.h │ ├── main.cpp │ ├── monkey.ply │ ├── phong.frag │ ├── phong.vert │ ├── plyreader.cpp │ ├── plyreader.h │ ├── resources.qrc │ ├── sceneglwindow.cpp │ ├── sceneglwindow.h │ ├── shaderglscene.cpp │ ├── shaderglscene.h │ └── shaders_and_buffers.pro │ ├── 5. vulkan_background │ ├── main.cpp │ ├── myrenderer.cpp │ ├── myrenderer.h │ ├── mywindow.cpp │ ├── mywindow.h │ └── vulkan_background.pro │ └── 6. opengl with widgets │ ├── abstractglscene.cpp │ ├── abstractglscene.h │ ├── cubeglscene.cpp │ ├── cubeglscene.h │ ├── main.cpp │ ├── opengl_with_widgets.pro │ ├── sceneglwindow.cpp │ ├── sceneglwindow.h │ ├── texture.jpg │ └── texture.qrc ├── Chapter10 └── Scripting │ ├── codeeditor │ ├── codeeditor.pro │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ └── mainwindow.ui │ ├── qtpython │ ├── qtpython_ver1 │ │ ├── main.cpp │ │ ├── qtpython.cpp │ │ ├── qtpython.h │ │ └── qtpython.pro │ ├── qtpython_ver2 │ │ ├── main.cpp │ │ ├── qtpython.cpp │ │ ├── qtpython.h │ │ ├── qtpython.pro │ │ ├── qtpythonvalue.cpp │ │ └── qtpythonvalue.h │ └── qtpython_ver3 │ │ ├── main.cpp │ │ ├── qtpython.cpp │ │ ├── qtpython.h │ │ ├── qtpython.pro │ │ ├── qtpythonvalue.cpp │ │ └── qtpythonvalue.h │ ├── scriptable_button │ ├── main.cpp │ └── scriptable_button.pro │ └── scripted_game │ ├── entity.cpp │ ├── entity.h │ ├── entityproxy.cpp │ ├── entityproxy.h │ ├── main.cpp │ ├── resources.qrc │ ├── scene.cpp │ ├── scene.h │ ├── sceneproxy.cpp │ ├── sceneproxy.h │ ├── scripted_game.pro │ └── scripts │ ├── 1.js │ └── 2.js ├── Chapter11 └── Introduction to Qt Quick │ └── calculator │ ├── ver1 │ ├── calculator_ver1.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── ver2 │ ├── Calculator.qml │ ├── CalculatorForm.ui.qml │ ├── calculator_ver2.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── ver3 │ ├── Calculator.qml │ ├── CalculatorForm.ui.qml │ ├── advancedcalculator.cpp │ ├── advancedcalculator.h │ ├── calculator_ver3.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ └── ver4 │ ├── Calculator.qml │ ├── CalculatorForm.ui.qml │ ├── advancedcalculator.cpp │ ├── advancedcalculator.h │ ├── calculator_ver4.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc ├── Chapter12 └── Customization in Qt Quick │ ├── canvas │ ├── canvas.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── clock │ ├── Clock.qml │ ├── Needle.qml │ ├── clock.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── custom_button │ ├── Button.qml │ ├── custom_button.pro │ ├── edit-undo.png │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── dashboard │ ├── Label.qml │ ├── Needle.qml │ ├── carinfo.cpp │ ├── carinfo.h │ ├── carinfoengine.cpp │ ├── carinfoengine.h │ ├── carinfoproxy.cpp │ ├── carinfoproxy.h │ ├── dashboard.png │ ├── dashboard.pro │ ├── form.ui │ ├── main.cpp │ ├── main.qml │ └── resources.qrc │ ├── drag │ ├── drag.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── load_component │ ├── Circle.qml │ ├── load_component.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── pinch │ ├── main.cpp │ ├── main.qml │ ├── pinch.pro │ ├── qml.qrc │ └── wilanow.jpg │ ├── positioning │ ├── main.cpp │ ├── main.qml │ ├── positioning.pro │ └── qml.qrc │ └── tilt_sensor │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── tilt_sensor.pro ├── Chapter13 └── Animations in Qt Quick games │ ├── actiongame │ ├── actiongame_ver01 │ │ ├── actiongame_ver01.qmlproject │ │ ├── images │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver02 │ │ ├── actiongame_ver02.qmlproject │ │ ├── images │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver03 │ │ ├── actiongame_ver03.qmlproject │ │ ├── images │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver04 │ │ ├── actiongame_ver04.qmlproject │ │ ├── images │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver05 │ │ ├── actiongame_ver05.qmlproject │ │ ├── images │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver06 │ │ ├── actiongame_ver06.qmlproject │ │ ├── images │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver07 │ │ ├── Player.qml │ │ ├── actiongame_ver07.qmlproject │ │ ├── images │ │ │ ├── elephant.png │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver08 │ │ ├── Player.qml │ │ ├── actiongame_ver08.qmlproject │ │ ├── images │ │ │ ├── elephant.png │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver09 │ │ ├── Coin.qml │ │ ├── Player.qml │ │ ├── actiongame_ver09.qmlproject │ │ ├── images │ │ │ ├── elephant.png │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver10 │ │ ├── Coin.qml │ │ ├── Player.qml │ │ ├── actiongame_ver10.qmlproject │ │ ├── images │ │ │ ├── elephant.png │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ ├── trees.png │ │ │ ├── walking_1.png │ │ │ ├── walking_2.png │ │ │ ├── walking_3.png │ │ │ ├── walking_4.png │ │ │ ├── walking_5.png │ │ │ ├── walking_6.png │ │ │ └── walking_7.png │ │ └── main.qml │ ├── actiongame_ver11 │ │ ├── Coin.qml │ │ ├── Player.qml │ │ ├── actiongame_ver11.qmlproject │ │ ├── images │ │ │ ├── elephant.png │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ ├── sprite.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver12 │ │ ├── Coin.qml │ │ ├── Player.qml │ │ ├── actiongame_ver12.qmlproject │ │ ├── images │ │ │ ├── elephant.png │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ ├── sprite.png │ │ │ └── trees.png │ │ └── main.qml │ ├── actiongame_ver13 │ │ ├── Coin.qml │ │ ├── ParallaxLayer.qml │ │ ├── ParallaxScene.qml │ │ ├── Player.qml │ │ ├── actiongame_ver13.qmlproject │ │ ├── images │ │ │ ├── elephant.png │ │ │ ├── grass.png │ │ │ ├── sky.png │ │ │ ├── sprite.png │ │ │ └── trees.png │ │ └── main.qml │ └── actiongame_ver14 │ │ ├── Coin.qml │ │ ├── Coin.qmlc │ │ ├── ParallaxLayer.qml │ │ ├── ParallaxLayer.qmlc │ │ ├── ParallaxScene.qml │ │ ├── ParallaxScene.qmlc │ │ ├── Player.qml │ │ ├── Player.qmlc │ │ ├── actiongame_ver14.qmlproject │ │ ├── coins.js │ │ ├── coins.jsc │ │ ├── collisions.js │ │ ├── collisions.jsc │ │ ├── images │ │ ├── elephant.png │ │ ├── grass.png │ │ ├── sky.png │ │ ├── sprite.png │ │ └── trees.png │ │ ├── main.qml │ │ └── main.qmlc │ └── dashboard │ ├── Label.qml │ ├── Needle.qml │ ├── carinfo.cpp │ ├── carinfo.h │ ├── carinfoengine.cpp │ ├── carinfoengine.h │ ├── carinfoproxy.cpp │ ├── carinfoproxy.h │ ├── dashboard.png │ ├── dashboard.pro │ ├── form.ui │ ├── main.cpp │ ├── main.qml │ └── resources.qrc ├── Chapter14 └── Advanced visual effects in Qt Quick │ ├── actiongame ver15 │ ├── Coin.qml │ ├── Coin.qmlc │ ├── ParallaxLayer.qml │ ├── ParallaxLayer.qmlc │ ├── ParallaxScene.qml │ ├── ParallaxScene.qmlc │ ├── Player.qml │ ├── Player.qmlc │ ├── actiongame.qmlproject │ ├── coins.js │ ├── coins.jsc │ ├── collisions.js │ ├── collisions.jsc │ ├── images │ │ ├── elephant.png │ │ ├── grass.png │ │ ├── particle.png │ │ ├── sky.png │ │ ├── sprite.png │ │ └── trees.png │ ├── main.qml │ └── main.qmlc │ ├── flickable │ ├── UI.qml │ ├── flickable.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── glow │ ├── Badge.qml │ ├── glow.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── heartbeat │ ├── HeartBeat.qml │ ├── heartbeat.pro │ ├── main.cpp │ ├── main.qml │ └── qml.qrc │ ├── outlinedtext │ ├── main.cpp │ ├── main.qml │ ├── outlinedtext.pro │ ├── outlinetextitem.cpp │ ├── outlinetextitem.h │ ├── outlinetextitemborder.cpp │ ├── outlinetextitemborder.h │ └── resources.qrc │ ├── particle_system │ ├── main.cpp │ ├── main.qml │ ├── particle_system.pro │ ├── qml.qrc │ ├── star.png │ └── star_white.png │ ├── regularpolygon │ ├── main.cpp │ ├── main.qml │ ├── regularpolygon.cpp │ ├── regularpolygon.h │ ├── regularpolygon.pro │ └── resources.qrc │ ├── scaled │ ├── UI.qml │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── scaled.pro │ └── scaled2 │ ├── UI.qml │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── scaled2.pro ├── Chapter15 └── 3D graphics with Qt │ ├── cpp3d │ ├── cpp3d.pro │ └── main.cpp │ ├── hanoi │ ├── Disk.qml │ ├── DiskAnimation.qml │ ├── Rod.qml │ ├── Scene.qml │ ├── hanoi.pro │ ├── main.cpp │ ├── main.qml │ ├── obj │ │ ├── disk.blend │ │ ├── disk0.obj │ │ ├── disk1.obj │ │ ├── disk2.obj │ │ ├── disk3.obj │ │ ├── disk4.obj │ │ ├── disk5.obj │ │ ├── disk6.obj │ │ └── disk7.obj │ └── qml.qrc │ ├── scene2d │ ├── main.cpp │ ├── main.qml │ ├── main.qmlc │ ├── qml.qrc │ └── scene2d.pro │ └── scene3d │ ├── My3DScene.qml │ ├── main.cpp │ ├── main.qml │ ├── main.qmlc │ ├── qml.qrc │ └── scene3d.pro ├── Chapter16 └── Miscellaneous and Advanced Concepts │ ├── qml_sound │ ├── .gitignore │ ├── example.ogg │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── qml_sound.pro │ ├── record_and_play_sound │ ├── main.cpp │ ├── record_and_play_sound.pro │ ├── recordandplaysound.cpp │ ├── recordandplaysound.h │ └── recordandplaysound.ui │ ├── shared_memory │ ├── client │ │ ├── .gitignore │ │ ├── main.cpp │ │ └── shared_memory_client.pro │ └── server │ │ ├── gameserver.cpp │ │ ├── gameserver.h │ │ ├── gamestats.h │ │ ├── main.cpp │ │ └── shared_memory_server.pro │ ├── threading │ ├── main.cpp │ ├── threading.pro │ ├── widget.cpp │ ├── widget.h │ ├── widget.ui │ ├── worker.cpp │ └── worker.h │ ├── translations │ ├── main.cpp │ ├── resources.qrc │ ├── translations.pro │ ├── translations │ │ ├── myapp_de.qm │ │ ├── myapp_de.ts │ │ ├── myapp_ru.qm │ │ └── myapp_ru.ts │ ├── widget.cpp │ ├── widget.h │ └── widget.ui │ ├── unit_test │ ├── tst_firsttest.cpp │ └── unit_test.pro │ └── websockets_qml │ ├── client │ ├── .gitignore │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── websockets_client.pro │ └── server │ ├── .gitignore │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── websockets_server.pro ├── LICENSE └── README.md /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver1/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver1/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MainWindow::~MainWindow() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver1/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver2/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver2/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | 5 | MainWindow::MainWindow(QWidget *parent) : 6 | QMainWindow(parent), 7 | ui(new Ui::MainWindow) 8 | { 9 | ui->setupUi(this); 10 | connect(ui->startNewGame, &QPushButton::clicked, 11 | this, &MainWindow::startNewGame); 12 | } 13 | 14 | MainWindow::~MainWindow() 15 | { 16 | delete ui; 17 | } 18 | 19 | void MainWindow::startNewGame() 20 | { 21 | ui->player1Name->setText(tr("Alice")); 22 | ui->player2Name->setText(tr("Bob")); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver2/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void startNewGame(); 20 | 21 | private: 22 | Ui::MainWindow *ui; 23 | }; 24 | 25 | #endif // MAINWINDOW_H 26 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver3/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver3/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | 5 | MainWindow::MainWindow(QWidget *parent) : 6 | QMainWindow(parent), 7 | ui(new Ui::MainWindow) 8 | { 9 | ui->setupUi(this); 10 | connect(ui->startNewGame, &QPushButton::clicked, 11 | this, &MainWindow::startNewGame);} 12 | 13 | MainWindow::~MainWindow() 14 | { 15 | delete ui; 16 | } 17 | 18 | void MainWindow::startNewGame() 19 | { 20 | ui->player1Name->setText(tr("Alice")); 21 | ui->player2Name->setText(tr("Bob")); 22 | } 23 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver3/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void startNewGame(); 20 | 21 | private: 22 | Ui::MainWindow *ui; 23 | }; 24 | 25 | #endif // MAINWINDOW_H 26 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver3/tictactoewidget.cpp: -------------------------------------------------------------------------------- 1 | #include "tictactoewidget.h" 2 | #include 3 | 4 | TicTacToeWidget::TicTacToeWidget(QWidget *parent) : QWidget(parent) 5 | { 6 | QGridLayout *gridLayout = new QGridLayout(this); 7 | for(int row = 0; row < 3; ++row) { 8 | for(int column = 0; column < 3; ++column) { 9 | QPushButton *button = new QPushButton(" "); 10 | gridLayout->addWidget(button, row, column); 11 | m_board.append(button); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver3/tictactoewidget.h: -------------------------------------------------------------------------------- 1 | #ifndef TICTACTOEWIDGET_H 2 | #define TICTACTOEWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | class TicTacToeWidget : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit TicTacToeWidget(QWidget *parent = nullptr); 12 | 13 | signals: 14 | 15 | public slots: 16 | 17 | private: 18 | QVector m_board; 19 | }; 20 | 21 | #endif // TICTACTOEWIDGET_H 22 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver4/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver4/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | 5 | MainWindow::MainWindow(QWidget *parent) : 6 | QMainWindow(parent), 7 | ui(new Ui::MainWindow) 8 | { 9 | ui->setupUi(this); 10 | connect(ui->startNewGame, &QPushButton::clicked, 11 | this, &MainWindow::startNewGame);} 12 | 13 | MainWindow::~MainWindow() 14 | { 15 | delete ui; 16 | } 17 | 18 | void MainWindow::startNewGame() 19 | { 20 | ui->player1Name->setText(tr("Alice")); 21 | ui->player2Name->setText(tr("Bob")); 22 | ui->gameBoard->initNewGame(); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver4/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void startNewGame(); 20 | 21 | private: 22 | Ui::MainWindow *ui; 23 | }; 24 | 25 | #endif // MAINWINDOW_H 26 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver5/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver5/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include "tictactoewidget.h" 7 | 8 | namespace Ui { 9 | class MainWindow; 10 | } 11 | 12 | class MainWindow : public QMainWindow 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | 20 | private slots: 21 | void startNewGame(); 22 | void updateNameLabels(); 23 | void handleGameOver(TicTacToeWidget::Player winner); 24 | private: 25 | Ui::MainWindow *ui; 26 | static void setLabelBold(QLabel *label, bool isBold); 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver6/configurationdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGURATIONDIALOG_H 2 | #define CONFIGURATIONDIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class ConfigurationDialog; 8 | } 9 | 10 | class ConfigurationDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit ConfigurationDialog(QWidget *parent = nullptr); 16 | ~ConfigurationDialog(); 17 | 18 | void setPlayer1Name(const QString &p1name); 19 | void setPlayer2Name(const QString &p2name); 20 | QString player1Name() const; 21 | QString player2Name() const; 22 | 23 | private: 24 | Ui::ConfigurationDialog *ui; 25 | 26 | private slots: 27 | void updateOKButtonState(); 28 | }; 29 | 30 | #endif // CONFIGURATIONDIALOG_H 31 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver6/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver6/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include "tictactoewidget.h" 7 | 8 | namespace Ui { 9 | class MainWindow; 10 | } 11 | 12 | class MainWindow : public QMainWindow 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | 20 | private slots: 21 | void startNewGame(); 22 | void updateNameLabels(); 23 | void handleGameOver(TicTacToeWidget::Player winner); 24 | private: 25 | Ui::MainWindow *ui; 26 | static void setLabelBold(QLabel *label, bool isBold); 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/configurationdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGURATIONDIALOG_H 2 | #define CONFIGURATIONDIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class ConfigurationDialog; 8 | } 9 | 10 | class ConfigurationDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit ConfigurationDialog(QWidget *parent = nullptr); 16 | ~ConfigurationDialog(); 17 | 18 | void setPlayer1Name(const QString &p1name); 19 | void setPlayer2Name(const QString &p2name); 20 | QString player1Name() const; 21 | QString player2Name() const; 22 | 23 | private: 24 | Ui::ConfigurationDialog *ui; 25 | 26 | private slots: 27 | void updateOKButtonState(); 28 | }; 29 | 30 | #endif // CONFIGURATIONDIALOG_H 31 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/icons/application-exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/icons/application-exit.png -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/icons/newgame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/icons/newgame.png -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include "tictactoewidget.h" 7 | 8 | namespace Ui { 9 | class MainWindow; 10 | } 11 | 12 | class MainWindow : public QMainWindow 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | 20 | private slots: 21 | void updateNameLabels(); 22 | void handleGameOver(TicTacToeWidget::Player winner); 23 | void startNewGame(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | static void setLabelBold(QLabel *label, bool isBold); 28 | }; 29 | 30 | #endif // MAINWINDOW_H 31 | -------------------------------------------------------------------------------- /Chapter03/Qt GUI Programming/tictactoe/tictactoe ver7/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icons/application-exit.png 4 | icons/newgame.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/Graphics View/9. Sine graph/main.cpp: -------------------------------------------------------------------------------- 1 | #include "view.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | View w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter04/Graphics View/9. Sine graph/sineitem.h: -------------------------------------------------------------------------------- 1 | #ifndef SINEITEM_H 2 | #define SINEITEM_H 3 | 4 | #include 5 | 6 | 7 | class SineItem : public QGraphicsItem 8 | { 9 | public: 10 | SineItem(); 11 | float maxX(); 12 | void setMaxX(float value); 13 | 14 | // QGraphicsItem interface 15 | public: 16 | QRectF boundingRect() const; 17 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 18 | void mousePressEvent(QGraphicsSceneMouseEvent *event); 19 | 20 | 21 | private: 22 | float m_maxX; 23 | }; 24 | 25 | #endif // SINEITEM_H 26 | -------------------------------------------------------------------------------- /Chapter04/Graphics View/9. Sine graph/view.h: -------------------------------------------------------------------------------- 1 | #ifndef VIEW_H 2 | #define VIEW_H 3 | 4 | #include 5 | 6 | class View : public QGraphicsView 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | View(QWidget *parent = 0); 12 | ~View(); 13 | 14 | // QWidget interface 15 | protected: 16 | void wheelEvent(QWheelEvent *event); 17 | void mousePressEvent(QMouseEvent *event); 18 | }; 19 | 20 | #endif // VIEW_H 21 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/backgrounditem.cpp: -------------------------------------------------------------------------------- 1 | #include "backgrounditem.h" 2 | 3 | BackgroundItem::BackgroundItem(const QPixmap &pixmap, QGraphicsItem * parent) 4 | : QGraphicsPixmapItem(pixmap, parent) 5 | { 6 | } 7 | 8 | QPainterPath BackgroundItem::shape() const 9 | { 10 | return QPainterPath(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/backgrounditem.h: -------------------------------------------------------------------------------- 1 | #ifndef BACKGROUNDITEM_H 2 | #define BACKGROUNDITEM_H 3 | 4 | #include 5 | 6 | class BackgroundItem : public QGraphicsPixmapItem 7 | { 8 | public: 9 | explicit BackgroundItem(const QPixmap &pixmap, QGraphicsItem *parent = 0); 10 | 11 | public: 12 | virtual QPainterPath shape() const; 13 | }; 14 | 15 | #endif // BACKGROUNDITEM_H 16 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/coin.h: -------------------------------------------------------------------------------- 1 | #ifndef COIN_H 2 | #define COIN_H 3 | 4 | #include 5 | #include 6 | 7 | class Coin : public QObject, public QGraphicsEllipseItem 8 | { 9 | Q_OBJECT 10 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) 11 | Q_PROPERTY(QRectF rect READ rect WRITE setRect) 12 | 13 | public: 14 | explicit Coin(QGraphicsItem *parent = 0); 15 | 16 | enum { Type = UserType + 1 }; 17 | int type() const; 18 | 19 | void explode(); 20 | 21 | private: 22 | bool m_explosion; 23 | }; 24 | 25 | #endif // COIN_H 26 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter05/Animations in Graphics View/jrgame/elephant.png -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter05/Animations in Graphics View/jrgame/grass.png -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter05/Animations in Graphics View/jrgame/ground.png -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/jrgame.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2013-10-10T19:50:28 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui widgets gamepad 8 | 9 | TARGET = jrgame 10 | TEMPLATE = app 11 | 12 | 13 | SOURCES += main.cpp\ 14 | myscene.cpp \ 15 | player.cpp \ 16 | coin.cpp \ 17 | backgrounditem.cpp 18 | 19 | HEADERS += myscene.h \ 20 | player.h \ 21 | coin.h \ 22 | backgrounditem.h 23 | 24 | RESOURCES += \ 25 | jrgame.qrc 26 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/jrgame.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | sky.png 4 | grass.png 5 | trees.png 6 | ground.png 7 | elephant.png 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "myscene.h" 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QApplication a(argc, argv); 10 | qsrand(QDateTime::currentMSecsSinceEpoch()); 11 | 12 | MyScene scene; 13 | QGraphicsView view; 14 | view.setRenderHint(QPainter::Antialiasing); 15 | view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 16 | view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 17 | view.setScene(&scene); 18 | view.setFixedSize(scene.sceneRect().size().toSize()); 19 | view.show(); 20 | 21 | return a.exec(); 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/player.h: -------------------------------------------------------------------------------- 1 | #ifndef PLAYER_H 2 | #define PLAYER_H 3 | 4 | #include 5 | 6 | class Player : public QGraphicsPixmapItem 7 | { 8 | public: 9 | explicit Player(QGraphicsItem *parent = 0); 10 | int direction() const; 11 | void setDirection(int direction); 12 | 13 | private: 14 | int m_direction; 15 | }; 16 | 17 | #endif // PLAYER_H 18 | -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter05/Animations in Graphics View/jrgame/sky.png -------------------------------------------------------------------------------- /Chapter05/Animations in Graphics View/jrgame/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter05/Animations in Graphics View/jrgame/trees.png -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/caesarcipherdevice/caesarcipherdevice.pro: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | caesarcipherdevice.h 3 | 4 | SOURCES += \ 5 | caesarcipherdevice.cpp \ 6 | main.cpp 7 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/caesarcipherdevice/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "caesarcipherdevice.h" 6 | 7 | int main(int, char **) { 8 | QByteArray ba = "plaintext"; 9 | QBuffer buf; 10 | buf.open(QIODevice::WriteOnly); 11 | CaesarCipherDevice encrypt; 12 | encrypt.setKey(3); 13 | encrypt.setBaseDevice(&buf); 14 | encrypt.open(buf.openMode()); 15 | encrypt.write(ba); 16 | qDebug() << buf.data(); 17 | 18 | CaesarCipherDevice decrypt; 19 | decrypt.setKey(3); 20 | decrypt.setBaseDevice(&buf); 21 | buf.open(QIODevice::ReadOnly); 22 | decrypt.open(buf.openMode()); 23 | qDebug() << decrypt.readAll(); 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/json_serializer/serializer.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = jsonserializer 3 | DEPENDPATH += . 4 | INCLUDEPATH += . 5 | 6 | HEADERS += playerinfo.h \ 7 | playerinfojson.h 8 | 9 | SOURCES += \ 10 | playerinfo.cpp \ 11 | playerinfojson.cpp \ 12 | main.cpp 13 | 14 | CONFIG += c++11 15 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/regularexpression/regularexpression.pro: -------------------------------------------------------------------------------- 1 | QT = core gui 2 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 3 | 4 | TARGET = regularexpression 5 | TEMPLATE = app 6 | 7 | SOURCES += \ 8 | main.cpp 9 | CONFIG += c++11 10 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/serialization/player.cpp: -------------------------------------------------------------------------------- 1 | #include "player.h" 2 | 3 | QDataStream& operator<<(QDataStream &stream, const Player &p) { 4 | stream << p.name; 5 | stream << p.experience; 6 | stream << p.position; 7 | stream << p.direction; 8 | return stream; 9 | } 10 | 11 | QDataStream& operator>>(QDataStream &stream, Player &p) { 12 | stream >> p.name; 13 | stream >> p.experience; 14 | stream >> p.position; 15 | stream >> p.direction; 16 | return stream; 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/serialization/player.h: -------------------------------------------------------------------------------- 1 | #ifndef PLAYER_H 2 | #define PLAYER_H 3 | 4 | #include 5 | #include 6 | 7 | struct Player { 8 | QString name; 9 | qint64 experience; 10 | QPoint position; 11 | QChar direction; 12 | }; 13 | 14 | QDataStream& operator<<(QDataStream &stream, const Player &p); 15 | QDataStream& operator>>(QDataStream &stream, Player &p); 16 | 17 | #endif // PLAYER_H 18 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/serialization/serialization.pro: -------------------------------------------------------------------------------- 1 | SOURCES = main.cpp \ 2 | player.cpp 3 | QT = core 4 | 5 | HEADERS += \ 6 | player.h 7 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/xmlreader/playerinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "playerinfo.h" 2 | #include 3 | 4 | InventoryItem::Type InventoryItem::typeByName(const QStringRef &r) { 5 | QMetaEnum metaEnum = QMetaEnum::fromType(); 6 | QByteArray latin1 = r.toLatin1(); 7 | int result = metaEnum.keyToValue(latin1.constData()); 8 | return static_cast(result); 9 | } 10 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/xmlreader/playerinfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Gandalf 4 | mithrandir 5 | 6 | 7 | Long sword 8 | 9 | 10 | Chain mail 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/xmlreader/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | playerinfo.xml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter06/Qt Core Essentials/xmlreader/xmlreader.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = xmlreader 3 | DEPENDPATH += . 4 | INCLUDEPATH += . 5 | QT = core 6 | 7 | # Input 8 | HEADERS += \ 9 | playerinforeader.h \ 10 | playerinfo.h 11 | 12 | SOURCES += \ 13 | playerinforeader.cpp \ 14 | main.cpp \ 15 | playerinfo.cpp 16 | 17 | RESOURCES += \ 18 | resources.qrc 19 | -------------------------------------------------------------------------------- /Chapter07/Networking/FileDownload/FileDownload.pro: -------------------------------------------------------------------------------- 1 | QT += core gui widgets network 2 | 3 | TARGET = FileDownload 4 | TEMPLATE = app 5 | 6 | SOURCES += main.cpp\ 7 | filedownload.cpp 8 | 9 | HEADERS += filedownload.h 10 | -------------------------------------------------------------------------------- /Chapter07/Networking/FileDownload/filedownload.h: -------------------------------------------------------------------------------- 1 | #ifndef FILEDOWNLOAD_H 2 | #define FILEDOWNLOAD_H 3 | 4 | #include 5 | 6 | class QNetworkAccessManager; 7 | class QPlainTextEdit; 8 | class QNetworkReply; 9 | 10 | class FileDownload : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit FileDownload(QWidget *parent = 0); 16 | virtual ~FileDownload(); 17 | 18 | private slots: 19 | void startDownload(); 20 | void downloadFinished(QNetworkReply *reply); 21 | 22 | private: 23 | QNetworkAccessManager *m_network_manager; 24 | QPlainTextEdit *m_edit; 25 | }; 26 | 27 | #endif // FILEDOWNLOAD_H 28 | -------------------------------------------------------------------------------- /Chapter07/Networking/FileDownload/main.cpp: -------------------------------------------------------------------------------- 1 | #include "filedownload.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | FileDownload w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter07/Networking/Navigation/Navigation.pro: -------------------------------------------------------------------------------- 1 | QT += core gui widgets network 2 | 3 | TARGET = Navigation 4 | TEMPLATE = app 5 | 6 | SOURCES += main.cpp\ 7 | mainwindow.cpp 8 | 9 | HEADERS += mainwindow.h 10 | 11 | FORMS += mainwindow.ui 12 | -------------------------------------------------------------------------------- /Chapter07/Networking/Navigation/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter07/Networking/Navigation/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | class QNetworkAccessManager; 7 | class QNetworkReply; 8 | 9 | namespace Ui { 10 | class MainWindow; 11 | } 12 | 13 | class MainWindow : public QMainWindow 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit MainWindow(QWidget *parent = 0); 19 | ~MainWindow(); 20 | 21 | private slots: 22 | void sendRequest(); 23 | void finished(QNetworkReply *reply); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | QNetworkAccessManager *m_network_manager; 28 | QNetworkReply *m_reply; 29 | }; 30 | 31 | #endif // MAINWINDOW_H 32 | -------------------------------------------------------------------------------- /Chapter07/Networking/ReplyFinished/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter07/Networking/ReplyFinished/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class Widget; 10 | } 11 | 12 | class Widget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Widget(QWidget *parent = 0); 18 | ~Widget(); 19 | 20 | private: 21 | Ui::Widget *ui; 22 | QNetworkAccessManager *m_networkManager; 23 | QSignalMapper *m_imageFinishedMapper; 24 | 25 | 26 | private slots: 27 | void load(); 28 | void imageFinished(QObject *replyObject); 29 | }; 30 | 31 | #endif // WIDGET_H 32 | -------------------------------------------------------------------------------- /Chapter07/Networking/TcpClient/TcpClient.pro: -------------------------------------------------------------------------------- 1 | QT += core gui widgets network 2 | 3 | TARGET = TcpClient 4 | TEMPLATE = app 5 | 6 | 7 | SOURCES += main.cpp\ 8 | tcpclient.cpp 9 | 10 | HEADERS += tcpclient.h 11 | 12 | FORMS += tcpclient.ui 13 | -------------------------------------------------------------------------------- /Chapter07/Networking/TcpClient/main.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpclient.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | TcpClient w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter07/Networking/TcpServer/TcpServer.pro: -------------------------------------------------------------------------------- 1 | QT += core gui widgets network 2 | 3 | TARGET = TcpServer 4 | TEMPLATE = app 5 | 6 | 7 | SOURCES += main.cpp\ 8 | tcpserver.cpp 9 | 10 | HEADERS += tcpserver.h 11 | 12 | FORMS += tcpserver.ui 13 | -------------------------------------------------------------------------------- /Chapter07/Networking/TcpServer/main.cpp: -------------------------------------------------------------------------------- 1 | #include "tcpserver.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | TcpServer w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/chess_ver1.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = chess 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp \ 10 | chessboard.cpp \ 11 | chessalgorithm.cpp \ 12 | chessview.cpp \ 13 | mainwindow.cpp 14 | 15 | HEADERS += \ 16 | chessboard.h \ 17 | chessalgorithm.h \ 18 | chessview.h \ 19 | mainwindow.h 20 | 21 | FORMS += \ 22 | mainwindow.ui 23 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/chessalgorithm.cpp: -------------------------------------------------------------------------------- 1 | #include "chessalgorithm.h" 2 | #include "chessboard.h" 3 | 4 | ChessAlgorithm::ChessAlgorithm(QObject *parent) : QObject(parent), m_board(0) 5 | { 6 | 7 | } 8 | 9 | ChessBoard *ChessAlgorithm::board() const 10 | { 11 | return m_board; 12 | } 13 | 14 | void ChessAlgorithm::newGame() 15 | { 16 | setupBoard(); 17 | } 18 | 19 | void ChessAlgorithm::setupBoard() 20 | { 21 | setBoard(new ChessBoard(8,8, this)); 22 | } 23 | 24 | void ChessAlgorithm::setBoard(ChessBoard *board) 25 | { 26 | if(board == m_board) return; 27 | if(m_board) delete m_board; 28 | m_board = board; 29 | emit boardChanged(m_board); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/chessalgorithm.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESSALGORITHM_H 2 | #define CHESSALGORITHM_H 3 | 4 | #include 5 | class ChessBoard; 6 | 7 | class ChessAlgorithm : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ChessAlgorithm(QObject *parent = 0); 12 | ChessBoard* board() const; 13 | 14 | public slots: 15 | virtual void newGame(); 16 | 17 | signals: 18 | void boardChanged(ChessBoard*); 19 | 20 | protected: 21 | virtual void setupBoard(); 22 | void setBoard(ChessBoard *board); 23 | 24 | private: 25 | ChessBoard* m_board; 26 | }; 27 | 28 | #endif // CHESSALGORITHM_H 29 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/chessboard.cpp: -------------------------------------------------------------------------------- 1 | #include "chessboard.h" 2 | 3 | ChessBoard::ChessBoard(int ranks, int columns, QObject *parent) 4 | : QObject(parent), m_ranks(ranks), m_columns(columns) 5 | { 6 | 7 | } 8 | 9 | void ChessBoard::setRanks(int newRanks) 10 | { 11 | if(ranks() == newRanks) return; 12 | m_ranks = newRanks; 13 | emit ranksChanged(m_ranks); 14 | } 15 | 16 | void ChessBoard::setColumns(int newColumns) 17 | { 18 | if(columns() == newColumns) return; 19 | m_columns = newColumns; 20 | emit columnsChanged(m_columns); 21 | } 22 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/chessview.cpp: -------------------------------------------------------------------------------- 1 | #include "chessview.h" 2 | #include "chessboard.h" 3 | 4 | ChessView::ChessView(QWidget *parent) : QWidget(parent) 5 | { 6 | 7 | } 8 | 9 | void ChessView::setBoard(ChessBoard *board) 10 | { 11 | if(m_board == board) return; 12 | 13 | if(m_board) { 14 | // disconnect all signal-slot connections between m_board and this 15 | m_board->disconnect(this); 16 | } 17 | m_board = board; 18 | // connect signals (to be done later) 19 | updateGeometry(); 20 | } 21 | 22 | ChessBoard *ChessView::ChessView::board() const { return m_board; } 23 | 24 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/chessview.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESSVIEW_H 2 | #define CHESSVIEW_H 3 | 4 | #include 5 | #include 6 | 7 | class ChessBoard; 8 | class ChessView : public QWidget 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit ChessView(QWidget *parent = 0); 13 | void setBoard(ChessBoard*); 14 | ChessBoard* board() const; 15 | 16 | private: 17 | QPointer m_board; 18 | }; 19 | 20 | #endif // CHESSVIEW_H 21 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow mw; 8 | mw.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | MainWindow::MainWindow(QWidget *parent) 4 | : QMainWindow(parent), ui(new Ui::MainWindow) 5 | { 6 | ui->setupUi(this); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "ui_mainwindow.h" 6 | 7 | class ChessView; 8 | class ChessAlgorithm; 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MainWindow(QWidget *parent = 0); 14 | 15 | protected: 16 | Ui::MainWindow *ui; 17 | 18 | private: 19 | ChessView *m_view; 20 | ChessAlgorithm *m_algorithm; 21 | }; 22 | 23 | #endif // MAINWINDOW_H 24 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver1/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | 9 | 0 10 | 0 11 | 800 12 | 600 13 | 14 | 15 | 16 | MainWindow 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/chess_ver2.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = chess 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp \ 10 | chessboard.cpp \ 11 | chessalgorithm.cpp \ 12 | chessview.cpp \ 13 | mainwindow.cpp 14 | 15 | HEADERS += \ 16 | chessboard.h \ 17 | chessalgorithm.h \ 18 | chessview.h \ 19 | mainwindow.h 20 | 21 | FORMS += \ 22 | mainwindow.ui 23 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/chessalgorithm.cpp: -------------------------------------------------------------------------------- 1 | #include "chessalgorithm.h" 2 | #include "chessboard.h" 3 | 4 | ChessAlgorithm::ChessAlgorithm(QObject *parent) : QObject(parent), m_board(0) 5 | { 6 | 7 | } 8 | 9 | ChessBoard *ChessAlgorithm::board() const 10 | { 11 | return m_board; 12 | } 13 | 14 | void ChessAlgorithm::newGame() 15 | { 16 | setupBoard(); 17 | } 18 | 19 | void ChessAlgorithm::setupBoard() 20 | { 21 | setBoard(new ChessBoard(8,8, this)); 22 | } 23 | 24 | void ChessAlgorithm::setBoard(ChessBoard *board) 25 | { 26 | if(board == m_board) return; 27 | if(m_board) delete m_board; 28 | m_board = board; 29 | emit boardChanged(m_board); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/chessalgorithm.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESSALGORITHM_H 2 | #define CHESSALGORITHM_H 3 | 4 | #include 5 | class ChessBoard; 6 | 7 | class ChessAlgorithm : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ChessAlgorithm(QObject *parent = 0); 12 | ChessBoard* board() const; 13 | 14 | public slots: 15 | virtual void newGame(); 16 | 17 | signals: 18 | void boardChanged(ChessBoard*); 19 | 20 | protected: 21 | virtual void setupBoard(); 22 | void setBoard(ChessBoard *board); 23 | 24 | private: 25 | ChessBoard* m_board; 26 | }; 27 | 28 | #endif // CHESSALGORITHM_H 29 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/chessview.cpp: -------------------------------------------------------------------------------- 1 | #include "chessview.h" 2 | #include "chessboard.h" 3 | 4 | ChessView::ChessView(QWidget *parent) : QWidget(parent) 5 | { 6 | 7 | } 8 | 9 | void ChessView::setBoard(ChessBoard *board) 10 | { 11 | if(m_board == board) return; 12 | 13 | if(m_board) { 14 | // disconnect all signal-slot connections between m_board and this 15 | m_board->disconnect(this); 16 | } 17 | m_board = board; 18 | // connect signals (to be done later) 19 | updateGeometry(); 20 | } 21 | 22 | ChessBoard *ChessView::ChessView::board() const { return m_board; } 23 | 24 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/chessview.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESSVIEW_H 2 | #define CHESSVIEW_H 3 | 4 | #include 5 | #include 6 | 7 | class ChessBoard; 8 | class ChessView : public QWidget 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit ChessView(QWidget *parent = 0); 13 | void setBoard(ChessBoard*); 14 | ChessBoard* board() const; 15 | 16 | private: 17 | QPointer m_board; 18 | }; 19 | 20 | #endif // CHESSVIEW_H 21 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow mw; 8 | mw.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | MainWindow::MainWindow(QWidget *parent) 4 | : QMainWindow(parent), ui(new Ui::MainWindow) 5 | { 6 | ui->setupUi(this); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "ui_mainwindow.h" 6 | 7 | class ChessView; 8 | class ChessAlgorithm; 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MainWindow(QWidget *parent = 0); 14 | 15 | protected: 16 | Ui::MainWindow *ui; 17 | 18 | private: 19 | ChessView *m_view; 20 | ChessAlgorithm *m_algorithm; 21 | }; 22 | 23 | #endif // MAINWINDOW_H 24 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver2/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | 9 | 0 10 | 0 11 | 800 12 | 600 13 | 14 | 15 | 16 | MainWindow 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver3/chess_ver3.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = chess 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp \ 10 | chessboard.cpp \ 11 | chessalgorithm.cpp \ 12 | chessview.cpp \ 13 | mainwindow.cpp 14 | 15 | HEADERS += \ 16 | chessboard.h \ 17 | chessalgorithm.h \ 18 | chessview.h \ 19 | mainwindow.h 20 | 21 | FORMS += \ 22 | mainwindow.ui 23 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver3/chessalgorithm.cpp: -------------------------------------------------------------------------------- 1 | #include "chessalgorithm.h" 2 | #include "chessboard.h" 3 | 4 | ChessAlgorithm::ChessAlgorithm(QObject *parent) : QObject(parent), m_board(0) 5 | { 6 | 7 | } 8 | 9 | ChessBoard *ChessAlgorithm::board() const 10 | { 11 | return m_board; 12 | } 13 | 14 | void ChessAlgorithm::newGame() 15 | { 16 | setupBoard(); 17 | } 18 | 19 | void ChessAlgorithm::setupBoard() 20 | { 21 | setBoard(new ChessBoard(8,8, this)); 22 | } 23 | 24 | void ChessAlgorithm::setBoard(ChessBoard *board) 25 | { 26 | if(board == m_board) return; 27 | if(m_board) delete m_board; 28 | m_board = board; 29 | emit boardChanged(m_board); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver3/chessalgorithm.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESSALGORITHM_H 2 | #define CHESSALGORITHM_H 3 | 4 | #include 5 | class ChessBoard; 6 | 7 | class ChessAlgorithm : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ChessAlgorithm(QObject *parent = 0); 12 | ChessBoard* board() const; 13 | 14 | public slots: 15 | virtual void newGame(); 16 | 17 | signals: 18 | void boardChanged(ChessBoard*); 19 | 20 | protected: 21 | virtual void setupBoard(); 22 | void setBoard(ChessBoard *board); 23 | 24 | private: 25 | ChessBoard* m_board; 26 | }; 27 | 28 | #endif // CHESSALGORITHM_H 29 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver3/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow mw; 8 | mw.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver3/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "chessview.h" 3 | #include "chessalgorithm.h" 4 | #include 5 | 6 | MainWindow::MainWindow(QWidget *parent) 7 | : QMainWindow(parent), ui(new Ui::MainWindow) 8 | { 9 | ui->setupUi(this); 10 | m_view = new ChessView; 11 | m_algorithm = new ChessAlgorithm(this); 12 | m_algorithm->newGame(); 13 | m_view->setBoard(m_algorithm->board()); 14 | setCentralWidget(m_view); 15 | m_view->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 16 | m_view->setFieldSize(QSize(50,50)); 17 | layout()->setSizeConstraint(QLayout::SetFixedSize); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver3/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "ui_mainwindow.h" 6 | 7 | class ChessView; 8 | class ChessAlgorithm; 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MainWindow(QWidget *parent = 0); 14 | 15 | protected: 16 | Ui::MainWindow *ui; 17 | 18 | private: 19 | ChessView *m_view; 20 | ChessAlgorithm *m_algorithm; 21 | }; 22 | 23 | #endif // MAINWINDOW_H 24 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver3/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | 9 | 0 10 | 0 11 | 800 12 | 600 13 | 14 | 15 | 16 | MainWindow 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver4/chess_ver4.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = chess 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp \ 10 | chessboard.cpp \ 11 | chessalgorithm.cpp \ 12 | chessview.cpp \ 13 | mainwindow.cpp 14 | 15 | HEADERS += \ 16 | chessboard.h \ 17 | chessalgorithm.h \ 18 | chessview.h \ 19 | mainwindow.h 20 | 21 | FORMS += \ 22 | mainwindow.ui 23 | 24 | RESOURCES += pieces.qrc 25 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver4/chessalgorithm.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESSALGORITHM_H 2 | #define CHESSALGORITHM_H 3 | 4 | #include 5 | class ChessBoard; 6 | 7 | class ChessAlgorithm : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ChessAlgorithm(QObject *parent = 0); 12 | ChessBoard* board() const; 13 | 14 | public slots: 15 | virtual void newGame(); 16 | 17 | signals: 18 | void boardChanged(ChessBoard*); 19 | 20 | protected: 21 | virtual void setupBoard(); 22 | void setBoard(ChessBoard *board); 23 | 24 | private: 25 | ChessBoard* m_board; 26 | }; 27 | 28 | #endif // CHESSALGORITHM_H 29 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver4/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow mw; 8 | mw.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver4/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "ui_mainwindow.h" 6 | 7 | class ChessView; 8 | class ChessAlgorithm; 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MainWindow(QWidget *parent = 0); 14 | 15 | protected: 16 | Ui::MainWindow *ui; 17 | 18 | private: 19 | ChessView *m_view; 20 | ChessAlgorithm *m_algorithm; 21 | }; 22 | 23 | #endif // MAINWINDOW_H 24 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver4/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | 9 | 0 10 | 0 11 | 800 12 | 600 13 | 14 | 15 | 16 | MainWindow 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver4/pieces.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | pieces/Chess_blt45.svg 4 | pieces/Chess_klt45.svg 5 | pieces/Chess_plt45.svg 6 | pieces/Chess_qlt45.svg 7 | pieces/Chess_rlt45.svg 8 | pieces/Chess_bdt45.svg 9 | pieces/Chess_kdt45.svg 10 | pieces/Chess_ndt45.svg 11 | pieces/Chess_pdt45.svg 12 | pieces/Chess_qdt45.svg 13 | pieces/Chess_rdt45.svg 14 | pieces/Chess_nlt45.svg 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver5/chess_ver5.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = chess 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp \ 10 | chessboard.cpp \ 11 | chessalgorithm.cpp \ 12 | chessview.cpp \ 13 | mainwindow.cpp 14 | 15 | HEADERS += \ 16 | chessboard.h \ 17 | chessalgorithm.h \ 18 | chessview.h \ 19 | mainwindow.h 20 | 21 | FORMS += \ 22 | mainwindow.ui 23 | 24 | RESOURCES += pieces.qrc 25 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver5/chessalgorithm.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESSALGORITHM_H 2 | #define CHESSALGORITHM_H 3 | 4 | #include 5 | class ChessBoard; 6 | 7 | class ChessAlgorithm : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ChessAlgorithm(QObject *parent = 0); 12 | ChessBoard* board() const; 13 | 14 | public slots: 15 | virtual void newGame(); 16 | 17 | signals: 18 | void boardChanged(ChessBoard*); 19 | 20 | protected: 21 | virtual void setupBoard(); 22 | void setBoard(ChessBoard *board); 23 | 24 | private: 25 | ChessBoard* m_board; 26 | }; 27 | 28 | #endif // CHESSALGORITHM_H 29 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver5/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow mw; 8 | mw.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver5/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "ui_mainwindow.h" 6 | #include "chessview.h" 7 | 8 | class ChessAlgorithm; 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MainWindow(QWidget *parent = 0); 14 | 15 | public slots: 16 | void viewClicked(const QPoint &field); 17 | 18 | protected: 19 | Ui::MainWindow *ui; 20 | 21 | private: 22 | ChessView *m_view; 23 | ChessAlgorithm *m_algorithm; 24 | QPoint m_clickPoint; 25 | ChessView::FieldHighlight *m_selectedField; 26 | }; 27 | 28 | #endif // MAINWINDOW_H 29 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver5/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | 9 | 0 10 | 0 11 | 800 12 | 600 13 | 14 | 15 | 16 | MainWindow 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver5/pieces.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | pieces/Chess_blt45.svg 4 | pieces/Chess_klt45.svg 5 | pieces/Chess_plt45.svg 6 | pieces/Chess_qlt45.svg 7 | pieces/Chess_rlt45.svg 8 | pieces/Chess_bdt45.svg 9 | pieces/Chess_kdt45.svg 10 | pieces/Chess_ndt45.svg 11 | pieces/Chess_pdt45.svg 12 | pieces/Chess_qdt45.svg 13 | pieces/Chess_rdt45.svg 14 | pieces/Chess_nlt45.svg 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver6/chess_ver6.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = chess 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp \ 10 | chessboard.cpp \ 11 | chessalgorithm.cpp \ 12 | chessview.cpp \ 13 | mainwindow.cpp \ 14 | foxandhounds.cpp 15 | 16 | HEADERS += \ 17 | chessboard.h \ 18 | chessalgorithm.h \ 19 | chessview.h \ 20 | mainwindow.h \ 21 | foxandhounds.h 22 | 23 | FORMS += \ 24 | mainwindow.ui 25 | 26 | RESOURCES += pieces.qrc 27 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver6/foxandhounds.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FOXANDHOUNDS_H 3 | #define FOXANDHOUNDS_H 4 | 5 | #include 6 | #include "chessalgorithm.h" 7 | #include 8 | 9 | class FoxAndHounds : public ChessAlgorithm 10 | { 11 | public: 12 | FoxAndHounds(QObject *parent = 0); 13 | ~FoxAndHounds(); 14 | 15 | void newGame(); 16 | bool move(int colFrom, int rankFrom, int colTo, int rankTo); 17 | protected: 18 | bool foxCanMove() const; 19 | bool emptyByOffset(int x, int y) const; 20 | private: 21 | QPoint m_fox; 22 | }; 23 | 24 | 25 | 26 | #endif // FOXANDHOUNDS_H 27 | 28 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver6/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow mw; 8 | mw.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver6/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "ui_mainwindow.h" 6 | #include "chessview.h" 7 | #include "chessalgorithm.h" 8 | 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MainWindow(QWidget *parent = 0); 14 | 15 | public slots: 16 | void viewClicked(const QPoint &field); 17 | 18 | protected: 19 | Ui::MainWindow *ui; 20 | 21 | private slots: 22 | void gameOver(ChessAlgorithm::Result); 23 | 24 | private: 25 | ChessView *m_view; 26 | ChessAlgorithm *m_algorithm; 27 | QPoint m_clickPoint; 28 | ChessView::FieldHighlight *m_selectedField; 29 | }; 30 | 31 | #endif // MAINWINDOW_H 32 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver6/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | 9 | 0 10 | 0 11 | 800 12 | 600 13 | 14 | 15 | 16 | MainWindow 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/chess/ver6/pieces.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | pieces/Chess_blt45.svg 4 | pieces/Chess_klt45.svg 5 | pieces/Chess_plt45.svg 6 | pieces/Chess_qlt45.svg 7 | pieces/Chess_rlt45.svg 8 | pieces/Chess_bdt45.svg 9 | pieces/Chess_kdt45.svg 10 | pieces/Chess_ndt45.svg 11 | pieces/Chess_pdt45.svg 12 | pieces/Chess_qdt45.svg 13 | pieces/Chess_rdt45.svg 14 | pieces/Chess_nlt45.svg 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver1/customwidget_ver1.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = customwidget 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp\ 10 | widget.cpp 11 | 12 | HEADERS += widget.h 13 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver1/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver1/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | { 7 | } 8 | 9 | Widget::~Widget() 10 | { 11 | 12 | } 13 | 14 | void Widget::paintEvent(QPaintEvent *) 15 | { 16 | QPainter painter(this); 17 | painter.setRenderHint(QPainter::Antialiasing, true); 18 | QPen pen(Qt::black); 19 | pen.setWidth(4); 20 | painter.setPen(pen); 21 | QRect r = rect().adjusted(10, 10, -10, -10); 22 | painter.drawRoundedRect(r, 20, 10); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver1/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = 0); 12 | ~Widget(); 13 | 14 | protected: 15 | void paintEvent(QPaintEvent *); 16 | }; 17 | 18 | #endif // WIDGET_H 19 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver2/customwidget_ver2.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = customwidget 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp\ 10 | widget.cpp 11 | 12 | HEADERS += widget.h 13 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver2/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver2/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = 0); 12 | ~Widget(); 13 | 14 | protected: 15 | void paintEvent(QPaintEvent *); 16 | void drawChart(QPainter *painter, const QRect &rect); 17 | }; 18 | 19 | #endif // WIDGET_H 20 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver3/customwidget_ver3.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = customwidget 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp\ 10 | widget.cpp 11 | 12 | HEADERS += widget.h 13 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver3/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | for(int i = 0; i < 450; ++i) { 9 | w.addPoint(qrand() % 120); 10 | } 11 | w.show(); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver3/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = 0); 12 | ~Widget(); 13 | 14 | public slots: 15 | void addPoint(unsigned yVal); 16 | void clear(); 17 | 18 | protected: 19 | void paintEvent(QPaintEvent *); 20 | void drawChart(QPainter *painter, const QRect &rect); 21 | QVector m_points; 22 | }; 23 | 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver4/customwidget_ver4.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = customwidget 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp\ 10 | widget.cpp 11 | 12 | HEADERS += widget.h 13 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver4/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | for(int i = 0; i < 450; ++i) { 9 | w.addPoint(qrand() % 120); 10 | } 11 | w.show(); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver5/customwidget_ver5.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = customwidget 6 | TEMPLATE = app 7 | 8 | 9 | SOURCES += main.cpp\ 10 | widget.cpp 11 | 12 | HEADERS += widget.h 13 | -------------------------------------------------------------------------------- /Chapter08/Custom Widgets/painting/ver5/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | for(int i = 0; i < 450;++i) { 9 | w.addPoint(qrand() % 120); 10 | } 11 | w.show(); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/1. triangle/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "simpleglwindow.h" 3 | 4 | int main(int argc, char **argv) { 5 | QGuiApplication app(argc, argv); 6 | SimpleGLWindow window; 7 | window.resize(600, 400); 8 | window.show(); 9 | return app.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/1. triangle/simpleglwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMPLEGLWINDOW_H 2 | #define SIMPLEGLWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class SimpleGLWindow : public QOpenGLWindow, protected QOpenGLFunctions_1_1 8 | { 9 | public: 10 | SimpleGLWindow(QWindow *parent = 0); 11 | protected: 12 | void initializeGL(); 13 | void paintGL(); 14 | }; 15 | 16 | #endif // SIMPLEGLWINDOW_H 17 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/1. triangle/triangle.pro: -------------------------------------------------------------------------------- 1 | QT = core gui 2 | TARGET = triangle 3 | TEMPLATE = app 4 | HEADERS += simpleglwindow.h 5 | SOURCES += simpleglwindow.cpp main.cpp 6 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/2. scene/abstractglscene.cpp: -------------------------------------------------------------------------------- 1 | #include "abstractglscene.h" 2 | #include 3 | 4 | AbstractGLScene::AbstractGLScene(QOpenGLWindow *window) 5 | { 6 | m_window = window; 7 | } 8 | 9 | AbstractGLScene::~AbstractGLScene() 10 | { 11 | 12 | } 13 | 14 | QOpenGLContext *AbstractGLScene::context() { 15 | return m_window ? m_window->context() : nullptr; 16 | } 17 | 18 | const QOpenGLContext *AbstractGLScene::context() const 19 | { 20 | return m_window ? m_window->context() : nullptr; 21 | } 22 | 23 | void AbstractGLScene::initialize() 24 | { 25 | if (!initializeOpenGLFunctions()) { 26 | qFatal("initializeOpenGLFunctions failed"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/2. scene/abstractglscene.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACTGLSCENE_H 2 | #define ABSTRACTGLSCENE_H 3 | 4 | #include 5 | 6 | class QOpenGLWindow; 7 | class AbstractGLScene : protected QOpenGLFunctions_1_1 8 | { 9 | public: 10 | AbstractGLScene(QOpenGLWindow *window = 0); 11 | virtual ~AbstractGLScene(); 12 | QOpenGLWindow* window() const { 13 | return m_window; 14 | } 15 | QOpenGLContext* context(); 16 | const QOpenGLContext* context() const; 17 | 18 | virtual void initialize(); 19 | virtual void paint() = 0; 20 | 21 | private: 22 | QOpenGLWindow* m_window = nullptr; 23 | }; 24 | 25 | #endif // ABSTRACTGLSCENE_H 26 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/2. scene/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sceneglwindow.h" 3 | 4 | int main(int argc, char **argv) { 5 | QGuiApplication app(argc, argv); 6 | SceneGLWindow window; 7 | window.resize(600, 400); 8 | window.show(); 9 | return app.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/2. scene/scene.pro: -------------------------------------------------------------------------------- 1 | QT = core gui 2 | TARGET = scene 3 | TEMPLATE = app 4 | HEADERS += abstractglscene.h \ 5 | sceneglwindow.h 6 | SOURCES += main.cpp abstractglscene.cpp \ 7 | sceneglwindow.cpp 8 | 9 | CONFIG += c++11 10 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/2. scene/sceneglwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "sceneglwindow.h" 2 | #include "abstractglscene.h" 3 | 4 | SceneGLWindow::SceneGLWindow(QWindow *parent) : QOpenGLWindow(NoPartialUpdate, parent) 5 | { 6 | 7 | } 8 | 9 | void SceneGLWindow::setScene(AbstractGLScene *s) 10 | { 11 | m_scene = s; 12 | } 13 | 14 | void SceneGLWindow::initializeGL() { 15 | if(m_scene) { 16 | m_scene->initialize(); 17 | } 18 | } 19 | void SceneGLWindow::paintGL() { 20 | if(m_scene) { 21 | m_scene->paint(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/2. scene/sceneglwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGLWINDOW_H 2 | #define SCENEGLWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class AbstractGLScene; 8 | class SceneGLWindow : public QOpenGLWindow 9 | { 10 | public: 11 | SceneGLWindow(QWindow *parent = 0); 12 | AbstractGLScene* scene() const { 13 | return m_scene; 14 | } 15 | void setScene(AbstractGLScene *s); 16 | 17 | protected: 18 | void initializeGL(); 19 | void paintGL(); 20 | private: 21 | AbstractGLScene *m_scene = nullptr; 22 | }; 23 | 24 | #endif // SCENEGLWINDOW_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/abstractglscene.cpp: -------------------------------------------------------------------------------- 1 | #include "abstractglscene.h" 2 | #include 3 | 4 | AbstractGLScene::AbstractGLScene(QOpenGLWindow *window) 5 | { 6 | m_window = window; 7 | } 8 | 9 | AbstractGLScene::~AbstractGLScene() 10 | { 11 | 12 | } 13 | 14 | QOpenGLContext *AbstractGLScene::context() { 15 | return m_window ? m_window->context() : nullptr; 16 | } 17 | 18 | const QOpenGLContext *AbstractGLScene::context() const 19 | { 20 | return m_window ? m_window->context() : nullptr; 21 | } 22 | 23 | void AbstractGLScene::initialize() 24 | { 25 | if (!initializeOpenGLFunctions()) { 26 | qFatal("initializeOpenGLFunctions failed"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/abstractglscene.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACTGLSCENE_H 2 | #define ABSTRACTGLSCENE_H 3 | 4 | #include 5 | class QOpenGLWindow; 6 | class AbstractGLScene : protected QOpenGLFunctions_1_1 7 | { 8 | public: 9 | AbstractGLScene(QOpenGLWindow *window = 0); 10 | virtual ~AbstractGLScene(); 11 | QOpenGLWindow* window() const { 12 | return m_window; 13 | } 14 | QOpenGLContext* context(); 15 | const QOpenGLContext* context() const; 16 | 17 | virtual void initialize(); 18 | virtual void paint() = 0; 19 | 20 | private: 21 | QOpenGLWindow* m_window = nullptr; 22 | }; 23 | 24 | #endif // ABSTRACTGLSCENE_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/cube.pro: -------------------------------------------------------------------------------- 1 | QT = core gui 2 | TARGET = cube 3 | TEMPLATE = app 4 | HEADERS += abstractglscene.h \ 5 | sceneglwindow.h \ 6 | cubeglscene.h 7 | SOURCES += main.cpp abstractglscene.cpp \ 8 | sceneglwindow.cpp \ 9 | cubeglscene.cpp 10 | 11 | CONFIG += c++11 12 | 13 | RESOURCES += \ 14 | texture.qrc 15 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sceneglwindow.h" 3 | #include "cubeglscene.h" 4 | 5 | int main(int argc, char **argv) { 6 | QGuiApplication app(argc, argv); 7 | SceneGLWindow window; 8 | QSurfaceFormat fmt; 9 | fmt.setSamples(16); 10 | window.setFormat(fmt); 11 | CubeGLScene scene(&window); 12 | window.setScene(&scene); 13 | scene.setTexture(QImage(":/texture.jpg")); 14 | window.resize(600, 600); 15 | window.show(); 16 | return app.exec(); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/sceneglwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "sceneglwindow.h" 2 | #include "abstractglscene.h" 3 | 4 | SceneGLWindow::SceneGLWindow(QWindow *parent) : QOpenGLWindow(NoPartialUpdate, parent) 5 | { 6 | 7 | } 8 | 9 | void SceneGLWindow::setScene(AbstractGLScene *s) 10 | { 11 | m_scene = s; 12 | } 13 | 14 | void SceneGLWindow::initializeGL() { 15 | if(m_scene) { 16 | m_scene->initialize(); 17 | } 18 | } 19 | void SceneGLWindow::paintGL() { 20 | if(m_scene) { 21 | m_scene->paint(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/sceneglwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGLWINDOW_H 2 | #define SCENEGLWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class AbstractGLScene; 8 | class SceneGLWindow : public QOpenGLWindow 9 | { 10 | public: 11 | SceneGLWindow(QWindow *parent = 0); 12 | AbstractGLScene* scene() const { 13 | return m_scene; 14 | } 15 | void setScene(AbstractGLScene *s); 16 | 17 | protected: 18 | void initializeGL(); 19 | void paintGL(); 20 | private: 21 | AbstractGLScene *m_scene = nullptr; 22 | }; 23 | 24 | #endif // SCENEGLWINDOW_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter09/OpenGL and Vulkan in Qt applications/3. cube/texture.jpg -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3. cube/texture.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | texture.jpg 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/abstractglscene.cpp: -------------------------------------------------------------------------------- 1 | #include "abstractglscene.h" 2 | #include 3 | 4 | AbstractGLScene::AbstractGLScene(QOpenGLWindow *window) 5 | { 6 | m_window = window; 7 | } 8 | 9 | AbstractGLScene::~AbstractGLScene() 10 | { 11 | 12 | } 13 | 14 | QOpenGLContext *AbstractGLScene::context() { 15 | return m_window ? m_window->context() : nullptr; 16 | } 17 | 18 | const QOpenGLContext *AbstractGLScene::context() const 19 | { 20 | return m_window ? m_window->context() : nullptr; 21 | } 22 | 23 | void AbstractGLScene::initialize() 24 | { 25 | if (!initializeOpenGLFunctions()) { 26 | qFatal("initializeOpenGLFunctions failed"); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/abstractglscene.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACTGLSCENE_H 2 | #define ABSTRACTGLSCENE_H 3 | 4 | #include 5 | class QOpenGLWindow; 6 | class AbstractGLScene : protected QOpenGLFunctions_1_1 7 | { 8 | public: 9 | AbstractGLScene(QOpenGLWindow *window = 0); 10 | virtual ~AbstractGLScene(); 11 | QOpenGLWindow* window() const { 12 | return m_window; 13 | } 14 | QOpenGLContext* context(); 15 | const QOpenGLContext* context() const; 16 | 17 | virtual void initialize(); 18 | virtual void paint() = 0; 19 | 20 | private: 21 | QOpenGLWindow* m_window = nullptr; 22 | }; 23 | 24 | #endif // ABSTRACTGLSCENE_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/animated_cube.pro: -------------------------------------------------------------------------------- 1 | QT = core gui 2 | TARGET = animated_cube 3 | TEMPLATE = app 4 | HEADERS += abstractglscene.h \ 5 | sceneglwindow.h \ 6 | cubeglscene.h 7 | SOURCES += main.cpp abstractglscene.cpp \ 8 | sceneglwindow.cpp \ 9 | cubeglscene.cpp 10 | 11 | CONFIG += c++11 12 | 13 | RESOURCES += \ 14 | texture.qrc 15 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/sceneglwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "sceneglwindow.h" 2 | #include "abstractglscene.h" 3 | 4 | SceneGLWindow::SceneGLWindow(QWindow *parent) : QOpenGLWindow(NoPartialUpdate, parent) 5 | { 6 | 7 | } 8 | 9 | void SceneGLWindow::setScene(AbstractGLScene *s) 10 | { 11 | m_scene = s; 12 | } 13 | 14 | void SceneGLWindow::initializeGL() { 15 | if(m_scene) { 16 | m_scene->initialize(); 17 | } 18 | } 19 | void SceneGLWindow::paintGL() { 20 | if(m_scene) { 21 | m_scene->paint(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/sceneglwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGLWINDOW_H 2 | #define SCENEGLWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class AbstractGLScene; 8 | class SceneGLWindow : public QOpenGLWindow 9 | { 10 | public: 11 | SceneGLWindow(QWindow *parent = 0); 12 | AbstractGLScene* scene() const { 13 | return m_scene; 14 | } 15 | void setScene(AbstractGLScene *s); 16 | 17 | protected: 18 | void initializeGL(); 19 | void paintGL(); 20 | private: 21 | AbstractGLScene *m_scene = nullptr; 22 | }; 23 | 24 | #endif // SCENEGLWINDOW_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/texture.jpg -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/3a. animated cube/texture.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | texture.jpg 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/abstractglscene.cpp: -------------------------------------------------------------------------------- 1 | #include "abstractglscene.h" 2 | #include 3 | 4 | AbstractGLScene::AbstractGLScene(QOpenGLWindow *window) 5 | { 6 | m_window = window; 7 | } 8 | 9 | AbstractGLScene::~AbstractGLScene() 10 | { 11 | 12 | } 13 | 14 | QOpenGLContext *AbstractGLScene::context() { 15 | return m_window ? m_window->context() : nullptr; 16 | } 17 | 18 | const QOpenGLContext *AbstractGLScene::context() const 19 | { 20 | return m_window ? m_window->context() : nullptr; 21 | } 22 | 23 | void AbstractGLScene::initialize() 24 | { 25 | if (!initializeOpenGLFunctions()) { 26 | qFatal("initializeOpenGLFunctions failed"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/abstractglscene.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACTGLSCENE_H 2 | #define ABSTRACTGLSCENE_H 3 | 4 | #include 5 | 6 | class QOpenGLWindow; 7 | class AbstractGLScene : protected QOpenGLFunctions_1_1 8 | { 9 | public: 10 | AbstractGLScene(QOpenGLWindow *window = 0); 11 | virtual ~AbstractGLScene(); 12 | QOpenGLWindow* window() const { 13 | return m_window; 14 | } 15 | QOpenGLContext* context(); 16 | const QOpenGLContext* context() const; 17 | 18 | virtual void initialize(); 19 | virtual void paint() = 0; 20 | 21 | private: 22 | QOpenGLWindow* m_window = nullptr; 23 | }; 24 | 25 | #endif // ABSTRACTGLSCENE_H 26 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sceneglwindow.h" 3 | #include "shaderglscene.h" 4 | 5 | int main(int argc, char **argv) { 6 | QGuiApplication app(argc, argv); 7 | SceneGLWindow window; 8 | QSurfaceFormat fmt; 9 | fmt.setSamples(16); 10 | window.setFormat(fmt); 11 | ShaderGLScene scene(&window); 12 | window.setScene(&scene); 13 | scene.setAngle(30); 14 | window.resize(600, 600); 15 | window.show(); 16 | return app.exec(); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/phong.vert: -------------------------------------------------------------------------------- 1 | uniform highp mat4 modelViewMatrix; 2 | uniform highp mat3 normalMatrix; 3 | uniform highp mat4 projectionMatrix; 4 | uniform highp mat4 mvpMatrix; 5 | 6 | attribute highp vec4 Vertex; 7 | attribute mediump vec3 Normal; 8 | 9 | varying mediump vec3 N; 10 | varying highp vec3 v; 11 | 12 | void main(void) 13 | { 14 | N = normalize(normalMatrix * Normal); 15 | v = vec3(modelViewMatrix * Vertex); 16 | 17 | gl_Position = mvpMatrix * Vertex; 18 | } 19 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | phong.vert 4 | phong.frag 5 | monkey.ply 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/sceneglwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "sceneglwindow.h" 2 | #include "abstractglscene.h" 3 | 4 | SceneGLWindow::SceneGLWindow(QWindow *parent) : QOpenGLWindow(NoPartialUpdate, parent) 5 | { 6 | 7 | } 8 | 9 | void SceneGLWindow::setScene(AbstractGLScene *s) 10 | { 11 | m_scene = s; 12 | } 13 | 14 | void SceneGLWindow::initializeGL() { 15 | if(m_scene) { 16 | m_scene->initialize(); 17 | } 18 | } 19 | void SceneGLWindow::paintGL() { 20 | if(m_scene) { 21 | m_scene->paint(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/sceneglwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGLWINDOW_H 2 | #define SCENEGLWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class AbstractGLScene; 8 | class SceneGLWindow : public QOpenGLWindow 9 | { 10 | public: 11 | SceneGLWindow(QWindow *parent = 0); 12 | AbstractGLScene* scene() const { 13 | return m_scene; 14 | } 15 | void setScene(AbstractGLScene *s); 16 | 17 | protected: 18 | void initializeGL(); 19 | void paintGL(); 20 | private: 21 | AbstractGLScene *m_scene = nullptr; 22 | }; 23 | 24 | #endif // SCENEGLWINDOW_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4. shaders/shaders.pro: -------------------------------------------------------------------------------- 1 | QT = core gui 2 | TARGET = shaders 3 | TEMPLATE = app 4 | HEADERS += abstractglscene.h sceneglwindow.h shaderglscene.h \ 5 | plyreader.h 6 | SOURCES += main.cpp abstractglscene.cpp sceneglwindow.cpp shaderglscene.cpp \ 7 | plyreader.cpp 8 | 9 | CONFIG += c++11 10 | 11 | RESOURCES += resources.qrc 12 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/abstractglscene.cpp: -------------------------------------------------------------------------------- 1 | #include "abstractglscene.h" 2 | #include 3 | 4 | AbstractGLScene::AbstractGLScene(QOpenGLWindow *window) 5 | { 6 | m_window = window; 7 | } 8 | 9 | AbstractGLScene::~AbstractGLScene() 10 | { 11 | 12 | } 13 | 14 | QOpenGLContext *AbstractGLScene::context() { 15 | return m_window ? m_window->context() : nullptr; 16 | } 17 | 18 | const QOpenGLContext *AbstractGLScene::context() const 19 | { 20 | return m_window ? m_window->context() : nullptr; 21 | } 22 | 23 | void AbstractGLScene::initialize() 24 | { 25 | if (!initializeOpenGLFunctions()) { 26 | qFatal("initializeOpenGLFunctions failed"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/abstractglscene.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACTGLSCENE_H 2 | #define ABSTRACTGLSCENE_H 3 | 4 | #include 5 | 6 | class QOpenGLWindow; 7 | class AbstractGLScene : protected QOpenGLFunctions_1_1 8 | { 9 | public: 10 | AbstractGLScene(QOpenGLWindow *window = 0); 11 | virtual ~AbstractGLScene(); 12 | QOpenGLWindow* window() const { 13 | return m_window; 14 | } 15 | QOpenGLContext* context(); 16 | const QOpenGLContext* context() const; 17 | 18 | virtual void initialize(); 19 | virtual void paint() = 0; 20 | 21 | private: 22 | QOpenGLWindow* m_window = nullptr; 23 | }; 24 | 25 | #endif // ABSTRACTGLSCENE_H 26 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sceneglwindow.h" 3 | #include "shaderglscene.h" 4 | 5 | int main(int argc, char **argv) { 6 | QGuiApplication app(argc, argv); 7 | SceneGLWindow window; 8 | QSurfaceFormat fmt; 9 | fmt.setSamples(16); 10 | window.setFormat(fmt); 11 | ShaderGLScene scene(&window); 12 | window.setScene(&scene); 13 | scene.setAngle(30); 14 | window.resize(600, 600); 15 | window.show(); 16 | return app.exec(); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/phong.vert: -------------------------------------------------------------------------------- 1 | uniform highp mat4 modelViewMatrix; 2 | uniform highp mat3 normalMatrix; 3 | uniform highp mat4 projectionMatrix; 4 | uniform highp mat4 mvpMatrix; 5 | 6 | attribute highp vec4 Vertex; 7 | attribute mediump vec3 Normal; 8 | 9 | varying mediump vec3 N; 10 | varying highp vec3 v; 11 | 12 | void main(void) 13 | { 14 | N = normalize(normalMatrix * Normal); 15 | v = vec3(modelViewMatrix * Vertex); 16 | 17 | gl_Position = mvpMatrix * Vertex; 18 | } 19 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | phong.vert 4 | phong.frag 5 | monkey.ply 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/sceneglwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "sceneglwindow.h" 2 | #include "abstractglscene.h" 3 | 4 | SceneGLWindow::SceneGLWindow(QWindow *parent) : QOpenGLWindow(NoPartialUpdate, parent) 5 | { 6 | 7 | } 8 | 9 | void SceneGLWindow::setScene(AbstractGLScene *s) 10 | { 11 | m_scene = s; 12 | } 13 | 14 | void SceneGLWindow::initializeGL() { 15 | if(m_scene) { 16 | m_scene->initialize(); 17 | } 18 | } 19 | void SceneGLWindow::paintGL() { 20 | if(m_scene) { 21 | m_scene->paint(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/sceneglwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGLWINDOW_H 2 | #define SCENEGLWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class AbstractGLScene; 8 | class SceneGLWindow : public QOpenGLWindow 9 | { 10 | public: 11 | SceneGLWindow(QWindow *parent = 0); 12 | AbstractGLScene* scene() const { 13 | return m_scene; 14 | } 15 | void setScene(AbstractGLScene *s); 16 | 17 | protected: 18 | void initializeGL(); 19 | void paintGL(); 20 | private: 21 | AbstractGLScene *m_scene = nullptr; 22 | }; 23 | 24 | #endif // SCENEGLWINDOW_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/4a. shaders_and_buffers/shaders_and_buffers.pro: -------------------------------------------------------------------------------- 1 | QT = core gui 2 | TARGET = shaders_and_buffers 3 | TEMPLATE = app 4 | HEADERS += abstractglscene.h sceneglwindow.h shaderglscene.h \ 5 | plyreader.h 6 | SOURCES += main.cpp abstractglscene.cpp sceneglwindow.cpp shaderglscene.cpp \ 7 | plyreader.cpp 8 | 9 | CONFIG += c++11 10 | 11 | RESOURCES += resources.qrc 12 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/5. vulkan_background/myrenderer.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class MyRenderer : public QVulkanWindowRenderer 4 | { 5 | public: 6 | MyRenderer(QVulkanWindow *w); 7 | void initResources(); 8 | void startNextFrame() override; 9 | 10 | protected: 11 | QVulkanWindow *m_window; 12 | QVulkanDeviceFunctions *m_devFuncs; 13 | float m_hue = 0; 14 | 15 | }; 16 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/5. vulkan_background/mywindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mywindow.h" 2 | #include "myrenderer.h" 3 | 4 | QVulkanWindowRenderer *MyWindow::createRenderer() { 5 | return new MyRenderer(this); 6 | } 7 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/5. vulkan_background/mywindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MYWINDOW_H 2 | #define MYWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class MyWindow : public QVulkanWindow { 8 | public: 9 | QVulkanWindowRenderer *createRenderer() override; 10 | }; 11 | 12 | 13 | #endif // MYWINDOW_H 14 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/5. vulkan_background/vulkan_background.pro: -------------------------------------------------------------------------------- 1 | QT += gui 2 | CONFIG += c++11 3 | DEFINES += QT_DEPRECATED_WARNINGS 4 | 5 | SOURCES += main.cpp \ 6 | myrenderer.cpp \ 7 | mywindow.cpp 8 | 9 | HEADERS += \ 10 | myrenderer.h \ 11 | mywindow.h 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/abstractglscene.cpp: -------------------------------------------------------------------------------- 1 | #include "abstractglscene.h" 2 | #include 3 | 4 | AbstractGLScene::AbstractGLScene(QOpenGLWindow *window) 5 | { 6 | m_window = window; 7 | } 8 | 9 | AbstractGLScene::~AbstractGLScene() 10 | { 11 | 12 | } 13 | 14 | QOpenGLContext *AbstractGLScene::context() { 15 | return m_window ? m_window->context() : nullptr; 16 | } 17 | 18 | const QOpenGLContext *AbstractGLScene::context() const 19 | { 20 | return m_window ? m_window->context() : nullptr; 21 | } 22 | 23 | void AbstractGLScene::initialize() 24 | { 25 | if (!initializeOpenGLFunctions()) { 26 | qFatal("initializeOpenGLFunctions failed"); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/abstractglscene.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACTGLSCENE_H 2 | #define ABSTRACTGLSCENE_H 3 | 4 | #include 5 | class QOpenGLWindow; 6 | class AbstractGLScene : protected QOpenGLFunctions_1_1 7 | { 8 | public: 9 | AbstractGLScene(QOpenGLWindow *window = 0); 10 | virtual ~AbstractGLScene(); 11 | QOpenGLWindow* window() const { 12 | return m_window; 13 | } 14 | QOpenGLContext* context(); 15 | const QOpenGLContext* context() const; 16 | 17 | virtual void initialize(); 18 | virtual void paint() = 0; 19 | 20 | private: 21 | QOpenGLWindow* m_window = nullptr; 22 | }; 23 | 24 | #endif // ABSTRACTGLSCENE_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/opengl_with_widgets.pro: -------------------------------------------------------------------------------- 1 | QT = core gui widgets 2 | TARGET = animated_cube 3 | TEMPLATE = app 4 | HEADERS += abstractglscene.h \ 5 | sceneglwindow.h \ 6 | cubeglscene.h 7 | SOURCES += main.cpp abstractglscene.cpp \ 8 | sceneglwindow.cpp \ 9 | cubeglscene.cpp 10 | 11 | CONFIG += c++11 12 | 13 | RESOURCES += \ 14 | texture.qrc 15 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/sceneglwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "sceneglwindow.h" 2 | #include "abstractglscene.h" 3 | 4 | SceneGLWindow::SceneGLWindow(QWindow *parent) : QOpenGLWindow(NoPartialUpdate, parent) 5 | { 6 | 7 | } 8 | 9 | void SceneGLWindow::setScene(AbstractGLScene *s) 10 | { 11 | m_scene = s; 12 | } 13 | 14 | void SceneGLWindow::initializeGL() { 15 | if(m_scene) { 16 | m_scene->initialize(); 17 | } 18 | } 19 | void SceneGLWindow::paintGL() { 20 | if(m_scene) { 21 | m_scene->paint(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/sceneglwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGLWINDOW_H 2 | #define SCENEGLWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | class AbstractGLScene; 8 | class SceneGLWindow : public QOpenGLWindow 9 | { 10 | public: 11 | SceneGLWindow(QWindow *parent = 0); 12 | AbstractGLScene* scene() const { 13 | return m_scene; 14 | } 15 | void setScene(AbstractGLScene *s); 16 | 17 | protected: 18 | void initializeGL(); 19 | void paintGL(); 20 | private: 21 | AbstractGLScene *m_scene = nullptr; 22 | }; 23 | 24 | #endif // SCENEGLWINDOW_H 25 | -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/texture.jpg -------------------------------------------------------------------------------- /Chapter09/OpenGL and Vulkan in Qt applications/6. opengl with widgets/texture.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | texture.jpg 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter10/Scripting/codeeditor/codeeditor.pro: -------------------------------------------------------------------------------- 1 | QT = core gui widgets qml 2 | TARGET = codeeditor 3 | TEMPLATE = app 4 | 5 | SOURCES += main.cpp mainwindow.cpp 6 | HEADERS += mainwindow.h 7 | FORMS += mainwindow.ui 8 | -------------------------------------------------------------------------------- /Chapter10/Scripting/codeeditor/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter10/Scripting/codeeditor/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | 11 | class MainWindow : public QMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit MainWindow(QWidget *parent = 0); 17 | ~MainWindow(); 18 | public slots: 19 | void newDocument(); 20 | void openDocument(); 21 | void saveDocument(); 22 | void saveDocumentAs(); 23 | void open(const QString &filePath); 24 | void save(const QString &filePath); 25 | void run(); 26 | 27 | private: 28 | Ui::MainWindow *ui; 29 | QJSEngine m_engine; 30 | }; 31 | 32 | #endif // MAINWINDOW_H 33 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "qtpython.h" 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication app(argc, argv); 9 | QtPython python; 10 | python.run("print('Hello from Python')"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver1/qtpython.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "qtpython.h" 3 | #include 4 | #include 5 | 6 | QtPython::QtPython(QObject *parent) : QObject(parent) { 7 | QStringList args = qApp->arguments(); 8 | if (args.count() > 0) { 9 | programNameBuffer.resize(args[0].count()); 10 | args[0].toWCharArray(programNameBuffer.data()); 11 | Py_SetProgramName(programNameBuffer.data()); 12 | } 13 | Py_InitializeEx(0); 14 | } 15 | 16 | QtPython::~QtPython() { 17 | Py_Finalize(); 18 | } 19 | 20 | void QtPython::run(const QString &program) { 21 | PyRun_SimpleString(qPrintable(program)); 22 | } 23 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver1/qtpython.h: -------------------------------------------------------------------------------- 1 | #ifndef QTPYTHON_H 2 | #define QTPYTHON_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class QtPython : public QObject { 9 | Q_OBJECT 10 | public: 11 | QtPython(QObject *parent = 0); 12 | ~QtPython(); 13 | void run(const QString &program); 14 | 15 | private: 16 | QVector programNameBuffer; 17 | }; 18 | #endif // QTPYTHON_H 19 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver1/qtpython.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | TARGET = qtpython 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | TEMPLATE = app 7 | 8 | SOURCES += main.cpp \ 9 | qtpython.cpp 10 | 11 | HEADERS += \ 12 | qtpython.h 13 | 14 | CONFIG += link_pkgconfig no_keywords 15 | PKGCONFIG += python-3.5m 16 | CONFIG += c++11 17 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver2/main.cpp: -------------------------------------------------------------------------------- 1 | #include "qtpython.h" 2 | #include "qtpythonvalue.h" 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication app(argc, argv); 9 | QtPython python; 10 | QtPythonValue integer = 7, string = QStringLiteral("foobar"), none; 11 | qDebug() << integer.toInt() << string.toString() << none.isNone(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver2/qtpython.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "qtpython.h" 3 | #include 4 | 5 | QtPython::QtPython(QObject *parent) : QObject(parent) { 6 | QStringList args = qApp->arguments(); 7 | if (args.count() > 0) { 8 | programNameBuffer.resize(args[0].count()); 9 | args[0].toWCharArray(programNameBuffer.data()); 10 | Py_SetProgramName(programNameBuffer.data()); 11 | } 12 | Py_InitializeEx(0); 13 | } 14 | 15 | QtPython::~QtPython() { 16 | Py_Finalize(); 17 | } 18 | 19 | void QtPython::run(const QString &program) { 20 | PyRun_SimpleString(qPrintable(program)); 21 | } 22 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver2/qtpython.h: -------------------------------------------------------------------------------- 1 | #ifndef QTPYTHON_H 2 | #define QTPYTHON_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class QtPython : public QObject { 9 | Q_OBJECT 10 | public: 11 | QtPython(QObject *parent = 0); 12 | ~QtPython(); 13 | void run(const QString &program); 14 | 15 | private: 16 | QVector programNameBuffer; 17 | }; 18 | #endif // QTPYTHON_H 19 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver2/qtpython.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | TARGET = qtpython 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | TEMPLATE = app 7 | 8 | SOURCES += main.cpp \ 9 | qtpython.cpp \ 10 | qtpythonvalue.cpp 11 | 12 | HEADERS += \ 13 | qtpython.h \ 14 | qtpythonvalue.h 15 | 16 | CONFIG += link_pkgconfig no_keywords 17 | PKGCONFIG += python-3.5m 18 | CONFIG += c++11 19 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver3/qtpython.h: -------------------------------------------------------------------------------- 1 | #ifndef QTPYTHON_H 2 | #define QTPYTHON_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "qtpythonvalue.h" 8 | 9 | class QtPython : public QObject { 10 | Q_OBJECT 11 | public: 12 | QtPython(QObject *parent = 0); 13 | ~QtPython(); 14 | void run(const QString &program); 15 | QtPythonValue run(const QString &program, const QtPythonValue &globals, const QtPythonValue &locals); 16 | 17 | QtPythonValue import(const QString &name) const; 18 | QtPythonValue addModule(const QString &name) const; 19 | QtPythonValue dictionary(const QtPythonValue &module) const; 20 | 21 | private: 22 | QVector programNameBuffer; 23 | }; 24 | #endif // QTPYTHON_H 25 | -------------------------------------------------------------------------------- /Chapter10/Scripting/qtpython/qtpython_ver3/qtpython.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | TARGET = qtpython 4 | CONFIG += console 5 | CONFIG -= app_bundle 6 | TEMPLATE = app 7 | 8 | SOURCES += main.cpp \ 9 | qtpython.cpp \ 10 | qtpythonvalue.cpp 11 | 12 | HEADERS += \ 13 | qtpython.h \ 14 | qtpythonvalue.h 15 | 16 | CONFIG += link_pkgconfig no_keywords 17 | PKGCONFIG += python-3.5m 18 | CONFIG += c++11 19 | -------------------------------------------------------------------------------- /Chapter10/Scripting/scripted_game/entityproxy.cpp: -------------------------------------------------------------------------------- 1 | #include "entityproxy.h" 2 | #include "entity.h" 3 | 4 | EntityProxy::EntityProxy(Entity *entity, QObject *parent) : 5 | QObject(parent), m_entity(entity) 6 | { 7 | 8 | 9 | } 10 | 11 | int EntityProxy::team() const 12 | { 13 | return m_entity->team(); 14 | } 15 | 16 | QPoint EntityProxy::pos() const 17 | { 18 | return m_entity->pos().toPoint(); 19 | } 20 | -------------------------------------------------------------------------------- /Chapter10/Scripting/scripted_game/entityproxy.h: -------------------------------------------------------------------------------- 1 | #ifndef ENTITYPROXY_H 2 | #define ENTITYPROXY_H 3 | 4 | #include 5 | #include 6 | 7 | class Entity; 8 | 9 | class EntityProxy : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit EntityProxy(Entity *entity, QObject *parent = nullptr); 14 | Q_INVOKABLE int team() const; 15 | Q_INVOKABLE QPoint pos() const; 16 | 17 | signals: 18 | void killed(); 19 | private: 20 | Entity *m_entity; 21 | }; 22 | 23 | #endif // ENTITYPROXY_H 24 | -------------------------------------------------------------------------------- /Chapter10/Scripting/scripted_game/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | scripts/1.js 4 | scripts/2.js 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter10/Scripting/scripted_game/sceneproxy.cpp: -------------------------------------------------------------------------------- 1 | #include "sceneproxy.h" 2 | #include "scene.h" 3 | #include "entity.h" 4 | #include "entityproxy.h" 5 | 6 | SceneProxy::SceneProxy(Scene *scene) : 7 | QObject(scene), m_scene(scene) 8 | { 9 | 10 | } 11 | 12 | QSize SceneProxy::size() const { 13 | return m_scene->fieldSize(); 14 | } 15 | 16 | QJSValue SceneProxy::entities() const 17 | { 18 | QJSValue list = m_scene->jsEngine()->newArray(); 19 | int arrayIndex = 0; 20 | for(Entity *entity: m_scene->entities()) { 21 | if (entity->isAlive()) { 22 | list.setProperty(arrayIndex, entity->proxyValue()); 23 | arrayIndex++; 24 | } 25 | } 26 | return list; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Chapter10/Scripting/scripted_game/sceneproxy.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEPROXY_H 2 | #define SCENEPROXY_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Scene; 9 | 10 | class SceneProxy : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | SceneProxy(Scene *scene); 15 | Q_INVOKABLE QSize size() const; 16 | Q_INVOKABLE QJSValue entities() const; 17 | 18 | 19 | 20 | private: 21 | Scene *m_scene; 22 | 23 | }; 24 | 25 | #endif // SCENEPROXY_H 26 | -------------------------------------------------------------------------------- /Chapter10/Scripting/scripted_game/scripts/2.js: -------------------------------------------------------------------------------- 1 | { 2 | "step": function(current) { 3 | // helper function to get random integer in [min, max) 4 | function getRandomInt(min, max) { 5 | return Math.floor(Math.random() * (max - min)) + min; 6 | } 7 | // select a random move 8 | return { 9 | x: current.pos().x + getRandomInt(-1, 2), 10 | y: current.pos().y + getRandomInt(-1, 2), 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver1/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import QtQuick.Controls 2.2 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | TextField { 11 | id: textField 12 | text: "Edit me" 13 | anchors { 14 | top: parent.top 15 | left: parent.left 16 | } 17 | } 18 | Label { 19 | text: { 20 | var x = textField.text; 21 | return "(" + x + ")"; 22 | } 23 | anchors { 24 | top: textField.bottom 25 | topMargin: 20 26 | left: parent.left 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver1/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver2/Calculator.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.4 2 | 3 | CalculatorForm { 4 | } 5 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver2/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import QtQuick.Controls 2.2 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | Calculator { 11 | anchors.fill: parent 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver2/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Calculator.qml 5 | CalculatorForm.ui.qml 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver3/Calculator.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.4 2 | 3 | CalculatorForm { 4 | reset.onClicked: { 5 | argument1.text = "0"; 6 | argument2.text = "0"; 7 | operationAdd.checked = true; 8 | } 9 | result.text: { 10 | var value1 = parseFloat(argument1.text); 11 | var value2 = parseFloat(argument2.text); 12 | if(operationMultiply.checked) { 13 | return value1 * value2; 14 | } else if (operationFactorial.checked) { 15 | return advancedCalculator.factorial(value1); 16 | } else { 17 | return value1 + value2; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver3/advancedcalculator.cpp: -------------------------------------------------------------------------------- 1 | #include "advancedcalculator.h" 2 | #include 3 | AdvancedCalculator::AdvancedCalculator(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | double AdvancedCalculator::factorial(int argument) { 9 | if (argument < 0) { 10 | return std::numeric_limits::quiet_NaN(); 11 | } 12 | if (argument > 180) { 13 | return std::numeric_limits::infinity(); 14 | } 15 | double r = 1.0; 16 | for(int i = 2; i <= argument; ++i) { 17 | r *= i; 18 | } 19 | return r; 20 | } 21 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver3/advancedcalculator.h: -------------------------------------------------------------------------------- 1 | #ifndef ADVANCEDCALCULATOR_H 2 | #define ADVANCEDCALCULATOR_H 3 | 4 | #include 5 | 6 | class AdvancedCalculator : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit AdvancedCalculator(QObject *parent = nullptr); 11 | Q_INVOKABLE double factorial(int argument); 12 | 13 | signals: 14 | 15 | public slots: 16 | }; 17 | 18 | #endif // ADVANCEDCALCULATOR_H 19 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver3/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import QtQuick.Controls 2.2 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Calculator") 9 | 10 | Calculator { 11 | anchors.fill: parent 12 | objectName: "calculator" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver3/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Calculator.qml 5 | CalculatorForm.ui.qml 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver4/advancedcalculator.cpp: -------------------------------------------------------------------------------- 1 | #include "advancedcalculator.h" 2 | #include 3 | AdvancedCalculator::AdvancedCalculator(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | double AdvancedCalculator::factorial(int argument) { 9 | if (argument < 0) { 10 | return std::numeric_limits::quiet_NaN(); 11 | } 12 | if (argument > 180) { 13 | return std::numeric_limits::infinity(); 14 | } 15 | double r = 1.0; 16 | for(int i = 2; i <= argument; ++i) { 17 | r *= i; 18 | } 19 | return r; 20 | } 21 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver4/advancedcalculator.h: -------------------------------------------------------------------------------- 1 | #ifndef ADVANCEDCALCULATOR_H 2 | #define ADVANCEDCALCULATOR_H 3 | 4 | #include 5 | 6 | class AdvancedCalculator : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit AdvancedCalculator(QObject *parent = nullptr); 11 | Q_INVOKABLE double factorial(int argument); 12 | 13 | signals: 14 | 15 | public slots: 16 | }; 17 | 18 | #endif // ADVANCEDCALCULATOR_H 19 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver4/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "advancedcalculator.h" 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | #if defined(Q_OS_WIN) 10 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 11 | #endif 12 | 13 | QGuiApplication app(argc, argv); 14 | 15 | QQmlApplicationEngine engine; 16 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 17 | if (engine.rootObjects().isEmpty()) 18 | return -1; 19 | engine.globalObject().setProperty("advancedCalculator", 20 | engine.newQObject(new AdvancedCalculator)); 21 | 22 | return app.exec(); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver4/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import QtQuick.Controls 2.2 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Calculator") 9 | 10 | Calculator { 11 | anchors.fill: parent 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter11/Introduction to Qt Quick/calculator/ver4/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Calculator.qml 5 | CalculatorForm.ui.qml 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/canvas/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/canvas/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/clock/Needle.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Rectangle { 4 | id: root 5 | 6 | property int value: 0 7 | property int granularity: 60 8 | property alias length: root.height 9 | 10 | width: 2 11 | height: parent.height / 2 12 | radius: width / 2 13 | antialiasing: true 14 | anchors.bottom: parent.verticalCenter 15 | anchors.horizontalCenter: parent.horizontalCenter 16 | transformOrigin: Item.Bottom 17 | rotation: 360 / granularity * (value % granularity) 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/clock/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/clock/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | Clock { 11 | id: clock 12 | anchors { 13 | fill: parent 14 | margins: 20 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/clock/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Clock.qml 5 | Needle.qml 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/custom_button/edit-undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter12/Customization in Qt Quick/custom_button/edit-undo.png -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/custom_button/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/custom_button/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | Button { 11 | id: button 12 | anchors.centerIn: parent 13 | 14 | onClicked: console.log("Clicked!") 15 | 16 | onPressedChanged: { 17 | console.log("The button is currently " + 18 | (pressed ? "" : "not ") + "pressed") 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/custom_button/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | edit-undo.png 5 | Button.qml 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/dashboard/Label.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Text { 4 | color: "white" 5 | font.pixelSize: 24 6 | } 7 | 8 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/dashboard/carinfoengine.cpp: -------------------------------------------------------------------------------- 1 | #include "carinfoengine.h" 2 | 3 | CarInfoEngine::CarInfoEngine(QObject *parent) : 4 | QObject(parent), m_gear(4) 5 | { 6 | 7 | } 8 | 9 | int CarInfoEngine::gear() const { 10 | return m_gear; 11 | } 12 | 13 | int CarInfoEngine::rpm() const 14 | { 15 | return m_rpm; 16 | } 17 | 18 | void CarInfoEngine::setGear(int g) { 19 | if(m_gear == g) { 20 | return; 21 | } 22 | m_gear = g; 23 | emit gearChanged(g); 24 | } 25 | 26 | void CarInfoEngine::setRpm(int arg) 27 | { 28 | if (m_rpm == arg) { 29 | return; 30 | } 31 | m_rpm = arg; 32 | emit rpmChanged(arg); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/dashboard/carinfoengine.h: -------------------------------------------------------------------------------- 1 | #ifndef CARINFOENGINE_H 2 | #define CARINFOENGINE_H 3 | 4 | #include 5 | 6 | class CarInfoEngine : public QObject { 7 | Q_OBJECT 8 | Q_PROPERTY(int gear READ gear WRITE setGear NOTIFY gearChanged) 9 | Q_PROPERTY(int rpm READ rpm WRITE setRpm NOTIFY rpmChanged) 10 | public: 11 | CarInfoEngine(QObject *parent = 0); 12 | int gear() const; 13 | int rpm() const; 14 | 15 | public slots: 16 | void setGear(int g); 17 | void setRpm(int arg); 18 | 19 | signals: 20 | void gearChanged(int); 21 | void rpmChanged(int arg); 22 | 23 | private: 24 | int m_gear; 25 | int m_rpm; 26 | }; 27 | 28 | #endif // CARINFOENGINE_H 29 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/dashboard/dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter12/Customization in Qt Quick/dashboard/dashboard.png -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/dashboard/dashboard.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = dashboard 3 | INCLUDEPATH += . 4 | 5 | SOURCES += main.cpp \ 6 | carinfo.cpp \ 7 | carinfoengine.cpp \ 8 | carinfoproxy.cpp 9 | 10 | QT += quick widgets 11 | 12 | FORMS += form.ui 13 | 14 | HEADERS += \ 15 | carinfo.h \ 16 | carinfoengine.h \ 17 | carinfoproxy.h 18 | 19 | RESOURCES += \ 20 | resources.qrc 21 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/dashboard/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | dashboard.png 5 | Needle.qml 6 | Label.qml 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/drag/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/drag/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | Rectangle { 11 | id: circle 12 | width: 60; height: width 13 | radius: width/2 14 | color: "red" 15 | 16 | MouseArea { 17 | anchors.fill: parent 18 | drag.target: circle 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/drag/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/load_component/Circle.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Item { 4 | property int diameter: 20 5 | property alias color: rect.color 6 | property alias border: rect.border 7 | 8 | implicitWidth: diameter 9 | implicitHeight: diameter 10 | 11 | Rectangle { 12 | id: rect 13 | width: radius 14 | height: radius 15 | radius: diameter / 2 16 | anchors.centerIn: parent 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/load_component/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/load_component/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Circle.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/pinch/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/pinch/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | Image { 11 | id: image 12 | anchors.centerIn: parent 13 | source: "qrc:/wilanow.jpg" 14 | } 15 | 16 | PinchArea { 17 | anchors.fill: parent 18 | pinch { 19 | target: image 20 | minimumScale: 0.2 21 | maximumScale: 2.0 22 | minimumRotation: -90 23 | maximumRotation: 90 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/pinch/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | wilanow.jpg 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/pinch/wilanow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter12/Customization in Qt Quick/pinch/wilanow.jpg -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/positioning/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 7 | 8 | QGuiApplication app(argc, argv); 9 | 10 | QQmlApplicationEngine engine; 11 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 12 | if (engine.rootObjects().isEmpty()) 13 | return -1; 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/positioning/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import QtPositioning 5.0 4 | 5 | Window { 6 | visible: true 7 | width: 640 8 | height: 480 9 | title: qsTr("Hello World") 10 | Text { 11 | anchors.centerIn: parent 12 | text: { 13 | var pos = positionSource.position; 14 | var coordinate = pos.coordinate; 15 | return "latitude: " + coordinate.latitude + 16 | "\nlongitude: " + coordinate.longitude; 17 | } 18 | } 19 | PositionSource { 20 | id: positionSource 21 | active: true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/positioning/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/tilt_sensor/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 7 | 8 | QGuiApplication app(argc, argv); 9 | 10 | QQmlApplicationEngine engine; 11 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 12 | if (engine.rootObjects().isEmpty()) 13 | return -1; 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter12/Customization in Qt Quick/tilt_sensor/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver01/actiongame_ver01.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver01/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver01/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver01/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver01/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver01/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver01/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver02/actiongame_ver02.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver02/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver02/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver02/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver02/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver02/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver02/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver03/actiongame_ver03.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver03/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver03/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver03/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver03/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver03/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver03/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver04/actiongame_ver04.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver04/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver04/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver04/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver04/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver04/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver04/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver05/actiongame_ver05.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver05/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver05/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver05/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver05/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver05/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver05/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver06/actiongame_ver06.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver06/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver06/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver06/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver06/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver06/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver06/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/actiongame_ver07.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver07/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/actiongame_ver08.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver08/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/actiongame_ver09.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver09/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/actiongame_ver10.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_1.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_2.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_3.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_4.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_5.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_6.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver10/images/walking_7.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/actiongame_ver11.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/sprite.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver11/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/actiongame_ver12.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/sprite.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver12/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/ParallaxLayer.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Item { 4 | property real factor: 0 5 | x: factor > 0 ? -parent.currentPos/factor - parent.x : 0 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/ParallaxScene.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Item { 4 | id: root 5 | property int currentPos 6 | x: -currentPos*(root.width - root.parent.width)/width 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/actiongame_ver13.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/sprite.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver13/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/Coin.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/Coin.qmlc -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/ParallaxLayer.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Item { 4 | property real factor: 0 5 | x: factor > 0 ? -parent.currentPos/factor - parent.x : 0 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/ParallaxLayer.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/ParallaxLayer.qmlc -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/ParallaxScene.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Item { 4 | id: root 5 | property int currentPos 6 | x: -currentPos*(root.width - root.parent.width)/width 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/ParallaxScene.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/ParallaxScene.qmlc -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/Player.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/Player.qmlc -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/actiongame_ver14.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/coins.js: -------------------------------------------------------------------------------- 1 | .import "collisions.js" as Collisions 2 | 3 | var coins = [] 4 | 5 | coins.collisionsWith = function(player) { 6 | var collisions = [] 7 | for(var index = 0; index < coins.length; ++index) { 8 | var obj = this[index] 9 | if(Collisions.intersect(player, obj)) collisions.push(obj) 10 | } 11 | return collisions 12 | } 13 | 14 | coins.remove = function(obj) { 15 | var arr = Array.isArray(obj) ? obj : [ obj ] 16 | var L = arr.length 17 | var idx, needle 18 | while(L && this.length) { 19 | needle = arr[--L] 20 | idx = this.indexOf(needle) 21 | if(idx !== -1) { this.splice(idx, 1) } 22 | } 23 | return this 24 | } 25 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/coins.jsc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/coins.jsc -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/collisions.jsc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/collisions.jsc -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/elephant.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/grass.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/sky.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/sprite.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/images/trees.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/main.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/actiongame/actiongame_ver14/main.qmlc -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/dashboard/Label.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Text { 4 | color: "white" 5 | font.pixelSize: 24 6 | } 7 | 8 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/dashboard/carinfoengine.cpp: -------------------------------------------------------------------------------- 1 | #include "carinfoengine.h" 2 | 3 | CarInfoEngine::CarInfoEngine(QObject *parent) : 4 | QObject(parent), m_gear(4) 5 | { 6 | 7 | } 8 | 9 | int CarInfoEngine::gear() const { 10 | return m_gear; 11 | } 12 | 13 | int CarInfoEngine::rpm() const 14 | { 15 | return m_rpm; 16 | } 17 | 18 | void CarInfoEngine::setGear(int g) { 19 | if(m_gear == g) { 20 | return; 21 | } 22 | m_gear = g; 23 | emit gearChanged(g); 24 | } 25 | 26 | void CarInfoEngine::setRpm(int arg) 27 | { 28 | if (m_rpm == arg) { 29 | return; 30 | } 31 | m_rpm = arg; 32 | emit rpmChanged(arg); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/dashboard/carinfoengine.h: -------------------------------------------------------------------------------- 1 | #ifndef CARINFOENGINE_H 2 | #define CARINFOENGINE_H 3 | 4 | #include 5 | 6 | class CarInfoEngine : public QObject { 7 | Q_OBJECT 8 | Q_PROPERTY(int gear READ gear WRITE setGear NOTIFY gearChanged) 9 | Q_PROPERTY(int rpm READ rpm WRITE setRpm NOTIFY rpmChanged) 10 | public: 11 | CarInfoEngine(QObject *parent = 0); 12 | int gear() const; 13 | int rpm() const; 14 | 15 | public slots: 16 | void setGear(int g); 17 | void setRpm(int arg); 18 | 19 | signals: 20 | void gearChanged(int); 21 | void rpmChanged(int arg); 22 | 23 | private: 24 | int m_gear; 25 | int m_rpm; 26 | }; 27 | 28 | #endif // CARINFOENGINE_H 29 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/dashboard/dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter13/Animations in Qt Quick games/dashboard/dashboard.png -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/dashboard/dashboard.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = dashboard 3 | INCLUDEPATH += . 4 | 5 | SOURCES += main.cpp \ 6 | carinfo.cpp \ 7 | carinfoengine.cpp \ 8 | carinfoproxy.cpp 9 | 10 | QT += quick widgets 11 | 12 | FORMS += form.ui 13 | 14 | HEADERS += \ 15 | carinfo.h \ 16 | carinfoengine.h \ 17 | carinfoproxy.h 18 | 19 | RESOURCES += \ 20 | resources.qrc 21 | -------------------------------------------------------------------------------- /Chapter13/Animations in Qt Quick games/dashboard/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | dashboard.png 5 | Needle.qml 6 | Label.qml 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/Coin.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/Coin.qmlc -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/ParallaxLayer.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Item { 4 | property real factor: 0 5 | x: factor > 0 ? -parent.currentPos/factor - parent.x : 0 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/ParallaxLayer.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/ParallaxLayer.qmlc -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/ParallaxScene.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | 3 | Item { 4 | id: root 5 | property int currentPos 6 | x: -currentPos*(root.width - root.parent.width)/width 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/ParallaxScene.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/ParallaxScene.qmlc -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/Player.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/Player.qmlc -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/actiongame.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/coins.js: -------------------------------------------------------------------------------- 1 | .import "collisions.js" as Collisions 2 | 3 | var coins = [] 4 | 5 | coins.collisionsWith = function(player) { 6 | var collisions = [] 7 | for(var index = 0; index < coins.length; ++index) { 8 | var obj = this[index] 9 | if(Collisions.intersect(player, obj)) collisions.push(obj) 10 | } 11 | return collisions 12 | } 13 | 14 | coins.remove = function(obj) { 15 | var arr = Array.isArray(obj) ? obj : [ obj ] 16 | var L = arr.length 17 | var idx, needle 18 | while(L && this.length) { 19 | needle = arr[--L] 20 | idx = this.indexOf(needle) 21 | if(idx !== -1) { this.splice(idx, 1) } 22 | } 23 | return this 24 | } 25 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/coins.jsc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/coins.jsc -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/collisions.js: -------------------------------------------------------------------------------- 1 | .pragma library 2 | 3 | function boundingBox(object1) { 4 | var cR = object1.childrenRect 5 | var mapped = object1.mapToItem(object1.parent, cR.x, cR.y, 6 | cR.width, cR.height) 7 | return Qt.rect(mapped.x, mapped.y, mapped.width, mapped.height) 8 | } 9 | 10 | function intersect(object1, object2) { 11 | var r1 = boundingBox(object1) 12 | var r2 = boundingBox(object2) 13 | return (r1.x <= r2.x+r2.width && // r1.left <= r2.right 14 | r2.x <= r1.x+r1.width && // r2.left <= r1.right 15 | r1.y <= r2.y+r2.height && // r1.top <= r2.bottom 16 | r2.y <= r1.y+r1.height) // r2.top <= r1.bottom 17 | } 18 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/collisions.jsc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/collisions.jsc -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/elephant.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/grass.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/particle.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/sky.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/sprite.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/images/trees.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/main.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/actiongame ver15/main.qmlc -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/flickable/UI.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | width: 300 5 | height: 300 6 | 7 | gradient: Gradient { 8 | GradientStop { position: 0.0; color: "lightsteelblue" } 9 | GradientStop { position: 1.0; color: "blue" } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/flickable/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/flickable/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | Flickable { 11 | id: uiFlickable 12 | anchors.centerIn: parent 13 | contentWidth: ui.width 14 | contentHeight: ui.height 15 | 16 | width: parent.width >= contentWidth ? 17 | contentWidth : parent.width 18 | height: parent.height >= contentHeight ? 19 | contentHeight : parent.height 20 | 21 | UI { 22 | id: ui 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/flickable/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | UI.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/glow/Badge.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Text { 4 | text: qsTr("Attention!") 5 | font.pointSize: 42 6 | } 7 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/glow/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/glow/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Badge.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/heartbeat/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/heartbeat/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | HeartBeat.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/outlinedtext/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "outlinetextitem.h" 5 | #include "outlinetextitemborder.h" 6 | 7 | int main(int argc, char **argv) { 8 | QGuiApplication app(argc, argv); 9 | qmlRegisterUncreatableType( 10 | "OutlineTextItem", 1, 0, "OutlineTextItemBorder", ""); 11 | qmlRegisterType( 12 | "OutlineTextItem", 1, 0, "OutlineTextItem"); 13 | 14 | QQmlApplicationEngine engine; 15 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 16 | if (engine.rootObjects().isEmpty()) 17 | return -1; 18 | 19 | return app.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/outlinedtext/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.3 3 | import OutlineTextItem 1.0 4 | 5 | Window { 6 | visible: true 7 | width: 800 8 | height: 400 9 | title: qsTr("Hello World") 10 | 11 | Rectangle { 12 | anchors.fill: parent 13 | OutlineTextItem { 14 | anchors.centerIn: parent 15 | text: "This is outlined text" 16 | fontFamily: "Arial" 17 | fontPixelSize: 64 18 | color: "#33ff0000" 19 | antialiasing: true 20 | border { 21 | color: "blue" 22 | width: 2 23 | style: Qt.DotLine 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/outlinedtext/outlinedtext.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = outlinedtext 3 | INCLUDEPATH += . 4 | 5 | SOURCES += main.cpp outlinetextitem.cpp \ 6 | outlinetextitemborder.cpp 7 | 8 | QT += quick 9 | 10 | HEADERS += outlinetextitem.h \ 11 | outlinetextitemborder.h 12 | 13 | RESOURCES += \ 14 | resources.qrc 15 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/outlinedtext/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/particle_system/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/particle_system/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | star.png 5 | star_white.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/particle_system/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/particle_system/star.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/particle_system/star_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter14/Advanced visual effects in Qt Quick/particle_system/star_white.png -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/regularpolygon/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "regularpolygon.h" 7 | 8 | int main(int argc, char **argv) { 9 | QGuiApplication app(argc, argv); 10 | QSurfaceFormat format = QSurfaceFormat::defaultFormat(); 11 | format.setSamples(16); 12 | QSurfaceFormat::setDefaultFormat(format); 13 | 14 | qmlRegisterType("RegularPolygon", 1, 0, "RegularPolygon"); 15 | 16 | QQmlApplicationEngine engine; 17 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 18 | if (engine.rootObjects().isEmpty()) 19 | return -1; 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/regularpolygon/regularpolygon.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = regularpolygon 3 | INCLUDEPATH += . 4 | 5 | SOURCES += main.cpp regularpolygon.cpp 6 | 7 | QT += quick 8 | 9 | HEADERS += regularpolygon.h 10 | 11 | DISTFILES += regoply.qml 12 | 13 | RESOURCES += \ 14 | resources.qrc 15 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/regularpolygon/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled/UI.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | width: 300 5 | height: 300 6 | 7 | gradient: Gradient { 8 | GradientStop { position: 0.0; color: "lightsteelblue" } 9 | GradientStop { position: 1.0; color: "blue" } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | UI { 11 | id: ui 12 | 13 | anchors.centerIn: parent 14 | scale: Math.min(parent.width / width, 15 | parent.height / height) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | UI.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled2/UI.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | width: 300 5 | height: 300 6 | 7 | gradient: Gradient { 8 | GradientStop { position: 0.0; color: "lightsteelblue" } 9 | GradientStop { position: 1.0; color: "blue" } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled2/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | Item { 11 | anchors { 12 | fill: parent 13 | margins: 10 14 | } 15 | 16 | UI { 17 | id: ui 18 | 19 | anchors.centerIn: parent 20 | scale: Math.min(parent.width / width, 21 | parent.height / height) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter14/Advanced visual effects in Qt Quick/scaled2/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | UI.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/hanoi/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | QGuiApplication app(argc, argv); 7 | Qt3DExtras::Quick::Qt3DQuickWindow window; 8 | window.setSource(QUrl("qrc:/main.qml")); 9 | window.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/hanoi/obj/disk.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter15/3D graphics with Qt/hanoi/obj/disk.blend -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/hanoi/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Scene.qml 5 | Rod.qml 6 | Disk.qml 7 | DiskAnimation.qml 8 | obj/disk0.obj 9 | obj/disk1.obj 10 | obj/disk2.obj 11 | obj/disk3.obj 12 | obj/disk4.obj 13 | obj/disk5.obj 14 | obj/disk6.obj 15 | obj/disk7.obj 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/scene2d/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | QGuiApplication app(argc, argv); 7 | Qt3DExtras::Quick::Qt3DQuickWindow window; 8 | window.setSource(QUrl("qrc:/main.qml")); 9 | window.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/scene2d/main.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter15/3D graphics with Qt/scene2d/main.qmlc -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/scene2d/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/scene3d/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #if defined(Q_OS_WIN) 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | #endif 9 | 10 | QGuiApplication app(argc, argv); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/scene3d/main.qmlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter15/3D graphics with Qt/scene3d/main.qmlc -------------------------------------------------------------------------------- /Chapter15/3D graphics with Qt/scene3d/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | My3DScene.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/qml_sound/example.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter16/Miscellaneous and Advanced Concepts/qml_sound/example.ogg -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/qml_sound/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 7 | 8 | QGuiApplication app(argc, argv); 9 | 10 | QQmlApplicationEngine engine; 11 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 12 | if (engine.rootObjects().isEmpty()) 13 | return -1; 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/qml_sound/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | example.ogg 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/record_and_play_sound/main.cpp: -------------------------------------------------------------------------------- 1 | #include "recordandplaysound.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | RecordAndPlaySound mainWindow; 8 | mainWindow.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/record_and_play_sound/record_and_play_sound.pro: -------------------------------------------------------------------------------- 1 | QT += core gui widgets multimedia 2 | 3 | TARGET = RecordAndPlaySound 4 | TEMPLATE = app 5 | 6 | SOURCES += main.cpp \ 7 | recordandplaysound.cpp 8 | 9 | HEADERS += recordandplaysound.h 10 | 11 | FORMS += recordandplaysound.ui 12 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/shared_memory/server/gameserver.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMESERVER_H 2 | #define GAMESERVER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | 11 | class GameServer : public QObject { 12 | Q_OBJECT 13 | public: 14 | GameServer(); 15 | ~GameServer(); 16 | 17 | private slots: 18 | void writeState(); 19 | 20 | private: 21 | QSharedMemory m_sharedMemory; 22 | QElapsedTimer m_elapsedTimer; 23 | QSlider *m_slider; 24 | }; 25 | 26 | #endif // GAMESERVER_H 27 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/shared_memory/server/gamestats.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMESTATS_H 2 | #define GAMESTATS_H 3 | 4 | #include 5 | 6 | struct GameStats { 7 | quint32 playerCount = 0; 8 | quint32 uptime = 0; 9 | }; 10 | 11 | #endif // GAMESTATS_H 12 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/shared_memory/server/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "gameserver.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | GameServer server; 8 | 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/threading/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/threading/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include "worker.h" 7 | 8 | namespace Ui { 9 | class Widget; 10 | } 11 | 12 | class Widget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Widget(QWidget *parent = 0); 18 | ~Widget(); 19 | 20 | private: 21 | Ui::Widget *ui; 22 | QThread* m_workerThread; 23 | Worker* m_worker; 24 | 25 | private slots: 26 | void start(); 27 | void workerFinished(float result); 28 | }; 29 | 30 | 31 | #endif // WIDGET_H 32 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/threading/worker.cpp: -------------------------------------------------------------------------------- 1 | #include "worker.h" 2 | #include 3 | #include 4 | #include 5 | 6 | Worker::Worker(QObject *parent) : QObject(parent) 7 | { 8 | 9 | } 10 | 11 | Worker::~Worker() 12 | { 13 | qDebug() << "worker deleted"; 14 | } 15 | 16 | void Worker::calculate() { 17 | float x = 0; 18 | for(int i = 0; i < 100000000; i++) { 19 | x += sin(i); 20 | } 21 | emit finished(x); 22 | } 23 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/threading/worker.h: -------------------------------------------------------------------------------- 1 | #ifndef WORKER_H 2 | #define WORKER_H 3 | 4 | #include 5 | 6 | class Worker : public QObject { 7 | Q_OBJECT 8 | public: 9 | explicit Worker(QObject *parent = nullptr); 10 | ~Worker(); 11 | 12 | public slots: 13 | void calculate(); 14 | 15 | signals: 16 | void finished(float result); 17 | 18 | }; 19 | 20 | #endif // WORKER_H 21 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/translations/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | 10 | QTranslator translator; 11 | if (!translator.load(QLocale::German, ":/translations/myapp_")) { 12 | qWarning() << "failed to load translation"; 13 | } 14 | app.installTranslator(&translator); 15 | 16 | Widget w; 17 | w.show(); 18 | 19 | return app.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/translations/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | translations/myapp_ru.qm 4 | translations/myapp_de.qm 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/translations/translations/myapp_de.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter16/Miscellaneous and Advanced Concepts/translations/translations/myapp_de.qm -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/translations/translations/myapp_ru.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition/4c95eecd43024e385344ec13f19842fd8b3855ed/Chapter16/Miscellaneous and Advanced Concepts/translations/translations/myapp_ru.qm -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/translations/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Widget; 8 | } 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Widget(QWidget *parent = 0); 16 | ~Widget(); 17 | 18 | private: 19 | Ui::Widget *ui; 20 | 21 | private slots: 22 | void leftClicked(); 23 | void rightClicked(); 24 | }; 25 | 26 | #endif // WIDGET_H 27 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/websockets_qml/client/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 7 | 8 | QGuiApplication app(argc, argv); 9 | 10 | QQmlApplicationEngine engine; 11 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 12 | if (engine.rootObjects().isEmpty()) 13 | return -1; 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/websockets_qml/client/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import QtWebSockets 1.0 4 | 5 | Window { 6 | visible: true 7 | width: 640 8 | height: 480 9 | title: qsTr("Client") 10 | 11 | WebSocket { 12 | id: socket 13 | url: "ws://localhost:8080" 14 | active: true 15 | onStatusChanged: { 16 | console.log("Client status changed: ", status); 17 | if(status == WebSocket.Open) { 18 | sendTextMessage("Hello!"); 19 | } 20 | } 21 | onTextMessageReceived: { 22 | console.log("Client received message: ", message); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/websockets_qml/client/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/websockets_qml/server/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 7 | 8 | QGuiApplication app(argc, argv); 9 | 10 | QQmlApplicationEngine engine; 11 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 12 | if (engine.rootObjects().isEmpty()) 13 | return -1; 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/websockets_qml/server/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import QtWebSockets 1.0 4 | 5 | Window { 6 | visible: true 7 | width: 640 8 | height: 480 9 | title: qsTr("Server") 10 | 11 | 12 | WebSocketServer { 13 | id: socketServer 14 | listen: true 15 | port: 8080 16 | onClientConnected: { 17 | webSocket.onTextMessageReceived.connect(function(message) { 18 | console.log("Server received message: ", message); 19 | webSocket.sendTextMessage("Server says 'Hello!'"); 20 | }); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter16/Miscellaneous and Advanced Concepts/websockets_qml/server/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | --------------------------------------------------------------------------------