2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:17:46 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-20 05:21:40 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** This file is part of the tools applications of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-20 05:21:40 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, 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
|
|
|
**
|
2012-09-20 05:21:40 +00:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia 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
|
2012-09-20 05:21:40 +00:00
|
|
|
** 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.
|
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
|
|
|
|
|
2012-06-29 00:15:16 +00:00
|
|
|
#include <QtCore/QTranslator>
|
|
|
|
#include <QtCore/QLibraryInfo>
|
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)
|
2012-06-14 00:28:00 +00:00
|
|
|
, transparent(false)
|
2011-04-27 12:13:26 +00:00
|
|
|
, 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)
|
2012-12-10 10:46:56 +00:00
|
|
|
, multisample(false)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl file;
|
|
|
|
bool originalQml;
|
|
|
|
bool originalQmlRaster;
|
|
|
|
bool maximized;
|
|
|
|
bool fullscreen;
|
2012-06-14 00:28:00 +00:00
|
|
|
bool transparent;
|
2011-04-27 12:13:26 +00:00
|
|
|
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;
|
2012-12-10 10:46:56 +00:00
|
|
|
bool multisample;
|
2012-06-29 00:15:16 +00:00
|
|
|
QString translationFile;
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(QMLSCENE_BUNDLE)
|
|
|
|
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
|
|
|
{
|
2012-06-18 15:33:58 +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;
|
2012-06-18 15:33:58 +00:00
|
|
|
if (quick1.indexIn(line) >= 0)
|
2012-01-31 06:52:36 +00:00
|
|
|
import = quick1.cap(0).trimmed();
|
2012-06-18 15:33:58 +00:00
|
|
|
else if (qt47.indexIn(line) >= 0)
|
2012-01-31 06:52:36 +00:00
|
|
|
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)
|
|
|
|
{
|
2012-05-28 00:34:32 +00:00
|
|
|
#if defined(QT_WIDGETS_LIB) && !defined(QT_NO_FILEDIALOG)
|
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-11-22 19:21:49 +00:00
|
|
|
#ifndef QT_NO_TRANSLATION
|
2012-06-29 00:15:16 +00:00
|
|
|
static void loadTranslationFile(QTranslator &translator, const QString& directory)
|
|
|
|
{
|
|
|
|
translator.load(QLatin1String("qml_" )+QLocale::system().name(), directory + QLatin1String("/i18n"));
|
2012-07-30 00:09:13 +00:00
|
|
|
QCoreApplication::installTranslator(&translator);
|
2012-06-29 00:15:16 +00:00
|
|
|
}
|
2012-11-22 19:21:49 +00:00
|
|
|
#endif
|
2012-06-29 00:15:16 +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();
|
2012-06-18 15:33:58 +00:00
|
|
|
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(" ");
|
2013-01-03 08:56:23 +00:00
|
|
|
qWarning(" Options:");
|
|
|
|
qWarning(" --maximized ............................... Run maximized");
|
|
|
|
qWarning(" --fullscreen .............................. Run fullscreen");
|
2012-06-14 00:28:00 +00:00
|
|
|
qWarning(" --transparent ............................. Make the window transparent");
|
2012-12-10 10:46:56 +00:00
|
|
|
qWarning(" --multisample ............................. Enable multisampling (OpenGL anti-aliasing)");
|
2011-04-27 12:13:26 +00:00
|
|
|
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");
|
2013-01-03 08:56:23 +00:00
|
|
|
qWarning(" -translation <translationfile> ............ Set the language to run in");
|
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;
|
2012-06-14 00:28:00 +00:00
|
|
|
else if (lowerArgument == QLatin1String("--transparent"))
|
|
|
|
options.transparent = true;
|
2011-10-17 14:02:01 +00:00
|
|
|
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-06-29 00:15:16 +00:00
|
|
|
else if (lowerArgument == QLatin1String("-translation"))
|
|
|
|
options.translationFile = QLatin1String(argv[++i]);
|
2012-05-25 13:30:47 +00:00
|
|
|
else if (lowerArgument == QLatin1String("--resize-to-root"))
|
|
|
|
options.resizeViewToRootItem = true;
|
2012-12-10 10:46:56 +00:00
|
|
|
else if (lowerArgument == QLatin1String("--multisample"))
|
|
|
|
options.multisample = 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");
|
2012-10-25 12:03:56 +00:00
|
|
|
app.setOrganizationName("Qt Project");
|
|
|
|
app.setOrganizationDomain("qt-project.org");
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-11-22 19:21:49 +00:00
|
|
|
#ifndef QT_NO_TRANSLATION
|
2012-06-29 00:15:16 +00:00
|
|
|
QTranslator translator;
|
|
|
|
QTranslator qtTranslator;
|
|
|
|
QString sysLocale = QLocale::system().name();
|
|
|
|
if (translator.load(QLatin1String("qmlscene_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
|
|
|
|
app.installTranslator(&translator);
|
|
|
|
if (qtTranslator.load(QLatin1String("qt_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
|
|
|
|
app.installTranslator(&qtTranslator);
|
|
|
|
} else {
|
|
|
|
app.removeTranslator(&translator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QTranslator qmlTranslator;
|
|
|
|
if (!options.translationFile.isEmpty()) {
|
|
|
|
if (qmlTranslator.load(options.translationFile)) {
|
|
|
|
app.installTranslator(&qmlTranslator);
|
|
|
|
} else {
|
|
|
|
qWarning() << "Could not load the translation file" << options.translationFile;
|
|
|
|
}
|
|
|
|
}
|
2012-11-22 19:21:49 +00:00
|
|
|
#endif
|
2012-06-29 00:15:16 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
int exitCode = 0;
|
|
|
|
|
|
|
|
if (!options.file.isEmpty()) {
|
2012-01-31 06:52:36 +00:00
|
|
|
if (!options.versionDetection || checkVersion(options.file)) {
|
2012-11-22 19:21:49 +00:00
|
|
|
#ifndef QT_NO_TRANSLATION
|
2012-06-29 00:15:16 +00:00
|
|
|
QTranslator translator;
|
2012-11-22 19:21:49 +00:00
|
|
|
#endif
|
2012-11-05 10:04:21 +00:00
|
|
|
|
|
|
|
// TODO: as soon as the engine construction completes, the debug service is
|
|
|
|
// listening for connections. But actually we aren't ready to debug anything.
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent *component = new QQmlComponent(&engine);
|
2012-01-31 06:52:36 +00:00
|
|
|
for (int i = 0; i < imports.size(); ++i)
|
2012-11-05 10:04:21 +00:00
|
|
|
engine.addImportPath(imports.at(i));
|
2012-04-10 17:11:30 +00:00
|
|
|
for (int i = 0; i < bundles.size(); ++i)
|
2012-11-05 10:04:21 +00:00
|
|
|
engine.addNamedBundle(bundles.at(i).first, bundles.at(i).second);
|
2012-01-31 06:52:36 +00:00
|
|
|
if (options.file.isLocalFile()) {
|
|
|
|
QFileInfo fi(options.file.toLocalFile());
|
2012-11-22 19:21:49 +00:00
|
|
|
#ifndef QT_NO_TRANSLATION
|
2012-06-29 00:15:16 +00:00
|
|
|
loadTranslationFile(translator, fi.path());
|
2012-11-22 19:21:49 +00:00
|
|
|
#endif
|
2012-11-05 10:04:21 +00:00
|
|
|
loadDummyDataFiles(engine, fi.path());
|
2012-01-31 06:52:36 +00:00
|
|
|
}
|
2012-11-05 10:04:21 +00:00
|
|
|
QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
|
|
|
|
component->loadUrl(options.file);
|
|
|
|
if ( !component->isReady() ) {
|
2012-12-06 22:17:47 +00:00
|
|
|
qWarning("%s", qPrintable(component->errorString()));
|
2012-11-05 10:04:21 +00:00
|
|
|
return -1;
|
2012-06-14 00:28:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-05 10:04:21 +00:00
|
|
|
QObject *topLevel = component->create();
|
|
|
|
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
|
|
|
|
QQuickView* qxView = 0;
|
2013-05-31 13:33:45 +00:00
|
|
|
if (window) {
|
|
|
|
engine.setIncubationController(window->incubationController());
|
|
|
|
} else {
|
2012-11-05 10:04:21 +00:00
|
|
|
QQuickItem *contentItem = qobject_cast<QQuickItem *>(topLevel);
|
|
|
|
if (contentItem) {
|
|
|
|
qxView = new QQuickView(&engine, NULL);
|
|
|
|
window = qxView;
|
2012-10-22 11:44:21 +00:00
|
|
|
// Set window default properties; the qml can still override them
|
|
|
|
QString oname = contentItem->objectName();
|
|
|
|
window->setTitle(oname.isEmpty() ? QString::fromLatin1("qmlscene") : QString::fromLatin1("qmlscene: ") + oname);
|
2012-11-05 10:04:21 +00:00
|
|
|
if (options.resizeViewToRootItem)
|
|
|
|
qxView->setResizeMode(QQuickView::SizeViewToRootObject);
|
|
|
|
else
|
|
|
|
qxView->setResizeMode(QQuickView::SizeRootObjectToView);
|
|
|
|
qxView->setContent(options.file, component, contentItem);
|
|
|
|
}
|
|
|
|
}
|
2012-06-18 15:31:06 +00:00
|
|
|
|
2012-11-05 10:04:21 +00:00
|
|
|
if (window) {
|
2013-02-01 11:38:26 +00:00
|
|
|
QSurfaceFormat surfaceFormat = window->requestedFormat();
|
2012-12-10 10:46:56 +00:00
|
|
|
if (options.multisample)
|
|
|
|
surfaceFormat.setSamples(16);
|
2012-11-05 10:04:21 +00:00
|
|
|
if (options.transparent) {
|
|
|
|
surfaceFormat.setAlphaBufferSize(8);
|
|
|
|
window->setClearBeforeRendering(true);
|
|
|
|
window->setColor(QColor(Qt::transparent));
|
2012-11-30 10:44:52 +00:00
|
|
|
window->setFlags(Qt::FramelessWindowHint);
|
2012-11-05 10:04:21 +00:00
|
|
|
}
|
2012-12-10 10:46:56 +00:00
|
|
|
window->setFormat(surfaceFormat);
|
2012-11-05 10:04:21 +00:00
|
|
|
|
2013-05-22 15:18:46 +00:00
|
|
|
if (window->flags() == Qt::Window) // Fix window flags unless set by QML.
|
|
|
|
window->setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint);
|
|
|
|
|
2012-11-05 10:04:21 +00:00
|
|
|
if (options.fullscreen)
|
|
|
|
window->showFullScreen();
|
|
|
|
else if (options.maximized)
|
|
|
|
window->showMaximized();
|
2013-05-22 13:17:56 +00:00
|
|
|
else if (!window->isVisible())
|
2012-11-05 10:04:21 +00:00
|
|
|
window->show();
|
|
|
|
}
|
2011-08-04 08:34:08 +00:00
|
|
|
|
2012-06-18 15:33:58 +00:00
|
|
|
if (options.quitImmediately)
|
2012-03-21 02:49:15 +00:00
|
|
|
QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
|
|
|
|
|
2012-11-05 10:04:21 +00:00
|
|
|
// Now would be a good time to inform the debug service to start listening.
|
|
|
|
|
2012-01-31 06:52:36 +00:00
|
|
|
exitCode = app.exec();
|
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-11-05 10:04:21 +00:00
|
|
|
// Ready to exit. If we created qxView, it owns the component;
|
|
|
|
// otherwise, the ownership is still right here. Nobody deletes the engine
|
|
|
|
// (which is odd since the container constructor takes the engine pointer),
|
|
|
|
// but it's stack-allocated anyway.
|
|
|
|
if (qxView)
|
|
|
|
delete qxView;
|
|
|
|
else
|
|
|
|
delete component;
|
2012-01-31 06:52:36 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return exitCode;
|
|
|
|
}
|