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>
This commit is contained in:
Pasi Keränen
2019-10-15 14:54:20 +03:00
committed by Pasi Keränen
parent 3ee870a3d8
commit c2c8b9a5d6
8 changed files with 204 additions and 52 deletions

View File

@@ -23,79 +23,98 @@
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.0 import QtQuick 2.12
import QtQuick.Window 2.0 import QtQuick.Window 2.0
import QtQuick3D 1.0 import QtQuick3D 1.0
import QtQuick3D.Helpers 1.0
import QtQuick.Controls 2.0 import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
Window { Window {
id: viewWindow
width: 1024 width: 1024
height: 768 height: 768
visible: true visible: true
title: "3D" title: "3D"
flags: Qt.WindowStaysOnTopHint | Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint 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 { Rectangle {
color: "black" id: sceneBg
color: "#FFFFFF"
anchors.fill: parent anchors.fill: parent
} focus: true
Column {
y: 32
Slider {
id: slider
value: -600
from: -1200
to: 600
}
Slider {
id: slider2
value: 0
from: -360
to: 360
}
CheckBox {
id: checkBox
text: "Light"
Rectangle {
anchors.fill: parent
z: -1
}
}
}
Binding {
target: view.scene
property: "rotation.y"
value: slider2.value
}
property alias scene: view.scene
property alias showLight: checkBox.checked
id: viewWindow
View3D { View3D {
id: view id: editView
anchors.fill: parent anchors.fill: parent
enableWireframeMode: true enableWireframeMode: true
camera: camera01 camera: editCamera
AxisHelper {
id: axisGrid
enableXZGrid: true
enableAxisLines: false
}
Light { Light {
id: directionalLight id: directionalLight
visible: checkBox.checked visible: showEditLight
} }
Camera { Camera {
id: camera01 id: editCamera
z: slider.value y: 200
z: -300
clipFar: 100000
projectionMode: usePerspective ? Camera.Perspective : Camera.Orthographic
} }
Component.onCompleted: { Component.onCompleted: {
directionalLight.setParentItem(view.scene) directionalLight.setParentItem(editView.scene);
camera01.setParentItem(view.scene) editCamera.setParentItem(editView.scene);
} }
} }
WasdController {
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()
}
}
}
Column {
y: 8
CheckBox {
id: editLightCheckbox
checked: false
text: qsTr("Use Edit View Light")
onCheckedChanged: cameraControl.forceActiveFocus()
}
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
}
} }

View 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.
**
****************************************************************************/
#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;
}
}
}

View File

@@ -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;
};
}
}

View File

@@ -0,0 +1,2 @@
HEADERS += $$PWD/cameracontrolhelper.h
SOURCES += $$PWD/cameracontrolhelper.cpp

View File

@@ -58,12 +58,15 @@
#include "changeselectioncommand.h" #include "changeselectioncommand.h"
#include "dummycontextobject.h" #include "dummycontextobject.h"
#include "../editor3d/cameracontrolhelper.h"
#include <designersupportdelegate.h> #include <designersupportdelegate.h>
#include <QQmlProperty> #include <QQmlProperty>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QQuickView> #include <QQuickView>
#include <QQmlContext>
#include <QQmlEngine>
namespace QmlDesigner { namespace QmlDesigner {
@@ -74,8 +77,10 @@ static QVariant objectToVariant(QObject *object)
static QObject *createEditView3D(QQmlEngine *engine) 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()); QWindow *window = qobject_cast<QWindow *>(component.create());
@@ -84,6 +89,7 @@ static QObject *createEditView3D(QQmlEngine *engine)
surfaceFormat.setVersion(4, 1); surfaceFormat.setVersion(4, 1);
surfaceFormat.setProfile(QSurfaceFormat::CoreProfile); surfaceFormat.setProfile(QSurfaceFormat::CoreProfile);
window->setFormat(surfaceFormat); window->setFormat(surfaceFormat);
helper->setParent(window);
return window; return window;
} }

View File

@@ -5,6 +5,7 @@ CONFIG += c++11
DEFINES -= QT_CREATOR DEFINES -= QT_CREATOR
include (editor3d/editor3d.pri)
include (../instances/instances.pri) include (../instances/instances.pri)
include (instances/instances.pri) include (instances/instances.pri)
include (../commands/commands.pri) include (../commands/commands.pri)

View File

@@ -96,6 +96,12 @@ extend_qtc_executable(qml2puppet
nodeinstanceserverinterface.cpp nodeinstanceserverinterface.h nodeinstanceserverinterface.cpp nodeinstanceserverinterface.h
) )
extend_qtc_executable(qml2puppet
SOURCES_PREFIX "${SRCDIR}/qml2puppet/editor3d"
SOURCES
cameracontrolhelper.cpp cameracontrolhelper.h
}
extend_qtc_executable(qml2puppet extend_qtc_executable(qml2puppet
SOURCES_PREFIX "${SRCDIR}/qml2puppet/instances" SOURCES_PREFIX "${SRCDIR}/qml2puppet/instances"
SOURCES SOURCES

View File

@@ -193,6 +193,8 @@ QtcTool {
"instances/qt5testnodeinstanceserver.h", "instances/qt5testnodeinstanceserver.h",
"instances/servernodeinstance.cpp", "instances/servernodeinstance.cpp",
"instances/servernodeinstance.h", "instances/servernodeinstance.h",
"editor3d/cameracontrolhelper.cpp",
"editor3d/cameracontrolhelper.h",
"qml2puppetmain.cpp", "qml2puppetmain.cpp",
] ]
} }