1 #include "qnstgraphicsinterface.h"
6 setncgType(Qncg::Interface);
7 setnstType(Qnst::Interface);
18 setWidth(DEFAULT_INTERFACE_WIDTH);
19 setHeight(DEFAULT_INTERFACE_HEIGHT);
22 QnstGraphicsInterface::~QnstGraphicsInterface()
27 bool QnstGraphicsInterface::isRefer()
32 void QnstGraphicsInterface::setRefer(
bool isRefer)
37 void QnstGraphicsInterface::updateToolTip()
40 QString name = (getnstId() !=
"" ? getnstId() :
"?");
42 if (getnstType() == Qnst::Port)
44 tip +=
"Port ("+name+
")";
46 else if (getnstType() == Qnst::Area)
48 tip +=
"Area ("+name+
")";
50 else if (getnstType() == Qnst::Property)
52 tip +=
"Property ("+name+
")";
56 tip +=
"Interface ("+name+
")";
62 void QnstGraphicsInterface::setProperties(
const QMap<QString, QString> &props)
64 QnstGraphicsEntityWithEdges::setProperties(props);
66 if(props.contains(
"isRefer"))
68 if(props[
"isRefer"] ==
"true")
75 void QnstGraphicsInterface::adjust(
bool avoidCollision)
86 int maxInter = 10, inter = 0;
89 if(inter > maxInter)
break;
94 getnstGraphicsParent()->getnstGraphicsEntities())
96 if(
this != entity && entity->getncgType() == Qncg::Interface)
101 entity->setSelectable(
false); update();
103 while(collidesWithItem(entity, Qt::IntersectsItemBoundingRect))
106 QPointF pa(getLeft()+getWidth()/2, getTop()+getHeight()/2);
107 QPointF pb(entity->getWidth()/2, entity->getHeight()/2);
111 line.setAngle(qrand()%360);
113 i += (double)(qrand()%100)/10000.0;
115 setTop(getTop()+line.pointAt(i/2).y()-pa.y());
116 setLeft(getLeft()+line.pointAt(i/2).x()-pa.x());
127 entity->setSelectable(
true); update();
132 getnstGraphicsParent()->getnstGraphicsEntities())
134 if(collidesWithItem(entity, Qt::IntersectsItemBoundingRect))
146 if (edges->getnstType() == Qnst::Reference ||
147 edges->getnstType() == Qnst::Link ||
148 edges->getnstType() == Qnst::Mapping ||
149 edges->getnstType() == Qnst::Action ||
150 edges->getnstType() == Qnst::Condition)
161 void QnstGraphicsInterface::adjustToBorder()
168 QPointF pointa(parent->getWidth()/2, parent->getHeight()/2);
169 QPointF pointb(getLeft() + getWidth()/2, getTop() + getHeight()/2);
171 if (pointa == pointb)
173 pointb.setX(pointa.x());
174 pointb.setY(pointa.y() - 10);
177 QLineF line(pointa,pointb);
180 if (parent->contains(pointb))
182 QPointF pointn = pointb;
186 if (parent->contains(line.pointAt(index+0.01)))
188 while(parent->contains(pointn))
192 pointn = line.pointAt(index);
196 setTop(pointn.y() - getHeight()/2);
197 setLeft(pointn.x() - getWidth()/2);
202 QPointF pointn = pointb;
206 if (!parent->contains(line.pointAt(index-0.01)))
208 while(!parent->contains(pointn))
212 pointn = line.pointAt(index);
216 setTop(pointn.y() - getHeight()/2);
217 setLeft(pointn.x() - getWidth()/2);
222 void QnstGraphicsInterface::move(QGraphicsSceneMouseEvent* event)
249 maxx = parent->getWidth() - getWidth() - 4;
250 maxy = parent->getHeight() - getHeight() - 4;
254 maxx = scene()->width() - getWidth();
255 maxy = scene()->height() - getHeight();
258 qreal dx =
event->pos().x() - getPressLeft();
259 qreal dy =
event->pos().y() - getPressTop();
261 qreal nextx = x + dx;
262 qreal nexty = y + dy;
273 void QnstGraphicsInterface::resize(QGraphicsSceneMouseEvent* event)
278 qreal w = getWidth();
279 qreal h = getHeight();
288 if (parentItem() != NULL)
308 if (parentItem() != NULL)
310 maxx = parent->getWidth() - getWidth() - 4;
311 maxy = parent->getHeight() - getHeight() - 4;
312 maxw = parent->getWidth() - 4;
313 maxh = parent->getHeight() - 4;
317 maxx = scene()->width() - getWidth();
318 maxy = scene()->height() - getHeight();
319 maxw = scene()->width();
320 maxh = scene()->height();
323 qreal dx =
event->pos().x() - getPressLeft();
324 qreal dy =
event->pos().y() - getPressTop();
328 qreal nextx = x + dx;
329 qreal nexty = y + dy;
330 qreal nextw = w + dw;
331 qreal nexth = h + dh;
334 switch(getncgResize())
368 case Qncg::BottomRight:
390 case Qncg::BottomLeft:
408 setResizeLeft(nextx);
409 setResizeWidth(nextw);
410 setResizeHeight(nexth);