diff options
author | Christian Strømme <christian.stromme@digia.com> | 2014-08-28 12:18:14 +0200 |
---|---|---|
committer | Christian Stromme <christian.stromme@digia.com> | 2014-09-26 23:44:42 +0200 |
commit | 8b0d9a16db7bcfb5d6439b8863aded5c583f9ed5 (patch) | |
tree | 5fca60950d6e7dba1f12f9ceda0e564965d35116 /src/plugins/platforms/android/qandroidplatformforeignwindow.cpp | |
parent | c30687f519de47279a70c3eca95eec2191eddbb1 (diff) |
Android: Improve the foreign-window implementation
Adds:
- Improved geometry calculations (e.g, inside a parent)
- Change visibility
- proper stacking order. Native views now reserve the top of the stack
to ensure that they stay visible.
- React to application state changes.
Change-Id: I35de0396937fff37ffcd272c9a7d8e9873a91dfb
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformforeignwindow.cpp')
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformforeignwindow.cpp | 74 |
1 files changed, 65 insertions, 9 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp index e8f7b3d145..af409d13a0 100644 --- a/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp @@ -34,16 +34,17 @@ #include "qandroidplatformforeignwindow.h" #include "androidjnimain.h" #include <QtCore/qvariant.h> +#include <qpa/qwindowsysteminterface.h> +#include <QtCore/private/qjnihelpers_p.h> + +QT_BEGIN_NAMESPACE QAndroidPlatformForeignWindow::QAndroidPlatformForeignWindow(QWindow *window) - : QAndroidPlatformWindow(window) + : QAndroidPlatformWindow(window), + m_surfaceId(-1) { const WId wId = window->property("_q_foreignWinId").value<WId>(); - if (wId) { - m_view = reinterpret_cast<jobject>(wId); - Q_ASSERT(m_view.isValid()); - m_surfaceId = QtAndroid::insertNativeView(m_view.object(), geometry()); - } + m_view = reinterpret_cast<jobject>(wId); } QAndroidPlatformForeignWindow::~QAndroidPlatformForeignWindow() @@ -54,9 +55,64 @@ QAndroidPlatformForeignWindow::~QAndroidPlatformForeignWindow() void QAndroidPlatformForeignWindow::setGeometry(const QRect &rect) { - if (rect == geometry()) + QWindow *parent = window()->parent(); + QRect newGeometry = rect; + + if (parent != 0) + newGeometry.moveTo(parent->mapToGlobal(rect.topLeft())); + + if (newGeometry == geometry()) + return; + + QAndroidPlatformWindow::setGeometry(newGeometry); + + if (m_surfaceId != -1) + QtAndroid::setSurfaceGeometry(m_surfaceId, newGeometry); +} + +void QAndroidPlatformForeignWindow::setVisible(bool visible) +{ + if (!m_view.isValid()) + return; + + QAndroidPlatformWindow::setVisible(visible); + + if (!visible && m_surfaceId != -1) { + QtAndroid::destroySurface(m_surfaceId); + m_surfaceId = -1; + } else if (m_surfaceId == -1) { + m_surfaceId = QtAndroid::insertNativeView(m_view.object(), geometry()); + } +} + +void QAndroidPlatformForeignWindow::applicationStateChanged(Qt::ApplicationState state) +{ + if (state <= Qt::ApplicationHidden + && QtAndroid::blockEventLoopsWhenSuspended() + && m_surfaceId != -1) { + QtAndroid::destroySurface(m_surfaceId); + m_surfaceId = -1; + } else if (m_view.isValid() && m_surfaceId == -1){ + m_surfaceId = QtAndroid::insertNativeView(m_view.object(), geometry()); + } + + QAndroidPlatformWindow::applicationStateChanged(state); +} + +void QAndroidPlatformForeignWindow::setParent(const QPlatformWindow *window) +{ + QRect newGeometry = geometry(); + + if (window != 0) + newGeometry.moveTo(window->mapToGlobal(geometry().topLeft())); + + if (newGeometry != geometry()) + QAndroidPlatformWindow::setGeometry(newGeometry); + + if (m_surfaceId == -1) return; - QAndroidPlatformWindow::setGeometry(rect); - QtAndroid::setSurfaceGeometry(m_surfaceId, rect); + QtAndroid::setSurfaceGeometry(m_surfaceId, newGeometry); } + +QT_END_NAMESPACE |