qmlFrontend/qtquick2applicationviewer/qtquick2applicationviewer.cpp
author unc0rr
Wed, 01 Oct 2014 01:20:05 +0400
branchqmlfrontend
changeset 10436 084e046f6bd5
parent 10402 3313336c1ee0
permissions -rw-r--r--
flib provides theme icons, qmlFrontend shows them
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     1
// checksum 0x4f6f version 0x90005
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     2
/*
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     3
  This file was generated by the Qt Quick 2 Application wizard of Qt Creator.
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     4
  QtQuick2ApplicationViewer is a convenience class containing mobile device specific
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     5
  code such as screen orientation handling. Also QML paths and debugging are
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     6
  handled here.
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     7
  It is recommended not to modify this file, since newer versions of Qt Creator
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     8
  may offer an updated version of it.
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     9
*/
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    10
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    11
#include "qtquick2applicationviewer.h"
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    12
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    13
#include <QtCore/QCoreApplication>
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    14
#include <QtCore/QDir>
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    15
#include <QtQml/QQmlEngine>
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    16
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    17
class QtQuick2ApplicationViewerPrivate
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    18
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    19
    QString mainQmlFile;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    20
    friend class QtQuick2ApplicationViewer;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    21
    static QString adjustPath(const QString &path);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    22
};
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    23
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    24
QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    25
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    26
#if defined(Q_OS_MAC)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    27
    if (!QDir::isAbsolutePath(path))
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    28
        return QString::fromLatin1("%1/../Resources/%2")
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    29
                .arg(QCoreApplication::applicationDirPath(), path);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    30
#elif defined(Q_OS_BLACKBERRY)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    31
    if (!QDir::isAbsolutePath(path))
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    32
        return QString::fromLatin1("app/native/%1").arg(path);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    33
#elif !defined(Q_OS_ANDROID)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    34
    QString pathInInstallDir =
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    35
            QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    36
    if (QFileInfo(pathInInstallDir).exists())
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    37
        return pathInInstallDir;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    38
    pathInInstallDir =
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    39
            QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    40
    if (QFileInfo(pathInInstallDir).exists())
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    41
        return pathInInstallDir;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    42
#endif
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    43
    return path;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    44
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    45
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    46
QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    47
    : QQuickView(parent)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    48
    , d(new QtQuick2ApplicationViewerPrivate())
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    49
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    50
    connect(engine(), SIGNAL(quit()), SLOT(close()));
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    51
    setResizeMode(QQuickView::SizeRootObjectToView);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    52
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    53
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    54
QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    55
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    56
    delete d;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    57
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    58
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    59
void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    60
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    61
    d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    62
#ifdef Q_OS_ANDROID
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    63
    setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile));
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    64
#else
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    65
    setSource(QUrl::fromLocalFile(d->mainQmlFile));
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    66
#endif
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    67
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    68
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    69
void QtQuick2ApplicationViewer::addImportPath(const QString &path)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    70
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    71
    engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path));
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    72
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    73
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    74
void QtQuick2ApplicationViewer::showExpanded()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    75
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    76
#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    77
    showFullScreen();
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    78
#else
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    79
    show();
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    80
#endif
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    81
}