Exemple #1
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
    qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice");

    Configuration m_configuration;
    SerialLink m_serialLink;
    MavLinkManager m_mavlink_manager;

    LinkManager m_gLinkManager;

    QtQuick2ApplicationViewer viewer;
    QtQuick2ApplicationViewer splashscreen;

    QString customPath = "Sqlite/OfflineStorage";
    QDir dir;
    if(dir.mkpath(QString(customPath))){
//        qDebug() << "Default path >> "+viewer.engine()->offlineStoragePath();
        viewer.engine()->setOfflineStoragePath(QString(customPath));
//        qDebug() << "New path >> "+viewer.engine()->offlineStoragePath();
    }
    // using as normal
//    viewer.setMainQmlFile(QStringLiteral("qml/gStabiSC/main.qml"));
    // using qml files form resources file, uncomment this to compile all qml file to .exe

    splashscreen.setSource(QUrl("qrc:/qml/gStabiSC/GSplashScreen.qml"));
    splashscreen.setFlags(Qt::FramelessWindowHint);
    splashscreen.setMinimumSize(QSize(1000,500));
    splashscreen.show();


    viewer.setSource(QUrl("qrc:/qml/gStabiSC/GMain.qml"));
    viewer.setTitle(QString("%1 %2").arg(APPLICATION_NAME).arg(APPLICATION_VERSION));
    viewer.setMinimumSize(QSize(APPLICATION_WIDTH,APPLICATION_HEIGHT));
    viewer.setMaximumSize(QSize(APPLICATION_WIDTH,APPLICATION_HEIGHT));

