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 | #ifndef ELEMENTITEM_H |
19 | #define ELEMENTITEM_H |
20 | |
21 | #include <QGraphicsSvgItem> |
22 | |
23 | #include "element.h" |
24 | |
25 | /** |
26 | * @brief This class is the graphical representation of a game Element. |
27 | */ |
28 | class ElementItem : public QGraphicsSvgItem { |
29 | |
30 | Q_OBJECT |
31 | |
32 | private: |
33 | /** The Label containing the points won when eaten, to display on the scene */ |
34 | QGraphicsTextItem* m_pointsToDisplay; |
35 | |
36 | protected: |
37 | |
38 | /** The instance of Element the ElementItem will represent */ |
39 | Element* m_model; |
40 | |
41 | public: |
42 | |
43 | /** |
44 | * Creates a new ElementItem instance. |
45 | * @param p_model the Element model |
46 | */ |
47 | ElementItem(Element* p_model); |
48 | |
49 | /** |
50 | * Deletes the ElementItem instance. |
51 | */ |
52 | ~ElementItem(); |
53 | |
54 | /** |
55 | * Gets the Element model. |
56 | * @return the model |
57 | */ |
58 | Element* getModel() const; |
59 | |
60 | /** |
61 | * Reimplement QGraphicsItem::shape() to return an ellipse to improve collisions. |
62 | */ |
63 | QPainterPath shape() const; |
64 | |
65 | public slots: |
66 | |
67 | /** |
68 | * Updates the ElementItem coordinates. |
69 | * @param p_x the new x-coordinate |
70 | * @param p_y the new y-coordinate |
71 | */ |
72 | virtual void update(qreal p_x, qreal p_y); |
73 | }; |
74 | |
75 | #endif |
76 | |
77 | |