summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-10-25 23:26:53 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-10-25 23:26:53 (GMT)
commitcbb1b29d397c063fc3bcae04c5b062f20cbd12c5 (patch)
treed89cebe45c9f6dfdcab34a95da19ee0d670e30f5 /src/gui/graphicsview
parented7d58f6668be4ffb5f915722dee81c864f74844 (diff)
parent9aa00de1d277763c0f7a380fde27face60e5f686 (diff)
downloadQt-cbb1b29d397c063fc3bcae04c5b062f20cbd12c5.zip
Qt-cbb1b29d397c063fc3bcae04c5b062f20cbd12c5.tar.gz
Qt-cbb1b29d397c063fc3bcae04c5b062f20cbd12c5.tar.bz2
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt into kinetic-declarativeui
Conflicts: tools/qdoc3/cppcodemarker.cpp
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.cpp182
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.h3
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp817
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h36
-rw-r--r--src/gui/graphicsview/qgraphicsgridlayout.cpp30
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp52
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h3
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h78
-rw-r--r--src/gui/graphicsview/qgraphicslinearlayout.cpp4
-rw-r--r--src/gui/graphicsview/qgraphicsproxywidget.cpp15
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp258
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h7
-rw-r--r--src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp68
-rw-r--r--src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicstransform.cpp4
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp13
16 files changed, 1026 insertions, 546 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
index ffbb67c..e21cd99 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
@@ -48,36 +48,60 @@
\ingroup geomanagement
\ingroup graphicsview-api
- The anchor layout is a layout where one can specify how widgets should be placed relative to
- each other. The specification is called an anchor, and it is set up by calling anchor().
+ The anchor layout allows developers to specify how widgets should be placed relative to
+ each other, and to the layout itself. The specification is made by adding anchors to the
+ layout by calling addAnchor(), addAnchors() or addCornerAnchors().
+
+ Existing anchors in the layout can be accessed with the anchor() function.
+ Items that are anchored are automatically added to the layout, and if items
+ are removed, all their anchors will be automatically removed.
+
+ \beginfloatleft
+ \inlineimage simpleanchorlayout-example.png Using an anchor layout to align simple colored widgets.
+ \endfloat
+
Anchors are always set up between edges of an item, where the "center" is also considered to
- be an edge. Considering this example:
- \code
- QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
- QGraphicsWidget *a = new QGraphicsWidget;
- QGraphicsWidget *b = new QGraphicsWidget;
- l->anchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
- \endcode
-
- Here is the right edge of item A anchored to the left edge of item B, with the result that
- item B will be placed to the right of item A, with a spacing between A and B. If the
- spacing is negative, the items will overlap to some extent. Items that are anchored are
- automatically added to the layout, and if items are removed, all their anchors will be
- automatically removed
-
- \section1 Size Hints and Size Policies in QGraphicsAnchorLayout
+ be an edge. Consider the following example:
+
+ \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors
+
+ Here, the right edge of item \c a is anchored to the left edge of item \c b and the bottom
+ edge of item \c a is anchored to the top edge of item \c b, with the result that
+ item \c b will be placed diagonally to the right and below item \c b.
+
+ The addCornerAnchors() function provides a simpler way of anchoring the corners
+ of two widgets than the two individual calls to addAnchor() shown in the code
+ above. Here, we see how a widget can be anchored to the top-left corner of the enclosing
+ layout:
+
+ \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding a corner anchor
+
+ In cases where anchors are used to match the widths or heights of widgets, it is
+ convenient to use the addAnchors() function. As with the other functions for specifying
+ anchors, it can also be used to anchor a widget to a layout.
+
+ \clearfloat
+ \section1 Size Hints and Size Policies in an Anchor Layout
QGraphicsAnchorLayout respects each item's size hints and size policies. However it does
- not respect stretch factors currently. This might change in the future, so please refrain
- from using stretch factors in anchor layout to avoid any future regressions.
+ not currently respect their stretch factors. This might change in the future, so avoid
+ using stretch factors in anchor layouts if you want to avoid any future regressions in
+ behavior.
+
+ \section1 Spacing within an Anchor Layout
- \section1 Spacing within QGraphicsAnchorLayout
+ The layout may distribute some space between the items. If the spacing has not been
+ explicitly specified, the actual amount of space will usually be 0.
- Between the items, the layout can distribute some space. If the spacing has not been
- explicitly specified, the actual amount of space will usually be 0, but if the first edge
- is the "opposite" of the second edge (i.e. Right is anchored to Left or vice-versa), the
- size of the anchor will be queried from the style through the pixelMetric
- PM_LayoutHorizontalSpacing (or PM_LayoutVerticalSpacing for vertical anchors).
+ However, if the first edge is the \e opposite of the second edge (e.g., the right edge
+ of the first widget is anchored to the left edge of the second widget), the size of the
+ anchor will be queried from the style through a pixel metric:
+ \l{QStyle::}{PM_LayoutHorizontalSpacing} for horizontal anchors and
+ \l{QStyle::}{PM_LayoutVerticalSpacing} for vertical anchors.
+
+ If the spacing is negative, the items will overlap to some extent.
+
+ \sa QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayout
*/
/*!
@@ -118,13 +142,40 @@ QGraphicsAnchor::~QGraphicsAnchor()
}
/*!
+ \property QGraphicsAnchor::sizePolicy
+ \brief the size policy for the QGraphicsAnchor.
+
+ By setting the size policy on an anchor you can configure how the item can resize itself
+ from its preferred spacing. For instance, if the anchor has the size policy
+ QSizePolicy::Minimum, the spacing is the minimum size of the anchor. However, its size
+ can grow up to the anchors maximum size. If the default size policy is QSizePolicy::Fixed,
+ the anchor can neither grow or shrink, which means that the only size the anchor can have
+ is the spacing. QSizePolicy::Fixed is the default size policy.
+ QGraphicsAnchor always has a minimum spacing of 0 and a very large maximum spacing.
+
+ \sa QGraphicsAnchor::spacing
+*/
+
+void QGraphicsAnchor::setSizePolicy(QSizePolicy::Policy policy)
+{
+ Q_D(QGraphicsAnchor);
+ d->setSizePolicy(policy);
+}
+
+QSizePolicy::Policy QGraphicsAnchor::sizePolicy() const
+{
+ Q_D(const QGraphicsAnchor);
+ return d->sizePolicy;
+}
+
+/*!
\property QGraphicsAnchor::spacing
- \brief the space between items in the QGraphicsAnchorLayout.
+ \brief the preferred space between items in the QGraphicsAnchorLayout.
Depending on the anchor type, the default spacing is either
0 or a value returned from the style.
- \sa QGraphicsAnchorLayout::anchor()
+ \sa QGraphicsAnchorLayout::addAnchor()
*/
void QGraphicsAnchor::setSpacing(qreal spacing)
{
@@ -188,7 +239,7 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
If there is already an anchor between the edges, the the new anchor will replace the old one.
\a firstItem and \a secondItem are automatically added to the layout if they are not part
- of the layout. This means that count() can increase with up to 2.
+ of the layout. This means that count() can increase by up to 2.
The spacing an anchor will get depends on the type of anchor. For instance, anchors from the
Right edge of one item to the Left edge of another (or vice versa) will use the default
@@ -198,7 +249,10 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
The spacing can also be set manually by using QGraphicsAnchor::setSpacing() method.
- \sa addCornerAnchors(), addAnchors()
+ Calling this function where \a firstItem or \a secondItem are ancestors of the layout have
+ undefined behaviour.
+
+ \sa addAnchors(), addCornerAnchors()
*/
QGraphicsAnchor *
QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
@@ -223,29 +277,26 @@ QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint fi
}
/*!
- Creates two anchors between \a firstItem and \a secondItem, where one is for the horizontal
- edge and another one for the vertical edge that the corners \a firstCorner and \a
- secondCorner specifies.
- The magnitude of the anchors is picked up from the style.
+ Creates two anchors between \a firstItem and \a secondItem specified by the corners,
+ \a firstCorner and \a secondCorner, where one is for the horizontal edge and another
+ one for the vertical edge.
- This is a convenience function, since anchoring corners can be expressed as anchoring two edges.
- For instance,
- \code
- layout->addAnchor(layout, Qt::AnchorTop, b, Qt::AnchorTop);
- layout->addAnchor(layout, Qt::AnchorLeft, b, Qt::AnchorLeft);
- \endcode
+ This is a convenience function, since anchoring corners can be expressed as anchoring
+ two edges. For instance:
- has the same effect as
+ \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding a corner anchor in two steps
- \code
- layout->addCornerAnchors(layout, Qt::TopLeft, b, Qt::TopLeft);
- \endcode
+ This can also be achieved with the following line of code:
+
+ \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding a corner anchor
If there is already an anchor between the edge pairs, it will be replaced by the anchors that
this function specifies.
\a firstItem and \a secondItem are automatically added to the layout if they are not part of the
- layout. This means that count() can increase with up to 2.
+ layout. This means that count() can increase by up to 2.
+
+ \sa addAnchor(), addAnchors()
*/
void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem,
Qt::Corner firstCorner,
@@ -272,17 +323,16 @@ void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem,
edges of \a secondItem, so that \a firstItem has the same size as
\a secondItem in the dimensions specified by \a orientations.
- Calling this convenience function with the following arguments
- \code
- l->addAnchors(firstItem, secondItem, Qt::Horizontal)
- \endcode
+ For example, the following example anchors the left and right edges of two items
+ to match their widths:
+
+ \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes in two steps
- is the same as
+ This can also be achieved using the following line of code:
- \code
- l->addAnchor(firstItem, Qt::AnchorLeft, secondItem, Qt::AnchorLeft);
- l->addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
- \endcode
+ \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes
+
+ \sa addAnchor(), addCornerAnchors()
*/
void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem *firstItem,
QGraphicsLayoutItem *secondItem,
@@ -306,6 +356,13 @@ void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem *firstItem,
void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
+
+ // ### We don't support negative spacing yet
+ if (spacing < 0) {
+ spacing = 0;
+ qWarning() << "QGraphicsAnchorLayout does not support negative spacing.";
+ }
+
d->spacings[0] = spacing;
invalidate();
}
@@ -318,6 +375,13 @@ void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing)
void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
+
+ // ### We don't support negative spacing yet
+ if (spacing < 0) {
+ spacing = 0;
+ qWarning() << "QGraphicsAnchorLayout does not support negative spacing.";
+ }
+
d->spacings[1] = spacing;
invalidate();
}
@@ -327,11 +391,23 @@ void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing)
If an item is anchored with no spacing associated with the anchor, it will use the default
spacing.
+
+ Currently QGraphicsAnchorLayout does not support negative default spacings.
+
\sa setHorizontalSpacing(), setVerticalSpacing()
*/
void QGraphicsAnchorLayout::setSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
+
+ // ### Currently we do not support negative anchors inside the graph.
+ // To avoid those being created by a negative spacing, we must
+ // make this test.
+ if (spacing < 0) {
+ spacing = 0;
+ qWarning() << "QGraphicsAnchorLayout does not support negative spacing.";
+ }
+
d->spacings[0] = d->spacings[1] = spacing;
invalidate();
}
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.h b/src/gui/graphicsview/qgraphicsanchorlayout.h
index 99dbf92..01c3a86 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.h
@@ -62,10 +62,13 @@ class Q_GUI_EXPORT QGraphicsAnchor : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET unsetSpacing)
+ Q_PROPERTY(QSizePolicy::Policy sizePolicy READ sizePolicy WRITE setSizePolicy)
public:
void setSpacing(qreal spacing);
void unsetSpacing();
qreal spacing() const;
+ void setSizePolicy(QSizePolicy::Policy policy);
+ QSizePolicy::Policy sizePolicy() const;
~QGraphicsAnchor();
private:
QGraphicsAnchor(QGraphicsAnchorLayout *parent);
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index f9b5c8c..8c8c303 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -53,7 +53,8 @@ QT_BEGIN_NAMESPACE
QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version)
- : QObjectPrivate(version), layoutPrivate(0), data(0)
+ : QObjectPrivate(version), layoutPrivate(0), data(0),
+ sizePolicy(QSizePolicy::Fixed)
{
}
@@ -62,6 +63,14 @@ QGraphicsAnchorPrivate::~QGraphicsAnchorPrivate()
layoutPrivate->removeAnchor(data->from, data->to);
}
+void QGraphicsAnchorPrivate::setSizePolicy(QSizePolicy::Policy policy)
+{
+ if (sizePolicy != policy) {
+ sizePolicy = policy;
+ layoutPrivate->q_func()->invalidate();
+ }
+}
+
void QGraphicsAnchorPrivate::setSpacing(qreal value)
{
if (data) {
@@ -92,28 +101,11 @@ qreal QGraphicsAnchorPrivate::spacing() const
}
-static void sizeHintsFromItem(QGraphicsLayoutItem *item,
- const QGraphicsAnchorLayoutPrivate::Orientation orient,
- qreal *minSize, qreal *prefSize,
- qreal *expSize, qreal *maxSize)
+static void internalSizeHints(QSizePolicy::Policy policy,
+ qreal minSizeHint, qreal prefSizeHint, qreal maxSizeHint,
+ qreal *minSize, qreal *prefSize,
+ qreal *expSize, qreal *maxSize)
{
- QSizePolicy::Policy policy;
- qreal minSizeHint;
- qreal prefSizeHint;
- qreal maxSizeHint;
-
- if (orient == QGraphicsAnchorLayoutPrivate::Horizontal) {
- policy = item->sizePolicy().horizontalPolicy();
- minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).width();
- prefSizeHint = item->effectiveSizeHint(Qt::PreferredSize).width();
- maxSizeHint = item->effectiveSizeHint(Qt::MaximumSize).width();
- } else {
- policy = item->sizePolicy().verticalPolicy();
- minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).height();
- prefSizeHint = item->effectiveSizeHint(Qt::PreferredSize).height();
- maxSizeHint = item->effectiveSizeHint(Qt::MaximumSize).height();
- }
-
// minSize, prefSize and maxSize are initialized
// with item's preferred Size: this is QSizePolicy::Fixed.
//
@@ -139,7 +131,7 @@ static void sizeHintsFromItem(QGraphicsLayoutItem *item,
// Note that these two initializations are affected by the previous flags
if (policy & QSizePolicy::IgnoreFlag)
- *prefSize = *maxSize;
+ *prefSize = *minSize;
else
*prefSize = prefSizeHint;
@@ -153,38 +145,63 @@ void AnchorData::refreshSizeHints(qreal effectiveSpacing)
{
const bool isInternalAnchor = from->m_item == to->m_item;
+ QSizePolicy::Policy policy;
+ qreal minSizeHint;
+ qreal prefSizeHint;
+ qreal maxSizeHint;
+
if (isInternalAnchor) {
const QGraphicsAnchorLayoutPrivate::Orientation orient =
QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge);
+ const Qt::AnchorPoint centerEdge =
+ QGraphicsAnchorLayoutPrivate::pickEdge(Qt::AnchorHorizontalCenter, orient);
+ bool hasCenter = (from->m_edge == centerEdge || to->m_edge == centerEdge);
if (isLayoutAnchor) {
minSize = 0;
prefSize = 0;
expSize = 0;
maxSize = QWIDGETSIZE_MAX;
+ if (hasCenter)
+ maxSize /= 2;
+ return;
} else {
- QGraphicsLayoutItem *item = from->m_item;
- sizeHintsFromItem(item, orient, &minSize, &prefSize, &expSize, &maxSize);
- }
- const Qt::AnchorPoint centerEdge =
- QGraphicsAnchorLayoutPrivate::pickEdge(Qt::AnchorHorizontalCenter, orient);
- bool hasCenter = (from->m_edge == centerEdge || to->m_edge == centerEdge);
+ QGraphicsLayoutItem *item = from->m_item;
+ if (orient == QGraphicsAnchorLayoutPrivate::Horizontal) {
+ policy = item->sizePolicy().horizontalPolicy();
+ minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).width();
+ prefSizeHint = item->effectiveSizeHint(Qt::PreferredSize).width();
+ maxSizeHint = item->effectiveSizeHint(Qt::MaximumSize).width();
+ } else {
+ policy = item->sizePolicy().verticalPolicy();
+ minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).height();
+ prefSizeHint = item->effectiveSizeHint(Qt::PreferredSize).height();
+ maxSizeHint = item->effectiveSizeHint(Qt::MaximumSize).height();
+ }
- if (hasCenter) {
- minSize /= 2;
- prefSize /= 2;
- expSize /= 2;
- maxSize /= 2;
+ if (hasCenter) {
+ minSizeHint /= 2;
+ prefSizeHint /= 2;
+ maxSizeHint /= 2;
+ }
}
-
- } else if (!hasSize) {
- // Anchor has no size defined, use given default information
- minSize = effectiveSpacing;
- prefSize = effectiveSpacing;
- expSize = effectiveSpacing;
- maxSize = effectiveSpacing;
+ } else {
+ Q_ASSERT(graphicsAnchor);
+ policy = graphicsAnchor->sizePolicy();
+ minSizeHint = 0;
+ if (hasSize) {
+ // One can only configure the preferred size of a normal anchor. Their minimum and
+ // maximum "size hints" are always 0 and QWIDGETSIZE_MAX, correspondingly. However,
+ // their effective size hints might be narrowed down due to their size policies.
+ prefSizeHint = prefSize;
+ } else {
+ prefSizeHint = effectiveSpacing;
+ }
+ maxSizeHint = QWIDGETSIZE_MAX;
}
+ internalSizeHints(policy, minSizeHint, prefSizeHint, maxSizeHint,
+ &minSize, &prefSize, &expSize, &maxSize);
// Set the anchor effective sizes to preferred.
//
@@ -250,44 +267,61 @@ void ParallelAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
0 is at Preferred
1 is at Maximum
*/
-static qreal getFactor(qreal value, qreal min, qreal pref, qreal max)
-{
- // ### Maybe remove some of the assertions? (since outside is asserting us)
- Q_ASSERT(value > min || qFuzzyCompare(value, min));
- Q_ASSERT(value < max || qFuzzyCompare(value, max));
-
- if (qFuzzyCompare(value, min)) {
- return -1.0;
- } else if (qFuzzyCompare(value, pref)) {
- return 0.0;
- } else if (qFuzzyCompare(value, max)) {
- return 1.0;
- } else if (value < pref) {
- // Since value < pref and value != pref and min <= value,
- // we can assert that min < pref.
- Q_ASSERT(min < pref);
- return (value - min) / (pref - min) - 1;
+static QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> getFactor(qreal value, qreal min,
+ qreal pref, qreal exp,
+ qreal max)
+{
+ QGraphicsAnchorLayoutPrivate::Interval interval;
+ qreal lower;
+ qreal upper;
+
+ if (value < pref) {
+ interval = QGraphicsAnchorLayoutPrivate::MinToPreferred;
+ lower = min;
+ upper = pref;
+ } else if (value < exp) {
+ interval = QGraphicsAnchorLayoutPrivate::PreferredToExpanding;
+ lower = pref;
+ upper = exp;
} else {
- // Since value > pref and value != pref and max >= value,
- // we can assert that max > pref.
- Q_ASSERT(max > pref);
- return (value - pref) / (max - pref);
+ interval = QGraphicsAnchorLayoutPrivate::ExpandingToMax;
+ lower = exp;
+ upper = max;
}
+
+ qreal progress;
+ if (upper == lower) {
+ progress = 0;
+ } else {
+ progress = (value - lower) / (upper - lower);
+ }
+
+ return qMakePair(interval, progress);
}
-static qreal getExpandingFactor(const qreal &expSize, const qreal &sizeAtPreferred,
- const qreal &sizeAtExpanding, const qreal &sizeAtMaximum)
+static qreal interpolate(const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> &factor,
+ qreal min, qreal pref,
+ qreal exp, qreal max)
{
- const qreal lower = qMin(sizeAtPreferred, sizeAtMaximum);
- const qreal upper = qMax(sizeAtPreferred, sizeAtMaximum);
- const qreal boundedExpSize = qBound(lower, expSize, upper);
+ qreal lower;
+ qreal upper;
- const qreal bandSize = sizeAtMaximum - boundedExpSize;
- if (bandSize == 0) {
- return 0;
- } else {
- return (sizeAtExpanding - boundedExpSize) / bandSize;
+ switch (factor.first) {
+ case QGraphicsAnchorLayoutPrivate::MinToPreferred:
+ lower = min;
+ upper = pref;
+ break;
+ case QGraphicsAnchorLayoutPrivate::PreferredToExpanding:
+ lower = pref;
+ upper = exp;
+ break;
+ case QGraphicsAnchorLayoutPrivate::ExpandingToMax:
+ lower = exp;
+ upper = max;
+ break;
}
+
+ return lower + factor.second * (upper - lower);
}
void SequentialAnchorData::updateChildrenSizes()
@@ -307,27 +341,22 @@ void SequentialAnchorData::updateChildrenSizes()
// Band here refers if the value is in the Minimum To Preferred
// band (the lower band) or the Preferred To Maximum (the upper band).
- const qreal minFactor = getFactor(sizeAtMinimum, minSize, prefSize, maxSize);
- const qreal prefFactor = getFactor(sizeAtPreferred, minSize, prefSize, maxSize);
- const qreal maxFactor = getFactor(sizeAtMaximum, minSize, prefSize, maxSize);
- const qreal expFactor = getExpandingFactor(expSize, sizeAtPreferred, sizeAtExpanding, sizeAtMaximum);
+ const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> minFactor =
+ getFactor(sizeAtMinimum, minSize, prefSize, expSize, maxSize);
+ const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> prefFactor =
+ getFactor(sizeAtPreferred, minSize, prefSize, expSize, maxSize);
+ const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> expFactor =
+ getFactor(sizeAtExpanding, minSize, prefSize, expSize, maxSize);
+ const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> maxFactor =
+ getFactor(sizeAtMaximum, minSize, prefSize, expSize, maxSize);
for (int i = 0; i < m_edges.count(); ++i) {
AnchorData *e = m_edges.at(i);
- qreal bandSize = minFactor > 0 ? e->maxSize - e->prefSize : e->prefSize - e->minSize;
- e->sizeAtMinimum = e->prefSize + bandSize * minFactor;
-
- bandSize = prefFactor > 0 ? e->maxSize - e->prefSize : e->prefSize - e->minSize;
- e->sizeAtPreferred = e->prefSize + bandSize * prefFactor;
-
- bandSize = maxFactor > 0 ? e->maxSize - e->prefSize : e->prefSize - e->minSize;
- e->sizeAtMaximum = e->prefSize + bandSize * maxFactor;
-
- const qreal lower = qMin(e->sizeAtPreferred, e->sizeAtMaximum);
- const qreal upper = qMax(e->sizeAtPreferred, e->sizeAtMaximum);
- const qreal edgeBoundedExpSize = qBound(lower, e->expSize, upper);
- e->sizeAtExpanding = edgeBoundedExpSize + expFactor * (e->sizeAtMaximum - edgeBoundedExpSize);
+ e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->prefSize, e->expSize, e->maxSize);
+ e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->prefSize, e->expSize, e->maxSize);
+ e->sizeAtExpanding = interpolate(expFactor, e->minSize, e->prefSize, e->expSize, e->maxSize);
+ e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->prefSize, e->expSize, e->maxSize);
e->updateChildrenSizes();
}
@@ -494,36 +523,46 @@ static bool simplifySequentialChunk(Graph<AnchorVertex, AnchorData> *graph,
const QVector<AnchorVertex*> &vertices,
AnchorVertex *after)
{
- int i;
+ AnchorData *data = graph->edgeData(before, vertices.first());
+ Q_ASSERT(data);
+
+ const bool forward = (before == data->from);
+ QVector<AnchorVertex *> orderedVertices;
+
+ if (forward) {
+ orderedVertices = vertices;
+ } else {
+ qSwap(before, after);
+ for (int i = vertices.count() - 1; i >= 0; --i)
+ orderedVertices.append(vertices.at(i));
+ }
+
#if defined(QT_DEBUG) && 0
QString strVertices;
- for (i = 0; i < vertices.count(); ++i)
- strVertices += QString::fromAscii("%1 - ").arg(vertices.at(i)->toString());
+ for (int i = 0; i < orderedVertices.count(); ++i) {
+ strVertices += QString::fromAscii("%1 - ").arg(orderedVertices.at(i)->toString());
+ }
QString strPath = QString::fromAscii("%1 - %2%3").arg(before->toString(), strVertices, after->toString());
qDebug("simplifying [%s] to [%s - %s]", qPrintable(strPath), qPrintable(before->toString()), qPrintable(after->toString()));
#endif
SequentialAnchorData *sequence = new SequentialAnchorData;
AnchorVertex *prev = before;
- AnchorData *data;
- for (i = 0; i <= vertices.count(); ++i) {
- AnchorVertex *next = (i < vertices.count()) ? vertices.at(i) : after;
- data = graph->takeEdge(prev, next);
- sequence->m_edges.append(data);
+
+ for (int i = 0; i <= orderedVertices.count(); ++i) {
+ AnchorVertex *next = (i < orderedVertices.count()) ? orderedVertices.at(i) : after;
+ AnchorData *ad = graph->takeEdge(prev, next);
+ Q_ASSERT(ad);
+ sequence->m_edges.append(ad);
prev = next;
}
- sequence->setVertices(vertices);
+
+ sequence->setVertices(orderedVertices);
sequence->from = before;
sequence->to = after;
sequence->refreshSizeHints_helper(0, false);
- // data here is the last edge in the sequence
- // ### this seems to be here for supporting reverse order sequences,
- // but doesnt seem to be used right now
- if (data->from != vertices.last())
- qSwap(sequence->from, sequence->to);
-
// Note that since layout 'edges' can't be simplified away from
// the graph, it's safe to assume that if there's a layout
// 'edge', it'll be in the boundaries of the sequence.
@@ -578,15 +617,6 @@ static bool simplifySequentialChunk(Graph<AnchorVertex, AnchorData> *graph,
2. Go to (1)
3. Done
-
- * Gathering sequential anchors *
- The algorithm walks the graph in depth-first order, and only collects vertices that has two
- edges connected to it. If the vertex does not have two edges or if it is a layout edge,
- it will take all the previously collected vertices and try to create a simplified sequential
- anchor representing all the previously collected vertices.
- Once the simplified anchor is inserted, the collected list is cleared in order to find the next
- sequence to simplify.
- Note that there are some catches to this that are not covered by the above explanation.
*/
void QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation)
{
@@ -603,9 +633,7 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation)
orientation == Horizontal ? "Horizontal" : "Vertical");
#endif
- AnchorVertex *rootVertex = graph[orientation].rootVertex();
-
- if (!rootVertex)
+ if (!graph[orientation].rootVertex())
return;
bool dirty;
@@ -614,164 +642,171 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation)
} while (dirty);
}
+/*!
+ \internal
+
+ One iteration of the simplification algorithm. Returns true if another iteration is needed.
+
+ The algorithm walks the graph in depth-first order, and only collects vertices that has two
+ edges connected to it. If the vertex does not have two edges or if it is a layout edge, it
+ will take all the previously collected vertices and try to create a simplified sequential
+ anchor representing all the previously collected vertices. Once the simplified anchor is
+ inserted, the collected list is cleared in order to find the next sequence to simplify.
+
+ Note that there are some catches to this that are not covered by the above explanation, see
+ the function comments for more details.
+*/
bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutPrivate::Orientation orientation)
{
Q_Q(QGraphicsAnchorLayout);
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
- AnchorVertex *v = g.rootVertex();
QSet<AnchorVertex *> visited;
- QStack<AnchorVertex *> stack;
- stack.push(v);
+ QStack<QPair<AnchorVertex *, AnchorVertex *> > stack;
+ stack.push(qMakePair(static_cast<AnchorVertex *>(0), g.rootVertex()));
QVector<AnchorVertex*> candidates;
+ bool candidatesForward;
const Qt::AnchorPoint centerEdge = pickEdge(Qt::AnchorHorizontalCenter, orientation);
- const Qt::AnchorPoint layoutEdge = oppositeEdge(v->m_edge);
- bool dirty = false;
-
- // walk depth-first.
+ // Walk depth-first, in the stack we store start of the candidate sequence (beforeSequence)
+ // and the vertex to be visited.
while (!stack.isEmpty()) {
- v = stack.pop();
- QList<AnchorVertex *> vertices = g.adjacentVertices(v);
- const int count = vertices.count();
- bool endOfSequence = (v->m_item == q && v->m_edge == layoutEdge) || count != 2;
- if (count == 2 && v->m_item != q) {
- candidates.append(v);
- if (visited.contains(vertices.first()) && visited.contains(vertices.last())) {
- // in case of a cycle
- endOfSequence = true;
+ QPair<AnchorVertex *, AnchorVertex *> pair = stack.pop();
+ AnchorVertex *beforeSequence = pair.first;
+ AnchorVertex *v = pair.second;
+
+ // The basic idea is to determine whether we found an end of sequence,
+ // if that's the case, we stop adding vertices to the candidate list
+ // and do a simplification step.
+ //
+ // A vertex can trigger an end of sequence if
+ // (a) it is a layout vertex, we don't simplify away the layout vertices;
+ // (b) it does not have exactly 2 adjacents;
+ // (c) it will change the direction of the sequence;
+ // (d) its next adjacent is already visited (a cycle in the graph).
+
+ const QList<AnchorVertex *> &adjacents = g.adjacentVertices(v);
+ const bool isLayoutVertex = v->m_item == q;
+ AnchorVertex *afterSequence = v;
+ bool endOfSequence = false;
+
+ //
+ // Identify the end cases.
+ //
+
+ // Identifies cases (a) and (b)
+ endOfSequence = isLayoutVertex || adjacents.count() != 2;
+
+ if (!endOfSequence) {
+ // If this is the first vertice, determine what is the direction to use for this
+ // sequence.
+ if (candidates.isEmpty()) {
+ const AnchorData *data = g.edgeData(beforeSequence, v);
+ Q_ASSERT(data);
+ candidatesForward = (beforeSequence == data->from);
}
- }
- if (endOfSequence && candidates.count() >= 1) {
- int i;
- AnchorVertex *afterSequence= 0;
- AnchorVertex *beforeSequence = 0;
- // find the items before and after the valid sequence
- if (candidates.count() == 1) {
- QList<AnchorVertex *> beforeAndAfterVertices = g.adjacentVertices(candidates.at(0));
- Q_ASSERT(beforeAndAfterVertices.count() == 2);
- // Since we only have one vertex, we can pick
- // any of the two vertices to become before/after.
- afterSequence = beforeAndAfterVertices.last();
- beforeSequence = beforeAndAfterVertices.first();
- } else {
- QList<AnchorVertex *> adjacentOfSecondLastVertex = g.adjacentVertices(candidates.last());
- Q_ASSERT(adjacentOfSecondLastVertex.count() == 2);
- if (adjacentOfSecondLastVertex.first() == candidates.at(candidates.count() - 2))
- afterSequence = adjacentOfSecondLastVertex.last();
- else
- afterSequence = adjacentOfSecondLastVertex.first();
- QList<AnchorVertex *> adjacentOfSecondVertex = g.adjacentVertices(candidates.first());
- Q_ASSERT(adjacentOfSecondVertex.count() == 2);
- if (adjacentOfSecondVertex.first() == candidates.at(1))
- beforeSequence = adjacentOfSecondVertex.last();
- else
- beforeSequence = adjacentOfSecondVertex.first();
+ // This is a tricky part. We peek at the next vertex to find out
+ //
+ // - whether the edge from this vertex to the next vertex has the same direction;
+ // - whether we already visited the next vertex.
+ //
+ // Those are needed to identify (c) and (d). Note that unlike (a) and (b), we preempt
+ // the end of sequence by looking into the next vertex.
+
+ // Peek at the next vertex
+ AnchorVertex *after;
+ if (candidates.isEmpty())
+ after = (beforeSequence == adjacents.last() ? adjacents.first() : adjacents.last());
+ else
+ after = (candidates.last() == adjacents.last() ? adjacents.first() : adjacents.last());
+
+ // ### At this point we assumed that candidates will not contain 'after', this may not hold
+ // when simplifying FLOATing anchors.
+ Q_ASSERT(!candidates.contains(after));
+
+ const AnchorData *data = g.edgeData(v, after);
+ Q_ASSERT(data);
+ const bool willChangeDirection = (candidatesForward != (v == data->from));
+ const bool cycleFound = visited.contains(after);
+
+ // Now cases (c) and (d)...
+ endOfSequence = willChangeDirection || cycleFound;
+
+ if (endOfSequence) {
+ if (!willChangeDirection) {
+ // If the direction will not change, we can add the current vertex to the
+ // candidates list and we know that 'after' can be used as afterSequence.
+ candidates.append(v);
+ afterSequence = after;
+ }
+ } else {
+ // If it's not an end of sequence, then the vertex didn't trigger neither of the
+ // previously four cases, so it can be added to the candidates list.
+ candidates.append(v);
}
- // The complete path of the sequence to simplify is: beforeSequence, <candidates>, afterSequence
- // where beforeSequence and afterSequence are the endpoints where the anchor is inserted
- // between.
-#if defined(QT_DEBUG) && 0
- // ### DEBUG
- QString strCandidates;
- for (i = 0; i < candidates.count(); ++i)
- strCandidates += QString::fromAscii("%1 - ").arg(candidates.at(i)->toString());
- QString strPath = QString::fromAscii("%1 - %2%3").arg(beforeSequence->toString(), strCandidates, afterSequence->toString());
- qDebug("candidate list for sequential simplification:\n[%s]", qPrintable(strPath));
-#endif
+ }
- bool forward = true;
- AnchorVertex *prev = beforeSequence;
- int intervalFrom = 0;
+ //
+ // Add next non-visited vertices to the stack.
+ //
+ for (int i = 0; i < adjacents.count(); ++i) {
+ AnchorVertex *next = adjacents.at(i);
+ if (visited.contains(next))
+ continue;
- // Check for directionality (from). We don't want to destroy that information,
- // thus we only combine anchors with the same direction.
+ // If current vertex is an end of sequence, and it'll reset the candidates list. So
+ // the next vertices will build candidates lists with the current vertex as 'before'
+ // vertex. If it's not an end of sequence, we keep the original 'before' vertex,
+ // since we are keeping the candidates list.
+ if (endOfSequence)
+ stack.push(qMakePair(v, next));
+ else
+ stack.push(qMakePair(beforeSequence, next));
+ }
- // "i" is the index *including* the beforeSequence and afterSequence vertices.
- for (i = 1; i <= candidates.count() + 1; ++i) {
- bool atVertexAfter = i > candidates.count();
- AnchorVertex *v1 = atVertexAfter ? afterSequence : candidates.at(i - 1);
- AnchorData *data = g.edgeData(prev, v1);
- Q_ASSERT(data);
- if (i == 1) {
- forward = (prev == data->from ? true : false);
- } else if (forward != (prev == data->from) || atVertexAfter) {
- int intervalTo = i;
- if (forward != (prev == data->from))
- --intervalTo;
-
- // intervalFrom and intervalTo should now be indices to the vertex before and
- // after the sequential anchor.
- if (intervalTo - intervalFrom >= 2) {
- // simplify in the range [intervalFrom, intervalTo]
-
- // Trim off internal center anchors (Left-Center/Center-Right) from the
- // start and the end of the sequence. We never want to simplify internal
- // center anchors where there is an external anchor connected to the center.
- AnchorVertex *intervalVertexFrom = intervalFrom == 0 ? beforeSequence : candidates.at(intervalFrom - 1);
- int effectiveIntervalFrom = intervalFrom;
- if (intervalVertexFrom->m_edge == centerEdge
- && intervalVertexFrom->m_item == candidates.at(effectiveIntervalFrom)->m_item) {
- ++effectiveIntervalFrom;
- intervalVertexFrom = candidates.at(effectiveIntervalFrom - 1);
- }
- AnchorVertex *intervalVertexTo = intervalTo <= candidates.count() ? candidates.at(intervalTo - 1) : afterSequence;
- int effectiveIntervalTo = intervalTo;
- if (intervalVertexTo->m_edge == centerEdge
- && intervalVertexTo->m_item == candidates.at(effectiveIntervalTo - 2)->m_item) {
- --effectiveIntervalTo;
- intervalVertexTo = candidates.at(effectiveIntervalTo - 1);
- }
- if (effectiveIntervalTo - effectiveIntervalFrom >= 2) {
- QVector<AnchorVertex*> subCandidates;
- if (forward) {
- subCandidates = candidates.mid(effectiveIntervalFrom, effectiveIntervalTo - effectiveIntervalFrom - 1);
- } else {
- // reverse the order of the candidates.
- qSwap(intervalVertexFrom, intervalVertexTo);
- do {
- ++effectiveIntervalFrom;
- subCandidates.prepend(candidates.at(effectiveIntervalFrom - 1));
- } while (effectiveIntervalFrom < effectiveIntervalTo - 1);
- }
- if (simplifySequentialChunk(&g, intervalVertexFrom, subCandidates, intervalVertexTo)) {
- dirty = true;
- break;
- }
- // finished simplification of chunk with same direction
- }
- }
- if (forward == (prev == data->from))
- --intervalTo;
- intervalFrom = intervalTo;
-
- forward = !forward;
- }
- prev = v1;
- }
+ visited.insert(v);
- if (dirty)
- break;
- }
+ if (!endOfSequence || candidates.isEmpty())
+ continue;
- if (endOfSequence)
- candidates.clear();
+ //
+ // Create a sequence for (beforeSequence, candidates, afterSequence).
+ //
- for (int i = 0; i < count; ++i) {
- AnchorVertex *next = vertices.at(i);
- if (next->m_item == q && next->m_edge == centerEdge)
+ // One restriction we have is to not simplify half of an anchor and let the other half
+ // unsimplified. So we remove center edges before and after the sequence.
+ if (beforeSequence->m_edge == centerEdge && beforeSequence->m_item == candidates.first()->m_item) {
+ beforeSequence = candidates.first();
+ candidates.remove(0);
+
+ // If there's not candidates to be simplified, leave.
+ if (candidates.isEmpty())
continue;
- if (visited.contains(next))
+ }
+
+ if (afterSequence->m_edge == centerEdge && afterSequence->m_item == candidates.last()->m_item) {
+ afterSequence = candidates.last();
+ candidates.remove(candidates.count() - 1);
+
+ if (candidates.isEmpty())
continue;
- stack.push(next);
}
- visited.insert(v);
+ // This function will remove the candidates from the graph and create one edge between
+ // beforeSequence and afterSequence. This function returns true if the sequential
+ // simplification also caused a parallel simplification to be created. In this case we end
+ // the iteration and start again (since all the visited state we have may be outdated).
+ if (simplifySequentialChunk(&g, beforeSequence, candidates, afterSequence))
+ return true;
+
+ // If there was no parallel simplification, we'll keep walking the graph. So we clear the
+ // candidates list to start again.
+ candidates.clear();
}
- return dirty;
+ return false;
}
static void restoreSimplifiedAnchor(Graph<AnchorVertex, AnchorData> &g,
@@ -1173,18 +1208,18 @@ QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *fi
|| secondItem == q
|| pickEdge(firstEdge, Horizontal) == Qt::AnchorHorizontalCenter
|| oppositeEdge(firstEdge) != secondEdge) {
- data->setFixedSize(0);
+ data->setPreferredSize(0);
} else {
data->unsetSize();
}
addAnchor_helper(firstItem, firstEdge, secondItem, secondEdge, data);
} else if (*spacing >= 0) {
- data->setFixedSize(*spacing);
+ data->setPreferredSize(*spacing);
addAnchor_helper(firstItem, firstEdge, secondItem, secondEdge, data);
} else {
- data->setFixedSize(-*spacing);
+ data->setPreferredSize(-*spacing);
addAnchor_helper(secondItem, secondEdge, firstItem, firstEdge, data);
}
@@ -1371,9 +1406,9 @@ void QGraphicsAnchorLayoutPrivate::setAnchorSize(AnchorData *data, const qreal *
// positive by definition.
// "negative spacing" is handled by inverting the standard item order.
if (*anchorSize >= 0) {
- data->setFixedSize(*anchorSize);
+ data->setPreferredSize(*anchorSize);
} else {
- data->setFixedSize(-*anchorSize);
+ data->setPreferredSize(-*anchorSize);
qSwap(data->from, data->to);
}
} else {
@@ -1550,6 +1585,13 @@ qreal QGraphicsAnchorLayoutPrivate::effectiveSpacing(Orientation orientation) co
}
}
}
+
+ // ### Currently we do not support negative anchors inside the graph.
+ // To avoid those being created by a negative style spacing, we must
+ // make this test.
+ if (s < 0)
+ s = 0;
+
return s;
}
@@ -1565,13 +1607,24 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs()
if (!calculateGraphCacheDirty)
return;
+#if defined(QT_DEBUG) && 0
+ static int count = 0;
+ count++;
+ dumpGraph(QString::fromAscii("%1-before").arg(count));
+#endif
+
calculateGraphs(Horizontal);
calculateGraphs(Vertical);
+#if defined(QT_DEBUG) && 0
+ dumpGraph(QString::fromAscii("%1-after").arg(count));
+#endif
+
calculateGraphCacheDirty = 0;
}
-// ### remove me:
+// ### Maybe getGraphParts could return the variables when traversing, at least
+// for trunk...
QList<AnchorData *> getVariables(QList<QSimplexConstraint *> constraints)
{
QSet<AnchorData *> variableSet;
@@ -1635,65 +1688,92 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(
// 2) The floating or semi-floating anchors (items) that are those which
// are connected to only one (or none) of the layout sides, thus are not
// influenced by the layout size.
- QList<QList<QSimplexConstraint *> > parts;
- parts = getGraphParts(orientation);
+ QList<QList<QSimplexConstraint *> > parts = getGraphParts(orientation);
// Now run the simplex solver to calculate Minimum, Preferred and Maximum sizes
// of the "trunk" set of constraints and variables.
// ### does trunk always exist? empty = trunk is the layout left->center->right
QList<QSimplexConstraint *> trunkConstraints = parts[0];
- QList<QSimplexConstraint *> sizeHintConstraints;
- sizeHintConstraints = constraintsFromSizeHints(getVariables(trunkConstraints));
- trunkConstraints += sizeHintConstraints;
+ QList<AnchorData *> trunkVariables = getVariables(trunkConstraints);
// For minimum and maximum, use the path between the two layout sides as the
// objective function.
-
- // Retrieve that path
AnchorVertex *v = internalVertex(q, pickEdge(Qt::AnchorRight, orientation));
GraphPath trunkPath = graphPaths[orientation].value(v);
+ bool feasible = calculateTrunk(orientation, trunkPath, trunkConstraints, trunkVariables);
+
+ // For the other parts that not the trunk, solve only for the preferred size
+ // that is the size they will remain at, since they are not stretched by the
+ // layout.
+
+ // Skipping the first (trunk)
+ for (int i = 1; i < parts.count(); ++i) {
+ if (!feasible)
+ break;
+
+ QList<QSimplexConstraint *> partConstraints = parts[i];
+ QList<AnchorData *> partVariables = getVariables(partConstraints);
+ Q_ASSERT(!partVariables.isEmpty());
+ feasible &= calculateNonTrunk(partConstraints, partVariables);
+ }
+
+ // Propagate the new sizes down the simplified graph, ie. tell the
+ // group anchors to set their children anchors sizes.
+ updateAnchorSizes(orientation);
+
+ graphHasConflicts[orientation] = !feasible;
+
+ // Clean up our data structures. They are not needed anymore since
+ // distribution uses just interpolation.
+ qDeleteAll(constraints[orientation]);
+ constraints[orientation].clear();
+ graphPaths[orientation].clear(); // ###
+}
+
+/*!
+ \internal
+
+ Calculate the sizes for all anchors which are part of the trunk. This works
+ on top of a (possibly) simplified graph.
+*/
+bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const GraphPath &path,
+ const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables)
+{
bool feasible = true;
- if (!trunkConstraints.isEmpty()) {
+ bool needsSimplex = !constraints.isEmpty();
+
#if 0
- qDebug("Simplex used for trunk of %s",
- orientation == Horizontal ? "Horizontal" : "Vertical");
+ qDebug("Simplex %s for trunk of %s", needsSimplex ? "used" : "NOT used",
+ orientation == Horizontal ? "Horizontal" : "Vertical");
#endif
- // Solve min and max size hints for trunk
- qreal min, max;
- feasible = solveMinMax(trunkConstraints, trunkPath, &min, &max);
+ if (needsSimplex) {
- if (feasible) {
- // Solve for preferred. The objective function is calculated from the constraints
- // and variables internally.
- solvePreferred(trunkConstraints);
+ QList<QSimplexConstraint *> sizeHintConstraints = constraintsFromSizeHints(variables);
+ QList<QSimplexConstraint *> allConstraints = constraints + sizeHintConstraints;
- // remove sizeHintConstraints from trunkConstraints
- trunkConstraints = parts[0];
-
- // Solve for expanding. The objective function and the constraints from items
- // are calculated internally.
- solveExpanding(trunkConstraints);
-
- // Propagate the new sizes down the simplified graph, ie. tell the
- // group anchors to set their children anchors sizes.
+ // Solve min and max size hints
+ qreal min, max;
+ feasible = solveMinMax(allConstraints, path, &min, &max);
- // ### we calculated variables already a few times, can't we reuse that?
- QList<AnchorData *> trunkVariables = getVariables(trunkConstraints);
+ if (feasible) {
+ solvePreferred(allConstraints, variables);
- for (int i = 0; i < trunkVariables.count(); ++i)
- trunkVariables.at(i)->updateChildrenSizes();
+ // Note that we don't include the sizeHintConstraints, since they
+ // have a different logic for solveExpanding().
+ solveExpanding(constraints, variables);
// Calculate and set the preferred and expanding sizes for the layout,
// from the edge sizes that were calculated above.
qreal pref(0.0);
qreal expanding(0.0);
- foreach (const AnchorData *ad, trunkPath.positives) {
+ foreach (const AnchorData *ad, path.positives) {
pref += ad->sizeAtPreferred;
expanding += ad->sizeAtExpanding;
}
- foreach (const AnchorData *ad, trunkPath.negatives) {
+ foreach (const AnchorData *ad, path.negatives) {
pref -= ad->sizeAtPreferred;
expanding -= ad->sizeAtExpanding;
}
@@ -1703,76 +1783,57 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(
sizeHints[orientation][Qt::MaximumSize] = max;
sizeAtExpanding[orientation] = expanding;
}
- } else {
-#if 0
- qDebug("Simplex NOT used for trunk of %s",
- orientation == Horizontal ? "Horizontal" : "Vertical");
-#endif
+ qDeleteAll(sizeHintConstraints);
+
+ } else {
// No Simplex is necessary because the path was simplified all the way to a single
// anchor.
- Q_ASSERT(trunkPath.positives.count() == 1);
- Q_ASSERT(trunkPath.negatives.count() == 0);
+ Q_ASSERT(path.positives.count() == 1);
+ Q_ASSERT(path.negatives.count() == 0);
- AnchorData *ad = trunkPath.positives.toList()[0];
+ AnchorData *ad = path.positives.toList()[0];
ad->sizeAtMinimum = ad->minSize;
ad->sizeAtPreferred = ad->prefSize;
ad->sizeAtExpanding = ad->expSize;
ad->sizeAtMaximum = ad->maxSize;
- // Propagate
- ad->updateChildrenSizes();
-
sizeHints[orientation][Qt::MinimumSize] = ad->sizeAtMinimum;
sizeHints[orientation][Qt::PreferredSize] = ad->sizeAtPreferred;
sizeHints[orientation][Qt::MaximumSize] = ad->sizeAtMaximum;
sizeAtExpanding[orientation] = ad->sizeAtExpanding;
}
- // Delete the constraints, we won't use them anymore.
- qDeleteAll(sizeHintConstraints);
- sizeHintConstraints.clear();
+#if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT)
+ lastCalculationUsedSimplex[orientation] = needsSimplex;
+#endif
- // For the other parts that not the trunk, solve only for the preferred size
- // that is the size they will remain at, since they are not stretched by the
- // layout.
+ return feasible;
+}
- // Solve the other only for preferred, skip trunk
- if (feasible) {
- for (int i = 1; i < parts.count(); ++i) {
- QList<QSimplexConstraint *> partConstraints = parts[i];
- QList<AnchorData *> partVariables = getVariables(partConstraints);
- Q_ASSERT(!partVariables.isEmpty());
-
- sizeHintConstraints = constraintsFromSizeHints(partVariables);
- partConstraints += sizeHintConstraints;
- feasible &= solvePreferred(partConstraints);
- if (!feasible)
- break;
-
- // Propagate size at preferred to other sizes. Semi-floats
- // always will be in their sizeAtPreferred.
- for (int j = 0; j < partVariables.count(); ++j) {
- AnchorData *ad = partVariables[j];
- Q_ASSERT(ad);
- ad->sizeAtMinimum = ad->sizeAtPreferred;
- ad->sizeAtExpanding = ad->sizeAtPreferred;
- ad->sizeAtMaximum = ad->sizeAtPreferred;
- ad->updateChildrenSizes();
- }
+/*!
+ \internal
+*/
+bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables)
+{
+ QList<QSimplexConstraint *> sizeHintConstraints = constraintsFromSizeHints(variables);
+ bool feasible = solvePreferred(constraints + sizeHintConstraints, variables);
- // Delete the constraints, we won't use them anymore.
- qDeleteAll(sizeHintConstraints);
- sizeHintConstraints.clear();
+ if (feasible) {
+ // Propagate size at preferred to other sizes. Semi-floats always will be
+ // in their sizeAtPreferred.
+ for (int j = 0; j < variables.count(); ++j) {
+ AnchorData *ad = variables[j];
+ Q_ASSERT(ad);
+ ad->sizeAtMinimum = ad->sizeAtPreferred;
+ ad->sizeAtExpanding = ad->sizeAtPreferred;
+ ad->sizeAtMaximum = ad->sizeAtPreferred;
}
}
- graphHasConflicts[orientation] = !feasible;
- // Clean up our data structures. They are not needed anymore since
- // distribution uses just interpolation.
- qDeleteAll(constraints[orientation]);
- constraints[orientation].clear();
- graphPaths[orientation].clear(); // ###
+ qDeleteAll(sizeHintConstraints);
+ return feasible;
}
/*!
@@ -1876,6 +1937,20 @@ void QGraphicsAnchorLayoutPrivate::constraintsFromPaths(Orientation orientation)
/*!
\internal
+*/
+void QGraphicsAnchorLayoutPrivate::updateAnchorSizes(Orientation orientation)
+{
+ Graph<AnchorVertex, AnchorData> &g = graph[orientation];
+ const QList<QPair<AnchorVertex *, AnchorVertex *> > &vertices = g.connections();
+
+ for (int i = 0; i < vertices.count(); ++i) {
+ AnchorData *ad = g.edgeData(vertices.at(i).first, vertices.at(i).second);
+ ad->updateChildrenSizes();
+ }
+}
+
+/*!
+ \internal
Create LP constraints for each anchor based on its minimum and maximum
sizes, as specified in its size hints
@@ -2160,39 +2235,26 @@ void QGraphicsAnchorLayoutPrivate::calculateVertexPositions(
\internal
Calculate interpolation parameters based on current Layout Size.
- Must once before calling "interpolateEdgeSize()" for each edge.
+ Must be called once before calling "interpolateEdgeSize()" for
+ the edges.
*/
void QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation(
Orientation orientation)
{
Q_Q(QGraphicsAnchorLayout);
- qreal lower, upper, current;
- if (orientation == Horizontal) {
- current = q->contentsRect().width();
- } else {
- current = q->contentsRect().height();
- }
+ qreal current;
+ current = (orientation == Horizontal) ? q->contentsRect().width() : q->contentsRect().height();
- if (current < sizeHints[orientation][Qt::PreferredSize]) {
- interpolationInterval[orientation] = MinToPreferred;
- lower = sizeHints[orientation][Qt::MinimumSize];
- upper = sizeHints[orientation][Qt::PreferredSize];
- } else if (current < sizeAtExpanding[orientation]) {
- interpolationInterval[orientation] = PreferredToExpanding;
- lower = sizeHints[orientation][Qt::PreferredSize];
- upper = sizeAtExpanding[orientation];
- } else {
- interpolationInterval[orientation] = ExpandingToMax;
- lower = sizeAtExpanding[orientation];
- upper = sizeHints[orientation][Qt::MaximumSize];
- }
+ QPair<Interval, qreal> result;
+ result = getFactor(current,
+ sizeHints[orientation][Qt::MinimumSize],
+ sizeHints[orientation][Qt::PreferredSize],
+ sizeAtExpanding[orientation],
+ sizeHints[orientation][Qt::MaximumSize]);
- if (upper == lower) {
- interpolationProgress[orientation] = 0;
- } else {
- interpolationProgress[orientation] = (current - lower) / (upper - lower);
- }
+ interpolationInterval[orientation] = result.first;
+ interpolationProgress[orientation] = result.second;
}
/*!
@@ -2219,20 +2281,11 @@ void QGraphicsAnchorLayoutPrivate::interpolateEdge(AnchorVertex *base,
AnchorData *edge,
Orientation orientation)
{
- qreal lower, upper;
+ const QPair<Interval, qreal> factor(interpolationInterval[orientation],
+ interpolationProgress[orientation]);
- if (interpolationInterval[orientation] == MinToPreferred) {
- lower = edge->sizeAtMinimum;
- upper = edge->sizeAtPreferred;
- } else if (interpolationInterval[orientation] == PreferredToExpanding) {
- lower = edge->sizeAtPreferred;
- upper = edge->sizeAtExpanding;
- } else {
- lower = edge->sizeAtExpanding;
- upper = edge->sizeAtMaximum;
- }
-
- qreal edgeDistance = (interpolationProgress[orientation] * (upper - lower)) + lower;
+ qreal edgeDistance = interpolate(factor, edge->sizeAtMinimum, edge->sizeAtPreferred,
+ edge->sizeAtExpanding, edge->sizeAtMaximum);
Q_ASSERT(edge->from == base || edge->to == base);
@@ -2303,7 +2356,7 @@ void QGraphicsAnchorLayoutPrivate::interpolateSequentialEdges(
interpolateEdge(prev, data->m_edges.last(), orientation);
}
-bool QGraphicsAnchorLayoutPrivate::solveMinMax(QList<QSimplexConstraint *> constraints,
+bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList<QSimplexConstraint *> &constraints,
GraphPath path, qreal *min, qreal *max)
{
QSimplex simplex;
@@ -2344,9 +2397,9 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(QList<QSimplexConstraint *> const
return feasible;
}
-bool QGraphicsAnchorLayoutPrivate::solvePreferred(QList<QSimplexConstraint *> constraints)
+bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables)
{
- QList<AnchorData *> variables = getVariables(constraints);
QList<QSimplexConstraint *> preferredConstraints;
QList<QSimplexVariable *> preferredVariables;
QSimplexConstraint objective;
@@ -2369,7 +2422,7 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(QList<QSimplexConstraint *> co
// A + A_shrinker - A_grower = A_pref
//
for (int i = 0; i < variables.size(); ++i) {
- AnchorData *ad = static_cast<AnchorData *>(variables[i]);
+ AnchorData *ad = variables[i];
if (ad->skipInPreferred)
continue;
@@ -2400,7 +2453,7 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(QList<QSimplexConstraint *> co
// Save sizeAtPreferred results
for (int i = 0; i < variables.size(); ++i) {
- AnchorData *ad = static_cast<AnchorData *>(variables[i]);
+ AnchorData *ad = variables[i];
ad->sizeAtPreferred = ad->result;
}
@@ -2461,9 +2514,9 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(QList<QSimplexConstraint *> co
expanding ones will shrink. Only after non-expanding anchors have
shrinked all the way, the expanding anchors will start to shrink too.
*/
-void QGraphicsAnchorLayoutPrivate::solveExpanding(QList<QSimplexConstraint *> constraints)
+void QGraphicsAnchorLayoutPrivate::solveExpanding(const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables)
{
- QList<AnchorData *> variables = getVariables(constraints);
QList<QSimplexConstraint *> itemConstraints;
QSimplexConstraint *objective = new QSimplexConstraint;
bool hasExpanding = false;
@@ -2566,9 +2619,9 @@ bool QGraphicsAnchorLayoutPrivate::hasConflicts() const
}
#ifdef QT_DEBUG
-void QGraphicsAnchorLayoutPrivate::dumpGraph()
+void QGraphicsAnchorLayoutPrivate::dumpGraph(const QString &name)
{
- QFile file(QString::fromAscii("anchorlayout.dot"));
+ QFile file(QString::fromAscii("anchorlayout.%1.dot").arg(name));
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
qWarning("Could not write to %s", file.fileName().toLocal8Bit().constData());
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index 9ac0e19..d45c004 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -169,16 +169,9 @@ struct AnchorData : public QSimplexVariable {
QString name;
#endif
- inline void setFixedSize(qreal size)
+ inline void setPreferredSize(qreal size)
{
- minSize = size;
prefSize = size;
- expSize = size;
- maxSize = size;
- sizeAtMinimum = size;
- sizeAtPreferred = size;
- sizeAtExpanding = size;
- sizeAtMaximum = size;
hasSize = true;
}
@@ -316,8 +309,11 @@ public:
void unsetSpacing();
qreal spacing() const;
+ void setSizePolicy(QSizePolicy::Policy policy);
+
QGraphicsAnchorLayoutPrivate *layoutPrivate;
AnchorData *data;
+ QSizePolicy::Policy sizePolicy;
};
@@ -438,9 +434,17 @@ public:
void calculateGraphs();
void calculateGraphs(Orientation orientation);
+
+ bool calculateTrunk(Orientation orientation, const GraphPath &trunkPath,
+ const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables);
+ bool calculateNonTrunk(const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables);
+
void setAnchorSizeHintsFromItems(Orientation orientation);
void findPaths(Orientation orientation);
void constraintsFromPaths(Orientation orientation);
+ void updateAnchorSizes(Orientation orientation);
QList<QSimplexConstraint *> constraintsFromSizeHints(const QList<AnchorData *> &anchors);
QList<QList<QSimplexConstraint *> > getGraphParts(Orientation orientation);
void identifyFloatItems(const QSet<AnchorData *> &visited, Orientation orientation);
@@ -471,14 +475,16 @@ public:
Orientation orientation);
// Linear Programming solver methods
- bool solveMinMax(QList<QSimplexConstraint *> constraints,
+ bool solveMinMax(const QList<QSimplexConstraint *> &constraints,
GraphPath path, qreal *min, qreal *max);
- bool solvePreferred(QList<QSimplexConstraint *> constraints);
- void solveExpanding(QList<QSimplexConstraint *> constraints);
+ bool solvePreferred(const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables);
+ void solveExpanding(const QList<QSimplexConstraint *> &constraints,
+ const QList<AnchorData *> &variables);
bool hasConflicts() const;
#ifdef QT_DEBUG
- void dumpGraph();
+ void dumpGraph(const QString &name = QString());
#endif
@@ -513,7 +519,13 @@ public:
bool graphHasConflicts[2];
QSet<QGraphicsLayoutItem *> m_floatItems[2];
+#if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT)
+ bool lastCalculationUsedSimplex[2];
+#endif
+
uint calculateGraphCacheDirty : 1;
+
+ friend class QGraphicsAnchorPrivate;
};
QT_END_NAMESPACE
diff --git a/src/gui/graphicsview/qgraphicsgridlayout.cpp b/src/gui/graphicsview/qgraphicsgridlayout.cpp
index d1d91db..9a8dba0 100644
--- a/src/gui/graphicsview/qgraphicsgridlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsgridlayout.cpp
@@ -63,7 +63,7 @@
You can access each item in the layout by calling count() and itemAt(). Calling
removeAt() will remove an item from the layout, without
destroying it.
-
+
\sa QGraphicsLinearLayout, QGraphicsWidget
*/
@@ -89,7 +89,7 @@ public:
QLayoutStyleInfo styleInfo() const;
QGridLayoutEngine engine;
-#ifdef QT_DEBUG
+#ifdef QT_DEBUG
void dump(int indent) const;
#endif
};
@@ -121,7 +121,7 @@ QGraphicsGridLayout::~QGraphicsGridLayout()
for (int i = count() - 1; i >= 0; --i) {
QGraphicsLayoutItem *item = itemAt(i);
// The following lines can be removed, but this removes the item
- // from the layout more efficiently than the implementation of
+ // from the layout more efficiently than the implementation of
// ~QGraphicsLayoutItem.
removeAt(i);
if (item) {
@@ -141,18 +141,22 @@ void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column
{
Q_D(QGraphicsGridLayout);
if (row < 0 || column < 0) {
- qWarning("QGraphicsGridLayout::addItem: invalid row/column: %d",
- row < 0 ? row : column);
- return;
+ qWarning("QGraphicsGridLayout::addItem: invalid row/column: %d",
+ row < 0 ? row : column);
+ return;
}
if (columnSpan < 1 || rowSpan < 1) {
- qWarning("QGraphicsGridLayout::addItem: invalid row span/column span: %d",
- rowSpan < 1 ? rowSpan : columnSpan);
- return;
+ qWarning("QGraphicsGridLayout::addItem: invalid row span/column span: %d",
+ rowSpan < 1 ? rowSpan : columnSpan);
+ return;
}
if (!item) {
- qWarning("QGraphicsGridLayout::addItem: cannot add null item");
- return;
+ qWarning("QGraphicsGridLayout::addItem: cannot add null item");
+ return;
+ }
+ if (item == this) {
+ qWarning("QGraphicsGridLayout::addItem: cannot insert itself");
+ return;
}
d->addChildLayoutItem(item);
@@ -647,5 +651,5 @@ QSizePolicy::ControlTypes QGraphicsGridLayout::controlTypes(LayoutSide side) con
#endif
QT_END_NAMESPACE
-
-#endif //QT_NO_GRAPHICSVIEW
+
+#endif //QT_NO_GRAPHICSVIEW
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index c914402..e22486b 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1228,7 +1228,7 @@ void QGraphicsItemCache::purge()
}
/*!
- Constructs a QGraphicsItem with the given \a parent.
+ Constructs a QGraphicsItem, passing \a item to QGraphicsItem's constructor. It does not modify \fn QObject::parent().
If \a parent is 0, you can add the item to a scene by calling
QGraphicsScene::addItem(). The item will then become a top-level item.
@@ -1511,6 +1511,8 @@ const QGraphicsObject *QGraphicsItem::toGraphicsObject() const
the parent. You should not \l{QGraphicsScene::addItem()}{add} the
item to the scene yourself.
+ Calling this function on an item that is an ancestor of \a parent have undefined behaviour.
+
\sa parentItem(), childItems()
*/
void QGraphicsItem::setParentItem(QGraphicsItem *parent)
@@ -2482,12 +2484,14 @@ void QGraphicsItem::setOpacity(qreal opacity)
itemChange(ItemOpacityHasChanged, newOpacityVariant);
// Update.
- if (d_ptr->scene)
+ if (d_ptr->scene) {
+ d_ptr->invalidateGraphicsEffectsRecursively();
d_ptr->scene->d_func()->markDirty(this, QRectF(),
/*invalidateChildren=*/true,
/*maybeDirtyClipPath=*/false,
/*force=*/false,
/*ignoreOpacity=*/true);
+ }
if (d_ptr->isObject)
emit static_cast<QGraphicsObject *>(this)->opacityChanged();
@@ -4745,7 +4749,7 @@ bool QGraphicsItem::isObscuredBy(const QGraphicsItem *item) const
{
if (!item)
return false;
- return QGraphicsSceneBspTreeIndexPrivate::closestItemFirst_withoutCache(item, this)
+ return qt_closestItemFirst(item, this)
&& qt_QGraphicsItem_isObscured(this, item, boundingRect());
}
@@ -4959,6 +4963,22 @@ int QGraphicsItemPrivate::depth() const
/*!
\internal
*/
+void QGraphicsItemPrivate::invalidateGraphicsEffectsRecursively()
+{
+ QGraphicsItemPrivate *itemPrivate = this;
+ do {
+ if (itemPrivate->graphicsEffect) {
+ itemPrivate->notifyInvalidated = 1;
+
+ if (!itemPrivate->updateDueToGraphicsEffect)
+ static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
+ }
+ } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));
+}
+
+/*!
+ \internal
+*/
void QGraphicsItemPrivate::invalidateDepthRecursively()
{
if (itemDepth == -1)
@@ -5290,11 +5310,7 @@ void QGraphicsItem::update(const QRectF &rect)
return;
// Make sure we notify effects about invalidated source.
- QGraphicsItem *item = this;
- do {
- if (item->d_ptr->graphicsEffect)
- item->d_ptr->notifyInvalidated = 1;
- } while ((item = item->d_ptr->parent));
+ d_ptr->invalidateGraphicsEffectsRecursively();
if (CacheMode(d_ptr->cacheMode) != NoCache) {
// Invalidate cache.
@@ -7312,7 +7328,7 @@ void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureContext co
/*!
\property QGraphicsObject::parent
- \brief the parent of the item
+ \brief the parent of the item. It is independent from \fn QObject::parent.
\sa QGraphicsItem::setParentItem(), QGraphicsItem::parentObject()
*/
@@ -10731,6 +10747,7 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QP
}
pixmapPainter.end();
+
return pixmap;
}
@@ -10750,6 +10767,23 @@ QDebug operator<<(QDebug debug, QGraphicsItem *item)
return debug;
}
+QDebug operator<<(QDebug debug, QGraphicsObject *item)
+{
+ if (!item) {
+ debug << "QGraphicsObject(0)";
+ return debug;
+ }
+
+ debug.nospace() << item->metaObject()->className() << '(' << (void*)item;
+ if (!item->objectName().isEmpty())
+ debug << ", name = " << item->objectName();
+ debug.nospace() << ", parent = " << ((void*)item->parentItem())
+ << ", pos = " << item->pos()
+ << ", z = " << item->zValue() << ", flags = "
+ << item->flags() << ')';
+ return debug.space();
+}
+
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change)
{
const char *str = "UnknownChange";
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index 2665235..f3fe99c 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -555,7 +555,7 @@ public:
using QObject::children;
#endif
- void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::WidgetWithChildrenGesture);
+ void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::ItemWithChildrenGesture);
Q_SIGNALS:
void parentChanged();
@@ -1120,6 +1120,7 @@ template <class T> inline T qgraphicsitem_cast(const QGraphicsItem *item)
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem *item);
+Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsObject *item);
Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change);
Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag);
Q_GUI_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags);
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index 6550362..7c3c4f0 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -177,6 +177,7 @@ public:
wantsActive(0),
holesInSiblingIndex(0),
sequentialOrdering(1),
+ updateDueToGraphicsEffect(0),
globalStackingOrder(-1),
q_ptr(0)
{
@@ -221,6 +222,7 @@ public:
bool discardUpdateRequest(bool ignoreClipping = false, bool ignoreVisibleBit = false,
bool ignoreDirtyBit = false, bool ignoreOpacity = false) const;
int depth() const;
+ void invalidateGraphicsEffectsRecursively();
void invalidateDepthRecursively();
void resolveDepth();
void addChild(QGraphicsItem *child);
@@ -502,6 +504,7 @@ public:
quint32 wantsActive : 1;
quint32 holesInSiblingIndex : 1;
quint32 sequentialOrdering : 1;
+ quint32 updateDueToGraphicsEffect : 1;
// Optional stacking order
int globalStackingOrder;
@@ -589,8 +592,11 @@ public:
inline const QWidget *widget() const
{ return 0; }
- inline void update()
- { item->update(); }
+ inline void update() {
+ item->d_ptr->updateDueToGraphicsEffect = true;
+ item->update();
+ item->d_ptr->updateDueToGraphicsEffect = false;
+ }
inline void effectBoundingRectChanged()
{ item->prepareGeometryChange(); }
@@ -619,10 +625,76 @@ public:
QGraphicsItem *item;
QGraphicsItemPaintInfo *info;
+ QTransform lastEffectTransform;
};
/*!
+ Returns true if \a item1 is on top of \a item2.
+ The items dont need to be siblings.
+
+ \internal
+*/
+inline bool qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem *item2)
+{
+ // Siblings? Just check their z-values.
+ const QGraphicsItemPrivate *d1 = item1->d_ptr.data();
+ const QGraphicsItemPrivate *d2 = item2->d_ptr.data();
+ if (d1->parent == d2->parent)
+ return qt_closestLeaf(item1, item2);
+
+ // Find common ancestor, and each item's ancestor closest to the common
+ // ancestor.
+ int item1Depth = d1->depth();
+ int item2Depth = d2->depth();
+ const QGraphicsItem *p = item1;
+ const QGraphicsItem *t1 = item1;
+ while (item1Depth > item2Depth && (p = p->d_ptr->parent)) {
+ if (p == item2) {
+ // item2 is one of item1's ancestors; item1 is on top
+ return !(t1->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent);
+ }
+ t1 = p;
+ --item1Depth;
+ }
+ p = item2;
+ const QGraphicsItem *t2 = item2;
+ while (item2Depth > item1Depth && (p = p->d_ptr->parent)) {
+ if (p == item1) {
+ // item1 is one of item2's ancestors; item1 is not on top
+ return (t2->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent);
+ }
+ t2 = p;
+ --item2Depth;
+ }
+
+ // item1Ancestor is now at the same level as item2Ancestor, but not the same.
+ const QGraphicsItem *p1 = t1;
+ const QGraphicsItem *p2 = t2;
+ while (t1 && t1 != t2) {
+ p1 = t1;
+ p2 = t2;
+ t1 = t1->d_ptr->parent;
+ t2 = t2->d_ptr->parent;
+ }
+
+ // in case we have a common ancestor, we compare the immediate children in the ancestor's path.
+ // otherwise we compare the respective items' topLevelItems directly.
+ return qt_closestLeaf(p1, p2);
+}
+
+/*!
+ Returns true if \a item2 is on top of \a item1.
+ The items dont need to be siblings.
+
+ \internal
+*/
+inline bool qt_closestItemLast(const QGraphicsItem *item1, const QGraphicsItem *item2)
+{
+ return qt_closestItemFirst(item2, item1);
+}
+
+/*!
\internal
*/
inline bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
@@ -642,7 +714,7 @@ inline bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item
/*!
\internal
*/
-static inline bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
+inline bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
{ return qt_closestLeaf(item2, item1); }
/*
diff --git a/src/gui/graphicsview/qgraphicslinearlayout.cpp b/src/gui/graphicsview/qgraphicslinearlayout.cpp
index 0aa68df..7ff7c9b 100644
--- a/src/gui/graphicsview/qgraphicslinearlayout.cpp
+++ b/src/gui/graphicsview/qgraphicslinearlayout.cpp
@@ -272,6 +272,10 @@ void QGraphicsLinearLayout::insertItem(int index, QGraphicsLayoutItem *item)
qWarning("QGraphicsLinearLayout::insertItem: cannot insert null item");
return;
}
+ if (item == this) {
+ qWarning("QGraphicsLinearLayout::insertItem: cannot insert itself");
+ return;
+ }
d->addChildLayoutItem(item);
Q_ASSERT(item);
diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp
index b7a3962..64c51ad 100644
--- a/src/gui/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp
@@ -57,6 +57,9 @@
#include <QtGui/qpainter.h>
#include <QtGui/qstyleoption.h>
#include <QtGui/qgraphicsview.h>
+#include <QtGui/qlistview.h>
+#include <QtGui/qlineedit.h>
+#include <QtGui/qtextedit.h>
QT_BEGIN_NAMESPACE
@@ -86,7 +89,9 @@ QT_BEGIN_NAMESPACE
of embedded widgets through creating a child proxy for each popup. This
means that when an embedded QComboBox shows its popup list, a new
QGraphicsProxyWidget is created automatically, embedding the popup, and
- positioning it correctly.
+ positioning it correctly. This only works if the popup is child of the
+ embedded widget (for example QToolButton::setMenu() requires the QMenu instance
+ to be child of the QToolButton).
\section1 Embedding a Widget with QGraphicsProxyWidget
@@ -184,6 +189,7 @@ QT_BEGIN_NAMESPACE
*/
extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
+extern bool qt_tab_all_widgets;
/*!
\internal
@@ -369,6 +375,7 @@ QVariant QGraphicsProxyWidgetPrivate::inputMethodQueryHelper(Qt::InputMethodQuer
/*!
\internal
+ Some of the logic is shared with QApplicationPrivate::focusNextPrevChild_helper
*/
QWidget *QGraphicsProxyWidgetPrivate::findFocusChild(QWidget *child, bool next) const
{
@@ -382,14 +389,16 @@ QWidget *QGraphicsProxyWidgetPrivate::findFocusChild(QWidget *child, bool next)
child = next ? child->d_func()->focus_next : child->d_func()->focus_prev;
if ((next && child == widget) || (!next && child == widget->d_func()->focus_prev)) {
return 0;
- }
+ }
}
QWidget *oldChild = child;
+ uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
do {
if (child->isEnabled()
&& child->isVisibleTo(widget)
- && (child->focusPolicy() & Qt::TabFocus)) {
+ && (child->focusPolicy() & focus_flag == focus_flag)
+ && !(child->d_func()->extra && child->d_func()->extra->focus_proxy)) {
return child;
}
child = next ? child->d_func()->focus_next : child->d_func()->focus_prev;
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index a624b10..c459d21 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -242,7 +242,6 @@
#include <QtGui/qstyleoption.h>
#include <QtGui/qtooltip.h>
#include <QtGui/qtransform.h>
-#include <QtGui/qgesture.h>
#include <QtGui/qinputcontext.h>
#include <QtGui/qgraphicseffect.h>
#include <private/qapplication_p.h>
@@ -251,6 +250,14 @@
#include <private/qt_x11_p.h>
#endif
#include <private/qgraphicseffect_p.h>
+#include <private/qgesturemanager_p.h>
+
+// #define GESTURE_DEBUG
+#ifndef GESTURE_DEBUG
+# define DEBUG if (0) qDebug
+#else
+# define DEBUG qDebug
+#endif
QT_BEGIN_NAMESPACE
@@ -1052,6 +1059,14 @@ bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event)
*/
bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event)
{
+ if (QGraphicsObject *object = item->toGraphicsObject()) {
+ QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
+ if (qAppPriv->gestureManager) {
+ if (qAppPriv->gestureManager->filterEvent(object, event))
+ return true;
+ }
+ }
+
if (filterEvent(item, event))
return false;
if (filterDescendantEvent(item, event))
@@ -3365,6 +3380,10 @@ bool QGraphicsScene::event(QEvent *event)
case QEvent::TouchEnd:
d->touchEventHandler(static_cast<QTouchEvent *>(event));
break;
+ case QEvent::Gesture:
+ case QEvent::GestureOverride:
+ d->gestureEventHandler(static_cast<QGestureEvent *>(event));
+ break;
default:
return QObject::event(event);
}
@@ -4569,6 +4588,11 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
else
painter->setWorldTransform(*transformPtr);
painter->setOpacity(opacity);
+
+ if (sourced->lastEffectTransform != painter->worldTransform()) {
+ sourced->lastEffectTransform = painter->worldTransform();
+ sourced->invalidateCache();
+ }
item->d_ptr->graphicsEffect->draw(painter, source);
painter->setWorldTransform(restoreTransform);
sourced->info = 0;
@@ -5699,6 +5723,238 @@ void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel)
dispatchHoverEvent(&hoverEvent);
}
+void QGraphicsScenePrivate::getGestureTargets(const QSet<QGesture *> &gestures,
+ QWidget *viewport,
+ QMap<Qt::GestureType, QGesture *> *conflictedGestures,
+ QList<QList<QGraphicsObject *> > *conflictedItems,
+ QHash<QGesture *, QGraphicsObject *> *normalGestures)
+{
+ foreach (QGesture *gesture, gestures) {
+ Qt::GestureType gestureType = gesture->gestureType();
+ if (gesture->hasHotSpot()) {
+ QPoint screenPos = gesture->hotSpot().toPoint();
+ QList<QGraphicsItem *> items = itemsAtPosition(screenPos, QPointF(), viewport);
+ QList<QGraphicsObject *> result;
+ for (int j = 0; j < items.size(); ++j) {
+ QGraphicsObject *item = items.at(j)->toGraphicsObject();
+ if (!item)
+ continue;
+ QGraphicsItemPrivate *d = item->QGraphicsItem::d_func();
+ if (d->gestureContext.contains(gestureType)) {
+ result.append(item);
+ }
+ }
+ DEBUG() << "QGraphicsScenePrivate::getGestureTargets:"
+ << gesture << result;
+ if (result.size() == 1) {
+ normalGestures->insert(gesture, result.first());
+ } else if (!result.isEmpty()) {
+ conflictedGestures->insert(gestureType, gesture);
+ conflictedItems->append(result);
+ }
+ }
+ }
+}
+
+void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
+{
+ QWidget *viewport = event->widget();
+ if (!viewport)
+ return;
+ QList<QGesture *> allGestures = event->allGestures();
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "Delivering gestures:" << allGestures;
+
+ typedef QHash<QGraphicsObject *, QList<QGesture *> > GesturesPerItem;
+ GesturesPerItem gesturesPerItem;
+
+ QSet<QGesture *> startedGestures;
+ foreach (QGesture *gesture, allGestures) {
+ QGraphicsObject *target = gestureTargets.value(gesture, 0);
+ if (!target) {
+ // when we are not in started mode but don't have a target
+ // then the only one interested in gesture is the view/scene
+ if (gesture->state() == Qt::GestureStarted)
+ startedGestures.insert(gesture);
+ } else {
+ gesturesPerItem[target].append(gesture);
+ }
+ }
+
+ QMap<Qt::GestureType, QGesture *> conflictedGestures;
+ QList<QList<QGraphicsObject *> > conflictedItems;
+ QHash<QGesture *, QGraphicsObject *> normalGestures;
+ getGestureTargets(startedGestures, viewport, &conflictedGestures, &conflictedItems,
+ &normalGestures);
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "Conflicting gestures:" << conflictedGestures.values() << conflictedItems;
+ Q_ASSERT((conflictedGestures.isEmpty() && conflictedItems.isEmpty()) ||
+ (!conflictedGestures.isEmpty() && !conflictedItems.isEmpty()));
+
+ // gestures that were sent as override events, but no one accepted them
+ QHash<QGesture *, QGraphicsObject *> ignoredConflictedGestures;
+
+ // deliver conflicted gestures as override events first
+ while (!conflictedGestures.isEmpty() && !conflictedItems.isEmpty()) {
+ // get the topmost item to deliver the override event
+ Q_ASSERT(!conflictedItems.isEmpty());
+ Q_ASSERT(!conflictedItems.first().isEmpty());
+ QGraphicsObject *topmost = conflictedItems.first().first();
+ for (int i = 1; i < conflictedItems.size(); ++i) {
+ QGraphicsObject *item = conflictedItems.at(i).first();
+ if (qt_closestItemFirst(item, topmost)) {
+ topmost = item;
+ }
+ }
+ // get a list of gestures to send to the item
+ QList<Qt::GestureType> grabbedGestures =
+ topmost->QGraphicsItem::d_func()->gestureContext.keys();
+ QList<QGesture *> gestures;
+ for (int i = 0; i < grabbedGestures.size(); ++i) {
+ if (QGesture *g = conflictedGestures.value(grabbedGestures.at(i), 0)) {
+ gestures.append(g);
+ if (!ignoredConflictedGestures.contains(g))
+ ignoredConflictedGestures.insert(g, topmost);
+ }
+ }
+
+ // send gesture override to the topmost item
+ QGestureEvent ev(gestures);
+ ev.t = QEvent::GestureOverride;
+ ev.setWidget(event->widget());
+ // mark event and individual gestures as ignored
+ ev.ignore();
+ foreach(QGesture *g, gestures)
+ ev.setAccepted(g, false);
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "delivering override to"
+ << topmost << gestures;
+ sendEvent(topmost, &ev);
+ // mark all accepted gestures to deliver them as normal gesture events
+ foreach (QGesture *g, gestures) {
+ if (ev.isAccepted() || ev.isAccepted(g)) {
+ conflictedGestures.remove(g->gestureType());
+ gestureTargets.remove(g);
+ // add the gesture to the list of normal delivered gestures
+ normalGestures.insert(g, topmost);
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "override was accepted:"
+ << g << topmost;
+ ignoredConflictedGestures.remove(g);
+ }
+ }
+ // remove the item that we've already delivered from the list
+ for (int i = 0; i < conflictedItems.size(); ) {
+ QList<QGraphicsObject *> &items = conflictedItems[i];
+ if (items.first() == topmost) {
+ items.removeFirst();
+ if (items.isEmpty()) {
+ conflictedItems.removeAt(i);
+ continue;
+ }
+ }
+ ++i;
+ }
+ }
+
+ // put back those started gestures that are not in the conflicted state
+ // and remember their targets
+ QHash<QGesture *, QGraphicsObject *>::const_iterator it = normalGestures.begin(),
+ e = normalGestures.end();
+ for (; it != e; ++it) {
+ QGesture *g = it.key();
+ QGraphicsObject *receiver = it.value();
+ Q_ASSERT(!gestureTargets.contains(g));
+ gestureTargets.insert(g, receiver);
+ gesturesPerItem[receiver].append(g);
+ }
+ it = ignoredConflictedGestures.begin();
+ e = ignoredConflictedGestures.end();
+ for (; it != e; ++it) {
+ QGesture *g = it.key();
+ QGraphicsObject *receiver = it.value();
+ Q_ASSERT(!gestureTargets.contains(g));
+ gestureTargets.insert(g, receiver);
+ gesturesPerItem[receiver].append(g);
+ }
+
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "Started gestures:" << normalGestures.keys()
+ << "All gestures:" << gesturesPerItem.values();
+
+ // deliver all events
+ QList<QGesture *> alreadyIgnoredGestures;
+ QHash<QGraphicsObject *, QSet<QGesture *> > itemIgnoredGestures;
+ QList<QGraphicsObject *> targetItems = gesturesPerItem.keys();
+ qSort(targetItems.begin(), targetItems.end(), qt_closestItemFirst);
+ for (int i = 0; i < targetItems.size(); ++i) {
+ QGraphicsObject *item = targetItems.at(i);
+ QList<QGesture *> gestures = gesturesPerItem.value(item);
+ // remove gestures that were already delivered once and were ignored
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "already ignored gestures for item"
+ << item << ":" << itemIgnoredGestures.value(item);
+
+ if (itemIgnoredGestures.contains(item)) // don't deliver twice to the same item
+ continue;
+
+ QGraphicsItemPrivate *gid = item->QGraphicsItem::d_func();
+ foreach(QGesture *g, alreadyIgnoredGestures) {
+ if (gid->gestureContext.contains(g->gestureType()))
+ gestures += g;
+ }
+ if (gestures.isEmpty())
+ continue;
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "delivering to"
+ << item << gestures;
+ QGestureEvent ev(gestures);
+ ev.setWidget(event->widget());
+ sendEvent(item, &ev);
+ QSet<QGesture *> ignoredGestures;
+ foreach (QGesture *g, gestures) {
+ if (!ev.isAccepted() && !ev.isAccepted(g))
+ ignoredGestures.insert(g);
+ }
+ if (!ignoredGestures.isEmpty()) {
+ // get a list of items under the (current) hotspot of each ignored
+ // gesture and start delivery again from the beginning
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "item has ignored the event, will propagate."
+ << item << ignoredGestures;
+ itemIgnoredGestures[item] += ignoredGestures;
+ QMap<Qt::GestureType, QGesture *> conflictedGestures;
+ QList<QList<QGraphicsObject *> > itemsForConflictedGestures;
+ QHash<QGesture *, QGraphicsObject *> normalGestures;
+ getGestureTargets(ignoredGestures, viewport,
+ &conflictedGestures, &itemsForConflictedGestures,
+ &normalGestures);
+ QSet<QGraphicsObject *> itemsSet = targetItems.toSet();
+ for (int k = 0; k < itemsForConflictedGestures.size(); ++k)
+ itemsSet += itemsForConflictedGestures.at(k).toSet();
+ targetItems = itemsSet.toList();
+ qSort(targetItems.begin(), targetItems.end(), qt_closestItemFirst);
+ alreadyIgnoredGestures = conflictedGestures.values();
+ DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
+ << "new targets:" << targetItems;
+ i = -1; // start delivery again
+ continue;
+ }
+ }
+
+ // forget about targets for gestures that have ended
+ foreach (QGesture *g, allGestures) {
+ switch (g->state()) {
+ case Qt::GestureFinished:
+ case Qt::GestureCanceled:
+ gestureTargets.remove(g);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
QT_END_NAMESPACE
#include "moc_qgraphicsscene.cpp"
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index 8073695..cd20fd0 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -282,6 +282,13 @@ public:
bool allItemsIgnoreTouchEvents;
void enableTouchEventsOnViews();
+ QHash<QGesture *, QGraphicsObject *> gestureTargets;
+ void gestureEventHandler(QGestureEvent *event);
+ void getGestureTargets(const QSet<QGesture *> &gestures, QWidget *viewport,
+ QMap<Qt::GestureType, QGesture *> *conflictedGestures,
+ QList<QList<QGraphicsObject *> > *conflictedItems,
+ QHash<QGesture *, QGraphicsObject *> *normalGestures);
+
void updateInputMethodSensitivityInViews();
QList<QGraphicsItem *> modalPanels;
diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp
index e21183a..47ae3f1 100644
--- a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp
+++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp
@@ -405,70 +405,6 @@ QList<QGraphicsItem *> QGraphicsSceneBspTreeIndexPrivate::estimateItems(const QR
}
/*!
- Returns true if \a item1 is on top of \a item2.
-
- \internal
-*/
-bool QGraphicsSceneBspTreeIndexPrivate::closestItemFirst_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
-{
- // Siblings? Just check their z-values.
- const QGraphicsItemPrivate *d1 = item1->d_ptr.data();
- const QGraphicsItemPrivate *d2 = item2->d_ptr.data();
- if (d1->parent == d2->parent)
- return qt_closestLeaf(item1, item2);
-
- // Find common ancestor, and each item's ancestor closest to the common
- // ancestor.
- int item1Depth = d1->depth();
- int item2Depth = d2->depth();
- const QGraphicsItem *p = item1;
- const QGraphicsItem *t1 = item1;
- while (item1Depth > item2Depth && (p = p->d_ptr->parent)) {
- if (p == item2) {
- // item2 is one of item1's ancestors; item1 is on top
- return !(t1->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent);
- }
- t1 = p;
- --item1Depth;
- }
- p = item2;
- const QGraphicsItem *t2 = item2;
- while (item2Depth > item1Depth && (p = p->d_ptr->parent)) {
- if (p == item1) {
- // item1 is one of item2's ancestors; item1 is not on top
- return (t2->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent);
- }
- t2 = p;
- --item2Depth;
- }
-
- // item1Ancestor is now at the same level as item2Ancestor, but not the same.
- const QGraphicsItem *a1 = t1;
- const QGraphicsItem *a2 = t2;
- while (a1) {
- const QGraphicsItem *p1 = a1;
- const QGraphicsItem *p2 = a2;
- a1 = a1->parentItem();
- a2 = a2->parentItem();
- if (a1 && a1 == a2)
- return qt_closestLeaf(p1, p2);
- }
-
- // No common ancestor? Then just compare the items' toplevels directly.
- return qt_closestLeaf(t1->topLevelItem(), t2->topLevelItem());
-}
-
-/*!
- Returns true if \a item2 is on top of \a item1.
-
- \internal
-*/
-bool QGraphicsSceneBspTreeIndexPrivate::closestItemLast_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
-{
- return closestItemFirst_withoutCache(item2, item1);
-}
-
-/*!
Sort a list of \a itemList in a specific \a order and use the cache if requested.
\internal
@@ -495,9 +431,9 @@ void QGraphicsSceneBspTreeIndexPrivate::sortItems(QList<QGraphicsItem *> *itemLi
}
} else {
if (order == Qt::DescendingOrder) {
- qSort(itemList->begin(), itemList->end(), closestItemFirst_withoutCache);
+ qSort(itemList->begin(), itemList->end(), qt_closestItemFirst);
} else if (order == Qt::AscendingOrder) {
- qSort(itemList->begin(), itemList->end(), closestItemLast_withoutCache);
+ qSort(itemList->begin(), itemList->end(), qt_closestItemLast);
}
}
}
diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
index 0a86bb7..c130190 100644
--- a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
+++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
@@ -145,8 +145,6 @@ public:
QList<QGraphicsItem *> estimateItems(const QRectF &, Qt::SortOrder, bool b = false);
static void climbTree(QGraphicsItem *item, int *stackingOrder);
- static bool closestItemFirst_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2);
- static bool closestItemLast_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2);
static inline bool closestItemFirst_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
{
diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp
index ec1a2f5..a0b5493 100644
--- a/src/gui/graphicsview/qgraphicstransform.cpp
+++ b/src/gui/graphicsview/qgraphicstransform.cpp
@@ -547,7 +547,9 @@ void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const
return;
matrix->translate(d->origin);
- matrix->rotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z());
+ QMatrix4x4 m;
+ m.rotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z());
+ *matrix *= m.toTransform(1024.0f); // Project back to 2D.
matrix->translate(-d->origin);
}
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index 32747cc..710c745 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -2701,6 +2701,19 @@ bool QGraphicsView::viewportEvent(QEvent *event)
return true;
}
+ case QEvent::Gesture:
+ case QEvent::GestureOverride:
+ {
+ if (!isEnabled())
+ return false;
+
+ if (d->scene && d->sceneInteractionAllowed) {
+ QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event);
+ gestureEvent->setWidget(viewport());
+ (void) QApplication::sendEvent(d->scene, gestureEvent);
+ }
+ return true;
+ }
default:
break;
}