Qt Quick based coffee brewing control chart.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

qmlapplicationviewer.cpp 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // checksum 0x3fbf version 0x70013
  2. /*
  3. This file was generated by the Qt Quick Application wizard of Qt Creator.
  4. QmlApplicationViewer is a convenience class containing mobile device specific
  5. code such as screen orientation handling. Also QML paths and debugging are
  6. handled here.
  7. It is recommended not to modify this file, since newer versions of Qt Creator
  8. may offer an updated version of it.
  9. */
  10. #include "qmlapplicationviewer.h"
  11. #include <QDir>
  12. #include <QFileInfo>
  13. #include <QApplication>
  14. #include <QDeclarativeComponent>
  15. #include <QDeclarativeEngine>
  16. #include <QDeclarativeContext>
  17. #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
  18. #ifdef HARMATTAN_BOOSTER
  19. #include <MDeclarativeCache>
  20. #endif
  21. #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
  22. #include <qt_private/qdeclarativedebughelper_p.h>
  23. #if !defined(NO_JSDEBUGGER)
  24. #include <jsdebuggeragent.h>
  25. #endif
  26. #if !defined(NO_QMLOBSERVER)
  27. #include <qdeclarativeviewobserver.h>
  28. #endif
  29. // Enable debugging before any QDeclarativeEngine is created
  30. struct QmlJsDebuggingEnabler
  31. {
  32. QmlJsDebuggingEnabler()
  33. {
  34. QDeclarativeDebugHelper::enableDebugging();
  35. }
  36. };
  37. // Execute code in constructor before first QDeclarativeEngine is instantiated
  38. static QmlJsDebuggingEnabler enableDebuggingHelper;
  39. #endif // QMLJSDEBUGGER
  40. class QmlApplicationViewerPrivate
  41. {
  42. QString mainQmlFile;
  43. friend class QmlApplicationViewer;
  44. static QString adjustPath(const QString &path);
  45. };
  46. QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
  47. {
  48. #ifdef Q_OS_UNIX
  49. #ifdef Q_OS_MAC
  50. if (!QDir::isAbsolutePath(path))
  51. return QString::fromLatin1("%1/../Resources/%2")
  52. .arg(QCoreApplication::applicationDirPath(), path);
  53. #else
  54. const QString pathInInstallDir =
  55. QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
  56. if (QFileInfo(pathInInstallDir).exists())
  57. return pathInInstallDir;
  58. #endif
  59. #endif
  60. return path;
  61. }
  62. QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
  63. : QDeclarativeView(parent)
  64. , d(new QmlApplicationViewerPrivate())
  65. {
  66. connect(engine(), SIGNAL(quit()), SLOT(close()));
  67. setResizeMode(QDeclarativeView::SizeRootObjectToView);
  68. // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
  69. #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
  70. #if !defined(NO_JSDEBUGGER)
  71. new QmlJSDebugger::JSDebuggerAgent(engine());
  72. #endif
  73. #if !defined(NO_QMLOBSERVER)
  74. new QmlJSDebugger::QDeclarativeViewObserver(this, this);
  75. #endif
  76. #endif
  77. }
  78. QmlApplicationViewer::~QmlApplicationViewer()
  79. {
  80. delete d;
  81. }
  82. QmlApplicationViewer *QmlApplicationViewer::create()
  83. {
  84. return new QmlApplicationViewer();
  85. }
  86. void QmlApplicationViewer::setMainQmlFile(const QString &file)
  87. {
  88. d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
  89. setSource(QUrl::fromLocalFile(d->mainQmlFile));
  90. }
  91. void QmlApplicationViewer::addImportPath(const QString &path)
  92. {
  93. engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
  94. }
  95. void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
  96. {
  97. #if defined(Q_OS_SYMBIAN)
  98. // If the version of Qt on the device is < 4.7.2, that attribute won't work
  99. if (orientation != ScreenOrientationAuto) {
  100. const QStringList v = QString::fromLatin1(qVersion()).split(QLatin1Char('.'));
  101. if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
  102. qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
  103. return;
  104. }
  105. }
  106. #endif // Q_OS_SYMBIAN
  107. Qt::WidgetAttribute attribute;
  108. switch (orientation) {
  109. #if QT_VERSION < 0x040702
  110. // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
  111. case ScreenOrientationLockPortrait:
  112. attribute = static_cast<Qt::WidgetAttribute>(128);
  113. break;
  114. case ScreenOrientationLockLandscape:
  115. attribute = static_cast<Qt::WidgetAttribute>(129);
  116. break;
  117. default:
  118. case ScreenOrientationAuto:
  119. attribute = static_cast<Qt::WidgetAttribute>(130);
  120. break;
  121. #else // QT_VERSION < 0x040702
  122. case ScreenOrientationLockPortrait:
  123. attribute = Qt::WA_LockPortraitOrientation;
  124. break;
  125. case ScreenOrientationLockLandscape:
  126. attribute = Qt::WA_LockLandscapeOrientation;
  127. break;
  128. default:
  129. case ScreenOrientationAuto:
  130. attribute = Qt::WA_AutoOrientation;
  131. break;
  132. #endif // QT_VERSION < 0x040702
  133. };
  134. setAttribute(attribute, true);
  135. }
  136. void QmlApplicationViewer::showExpanded()
  137. {
  138. #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
  139. showFullScreen();
  140. #elif defined(Q_WS_MAEMO_5)
  141. showMaximized();
  142. #else
  143. show();
  144. #endif
  145. }
  146. QApplication *createApplication(int &argc, char **argv)
  147. {
  148. #ifdef HARMATTAN_BOOSTER
  149. return MDeclarativeCache::qApplication(argc, argv);
  150. #else
  151. return new QApplication(argc, argv);
  152. #endif
  153. }