2
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
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.
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.
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/>.
19
#include "gamescene.h"
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*)));
28
GameView::~GameView() {
32
void GameView::resizeEvent(QResizeEvent*) {
33
fitInView(sceneRect(), Qt::KeepAspectRatio);
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();
43
void GameView::keyPressEvent(QKeyEvent* p_event) {
44
emit(keyPressed(p_event));