forked from qt-creator/qt-creator
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:
@@ -35,6 +35,7 @@ Model {
|
|||||||
property View3D view3D
|
property View3D view3D
|
||||||
property alias color: material.emissiveColor
|
property alias color: material.emissiveColor
|
||||||
property Node targetNode: null
|
property Node targetNode: null
|
||||||
|
property bool isDragging: false
|
||||||
|
|
||||||
readonly property bool hovering: mouseAreaYZ.hovering || mouseAreaXZ.hovering
|
readonly property bool hovering: mouseAreaYZ.hovering || mouseAreaXZ.hovering
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ Model {
|
|||||||
_pointerPosPressed = mouseArea.mapPositionToScene(maskedPosition);
|
_pointerPosPressed = mouseArea.mapPositionToScene(maskedPosition);
|
||||||
var sp = targetNode.positionInScene;
|
var sp = targetNode.positionInScene;
|
||||||
_targetStartPos = Qt.vector3d(sp.x, sp.y, sp.z);
|
_targetStartPos = Qt.vector3d(sp.x, sp.y, sp.z);
|
||||||
|
isDragging = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function posInParent(mouseArea, pointerPosition)
|
function posInParent(mouseArea, pointerPosition)
|
||||||
@@ -91,6 +93,7 @@ Model {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
targetNode.position = posInParent(mouseArea, pointerPosition);
|
targetNode.position = posInParent(mouseArea, pointerPosition);
|
||||||
|
isDragging = false;
|
||||||
arrow.positionCommit();
|
arrow.positionCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,11 +44,6 @@ Node {
|
|||||||
onGlobalTransformChanged: updateScale()
|
onGlobalTransformChanged: updateScale()
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: window
|
|
||||||
onFirstFrameReady: updateScale()
|
|
||||||
}
|
|
||||||
|
|
||||||
function getScale(baseScale)
|
function getScale(baseScale)
|
||||||
{
|
{
|
||||||
return Qt.vector3d(baseScale.x * relativeScale, baseScale.y * relativeScale,
|
return Qt.vector3d(baseScale.x * relativeScale, baseScale.y * relativeScale,
|
||||||
|
@@ -135,6 +135,36 @@ Window {
|
|||||||
scene: overlayScene
|
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 {
|
WasdController {
|
||||||
id: cameraControl
|
id: cameraControl
|
||||||
controlledObject: editView.camera
|
controlledObject: editView.camera
|
||||||
|
@@ -32,6 +32,7 @@ Node {
|
|||||||
property View3D view3D
|
property View3D view3D
|
||||||
property bool highlightOnHover: false
|
property bool highlightOnHover: false
|
||||||
property Node targetNode: null
|
property Node targetNode: null
|
||||||
|
readonly property bool isDragging: arrowX.isDragging || arrowY.isDragging || arrowZ.isDragging
|
||||||
|
|
||||||
scale: Qt.vector3d(5, 5, 5)
|
scale: Qt.vector3d(5, 5, 5)
|
||||||
|
|
||||||
|
59
share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml
Normal file
59
share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@@ -11,6 +11,7 @@
|
|||||||
<file>mockfiles/Arrow.qml</file>
|
<file>mockfiles/Arrow.qml</file>
|
||||||
<file>mockfiles/AutoScaleHelper.qml</file>
|
<file>mockfiles/AutoScaleHelper.qml</file>
|
||||||
<file>mockfiles/MoveGizmo.qml</file>
|
<file>mockfiles/MoveGizmo.qml</file>
|
||||||
|
<file>mockfiles/Overlay2D.qml</file>
|
||||||
<file>mockfiles/meshes/Arrow.mesh</file>
|
<file>mockfiles/meshes/Arrow.mesh</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
Reference in New Issue
Block a user