diff options
-rw-r--r-- | src/corelib/layout/mlayout.cpp | 3 | ||||
-rw-r--r-- | src/corelib/layout/mlayout_p.cpp | 13 | ||||
-rw-r--r-- | src/corelib/layout/mlayout_p.h | 2 |
3 files changed, 12 insertions, 6 deletions
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<MWindow *>(w->scene()->views().at(0)); - if(window) { - setOrientation(window->orientation()); - } + window = qobject_cast<MWindow *>(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; |