File indexing completed on 2024-04-21 04:01:57

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "characteritem.h"
0008 
0009 CharacterItem::CharacterItem(Character *p_model)
0010     : ElementItem(p_model)
0011 {
0012     connect(p_model, &Character::eaten, this, &CharacterItem::startBlinking);
0013 }
0014 
0015 CharacterItem::~CharacterItem()
0016 {
0017     delete m_blinkTimer;
0018 }
0019 
0020 QPainterPath CharacterItem::shape() const
0021 {
0022     QPainterPath path;
0023     // Temporary variable to keep the boundingRect available
0024     QRectF rect = boundingRect();
0025 
0026     // Calculation of the shape
0027     QRectF shapeRect = QRectF(rect.x() + rect.width() / 4, rect.y() + rect.height() / 4, rect.width() / 2, rect.height() / 2);
0028     path.addEllipse(shapeRect);
0029     return path;
0030 }
0031 
0032 void CharacterItem::update(qreal p_x, qreal p_y)
0033 {
0034     // Compute the top-right coordinates of the item
0035     qreal x = p_x - boundingRect().width() / 2;
0036     qreal y = p_y - boundingRect().height() / 2;
0037     // Updates the view coordinates
0038     setPos(x, y);
0039 }
0040 
0041 void CharacterItem::startBlinking()
0042 {
0043     m_nbBlinks = 0;
0044     m_blinkTimer->start();
0045 }
0046 
0047 void CharacterItem::blink()
0048 {
0049     m_nbBlinks++;
0050 }
0051 
0052 #include "moc_characteritem.cpp"