summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/mouseinput-qml
diff options
context:
space:
mode:
authorRĂ©mi Benoit <remi.benoit@kdab.com>2015-02-11 18:40:44 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-08-03 14:43:58 +0000
commit5be0ec8da8a63d75b0dd9c70119fc01e908f8618 (patch)
tree8b7f7f3fb44f7438fc61ff64f2331f745e2d9933 /examples/qt3d/mouseinput-qml
parent01a380405e05ad18251ec6635c096392c89633a7 (diff)
MouseInput API and example mockup
The meaning of exclusiveFocus is not set in stone for now. We know some kind of exclusive focus will be needed but defining it precisely will be done as the input aspect takes shape. QMouseController -> dispatch events to QMouseInput, specify the camera to be used to perform the picks. QMouseInput -> Component that offers a way to react to mouse events Q3DMouseEvent/Q3DWheelEvent -> Qt3D mapping of QMouseEvent/QWheelEvent Change-Id: I462bea2932d4bad6595d04a75ea1e0a67c7c8ba0 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/mouseinput-qml')
-rw-r--r--examples/qt3d/mouseinput-qml/main.cpp65
-rw-r--r--examples/qt3d/mouseinput-qml/main.qml115
-rw-r--r--examples/qt3d/mouseinput-qml/mouseinput-qml.pro13
-rw-r--r--examples/qt3d/mouseinput-qml/mouseinput-qml.qrc5
4 files changed, 198 insertions, 0 deletions
diff --git a/examples/qt3d/mouseinput-qml/main.cpp b/examples/qt3d/mouseinput-qml/main.cpp
new file mode 100644
index 000000000..2751fe41a
--- /dev/null
+++ b/examples/qt3d/mouseinput-qml/main.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later 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 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGuiApplication>
+
+#include <window.h>
+#include <Qt3DRenderer/QRenderAspect>
+#include <Qt3DInput/QInputAspect>
+#include <Qt3DQuick/QQmlAspectEngine>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ Window view;
+ Qt3D::Quick::QQmlAspectEngine engine;
+
+ engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect());
+ engine.aspectEngine()->registerAspect(new Qt3D::QInputAspect());
+
+ QVariantMap data;
+ data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view)));
+ data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view));
+ engine.aspectEngine()->setData(data);
+ engine.aspectEngine()->initialize();
+
+ engine.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
+
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/qt3d/mouseinput-qml/main.qml b/examples/qt3d/mouseinput-qml/main.qml
new file mode 100644
index 000000000..443b9a952
--- /dev/null
+++ b/examples/qt3d/mouseinput-qml/main.qml
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later 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 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Renderer 2.0
+import Qt3D.Input 2.0
+
+Entity {
+ id: sceneRoot
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ aspectRatio: 16/9
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 0.0, -40.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ }
+
+ Configuration {
+ controlledCamera: camera
+ }
+
+ components: FrameGraph {
+ ForwardRenderer {
+ camera: camera
+ clearColor: "black"
+ }
+ }
+
+ SphereMesh {
+ id: sphereMesh
+ radius: 3
+ }
+
+ Material {
+ id: material
+ effect : Effect {
+ }
+ }
+
+ MouseController {
+ id: mouseController
+ }
+
+ Entity {
+ id: sphere1
+
+ property real scaleFactor: 1.0
+
+ property Transform transform: Transform {
+ Scale {
+ scale: sphere1.scaleFactor
+ }
+ }
+
+ property MouseInput mouseInput : MouseInput {
+ controller: mouseController
+
+ onClicked: {
+ //Signal not implemented yet
+ }
+
+ onReleased: {
+ switch (mouse.button) {
+ case Qt.LeftButton:
+ sphere1.scaleFactor += 0.5;
+ break;
+
+ case Qt.RightButton:
+ sphere1.scaleFactor -= 0.5;
+ break;
+ }
+ }
+ }
+
+ components: [sphereMesh, material, transform, mouseInput]
+ }
+}
diff --git a/examples/qt3d/mouseinput-qml/mouseinput-qml.pro b/examples/qt3d/mouseinput-qml/mouseinput-qml.pro
new file mode 100644
index 000000000..190662372
--- /dev/null
+++ b/examples/qt3d/mouseinput-qml/mouseinput-qml.pro
@@ -0,0 +1,13 @@
+!include( ../examples.pri ) {
+ error( "Couldn't find the examples.pri file!" )
+}
+
+QT += 3dcore 3drenderer 3dinput 3dquick qml quick
+
+SOURCES += main.cpp
+
+RESOURCES += \
+ mouseinput-qml.qrc
+
+OTHER_FILES += \
+ main.qml
diff --git a/examples/qt3d/mouseinput-qml/mouseinput-qml.qrc b/examples/qt3d/mouseinput-qml/mouseinput-qml.qrc
new file mode 100644
index 000000000..5f6483ac3
--- /dev/null
+++ b/examples/qt3d/mouseinput-qml/mouseinput-qml.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ </qresource>
+</RCC>