From 3a96a8f8e37b7349b2cf726ef8aa42cc5ce75d8d Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Wed, 10 Aug 2011 03:04:31 +0300 Subject: [PATCH] Fixed: #1301 Added max and min zooming. --HG-- branch : gsoc2011-worldeditorqt --- .../landscape_editor/landscape_view.cpp | 39 ++++++------------- .../plugins/landscape_editor/landscape_view.h | 2 +- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp index 6cc6b159e..10e1348df 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp @@ -33,17 +33,15 @@ namespace LandscapeEditor LandscapeView::LandscapeView(QWidget *parent) : QGraphicsView(parent), m_visibleGrid(true), - m_visibleText(false) + m_visibleText(true) { - //setDragMode(ScrollHandDrag); setTransformationAnchor(AnchorUnderMouse); setBackgroundBrush(QBrush(Qt::lightGray)); - //setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - //setRenderHints(QPainter::Antialiasing); - //setCacheMode(QGraphicsView::CacheBackground); + m_cellSize = 160; - m_numSteps = 0; - m_maxSteps = 20; + m_maxView = 0.06; + m_minView = 32.0; + m_maxViewText = 0.6; //A modified version of centerOn(), handles special cases setCenter(QPointF(500.0, 500.0)); @@ -72,25 +70,7 @@ void LandscapeView::setVisibleText(bool visible) void LandscapeView::wheelEvent(QWheelEvent *event) { - /* double numDegrees = event->delta() / 8.0; - double numSteps = numDegrees / 15.0; - double factor = std::pow(1.125, numSteps); - if (factor > 1.0) - { - // check max scale view - if (m_numSteps > m_maxSteps) - return; - ++m_numSteps; - } - else - { - // check min scale view - if (m_numSteps < -m_maxSteps) - return; - --m_numSteps; - } - scale(factor, factor); - QGraphicsView::wheelEvent(event);*/ + //nlinfo(QString("%1").arg(transform().m11()).toStdString().c_str()); //Get the position of the mouse before scaling, in scene coords QPointF pointBeforeScale(mapToScene(event->pos())); @@ -102,11 +82,16 @@ void LandscapeView::wheelEvent(QWheelEvent *event) double scaleFactor = 1.15; //How fast we zoom if(event->delta() > 0) { + if (transform().m11() > m_minView ) + return; //Zoom in scale(scaleFactor, scaleFactor); } else { + if (transform().m11() < m_maxView ) + return; + //Zooming out scale(1.0 / scaleFactor, 1.0 / scaleFactor); } @@ -242,7 +227,7 @@ void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect) if (!m_visibleText) return; - if (m_numSteps > -m_maxSteps / 4) + if (transform().m11() > m_maxViewText) { painter->setPen(QPen(Qt::white, 0.5, Qt::SolidLine)); //painter->setFont(QFont("Helvetica [Cronyx]", 12)); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h index 607afe60f..5ce1fb3a7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h @@ -59,7 +59,7 @@ protected: private: bool m_visibleGrid, m_visibleText; - int m_numSteps, m_maxSteps; + qreal m_maxView, m_minView, m_maxViewText; int m_cellSize; //Holds the current centerpoint for the view, used for panning and zooming