diff options
Diffstat (limited to 'doc/examples/accelbubble/main.qml')
-rw-r--r-- | doc/examples/accelbubble/main.qml | 115 |
1 files changed, 67 insertions, 48 deletions
diff --git a/doc/examples/accelbubble/main.qml b/doc/examples/accelbubble/main.qml index ddd617af69..26fe2598f0 100644 --- a/doc/examples/accelbubble/main.qml +++ b/doc/examples/accelbubble/main.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator @@ -48,10 +48,9 @@ ** ****************************************************************************/ -import QtQuick 2.7 -import QtQuick.Controls 2.0 -import QtQuick.Layouts 1.0 -import QtSensors 5.7 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtSensors 5.9 ApplicationWindow { visible: true @@ -59,64 +58,84 @@ ApplicationWindow { height: 480 title: qsTr("Accelerate Bubble") - Page1 { + SwipeView { + id: swipeView anchors.fill: parent - bubble { - id: bubble - centerX: mainWindow.width / 2 - centerY: mainWindow.height / 2 - bubbleCenter: bubble.width / 2 - x: bubble.centerX - bubble.bubbleCenter - y: bubble.centerY - bubble.bubbleCenter - - Behavior on y { - SmoothedAnimation { - easing.type: Easing.Linear - duration: 100 + currentIndex: tabBar.currentIndex + + Page1Form { + bubble { + id: bubble + centerX: mainWindow.width / 2 + centerY: mainWindow.height / 2 + bubbleCenter: bubble.width / 2 + x: bubble.centerX - bubble.bubbleCenter + y: bubble.centerY - bubble.bubbleCenter + + Behavior on y { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } } - } - Behavior on x { - SmoothedAnimation { - easing.type: Easing.Linear - duration: 100 + Behavior on x { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } } } } + + Page2Form { + } + } + + footer: TabBar { + id: tabBar + currentIndex: swipeView.currentIndex + + TabButton { + text: qsTr("Page 1") + } + TabButton { + text: qsTr("Page 2") + } } Accelerometer { - id: accel - dataRate: 100 - active: true + id: accel + dataRate: 100 + active: true - onReadingChanged: { - var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) - var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) + onReadingChanged: { + var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) + var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) - if (isNaN(newX) || isNaN(newY)) - return; + if (isNaN(newX) || isNaN(newY)) + return; - if (newX < 0) - newX = 0 + if (newX < 0) + newX = 0 - if (newX > mainWindow.width - bubble.width) - newX = mainWindow.width - bubble.width + if (newX > mainWindow.width - bubble.width) + newX = mainWindow.width - bubble.width - if (newY < 18) - newY = 18 + if (newY < 18) + newY = 18 - if (newY > mainWindow.height - bubble.height) - newY = mainWindow.height - bubble.height + if (newY > mainWindow.height - bubble.height) + newY = mainWindow.height - bubble.height - bubble.x = newX - bubble.y = newY - } + bubble.x = newX + bubble.y = newY } + } - function calcPitch(x, y, z) { - return -(Math.atan(y / Math.sqrt(x * x + z * z)) * 57.2957795); - } - function calcRoll(x, y, z) { - return -(Math.atan(x / Math.sqrt(y * y + z * z)) * 57.2957795); - } + function calcPitch(x, y, z) { + return -(Math.atan(y / Math.sqrt(x * x + z * z)) * 57.2957795); + } + function calcRoll(x, y, z) { + return -(Math.atan(x / Math.sqrt(y * y + z * z)) * 57.2957795); + } } |