Limit the zoom size of the rendered widget

master
Jeremy Hu 2019-08-21 08:29:50 +09:30
parent c4da15eb9e
commit ee94913c62
2 changed files with 17 additions and 0 deletions

View File

@ -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));
}

View File

@ -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<QVector3D, QVector3D> screenPositionToMouseRay(const QPoint &screenPosition);
};