QmlDesigner: Fix orthographic camera zoom

Scale no longer affects cameras, so use magnification instead to do
orthographic camera zooming.

Fixes: QDS-10241
Change-Id: Ic31abfdf741369a494b8178109fa1c5b95fbdd1c
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2023-08-08 13:00:18 +03:00
parent 60ea887d5f
commit a05ba1696f
2 changed files with 11 additions and 10 deletions

View File

@@ -747,7 +747,8 @@ Item {
clipNear: viewRoot.editView ? viewRoot.editView.orthoCamera.clipNear : 1 clipNear: viewRoot.editView ? viewRoot.editView.orthoCamera.clipNear : 1
position: viewRoot.editView ? viewRoot.editView.orthoCamera.position : Qt.vector3d(0, 0, 0) position: viewRoot.editView ? viewRoot.editView.orthoCamera.position : Qt.vector3d(0, 0, 0)
rotation: viewRoot.editView ? viewRoot.editView.orthoCamera.rotation : Qt.quaternion(1, 0, 0, 0) rotation: viewRoot.editView ? viewRoot.editView.orthoCamera.rotation : Qt.quaternion(1, 0, 0, 0)
scale: viewRoot.editView ? viewRoot.editView.orthoCamera.scale : Qt.vector3d(0, 0, 0) horizontalMagnification: viewRoot.editView ? viewRoot.editView.orthoCamera.horizontalMagnification : 1
verticalMagnification: viewRoot.editView ? viewRoot.editView.orthoCamera.verticalMagnification : 1
} }
MouseArea3D { MouseArea3D {

View File

@@ -154,16 +154,16 @@ float GeneralHelper::zoomCamera([[maybe_unused]] QQuick3DViewport *viewPort,
float newZoomFactor = relative ? qBound(.01f, zoomFactor * multiplier, 100.f) float newZoomFactor = relative ? qBound(.01f, zoomFactor * multiplier, 100.f)
: zoomFactor; : zoomFactor;
if (qobject_cast<QQuick3DOrthographicCamera *>(camera)) { if (auto orthoCamera = qobject_cast<QQuick3DOrthographicCamera *>(camera)) {
// Ortho camera we can simply scale // Ortho camera we can simply magnify
float orthoFactor = newZoomFactor; if (newZoomFactor != 0.f) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) orthoCamera->setHorizontalMagnification(1.f / newZoomFactor);
if (viewPort) { orthoCamera->setVerticalMagnification(1.f / newZoomFactor);
if (const QQuickWindow *w = viewPort->window()) // Force update on transform, so gizmos get correctly scaled and positioned
orthoFactor *= w->devicePixelRatio(); float x = orthoCamera->x();
orthoCamera->setX(x + 1.f);
orthoCamera->setX(x);
} }
#endif
camera->setScale(QVector3D(orthoFactor, orthoFactor, orthoFactor));
} else if (qobject_cast<QQuick3DPerspectiveCamera *>(camera)) { } else if (qobject_cast<QQuick3DPerspectiveCamera *>(camera)) {
// Perspective camera is zoomed by moving camera forward or backward while keeping the // Perspective camera is zoomed by moving camera forward or backward while keeping the
// look-at point the same // look-at point the same