blob: 0b7ffe85da150c13640ed4d4ffa3bfe7d2600c12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
This file was generated by the Qt Quick 1 Application wizard of Qt Creator.
QtQuick1ApplicationViewer is a convenience class containing mobile device
specific code such as screen orientation handling. Also QML paths 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 "qtquick1applicationviewer.h"
#include <QDir>
#include <QFileInfo>
#include <QApplication>
#include <QDeclarativeComponent>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
class QtQuick1ApplicationViewerPrivate
{
QString mainQmlFile;
friend class QtQuick1ApplicationViewer;
static QString adjustPath(const QString &path);
};
QString QtQuick1ApplicationViewerPrivate::adjustPath(const QString &path)
{
#if defined(Q_OS_IOS)
if (!QDir::isAbsolutePath(path))
return QString::fromLatin1("%1/%2")
.arg(QCoreApplication::applicationDirPath(), path);
#elif defined(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;
}
QtQuick1ApplicationViewer::QtQuick1ApplicationViewer(QWidget *parent)
: QDeclarativeView(parent)
, d(new QtQuick1ApplicationViewerPrivate())
{
connect(engine(), SIGNAL(quit()), SLOT(close()));
setResizeMode(QDeclarativeView::SizeRootObjectToView);
}
QtQuick1ApplicationViewer::~QtQuick1ApplicationViewer()
{
delete d;
}
QtQuick1ApplicationViewer *QtQuick1ApplicationViewer::create()
{
return new QtQuick1ApplicationViewer();
}
void QtQuick1ApplicationViewer::setMainQmlFile(const QString &file)
{
d->mainQmlFile = QtQuick1ApplicationViewerPrivate::adjustPath(file);
#ifdef Q_OS_ANDROID
setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile));
#else
setSource(QUrl::fromLocalFile(d->mainQmlFile));
#endif
}
void QtQuick1ApplicationViewer::addImportPath(const QString &path)
{
engine()->addImportPath(QtQuick1ApplicationViewerPrivate::adjustPath(path));
}
void QtQuick1ApplicationViewer::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 QtQuick1ApplicationViewer::showExpanded()
{
#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX)
showFullScreen();
#else
show();
#endif
}
|