From d1a7afa28fb1050b7e72cad0aa9ab2ff9dbc5287 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 23 Apr 2020 15:40:41 +0300 Subject: [PATCH] QmlDesigner: Add "closeup" option to focusObjectToCamera function The closeup option is used for itemlibrary thumbnail generation, where the regular fit produces too small images on most imports. Change-Id: I2901a2e20d100b155111f002b22489df945e9e01 Fixes: QDS-1899 Reviewed-by: Thomas Hartmann Reviewed-by: Mahmoud Badri --- share/qtcreator/qml/qmlpuppet/mockfiles/AxisHelper.qml | 2 +- .../qml/qmlpuppet/mockfiles/EditCameraController.qml | 5 +++-- share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml | 2 +- share/qtcreator/qml/qmlpuppet/mockfiles/IconRenderer3D.qml | 2 +- .../qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp | 6 ++++-- .../qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h | 5 +++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/AxisHelper.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/AxisHelper.qml index 7481d242252..7ae7bd44d91 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/AxisHelper.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/AxisHelper.qml @@ -121,7 +121,7 @@ View3D { pick(mouse); if (pickObj) { axisHelperView.editCameraCtrl.focusObject(axisHelperView.selectedNode, - pickObj.cameraRotation, false); + pickObj.cameraRotation, false, false); } else { mouse.accepted = false; } diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml index 207dc941994..20dd112d614 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml @@ -87,14 +87,15 @@ Item { } - function focusObject(targetObject, rotation, updateZoom) + function focusObject(targetObject, rotation, updateZoom, closeUp) { if (!camera) return; camera.eulerRotation = rotation; var newLookAtAndZoom = _generalHelper.focusObjectToCamera( - camera, _defaultCameraLookAtDistance, targetObject, view3d, _zoomFactor, updateZoom); + camera, _defaultCameraLookAtDistance, targetObject, view3d, _zoomFactor, + updateZoom, closeUp); _lookAtPoint = newLookAtAndZoom.toVector3d(); _zoomFactor = newLookAtAndZoom.w; storeCameraState(0); diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml index db8d4fb4eab..6527d06e6e7 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml @@ -146,7 +146,7 @@ Item { if (editView) { var targetNode = selectionBoxes.length > 0 ? selectionBoxes[0].model : null; - cameraControl.focusObject(targetNode, editView.camera.eulerRotation, true); + cameraControl.focusObject(targetNode, editView.camera.eulerRotation, true, false); } } diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/IconRenderer3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/IconRenderer3D.qml index b16b27406d9..afaf8481ca6 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/IconRenderer3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/IconRenderer3D.qml @@ -42,7 +42,7 @@ Item { function fitAndHideBox() : bool { - cameraControl.focusObject(selectionBox.model, viewCamera.eulerRotation, true); + cameraControl.focusObject(selectionBox.model, viewCamera.eulerRotation, true, true); if (cameraControl._zoomFactor < 0.1) { view3D.importScene.scale = view3D.importScene.scale.times(10); return false; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp index f99d219c5c5..f62a7e51736 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp @@ -148,7 +148,7 @@ float GeneralHelper::zoomCamera(QQuick3DCamera *camera, float distance, float de // Return value contains new lookAt point (xyz) and zoom factor (w) QVector4D GeneralHelper::focusObjectToCamera(QQuick3DCamera *camera, float defaultLookAtDistance, QQuick3DNode *targetObject, QQuick3DViewport *viewPort, - float oldZoom, bool updateZoom) + float oldZoom, bool updateZoom, bool closeUp) { if (!camera) return QVector4D(0.f, 0.f, 0.f, 1.f); @@ -200,7 +200,9 @@ QVector4D GeneralHelper::focusObjectToCamera(QQuick3DCamera *camera, float defau camera->setPosition(lookAt + newLookVector); - float newZoomFactor = updateZoom ? qBound(.01f, float(maxExtent / 900.), 100.f) : oldZoom; + qreal divisor = closeUp ? 900. : 725.; + + float newZoomFactor = updateZoom ? qBound(.01f, float(maxExtent / divisor), 100.f) : oldZoom; float cameraZoomFactor = zoomCamera(camera, 0, defaultLookAtDistance, lookAt, newZoomFactor, false); return QVector4D(lookAt, cameraZoomFactor); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h index e9d8e525458..15795ac28bd 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h @@ -66,8 +66,9 @@ public: float defaultLookAtDistance, const QVector3D &lookAt, float zoomFactor, bool relative); Q_INVOKABLE QVector4D focusObjectToCamera(QQuick3DCamera *camera, float defaultLookAtDistance, - QQuick3DNode *targetObject, QQuick3DViewport *viewPort, - float oldZoom, bool updateZoom = true); + QQuick3DNode *targetObject, QQuick3DViewport *viewPort, + float oldZoom, bool updateZoom = true, + bool closeUp = false); Q_INVOKABLE void delayedPropertySet(QObject *obj, int delay, const QString &property, const QVariant& value); Q_INVOKABLE QQuick3DNode *resolvePick(QQuick3DNode *pickNode);