#include <QtGui/QGuiApplication>
-#include <QtDeclarative/qdeclarative.h>
-#include <QtDeclarative/qdeclarativeengine.h>
-#include <QtDeclarative/qdeclarativecomponent.h>
-#include <QtDeclarative/qdeclarativecontext.h>
+#include <QtQml/qqml.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
}
#endif
-class MyQQuickView : public QQuickView
-{
-public:
- MyQQuickView() : QQuickView()
- {
- setResizeMode(QQuickView::SizeRootObjectToView);
- }
-};
-
struct Options
{
Options()
, clip(false)
, versionDetection(true)
, slowAnimations(false)
+ , quitImmediately(false)
+ , resizeViewToRootItem(false)
{
}
bool clip;
bool versionDetection;
bool slowAnimations;
+ bool quitImmediately;
+ bool resizeViewToRootItem;
};
#if defined(QMLSCENE_BUNDLE)
static void displayFileDialog(Options *options)
{
-#ifdef QT_WIDGETS_LIB
+#if defined(QT_WIDGETS_LIB) && !defined(QT_NO_FILEDIALOG)
QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)");
if (!fileName.isEmpty()) {
QFileInfo fi(fileName);
#endif
}
-static void loadDummyDataFiles(QDeclarativeEngine &engine, const QString& directory)
+static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory)
{
QDir dir(directory+"/dummydata", "*.qml");
QStringList list = dir.entryList();
QFile f(dir.filePath(qml));
f.open(QIODevice::ReadOnly);
QByteArray data = f.readAll();
- QDeclarativeComponent comp(&engine);
+ QQmlComponent comp(&engine);
comp.setData(data, QUrl());
QObject *dummyData = comp.create();
if(comp.isError()) {
- QList<QDeclarativeError> errors = comp.errors();
- foreach (const QDeclarativeError &error, errors) {
+ QList<QQmlError> errors = comp.errors();
+ foreach (const QQmlError &error, errors) {
qWarning() << error;
}
}
qWarning(" --no-multisample .......................... Disable multisampling (anti-aliasing)");
qWarning(" --no-version-detection .................... Do not try to detect the version of the .qml file");
qWarning(" --slow-animations ......................... Run all animations in slow motion");
+ qWarning(" --resize-to-root .......................... Resize the window to the size of the root item");
+ qWarning(" --quit .................................... Quit immediately after starting");
+ qWarning(" -I <path> ................................. Add <path> to the list of import paths");
+ qWarning(" -B <name> <file> .......................... Add a named bundle");
qWarning(" ");
exit(1);
Options options;
QStringList imports;
+ QList<QPair<QString, QString> > bundles;
for (int i = 1; i < argc; ++i) {
if (*argv[i] != '-' && QFileInfo(QFile::decodeName(argv[i])).exists()) {
options.file = QUrl::fromLocalFile(argv[i]);
options.versionDetection = false;
else if (lowerArgument == QLatin1String("--slow-animations"))
options.slowAnimations = true;
+ else if (lowerArgument == QLatin1String("--quit"))
+ options.quitImmediately = true;
+ else if (lowerArgument == QLatin1String("--resize-to-root"))
+ options.resizeViewToRootItem = true;
else if (lowerArgument == QLatin1String("-i") && i + 1 < argc)
imports.append(QString::fromLatin1(argv[++i]));
- else if (lowerArgument == QLatin1String("--help")
+ 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")
|| lowerArgument == QLatin1String("-help")
|| lowerArgument == QLatin1String("--h")
|| lowerArgument == QLatin1String("-h"))
#endif
QWindow *window = 0;
- QDeclarativeEngine *engine = 0;
+ QQmlEngine *engine = 0;
int exitCode = 0;
if (!options.file.isEmpty()) {
if (!options.versionDetection || checkVersion(options.file)) {
- QQuickView *qxView = new MyQQuickView();
+ QQuickView *qxView = new QQuickView();
engine = qxView->engine();
for (int i = 0; i < imports.size(); ++i)
engine->addImportPath(imports.at(i));
+ for (int i = 0; i < bundles.size(); ++i)
+ engine->addNamedBundle(bundles.at(i).first, bundles.at(i).second);
window = qxView;
if (options.file.isLocalFile()) {
QFileInfo fi(options.file.toLocalFile());
QObject::connect(engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
+ if (options.resizeViewToRootItem)
+ qxView->setResizeMode(QQuickView::SizeViewToRootObject);
+ else
+ qxView->setResizeMode(QQuickView::SizeRootObjectToView);
+
window->setWindowFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
if (options.fullscreen)
window->showFullScreen();
else
window->show();
+ if (options.quitImmediately) {
+ QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
+ }
+
exitCode = app.exec();
delete window;