Change: Fixed incorrect behavior scroll of 2d view in landscape editor qt

This commit is contained in:
dnk-88 2012-12-15 00:41:29 +03:00
parent 199ee931d9
commit 697a92b1d6

View file

@ -70,41 +70,24 @@ void LandscapeView::setVisibleText(bool visible)
void LandscapeView::wheelEvent(QWheelEvent *event) void LandscapeView::wheelEvent(QWheelEvent *event)
{ {
//nlinfo(QString("%1").arg(transform().m11()).toStdString().c_str()); //How fast we zoom
float numSteps = (( event->delta() / 8 ) / 15) * 1.2;
//Get the position of the mouse before scaling, in scene coords QMatrix mat = matrix();
QPointF pointBeforeScale(mapToScene(event->pos())); QPointF mousePosition = event->pos();
//Get the original screen centerpoint mat.translate((width() / 2) - mousePosition.x(), (height() / 2) - mousePosition.y());
QPointF screenCenter = getCenter(); //CurrentCenterPoint; //(visRect.center());
//Scale the view ie. do the zoom if ( numSteps > 0 )
double scaleFactor = 1.15; //How fast we zoom mat.scale(numSteps, numSteps);
if(event->delta() > 0)
{
if (transform().m11() > m_minView )
return;
//Zoom in
scale(scaleFactor, scaleFactor);
}
else else
{ mat.scale(-1 / numSteps, -1 / numSteps);
if (transform().m11() < m_maxView )
return;
//Zooming out mat.translate(mousePosition.x() - (width() / 2), mousePosition.y() - (height() / 2));
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 //Adjust to the new center for correct zooming
QPointF newCenter = screenCenter + offset; setMatrix(mat);
setCenter(newCenter); event->accept();
} }
void LandscapeView::mousePressEvent(QMouseEvent *event) void LandscapeView::mousePressEvent(QMouseEvent *event)
@ -202,7 +185,8 @@ void LandscapeView::setCenter(const QPointF &centerPoint)
QPointF LandscapeView::getCenter() const QPointF LandscapeView::getCenter() const
{ {
return m_currentCenterPoint; //return m_currentCenterPoint;
return mapToScene(viewport()->rect().center());
} }
void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect) void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)