summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Yadrov <oleg.yadrov@qt.io>2016-10-17 16:09:52 -0700
committerOleg Yadrov <oleg.yadrov@qt.io>2016-10-28 22:34:28 +0000
commit59fc9863568456e3a5113f5633354d8d0fad00be (patch)
treebe7d1a3600d64d84a25812ce11cfa586efbcd4da
parent8be45352146be822e45e9d563d8e74687fa0fd0e (diff)
Port Planets QML example to Apple TV
Change-Id: I254cbc1643fcb5b67af8338c0b7adc8c25829f9d Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r--examples/qt3d/planets-qml/AppleTVInput.qml202
-rw-r--r--examples/qt3d/planets-qml/InfoSheet.qml4
-rw-r--r--examples/qt3d/planets-qml/PlanetButton.qml2
-rw-r--r--examples/qt3d/planets-qml/PlanetsMain.qml371
-rw-r--r--examples/qt3d/planets-qml/main.cpp5
-rw-r--r--examples/qt3d/planets-qml/networkcontroller.cpp105
-rw-r--r--examples/qt3d/planets-qml/networkcontroller.h77
-rw-r--r--examples/qt3d/planets-qml/planets-qml.pro16
-rw-r--r--examples/qt3d/planets-qml/planets-qml.qrc1
-rw-r--r--examples/qt3d/planets-qml/planets.js52
10 files changed, 758 insertions, 77 deletions
diff --git a/examples/qt3d/planets-qml/AppleTVInput.qml b/examples/qt3d/planets-qml/AppleTVInput.qml
new file mode 100644
index 000000000..5581035bc
--- /dev/null
+++ b/examples/qt3d/planets-qml/AppleTVInput.qml
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.7
+import QtQuick.Window 2.2
+
+Item {
+ id: appleTVInput
+
+ property real xThreshold: 500
+ property real yThreshold: 300
+
+ signal swipeLeft()
+ signal swipeRight()
+ signal swipeUp()
+ signal swipeDown()
+
+ onSwipeLeft: {
+ var focusedItem = Window.window.activeFocusItem
+ if (typeof(focusedItem.swipeLeft) === "function") {
+ focusedItem.swipeLeft()
+ }
+ }
+
+ onSwipeRight: {
+ var focusedItem = Window.window.activeFocusItem
+ if (typeof(focusedItem.swipeRight) === "function") {
+ focusedItem.swipeRight()
+ }
+ }
+
+ onSwipeUp: {
+ var focusedItem = Window.window.activeFocusItem
+ if (typeof(focusedItem.swipeUp) === "function") {
+ focusedItem.swipeUp()
+ }
+ }
+
+ onSwipeDown: {
+ var focusedItem = Window.window.activeFocusItem
+ if (typeof(focusedItem.swipeDown) === "function") {
+ focusedItem.swipeDown()
+ }
+ }
+
+ MultiPointTouchArea {
+ id: multiPointTouchArea
+
+ anchors.fill: parent
+
+ property int startX: 0
+ property int startY: 0
+
+ property int pointX: 0
+ property int pointY: 0
+
+ property int xIsIncreasing: -1 // 1 - true, 0 - false, -1 - undefined
+ property int yIsIncreasing: -1 // 1 - true, 0 - false, -1 - undefined
+
+ property bool pressed: false
+
+ touchPoints: [
+ TouchPoint {
+
+ onPressedChanged: {
+ if (pressed) {
+ multiPointTouchArea.startX = x
+ multiPointTouchArea.startY = y
+ multiPointTouchArea.pressed = true
+ } else {
+ multiPointTouchArea.pressed = false
+ multiPointTouchArea.xIsIncreasing = -1
+ multiPointTouchArea.yIsIncreasing = -1
+ multiPointTouchArea.startX = 0
+ multiPointTouchArea.startY = 0
+ }
+ }
+
+ onXChanged: {
+ if (multiPointTouchArea.pressed) {
+ var newValue = x - multiPointTouchArea.startX
+
+ var focusedItem = appleTVInput.Window.window.activeFocusItem
+
+ if (focusedItem.panningEnabled) {
+ if (multiPointTouchArea.xIsIncreasing === -1) {
+ multiPointTouchArea.xIsIncreasing = (newValue > multiPointTouchArea.startX) ? 1 : 0
+ } else {
+ if (multiPointTouchArea.xIsIncreasing === 1 && newValue < multiPointTouchArea.pointX) {
+ multiPointTouchArea.startX = x
+ multiPointTouchArea.xIsIncreasing = 0
+ multiPointTouchArea.pointX = newValue
+ } else if (multiPointTouchArea.xIsIncreasing === 0 && newValue > multiPointTouchArea.pointX) {
+ multiPointTouchArea.startX = x
+ multiPointTouchArea.xIsIncreasing = 1
+ multiPointTouchArea.pointX = newValue
+ } else {
+ multiPointTouchArea.pointX = newValue
+ focusedItem.pannedHorizontally(multiPointTouchArea.pointX / (multiPointTouchArea.width / 2))
+ }
+ }
+ } else {
+ multiPointTouchArea.pointX = newValue
+
+ if (multiPointTouchArea.pointX > xThreshold) {
+ multiPointTouchArea.startX = x
+ swipeRight()
+ } else if (multiPointTouchArea.pointX < -xThreshold) {
+ multiPointTouchArea.startX = x
+ swipeLeft()
+ }
+ }
+ }
+ }
+
+ onYChanged: {
+ if (multiPointTouchArea.pressed) {
+ var newValue = multiPointTouchArea.startY - y
+
+ var focusedItem = appleTVInput.Window.window.activeFocusItem
+
+ if (focusedItem.panningEnabled) {
+ if (multiPointTouchArea.yIsIncreasing === -1) {
+ multiPointTouchArea.yIsIncreasing = (newValue > multiPointTouchArea.startY) ? 1 : 0
+ } else {
+ if (multiPointTouchArea.yIsIncreasing === 1 && newValue < multiPointTouchArea.pointY) {
+ multiPointTouchArea.startY = y
+ multiPointTouchArea.yIsIncreasing = 0
+ multiPointTouchArea.pointY = newValue
+ } else if (multiPointTouchArea.yIsIncreasing === 0 && newValue > multiPointTouchArea.pointY) {
+ multiPointTouchArea.startY = y
+ multiPointTouchArea.yIsIncreasing = 1
+ multiPointTouchArea.pointY = newValue
+ } else {
+ multiPointTouchArea.pointY = newValue
+ focusedItem.pannedVertically(multiPointTouchArea.pointY / (multiPointTouchArea.height / 2))
+ }
+ }
+ } else {
+ multiPointTouchArea.pointY = newValue
+
+ if (multiPointTouchArea.pointY > yThreshold) {
+ multiPointTouchArea.startY = y
+ swipeUp()
+ } else if (multiPointTouchArea.pointY < -yThreshold) {
+ multiPointTouchArea.startY = y
+ swipeDown()
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
diff --git a/examples/qt3d/planets-qml/InfoSheet.qml b/examples/qt3d/planets-qml/InfoSheet.qml
index 4d03d8871..171477329 100644
--- a/examples/qt3d/planets-qml/InfoSheet.qml
+++ b/examples/qt3d/planets-qml/InfoSheet.qml
@@ -96,9 +96,9 @@ Rectangle {
property string exampleDetails: ""
font.family: "Helvetica"
- font.pixelSize: 16
+ font.pixelSize: 18
font.weight: Font.Light
- lineHeight: 1.625 * 16
+ lineHeight: 1.625 * 18
lineHeightMode: Text.FixedHeight
color: "white"
diff --git a/examples/qt3d/planets-qml/PlanetButton.qml b/examples/qt3d/planets-qml/PlanetButton.qml
index 443244478..adfc8c2e5 100644
--- a/examples/qt3d/planets-qml/PlanetButton.qml
+++ b/examples/qt3d/planets-qml/PlanetButton.qml
@@ -95,7 +95,7 @@ Rectangle {
font.weight: Font.Light
color: "white"
opacity: {
- if (text == "Solar System")
+ if (text == "Solar System" || (Qt.platform.os === "tvos" && planetButton.activeFocus))
opacity = 1
else
opacity = 0
diff --git a/examples/qt3d/planets-qml/PlanetsMain.qml b/examples/qt3d/planets-qml/PlanetsMain.qml
index f6e8db05b..a6fb3545f 100644
--- a/examples/qt3d/planets-qml/PlanetsMain.qml
+++ b/examples/qt3d/planets-qml/PlanetsMain.qml
@@ -49,7 +49,9 @@
****************************************************************************/
import QtQuick 2.0
+import QtQuick.Window 2.2
import QtQuick.Scene3D 2.0
+import "planets.js" as Planets
Item {
id: mainview
@@ -61,13 +63,46 @@ Item {
property int frames: 0
property int sliderLength: (width < height) ? width / 2 : height / 2
property real textSize: sliderLength / 20
- property real planetButtonSize: (height < 2200) ? (height / 11) : 200
+ property real planetButtonSize: (height < 2200) ? (height / 13) : 200
+
+ Connections {
+ target: networkController
+
+ onCommandAccepted: {
+ var focusedItem = mainview.Window.window.activeFocusItem
+ if (focusedItem && focusedItem.panningEnabled) {
+ focusedItem.panningEnabled = false
+ }
+
+ switch (command) {
+ case "selectPlanet":
+ mainview.focusedPlanet = Planets.planetId(decodeURIComponent(value))
+ planetButtonView.forceActiveFocus()
+ planetButtonView.currentIndex = Planets.planetIndex(value)
+ break
+ case "setRotationSpeed":
+ rotationSpeedSlider.forceActiveFocus()
+ rotationSpeedSlider.value = rotationSpeedSlider.minimumValue +
+ ((rotationSpeedSlider.maximumValue - rotationSpeedSlider.minimumValue) * value)
+ break
+ case "setViewingDistance":
+ viewingDistanceSlider.forceActiveFocus()
+ viewingDistanceSlider.value = viewingDistanceSlider.minimumValue +
+ ((viewingDistanceSlider.maximumValue - viewingDistanceSlider.minimumValue) * value)
+ break
+ case "setPlanetSize":
+ planetSizeSlider.forceActiveFocus()
+ planetSizeSlider.value = planetSizeSlider.minimumValue +
+ ((planetSizeSlider.maximumValue - planetSizeSlider.minimumValue) * value)
+ break
+ }
+ }
+ }
//! [0]
Scene3D {
anchors.fill: parent
aspects: ["render", "logic", "input"]
- focus: true
SolarSystem { id: solarsystem }
}
@@ -87,7 +122,7 @@ Item {
updatePlanetInfo()
} else {
updatePlanetInfo()
- info.opacity = 0.5
+ info.opacity = 1
}
solarsystem.changePlanetFocus(oldPlanet, focusedPlanet)
@@ -195,17 +230,58 @@ Item {
planetSelector: mainview
buttonSize: planetButtonSize
fontSize: textSize
+
+ scale: activeFocus ? 1.4 : 1.0
+
+ Behavior on scale {
+ PropertyAnimation {
+ duration: 200
+ }
+ }
+
+ signal swipeUp()
+ signal swipeDown()
+ signal swipeLeft()
+
+ onSwipeUp: {
+ if (planetButtonView.currentIndex > 0) {
+ planetButtonView.currentIndex--
+ } else {
+ rotationSpeedSlider.forceActiveFocus()
+ }
+ }
+
+ onSwipeDown: {
+ if (planetButtonView.currentIndex < planetButtonView.count - 1) {
+ planetButtonView.currentIndex++
+ } else {
+ planetSizeSlider.forceActiveFocus()
+ }
+ }
+
+ onSwipeLeft: {
+ if (index <= planetButtonView.count / 2) {
+ rotationSpeedSlider.forceActiveFocus()
+ } else {
+ planetSizeSlider.forceActiveFocus()
+ }
+ }
+
+ Keys.onPressed: {
+ if (event.key === Qt.Key_Select) {
+ planetSelector.focusedPlanet = focusPlanet
+ }
+ }
}
}
ListView {
id: planetButtonView
- anchors.top: parent.top
+ anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
- anchors.bottom: parent.bottom
- anchors.rightMargin: planetButtonSize / 5
- anchors.bottomMargin: planetButtonSize / 7
- spacing: planetButtonSize / 7
+ anchors.rightMargin: planetButtonSize / 2
+ height: childrenRect.height
+ spacing: planetButtonSize / 6
width: planetButtonSize * 1.4
interactive: false
model: planetModel
@@ -216,8 +292,8 @@ Item {
id: info
width: 400
anchors.right: planetButtonView.left
- anchors.rightMargin: 10
- opacity: 0.5
+ anchors.rightMargin: 40
+ opacity: 1
// Set initial information for Solar System
planet: "Solar System"
@@ -243,84 +319,231 @@ Item {
}
}
- StyledSlider {
- id: speedSlider
+ Row {
anchors.top: parent.top
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
- width: sliderLength
- value: 0.2
- minimumValue: 0
- maximumValue: 1
- onValueChanged: solarsystem.changeSpeed(value)
+
+ spacing: 10
+ scale: rotationSpeedSlider.activeFocus ? 1.4 : 1.0
+ opacity: rotationSpeedSlider.activeFocus ? 1.0 : 0.5
+
+ Behavior on scale {
+ PropertyAnimation {
+ duration: 200
+ }
+ }
+
+ Text {
+ anchors.verticalCenter: parent.verticalCenter
+
+ font.family: "Helvetica"
+ font.pixelSize: textSize
+ font.weight: Font.Light
+ color: rotationSpeedSlider.panningEnabled ? "#80c342" : "#ffffff"
+ text: "Rotation Speed"
+ }
+
+ StyledSlider {
+ id: rotationSpeedSlider
+ anchors.verticalCenter: parent.verticalCenter
+ width: sliderLength
+ value: 0.2
+ minimumValue: 0
+ maximumValue: 1
+ onValueChanged: solarsystem.changeSpeed(value)
+
+ focus: Qt.platform.os === "tvos" ? true : false
+
+ property bool panningEnabled: false
+ signal swipeDown()
+ signal swipeLeft()
+ signal swipeRight()
+ signal pannedHorizontally(real p)
+ signal pannedVertically(real p)
+
+ onSwipeDown: {
+ planetSizeSlider.forceActiveFocus()
+ }
+
+ onSwipeLeft: {
+ viewingDistanceSlider.forceActiveFocus()
+ }
+
+ onSwipeRight: {
+ planetButtonView.currentIndex = 0
+ planetButtonView.forceActiveFocus()
+ }
+
+ onPannedHorizontally: {
+ var step = (maximumValue - minimumValue) / 30
+
+ if (p > 0) {
+ value += step
+ } else {
+ value -= step
+ }
+ }
+
+ Keys.onPressed: {
+ if (event.key === Qt.Key_Select) {
+ panningEnabled = !panningEnabled
+ }
+ }
+ }
}
- Text {
- anchors.right: speedSlider.left
- anchors.verticalCenter: speedSlider.verticalCenter
- anchors.rightMargin: 10
- font.family: "Helvetica"
- font.pixelSize: textSize
- font.weight: Font.Light
- color: "white"
- text: "Rotation Speed"
+
+ Column {
+ anchors.left: parent.left
+ anchors.leftMargin: 30
+ anchors.verticalCenter: parent.verticalCenter
+
+ spacing: 10
+ scale: viewingDistanceSlider.activeFocus ? 1.4 : 1.0
+ opacity: viewingDistanceSlider.activeFocus ? 1.0 : 0.5
+
+ Behavior on scale {
+ PropertyAnimation {
+ duration: 200
+ }
+ }
+
+ StyledSlider {
+ id: viewingDistanceSlider
+
+ anchors.horizontalCenter: parent.horizontalCenter
+ orientation: Qt.Vertical
+ height: sliderLength
+ value: 1
+ minimumValue: 1
+ maximumValue: 2
+
+ onValueChanged: solarsystem.changeCameraDistance(value)
+
+ property bool panningEnabled: false
+ signal swipeUp()
+ signal swipeDown()
+ signal swipeRight()
+ signal pannedHorizontally(real p)
+ signal pannedVertically(real p)
+
+ onSwipeUp: {
+ rotationSpeedSlider.forceActiveFocus()
+ }
+
+ onSwipeDown: {
+ planetSizeSlider.forceActiveFocus()
+ }
+
+ onSwipeRight: {
+ planetButtonView.currentIndex = 0
+ planetButtonView.forceActiveFocus()
+ }
+
+ onPannedVertically: {
+ var step = (maximumValue - minimumValue) / 30
+
+ if (p > 0) {
+ value += step
+ } else {
+ value -= step
+ }
+ }
+
+ Keys.onPressed: {
+ if (event.key === Qt.Key_Select) {
+ panningEnabled = !panningEnabled
+ }
+ }
+ }
+
+ Text {
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ font.family: "Helvetica"
+ font.pixelSize: textSize
+ font.weight: Font.Light
+ color: viewingDistanceSlider.panningEnabled ? "#80c342" : "#ffffff"
+ text: "Viewing\nDistance"
+ }
}
- StyledSlider {
- id: scaleSlider
+ Row {
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
- width: sliderLength
- value: 1200
- minimumValue: 1
- maximumValue: 2000
- onValueChanged: solarsystem.changeScale(value, false)
- }
- Text {
- anchors.right: scaleSlider.left
- anchors.verticalCenter: scaleSlider.verticalCenter
- anchors.rightMargin: 10
- font.family: "Helvetica"
- font.pixelSize: textSize
- font.weight: Font.Light
- color: "white"
- text: "Planet Size"
- }
- StyledSlider {
- id: distanceSlider
- anchors.left: parent.left
- anchors.leftMargin: 10
- anchors.verticalCenter: parent.verticalCenter
- orientation: Qt.Vertical
- height: sliderLength
- value: 1
- minimumValue: 1
- maximumValue: 2
- //! [2]
- onValueChanged: solarsystem.changeCameraDistance(value)
- //! [2]
- }
- Text {
- y: distanceSlider.y + distanceSlider.height + width + 10
- x: distanceSlider.x + 30 - textSize
- transform: Rotation {
- origin.x: 0
- origin.y: 0
- angle: -90
+ spacing: 10
+ scale: planetSizeSlider.activeFocus ? 1.4 : 1.0
+ opacity: planetSizeSlider.activeFocus ? 1.0 : 0.5
+
+ Behavior on scale {
+ PropertyAnimation {
+ duration: 200
+ }
+ }
+
+ Text {
+ anchors.verticalCenter: parent.verticalCenter
+ font.family: "Helvetica"
+ font.pixelSize: textSize
+ font.weight: Font.Light
+ color: planetSizeSlider.panningEnabled ? "#80c342" : "#ffffff"
+ text: "Planet Size"
+ }
+
+ StyledSlider {
+ id: planetSizeSlider
+ anchors.verticalCenter: parent.verticalCenter
+ width: sliderLength
+ value: 1200
+ minimumValue: 1
+ maximumValue: 2000
+ onValueChanged: solarsystem.changeScale(value, false)
+
+ property bool panningEnabled: false
+ signal swipeUp()
+ signal swipeLeft()
+ signal swipeRight()
+ signal pannedHorizontally(real p)
+ signal pannedVertically(real p)
+
+ onSwipeUp: {
+ rotationSpeedSlider.forceActiveFocus()
+ }
+
+ onSwipeLeft: {
+ viewingDistanceSlider.forceActiveFocus()
+ }
+
+ onSwipeRight: {
+ planetButtonView.currentIndex = planetButtonView.count - 1
+ planetButtonView.forceActiveFocus()
+ }
+
+ onPannedHorizontally: {
+ var step = (maximumValue - minimumValue) / 30
+
+ if (p > 0) {
+ value += step
+ } else {
+ value -= step
+ }
+ }
+
+ Keys.onPressed: {
+ if (event.key === Qt.Key_Select) {
+ panningEnabled = !panningEnabled
+ }
+ }
}
- font.family: "Helvetica"
- font.pixelSize: textSize
- font.weight: Font.Light
- color: "white"
- text: "Viewing Distance"
}
// FPS display, initially hidden, clicking will show it
FpsDisplay {
id: fpsDisplay
anchors.left: parent.left
- anchors.top: parent.top
+ anchors.bottom: parent.bottom
width: 32
height: 64
hidden: true
@@ -336,4 +559,10 @@ Item {
}
onRunningChanged: frames = 0
}
+
+ Loader {
+ anchors.fill: parent
+
+ source: Qt.platform.os === "tvos" ? "AppleTVInput.qml" : ""
+ }
}
diff --git a/examples/qt3d/planets-qml/main.cpp b/examples/qt3d/planets-qml/main.cpp
index 2e1199432..b044a22b2 100644
--- a/examples/qt3d/planets-qml/main.cpp
+++ b/examples/qt3d/planets-qml/main.cpp
@@ -50,7 +50,9 @@
#include <QGuiApplication>
#include <QQuickView>
+#include <QQmlContext>
#include <QOpenGLContext>
+#include "networkcontroller.h"
int main(int argc, char **argv)
{
@@ -65,8 +67,11 @@ int main(int argc, char **argv)
format.setStencilBufferSize(8);
format.setSamples(4);
+ NetworkController networkController;
+
QQuickView view;
view.setFormat(format);
+ view.rootContext()->setContextProperty("networkController", &networkController);
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:/PlanetsMain.qml"));
view.setColor("#000000");
diff --git a/examples/qt3d/planets-qml/networkcontroller.cpp b/examples/qt3d/planets-qml/networkcontroller.cpp
new file mode 100644
index 000000000..a08a26300
--- /dev/null
+++ b/examples/qt3d/planets-qml/networkcontroller.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "NetworkController.h"
+
+NetworkController::NetworkController(QObject *parent) :
+ QObject(parent)
+{
+ QObject::connect(&m_server, &QTcpServer::newConnection, this, &NetworkController::newConnection);
+
+ if (!m_server.listen(QHostAddress::Any, 8080)) {
+ qDebug() << "Failed to run http server";
+ }
+}
+
+void NetworkController::newConnection()
+{
+ QTcpSocket *socket = m_server.nextPendingConnection();
+
+ if (!socket)
+ return;
+
+ QObject::connect(socket, &QAbstractSocket::disconnected, this, &NetworkController::disconnected);
+ QObject::connect(socket, &QIODevice::readyRead, this, &NetworkController::readyRead);
+}
+
+void NetworkController::disconnected()
+{
+ QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
+ if (!socket)
+ return;
+
+ socket->disconnect();
+ socket->deleteLater();
+}
+
+void NetworkController::readyRead()
+{
+ QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
+ if (!socket || socket->state() == QTcpSocket::ClosingState)
+ return;
+
+ QString requestData = socket->readAll();
+ QStringList list = requestData.split(' ');
+ QString path = list[1];
+ list = path.split('/');
+
+ QByteArray reply;
+ if (list.count() == 3) {
+ reply = "Command accepted.";
+ emit commandAccepted(list[1], list[2]);
+ } else {
+ reply = "Command rejected.";
+ }
+
+ socket->write(reply);
+ socket->disconnectFromHost();
+}
diff --git a/examples/qt3d/planets-qml/networkcontroller.h b/examples/qt3d/planets-qml/networkcontroller.h
new file mode 100644
index 000000000..ba7ecf086
--- /dev/null
+++ b/examples/qt3d/planets-qml/networkcontroller.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef NETWORKCONTROLLER_H
+#define NETWORKCONTROLLER_H
+
+#include <QObject>
+#include <QTcpServer>
+#include <QTcpSocket>
+
+class NetworkController : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit NetworkController(QObject *parent = 0);
+
+private:
+ QTcpServer m_server;
+
+private slots:
+ void newConnection();
+ void disconnected();
+ void readyRead();
+
+signals:
+ void commandAccepted(QString command, QString value);
+};
+
+#endif // NETWORKCONTROLLER_H
diff --git a/examples/qt3d/planets-qml/planets-qml.pro b/examples/qt3d/planets-qml/planets-qml.pro
index 22efc8ca2..39b93cb8c 100644
--- a/examples/qt3d/planets-qml/planets-qml.pro
+++ b/examples/qt3d/planets-qml/planets-qml.pro
@@ -2,11 +2,21 @@
error( "Couldn't find the examples.pri file!" )
}
-QT += qml quick
-CONFIG += resources_big
+QT += qml quick \
+ widgets \
+ concurrent \
+ 3dcore 3drender 3dinput \
+ 3dquick 3dquickrender 3dquickinput 3dquickextras \
+ network
+
+CONFIG += resources_big c++11
+
+HEADERS += \
+ networkcontroller.h
SOURCES += \
- main.cpp
+ main.cpp \
+ networkcontroller.cpp
OTHER_FILES += \
*.qml \
diff --git a/examples/qt3d/planets-qml/planets-qml.qrc b/examples/qt3d/planets-qml/planets-qml.qrc
index ebac0bcd5..f3a34fa9f 100644
--- a/examples/qt3d/planets-qml/planets-qml.qrc
+++ b/examples/qt3d/planets-qml/planets-qml.qrc
@@ -37,5 +37,6 @@
<file>shaders/es2/planetDSB.frag</file>
<file>shaders/gl3/planetDShadow.frag</file>
<file>shaders/gl3/planetDShadow.vert</file>
+ <file>AppleTVInput.qml</file>
</qresource>
</RCC>
diff --git a/examples/qt3d/planets-qml/planets.js b/examples/qt3d/planets-qml/planets.js
index 0534d86ab..f64ec3149 100644
--- a/examples/qt3d/planets-qml/planets.js
+++ b/examples/qt3d/planets-qml/planets.js
@@ -48,6 +48,8 @@
**
****************************************************************************/
+.pragma library
+
var SUN = 0;
var MERCURY = 1;
var VENUS = 2;
@@ -61,6 +63,56 @@ var NUM_SELECTABLE_PLANETS = 9;
var MOON = 9;
var SOLAR_SYSTEM = 100;
+function planetId(planetName) {
+ switch (planetName) {
+ case "Sun":
+ return SUN
+ case "Mercury":
+ return MERCURY
+ case "Venus":
+ return VENUS
+ case "Earth":
+ return EARTH
+ case "Mars":
+ return MARS
+ case "Jupiter":
+ return JUPITER
+ case "Saturn":
+ return SATURN
+ case "Uranus":
+ return URANUS
+ case "Neptune":
+ return NEPTUNE
+ case "Solar System":
+ return SOLAR_SYSTEM
+ }
+}
+
+function planetIndex(planetName) {
+ switch (planetName) {
+ case "Sun":
+ return 0
+ case "Mercury":
+ return 1
+ case "Venus":
+ return 2
+ case "Earth":
+ return 3
+ case "Mars":
+ return 4
+ case "Jupiter":
+ return 5
+ case "Saturn":
+ return 6
+ case "Uranus":
+ return 7
+ case "Neptune":
+ return 8
+ case "Solar System":
+ return 9
+ }
+}
+
var planets = []; // Planet data info
var solarDistance = 2600000;