Change: Fixed incorrect behavior scroll of 2d view in landscape editor qt
--HG-- branch : gsoc2011-worldeditorqt
This commit is contained in:
parent
602ca06998
commit
d62b9db23c
1 changed files with 14 additions and 30 deletions
|
@ -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
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
mat.translate(mousePosition.x() - (width() / 2), mousePosition.y() - (height() / 2));
|
||||||
|
|
||||||
//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 ¢erPoint)
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue