~josephjamesmills/ubuntutv/maps_fanart

« back to all changes in this revision

Viewing changes to qmlvideofx/qmlapplicationviewer/qmlapplicationviewer.cpp

  • Committer: Joseph Mills
  • Date: 2012-09-14 21:17:55 UTC
  • Revision ID: josephjamesmills@gmail.com-20120914211755-513lxkux1dlp26yp
just a update push so I can use elsewhere

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
 
5
** Contact: Nokia Corporation (qt-info@nokia.com)
 
6
**
 
7
** This file is part of the Qt Mobility Components.
 
8
**
 
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.
 
17
**
 
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.
 
21
**
 
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.
 
29
**
 
30
** Other Usage
 
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.
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include "qmlapplicationviewer.h"
 
43
 
 
44
#include <QtCore/QDir>
 
45
#include <QtCore/QFileInfo>
 
46
#include <QtDeclarative/QDeclarativeComponent>
 
47
#include <QtDeclarative/QDeclarativeEngine>
 
48
#include <QtDeclarative/QDeclarativeContext>
 
49
#include <QtGui/QApplication>
 
50
 
 
51
#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
 
52
 
 
53
#ifdef HARMATTAN_BOOSTER
 
54
#include <MDeclarativeCache>
 
55
#endif
 
56
 
 
57
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
 
58
 
 
59
#include <qt_private/qdeclarativedebughelper_p.h>
 
60
 
 
61
#if !defined(NO_JSDEBUGGER)
 
62
#include <jsdebuggeragent.h>
 
63
#endif
 
64
#if !defined(NO_QMLOBSERVER)
 
65
#include <qdeclarativeviewobserver.h>
 
66
#endif
 
67
 
 
68
// Enable debugging before any QDeclarativeEngine is created
 
69
struct QmlJsDebuggingEnabler
 
70
{
 
71
    QmlJsDebuggingEnabler()
 
72
    {
 
73
        QDeclarativeDebugHelper::enableDebugging();
 
74
    }
 
75
};
 
76
 
 
77
// Execute code in constructor before first QDeclarativeEngine is instantiated
 
78
static QmlJsDebuggingEnabler enableDebuggingHelper;
 
79
 
 
80
#endif // QMLJSDEBUGGER
 
81
 
 
82
class QmlApplicationViewerPrivate
 
83
{
 
84
    QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
 
85
 
 
86
    QString mainQmlFile;
 
87
    QDeclarativeView *view;
 
88
    friend class QmlApplicationViewer;
 
89
    QString adjustPath(const QString &path);
 
90
};
 
91
 
 
92
QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
 
93
{
 
94
#ifdef Q_OS_UNIX
 
95
#ifdef Q_OS_MAC
 
96
    if (!QDir::isAbsolutePath(path))
 
97
        return QCoreApplication::applicationDirPath()
 
98
                + QLatin1String("/../Resources/") + path;
 
99
#else
 
100
    QString pathInInstallDir;
 
101
    const QString applicationDirPath = QCoreApplication::applicationDirPath();
 
102
    pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
 
103
 
 
104
    if (QFileInfo(pathInInstallDir).exists())
 
105
        return pathInInstallDir;
 
106
#endif
 
107
#endif
 
108
    return path;
 
109
}
 
110
 
 
111
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
 
112
    : QDeclarativeView(parent)
 
113
    , d(new QmlApplicationViewerPrivate(this))
 
114
{
 
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());
 
121
#endif
 
122
#if !defined(NO_QMLOBSERVER)
 
123
    new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
 
124
#endif
 
125
#endif
 
126
}
 
127
 
 
128
QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
 
129
    : QDeclarativeView(parent)
 
130
    , d(new QmlApplicationViewerPrivate(view))
 
131
{
 
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());
 
138
#endif
 
139
#if !defined(NO_QMLOBSERVER)
 
140
    new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
 
141
#endif
 
142
#endif
 
143
}
 
144
 
 
145
QmlApplicationViewer::~QmlApplicationViewer()
 
146
{
 
147
    delete d;
 
148
}
 
149
 
 
150
QmlApplicationViewer *QmlApplicationViewer::create()
 
151
{
 
152
#ifdef HARMATTAN_BOOSTER
 
153
    return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
 
154
#else
 
155
    return new QmlApplicationViewer();
 
156
#endif
 
157
}
 
158
 
 
159
void QmlApplicationViewer::setMainQmlFile(const QString &file)
 
160
{
 
161
    d->mainQmlFile = d->adjustPath(file);
 
162
    d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
 
163
}
 
164
 
 
165
void QmlApplicationViewer::addImportPath(const QString &path)
 
166
{
 
167
    d->view->engine()->addImportPath(d->adjustPath(path));
 
168
}
 
169
 
 
170
void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
 
171
{
 
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");
 
178
            return;
 
179
        }
 
180
    }
 
181
#endif // Q_OS_SYMBIAN
 
182
 
 
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);
 
189
        break;
 
190
    case ScreenOrientationLockLandscape:
 
191
        attribute = static_cast<Qt::WidgetAttribute>(129);
 
192
        break;
 
193
    default:
 
194
    case ScreenOrientationAuto:
 
195
        attribute = static_cast<Qt::WidgetAttribute>(130);
 
196
        break;
 
197
#else // QT_VERSION < 0x040702
 
198
    case ScreenOrientationLockPortrait:
 
199
        attribute = Qt::WA_LockPortraitOrientation;
 
200
        break;
 
201
    case ScreenOrientationLockLandscape:
 
202
        attribute = Qt::WA_LockLandscapeOrientation;
 
203
        break;
 
204
    default:
 
205
    case ScreenOrientationAuto:
 
206
        attribute = Qt::WA_AutoOrientation;
 
207
        break;
 
208
#endif // QT_VERSION < 0x040702
 
209
    };
 
210
    setAttribute(attribute, true);
 
211
}
 
212
 
 
213
void QmlApplicationViewer::showExpanded()
 
214
{
 
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();
 
219
#else
 
220
    d->view->show();
 
221
#endif
 
222
}
 
223
 
 
224
QApplication *createApplication(int &argc, char **argv)
 
225
{
 
226
#ifdef HARMATTAN_BOOSTER
 
227
    return MDeclarativeCache::qApplication(argc, argv);
 
228
#else
 
229
    return new QApplication(argc, argv);
 
230
#endif
 
231
}