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 | #include "gameview.h" |
19 | #include "gamescene.h" |
20 | |
21 | GameView::GameView(Game * p_game) : QGraphicsView(new GameScene(p_game)) { |
22 | setFrameStyle(QFrame::NoFrame); |
23 | setFocusPolicy(Qt::StrongFocus); |
24 | // Forward the key press events to the Game instance |
25 | connect(this, SIGNAL(keyPressed(QKeyEvent*)), p_game, SLOT(keyPressEvent(QKeyEvent*))); |
26 | } |
27 | |
28 | GameView::~GameView() { |
29 | |
30 | } |
31 | |
32 | void GameView::resizeEvent(QResizeEvent*) { |
33 | fitInView(sceneRect(), Qt::KeepAspectRatio); |
34 | } |
35 | |
36 | void GameView::focusOutEvent(QFocusEvent*) { |
37 | // Pause the game if it is not already paused |
38 | if (((GameScene*)scene())->getGame()->getTimer()->isActive()) { |
39 | ((GameScene*)scene())->getGame()->switchPause(); |
40 | } |
41 | } |
42 | |
43 | void GameView::keyPressEvent(QKeyEvent* p_event) { |
44 | emit(keyPressed(p_event)); |
45 | } |
46 | |
47 |