File indexing completed on 2024-04-21 07:49:08

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef GAMEVIEW_H
0008 #define GAMEVIEW_H
0009 
0010 #include "game.h"
0011 
0012 #include <QGraphicsView>
0013 #include <QKeyEvent>
0014 
0015 class KGameTheme;
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      * Creates a new GameView instance.
0028      * @param p_game the Game instance whose elements have to be drawn
0029      */
0030     explicit GameView(Game *p_game, const KGameTheme *theme);
0031 
0032     /**
0033      * Deletes the GameView instance.
0034      */
0035     ~GameView() override;
0036 
0037     /**
0038      * Resizes the items when the view is resized.
0039      * @param p_event the resize event
0040      */
0041     void resizeEvent(QResizeEvent *p_event) override;
0042 
0043 protected:
0044     /**
0045      * Manages the player actions by hanlding the key press events.
0046      * @param p_event the key press event
0047      */
0048     void keyPressEvent(QKeyEvent *p_event) override;
0049 
0050     /**
0051      * Pauses the game on focus lost.
0052      * @param p_event the focus event
0053      */
0054     void focusOutEvent(QFocusEvent *p_event) override;
0055 
0056 Q_SIGNALS:
0057 
0058     /**
0059      * Emitted on key press event for the Game instance
0060      * @param p_event the key press event
0061      */
0062     void keyPressed(QKeyEvent *p_event);
0063 };
0064 
0065 #endif