//=============================================================== bool MouseElementDeleter::eventFilter(QObject *widget, QEvent *e) { QMouseEvent *qMouseEv = (QMouseEvent *) e; if(qMouseEv != NULL) { node tmpNode; edge tmpEdge; ElementType type; GlMainWidget *glMainWidget = (GlMainWidget *) widget; if(e->type() == QEvent::MouseMove) { if (glMainWidget->doSelect(qMouseEv->x(), qMouseEv->y(), type, tmpNode, tmpEdge)) { glMainWidget->setCursor(QCursor(QPixmap(":/i_del.png"))); } else { glMainWidget->setCursor(Qt::ArrowCursor); } return false; } else if (e->type() == QEvent::MouseButtonPress && qMouseEv->button()==Qt::LeftButton) { if (glMainWidget->doSelect(qMouseEv->x(), qMouseEv->y(), type, tmpNode, tmpEdge)) { Observable::holdObservers(); Graph* graph = glMainWidget->getGraph(); // allow to undo graph->push(); switch(type) { case NODE: graph->delNode(tmpNode); break; case EDGE: graph->delEdge(tmpEdge); break; } glMainWidget->redraw(); Observable::unholdObservers(); 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; }