diff options
author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2013-01-02 12:53:43 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2013-02-27 23:56:04 +0100 |
commit | 355f064ec97cf61c7041a6d32f198a6bde800e6e (patch) | |
tree | ff840b063f4ba63f2ac9522f025d0ec6c7e61265 /src/plugins/platforms/ios | |
parent | 7150e8f51f44b6299728c5bdfb8cb5b54b8d1141 (diff) |
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>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r-- | src/plugins/platforms/ios/qioswindow.h | 5 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qioswindow.mm | 32 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.h b/src/plugins/platforms/ios/qioswindow.h index 1f36c525ce..e7b04c53eb 100644 --- a/src/plugins/platforms/ios/qioswindow.h +++ b/src/plugins/platforms/ios/qioswindow.h @@ -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 diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index c7c27c08ce..5bb5048b0a 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -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 |