main.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <QtGui/QApplication>
  2. #include <QtDeclarative/QDeclarativeContext>
  3. #include "qmlapplicationviewer.h"
  4. #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
  5. #include <QOrientationSensor>
  6. #include "orientationfilter.h"
  7. QTM_USE_NAMESPACE
  8. #endif
  9. int main(int argc, char *argv[])
  10. {
  11. QApplication app(argc, argv);
  12. QmlApplicationViewer viewer;
  13. QDeclarativeContext* context = viewer.rootContext();
  14. #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
  15. // Create an orientation sensor and add it to QML context
  16. QOrientationSensor sensor;
  17. OrientationFilter filter;
  18. sensor.addFilter(&filter);
  19. sensor.start();
  20. context->setContextProperty("filter", &filter);
  21. #endif
  22. // Lock to landscape for Maemo 5 and portrait for Symbian^3 because we handle orientation switch with animation ourself
  23. #if defined(Q_WS_MAEMO_5)
  24. viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
  25. #endif
  26. #if defined(Q_OS_SYMBIAN)
  27. viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
  28. #endif
  29. viewer.setMainQmlFile(QLatin1String("qml/OrientationExample/main.qml"));
  30. viewer.showExpanded();
  31. return app.exec();
  32. }