From 74232ac426d9911417e880334292925f47f0df1e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 2 Jun 2010 17:19:22 +1000 Subject: QML viewer now supports TopUp, TopDown, RightUp and LeftUp orientations instead of Portrait/Landscape. The new orientations are named the same as the orientations in the QtMobility sensors module. Task-number: QTBUG-11106 Reviewed-by: akennedy --- .../qdeclarativeviewer/data/orientation.qml | 17 +++-- .../qdeclarativeviewer/tst_qdeclarativeviewer.cpp | 4 +- tools/qml/deviceorientation.cpp | 2 +- tools/qml/deviceorientation.h | 9 ++- tools/qml/deviceorientation_maemo.cpp | 12 ++-- tools/qml/qmlruntime.cpp | 82 ++++++++++++---------- tools/qml/qmlruntime.h | 9 +-- 7 files changed, 79 insertions(+), 56 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeviewer/data/orientation.qml b/tests/auto/declarative/qdeclarativeviewer/data/orientation.qml index 687fac6..be911a3 100644 --- a/tests/auto/declarative/qdeclarativeviewer/data/orientation.qml +++ b/tests/auto/declarative/qdeclarativeviewer/data/orientation.qml @@ -1,10 +1,19 @@ import Qt 4.7 Rectangle { color: "black" - width: (runtime.orientation == Orientation.Landscape) ? 300 : 200 - height: (runtime.orientation == Orientation.Landscape) ? 200 : 300 + width: (runtime.orientation == Orientation.RightUp || runtime.orientation == Orientation.LeftUp) ? 300 : 200 + height: (runtime.orientation == Orientation.RightUp || runtime.orientation == Orientation.LeftUp) ? 200 : 300 Text { - text: runtime.orientation == Orientation.Landscape ? "Landscape" : "Portrait" + text: { + if (runtime.orientation == Orientation.TopUp) + return "TopUp" + if (runtime.orientation == Orientation.TopDown) + return "TopDown" + if (runtime.orientation == Orientation.LeftUp) + return "LeftUp" + if (runtime.orientation == Orientation.RightUp) + return "RightUp" + } color: "white" } -} \ No newline at end of file +} diff --git a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp index 9429dc9..f296d9e 100644 --- a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp +++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp @@ -82,7 +82,7 @@ void tst_QDeclarativeViewer::orientation() QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); QCOMPARE(viewer->size(), viewer->sizeHint()); - viewer->toggleOrientation(); + viewer->rotateOrientation(); qApp->processEvents(); QCOMPARE(rootItem->width(), 300.0); @@ -92,7 +92,7 @@ void tst_QDeclarativeViewer::orientation() QCOMPARE(viewer->size(), QSize(300, 200+viewer->menuBar()->height())); QCOMPARE(viewer->size(), viewer->sizeHint()); - viewer->toggleOrientation(); + viewer->rotateOrientation(); qApp->processEvents(); QCOMPARE(rootItem->width(), 200.0); diff --git a/tools/qml/deviceorientation.cpp b/tools/qml/deviceorientation.cpp index e7c70d5..a13b912 100644 --- a/tools/qml/deviceorientation.cpp +++ b/tools/qml/deviceorientation.cpp @@ -47,7 +47,7 @@ class DefaultDeviceOrientation : public DeviceOrientation { Q_OBJECT public: - DefaultDeviceOrientation() : DeviceOrientation(), m_orientation(DeviceOrientation::Portrait) {} + DefaultDeviceOrientation() : DeviceOrientation(), m_orientation(DeviceOrientation::TopUp) {} Orientation orientation() const { return m_orientation; diff --git a/tools/qml/deviceorientation.h b/tools/qml/deviceorientation.h index d209005..fe73868 100644 --- a/tools/qml/deviceorientation.h +++ b/tools/qml/deviceorientation.h @@ -52,7 +52,14 @@ class DeviceOrientation : public QObject Q_OBJECT Q_ENUMS(Orientation) public: - enum Orientation { UnknownOrientation, Portrait, Landscape }; + enum Orientation { + UnknownOrientation, + TopUp, + TopDown, + LeftUp, + RightUp + }; + virtual Orientation orientation() const = 0; virtual void setOrientation(Orientation) = 0; diff --git a/tools/qml/deviceorientation_maemo.cpp b/tools/qml/deviceorientation_maemo.cpp index 9f12f3d..501ff79 100644 --- a/tools/qml/deviceorientation_maemo.cpp +++ b/tools/qml/deviceorientation_maemo.cpp @@ -48,11 +48,11 @@ class MaemoOrientation : public DeviceOrientation Q_OBJECT public: MaemoOrientation() - : DeviceOrientation(),m_current(Portrait), m_lastSeen(Portrait), m_lastSeenCount(0) + : DeviceOrientation(),m_current(TopUp), m_lastSeen(TopUp), m_lastSeenCount(0) { m_current = get(); if (m_current == UnknownOrientation) - m_current = Portrait; + m_current = TopUp; startTimer(100); } @@ -101,9 +101,13 @@ private: if (abs(az) > 850) { o = UnknownOrientation; } else if (ax < -750) { - o = Portrait; + o = LeftUp; + } else if (ax > 750) { + o = RightUp; } else if (ay < -750) { - o = Landscape; + o = TopUp; + } else if (ay > 750) { + o = TopDown; } return o; diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index fe323c1..f681303 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -367,7 +367,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) #endif , loggerWindow(new LoggerWidget()) , frame_stream(0), mb(0) - , portraitOrientation(0), landscapeOrientation(0) + , orientation(0) , showWarningsWindow(0) , m_scriptOptions(0) , tester(0) @@ -418,7 +418,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) if (!(flags & Qt::FramelessWindowHint)) { createMenu(menuBar(),0); - setPortrait(); + changeOrientation(orientation->actions().value(0)); } #if !defined(Q_OS_SYMBIAN) @@ -571,26 +571,25 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties")); - QActionGroup *orientation = new QActionGroup(parent); + orientation = new QActionGroup(parent); - QAction *toggleOrientation = new QAction(tr("&Toggle Orientation"), parent); - toggleOrientation->setCheckable(true); - toggleOrientation->setShortcut(QKeySequence("Ctrl+T")); - settingsMenu->addAction(toggleOrientation); - connect(toggleOrientation, SIGNAL(triggered()), this, SLOT(toggleOrientation())); + QAction *rotateOrientation = new QAction(tr("Rotate orientation"), parent); + rotateOrientation->setShortcut(QKeySequence("Ctrl+T")); + settingsMenu->addAction(rotateOrientation); + connect(rotateOrientation, SIGNAL(triggered()), this, SLOT(rotateOrientation())); orientation->setExclusive(true); - portraitOrientation = new QAction(tr("orientation: Portrait"), parent); - portraitOrientation->setCheckable(true); - connect(portraitOrientation, SIGNAL(triggered()), this, SLOT(setPortrait())); - orientation->addAction(portraitOrientation); - propertiesMenu->addAction(portraitOrientation); - - landscapeOrientation = new QAction(tr("orientation: Landscape"), parent); - landscapeOrientation->setCheckable(true); - connect(landscapeOrientation, SIGNAL(triggered()), this, SLOT(setLandscape())); - orientation->addAction(landscapeOrientation); - propertiesMenu->addAction(landscapeOrientation); + connect(orientation, SIGNAL(triggered(QAction*)), this, SLOT(changeOrientation(QAction*))); + + orientation->addAction(tr("orientation: TopUp")); + orientation->addAction(tr("orientation: LeftUp")); + orientation->addAction(tr("orientation: TopDown")); + orientation->addAction(tr("orientation: RightUp")); + QList actions = orientation->actions(); + for (int i=0; iaddAction(actions[i]); + actions[i]->setCheckable(true); + } if (flatmenu) flatmenu->addSeparator(); @@ -624,21 +623,16 @@ void QDeclarativeViewer::proxySettingsChanged() reload (); } -void QDeclarativeViewer::setPortrait() -{ - DeviceOrientation::instance()->setOrientation(DeviceOrientation::Portrait); - portraitOrientation->setChecked(true); -} - -void QDeclarativeViewer::setLandscape() +void QDeclarativeViewer::rotateOrientation() { - DeviceOrientation::instance()->setOrientation(DeviceOrientation::Landscape); - landscapeOrientation->setChecked(true); -} + QAction *current = orientation->checkedAction(); + QList actions = orientation->actions(); + int index = actions.indexOf(current); + if (index < 0) + return; -void QDeclarativeViewer::toggleOrientation() -{ - DeviceOrientation::instance()->setOrientation(DeviceOrientation::instance()->orientation()==DeviceOrientation::Portrait?DeviceOrientation::Landscape:DeviceOrientation::Portrait); + QAction *newOrientation = actions[(index + 1) % actions.count()]; + changeOrientation(newOrientation); } void QDeclarativeViewer::toggleFullScreen() @@ -971,12 +965,7 @@ void QDeclarativeViewer::keyPressEvent(QKeyEvent *event) } else if (event->key() == Qt::Key_F9 || (event->key() == Qt::Key_9 && devicemode)) { toggleRecording(); } else if (event->key() == Qt::Key_F10) { - if (portraitOrientation) { - if (portraitOrientation->isChecked()) - setLandscape(); - else - setPortrait(); - } + rotateOrientation(); } QWidget::keyPressEvent(event); @@ -1181,6 +1170,23 @@ void QDeclarativeViewer::recordFrame() } } +void QDeclarativeViewer::changeOrientation(QAction *action) +{ + if (!action) + return; + action->setChecked(true); + + QString o = action->text().split(QLatin1Char(':')).value(1).trimmed(); + if (o == QLatin1String("TopUp")) + DeviceOrientation::instance()->setOrientation(DeviceOrientation::TopUp); + else if (o == QLatin1String("TopDown")) + DeviceOrientation::instance()->setOrientation(DeviceOrientation::TopDown); + else if (o == QLatin1String("LeftUp")) + DeviceOrientation::instance()->setOrientation(DeviceOrientation::LeftUp); + else if (o == QLatin1String("RightUp")) + DeviceOrientation::instance()->setOrientation(DeviceOrientation::RightUp); +} + void QDeclarativeViewer::orientationChanged() { if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 5086e02..27bd217 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -124,7 +124,7 @@ public slots: void ffmpegFinished(int code); void showProxySettings (); void proxySettingsChanged (); - void toggleOrientation(); + void rotateOrientation(); void statusChanged(); void setSlowMode(bool); void launch(const QString &); @@ -140,9 +140,8 @@ private slots: void recordFrame(); void chooseRecordingOptions(); void pickRecordingFile(); - void setPortrait(); - void setLandscape(); void toggleFullScreen(); + void changeOrientation(QAction*); void orientationChanged(); void showWarnings(bool show); @@ -183,9 +182,7 @@ private: bool ffmpegAvailable; bool convertAvailable; - QAction *portraitOrientation; - QAction *landscapeOrientation; - + QActionGroup *orientation; QAction *showWarningsWindow; QString m_script; -- cgit v0.12