1
/****************************************************************************
3
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the Qt Mobility Components.
9
** $QT_BEGIN_LICENSE:LGPL$
10
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
40
****************************************************************************/
42
#include "qmlapplicationviewer.h"
44
#include <QtCore/QDir>
45
#include <QtCore/QFileInfo>
46
#include <QtDeclarative/QDeclarativeComponent>
47
#include <QtDeclarative/QDeclarativeEngine>
48
#include <QtDeclarative/QDeclarativeContext>
49
#include <QtGui/QApplication>
51
#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
53
#ifdef HARMATTAN_BOOSTER
54
#include <MDeclarativeCache>
57
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
59
#include <qt_private/qdeclarativedebughelper_p.h>
61
#if !defined(NO_JSDEBUGGER)
62
#include <jsdebuggeragent.h>
64
#if !defined(NO_QMLOBSERVER)
65
#include <qdeclarativeviewobserver.h>
68
// Enable debugging before any QDeclarativeEngine is created
69
struct QmlJsDebuggingEnabler
71
QmlJsDebuggingEnabler()
73
QDeclarativeDebugHelper::enableDebugging();
77
// Execute code in constructor before first QDeclarativeEngine is instantiated
78
static QmlJsDebuggingEnabler enableDebuggingHelper;
80
#endif // QMLJSDEBUGGER
82
class QmlApplicationViewerPrivate
84
QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
87
QDeclarativeView *view;
88
friend class QmlApplicationViewer;
89
QString adjustPath(const QString &path);
92
QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
96
if (!QDir::isAbsolutePath(path))
97
return QCoreApplication::applicationDirPath()
98
+ QLatin1String("/../Resources/") + path;
100
QString pathInInstallDir;
101
const QString applicationDirPath = QCoreApplication::applicationDirPath();
102
pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
104
if (QFileInfo(pathInInstallDir).exists())
105
return pathInInstallDir;
111
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
112
: QDeclarativeView(parent)
113
, d(new QmlApplicationViewerPrivate(this))
115
connect(engine(), SIGNAL(quit()), SLOT(close()));
116
setResizeMode(QDeclarativeView::SizeRootObjectToView);
117
// Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
118
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
119
#if !defined(NO_JSDEBUGGER)
120
new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
122
#if !defined(NO_QMLOBSERVER)
123
new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
128
QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
129
: QDeclarativeView(parent)
130
, d(new QmlApplicationViewerPrivate(view))
132
connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
133
view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
134
// Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
135
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
136
#if !defined(NO_JSDEBUGGER)
137
new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
139
#if !defined(NO_QMLOBSERVER)
140
new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
145
QmlApplicationViewer::~QmlApplicationViewer()
150
QmlApplicationViewer *QmlApplicationViewer::create()
152
#ifdef HARMATTAN_BOOSTER
153
return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
155
return new QmlApplicationViewer();
159
void QmlApplicationViewer::setMainQmlFile(const QString &file)
161
d->mainQmlFile = d->adjustPath(file);
162
d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
165
void QmlApplicationViewer::addImportPath(const QString &path)
167
d->view->engine()->addImportPath(d->adjustPath(path));
170
void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
172
#if defined(Q_OS_SYMBIAN)
173
// If the version of Qt on the device is < 4.7.2, that attribute won't work
174
if (orientation != ScreenOrientationAuto) {
175
const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
176
if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
177
qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
181
#endif // Q_OS_SYMBIAN
183
Qt::WidgetAttribute attribute;
184
switch (orientation) {
185
#if QT_VERSION < 0x040702
186
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
187
case ScreenOrientationLockPortrait:
188
attribute = static_cast<Qt::WidgetAttribute>(128);
190
case ScreenOrientationLockLandscape:
191
attribute = static_cast<Qt::WidgetAttribute>(129);
194
case ScreenOrientationAuto:
195
attribute = static_cast<Qt::WidgetAttribute>(130);
197
#else // QT_VERSION < 0x040702
198
case ScreenOrientationLockPortrait:
199
attribute = Qt::WA_LockPortraitOrientation;
201
case ScreenOrientationLockLandscape:
202
attribute = Qt::WA_LockLandscapeOrientation;
205
case ScreenOrientationAuto:
206
attribute = Qt::WA_AutoOrientation;
208
#endif // QT_VERSION < 0x040702
210
setAttribute(attribute, true);
213
void QmlApplicationViewer::showExpanded()
215
#if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
216
d->view->showFullScreen();
217
#elif defined(Q_WS_MAEMO_5)
218
d->view->showMaximized();
224
QApplication *createApplication(int &argc, char **argv)
226
#ifdef HARMATTAN_BOOSTER
227
return MDeclarativeCache::qApplication(argc, argv);
229
return new QApplication(argc, argv);