foreach (QSGParticleData* d, m_loadables){
     if (m_stasis.contains(d->delegate))
         qWarning() << "Current model particles prefers overwrite:false";
     //remove old item from the particle that is dying to make room for this one
     if (d->delegate)
         m_deletables << d->delegate;
     d->delegate = 0;
     if (!m_pendingItems.isEmpty()){
         d->delegate = m_pendingItems.front();
         m_pendingItems.pop_front();
     }else if (m_delegate){
         d->delegate = qobject_cast<QSGItem*>(m_delegate->create(qmlContext(this)));
     }
     if (d->delegate && d){//###Data can be zero if creating an item leads to a reset - this screws things up.
         d->delegate->setX(d->curX() - d->delegate->width()/2);//TODO: adjust for system?
         d->delegate->setY(d->curY() - d->delegate->height()/2);
         QSGItemParticleAttached* mpa = qobject_cast<QSGItemParticleAttached*>(qmlAttachedPropertiesObject<QSGItemParticle>(d->delegate));
         if (mpa){
             mpa->m_mp = this;
             mpa->attach();
         }
         d->delegate->setParentItem(this);
         if (m_fade)
             d->delegate->setOpacity(0.);
         d->delegate->setVisible(false);//Will be set to true when we prepare the next frame
         m_activeCount++;
     }
 }
Beispiel #2
0
void Game::finishLoad(){
    if(m_cc->isError()){
        qDebug() << "Error loading: " << m_cc->errors();
        return;
    }
    m_currentMap = qobject_cast<Map*>(m_cc->create(qmlContext(m_gameArea)));
    if(!m_currentMap){
        qDebug() << "Error loading map.";
        return;
    }
    m_currentMap->setParentItem(m_gameArea);
    m_players = m_currentMap->m_players;//Yes, we share references.
    qDebug() << "Loading Map" << m_currentMap << m_players;
    playersChanged(m_players);

    m_gameOver = false;
    //HQs (must be unit[0])
    bool hqsBuilt = true;
    for(int i=0; i<m_players.size(); i++)
        hqsBuilt = build(m_players[i]->startPos().x(), m_players[i]->startPos().y(), m_players[i]->hq(), i) && hqsBuilt;
    Q_ASSERT(hqsBuilt);//TODO: Nicer error handling, this was just a QML error
    //Other starting units
    recursiveLoadStartState(m_currentMap);
    //Sentinel Waypoints
    m_players[0]->m_waypoints << new Waypoint(m_players[0], m_players[1]->m_units[0], m_currentMap);
    m_players[1]->m_waypoints << new Waypoint(m_players[1], m_players[0]->m_units[0], m_currentMap);
    debugPrint("Map Loaded: " + QString::number(m_currentMap->width()) + "," + QString::number(m_currentMap->height()));
    QTimer::singleShot(16, this, SLOT(gameTick()));
}
void QDeclarativeFontLoader::setSource(const QUrl &url)
{
    Q_D(QDeclarativeFontLoader);
    if (url == d->url)
        return;
    d->url = qmlContext(this)->resolvedUrl(url);

    d->status = Loading;
    emit statusChanged();
    emit sourceChanged();
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
    QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url);
    if (!lf.isEmpty()) {
        int id = QFontDatabase::addApplicationFont(lf);
        if (id != -1) {
            d->name = QFontDatabase::applicationFontFamilies(id).at(0);
            emit nameChanged();
            d->status = QDeclarativeFontLoader::Ready;
        } else {
            d->status = QDeclarativeFontLoader::Error;
            qmlInfo(this) << "Cannot load font: \"" << url.toString() << "\"";
        }
        emit statusChanged();
    } else
#endif
    {
        QNetworkRequest req(d->url);
        req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
        d->reply = qmlEngine(this)->networkAccessManager()->get(req);
        QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished()));
    }
}
QT_BEGIN_NAMESPACE

