• 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
characteritem.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 "characteritem.h"
19 
20 CharacterItem::CharacterItem(Character* p_model) : ElementItem (p_model) {
21  connect(p_model, SIGNAL(eaten()), this, SLOT(startBlinking()));
22 }
23 
24 CharacterItem::~CharacterItem() {
25  delete m_blinkTimer;
26 }
27 
28 QPainterPath CharacterItem::shape() const
29 {
30  QPainterPath path;
31  // Temporary variable to keep the boundingRect available
32  QRectF rect = boundingRect();
33 
34  // Calculation of the shape
35  QRectF shapeRect = QRectF( rect.x()+rect.width()/4, rect.y()+rect.height()/4, rect.width()/2, rect.height()/2 );
36  path.addEllipse(shapeRect);
37  return path;
38 }
39 
40 void CharacterItem::update(qreal p_x, qreal p_y) {
41  // Compute the top-right coordinates of the item
42  qreal x = p_x - boundingRect().width() / 2;
43  qreal y = p_y - boundingRect().height() / 2;
44  // Updates the view coordinates
45  setPos(x, y);
46 }
47 
48 void CharacterItem::startBlinking() {
49  m_nbBlinks = 0;
50  m_blinkTimer->start();
51 }
52 
53 void CharacterItem::blink() {
54  m_nbBlinks++;
55 }
56 
QPainterPath::addEllipse
void addEllipse(const QRectF &boundingRectangle)
CharacterItem::update
virtual void update(qreal p_x, qreal p_y)
Updates the CharacterItem coordinates.
Definition: characteritem.cpp:40
QGraphicsItem::x
qreal x() const
QGraphicsItem::y
qreal y() const
QRectF::x
qreal x() const
QRectF::y
qreal y() const
Character
This class describes the common characteristics and behaviour of the game characters (Kapman and the ...
Definition: character.h:27
CharacterItem::startBlinking
virtual void startBlinking()
Starts the character blinking.
Definition: characteritem.cpp:48
CharacterItem::m_blinkTimer
QTimer * m_blinkTimer
Timer used to make the character blink.
Definition: characteritem.h:36
CharacterItem::shape
QPainterPath shape() const
Overrides the default shape function to make it a small circle This function is used to determinate c...
Definition: characteritem.cpp:28
characteritem.h
QGraphicsSvgItem::boundingRect
virtual QRectF boundingRect() const
QGraphicsItem::setPos
void setPos(const QPointF &pos)
CharacterItem::CharacterItem
CharacterItem(Character *p_model)
Creates a new CharacterItem instance.
Definition: characteritem.cpp:20
ElementItem
This class is the graphical representation of a game Element.
Definition: elementitem.h:28
CharacterItem::~CharacterItem
~CharacterItem()
Deletes the CharacterItem instance.
Definition: characteritem.cpp:24
CharacterItem::blink
virtual void blink()
Makes the character blink.
Definition: characteritem.cpp:53
QPainterPath
QRectF::width
qreal width() const
QRectF
QTimer::start
void start(int msec)
QRectF::height
qreal height() const
CharacterItem::m_nbBlinks
int m_nbBlinks
Number of ticks of the blink timer.
Definition: characteritem.h:39
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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