From af5fc41e27f068604453a927cac4d81886d1987e Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 7 Jul 2010 15:45:33 +1000 Subject: Add Symbian support for runtime.orientation property Task-number: Reviewed-by: Martin Jones --- demos/declarative/calculator/Core/calculator.js | 2 +- demos/declarative/calculator/calculator.qml | 29 +++-- tools/qml/deviceorientation_symbian.cpp | 166 ++++++++++++++++++++++++ tools/qml/main.cpp | 11 ++ tools/qml/qml.pri | 2 + tools/qml/qml.pro | 4 + 6 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 tools/qml/deviceorientation_symbian.cpp diff --git a/demos/declarative/calculator/Core/calculator.js b/demos/declarative/calculator/Core/calculator.js index 51b3dd3..c80c42f 100644 --- a/demos/declarative/calculator/Core/calculator.js +++ b/demos/declarative/calculator/Core/calculator.js @@ -84,7 +84,7 @@ function doOperation(op) { } if (op == rotateLeft) - main.state = 'rotated' + main.state = "orientation " + Orientation.Landscape if (op == rotateRight) main.state = '' } diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml index 3d36211..63b6c55 100644 --- a/demos/declarative/calculator/calculator.qml +++ b/demos/declarative/calculator/calculator.qml @@ -58,10 +58,11 @@ Rectangle { property string plusminus : "\u00b1" function doOp(operation) { CalcEngine.doOperation(operation) } - + Item { id: main - state: (runtime.orientation == Orientation.Portrait) ? '' : 'rotated' + state: "orientation " + runtime.orientation + width: parent.width; height: parent.height; anchors.centerIn: parent Column { @@ -130,16 +131,28 @@ Rectangle { } } - states: State { - name: 'rotated' - PropertyChanges { target: main; rotation: -90; width: window.height; height: window.width } - PropertyChanges { target: rotateButton; operation: rotateRight } - } + states: [ + State { + name: "orientation " + Orientation.Landscape + PropertyChanges { target: main; rotation: -90; width: window.height; height: window.width } + PropertyChanges { target: rotateButton; operation: rotateRight } + }, + State { + name: "orientation " + Orientation.PortraitInverted + PropertyChanges { target: main; rotation: -180; } + PropertyChanges { target: rotateButton; operation: rotateLeft } + }, + State { + name: "orientation " + Orientation.LandscapeInverted + PropertyChanges { target: main; rotation: -270; width: window.height; height: window.width } + PropertyChanges { target: rotateButton; operation: rotateRight } + } + ] transitions: Transition { SequentialAnimation { PropertyAction { target: rotateButton; property: "operation" } - NumberAnimation { properties: "rotation"; duration: 300; easing.type: Easing.InOutQuint } + 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/tools/qml/deviceorientation_symbian.cpp b/tools/qml/deviceorientation_symbian.cpp new file mode 100644 index 0000000..48bfc72 --- /dev/null +++ b/tools/qml/deviceorientation_symbian.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** 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 tools applications 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$ +** +****************************************************************************/ + +#include "deviceorientation.h" + +#include +#include +#include +#include +#include + +class SymbianOrientation : public DeviceOrientation, public MSensrvDataListener +{ + Q_OBJECT +public: + SymbianOrientation() + : DeviceOrientation(), m_current(UnknownOrientation), m_sensorChannel(0) + { + TRAP_IGNORE(initL()); + if (!m_sensorChannel) + qWarning("No valid sensors found."); + } + + ~SymbianOrientation() + { + if (m_sensorChannel) { + m_sensorChannel->StopDataListening(); + m_sensorChannel->CloseChannel(); + delete m_sensorChannel; + } + } + + void initL() + { + CSensrvChannelFinder *channelFinder = CSensrvChannelFinder::NewLC(); + RSensrvChannelInfoList channelInfoList; + CleanupClosePushL(channelInfoList); + + TSensrvChannelInfo searchConditions; + searchConditions.iChannelType = KSensrvChannelTypeIdOrientationData; + channelFinder->FindChannelsL(channelInfoList, searchConditions); + + for (int i = 0; i < channelInfoList.Count(); ++i) { + TRAPD(error, m_sensorChannel = CSensrvChannel::NewL(channelInfoList[i])); + if (!error) + TRAP(error, m_sensorChannel->OpenChannelL()); + if (!error) { + TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0)); + break; + } + if (error) { + delete m_sensorChannel; + m_sensorChannel = 0; + } + } + + channelInfoList.Close(); + CleanupStack::Pop(&channelInfoList); + CleanupStack::PopAndDestroy(channelFinder); + } + + Orientation orientation() const + { + return m_current; + } + + void setOrientation(Orientation) { } + +private: + DeviceOrientation::Orientation m_current; + CSensrvChannel *m_sensorChannel; + + void DataReceived(CSensrvChannel &channel, TInt count, TInt dataLost) + { + if (channel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdOrientationData) { + TSensrvOrientationData data; + for (int i = 0; i < count; ++i) { + TPckgBuf dataBuf; + channel.GetData(dataBuf); + data = dataBuf(); + Orientation o = UnknownOrientation; + switch (data.iDeviceOrientation) { + case TSensrvOrientationData::EOrientationDisplayRightUp: + o = LandscapeInverted; + break; + case TSensrvOrientationData::EOrientationDisplayUp: + o = Portrait; + break; + case TSensrvOrientationData::EOrientationDisplayDown: + o = PortraitInverted; + break; + case TSensrvOrientationData::EOrientationDisplayLeftUp: + o = Landscape; + break; + case TSensrvOrientationData::EOrientationUndefined: + case TSensrvOrientationData::EOrientationDisplayUpwards: + case TSensrvOrientationData::EOrientationDisplayDownwards: + default: + break; + } + + if (m_current != o) { + m_current = o; + emit orientationChanged(); + } + } + } + } + + void DataError(CSensrvChannel& /* channel */, TSensrvErrorSeverity /* error */) + { + } + + void GetDataListenerInterfaceL(TUid /* interfaceUid */, TAny*& /* interface */) + { + } +}; + + +DeviceOrientation* DeviceOrientation::instance() +{ + static SymbianOrientation *o = 0; + if (!o) + o = new SymbianOrientation; + return o; +} + +#include "deviceorientation_symbian.moc" diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index d5ad9ad..dfd1726 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -56,6 +56,10 @@ QT_USE_NAMESPACE QtMsgHandler systemMsgOutput = 0; +#if defined(Q_WS_S60) +#include // For locking app to portrait +#endif + #if defined (Q_OS_SYMBIAN) #include #include @@ -207,6 +211,13 @@ int main(int argc, char ** argv) app.setOrganizationName("Nokia"); app.setOrganizationDomain("nokia.com"); +#if defined(Q_WS_S60) + CAknAppUi *appUi = static_cast(CEikonEnv::Static()->AppUi()); + if (appUi) { + appUi->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait); + } +#endif + QDeclarativeViewer::registerTypes(); QDeclarativeTester::registerTypes(); diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index 3e5a88b..0d01f70 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -23,6 +23,8 @@ maemo5 { SOURCES += $$PWD/deviceorientation_maemo5.cpp FORMS = $$PWD/recopts_maemo5.ui \ $$PWD/proxysettings_maemo5.ui +} symbian:!contains(S60_VERSION, 3.1):!contains(S60_VERSION, 3.2) { + SOURCES += $$PWD/deviceorientation_symbian.cpp } else { SOURCES += $$PWD/deviceorientation.cpp FORMS = $$PWD/recopts.ui \ diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index 63efff1..0a51c0b 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -37,6 +37,10 @@ symbian { include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 TARGET.CAPABILITY = NetworkServices ReadUserData + !contains(S60_VERSION, 3.1):!contains(S60_VERSION, 3.2) { + LIBS += -lsensrvclient -lsensrvutil + contains(QT_CONFIG, s60): LIBS += -lavkon -lcone + } } mac { QMAKE_INFO_PLIST=Info_mac.plist -- cgit v0.12