]> AND Private Git Repository - blast.git/blobdiff - GroupItem.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
correct relative positionning of source/group
[blast.git] / GroupItem.cpp
index e219f4c7fa68e24843f95bbb6c6060096a7e7bba..90c5574f025c58578e1277154f3371b8143775dc 100644 (file)
@@ -5,6 +5,7 @@
 #include "Dispatcher.h"
 #include "Parameters.h"
 #include "BoxItem.h"
+#include "SourceItem.h"
 #include "AbstractBlock.h"
 #include "AbstractInterface.h"
 #include "ConnectedInterface.h"
@@ -38,7 +39,7 @@ GroupItem::GroupItem(BoxItem *_parentItem,
   selected = false;
 
 
-  setZValue(-100);
+  setZValue(100);
 
   setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);  
 
@@ -55,7 +56,7 @@ GroupItem::GroupItem(Dispatcher *_dispatcher,Parameters *_params) throw(Exceptio
   parentItem = NULL;
   rectTitle = QRectF(0,-(nameHeight+2*nameMargin),nameWidth+2*nameMargin,nameHeight+2*nameMargin);
   selected = false;
-  setZValue(-100);
+  setZValue(100);
   setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
 
   updateGeometry(InterfaceMove);
@@ -259,7 +260,7 @@ bool GroupItem::updateGeometry(ChangeType type) {
   originPoint.setY(y);
 
   if ((boxSizeChanged) || (newSize != oldSize) || (originPoint != oldOrigin)) {
-    cout << "GroupItem: must change group item shape" << endl;
+    //cout << "GroupItem: must change group item shape" << endl;
     prepareGeometryChange();
     return true;
   }
@@ -284,26 +285,28 @@ void GroupItem::nameChanged() {
 
 void GroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 
-  if(params->editState == Parameters::EditGroupMove) {
-    QPointF absPos = currentPosition + originPoint;    
+  if(params->editState == Parameters::EditGroupMove) {    
     int gapX = event->scenePos().x() - cursorPosition.x();
     int gapY = event->scenePos().y() - cursorPosition.y();
 
-    //cout << "block abs. pos: " << absPos.x() << "," << absPos.y() << " | ";
-    //cout << "block current. pos: " << currentPosition.x() << "," << currentPosition.y() << " | ";
-/*
-    if (absPos.x()+gapX < 0) {
-      gapX = -absPos.x();
+    bool canMove = true;
+    if (refBlock->isTopGroupBlock()) {
+      QRectF rectGroup = boundingRectInScene();
+      rectGroup.moveTo(rectGroup.x()+gapX,rectGroup.y()+gapY);
+      foreach(SourceItem* source, getScene()->getSourceItems()) {
+        QRectF rectSource = source->boundingRectInScene();
+        if (rectGroup.intersects(rectSource)) canMove = false;
+      }
     }
-    if (absPos.y()+gapY < 0) {
-      gapY = -absPos.y();
+        
+    if (canMove) {
+      QPointF gap(gapX,gapY);
+      currentPosition = currentPosition+gap;
+      setPos(currentPosition);
+      
+      // updating all connections of the scene.
+      getScene()->updateConnectionItemsShape();
     }
-    */
-    //cout << "gap: " << gapX << "," << gapY << " | ";
-    //cout << "scene: " << getScene()->sceneRect().x() << "," << getScene()->sceneRect().y() << endl;
-    QPointF gap(gapX,gapY);
-    currentPosition = currentPosition+gap;
-    setPos(currentPosition);
     cursorPosition = event->scenePos();
   }
   else if(params->editState == Parameters::EditGroupResize) {
@@ -383,7 +386,7 @@ void GroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
   dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
 
-  if ((refBlock->isTopGroupBlock()) && (mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
+  if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
     InterfaceItem *inter = getInterfaceFromCursor(x,y);
     if (inter != NULL) {
 
@@ -427,7 +430,7 @@ void GroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent  *event) {
 
   int mode = getScene()->getEditionMode();
 
-  if ((refBlock->isTopGroupBlock()) && (mode == GroupScene::AddConnection)) {
+  if (mode == GroupScene::AddConnection) {
 
     if (params->editState == Parameters::EditStartConnection) {
       params->setEditState(Parameters::EditStartConnection);
@@ -444,15 +447,22 @@ void GroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent  *event) {
     }
     else if (params->editState == Parameters::EditCloseConnection) {
       InterfaceItem* iface1 = getScene()->getSelectedInterface(1);
-      InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
-      bool ok = dispatcher->createConnectionItem(iface1,iface2);
+      InterfaceItem* iface2 = getScene()->getSelectedInterface(2);      
+      bool ok = dispatcher->createConnectionItem(iface1,iface2);     
       if (ok) {
         iface1->selected = false;
         update(iface1->boundingRect());
+        iface2->selected = false;
+        update(iface2->boundingRect());        
         getScene()->setSelectedInterface(1,NULL);
         getScene()->setSelectedInterface(2,NULL);
         params->setEditState(Parameters::EditNoOperation);
       }
+      else {
+        //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
+        getScene()->setSelectedInterface(2,NULL);
+        params->setEditState(Parameters::EditStartConnection);
+      }
     }
   }  
   else if (mode == GroupScene::ItemEdition) {
@@ -527,7 +537,8 @@ void GroupItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
       }
     }
   }
-  QGraphicsItem::hoverMoveEvent(event);
+  //QGraphicsItem::hoverMoveEvent(event);
+  event->ignore();
 }
 
 void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
@@ -586,7 +597,7 @@ void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
   }
   else if(selectedAction == showParameters) {
     new ParametersWindow(refBlock, params, NULL);
-  }
+  }   
 }
 
 InterfaceItem* GroupItem::isHoverInterface(QPointF point) {