~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to share/qtcreator/templates/qtquick/qtquick_1_1/qtquick1applicationviewer/qtquick1applicationviewer.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-12-02 09:16:15 UTC
  • mfrom: (1.1.29)
  • Revision ID: timo.jyrinki@canonical.com-20131202091615-xbj1os1f604ber1m
New upstream release candidate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This file was generated by the Qt Quick 1 Application wizard of Qt Creator.
 
3
  QtQuick1ApplicationViewer is a convenience class containing mobile device
 
4
  specific code such as screen orientation handling. Also QML paths are
 
5
  handled here.
 
6
  It is recommended not to modify this file, since newer versions of Qt Creator
 
7
  may offer an updated version of it.
 
8
*/
 
9
 
 
10
#include "qtquick1applicationviewer.h"
 
11
 
 
12
#include <QDir>
 
13
#include <QFileInfo>
 
14
#include <QApplication>
 
15
#include <QDeclarativeComponent>
 
16
#include <QDeclarativeEngine>
 
17
#include <QDeclarativeContext>
 
18
 
 
19
#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
 
20
 
 
21
class QtQuick1ApplicationViewerPrivate
 
22
{
 
23
    QString mainQmlFile;
 
24
    friend class QtQuick1ApplicationViewer;
 
25
    static QString adjustPath(const QString &path);
 
26
};
 
27
 
 
28
QString QtQuick1ApplicationViewerPrivate::adjustPath(const QString &path)
 
29
{
 
30
#if defined(Q_OS_IOS)
 
31
    if (!QDir::isAbsolutePath(path))
 
32
        return QString::fromLatin1("%1/%2")
 
33
                .arg(QCoreApplication::applicationDirPath(), path);
 
34
#elif defined(Q_OS_MAC)
 
35
    if (!QDir::isAbsolutePath(path))
 
36
        return QString::fromLatin1("%1/../Resources/%2")
 
37
                .arg(QCoreApplication::applicationDirPath(), path);
 
38
#elif defined(Q_OS_BLACKBERRY)
 
39
    if (!QDir::isAbsolutePath(path))
 
40
        return QString::fromLatin1("app/native/%1").arg(path);
 
41
#elif !defined(Q_OS_ANDROID)
 
42
    QString pathInInstallDir =
 
43
            QString::fromLatin1("%1/../%2").arg(
 
44
                QCoreApplication::applicationDirPath(), path);
 
45
    if (QFileInfo(pathInInstallDir).exists())
 
46
        return pathInInstallDir;
 
47
    pathInInstallDir =
 
48
            QString::fromLatin1("%1/%2").arg(
 
49
                QCoreApplication::applicationDirPath(), path);
 
50
    if (QFileInfo(pathInInstallDir).exists())
 
51
        return pathInInstallDir;
 
52
#endif
 
53
    return path;
 
54
}
 
55
 
 
56
QtQuick1ApplicationViewer::QtQuick1ApplicationViewer(QWidget *parent)
 
57
    : QDeclarativeView(parent)
 
58
    , d(new QtQuick1ApplicationViewerPrivate())
 
59
{
 
60
    connect(engine(), SIGNAL(quit()), SLOT(close()));
 
61
    setResizeMode(QDeclarativeView::SizeRootObjectToView);
 
62
}
 
63
 
 
64
QtQuick1ApplicationViewer::~QtQuick1ApplicationViewer()
 
65
{
 
66
    delete d;
 
67
}
 
68
 
 
69
QtQuick1ApplicationViewer *QtQuick1ApplicationViewer::create()
 
70
{
 
71
    return new QtQuick1ApplicationViewer();
 
72
}
 
73
 
 
74
void QtQuick1ApplicationViewer::setMainQmlFile(const QString &file)
 
75
{
 
76
    d->mainQmlFile = QtQuick1ApplicationViewerPrivate::adjustPath(file);
 
77
#ifdef Q_OS_ANDROID
 
78
    setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile));
 
79
#else
 
80
    setSource(QUrl::fromLocalFile(d->mainQmlFile));
 
81
#endif
 
82
}
 
83
 
 
84
void QtQuick1ApplicationViewer::addImportPath(const QString &path)
 
85
{
 
86
    engine()->addImportPath(QtQuick1ApplicationViewerPrivate::adjustPath(path));
 
87
}
 
88
 
 
89
void QtQuick1ApplicationViewer::setOrientation(ScreenOrientation orientation)
 
90
{
 
91
#if QT_VERSION < 0x050000
 
92
    Qt::WidgetAttribute attribute;
 
93
    switch (orientation) {
 
94
    case ScreenOrientationLockPortrait:
 
95
        attribute = Qt::WA_LockPortraitOrientation;
 
96
        break;
 
97
    case ScreenOrientationLockLandscape:
 
98
        attribute = Qt::WA_LockLandscapeOrientation;
 
99
        break;
 
100
    default:
 
101
    case ScreenOrientationAuto:
 
102
        attribute = Qt::WA_AutoOrientation;
 
103
        break;
 
104
    };
 
105
    setAttribute(attribute, true);
 
106
#else // QT_VERSION < 0x050000
 
107
    Q_UNUSED(orientation)
 
108
#endif // QT_VERSION < 0x050000
 
109
}
 
110
 
 
111
void QtQuick1ApplicationViewer::showExpanded()
 
112
{
 
113
#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX)
 
114
    showFullScreen();
 
115
#else
 
116
    show();
 
117
#endif
 
118
}