mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-19 13:46:13 +00:00
Change: Fixed incorrect behavior scroll of 2d view in landscape editor qt
This commit is contained in:
parent
ebeae32287
commit
c72828b6dd
1 changed files with 14 additions and 30 deletions
|
@ -70,41 +70,24 @@ void LandscapeView::setVisibleText(bool visible)
|
|||
|
||||
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
|
||||
QPointF pointBeforeScale(mapToScene(event->pos()));
|
||||
QMatrix mat = matrix();
|
||||
QPointF mousePosition = event->pos();
|
||||
|
||||
//Get the original screen centerpoint
|
||||
QPointF screenCenter = getCenter(); //CurrentCenterPoint; //(visRect.center());
|
||||
mat.translate((width() / 2) - mousePosition.x(), (height() / 2) - mousePosition.y());
|
||||
|
||||
//Scale the view ie. do the zoom
|
||||
double scaleFactor = 1.15; //How fast we zoom
|
||||
if(event->delta() > 0)
|
||||
{
|
||||
if (transform().m11() > m_minView )
|
||||
return;
|
||||
//Zoom in
|
||||
scale(scaleFactor, scaleFactor);
|
||||
}
|
||||
if ( numSteps > 0 )
|
||||
mat.scale(numSteps, numSteps);
|
||||
else
|
||||
{
|
||||
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.scale(-1 / numSteps, -1 / numSteps);
|
||||
|
||||
mat.translate(mousePosition.x() - (width() / 2), mousePosition.y() - (height() / 2));
|
||||
|
||||
//Adjust to the new center for correct zooming
|
||||
QPointF newCenter = screenCenter + offset;
|
||||
setCenter(newCenter);
|
||||
setMatrix(mat);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void LandscapeView::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -202,7 +185,8 @@ void LandscapeView::setCenter(const QPointF ¢erPoint)
|
|||
|
||||
QPointF LandscapeView::getCenter() const
|
||||
{
|
||||
return m_currentCenterPoint;
|
||||
//return m_currentCenterPoint;
|
||||
return mapToScene(viewport()->rect().center());
|
||||
}
|
||||
|
||||
void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
|
||||
|
|
Loading…
Reference in a new issue