2
* @see http://www.davidwdrell.net/wordpress/?page_id=46
5
#ifndef BOXGRAPHICSITEM_H_
6
#define BOXGRAPHICSITEM_H_
8
#include <QtCore/QRectF>
9
#include <QtCore/QPointF>
10
#include <QtCore/QString>
12
#include <QtGui/QGraphicsRectItem>
13
#include <QtGui/QGraphicsItem>
14
#include <QtGui/QGraphicsSceneMouseEvent>
15
#include <QtGui/QPainter>
16
#include <QtGui/QStyleOptionGraphicsItem>
17
#include <QtGui/QWidget>
18
#include <QtGui/QImage>
20
#include <navitconf/data/TreeItem.h>
21
#include <navitconf/data/TreeModel.h>
23
#include "BoxGraphicsItemListener.h"
24
#include "BoxItemAttribute.h"
27
* An OSD node of the navit.xml file shown in the MapViewScene.
29
class BoxGraphicsItem: public QGraphicsRectItem {
33
* Unique IDs for each box item property.
34
* Attention: Must be in sync with internal list defined in method
35
* {@link #init(const QModelIndex&,const TreeItem&,int,int)}
37
enum BoxItemAttributeId {
39
OSD_OSD_CONFIGURATION,
56
static int getAttributeCount();
57
static QStringList getAttributeNames();
60
* Method for creating an instance of this BoxGraohicsItem.
61
* @param index The tree index this item is associated with.
62
* @param sceneWidth The width in pixel of this scene.
63
* @param sceneHeight The height in pixel of this scene.
65
static BoxGraphicsItem* init(const QModelIndex& index, const TreeItem& item, int sceneWidth, int sceneHeight);
67
* Not valid default constructor.
71
* Normal constructor sets the same valued as the inherited class {@link QGraphicsRectItem#QGraphicsRectItem()}
73
BoxGraphicsItem(const QModelIndex& index, int x, int y, int width, int height);
74
virtual ~BoxGraphicsItem();
78
BoxGraphicsItem& operator=(const BoxGraphicsItem& other);
81
* @return True, if this class holds valid data, i. e. width >= 0, otherwise false. Normally only used by overloaded default constructor.
84
QModelIndex getModelIndex() const;
85
void setPos(const QPointF& newPos);
86
void setRect(const QRectF& newRect);
88
void setIsLeft(bool isLeft);
89
void setIsTop(bool isTop);
90
bool isOsdConfiguration() const;
91
void setIsOsdConfiguration(bool isOsdConfiguration);
92
void setAttribute(BoxItemAttributeId id, const QString& value);
93
BoxItemAttribute& getAttribute(BoxItemAttributeId id);
94
const BoxItemAttribute& getAttribute(BoxItemAttributeId id) const;
95
void setHasSize(bool hasSize);
96
void sceneSizeChanged();
98
* @return True, it both items has the same row number at the index,
99
* <code>i. e. index.row() == other.index.row()</code>.
101
bool equalsByRow(const BoxGraphicsItem& other) const;
103
* Stores the differences between the given last state and the current state into the tree model.
105
void storeChangedAttributes(TreeModel& model);
106
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
111
* Called, when a mouse button is clicked:
113
* <li>Left mouse button: Begin moving this item and showing moving mouse cursor.</li>
114
* <li>Right mouse button: Begin resizing this item and showing resizing mouse cursor.</li>
117
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
120
* Called, when mouse is moved after pressing left or right button
121
* to move and resize interactively.
122
* @see #mousePressEvent(QGraphicsSceneMouseEvent*)
124
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
126
* Called, when the mouse is released to show the normal mouse cursor.
128
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
132
QList<BoxItemAttribute> attributes;
134
QPointF moveStartPos;
135
QPointF resizeStartEventPos;
136
QRectF resizeStartRect;
137
QPointF lastPosMovingFired;
138
QRectF lastRectResizingFired;
139
QPointF rightBottonPos;
141
void setImage(const QString& filename);
142
void fireItemMoving();
143
void fireItemMoveFinished();
144
void fireItemResizing();
145
void fireItemResizeFinished();
146
BoxGraphicsItemListener& getListener();
149
#endif /* BOXGRAPHICSITEM_H_ */