• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kapman

  • sources
  • kde-4.14
  • kdegames
  • kapman
gameview.cpp
Go to the documentation of this file.
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 
QResizeEvent
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
GameView::GameView
GameView(Game *p_game)
Creates a new GameView instance.
Definition: gameview.cpp:21
QGraphicsView::sceneRect
QRectF sceneRect() const
QFrame::setFrameStyle
void setFrameStyle(int style)
QGraphicsView::scene
QGraphicsScene * scene() const
GameView::keyPressed
void keyPressed(QKeyEvent *p_event)
Emitted on key press event for the Game instance.
GameView::focusOutEvent
void focusOutEvent(QFocusEvent *p_event)
Pauses the game on focus lost.
Definition: gameview.cpp:36
GameView::resizeEvent
void resizeEvent(QResizeEvent *p_event)
Resizes the items when the view is resized.
Definition: gameview.cpp:32
gameview.h
Game
This class manages the game main loop : it regularly checks the key press events, computes the charac...
Definition: game.h:35
gamescene.h
QKeyEvent
GameView::keyPressEvent
void keyPressEvent(QKeyEvent *p_event)
Manages the player actions by hanlding the key press events.
Definition: gameview.cpp:43
GameScene
This class contains all the Game elements to be drawn on the screen by the GameView instance...
Definition: gamescene.h:38
GameView::~GameView
~GameView()
Deletes the GameView instance.
Definition: gameview.cpp:28
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QFocusEvent
QGraphicsView
QGraphicsView::fitInView
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRatioMode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapman

Skip menu "kapman"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal