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

granatier

  • sources
  • kde-4.14
  • kdegames
  • granatier
  • src
gameview.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
3  * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "gameview.h"
20 #include "gamescene.h"
21 #include "game.h"
22 
23 #include <QKeyEvent>
24 #include <QTimer>
25 
26 GameView::GameView(GameScene* p_scene, Game * p_game) : QGraphicsView(p_scene)
27 {
28  setFrameStyle(QFrame::NoFrame);
29  setFocusPolicy(Qt::StrongFocus);
30  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
31  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
32 
33  // Forward the key press events to the Game instance
34  connect(this, SIGNAL(keyPressed(QKeyEvent*)), p_game, SLOT(keyPressEvent(QKeyEvent*)));
35  connect(this, SIGNAL(keyReleased(QKeyEvent*)), p_game, SLOT(keyReleaseEvent(QKeyEvent*)));
36 }
37 
38 GameView::~GameView()
39 {
40 
41 }
42 
43 void GameView::resizeEvent(QResizeEvent*)
44 {
45  dynamic_cast <GameScene*> (scene())->resizeSprites(250);
46 }
47 
48 void GameView::focusOutEvent(QFocusEvent*)
49 {
50  // Pause the game if it is not already paused
51  if (((GameScene*)scene())->getGame()->getTimer()->isActive())
52  {
53  ((GameScene*)scene())->getGame()->switchPause();
54  }
55 }
56 
57 void GameView::keyPressEvent(QKeyEvent* p_event)
58 {
59  if(p_event->isAutoRepeat())
60  {
61  return;
62  }
63  emit(keyPressed(p_event));
64 }
65 
66 void GameView::keyReleaseEvent(QKeyEvent* p_event)
67 {
68  if(p_event->isAutoRepeat())
69  {
70  return;
71  }
72  emit(keyReleased(p_event));
73 }
QResizeEvent
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
QKeyEvent::isAutoRepeat
bool isAutoRepeat() const
QFrame::setFrameStyle
void setFrameStyle(int style)
game.h
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:48
GameView::keyReleased
void keyReleased(QKeyEvent *p_event)
Emitted on key release event for the Game instance.
GameView::resizeEvent
void resizeEvent(QResizeEvent *p_event)
Resizes the items when the view is resized.
Definition: gameview.cpp:43
gameview.h
QAbstractScrollArea::setHorizontalScrollBarPolicy
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
Game
This class manages the game main loop : it regularly checks the key press events, computes the charac...
Definition: game.h:43
GameView::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *p_event)
Manages the player actions by hanlding the key release events.
Definition: gameview.cpp:66
gamescene.h
QKeyEvent
GameView::keyPressEvent
void keyPressEvent(QKeyEvent *p_event)
Manages the player actions by hanlding the key press events.
Definition: gameview.cpp:57
GameScene
This class contains all the Game elements to be drawn on the screen by the GameView instance...
Definition: gamescene.h:50
GameView::~GameView
~GameView()
Deletes the GameView instance.
Definition: gameview.cpp:38
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QAbstractScrollArea::setVerticalScrollBarPolicy
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
QFocusEvent
GameView::GameView
GameView(GameScene *p_scene, Game *p_game)
Creates a new GameView instance.
Definition: gameview.cpp:26
QGraphicsView
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

granatier

Skip menu "granatier"
  • Main Page
  • Namespace List
  • Namespace Members
  • 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