forked from qt-creator/qt-creator
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 <thomas.hartmann@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -121,7 +121,7 @@ View3D {
|
|||||||
pick(mouse);
|
pick(mouse);
|
||||||
if (pickObj) {
|
if (pickObj) {
|
||||||
axisHelperView.editCameraCtrl.focusObject(axisHelperView.selectedNode,
|
axisHelperView.editCameraCtrl.focusObject(axisHelperView.selectedNode,
|
||||||
pickObj.cameraRotation, false);
|
pickObj.cameraRotation, false, false);
|
||||||
} else {
|
} else {
|
||||||
mouse.accepted = false;
|
mouse.accepted = false;
|
||||||
}
|
}
|
||||||
|
@@ -87,14 +87,15 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function focusObject(targetObject, rotation, updateZoom)
|
function focusObject(targetObject, rotation, updateZoom, closeUp)
|
||||||
{
|
{
|
||||||
if (!camera)
|
if (!camera)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
camera.eulerRotation = rotation;
|
camera.eulerRotation = rotation;
|
||||||
var newLookAtAndZoom = _generalHelper.focusObjectToCamera(
|
var newLookAtAndZoom = _generalHelper.focusObjectToCamera(
|
||||||
camera, _defaultCameraLookAtDistance, targetObject, view3d, _zoomFactor, updateZoom);
|
camera, _defaultCameraLookAtDistance, targetObject, view3d, _zoomFactor,
|
||||||
|
updateZoom, closeUp);
|
||||||
_lookAtPoint = newLookAtAndZoom.toVector3d();
|
_lookAtPoint = newLookAtAndZoom.toVector3d();
|
||||||
_zoomFactor = newLookAtAndZoom.w;
|
_zoomFactor = newLookAtAndZoom.w;
|
||||||
storeCameraState(0);
|
storeCameraState(0);
|
||||||
|
@@ -146,7 +146,7 @@ Item {
|
|||||||
if (editView) {
|
if (editView) {
|
||||||
var targetNode = selectionBoxes.length > 0
|
var targetNode = selectionBoxes.length > 0
|
||||||
? selectionBoxes[0].model : null;
|
? selectionBoxes[0].model : null;
|
||||||
cameraControl.focusObject(targetNode, editView.camera.eulerRotation, true);
|
cameraControl.focusObject(targetNode, editView.camera.eulerRotation, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ Item {
|
|||||||
|
|
||||||
function fitAndHideBox() : bool
|
function fitAndHideBox() : bool
|
||||||
{
|
{
|
||||||
cameraControl.focusObject(selectionBox.model, viewCamera.eulerRotation, true);
|
cameraControl.focusObject(selectionBox.model, viewCamera.eulerRotation, true, true);
|
||||||
if (cameraControl._zoomFactor < 0.1) {
|
if (cameraControl._zoomFactor < 0.1) {
|
||||||
view3D.importScene.scale = view3D.importScene.scale.times(10);
|
view3D.importScene.scale = view3D.importScene.scale.times(10);
|
||||||
return false;
|
return false;
|
||||||
|
@@ -148,7 +148,7 @@ float GeneralHelper::zoomCamera(QQuick3DCamera *camera, float distance, float de
|
|||||||
// Return value contains new lookAt point (xyz) and zoom factor (w)
|
// Return value contains new lookAt point (xyz) and zoom factor (w)
|
||||||
QVector4D GeneralHelper::focusObjectToCamera(QQuick3DCamera *camera, float defaultLookAtDistance,
|
QVector4D GeneralHelper::focusObjectToCamera(QQuick3DCamera *camera, float defaultLookAtDistance,
|
||||||
QQuick3DNode *targetObject, QQuick3DViewport *viewPort,
|
QQuick3DNode *targetObject, QQuick3DViewport *viewPort,
|
||||||
float oldZoom, bool updateZoom)
|
float oldZoom, bool updateZoom, bool closeUp)
|
||||||
{
|
{
|
||||||
if (!camera)
|
if (!camera)
|
||||||
return QVector4D(0.f, 0.f, 0.f, 1.f);
|
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);
|
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);
|
float cameraZoomFactor = zoomCamera(camera, 0, defaultLookAtDistance, lookAt, newZoomFactor, false);
|
||||||
|
|
||||||
return QVector4D(lookAt, cameraZoomFactor);
|
return QVector4D(lookAt, cameraZoomFactor);
|
||||||
|
@@ -66,8 +66,9 @@ public:
|
|||||||
float defaultLookAtDistance, const QVector3D &lookAt,
|
float defaultLookAtDistance, const QVector3D &lookAt,
|
||||||
float zoomFactor, bool relative);
|
float zoomFactor, bool relative);
|
||||||
Q_INVOKABLE QVector4D focusObjectToCamera(QQuick3DCamera *camera, float defaultLookAtDistance,
|
Q_INVOKABLE QVector4D focusObjectToCamera(QQuick3DCamera *camera, float defaultLookAtDistance,
|
||||||
QQuick3DNode *targetObject, QQuick3DViewport *viewPort,
|
QQuick3DNode *targetObject, QQuick3DViewport *viewPort,
|
||||||
float oldZoom, bool updateZoom = true);
|
float oldZoom, bool updateZoom = true,
|
||||||
|
bool closeUp = false);
|
||||||
Q_INVOKABLE void delayedPropertySet(QObject *obj, int delay, const QString &property,
|
Q_INVOKABLE void delayedPropertySet(QObject *obj, int delay, const QString &property,
|
||||||
const QVariant& value);
|
const QVariant& value);
|
||||||
Q_INVOKABLE QQuick3DNode *resolvePick(QQuick3DNode *pickNode);
|
Q_INVOKABLE QQuick3DNode *resolvePick(QQuick3DNode *pickNode);
|
||||||
|
Reference in New Issue
Block a user