1 /****************************************************************************
3 ** Copyright (C) 2006-2007 Trolltech ASA. All rights reserved.
5 ** This file is part of the example classes of the Qt Toolkit.
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.
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.
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.
20 ****************************************************************************/
22 #include <QGraphicsScene>
23 #include <QGraphicsSceneMouseEvent>
25 #include <QStyleOption>
29 #include "graphwidget.h"
31 #include <TFunction_IFunction.hxx>
32 #include <TFunction_GraphNode.hxx>
33 #include <TDataStd_Name.hxx>
34 #include <TDataStd_Tick.hxx>
36 Node::Node(GraphWidget *graphWidget)
39 setFlag(ItemIsMovable);
43 void Node::setFunction(const TDF_Label& func)
48 const TDF_Label& Node::getFunction() const
53 void Node::addEdge(Edge *edge)
59 QList<Edge *> Node::edges() const
64 QRectF Node::boundingRect() const
67 return QRectF(-15 - adjust, -15 - adjust,
68 33 + adjust, 33 + adjust);
71 QPainterPath Node::shape() const
74 path.addEllipse(-15, -15, 30, 30);
78 void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
80 painter->setPen(Qt::NoPen);
81 painter->setBrush(Qt::darkGray);
82 painter->drawEllipse(-12, -12, 30, 30);
84 QColor light_color(Qt::yellow);
85 TFunction_IFunction iFunc(myFunction);
86 Handle(TFunction_GraphNode) graphNode = iFunc.GetGraphNode();
87 TFunction_ExecutionStatus status = graphNode->GetStatus();
90 case TFunction_ES_WrongDefinition:
91 case TFunction_ES_Failed:
92 light_color = Qt::red;
94 case TFunction_ES_NotExecuted:
95 light_color = Qt::green;
97 case TFunction_ES_Executing:
98 light_color = Qt::yellow;
100 case TFunction_ES_Succeeded:
101 light_color = Qt::blue;
104 if (myFunction.IsAttribute(TDataStd_Tick::GetID()))
105 light_color = Qt::white;
106 QColor dark_color = light_color.dark(150);
108 QRadialGradient gradient(-3, -3, 10);
109 if (option->state & QStyle::State_Sunken) {
110 gradient.setCenter(3, 3);
111 gradient.setFocalPoint(3, 3);
112 gradient.setColorAt(1, light_color.light(120));
113 gradient.setColorAt(0, dark_color.light(120));
115 gradient.setColorAt(0, light_color);
116 gradient.setColorAt(1, dark_color);
118 painter->setBrush(gradient);
119 painter->setPen(QPen(Qt::black, 0));
120 painter->drawEllipse(-15, -15, 30, 30);
123 Handle(TDataStd_Name) n;
124 if (myFunction.FindAttribute(TDataStd_Name::GetID(), n))
125 s = TCollection_AsciiString(n->Get()).ToCString();
126 painter->drawText(-7, 3, s);
129 QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
132 case ItemPositionChange:
133 foreach (Edge *edge, edgeList)
140 return QGraphicsItem::itemChange(change, value);
143 void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
146 QGraphicsItem::mousePressEvent(event);
149 void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
152 QGraphicsItem::mouseReleaseEvent(event);