/** * Event delegation * * @param e The event to be identified and processed * */ bool SelectTool::processEvent(QEvent* e) { KivioCanvas* canvas = view()->canvasWidget(); QMouseEvent *m; switch (e->type()) { case QEvent::MouseButtonDblClick: m = (QMouseEvent *)e; if( m->button() == LeftButton ) { leftDoubleClick(m->pos()); } canvas->setFocus(); return true; break; case QEvent::MouseButtonPress: m = (QMouseEvent *)e; if( m->button() == RightButton ) { showPopupMenu(m->globalPos()); } else if( m->button() == LeftButton ) { if(m->state() & ControlButton) { m_controlKey = true; } else { m_controlKey = false; } mousePress( m->pos() ); } canvas->setFocus(); return true; break; case QEvent::MouseButtonRelease: mouseRelease( ((QMouseEvent *)e)->pos() ); canvas->setFocus(); return true; break; case QEvent::MouseMove: mouseMove( static_cast<QMouseEvent*>(e)); return true; break; case QEvent::KeyPress: if((static_cast<QKeyEvent*>(e)->key() >= Key_Left) && (static_cast<QKeyEvent*>(e)->key() <= Key_Down)) { keyPress(static_cast<QKeyEvent*>(e)); return true; } break; default: break; } return false; }
void SelectTool::keyPress(QKeyEvent* e) { KivioCanvas* canvas = view()->canvasWidget(); canvas->setEnabled(false); // Create a new painter object canvas->beginUnclippedSpawnerPainter(); // Build the list of old geometry KivioSelectDragData *pData; m_lstOldGeometry.clear(); KivioStencil* pStencil = canvas->activePage()->selectedStencils()->first(); while( pStencil ) { pData = new KivioSelectDragData; pData->rect = pStencil->rect(); m_lstOldGeometry.append(pData); pStencil = canvas->activePage()->selectedStencils()->next(); } m_selectedRect = view()->activePage()->getRectForAllSelectedStencils(); // Set the mode m_mode = stmDragging; canvas->setEnabled(true); m_origPoint = m_selectedRect.topLeft(); KivioGridData gd = view()->doc()->grid(); bool ignoreGridGuides = e->state() & ShiftButton; double distX, distY; if(ignoreGridGuides || !view()->doc()->grid().isSnap) { distX = view()->zoomHandler()->unzoomItX(1); distY = view()->zoomHandler()->unzoomItY(1); } else { distX = gd.freq.width(); distY = gd.freq.height(); } switch(e->key()) { case Key_Left: continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x() - distX, m_selectedRect.y())), ignoreGridGuides); break; case Key_Up: continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x(), m_selectedRect.y() - distY)), ignoreGridGuides); break; case Key_Right: continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x() + distX, m_selectedRect.y())), ignoreGridGuides); break; case Key_Down: continueDragging(canvas->mapToScreen(KoPoint(m_selectedRect.x(), m_selectedRect.y() + distY)), ignoreGridGuides); break; default: break; } endDragging(QPoint()); canvas->guideLines().repaintAfterSnapping(); canvas->setFocus(); }