Guest User

Test

a guest
Oct 20th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. // checksum 0xfe24 version 0x6000e
  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.  
  11. #include "qmlapplicationviewer.h"
  12.  
  13. #include <QtCore/QCoreApplication>
  14. #include <QtCore/QDir>
  15. #include <QtCore/QFileInfo>
  16. #include <QtDeclarative/QDeclarativeComponent>
  17. #include <QtDeclarative/QDeclarativeEngine>
  18. #include <QtDeclarative/QDeclarativeContext>
  19.  
  20. #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
  21.  
  22. #include <qt_private/qdeclarativedebughelper_p.h>
  23.  
  24. #if !defined(NO_JSDEBUGGER)
  25. #include <jsdebuggeragent.h>
  26. #endif
  27. #if !defined(NO_QMLOBSERVER)
  28. #include <qdeclarativeviewobserver.h>
  29. #endif
  30.  
  31. // Enable debugging before any QDeclarativeEngine is created
  32. struct QmlJsDebuggingEnabler
  33. {
  34. QmlJsDebuggingEnabler()
  35. {
  36. QDeclarativeDebugHelper::enableDebugging();
  37. }
  38. };
  39.  
  40. // Execute code in constructor before first QDeclarativeEngine is instantiated
  41. static QmlJsDebuggingEnabler enableDebuggingHelper;
  42.  
  43. #endif // QMLJSDEBUGGER
  44.  
  45. class QmlApplicationViewerPrivate
  46. {
  47. QString mainQmlFile;
  48. friend class QmlApplicationViewer;
  49. static QString adjustPath(const QString &path);
  50. };
  51.  
  52. QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
  53. {
  54. #ifdef Q_OS_UNIX
  55. #ifdef Q_OS_MAC
  56. if (!QDir::isAbsolutePath(path))
  57. return QCoreApplication::applicationDirPath()
  58. + QLatin1String("/../Resources/") + path;
  59. #else
  60. const QString pathInInstallDir = QCoreApplication::applicationDirPath()
  61. + QLatin1String("/../") + path;
  62. if (pathInInstallDir.contains(QLatin1String("opt"))
  63. && pathInInstallDir.contains(QLatin1String("bin"))
  64. && QFileInfo(pathInInstallDir).exists()) {
  65. return pathInInstallDir;
  66. }
  67. #endif
  68. #endif
  69. return path;
  70. }
  71.  
  72. QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
  73. QDeclarativeView(parent),
  74. m_d(new QmlApplicationViewerPrivate)
  75. {
  76. connect(engine(), SIGNAL(quit()), SLOT(close()));
  77. setResizeMode(QDeclarativeView::SizeRootObjectToView);
  78. // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
  79. #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
  80. #if !defined(NO_JSDEBUGGER)
  81. new QmlJSDebugger::JSDebuggerAgent(engine());
  82. #endif
  83. #if !defined(NO_QMLOBSERVER)
  84. new QmlJSDebugger::QDeclarativeViewObserver(this, this);
  85. #endif
  86. #endif
  87. }
  88.  
  89. QmlApplicationViewer::~QmlApplicationViewer()
  90. {
  91. delete m_d;
  92. }
  93.  
  94. void QmlApplicationViewer::setMainQmlFile(const QString &file)
  95. {
  96. m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
  97. setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
  98. }
  99.  
  100. void QmlApplicationViewer::addImportPath(const QString &path)
  101. {
  102. engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
  103. }
  104.  
  105. void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
  106. {
  107. #if defined(Q_OS_SYMBIAN)
  108. // If the version of Qt on the device is < 4.7.2, that attribute won't work
  109. if (orientation != ScreenOrientationAuto) {
  110. const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
  111. if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
  112. qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
  113. return;
  114. }
  115. }
  116. #endif // Q_OS_SYMBIAN
  117.  
  118. Qt::WidgetAttribute attribute;
  119. switch (orientation) {
  120. #if QT_VERSION < 0x040702
  121. // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
  122. case ScreenOrientationLockPortrait:
  123. attribute = static_cast<Qt::WidgetAttribute>(128);
  124. break;
  125. case ScreenOrientationLockLandscape:
  126. attribute = static_cast<Qt::WidgetAttribute>(129);
  127. break;
  128. default:
  129. case ScreenOrientationAuto:
  130. attribute = static_cast<Qt::WidgetAttribute>(130);
  131. break;
  132. #else // QT_VERSION < 0x040702
  133. case ScreenOrientationLockPortrait:
  134. attribute = Qt::WA_LockPortraitOrientation;
  135. break;
  136. case ScreenOrientationLockLandscape:
  137. attribute = Qt::WA_LockLandscapeOrientation;
  138. break;
  139. default:
  140. case ScreenOrientationAuto:
  141. attribute = Qt::WA_AutoOrientation;
  142. break;
  143. #endif // QT_VERSION < 0x040702
  144. };
  145. setAttribute(attribute, true);
  146. }
  147.  
  148. void QmlApplicationViewer::showExpanded()
  149. {
  150. #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
  151. showFullScreen();
  152. #elif defined(Q_WS_MAEMO_5)
  153. showMaximized();
  154. #else
  155. show();
  156. #endif
  157. }
Advertisement
Add Comment
Please, Sign In to add comment