Fix compilation for QT_NO_FILEDIALOG
[profile/ivi/qtdeclarative.git] / tools / qmlscene / main.cpp
index 115dace..4e6dd92 100644 (file)
 
 #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>
 
+#include <private/qabstractanimation_p.h>
+
 #ifdef QT_WIDGETS_LIB
 #include <QtWidgets/QApplication>
 #include <QtWidgets/QFileDialog>
@@ -135,15 +137,6 @@ void RenderStatistics::printTotalStats()
 }
 #endif
 
-class MyQQuickView : public QQuickView
-{
-public:
-    MyQQuickView() : QQuickView()
-    {
-        setResizeMode(QQuickView::SizeRootObjectToView);
-    }
-};
-
 struct Options
 {
     Options()
@@ -153,6 +146,9 @@ struct Options
         , fullscreen(false)
         , clip(false)
         , versionDetection(true)
+        , slowAnimations(false)
+        , quitImmediately(false)
+        , resizeViewToRootItem(false)
     {
     }
 
@@ -164,6 +160,9 @@ struct Options
     bool scenegraphOnGraphicsview;
     bool clip;
     bool versionDetection;
+    bool slowAnimations;
+    bool quitImmediately;
+    bool resizeViewToRootItem;
 };
 
 #if defined(QMLSCENE_BUNDLE)
@@ -292,7 +291,7 @@ static bool checkVersion(const QUrl &url)
 
 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);
@@ -304,7 +303,7 @@ static void displayFileDialog(Options *options)
 #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();
@@ -313,13 +312,13 @@ static void loadDummyDataFiles(QDeclarativeEngine &engine, const QString& direct
         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;
             }
         }
@@ -342,6 +341,11 @@ static void usage()
     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");
+    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);
@@ -352,6 +356,7 @@ int main(int argc, char ** argv)
     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]);
@@ -365,9 +370,19 @@ int main(int argc, char ** argv)
                 options.clip = true;
             else if (lowerArgument == QLatin1String("--no-version-detection"))
                 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"))
@@ -384,6 +399,8 @@ int main(int argc, char ** argv)
     app.setOrganizationName("Nokia");
     app.setOrganizationDomain("nokia.com");
 
+    QUnifiedTimer::instance()->setSlowModeEnabled(options.slowAnimations);
+
     if (options.file.isEmpty())
 #if defined(QMLSCENE_BUNDLE)
         displayOptionsDialog(&options);
@@ -392,16 +409,18 @@ int main(int argc, char ** argv)
 #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());
@@ -411,6 +430,11 @@ int main(int argc, char ** argv)
 
             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();
@@ -419,6 +443,10 @@ int main(int argc, char ** argv)
             else
                 window->show();
 
+            if (options.quitImmediately) {
+                QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
+            }
+
             exitCode = app.exec();
 
             delete window;