From d5f46ae26ee0cd4a3ccdde526f011b3bdd884abc Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 22 Jul 2009 08:56:48 +0200 Subject: unify z-value handling in graphics and fx items. Add a ItemNegativeZStacksBehindParent flag to QGraphicsItem to get the behavior we need in QFxItems. Removed the z property in QFxItems. --- src/declarative/extra/qfxflowview.cpp | 6 +++--- src/declarative/fx/qfxgridview.cpp | 2 +- src/declarative/fx/qfxitem.cpp | 18 ------------------ src/declarative/fx/qfxitem.h | 4 ---- src/declarative/fx/qfxitem_p.h | 5 +++-- src/declarative/fx/qfxlistview.cpp | 2 +- src/declarative/fx/qfxpathview.cpp | 8 ++++---- src/gui/graphicsview/qgraphicsitem.cpp | 11 +++++++++++ src/gui/graphicsview/qgraphicsitem.h | 3 ++- src/gui/graphicsview/qgraphicsitem_p.h | 4 ++-- 10 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/declarative/extra/qfxflowview.cpp b/src/declarative/extra/qfxflowview.cpp index 1676512..e1200c7 100644 --- a/src/declarative/extra/qfxflowview.cpp +++ b/src/declarative/extra/qfxflowview.cpp @@ -132,7 +132,7 @@ void QFxFlowView::refresh() for (int ii = 0; ii < m_model->count(); ++ii) { if (QFxItem *item = m_model->item(ii)) { item->setParent(this); - item->setZ(0); + item->setZValue(0); m_items << item; } } @@ -296,7 +296,7 @@ void QFxFlowView::mousePressEvent(QGraphicsSceneMouseEvent *event) if (r.contains(event->pos())) { m_dragItem = item; - m_dragItem->setZ(1); + m_dragItem->setZValue(1); m_dragOffset = r.topLeft() - event->pos(); event->accept(); return; @@ -316,7 +316,7 @@ void QFxFlowView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event); if (m_dragItem) { - m_dragItem->setZ(0); + m_dragItem->setZValue(0); clearTimeLine(); diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 3c80e98..9528af7 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -356,7 +356,7 @@ FxGridItem *QFxGridViewPrivate::createItem(int modelIndex) listItem->index = modelIndex; // complete model->completeItem(); - listItem->item->setZ(modelIndex + 1); + listItem->item->setZValue(modelIndex + 1); listItem->item->setParent(q->viewport()); } requestedIndex = 0; diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 354e4cc..42ff436 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -2017,24 +2017,6 @@ QPointF QFxItem::transformOriginPoint() const return d->transformOrigin(); } -qreal QFxItem::z() const -{ - return zValue(); -} - -void QFxItem::setZ(qreal z) -{ - if (z == this->z()) - return; - - if (z < 0) - setFlag(QGraphicsItem::ItemStacksBehindParent, true); - else - setFlag(QGraphicsItem::ItemStacksBehindParent, false); - - setZValue(z); -} - qreal QFxItem::width() const { Q_D(const QFxItem); diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 0dcf852..8e0916e 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -111,7 +111,6 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) Q_PROPERTY(QUrl qml READ qml WRITE setQml NOTIFY qmlChanged) // ### name? Move to own class? Q_PROPERTY(QFxItem *qmlItem READ qmlItem NOTIFY qmlChanged) // ### see above - Q_PROPERTY(qreal z READ z WRITE setZ FINAL) // ### use method in QGO Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL) Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged FINAL) Q_PROPERTY(QFxAnchorLine left READ left CONSTANT FINAL) @@ -208,9 +207,6 @@ public: Options options() const; void setOptions(Options, bool set = true); - qreal z() const; - void setZ(qreal); - qreal width() const; void setWidth(qreal); void setImplicitWidth(qreal); diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 1615ad8..ec45d6e 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -93,8 +93,9 @@ public: q->setItemParent(parent); _baselineOffset.invalidate(); q->setAcceptedMouseButtons(Qt::NoButton); - q->setFlag(QGraphicsItem::ItemHasNoContents, true); - q->setFlag(QGraphicsItem::ItemIsFocusable, true); + q->setFlags(QGraphicsItem::ItemHasNoContents | + QGraphicsItem::ItemIsFocusable | + QGraphicsItem::ItemNegativeZStacksBehindParent); mouseSetsFocus = false; } diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 50564fb..3515b78 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -423,7 +423,7 @@ FxListItem *QFxListViewPrivate::createItem(int modelIndex) } // complete model->completeItem(); - listItem->item->setZ(modelIndex + 1); + listItem->item->setZValue(modelIndex + 1); listItem->item->setParent(q->viewport()); if (orient == Qt::Vertical) QObject::connect(listItem->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 47364d0..4f6fddd 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -581,7 +581,7 @@ void QFxPathViewPrivate::regenerate() return; } items.append(item); - item->setZ(i); + item->setZValue(i); } q->refill(); } @@ -639,7 +639,7 @@ void QFxPathView::refill() d->firstIndex %= d->model->count(); int index = (d->firstIndex + d->items.count())%d->model->count(); d->items << d->getItem(index); - d->items.last()->setZ(wrapIndex); + d->items.last()->setZValue(wrapIndex); d->pathOffset++; d->pathOffset=d->pathOffset % d->items.count(); } @@ -652,7 +652,7 @@ void QFxPathView::refill() if (d->firstIndex < 0) d->firstIndex = d->model->count() - 1; d->items.prepend(d->getItem(d->firstIndex)); - d->items.first()->setZ(d->firstIndex); + d->items.first()->setZValue(d->firstIndex); d->pathOffset--; if (d->pathOffset < 0) d->pathOffset = d->items.count() - 1; @@ -675,7 +675,7 @@ void QFxPathView::itemsInserted(int modelIndex, int count) if (d->pathItems == -1) { for (int i = 0; i < count; ++i) { QFxItem *item = d->getItem(modelIndex + i); - item->setZ(modelIndex + i); + item->setZValue(modelIndex + i); d->items.insert(modelIndex + i, item); } refill(); diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 916724c..638f20f 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -327,6 +327,10 @@ \value ItemAcceptsInputMethod The item supports input methods typically used for Asian languages. This flag was introduced in Qt 4.6. + + \value ItemNegativeZStacksBehindParent The item automatically stacks + it's parent if it's z-value is negative. + This flag was introduced in Qt 4.6. */ /*! @@ -3726,6 +3730,13 @@ void QGraphicsItem::setZValue(qreal z) itemChange(ItemZValueHasChanged, newZVariant); + if(d_ptr->flags & ItemNegativeZStacksBehindParent) { + if (z < 0) + setFlag(QGraphicsItem::ItemStacksBehindParent, true); + else + setFlag(QGraphicsItem::ItemStacksBehindParent, false); + } + if (d_ptr->isObject) emit static_cast(this)->zChanged(); } diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 6012053..ba7b5ef 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -100,7 +100,8 @@ public: ItemUsesExtendedStyleOption = 0x200, ItemHasNoContents = 0x400, ItemSendsGeometryChanges = 0x800, - ItemAcceptsInputMethod = 0x1000 + ItemAcceptsInputMethod = 0x1000, + ItemNegativeZStacksBehindParent = 0x2000 // NB! Don't forget to increase the d_ptr->flags bit field by 1 when adding a new flag. }; Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag) diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 9e30f54..ba24806 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -449,7 +449,7 @@ public: // New 32 bits quint32 fullUpdatePending : 1; - quint32 flags : 13; + quint32 flags : 14; quint32 dirtyChildrenBoundingRect : 1; quint32 paintedViewBoundingRectsNeedRepaint : 1; quint32 dirtySceneTransform : 1; @@ -466,7 +466,7 @@ public: quint32 isFocusItemForArea : 1; quint32 hasActiveFocus : 1; quint32 mouseSetsFocus : 1; - quint32 unused : 2; // feel free to use + quint32 unused : 1; // feel free to use // Optional stacking order int globalStackingOrder; -- cgit v0.12