Example #1
0
/*!
    \internal
*/
void QGraphicsWidgetPrivate::clearFocusWidget()
{
    // Reset focus child chain.
    QGraphicsWidget *parent = static_cast<QGraphicsWidget *>(q_ptr);
    do {
        if (parent->d_func()->focusChild != q_ptr)
            break;
        parent->d_func()->focusChild = 0;
    } while (!parent->isWindow() && (parent = parent->parentWidget()));
}
/**
 * is called after a reparent has taken place to fix up the focus chain(s)
 */
void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene)
{
    Q_Q(QGraphicsWidget);
    Q_ASSERT(focusNext && focusPrev);

    if (q_ptr->isPanel()) {
        // panels are never a part of their parent's or ancestors' focus
        // chains. so reparenting a panel is easy; there's nothing to
        // do.
        return;
    }

    // we're not a panel, so find the first widget in the focus chain
    // (this), and the last (this, or the last widget that is still
    // a descendent of this). also find the widgets that currently /
    // before reparenting point to this widgets' focus chain.
    QGraphicsWidget *focusFirst = q;
    QGraphicsWidget *focusBefore = focusPrev;
    QGraphicsWidget *focusLast = focusFirst;
    QGraphicsWidget *focusAfter = focusNext;
    do {
        if (!q->isAncestorOf(focusAfter))
            break;
        focusLast = focusAfter;
    } while ((focusAfter = focusAfter->d_func()->focusNext));

    if (!parent && oldScene && oldScene != newScene && oldScene->d_func()->tabFocusFirst == q) {
        // detach from old scene's top level focus chain.
        oldScene->d_func()->tabFocusFirst = (focusAfter != q) ? focusAfter : 0;
    }

    // detach from current focus chain; skip this widget subtree.
    focusBefore->d_func()->focusNext = focusAfter;
    focusAfter->d_func()->focusPrev = focusBefore;

    if (newParent) {
        // attach to new parent's focus chain as the last element
        // in its chain.
        QGraphicsWidget *newFocusFirst = newParent;
        QGraphicsWidget *newFocusLast = newFocusFirst;
        QGraphicsWidget *newFocusAfter = newFocusFirst->d_func()->focusNext;
        do {
            if (!newParent->isAncestorOf(newFocusAfter))
                break;
            newFocusLast = newFocusAfter;
        } while ((newFocusAfter = newFocusAfter->d_func()->focusNext));

        newFocusLast->d_func()->focusNext = q;
        focusLast->d_func()->focusNext = newFocusAfter;
        newFocusAfter->d_func()->focusPrev = focusLast;
        focusPrev = newFocusLast;
    } else {
        // no new parent, so just link up our own prev->last widgets.
        focusPrev = focusLast;
        focusLast->d_func()->focusNext = q;
    }
}
void QGraphicsWidgetPrivate::updateFont(const QFont &font)
{
    Q_Q(QGraphicsWidget);
    // Update the local font setting.
    this->font = font;

    // Calculate new mask.
    if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
        inheritedFontResolveMask = 0;
    int mask = font.resolve() | inheritedFontResolveMask;

    // Propagate to children.
    for (int i = 0; i < children.size(); ++i) {
        QGraphicsItem *item = children.at(i);
        if (item->isWidget()) {
            QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
            if (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
                w->d_func()->resolveFont(mask);
        } else {
            item->d_ptr->resolveFont(mask);
        }
    }

    if (!polished)
        return;
    // Notify change.
    QEvent event(QEvent::FontChange);
    QApplication::sendEvent(q, &event);
}
void QGraphicsWidgetPrivate::updatePalette(const QPalette &palette)
{
    Q_Q(QGraphicsWidget);
    // Update local palette setting.
    this->palette = palette;

    // Calculate new mask.
    if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
        inheritedPaletteResolveMask = 0;
    int mask = palette.resolve() | inheritedPaletteResolveMask;

    // Propagate to children.
    for (int i = 0; i < children.size(); ++i) {
        QGraphicsItem *item = children.at(i);
        if (item->isWidget()) {
            QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
            if (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
                w->d_func()->resolvePalette(mask);
        } else {
            item->d_ptr->resolvePalette(mask);
        }
    }

    // Notify change.
    QEvent event(QEvent::PaletteChange);
    QApplication::sendEvent(q, &event);
}
Example #5
0
/*!
    \internal
*/
void QGraphicsWidgetPrivate::setFocusWidget()
{
    // Update focus child chain.
    QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
    QGraphicsWidget *parent = widget;
    bool hidden = !visible;
    do {
        parent->d_func()->focusChild = widget;
    } while (!parent->isWindow() && (parent = parent->parentWidget()) && (!hidden || !parent->d_func()->visible));
}
void QGraphicsWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction)
{
    Q_Q(QGraphicsWidget);
    if ((direction == Qt::RightToLeft) == (testAttribute(Qt::WA_RightToLeft)))
        return;
    q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));

    // Propagate this change to all children.
    for (int i = 0; i < children.size(); ++i) {
        QGraphicsItem *item = children.at(i);
        if (item->isWidget()) {
            QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
            if (widget->parentWidget() && !widget->testAttribute(Qt::WA_SetLayoutDirection))
                widget->d_func()->setLayoutDirection_helper(direction);
        }
    }

    // Send the notification event to this widget item.
    QEvent e(QEvent::LayoutDirectionChange);
    QApplication::sendEvent(q, &e);
}
Example #7
0
/**
 * is called after a reparent has taken place to fix up the focus chain(s)
 */
