void ConnectorTool::continueRubberBanding( QMouseEvent *e ) { KivioCanvas* canvas = view()->canvasWidget(); KivioPage* pPage = view()->activePage(); bool hit = false; KoPoint endPoint = pPage->snapToTarget(canvas->mapFromScreen(e->pos()), 8.0, hit); if(!hit) { endPoint = canvas->snapToGridAndGuides(endPoint); } m_pDragData->x = endPoint.x(); m_pDragData->y = endPoint.y(); if(m_type == StraightConnector) { KivioStraightConnector* connector = static_cast<KivioStraightConnector*>(m_pStencil); connector->setEndPoint(endPoint.x(), endPoint.y()); m_pDragData->id = kctCustom + 2; } else { Kivio::PolyLineConnector* connector = static_cast<Kivio::PolyLineConnector*>(m_pStencil); m_pDragData->id = kctCustom + connector->pointCount(); } m_pStencil->customDrag(m_pDragData); m_pStencil->updateGeometry(); canvas->repaint(); }
void SelectTool::continueCustomDragging(const QPoint &pos) { KivioCanvas* canvas = view()->canvasWidget(); KoPoint pagePoint = canvas->mapFromScreen(pos); bool hit = false; if(m_pCustomDraggingStencil->type() == kstConnector){ pagePoint = canvas->activePage()->snapToTarget(pagePoint, 8.0, hit); } if(!hit) { pagePoint = canvas->snapToGridAndGuides( pagePoint ); } KivioCustomDragData data; data.page = canvas->activePage(); data.dx = pagePoint.x() - m_lastPoint.x(); data.dy = pagePoint.y() - m_lastPoint.y(); data.x = pagePoint.x(); data.y = pagePoint.y(); data.id = m_customDragID; data.scale = view()->zoomHandler()->zoomedResolutionY(); if(m_pCustomDraggingStencil->type() != kstConnector){ // Undraw the old stencils if(!m_firstTime) { canvas->drawStencilXOR(m_pCustomDraggingStencil); } else { m_pCustomDraggingStencil->setHidden(true); canvas->repaint(); m_firstTime = false; } } // Custom dragging can only occur on one stencil if( m_pCustomDraggingStencil ) m_pCustomDraggingStencil->customDrag( &data ); // Draw the stencils if(m_pCustomDraggingStencil->type() != kstConnector){ canvas->drawStencilXOR(m_pCustomDraggingStencil); } else { view()->canvasWidget()->repaint(); } view()->updateToolBars(); }
void SelectTool::continueResizing(const QPoint &pos, bool ignoreGridGuides) { KivioCanvas* canvas = view()->canvasWidget(); KoPoint pagePoint = canvas->mapFromScreen(pos); if(!ignoreGridGuides) { pagePoint = canvas->snapToGridAndGuides( pagePoint ); } KivioSelectDragData *pData = m_lstOldGeometry.first(); /* QWMatrix m; double w2 = m_pResizingStencil->w() / 2.0; double h2 = m_pResizingStencil->h() / 2.0; m.translate(m_pResizingStencil->x(), m_pResizingStencil->y()); m.translate(m_pResizingStencil->pinPoint().x(), m_pResizingStencil->pinPoint().y()); m.rotate(-m_pResizingStencil->rotation()); m.translate(-m_pResizingStencil->pinPoint().x(), -m_pResizingStencil->pinPoint().y()); m.translate(-m_pResizingStencil->x(), -m_pResizingStencil->y()); m.invert(); double x = pagePoint.x() * m.m11() + pagePoint.y() * m.m21() + m.dx(); double y = pagePoint.x() * m.m12() + pagePoint.y() * m.m22() + m.dy();*/ if( !pData ) { kdDebug(43000) << "SelectTool::continueResizing() - Original geometry not found" << endl; return; } double dx = pagePoint.x() - m_origPoint.x(); double dy = pagePoint.y() - m_origPoint.y(); if((dx > 0) || (dy > 0) || (dx < 0) || (dy < 0)) { // Do we really need to redraw? // Undraw the old outline if(!m_firstTime) { canvas->drawStencilXOR( m_pResizingStencil ); } else { m_pResizingStencil->setHidden(true); canvas->repaint(); m_firstTime = false; } double sx = pData->rect.x(); double sy = pData->rect.y(); double sw = pData->rect.width(); double sh = pData->rect.height(); double ratio = sw / sh; switch( m_resizeHandle ) { case 1: // top left if( m_pResizingStencil->protection()->testBit( kpWidth )==false && m_pResizingStencil->protection()->testBit( kpHeight )==false ) { if((dx > dy) && (dx != 0)) { dy = dx / ratio; } else { dx = dy * ratio; } m_pResizingStencil->setX( sx + dx ); m_pResizingStencil->setW( sw - dx ); m_pResizingStencil->setY( sy + dy ); m_pResizingStencil->setH( sh - dy ); } break; case 2: // top if( m_pResizingStencil->protection()->testBit( kpHeight )==false ) { m_pResizingStencil->setY( sy + dy ); m_pResizingStencil->setH( sh - dy ); } break; case 3: // top right if( m_pResizingStencil->protection()->testBit( kpHeight )==false && m_pResizingStencil->protection()->testBit( kpWidth )==false ) { if((dx > dy) && (dx != 0)) { dy = -(dx / ratio); } else { dx = -(dy * ratio); } m_pResizingStencil->setY( sy + dy ); m_pResizingStencil->setH( sh - dy ); m_pResizingStencil->setW( sw + dx ); } break; case 4: // right if( m_pResizingStencil->protection()->testBit( kpWidth )==false ) { // see old kivio source when snaptogrid gets implemented //setX( SnapToGrid(sx+sw+dx)-sx ) m_pResizingStencil->setW( sw + dx ); } break; case 5: // bottom right if( m_pResizingStencil->protection()->testBit( kpWidth )==false && m_pResizingStencil->protection()->testBit( kpHeight )==false ) { if((dx > dy) && (dx != 0)) { dy = dx / ratio; } else { dx = dy * ratio; } m_pResizingStencil->setW( sw + dx ); m_pResizingStencil->setH( sh + dy ); } break; case 6: // bottom if( m_pResizingStencil->protection()->testBit( kpHeight )==false ) { m_pResizingStencil->setH( sh + dy ); } break; case 7: // bottom left if( m_pResizingStencil->protection()->testBit( kpWidth )==false && m_pResizingStencil->protection()->testBit( kpHeight )==false ) { if((dx > dy) && (dx != 0)) { dy = -(dx / ratio); } else { dx = -(dy * ratio); } m_pResizingStencil->setX( sx + dx ); m_pResizingStencil->setW( sw - dx ); m_pResizingStencil->setH( sh + dy ); } break; case 8: // left if( m_pResizingStencil->protection()->testBit( kpWidth )==false ) { KoPoint pinPoint = m_pResizingStencil->pinPoint(); m_pResizingStencil->setPinPoint(KoPoint(pinPoint.x() - (dx / 2.0), pinPoint.y())); m_pResizingStencil->setX( sx + dx ); m_pResizingStencil->setW( sw - dx ); } break; default: kdDebug(43000) << "SelectTool::continueResizing() - unknown resize handle: " << m_resizeHandle << endl; break; } canvas->drawStencilXOR( m_pResizingStencil ); view()->updateToolBars(); } }