0024665: A sample for advanced function mechanism
[occt.git] / samples / qt / FuncDemo / src / node.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2007 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the example classes of the Qt Toolkit.
6 **
7 ** Licensees holding a valid Qt License Agreement may use this file in
8 ** accordance with the rights, responsibilities and obligations
9 ** contained therein.  Please consult your licensing agreement or
10 ** contact sales@trolltech.com if any conditions of this licensing
11 ** agreement are not clear to you.
12 **
13 ** Further information about Qt licensing is available at:
14 ** http://www.trolltech.com/products/qt/licensing.html or by
15 ** contacting info@trolltech.com.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ****************************************************************************/
21
22 #ifndef NODE_H
23 #define NODE_H
24
25 #include <QGraphicsItem>
26 #include <QList>
27
28 #include <TDF_Label.hxx>
29
30 class Edge;
31 class GraphWidget;
32 class QGraphicsSceneMouseEvent;
33
34 class Node : public QGraphicsItem
35 {
36 public:
37     Node(GraphWidget *graphWidget);
38
39     void setFunction(const TDF_Label& func);
40     const TDF_Label& getFunction() const;
41
42     void addEdge(Edge *edge);
43     QList<Edge *> edges() const;
44
45     enum { Type = UserType + 1 };
46     int type() const { return Type; }
47
48     QRectF boundingRect() const;
49     QPainterPath shape() const;
50     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
51
52 protected:
53     QVariant itemChange(GraphicsItemChange change, const QVariant &value);
54     void mousePressEvent(QGraphicsSceneMouseEvent *event);
55     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
56     
57 private:
58     QList<Edge *> edgeList;
59     QPointF newPos;
60     GraphWidget *graph;
61     TDF_Label myFunction;
62 };
63
64 #endif