/** * Tests if we should start rubber banding (always returns true). */ bool SMLConnector::startRubberBanding( QMouseEvent *e ) { KivioDoc* doc = view()->doc(); KivioPage* pPage = view()->activePage(); KivioCanvas* canvas = view()->canvasWidget(); startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() )); // Create the stencil KivioStencilSpawner* ss = doc->findInternalStencilSpawner("SML Connector"); if (!ss) { kdDebug(43000) << "SMLTool: Failed to find StencilSpawner!" << endl; return false; } startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() )); // Create the stencil m_pStencil = (KivioSMLConnector*)ss->newStencil("basic_line"); m_pStencil->setTextFont(doc->defaultFont()); // Unselect everything, add the stencil to the page, and select it pPage->unselectAllStencils(); pPage->addStencil(m_pStencil); pPage->selectStencil(m_pStencil); // Get drag info ready m_pDragData = new KivioCustomDragData(); m_pDragData->page = pPage; m_pDragData->x = startPoint.x(); m_pDragData->y = startPoint.y(); m_pDragData->id = kctCustom + 2; m_pStencil->setStartPoint(startPoint.x() + 10.0f, startPoint.y() + 10.0f); m_pStencil->setEndPoint(startPoint.x(), startPoint.y()); m_pStencil->customDrag(m_pDragData); canvas->repaint(); canvas->setCursor(*m_pConnectorCursor2); return true; }
void SMLConnector::continueRubberBanding( QMouseEvent *e ) { KivioCanvas* canvas = view()->canvasWidget(); KoPoint endPoint = canvas->mapFromScreen( e->pos() ); endPoint = canvas->snapToGrid(endPoint); m_pStencil->setStartPoint(endPoint.x(), endPoint.y()); m_pDragData->x = endPoint.x(); m_pDragData->y = endPoint.y(); m_pDragData->id = kctCustom + 1; m_pStencil->customDrag(m_pDragData); m_pStencil->updateGeometry(); canvas->repaint(); }
void ConnectorTool::mousePress( QMouseEvent *e ) { if(e->button() == LeftButton) { bool ok = true; if(!m_pStencil || (m_type == StraightConnector)) { ok = startRubberBanding(e); } else { if(m_pStencil) { Kivio::PolyLineConnector* connector = static_cast<Kivio::PolyLineConnector*>(m_pStencil); KivioCanvas* canvas = view()->canvasWidget(); KivioPage* pPage = canvas->activePage(); bool hit = false; KoPoint point = pPage->snapToTarget(canvas->mapFromScreen(e->pos()), 8.0, hit); if(!hit) { point = canvas->snapToGrid(startPoint); } if((m_mode == stmDrawRubber) && hit) { endRubberBanding(e); } else { connector->addPoint(point); } } } if(ok) { m_mode = stmDrawRubber; } else { m_mode = stmNone; } } else if(e->button() == RightButton) { if(m_type == PolyLineConnector) { if(m_mode == stmDrawRubber) { endRubberBanding(e); } view()->canvasWidget()->setCursor(*m_pConnectorCursor1); m_mode = stmNone; } } }
/** * Tests if we should start rubber banding (always returns true). */ bool ConnectorTool::startRubberBanding( QMouseEvent *e ) { KivioCanvas* canvas = view()->canvasWidget(); KivioDoc* doc = view()->doc(); KivioPage* pPage = canvas->activePage(); QString spawnerId; if(m_type == StraightConnector) { spawnerId = "Dave Marotti - Straight Connector"; } else { spawnerId = "Internal - PolyLine Connector"; } KivioStencilSpawner* ss = doc->findInternalStencilSpawner(spawnerId); if(!ss) { kdDebug(43000) << "ConnectorTool: Failed to find StencilSpawner!" << endl; return false; } // Create the stencil m_pStencil = static_cast<Kivio1DStencil*>(ss->newStencil()); bool hit = false; startPoint = pPage->snapToTarget(canvas->mapFromScreen(e->pos()), 8.0, hit); if(!hit) { startPoint = canvas->snapToGrid(startPoint); } if(!m_pStencil) { return false; } m_pStencil->setTextFont(doc->defaultFont()); // Unselect everything, add the stencil to the page, and select it pPage->unselectAllStencils(); pPage->addStencil(m_pStencil); pPage->selectStencil(m_pStencil); // Get drag info ready m_pDragData = new KivioCustomDragData(); m_pDragData->page = pPage; m_pDragData->x = startPoint.x(); m_pDragData->y = startPoint.y(); if(m_type == StraightConnector) { KivioStraightConnector* connector = static_cast<KivioStraightConnector*>(m_pStencil); m_pDragData->id = kctCustom + 2; connector->setStartPoint(startPoint.x(), startPoint.y()); connector->setEndPoint(startPoint.x() + 10.0, startPoint.y() + 10.0); } else { Kivio::PolyLineConnector* connector = static_cast<Kivio::PolyLineConnector*>(m_pStencil); m_pDragData->id = kctCustom + 1; connector->addPoint(startPoint); connector->addPoint(startPoint); } m_pStencil->customDrag(m_pDragData); canvas->repaint(); canvas->setCursor(*m_pConnectorCursor2); return true; }
/** * Continues the dragging process of a stencil (moving) * * How does this work? Initially we create a list of all the original * geometry of all the selected stencils. We use that to calculate delta * movements and snap them to the grid. */ void SelectTool::continueDragging(const QPoint &pos, bool ignoreGridGuides) { KivioCanvas* canvas = view()->canvasWidget(); KoPoint pagePoint = canvas->mapFromScreen( pos ); double dx = pagePoint.x() - m_origPoint.x(); double dy = pagePoint.y() - m_origPoint.y(); bool snappedX; bool snappedY; double newX, newY; // Undraw the old stencils if(!m_firstTime) { canvas->drawSelectedStencilsXOR(); } else { canvas->activePage()->setPaintSelected(false); canvas->repaint(); m_firstTime = false; } // Translate to the new position KoPoint p; newX = m_selectedRect.x() + dx; newY = m_selectedRect.y() + dy; if(!ignoreGridGuides) { // First attempt a snap-to-grid p.setCoords(newX, newY); p = canvas->snapToGrid(p); newX = p.x(); newY = p.y(); // Now the guides override the grid so we attempt to snap to them // The bottom p.setCoords(m_selectedRect.x() + dx + m_selectedRect.width(), m_selectedRect.y() + dy + m_selectedRect.height()); p = canvas->snapToGuides(p, snappedX, snappedY); if(snappedX) { newX = p.x() - m_selectedRect.width(); } if(snappedY) { newY = p.y() - m_selectedRect.height(); } // The middle p.setCoords(m_selectedRect.x() + dx + (m_selectedRect.width() / 2.0), m_selectedRect.y() + dy + (m_selectedRect.height() / 2.0)); p = canvas->snapToGuides(p, snappedX, snappedY); if(snappedX) { newX = p.x() - (m_selectedRect.width() / 2.0); } if(snappedY) { newY = p.y() - (m_selectedRect.height() / 2.0); } // The top p.setCoords(m_selectedRect.x() + dx, m_selectedRect.y() + dy); p = canvas->snapToGuides(p, snappedX, snappedY); if(snappedX) { newX = p.x(); } if(snappedY) { newY = p.y(); } } dx = newX - m_selectedRect.x(); dy = newY - m_selectedRect.y(); KivioSelectDragData *pData; KivioStencil *pStencil = canvas->activePage()->selectedStencils()->first(); pData = m_lstOldGeometry.first(); while( pStencil && pData ) { newX = pData->rect.x() + dx; newY = pData->rect.y() + dy; if( pStencil->protection()->at( kpX ) == false ) { pStencil->setX(newX); } if( pStencil->protection()->at( kpY ) == false ) { pStencil->setY(newY); } pData = m_lstOldGeometry.next(); pStencil = canvas->activePage()->selectedStencils()->next(); } // Draw the stencils canvas->drawSelectedStencilsXOR(); view()->updateToolBars(); }