void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene)
{
    Q_Q(QGraphicsWidget);

    Q_ASSERT(focusNext && focusPrev);

    QGraphicsWidget *n = q;     //last one in 'new' list
    QGraphicsWidget *o = 0;     //last one in 'old' list

    QGraphicsWidget *w = focusNext;

    QGraphicsWidget *firstOld = 0;
    bool wasPreviousNew = true;

    while (w != q) {
        bool isCurrentNew = q->isAncestorOf(w);
        if (isCurrentNew) {
            if (!wasPreviousNew) {
                n->d_func()->focusNext = w;
                w->d_func()->focusPrev = n;
            }
            n = w;
        } else /*if (!isCurrentNew)*/ {
            if (wasPreviousNew) {
                if (o) {
                    o->d_func()->focusNext = w;
                    w->d_func()->focusPrev = o;
                } else {
                    firstOld = w;
                }
            }
            o = w;
        }
        w = w->d_func()->focusNext;
        wasPreviousNew = isCurrentNew;
    }

    // repair the 'old' chain
    if (firstOld) {
        o->d_func()->focusNext = firstOld;
        firstOld->d_func()->focusPrev = o;
    }

    // update tabFocusFirst for oldScene if the item is going to be removed from oldScene
    if (newParent)
        newScene = newParent->scene();

    if (oldScene && newScene != oldScene)
        oldScene->d_func()->tabFocusFirst = (firstOld && firstOld->scene() == oldScene) ? firstOld : 0;

    QGraphicsItem *topLevelItem = newParent ? newParent->topLevelItem() : 0;
    QGraphicsWidget *topLevel = 0;
    if (topLevelItem && topLevelItem->isWidget())
        topLevel = static_cast<QGraphicsWidget *>(topLevelItem);

    if (topLevel && newParent) {
        QGraphicsWidget *last = topLevel->d_func()->focusPrev;
        // link last with new chain
        last->d_func()->focusNext = q;
        focusPrev = last;

        // link last in chain with
        topLevel->d_func()->focusPrev = n;
        n->d_func()->focusNext = topLevel;
    } else {
        // q is the start of the focus chain
        n->d_func()->focusNext = q;
        focusPrev = n;
    }

}