qtquick2applicationviewer.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // checksum 0x56a9 version 0x80001
  2. /*
  3. This file was generated by the Qt Quick 2 Application wizard of Qt Creator.
  4. QtQuick2ApplicationViewer 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 "qtquick2applicationviewer.h"
  11. #include <QtCore/QCoreApplication>
  12. #include <QtCore/QDir>
  13. #include <QtQml/QQmlEngine>
  14. class QtQuick2ApplicationViewerPrivate
  15. {
  16. QString mainQmlFile;
  17. friend class QtQuick2ApplicationViewer;
  18. static QString adjustPath(const QString &path);
  19. };
  20. QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path)
  21. {
  22. #if defined(Q_OS_MAC)
  23. if (!QDir::isAbsolutePath(path))
  24. return QString::fromLatin1("%1/../Resources/%2")
  25. .arg(QCoreApplication::applicationDirPath(), path);
  26. #elif defined(Q_OS_UNIX)
  27. const QString pathInInstallDir =
  28. QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
  29. if (QFileInfo(pathInInstallDir).exists())
  30. return pathInInstallDir;
  31. #endif
  32. return path;
  33. }
  34. QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent)
  35. : QQuickView(parent)
  36. , d(new QtQuick2ApplicationViewerPrivate())
  37. {
  38. connect(engine(), SIGNAL(quit()), SLOT(close()));
  39. setResizeMode(QQuickView::SizeRootObjectToView);
  40. }
  41. QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer()
  42. {
  43. delete d;
  44. }
  45. void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file)
  46. {
  47. d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file);
  48. setSource(QUrl::fromLocalFile(d->mainQmlFile));
  49. }
  50. void QtQuick2ApplicationViewer::addImportPath(const QString &path)
  51. {
  52. engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path));
  53. }
  54. void QtQuick2ApplicationViewer::showExpanded()
  55. {
  56. #if defined(Q_WS_SIMULATOR)
  57. showFullScreen();
  58. #else
  59. show();
  60. #endif
  61. }