QQuickItem *QQuickTextUtil::createCursor(
    QQmlComponent *component, QQuickItem *parent, const QRectF &rectangle, const char *className)
{
    QQuickItem *item = 0;
    if (component->isReady()) {
        QQmlContext *creationContext = component->creationContext();

        if (QObject *object = component->beginCreate(creationContext
                              ? creationContext
                              : qmlContext(parent))) {
            if ((item = qobject_cast<QQuickItem *>(object))) {
                QQml_setParent_noEvent(item, parent);
                item->setParentItem(parent);
                item->setPosition(rectangle.topLeft());
                item->setHeight(rectangle.height());
            } else {
                qmlInfo(parent) << tr("%1 does not support loading non-visual cursor delegates.")
                                .arg(QString::fromUtf8(className));
            }
            component->completeCreate();
            return item;
        }
    } else if (component->isLoading()) {
        QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)),
                         parent, SLOT(createCursor()), Qt::UniqueConnection);
        return item;
    }
    qmlInfo(parent, component->errors()) << tr("Could not load cursor delegate");
    return item;
}
void QQuickLoaderPrivate::_q_sourceLoaded()
{
    Q_Q(QQuickLoader);
    if (!component || !component->errors().isEmpty()) {
        if (component)
            QQmlEnginePrivate::warning(qmlEngine(q), component->errors());
        if (loadingFromSource)
            emit q->sourceChanged();
        else
            emit q->sourceComponentChanged();
        emit q->statusChanged();
        emit q->progressChanged();
        emit q->itemChanged(); //Like clearing source, emit itemChanged even if previous item was also null
        disposeInitialPropertyValues(); // cleanup
        return;
    }

    QQmlContext *creationContext = component->creationContext();
    if (!creationContext) creationContext = qmlContext(q);
    itemContext = new QQmlContext(creationContext);
    itemContext->setContextObject(q);

    delete incubator;
    incubator = new QQuickLoaderIncubator(this, asynchronous ? QQmlIncubator::Asynchronous : QQmlIncubator::AsynchronousIfNested);

    component->create(*incubator, itemContext);

    if (incubator && incubator->status() == QQmlIncubator::Loading)
        emit q->statusChanged();
}
Beispiel #6
0
void QDeclarativeConnections::connectSignals()
{
    Q_D(QDeclarativeConnections);
    if (!d->componentcomplete)
        return;

    QDataStream ds(d->data);
    while (!ds.atEnd()) {
        QString propName;
        ds >> propName;
        QString script;
        ds >> script;
        QDeclarativeProperty prop(target(), propName);
        if (!prop.isValid()) {
            qmlInfo(this) << tr("Cannot assign to non-existent property \"%1\"").arg(propName);
        } else if (prop.type() & QDeclarativeProperty::SignalProperty) {
            QDeclarativeBoundSignal *signal =
                new QDeclarativeBoundSignal(target(), prop.method(), this);
            signal->setExpression(new QDeclarativeExpression(qmlContext(this), script, 0));
            d->boundsignals += signal;
        } else {
            qmlInfo(this) << tr("Cannot assign to non-existent property \"%1\"").arg(propName);
        }
    }
}
Beispiel #7
0
int FlameGraph::buildNode(const QModelIndex &parentIndex, QObject *parentObject, int depth)
{
    qreal position = 0;
    qreal skipped = 0;
    qreal parentSize = m_model->data(parentIndex, m_sizeRole).toReal();
    QQuickItem *parentItem = qobject_cast<QQuickItem *>(parentObject);
    QQmlContext *context = qmlContext(this);
    int rowCount = m_model->rowCount(parentIndex);
    int childrenDepth = depth;
    for (int row = 0; row < rowCount; ++row) {
        QModelIndex childIndex = m_model->index(row, 0, parentIndex);
        qreal size = m_model->data(childIndex, m_sizeRole).toReal();
        if (size / m_model->data(QModelIndex(), m_sizeRole).toReal() < m_sizeThreshold) {
            skipped += size;
            continue;
        }

        QObject *childObject = appendChild(parentObject, parentItem, context, childIndex,
                                           position / parentSize, size / parentSize);
        position += size;
        childrenDepth = qMax(childrenDepth, buildNode(childIndex, childObject, depth + 1));
    }

    if (skipped > 0) {
        appendChild(parentObject, parentItem, context, QModelIndex(), position / parentSize,
                    skipped / parentSize);
        childrenDepth = qMax(childrenDepth, depth + 1);
    }

    return childrenDepth;
}
/*!
Returns the QDeclarativeContext the component was created in.  This is only
valid for components created directly from QML.
*/
QDeclarativeContext *QDeclarativeComponent::creationContext() const
{
    Q_D(const QDeclarativeComponent);
    if(d->creationContext)
        return d->creationContext->asQDeclarativeContext();

    return qmlContext(this);
}
Beispiel #9
0
/*!
  \brief QEngineMonitor::grabFromContext
  \a item
  \a contextProperty

  Returns the engine monitor located within the items context.
 */
