/** * 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; }
/** * 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; }
/** * Change the mouse cursor based on what it is over. */ void SelectTool::changeMouseCursor(const QPoint &pos) { KivioCanvas* canvas = view()->canvasWidget(); KoPoint pagePoint = canvas->mapFromScreen(pos); KivioStencil *pStencil; double threshold = view()->zoomHandler()->unzoomItY(4); int cursorType; // Iterate through all the selected stencils pStencil = canvas->activePage()->selectedStencils()->first(); while( pStencil ) { cursorType = isOverResizeHandle(pStencil, pagePoint.x(), pagePoint.y()); switch( cursorType ) { case 1: // top left canvas->setCursor( sizeFDiagCursor ); return; case 2: // top canvas->setCursor( sizeVerCursor ); return; case 3: // top right canvas->setCursor( sizeBDiagCursor ); return; case 4: // right canvas->setCursor( sizeHorCursor ); return; case 5: // bottom right canvas->setCursor( sizeFDiagCursor ); return; case 6: // bottom canvas->setCursor( sizeVerCursor ); return; case 7: // bottom left canvas->setCursor( sizeBDiagCursor ); return; case 8: // left canvas->setCursor( sizeHorCursor ); return; default: if( pStencil->checkForCollision( &pagePoint, threshold )!= kctNone ) { canvas->setCursor( sizeAllCursor ); return; } break; } pStencil = canvas->activePage()->selectedStencils()->next(); } canvas->unsetCursor(); }