Add screenshots etc. for ovi store and apps.formeego.com.
[qzeecontrol] / qmlapplicationviewer / qmlapplicationviewer.cpp
1 // checksum 0xee24 version 0x70013
2 /*
3   This file was generated by the Qt Quick Application wizard of Qt Creator.
4   QmlApplicationViewer is a convenience class containing mobile device specific
5   code such as screen orientation handling. Also QML paths and debugging are
6   handled here.
7   It is recommended not to modify this file, since newer versions of Qt Creator
8   may offer an updated version of it.
9 */
10
11 #include "qmlapplicationviewer.h"
12
13 #include <QtCore/QDir>
14 #include <QtCore/QFileInfo>
15 #include <QtGui/QApplication>
16 #include <QtDeclarative/QDeclarativeComponent>
17 #include <QtDeclarative/QDeclarativeEngine>
18 #include <QtDeclarative/QDeclarativeContext>
19
20 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21
22 #ifdef HARMATTAN_BOOSTER
23 #include <MDeclarativeCache>
24 #endif
25
26 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27
28 #include <qt_private/qdeclarativedebughelper_p.h>
29
30 #if !defined(NO_JSDEBUGGER)
31 #include <jsdebuggeragent.h>
32 #endif
33 #if !defined(NO_QMLOBSERVER)
34 #include <qdeclarativeviewobserver.h>
35 #endif
36
37 // Enable debugging before any QDeclarativeEngine is created
38 struct QmlJsDebuggingEnabler
39 {
40     QmlJsDebuggingEnabler()
41     {
42         QDeclarativeDebugHelper::enableDebugging();
43     }
44 };
45
46 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 static QmlJsDebuggingEnabler enableDebuggingHelper;
48
49 #endif // QMLJSDEBUGGER
50
51 class QmlApplicationViewerPrivate
52 {
53     QString mainQmlFile;
54     friend class QmlApplicationViewer;
55     static QString adjustPath(const QString &path);
56 };
57
58 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
59 {
60 #ifdef Q_OS_UNIX
61 #ifdef Q_OS_MAC
62     if (!QDir::isAbsolutePath(path))
63         return QString::fromLatin1("%1/../Resources/%2")
64                 .arg(QCoreApplication::applicationDirPath(), path);
65 #else
66     const QString pathInInstallDir =
67             QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
68     if (QFileInfo(pathInInstallDir).exists())
69         return pathInInstallDir;
70 #endif
71 #endif
72     return path;
73 }
74
75 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
76     : QDeclarativeView(parent)
77     , d(new QmlApplicationViewerPrivate())
78 {
79     connect(engine(), SIGNAL(quit()), SLOT(close()));
80     setResizeMode(QDeclarativeView::SizeRootObjectToView);
81     // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
82 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
83 #if !defined(NO_JSDEBUGGER)
84     new QmlJSDebugger::JSDebuggerAgent(engine());
85 #endif
86 #if !defined(NO_QMLOBSERVER)
87     new QmlJSDebugger::QDeclarativeViewObserver(this, this);
88 #endif
89 #endif
90 }
91
92 QmlApplicationViewer::~QmlApplicationViewer()
93 {
94     delete d;
95 }
96
97 QmlApplicationViewer *QmlApplicationViewer::create()
98 {
99     return new QmlApplicationViewer();
100 }
101
102 void QmlApplicationViewer::setMainQmlFile(const QString &file)
103 {
104     d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
105     setSource(QUrl::fromLocalFile(d->mainQmlFile));
106 }
107
108 void QmlApplicationViewer::addImportPath(const QString &path)
109 {
110     engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
111 }
112
113 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
114 {
115 #if defined(Q_OS_SYMBIAN)
116     // If the version of Qt on the device is < 4.7.2, that attribute won't work
117     if (orientation != ScreenOrientationAuto) {
118         const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
119         if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
120             qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
121             return;
122         }
123     }
124 #endif // Q_OS_SYMBIAN
125
126     Qt::WidgetAttribute attribute;
127     switch (orientation) {
128 #if QT_VERSION < 0x040702
129     // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
130     case ScreenOrientationLockPortrait:
131         attribute = static_cast<Qt::WidgetAttribute>(128);
132         break;
133     case ScreenOrientationLockLandscape:
134         attribute = static_cast<Qt::WidgetAttribute>(129);
135         break;
136     default:
137     case ScreenOrientationAuto:
138         attribute = static_cast<Qt::WidgetAttribute>(130);
139         break;
140 #else // QT_VERSION < 0x040702
141     case ScreenOrientationLockPortrait:
142         attribute = Qt::WA_LockPortraitOrientation;
143         break;
144     case ScreenOrientationLockLandscape:
145         attribute = Qt::WA_LockLandscapeOrientation;
146         break;
147     default:
148     case ScreenOrientationAuto:
149         attribute = Qt::WA_AutoOrientation;
150         break;
151 #endif // QT_VERSION < 0x040702
152     };
153     setAttribute(attribute, true);
154 }
155
156 void QmlApplicationViewer::showExpanded()
157 {
158 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
159     showFullScreen();
160 #elif defined(Q_WS_MAEMO_5)
161     showMaximized();
162 #else
163     show();
164 #endif
165 }
166
167 QApplication *createApplication(int &argc, char **argv)
168 {
169 #ifdef HARMATTAN_BOOSTER
170     return MDeclarativeCache::qApplication(argc, argv);
171 #else
172     return new QApplication(argc, argv);
173 #endif
174 }