2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-10 05:19:47 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** This file is part of the tools applications of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-07-07 12:52:03 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-07-07 12:52:03 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 12:13:26 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-07-07 12:52:03 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtCore/qdebug.h>
|
|
|
|
#include <QtCore/qabstractanimation.h>
|
2011-12-06 07:06:03 +00:00
|
|
|
#include <QtCore/qdir.h>
|
|
|
|
#include <QtCore/qmath.h>
|
|
|
|
#include <QtCore/qdatetime.h>
|
|
|
|
|
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qqml.h>
|
|
|
|
#include <QtQml/qqmlengine.h>
|
|
|
|
#include <QtQml/qqmlcomponent.h>
|
|
|
|
#include <QtQml/qqmlcontext.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/qquickitem.h>
|
|
|
|
#include <QtQuick/qquickview.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-02-07 12:29:45 +00:00
|
|
|
#include <private/qabstractanimation_p.h>
|
|
|
|
|
2011-12-12 06:18:03 +00:00
|
|
|
#ifdef QT_WIDGETS_LIB
|
2011-12-13 10:06:15 +00:00
|
|
|
#include <QtWidgets/QApplication>
|
2011-12-12 06:18:03 +00:00
|
|
|
#include <QtWidgets/QFileDialog>
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
#ifdef QML_RUNTIME_TESTING
|
|
|
|
class RenderStatistics
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void updateStats();
|
|
|
|
static void printTotalStats();
|
|
|
|
private:
|
|
|
|
static QVector<qreal> timePerFrame;
|
|
|
|
static QVector<int> timesPerFrames;
|
|
|
|
};
|
|
|
|
|
|
|
|
QVector<qreal> RenderStatistics::timePerFrame;
|
|
|
|
QVector<int> RenderStatistics::timesPerFrames;
|
|
|
|
|
|
|
|
void RenderStatistics::updateStats()
|
|
|
|
{
|
|
|
|
static QTime time;
|
|
|
|
static int frames;
|
|
|
|
static int lastTime;
|
|
|
|
|
|
|
|
if (frames == 0) {
|
|
|
|
time.start();
|
|
|
|
} else {
|
|
|
|
int elapsed = time.elapsed();
|
|
|
|
timesPerFrames.append(elapsed - lastTime);
|
|
|
|
lastTime = elapsed;
|
|
|
|
|
|
|
|
if (elapsed > 5000) {
|
|
|
|
qreal avgtime = elapsed / (qreal) frames;
|
|
|
|
qreal var = 0;
|
|
|
|
for (int i = 0; i < timesPerFrames.size(); ++i) {
|
|
|
|
qreal diff = timesPerFrames.at(i) - avgtime;
|
|
|
|
var += diff * diff;
|
|
|
|
}
|
|
|
|
var /= timesPerFrames.size();
|
|
|
|
|
|
|
|
qDebug("Average time per frame: %f ms (%i fps), std.dev: %f ms", avgtime, qRound(1000. / avgtime), qSqrt(var));
|
|
|
|
|
|
|
|
timePerFrame.append(avgtime);
|
|
|
|
timesPerFrames.clear();
|
|
|
|
time.start();
|
|
|
|
lastTime = 0;
|
|
|
|
frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderStatistics::printTotalStats()
|
|
|
|
{
|
|
|
|
int count = timePerFrame.count();
|
|
|
|
if (count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
qreal minTime = 0;
|
|
|
|
qreal maxTime = 0;
|
|
|
|
qreal avg = 0;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
minTime = minTime == 0 ? timePerFrame.at(i) : qMin(minTime, timePerFrame.at(i));
|
|
|
|
maxTime = qMax(maxTime, timePerFrame.at(i));
|
|
|
|
avg += timePerFrame.at(i);
|
|
|
|
}
|
|
|
|
avg /= count;
|
|
|
|
|
|
|
|
qDebug(" ");
|
|
|
|
qDebug("----- Statistics -----");
|
|
|
|
qDebug("Average time per frame: %f ms (%i fps)", avg, qRound(1000. / avg));
|
|
|
|
qDebug("Best time per frame: %f ms (%i fps)", minTime, int(1000 / minTime));
|
|
|
|
qDebug("Worst time per frame: %f ms (%i fps)", maxTime, int(1000 / maxTime));
|
|
|
|
qDebug("----------------------");
|
|
|
|
qDebug(" ");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct Options
|
|
|
|
{
|
|
|
|
Options()
|
|
|
|
: originalQml(false)
|
|
|
|
, originalQmlRaster(false)
|
|
|
|
, maximized(false)
|
|
|
|
, fullscreen(false)
|
|
|
|
, clip(false)
|
|
|
|
, versionDetection(true)
|
2012-02-07 12:29:45 +00:00
|
|
|
, slowAnimations(false)
|
2012-03-21 02:49:15 +00:00
|
|
|
, quitImmediately(false)
|
2012-05-25 13:30:47 +00:00
|
|
|
, resizeViewToRootItem(false)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl file;
|
|
|
|
bool originalQml;
|
|
|
|
bool originalQmlRaster;
|
|
|
|
bool maximized;
|
|
|
|
bool fullscreen;
|
|
|
|
bool scenegraphOnGraphicsview;
|
|
|
|
bool clip;
|
|
|
|
bool versionDetection;
|
2012-02-07 12:29:45 +00:00
|
|
|
bool slowAnimations;
|
2012-03-21 02:49:15 +00:00
|
|
|
bool quitImmediately;
|
2012-05-25 13:30:47 +00:00
|
|
|
bool resizeViewToRootItem;
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(QMLSCENE_BUNDLE)
|
|
|
|
Q_DECLARE_METATYPE(QFileInfo);
|
|
|
|
QFileInfoList findQmlFiles(const QString &dirName)
|
|
|
|
{
|
|
|
|
QDir dir(dirName);
|
|
|
|
|
|
|
|
QFileInfoList ret;
|
|
|
|
if (dir.exists()) {
|
|
|
|
QFileInfoList fileInfos = dir.entryInfoList(QStringList() << "*.qml",
|
|
|
|
QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
foreach (QFileInfo fileInfo, fileInfos) {
|
|
|
|
if (fileInfo.isDir())
|
|
|
|
ret += findQmlFiles(fileInfo.filePath());
|
|
|
|
else if (fileInfo.fileName().length() > 0 && fileInfo.fileName().at(0).isLower())
|
|
|
|
ret.append(fileInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int displayOptionsDialog(Options *options)
|
|
|
|
{
|
|
|
|
QDialog dialog;
|
|
|
|
|
|
|
|
QFormLayout *layout = new QFormLayout(&dialog);
|
|
|
|
|
|
|
|
QComboBox *qmlFileComboBox = new QComboBox(&dialog);
|
|
|
|
QFileInfoList fileInfos = findQmlFiles(":/bundle") + findQmlFiles("./qmlscene-resources");
|
|
|
|
|
|
|
|
foreach (QFileInfo fileInfo, fileInfos)
|
|
|
|
qmlFileComboBox->addItem(fileInfo.dir().dirName() + "/" + fileInfo.fileName(), QVariant::fromValue(fileInfo));
|
|
|
|
|
|
|
|
QCheckBox *originalCheckBox = new QCheckBox(&dialog);
|
|
|
|
originalCheckBox->setText("Use original QML viewer");
|
|
|
|
originalCheckBox->setChecked(options->originalQml);
|
|
|
|
|
|
|
|
QCheckBox *fullscreenCheckBox = new QCheckBox(&dialog);
|
|
|
|
fullscreenCheckBox->setText("Start fullscreen");
|
|
|
|
fullscreenCheckBox->setChecked(options->fullscreen);
|
|
|
|
|
|
|
|
QCheckBox *maximizedCheckBox = new QCheckBox(&dialog);
|
|
|
|
maximizedCheckBox->setText("Start maximized");
|
|
|
|
maximizedCheckBox->setChecked(options->maximized);
|
|
|
|
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
|
|
|
Qt::Horizontal,
|
|
|
|
&dialog);
|
|
|
|
QObject::connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
|
|
|
QObject::connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
|
|
|
|
|
|
|
layout->addRow("Qml file:", qmlFileComboBox);
|
|
|
|
layout->addWidget(originalCheckBox);
|
|
|
|
layout->addWidget(maximizedCheckBox);
|
|
|
|
layout->addWidget(fullscreenCheckBox);
|
|
|
|
layout->addWidget(buttonBox);
|
|
|
|
|
|
|
|
int result = dialog.exec();
|
|
|
|
if (result == QDialog::Accepted) {
|
|
|
|
QVariant variant = qmlFileComboBox->itemData(qmlFileComboBox->currentIndex());
|
|
|
|
QFileInfo fileInfo = variant.value<QFileInfo>();
|
|
|
|
|
|
|
|
if (fileInfo.canonicalFilePath().startsWith(":"))
|
|
|
|
options->file = QUrl("qrc" + fileInfo.canonicalFilePath());
|
|
|
|
else
|
|
|
|
options->file = QUrl::fromLocalFile(fileInfo.canonicalFilePath());
|
|
|
|
options->originalQml = originalCheckBox->isChecked();
|
|
|
|
options->maximized = maximizedCheckBox->isChecked();
|
|
|
|
options->fullscreen = fullscreenCheckBox->isChecked();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
static bool checkVersion(const QUrl &url)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
if (!qgetenv("QMLSCENE_IMPORT_NAME").isEmpty()) {
|
2012-01-31 06:52:36 +00:00
|
|
|
qWarning("QMLSCENE_IMPORT_NAME is no longer supported.");
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString fileName = url.toLocalFile();
|
2012-01-31 06:52:36 +00:00
|
|
|
if (fileName.isEmpty()) {
|
|
|
|
qWarning("qmlscene: filename required.");
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QFile f(fileName);
|
|
|
|
if (!f.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
|
qWarning("qmlscene: failed to check version of file '%s', could not open...",
|
|
|
|
qPrintable(fileName));
|
2012-01-31 06:52:36 +00:00
|
|
|
return false;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
QRegExp quick1("^\\s*import +QtQuick +1\\.\\w*");
|
2011-08-01 06:27:01 +00:00
|
|
|
QRegExp qt47("^\\s*import +Qt +4\\.7");
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QTextStream stream(&f);
|
|
|
|
bool codeFound= false;
|
2011-07-06 03:43:47 +00:00
|
|
|
while (!codeFound) {
|
2011-04-27 12:13:26 +00:00
|
|
|
QString line = stream.readLine();
|
2012-01-31 06:52:36 +00:00
|
|
|
if (line.contains("{")) {
|
2011-04-27 12:13:26 +00:00
|
|
|
codeFound = true;
|
2012-01-31 06:52:36 +00:00
|
|
|
} else {
|
|
|
|
QString import;
|
|
|
|
if (quick1.indexIn(line) >= 0) {
|
|
|
|
import = quick1.cap(0).trimmed();
|
|
|
|
} else if (qt47.indexIn(line) >= 0) {
|
|
|
|
import = qt47.cap(0).trimmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!import.isNull()) {
|
|
|
|
qWarning("qmlscene: '%s' is no longer supported.\n"
|
|
|
|
"Use qmlviewer to load file '%s'.",
|
|
|
|
qPrintable(import),
|
|
|
|
qPrintable(fileName));
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
return true;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void displayFileDialog(Options *options)
|
|
|
|
{
|
2011-12-06 07:06:03 +00:00
|
|
|
#ifdef QT_WIDGETS_LIB
|
2011-04-27 12:13:26 +00:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)");
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
QFileInfo fi(fileName);
|
|
|
|
options->file = QUrl::fromLocalFile(fi.canonicalFilePath());
|
|
|
|
}
|
2011-12-06 07:06:03 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(options);
|
|
|
|
qWarning("No filename specified...");
|
|
|
|
#endif
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDir dir(directory+"/dummydata", "*.qml");
|
|
|
|
QStringList list = dir.entryList();
|
|
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
|
|
QString qml = list.at(i);
|
|
|
|
QFile f(dir.filePath(qml));
|
|
|
|
f.open(QIODevice::ReadOnly);
|
|
|
|
QByteArray data = f.readAll();
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent comp(&engine);
|
2011-04-27 12:13:26 +00:00
|
|
|
comp.setData(data, QUrl());
|
|
|
|
QObject *dummyData = comp.create();
|
|
|
|
|
|
|
|
if(comp.isError()) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QList<QQmlError> errors = comp.errors();
|
|
|
|
foreach (const QQmlError &error, errors) {
|
2011-04-27 12:13:26 +00:00
|
|
|
qWarning() << error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dummyData) {
|
|
|
|
qWarning() << "Loaded dummy data:" << dir.filePath(qml);
|
|
|
|
qml.truncate(qml.length()-4);
|
|
|
|
engine.rootContext()->setContextProperty(qml, dummyData);
|
|
|
|
dummyData->setParent(&engine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usage()
|
|
|
|
{
|
|
|
|
qWarning("Usage: qmlscene [options] <filename>");
|
|
|
|
qWarning(" ");
|
|
|
|
qWarning(" options:");
|
|
|
|
qWarning(" --maximized ............................... run maximized");
|
|
|
|
qWarning(" --fullscreen .............................. run fullscreen");
|
|
|
|
qWarning(" --no-multisample .......................... Disable multisampling (anti-aliasing)");
|
|
|
|
qWarning(" --no-version-detection .................... Do not try to detect the version of the .qml file");
|
2012-02-07 12:29:45 +00:00
|
|
|
qWarning(" --slow-animations ......................... Run all animations in slow motion");
|
2012-05-25 13:30:47 +00:00
|
|
|
qWarning(" --resize-to-root .......................... Resize the window to the size of the root item");
|
2012-03-21 02:49:15 +00:00
|
|
|
qWarning(" --quit .................................... Quit immediately after starting");
|
2012-04-10 17:11:30 +00:00
|
|
|
qWarning(" -I <path> ................................. Add <path> to the list of import paths");
|
|
|
|
qWarning(" -B <name> <file> .......................... Add a named bundle");
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
qWarning(" ");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
Options options;
|
|
|
|
|
|
|
|
QStringList imports;
|
2012-04-10 17:11:30 +00:00
|
|
|
QList<QPair<QString, QString> > bundles;
|
2011-04-27 12:13:26 +00:00
|
|
|
for (int i = 1; i < argc; ++i) {
|
2011-10-17 14:02:01 +00:00
|
|
|
if (*argv[i] != '-' && QFileInfo(QFile::decodeName(argv[i])).exists()) {
|
2011-04-27 12:13:26 +00:00
|
|
|
options.file = QUrl::fromLocalFile(argv[i]);
|
2011-10-17 14:02:01 +00:00
|
|
|
} else {
|
|
|
|
const QString lowerArgument = QString::fromLatin1(argv[i]).toLower();
|
2011-12-06 07:06:03 +00:00
|
|
|
if (lowerArgument == QLatin1String("--maximized"))
|
2011-10-17 14:02:01 +00:00
|
|
|
options.maximized = true;
|
|
|
|
else if (lowerArgument == QLatin1String("--fullscreen"))
|
|
|
|
options.fullscreen = true;
|
|
|
|
else if (lowerArgument == QLatin1String("--clip"))
|
|
|
|
options.clip = true;
|
|
|
|
else if (lowerArgument == QLatin1String("--no-version-detection"))
|
|
|
|
options.versionDetection = false;
|
2012-02-07 12:29:45 +00:00
|
|
|
else if (lowerArgument == QLatin1String("--slow-animations"))
|
|
|
|
options.slowAnimations = true;
|
2012-03-21 02:49:15 +00:00
|
|
|
else if (lowerArgument == QLatin1String("--quit"))
|
|
|
|
options.quitImmediately = true;
|
2012-05-25 13:30:47 +00:00
|
|
|
else if (lowerArgument == QLatin1String("--resize-to-root"))
|
|
|
|
options.resizeViewToRootItem = true;
|
2011-10-17 14:02:01 +00:00
|
|
|
else if (lowerArgument == QLatin1String("-i") && i + 1 < argc)
|
|
|
|
imports.append(QString::fromLatin1(argv[++i]));
|
2012-04-10 17:11:30 +00:00
|
|
|
else if (lowerArgument == QLatin1String("-b") && i + 2 < argc) {
|
|
|
|
QString name = QString::fromLatin1(argv[++i]);
|
|
|
|
QString file = QString::fromLatin1(argv[++i]);
|
|
|
|
bundles.append(qMakePair(name, file));
|
|
|
|
} else if (lowerArgument == QLatin1String("--help")
|
2011-10-17 14:02:01 +00:00
|
|
|
|| lowerArgument == QLatin1String("-help")
|
|
|
|
|| lowerArgument == QLatin1String("--h")
|
|
|
|
|| lowerArgument == QLatin1String("-h"))
|
|
|
|
usage();
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 10:06:15 +00:00
|
|
|
#ifdef QT_WIDGETS_LIB
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
#else
|
2011-12-06 07:06:03 +00:00
|
|
|
QGuiApplication app(argc, argv);
|
2011-12-13 10:06:15 +00:00
|
|
|
#endif
|
2011-04-27 12:13:26 +00:00
|
|
|
app.setApplicationName("QtQmlViewer");
|
|
|
|
app.setOrganizationName("Nokia");
|
|
|
|
app.setOrganizationDomain("nokia.com");
|
|
|
|
|
2012-02-07 12:29:45 +00:00
|
|
|
QUnifiedTimer::instance()->setSlowModeEnabled(options.slowAnimations);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
if (options.file.isEmpty())
|
|
|
|
#if defined(QMLSCENE_BUNDLE)
|
|
|
|
displayOptionsDialog(&options);
|
|
|
|
#else
|
|
|
|
displayFileDialog(&options);
|
|
|
|
#endif
|
|
|
|
|
2011-08-04 08:34:08 +00:00
|
|
|
QWindow *window = 0;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine *engine = 0;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
int exitCode = 0;
|
|
|
|
|
|
|
|
if (!options.file.isEmpty()) {
|
2012-01-31 06:52:36 +00:00
|
|
|
if (!options.versionDetection || checkVersion(options.file)) {
|
2012-05-25 13:30:47 +00:00
|
|
|
QQuickView *qxView = new QQuickView();
|
2012-01-31 06:52:36 +00:00
|
|
|
engine = qxView->engine();
|
|
|
|
for (int i = 0; i < imports.size(); ++i)
|
|
|
|
engine->addImportPath(imports.at(i));
|
2012-04-10 17:11:30 +00:00
|
|
|
for (int i = 0; i < bundles.size(); ++i)
|
|
|
|
engine->addNamedBundle(bundles.at(i).first, bundles.at(i).second);
|
2012-01-31 06:52:36 +00:00
|
|
|
window = qxView;
|
|
|
|
if (options.file.isLocalFile()) {
|
|
|
|
QFileInfo fi(options.file.toLocalFile());
|
|
|
|
loadDummyDataFiles(*engine, fi.path());
|
|
|
|
}
|
|
|
|
qxView->setSource(options.file);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
QObject::connect(engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-05-25 13:30:47 +00:00
|
|
|
if (options.resizeViewToRootItem)
|
|
|
|
qxView->setResizeMode(QQuickView::SizeViewToRootObject);
|
|
|
|
else
|
|
|
|
qxView->setResizeMode(QQuickView::SizeRootObjectToView);
|
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
window->setWindowFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
|
|
|
|
if (options.fullscreen)
|
|
|
|
window->showFullScreen();
|
|
|
|
else if (options.maximized)
|
|
|
|
window->showMaximized();
|
|
|
|
else
|
|
|
|
window->show();
|
2011-08-04 08:34:08 +00:00
|
|
|
|
2012-03-21 02:49:15 +00:00
|
|
|
if (options.quitImmediately) {
|
|
|
|
QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
exitCode = app.exec();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
delete window;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
#ifdef QML_RUNTIME_TESTING
|
2012-01-31 06:52:36 +00:00
|
|
|
RenderStatistics::printTotalStats();
|
2011-04-27 12:13:26 +00:00
|
|
|
#endif
|
2012-01-31 06:52:36 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return exitCode;
|
|
|
|
}
|
|
|
|
|