tools/qml/main.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    47 #include <QDir>
    47 #include <QDir>
    48 #include <QApplication>
    48 #include <QApplication>
    49 #include <QTranslator>
    49 #include <QTranslator>
    50 #include <QDebug>
    50 #include <QDebug>
    51 #include <QMessageBox>
    51 #include <QMessageBox>
       
    52 #include <QAtomicInt>
    52 #include "qdeclarativetester.h"
    53 #include "qdeclarativetester.h"
    53 
    54 
    54 QT_USE_NAMESPACE
    55 QT_USE_NAMESPACE
    55 
    56 
    56 QtMsgHandler systemMsgOutput = 0;
    57 QtMsgHandler systemMsgOutput = 0;
       
    58 
       
    59 
    57 
    60 
    58 #if defined (Q_OS_SYMBIAN)
    61 #if defined (Q_OS_SYMBIAN)
    59 #include <unistd.h>
    62 #include <unistd.h>
    60 #include <sys/types.h>
    63 #include <sys/types.h>
    61 #include <sys/stat.h>
    64 #include <sys/stat.h>
    87     if (!warnings.isEmpty()) {
    90     if (!warnings.isEmpty()) {
    88         QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings);
    91         QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings);
    89     }
    92     }
    90 }
    93 }
    91 
    94 
       
    95 static QAtomicInt recursiveLock(0);
       
    96 
    92 void myMessageOutput(QtMsgType type, const char *msg)
    97 void myMessageOutput(QtMsgType type, const char *msg)
    93 {
    98 {
    94     if (!logger.isNull()) {
    99     QString strMsg = QString::fromLatin1(msg);
    95         QString strMsg = QString::fromAscii(msg);
   100 
    96         QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg));
   101     if (!logger.isNull() && !QCoreApplication::closingDown()) {
       
   102         if (recursiveLock.testAndSetOrdered(0, 1)) {
       
   103             QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg));
       
   104             recursiveLock = 0;
       
   105         }
    97     } else {
   106     } else {
    98         warnings += msg;
   107         warnings += strMsg;
    99         warnings += QLatin1Char('\n');
   108         warnings += QLatin1Char('\n');
   100     }
   109     }
   101     if (systemMsgOutput) { // Windows
   110     if (systemMsgOutput) { // Windows
   102         systemMsgOutput(type, msg);
   111         systemMsgOutput(type, msg);
   103     } else { // Unix
   112     } else { // Unix
   104         fprintf(stderr, "%s\n",msg);
   113         fprintf(stderr, "%s\n", msg);
   105         fflush(stderr);
   114         fflush(stderr);
   106     }
   115     }
   107 }
   116 }
   108 
   117 
   109 #endif
   118 #endif
   117     qWarning("  -frameless ............................... run with no window frame");
   126     qWarning("  -frameless ............................... run with no window frame");
   118     qWarning("  -maximized................................ run maximized");
   127     qWarning("  -maximized................................ run maximized");
   119     qWarning("  -fullscreen............................... run fullscreen");
   128     qWarning("  -fullscreen............................... run fullscreen");
   120     qWarning("  -stayontop................................ keep viewer window on top");
   129     qWarning("  -stayontop................................ keep viewer window on top");
   121     qWarning("  -sizeviewtorootobject .................... the view resizes to the changes in the content");
   130     qWarning("  -sizeviewtorootobject .................... the view resizes to the changes in the content");
   122     qWarning("  -sizerootobjecttoview .................... the content resizes to the changes in the view");
   131     qWarning("  -sizerootobjecttoview .................... the content resizes to the changes in the view (default)");
   123     qWarning("  -qmlbrowser .............................. use a QML-based file browser");
   132     qWarning("  -qmlbrowser .............................. use a QML-based file browser");
   124     qWarning("  -warnings [show|hide]..................... show warnings in a separate log window");
   133     qWarning("  -warnings [show|hide]..................... show warnings in a separate log window");
   125     qWarning("  -recordfile <output> ..................... set video recording file");
   134     qWarning("  -recordfile <output> ..................... set video recording file");
   126     qWarning("                                              - ImageMagick 'convert' for GIF)");
   135     qWarning("                                              - ImageMagick 'convert' for GIF)");
   127     qWarning("                                              - png file for raw frames");
   136     qWarning("                                              - png file for raw frames");
   198     QApplication app(argc, argv);
   207     QApplication app(argc, argv);
   199     app.setApplicationName("QtQmlViewer");
   208     app.setApplicationName("QtQmlViewer");
   200     app.setOrganizationName("Nokia");
   209     app.setOrganizationName("Nokia");
   201     app.setOrganizationDomain("nokia.com");
   210     app.setOrganizationDomain("nokia.com");
   202 
   211 
       
   212 
       
   213     
   203     QDeclarativeViewer::registerTypes();
   214     QDeclarativeViewer::registerTypes();
   204     QDeclarativeTester::registerTypes();
   215     QDeclarativeTester::registerTypes();
   205 
   216 
   206     bool frameless = false;
   217     bool frameless = false;
   207     QString fileName;
   218     QString fileName;
   345     Qt::WFlags wflags = (frameless ? Qt::FramelessWindowHint : Qt::Widget);
   356     Qt::WFlags wflags = (frameless ? Qt::FramelessWindowHint : Qt::Widget);
   346     if (stayOnTop)
   357     if (stayOnTop)
   347         wflags |= Qt::WindowStaysOnTopHint;
   358         wflags |= Qt::WindowStaysOnTopHint;
   348 
   359 
   349     QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
   360     QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
       
   361     viewer->setAttribute(Qt::WA_DeleteOnClose, true);
   350     if (!scriptopts.isEmpty()) {
   362     if (!scriptopts.isEmpty()) {
   351         QStringList options = 
   363         QStringList options =
   352             scriptopts.split(QLatin1Char(','), QString::SkipEmptyParts);
   364             scriptopts.split(QLatin1Char(','), QString::SkipEmptyParts);
   353 
   365 
   354         QDeclarativeViewer::ScriptOptions scriptOptions = 0;
   366         QDeclarativeViewer::ScriptOptions scriptOptions = 0;
   355         for (int i = 0; i < options.count(); ++i) {
   367         for (int i = 0; i < options.count(); ++i) {
   356             const QString &option = options.at(i);
   368             const QString &option = options.at(i);
   449             viewer->openFile();
   461             viewer->openFile();
   450     }
   462     }
   451     viewer->setUseGL(useGL);
   463     viewer->setUseGL(useGL);
   452     viewer->raise();
   464     viewer->raise();
   453 
   465 
   454     int rv = app.exec();
   466     return app.exec();
   455     delete viewer;
   467 }
   456     exit(rv);
       
   457 }