/** * Zoom the view in and out. */ void PlotView::wheelEvent(QWheelEvent* event) { // Get the position of the mouse before scaling, in scene coords QPointF pointBeforeScale(mapToScene(event->pos())); // Get the original screen centerpoint QPointF screenCenter = GetCenter(); //CurrentCenterPoint; //(visRect.center()); // Scale the view ie. do the zoom double scaleFactor = 1.25; // How fast we zoom if (event->delta() > 0) { // Zoom in scale(scaleFactor, scaleFactor); } else { // Zooming out scale(1.0 / scaleFactor, 1.0 / scaleFactor); } // Get the position after scaling, in scene coords QPointF pointAfterScale(mapToScene(event->pos())); // Get the offset of how the screen moved QPointF offset = pointBeforeScale - pointAfterScale; // Adjust to the new center for correct zooming QPointF newCenter = screenCenter + offset; SetCenter(newCenter); }
/** * Zoom the view in and out. */ void UMLView::wheelEvent(QWheelEvent* event) { // get the position of the mouse before scaling, in scene coords QPointF pointBeforeScale(mapToScene(event->pos())); // get the original screen centerpoint QPointF screenCenter = center(); // scale the view ie. do the zoom double scaleFactor = 1.15; if (event->delta() > 0) { // zoom in if (currentZoom() < 500) { scale(scaleFactor, scaleFactor); } } else { // zooming out if (currentZoom() > 10) { scale(1.0 / scaleFactor, 1.0 / scaleFactor); } } // get the position after scaling, in scene coords QPointF pointAfterScale(mapToScene(event->pos())); // get the offset of how the screen moved QPointF offset = pointBeforeScale - pointAfterScale; // adjust to the new center for correct zooming QPointF newCenter = screenCenter + offset; setCenter(newCenter); DEBUG(DBG_SRC) << "currentZoom=" << currentZoom(); UMLApp::app()->slotZoomSliderMoved(currentZoom()); }
void MyGraphicsView::scale(double factor) { //Get the position of the mouse before scaling, in scene coords QPointF pointBeforeScale(mapToScene( mLastMouseMovePt )); //Get the original screen centerpoint QPointF screenCenter = GetCenter(); //CurrentCenterPoint; //(visRect.center()); double tempScale = factor; tempScale *= mScaleFactor; if ( tempScale > mZoomMax ) tempScale = mZoomMax; if (tempScale < mZoomMin) tempScale = mZoomMin; factor = tempScale / mScaleFactor; mScaleFactor = tempScale; //Scale the view ie. do the zoom QGraphicsView::scale(factor, factor); //Get the position after scaling, in scene coords QPointF pointAfterScale(mapToScene( mLastMouseMovePt )); //Get the offset of how the screen moved QPointF offset = pointBeforeScale - pointAfterScale; //Adjust to the new center for correct zooming QPointF newCenter = screenCenter + offset; SetCenter(newCenter); }