59#include <QGraphicsDropShadowEffect>
60#include <QStyleOptionGraphicsItem>
63#define AUTOSNIPE_MARGINE 5
70 bool isInApp,
bool editingMode,
BuilderItem *parent) :
73 externalSelection(false),
74 editingMode(editingMode),
76 myStartItem(startItem),
86 setFlag(ItemIsSelectable,
true);
87 setFlag(ItemClipsToShape,
false);
88 setToolTip(QString(
"%1 --> %2").arg(myStartItem->
itemName).arg(myEndItem->
itemName));
90 textLbl.setFlag(ItemSendsGeometryChanges,!
nestedInApp);
101 if(editingMode && manager){
115 QString label = connection.
carrier();
116 if(!label.isEmpty()){
119 QFontMetrics fontMetric(font);
120#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
121 textWidth = fontMetric.horizontalAdvance(label);
123 textWidth = fontMetric.width(label);
127 if(mod.
points.size() > 0){
129 if(p.
x >= 0 && p.
y >= 0){
131 textLbl.setPos(p.
x,p.
y);
133 if(mod.
points.size() > 3){
138 polyline.prepend(startP);
140 for(
unsigned int i=2; i<mod.
points.size() - 1;i++){
142 QPointF point(p.
x,p.
y);
144 handleList.append(handle);
145 polyline.append(point);
146 qDebug() <<
"APPENDING " << handle;
148 polyline.append(endP);
149 boundingPolyline = polyline;
165 connection.
setCarrier(carrier.toLatin1().data());
179 updatedCon.
setFrom(from.toLatin1().data());
182 connection = updatedCon;
199 updatedCon.
setTo(to.toLatin1().data());
202 connection = updatedCon;
220 QPointF p = textLbl.pos();
221 labelPoint.
x = p.x();
222 labelPoint.
y = p.y();
224 startPoint.
x = (myStartItem->pos()).x();
225 startPoint.
y = (myStartItem->pos()).y();
226 endPoint.
x = (myEndItem->pos()).x();
227 endPoint.
y = (myEndItem->pos()).y();
234 model.
points.push_back(labelPoint);
235 model.
points.push_back(startPoint);
241 model.
points.push_back(point);
244 model.
points.push_back(endPoint);
267 externalSelection =
true;
268 setSelected(selected);
273 QPointF startIngPoint;
275 return startIngPoint;
280 return QString(
"%1").arg(connection.
from());
285 return QString(
"%1").arg(connection.
to());
290 this->connected = connected;
301 qreal extra = (2 + 30) / 2.0;
303 QRectF bRect = QRectF(boundingPolyline.boundingRect())
305 .adjusted(-extra, -extra, extra, extra);
307 return bRect.united(textLbl.boundingRect());
313 QPainterPathStroker pathStroke;
314 pathStroke.setWidth(8);
315 for(
int i=0;i<boundingPolyline.count();i++){
316 QPointF p = boundingPolyline.at(i);
321 path.lineTo(p.x(),p.y());
325 QPainterPath
ret = pathStroke.createStroke(path);
332 if(boundingPolyline.isEmpty()){
333 boundingPolyline.prepend(mapFromItem(myStartItem,myStartItem->
connectionPoint()));
334 boundingPolyline.append( mapFromItem(myEndItem,myEndItem->
connectionPoint()));
339void Arrow::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
342 qreal arrowSize = 10;
349 polyline.prepend(startP);
352 polyline.append(handlePoint);
360 polyline.append(endP);
361 boundingPolyline = polyline;
365 QLineF lastLine(polyline.at(polyline.count()-2),
367 QPointF p1 = lastLine.p1();
368 QPointF p2 = lastLine.p2();
370 QLineF line = QLineF(p2,p1);
372 double angle = ::acos(line.dx() / line.length());
374 angle = (
Pi * 2) - angle;
377 QPointF arrowP1 = line.p1() + QPointF(sin(angle +
Pi / 3) * arrowSize,
378 cos(angle +
Pi / 3) * arrowSize);
379 QPointF arrowP2 = line.p1() + QPointF(sin(angle +
Pi -
Pi / 3) * arrowSize,
380 cos(angle +
Pi -
Pi / 3) * arrowSize);
383 arrowHead << line.p1() << arrowP1 << arrowP2;
385 painter->setPen(QPen(Qt::blue, 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin));
388 painter->setPen(QPen(Qt::green, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
390 painter->setPen(QPen(Qt::red, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
396 painter->setBrush(Qt::green);
398 painter->setBrush(Qt::red);
400 painter->drawPolyline(polyline);
401 painter->drawPolygon(arrowHead);
405 QPointF centerP = QPointF((p1.x() + p2.x())/2 - textWidth/2,((p1.y() + p2.y())/2) - 5);
406 textLbl.setPos(centerP);
419 setFlag(ItemIsMovable,
true);
421 BuilderItem::mousePressEvent(event);
431 setFlag(ItemIsMovable,
false);
433 BuilderItem::mouseReleaseEvent(event);
440 setFlag(ItemIsMovable,
false);
442 BuilderItem::mouseMoveEvent(event);
450 QPointF clickPos =
event->pos();
456 QGraphicsItem::mouseDoubleClickEvent(event);
462 handle->setSelected(
true);
463 if(handleList.isEmpty()){
464 handleList.append(handle);
466 bool inserted =
false;
467 for(
int i=0;i<handleList.count();i++){
469 if(hndl->x() > clickPos.x()){
470 handleList.insert(i,handle);
476 handleList.append(handle);
484 handleList.removeOne(handle);
494 if (change == QGraphicsItem::ItemPositionChange) {
496 setFlag(ItemIsMovable,
false);
499 if (change == QGraphicsItem::ItemSelectedHasChanged) {
500 if(!externalSelection){
503 externalSelection =
false;
511 for(
int i=0;i<handleList.count();i++) {
523 if(index >= 0 && index <= handleList.count() - 1){
524 return handleList.at(index);
533 this->parent = parent;
534 setFlag(ItemIsSelectable,
true);
535 setFlag(ItemIsMovable,
true);
536 setFlag(ItemSendsGeometryChanges,
true);
539 setRect( - rectSize/2, -rectSize/2, rectSize,rectSize);
541 setPen(QPen(QColor(Qt::black),1));
542 setBrush(QBrush(QColor(Qt::red)));
545 offset = QPointF(0,0);
548 this->center = center;
549 qDebug() <<
"CENTER CREATED IN " << center;
556 qreal xV = gridSize/2 + floor(pointP.x()/gridSize)*gridSize;
557 qreal yV = gridSize/2 + floor(pointP.y()/gridSize)*gridSize;
570 QPainterPath newPath;
572 if(event->modifiers() == Qt::ControlModifier){
578 newPath.addRect(pos().x() + rect().x() - 2,
579 pos().y() + rect().y() - 2 ,
583 scene()->setSelectionArea(newPath);
585 QGraphicsRectItem::mousePressEvent(event);
592 if(event->modifiers() == Qt::ControlModifier){
601 QGraphicsRectItem::mouseMoveEvent(event);
608 parent->setSelected(
true);
610 QGraphicsRectItem::mouseReleaseEvent(event);
615 QVariant val = value;
616 if (change == QGraphicsItem::ItemPositionChange && pressed) {
618 QPointF newPos = parent->mapToScene(value.toPointF());
620 QPointF
ret = parent->mapFromScene(closestPoint);
627 QPointF current_point, base_point;
629 bool modified =
false;
631 current_point = mapToItem(parent,val.toPointF());
635 base_point = mapToItem(parent,h->pos());
640 dist = current_point.y() - base_point.y();
644 current_point = QPointF(current_point.x(), current_point.y() -dist);
646 dist = current_point.x() - base_point.x();
650 current_point = QPointF(current_point.x()-dist, current_point.y());
658 base_point = mapToItem(parent,h->pos());
662 dist = current_point.y() - base_point.y();
665 current_point = QPointF(current_point.x(), current_point.y() -dist);
667 dist = current_point.x() - base_point.x();
671 current_point = QPointF(current_point.x()-dist, current_point.y());
678 val = mapFromItem(parent,current_point);
690 QRectF myRect = rect();
693 painter->setPen(QPen(QColor(Qt::black),1,Qt::DashLine));
694 painter->setBrush(QBrush(QColor(Qt::blue)));
696 painter->setPen(QPen(QColor(Qt::black),1));
697 painter->setBrush(QBrush(QColor(Qt::red)));
701 painter->drawRect(myRect);
707Label::Label(QString label, QGraphicsItem *parent) : QGraphicsTextItem(label,parent)
712 auto* combo =
new QComboBox();
713 combo->setEditable(
true);
715 QObject::connect(combo,
SIGNAL(activated(QString)),
716 sigHandler,SLOT(onConnectionComboChanged(QString)));
718 combo->addItem(
"tcp");
719 combo->addItem(
"udp");
725 setFlag(ItemIsSelectable,
true);
760 if(((QComboBox*)
comboWidget->widget())->findText(label) == -1){
761 ((QComboBox*)
comboWidget->widget())->addItem(label);
780 QGraphicsTextItem::mouseDoubleClickEvent(event);
787 QGraphicsItem::mousePressEvent(event);
800 QGraphicsItem::mouseReleaseEvent(event);
810 QGraphicsItem::mouseMoveEvent(event);
816 if (change == QGraphicsItem::ItemPositionChange) {
818 QPointF newPos = value.toPointF();
821 return closestPoint+=
offset;
825 if (change == QGraphicsItem::ItemSelectedHasChanged) {
826 bool selected = isSelected();
840 qreal xV = gridSize/2 + floor(pointP.x()/gridSize)*gridSize;
841 qreal yV = gridSize/2 + floor(pointP.y()/gridSize)*gridSize;
int SIGNAL(int pid, int signum)
#define AUTOSNIPE_MARGINE
Original license follows:
void updateConnectionTo(QString to)
QPointF connectionPoint() override
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override
void setConnectionSelected(bool selected)
void updateCarrier(QString carrier)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override
int getHandleIndex(LineHandle *handle)
void addHandle(QPointF clickPos)
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
GraphicModel * getModel()
QPainterPath shape() const override
BuilderItem * startItem() const
LineHandle * getLineHandle(int index)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
void removeHandle(LineHandle *)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
void updateConnectionFrom(QString from)
QList< LineHandle * > handles()
void mousePressEvent(QGraphicsSceneMouseEvent *e) override
BuilderItem * endItem() const
void updateGraphicModel()
QRectF boundingRect() const override
void setConnection(const Connection &conn)
ItemSignalHandler * sigHandler
void removeArrow(Arrow *arrow)
ItemSignalHandler * signalHandler()
virtual QPointF connectionPoint()=0
void connectctionSelected(QGraphicsItem *it)
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
void currentComboTextChanged(QString text)
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
QPointF computeTopLeftGridPoint(const QPointF &pointP)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
ItemSignalHandler * sigHandler
Label(QString label, QGraphicsItem *parent=0)
QGraphicsProxyWidget * comboWidget
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
QPointF computeTopLeftGridPoint(const QPointF &pointP)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
LineHandle(QPointF center, Arrow *parent=0)
void setTo(const char *szTo)
void setCarrier(const char *szCr)
GraphicModel & getModelBase()
void setModelBase(GraphicModel &mdl)
void setFrom(const char *szFrom)
void setModel(GraphicModel *mdl)
std::vector< GyPoint > points
bool updateConnectionOfApplication(Application *application, Connection &prev, Connection &con)
bool removeConnectionFromApplication(Application *application, Connection &cnn)
Connection & addConnectionToApplication(Application *application, Connection &cnn)
Application * getApplication()
KnowledgeBase * getKnowledgeBase()