Commit fbfbffea authored by Ralf Habacker's avatar Ralf Habacker

Fix wheel mouse inaccuracy on zooming.

The inaccuracy is caused by UMLApp instance and UMLView scroll bars
propagating slightly modified zoom value back to the UMLView instance.

The fix is to disable the back propagation.

CCBUG:358097
parent 014319ab
......@@ -712,11 +712,15 @@ void UMLApp::slotZoomIn()
* Set the zoom factor of the current diagram.
*
* @param zoom Zoom factor in percentage.
* @param withView also setup the currently displayed diagram
*/
void UMLApp::setZoom(int zoom)
void UMLApp::setZoom(int zoom, bool withView)
{
currentView()->setZoom(zoom);
if (withView)
currentView()->setZoom(zoom);
bool oldState = m_pZoomSlider->blockSignals(true);
m_pZoomSlider->setValue(zoom);
m_pZoomSlider->blockSignals(oldState);
m_zoomValueLbl->setText(QString::number(zoom) + QLatin1Char('%'));
}
......
......@@ -357,7 +357,7 @@ private:
QMenu* findMenu(const QString &name);
QAction* createZoomAction(int zoom, int currentZoom);
void setZoom(int zoom);
void setZoom(int zoom, bool withView = true);
void resetStatusMsg();
......@@ -519,6 +519,7 @@ private:
signals:
void sigCutSuccessful();
friend class UMLView;
};
#endif // UML_H
......@@ -24,6 +24,7 @@
#include "umlwidget.h"
#include <QPointer>
#include <QScrollBar>
DEBUG_REGISTER(UMLView)
......@@ -37,6 +38,8 @@ UMLView::UMLView(UMLFolder *parentFolder)
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setDragMode(NoDrag); //:TODO: RubberBandDrag);
setScene(new UMLScene(parentFolder, this));
setResizeAnchor(AnchorUnderMouse);
setTransformationAnchor(AnchorUnderMouse);
}
/**
......@@ -132,14 +135,14 @@ void UMLView::wheelEvent(QWheelEvent* event)
if (event->delta() > 0) {
// zoom in
if (zoom() < 500) {
scale(scaleFactor, scaleFactor);
setZoom(zoom() * scaleFactor);
} else {
return;
}
} else {
// zooming out
if (zoom() > 10) {
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
setZoom(zoom() / scaleFactor);
} else {
return;
}
......@@ -152,11 +155,16 @@ void UMLView::wheelEvent(QWheelEvent* event)
QPointF offset = pointBeforeScale - pointAfterScale;
// adjust to the new center for correct zooming
QPointF newCenter = mapToScene(rect()).boundingRect().center() + offset;
QPointF newCenter = mapToScene(viewport()->rect().center()) + offset;
bool oldState1 = verticalScrollBar()->blockSignals(true);
bool oldState2 = horizontalScrollBar()->blockSignals(true);
centerOn(newCenter);
verticalScrollBar()->blockSignals(oldState1);
horizontalScrollBar()->blockSignals(oldState2);
DEBUG(DBG_SRC) << "currentZoom=" << zoom();
UMLApp::app()->slotZoomSliderMoved(zoom());
UMLApp::app()->setZoom(zoom(), false);
}
/**
......@@ -215,3 +223,15 @@ void UMLView::mouseReleaseEvent(QMouseEvent* event)
} else
QGraphicsView::mouseReleaseEvent(event);
}
/**
* Override standard method.
*/
void UMLView::resizeEvent(QResizeEvent *event)
{
bool oldState1 = verticalScrollBar()->blockSignals(true);
bool oldState2 = horizontalScrollBar()->blockSignals(true);
QGraphicsView::resizeEvent(event);
verticalScrollBar()->blockSignals(oldState1);
horizontalScrollBar()->blockSignals(oldState2);
}
......@@ -56,6 +56,7 @@ protected:
virtual void hideEvent(QHideEvent *he);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
virtual void resizeEvent(QResizeEvent *event);
};
#endif // UMLVIEW_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment