File indexing completed on 2024-10-06 03:45:00

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 #ifndef ELEMENTITEM_H
0009 #define ELEMENTITEM_H
0010 
0011 #include <KGameRenderedItem>
0012 
0013 class Element;
0014 class KGameRenderer;
0015 
0016 /**
0017  * @brief This class is the graphical representation of a game Element.
0018  */
0019 class ElementItem : public QObject, public KGameRenderedItem
0020 {
0021 
0022 Q_OBJECT
0023 
0024 private:
0025 
0026 protected:
0027 
0028     /** The instance of Element the ElementItem will represent */
0029     Element* m_model;
0030 
0031     QSize m_renderSize;
0032 
0033     QSize m_itemSizeSet;
0034     QSize m_itemSizeReal;
0035 
0036 public:
0037 
0038     /**
0039       * Creates a new ElementItem instance.
0040       * @param p_model the Element model
0041       * @param renderer the KGameRenderer
0042       */
0043     ElementItem(Element* p_model, KGameRenderer* renderer);
0044 
0045     /**
0046       * Deletes the ElementItem instance.
0047       */
0048     ~ElementItem() override;
0049 
0050     /**
0051       * Gets the Element model.
0052       * @return the model
0053       */
0054     Element* getModel() const;
0055 
0056     /**
0057       * Reimplement QGraphicsItem::shape() to return an ellipse to improve collisions.
0058       */
0059     QPainterPath shape() const override;
0060 
0061 public Q_SLOTS:
0062 
0063     /**
0064       * Updates the ElementItem coordinates.
0065       * @param p_x the new x-coordinate
0066       * @param p_y the new y-coordinate
0067       */
0068     virtual void update(qreal p_x, qreal p_y);
0069 
0070     /**
0071      * Updates the graphics after a resize
0072      * @param svgScaleFactor the scaling factor between svg and rendered pixmap
0073      */
0074     virtual void updateGraphics(qreal svgScaleFactor);
0075 
0076 protected:
0077     virtual void updateGraphicsInternal(qreal svgScaleFactor);
0078 };
0079 
0080 #endif
0081