summaryrefslogtreecommitdiff
path: root/share/qtcreator/qml/qmlpuppet/mockfiles
diff options
context:
space:
mode:
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/mockfiles')
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml2
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml118
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml54
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml2
4 files changed, 137 insertions, 39 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml
index 9ffd3aa85b..cec64b32b5 100644
--- a/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/AutoScaleHelper.qml
@@ -46,7 +46,7 @@ Node {
}
Connections {
- target: designStudioNativeCameraControlHelper
+ target: _generalHelper
onOverlayUpdateNeeded: updateScale()
}
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml
new file mode 100644
index 0000000000..90f82bd341
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditCameraController.qml
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** 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.12
+import QtQuick3D 1.0
+
+Item {
+ id: cameraCtrl
+
+ property Camera camera: null
+
+ property vector3d _lookAtPoint
+ property vector3d _pressPoint
+ property vector3d _prevPoint
+ property vector3d _startRotation
+ property vector3d _startPosition
+ property vector3d _startLookAtPoint
+ property matrix4x4 _startTransform
+ property bool _dragging
+ property int _button
+ property real _zoomFactor: 1
+ property real _defaultCameraLookAtDistance: 0
+ property Camera _prevCamera: null
+
+ function zoomRelative(distance)
+ {
+ _zoomFactor = _generalHelper.zoomCamera(camera, distance, _defaultCameraLookAtDistance,
+ _lookAtPoint, _zoomFactor, true);
+ }
+
+ Component.onCompleted: {
+ cameraCtrl._defaultCameraLookAtDistance = cameraCtrl.camera.position.length();
+ }
+
+ onCameraChanged: {
+ if (_prevCamera) {
+ // Reset zoom on previous camera to ensure it's properties are good to copy to new cam
+ _generalHelper.zoomCamera(_prevCamera, 0, _defaultCameraLookAtDistance, _lookAtPoint,
+ 1, false);
+
+ camera.position = _prevCamera.position;
+ camera.rotation = _prevCamera.rotation;
+
+ // Apply correct zoom to new camera
+ _generalHelper.zoomCamera(camera, 0, _defaultCameraLookAtDistance, _lookAtPoint,
+ _zoomFactor, false);
+ }
+ _prevCamera = camera;
+ }
+
+ MouseArea {
+ id: mouseHandler
+ acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
+ hoverEnabled: false
+ anchors.fill: parent
+ onPositionChanged: {
+ if (mouse.modifiers === Qt.AltModifier && cameraCtrl._dragging) {
+ var currentPoint = Qt.vector3d(mouse.x, mouse.y, 0);
+ if (cameraCtrl._button == Qt.LeftButton) {
+ _generalHelper.orbitCamera(cameraCtrl.camera, cameraCtrl._startRotation,
+ cameraCtrl._lookAtPoint, cameraCtrl._pressPoint,
+ currentPoint);
+ } else if (cameraCtrl._button == Qt.MiddleButton) {
+ cameraCtrl._lookAtPoint = _generalHelper.panCamera(
+ cameraCtrl.camera, cameraCtrl._startTransform,
+ cameraCtrl._startPosition, cameraCtrl._startLookAtPoint,
+ cameraCtrl._pressPoint, currentPoint, _zoomFactor);
+ } else if (cameraCtrl._button == Qt.RightButton) {
+ cameraCtrl.zoomRelative(currentPoint.y - cameraCtrl._prevPoint.y)
+ cameraCtrl._prevPoint = currentPoint;
+ }
+ }
+ }
+ onPressed: {
+ if (mouse.modifiers === Qt.AltModifier) {
+ cameraCtrl._dragging = true;
+ cameraCtrl._startRotation = cameraCtrl.camera.rotation;
+ cameraCtrl._startPosition = cameraCtrl.camera.position;
+ cameraCtrl._startLookAtPoint = _lookAtPoint;
+ cameraCtrl._pressPoint = Qt.vector3d(mouse.x, mouse.y, 0);
+ cameraCtrl._prevPoint = cameraCtrl._pressPoint;
+ cameraCtrl._button = mouse.button;
+ cameraCtrl._startTransform = cameraCtrl.camera.sceneTransform;
+ } else {
+ mouse.accepted = false;
+ }
+ }
+
+ onReleased: cameraCtrl._dragging = false;
+ onCanceled: cameraCtrl._dragging = false;
+ onWheel: {
+ // Emprically determined divisor for nice zoom
+ cameraCtrl.zoomRelative(wheel.angleDelta.y / -40);
+ }
+ }
+}
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml
index 9db9d0c8a8..a4d63962d8 100644
--- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml
@@ -26,7 +26,6 @@
import QtQuick 2.12
import QtQuick.Window 2.0
import QtQuick3D 1.0
-import QtQuick3D.Helpers 1.0
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
@@ -78,7 +77,7 @@ Window {
{
var component = Qt.createComponent("CameraGizmo.qml");
if (component.status === Component.Ready) {
- var geometryName = designStudioNativeCameraControlHelper.generateUniqueName("CameraGeometry");
+ var geometryName = _generalHelper.generateUniqueName("CameraGeometry");
var gizmo = component.createObject(
overlayScene,
{"view3D": overlayView, "targetNode": obj, "geometryName": geometryName,
@@ -92,10 +91,10 @@ Window {
// Work-around the fact that the projection matrix for the camera is not calculated until
// the first frame is rendered, so any initial calls to mapFrom3DScene() will fail.
- Component.onCompleted: designStudioNativeCameraControlHelper.requestOverlayUpdate();
+ Component.onCompleted: _generalHelper.requestOverlayUpdate();
- onWidthChanged: designStudioNativeCameraControlHelper.requestOverlayUpdate();
- onHeightChanged: designStudioNativeCameraControlHelper.requestOverlayUpdate();
+ onWidthChanged: _generalHelper.requestOverlayUpdate();
+ onHeightChanged: _generalHelper.requestOverlayUpdate();
Node {
id: overlayScene
@@ -114,6 +113,7 @@ Window {
clipNear: editOrthoCamera.clipNear
position: editOrthoCamera.position
rotation: editOrthoCamera.rotation
+ scale: editOrthoCamera.scale
}
MoveGizmo {
@@ -209,11 +209,14 @@ Window {
linearFade: 0
}
+ // Initial camera position and rotation should be such that they look at origin.
+ // Otherwise EditCameraController._lookAtPoint needs to be initialized to correct
+ // point.
PerspectiveCamera {
id: editPerspectiveCamera
z: -600
- y: 200
- rotation.x: 30
+ y: 600
+ rotation.x: 45
clipFar: 100000
clipNear: 1
}
@@ -221,8 +224,8 @@ Window {
OrthographicCamera {
id: editOrthoCamera
z: -600
- y: 200
- rotation.x: 30
+ y: 600
+ rotation.x: 45
clipFar: 100000
clipNear: 1
}
@@ -273,19 +276,10 @@ Window {
}
}
- WasdController {
+ EditCameraController {
id: cameraControl
- controlledObject: editView.camera
- acceptedButtons: Qt.RightButton
-
- onInputsNeedProcessingChanged: designStudioNativeCameraControlHelper.enabled
- = cameraControl.inputsNeedProcessing
-
- // Use separate native timer as QML timers don't work inside Qt Design Studio
- Connections {
- target: designStudioNativeCameraControlHelper
- onUpdateInputs: cameraControl.processInputs()
- }
+ camera: editView.camera
+ anchors.fill: parent
}
}
@@ -365,39 +359,25 @@ Window {
id: editLightCheckbox
checked: false
text: qsTr("Use Edit View Light")
- onCheckedChanged: cameraControl.forceActiveFocus()
}
CheckBox {
id: usePerspectiveCheckbox
checked: true
text: qsTr("Use Perspective Projection")
- onCheckedChanged: {
- // Since WasdController always acts on active camera, we need to update pos/rot
- // to the other camera when we change
- if (checked) {
- editPerspectiveCamera.position = editOrthoCamera.position;
- editPerspectiveCamera.rotation = editOrthoCamera.rotation;
- } else {
- editOrthoCamera.position = editPerspectiveCamera.position;
- editOrthoCamera.rotation = editPerspectiveCamera.rotation;
- }
- designStudioNativeCameraControlHelper.requestOverlayUpdate();
- cameraControl.forceActiveFocus();
- }
+ onCheckedChanged: _generalHelper.requestOverlayUpdate()
}
CheckBox {
id: globalControl
checked: true
text: qsTr("Use Global Orientation")
- onCheckedChanged: cameraControl.forceActiveFocus()
}
}
Text {
id: helpText
- text: qsTr("Camera: W,A,S,D,R,F,right mouse drag")
+ text: qsTr("Camera controls: ALT + mouse press and drag. Left: Rotate, Middle: Pan, Right/Wheel: Zoom.")
anchors.bottom: parent.bottom
}
}
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml
index 1392c60cb2..ce8c85bffb 100644
--- a/share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/Overlay2D.qml
@@ -49,7 +49,7 @@ Item {
}
Connections {
- target: designStudioNativeCameraControlHelper
+ target: _generalHelper
onOverlayUpdateNeeded: updateOverlay()
}