1/**************************************************************************** 2** 3** Copyright (C) 2019 The Qt Company Ltd. 4** Contact: https://www.qt.io/licensing/ 5** 6** This file is part of Qt Creator. 7** 8** Commercial License Usage 9** Licensees holding valid commercial Qt licenses may use this file in 10** accordance with the commercial license agreement provided with the 11** Software or, alternatively, in accordance with the terms contained in 12** a written agreement between you and The Qt Company. For licensing terms 13** and conditions see https://www.qt.io/terms-conditions. For further 14** information use the contact form at https://www.qt.io/contact-us. 15** 16** GNU General Public License Usage 17** Alternatively, this file may be used under the terms of the GNU 18** General Public License version 3 as published by the Free Software 19** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20** included in the packaging of this file. Please review the following 21** information to ensure the GNU General Public License requirements will 22** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23** 24****************************************************************************/ 25 26import QtQuick 6.0 27import QtQuick3D 6.0 28import MouseArea3D 1.0 29 30Node { 31 id: moveGizmo 32 33 property View3D view3D 34 property bool highlightOnHover: false 35 property Node targetNode: null 36 property bool globalOrientation: true 37 readonly property bool dragging: arrowX.dragging || arrowY.dragging || arrowZ.dragging 38 || planeX.dragging || planeY.dragging || planeZ.dragging 39 || centerBall.dragging 40 property MouseArea3D dragHelper: null 41 property alias freeDraggerArea: centerBall.mouseArea 42 43 position: dragHelper.pivotScenePosition(targetNode) 44 45 onTargetNodeChanged: position = dragHelper.pivotScenePosition(targetNode) 46 47 Connections { 48 target: moveGizmo.targetNode 49 function onSceneTransformChanged() 50 { 51 moveGizmo.position = moveGizmo.dragHelper.pivotScenePosition(moveGizmo.targetNode); 52 } 53 } 54 55 signal positionCommit() 56 signal positionMove() 57 58 Node { 59 rotation: globalOrientation || !moveGizmo.targetNode ? Qt.quaternion(1, 0, 0, 0) 60 : moveGizmo.targetNode.sceneRotation 61 Arrow { 62 id: arrowX 63 eulerRotation: Qt.vector3d(0, 0, -90) 64 targetNode: moveGizmo.targetNode 65 color: highlightOnHover && (hovering || dragging) ? Qt.lighter(Qt.rgba(1, 0, 0, 1)) 66 : Qt.rgba(1, 0, 0, 1) 67 view3D: moveGizmo.view3D 68 active: moveGizmo.visible 69 dragHelper: moveGizmo.dragHelper 70 71 onPositionCommit: moveGizmo.positionCommit() 72 onPositionMove: moveGizmo.positionMove() 73 } 74 75 Arrow { 76 id: arrowY 77 eulerRotation: Qt.vector3d(0, 0, 0) 78 targetNode: moveGizmo.targetNode 79 color: highlightOnHover && (hovering || dragging) ? Qt.lighter(Qt.rgba(0, 0.6, 0, 1)) 80 : Qt.rgba(0, 0.6, 0, 1) 81 view3D: moveGizmo.view3D 82 active: moveGizmo.visible 83 dragHelper: moveGizmo.dragHelper 84 85 onPositionCommit: moveGizmo.positionCommit() 86 onPositionMove: moveGizmo.positionMove() 87 } 88 89 Arrow { 90 id: arrowZ 91 eulerRotation: Qt.vector3d(90, 0, 0) 92 targetNode: moveGizmo.targetNode 93 color: highlightOnHover && (hovering || dragging) ? Qt.lighter(Qt.rgba(0, 0, 1, 1)) 94 : Qt.rgba(0, 0, 1, 1) 95 view3D: moveGizmo.view3D 96 active: moveGizmo.visible 97 dragHelper: moveGizmo.dragHelper 98 99 onPositionCommit: moveGizmo.positionCommit() 100 onPositionMove: moveGizmo.positionMove() 101 } 102 103 PlanarMoveHandle { 104 id: planeX 105 106 y: 10 107 z: 10 108 109 eulerRotation: Qt.vector3d(0, 90, 0) 110 targetNode: moveGizmo.targetNode 111 color: highlightOnHover && (hovering || dragging) ? Qt.lighter(Qt.rgba(1, 0, 0, 1)) 112 : Qt.rgba(1, 0, 0, 1) 113 view3D: moveGizmo.view3D 114 active: moveGizmo.visible 115 dragHelper: moveGizmo.dragHelper 116 117 onPositionCommit: moveGizmo.positionCommit() 118 onPositionMove: moveGizmo.positionMove() 119 } 120 121 PlanarMoveHandle { 122 id: planeY 123 124 x: 10 125 z: 10 126 127 eulerRotation: Qt.vector3d(90, 0, 0) 128 targetNode: moveGizmo.targetNode 129 color: highlightOnHover && (hovering || dragging) ? Qt.lighter(Qt.rgba(0, 0.6, 0, 1)) 130 : Qt.rgba(0, 0.6, 0, 1) 131 view3D: moveGizmo.view3D 132 active: moveGizmo.visible 133 dragHelper: moveGizmo.dragHelper 134 135 onPositionCommit: moveGizmo.positionCommit() 136 onPositionMove: moveGizmo.positionMove() 137 } 138 139 PlanarMoveHandle { 140 id: planeZ 141 142 x: 10 143 y: 10 144 145 eulerRotation: Qt.vector3d(0, 0, 0) 146 targetNode: moveGizmo.targetNode 147 color: highlightOnHover && (hovering || dragging) ? Qt.lighter(Qt.rgba(0, 0, 1, 1)) 148 : Qt.rgba(0, 0, 1, 1) 149 view3D: moveGizmo.view3D 150 active: moveGizmo.visible 151 dragHelper: moveGizmo.dragHelper 152 153 onPositionCommit: moveGizmo.positionCommit() 154 onPositionMove: moveGizmo.positionMove() 155 } 156 } 157 158 PlanarMoveHandle { 159 id: centerBall 160 161 source: "#Sphere" 162 color: highlightOnHover && (hovering || dragging) ? Qt.lighter(Qt.rgba(0.5, 0.5, 0.5, 1)) 163 : Qt.rgba(0.5, 0.5, 0.5, 1) 164 rotation: view3D.camera.rotation 165 priority: 10 166 targetNode: moveGizmo.targetNode 167 168 view3D: moveGizmo.view3D 169 active: moveGizmo.visible 170 dragHelper: moveGizmo.dragHelper 171 172 onPositionCommit: moveGizmo.positionCommit() 173 onPositionMove: moveGizmo.positionMove() 174 } 175} 176