Пример #1
0
void GuiItem::findGui()
{
    if (m_gui)
        return;

//    // Disconnect from an external sender
//    QObject *sender = QObject::sender();
//    if (sender && this != sender)
//        sender->disconnect(this);

    // Work up the tree until the next Figure item is found.
    QQuickItem *newParent = parentItem();
    if (!newParent) return; // Either being deleted or instantiated
    GuiBase *guiObj;
    while (true) {
        guiObj = qobject_cast<GuiBase*>(newParent);
        if (guiObj)
            break;
        if (!newParent->parentItem()) {
            connect(newParent, &QQuickItem::parentChanged, this, &GuiItem::findGui);
            return;
        }
        newParent = newParent->parentItem();
    }

    if (guiObj) {
        disconnect(this, &QQuickItem::parentChanged, this, &GuiItem::findGui);
        setGui(guiObj);
    }
}
Пример #2
0
bool Navigation::dispatchNavigationEvent(NavEvent *event)
{
    if (event->key() == Navigation::Undefined)
        return false;

    QObject * receiver = QGuiApplication::focusObject();

    while (receiver && !event->isAccepted())
    {
        // Send to object
        QCoreApplication::sendEvent(receiver, event);

        if (!event->isAccepted())
        {
            // Send to attached item
            QObject * attachee = qmlAttachedPropertiesObject<Navigation>(receiver, false);

            if (attachee)
                QCoreApplication::sendEvent(attachee, event);

            // Try parent next, visual items if Quick items
            QQuickItem * qItem = qobject_cast<QQuickItem *>(receiver);
            if (qItem && qItem->parentItem())
                receiver = qItem->parentItem();
            else
                receiver = receiver->parent();
        }
    }

    return event->isAccepted();
}
Пример #3
0
void QQuickMultiPointTouchArea::touchEvent(QTouchEvent *event)
{
    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd: {
        //if e.g. a parent Flickable has the mouse grab, don't process the touch events
        QQuickWindow *c = window();
        QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
        if (grabber && grabber != this && grabber->keepMouseGrab() && grabber->isEnabled()) {
            QQuickItem *item = this;
            while ((item = item->parentItem())) {
                if (item == grabber)
                    return;
            }
        }
        updateTouchData(event);
        if (event->type() == QEvent::TouchEnd)
            ungrab();
        break;
    }
    case QEvent::TouchCancel:
        ungrab();
        break;
    default:
        QQuickItem::touchEvent(event);
        break;
    }
}
Пример #4
0
/* Q_INVOKABLE */ void WWindow::clearFocusItem(QQuickItem * item)
#endif
{
    Q_ASSERT(item);

#ifdef QT_4
    if (item->focusItem())
    {
        setFocus(true);
    }
#else
    Q_D(WWindow);

    QQuickItem * parent = d->view->activeFocusItem();

    while (parent)
    {
        parent = parent->parentItem();

        if (parent == item)
        {
            setFocus(true);

            return;
        }
    }
#endif
}
Пример #5
0
void QuickItemModel::itemReparented()
{
  QQuickItem *item = qobject_cast<QQuickItem*>(sender());
  if (!item || item->window() != m_window)
    return;

  QQuickItem* sourceParent = m_childParentMap.value(item);
  Q_ASSERT(sourceParent);
  const QModelIndex sourceParentIndex = indexForItem(sourceParent);

  QVector<QQuickItem*> &sourceSiblings = m_parentChildMap[sourceParent];
  QVector<QQuickItem*>::iterator sit = std::lower_bound(sourceSiblings.begin(), sourceSiblings.end(), item);
  Q_ASSERT(sit != sourceSiblings.end() && *sit == item);
  const int sourceRow = std::distance(sourceSiblings.begin(), sit);

  QQuickItem* destParent = item->parentItem();
  Q_ASSERT(destParent);
  const QModelIndex destParentIndex = indexForItem(destParent);

  QVector<QQuickItem*> &destSiblings = m_parentChildMap[destParent];
  QVector<QQuickItem*>::iterator dit = std::lower_bound(destSiblings.begin(), destSiblings.end(), item);
  const int destRow = std::distance(destSiblings.begin(), dit);

  beginMoveRows(sourceParentIndex, sourceRow, sourceRow, destParentIndex, destRow);
  destSiblings.insert(dit, item);
  sourceSiblings.erase(sit);
  m_childParentMap.insert(item, destParent);
  endMoveRows();
}
Пример #6
0
void QuickItemModel::objectAdded(QObject* obj)
{
  Q_ASSERT(thread() == QThread::currentThread());
  QQuickItem *item = qobject_cast<QQuickItem*>(obj);
  if (!item)
    return;

  if (item->window() != m_window)
    return; // item for a different scene

  if (m_childParentMap.contains(item))
    return; // already known

  QQuickItem *parentItem = item->parentItem();
  if (parentItem) {
    // add parent first, if we don't know that yet
    if (!m_childParentMap.contains(parentItem))
      objectAdded(parentItem);
  }

  connectItem(item);

  const QModelIndex index = indexForItem(parentItem);
  Q_ASSERT(index.isValid() || !parentItem);

  QVector<QQuickItem*> &children = m_parentChildMap[parentItem];
  QVector<QQuickItem*>::iterator it = std::lower_bound(children.begin(), children.end(), obj);
  const int row = std::distance(children.begin(), it);

  beginInsertRows(index, row, row);
  children.insert(it, item);
  m_childParentMap.insert(item, parentItem);
  endInsertRows();
}
bool MInverseMouseArea::isClickedOnSoftwareInputPanel() const
{
    QQuickItem * item = canvas()->activeFocusItem();
    while(item != NULL) {
        if(item->objectName() == "softwareInputPanel")
            return true;
        item = item->parentItem();
    }
    return false;
}
Пример #8
0
/*!
    \internal

    Injects this as a listener to \a item and all its ancestors.
 */
