File indexing completed on 2023-10-01 08:02:04
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef ELEMENTITEM_H 0008 #define ELEMENTITEM_H 0009 0010 #include <QGraphicsSvgItem> 0011 0012 #include "element.h" 0013 0014 /** 0015 * @brief This class is the graphical representation of a game Element. 0016 */ 0017 class ElementItem : public QGraphicsSvgItem 0018 { 0019 Q_OBJECT 0020 0021 private: 0022 /** The Label containing the points won when eaten, to display on the scene */ 0023 QGraphicsTextItem *m_pointsToDisplay = nullptr; 0024 0025 protected: 0026 /** The instance of Element the ElementItem will represent */ 0027 Element *m_model = nullptr; 0028 0029 public: 0030 /** 0031 * Creates a new ElementItem instance. 0032 * @param p_model the Element model 0033 */ 0034 explicit ElementItem(Element *p_model); 0035 0036 /** 0037 * Deletes the ElementItem instance. 0038 */ 0039 ~ElementItem() override; 0040 0041 /** 0042 * Gets the Element model. 0043 * @return the model 0044 */ 0045 Element *getModel() const; 0046 0047 /** 0048 * Reimplement QGraphicsItem::shape() to return an ellipse to improve collisions. 0049 */ 0050 QPainterPath shape() const override; 0051 0052 public Q_SLOTS: 0053 0054 /** 0055 * Updates the ElementItem coordinates. 0056 * @param p_x the new x-coordinate 0057 * @param p_y the new y-coordinate 0058 */ 0059 virtual void update(qreal p_x, qreal p_y); 0060 }; 0061 0062 #endif