From d4e5890286f56c1976a187e75eb48fdf64269e55 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 2 Feb 2011 13:41:22 +0100 Subject: [PATCH] Removing the usage of Avkon to lock the screen orientation Locking the screen orientation was not a Qt feature of the Symbian port till Qt 4.7.2. Therefore, client applications had to do the locking themselves. That locking is right now only achievable by using Avkon Api. The template code of the Qt Quick App wizard did exactly that. Now, Qt 4.7.2 has the screen orientation lock built in. That implementation was done for QTBUG-11785. No need to do that in the application code, anymore. This patch removes Avkon usage from the templates, using new enum keys and setting QWidget flags, just like Maemo5 does. Two Qt version checks/fixes: 1) If the application tries to lock the orientation on Qt < 4.7.2, a warning is given that this won't work 2) If Qt < 4.7.2 is used to build the application, the enum keys are not used directly but casted from constants Task-Number: QTCREATORBUG-3598 Reviewed-by: ck --- share/qtcreator/templates/mobileapp/app.pro | 4 -- .../templates/mobileapp/mainwindow.cpp | 58 +++++++++---------- share/qtcreator/templates/qmlapp/app.pro | 4 -- .../qmlapplicationviewer.cpp | 58 +++++++++---------- .../qtcreator/templates/shared/deployment.pri | 1 - .../wizards/abstractmobileapp.cpp | 3 - 6 files changed, 56 insertions(+), 72 deletions(-) diff --git a/share/qtcreator/templates/mobileapp/app.pro b/share/qtcreator/templates/mobileapp/app.pro index ec826e61e60..5c1eacc1144 100644 --- a/share/qtcreator/templates/mobileapp/app.pro +++ b/share/qtcreator/templates/mobileapp/app.pro @@ -4,10 +4,6 @@ # dir1.source = mydir DEPLOYMENTFOLDERS = # file1 dir1 -# Avoid auto screen rotation -# ORIENTATIONLOCK # -DEFINES += ORIENTATIONLOCK - # TARGETUID3 # symbian:TARGET.UID3 = 0xE1111234 diff --git a/share/qtcreator/templates/mobileapp/mainwindow.cpp b/share/qtcreator/templates/mobileapp/mainwindow.cpp index aad030d8aa1..e719b5f9169 100644 --- a/share/qtcreator/templates/mobileapp/mainwindow.cpp +++ b/share/qtcreator/templates/mobileapp/mainwindow.cpp @@ -11,13 +11,6 @@ #include -#if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK) -#include -#include -#include -#include -#endif // Q_OS_SYMBIAN && ORIENTATIONLOCK - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -31,40 +24,45 @@ MainWindow::~MainWindow() void MainWindow::setOrientation(ScreenOrientation orientation) { -#ifdef Q_OS_SYMBIAN +#if defined(Q_OS_SYMBIAN) + // If the version of Qt on the device is < 4.7.2, that attribute won't work if (orientation != ScreenOrientationAuto) { -#if defined(ORIENTATIONLOCK) - const CAknAppUiBase::TAppUiOrientation uiOrientation = - (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait - : CAknAppUi::EAppUiOrientationLandscape; - CAknAppUi* appUi = dynamic_cast (CEikonEnv::Static()->AppUi()); - TRAPD(error, - if (appUi) - appUi->SetOrientationL(uiOrientation); - ); - Q_UNUSED(error) -#else // ORIENTATIONLOCK - qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation."); -#endif // ORIENTATIONLOCK + const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); + if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { + qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); + return; + } } -#elif defined(Q_WS_MAEMO_5) +#endif // Q_OS_SYMBIAN + Qt::WidgetAttribute attribute; switch (orientation) { +#if QT_VERSION < 0x040702 + // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes case ScreenOrientationLockPortrait: - attribute = Qt::WA_Maemo5PortraitOrientation; + attribute = static_cast(128); break; case ScreenOrientationLockLandscape: - attribute = Qt::WA_Maemo5LandscapeOrientation; + attribute = static_cast(129); break; - case ScreenOrientationAuto: default: - attribute = Qt::WA_Maemo5AutoOrientation; + case ScreenOrientationAuto: + attribute = static_cast(130); break; - } +#else // QT_VERSION < 0x040702 + case ScreenOrientationLockPortrait: + attribute = Qt::WA_LockPortraitOrientation; + break; + case ScreenOrientationLockLandscape: + attribute = Qt::WA_LockLandscapeOrientation; + break; + default: + case ScreenOrientationAuto: + attribute = Qt::WA_AutoOrientation; + break; +#endif // QT_VERSION < 0x040702 + }; setAttribute(attribute, true); -#else // Q_OS_SYMBIAN - Q_UNUSED(orientation); -#endif // Q_OS_SYMBIAN } void MainWindow::showExpanded() diff --git a/share/qtcreator/templates/qmlapp/app.pro b/share/qtcreator/templates/qmlapp/app.pro index cc8c3346451..1ba2bce8235 100644 --- a/share/qtcreator/templates/qmlapp/app.pro +++ b/share/qtcreator/templates/qmlapp/app.pro @@ -9,10 +9,6 @@ DEPLOYMENTFOLDERS = folder_01 # QML_IMPORT_PATH # QML_IMPORT_PATH = -# Avoid auto screen rotation -# ORIENTATIONLOCK # -DEFINES += ORIENTATIONLOCK - # TARGETUID3 # symbian:TARGET.UID3 = 0xE1111234 diff --git a/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp b/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp index 59d9750edd6..4298aa74671 100644 --- a/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp +++ b/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -27,13 +27,6 @@ #include #endif -#if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK) -#include -#include -#include -#include -#endif // Q_OS_SYMBIAN && ORIENTATIONLOCK - #if defined(QMLJSDEBUGGER) // Enable debugging before any QDeclarativeEngine is created @@ -108,40 +101,45 @@ void QmlApplicationViewer::addImportPath(const QString &path) void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) { -#ifdef Q_OS_SYMBIAN +#if defined(Q_OS_SYMBIAN) + // If the version of Qt on the device is < 4.7.2, that attribute won't work if (orientation != ScreenOrientationAuto) { -#if defined(ORIENTATIONLOCK) - const CAknAppUiBase::TAppUiOrientation uiOrientation = - (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait - : CAknAppUi::EAppUiOrientationLandscape; - CAknAppUi* appUi = dynamic_cast (CEikonEnv::Static()->AppUi()); - TRAPD(error, - if (appUi) - appUi->SetOrientationL(uiOrientation); - ); - Q_UNUSED(error) -#else // ORIENTATIONLOCK - qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation."); -#endif // ORIENTATIONLOCK + const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); + if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { + qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); + return; + } } -#elif defined(Q_WS_MAEMO_5) +#endif // Q_OS_SYMBIAN + Qt::WidgetAttribute attribute; switch (orientation) { +#if QT_VERSION < 0x040702 + // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes case ScreenOrientationLockPortrait: - attribute = Qt::WA_Maemo5PortraitOrientation; + attribute = static_cast(128); break; case ScreenOrientationLockLandscape: - attribute = Qt::WA_Maemo5LandscapeOrientation; + attribute = static_cast(129); break; - case ScreenOrientationAuto: default: - attribute = Qt::WA_Maemo5AutoOrientation; + case ScreenOrientationAuto: + attribute = static_cast(130); break; - } +#else // QT_VERSION < 0x040702 + case ScreenOrientationLockPortrait: + attribute = Qt::WA_LockPortraitOrientation; + break; + case ScreenOrientationLockLandscape: + attribute = Qt::WA_LockLandscapeOrientation; + break; + default: + case ScreenOrientationAuto: + attribute = Qt::WA_AutoOrientation; + break; +#endif // QT_VERSION < 0x040702 + }; setAttribute(attribute, true); -#else // Q_OS_SYMBIAN - Q_UNUSED(orientation); -#endif // Q_OS_SYMBIAN } void QmlApplicationViewer::showExpanded() diff --git a/share/qtcreator/templates/shared/deployment.pri b/share/qtcreator/templates/shared/deployment.pri index c225424f199..10c36f748a4 100644 --- a/share/qtcreator/templates/shared/deployment.pri +++ b/share/qtcreator/templates/shared/deployment.pri @@ -21,7 +21,6 @@ MAINPROFILEPWD = $$PWD symbian { isEmpty(ICON):exists($${TARGET}.svg):ICON = $${TARGET}.svg isEmpty(TARGET.EPOCHEAPSIZE):TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 - contains(DEFINES, ORIENTATIONLOCK):LIBS += -lavkon -leikcore -lcone } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { diff --git a/src/plugins/qt4projectmanager/wizards/abstractmobileapp.cpp b/src/plugins/qt4projectmanager/wizards/abstractmobileapp.cpp index aa88ef1fb63..212c2555fb5 100644 --- a/src/plugins/qt4projectmanager/wizards/abstractmobileapp.cpp +++ b/src/plugins/qt4projectmanager/wizards/abstractmobileapp.cpp @@ -262,9 +262,6 @@ QByteArray AbstractMobileApp::generateProFile(QString *errorMessage) const while (!(line = in.readLine()).isNull()) { if (line.contains(QLatin1String("# TARGETUID3"))) { valueOnNextLine = symbianTargetUid(); - } else if (line.contains(QLatin1String("# ORIENTATIONLOCK")) - && orientation() == ScreenOrientationAuto) { - uncommentNextLine = true; } else if (line.contains(QLatin1String("# NETWORKACCESS")) && !networkEnabled()) { uncommentNextLine = true;