52 #include <QGraphicsItem> 53 #include <QFontMetrics> 56 #include "connectionPoint.hh" 57 #include "connection.hh" 58 #include "elementInOut.hh" 59 #include "graphicsScene.hh" 60 #include "elementArea.hh" 62 #include "../parser/inout.hh" 76 QColor colors_[] = { QColor(255, 0, 0),
87 QGraphicsEllipseItem (_parent),
91 setRect (0, 0, width_, width_);
93 setBrush (QColor (64,64,64));
95 setAcceptHoverEvents (
true);
110 QGraphicsEllipseItem::setPos (_rect.topLeft ());
111 QGraphicsLayoutItem::setGeometry (_rect);
112 setRect (0, 0, width_, width_);
118 QSizeF ConnectionPoint::sizeHint (Qt::SizeHint _which,
const QSizeF &)
const 122 case Qt::MinimumSize:
123 case Qt::PreferredSize:
124 case Qt::MaximumSize:
125 sh = QSizeF(width_, width_);
137 void ConnectionPoint::mousePressEvent (QGraphicsSceneMouseEvent *_event)
140 static_cast<GraphicsScene *
>(scene ())->setActiveConnection (c);
141 QGraphicsEllipseItem::mousePressEvent(_event);
149 QGraphicsItem *elementArea =
dynamic_cast<GraphicsScene *
> (scene ())->elementArea ();
151 if (inout_->
type () == ElementInOut::TypeInput)
152 return elementArea->mapFromScene (mapToScene (QPointF (0, width_ / 2)));
153 return elementArea->mapFromScene (mapToScene (QPointF (width_, width_ / 2)));
161 setBrush (colors_[_state]);
168 stateStr =
"[NOT CONNECTED]";
171 stateStr =
"[OPTIONAL]";
174 stateStr =
"[ASK DURING EXECUTION]";
177 stateStr =
"[CONSTANT SET]";
180 stateStr =
"[CONNECTED]";
182 case OutputNotConnected:
183 stateStr =
"[NOT CONNECTED]";
188 setToolTip (stateStr);
196 void ConnectionPoint::hoverEnterEvent (QGraphicsSceneHoverEvent * )
202 if (
inOut ()->
inOut ()->typeString () ==
"data")
207 p.setColor (QColor (0, 0, 255));
215 void ConnectionPoint::hoverLeaveEvent (QGraphicsSceneHoverEvent * )
221 if (
inOut ()->
inOut ()->typeString () ==
"data")
226 p.setColor (QColor (0, 0, 0));
243 void ConnectionPoint::paint(QPainter *_painter,
const QStyleOptionGraphicsItem * _option, QWidget *_widget)
245 QGraphicsEllipseItem::paint (_painter, _option, _widget);
247 float wH = width_ / 2.0;
248 float wT = width_ / 3.0;
249 float wS = width_ / 6.0;
253 path.arcTo (0, 0, width_, width_, 0, 360);
255 QRadialGradient rG (QPointF(width_ * 0.8, width_), width_ * 0.8);
256 rG.setColorAt(0, QColor (255, 255, 255, 128));
257 rG.setColorAt(1, Qt::transparent);
258 _painter->setBrush (rG);
259 _painter->setPen (Qt::NoPen);
260 _painter->drawPath (path);
262 path = QPainterPath ();
264 path.arcTo (1, 1, width_ - 2, width_ - 2, 180, - 165);
265 path.cubicTo (QPointF (wH + wT, wH + wS), QPointF (wH + wS, wH - wS), QPointF (wH, wH));
266 path.cubicTo (QPointF (wT, wH + wS), QPointF (wS, wH + wS), QPointF (1, wH));
268 rG.setCenter (wS, 0);
269 rG.setFocalPoint(wS, 0);
270 rG.setRadius (width_);
271 rG.setColorAt(0, Qt::white);
272 rG.setColorAt(1, Qt::transparent);
273 _painter->setBrush (rG);
274 _painter->setPen (Qt::NoPen);
275 _painter->drawPath(path);
QString typeString() const
Type.
virtual void setGeometry(const QRectF &_rect)
Sets the geometry.
const QString & longDescription() const
Long description.
QPointF connectPos()
Position for connections.
State
State of the connection point.
void setState(State _state)
sets the state
void setWidth(int _width)
Sets the diameter.
Text * descriptionTextItem() const
Short description widget.
Text * typeTextItem() const
Type text widget.
~ConnectionPoint()
Destructor.
ConnectionPoint(ElementInOut *_e, QGraphicsItem *_parent)
Constructor.
InOut * inOut() const
InOut context object.
virtual Type type() const =0
Type.
QList< Connection * > connections() const
Connections.
ElementInOut * inOut() const
Input/output element.