diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-07-28 08:45:23 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-08-03 01:45:34 (GMT) |
commit | e62f266a7642e675e9d235a1f54a6b5746500d48 (patch) | |
tree | 7ed719f4539ecb0a634dad714105c70819683810 /examples | |
parent | 1fc6cab93ba2d067fadcd0979640c32aa1d5ae4a (diff) | |
download | Qt-e62f266a7642e675e9d235a1f54a6b5746500d48.zip Qt-e62f266a7642e675e9d235a1f54a6b5746500d48.tar.gz Qt-e62f266a7642e675e9d235a1f54a6b5746500d48.tar.bz2 |
Make it possible to manually set the orientation of QML Viewer on Symbian
Task-number: QTBUG-12142
Reviewed-by: Warwick Allison
This patch brings ability to switch QML Viewer's orientation between auto-orientation (=follow sensor),
portrait and landscape orientations (lock orientation) on Symbian. It provides same orientation options as
Qt Creator 2.1's Qt QML Standalone Application creation wizard. Also, menu item rotateOrientation now
works on Symbian, but it's hidden when orientation mode is set to auto-orientation.
Property runtime.orientation has been switched back to supporting four-way orientation on Symbian, previously
it only updated values between portrait and landscape. If your application only supports landscape or portrait
modes, just don't react to the inverted orientations.
Added orientation example screenorientation under examples/declarative.
The patch includes a fix for calculator example, which rotated to wrong direction when switching from portrait
to landscape. Also, improved qdeclarativeviewer unit tests. Changes have been tested to work on Windows,
Linux and Symbian^3.
Diffstat (limited to 'examples')
5 files changed, 476 insertions, 0 deletions
diff --git a/examples/declarative/screenorientation/Core/Bubble.qml b/examples/declarative/screenorientation/Core/Bubble.qml new file mode 100644 index 0000000..2474f30 --- /dev/null +++ b/examples/declarative/screenorientation/Core/Bubble.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 + +Rectangle { + property bool rising: false + property bool verticalRise: true + property real xAttractor: 0 + property real yAttractor: 0 + + width: 5 + 10*Math.random() + height: width + radius: Math.floor(width/2)-1 + property real amountOfGray: Math.random() + color: Qt.rgba(amountOfGray,amountOfGray,amountOfGray,1) + + y: (rising && verticalRise) ? yAttractor : Math.random()*(main.inPortrait ? main.baseHeight : main.baseWidth) + x: (rising && !verticalRise) ? xAttractor : Math.random()*(main.inPortrait ? main.baseWidth : main.baseHeight) + Behavior on x { + id: xBehavior + SmoothedAnimation { + velocity: 100+Math.random()*100 + } + } + Behavior on y { + id: yBehavior + SmoothedAnimation { + velocity: 100+Math.random()*100 + } + } + Timer { + interval: 80+Math.random()*40 + repeat: true + running: true + onTriggered: { + if (rising) { + if (x > main.width || x < 0) { + xBehavior.enabled = false; + rising = false; + xBehavior.enabled = true; + rising = true; + } + if (y > main.height || y < 0) { + yBehavior.enabled = false; + rising = false; + yBehavior.enabled = true; + rising = true; + } + } + } + } +}
\ No newline at end of file diff --git a/examples/declarative/screenorientation/Core/Button.qml b/examples/declarative/screenorientation/Core/Button.qml new file mode 100644 index 0000000..60083d8 --- /dev/null +++ b/examples/declarative/screenorientation/Core/Button.qml @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +Item { + id: button + signal clicked + property string text + property bool toggled: false + width: 100 + height: 60 + Rectangle { + anchors.fill: button + anchors.margins: mouseArea.pressed ? 3 : 2 + color: toggled ? (mouseArea.pressed ? "#442222" : "darkred") : (mouseArea.pressed ? "#333333": "black") + radius: mouseArea.pressed ? 8 : 6 + Text { + id: text + anchors.centerIn: parent + text: button.text + font.pixelSize: mouseArea.pressed ? 12 : 14 + color: "white" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: { + button.clicked() + } + } + } +} diff --git a/examples/declarative/screenorientation/Core/screenorientation.js b/examples/declarative/screenorientation/Core/screenorientation.js new file mode 100644 index 0000000..f0a5574 --- /dev/null +++ b/examples/declarative/screenorientation/Core/screenorientation.js @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +function printOrientation(orientation) { + var orientationString; + if (orientation == Orientation.Portrait) { + orientationString = "Portrait"; + } else if (orientation == Orientation.Landscape) { + orientationString = "Landscape"; + } else if (orientation == Orientation.PortraitInverted) { + orientationString = "Portrait inverted"; + } else if (orientation == Orientation.LandscapeInverted) { + orientationString = "Landscape inverted"; + } else { + orientationString = "UnknownOrientation"; + } + return orientationString; +} + +function getAngle(orientation) { + var angle; + if (orientation == Orientation.Portrait) { + angle = 0; + } else if (orientation == Orientation.Landscape) { + angle = 90; + } else if (orientation == Orientation.PortraitInverted) { + angle = 180; + } else if (orientation == Orientation.LandscapeInverted) { + angle = 270; + } else { + angle = 0; + } + return angle; +} + +function parallel(firstOrientation, secondOrientation) { + var difference = getAngle(firstOrientation) - getAngle(secondOrientation) + return difference % 180 == 0; +} + +function calculateGravityPoint(firstOrientation, secondOrientation) { + var position = Qt.point(0, 0); + var difference = getAngle(firstOrientation) - getAngle(secondOrientation) + if (difference < 0) { + difference = 360 + difference; + } + if (difference == 0) { + position = Qt.point(0, -10); + } else if (difference == 90) { + position = Qt.point(-10, 0); + } else if (difference == 180) { + position = Qt.point(0, 1000); + } else if (difference == 270) { + position = Qt.point(1000, 0); + } + return position; +} diff --git a/examples/declarative/screenorientation/screenorientation.qml b/examples/declarative/screenorientation/screenorientation.qml new file mode 100644 index 0000000..6af38bb --- /dev/null +++ b/examples/declarative/screenorientation/screenorientation.qml @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +import "Core" +import "Core/screenorientation.js" as ScreenOrientation + +Rectangle { + id: window + width: 360 + height: 640 + color: "white" + + Rectangle { + id: main + clip: true + property variant selectedOrientation: Orientation.UnknownOrientation + property variant activeOrientation: selectedOrientation == Orientation.UnknownOrientation ? runtime.orientation : selectedOrientation + state: "orientation " + activeOrientation + property bool inPortrait: (activeOrientation == Orientation.Portrait || activeOrientation == Orientation.PortraitInverted); + + // rotation correction for landscape devices like N900 + property bool landscapeWindow: window.width > window.height + property variant rotationDelta: landscapeWindow ? -90 : 0 + rotation: rotationDelta + + // initial state is portrait + property real baseWidth: landscapeWindow ? window.height-10 : window.width-10 + property real baseHeight: landscapeWindow ? window.width-10 : window.height-10 + + width: baseWidth + height: baseHeight + anchors.centerIn: parent + + color: "black" + gradient: Gradient { + GradientStop { position: 0.0; color: Qt.rgba(0.5,0.5,0.5,0.5) } + GradientStop { position: 0.8; color: "black" } + GradientStop { position: 1.0; color: "black" } + } + Item { + id: bubbles + property bool rising: false + anchors.fill: parent + property variant gravityPoint: ScreenOrientation.calculateGravityPoint(main.activeOrientation, runtime.orientation) + Repeater { + model: 24 + Bubble { + rising: bubbles.rising + verticalRise: ScreenOrientation.parallel(main.activeOrientation, runtime.orientation) + xAttractor: parent.gravityPoint.x + yAttractor: parent.gravityPoint.y + } + } + Component.onCompleted: bubbles.rising = true; + } + + Column { + width: centeredText.width + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenterOffset: 30 + Text { + text: "Orientation" + color: "white" + font.pixelSize: 22 + anchors.horizontalCenter: parent.horizontalCenter + } + Text { + id: centeredText + text: ScreenOrientation.printOrientation(main.activeOrientation) + color: "white" + font.pixelSize: 40 + anchors.horizontalCenter: parent.horizontalCenter + } + Text { + text: "sensor: " + ScreenOrientation.printOrientation(runtime.orientation) + color: "white" + font.pixelSize: 14 + anchors.horizontalCenter: parent.horizontalCenter + } + } + Flow { + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 10 + spacing: 4 + Button { + width: main.inPortrait ? (parent.width-4)/2 : (parent.width-8)/3 + text: "Portrait" + onClicked: main.selectedOrientation = Orientation.Portrait + toggled: main.selectedOrientation == Orientation.Portrait + } + Button { + width: main.inPortrait ? (parent.width-4)/2 : (parent.width-8)/3 + text: "Portrait inverted" + onClicked: main.selectedOrientation = Orientation.PortraitInverted + toggled: main.selectedOrientation == Orientation.PortraitInverted + } + Button { + width: main.inPortrait ? (parent.width-4)/2 : (parent.width-8)/3 + text: "Landscape" + onClicked: main.selectedOrientation = Orientation.Landscape + toggled: main.selectedOrientation == Orientation.Landscape + } + Button { + width: main.inPortrait ? (parent.width-4)/2 : (parent.width-8)/3 + text: "Landscape inverted" + onClicked: main.selectedOrientation = Orientation.LandscapeInverted + toggled: main.selectedOrientation == Orientation.LandscapeInverted + } + Button { + width: main.inPortrait ? parent.width : 2*(parent.width-2)/3 + text: "From runtime.orientation" + onClicked: main.selectedOrientation = Orientation.UnknownOrientation + toggled: main.selectedOrientation == Orientation.UnknownOrientation + } + } + states: [ + State { + name: "orientation " + Orientation.Landscape + PropertyChanges { + target: main + rotation: ScreenOrientation.getAngle(Orientation.Landscape)+rotationDelta + width: baseHeight + height: baseWidth + } + }, + State { + name: "orientation " + Orientation.PortraitInverted + PropertyChanges { + target: main + rotation: ScreenOrientation.getAngle(Orientation.PortraitInverted)+rotationDelta + width: baseWidth + height: baseHeight + } + }, + State { + name: "orientation " + Orientation.LandscapeInverted + PropertyChanges { + target: main + rotation: ScreenOrientation.getAngle(Orientation.LandscapeInverted)+rotationDelta + width: baseHeight + height: baseWidth + } + } + ] + transitions: Transition { + ParallelAnimation { + RotationAnimation { + direction: RotationAnimation.Shortest + duration: 300 + easing.type: Easing.InOutQuint + } + NumberAnimation { + properties: "x,y,width,height" + duration: 300 + easing.type: Easing.InOutQuint + } + } + } + } +} diff --git a/examples/declarative/screenorientation/screenorientation.qmlproject b/examples/declarative/screenorientation/screenorientation.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/screenorientation/screenorientation.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ " ../exampleplugin " ] +} |