//    viewer.addImportPath("qrc:/qml/gStabiSC");
//    viewer.addImportPath("qrc:/qml/gStabiSC/Components");
//    viewer.addImportPath("qrc:/qml/gStabiSC/GDashboard");
//    viewer.addImportPath("qrc:/javascript/storage.js");

    viewer.rootContext()->setContextProperty("_configuration",&m_configuration);
    viewer.rootContext()->setContextProperty("_serialLink", &m_serialLink);
    viewer.rootContext()->setContextProperty("_mavlink_manager", &m_mavlink_manager);

    m_gLinkManager.connectLink(&m_serialLink,&m_mavlink_manager);

    QTimer::singleShot(3000, &splashscreen, SLOT(close()));
    QTimer::singleShot(3000, &viewer, SLOT(show()));

    return app.exec();
}
Exemple #2
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QtQuick2ApplicationViewer viewer;

    NestedListModel* platforms = new NestedListModel(new UPlatform);

    UPlatform* platform1 = createPlatform(platforms, 1);
    UPlatform* platform2 = createPlatform(platforms, 2);
    UPlatform* platform3 = createPlatform(platforms, 3);

    ListModel* devices1 = platform1->nestedModel();
    ListModel* devices2 = platform2->nestedModel();
    ListModel* devices3 = platform3->nestedModel();

    UDevice* device1 = createDevice(devices1, 1);
    UDevice* device2 = createDevice(devices2, 2);
    UDevice* device3 = createDevice(devices3, 3);

    ListModel* scenarios1 = device1->nestedModel();
    ListModel* scenarios2 = device2->nestedModel();
    ListModel* scenarios3 = device3->nestedModel();

    UScenario* scenario1 = createScenario(scenarios1, 1);
    UScenario* scenario2 = createScenario(scenarios2, 2);
    UScenario* scenario3 = createScenario(scenarios3, 3);

    ListModel* tasks1 = scenario1->nestedModel();
    ListModel* tasks2 = scenario2->nestedModel();
    ListModel* tasks3 = scenario3->nestedModel();

    UTask* taks1 = createTask(tasks1, 1);
    UTask* taks2 = createTask(tasks2, 2);
    UTask* taks3 = createTask(tasks3, 3);

    ListModel* conditions1 = taks1->nestedModel();
    ListModel* conditions2 = taks2->nestedModel();
    ListModel* conditions3 = taks3->nestedModel();

    createCondition(conditions1, 1);
    createCondition(conditions2, 2);
    createCondition(conditions3, 3);

    QQmlContext* ctxt = viewer.rootContext();
    ctxt->setContextProperty("platformsModel", platforms);

    viewer.setSource(QUrl("qrc:///main.qml"));
    viewer.show();

    return app.exec();
}
Exemple #3
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer *viewer = new QtQuick2ApplicationViewer;

    qmlRegisterType<BrowserDbus>("browserdbusinterface",1,0,"BrowserInterface");
    qmlRegisterType<Bookmark>("browserdbusinterface",1,0,"Tmp");

    viewer->setMainQmlFile(QStringLiteral("qml/demoui/main.qml"));
    viewer->setFlags(Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint);
    viewer->setGeometry(0, 0, 1024, 80);
    viewer->show();

    QObject::connect((QObject*)viewer->rootObject(), SIGNAL(bookmarksopen(bool)),(QObject*)viewer, SLOT(changeGeometry(bool)));

    return app.exec();
}
Exemple #4
0
int main(int argc, char *argv[])
{
    QOptions options(get_common_options());
    options.add(QLatin1String("QMLPlayer options"))
            ("scale", 1.0, QLatin1String("scale of graphics context. 0: auto"))
            ;
    options.parse(argc, argv);
    if (options.value(QLatin1String("help")).toBool()) {
        options.print();
        return 0;
    }

    QGuiApplication app(argc, argv);
    QDir::setCurrent(qApp->applicationDirPath());
    qDebug() << "arguments======= " << app.arguments();
    set_opengl_backend(options.option(QStringLiteral("gl")).value().toString(), app.arguments().first());
    load_qm(QStringList() << QStringLiteral("QMLPlayer"), options.value(QStringLiteral("language")).toString());
    QtQuick2ApplicationViewer viewer;
    QString binDir = qApp->applicationDirPath();
    if (binDir.endsWith(QLatin1String(".app/Contents/MacOS"))) {
        binDir.remove(QLatin1String(".app/Contents/MacOS"));
        binDir = binDir.left(binDir.lastIndexOf(QLatin1String("/")));
    }
    QQmlEngine *engine = viewer.engine();
    if (!engine->importPathList().contains(binDir))
        engine->addImportPath(binDir);
    qDebug() << engine->importPathList();
    engine->rootContext()->setContextProperty(QStringLiteral("PlayerConfig"), &Config::instance());
    qDebug(">>>>>>>>devicePixelRatio: %f", qApp->devicePixelRatio());
    QScreen *sc = app.primaryScreen();
    qDebug() << "dpi phy: " << sc->physicalDotsPerInch() << ", logical: " << sc->logicalDotsPerInch() << ", dpr: " << sc->devicePixelRatio()
                << "; vis rect:" << sc->virtualGeometry();
    // define a global var for js and qml
    engine->rootContext()->setContextProperty(QStringLiteral("screenPixelDensity"), qApp->primaryScreen()->physicalDotsPerInch()*qApp->primaryScreen()->devicePixelRatio());
    qreal r = sc->physicalDotsPerInch()/sc->logicalDotsPerInch();
    if (std::isinf(r) || std::isnan(r))
#if defined(Q_OS_ANDROID)
        r = 2.0;
#else
        r = 1.0;
#endif
    float sr = options.value(QStringLiteral("scale")).toFloat();
#if defined(Q_OS_ANDROID)
    sr = r;
    if (sr > 2.0)
        sr = 2.0; //FIXME
#endif
    if (qFuzzyIsNull(sr))
        sr = r;
    engine->rootContext()->setContextProperty(QStringLiteral("scaleRatio"), sr);
    QString qml = QStringLiteral("qml/QMLPlayer/main.qml");
    if (QFile(qApp->applicationDirPath() + QLatin1String("/") + qml).exists())
        qml.prepend(qApp->applicationDirPath() + QLatin1String("/"));
    else
        qml.prepend(QLatin1String("qrc:///"));
    viewer.setMainQmlFile(qml);
    viewer.show();
    QOption op = options.option(QStringLiteral("width"));
    if (op.isSet())
        viewer.setWidth(op.value().toInt());
    op = options.option(QStringLiteral("height"));
    if (op.isSet())
        viewer.setHeight(op.value().toInt());
    op = options.option(QStringLiteral("x"));
    if (op.isSet())
        viewer.setX(op.value().toInt());
    op = options.option(QStringLiteral("y"));
    if (op.isSet())
        viewer.setY(op.value().toInt());
    if (options.value(QStringLiteral("fullscreen")).toBool())
        viewer.showFullScreen();

    viewer.setTitle(QStringLiteral("QMLPlayer based on QtAV. [email protected]"));
    /*
     * find root item, then root.init(argv). so we can deal with argv in qml
     */
#if 1
    QString json = app.arguments().join(QStringLiteral("\",\""));
    json.prepend(QLatin1String("[\"")).append(QLatin1String("\"]"));
    json.replace(QLatin1String("\\"), QLatin1String("/")); //FIXME
    QMetaObject::invokeMethod(viewer.rootObject(), "init", Q_ARG(QVariant, json));
//#else
    QObject *player = viewer.rootObject()->findChild<QObject*>(QStringLiteral("player"));
    if (player) {
        AppEventFilter *ae = new AppEventFilter(player, player);
        qApp->installEventFilter(ae);
    }
    QString file;
#ifdef Q_OS_ANDROID
    file = QAndroidJniObject::callStaticObjectMethod("org.qtav.qmlplayer.QMLPlayerActivity"
                                                                              , "getUrl"
                                                                              , "()Ljava/lang/String;")
            .toString();
#endif
    if (app.arguments().size() > 1) {
        file = options.value(QStringLiteral("file")).toString();
        if (file.isEmpty()) {
            if (argc > 1 && !app.arguments().last().startsWith(QLatin1Char('-')) && !app.arguments().at(argc-2).startsWith(QLatin1Char('-')))
                file = app.arguments().last();
        }
    }
    qDebug() << "file: " << file;
    if (player && !file.isEmpty()) {
        if (!file.startsWith(QLatin1String("file:")) && QFile(file).exists())
            file.prepend(QLatin1String("file:")); //qml use url and will add qrc: if no scheme
        file.replace(QLatin1String("\\"), QLatin1String("/")); //qurl
        QMetaObject::invokeMethod(player, "play", Q_ARG(QUrl, QUrl(file)));
    }
#endif
    QObject::connect(viewer.rootObject(), SIGNAL(requestFullScreen()), &viewer, SLOT(showFullScreen()));
    QObject::connect(viewer.rootObject(), SIGNAL(requestNormalSize()), &viewer, SLOT(showNormal()));
    ScreenSaver::instance().disable(); //restore in dtor
    return app.exec();
}