diff options
Diffstat (limited to 'tools/qmlscene/main.cpp')
-rw-r--r-- | tools/qmlscene/main.cpp | 116 |
1 files changed, 87 insertions, 29 deletions
diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index 7741c4c45b..fc8b9c5292 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -33,7 +33,7 @@ #include <QtCore/qpointer.h> #include <QtCore/qscopedpointer.h> #include <QtCore/qtextstream.h> -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> #include <QtGui/QGuiApplication> #include <QtGui/QOpenGLFunctions> @@ -133,6 +133,17 @@ void RenderStatistics::printTotalStats() struct Options { + enum QmlApplicationType + { + QmlApplicationTypeGui, + QmlApplicationTypeWidget, +#ifdef QT_WIDGETS_LIB + DefaultQmlApplicationType = QmlApplicationTypeWidget +#else + DefaultQmlApplicationType = QmlApplicationTypeGui +#endif + }; + Options() : originalQml(false) , originalQmlRaster(false) @@ -145,7 +156,10 @@ struct Options , quitImmediately(false) , resizeViewToRootItem(false) , multisample(false) + , coreProfile(false) , verbose(false) + , applicationType(DefaultQmlApplicationType) + , textRenderType(QQuickWindow::textRenderType()) { // QtWebEngine needs a shared context in order for the GPU thread to // upload textures. @@ -164,9 +178,12 @@ struct Options bool quitImmediately; bool resizeViewToRootItem; bool multisample; + bool coreProfile; bool verbose; QVector<Qt::ApplicationAttribute> applicationAttributes; QString translationFile; + QmlApplicationType applicationType; + QQuickWindow::TextRenderType textRenderType; }; #if defined(QMLSCENE_BUNDLE) @@ -259,8 +276,8 @@ static bool checkVersion(const QUrl &url) return false; } - QRegExp quick1("^\\s*import +QtQuick +1\\.\\w*"); - QRegExp qt47("^\\s*import +Qt +4\\.7"); + QRegularExpression quick1("^\\s*import +QtQuick +1\\.\\w*"); + QRegularExpression qt47("^\\s*import +Qt +4\\.7"); QTextStream stream(&f); bool codeFound= false; @@ -270,10 +287,11 @@ static bool checkVersion(const QUrl &url) codeFound = true; } else { QString import; - if (quick1.indexIn(line) >= 0) - import = quick1.cap(0).trimmed(); - else if (qt47.indexIn(line) >= 0) - import = qt47.cap(0).trimmed(); + QRegularExpressionMatch match = quick1.match(line); + if (match.hasMatch()) + import = match.captured(0).trimmed(); + else if ((match = qt47.match(line)).hasMatch()) + import = match.captured(0).trimmed(); if (!import.isNull()) { fprintf(stderr, "qmlscene: '%s' is no longer supported.\n" @@ -291,15 +309,17 @@ static bool checkVersion(const QUrl &url) static void displayFileDialog(Options *options) { #if defined(QT_WIDGETS_LIB) && QT_CONFIG(filedialog) - QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)"); - if (!fileName.isEmpty()) { - QFileInfo fi(fileName); - options->url = QUrl::fromLocalFile(fi.canonicalFilePath()); + if (options->applicationType == Options::QmlApplicationTypeWidget) { + QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)"); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + options->url = QUrl::fromLocalFile(fi.canonicalFilePath()); + } + return; } -#else +#endif // QT_WIDGETS_LIB && QT_CONFIG(filedialog) Q_UNUSED(options); puts("No filename specified..."); -#endif } #if QT_CONFIG(translation) @@ -343,6 +363,7 @@ static void usage() puts(" --fullscreen ..................... Run fullscreen"); puts(" --transparent .................... Make the window transparent"); puts(" --multisample .................... Enable multisampling (OpenGL anti-aliasing)"); + puts(" --core-profile ................... Request a core profile OpenGL context"); puts(" --no-version-detection ........... Do not try to detect the version of the .qml file"); puts(" --slow-animations ................ Run all animations in slow motion"); puts(" --resize-to-root ................. Resize the window to the size of the root item"); @@ -355,6 +376,10 @@ static void usage() puts(" --scaling..........................Enable High DPI scaling (AA_EnableHighDpiScaling)"); puts(" --no-scaling.......................Disable High DPI scaling (AA_DisableHighDpiScaling)"); puts(" --verbose..........................Print version and graphical diagnostics for the run-time"); +#ifdef QT_WIDGETS_LIB + puts(" --apptype [gui|widgets] ...........Select which application class to use. Default is widgets."); +#endif + puts(" --textrendertype [qt|native].......Select the default render type for text-like elements."); puts(" -I <path> ........................ Add <path> to the list of import paths"); puts(" -P <path> ........................ Add <path> to the list of plugin paths"); puts(" -translation <translationfile> ... Set the language to run in"); @@ -434,6 +459,19 @@ static QUrl parseUrlArgument(const QString &arg) return url; } +static QQuickWindow::TextRenderType parseTextRenderType(const QString &renderType) +{ + if (renderType == QLatin1String("qt")) + return QQuickWindow::QtTextRendering; + else if (renderType == QLatin1String("native")) + return QQuickWindow::NativeTextRendering; + + usage(); + + Q_UNREACHABLE(); + return QQuickWindow::QtTextRendering; +} + int main(int argc, char ** argv) { Options options; @@ -444,30 +482,38 @@ int main(int argc, char ** argv) // Parse arguments for application attributes to be applied before Q[Gui]Application creation. for (int i = 1; i < argc; ++i) { const char *arg = argv[i]; - if (!qstrcmp(arg, "--disable-context-sharing")) + if (!qstrcmp(arg, "--disable-context-sharing")) { options.applicationAttributes.removeAll(Qt::AA_ShareOpenGLContexts); - else if (!qstrcmp(arg, "--gles")) + } else if (!qstrcmp(arg, "--gles")) { options.applicationAttributes.append(Qt::AA_UseOpenGLES); - else if (!qstrcmp(arg, "--software")) + } else if (!qstrcmp(arg, "--software")) { options.applicationAttributes.append(Qt::AA_UseSoftwareOpenGL); - else if (!qstrcmp(arg, "--desktop")) + } else if (!qstrcmp(arg, "--desktop")) { options.applicationAttributes.append(Qt::AA_UseDesktopOpenGL); - else if (!qstrcmp(arg, "--scaling")) + } else if (!qstrcmp(arg, "--scaling")) { options.applicationAttributes.append(Qt::AA_EnableHighDpiScaling); - else if (!qstrcmp(arg, "--no-scaling")) + } else if (!qstrcmp(arg, "--no-scaling")) { options.applicationAttributes.append(Qt::AA_DisableHighDpiScaling); + } else if (!qstrcmp(arg, "--apptype")) { + if (++i >= argc) + usage(); + if (!qstrcmp(argv[i], "gui")) + options.applicationType = Options::QmlApplicationTypeGui; + } } for (Qt::ApplicationAttribute a : qAsConst(options.applicationAttributes)) QCoreApplication::setAttribute(a); + QScopedPointer<QGuiApplication> app; #ifdef QT_WIDGETS_LIB - QApplication app(argc, argv); -#else - QGuiApplication app(argc, argv); + if (options.applicationType == Options::QmlApplicationTypeWidget) + app.reset(new QApplication(argc, argv)); #endif - app.setApplicationName("QtQmlViewer"); - app.setOrganizationName("QtProject"); - app.setOrganizationDomain("qt-project.org"); + if (app.isNull()) + app.reset(new QGuiApplication(argc, argv)); + QCoreApplication::setApplicationName(QStringLiteral("QtQmlViewer")); + QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); + QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); const QStringList arguments = QCoreApplication::arguments(); @@ -496,12 +542,18 @@ int main(int argc, char ** argv) options.resizeViewToRootItem = true; else if (lowerArgument == QLatin1String("--multisample")) options.multisample = true; + else if (lowerArgument == QLatin1String("--core-profile")) + options.coreProfile = true; else if (lowerArgument == QLatin1String("--verbose")) options.verbose = true; else if (lowerArgument == QLatin1String("-i") && i + 1 < size) imports.append(arguments.at(++i)); else if (lowerArgument == QLatin1String("-p") && i + 1 < size) pluginPaths.append(arguments.at(++i)); + else if (lowerArgument == QLatin1String("--apptype")) + ++i; // Consume previously parsed argument + else if (lowerArgument == QLatin1String("--textrendertype") && i + 1 < size) + options.textRenderType = parseTextRenderType(arguments.at(++i)); else if (lowerArgument == QLatin1String("--help") || lowerArgument == QLatin1String("-help") || lowerArgument == QLatin1String("--h") @@ -515,14 +567,14 @@ int main(int argc, char ** argv) QTranslator qtTranslator; QString sysLocale = QLocale::system().name(); if (qtTranslator.load(QLatin1String("qt_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - app.installTranslator(&qtTranslator); + app->installTranslator(&qtTranslator); if (translator.load(QLatin1String("qmlscene_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - app.installTranslator(&translator); + app->installTranslator(&translator); QTranslator qmlTranslator; if (!options.translationFile.isEmpty()) { if (qmlTranslator.load(options.translationFile)) { - app.installTranslator(&qmlTranslator); + app->installTranslator(&qmlTranslator); } else { fprintf(stderr, "Could not load the translation file \"%s\"\n", qPrintable(options.translationFile)); @@ -530,6 +582,8 @@ int main(int argc, char ** argv) } #endif + QQuickWindow::setTextRenderType(options.textRenderType); + QUnifiedTimer::instance()->setSlowModeEnabled(options.slowAnimations); if (options.url.isEmpty()) @@ -612,6 +666,10 @@ int main(int argc, char ** argv) window->setColor(QColor(Qt::transparent)); window->setFlags(Qt::FramelessWindowHint); } + if (options.coreProfile) { + surfaceFormat.setVersion(4, 1); + surfaceFormat.setProfile(QSurfaceFormat::CoreProfile); + } window->setFormat(surfaceFormat); if (window->flags() == Qt::Window) // Fix window flags unless set by QML. @@ -630,7 +688,7 @@ int main(int argc, char ** argv) // Now would be a good time to inform the debug service to start listening. - exitCode = app.exec(); + exitCode = app->exec(); #ifdef QML_RUNTIME_TESTING RenderStatistics::printTotalStats(); |