• 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
elementitem.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 "elementitem.h"
19 
20 ElementItem::ElementItem(Element* p_model) : QGraphicsSvgItem() {
21  m_model = p_model;
22  // Init the view coordinates
23  setPos(p_model->getX() - boundingRect().width() / 2, p_model->getY() - boundingRect().height() / 2);
24  // Connects the model to the view
25  connect(p_model, SIGNAL(moved(qreal,qreal)), this, SLOT(update(qreal,qreal)));
26  setCacheMode(DeviceCoordinateCache);
27  setMaximumCacheSize(QSize(500, 500));
28 }
29 
30 ElementItem::~ElementItem() {
31  delete m_model;
32 
33 }
34 
35 Element* ElementItem::getModel() const {
36  return m_model;
37 }
38 
39 QPainterPath ElementItem::shape() const {
40  QPainterPath path;
41  path.addEllipse(boundingRect());
42  return path;
43 }
44 
45 void ElementItem::update(qreal p_x, qreal p_y) {
46  // Compute the top-right coordinates of the item
47  qreal x = p_x - boundingRect().width() / 2;
48  qreal y = p_y - boundingRect().height() / 2;
49 
50  // Updates the view coordinates
51  setPos(x, y);
52 }
QPainterPath::addEllipse
void addEllipse(const QRectF &boundingRectangle)
QGraphicsItem::x
qreal x() const
QGraphicsItem::y
qreal y() const
Element::getX
qreal getX() const
Gets the Element x-coordinate.
Definition: element.cpp:32
ElementItem::update
virtual void update(qreal p_x, qreal p_y)
Updates the ElementItem coordinates.
Definition: elementitem.cpp:45
ElementItem::~ElementItem
~ElementItem()
Deletes the ElementItem instance.
Definition: elementitem.cpp:30
ElementItem::getModel
Element * getModel() const
Gets the Element model.
Definition: elementitem.cpp:35
ElementItem::m_model
Element * m_model
The instance of Element the ElementItem will represent.
Definition: elementitem.h:39
QGraphicsSvgItem::boundingRect
virtual QRectF boundingRect() const
QGraphicsItem::setPos
void setPos(const QPointF &pos)
Element
This class describes the common characteristics and behaviour of any game Element (character or item)...
Definition: element.h:30
QSize
Element::getY
qreal getY() const
Gets the Element y-coordinate.
Definition: element.cpp:36
QGraphicsSvgItem
QPainterPath
QRectF::width
qreal width() const
QGraphicsItem::setCacheMode
void setCacheMode(CacheMode mode, const QSize &logicalCacheSize)
elementitem.h
ElementItem::shape
QPainterPath shape() const
Reimplement QGraphicsItem::shape() to return an ellipse to improve collisions.
Definition: elementitem.cpp:39
ElementItem::ElementItem
ElementItem(Element *p_model)
Creates a new ElementItem instance.
Definition: elementitem.cpp:20
QRectF::height
qreal height() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QGraphicsSvgItem::setMaximumCacheSize
void setMaximumCacheSize(const QSize &size)
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