forked from qt-creator/qt-creator
Also bump the minimum Qt version required for new Qt Quick apps to 4.8 Change-Id: Ieeabc8475ccfa7f9fec7ca08cd88384ed88f0d1d Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
113 lines
3.1 KiB
C++
113 lines
3.1 KiB
C++
/*
|
|
This file was generated by the Qt Quick Application wizard of Qt Creator.
|
|
QmlApplicationViewer is a convenience class containing mobile device specific
|
|
code such as screen orientation handling. Also QML paths and debugging are
|
|
handled here.
|
|
It is recommended not to modify this file, since newer versions of Qt Creator
|
|
may offer an updated version of it.
|
|
*/
|
|
|
|
#include "qmlapplicationviewer.h"
|
|
|
|
#include <QDir>
|
|
#include <QFileInfo>
|
|
#include <QApplication>
|
|
#include <QDeclarativeComponent>
|
|
#include <QDeclarativeEngine>
|
|
#include <QDeclarativeContext>
|
|
|
|
#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
|
|
|
|
class QmlApplicationViewerPrivate
|
|
{
|
|
QString mainQmlFile;
|
|
friend class QmlApplicationViewer;
|
|
static QString adjustPath(const QString &path);
|
|
};
|
|
|
|
QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
|
|
{
|
|
#ifdef Q_OS_MAC
|
|
if (!QDir::isAbsolutePath(path))
|
|
return QString::fromLatin1("%1/../Resources/%2")
|
|
.arg(QCoreApplication::applicationDirPath(), path);
|
|
#elif defined(Q_OS_BLACKBERRY)
|
|
if (!QDir::isAbsolutePath(path))
|
|
return QString::fromLatin1("app/native/%1").arg(path);
|
|
#elif !defined(Q_OS_ANDROID)
|
|
QString pathInInstallDir =
|
|
QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
|
|
if (QFileInfo(pathInInstallDir).exists())
|
|
return pathInInstallDir;
|
|
pathInInstallDir =
|
|
QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path);
|
|
if (QFileInfo(pathInInstallDir).exists())
|
|
return pathInInstallDir;
|
|
#endif
|
|
return path;
|
|
}
|
|
|
|
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
|
|
: QDeclarativeView(parent)
|
|
, d(new QmlApplicationViewerPrivate())
|
|
{
|
|
connect(engine(), SIGNAL(quit()), SLOT(close()));
|
|
setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
|
}
|
|
|
|
QmlApplicationViewer::~QmlApplicationViewer()
|
|
{
|
|
delete d;
|
|
}
|
|
|
|
QmlApplicationViewer *QmlApplicationViewer::create()
|
|
{
|
|
return new QmlApplicationViewer();
|
|
}
|
|
|
|
void QmlApplicationViewer::setMainQmlFile(const QString &file)
|
|
{
|
|
d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
|
|
#ifdef Q_OS_ANDROID
|
|
setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile));
|
|
#else
|
|
setSource(QUrl::fromLocalFile(d->mainQmlFile));
|
|
#endif
|
|
}
|
|
|
|
void QmlApplicationViewer::addImportPath(const QString &path)
|
|
{
|
|
engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
|
|
}
|
|
|
|
void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
|
|
{
|
|
#if QT_VERSION < 0x050000
|
|
Qt::WidgetAttribute attribute;
|
|
switch (orientation) {
|
|
case ScreenOrientationLockPortrait:
|
|
attribute = Qt::WA_LockPortraitOrientation;
|
|
break;
|
|
case ScreenOrientationLockLandscape:
|
|
attribute = Qt::WA_LockLandscapeOrientation;
|
|
break;
|
|
default:
|
|
case ScreenOrientationAuto:
|
|
attribute = Qt::WA_AutoOrientation;
|
|
break;
|
|
};
|
|
setAttribute(attribute, true);
|
|
#else // QT_VERSION < 0x050000
|
|
Q_UNUSED(orientation)
|
|
#endif // QT_VERSION < 0x050000
|
|
}
|
|
|
|
void QmlApplicationViewer::showExpanded()
|
|
{
|
|
#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX)
|
|
showFullScreen();
|
|
#else
|
|
show();
|
|
#endif
|
|
}
|