Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
androidwindowembedding.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qcoreapplication.h>
7#include <QtCore/qjnienvironment.h>
8#include <QtCore/qjniobject.h>
9#include <QtCore/qjnitypes.h>
10#include <QtGui/qwindow.h>
11
13
14Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView");
15
17 void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView,
18 jint x, jint y, jint width, jint height)
19 {
20 // QWindow should be constructed on the Qt thread rather than directly in the caller thread
21 // To avoid hitting checkReceiverThread assert in QCoreApplication::doNotify
23 QWindow *parentWindow = QWindow::fromWinId(reinterpret_cast<WId>(rootView.object()));
24 parentWindow->setGeometry(x, y, width, height);
25 rootView.callMethod<void>("createWindow", reinterpret_cast<jlong>(parentWindow));
26 });
27 }
28
29 void deleteWindow(JNIEnv *, jclass, jlong windowRef)
30 {
31 QWindow *window = reinterpret_cast<QWindow*>(windowRef);
32 window->deleteLater();
33 }
34
35 void setWindowVisible(JNIEnv *, jclass, jlong windowRef, jboolean visible)
36 {
37 QMetaObject::invokeMethod(qApp, [windowRef, visible] {
38 QWindow *window = reinterpret_cast<QWindow*>(windowRef);
39 if (visible) {
40 window->showNormal();
41 if (!window->parent()->isVisible())
42 window->parent()->showNormal();
43 } else {
44 window->hide();
45 }
46 });
47 }
48
49 void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint x, jint y, jint width, jint height)
50 {
51 QMetaObject::invokeMethod(qApp, [windowRef, x, y, width, height] {
52 QWindow *window = reinterpret_cast<QWindow*>(windowRef);
53 QWindow *parent = window->parent();
54 if (parent)
55 parent->setGeometry(x, y, width, height);
56 window->setGeometry(0, 0, width, height);
57 });
58 }
59
61 return env.registerNativeMethods(
62 QtJniTypes::Traits<QtJniTypes::QtView>::className(),
63 { Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding),
64 Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding),
65 Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding),
66 Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding) });
67 }
68}
69
QT_BEGIN_NAMESPACE Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView")
\inmodule QtCore
\inmodule QtGui
Definition qwindow.h:63
void setGeometry(int posx, int posy, int w, int h)
Sets the geometry of the window, excluding its window frame, to a rectangle constructed from posx,...
Definition qwindow.cpp:1802
static bool registerNatives()
Combined button and popup list for selecting options.
void setWindowVisible(JNIEnv *, jclass, jlong windowRef, jboolean visible)
void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, jint x, jint y, jint width, jint height)
void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint x, jint y, jint width, jint height)
void deleteWindow(JNIEnv *, jclass, jlong windowRef)
#define qApp
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLint GLsizei width
GLint y
aWidget window() -> setWindowTitle("New Window Title")
[2]
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...