summaryrefslogtreecommitdiffstats
path: root/src/quick3d
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-05-30 17:42:56 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-31 15:49:14 +0200
commit7f750d898f26312ab76f716c8f9b69089cebe576 (patch)
tree732d6338d3f332923e493eaf259c9d77efa0f455 /src/quick3d
parent76efd5b9713431984c143bf2b861f196dd05acb8 (diff)
CameraController usable from QML
Configuration QML element with controlledCamera property which has to be set to as valid Camera element we want to control. Slight hack (behind the scene) to make that work. Will be cleaned up on the next iteration. Change-Id: I794ee1c26207178f94765c873331bce19efaab9f Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d')
-rw-r--r--src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp11
-rw-r--r--src/quick3d/quick3d/items/items.pri2
-rw-r--r--src/quick3d/quick3d/items/quick3dconfiguration.cpp76
-rw-r--r--src/quick3d/quick3d/items/quick3dconfiguration.h79
-rw-r--r--src/quick3d/quick3d/quickwindow.cpp23
-rw-r--r--src/quick3d/quick3d/quickwindow.h7
6 files changed, 194 insertions, 4 deletions
diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
index 503106129..5ca63962a 100644
--- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
+++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
@@ -55,18 +55,24 @@
#include <Qt3DCore/qabstracttechnique.h>
#include <Qt3DCore/qabstractmesh.h>
#include <Qt3DCore/qabstractrenderpass.h>
+#include <Qt3DQuick/quick3dconfiguration.h>
QT_BEGIN_NAMESPACE
void Qt3DQuick3DCorePlugin::registerTypes(const char *uri)
{
- qmlRegisterUncreatableType<Qt3D::Node>(uri, 2, 0, "Node_priv", "");
+ qmlRegisterUncreatableType<Qt3D::Node>(uri, 2, 0, "Node_private", "");
+ qmlRegisterUncreatableType<Qt3D::Transform>(uri, 2, 0, "Transform_private", "");
qmlRegisterInterface<Qt3D::QAbstractEffect>("QAbstractEffect");
qmlRegisterUncreatableType<Qt3D::QAbstractMesh>(uri, 2, 0, "QAbstractMesh", "");
qmlRegisterUncreatableType<Qt3D::QAbstractMaterial>(uri, 2, 0, "QAbstractMaterial", "");
qmlRegisterUncreatableType<Qt3D::QAbstractTechnique>(uri, 2, 0, "QAbstractTechnique", "");
qmlRegisterUncreatableType<Qt3D::QAbstractRenderPass>(uri, 2, 0, "QAbstractRenderPass", "");
+ qmlRegisterType<Qt3D::Quick::Quick3DConfiguration>(uri, 2, 0, "Configuration");
+ qmlRegisterType<Qt3D::Quick::Quick3DEntity>(uri, 2, 0, "Entity");
+ qmlRegisterType<Qt3D::Quick::Quick3DTransform>(uri, 2, 0, "Transform");
+ qmlRegisterType<Qt3D::Quick::Quick3DNode>(uri, 2, 0, "Node");
qmlRegisterType<Qt3D::Component>(uri, 2, 0, "Component");
qmlRegisterType<Qt3D::Camera>(uri, 2, 0, "Camera");
qmlRegisterType<Qt3D::CameraLens>(uri, 2, 0, "CameraLens");
@@ -75,9 +81,6 @@ void Qt3DQuick3DCorePlugin::registerTypes(const char *uri)
qmlRegisterType<Qt3D::RotateTransform>(uri, 2, 0, "Rotate");
qmlRegisterType<Qt3D::LookAtTransform>(uri, 2, 0, "LookAt");
qmlRegisterType<Qt3D::ScaleTransform>(uri, 2, 0, "Scale");
- qmlRegisterType<Qt3D::Quick::Quick3DEntity>(uri, 2, 0, "Entity");
- qmlRegisterType<Qt3D::Quick::Quick3DTransform>(uri, 2, 0, "Transform");
- qmlRegisterType<Qt3D::Quick::Quick3DNode>(uri, 2, 0, "Node");
}
QT_END_NAMESPACE
diff --git a/src/quick3d/quick3d/items/items.pri b/src/quick3d/quick3d/items/items.pri
index 19db4cb55..199532964 100644
--- a/src/quick3d/quick3d/items/items.pri
+++ b/src/quick3d/quick3d/items/items.pri
@@ -2,10 +2,12 @@ HEADERS += \
$$PWD/quick3dnode.h \
$$PWD/quick3dentity.h \
$$PWD/quick3dtransform.h \
+ $$PWD/quick3dconfiguration.h
SOURCES += \
$$PWD/quick3dnode.cpp \
$$PWD/quick3dentity.cpp \
$$PWD/quick3dtransform.cpp \
+ $$PWD/quick3dconfiguration.cpp
INCLUDEPATH += $$PWD
diff --git a/src/quick3d/quick3d/items/quick3dconfiguration.cpp b/src/quick3d/quick3d/items/quick3dconfiguration.cpp
new file mode 100644
index 000000000..7a24022d7
--- /dev/null
+++ b/src/quick3d/quick3d/items/quick3dconfiguration.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "quick3dconfiguration.h"
+#include "quickwindow.h"
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Quick {
+
+Quick3DConfiguration::Quick3DConfiguration(QObject *parent)
+ : QObject(parent)
+ , m_camera(Q_NULLPTR)
+{
+}
+
+void Quick3DConfiguration::setControlledCamera(Camera *camera)
+{
+ if (m_camera != camera) {
+ m_camera = camera;
+ emit controlledCameraChanged();
+ Qt3D::Quick::QuickWindow::getInstance()->setCamera(camera);
+ }
+}
+
+Camera *Quick3DConfiguration::controlledCamera() const
+{
+ return m_camera;
+}
+
+} // Quick
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/quick3d/quick3d/items/quick3dconfiguration.h b/src/quick3d/quick3d/items/quick3dconfiguration.h
new file mode 100644
index 000000000..768892487
--- /dev/null
+++ b/src/quick3d/quick3d/items/quick3dconfiguration.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QUICK_QUICK3DCONFIGURATION_H
+#define QT3D_QUICK_QUICK3DCONFIGURATION_H
+
+#include <Qt3DQuick/qt3dquick_global.h>
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class Camera;
+
+namespace Quick {
+
+class QT3DQUICKSHARED_EXPORT Quick3DConfiguration : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3D::Camera *controlledCamera READ controlledCamera WRITE setControlledCamera NOTIFY controlledCameraChanged)
+public:
+ explicit Quick3DConfiguration(QObject *parent = 0);
+
+ void setControlledCamera(Camera *camera);
+ Camera *controlledCamera() const;
+
+Q_SIGNALS:
+ void controlledCameraChanged();
+
+private:
+ Camera *m_camera;
+};
+
+} // Quick
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QUICK_QUICK3DCONFIGURATION_H
diff --git a/src/quick3d/quick3d/quickwindow.cpp b/src/quick3d/quick3d/quickwindow.cpp
index 339084acf..43922ba01 100644
--- a/src/quick3d/quick3d/quickwindow.cpp
+++ b/src/quick3d/quick3d/quickwindow.cpp
@@ -43,7 +43,10 @@
#include <Qt3DCore/qaspectengine.h>
#include <QQmlComponent>
+#include <QQmlContext>
#include <QDebug>
+#include <QTimer>
+#include "cameracontroller.h"
QT_BEGIN_NAMESPACE
@@ -51,10 +54,16 @@ namespace Qt3D {
namespace Quick {
+QuickWindow *QuickWindow::m_instance = Q_NULLPTR;
+
QuickWindow::QuickWindow(QScreen *screen)
: Window(screen)
, m_engine(new QQmlEngine)
{
+
+ // HACKED TO BE ABLE TO ASSIGN CAMERA TO CONTROLLER
+ // FROM QML EASILY
+ QuickWindow::m_instance = this;
}
QuickWindow::~QuickWindow()
@@ -99,6 +108,20 @@ void QuickWindow::setSource(const QUrl& source)
}
}
+void QuickWindow::setCamera(Camera *camera)
+{
+ Window::setCamera(camera);
+ if (m_camera) {
+ m_controller->setCamera(m_camera);
+ m_updateTimer->start();
+ }
+}
+
+QuickWindow *QuickWindow::getInstance()
+{
+ return QuickWindow::m_instance;
+}
+
void QuickWindow::continueExecute()
{
qDebug() << Q_FUNC_INFO;
diff --git a/src/quick3d/quick3d/quickwindow.h b/src/quick3d/quick3d/quickwindow.h
index f104fe7c0..59207448d 100644
--- a/src/quick3d/quick3d/quickwindow.h
+++ b/src/quick3d/quick3d/quickwindow.h
@@ -56,6 +56,8 @@ class QAspectEngine;
namespace Quick {
+class Quick3DConfiguration;
+
class QT3DQUICKSHARED_EXPORT QuickWindow : public Qt3D::Window
{
Q_OBJECT
@@ -68,6 +70,10 @@ public:
Status status() const;
void setSource(const QUrl& url);
+ void setCamera(Camera *camera);
+ static QuickWindow *getInstance();
+
+
Q_SIGNALS:
void statusChanged(Status);
@@ -78,6 +84,7 @@ private:
QScopedPointer<QQmlEngine> m_engine;
QSharedPointer<QQmlComponent> m_component;
+ static QuickWindow *m_instance;
};
} // Quick