Root/Software/sie_cg/diagramitem.h

1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef DIAGRAMITEM_H
43#define DIAGRAMITEM_H
44
45#include <QGraphicsPixmapItem>
46#include <QGraphicsSimpleTextItem>
47#include <QList>
48#include <QtXml>
49#include <stdio.h>
50
51class Arrow;
52class DiagramTextItem;
53
54QT_BEGIN_NAMESPACE
55class QPixmap;
56class QGraphicsItem;
57class QGraphicsScene;
58class QTextEdit;
59class QGraphicsSceneMouseEvent;
60class QMenu;
61class QGraphicsSceneContextMenuEvent;
62class QPainter;
63class QStyleOptionGraphicsItem;
64class QWidget;
65class QPolygonF;
66QT_END_NAMESPACE
67
68class QObject;
69
70class DiagramItem : public QGraphicsPolygonItem
71{
72public:
73    enum { Type = UserType + 15 };
74
75    DiagramItem(QMenu *contextMenu,
76                QString diagramType,
77                QDomElement *domElement,
78                QGraphicsItem *parent = 0, QGraphicsScene *scene = 0,
79                QPointF position = QPointF(0,0), double zV=500);
80
81    void removeArrow(Arrow *arrow);
82    void removeArrows();
83    void addArrow(Arrow *arrow);
84
85    void addText(DiagramTextItem *externalTextItem)
86        { textItems.append(externalTextItem);}
87
88    void removeTextItem(DiagramTextItem *textItem);
89    void removeTextItems();
90
91    QString diagramType() const
92        { return myDiagramType; }
93
94    QPolygonF polygon() const
95        { return myPolygon; }
96
97    QDomElement *getDomElement()
98        {return myDomElement;}
99
100    QPixmap image() const;
101
102    int type() const
103        { return Type;}
104
105    QList<DiagramTextItem *> getTextItems() const
106        { return textItems;}
107
108    QList<Arrow *> getArrows() const
109        { return arrows;}
110
111    unsigned char existArrow(DiagramTextItem *startItem,
112                             DiagramTextItem *endItem);
113
114    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
115    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
116    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
117
118    QDomElement toXml(QDomDocument &) const;
119
120    bool setValue(unsigned char ioID, QString value);
121    DiagramTextItem * pointerText(unsigned char ID);
122    bool textIsIO(unsigned char ID);
123
124    void setColor(const QColor &color)
125        { myColor=color; setBrush(color); }
126
127    int getID()
128        { return myID;}
129
130    void setID(int value)
131        { myID=value;}
132
133    bool existText(DiagramTextItem * text);
134
135    QGraphicsScene * getOwnerScene()
136        { return myOwnerScene;}
137
138    void updateTexts();
139
140protected:
141    void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
142    QVariant itemChange(GraphicsItemChange change, const QVariant &value);
143
144private:
145    QGraphicsScene *myOwnerScene;
146    QString myDiagramType;
147    int myID;
148    QPolygonF myPolygon;
149    QMenu *myContextMenu;
150    QList<Arrow *> arrows;
151    QList<DiagramTextItem *> textItems;
152    DiagramTextItem *textItem;
153    QColor myColor;
154    QDomElement *myDomElement;
155    bool positionChanged;
156};
157
158#endif
159

Archive Download this file

Branches:
master



interactive