From 0de98aa240b696d399ed7ed66856ff87f7e596af Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 24 Oct 2019 17:22:49 +0300 Subject: [PATCH] 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 Reviewed-by: Thomas Hartmann --- .../qml/qmlpuppet/mockfiles/Arrow.qml | 3 + .../qmlpuppet/mockfiles/AutoScaleHelper.qml | 5 -- .../qml/qmlpuppet/mockfiles/EditView3D.qml | 30 ++++++++++ .../qml/qmlpuppet/mockfiles/MoveGizmo.qml | 1 + .../qml/qmlpuppet/mockfiles/Overlay2D.qml | 59 +++++++++++++++++++ share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc | 1 + 6 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/Arrow.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/Arrow.qml index 7c9ef095897..ae84b05cb65 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/Arrow.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/Arrow.qml @@ -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(); } diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml index c8d21604d3b..640f560ff80 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml @@ -44,11 +44,6 @@ Node { onGlobalTransformChanged: updateScale() } - Connections { - target: window - onFirstFrameReady: updateScale() - } - function getScale(baseScale) { return Qt.vector3d(baseScale.x * relativeScale, baseScale.y * relativeScale, diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml index b0ec597cba1..dc1ff60cfca 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml @@ -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 diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/MoveGizmo.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/MoveGizmo.qml index 62a4e9e7c73..73b80018a92 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/MoveGizmo.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/MoveGizmo.qml @@ -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) diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml new file mode 100644 index 00000000000..fe9398bfdfd --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml @@ -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 + } +} diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc b/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc index 001591a96d5..03931c280e6 100644 --- a/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc +++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc @@ -11,6 +11,7 @@ mockfiles/Arrow.qml mockfiles/AutoScaleHelper.qml mockfiles/MoveGizmo.qml + mockfiles/Overlay2D.qml mockfiles/meshes/Arrow.mesh