examples/QtQuick/telephonyexampleqml/qmlapplicationviewer/qmlapplicationviewer.cpp

00001 /*
00002 * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
00003 * All rights reserved.
00004 * This software, including documentation is protected by copyright controlled
00005 * by Nokia Corporation. Copying, including reproducing, storing, adapting or
00006 * translating, any or all of this material can only be done in accordance
00007 * with the Nokia Symbian License version 1.0 (or any subsequent update) or 
00008 * any other license terms expressly agreed between you and Nokia.
00009 * This material contains Nokia's confidential information which
00010 * may not be disclosed to others without the prior written consent of Nokia.
00011 *
00012 * Initial Contributors:
00013 * Nokia Corporation - initial contribution.
00014 *
00015 * Contributors:
00016 *
00017 * Description:
00018 *
00019 */
00020 // checksum 0x17fa version 0x3000a
00021 /*
00022   This file was generated by the Qt Quick Application wizard of Qt Creator.
00023   QmlApplicationViewer is a convenience class containing mobile device specific
00024   code such as screen orientation handling. Also QML paths and debugging are
00025   handled here.
00026   It is recommended not to modify this file, since newer versions of Qt Creator
00027   may offer an updated version of it.
00028 */
00029 
00030 #include "qmlapplicationviewer.h"
00031 
00032 #include <QtCore/QCoreApplication>
00033 #include <QtCore/QDir>
00034 #include <QtCore/QFileInfo>
00035 #include <QtDeclarative/QDeclarativeComponent>
00036 #include <QtDeclarative/QDeclarativeEngine>
00037 #include <QtDeclarative/QDeclarativeContext>
00038 
00039 #if defined(QMLJSDEBUGGER)
00040 #include <qt_private/qdeclarativedebughelper_p.h>
00041 #endif
00042 
00043 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
00044 #include <jsdebuggeragent.h>
00045 #endif
00046 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
00047 #include <qdeclarativeviewobserver.h>
00048 #endif
00049 
00050 #if defined(QMLJSDEBUGGER)
00051 
00052 // Enable debugging before any QDeclarativeEngine is created
00053 struct QmlJsDebuggingEnabler
00054 {
00055     QmlJsDebuggingEnabler()
00056     {
00057         QDeclarativeDebugHelper::enableDebugging();
00058     }
00059 };
00060 
00061 // Execute code in constructor before first QDeclarativeEngine is instantiated
00062 static QmlJsDebuggingEnabler enableDebuggingHelper;
00063 
00064 #endif // QMLJSDEBUGGER
00065 
00066 class QmlApplicationViewerPrivate
00067 {
00068     QString mainQmlFile;
00069     friend class QmlApplicationViewer;
00070     static QString adjustPath(const QString &path);
00071 };
00072 
00073 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
00074 {
00075 #ifdef Q_OS_UNIX
00076 #ifdef Q_OS_MAC
00077     if (!QDir::isAbsolutePath(path))
00078         return QCoreApplication::applicationDirPath()
00079                 + QLatin1String("/../Resources/") + path;
00080 #else
00081     const QString pathInShareDir = QCoreApplication::applicationDirPath()
00082         + QLatin1String("/../share/")
00083         + QFileInfo(QCoreApplication::applicationFilePath()).fileName()
00084         + QLatin1Char('/') + path;
00085     if (QFileInfo(pathInShareDir).exists())
00086         return pathInShareDir;
00087 #endif
00088 #endif
00089     return path;
00090 }
00091 
00092 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
00093     QDeclarativeView(parent),
00094     m_d(new QmlApplicationViewerPrivate)
00095 {
00096     connect(engine(), SIGNAL(quit()), SLOT(close()));
00097     setResizeMode(QDeclarativeView::SizeRootObjectToView);
00098 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
00099     new QmlJSDebugger::JSDebuggerAgent(engine());
00100 #endif
00101 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
00102     new QmlJSDebugger::QDeclarativeViewObserver(this, parent);
00103 #endif
00104 }
00105 
00106 QmlApplicationViewer::~QmlApplicationViewer()
00107 {
00108     delete m_d;
00109 }
00110 
00111 void QmlApplicationViewer::setMainQmlFile(const QString &file)
00112 {
00113     m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
00114     setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
00115 }
00116 
00117 void QmlApplicationViewer::addImportPath(const QString &path)
00118 {
00119     engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
00120 }
00121 
00122 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
00123 {
00124 #if defined(Q_OS_SYMBIAN)
00125     // If the version of Qt on the device is < 4.7.2, that attribute won't work
00126     if (orientation != ScreenOrientationAuto) {
00127         const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
00128         if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
00129             qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
00130             return;
00131         }
00132     }
00133 #endif // Q_OS_SYMBIAN
00134 
00135     Qt::WidgetAttribute attribute;
00136     switch (orientation) {
00137 #if QT_VERSION < 0x040702
00138     // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
00139     case ScreenOrientationLockPortrait:
00140         attribute = static_cast<Qt::WidgetAttribute>(128);
00141         break;
00142     case ScreenOrientationLockLandscape:
00143         attribute = static_cast<Qt::WidgetAttribute>(129);
00144         break;
00145     default:
00146     case ScreenOrientationAuto:
00147         attribute = static_cast<Qt::WidgetAttribute>(130);
00148         break;
00149 #else // QT_VERSION < 0x040702
00150     case ScreenOrientationLockPortrait:
00151         attribute = Qt::WA_LockPortraitOrientation;
00152         break;
00153     case ScreenOrientationLockLandscape:
00154         attribute = Qt::WA_LockLandscapeOrientation;
00155         break;
00156     default:
00157     case ScreenOrientationAuto:
00158         attribute = Qt::WA_AutoOrientation;
00159         break;
00160 #endif // QT_VERSION < 0x040702
00161     };
00162     setAttribute(attribute, true);
00163 }
00164 
00165 void QmlApplicationViewer::showExpanded()
00166 {
00167 #ifdef Q_OS_SYMBIAN
00168     showFullScreen();
00169 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
00170     showMaximized();
00171 #else
00172     show();
00173 #endif
00174 }

Generated by  doxygen 1.6.2