diff --git a/src/modelwidget.cpp b/src/modelwidget.cpp index ec15b4f1..64fb4175 100644 --- a/src/modelwidget.cpp +++ b/src/modelwidget.cpp @@ -11,6 +11,8 @@ bool ModelWidget::m_transparent = true; const QVector3D ModelWidget::m_cameraPosition = QVector3D(0, 0, -4.0); +float ModelWidget::m_minZoomRatio = 5.0; +float ModelWidget::m_maxZoomRatio = 90.0; ModelWidget::ModelWidget(QWidget *parent) : QOpenGLWidget(parent), @@ -320,6 +322,18 @@ bool ModelWidget::inputWheelEventFromOtherWidget(QWheelEvent *event) void ModelWidget::zoom(float delta) { QMargins margins(delta, delta, delta, delta); + if (0 == m_modelInitialHeight) { + m_modelInitialHeight = height(); + } else { + float ratio = (float)height() / m_modelInitialHeight; + if (ratio <= m_minZoomRatio) { + if (delta < 0) + return; + } else if (ratio >= m_maxZoomRatio) { + if (delta > 0) + return; + } + } setGeometry(geometry().marginsAdded(margins)); } diff --git a/src/modelwidget.h b/src/modelwidget.h index 0e791c77..2e9d08a8 100644 --- a/src/modelwidget.h +++ b/src/modelwidget.h @@ -88,8 +88,11 @@ private: float m_mousePickRadius = 0.0; static bool m_transparent; static const QVector3D m_cameraPosition; + static float m_minZoomRatio; + static float m_maxZoomRatio; QPoint m_moveStartPos; QRect m_moveStartGeometry; + int m_modelInitialHeight = 0; std::pair screenPositionToMouseRay(const QPoint &screenPosition); };