File indexing completed on 2024-04-14 03:59:06

0001 /*
0002     SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de>
0003     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef GAMEVIEW_H
0009 #define GAMEVIEW_H
0010 
0011 #include <QGraphicsView>
0012 
0013 class QKeyEvent;
0014 class Game;
0015 class GameScene;
0016 
0017 /**
0018  * @brief This class manages the drawing of each element of the Game instance.
0019  * It creates a GameScene instance associated to the given Game instance in order to manage the elements to be drawn at each moment of the game.
0020  */
0021 class GameView : public QGraphicsView {
0022 
0023 Q_OBJECT
0024 
0025 public:
0026 
0027     /**
0028       * Creates a new GameView instance.
0029       * @param p_scene the Game scene
0030       * @param p_game the Game instance whose elements have to be drawn
0031       */
0032     GameView(GameScene* p_scene, Game* p_game);
0033 
0034     /**
0035       * Deletes the GameView instance.
0036       */
0037     ~GameView() override;
0038 
0039     /**
0040       * Resizes the items when the view is resized.
0041       * @param p_event the resize event
0042       */
0043     void resizeEvent(QResizeEvent* p_event) override;
0044 
0045 protected:
0046 
0047     /**
0048       * Manages the player actions by hanlding the key press events.
0049       * @param p_event the key press event
0050       */
0051     void keyPressEvent(QKeyEvent* p_event) override;
0052 
0053     /**
0054       * Manages the player actions by hanlding the key release events.
0055       * @param p_event the key release event
0056       */
0057     void keyReleaseEvent(QKeyEvent* p_event) override;
0058 
0059     /**
0060       * Pauses the game on focus lost.
0061       * @param p_event the focus event
0062       */
0063     void focusOutEvent(QFocusEvent* p_event) override;
0064 
0065 Q_SIGNALS:
0066 
0067     /**
0068       * Emitted on key press event for the Game instance
0069       * @param p_event the key press event
0070       */
0071     void keyPressed(QKeyEvent* p_event);
0072 
0073     /**
0074       * Emitted on key release event for the Game instance
0075       * @param p_event the key release event
0076       */
0077     void keyReleased(QKeyEvent* p_event);
0078 };
0079 
0080 #endif
0081