void CommonItemMECS::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QGraphicsItem::mouseReleaseEvent(event); setX(snapToGrid(scenePos().x())); setY(snapToGrid(scenePos().y())); update(); }
Vec3f snapLength(const Vec3f p, float t) const { if (p.length() == 0.0f) return Vec3f(0.0f); else return p.normalized()*snapToGrid(p.length(), t); }
bool ApplicationModel::onItemMotionNotifyEvent(const Glib::RefPtr<Goocanvas::Item>& item, GdkEventMotion* event) { if(item && _dragging && (item == _dragging)) { parentWindow->setModified(); double new_x = event->x ; double new_y = event->y ; item->get_parent()->translate(new_x - _drag_x, new_y - _drag_y); Goocanvas::Bounds bi = item->get_parent()->get_bounds(); bi = item->get_parent()->get_bounds(); if(bi.get_x1() < 0) item->get_parent()->translate(-bi.get_x1(), 0); if(bi.get_y1() < 0) item->get_parent()->translate(0, -bi.get_y1()); snapToGrid(); bi = item->get_parent()->get_bounds(); this->points.clear(); GyPoint pt; pt.x = bi.get_x1(); pt.y = bi.get_y1(); this->points.push_back(pt); for(int i=0; i<get_n_children(); i++) { if(Glib::RefPtr<ModuleModel>::cast_dynamic(get_child(i))) Glib::RefPtr<ModuleModel>::cast_dynamic(get_child(i))->updateArrowCoordination(); if(Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i))) Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i))->updateArrowCoordination(); } // updating canvas boundries bool needUpdate = false; if(parentWindow->m_Canvas) { Goocanvas::Bounds bc; parentWindow->m_Canvas->get_bounds(bc); needUpdate = (bi.get_x2() > bc.get_x2()) || (bi.get_y2() > bc.get_y2()); if(needUpdate) { new_x = (bi.get_x2() > bc.get_x2()) ? bi.get_x2() : bc.get_x2(); new_y = (bi.get_y2() > bc.get_y2()) ? bi.get_y2() : bc.get_y2(); parentWindow->m_Canvas->set_bounds(0,0, new_x, new_y); if(parentWindow->m_Grid) { g_object_set(parentWindow->m_Grid, "width", new_x, NULL); g_object_set(parentWindow->m_Grid, "height", new_y, NULL); } } } } return true; }
bool ApplicationModel::onItemButtonReleaseEvent(const Glib::RefPtr<Goocanvas::Item>& item, GdkEventButton* event) { if(event->button == 1) { snapToGrid(); _dragging.clear() ; } return true; }
bool MidpointModel::onItemMotionNotifyEvent(const Glib::RefPtr<Goocanvas::Item>& item, GdkEventMotion* event) { if(item && _dragging && item == _dragging) { parentWindow->setModified(); double new_x = event->x ; double new_y = event->y ; item->translate(new_x - _drag_x, new_y - _drag_y); if(event->state & GDK_CONTROL_MASK) { int index = arrow->getIndex(point_x, point_y); if(index) { Gdk::Point current_point, base_point; int dist; current_point = getContactPoint(); // adjusting to the previous point base_point = arrow->getPoint(index-1); dist = current_point.get_y() - base_point.get_y(); if(abs(dist) <= AUTOSNIPE_MARGINE) item->translate(0, -dist); dist = current_point.get_x() - base_point.get_x(); if(abs(dist) <= AUTOSNIPE_MARGINE) item->translate(-dist, 0); // adjusting to the next point base_point = arrow->getPoint(index+1); dist = current_point.get_y() - base_point.get_y(); if(abs(dist) <= AUTOSNIPE_MARGINE) item->translate(0, -dist); dist = current_point.get_x() - base_point.get_x(); if(abs(dist) <= AUTOSNIPE_MARGINE) item->translate(-dist, 0); } } Goocanvas::Bounds bi = item->get_bounds(); bi = item->get_bounds(); if(bi.get_x1() < 0) item->translate(-bi.get_x1(), 0); if(bi.get_y1() < 0) item->translate(0, -bi.get_y1()); snapToGrid(); // updating arrows coordination updateCoordiantes(); } return true; }
bool ExternalPortModel::onItemButtonReleaseEvent(const Glib::RefPtr<Goocanvas::Item>& item, GdkEventButton* event) { if(bNested) return true; if(event->button == 1) { snapToGrid(); _dragging.clear(); } return true; }
bool ExternalPortModel::onItemMotionNotifyEvent(const Glib::RefPtr<Goocanvas::Item>& item, GdkEventMotion* event) { if(bNested) return true; if(item && _dragging && item == _dragging) { parentWindow->setModified(); double new_x = event->x ; double new_y = event->y ; item->get_parent()->translate(new_x - _drag_x, new_y - _drag_y); Goocanvas::Bounds bi = item->get_bounds(); bi = item->get_parent()->get_bounds(); if(bi.get_x1() < 0) item->get_parent()->translate(-bi.get_x1(), 0); if(bi.get_y1() < 0) item->get_parent()->translate(0, -bi.get_y1()); snapToGrid(); // updating arrows coordination updateArrowCoordination(); bool needUpdate = false; if(parentWindow->m_Canvas) { Goocanvas::Bounds bc; parentWindow->m_Canvas->get_bounds(bc); needUpdate = (bi.get_x2() > bc.get_x2()) || (bi.get_y2() > bc.get_y2()); if(needUpdate) { new_x = (bi.get_x2() > bc.get_x2()) ? bi.get_x2() : bc.get_x2(); new_y = (bi.get_y2() > bc.get_y2()) ? bi.get_y2() : bc.get_y2(); parentWindow->m_Canvas->set_bounds(0,0, new_x, new_y); if(parentWindow->m_Grid) { g_object_set(parentWindow->m_Grid, "width", new_x, NULL); g_object_set(parentWindow->m_Grid, "height", new_y, NULL); } } } } return true; }
/** * @brief ElementScene::mouseMoveEvent * @param e */ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { if (m_event_interface) { if (m_event_interface -> mouseMoveEvent(e)) { if (m_event_interface->isFinish()) { emit(partsAdded()); delete m_event_interface; m_event_interface = NULL; } return; } } QPointF event_pos = e -> scenePos(); if (!e -> modifiers() & Qt::ControlModifier) event_pos = snapToGrid(event_pos); if (behavior == PasteArea) { QRectF current_rect(paste_area_ -> rect()); current_rect.moveCenter(event_pos); paste_area_ -> setRect(current_rect); return; } QGraphicsScene::mouseMoveEvent(e); }