Esempio n. 1
0
bool MouseRotXRotY::eventFilter(QObject *widget, QEvent *e) {
  if (e->type() == QEvent::MouseButtonPress) {
    x = ((QMouseEvent *) e)->x();
    y = ((QMouseEvent *) e)->y();
    return true;
  }

  if (e->type() == QEvent::MouseMove) {
    QMouseEvent *qMouseEv = (QMouseEvent *) e;
    GlMainWidget *glMainWidget = (GlMainWidget *) widget;
    int deltaX,deltaY;
    deltaX=qMouseEv->x()-x;
    deltaY=qMouseEv->y()-y;

    if (abs(deltaX)>abs(deltaY))
      deltaY=0;
    else
      deltaX=0;

    if (deltaY!=0) glMainWidget->getScene()->rotateScene(deltaY,0,0);

    if (deltaX!=0) glMainWidget->getScene()->rotateScene(0,deltaX,0);

    x=qMouseEv->x();
    y=qMouseEv->y();
    glMainWidget->draw();
    return true;
  }

  return false;
}
Esempio n. 2
0
bool MouseMove::eventFilter(QObject *widget, QEvent *e) {
  if (e->type() == QEvent::MouseButtonPress) {
    x = ((QMouseEvent *) e)->x();
    y = ((QMouseEvent *) e)->y();
    return true;
  }

  if (e->type() == QEvent::MouseMove) {
    QMouseEvent *qMouseEv = (QMouseEvent *) e;
    GlMainWidget *glMainWidget = (GlMainWidget *) widget;

    if (qMouseEv->x() != x)
      glMainWidget->getScene()->translateCamera(qMouseEv->x()-x,0,0);

    if (qMouseEv->y() != y)
      glMainWidget->getScene()->translateCamera(0,y-qMouseEv->y(),0);

    x = qMouseEv->x();
    y = qMouseEv->y();
    glMainWidget->draw(false);
    return true;
  }

  return false;
}
Esempio n. 3
0
void MouseEdgeBuilder::addLink(QObject *widget, const node source, const node target) {
    GlMainWidget *glMainWidget = static_cast<GlMainWidget *>(widget);
    Graph * g = glMainWidget->getScene()->getGlGraphComposite()->getInputData()->getGraph();

    LayoutProperty* mLayout = glMainWidget->getScene()->getGlGraphComposite()->getInputData()->getElementLayout();
    edge newEdge = g->addEdge(source, target);
    mLayout->setEdgeValue(newEdge, bends());
    _bends.clear();
}
Esempio n. 4
0
int main(int argc, char **argv) {

  // A QApplication must always be declared at the beginning of the main function if you intend to
  // use the tulip-gui library
  // This must be done before calling tlp::initTulipSoftware()
  QApplication app(argc, argv);

  // Initialize the library and load all plugins
  tlp::initTulipSoftware();

  Graph *g = nullptr;
  if (QApplication::arguments().size() == 2) {
    // Load the file passed as first argument into a graph.
    // This method will select the default Tulip algorithm plugin (TLP)
    QString filename = QApplication::arguments()[1];
    if (!((filename.endsWith(".tlp")) || (filename.endsWith(".tlp.gz")))) {
      cout << "File " << QStringToTlpString(filename)
           << " not compatible. Use a tlp file or a tlp.gz file" << endl;
      exit(EXIT_FAILURE);
    }
    g = tlp::loadGraph(QStringToTlpString(filename));
  } else {
    // If no arguments were given to the command, create a complete tree of depth 5
    // and degree 2 for demo purpose
    g = createCompleteTree(5, 2);
    // Set some visual properties in order to visualize the tree
    setTreeVisualProperties(g);
  }

  // Creates the main widget that will display our graph
  GlMainWidget *mainWidget = new GlMainWidget(nullptr);

  // Adds a layer to the scene
  GlLayer *mainLayer = mainWidget->getScene()->createLayer("Main");

  // Adds the graph to this layer
  mainLayer->addGraph(g, "graph");

  // Sets some rendering parameters on the graph to visualize
  setGraphRenderingParameters(mainWidget->getScene()->getGlGraphComposite());

  // Display the widget
  mainWidget->show();

  // Flush event loop in order to let paint events pass through in order for the scene to be
  // initialized.
  QApplication::processEvents();

  // Center the camera and draw the graph
  mainWidget->centerScene();
  mainWidget->draw();

  // Adds Zoom and pan navigation to the widget
  mainWidget->installEventFilter(new MouseNKeysNavigator);
  return app.exec();
}
Esempio n. 5
0
bool MouseZoomRotZ::eventFilter(QObject *widget, QEvent *e) {
  if (e->type() == QEvent::MouseButtonPress) {
    x = ((QMouseEvent *) e)->x();
    y = ((QMouseEvent *) e)->y();
    inRotation=false;
    inZoom=false;
    return true;
  }

  if (e->type() == QEvent::MouseMove) {
    QMouseEvent *qMouseEv = (QMouseEvent *) e;
    GlMainWidget *glMainWidget = (GlMainWidget *) widget;
    int deltaX,deltaY;

    if(!inRotation && !inZoom) {
      deltaX = qMouseEv->x() - x;
      deltaY= qMouseEv->y() - y;

      if (deltaY && abs(deltaX) >= 3 * abs(deltaY)) {
        inRotation=true;
        inZoom=false;
      }
      else if (deltaX && abs(deltaY) >=  3 * abs(deltaX)) {
        inZoom=true;
        inRotation=false;
      }
      else {

      }

      x = qMouseEv->x();
      y = qMouseEv->y();
    }

    if (inZoom) {
      // Zoom
      deltaY = qMouseEv->y() - y;
      glMainWidget->getScene()->zoom(-deltaY/2);
      y = qMouseEv->y();
    }

    if(inRotation) {
      // Rotation
      deltaX = qMouseEv->x() - x;
      glMainWidget->getScene()->rotateScene(0,0,deltaX);
      x = qMouseEv->x();
    }

    glMainWidget->draw();
    return true;
  }

  return false;
}
// Event filter of the interactor component (main function of the interactor component)
bool InteractorPluginComponent::eventFilter(QObject *widget, QEvent *e) {

  if (e->type() == QEvent::MouseButtonRelease) {
    QMouseEvent * qMouseEv = (QMouseEvent *) e;
    GlMainWidget *glMainWidget = (GlMainWidget *) widget;

    if (qMouseEv->button()== Qt::LeftButton) {
      // Enter here if we have released the left button of the mouse

      // doSelect function return node/edge under the mouse
      node tmpNode;
      edge tmpEdge;
      ElementType type;
      bool result = glMainWidget->doSelect(qMouseEv->x(), qMouseEv->y(), type, tmpNode, tmpEdge);

      if (result) {
        // Enter here if we have node/edge under the mouse

        // Store selection property
        Graph *graph=glMainWidget->getScene()->getGlGraphComposite()->getInputData()->getGraph();
        string selectionPropertyName=glMainWidget->getScene()->getGlGraphComposite()->getInputData()->getElementSelectedPropName();
        BooleanProperty* selection=graph->getProperty<BooleanProperty>(selectionPropertyName);

        // Before do any think on the graph, we push the current state of the graph (this activate the undo/redo system)
        graph->push();

        // Deselect all nodes/edges
        selection->setAllNodeValue(false);
        selection->setAllEdgeValue(false);

        switch(type) {
        case NODE:
          // Set selection at true for selected node
          selection->setNodeValue(tmpNode, true);
          break;

        case EDGE:
          // Set selection at false for selected edge
          selection->setEdgeValue(tmpEdge, true);
          break;
        }

        // We have treated the event so we return true
        // (this event will not be passed to others interactorComponent)
        return true;
      }
    }
  }

  // We don't have treated the event so we return false
  // (this event will be passed to others interactorComponent)
  return false;
}
bool PixelOrientedViewNavigator::eventFilter(QObject *widget, QEvent *e) {

    if(e->type() != QEvent::MouseButtonDblClick && e->type() != QEvent::MouseMove)
        return false;

    GlMainWidget *glWidget = (GlMainWidget *) widget;

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

    if (!pixelView->smallMultiplesViewSet() && !pixelView->interactorsEnabled()) {
        pixelView->toggleInteractors(true);
    }

    if (pixelView->getOverviews().size() == 0) {
        return false;
    }

    if (e->type() == QEvent::MouseMove && pixelView->smallMultiplesViewSet()) {
        QMouseEvent *me = (QMouseEvent *) e;
        int x = glWidget->width() - me->x();
        int y = me->y();
        Coord screenCoords(x, y, 0);
        Coord sceneCoords = glWidget->getScene()->getGraphCamera().viewportTo3DWorld(glWidget->screenToViewport(screenCoords));
        PixelOrientedOverview *overviewUnderPointer = getOverviewUnderPointer(sceneCoords);

        if (overviewUnderPointer != NULL && overviewUnderPointer != selectedOverview) {
            selectedOverview = overviewUnderPointer;
        }

        return true;
    }
    else if (e->type() == QEvent::MouseButtonDblClick) {
        if (selectedOverview != NULL && !selectedOverview->overviewGenerated()) {
            pixelView->generatePixelOverview(selectedOverview, glWidget);
            glWidget->draw();
        }
        else if (selectedOverview != NULL && pixelView->smallMultiplesViewSet()) {
            QtGlSceneZoomAndPanAnimator zoomAndPanAnimator(glWidget, selectedOverview->getBoundingBox());
            zoomAndPanAnimator.animateZoomAndPan();
            pixelView->switchFromSmallMultiplesToDetailView(selectedOverview);
            selectedOverview = NULL;
        }
        else if (!pixelView->smallMultiplesViewSet() && pixelView->getOverviews().size() > 1) {
            pixelView->switchFromDetailViewToSmallMultiples();
            QtGlSceneZoomAndPanAnimator zoomAndPanAnimator(glWidget, pixelView->getSmallMultiplesViewBoundingBox());
            zoomAndPanAnimator.animateZoomAndPan();
            pixelView->centerView();
        }

        return true;
    }

    return false;
}
Esempio n. 8
0
int main(int argc, char **argv) {
  /*
  A QApplication must always be declared at the beginning of the main function in order for Tulip to work.
  This must be done before calling tlp::initTulipSoftware()
  */
  QApplication app(argc, argv);
  /*
  Initialize the library, load plugins and set application runtime pathes accordingly to the host
  operating system
  This method should always be called if you intend to use plugins in your application.
  */
  tlp::initTulipSoftware();
  /*
  Load the file passed as first argument into a graph.
  This method will select the default Tulip algorithm plugin (TLP)
  */
  // Graph* g = tlp::loadGraph(argv[1]);
  Graph *g = newGraph();

  TulipProject *_project = TulipProject::openProject(QString::fromLatin1(argv[1]));

  // std::cout << QString::fromLatin1(argv[1]) << std::endl;

  if (_project->exists("/data/graphs/0/graph.tlp")) {
    std::cout << "pouet pouet" << std::endl;
    DataSet data;

    data.set<std::string>("file::filename",
                          QStringToTlpString(_project->toAbsolutePath("/data/graphs/0/graph.tlp")));

    g = tlp::importGraph("TLP Import", data);
    std::cout << g << std::endl;
  }

  // Creates the main widget that will display our graph
  GlMainWidget *mainWidget = new GlMainWidget();
  // Adds a layer to the scene
  GlLayer *mainLayer = mainWidget->getScene()->createLayer("Main");
  // Adds the graph to this layer
  mainLayer->addGraph(g, "graph");

  // Display the widget
  mainWidget->show();
  // Flush event loop in order to let paint events pass through in order for the scene to be
  // initialized.
  QApplication::processEvents();
  // Center the camera and draw the graph
  mainWidget->centerScene();
  mainWidget->draw();
  // Adds Zoom and pan navigation to the widget
  mainWidget->installEventFilter(new MouseNKeysNavigator);
  return app.exec();
}
bool ParallelCoordsAxisBoxPlot::eventFilter(QObject *widget, QEvent *e) {

  GlMainWidget *glWidget = dynamic_cast<GlMainWidget *>(widget);

  if(!glWidget)
    return false;

  initOrUpdateBoxPlots();

  if (e->type() == QEvent::MouseMove) {
    QMouseEvent *me = (QMouseEvent *) e;
    int x = glWidget->width() - me->x();
    int y = me->y();
    Coord screenCoords(x, y, 0.0f);
    Coord sceneCoords(glWidget->getScene()->getLayer("Main")->getCamera().viewportTo3DWorld(glWidget->screenToViewport(screenCoords)));
    selectedAxis = parallelView->getAxisUnderPointer(me->x(), me->y());

    if (selectedAxis != NULL && dynamic_cast<QuantitativeParallelAxis *>(selectedAxis)) {
      if (axisBoxPlotMap.find(static_cast<QuantitativeParallelAxis *>(selectedAxis)) != axisBoxPlotMap.end())
        if (parallelView->getLayoutType() == ParallelCoordinatesDrawing::CIRCULAR) {
          rotateVector(sceneCoords, -(selectedAxis->getRotationAngle()), Z_ROT);
        }

      axisBoxPlotMap[static_cast<QuantitativeParallelAxis *>(selectedAxis)]->setHighlightRangeIfAny(sceneCoords);
    }

    parallelView->refresh();
    return true;
  }

  if (e->type() == QEvent::MouseButtonPress) {
    return false;
  }

  if (e->type() == QEvent::MouseButtonRelease) {
    if (selectedAxis != NULL && dynamic_cast<QuantitativeParallelAxis *>(selectedAxis)) {
      Observable::holdObservers();

      if (axisBoxPlotMap.find(static_cast<QuantitativeParallelAxis *>(selectedAxis)) != axisBoxPlotMap.end())
        parallelView->highlightDataInAxisBoxPlotRange(static_cast<QuantitativeParallelAxis *>(selectedAxis));

      Observable::unholdObservers();
      selectedAxis = NULL;
      parallelView->refresh();
      return true;
    }
  }

  return false;
}
Esempio n. 10
0
bool FishEyeInteractorComponent::eventFilter(QObject *obj, QEvent *e) {

  GlMainWidget *glWidget = (GlMainWidget*)obj;
  Camera *camera=&glWidget->getScene()->getGraphCamera();

  activateFishEye = false;

  if (e->type() == QEvent::MouseMove ||
      e->type() == QEvent::MouseButtonPress ||
      e->type() == QEvent::MouseButtonRelease) {
    activateFishEye = true;
    QMouseEvent *me = (QMouseEvent *) e;
    float x = glWidget->width() - me->x();
    float y = me->y();
    Coord screenCoords(x, y, 0);
    fisheyeCenter = camera->viewportTo3DWorld(glWidget->screenToViewport(screenCoords));
    glWidget->redraw();
    return true;
  }
  else if (e->type() == QEvent::Wheel) {
    activateFishEye = true;
    QWheelEvent *wheelEvent = (QWheelEvent *) e;
    int numDegrees = wheelEvent->delta() / 8;
    int numSteps = numDegrees / 15;

    if (wheelEvent->orientation() == Qt::Vertical && (wheelEvent->modifiers() == Qt::ControlModifier)) {
      activateFishEye = true;
      configWidget->setFishEyeRadius(configWidget->getFishEyeRadius() + configWidget->getFishEyeRadiusIncrementStep() * numSteps);
      glWidget->redraw();
      return true;
    }
    else if (wheelEvent->orientation() == Qt::Vertical && (wheelEvent->modifiers() == Qt::ShiftModifier)) {
      activateFishEye = true;
      float newHeight = configWidget->getFishEyeHeight() + configWidget->getFishEyeHeightIncrementStep() * numSteps;

      if (newHeight < 0) {
        newHeight = 0;
      }

      configWidget->setFishEyeHeight(newHeight);
      glWidget->redraw();
      return true;
    }

    return false;
  }

  return false;

}
Esempio n. 11
0
int main(int argc, char **argv) {
  /*
  A QApplication must always be declared at the beginning of the main function in order for Tulip to work.
  This must be done before calling tlp::initTulipSoftware()
  */
  QApplication app(argc, argv);
  /*
  Initialize the library, load plugins and set application runtime pathes accordingly to the host
  operating system
  This method should always be called if you intend to use plugins in your application.
  */
  tlp::initTulipSoftware();

  // Creates the main widget that will display our graph
  GlMainWidget *mainWidget = new GlMainWidget();
  // Adds a layer to the scene
  GlLayer *mainLayer = mainWidget->getScene()->createLayer("Main");

  Coord center1(-1, -1, -1);
  Coord center2(1, 1, 1);
  Size size(1, 1, 1);
  Color whiteOpaque(255, 255, 255, 255);
  Color blackOpaque(0, 0, 0, 255);

  GlBox *node1 = new GlBox(center1, size, whiteOpaque, blackOpaque);
  GlBox *node2 = new GlBox(center2, size, whiteOpaque, blackOpaque);

  mainLayer->addGlEntity(node1, "Gl Tutorial 1: Node 1");
  mainLayer->addGlEntity(node2, "Gl Tutorial 1: Node 2");

  Coord centerBox(0, 0, 0);
  Size sizeBox(3.001, 3.001, 3.001);
  Color purpleTrans(155, 0, 155, 50);
  GlBox *box = new GlBox(centerBox, sizeBox, purpleTrans, blackOpaque);
  mainLayer->addGlEntity(box, "Gl Tutorial 2: Box");

  // Display the widget
  mainWidget->show();
  // Flush event loop in order to let paint events pass through in order for the scene to be
  // initialized.
  QApplication::processEvents();
  // Center the camera and draw the graph
  mainWidget->centerScene();
  mainWidget->draw();
  // Adds Zoom and pan navigation to the widget
  mainWidget->installEventFilter(new MouseNKeysNavigator);
  return app.exec();
}
Esempio n. 12
0
void FishEyeInteractorComponent::viewChanged(View *view) {
  if (view == nullptr) {
    return;
  }

  GlMainView *glView = static_cast<GlMainView *>(view);
  GlMainWidget *glWidget = glView->getGlMainWidget();

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

  if (configWidget->getFishEyeRadius() == 0.) {
    configWidget->setFishEyeRadius(glWidget->getScene()->getGraphCamera().getSceneRadius() / 4.);
    configWidget->setFishEyeHeight(4.);
  }
}
//========================================================================================
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 GoogleMapViewNavigator::eventFilter(QObject *widget, QEvent *e) {
  GoogleMapsView *googleMapsView=static_cast<GoogleMapsView*>(view());

  if(googleMapsView->viewType()==GoogleMapsView::GoogleRoadMap ||
      googleMapsView->viewType()==GoogleMapsView::GoogleSatellite ||
      googleMapsView->viewType()==GoogleMapsView::GoogleTerrain ||
      googleMapsView->viewType()==GoogleMapsView::GoogleHybrid) {
    QMouseEvent *qMouseEv = dynamic_cast<QMouseEvent *>(e);
    QWheelEvent *qWheelEv = dynamic_cast<QWheelEvent *>(e);

    if(qMouseEv || qWheelEv) {
      GoogleMapsView* googleMapsView=static_cast<GoogleMapsView*>(view());
      QApplication::sendEvent(googleMapsView->getGoogleMap(), e);
    }

    return false;
  }
  else if (googleMapsView->viewType()==GoogleMapsView::Globe) {
    if (e->type() == QEvent::Wheel &&
        (((QWheelEvent *) e)->orientation() == Qt::Vertical)) {
#define WHEEL_DELTA 120
      GlMainWidget *g = (GlMainWidget *) widget;
      g->getScene()->zoomXY(((QWheelEvent *) e)->delta() / WHEEL_DELTA,
                            g->width()/2., g->height()/2.);
      view()->draw();
      return true;
    }

    if (e->type() == QEvent::MouseButtonPress && !inRotation) {
      if(((QMouseEvent*)e)->button()==Qt::LeftButton) {
        x = ((QMouseEvent *) e)->x();
        y = ((QMouseEvent *) e)->y();
        inRotation=true;
        return true;
      }
    }

    if(e->type() == QEvent::MouseButtonRelease) {
      if(((QMouseEvent*)e)->button()==Qt::LeftButton) {
        inRotation=false;
        return true;
      }
    }

    if (e->type() == QEvent::MouseMove && inRotation) {
      GlMainWidget *g = (GlMainWidget *) widget;
      Camera &camera=g->getScene()->getGraphCamera();
      Coord c1=camera.getEyes()-camera.getCenter();
      Coord c2=camera.getEyes()-camera.getCenter()+camera.getUp();
      trans(c1,c2,-0.005*(((QMouseEvent *) e)->y()-y),-0.005*(((QMouseEvent *) e)->x()-x));
      camera.setCenter(Coord(0,0,0));
      camera.setEyes(c1);
      camera.setUp(c2-camera.getEyes());

      x = ((QMouseEvent *) e)->x();
      y = ((QMouseEvent *) e)->y();

      view()->draw();
      return true;
    }

    if (e->type() == QEvent::KeyPress) {
      GlMainWidget *g = (GlMainWidget *) widget;

      float angle1=0;
      float angle2=0;

      switch(((QKeyEvent *) e)->key()) {
      case Qt::Key_Left:
        angle2=-0.05f;
        break;

      case Qt::Key_Right:
        angle2=0.05f;
        break;

      case Qt::Key_Up:
        angle1=0.05f;
        break;

      case Qt::Key_Down:
        angle1=-0.05f;
        break;
      }

      Camera &camera=g->getScene()->getGraphCamera();
      Coord c1=camera.getEyes()-camera.getCenter();
      Coord c2=camera.getEyes()-camera.getCenter()+camera.getUp();
      trans(c1,c2,angle1,angle2);
      camera.setCenter(Coord(0,0,0));
      camera.setEyes(c1);
      camera.setUp(c2-camera.getEyes());

      view()->draw();

      return true;
    }

    return false;
  }
  else {
    return MouseNKeysNavigator::eventFilter(widget, e);
  }
}
Esempio n. 15
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;
}
Esempio n. 16
0
//===============================================================
bool MouseNKeysNavigator::eventFilter(QObject *widget, QEvent *e) {
  if(isGesturing) {
    return MousePanNZoomNavigator::eventFilter(widget, e);
  }

  if(currentSpecInteractorComponent) {
    if(currentSpecInteractorComponent->eventFilter(widget,e))
      return true;
  }

  if (e->type() == QEvent::MouseButtonPress) {
    if (((QMouseEvent *) e)->buttons() == Qt::LeftButton) {
      oldCursor=((QWidget*)widget)->cursor();
      InteractorComponent *currentMouse;
      // give focus so we can catch key events
      ((GlMainWidget *)widget)->setFocus();

      if (((QMouseEvent *) e)->modifiers() &
#if defined(__APPLE__)
          Qt::AltModifier
#else
          Qt::ControlModifier
#endif
         )
        currentMouse = new MouseZoomRotZ();
      else if (((QMouseEvent *) e)->modifiers() & Qt::ShiftModifier)
        currentMouse = new MouseRotXRotY();
      else {
        currentMouse = new MouseMove();
        ((QWidget*)widget)->setCursor(QCursor(Qt::ClosedHandCursor));
      }

      bool result = currentMouse->eventFilter(widget, e);

      currentSpecInteractorComponent=currentMouse;

      //currentMouseID = abstractView->pushInteractor(currentMouse);
      return result;
    }

    return false;
  }

  if (e->type() == QEvent::MouseButtonRelease) {
    ((QWidget*)widget)->setCursor(oldCursor);
    delete currentSpecInteractorComponent;
    currentSpecInteractorComponent=NULL;
    return true;
  }

  if (e->type() == QEvent::KeyPress) {
    int delta = (((QKeyEvent *) e)->isAutoRepeat() ? 3 : 1);
    GlMainWidget *g = (GlMainWidget *) widget;

    switch(((QKeyEvent *) e)->key()) {
    case Qt::Key_Left:
      g->getScene()->translateCamera(delta * 2,0,0);
      break;

    case Qt::Key_Right:
      g->getScene()->translateCamera(-1 * delta * 2,0,0);
      break;

    case Qt::Key_Up:
      g->getScene()->translateCamera(0,-1 * delta * 2,0);
      break;

    case Qt::Key_Down:
      g->getScene()->translateCamera(0,delta * 2,0);
      break;

    case Qt::Key_PageUp:
      g->getScene()->zoom(delta);
      break;

    case Qt::Key_PageDown:
      g->getScene()->zoom(-1 * delta);
      break;

    case Qt::Key_Home:
      g->getScene()->translateCamera(0,0,-1 * delta * 2);
      break;

    case Qt::Key_End:
      g->getScene()->translateCamera(0,0,delta * 2);
      break;

    case Qt::Key_Insert:
      g->getScene()->rotateScene(0,0,-1 * delta * 2);
      break;

    case Qt::Key_Delete :
      g->getScene()->rotateScene(0,0,delta * 2);
      break;

    default:
      return false;
    }

    g->draw();
    return true;
  }

  if (e->type() == QEvent::KeyRelease) {
    switch(((QKeyEvent *) e)->key()) {
    case Qt::Key_Left:
    case Qt::Key_Right:
    case Qt::Key_Up:
    case Qt::Key_Down:
    case Qt::Key_PageUp:
    case Qt::Key_PageDown:
    case Qt::Key_Home:
    case Qt::Key_End:
    case Qt::Key_Insert:
    case Qt::Key_Delete:
      break;

    default:
      return false;
    }

    return true;
  }

  return MousePanNZoomNavigator::eventFilter(widget, e);
}
Esempio n. 17
0
//===============================================================
bool MousePanNZoomNavigator::eventFilter(QObject *widget, QEvent *e) {
// according to Qt's doc, this constant has been defined by wheel mouse vendors
// we need it to interpret the value of QWheelEvent->delta()
#define WHEEL_DELTA 120
  if (e->type() == QEvent::Wheel &&
      (((QWheelEvent *) e)->orientation() == Qt::Vertical)) {

    GlMainWidget *g = (GlMainWidget *) widget;

    if(((QWheelEvent *) e)->delta() < 0 && g->getScene()->getCamera().getZoomFactor() < 0.5f) {
      return true;
    }

    g->getScene()->zoomXY(((QWheelEvent *) e)->delta() / WHEEL_DELTA,
                          ((QWheelEvent *) e)->x(), ((QWheelEvent *) e)->y());
    g->draw(false);
    return true;
  }

  if(e->type() == QEvent::Gesture) {
    GlMainWidget *g = (GlMainWidget *) widget;
    QGestureEvent* gesture = (QGestureEvent*)e;
    QPointF center;
    //swipe events and pan events are never fired, known Qt bug
    /*if(gesture->gesture(Qt::SwipeGesture)) {
      QSwipeGesture* swipe = (QSwipeGesture*)gesture->gesture(Qt::SwipeGesture);
      int x = cos(swipe->swipeAngle()) * swipe->property("velocity").toFloat();
      int y = sin(swipe->swipeAngle()) * swipe->property("velocity").toFloat();
      g->getScene()->translateCamera(x, y, 0);
    }*/

    if(gesture->gesture(Qt::PinchGesture)) {
      QPinchGesture* pinch = (QPinchGesture*)gesture->gesture(Qt::PinchGesture);
      Camera& camera = g->getScene()->getCamera();

      //store the camera scale factor when starting the gesture
      if(pinch->state() == Qt::GestureStarted) {
        cameraScaleFactor = camera.getZoomFactor();
        isGesturing = true;
      }

      if(pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) {
        //only set the zoom factor if two events in a row were in the same direction (zoom in or out) to smooth a bit the effect.
        if((pinch->lastScaleFactor() > 1 && pinch->scaleFactor() > 1) || (pinch->lastScaleFactor() <= 1 && pinch->scaleFactor() <= 1)) {
          camera.setZoomFactor(cameraScaleFactor * pinch->totalScaleFactor());
        }
      }

      if(pinch->changeFlags() & QPinchGesture::RotationAngleChanged) {
        /*//backup the current camera center
              Coord oldCenter = camera.getCenter();
              Coord oldEye = camera.getEyes();
        //sets the camera center to the center of the pich gesture
              Coord rotationCenter(g->mapFromGlobal(pinch->centerPoint().toPoint()).x(), g->mapFromGlobal(pinch->centerPoint().toPoint()).y(), oldCenter.getZ());
              Coord rotationEye=camera.getEyes()+(rotationCenter-oldCenter);
              camera.setCenter(rotationCenter);
              camera.setEyes(rotationEye);*/
        //rotates the camera
        camera.rotate((pinch->rotationAngle() - pinch->lastRotationAngle())/180*M_PI, 0, 0, 1);
        /*
        //restore old camera center and eyes
              camera.setCenter(oldCenter);
              camera.setEyes(oldEye); */
      }

      if(pinch->state() == Qt::GestureFinished) {
        isGesturing = false;
      }

      if(gesture->gesture(Qt::PanGesture)) {
        QPanGesture* pan = (QPanGesture*)gesture->gesture(Qt::PanGesture);

        if(pan->state() == Qt::GestureStarted) {
          isGesturing = true;
        }

        if(pan->state() == Qt::GestureFinished) {
          isGesturing = false;
        }

        center = pan->delta();
        g->getScene()->translateCamera(pan->delta().x(), -pan->delta().y(), 0);
      }
    }

    g->draw(false);
    return true;
  }

  return false;
}
Esempio n. 18
0
//=====================================================================
bool MouseBoxZoomer::eventFilter(QObject *widget, QEvent *e) {
  GlMainWidget *glw = static_cast<GlMainWidget *>(widget);
  GlGraphInputData *inputData = glw->getScene()->getGlGraphComposite()->getInputData();

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

    if (qMouseEv->buttons() == mButton &&
        (kModifier == Qt::NoModifier ||
         qMouseEv->modifiers() & kModifier)) {
      if (!started) {
        x = qMouseEv->x();
        y =  glw->height() - qMouseEv->y();
        w = 0;
        h = 0;
        started = true;
        graph = inputData->getGraph();
      }
      else {
        if (inputData->getGraph() != graph) {
          graph = NULL;
          started = false;
        }
      }

      return true;
    }

    if (qMouseEv->buttons()==Qt::MidButton) {
      started = false;
      glw->redraw();
      return true;
    }

    return false;
  }

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

    if ((qMouseEv->buttons() & mButton) &&
        (kModifier == Qt::NoModifier ||
         qMouseEv->modifiers() & kModifier)) {
      if (inputData->getGraph() != graph) {
        graph = NULL;
        started = false;
      }

      if (started) {
        if ((qMouseEv->x() > 0) && (qMouseEv->x() < glw->width()))
          w = qMouseEv->x() - x;

        if ((qMouseEv->y() > 0) && (qMouseEv->y() < glw->height()))
          h = y - (glw->height() - qMouseEv->y());

        glw->redraw();
        return true;
      }
    }
  }

  if (e->type() == QEvent::MouseButtonDblClick) {
    GlBoundingBoxSceneVisitor bbVisitor(inputData);
    glw->getScene()->getLayer("Main")->acceptVisitor(&bbVisitor);
    QtGlSceneZoomAndPanAnimator zoomAnPan(glw, bbVisitor.getBoundingBox());
    zoomAnPan.animateZoomAndPan();
    return true;
  }

  if (e->type() == QEvent::MouseButtonRelease) {

    QMouseEvent * qMouseEv = static_cast<QMouseEvent *>(e);

    if ((qMouseEv->button() == mButton &&
         (kModifier == Qt::NoModifier ||
          qMouseEv->modifiers() & kModifier))) {
      if (inputData->getGraph() != graph) {
        graph = NULL;
        started = false;
      }

      if (started) {
        started = false;

        if(!(w==0 && h==0)) {
          int width = glw->width();
          int height = glw->height();

          Coord bbMin(width-x, height - y+h);
          Coord bbMax(width-(x+w), height - y);

          if (abs(bbMax[0] - bbMin[0]) > 1 && abs(bbMax[1] - bbMin[1]) > 1) {

            BoundingBox sceneBB;
            sceneBB.expand(glw->getScene()->getGraphCamera().viewportTo3DWorld(glw->screenToViewport(bbMin)));
            sceneBB.expand(glw->getScene()->getGraphCamera().viewportTo3DWorld(glw->screenToViewport(bbMax)));

            QtGlSceneZoomAndPanAnimator zoomAnPan(glw, sceneBB);
            zoomAnPan.animateZoomAndPan();
          }
        }
      }

      return true;
    }
  }

  return false;
}