QmlDesigner: Add overlay display to show position in 3D edit view

When dragging using move gizmo, a label is displayed that shows the
current position of the selected object.

Change-Id: I2e03b363ce9dcb975bcfe198ffae2e98024d74c8
Fixes: QDS-1129
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2019-10-24 17:22:49 +03:00
parent 362d65301d
commit 0de98aa240
6 changed files with 94 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ Model {
property View3D view3D
property alias color: material.emissiveColor
property Node targetNode: null
property bool isDragging: false
readonly property bool hovering: mouseAreaYZ.hovering || mouseAreaXZ.hovering
@@ -58,6 +59,7 @@ Model {
_pointerPosPressed = mouseArea.mapPositionToScene(maskedPosition);
var sp = targetNode.positionInScene;
_targetStartPos = Qt.vector3d(sp.x, sp.y, sp.z);
isDragging = true;
}
function posInParent(mouseArea, pointerPosition)
@@ -91,6 +93,7 @@ Model {
return;
targetNode.position = posInParent(mouseArea, pointerPosition);
isDragging = false;
arrow.positionCommit();
}

View File

@@ -44,11 +44,6 @@ Node {
onGlobalTransformChanged: updateScale()
}
Connections {
target: window
onFirstFrameReady: updateScale()
}
function getScale(baseScale)
{
return Qt.vector3d(baseScale.x * relativeScale, baseScale.y * relativeScale,

View File

@@ -135,6 +135,36 @@ Window {
scene: overlayScene
}
Overlay2D {
id: gizmoLabel
targetNode: moveGizmo
targetView: overlayView
offsetX: 0
offsetY: 45
visible: moveGizmo.isDragging
Rectangle {
color: "white"
x: -width / 2
y: -height
width: gizmoLabelText.width + 4
height: gizmoLabelText.height + 4
border.width: 1
Text {
id: gizmoLabelText
text: {
var l = Qt.locale();
selectedNode
? qsTr("x:") + Number(selectedNode.position.x).toLocaleString(l, 'f', 1)
+ qsTr(" y:") + Number(selectedNode.position.y).toLocaleString(l, 'f', 1)
+ qsTr(" z:") + Number(selectedNode.position.z).toLocaleString(l, 'f', 1)
: "";
}
anchors.centerIn: parent
}
}
}
WasdController {
id: cameraControl
controlledObject: editView.camera

View File

@@ -32,6 +32,7 @@ Node {
property View3D view3D
property bool highlightOnHover: false
property Node targetNode: null
readonly property bool isDragging: arrowX.isDragging || arrowY.isDragging || arrowZ.isDragging
scale: Qt.vector3d(5, 5, 5)

View File

@@ -0,0 +1,59 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
import QtQuick 2.0
import QtQuick3D 1.0
Item {
id: root
property Node targetNode
property View3D targetView
property real offsetX: 0
property real offsetY: 0
onTargetNodeChanged: updateOverlay()
Connections {
target: targetNode
onGlobalTransformChanged: updateOverlay()
}
Connections {
target: targetView.camera
onGlobalTransformChanged: updateOverlay()
}
function updateOverlay()
{
var posInScene = targetNode.positionInScene
var posInSceneWithOffset = Qt.vector3d(posInScene.x + offsetX, posInScene.y + offsetY,
posInScene.z)
var viewPos = targetView.mapFrom3DScene(posInSceneWithOffset)
root.x = viewPos.x
root.y = viewPos.y
root.z = 100000 - viewPos.z // flip left-handed to right-handed
}
}

View File

@@ -11,6 +11,7 @@
<file>mockfiles/Arrow.qml</file>
<file>mockfiles/AutoScaleHelper.qml</file>
<file>mockfiles/MoveGizmo.qml</file>
<file>mockfiles/Overlay2D.qml</file>
<file>mockfiles/meshes/Arrow.mesh</file>
</qresource>
</RCC>