QEngineMonitor *QEngineMonitor::grabFromContext(QQuickItem *item, const QString &contextProperty){
    QQmlContext* ctx = qmlContext(item);
    if ( ctx == 0 ){
        qWarning("Context is not yet available. Call this method outside the constructor of your current object.");
        return 0;
    }
    return static_cast<QEngineMonitor*>(ctx->contextProperty(contextProperty).value<QObject*>());
}
void QDeclarativeLoaderPrivate::_q_sourceLoaded()
{
    Q_Q(QDeclarativeLoader);

    if (component) {
        if (!component->errors().isEmpty()) {
            QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
            emit q->sourceChanged();
            emit q->statusChanged();
            emit q->progressChanged();
            return;
        }

        QDeclarativeContext *creationContext = component->creationContext();
        if (!creationContext) creationContext = qmlContext(q);
        QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
        ctxt->setContextObject(q);

        QDeclarativeGuard<QDeclarativeComponent> c = component;
        QObject *obj = component->beginCreate(ctxt);
        if (component != c) {
            // component->create could trigger a change in source that causes
            // component to be set to something else. In that case we just
            // need to cleanup.
            if (c)
                c->completeCreate();
            delete obj;
            delete ctxt;
            return;
        }
        if (obj) {
            item = qobject_cast<QGraphicsObject *>(obj);
            if (item) {
                QDeclarative_setParent_noEvent(ctxt, obj);
                QDeclarative_setParent_noEvent(item, q);
                item->setParentItem(q);
//                item->setFocus(true);
                initResize();
            } else {
                qmlInfo(q) << QDeclarativeLoader::tr("Loader does not support loading non-visual elements.");
                delete obj;
                delete ctxt;
            }
        } else {
            if (!component->errors().isEmpty())
                QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
            delete obj;
            delete ctxt;
            source = QUrl();
        }
        component->completeCreate();
        emit q->sourceChanged();
        emit q->statusChanged();
        emit q->progressChanged();
        emit q->itemChanged();
        emit q->loaded();
    }
}
Beispiel #11
0
void CustomBinding::componentComplete()
{
    Q_ASSERT(m_target);

    foreach (const QV4::CompiledData::Binding *binding, bindings) {
        QString name = cdata->compilationUnit->data->stringAt(binding->propertyNameIndex);

        int bindingId = binding->value.compiledScriptIndex;

        QQmlContextData *context = QQmlContextData::get(qmlContext(this));

        QV4::Scope scope(QQmlEnginePrivate::getV4Engine(qmlEngine(this)));
        QV4::ScopedValue function(scope, QV4::QmlBindingWrapper::createQmlCallableForFunction(context, m_target, cdata->compilationUnit->runtimeFunctions[bindingId]));
        QQmlBinding *qmlBinding = new QQmlBinding(function, m_target, context);

        QQmlProperty property(m_target, name, qmlContext(this));
        qmlBinding->setTarget(property);
        QQmlPropertyPrivate::setBinding(property, qmlBinding);
    }
Beispiel #12
0
QObject_ *componentCreate(QQmlComponent_ *component, QQmlContext_ *context)
{
    QQmlComponent *qcomponent = reinterpret_cast<QQmlComponent *>(component);
    QQmlContext *qcontext = reinterpret_cast<QQmlContext *>(context);

    if (!qcontext) {
        qcontext = qmlContext(qcomponent);
    }
    return qcomponent->create(qcontext);
}
Beispiel #13
0
void Quick3DNodeInstantiatorPrivate::makeModel()
{
    Q_Q(Quick3DNodeInstantiator);
    QQmlDelegateModel* delegateModel = new QQmlDelegateModel(qmlContext(q));
    m_instanceModel = delegateModel;
    m_ownModel = true;
    delegateModel->setDelegate(m_delegate);
    delegateModel->classBegin(); //Pretend it was made in QML
    if (m_componentComplete)
        delegateModel->componentComplete();
}
Beispiel #14
0
QtFlickProvider::QtFlickProvider(QQuickWebView* viewItem, QQuickWebPage* pageItem)
    : QObject(viewItem)
{
    ASSERT(viewItem);
    ASSERT(pageItem);

    QDeclarativeEngine* engine = qmlEngine(viewItem);
    QDeclarativeContext* context = qmlContext(viewItem);

    ASSERT(engine);
    ASSERT(context);

    QDeclarativeComponent component(engine, viewItem);

    // Create the internal Flickable instance dynamically.
    // We only use public QML API so that we do not depend
    // on private API of the QtDeclarative module.
    component.setData(QByteArrayLiteral("import QtQuick 2.0\nFlickable {}"), QUrl());

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

    QMetaProperty content = resolveMetaProperty(m_flickable, "contentItem");
    m_contentItem = content.read(m_flickable).value<QQuickItem*>();
    ASSERT(m_contentItem);

    // Resolve meta methods and properties of the Flickable instance.
    m_returnToBoundsMethod = resolveMetaMethod(m_flickable, "returnToBounds()");
    m_cancelFlickMethod = resolveMetaMethod(m_flickable, "cancelFlick()");

    m_contentWidth = resolveMetaProperty(m_flickable, "contentWidth");
    m_contentHeight = resolveMetaProperty(m_flickable, "contentHeight");
    m_contentX = resolveMetaProperty(m_flickable, "contentX");
    m_contentY = resolveMetaProperty(m_flickable, "contentY");
    m_moving = resolveMetaProperty(m_flickable, "moving");
    m_dragging = resolveMetaProperty(m_flickable, "dragging");
    m_flicking = resolveMetaProperty(m_flickable, "flicking");

    m_flickableData = resolveMetaProperty(m_flickable, "flickableData");

    // Set the viewItem as the parent of the flickable instance
    // and reparent the page so it is placed on the flickable contentItem.
    m_flickable->setParentItem(viewItem);
    pageItem->setParentItem(m_contentItem);

    // Propagate flickable signals.
    connect(m_flickable, SIGNAL(movementStarted()), SIGNAL(movementStarted()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(movementEnded()), SIGNAL(movementEnded()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(flickingChanged()), SIGNAL(flickingChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(draggingChanged()), SIGNAL(draggingChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentWidthChanged()), SIGNAL(contentWidthChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentHeightChanged()), SIGNAL(contentHeightChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentXChanged()), SIGNAL(contentXChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentYChanged()), SIGNAL(contentYChanged()), Qt::DirectConnection);
}
Beispiel #15
0
void QDeclarativeWebView::setContent(const QByteArray& data, const QString& mimeType, const QUrl& baseUrl)
{
    updateContentsSize();

    if (isComponentComplete())
        page()->mainFrame()->setContent(data, mimeType, qmlContext(this)->resolvedUrl(baseUrl));
    else {
        d->pending = d->PendingContent;
        d->pendingUrl = baseUrl;
        d->pendingString = mimeType;
        d->pendingData = data;
    }
}
bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenuData &data)
{
    Q_Q(QQuickWebEngineView);

    QObject *menu = ui()->addMenu(0, QString(), data.pos);
    if (!menu)
        return false;

    // Populate our menu
    MenuItemHandler *item = 0;

    if (data.selectedText.isEmpty()) {
        item = new MenuItemHandler(menu);
        QObject::connect(item, &MenuItemHandler::triggered, q, &QQuickWebEngineView::goBack);
        ui()->addMenuItem(item, QObject::tr("Back"), QStringLiteral("go-previous"), q->canGoBack());

        item = new MenuItemHandler(menu);
        QObject::connect(item, &MenuItemHandler::triggered, q, &QQuickWebEngineView::goForward);
        ui()->addMenuItem(item, QObject::tr("Forward"), QStringLiteral("go-next"), q->canGoForward());

        item = new MenuItemHandler(menu);
        QObject::connect(item, &MenuItemHandler::triggered, q, &QQuickWebEngineView::reload);
        ui()->addMenuItem(item, QObject::tr("Reload"), QStringLiteral("view-refresh"));
    } else {
        item = new CopyMenuItem(menu, data.selectedText);
        ui()->addMenuItem(item, QObject::tr("Copy..."));
    }

    if (!data.linkText.isEmpty() && data.linkUrl.isValid()) {
        item = new NavigateMenuItem(menu, adapter, data.linkUrl);
        ui()->addMenuItem(item, QObject::tr("Navigate to..."));
        item = new CopyMenuItem(menu, data.linkUrl.toString());
        ui()->addMenuItem(item, QObject::tr("Copy link address"));
    }

    // FIXME: expose the context menu data as an attached property to make this more useful
    if (contextMenuExtraItems) {
        ui()->addMenuSeparator(menu);
        if (QObject* menuExtras = contextMenuExtraItems->create(qmlContext(q))) {
            menuExtras->setParent(menu);
            QQmlListReference entries(menu, defaultPropertyName(menu), qmlEngine(q));
            if (entries.isValid())
                entries.append(menuExtras);
        }
    }

    // Now fire the popup() method on the top level menu
    QMetaObject::invokeMethod(menu, "popup");
    return true;
}
Beispiel #17
0
error *objectSetProperty(QObject_ *object, const char *name, DataValue *value)
{
    QObject *qobject = reinterpret_cast<QObject *>(object);
    QVariant var;
    unpackDataValue(value, &var);

    // Give qvalue an engine reference if it doesn't yet have one.
    QObject *obj = var.value<QObject *>();
    if (obj && !qmlEngine(obj)) {
        QQmlContext *context = qmlContext(qobject);
        if (context) {
            QQmlEngine::setContextForObject(obj, context);
        }
    }

    // Check that the types are compatible. There's probably more to be done here.
    const QMetaObject *metaObject = qobject->metaObject();
    int propIndex = metaObject->indexOfProperty(name);
    if (propIndex == -1) {
            return errorf("cannot set non-existent property \"%s\" on type %s", name, qobject->metaObject()->className());
    }

    QMetaProperty prop = metaObject->property(propIndex);
    int propType = prop.userType();
    void *valueArg;
    if (propType == QMetaType::QVariant) {
        valueArg = (void *)&var;
    } else {
        int varType = var.userType();
        QVariant saved = var;
        if (propType != varType && !var.convert(propType)) {
            if (varType == QMetaType::QObjectStar) {
                return errorf("cannot set property \"%s\" with type %s to value of %s*",
                        name, QMetaType::typeName(propType), saved.value<QObject*>()->metaObject()->className());
            } else {
                return errorf("cannot set property \"%s\" with type %s to value of %s",
                        name, QMetaType::typeName(propType), QMetaType::typeName(varType));
            }
        }
        valueArg = (void *)var.constData();
    }

    int status = -1;
    int flags = 0;
    void *args[] = {valueArg, 0, &status, &flags};
    QMetaObject::metacall(qobject, QMetaObject::WriteProperty, propIndex, args);
    return 0;
}
// Currently item creation is tightly bound to landmark model. Some day
// this may be leveraged to any user defined model or e.g. XML model.
QDeclarativeGeoMapObject* QDeclarativeGeoMapObjectView::createItem(int modelRow)
{
    if (!delegate_ || !model_)
        return NULL;
    QModelIndex index = model_->index(modelRow, 0); // column 0
    if (!index.isValid()) {
        qWarning() << "QDeclarativeGeoMapObject Index is not valid: " << modelRow;
        return NULL;
    }
    QHashIterator<int, QByteArray> iterator(model_->roleNames());
    QDeclarativeContext *itemContext = new QDeclarativeContext(qmlContext(this));
    while (iterator.hasNext()) {
        iterator.next();
        QVariant modelData = model_->data(index, iterator.key());
        if (!modelData.isValid())
            continue;
        // This call would fail for <QObject*> Need to be figured out why
        // if the model support is leveraged.
        QObject *data_ptr = modelData.value<QDeclarativeLandmark*>();
        if (!data_ptr)
            continue;
        itemContext->setContextProperty(QLatin1String(iterator.value().data()), data_ptr);
        // To avoid name collisions (delegate has same named attribute as model's role)
        // one can add here that the data is accessible also e.g. via 'model'.
        // In case of landmarks, two of the following are then equivalent:
        // latitude : landmark.coordinate.latitude
        // latitude : model.landmark.coordinate.latitude
        // itemContext->setContextProperty(QLatin1String("model."), data_ptr);
        // At the time being, it is however uncertain how to make it from a
        // QtMobility project (QDeclarativeVisualDataModel not available).
        // This however needs to be figured out if model support is generalized.
    }
    QObject* obj = delegate_->create(itemContext);

    if (!obj) {
        qWarning() << "QDeclarativeGeoMapObject map object creation failed.";
        delete itemContext;
        return NULL;
    }
    QDeclarativeGeoMapObject *declMapObj =  qobject_cast<QDeclarativeGeoMapObject*>(obj);
    if (!declMapObj) {
        qWarning() << "QDeclarativeGeoMapObject map object delegate is of unsupported type.";
        delete itemContext;
        return NULL;
    }
    itemContext->setParent(declMapObj);
    return declMapObj;
}
Beispiel #19
0
QQuickWindow_ *componentCreateWindow(QQmlComponent_ *component, QQmlContext_ *context)
{
    QQmlComponent *qcomponent = reinterpret_cast<QQmlComponent *>(component);
    QQmlContext *qcontext = reinterpret_cast<QQmlContext *>(context);

    if (!qcontext) {
        qcontext = qmlContext(qcomponent);
    }
    QObject *obj = qcomponent->create(qcontext);
    if (!objectIsWindow(obj)) {
        QQuickView *view = new QQuickView(qmlEngine(qcomponent), 0);
        view->setContent(qcomponent->url(), qcomponent, obj);
        view->setResizeMode(QQuickView::SizeRootObjectToView);
        obj = view;
    }
    return obj;
}
Beispiel #20
0
void objectSetProperty(QObject_ *object, const char *name, DataValue *value)
{
    QObject *qobject = reinterpret_cast<QObject *>(object);
    QVariant var;
    unpackDataValue(value, &var);

    // Give qvalue an engine reference if it doesn't yet have one.
    QObject *obj = var.value<QObject *>();
    if (obj && !qmlEngine(obj)) {
        QQmlContext *context = qmlContext(qobject);
        if (context) {
            QQmlEngine::setContextForObject(obj, context);
        }
    }

    qobject->setProperty(name, var);
}
void TelegramImageElement::initImage()
{
    if(p->image)
        return;

    QQmlEngine *engine = qmlEngine(this);
    QQmlContext *context = qmlContext(this);
    if(!engine || !context)
        return;

    QQmlComponent component(engine);

    QString qmlImageCreationCode = p->qmlImageCreationCode;
    if(qmlImageCreationCode.isEmpty())
        qmlImageCreationCode = QString("import QtQuick %1\n"
                                       "Image { anchors.fill: parent; }").arg(p->qtQuickVersion);

    component.setData(qmlImageCreationCode.toUtf8(), QUrl());
    QQuickItem *item = qobject_cast<QQuickItem *>(component.create(context));
    if(!item)
        return;

    item->setParent(this);
    item->setParentItem(this);

    QHashIterator<QString, QVariant> i(p->properties);
    while(i.hasNext())
    {
        i.next();
        item->setProperty(i.key().toUtf8(), i.value());
    }

    connect(item, SIGNAL(asynchronousChanged()), this, SIGNAL(asynchronousChanged()));

    #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
        connect(item, SIGNAL(autoTransformChanged()), this, SIGNAL(autoTransformChanged()));
    #endif

    connect(item, SIGNAL(cacheChanged()), this, SIGNAL(cacheChanged()));
    connect(item, SIGNAL(fillModeChanged()), this, SIGNAL(fillModeChanged()));
    connect(item, SIGNAL(mirrorChanged()), this, SIGNAL(mirrorChanged()));
    connect(item, SIGNAL(sourceSizeChanged()), this, SIGNAL(sourceSizeChanged()));

    p->image = item;
}
Beispiel #22
0
void QQuickItemParticle::tick(int time)
{
    Q_UNUSED(time);//only needed because QTickAnimationProxy expects one
    foreach (QQuickItem* item, m_deletables){
        if (m_fade)
            item->setOpacity(0.);
        item->setVisible(false);
        QQuickItemParticleAttached* mpa;
        if ((mpa = qobject_cast<QQuickItemParticleAttached*>(qmlAttachedPropertiesObject<QQuickItemParticle>(item))))
            mpa->detach();//reparent as well?
        //TODO: Delete iff we created it
        m_activeCount--;
    }
    m_deletables.clear();

    foreach (QQuickParticleData* d, m_loadables){
        if (m_stasis.contains(d->delegate))
            qWarning() << "Current model particles prefers overwrite:false";
        //remove old item from the particle that is dying to make room for this one
        if (d->delegate)
            m_deletables << d->delegate;
        d->delegate = 0;
        if (!m_pendingItems.isEmpty()){
            d->delegate = m_pendingItems.front();
            m_pendingItems.pop_front();
        }else if (m_delegate){
            d->delegate = qobject_cast<QQuickItem*>(m_delegate->create(qmlContext(this)));
        }
        if (d->delegate && d){//###Data can be zero if creating an item leads to a reset - this screws things up.
            d->delegate->setX(d->curX() - d->delegate->width()/2);//TODO: adjust for system?
            d->delegate->setY(d->curY() - d->delegate->height()/2);
            QQuickItemParticleAttached* mpa = qobject_cast<QQuickItemParticleAttached*>(qmlAttachedPropertiesObject<QQuickItemParticle>(d->delegate));
            if (mpa){
                mpa->m_mp = this;
                mpa->attach();
            }
            d->delegate->setParentItem(this);
            if (m_fade)
                d->delegate->setOpacity(0.);
            d->delegate->setVisible(false);//Will be set to true when we prepare the next frame
            m_activeCount++;
        }
    }
    m_loadables.clear();
}
void QDeclarativeGestureArea::connectSignals()
{
    Q_D(QDeclarativeGestureArea);
    if (!d->componentcomplete)
        return;

    QDataStream ds(d->data);
    while (!ds.atEnd()) {
        QString propName;
        ds >> propName;
        int gesturetype;
        ds >> gesturetype;
        QString script;
        ds >> script;
        QDeclarativeExpression *exp = new QDeclarativeExpression(qmlContext(this), this, script);
        d->bindings.insert(Qt::GestureType(gesturetype),exp);
        grabGesture(Qt::GestureType(gesturetype));
    }
}
Beispiel #24
0
void QDeclarativeTextEdit::loadCursorDelegate()
{
    Q_D(QDeclarativeTextEdit);
    if(d->cursorComponent->isLoading())
        return;
    d->cursor = qobject_cast<QDeclarativeItem*>(d->cursorComponent->create(qmlContext(this)));
    if(d->cursor){
        connect(d->control, SIGNAL(cursorPositionChanged()),
                this, SLOT(moveCursorDelegate()));
        d->control->setCursorWidth(0);
        dirtyCache(cursorRect());
        QDeclarative_setParent_noEvent(d->cursor, this);
        d->cursor->setParentItem(this);
        d->cursor->setHeight(QFontMetrics(d->font).height());
        moveCursorDelegate();
    }else{
        qWarning() << QLatin1String("Error loading cursor delegate for TextEdit:") + objectName();
    }
}
Beispiel #25
0
Kernel::Kernel(const RuntimeConfiguration &config, QObject *parent)
    : QObject(parent)
    , m_runtimeConfiguration(config)
    , m_storage(new JsonStorage(this, this))
    , m_qmlEngine(new QQmlEngine(0)) // leak the engine, no point in wasting shutdown time. Also we get a qmldebug server crash if it's parented to qApp, which Kernel is
    , m_settings(config.settings() ? config.settings() : new Settings(this))
    , m_controller(new Controller(m_qmlEngine->rootContext(), this, m_storage, m_settings, this))
    , m_pluginModel(new PluginModel(this))
#ifndef NO_WEBDAV
    , m_webDavSyncer(new WebDAVSyncer(this))
#endif
#if defined(QT_WIDGETS_LIB) && !defined(QT_NO_SYSTRAY)
    , m_systrayIcon(0)
    , m_trayMenu(0)
#endif
{
    QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fontawesome-webfont.ttf"));
    QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/open-sans/OpenSans-Regular.ttf"));
    qApp->setFont(QFont(QStringLiteral("Open Sans")));

    m_qmlEngine->rootContext()->setObjectName(QStringLiteral("QQmlContext")); // GammaRay convenience
    registerQmlTypes();
    qmlContext()->setContextProperty(QStringLiteral("_controller"), m_controller);
    qmlContext()->setContextProperty(QStringLiteral("_storage"), m_storage);
    qmlContext()->setContextProperty(QStringLiteral("_pluginModel"), m_pluginModel);
    qmlContext()->setContextProperty(QStringLiteral("_loadManager"), m_controller->loadManager());
    qmlContext()->setContextProperty(QStringLiteral("_settings"), m_settings);
#ifndef NO_WEBDAV
    qmlContext()->setContextProperty("_webdavSync", m_webDavSyncer);
#endif

    connect(m_controller, &Controller::currentTaskChanged, this, &Kernel::onTaskStatusChanged);
    connect(m_qmlEngine, &QQmlEngine::quit, qGuiApp, &QGuiApplication::quit);
    QMetaObject::invokeMethod(m_storage, "load", Qt::QueuedConnection); // Schedule a load. Don't do it directly, it will deadlock in instance()
    QMetaObject::invokeMethod(this, "maybeLoadPlugins", Qt::QueuedConnection);
    QMetaObject::invokeMethod(m_controller, "updateWebDavCredentials", Qt::QueuedConnection);

    if (m_runtimeConfiguration.useSystray() && m_settings->useSystray())
        setupSystray();

    const QDateTime currentDateTime = QDateTime::currentDateTime();
    m_currentDate = currentDateTime.date();
    connect(&m_dayChangedTimer, &QTimer::timeout, this, &Kernel::checkDayChanged);
    m_dayChangedTimer.start(5 * 60 * 1000); // every 5 minutes instead of daily in case of suspend

    // Startup counts as dayChanged, so handlers are run
    QMetaObject::invokeMethod(this, "dayChanged", Qt::QueuedConnection);
}
Beispiel #26
0
QDeclarativeWebView* QDeclarativeWebView::createWindow(QWebPage::WebWindowType type)
{
    switch (type) {
    case QWebPage::WebBrowserWindow: {
        if (!d->newWindowComponent && d->newWindowParent)
            qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored");
        else if (d->newWindowComponent && !d->newWindowParent)
            qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored");
        else if (d->newWindowComponent && d->newWindowParent) {
            QDeclarativeWebView* webview = 0;
            QDeclarativeContext* windowContext = new QDeclarativeContext(qmlContext(this));

            QObject* newObject = d->newWindowComponent->create(windowContext);
            if (newObject) {
                windowContext->setParent(newObject);
                QDeclarativeItem* item = qobject_cast<QDeclarativeItem *>(newObject);
                if (!item)
                    delete newObject;
                else {
                    webview = item->findChild<QDeclarativeWebView*>();
                    if (!webview)
                        delete item;
                    else {
                        newObject->setParent(d->newWindowParent);
                        static_cast<QGraphicsObject*>(item)->setParentItem(d->newWindowParent);
                    }
                }
            } else
                delete windowContext;

            return webview;
        }
    }
    break;
    case QWebPage::WebModalDialog: {
        // Not supported
    }
    }
    return 0;
}
void tst_qqmltranslation::idTranslation()
{
    QTranslator translator;
    translator.load(QLatin1String("qmlid_fr"), dataDirectory());
    QCoreApplication::installTranslator(&translator);

    QQmlEngine engine;
    QQmlComponent component(&engine, testFileUrl("idtranslation.qml"));
    QObject *object = component.create();
    QVERIFY(object != 0);

    {
        QQmlContext *context = qmlContext(object);
        QQmlEnginePrivate *engine = QQmlEnginePrivate::get(context->engine());
        QQmlTypeData *typeData = engine->typeLoader.getType(context->baseUrl());
        QQmlCompiledData *cdata = typeData->compiledData();
        QVERIFY(cdata);

        const QV4::CompiledData::Unit *unit = cdata->compilationUnit->data;
        const QV4::CompiledData::Object *rootObject = unit->objectAt(unit->indexOfRootObject);
        const QV4::CompiledData::Binding *binding = rootObject->bindingTable();
        for (quint32 i = 0; i < rootObject->nBindings; ++i, ++binding) {
            const QString propertyName = unit->stringAt(binding->propertyNameIndex);
            if (propertyName == "idTranslation") {
                if (binding->type != QV4::CompiledData::Binding::Type_TranslationById)
                    qDebug() << "binding for property" << propertyName << "is not a compiled translation";
                QCOMPARE(binding->type, quint32(QV4::CompiledData::Binding::Type_TranslationById));
            } else {
                QVERIFY(binding->type != QV4::CompiledData::Binding::Type_Translation);
            }
        }
    }

    QCOMPARE(object->property("idTranslation").toString(), QLatin1String("bonjour tout le monde"));
    QCOMPARE(object->property("idTranslation2").toString(), QLatin1String("bonjour tout le monde"));
    QCOMPARE(object->property("idTranslation3").toString(), QLatin1String("bonjour tout le monde"));

    QCoreApplication::removeTranslator(&translator);
    delete object;
}
Beispiel #28
0
void AbstractDataPlugin::handleViewportChange( const ViewportParams *viewport )
{
    QList<AbstractDataPluginItem*> orphane = d->m_delegateInstances.keys();
    QList<AbstractDataPluginItem*> const items = d->m_model->items( viewport, numberOfItems() );
    foreach( AbstractDataPluginItem* item, items ) {
        qreal x, y;
        Marble::GeoDataCoordinates const coordinates = item->coordinate();
        bool const visible = viewport->screenCoordinates( coordinates.longitude(), coordinates.latitude(), x, y );

        if ( !d->m_delegateInstances.contains( item ) ) {
            if ( !visible ) {
                // We don't have, but don't need it either. Shouldn't happen though as the model checks for it already.
                continue;
            }

            // Create a new QML object instance using the delegate as the factory. The original
            // data plugin item is set as the context object, i.e. all its properties are available
            // to QML directly with their names
            QQmlContext *context = new QQmlContext( qmlContext( d->m_delegate ) );
            context->setContextObject( item );
            QList<QByteArray> const dynamicProperties = item->dynamicPropertyNames();
            foreach( const QByteArray &property, dynamicProperties ) {
                context->setContextProperty( property, item->property( property ) );
            }

            QObject* component = d->m_delegate->create( context );
            QQuickItem* newItem = qobject_cast<QQuickItem*>( component );
            QGraphicsItem* graphicsItem = qobject_cast<QGraphicsItem*>( component );
            if ( graphicsItem && newItem ) {
                graphicsItem->setParentItem( d->m_delegateParent );
            }

            if ( newItem ) {
                d->m_delegateInstances[item] = newItem;
            } else {
                mDebug() << "Failed to create delegate";
                continue;
            }
        } else if ( !visible ) {
Beispiel #29
0
void CustomBinding::componentComplete()
{
    Q_ASSERT(m_target);

    QDataStream ds(m_bindingData);
    int count;
    ds >> count;
    for (int i = 0; i < count; ++i) {
        QString name;
        ds >> name;

        int bindingId;
        ds >> bindingId;

        int line;
        ds >> line;

        QQmlBinding *binding = QQmlBinding::createBinding(QQmlBinding::Identifier(bindingId), m_target, qmlContext(this), QString(), line);

        QQmlProperty property(m_target, name, qmlContext(this));
        binding->setTarget(property);
        QQmlPropertyPrivate::setBinding(property, binding);
    }
}
Beispiel #30
0
QQmlContext_ *objectContext(QObject_ *object)
{
    return qmlContext(static_cast<QObject *>(object));
}