示例#1
0
bool MouseEdgeBuilder::eventFilter(QObject *widget, QEvent *e) {

    GlMainWidget *glMainWidget = static_cast<GlMainWidget *>(widget);

    if (e->type() == QEvent::MouseButtonPress) {
        QMouseEvent * qMouseEv = static_cast<QMouseEvent *>(e);

        SelectedEntity selectedEntity;
        GlGraphInputData *inputData=glMainWidget->getScene()->getGlGraphComposite()->getInputData();
        Graph * _graph = inputData->getGraph();

        LayoutProperty* mLayout = inputData->getElementLayout();

        if (qMouseEv->buttons()==Qt::LeftButton) {
            if (!_started) {
                bool result=glMainWidget->pickNodesEdges(qMouseEv->x(), qMouseEv->y(), selectedEntity);

                if (result && (selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED)) {
                    _started=true;
                    initObserver(_graph);
                    _source=node(selectedEntity.getComplexEntityId());
                    _curPos=_startPos=mLayout->getNodeValue(_source);
                    return true;
                }

                return false;
            }
            else {
                bool result = glMainWidget->pickNodesEdges(qMouseEv->x(),qMouseEv->y(),selectedEntity);

                if (result && (selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED)) {
                    Observable::holdObservers();
                    _started=false;
                    clearObserver();
                    // allow to undo
                    _graph->push();
                    addLink(widget,_source,node(selectedEntity.getComplexEntityId()));
                    Observable::unholdObservers();

                }
                else {
                    Coord point(glMainWidget->width() - qMouseEv->x(), qMouseEv->y(), 0);
                    _bends.push_back(glMainWidget->getScene()->getGraphCamera().viewportTo3DWorld(glMainWidget->screenToViewport(point)));
                    glMainWidget->redraw();
                }
            }

            return true;
        }

        if (qMouseEv->buttons()==Qt::MidButton) {
            _bends.clear();
            _started=false;
            _source=node();
            clearObserver();
            glMainWidget->draw();
            return true;
        }
    }

    if  (e->type() == QEvent::MouseMove) {
        QMouseEvent * qMouseEv = static_cast<QMouseEvent *>(e);

        if (!_started) {
            SelectedEntity selectedEntity;
            bool hoveringOverNode = glMainWidget->pickNodesEdges(qMouseEv->x(), qMouseEv->y(), selectedEntity) && selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED;

            if (!hoveringOverNode) {
                glMainWidget->setCursor(QCursor(Qt::ArrowCursor));
                return false;
            }
            else {
                glMainWidget->setCursor(QCursor(Qt::CrossCursor));
            }
        }
        else {
            SelectedEntity selectedEntity;

            if(glMainWidget->pickNodesEdges(qMouseEv->x(), qMouseEv->y(), selectedEntity) && selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED) {
                glMainWidget->setCursor(QCursor(Qt::CrossCursor));
            }
            else {
                glMainWidget->setCursor(QCursor(Qt::ArrowCursor));
            }

            Coord point(glMainWidget->width() - qMouseEv->x(), qMouseEv->y(), 0);
            point = glMainWidget->getScene()->getGraphCamera().viewportTo3DWorld(glMainWidget->screenToViewport(point));
            _curPos.set(point[0], point[1], point[2]);
            glMainWidget->redraw();
        }

        return true;
    }

    return false;
}
//========================================================================================
bool MouseEdgeBendEditor::eventFilter(QObject *widget, QEvent *e) {

  QMouseEvent * qMouseEv = (QMouseEvent *) e;

  if(qMouseEv == NULL)
    return false;

  // Double click to create a new control point
  if(e->type() == QEvent::MouseButtonDblClick &&  qMouseEv->button() == Qt::LeftButton && haveSelection(glMainWidget)) {
    _operation = NEW_OP;
    mMouseCreate(qMouseEv->x(), qMouseEv->y(), glMainWidget);
    return true;
  }

  if (e->type() == QEvent::MouseButtonPress) {
    if(!glMainWidget)
      glMainWidget = (GlMainWidget *) widget;

    initProxies(glMainWidget);
    bool hasSelection = haveSelection(glMainWidget);

    editPosition[0] = qMouseEv->x();
    editPosition[1] = qMouseEv->y();
    editPosition[2] = 0;

    switch(qMouseEv->buttons()) {
    case Qt::LeftButton : {

      if (!hasSelection) {
        // event occurs outside the selection rectangle
        // so from now we delegate the job to a MouseEdgeSelector object
        // which should intercept the event
        _operation = NONE_OP;
      }
      else {

        bool entityIsSelected = glMainWidget->pickGlEntities((int)editPosition[0] - 3, (int)editPosition[1] - 3, 6, 6, select, layer);

        if(!entityIsSelected) {
          // We have click outside an entity
          _operation = NONE_OP;
        }
        else {
          selectedEntity=circleString->findKey(select[0].getSimpleEntity());

          if (qMouseEv->modifiers() &
#if defined(__APPLE__)
              Qt::AltModifier
#else
              Qt::ControlModifier
#endif
             ) {
            _operation = DELETE_OP;
            mMouseDelete();
          }
          else {
            _graph->push();
            _operation = TRANSLATE_OP;
            glMainWidget->setCursor(QCursor(Qt::SizeAllCursor));
            mode = COORD;
          }

          return true;
        }
      }

      break;
    }

    default: {
      return false;
    }
    }

    glMainWidget->redraw();
  }

  if (e->type() == QEvent::MouseButtonRelease &&
      qMouseEv->button() == Qt::LeftButton &&
      _operation != NONE_OP) {
    GlMainWidget *glMainWidget = (GlMainWidget *) widget;

    if(selectedEntity=="targetTriangle") {
      SelectedEntity selectedEntity;

      if (glMainWidget->pickNodesEdges(qMouseEv->x(), qMouseEv->y(), selectedEntity) && selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED) {
        glMainWidget->getScene()->getGlGraphComposite()->getGraph()->setEnds(mEdge,glMainWidget->getScene()->getGlGraphComposite()->getGraph()->ends(mEdge).first,node(selectedEntity.getComplexEntityId()));
      }
    }
    else if(selectedEntity=="sourceCircle") {
      SelectedEntity selectedEntity;

      if (glMainWidget->pickNodesEdges(qMouseEv->x(), qMouseEv->y(), selectedEntity) && selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED) {
        glMainWidget->getScene()->getGlGraphComposite()->getGraph()->setEnds(mEdge,node(selectedEntity.getComplexEntityId()),glMainWidget->getScene()->getGlGraphComposite()->getGraph()->ends(mEdge).second);
      }
    }

    selectedEntity="";

    _operation = NONE_OP;
    glMainWidget->setCursor(QCursor(Qt::PointingHandCursor));
    glMainWidget->redraw();
    return true;
  }

  if(e->type() == QEvent::MouseButtonPress) {
    vector<SelectedEntity> selectedEntities;
    glMainWidget->pickGlEntities(qMouseEv->x(), qMouseEv->y(), selectedEntities);

    if(!selectedEntities.empty())
      if(selectedEntities[0].getEntityType()==SelectedEntity::SIMPLE_ENTITY_SELECTED)
        if(selectedEntities[0].getSimpleEntity()==edgeEntity) {
          mouseButtonPressOnEdge=true;
          return true;
        }
  }

  if(e->type() == QEvent::MouseButtonRelease) {
    vector<SelectedEntity> selectedEntities;
    glMainWidget->pickGlEntities(qMouseEv->x(), qMouseEv->y(), selectedEntities);

    if(!selectedEntities.empty())
      if(selectedEntities[0].getEntityType()==SelectedEntity::SIMPLE_ENTITY_SELECTED)
        if(selectedEntities[0].getSimpleEntity()==edgeEntity && mouseButtonPressOnEdge) {
          mouseButtonPressOnEdge=false;
          return true;
        }

    mouseButtonPressOnEdge=false;
  }

  if  (e->type() == QEvent::MouseMove) {
    if(qMouseEv->buttons() == Qt::LeftButton &&
        _operation != NONE_OP) {
      GlMainWidget *glMainWidget = (GlMainWidget *) widget;

      switch (_operation) {
      case TRANSLATE_OP:
        mMouseTranslate(qMouseEv->x(), qMouseEv->y(), glMainWidget);
        return true;

      default:
        return false;
      }
    }
    else if(qMouseEv->buttons() == Qt::NoButton) {
      SelectedEntity selectedEntity;
      GlMainWidget *g = (GlMainWidget *) widget;

      if (g->pickNodesEdges(qMouseEv->x(), qMouseEv->y(), selectedEntity) && selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED) {
        g->setCursor(Qt::CrossCursor);
      }
      else {
        g->setCursor(Qt::ArrowCursor);
      }

      return false;
    }
  }

  return false;
}
bool MouseLassoNodesSelectorInteractorComponent::eventFilter(QObject *obj, QEvent *e) {
  GlMainWidget *glWidget=static_cast<GlMainWidget *>(obj);

  if (!glWidget->hasMouseTracking()) {
    glWidget->setMouseTracking(true);
  }

  QMouseEvent *me = dynamic_cast<QMouseEvent *>(e);

  if (!me) return false;

  camera = &glWidget->getScene()->getLayer("Main")->getCamera();
  graph = glWidget->getScene()->getGlGraphComposite()->getInputData()->getGraph();
  viewSelection = graph->getProperty<BooleanProperty>("viewSelection");

  currentPointerScreenCoord = Coord(me->x(), glWidget->height() - me->y());

  if (me->type() == QEvent::MouseMove) {
    if (dragStarted) {
      polygon.push_back(glWidget->screenToViewport(currentPointerScreenCoord));
      drawInteractor = true;
      glWidget->redraw();

    }

    return true;
  }
  else if (me->type() == QEvent::MouseButtonPress) {
    if (me->button() == Qt::LeftButton) {
      dragStarted = true;
      polygon.push_back(glWidget->screenToViewport(currentPointerScreenCoord));
    }
    else if (me->button() == Qt::RightButton) {
      dragStarted = false;

      if (!polygon.empty()) {
        polygon.clear();
        drawInteractor = true;
        glWidget->redraw();
      }
      else {
        Observable::holdObservers();
        SelectedEntity selectedEntity;
        bool result = glWidget->pickNodesEdges(me->x(), me->y(),  selectedEntity);

        if (result && selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED) {
          bool sel = viewSelection->getNodeValue(node(selectedEntity.getComplexEntityId()));
          viewSelection->setNodeValue(node(selectedEntity.getComplexEntityId()), !sel);
        }

        Observable::unholdObservers();
      }
    }

    return true;
  }
  else if (me->type() == QEvent::MouseButtonRelease) {
    dragStarted = false;

    if (me->button() == Qt::LeftButton && polygon.size() > 10) {
      Observable::holdObservers();

      if (me->modifiers() != Qt::ControlModifier) {
        viewSelection->setAllNodeValue(false);
        viewSelection->setAllEdgeValue(false);
      }

      selectGraphElementsUnderPolygon(glWidget);
      Observable::unholdObservers();

    }

    polygon.clear();

  }

  return false;
}
示例#4
0
  /*
  Most important function of an interactor component
  When an event arrive on your interactor : this function is call
  You have to process it and return true. If the event do nothing in your interactor : this function
  return false;
  */
  bool eventFilter(QObject *, QEvent *e) {

    /*
    If you have clicked on a node/edge, information widget is visible.
    And if you use the wheel of the mouse we hide the information widget
    */
    if (_informationWidgetItem->isVisible() && e->type() == QEvent::Wheel) {
      _informationWidgetItem->setVisible(false);
      return false;
    }

    /*
    Check if the event is a mouse event
    */
    QMouseEvent *qMouseEv = dynamic_cast<QMouseEvent *>(e);

    if (qMouseEv != nullptr) {
      GlMainView *glMainView = static_cast<GlMainView *>(view());

      /*
      Check if event is a left mouse button press
      */
      if (e->type() == QEvent::MouseButtonPress && qMouseEv->button() == Qt::LeftButton) {

        /*
        If you have clicked on a node/edge, information widget is visible.
        And if you reclick : hide it
        */
        if (_informationWidgetItem->isVisible()) {
          _informationWidgetItem->setVisible(false);
        } else {

          /*
          Select entities under the mouse cursor
          The result of selection is stored in SelectedEntity
          And pickNodesEdges return true if you click on node or edge
          */
          SelectedEntity selectedEntity;

          if (glMainView->getGlMainWidget()->pickNodesEdges(qMouseEv->x(), qMouseEv->y(),
                                                            selectedEntity)) {

            /*
            Change text of the information label with
            - If you click on a node : "Click on node id : nodeId"
            - If you click on an edge : "Click on edge id : edgeId"
            */
            QString text("Click on ");

            if (selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED)
              text += "node ";
            else
              text += "edge ";

            text += " id : " + QString::number(selectedEntity.getComplexEntityId());

            /*
            - Update QLabel with new text
            - Auto resize QLabel
            - Set position of the label at mouse position
            - Display it
            */
            _informationLabel->setText(text);
            _informationLabel->adjustSize();
            _informationWidgetItem->setPos(qMouseEv->pos());
            _informationWidgetItem->setVisible(true);

            /*
            Here we just add a small smooth animation on the label pop
            */
            QPropertyAnimation *animation =
                new QPropertyAnimation(_informationWidgetItem, "opacity");
            animation->setDuration(100);
            animation->setStartValue(0.);
            animation->setEndValue(0.99);
            animation->start();

            /*
            We have treated the event so we return true
            */
            return true;
          }
        }
      }
    }

    /*
    We don't have treated the event se we return false
    */
    return false;
  }