aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/layout
diff options
context:
space:
mode:
authorJohn Tapsell <john.tapsell.ext@basyskom.de>2010-08-04 22:12:56 +0900
committerSergiy Dubovik <sergiy.dubovik@nokia.com>2010-08-05 11:04:42 +0300
commitf358a180544857623f640202772193db9e823c8c (patch)
tree866942a79081d8a2d0683b740e7c2b01cc13c6d4 /src/corelib/layout
parent6cc39fefc9ff243993c82a09f71cb3db74a29f71 (diff)
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.
Diffstat (limited to 'src/corelib/layout')
-rw-r--r--src/corelib/layout/mlayout.cpp3
-rw-r--r--src/corelib/layout/mlayout_p.cpp13
-rw-r--r--src/corelib/layout/mlayout_p.h2
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;