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 QtCore module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
41 // checksum 0x28c7 version 0x2000a
43 This file was generated by the Qt Quick Application wizard of Qt Creator.
44 QmlApplicationViewer is a convenience class containing mobile device specific
45 code such as screen orientation handling. Also QML paths and debugging are
47 It is recommended not to modify this file, since newer versions of Qt Creator
48 may offer an updated version of it.
51 #include "qmlapplicationviewer.h"
53 #include <QtCore/QCoreApplication>
54 #include <QtCore/QDir>
55 #include <QtCore/QFileInfo>
56 #include <QtDeclarative/QDeclarativeComponent>
57 #include <QtDeclarative/QDeclarativeEngine>
58 #include <QtDeclarative/QDeclarativeContext>
60 #if defined(QMLJSDEBUGGER)
61 #include <qt_private/qdeclarativedebughelper_p.h>
64 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
65 #include <jsdebuggeragent.h>
67 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
68 #include <qdeclarativeviewobserver.h>
71 #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
76 #endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
78 #if defined(QMLJSDEBUGGER)
80 // Enable debugging before any QDeclarativeEngine is created
81 struct QmlJsDebuggingEnabler
83 QmlJsDebuggingEnabler()
85 QDeclarativeDebugHelper::enableDebugging();
89 // Execute code in constructor before first QDeclarativeEngine is instantiated
90 static QmlJsDebuggingEnabler enableDebuggingHelper;
92 #endif // QMLJSDEBUGGER
94 class QmlApplicationViewerPrivate
97 friend class QmlApplicationViewer;
98 static QString adjustPath(const QString &path);
101 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
105 if (!QDir::isAbsolutePath(path))
106 return QCoreApplication::applicationDirPath()
107 + QLatin1String("/../Resources/") + path;
109 const QString pathInShareDir = QCoreApplication::applicationDirPath()
110 + QLatin1String("/../share/")
111 + QFileInfo(QCoreApplication::applicationFilePath()).fileName()
112 + QLatin1Char('/') + path;
113 if (QFileInfo(pathInShareDir).exists())
114 return pathInShareDir;
120 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
121 QDeclarativeView(parent),
122 m_d(new QmlApplicationViewerPrivate)
124 connect(engine(), SIGNAL(quit()), SLOT(close()));
125 setResizeMode(QDeclarativeView::SizeRootObjectToView);
126 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
127 new QmlJSDebugger::JSDebuggerAgent(engine());
129 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
130 new QmlJSDebugger::QDeclarativeViewObserver(this, parent);
134 QmlApplicationViewer::~QmlApplicationViewer()
139 void QmlApplicationViewer::setMainQmlFile(const QString &file)
141 m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
142 setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
145 void QmlApplicationViewer::addImportPath(const QString &path)
147 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
150 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
153 if (orientation != ScreenOrientationAuto) {
154 #if defined(ORIENTATIONLOCK)
155 const CAknAppUiBase::TAppUiOrientation uiOrientation =
156 (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
157 : CAknAppUi::EAppUiOrientationLandscape;
158 CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
161 appUi->SetOrientationL(uiOrientation);
164 #else // ORIENTATIONLOCK
165 qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
166 #endif // ORIENTATIONLOCK
168 #elif defined(Q_WS_MAEMO_5)
169 Qt::WidgetAttribute attribute;
170 switch (orientation) {
171 case ScreenOrientationLockPortrait:
172 attribute = Qt::WA_Maemo5PortraitOrientation;
174 case ScreenOrientationLockLandscape:
175 attribute = Qt::WA_Maemo5LandscapeOrientation;
177 case ScreenOrientationAuto:
179 attribute = Qt::WA_Maemo5AutoOrientation;
182 setAttribute(attribute, true);
183 #else // Q_OS_SYMBIAN
184 Q_UNUSED(orientation);
185 #endif // Q_OS_SYMBIAN
188 void QmlApplicationViewer::showExpanded()
192 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)