void shouldNotifyWhenTabPropertiesChange()
    {
        qRegisterMetaType<QVector<int> >();
        QSignalSpy spy(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
        QQuickItem* tab = createTab();
        model->add(tab);

        QQmlProperty(tab, "url").write(QUrl("http://ubuntu.com"));
        QCOMPARE(spy.count(), 1);
        QList<QVariant> args = spy.takeFirst();
        QCOMPARE(args.at(0).toModelIndex().row(), 0);
        QCOMPARE(args.at(1).toModelIndex().row(), 0);
        QVector<int> roles = args.at(2).value<QVector<int> >();
        QCOMPARE(roles.size(), 1);
        QVERIFY(roles.contains(TabsModel::Url));

        QQmlProperty(tab, "title").write(QString("Lorem Ipsum"));
        QCOMPARE(spy.count(), 1);
        args = spy.takeFirst();
        QCOMPARE(args.at(0).toModelIndex().row(), 0);
        QCOMPARE(args.at(1).toModelIndex().row(), 0);
        roles = args.at(2).value<QVector<int> >();
        QCOMPARE(roles.size(), 1);
        QVERIFY(roles.contains(TabsModel::Title));

        QQmlProperty(tab, "icon").write(QUrl("image://webicon/123"));
        QCOMPARE(spy.count(), 1);
        args = spy.takeFirst();
        QCOMPARE(args.at(0).toModelIndex().row(), 0);
        QCOMPARE(args.at(1).toModelIndex().row(), 0);
        roles = args.at(2).value<QVector<int> >();
        QCOMPARE(roles.size(), 1);
        QVERIFY(roles.contains(TabsModel::Icon));
    }
Example #2
0
MainWindow::MainWindow(QWindow *parent)
    : QQuickView(parent)
{
    setSource(QUrl::fromLocalFile("H:/VK/main.qml").toString());

    photoSize = "130";


    // !!! SET QNAM AND CACHE
    manager = new QNetworkAccessManager(this);
    cache = new QNetworkDiskCache(this);
    // 500 Mb
    cache->setMaximumCacheSize(500*1024*1024);
    cache->setCacheDirectory("cacheDir");
    manager->setCache(cache);

    // SET CACHED NAM TO QMLENGINE TO
    MyNetworkAccessManagerFactory* namFactory = new MyNetworkAccessManagerFactory();
    QQmlEngine* eng =  engine();
    eng->setNetworkAccessManagerFactory(namFactory);


    QQmlProperty((QObject*)rootObject(), "color").write("#F5F5F5");
    QQmlProperty((QObject*)rootObject(), "height").write(height());


    wallObj = rootObject();
    //wallObj->setProperty("color", "#F5F5F5");
    //wallObj->setProperty("height",height());

    connect((QObject*)wallObj, SIGNAL(login()),this,SLOT(login()));
    connect((QObject*)wallObj, SIGNAL(getGroups()),this, SLOT(getGroups()));
    connect((QObject*)wallObj, SIGNAL(getWall(QString)),this, SLOT(getWall(QString)));
    connect((QObject*)wallObj, SIGNAL(morePosts()), this, SLOT(morePosts()));
    connect((QObject*)wallObj, SIGNAL(setPhotoSize(QString)), this, SLOT(setPhotoSize(QString)));


    LoadIni("H:/VK/config.ini");
    // do we have token
    if( settings->contains("token")){
        // its a unlimit token
        qDebug() << " HAVE TOKEN ";
        if(ReadConfig("expires").toInt()==0){
            Token = ReadConfig("token").toString();
        }
        // if no doesnt it token expire
        else if(ReadConfig("expDate").toDate()<=QDate::currentDate()){
            Token = ReadConfig("token").toString();
        }
    // if havent token login
    }else{
        login();
        qDebug() << " NEED LOGIN ";
    }
}
 void shouldReturnData()
 {
     QQuickItem* tab = createTab();
     QQmlProperty(tab, "url").write(QUrl("http://ubuntu.com/"));
     QQmlProperty(tab, "title").write(QString("Lorem Ipsum"));
     QQmlProperty(tab, "icon").write(QUrl("image://webicon/123"));
     model->add(tab);
     QVERIFY(!model->data(QModelIndex(), TabsModel::Url).isValid());
     QVERIFY(!model->data(model->index(-1, 0), TabsModel::Url).isValid());
     QVERIFY(!model->data(model->index(3, 0), TabsModel::Url).isValid());
     QCOMPARE(model->data(model->index(0, 0), TabsModel::Url).toUrl(), QUrl("http://ubuntu.com/"));
     QCOMPARE(model->data(model->index(0, 0), TabsModel::Title).toString(), QString("Lorem Ipsum"));
     QCOMPARE(model->data(model->index(0, 0), TabsModel::Icon).toUrl(), QUrl("image://webicon/123"));
     QCOMPARE(model->data(model->index(0, 0), TabsModel::Tab).value<QQuickItem*>(), tab);
     QVERIFY(!model->data(model->index(0, 0), TabsModel::Tab + 3).isValid());
 }
Example #4
0
bool TestPlugin::init(QOpenGLExtraFunctions* f, QQmlEngine* qmlEngine) {
    Q_UNUSED(f)

    Q_INIT_RESOURCE(testplugin);

    shader = new QOpenGLShaderProgram;

    shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/TestPlugin/glsl/plugin.vsh");
    shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/TestPlugin/glsl/plugin.fsh");

    shader->link();

    /* Bind so we set the texture sampler uniform values. */
    shader->bind();

    /* Left image is TEXTURE0. */
    shader->setUniformValue("textureL", 0);
    /* Right image is TEXTURE1. */
    shader->setUniformValue("textureR", 1);

    QQmlComponent component(qmlEngine);

    component.loadUrl(QUrl(QStringLiteral("qrc:/TestPlugin/Config.qml")));

    /* Wait for it to load... */
    while(component.isLoading());

    /* The program can't run if there was an error. */
    if (component.isError()) {
        qDebug(qPrintable(component.errorString()));
        return false;
    }

    configMenuObject = qobject_cast<QQuickItem*>(component.create());

    /* Critical error! abort! abort! */
    if (configMenuObject == nullptr)
        return false;

    logRenderStart = QQmlProperty(configMenuObject, "logRenderStart");
    logRenderEnd = QQmlProperty(configMenuObject, "logRenderEnd");
    logFrameSwap = QQmlProperty(configMenuObject, "logFrameSwap");

    qDebug("inited");

    return true;
}
Example #5
0
void QQmlBind::componentComplete()
{
    Q_D(QQmlBind);
    d->componentComplete = true;
    if (!d->prop.isValid())
        d->prop = QQmlProperty(d->obj, d->propName);
    eval();
}
Example #6
0
/*!
  \qmltype Layer
  \inqmlmodule Bacon2D
  \brief Is the base component providing common properties and functionality
   needed by other Layer types.  See \l ImageLayer.
*/
Layer::Layer(QQuickItem *parent)
    : QQuickItem(parent)
    , m_type(Layer::Infinite)
    , m_updateInterval(0)
    , m_behavior(0)
    , m_scene(0)
{
    // this activates the item layered mode
    QQmlProperty(this, "layer.enabled").write(true);
}
/*!
 \fn void ApplicationSettings::refresh()
 Refreshes all properties defined by the QML interface with those from QSettings
 */
void ApplicationSettings::refresh() {
    if(!isSettingsValid())
        return;

    const QMetaObject* myMetaObj = metaObject();
    for(int i = 0; i < myMetaObj->propertyCount();i++) {
        QMetaProperty property = myMetaObj->property(i);
        if(m_existingProperties->contains(property.name())) continue;

        handleProperty(QQmlProperty(this, property.name()));

        for(int i = 0; i < ApplicationSettings::s_allSettings.length(); ++i) {
            ApplicationSettings* appSettings = s_allSettings.at(i);

            if(appSettings != this && appSettings->applicationName() == m_applicationName && appSettings->fileName() == m_fileName) {
                appSettings->handleProperty(QQmlProperty(appSettings, property.name()));
            }
        }
    }
}
Example #8
0
SpriteSheet::SpriteSheet(QQuickItem *parent)
    : QQuickPaintedItem(parent)
    , m_pixMap(0)
    , m_frames(0)
    , m_frame(0)
    , m_initialFrame(0)
    , m_frameWidth(0)
    , m_vertical(1)
    , m_horizontal(1)
    , m_mirror(false)
{
    setVisible(false);
    QQmlProperty(this, "layer.enabled").write(true);
}
Example #9
0
void QQmlBind::setProperty(const QString &p)
{
    Q_D(QQmlBind);
    if (!d->propName.isEmpty() && d->when.isValid() && d->when) {
        /* if we switch the property name at runtime, we need to restore the
           previous binding on the old object before continuing */
        d->when = false;
        eval();
        d->when = true;
    }
    d->propName = p;
    if (d->componentComplete)
        d->prop = QQmlProperty(d->obj, d->propName);
    eval();
}
Example #10
0
void QQmlBind::setObject(QObject *obj)
{
    Q_D(QQmlBind);
    if (d->obj && d->when.isValid() && d->when) {
        /* if we switch the object at runtime, we need to restore the
           previous binding on the old object before continuing */
        d->when = false;
        eval();
        d->when = true;
    }
    d->obj = obj;
    if (d->componentComplete)
        d->prop = QQmlProperty(d->obj, d->propName);
    eval();
}
void MainWindow::connectSignals()
{
    for(auto iter = kProperties.constBegin(); iter != kProperties.constEnd(); ++iter)
    {
        QSignalMapper *mapper = new QSignalMapper(this);
        mapper->setMapping(mWindow, iter.key());
        connect(mapper, SIGNAL(mapped(int)), SLOT(onMapped(int)));

        const QMetaObject *meta = mapper->metaObject();
        connect(mWindow, QQmlProperty(mWindow, iter.value()).property().notifySignal(),
                mapper, meta->method(meta->indexOfMethod("map()")));
    }
    connect(mWindow, SIGNAL(saveClicked()), SIGNAL(saveClicked()));
    connect(mWindow, SIGNAL(updateViewClicked()), SIGNAL(updateViewClicked()));
}
void tst_QQmlEngineDebugService::recursiveObjectTest(
        QObject *o, const QmlDebugObjectReference &oref, bool recursive) const
{
    const QMetaObject *meta = o->metaObject();

    QQmlType *type = QQmlMetaType::qmlType(meta);
    QString className = type ? QString(type->qmlTypeName())
                             : QString(meta->className());
    className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1);

    QCOMPARE(oref.debugId, QQmlDebugService::idForObject(o));
    QCOMPARE(oref.name, o->objectName());
    QCOMPARE(oref.className, className);
    QCOMPARE(oref.contextDebugId, QQmlDebugService::idForObject(
                 qmlContext(o)));

    const QObjectList &children = o->children();
    for (int i=0; i<children.count(); i++) {
        QObject *child = children[i];
        if (!qmlContext(child))
            continue;
        int debugId = QQmlDebugService::idForObject(child);
        QVERIFY(debugId >= 0);

        QmlDebugObjectReference cref;
        foreach (const QmlDebugObjectReference &ref, oref.children) {
            if (ref.debugId == debugId) {
                cref = ref;
                break;
            }
        }
        QVERIFY(cref.debugId >= 0);

        if (recursive)
            recursiveObjectTest(child, cref, true);
    }

    foreach (const QmlDebugPropertyReference &p, oref.properties) {
        QCOMPARE(p.objectDebugId, QQmlDebugService::idForObject(o));

        // signal properties are fake - they are generated from QQmlAbstractBoundSignal children
        if (p.name.startsWith("on") && p.name.length() > 2 && p.name[2].isUpper()) {
            QString signal = p.value.toString();
            QQmlBoundSignalExpression *expr = QQmlPropertyPrivate::signalExpression(QQmlProperty(o, p.name));
            QVERIFY(expr && expr->expression() == signal);
            QVERIFY(p.valueTypeName.isEmpty());
            QVERIFY(p.binding.isEmpty());
            QVERIFY(!p.hasNotifySignal);
            continue;
        }

        QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name.toUtf8().constData()));

        QCOMPARE(p.name, QString::fromUtf8(pmeta.name()));

        if (pmeta.type() < QVariant::UserType && pmeta.userType() !=
                QMetaType::QVariant) // TODO test complex types
            QCOMPARE(p.value , pmeta.read(o));

        if (p.name == "parent")
            QVERIFY(p.valueTypeName == "QGraphicsObject*" ||
                    p.valueTypeName == "QQuickItem*");
        else
            QCOMPARE(p.valueTypeName, QString::fromUtf8(pmeta.typeName()));

        QQmlAbstractBinding *binding =
                QQmlPropertyPrivate::binding(
                    QQmlProperty(o, p.name));
        if (binding)
            QCOMPARE(binding->expression(), p.binding);

        QCOMPARE(p.hasNotifySignal, pmeta.hasNotifySignal());

        QVERIFY(pmeta.isValid());
    }
}
Example #13
0
bool OpenVRPlugin::init(QOpenGLExtraFunctions* f, QQmlEngine* qmlEngine) {
    Q_UNUSED(f)
    Q_INIT_RESOURCE(openvrplugin);

    if (!vr::VR_IsHmdPresent()) {
        qDebug("No HMD detected...");
        return false;
    }

    /* This wil be inited on first usage. */
    vrSystem = nullptr;

    mirrorShader = new QOpenGLShaderProgram;

    mirrorShader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/OpenVR/glsl/mirror.vsh");
    mirrorShader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/OpenVR/glsl/mirror.fsh");

    mirrorShader->link();

    /* Bind so we set the texture sampler uniform values. */
    mirrorShader->bind();

    /* Left image is TEXTURE0. */
    mirrorShader->setUniformValue("textureL", 0);
    /* Right image is TEXTURE1. */
    mirrorShader->setUniformValue("textureR", 1);

    vrSceneShader = new QOpenGLShaderProgram;
    vrSceneShader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/OpenVR/glsl/vrscene.vsh");
    vrSceneShader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/OpenVR/glsl/vrscene.fsh");

    vrSceneShader->link();

    /* Bind so we set the texture sampler uniform values. */
    vrSceneShader->bind();

    /* Left image is TEXTURE0. */
    vrSceneShader->setUniformValue("textureL", 0);
    /* Right image is TEXTURE1. */
    vrSceneShader->setUniformValue("textureR", 1);

    distortionShader = new QOpenGLShaderProgram;
    distortionShader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/OpenVR/glsl/distortion.vsh");
    distortionShader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/OpenVR/glsl/distortion.fsh");

    /* Make sure the attributes are bound correctly. */
    distortionShader->bindAttributeLocation("position",     0);
    distortionShader->bindAttributeLocation("uvRedIn",      1);
    distortionShader->bindAttributeLocation("uvGreenIn",    2);
    distortionShader->bindAttributeLocation("uvBlueIn",     3);

    distortionShader->link();

    /* Bind so we set the texture sampler uniform values. */
    distortionShader->bind();

    /* The source texture will be bound to TEXTURE0. */
    distortionShader->setUniformValue("texture", 0);

    QQmlComponent component(qmlEngine);

    component.loadUrl(QUrl(QStringLiteral("qrc:/OpenVR/Config.qml")));

    /* Wait for it to load... */
    while(component.isLoading());

    /* The program can't run if there was an error. */
    if (component.isError()) {
        qDebug(qPrintable(component.errorString()));
        return false;
    }

    configMenu = qobject_cast<QQuickItem*>(component.create());

    /* Critical error! abort! abort! */
    if (configMenu == nullptr)
        return false;

    screenDistance = QQmlProperty(configMenu, "screenDistance");
    screenHeight = QQmlProperty(configMenu, "screenHeight");
    screenSize = QQmlProperty(configMenu, "screenSize");
    curvedScreen = QQmlProperty(configMenu, "curvedScreen");
    lockMouse = QQmlProperty(configMenu, "lockMouse");
    screenDistance.connectNotifySignal(this, SLOT(updateScreen()));
    screenHeight.connectNotifySignal(this, SLOT(updateScreen()));
    screenSize.connectNotifySignal(this, SLOT(updateScreen()));
    curvedScreen.connectNotifySignal(this, SLOT(updateScreen()));

    qDebug("OpenVR plugin base inited.");

    return true;
}