void RootPanel::updateUnit(NavUnit *unit) { NodeItem *el = 0; nodeMap.find(unit->getID(), el); UnitLocation loc = unit->getLocation(); //width is incl. borders and text, so correct for this . loc.x_ = (long)loc.x_ % (navview->width() - 40); loc.y_ = (long)loc.y_ % (navview->height() - 80); el->moveBy(loc.x_ - el->pos().x() , loc.y_ - el->pos().y()); el->show(); canvas.update(); if(unit->getID() == 1) { this->details->updateLocation(loc); } }
void GraphEditor::mouseMoveEvent(QMouseEvent* e) {if(gwp->moving_item) {//setRenderHints(!QPainter::Antialiasing); gwp->moving_item->moveBy(e->pos().x() - start_position.x(), e->pos().y() - start_position.y()); start_position = e->pos(); } else if(gwp->moving_subgraph) {setRenderHints(0); GeometricGraph & G = *(gwp->pGG); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); short vcol=0; G.vcolor.getinit(vcol); NodeItem * node; for(tvertex v = 1; v <= G.nv();v++) {node =(NodeItem *)nodeitem[v]; if(G.vcolor[node->v] != vcol)continue; node->moveBy(e->pos().x() - start_position.x(), e->pos().y() - start_position.y()); } start_position = e->pos(); } else if(gwp->curs_item) // moving the elastic cursor gwp->curs_item->setToPoint(e->pos().x(),e->pos().y()); }
void GraphEditor::mouseReleaseEvent(QMouseEvent* event) {//setRenderHints(QPainter::Antialiasing); if(gwp->info_item) //end info {scene()->removeItem(gwp->info_item->rectitem); scene()->removeItem(gwp->info_item); gwp->info_item = 0; setCursor(QCursor(Qt::ArrowCursor)); return; } if(gwp->moving_item) //end moving a vertex {if(!FitToGrid) {gwp->moving_item = 0;return;} GeometricGraph & G = *(gwp->pGG); NodeItem *node = gwp->moving_item; tvertex v = node->v; double prev_x = G.vcoord[v].x(); double prev_y = G.vcoord[v].y(); ToGrid(v); double dx = G.vcoord[v].x() - prev_x; double dy = G.vcoord[v].y() - prev_y; G.vcoord[v].x() = prev_x; G.vcoord[v].y() = prev_y; node->moveBy(dx,-dy); gwp->moving_item = 0; UpdateSizeGrid(); PrintSizeGrid(); return; } if(gwp->moving_subgraph == true) {gwp->moving_subgraph = false; if(!FitToGrid)return; GeometricGraph & G = *(gwp->pGG); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); short vcol=0; G.vcolor.getinit(vcol); NodeItem * node; // Find a vertex of the subgraph tvertex mv = 0; tvertex v; for(v = 1; v <= G.nv();v++) {node =(NodeItem *)nodeitem[v]; if(G.vcolor[node->v] != vcol)continue; else {mv = v;break;} } if(!mv)return; double prev_x = G.vcoord[mv].x(); double prev_y = G.vcoord[mv].y(); ToGrid(mv); double dx = G.vcoord[mv].x() - prev_x; double dy = G.vcoord[mv].y() - prev_y; G.vcoord[mv].x() = prev_x; G.vcoord[mv].y() = prev_y; for(v = 1;v <= G.nv();v++) {node =(NodeItem *)nodeitem[v]; if(G.vcolor[node->v] != vcol)continue; node->moveBy(dx,-dy); } UpdateSizeGrid(); PrintSizeGrid(); return; } if(gwp->curs_item)// end creating an edge {GeometricGraph & G = *(gwp->pGG); Prop<EdgeItem *> edgeitem(G.Set(tedge()),PROP_CANVAS_ITEM); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); NodeItem* node; EdgeItem *edge; tvertex v1,v2; // Reset the color of starting vertex v1 = gwp->curs_item->v; node = (NodeItem *)(nodeitem[v1]); node->SetColor(color[G.vcolor[v1]]); QPoint p(event->pos()); ToGrid(p); int rtt = FindItem(p,node,edge); v2 = (rtt != node_rtti) ? 0 : node->v; if(rtt != node_rtti) //create a vertex {int h = (int)gwp->canvas->height(); Tpoint pp((double)p.x(),(double)(h - p.y())); v2 = G.NewVertex(pp);ToGrid(v2); nodeitem[v2] = CreateNodeItem(v2,gwp); mywindow->mouse_actions->ButtonUndoGrid->setDisabled(true); if(IsGrid)UpdateSizeGrid(); } else v2 = node->v; if(v1 != v2) // Create an edge {tedge e = G.NewEdge(v1,v2); edgeitem[e] = CreateEdgeItem(e,gwp); } delete gwp->curs_item; gwp->curs_item = 0; mywindow->information();// Informations if(v1 == v2) // We have created a vertex PrintSizeGrid(); return; } }