October 25, 2010

johnk johnk
Lab Rat
56 posts

QML - screen orientation

 

Hello,

I would like to add code to properly react to screen orientation to a QML app for Symbian IFF it can be done in a principled manner. This is some demo code meant to show of QML in a positive light. Since it is a Symbian app, I’ll be use QtDeclarativeView. In this case, the runtime property [apidocs.meego.com] doesn’t appear to be defined. This shots down this approach [doc.trollteck.com] too because it relies on the runtime property as well.

I understand that the intend is to eventually provide Orientation binding for QML from the Qt Mobility project. Is there a principled way to use it today?

-jk

4 replies

November 9, 2010

fcrochik fcrochik
Ant Farmer
517 posts

I haven’t tried on symbian but if you generate a “Qt Quick Application” on the qt creator beta 2.1 you will get “orientation” code that seems to also apply to Symbian.

a sneak peek:

  1. void QmlApplicationViewer::setOrientation(Orientation orientation)
  2. {
  3. #ifdef Q_OS_SYMBIAN
  4.     if (orientation != Auto) {
  5. #if defined(ORIENTATIONLOCK)
  6.         const CAknAppUiBase::TAppUiOrientation uiOrientation =
  7.                 (orientation == LockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
  8.                     : CAknAppUi::EAppUiOrientationLandscape;
  9.         CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
  10.         TRAPD(error,
  11.             if (appUi)
  12.                 appUi->SetOrientationL(uiOrientation);
  13.         );
  14. #else // ORIENTATIONLOCK
  15.         qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
  16. #endif // ORIENTATIONLOCK
  17.     }
  18. #elif defined(Q_WS_MAEMO_5)
  19.     Qt::WidgetAttribute attribute;
  20.     switch (orientation) {
  21.     case LockPortrait:
  22.         attribute = Qt::WA_Maemo5PortraitOrientation;
  23.         break;
  24.     case LockLandscape:
  25.         attribute = Qt::WA_Maemo5LandscapeOrientation;
  26.         break;
  27.     case Auto:
  28.     default:
  29.         attribute = Qt::WA_Maemo5AutoOrientation;
  30.         break;
  31.     }
  32.     setAttribute(attribute, true);
  33. #else // Q_OS_SYMBIAN
  34.     Q_UNUSED(orientation);
  35. #endif // Q_OS_SYMBIAN
  36. }

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

November 14, 2010

beardog beardog
Lab Rat
3 posts

fcrochik wrote:
I haven’t tried on symbian but if you generate a “Qt Quick Application” on the qt creator beta 2.1 you will get “orientation” code that seems to also apply to Symbian.

a sneak peek:

please can you provide a full example or source file? I use usual Nokia Qt sdk and there is no such option there :(

November 25, 2010

fcrochik fcrochik
Ant Farmer
517 posts

The application template includes several files that may be useful or not in your case. I suggest you to download the qt-creator beta version 2.1 and try. It will not affect your nokia qt sdk and it is much better to write qml applications

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

June 19, 2011

David Talmage David Talmage
Ant Farmer
61 posts

I have a QML application that needs to know when handset orientation changes. I solved this in QML with a little hack. [developer.qt.nokia.com]

 
  ‹‹ Restart App      Symbian^3, Qt 4.7.0 and UiTools ››

You must log in to post a reply. Not a member yet? Register here!