summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPasi Keränen <pasi.keranen@qt.io>2019-10-15 14:54:20 +0300
committerPasi Keränen <pasi.keranen@qt.io>2019-10-21 08:27:16 +0000
commitc2c8b9a5d65236f9103f00dd9b0be605aa812409 (patch)
treeaea1f27b5c34c75f29426ac977b78afb08d5a961
parent3ee870a3d8860c23e23661bfda3aee2b4ab4b8b8 (diff)
downloadqt-creator-c2c8b9a5d65236f9103f00dd9b0be605aa812409.tar.gz
Add edit camera controls for 3D edit view
Add edit camera controls and grid helper to 3D edit view. Task-number: QDS-1127 Change-Id: Ice5ea0fcca18d59dc8a2907710e16c6688b90628 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml113
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.cpp59
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.h57
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri2
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp8
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri1
-rw-r--r--src/tools/qml2puppet/CMakeLists.txt6
-rw-r--r--src/tools/qml2puppet/qml2puppet.qbs2
8 files changed, 200 insertions, 48 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml
index f6ad8b58f2..519dc83569 100644
--- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml
+++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml
@@ -23,79 +23,98 @@
**
****************************************************************************/
-import QtQuick 2.0
+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
Window {
+ id: viewWindow
width: 1024
height: 768
visible: true
title: "3D"
flags: Qt.WindowStaysOnTopHint | Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint
+ property alias scene: editView.scene
+ property alias showEditLight: editLightCheckbox.checked
+ property alias usePerspective: usePerspectiveCheckbox.checked
+
Rectangle {
- color: "black"
+ id: sceneBg
+ color: "#FFFFFF"
anchors.fill: parent
- }
+ focus: true
- Column {
- y: 32
- Slider {
- id: slider
+ View3D {
+ id: editView
+ anchors.fill: parent
+ enableWireframeMode: true
+ camera: editCamera
- value: -600
- from: -1200
- to: 600
- }
- Slider {
- id: slider2
+ AxisHelper {
+ id: axisGrid
+ enableXZGrid: true
+ enableAxisLines: false
+ }
- value: 0
- from: -360
- to: 360
- }
- CheckBox {
- id: checkBox
- text: "Light"
- Rectangle {
- anchors.fill: parent
- z: -1
+ Light {
+ id: directionalLight
+ visible: showEditLight
}
- }
- }
- Binding {
- target: view.scene
- property: "rotation.y"
- value: slider2.value
- }
+ Camera {
+ id: editCamera
+ y: 200
+ z: -300
+ clipFar: 100000
+ projectionMode: usePerspective ? Camera.Perspective : Camera.Orthographic
+ }
- property alias scene: view.scene
- property alias showLight: checkBox.checked
+ Component.onCompleted: {
+ directionalLight.setParentItem(editView.scene);
+ editCamera.setParentItem(editView.scene);
+ }
+ }
- id: viewWindow
+ WasdController {
+ id: cameraControl
+ controlledObject: editView.camera
+ acceptedButtons: Qt.RightButton
- View3D {
- id: view
- anchors.fill: parent
- enableWireframeMode: true
- camera: camera01
+ onInputsNeedProcessingChanged: designStudioNativeCameraControlHelper.enabled
+ = cameraControl.inputsNeedProcessing
- Light {
- id: directionalLight
- visible: checkBox.checked
+ // Use separate native timer as QML timers don't work inside Qt Design Studio
+ Connections {
+ target: designStudioNativeCameraControlHelper
+ onUpdateInputs: cameraControl.processInputs()
+ }
}
+ }
- Camera {
- id: camera01
- z: slider.value
+ Column {
+ y: 8
+ CheckBox {
+ id: editLightCheckbox
+ checked: false
+ text: qsTr("Use Edit View Light")
+ onCheckedChanged: cameraControl.forceActiveFocus()
}
- Component.onCompleted: {
- directionalLight.setParentItem(view.scene)
- camera01.setParentItem(view.scene)
+ CheckBox {
+ id: usePerspectiveCheckbox
+ checked: true
+ text: qsTr("Use Perspective Projection")
+ onCheckedChanged: cameraControl.forceActiveFocus()
}
}
+
+ Text {
+ id: helpText
+ text: qsTr("Camera: W,A,S,D,R,F,right mouse drag")
+ anchors.bottom: parent.bottom
+ }
}
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.cpp
new file mode 100644
index 0000000000..c05e8230bf
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.cpp
@@ -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.
+**
+****************************************************************************/
+#include "cameracontrolhelper.h"
+
+namespace QmlDesigner {
+namespace Internal {
+
+CameraControlHelper::CameraControlHelper()
+ : QObject()
+{
+ m_timer.setInterval(16);
+ m_timer.setSingleShot(false);
+ QObject::connect(&m_timer, &QTimer::timeout,
+ this, &CameraControlHelper::handleUpdateTimer);
+}
+
+bool CameraControlHelper::enabled()
+{
+ return m_enabled;
+}
+
+void CameraControlHelper::handleUpdateTimer()
+{
+ emit updateInputs();
+}
+
+void CameraControlHelper::setEnabled(bool enabled)
+{
+ if (enabled)
+ m_timer.start();
+ else
+ m_timer.stop();
+ m_enabled = enabled;
+}
+
+}
+}
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.h
new file mode 100644
index 0000000000..87ef1025ff
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/cameracontrolhelper.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** 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.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QtCore/QObject>
+#include <QtCore/QTimer>
+
+namespace QmlDesigner {
+namespace Internal {
+class CameraControlHelper : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
+
+public:
+ CameraControlHelper();
+
+ bool enabled();
+ void setEnabled(bool enabled);
+
+public slots:
+ void handleUpdateTimer();
+
+signals:
+ void updateInputs();
+ void enabledChanged(bool enabled);
+
+private:
+ bool m_enabled = false;
+ QTimer m_timer;
+};
+
+}
+}
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri
new file mode 100644
index 0000000000..7b86f8bc82
--- /dev/null
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri
@@ -0,0 +1,2 @@
+HEADERS += $$PWD/cameracontrolhelper.h
+SOURCES += $$PWD/cameracontrolhelper.cpp
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
index 4754181a77..d0931da3e0 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
@@ -58,12 +58,15 @@
#include "changeselectioncommand.h"
#include "dummycontextobject.h"
+#include "../editor3d/cameracontrolhelper.h"
#include <designersupportdelegate.h>
#include <QQmlProperty>
#include <QOpenGLContext>
#include <QQuickView>
+#include <QQmlContext>
+#include <QQmlEngine>
namespace QmlDesigner {
@@ -74,8 +77,10 @@ static QVariant objectToVariant(QObject *object)
static QObject *createEditView3D(QQmlEngine *engine)
{
- QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml"));
+ QmlDesigner::Internal::CameraControlHelper *helper = new QmlDesigner::Internal::CameraControlHelper();
+ engine->rootContext()->setContextProperty("designStudioNativeCameraControlHelper", helper);
+ QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml"));
QWindow *window = qobject_cast<QWindow *>(component.create());
@@ -84,6 +89,7 @@ static QObject *createEditView3D(QQmlEngine *engine)
surfaceFormat.setVersion(4, 1);
surfaceFormat.setProfile(QSurfaceFormat::CoreProfile);
window->setFormat(surfaceFormat);
+ helper->setParent(window);
return window;
}
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri
index 39599385a8..d0bab57ca1 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri
@@ -5,6 +5,7 @@ CONFIG += c++11
DEFINES -= QT_CREATOR
+include (editor3d/editor3d.pri)
include (../instances/instances.pri)
include (instances/instances.pri)
include (../commands/commands.pri)
diff --git a/src/tools/qml2puppet/CMakeLists.txt b/src/tools/qml2puppet/CMakeLists.txt
index 3db1cb34cd..060ee7d2c9 100644
--- a/src/tools/qml2puppet/CMakeLists.txt
+++ b/src/tools/qml2puppet/CMakeLists.txt
@@ -97,6 +97,12 @@ extend_qtc_executable(qml2puppet
)
extend_qtc_executable(qml2puppet
+ SOURCES_PREFIX "${SRCDIR}/qml2puppet/editor3d"
+ SOURCES
+ cameracontrolhelper.cpp cameracontrolhelper.h
+}
+
+extend_qtc_executable(qml2puppet
SOURCES_PREFIX "${SRCDIR}/qml2puppet/instances"
SOURCES
anchorchangesnodeinstance.cpp anchorchangesnodeinstance.h
diff --git a/src/tools/qml2puppet/qml2puppet.qbs b/src/tools/qml2puppet/qml2puppet.qbs
index bc67e79a1a..9dd7baa8bd 100644
--- a/src/tools/qml2puppet/qml2puppet.qbs
+++ b/src/tools/qml2puppet/qml2puppet.qbs
@@ -193,6 +193,8 @@ QtcTool {
"instances/qt5testnodeinstanceserver.h",
"instances/servernodeinstance.cpp",
"instances/servernodeinstance.h",
+ "editor3d/cameracontrolhelper.cpp",
+ "editor3d/cameracontrolhelper.h",
"qml2puppetmain.cpp",
]
}