1 | /* |
2 | * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> |
3 | * |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License as |
6 | * published by the Free Software Foundation; either version 2 of |
7 | * the License, or (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #ifndef GAMEVIEW_H |
19 | #define GAMEVIEW_H |
20 | |
21 | #include "game.h" |
22 | |
23 | #include <QGraphicsView> |
24 | #include <QKeyEvent> |
25 | |
26 | /** |
27 | * @brief This class manages the drawing of each element of the Game instance. |
28 | * 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. |
29 | */ |
30 | class GameView : public QGraphicsView { |
31 | |
32 | Q_OBJECT |
33 | |
34 | public: |
35 | |
36 | /** |
37 | * Creates a new GameView instance. |
38 | * @param p_game the Game instance whose elements have to be drawn |
39 | */ |
40 | GameView(Game* p_game); |
41 | |
42 | /** |
43 | * Deletes the GameView instance. |
44 | */ |
45 | ~GameView(); |
46 | |
47 | /** |
48 | * Resizes the items when the view is resized. |
49 | * @param p_event the resize event |
50 | */ |
51 | void resizeEvent(QResizeEvent* p_event); |
52 | |
53 | protected: |
54 | |
55 | /** |
56 | * Manages the player actions by hanlding the key press events. |
57 | * @param p_event the key press event |
58 | */ |
59 | void keyPressEvent(QKeyEvent* p_event); |
60 | |
61 | /** |
62 | * Pauses the game on focus lost. |
63 | * @param p_event the focus event |
64 | */ |
65 | void focusOutEvent(QFocusEvent* p_event); |
66 | |
67 | signals: |
68 | |
69 | /** |
70 | * Emitted on key press event for the Game instance |
71 | * @param p_event the key press event |
72 | */ |
73 | void keyPressed(QKeyEvent* p_event); |
74 | }; |
75 | |
76 | #endif |
77 | |
78 | |