qmlapplicationviewer.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // checksum 0x7895 version 0x4000b
  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 <QtCore/QCoreApplication>
  12. #include <QtCore/QDir>
  13. #include <QtCore/QFileInfo>
  14. #include <QtDeclarative/QDeclarativeComponent>
  15. #include <QtDeclarative/QDeclarativeEngine>
  16. #include <QtDeclarative/QDeclarativeContext>
  17. #if defined(QMLJSDEBUGGER)
  18. #include <qt_private/qdeclarativedebughelper_p.h>
  19. #endif
  20. #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
  21. #include <jsdebuggeragent.h>
  22. #endif
  23. #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
  24. #include <qdeclarativeviewobserver.h>
  25. #endif
  26. #if defined(QMLJSDEBUGGER)
  27. // Enable debugging before any QDeclarativeEngine is created
  28. struct QmlJsDebuggingEnabler
  29. {
  30. QmlJsDebuggingEnabler()
  31. {
  32. QDeclarativeDebugHelper::enableDebugging();
  33. }
  34. };
  35. // Execute code in constructor before first QDeclarativeEngine is instantiated
  36. static QmlJsDebuggingEnabler enableDebuggingHelper;
  37. #endif // QMLJSDEBUGGER
  38. class QmlApplicationViewerPrivate
  39. {
  40. QString mainQmlFile;
  41. friend class QmlApplicationViewer;
  42. static QString adjustPath(const QString &path);
  43. };
  44. QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
  45. {
  46. #ifdef Q_OS_UNIX
  47. #ifdef Q_OS_MAC
  48. if (!QDir::isAbsolutePath(path))
  49. return QCoreApplication::applicationDirPath()
  50. + QLatin1String("/../Resources/") + path;
  51. #else
  52. const QString pathInInstallDir = QCoreApplication::applicationDirPath()
  53. + QLatin1String("/../") + path;
  54. if (pathInInstallDir.contains(QLatin1String("opt"))
  55. && pathInInstallDir.contains(QLatin1String("bin"))
  56. && QFileInfo(pathInInstallDir).exists()) {
  57. return pathInInstallDir;
  58. }
  59. #endif
  60. #endif
  61. return path;
  62. }
  63. QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
  64. QDeclarativeView(parent),
  65. m_d(new QmlApplicationViewerPrivate)
  66. {
  67. connect(engine(), SIGNAL(quit()), SLOT(close()));
  68. setResizeMode(QDeclarativeView::SizeRootObjectToView);
  69. #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
  70. new QmlJSDebugger::JSDebuggerAgent(engine());
  71. #endif
  72. #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
  73. new QmlJSDebugger::QDeclarativeViewObserver(this, this);
  74. #endif
  75. }
  76. QmlApplicationViewer::~QmlApplicationViewer()
  77. {
  78. delete m_d;
  79. }
  80. void QmlApplicationViewer::setMainQmlFile(const QString &file)
  81. {
  82. m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
  83. setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
  84. }
  85. void QmlApplicationViewer::addImportPath(const QString &path)
  86. {
  87. engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
  88. }
  89. void QmlApplicationViewer::showExpanded()
  90. {
  91. //#ifdef Q_OS_SYMBIAN
  92. showFullScreen();
  93. //#elif defined(Q_WS_MAEMO_5)
  94. // showMaximized();
  95. //#else
  96. // show();
  97. //#endif
  98. }