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
20CharacterItem::CharacterItem(Character* p_model) : ElementItem (p_model) {
21 connect(p_model, SIGNAL(eaten()), this, SLOT(startBlinking()));
22}
23
24CharacterItem::~CharacterItem() {
25 delete m_blinkTimer;
26}
27
28QPainterPath 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
40void 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
48void CharacterItem::startBlinking() {
49 m_nbBlinks = 0;
50 m_blinkTimer->start();
51}
52
53void CharacterItem::blink() {
54 m_nbBlinks++;
55}
56
57