From a129444bb0156c936900dbd2f12bd9f427ff366c Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 14:13:26 +0200 Subject: Initial import from qtquick2. Branched from the monolithic repo, Qt qtquick2 branch, at commit a4a585d2ee907746682846ae6e8a48e19deef469 --- tools/distfieldgen/distfieldgen.pro | 12 + tools/distfieldgen/main.cpp | 262 ++++++++++++++ tools/qmlplugindump/Info.plist | 16 + tools/qmlplugindump/main.cpp | 597 ++++++++++++++++++++++++++++++++ tools/qmlplugindump/qmlplugindump.pro | 20 ++ tools/qmlplugindump/qmlstreamwriter.cpp | 183 ++++++++++ tools/qmlplugindump/qmlstreamwriter.h | 79 +++++ tools/qmlscene/main.cpp | 574 ++++++++++++++++++++++++++++++ tools/qmlscene/qmlscene.pro | 20 ++ tools/qmlviewer/main.cpp | 7 +- tools/qmlviewer/qmlruntime.cpp | 1 + tools/tools.pro | 2 +- 12 files changed, 1769 insertions(+), 4 deletions(-) create mode 100644 tools/distfieldgen/distfieldgen.pro create mode 100644 tools/distfieldgen/main.cpp create mode 100644 tools/qmlplugindump/Info.plist create mode 100644 tools/qmlplugindump/main.cpp create mode 100644 tools/qmlplugindump/qmlplugindump.pro create mode 100644 tools/qmlplugindump/qmlstreamwriter.cpp create mode 100644 tools/qmlplugindump/qmlstreamwriter.h create mode 100644 tools/qmlscene/main.cpp create mode 100644 tools/qmlscene/qmlscene.pro (limited to 'tools') diff --git a/tools/distfieldgen/distfieldgen.pro b/tools/distfieldgen/distfieldgen.pro new file mode 100644 index 0000000000..4c2d63603b --- /dev/null +++ b/tools/distfieldgen/distfieldgen.pro @@ -0,0 +1,12 @@ +TARGET = distfieldgen +TEMPLATE = app + +QT += declarative opengl + +CONFIG += console +CONFIG -= app_bundle +DESTDIR = ../../bin + +INCLUDEPATH += $$PWD/../../src/3rdparty/harfbuzz/src + +SOURCES += main.cpp diff --git a/tools/distfieldgen/main.cpp b/tools/distfieldgen/main.cpp new file mode 100644 index 0000000000..3c944b3d4c --- /dev/null +++ b/tools/distfieldgen/main.cpp @@ -0,0 +1,262 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt scene graph research project. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +static void usage() +{ + qWarning("Usage: distfieldgen [options] "); + qWarning(" "); + qWarning("Distfieldgen generates distance-field renderings of the provided font file,"); + qWarning("one for each font family/style it contains."); + qWarning("Unless the QT_QML_DISTFIELDDIR environment variable is set, the renderings are"); + qWarning("saved in the fonts/distancefields directory where the Qt libraries are located."); + qWarning("You can also override the output directory with the -d option."); + qWarning(" "); + qWarning(" options:"); + qWarning(" -d ................................ output directory"); + qWarning(" --no-multithread.............................. don't use multiple threads to render distance-fields"); + qWarning(" --force-all-styles............................ force rendering of styles Normal, Bold, Italic and Bold Italic"); + qWarning(" -styles \"style1,style2,..\".................... force rendering of specified styles"); + + qWarning(" "); + exit(1); +} + +void printProgress(int p) +{ + printf("\r ["); + for (int i = 0; i < 50; ++i) + printf(i < p / 2 ? "=" : " "); + printf("]"); + printf(" %d%%", p); + fflush(stdout); +} + +class DistFieldGenTask : public QRunnable +{ +public: + DistFieldGenTask(QSGDistanceFieldGlyphCache *atlas, int c, int nbGlyph, QMap *outList) + : QRunnable() + , m_atlas(atlas) + , m_char(c) + , m_nbGlyph(nbGlyph) + , m_outList(outList) + { } + + void run() + { + QImage df = m_atlas->renderDistanceFieldGlyph(m_char); + QMutexLocker lock(&m_mutex); + m_outList->insert(m_char, df); + printProgress(float(m_outList->count()) / m_nbGlyph * 100); + } + + static QMutex m_mutex; + QSGDistanceFieldGlyphCache *m_atlas; + int m_char; + int m_nbGlyph; + QMap *m_outList; +}; + +QMutex DistFieldGenTask::m_mutex; + +static void generateDistanceFieldForFont(const QFont &font, const QString &destinationDir, bool multithread) +{ + QSGDistanceFieldGlyphCache *atlas = QSGDistanceFieldGlyphCache::get(QGLContext::currentContext(), font); + QFontDatabase db; + QString fontString = font.family() + QLatin1String(" ") + db.styleString(font); + qWarning("> Generating distance-field for font '%s' (%d glyphs)", fontString.toLatin1().constData(), atlas->glyphCount()); + + QMap distfields; + for (int i = 0; i < atlas->glyphCount(); ++i) { + if (multithread) { + DistFieldGenTask *task = new DistFieldGenTask(atlas, i, atlas->glyphCount(), &distfields); + QThreadPool::globalInstance()->start(task); + } else { + QImage df = atlas->renderDistanceFieldGlyph(i); + distfields.insert(i, df); + printProgress(float(distfields.count()) / atlas->glyphCount() * 100); + } + } + + if (multithread) + QThreadPool::globalInstance()->waitForDone(); + + // Combine dist fields in one image + int size = qCeil(qSqrt(qreal(atlas->glyphCount()))) * 64; + QImage output(size, size, QImage::Format_ARGB32_Premultiplied); + output.fill(Qt::transparent); + QPainter p(&output); + int x, y = 0; + for (QMap::const_iterator i = distfields.constBegin(); i != distfields.constEnd(); ++i) { + p.drawImage(x, y, i.value()); + x += 64; + if (x >= size) { + x = 0; + y += 64; + } + } + p.end(); + printProgress(100); + printf("\n"); + + // Save output + QFileInfo dfi(destinationDir); + if (!dfi.isDir()) { + qWarning("Error: '%s' is not a directory.", destinationDir.toLatin1().constData()); + qWarning(" "); + exit(1); + } + + QString filename = font.family(); + filename.remove(QLatin1String(" ")); + QString italic = font.italic() ? QLatin1String("i") : QLatin1String(""); + QString bold = font.weight() > QFont::Normal ? QLatin1String("b") : QLatin1String(""); + filename = filename + bold + italic; + QString out = QString(QLatin1String("%1/%2.png")).arg(destinationDir).arg(filename); + output.save(out); + qWarning(" Distance-field saved to '%s'\n", out.toLatin1().constData()); +} + +class MyWidget : public QGLWidget +{ + Q_OBJECT +public: + MyWidget() + : QGLWidget() + { } + + ~MyWidget() { } + + void showEvent(QShowEvent *e) + { + QStringList args = QApplication::arguments(); + + bool noMultithread = args.contains(QLatin1String("--no-multithread")); + bool forceAllStyles = args.contains(QLatin1String("--force-all-styles")); + + QString fontFile; + QString destDir; + for (int i = 0; i < args.count(); ++i) { + QString a = args.at(i); + if (!a.startsWith('-') && QFileInfo(a).exists()) + fontFile = a; + if (a == QLatin1String("-d")) + destDir = args.at(++i); + } + if (destDir.isEmpty()) { + destDir = QFileInfo(fontFile).canonicalPath(); + } + + QStringList customStyles; + if (args.contains(QLatin1String("-styles"))) { + int index = args.indexOf(QLatin1String("-styles")); + QString styles = args.at(index + 1); + customStyles = styles.split(QLatin1String(",")); + } + + // Load the font + int fontID = QFontDatabase::addApplicationFont(fontFile); + if (fontID == -1) { + qWarning("Error: Invalid font file."); + qWarning(" "); + exit(1); + } + + QStringList allStyles = QStringList() << QLatin1String("Normal") + << QLatin1String("Bold") + << QLatin1String("Italic") + << QLatin1String("Bold Italic"); + + // Generate distance-fields for all families and all styles provided by the font file + QFontDatabase fontDatabase; + QStringList families = QFontDatabase::applicationFontFamilies(fontID); + int famCount = families.count(); + for (int i = 0; i < famCount; ++i) { + QStringList styles; + if (forceAllStyles) + styles = allStyles; + else if (customStyles.count() > 0) + styles = customStyles; + else + styles = fontDatabase.styles(families.at(i)); + + int styleCount = styles.count(); + for (int j = 0; j < styleCount; ++j) { + QFont font; + if (forceAllStyles || customStyles.count() > 0) { + int weight = styles.at(j).contains(QLatin1String("Bold")) ? QFont::Bold : QFont::Normal; + font = QFont(families.at(i), 10, weight, styles.at(j).contains(QLatin1String("Italic"))); + } else { + font = fontDatabase.font(families.at(i), styles.at(j), 10); // point size is ignored + } + generateDistanceFieldForFont(font, destDir, !noMultithread); + } + } + + exit(0); + } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QStringList args = QApplication::arguments(); + + if (argc < 2 + || args.contains(QLatin1String("--help")) + || args.contains(QLatin1String("-help")) + || args.contains(QLatin1String("--h")) + || args.contains(QLatin1String("-h"))) + usage(); + + + MyWidget w; + w.show(); + + return app.exec(); +} + +#include "main.moc" diff --git a/tools/qmlplugindump/Info.plist b/tools/qmlplugindump/Info.plist new file mode 100644 index 0000000000..f35846d048 --- /dev/null +++ b/tools/qmlplugindump/Info.plist @@ -0,0 +1,16 @@ + + + + + CFBundlePackageType + APPL + CFBundleSignature + @TYPEINFO@ + CFBundleExecutable + @EXECUTABLE@ + CFBundleIdentifier + com.nokia.qt.qmlplugindump + LSUIElement + 1 + + diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp new file mode 100644 index 0000000000..848b0917cb --- /dev/null +++ b/tools/qmlplugindump/main.cpp @@ -0,0 +1,597 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "qmlstreamwriter.h" + +#ifdef QT_SIMULATOR +#include +#endif + +#ifdef Q_OS_UNIX +#include +#endif + +void collectReachableMetaObjects(const QMetaObject *meta, QSet *metas) +{ + if (! meta || metas->contains(meta)) + return; + + // dynamic meta objects break things badly, so just ignore them + const QMetaObjectPrivate *mop = reinterpret_cast(meta->d.data); + if (!(mop->flags & DynamicMetaObject)) + metas->insert(meta); + + collectReachableMetaObjects(meta->superClass(), metas); +} + +QString currentProperty; + +void collectReachableMetaObjects(QObject *object, QSet *metas) +{ + if (! object) + return; + + const QMetaObject *meta = object->metaObject(); + qDebug() << "Processing object" << meta->className(); + collectReachableMetaObjects(meta, metas); + + for (int index = 0; index < meta->propertyCount(); ++index) { + QMetaProperty prop = meta->property(index); + if (QDeclarativeMetaType::isQObject(prop.userType())) { + qDebug() << " Processing property" << prop.name(); + currentProperty = QString("%1::%2").arg(meta->className(), prop.name()); + + // if the property was not initialized during construction, + // accessing a member of oo is going to cause a segmentation fault + QObject *oo = QDeclarativeMetaType::toQObject(prop.read(object)); + if (oo && !metas->contains(oo->metaObject())) + collectReachableMetaObjects(oo, metas); + currentProperty.clear(); + } + } +} + +void collectReachableMetaObjects(const QDeclarativeType *ty, QSet *metas) +{ + collectReachableMetaObjects(ty->metaObject(), metas); + if (ty->attachedPropertiesType()) + collectReachableMetaObjects(ty->attachedPropertiesType(), metas); +} + +/* We want to add the MetaObject for 'Qt' to the list, this is a + simple way to access it. +*/ +class FriendlyQObject: public QObject +{ +public: + static const QMetaObject *qtMeta() { return &staticQtMetaObject; } +}; + +/* When we dump a QMetaObject, we want to list all the types it is exported as. + To do this, we need to find the QDeclarativeTypes associated with this + QMetaObject. +*/ +static QHash > qmlTypesByCppName; + +static QHash cppToId; + +/* Takes a C++ type name, such as Qt::LayoutDirection or QString and + maps it to how it should appear in the description file. + + These names need to be unique globally, so we don't change the C++ symbol's + name much. It is mostly used to for explicit translations such as + QString->string and translations for extended QML objects. +*/ +QByteArray convertToId(const QByteArray &cppName) +{ + return cppToId.value(cppName, cppName); +} + +QSet collectReachableMetaObjects(const QString &importCode, QDeclarativeEngine *engine) +{ + QSet metas; + metas.insert(FriendlyQObject::qtMeta()); + + QHash > extensions; + foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { + qmlTypesByCppName[ty->metaObject()->className()].insert(ty); + if (ty->isExtendedType()) { + extensions[ty->typeName()].insert(ty->metaObject()->className()); + } + collectReachableMetaObjects(ty, &metas); + } + + // Adjust ids of extended objects. + // The chain ends up being: + // __extended__.originalname - the base object + // __extension_0_.originalname - first extension + // .. + // __extension_n-2_.originalname - second to last extension + // originalname - last extension + // ### does this actually work for multiple extensions? it seems like the prototypes might be wrong + foreach (const QByteArray &extendedCpp, extensions.keys()) { + cppToId.remove(extendedCpp); + const QByteArray extendedId = convertToId(extendedCpp); + cppToId.insert(extendedCpp, "__extended__." + extendedId); + QSet extensionCppNames = extensions.value(extendedCpp); + int c = 0; + foreach (const QByteArray &extensionCppName, extensionCppNames) { + if (c != extensionCppNames.size() - 1) { + QByteArray adjustedName = QString("__extension__%1.%2").arg(QString::number(c), QString(extendedId)).toAscii(); + cppToId.insert(extensionCppName, adjustedName); + } else { + cppToId.insert(extensionCppName, extendedId); + } + ++c; + } + } + + // find even more QMetaObjects by instantiating QML types and running + // over the instances + foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { + if (ty->isExtendedType()) + continue; + + QByteArray tyName = ty->qmlTypeName(); + tyName = tyName.mid(tyName.lastIndexOf('/') + 1); + + QByteArray code = importCode.toUtf8(); + code += tyName; + code += " {}\n"; + + QDeclarativeComponent c(engine); + c.setData(code, QUrl("typeinstance")); + + QObject *object = c.create(); + if (object) + collectReachableMetaObjects(object, &metas); + else + qDebug() << "Could not create" << tyName << ":" << c.errorString(); + } + + return metas; +} + + +class Dumper +{ + QmlStreamWriter *qml; + QString relocatableModuleUri; + +public: + Dumper(QmlStreamWriter *qml) : qml(qml) {} + + void setRelocatableModuleUri(const QString &uri) + { + relocatableModuleUri = uri; + } + + void dump(const QMetaObject *meta) + { + qml->writeStartObject("Component"); + + QByteArray id = convertToId(meta->className()); + qml->writeScriptBinding(QLatin1String("name"), enquote(id)); + + for (int index = meta->classInfoCount() - 1 ; index >= 0 ; --index) { + QMetaClassInfo classInfo = meta->classInfo(index); + if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) { + qml->writeScriptBinding(QLatin1String("defaultProperty"), enquote(QLatin1String(classInfo.value()))); + break; + } + } + + if (meta->superClass()) + qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass()->className()))); + + QSet qmlTypes = qmlTypesByCppName.value(meta->className()); + if (!qmlTypes.isEmpty()) { + QStringList exports; + + foreach (const QDeclarativeType *qmlTy, qmlTypes) { + QString qmlTyName = qmlTy->qmlTypeName(); + // some qmltype names are missing the actual names, ignore that import + if (qmlTyName.endsWith('/')) + continue; + if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) { + qmlTyName.remove(0, relocatableModuleUri.size() + 1); + } + exports += enquote(QString("%1 %2.%3").arg( + qmlTyName, + QString::number(qmlTy->majorVersion()), + QString::number(qmlTy->minorVersion()))); + } + + // ensure exports are sorted and don't change order when the plugin is dumped again + exports.removeDuplicates(); + qSort(exports); + + qml->writeArrayBinding(QLatin1String("exports"), exports); + + if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType()) { + qml->writeScriptBinding(QLatin1String("attachedType"), enquote( + convertToId(attachedType->className()))); + } + } + + for (int index = meta->enumeratorOffset(); index < meta->enumeratorCount(); ++index) + dump(meta->enumerator(index)); + + for (int index = meta->propertyOffset(); index < meta->propertyCount(); ++index) + dump(meta->property(index)); + + for (int index = meta->methodOffset(); index < meta->methodCount(); ++index) + dump(meta->method(index)); + + qml->writeEndObject(); + } + + void writeEasingCurve() + { + qml->writeStartObject("Component"); + qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("QEasingCurve"))); + qml->writeScriptBinding(QLatin1String("prototype"), enquote(QLatin1String("QDeclarativeEasingValueType"))); + qml->writeEndObject(); + } + +private: + static QString enquote(const QString &string) + { + return QString("\"%1\"").arg(string); + } + + /* Removes pointer and list annotations from a type name, returning + what was removed in isList and isPointer + */ + static void removePointerAndList(QByteArray *typeName, bool *isList, bool *isPointer) + { + static QByteArray declListPrefix = "QDeclarativeListProperty<"; + + if (typeName->endsWith('*')) { + *isPointer = true; + typeName->truncate(typeName->length() - 1); + removePointerAndList(typeName, isList, isPointer); + } else if (typeName->startsWith(declListPrefix)) { + *isList = true; + typeName->truncate(typeName->length() - 1); // get rid of the suffix '>' + *typeName = typeName->mid(declListPrefix.size()); + removePointerAndList(typeName, isList, isPointer); + } + + *typeName = convertToId(*typeName); + } + + void writeTypeProperties(QByteArray typeName, bool isWritable) + { + bool isList = false, isPointer = false; + removePointerAndList(&typeName, &isList, &isPointer); + + qml->writeScriptBinding(QLatin1String("type"), enquote(typeName)); + if (isList) + qml->writeScriptBinding(QLatin1String("isList"), QLatin1String("true")); + if (!isWritable) + qml->writeScriptBinding(QLatin1String("isReadonly"), QLatin1String("true")); + if (isPointer) + qml->writeScriptBinding(QLatin1String("isPointer"), QLatin1String("true")); + } + + void dump(const QMetaProperty &prop) + { + qml->writeStartObject("Property"); + + qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(prop.name()))); + writeTypeProperties(prop.typeName(), prop.isWritable()); + + qml->writeEndObject(); + } + + void dump(const QMetaMethod &meth) + { + if (meth.methodType() == QMetaMethod::Signal) { + if (meth.access() != QMetaMethod::Protected) + return; // nothing to do. + } else if (meth.access() != QMetaMethod::Public) { + return; // nothing to do. + } + + QByteArray name = meth.signature(); + int lparenIndex = name.indexOf('('); + if (lparenIndex == -1) { + return; // invalid signature + } + name = name.left(lparenIndex); + + if (meth.methodType() == QMetaMethod::Signal) + qml->writeStartObject(QLatin1String("Signal")); + else + qml->writeStartObject(QLatin1String("Method")); + + qml->writeScriptBinding(QLatin1String("name"), enquote(name)); + + const QString typeName = convertToId(meth.typeName()); + if (! typeName.isEmpty()) + qml->writeScriptBinding(QLatin1String("type"), enquote(typeName)); + + for (int i = 0; i < meth.parameterTypes().size(); ++i) { + QByteArray argName = meth.parameterNames().at(i); + + qml->writeStartObject(QLatin1String("Parameter")); + if (! argName.isEmpty()) + qml->writeScriptBinding(QLatin1String("name"), enquote(argName)); + writeTypeProperties(meth.parameterTypes().at(i), true); + qml->writeEndObject(); + } + + qml->writeEndObject(); + } + + void dump(const QMetaEnum &e) + { + qml->writeStartObject(QLatin1String("Enum")); + qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(e.name()))); + + QList > namesValues; + for (int index = 0; index < e.keyCount(); ++index) { + namesValues.append(qMakePair(enquote(QString::fromUtf8(e.key(index))), QString::number(e.value(index)))); + } + + qml->writeScriptObjectLiteralBinding(QLatin1String("values"), namesValues); + qml->writeEndObject(); + } +}; + + +enum ExitCode { + EXIT_INVALIDARGUMENTS = 1, + EXIT_SEGV = 2, + EXIT_IMPORTERROR = 3 +}; + +#ifdef Q_OS_UNIX +void sigSegvHandler(int) { + fprintf(stderr, "Error: SEGV\n"); + if (!currentProperty.isEmpty()) + fprintf(stderr, "While processing the property '%s', which probably has uninitialized data.\n", currentProperty.toLatin1().constData()); + exit(EXIT_SEGV); +} +#endif + +void printUsage(const QString &appName) +{ + qWarning() << qPrintable(QString( + "Usage: %1 [-notrelocatable] module.uri version [module/import/path]\n" + " %1 -path path/to/qmldir/directory [version]\n" + " %1 -builtins\n" + "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg( + appName)); +} + +int main(int argc, char *argv[]) +{ +#ifdef Q_OS_UNIX + // qmldump may crash, but we don't want any crash handlers to pop up + // therefore we intercept the segfault and just exit() ourselves + struct sigaction action; + + sigemptyset(&action.sa_mask); + action.sa_handler = &sigSegvHandler; + action.sa_flags = 0; + + sigaction(SIGSEGV, &action, 0); +#endif + +#ifdef QT_SIMULATOR + // Running this application would bring up the Qt Simulator (since it links QtGui), avoid that! + QtSimulatorPrivate::SimulatorConnection::createStubInstance(); +#endif + QApplication app(argc, argv); + const QStringList args = app.arguments(); + const QString appName = QFileInfo(app.applicationFilePath()).baseName(); + if (!(args.size() >= 3 + || (args.size() == 2 + && (args.at(1) == QLatin1String("--builtins") + || args.at(1) == QLatin1String("-builtins"))))) { + printUsage(appName); + return EXIT_INVALIDARGUMENTS; + } + + QString pluginImportUri; + QString pluginImportVersion; + QString pluginImportPath; + bool relocatable = true; + bool pathImport = false; + if (args.size() >= 3) { + QStringList positionalArgs; + foreach (const QString &arg, args) { + if (!arg.startsWith(QLatin1Char('-'))) { + positionalArgs.append(arg); + continue; + } + + if (arg == QLatin1String("--notrelocatable") + || arg == QLatin1String("-notrelocatable")) { + relocatable = false; + } else if (arg == QLatin1String("--path") + || arg == QLatin1String("-path")) { + pathImport = true; + } else { + qWarning() << "Invalid argument: " << arg; + return EXIT_INVALIDARGUMENTS; + } + } + + if (!pathImport) { + if (positionalArgs.size() != 3 && positionalArgs.size() != 4) { + qWarning() << "Incorrect number of positional arguments"; + return EXIT_INVALIDARGUMENTS; + } + pluginImportUri = positionalArgs[1]; + pluginImportVersion = positionalArgs[2]; + if (positionalArgs.size() >= 4) + pluginImportPath = positionalArgs[3]; + } else { + if (positionalArgs.size() != 2 && positionalArgs.size() != 3) { + qWarning() << "Incorrect number of positional arguments"; + return EXIT_INVALIDARGUMENTS; + } + pluginImportPath = positionalArgs[1]; + if (positionalArgs.size() == 3) + pluginImportVersion = positionalArgs[2]; + } + } + + QDeclarativeView view; + QDeclarativeEngine *engine = view.engine(); + if (!pluginImportPath.isEmpty()) + engine->addImportPath(pluginImportPath); + + // find all QMetaObjects reachable from the builtin module + QByteArray importCode("import QtQuick 1.0\n"); + QSet defaultReachable = collectReachableMetaObjects(importCode, engine); + + // this will hold the meta objects we want to dump information of + QSet metas; + + if (pluginImportUri.isEmpty() && !pathImport) { + metas = defaultReachable; + } else { + // find all QMetaObjects reachable when the specified module is imported + if (!pathImport) { + importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii(); + } else { + // pluginImportVersion can be empty + importCode += QString("import \"%1\" %2\n").arg(pluginImportPath, pluginImportVersion).toAscii(); + } + + // create a component with these imports to make sure the imports are valid + // and to populate the declarative meta type system + { + QByteArray code = importCode; + code += "QtObject {}"; + QDeclarativeComponent c(engine); + + c.setData(code, QUrl("typelist")); + c.create(); + if (!c.errors().isEmpty()) { + foreach (const QDeclarativeError &error, c.errors()) + qWarning() << error.toString(); + return EXIT_IMPORTERROR; + } + } + + QSet candidates = collectReachableMetaObjects(importCode, engine); + candidates.subtract(defaultReachable); + + // Also eliminate meta objects with the same classname. + // This is required because extended objects seem not to share + // a single meta object instance. + QSet defaultReachableNames; + foreach (const QMetaObject *mo, defaultReachable) + defaultReachableNames.insert(QByteArray(mo->className())); + foreach (const QMetaObject *mo, candidates) { + if (!defaultReachableNames.contains(mo->className())) + metas.insert(mo); + } + } + + // setup static rewrites of type names + cppToId.insert("QString", "string"); + cppToId.insert("QDeclarativeEasingValueType::Type", "Type"); + + // start dumping data + QByteArray bytes; + QmlStreamWriter qml(&bytes); + + qml.writeStartDocument(); + qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 0); + qml.write("\n" + "// This file describes the plugin-supplied types contained in the library.\n" + "// It is used for QML tooling purposes only.\n" + "\n"); + qml.writeStartObject("Module"); + + // put the metaobjects into a map so they are always dumped in the same order + QMap nameToMeta; + foreach (const QMetaObject *meta, metas) + nameToMeta.insert(convertToId(meta->className()), meta); + + Dumper dumper(&qml); + if (relocatable) + dumper.setRelocatableModuleUri(pluginImportUri); + foreach (const QMetaObject *meta, nameToMeta) { + dumper.dump(meta); + } + + // define QEasingCurve as an extension of QDeclarativeEasingValueType, this way + // properties using the QEasingCurve type get useful type information. + if (pluginImportUri.isEmpty()) + dumper.writeEasingCurve(); + + qml.writeEndObject(); + qml.writeEndDocument(); + + std::cout << bytes.constData(); + + // workaround to avoid crashes on exit + QTimer timer; + timer.setSingleShot(true); + timer.setInterval(0); + QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit())); + timer.start(); + + return app.exec(); +} diff --git a/tools/qmlplugindump/qmlplugindump.pro b/tools/qmlplugindump/qmlplugindump.pro new file mode 100644 index 0000000000..53827e2f40 --- /dev/null +++ b/tools/qmlplugindump/qmlplugindump.pro @@ -0,0 +1,20 @@ +TEMPLATE = app +CONFIG += qt uic console +DESTDIR = ../../bin + +QT += declarative + +TARGET = qmlplugindump + +SOURCES += \ + main.cpp \ + qmlstreamwriter.cpp + +HEADERS += \ + qmlstreamwriter.h + +OTHER_FILES += Info.plist +macx: QMAKE_INFO_PLIST = Info.plist + +target.path = $$[QT_INSTALL_BINS] +INSTALLS += target diff --git a/tools/qmlplugindump/qmlstreamwriter.cpp b/tools/qmlplugindump/qmlstreamwriter.cpp new file mode 100644 index 0000000000..d083f7b64c --- /dev/null +++ b/tools/qmlplugindump/qmlstreamwriter.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlstreamwriter.h" + +#include +#include + +QmlStreamWriter::QmlStreamWriter(QByteArray *array) + : m_indentDepth(0) + , m_pendingLineLength(0) + , m_maybeOneline(false) + , m_stream(new QBuffer(array)) +{ + m_stream->open(QIODevice::WriteOnly); +} + +void QmlStreamWriter::writeStartDocument() +{ +} + +void QmlStreamWriter::writeEndDocument() +{ +} + +void QmlStreamWriter::writeLibraryImport(const QString &uri, int majorVersion, int minorVersion, const QString &as) +{ + m_stream->write(QString("import %1 %2.%3").arg(uri, QString::number(majorVersion), QString::number(minorVersion)).toUtf8()); + if (!as.isEmpty()) + m_stream->write(QString(" as %1").arg(as).toUtf8()); + m_stream->write("\n"); +} + +void QmlStreamWriter::writeStartObject(const QString &component) +{ + flushPotentialLinesWithNewlines(); + writeIndent(); + m_stream->write(QString("%1 {").arg(component).toUtf8()); + ++m_indentDepth; + m_maybeOneline = true; +} + +void QmlStreamWriter::writeEndObject() +{ + if (m_maybeOneline && !m_pendingLines.isEmpty()) { + --m_indentDepth; + for (int i = 0; i < m_pendingLines.size(); ++i) { + m_stream->write(" "); + m_stream->write(m_pendingLines.at(i).trimmed()); + if (i != m_pendingLines.size() - 1) + m_stream->write(";"); + } + m_stream->write(" }\n"); + m_pendingLines.clear(); + m_pendingLineLength = 0; + m_maybeOneline = false; + } else { + if (m_maybeOneline) + flushPotentialLinesWithNewlines(); + --m_indentDepth; + writeIndent(); + m_stream->write("}\n"); + } +} + +void QmlStreamWriter::writeScriptBinding(const QString &name, const QString &rhs) +{ + writePotentialLine(QString("%1: %2").arg(name, rhs).toUtf8()); +} + +void QmlStreamWriter::writeArrayBinding(const QString &name, const QStringList &elements) +{ + flushPotentialLinesWithNewlines(); + writeIndent(); + m_stream->write(QString("%1: [\n").arg(name).toUtf8()); + ++m_indentDepth; + for (int i = 0; i < elements.size(); ++i) { + writeIndent(); + m_stream->write(elements.at(i).toUtf8()); + if (i != elements.size() - 1) { + m_stream->write(",\n"); + } else { + m_stream->write("\n"); + } + } + --m_indentDepth; + writeIndent(); + m_stream->write("]\n"); +} + +void QmlStreamWriter::write(const QString &data) +{ + flushPotentialLinesWithNewlines(); + m_stream->write(data.toUtf8()); +} + +void QmlStreamWriter::writeScriptObjectLiteralBinding(const QString &name, const QList > &keyValue) +{ + flushPotentialLinesWithNewlines(); + writeIndent(); + m_stream->write(QString("%1: {\n").arg(name).toUtf8()); + ++m_indentDepth; + for (int i = 0; i < keyValue.size(); ++i) { + const QString key = keyValue.at(i).first; + const QString value = keyValue.at(i).second; + writeIndent(); + m_stream->write(QString("%1: %2").arg(key, value).toUtf8()); + if (i != keyValue.size() - 1) { + m_stream->write(",\n"); + } else { + m_stream->write("\n"); + } + } + --m_indentDepth; + writeIndent(); + m_stream->write("}\n"); +} + +void QmlStreamWriter::writeIndent() +{ + m_stream->write(QByteArray(m_indentDepth * 4, ' ')); +} + +void QmlStreamWriter::writePotentialLine(const QByteArray &line) +{ + m_pendingLines.append(line); + m_pendingLineLength += line.size(); + if (m_pendingLineLength >= 80) { + flushPotentialLinesWithNewlines(); + } +} + +void QmlStreamWriter::flushPotentialLinesWithNewlines() +{ + if (m_maybeOneline) + m_stream->write("\n"); + foreach (const QByteArray &line, m_pendingLines) { + writeIndent(); + m_stream->write(line); + m_stream->write("\n"); + } + m_pendingLines.clear(); + m_pendingLineLength = 0; + m_maybeOneline = false; +} diff --git a/tools/qmlplugindump/qmlstreamwriter.h b/tools/qmlplugindump/qmlstreamwriter.h new file mode 100644 index 0000000000..cd73aad8f2 --- /dev/null +++ b/tools/qmlplugindump/qmlstreamwriter.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLSTREAMWRITER_H +#define QMLSTREAMWRITER_H + +#include +#include +#include +#include +#include + +class QmlStreamWriter +{ +public: + QmlStreamWriter(QByteArray *array); + + void writeStartDocument(); + void writeEndDocument(); + void writeLibraryImport(const QString &uri, int majorVersion, int minorVersion, const QString &as = QString()); + //void writeFilesystemImport(const QString &file, const QString &as = QString()); + void writeStartObject(const QString &component); + void writeEndObject(); + void writeScriptBinding(const QString &name, const QString &rhs); + void writeScriptObjectLiteralBinding(const QString &name, const QList > &keyValue); + void writeArrayBinding(const QString &name, const QStringList &elements); + void write(const QString &data); + +private: + void writeIndent(); + void writePotentialLine(const QByteArray &line); + void flushPotentialLinesWithNewlines(); + + int m_indentDepth; + QList m_pendingLines; + int m_pendingLineLength; + bool m_maybeOneline; + QScopedPointer m_stream; +}; + +#endif // QMLSTREAMWRITER_H diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp new file mode 100644 index 0000000000..765a9dc2fb --- /dev/null +++ b/tools/qmlscene/main.cpp @@ -0,0 +1,574 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +// ### This should be private API +#include +#include + +#define QT_NO_SCENEGRAPHITEM + +#ifndef QT_NO_SCENEGRAPHITEM +#include "scenegraphitem.h" +#endif + +#include + +#ifdef QML_RUNTIME_TESTING +class RenderStatistics +{ +public: + static void updateStats(); + static void printTotalStats(); +private: + static QVector timePerFrame; + static QVector timesPerFrames; +}; + +QVector RenderStatistics::timePerFrame; +QVector 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 + + +static QGLFormat getFormat() +{ + QGLFormat f = QGLFormat::defaultFormat(); + f.setSampleBuffers(!qApp->arguments().contains("--no-multisample")); + f.setSwapInterval(qApp->arguments().contains("--nonblocking-swap") ? 0 : 1); + f.setStereo(qApp->arguments().contains("--stereo")); + return f; +} + +class MyQSGView : public QSGView +{ +public: + MyQSGView() : QSGView(getFormat()) + { + setResizeMode(QSGView::SizeRootObjectToView); + } + +protected: + void paintEvent(QPaintEvent *e) { + QSGView::paintEvent(e); + +#ifdef QML_RUNTIME_TESTING +// RenderStatistics::updateStats(); +#endif + + static bool continuousUpdate = qApp->arguments().contains("--continuous-update"); + if (continuousUpdate) + update(); + } +}; + +class MyDeclarativeView: public QDeclarativeView +{ +public: + MyDeclarativeView(QWidget *parent = 0) : QDeclarativeView(parent) + { + setResizeMode(QDeclarativeView::SizeRootObjectToView); + } + +protected: + void paintEvent(QPaintEvent *event) + { + QDeclarativeView::paintEvent(event); + +#ifdef QML_RUNTIME_TESTING + RenderStatistics::updateStats(); +#endif + + static bool continuousUpdate = qApp->arguments().contains("--continuous-update"); + if (continuousUpdate) + scene()->update(); + } +}; + +#ifndef QT_NO_SCENEGRAPHITEM +class MyGraphicsView: public QGraphicsView +{ +public: + MyGraphicsView(bool clip, QWidget *parent = 0) : QGraphicsView(parent) + { + setViewport(new QGLWidget(getFormat())); + setScene(&scene); + scene.addItem(&item); + item.setFlag(QGraphicsItem::ItemClipsToShape, clip); + QGraphicsTextItem *text; + text = scene.addText(QLatin1String("Scene graph on graphics view."), QFont(QLatin1String("Times"), 10)); + text->setX(5); + text->setY(5); + text->setDefaultTextColor(Qt::black); + text = scene.addText(QLatin1String("Scene graph on graphics view."), QFont(QLatin1String("Times"), 10)); + text->setX(4); + text->setY(4); + text->setDefaultTextColor(Qt::yellow); + } + + SceneGraphItem *sceneGraphItem() { return &item; } + +protected: + void paintEvent(QPaintEvent *event) + { + QGraphicsView::paintEvent(event); + +#ifdef QML_RUNTIME_TESTING + RenderStatistics::updateStats(); +#endif + + static bool continuousUpdate = qApp->arguments().contains("--continuous-update"); + if (continuousUpdate) + QGraphicsView::scene()->update(); + } + + QGraphicsScene scene; + SceneGraphItem item; +}; +#endif + +struct Options +{ + Options() + : originalQml(false) + , originalQmlRaster(false) + , maximized(false) + , fullscreen(false) + , scenegraphOnGraphicsview(false) + , clip(false) + , versionDetection(true) + { + } + + QUrl file; + bool originalQml; + bool originalQmlRaster; + bool maximized; + bool fullscreen; + bool scenegraphOnGraphicsview; + bool clip; + bool versionDetection; +}; + +#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(); + + 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 + +static void checkAndAdaptVersion(const QUrl &url) +{ + if (!qgetenv("QMLSCENE_IMPORT_NAME").isEmpty()) { + return; + } + + QString fileName = url.toLocalFile(); + if (fileName.isEmpty()) + return; + + QFile f(fileName); + if (!f.open(QFile::ReadOnly | QFile::Text)) { + qWarning("qmlscene: failed to check version of file '%s', could not open...", + qPrintable(fileName)); + return; + } + + QRegExp quick1("import +QtQuick +1\\."); + QRegExp qt47("import +Qt +4\\.7"); + + QString envToWrite; + QString compat; + + QTextStream stream(&f); + bool codeFound= false; + while (!codeFound && envToWrite.isEmpty()) { + QString line = stream.readLine(); + if (line.contains("{")) + codeFound = true; + if (quick1.indexIn(line) >= 0) { + envToWrite = QLatin1String("quick1"); + compat = QLatin1String("QtQuick 1.0"); + } else if (qt47.indexIn(line) >= 0) { + envToWrite = QLatin1String("qt"); + compat = QLatin1String("Qt 4.7"); + } + } + + if (!envToWrite.isEmpty()) { + qWarning("qmlscene: Autodetecting compatibility import \"%s\"...", qPrintable(compat)); + if (qgetenv("QMLSCENE_IMPORT_NAME").isEmpty()) + qputenv("QMLSCENE_IMPORT_NAME", envToWrite.toLatin1().constData()); + } +} + +static void displayFileDialog(Options *options) +{ + QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)"); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + options->file = QUrl::fromLocalFile(fi.canonicalFilePath()); + } +} + +static void loadDummyDataFiles(QDeclarativeEngine &engine, const QString& directory) +{ + 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(); + QDeclarativeComponent comp(&engine); + comp.setData(data, QUrl()); + QObject *dummyData = comp.create(); + + if(comp.isError()) { + QList errors = comp.errors(); + foreach (const QDeclarativeError &error, errors) { + 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] "); + qWarning(" "); + qWarning(" options:"); + qWarning(" --maximized ............................... run maximized"); + qWarning(" --fullscreen .............................. run fullscreen"); + qWarning(" --original-qml ............................ run using QGraphicsView instead of scenegraph (OpenGL engine)"); + qWarning(" --original-qml-raster ..................... run using QGraphicsView instead of scenegraph (Raster engine)"); + qWarning(" --no-multisample .......................... Disable multisampling (anti-aliasing)"); + qWarning(" --continuous-update ....................... Continuously render the scene"); + qWarning(" --nonblocking-swap ........................ Do not wait for v-sync to swap buffers"); + qWarning(" --stereo .................................. Enable stereo on the GL context"); +#ifndef QT_NO_SCENEGRAPHITEM + qWarning(" --sg-on-gv [--clip] ....................... Scenegraph on graphicsview (and clip to item)"); +#endif + qWarning(" --no-version-detection .................... Do not try to detect the version of the .qml file"); + + qWarning(" "); + exit(1); +} + +int main(int argc, char ** argv) +{ +#ifdef Q_WS_X11 + QApplication::setAttribute(Qt::AA_X11InitThreads); +#endif + + Options options; + + QDeclarativeDebugHelper::enableDebugging(); + QStringList imports; + for (int i = 1; i < argc; ++i) { + if (*argv[i] != '-' && QFileInfo(argv[i]).exists()) + options.file = QUrl::fromLocalFile(argv[i]); + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--original-qml")) + options.originalQml = true; + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--original-qml-raster")) + options.originalQmlRaster = true; + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--maximized")) + options.maximized = true; + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--fullscreen")) + options.fullscreen = true; + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--sg-on-gv")) + options.scenegraphOnGraphicsview = true; + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--clip")) + options.clip = true; + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--no-version-detection")) + options.versionDetection = false; + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("-i") && i + 1 < argc) + imports.append(QString::fromLatin1(argv[++i])); + else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--help") + || QString::fromLatin1(argv[i]).toLower() == QLatin1String("-help") + || QString::fromLatin1(argv[i]).toLower() == QLatin1String("--h") + || QString::fromLatin1(argv[i]).toLower() == QLatin1String("-h")) + usage(); + } + + QApplication::setGraphicsSystem("raster"); + + QApplication app(argc, argv); + app.setApplicationName("QtQmlViewer"); + app.setOrganizationName("Nokia"); + app.setOrganizationDomain("nokia.com"); + + if (options.file.isEmpty()) +#if defined(QMLSCENE_BUNDLE) + displayOptionsDialog(&options); +#else + displayFileDialog(&options); +#endif + + QWidget *view = 0; + QDeclarativeEngine *engine = 0; + + int exitCode = 0; + + if (!options.file.isEmpty()) { +#ifndef QT_NO_SCENEGRAPHITEM + if (options.scenegraphOnGraphicsview) { + MyGraphicsView *gvView = new MyGraphicsView(options.clip); + SceneGraphItem *item = gvView->sceneGraphItem(); + engine = item->engine(); + for (int i = 0; i < imports.size(); ++i) + engine->addImportPath(imports.at(i)); + view = gvView; + if (options.file.isLocalFile()) { + QFileInfo fi(options.file.toLocalFile()); + loadDummyDataFiles(*engine, fi.path()); + } + item->setSource(options.file); + } else +#endif + if (!options.originalQml && !options.originalQmlRaster) { + if (options.versionDetection) + checkAndAdaptVersion(options.file); + QSGView *qxView = new MyQSGView(); + engine = qxView->engine(); + for (int i = 0; i < imports.size(); ++i) + engine->addImportPath(imports.at(i)); + view = qxView; + if (options.file.isLocalFile()) { + QFileInfo fi(options.file.toLocalFile()); + loadDummyDataFiles(*engine, fi.path()); + } + qxView->setSource(options.file); + + } else { + MyDeclarativeView *gvView = new MyDeclarativeView(); + engine = gvView->engine(); + for (int i = 0; i < imports.size(); ++i) + engine->addImportPath(imports.at(i)); + view = gvView; + if (options.file.isLocalFile()) { + QFileInfo fi(options.file.toLocalFile()); + loadDummyDataFiles(*engine, fi.path()); + } + gvView->setSource(options.file); + if (!options.originalQmlRaster) { + QGLWidget *viewport = new QGLWidget(getFormat()); + gvView->setViewport(viewport); + } + } + + QObject::connect(engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit())); + + if (options.fullscreen) + view->showFullScreen(); + else if (options.maximized) + view->showMaximized(); + else + view->show(); + +#ifdef Q_WS_MAC + view->raise(); +#endif + + exitCode = app.exec(); + + delete view; + +#ifdef QML_RUNTIME_TESTING + RenderStatistics::printTotalStats(); +#endif + } + + return exitCode; +} + diff --git a/tools/qmlscene/qmlscene.pro b/tools/qmlscene/qmlscene.pro new file mode 100644 index 0000000000..3849336fc8 --- /dev/null +++ b/tools/qmlscene/qmlscene.pro @@ -0,0 +1,20 @@ +TEMPLATE = app +TARGET = qmlscene +DESTDIR= ../../bin + +QT += declarative + +target.path = $$[QT_INSTALL_BINS] +INSTALLS += target + +macx: CONFIG -= app_bundle + +SOURCES += main.cpp + +CONFIG += console + +symbian { + TARGET.EPOCHEAPSIZE = 0x20000 0x5000000 +} + +DEFINES += QML_RUNTIME_TESTING diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index b2c7f4f730..b1a10ff6c4 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -156,7 +156,9 @@ void usage() qWarning(" -P ........................... prepend to the plugin search path"); #if defined(Q_WS_MAC) qWarning(" -no-opengl ............................... don't use a QGLWidget for the viewport"); + qWarning(" -opengl .................................. use a QGLWidget for the viewport (default)"); #else + qWarning(" -no-opengl ............................... don't use a QGLWidget for the viewport (default)"); qWarning(" -opengl .................................. use a QGLWidget for the viewport"); #endif qWarning(" -script ........................... set the script to use"); @@ -375,13 +377,10 @@ static void parseCommandLineOptions(const QStringList &arguments) } else if (arg == "-translation") { if (lastArg) usage(); opts.translationFile = arguments.at(++i); -#if defined(Q_WS_MAC) } else if (arg == "-no-opengl") { opts.useGL = false; -#else } else if (arg == "-opengl") { opts.useGL = true; -#endif } else if (arg == "-qmlbrowser") { opts.useNativeFileBrowser = false; } else if (arg == "-warnings") { @@ -522,6 +521,8 @@ QDeclarativeViewer *openFile(const QString &fileName) int main(int argc, char ** argv) { + QDeclarativeDebugHelper::enableDebugging(); + systemMsgOutput = qInstallMsgHandler(myMessageOutput); #if defined (Q_WS_X11) || defined (Q_WS_MAC) diff --git a/tools/qmlviewer/qmlruntime.cpp b/tools/qmlviewer/qmlruntime.cpp index 36915d12bf..4bae7f3ec0 100644 --- a/tools/qmlviewer/qmlruntime.cpp +++ b/tools/qmlviewer/qmlruntime.cpp @@ -1477,6 +1477,7 @@ void QDeclarativeViewer::setUseGL(bool useGL) QGLFormat format = QGLFormat::defaultFormat(); #ifdef Q_WS_MAC format.setSampleBuffers(true); + format.setSwapInterval(1); #else format.setSampleBuffers(false); #endif diff --git a/tools/tools.pro b/tools/tools.pro index 2035460ce2..6d5b43a9e4 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += qmlviewer +SUBDIRS += qmlviewer qmlscene qmlplugindump distfieldgen -- cgit v1.2.3 From 3904e604f453b43b2a0e45a882283e26a27eaa18 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 28 Apr 2011 12:22:30 +0200 Subject: qmlplugindump: Fix --path usage with drive letters on Windows. Since we can't import by such a path, we instead use a "." import and set the uri of the component to the correct path. Mirrors a change to qmldump in qt-creator/0c8b4e38fab1862e3427aac7e7db68623bc7f174 Reviewed-by: Thomas Hartmann --- tools/qmlplugindump/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index 848b0917cb..c2d2681b42 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -65,6 +65,8 @@ #include #endif +QString pluginImportPath; + void collectReachableMetaObjects(const QMetaObject *meta, QSet *metas) { if (! meta || metas->contains(meta)) @@ -194,7 +196,7 @@ QSet collectReachableMetaObjects(const QString &importCode, code += " {}\n"; QDeclarativeComponent c(engine); - c.setData(code, QUrl("typeinstance")); + c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typeinstance.qml")); QObject *object = c.create(); if (object) @@ -451,7 +453,6 @@ int main(int argc, char *argv[]) QString pluginImportUri; QString pluginImportVersion; - QString pluginImportPath; bool relocatable = true; bool pathImport = false; if (args.size() >= 3) { @@ -488,7 +489,7 @@ int main(int argc, char *argv[]) qWarning() << "Incorrect number of positional arguments"; return EXIT_INVALIDARGUMENTS; } - pluginImportPath = positionalArgs[1]; + pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]); if (positionalArgs.size() == 3) pluginImportVersion = positionalArgs[2]; } @@ -514,7 +515,7 @@ int main(int argc, char *argv[]) importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii(); } else { // pluginImportVersion can be empty - importCode += QString("import \"%1\" %2\n").arg(pluginImportPath, pluginImportVersion).toAscii(); + importCode += QString("import \".\" %2\n").arg(pluginImportVersion).toAscii(); } // create a component with these imports to make sure the imports are valid @@ -524,7 +525,7 @@ int main(int argc, char *argv[]) code += "QtObject {}"; QDeclarativeComponent c(engine); - c.setData(code, QUrl("typelist")); + c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml")); c.create(); if (!c.errors().isEmpty()) { foreach (const QDeclarativeError &error, c.errors()) -- cgit v1.2.3 From c0d8a352b84db4899f2714382739728183ea9c30 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Fri, 29 Apr 2011 11:01:58 +0200 Subject: Removed distfieldgen tool. Not needed anymore. --- tools/distfieldgen/distfieldgen.pro | 12 -- tools/distfieldgen/main.cpp | 262 ------------------------------------ tools/tools.pro | 2 +- 3 files changed, 1 insertion(+), 275 deletions(-) delete mode 100644 tools/distfieldgen/distfieldgen.pro delete mode 100644 tools/distfieldgen/main.cpp (limited to 'tools') diff --git a/tools/distfieldgen/distfieldgen.pro b/tools/distfieldgen/distfieldgen.pro deleted file mode 100644 index 4c2d63603b..0000000000 --- a/tools/distfieldgen/distfieldgen.pro +++ /dev/null @@ -1,12 +0,0 @@ -TARGET = distfieldgen -TEMPLATE = app - -QT += declarative opengl - -CONFIG += console -CONFIG -= app_bundle -DESTDIR = ../../bin - -INCLUDEPATH += $$PWD/../../src/3rdparty/harfbuzz/src - -SOURCES += main.cpp diff --git a/tools/distfieldgen/main.cpp b/tools/distfieldgen/main.cpp deleted file mode 100644 index 3c944b3d4c..0000000000 --- a/tools/distfieldgen/main.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the Qt scene graph research project. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** 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. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include - -static void usage() -{ - qWarning("Usage: distfieldgen [options] "); - qWarning(" "); - qWarning("Distfieldgen generates distance-field renderings of the provided font file,"); - qWarning("one for each font family/style it contains."); - qWarning("Unless the QT_QML_DISTFIELDDIR environment variable is set, the renderings are"); - qWarning("saved in the fonts/distancefields directory where the Qt libraries are located."); - qWarning("You can also override the output directory with the -d option."); - qWarning(" "); - qWarning(" options:"); - qWarning(" -d ................................ output directory"); - qWarning(" --no-multithread.............................. don't use multiple threads to render distance-fields"); - qWarning(" --force-all-styles............................ force rendering of styles Normal, Bold, Italic and Bold Italic"); - qWarning(" -styles \"style1,style2,..\".................... force rendering of specified styles"); - - qWarning(" "); - exit(1); -} - -void printProgress(int p) -{ - printf("\r ["); - for (int i = 0; i < 50; ++i) - printf(i < p / 2 ? "=" : " "); - printf("]"); - printf(" %d%%", p); - fflush(stdout); -} - -class DistFieldGenTask : public QRunnable -{ -public: - DistFieldGenTask(QSGDistanceFieldGlyphCache *atlas, int c, int nbGlyph, QMap *outList) - : QRunnable() - , m_atlas(atlas) - , m_char(c) - , m_nbGlyph(nbGlyph) - , m_outList(outList) - { } - - void run() - { - QImage df = m_atlas->renderDistanceFieldGlyph(m_char); - QMutexLocker lock(&m_mutex); - m_outList->insert(m_char, df); - printProgress(float(m_outList->count()) / m_nbGlyph * 100); - } - - static QMutex m_mutex; - QSGDistanceFieldGlyphCache *m_atlas; - int m_char; - int m_nbGlyph; - QMap *m_outList; -}; - -QMutex DistFieldGenTask::m_mutex; - -static void generateDistanceFieldForFont(const QFont &font, const QString &destinationDir, bool multithread) -{ - QSGDistanceFieldGlyphCache *atlas = QSGDistanceFieldGlyphCache::get(QGLContext::currentContext(), font); - QFontDatabase db; - QString fontString = font.family() + QLatin1String(" ") + db.styleString(font); - qWarning("> Generating distance-field for font '%s' (%d glyphs)", fontString.toLatin1().constData(), atlas->glyphCount()); - - QMap distfields; - for (int i = 0; i < atlas->glyphCount(); ++i) { - if (multithread) { - DistFieldGenTask *task = new DistFieldGenTask(atlas, i, atlas->glyphCount(), &distfields); - QThreadPool::globalInstance()->start(task); - } else { - QImage df = atlas->renderDistanceFieldGlyph(i); - distfields.insert(i, df); - printProgress(float(distfields.count()) / atlas->glyphCount() * 100); - } - } - - if (multithread) - QThreadPool::globalInstance()->waitForDone(); - - // Combine dist fields in one image - int size = qCeil(qSqrt(qreal(atlas->glyphCount()))) * 64; - QImage output(size, size, QImage::Format_ARGB32_Premultiplied); - output.fill(Qt::transparent); - QPainter p(&output); - int x, y = 0; - for (QMap::const_iterator i = distfields.constBegin(); i != distfields.constEnd(); ++i) { - p.drawImage(x, y, i.value()); - x += 64; - if (x >= size) { - x = 0; - y += 64; - } - } - p.end(); - printProgress(100); - printf("\n"); - - // Save output - QFileInfo dfi(destinationDir); - if (!dfi.isDir()) { - qWarning("Error: '%s' is not a directory.", destinationDir.toLatin1().constData()); - qWarning(" "); - exit(1); - } - - QString filename = font.family(); - filename.remove(QLatin1String(" ")); - QString italic = font.italic() ? QLatin1String("i") : QLatin1String(""); - QString bold = font.weight() > QFont::Normal ? QLatin1String("b") : QLatin1String(""); - filename = filename + bold + italic; - QString out = QString(QLatin1String("%1/%2.png")).arg(destinationDir).arg(filename); - output.save(out); - qWarning(" Distance-field saved to '%s'\n", out.toLatin1().constData()); -} - -class MyWidget : public QGLWidget -{ - Q_OBJECT -public: - MyWidget() - : QGLWidget() - { } - - ~MyWidget() { } - - void showEvent(QShowEvent *e) - { - QStringList args = QApplication::arguments(); - - bool noMultithread = args.contains(QLatin1String("--no-multithread")); - bool forceAllStyles = args.contains(QLatin1String("--force-all-styles")); - - QString fontFile; - QString destDir; - for (int i = 0; i < args.count(); ++i) { - QString a = args.at(i); - if (!a.startsWith('-') && QFileInfo(a).exists()) - fontFile = a; - if (a == QLatin1String("-d")) - destDir = args.at(++i); - } - if (destDir.isEmpty()) { - destDir = QFileInfo(fontFile).canonicalPath(); - } - - QStringList customStyles; - if (args.contains(QLatin1String("-styles"))) { - int index = args.indexOf(QLatin1String("-styles")); - QString styles = args.at(index + 1); - customStyles = styles.split(QLatin1String(",")); - } - - // Load the font - int fontID = QFontDatabase::addApplicationFont(fontFile); - if (fontID == -1) { - qWarning("Error: Invalid font file."); - qWarning(" "); - exit(1); - } - - QStringList allStyles = QStringList() << QLatin1String("Normal") - << QLatin1String("Bold") - << QLatin1String("Italic") - << QLatin1String("Bold Italic"); - - // Generate distance-fields for all families and all styles provided by the font file - QFontDatabase fontDatabase; - QStringList families = QFontDatabase::applicationFontFamilies(fontID); - int famCount = families.count(); - for (int i = 0; i < famCount; ++i) { - QStringList styles; - if (forceAllStyles) - styles = allStyles; - else if (customStyles.count() > 0) - styles = customStyles; - else - styles = fontDatabase.styles(families.at(i)); - - int styleCount = styles.count(); - for (int j = 0; j < styleCount; ++j) { - QFont font; - if (forceAllStyles || customStyles.count() > 0) { - int weight = styles.at(j).contains(QLatin1String("Bold")) ? QFont::Bold : QFont::Normal; - font = QFont(families.at(i), 10, weight, styles.at(j).contains(QLatin1String("Italic"))); - } else { - font = fontDatabase.font(families.at(i), styles.at(j), 10); // point size is ignored - } - generateDistanceFieldForFont(font, destDir, !noMultithread); - } - } - - exit(0); - } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - QStringList args = QApplication::arguments(); - - if (argc < 2 - || args.contains(QLatin1String("--help")) - || args.contains(QLatin1String("-help")) - || args.contains(QLatin1String("--h")) - || args.contains(QLatin1String("-h"))) - usage(); - - - MyWidget w; - w.show(); - - return app.exec(); -} - -#include "main.moc" diff --git a/tools/tools.pro b/tools/tools.pro index 6d5b43a9e4..ec83a1e76a 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += qmlviewer qmlscene qmlplugindump distfieldgen +SUBDIRS += qmlviewer qmlscene qmlplugindump -- cgit v1.2.3 From 6a1a69e9e299a5cd7b7f262508d11de5e610c5b9 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 4 May 2011 11:52:52 +0200 Subject: added private headers to qmlplugindump.pro --- tools/qmlplugindump/qmlplugindump.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/qmlplugindump/qmlplugindump.pro b/tools/qmlplugindump/qmlplugindump.pro index 53827e2f40..b9fc0fc0ad 100644 --- a/tools/qmlplugindump/qmlplugindump.pro +++ b/tools/qmlplugindump/qmlplugindump.pro @@ -2,7 +2,7 @@ TEMPLATE = app CONFIG += qt uic console DESTDIR = ../../bin -QT += declarative +QT += declarative declarative-private core-private TARGET = qmlplugindump -- cgit v1.2.3 From 09e769903362cc933aca478a5779e30d0cec4544 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 4 May 2011 12:57:28 +0200 Subject: added private headers to qmlscene --- tools/qmlscene/qmlscene.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/qmlscene/qmlscene.pro b/tools/qmlscene/qmlscene.pro index 3849336fc8..a2da6ad982 100644 --- a/tools/qmlscene/qmlscene.pro +++ b/tools/qmlscene/qmlscene.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = qmlscene DESTDIR= ../../bin -QT += declarative +QT += declarative declarative-private target.path = $$[QT_INSTALL_BINS] INSTALLS += target -- cgit v1.2.3 From 7b337d460c6a1b718259177840ad86ea242e24d9 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 2 May 2011 14:03:35 +0200 Subject: QmlViewer: Translate UI Install translators for the Qt & QmlViewer translations. also add QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII to check for untranslated strings. Reviewed-by: Oswald Buddenhagen Task-number: QTBUG-14848 (cherry-picked from commit f33b31dcc1b8fd35501ab5b441a4529e2f8570f3) --- tools/qmlviewer/loggerwidget.cpp | 14 ++-- tools/qmlviewer/main.cpp | 91 ++++++++++++++------------ tools/qmlviewer/proxysettings.cpp | 36 +++++------ tools/qmlviewer/proxysettings_maemo5.ui | 6 +- tools/qmlviewer/qdeclarativetester.cpp | 10 +-- tools/qmlviewer/qmlruntime.cpp | 109 ++++++++++++++++---------------- tools/qmlviewer/qmlviewer.pro | 2 + 7 files changed, 142 insertions(+), 126 deletions(-) (limited to 'tools') diff --git a/tools/qmlviewer/loggerwidget.cpp b/tools/qmlviewer/loggerwidget.cpp index 3f2337a622..9a07402eb0 100644 --- a/tools/qmlviewer/loggerwidget.cpp +++ b/tools/qmlviewer/loggerwidget.cpp @@ -139,10 +139,10 @@ QAction *LoggerWidget::showAction() void LoggerWidget::readSettings() { QSettings settings; - QString warningsPreferences = settings.value("warnings", "hide").toString(); - if (warningsPreferences == "show") { + QString warningsPreferences = settings.value(QLatin1String("warnings"), QLatin1String("hide")).toString(); + if (warningsPreferences == QLatin1String("show")) { m_visibility = ShowWarnings; - } else if (warningsPreferences == "hide") { + } else if (warningsPreferences == QLatin1String("hide")) { m_visibility = HideWarnings; } else { m_visibility = AutoShowWarnings; @@ -154,15 +154,15 @@ void LoggerWidget::saveSettings() if (m_visibilityOrigin != SettingsOrigin) return; - QString value = "autoShow"; + QString value = QLatin1String("autoShow"); if (defaultVisibility() == ShowWarnings) { - value = "show"; + value = QLatin1String("show"); } else if (defaultVisibility() == HideWarnings) { - value = "hide"; + value = QLatin1String("hide"); } QSettings settings; - settings.setValue("warnings", value); + settings.setValue(QLatin1String("warnings"), value); } void LoggerWidget::warningsPreferenceChanged(QAction *action) diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index b1a10ff6c4..236edfe5a6 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include "qdeclarativetester.h" #include @@ -67,7 +68,7 @@ void exitApp(int i) // Debugging output is not visible by default on Windows - // therefore show modal dialog with errors instead. if (!warnings.isEmpty()) { - QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings); + QMessageBox::warning(0, QApplication::translate("QDeclarativeViewer", "Qt QML Viewer"), warnings); } #endif exit(i); @@ -123,7 +124,7 @@ void myMessageOutput(QtMsgType type, const char *msg) static QDeclarativeViewer* globalViewer = 0; // The qml file that is shown if the user didn't specify a QML file -QString initialFile = "qrc:/startup/startup.qml"; +QString initialFile = QLatin1String("qrc:/startup/startup.qml"); void usage() { @@ -199,7 +200,7 @@ struct ViewerOptions fps(0.0), autorecord_from(0), autorecord_to(0), - dither("none"), + dither(QLatin1String("none")), runScript(false), devkeys(false), cache(0), @@ -336,54 +337,54 @@ static void parseCommandLineOptions(const QStringList &arguments) for (int i = 1; i < arguments.count(); ++i) { bool lastArg = (i == arguments.count() - 1); QString arg = arguments.at(i); - if (arg == "-frameless") { + if (arg == QLatin1String("-frameless")) { opts.frameless = true; - } else if (arg == "-maximized") { + } else if (arg == QLatin1String("-maximized")) { opts.maximized = true; - } else if (arg == "-fullscreen") { + } else if (arg == QLatin1String("-fullscreen")) { opts.fullScreen = true; - } else if (arg == "-stayontop") { + } else if (arg == QLatin1String("-stayontop")) { opts.stayOnTop = true; - } else if (arg == "-netcache") { + } else if (arg == QLatin1String("-netcache")) { if (lastArg) usage(); opts.cache = arguments.at(++i).toInt(); - } else if (arg == "-recordrate") { + } else if (arg == QLatin1String("-recordrate")) { if (lastArg) usage(); opts.fps = arguments.at(++i).toDouble(); - } else if (arg == "-recordfile") { + } else if (arg == QLatin1String("-recordfile")) { if (lastArg) usage(); opts.recordfile = arguments.at(++i); - } else if (arg == "-record") { + } else if (arg == QLatin1String("-record")) { if (lastArg) usage(); opts.recordargs << arguments.at(++i); - } else if (arg == "-recorddither") { + } else if (arg == QLatin1String("-recorddither")) { if (lastArg) usage(); opts.dither = arguments.at(++i); - } else if (arg == "-autorecord") { + } else if (arg == QLatin1String("-autorecord")) { if (lastArg) usage(); QString range = arguments.at(++i); - int dash = range.indexOf('-'); + int dash = range.indexOf(QLatin1Char('-')); if (dash > 0) opts.autorecord_from = range.left(dash).toInt(); opts.autorecord_to = range.mid(dash+1).toInt(); - } else if (arg == "-devicekeys") { + } else if (arg == QLatin1String("-devicekeys")) { opts.devkeys = true; - } else if (arg == "-dragthreshold") { + } else if (arg == QLatin1String("-dragthreshold")) { if (lastArg) usage(); qApp->setStartDragDistance(arguments.at(++i).toInt()); } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { qWarning("Qt QML Viewer version %s", QT_VERSION_STR); exitApp(0); - } else if (arg == "-translation") { + } else if (arg == QLatin1String("-translation")) { if (lastArg) usage(); opts.translationFile = arguments.at(++i); - } else if (arg == "-no-opengl") { + } else if (arg == QLatin1String("-no-opengl")) { opts.useGL = false; - } else if (arg == "-opengl") { + } else if (arg == QLatin1String("-opengl")) { opts.useGL = true; - } else if (arg == "-qmlbrowser") { + } else if (arg == QLatin1String("-qmlbrowser")) { opts.useNativeFileBrowser = false; - } else if (arg == "-warnings") { + } else if (arg == QLatin1String("-warnings")) { if (lastArg) usage(); QString warningsStr = arguments.at(++i); if (warningsStr == QLatin1String("show")) { @@ -393,8 +394,8 @@ static void parseCommandLineOptions(const QStringList &arguments) } else { usage(); } - } else if (arg == "-I" || arg == "-L") { - if (arg == "-L") + } else if (arg == QLatin1String("-I") || arg == QLatin1String("-L")) { + if (arg == QLatin1String("-L")) qWarning("-L option provided for compatibility only, use -I instead"); if (lastArg) { QDeclarativeEngine tmpEngine; @@ -403,32 +404,32 @@ static void parseCommandLineOptions(const QStringList &arguments) exitApp(0); } opts.imports << arguments.at(++i); - } else if (arg == "-P") { + } else if (arg == QLatin1String("-P")) { if (lastArg) usage(); opts.plugins << arguments.at(++i); - } else if (arg == "-script") { + } else if (arg == QLatin1String("-script")) { if (lastArg) usage(); opts.script = arguments.at(++i); - } else if (arg == "-scriptopts") { + } else if (arg == QLatin1String("-scriptopts")) { if (lastArg) usage(); opts.scriptopts = arguments.at(++i); - } else if (arg == "-savescript") { + } else if (arg == QLatin1String("-savescript")) { if (lastArg) usage(); opts.script = arguments.at(++i); opts.runScript = false; - } else if (arg == "-playscript") { + } else if (arg == QLatin1String("-playscript")) { if (lastArg) usage(); opts.script = arguments.at(++i); opts.runScript = true; - } else if (arg == "-sizeviewtorootobject") { + } else if (arg == QLatin1String("-sizeviewtorootobject")) { opts.sizeToView = false; - } else if (arg == "-sizerootobjecttoview") { + } else if (arg == QLatin1String("-sizerootobjecttoview")) { opts.sizeToView = true; - } else if (arg == "-experimentalgestures") { + } else if (arg == QLatin1String("-experimentalgestures")) { opts.experimentalGestures = true; - } else if (!arg.startsWith('-')) { + } else if (!arg.startsWith(QLatin1Char('-'))) { fileNames.append(arg); - } else if (true || arg == "-help") { + } else if (true || arg == QLatin1String("-help")) { usage(); } } @@ -529,29 +530,41 @@ int main(int argc, char ** argv) //### default to using raster graphics backend for now bool gsSpecified = false; for (int i = 0; i < argc; ++i) { - QString arg = argv[i]; - if (arg == "-graphicssystem") { + QString arg = QString::fromAscii(argv[i]); + if (arg == QLatin1String("-graphicssystem")) { gsSpecified = true; break; } } if (!gsSpecified) - QApplication::setGraphicsSystem("raster"); + QApplication::setGraphicsSystem(QLatin1String("raster")); #endif QDeclarativeDebugHelper::enableDebugging(); Application app(argc, argv); - app.setApplicationName("QtQmlViewer"); - app.setOrganizationName("Nokia"); - app.setOrganizationDomain("nokia.com"); + app.setApplicationName(QLatin1String("QtQmlViewer")); + app.setOrganizationName(QLatin1String("Nokia")); + app.setOrganizationDomain(QLatin1String("nokia.com")); QDeclarativeViewer::registerTypes(); QDeclarativeTester::registerTypes(); parseCommandLineOptions(app.arguments()); + QTranslator translator; + QTranslator qtTranslator; + QString sysLocale = QLocale::system().name(); + if (translator.load(QLatin1String("qmlviewer_") + 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 (!opts.translationFile.isEmpty()) { if (qmlTranslator.load(opts.translationFile)) { diff --git a/tools/qmlviewer/proxysettings.cpp b/tools/qmlviewer/proxysettings.cpp index c4dc087263..78963da9a6 100644 --- a/tools/qmlviewer/proxysettings.cpp +++ b/tools/qmlviewer/proxysettings.cpp @@ -54,17 +54,17 @@ ProxySettings::ProxySettings (QWidget * parent) #if !defined Q_WS_MAEMO_5 // the onscreen keyboard can't cope with masks - proxyServerEdit->setInputMask ("000.000.000.000;_"); + proxyServerEdit->setInputMask(QLatin1String("000.000.000.000;_")); #endif QIntValidator *validator = new QIntValidator (0, 9999, this); - proxyPortEdit->setValidator (validator); + proxyPortEdit->setValidator(validator); QSettings settings; - proxyCheckBox->setChecked (settings.value ("http_proxy/use", 0).toBool ()); - proxyServerEdit->insert (settings.value ("http_proxy/hostname", "").toString ()); - proxyPortEdit->insert (settings.value ("http_proxy/port", "80").toString ()); - usernameEdit->insert (settings.value ("http_proxy/username", "").toString ()); - passwordEdit->insert (settings.value ("http_proxy/password", "").toString ()); + proxyCheckBox->setChecked(settings.value(QLatin1String("http_proxy/use"), 0).toBool()); + proxyServerEdit->insert(settings.value(QLatin1String("http_proxy/hostname")).toString()); + proxyPortEdit->insert(settings.value(QLatin1String("http_proxy/port"), QLatin1String("80")).toString ()); + usernameEdit->insert(settings.value(QLatin1String("http_proxy/username")).toString ()); + passwordEdit->insert(settings.value(QLatin1String("http_proxy/password")).toString ()); } ProxySettings::~ProxySettings() @@ -75,11 +75,11 @@ void ProxySettings::accept () { QSettings settings; - settings.setValue ("http_proxy/use", proxyCheckBox->isChecked ()); - settings.setValue ("http_proxy/hostname", proxyServerEdit->text ()); - settings.setValue ("http_proxy/port", proxyPortEdit->text ()); - settings.setValue ("http_proxy/username", usernameEdit->text ()); - settings.setValue ("http_proxy/password", passwordEdit->text ()); + settings.setValue(QLatin1String("http_proxy/use"), proxyCheckBox->isChecked()); + settings.setValue(QLatin1String("http_proxy/hostname"), proxyServerEdit->text()); + settings.setValue(QLatin1String("http_proxy/port"), proxyPortEdit->text()); + settings.setValue(QLatin1String("http_proxy/username"), usernameEdit->text()); + settings.setValue(QLatin1String("http_proxy/password"), passwordEdit->text()); QDialog::accept (); } @@ -89,13 +89,13 @@ QNetworkProxy ProxySettings::httpProxy () QSettings settings; QNetworkProxy proxy; - bool proxyInUse = settings.value ("http_proxy/use", 0).toBool (); + bool proxyInUse = settings.value(QLatin1String("http_proxy/use"), 0).toBool(); if (proxyInUse) { proxy.setType (QNetworkProxy::HttpProxy); - proxy.setHostName (settings.value ("http_proxy/hostname", "").toString ());// "192.168.220.5" - proxy.setPort (settings.value ("http_proxy/port", 80).toInt ()); // 8080 - proxy.setUser (settings.value ("http_proxy/username", "").toString ()); - proxy.setPassword (settings.value ("http_proxy/password", "").toString ()); + proxy.setHostName (settings.value(QLatin1String("http_proxy/hostname")).toString());// "192.168.220.5" + proxy.setPort (settings.value(QLatin1String("http_proxy/port"), 80).toInt()); // 8080 + proxy.setUser (settings.value(QLatin1String("http_proxy/username")).toString()); + proxy.setPassword (settings.value(QLatin1String("http_proxy/password")).toString()); //QNetworkProxy::setApplicationProxy (proxy); } else { @@ -107,7 +107,7 @@ QNetworkProxy ProxySettings::httpProxy () bool ProxySettings::httpProxyInUse() { QSettings settings; - return settings.value ("http_proxy/use", 0).toBool (); + return settings.value(QLatin1String("http_proxy/use"), 0).toBool(); } QT_END_NAMESPACE diff --git a/tools/qmlviewer/proxysettings_maemo5.ui b/tools/qmlviewer/proxysettings_maemo5.ui index 83f0c2a9de..75875d835b 100644 --- a/tools/qmlviewer/proxysettings_maemo5.ui +++ b/tools/qmlviewer/proxysettings_maemo5.ui @@ -6,8 +6,8 @@ 0 0 - 449 - 164 + 447 + 162 @@ -88,7 +88,7 @@ - 8080 + 8080 diff --git a/tools/qmlviewer/qdeclarativetester.cpp b/tools/qmlviewer/qdeclarativetester.cpp index 11f81fc169..fa8af8f314 100644 --- a/tools/qmlviewer/qdeclarativetester.cpp +++ b/tools/qmlviewer/qdeclarativetester.cpp @@ -205,7 +205,7 @@ void QDeclarativeTester::save() QString filename = m_script + QLatin1String(".qml"); QFileInfo filenameInfo(filename); QDir saveDir = filenameInfo.absoluteDir(); - saveDir.mkpath("."); + saveDir.mkpath(QLatin1String(".")); QFile file(filename); file.open(QIODevice::WriteOnly); @@ -224,8 +224,8 @@ void QDeclarativeTester::save() if (!fe.hash.isEmpty()) { ts << " hash: \"" << fe.hash.toHex() << "\"\n"; } else if (!fe.image.isNull()) { - QString filename = filenameInfo.baseName() + "." + QString::number(imgCount) + ".png"; - fe.image.save(m_script + "." + QString::number(imgCount) + ".png"); + QString filename = filenameInfo.baseName() + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png"); + fe.image.save(m_script + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png")); imgCount++; ts << " image: \"" << filename << "\"\n"; } @@ -375,7 +375,7 @@ void QDeclarativeTester::updateCurrentTime(int msec) imagefailure(); } if (goodImage != img) { - QString reject(frame->image().toLocalFile() + ".reject.png"); + QString reject(frame->image().toLocalFile() + QLatin1String(".reject.png")); qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch. Reject saved to:" << reject; img.save(reject); @@ -393,7 +393,7 @@ void QDeclarativeTester::updateCurrentTime(int msec) } } } - QString diff(frame->image().toLocalFile() + ".diff.png"); + QString diff(frame->image().toLocalFile() + QLatin1String(".diff.png")); diffimg.save(diff); qWarning().nospace() << " Diff (" << diffCount << " pixels differed) saved to: " << diff; } diff --git a/tools/qmlviewer/qmlruntime.cpp b/tools/qmlviewer/qmlruntime.cpp index 4bae7f3ec0..e49c7f3d42 100644 --- a/tools/qmlviewer/qmlruntime.cpp +++ b/tools/qmlviewer/qmlruntime.cpp @@ -265,7 +265,7 @@ public: hz->setValidator(new QDoubleValidator(hz)); #endif for (int i=0; ffmpegprofiles[i].name; ++i) { - profile->addItem(ffmpegprofiles[i].name); + profile->addItem(QString::fromAscii(ffmpegprofiles[i].name)); } } @@ -273,9 +273,9 @@ public: { int i; for (i=0; ffmpegprofiles[i].args[0]; ++i) { - if (ffmpegprofiles[i].args == a) { + if (QString::fromAscii(ffmpegprofiles[i].args) == a) { profile->setCurrentIndex(i); - args->setText(QLatin1String(ffmpegprofiles[i].args)); + args->setText(QString::fromAscii(ffmpegprofiles[i].args)); return; } } @@ -465,14 +465,14 @@ private: } } QSettings settings; - settings.setValue("Cookies",data); + settings.setValue(QLatin1String("Cookies"), data); } void load() { QMutexLocker lock(&mutex); QSettings settings; - QByteArray data = settings.value("Cookies").toByteArray(); + QByteArray data = settings.value(QLatin1String("Cookies")).toByteArray(); setAllCookies(QNetworkCookie::parseCookies(data)); } @@ -490,7 +490,7 @@ public: if (proxyDirty) setupProxy(); QString protocolTag = query.protocolTag(); - if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) { + if (httpProxyInUse && (protocolTag == QLatin1String("http") || protocolTag == QLatin1String("https"))) { QList ret; ret << httpProxy; return ret; @@ -597,7 +597,7 @@ QString QDeclarativeViewer::getVideoFileName() if (convertAvailable) types += tr("GIF Animation")+QLatin1String(" (*.gif)"); types += tr("Individual PNG frames")+QLatin1String(" (*.png)"); if (ffmpegAvailable) types += tr("All ffmpeg formats (*.*)"); - return QFileDialog::getSaveFileName(this, title, "", types.join(";; ")); + return QFileDialog::getSaveFileName(this, title, QString(), types.join(QLatin1String(";; "))); } QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) @@ -725,18 +725,18 @@ void QDeclarativeViewer::createMenu() connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this); - snapshotAction->setShortcut(QKeySequence("F3")); + snapshotAction->setShortcut(QKeySequence(tr("F3"))); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); recordAction = new QAction(tr("Start Recording &Video"), this); - recordAction->setShortcut(QKeySequence("F9")); + recordAction->setShortcut(QKeySequence(tr("F9"))); connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection())); QAction *recordOptions = new QAction(tr("Video &Options..."), this); connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions())); QAction *slowAction = new QAction(tr("&Slow Down Animations"), this); - slowAction->setShortcut(QKeySequence("Ctrl+.")); + slowAction->setShortcut(QKeySequence(tr("Ctrl+."))); slowAction->setCheckable(true); connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); @@ -755,7 +755,7 @@ void QDeclarativeViewer::createMenu() connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen())); rotateAction = new QAction(tr("Rotate orientation"), this); - rotateAction->setShortcut(QKeySequence("Ctrl+T")); + rotateAction->setShortcut(QKeySequence(tr("Ctrl+T"))); connect(rotateAction, SIGNAL(triggered()), this, SLOT(rotateOrientation())); orientation = new QActionGroup(this); @@ -963,7 +963,7 @@ void QDeclarativeViewer::chooseRecordingOptions() // Profile - recdlg->setArguments(record_args.join(" ")); + recdlg->setArguments(record_args.join(QLatin1String(" "))); if (recdlg->exec()) { // File record_file = recdlg->file->text(); @@ -972,7 +972,7 @@ void QDeclarativeViewer::chooseRecordingOptions() // Rate record_rate = recdlg->videoRate(); // Profile - record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts); + record_args = recdlg->arguments().split(QLatin1Char(' '),QString::SkipEmptyParts); } } @@ -983,8 +983,8 @@ void QDeclarativeViewer::toggleRecordingWithSelection() QString fileName = getVideoFileName(); if (fileName.isEmpty()) return; - if (!fileName.contains(QRegExp(".[^\\/]*$"))) - fileName += ".avi"; + if (!fileName.contains(QRegExp(QLatin1String(".[^\\/]*$")))) + fileName += QLatin1String(".avi"); setRecordFile(fileName); } } @@ -1026,7 +1026,7 @@ void QDeclarativeViewer::openFile() { QString cur = canvas->source().toLocalFile(); if (useQmlFileBrowser) { - open("qrc:/browser/Browser.qml"); + open(QLatin1String("qrc:/browser/Browser.qml")); } else { QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); if (!fileName.isEmpty()) { @@ -1072,7 +1072,7 @@ void QDeclarativeViewer::loadTranslationFile(const QString& directory) void QDeclarativeViewer::loadDummyDataFiles(const QString& directory) { - QDir dir(directory+"/dummydata", "*.qml"); + QDir dir(directory + QLatin1String("/dummydata"), QLatin1String("*.qml")); QStringList list = dir.entryList(); for (int i = 0; i < list.size(); ++i) { QString qml = list.at(i); @@ -1114,14 +1114,14 @@ bool QDeclarativeViewer::open(const QString& file_or_url) delete canvas->rootObject(); canvas->engine()->clearComponentCache(); QDeclarativeContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("qmlViewer", this); + ctxt->setContextProperty(QLatin1String("qmlViewer"), this); #ifdef Q_OS_SYMBIAN - ctxt->setContextProperty("qmlViewerFolder", "E:\\"); // Documents on your S60 phone + ctxt->setContextProperty(QLatin1String("qmlViewerFolder"), QLatin1String("E:\\")); // Documents on your S60 phone #else - ctxt->setContextProperty("qmlViewerFolder", QDir::currentPath()); + ctxt->setContextProperty(QLatin1String("qmlViewerFolder"), QDir::currentPath()); #endif - ctxt->setContextProperty("runtime", Runtime::instance()); + ctxt->setContextProperty(QLatin1String("runtime"), Runtime::instance()); QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { @@ -1224,26 +1224,26 @@ bool QDeclarativeViewer::event(QEvent *event) void QDeclarativeViewer::senseImageMagick() { QProcess proc; - proc.start("convert", QStringList() << "-h"); + proc.start(QLatin1String("convert"), QStringList() << QLatin1String("-h")); proc.waitForFinished(2000); - QString help = proc.readAllStandardOutput(); - convertAvailable = help.contains("ImageMagick"); + QString help = QString::fromAscii(proc.readAllStandardOutput()); + convertAvailable = help.contains(QLatin1String("ImageMagick")); } void QDeclarativeViewer::senseFfmpeg() { QProcess proc; - proc.start("ffmpeg", QStringList() << "-h"); + proc.start(QLatin1String("ffmpeg"), QStringList() << QLatin1String("-h")); proc.waitForFinished(2000); - QString ffmpegHelp = proc.readAllStandardOutput(); - ffmpegAvailable = ffmpegHelp.contains("-s "); - ffmpegHelp = tr("Video recording uses ffmpeg:")+"\n\n"+ffmpegHelp; + QString ffmpegHelp = QString::fromAscii(proc.readAllStandardOutput()); + ffmpegAvailable = ffmpegHelp.contains(QLatin1String("-s ")); + ffmpegHelp = tr("Video recording uses ffmpeg:") + QLatin1String("\n\n") + ffmpegHelp; QDialog *d = new QDialog(recdlg); QVBoxLayout *l = new QVBoxLayout(d); QTextBrowser *b = new QTextBrowser(d); QFont f = b->font(); - f.setFamily("courier"); + f.setFamily(QLatin1String("courier")); b->setFont(f); b->setText(ffmpegHelp); l->addWidget(b); @@ -1266,7 +1266,7 @@ void QDeclarativeViewer::setRecording(bool on) recordTimer.start(); frame_fmt = record_file.right(4).toLower(); frame = QImage(canvas->width(),canvas->height(),QImage::Format_RGB32); - if (frame_fmt != ".png" && (!convertAvailable || frame_fmt != ".gif")) { + if (frame_fmt != QLatin1String(".png") && (!convertAvailable || frame_fmt != QLatin1String(".gif"))) { // Stream video to ffmpeg QProcess *proc = new QProcess(this); @@ -1274,19 +1274,19 @@ void QDeclarativeViewer::setRecording(bool on) frame_stream = proc; QStringList args; - args << "-y"; - args << "-r" << QString::number(record_rate); - args << "-f" << "rawvideo"; - args << "-pix_fmt" << (frame_fmt == ".gif" ? "rgb24" : "rgb32"); - args << "-s" << QString("%1x%2").arg(canvas->width()).arg(canvas->height()); - args << "-i" << "-"; + args << QLatin1String("-y"); + args << QLatin1String("-r") << QString::number(record_rate); + args << QLatin1String("-f") << QLatin1String("rawvideo"); + args << QLatin1String("-pix_fmt") << (frame_fmt == QLatin1String(".gif") ? QLatin1String("rgb24") : QLatin1String("rgb32")); + args << QLatin1String("-s") << QString::fromAscii("%1x%2").arg(canvas->width()).arg(canvas->height()); + args << QLatin1String("-i") << QLatin1String("-"); if (record_outsize.isValid()) { - args << "-s" << QString("%1x%2").arg(record_outsize.width()).arg(record_outsize.height()); - args << "-aspect" << QString::number(double(canvas->width())/canvas->height()); + args << QLatin1String("-s") << QString::fromAscii("%1x%2").arg(record_outsize.width()).arg(record_outsize.height()); + args << QLatin1String("-aspect") << QString::number(double(canvas->width())/canvas->height()); } args += record_args; args << record_file; - proc->start("ffmpeg",args); + proc->start(QLatin1String("ffmpeg"), args); } else { // Store frames, save to GIF/PNG @@ -1309,14 +1309,14 @@ void QDeclarativeViewer::setRecording(bool on) QString framename; bool png_output = false; - if (record_file.right(4).toLower()==".png") { - if (record_file.contains('%')) + if (record_file.right(4).toLower() == QLatin1String(".png")) { + if (record_file.contains(QLatin1Char('%'))) framename = record_file; else - framename = record_file.left(record_file.length()-4)+"%04d"+record_file.right(4); + framename = record_file.left(record_file.length()-4) + QLatin1String("%04d") + record_file.right(4); png_output = true; } else { - framename = "tmp-frame%04d.png"; + framename = QLatin1String("tmp-frame%04d.png"); png_output = false; } foreach (QImage* img, frames) { @@ -1327,11 +1327,11 @@ void QDeclarativeViewer::setRecording(bool on) name.sprintf(framename.toLocal8Bit(),frame++); if (record_outsize.isValid()) *img = img->scaled(record_outsize,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); - if (record_dither=="ordered") + if (record_dither==QLatin1String("ordered")) img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::OrderedDither).save(name); - else if (record_dither=="threshold") + else if (record_dither==QLatin1String("threshold")) img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::ThresholdDither).save(name); - else if (record_dither=="floyd") + else if (record_dither==QLatin1String("floyd")) img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither).save(name); else img->save(name); @@ -1341,25 +1341,26 @@ void QDeclarativeViewer::setRecording(bool on) if (!progress.wasCanceled()) { if (png_output) { - framename.replace(QRegExp("%\\d*."),"*"); + framename.replace(QRegExp(QLatin1String("%\\d*.")), QLatin1String("*")); qDebug() << "Wrote frames" << framename; inputs.clear(); // don't remove them } else { // ImageMagick and gifsicle for GIF encoding progress.setLabelText(tr("Converting frames to GIF file...")); QStringList args; - args << "-delay" << QString::number(period/10); + args << QLatin1String("-delay") << QString::number(period/10); args << inputs; args << record_file; qDebug() << "Converting..." << record_file << "(this may take a while)"; - if (0!=QProcess::execute("convert", args)) { + if (0!=QProcess::execute(QLatin1String("convert"), args)) { qWarning() << "Cannot run ImageMagick 'convert' - recorded frames not converted"; inputs.clear(); // don't remove them qDebug() << "Wrote frames tmp-frame*.png"; } else { - if (record_file.right(4).toLower() == ".gif") { + if (record_file.right(4).toLower() == QLatin1String(".gif")) { qDebug() << "Compressing..." << record_file; - if (0!=QProcess::execute("gifsicle", QStringList() << "-O2" << "-o" << record_file << record_file)) + if (0!=QProcess::execute(QLatin1String("gifsicle"), QStringList() << QLatin1String("-O2") + << QLatin1String("-o") << record_file << record_file)) qWarning() << "Cannot run 'gifsicle' - not compressed"; } qDebug() << "Wrote" << record_file; @@ -1410,7 +1411,7 @@ void QDeclarativeViewer::recordFrame() { canvas->QWidget::render(&frame); if (frame_stream) { - if (frame_fmt == ".gif") { + if (frame_fmt == QLatin1String(".gif")) { // ffmpeg can't do 32bpp with gif QImage rgb24 = frame.convertToFormat(QImage::Format_RGB888); frame_stream->write((char*)rgb24.bits(),rgb24.numBytes()); @@ -1542,8 +1543,8 @@ void QDeclarativeViewer::registerTypes() if (!registered) { // registering only for exposing the DeviceOrientation::Orientation enum - qmlRegisterUncreatableType("Qt",4,7,"Orientation",""); - qmlRegisterUncreatableType("QtQuick",1,0,"Orientation",""); + qmlRegisterUncreatableType("Qt", 4, 7, "Orientation", QString()); + qmlRegisterUncreatableType("QtQuick", 1, 0, "Orientation", QString()); registered = true; } } diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index a185bdc9b4..87b5899fcc 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -10,6 +10,8 @@ INCLUDEPATH += ../../include/QtDeclarative INCLUDEPATH += ../../src/declarative/util INCLUDEPATH += ../../src/declarative/graphicsitems +DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII + target.path = $$[QT_INSTALL_BINS] INSTALLS += target -- cgit v1.2.3 From 21deca53df68504f06d71f7b7ce4a4bfde2da0ef Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 10 May 2011 11:42:03 +0200 Subject: QmlViewer: Remove one call to enableDebugging Merge f9b198987d2 resulted in two calls of the method. Reviewed-by: TrustMe --- tools/qmlviewer/main.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools') diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 236edfe5a6..24a4940915 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -522,8 +522,6 @@ QDeclarativeViewer *openFile(const QString &fileName) int main(int argc, char ** argv) { - QDeclarativeDebugHelper::enableDebugging(); - systemMsgOutput = qInstallMsgHandler(myMessageOutput); #if defined (Q_WS_X11) || defined (Q_WS_MAC) -- cgit v1.2.3 From daf671b42241533a2db1e598487256d616edf290 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Fri, 20 May 2011 11:57:29 +1000 Subject: Integrate QtQuickTest into Qt Change-Id: I558821c0dec9166ea1d0d2e1e2f889553c436316 Task-number:QTBUG-16082 --- tools/qmltestrunner/main.cpp | 75 +++++++++++++++++++++++++++++++++++ tools/qmltestrunner/qmltestrunner.pro | 11 +++++ tools/tools.pro | 2 + 3 files changed, 88 insertions(+) create mode 100644 tools/qmltestrunner/main.cpp create mode 100644 tools/qmltestrunner/qmltestrunner.pro (limited to 'tools') diff --git a/tools/qmltestrunner/main.cpp b/tools/qmltestrunner/main.cpp new file mode 100644 index 0000000000..47f34ee65e --- /dev/null +++ b/tools/qmltestrunner/main.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#ifdef QT_OPENGL_LIB +#include +#endif + +#ifdef QT_OPENGL_LIB + +static QWidget *qmltestrunner_create_gl_viewport() +{ + return new QGLWidget(); +} + +#endif + +int main(int argc, char **argv) +{ +#ifdef QT_OPENGL_LIB + bool isOpenGL = false; + for (int index = 1; index < argc; ++index) { + if (strcmp(argv[index], "-opengl") == 0) { + isOpenGL = true; + break; + } + } + if (isOpenGL) { + return quick_test_main(argc, argv, "qmltestrunner", + qmltestrunner_create_gl_viewport, "."); + } else +#endif + { + return quick_test_main(argc, argv, "qmltestrunner", 0, "."); + } +} diff --git a/tools/qmltestrunner/qmltestrunner.pro b/tools/qmltestrunner/qmltestrunner.pro new file mode 100644 index 0000000000..b2aabf6355 --- /dev/null +++ b/tools/qmltestrunner/qmltestrunner.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = qmltestrunner +CONFIG += warn_on qmltestcase +SOURCES += main.cpp + +contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) { + QT += opengl +} + +target.path = $$[QT_INSTALL_BINS] +INSTALLS += target diff --git a/tools/tools.pro b/tools/tools.pro index ec83a1e76a..b1a896b7f8 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -1,2 +1,4 @@ TEMPLATE = subdirs SUBDIRS += qmlviewer qmlscene qmlplugindump +contains(QT_CONFIG, quicktest): SUBDIRS += qmltestrunner + -- cgit v1.2.3 From 7aed0fc2d0176d82f9ebd10857d3d6fe7b24b026 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Mon, 23 May 2011 21:41:19 +1000 Subject: qmltestrunner not installed by default --- tools/tools.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/tools.pro b/tools/tools.pro index b1a896b7f8..dccdce8160 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs SUBDIRS += qmlviewer qmlscene qmlplugindump -contains(QT_CONFIG, quicktest): SUBDIRS += qmltestrunner +contains(QT_CONFIG, qmltest): SUBDIRS += qmltestrunner -- cgit v1.2.3 From 285d89eed4801f6e5f78057e7b082cab6b3fa03e Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 27 May 2011 16:31:50 +1000 Subject: Work around remaining 'make check' failures. Change-Id: Ie4480d4f05f5d784eb277fa2be6e502da00524f8 --- tools/qmltestrunner/qmltestrunner.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/qmltestrunner/qmltestrunner.pro b/tools/qmltestrunner/qmltestrunner.pro index b2aabf6355..7ace0f7358 100644 --- a/tools/qmltestrunner/qmltestrunner.pro +++ b/tools/qmltestrunner/qmltestrunner.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = qmltestrunner -CONFIG += warn_on qmltestcase +CONFIG += warn_on SOURCES += main.cpp contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) { -- cgit v1.2.3 From b3aae617644ffdfb760bf21521d9841c6408fe19 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Mon, 30 May 2011 09:40:45 +1000 Subject: fix the qmltestrunner building errors Change-Id: Ib544544615d8aa96d2e5af8c82766472e1ed4018 --- tools/qmltestrunner/qmltestrunner.pro | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/qmltestrunner/qmltestrunner.pro b/tools/qmltestrunner/qmltestrunner.pro index 7ace0f7358..c431aafcb5 100644 --- a/tools/qmltestrunner/qmltestrunner.pro +++ b/tools/qmltestrunner/qmltestrunner.pro @@ -3,9 +3,10 @@ TARGET = qmltestrunner CONFIG += warn_on SOURCES += main.cpp -contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) { - QT += opengl -} + +QT += declarative qmltest + +DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$OUT_PWD\\\"\" target.path = $$[QT_INSTALL_BINS] INSTALLS += target -- cgit v1.2.3 From 609c3920cd90181e59d9a699cee632bcbf68366b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 30 May 2011 09:24:20 +0200 Subject: qmlplugindump: Dump revision property. Mirrors a change to qmldump in qt-creator/6e3274240077fc356a37d3de735b3b2da9654d2e Reviewed-by: Roberto Raggi (cherry picked from commit b0392d398e2f28682cdce6e85546d38a838440f7) --- tools/qmlplugindump/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tools') diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index c2d2681b42..e6bf24c316 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -336,6 +336,10 @@ private: qml->writeStartObject("Property"); qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(prop.name()))); +#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4)) + if (int revision = prop.revision()) + qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision)); +#endif writeTypeProperties(prop.typeName(), prop.isWritable()); qml->writeEndObject(); @@ -364,6 +368,11 @@ private: qml->writeScriptBinding(QLatin1String("name"), enquote(name)); +#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4)) + if (int revision = meth.revision()) + qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision)); +#endif + const QString typeName = convertToId(meth.typeName()); if (! typeName.isEmpty()) qml->writeScriptBinding(QLatin1String("type"), enquote(typeName)); -- cgit v1.2.3 From 3fb35b37a00735bd9573c60d629a15a54bdf80be Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 30 May 2011 10:20:29 +0200 Subject: qmlplugindump: Bump QtQuick.tooling version to 1.1. Mirrors a change to qmlplugindump in qtcreator/715cee76a9e46efb7f8245004aaa8a1c47b1618d Reviewed-by: Kai Koehne (cherry picked from commit 10f16bc55b9e5535bc3353260f97a32e18d70cf1) --- tools/qmlplugindump/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index e6bf24c316..dda5d3da87 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -510,7 +510,7 @@ int main(int argc, char *argv[]) engine->addImportPath(pluginImportPath); // find all QMetaObjects reachable from the builtin module - QByteArray importCode("import QtQuick 1.0\n"); + QByteArray importCode("import QtQuick 1.1\n"); QSet defaultReachable = collectReachableMetaObjects(importCode, engine); // this will hold the meta objects we want to dump information of -- cgit v1.2.3