void QQuickScenePosListener::addAncestorListeners(QQuickItem *item)
{
    if (item == m_item)
        return;

    QQuickItem *p = item;
    while (p != 0) {
        QQuickItemPrivate::get(p)->addItemChangeListener(this, AncestorChangeTypes);
        p = p->parentItem();
    }
}
Пример #9
0
bool QQuickScenePosListener::isAncestor(QQuickItem *item) const
{
    if (!m_item)
        return false;

    QQuickItem *parent = m_item->parentItem();
    while (parent) {
        if (parent == item)
            return true;
        parent = parent->parentItem();
    }
    return false;
}
Пример #10
0
ColorScope *ColorScope::findParentScope() const
{
    QObject *p = 0;
    if (m_parent) {
        QQuickItem *gp = qobject_cast<QQuickItem *>(m_parent);
        if (gp) {
            p = gp->parentItem();
        } else {
            p = m_parent->parent();
        }
    }

    if (!p || !m_parent) {
        if (m_parentScope) {
            disconnect(m_parentScope.data(), &ColorScope::colorGroupChanged,
                    this, &ColorScope::colorGroupChanged);
            disconnect(m_parentScope.data(), &ColorScope::colorsChanged,
                    this, &ColorScope::colorsChanged);
        }
        return 0;
    }

    ColorScope *c = qobject_cast<ColorScope *>(p);
    if (!c) {
        c = qmlAttachedProperties(p);
    }

    if (c != m_parentScope) {
        if (m_parentScope) {
            disconnect(m_parentScope.data(), &ColorScope::colorGroupChanged,
                    this, &ColorScope::colorGroupChanged);
            disconnect(m_parentScope.data(), &ColorScope::colorsChanged,
                    this, &ColorScope::colorsChanged);
        }
        if (c) {
            connect(c, &ColorScope::colorGroupChanged,
                    this, &ColorScope::colorGroupChanged);
            connect(c, &ColorScope::colorsChanged,
                    this, &ColorScope::colorsChanged);
        }
        //HACK
        const_cast<ColorScope *>(this)->m_parentScope = c;
    }


    return m_parentScope;
}
Пример #11
0
void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, const QString &newParentProperty)
{
    QQmlProperty property(newParent, newParentProperty, context());

    if (isList(property)) {
        QQmlListReference list = qvariant_cast<QQmlListReference>(property.read());

        if (!hasFullImplementedListInterface(list)) {
            qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!";
            return;
        }

        list.append(object);
    } else if (isObject(property)) {
        property.write(objectToVariant(object));
    }

    QQuickItem *quickItem = qobject_cast<QQuickItem*>(object);

    if (object && !(quickItem && quickItem->parentItem()))
        object->setParent(newParent);

    Q_ASSERT(objectToVariant(object).isValid());
}