iOS: implement QPlatformWindow::raise() and lower()

Probably not going to be the most used functions on iOS, but
implemented to support old widget apps out of the box. The
implementation stacks both staysOnTop and popup windows on
the same level for simplicity, since iOS does not have a
concept of z-ordering UIViews (UILayer has z-order, but layers
belong in a different hierarchy, and cannot be used in this
respect).

Change-Id: Idd68e5ceea7d4eaeb3066486c47400930cebb1b0
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
bb10
Richard Moe Gustavsen 2013-01-02 12:53:43 +01:00 committed by Tor Arne Vestbø
parent 7150e8f51f
commit 355f064ec9
2 changed files with 36 additions and 1 deletions

View File

@ -67,6 +67,9 @@ public:
void handleContentOrientationChange(Qt::ScreenOrientation orientation);
void setVisible(bool visible);
void raise() { raiseOrLower(true); }
void lower() { raiseOrLower(false); }
qreal devicePixelRatio() const;
int effectiveWidth() const;
int effectiveHeight() const;
@ -78,6 +81,8 @@ private:
QRect m_requestedGeometry;
qreal m_devicePixelRatio;
void raiseOrLower(bool raise);
};
QT_END_NAMESPACE

View File

@ -153,8 +153,10 @@
{
// Transfer focus to the touched window:
QWindow *window = m_qioswindow->window();
if (window != QGuiApplication::focusWindow())
if (window != QGuiApplication::focusWindow()) {
m_qioswindow->raise();
QWindowSystemInterface::handleWindowActivated(window);
}
[self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
}
@ -314,6 +316,34 @@ void QIOSWindow::setWindowState(Qt::WindowState state)
}
}
void QIOSWindow::raiseOrLower(bool raise)
{
// Re-insert m_view at the correct index among its sibling views (QWindows), and ensure
// that window flags (staysOnTop, popup) are respected. This function assumes that all
// sibling views are sorted correctly. Note: We sort popup and staysOnTop windows at
// the same level:
if (!isQtApplication())
return;
NSArray *subviews = m_view.superview.subviews;
if (subviews.count == 1)
return;
const Qt::WindowFlags topFlag = (Qt::Popup | Qt::WindowStaysOnTopHint) & ~Qt::Dialog;
bool thisWindowIsTop = topFlag & window()->flags();
for (int i = int(subviews.count) - 1; i >= 0; --i) {
UIView *view = static_cast<UIView *>([subviews objectAtIndex:i]);
bool otherWindowIsTop = topFlag & view.qwindow->flags();
if ((raise && (thisWindowIsTop || !otherWindowIsTop))
|| (!raise && (thisWindowIsTop && !otherWindowIsTop))) {
[m_view.superview insertSubview:m_view aboveSubview:view];
return;
}
}
[m_view.superview insertSubview:m_view atIndex:0];
}
void QIOSWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation)
{
// Keep the status bar in sync with content orientation. This will ensure