File indexing completed on 2024-02-18 04:03:24

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