From f358a180544857623f640202772193db9e823c8c Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Wed, 4 Aug 2010 22:12:56 +0900 Subject: Changes: MLayout - Fallback to orientation of activeWindow if not attached to a window RevBy: TrustMe Details: When a layout is attached to an item or placed inside another layout, we don't get notified. So we need to guess at what the correct orientation is before hand. We do this by taking the orientation of the currently active window if we are not attached to any window. This fixes several unit test failures. --- src/corelib/layout/mlayout.cpp | 3 +++ src/corelib/layout/mlayout_p.cpp | 13 ++++++++----- src/corelib/layout/mlayout_p.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/corelib/layout') diff --git a/src/corelib/layout/mlayout.cpp b/src/corelib/layout/mlayout.cpp index 08d7900c..42285b4b 100644 --- a/src/corelib/layout/mlayout.cpp +++ b/src/corelib/layout/mlayout.cpp @@ -39,6 +39,7 @@ MLayout::MLayout(QGraphicsLayoutItem *parent) : QSizePolicy newSizePolicy(sizePolicy()); newSizePolicy.setHeightForWidth(true); setSizePolicy(newSizePolicy); + d_ptr->recheckOrientation(false); // Disabling layout animations by default // new MBasicLayoutAnimation(this); } @@ -309,6 +310,7 @@ void MLayout::setLandscapePolicy(MAbstractLayoutPolicy *policy) return; d->landscapePolicy = policy; Q_ASSERT(!policy || policy->layout() == this); + d->recheckOrientation(); if (d->landscapePolicy && d->m_orientation == M::Landscape) { policy->activate(); } @@ -326,6 +328,7 @@ void MLayout::setPortraitPolicy(MAbstractLayoutPolicy *policy) return; d->portraitPolicy = policy; Q_ASSERT(!policy || policy->layout() == this); + d->recheckOrientation(); if (d->portraitPolicy && d->m_orientation == M::Portrait) { policy->activate(); } diff --git a/src/corelib/layout/mlayout_p.cpp b/src/corelib/layout/mlayout_p.cpp index dca7ce64..a29f415b 100644 --- a/src/corelib/layout/mlayout_p.cpp +++ b/src/corelib/layout/mlayout_p.cpp @@ -168,9 +168,10 @@ QGraphicsItem *MLayoutPrivate::parentItem() const M::Orientation MLayoutPrivate::orientation() const { return m_orientation; } -void MLayoutPrivate::recheckOrientation() { +void MLayoutPrivate::recheckOrientation(bool fallbackToActiveWindow) { //We need to check if the orientation has changed. QGraphicsItem *parent = parentItem(); + MWindow *window = NULL; if(parent) { QGraphicsWidget *w; if(parent->isWidget()) { @@ -181,12 +182,14 @@ void MLayoutPrivate::recheckOrientation() { return; } if(w->scene() && !w->scene()->views().isEmpty()) { - MWindow *window = qobject_cast(w->scene()->views().at(0)); - if(window) { - setOrientation(window->orientation()); - } + window = qobject_cast(w->scene()->views().at(0)); } } + + if(!window && fallbackToActiveWindow) + window = MApplication::activeWindow(); + if(window) + setOrientation(window->orientation()); } void MLayoutPrivate::showItemNow(QGraphicsItem *graphicsItem) const { diff --git a/src/corelib/layout/mlayout_p.h b/src/corelib/layout/mlayout_p.h index ea191389..04e325d8 100644 --- a/src/corelib/layout/mlayout_p.h +++ b/src/corelib/layout/mlayout_p.h @@ -102,7 +102,7 @@ public: /** This is called when the widget's orientation has changed (probably because the device has been rotated) */ void setOrientation(M::Orientation orientation); /** Check the closest parent widget's scene to find out what orientation we are in */ - void recheckOrientation(); + void recheckOrientation(bool fallbackToActiveWindow = true); /** Return the current orientation of the layout */ M::Orientation orientation() const; -- cgit v1.2.3