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
QtWindow.java
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
4package org.qtproject.qt.android;
5
6import android.content.Context;
7import android.view.GestureDetector;
8import android.view.MotionEvent;
9import android.util.Log;
10import android.view.Surface;
11import android.view.View;
12import android.view.ViewGroup;
13
14import java.util.HashMap;
15
16class QtWindow extends QtLayout implements QtSurfaceInterface {
17 private final static String TAG = "QtWindow";
18
19 private View m_surfaceContainer;
20 private View m_nativeView;
21 private HashMap<Integer, QtWindow> m_childWindows = new HashMap<Integer, QtWindow>();
22 private QtWindow m_parentWindow;
23 private GestureDetector m_gestureDetector;
24 private final QtEditText m_editText;
25
26 private static native void setSurface(int windowId, Surface surface);
27 static native void windowFocusChanged(boolean hasFocus, int id);
28
29 public QtWindow(Context context, QtWindow parentWindow, QtInputDelegate delegate)
30 {
31 super(context);
32 setId(View.generateViewId());
33 m_editText = new QtEditText(context, delegate);
34 setParent(parentWindow);
35 setFocusableInTouchMode(true);
36 addView(m_editText, new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
37 ViewGroup.LayoutParams.MATCH_PARENT));
38
39 QtNative.runAction(() -> {
40 m_gestureDetector =
41 new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
42 public void onLongPress(MotionEvent event) {
43 QtInputDelegate.longPress(getId(), (int) event.getX(), (int) event.getY());
44 }
45 });
46 m_gestureDetector.setIsLongpressEnabled(true);
47 });
48 }
49
50 void setVisible(boolean visible) {
51 QtNative.runAction(() -> {
52 if (visible)
53 setVisibility(View.VISIBLE);
54 else
55 setVisibility(View.INVISIBLE);
56 });
57 }
58
59 @Override
60 public void onSurfaceChanged(Surface surface)
61 {
62 setSurface(getId(), surface);
63 }
64
65 @Override
66 public boolean onTouchEvent(MotionEvent event)
67 {
68 m_editText.requestFocus();
69 event.setLocation(event.getX() + getX(), event.getY() + getY());
70 QtInputDelegate.sendTouchEvent(event, getId());
71 m_gestureDetector.onTouchEvent(event);
72 return true;
73 }
74
75 @Override
76 public boolean onTrackballEvent(MotionEvent event)
77 {
78 QtInputDelegate.sendTrackballEvent(event, getId());
79 return true;
80 }
81
82 @Override
83 public boolean onGenericMotionEvent(MotionEvent event)
84 {
85 return QtInputDelegate.sendGenericMotionEvent(event, getId());
86 }
87
88 public void removeWindow()
89 {
90 if (m_parentWindow != null)
91 m_parentWindow.removeChildWindow(getId());
92 }
93
94 public void createSurface(final boolean onTop,
95 final int x, final int y, final int w, final int h,
96 final int imageDepth, final boolean isOpaque,
97 final int surfaceContainerType) // TODO constant for type
98 {
99 QtNative.runAction(()-> {
100 if (m_surfaceContainer != null)
101 removeView(m_surfaceContainer);
102
103 setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
104 if (surfaceContainerType == 0) {
105 m_surfaceContainer = new QtSurface(getContext(), QtWindow.this,
106 onTop, imageDepth);
107 } else {
108 m_surfaceContainer = new QtTextureView(getContext(), QtWindow.this, isOpaque);
109 }
110 m_surfaceContainer.setLayoutParams(new QtLayout.LayoutParams(
111 ViewGroup.LayoutParams.MATCH_PARENT,
112 ViewGroup.LayoutParams.MATCH_PARENT));
113 // The surface container of this window will be added as the first of the stack.
114 // All other views are stacked based on the order they are created.
115 addView(m_surfaceContainer, 0);
116 });
117 }
118
119 public void destroySurface()
120 {
121 QtNative.runAction(()-> {
122 if (m_surfaceContainer != null) {
123 removeView(m_surfaceContainer);
124 m_surfaceContainer = null;
125 }
126 }, false);
127 }
128
129 public void setGeometry(final int x, final int y, final int w, final int h)
130 {
131 QtNative.runAction(()-> {
132 if (getContext() instanceof QtActivityBase)
133 setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
134 });
135 }
136
137 public void addChildWindow(QtWindow window)
138 {
139 QtNative.runAction(()-> {
140 m_childWindows.put(window.getId(), window);
141 addView(window, getChildCount());
142 });
143 }
144
145 public void removeChildWindow(int id)
146 {
147 QtNative.runAction(()-> {
148 if (m_childWindows.containsKey(id))
149 removeView(m_childWindows.remove(id));
150 });
151 }
152
153 public void setNativeView(final View view,
154 final int x, final int y, final int w, final int h)
155 {
156 QtNative.runAction(()-> {
157 if (m_nativeView != null)
158 removeView(m_nativeView);
159
160 m_nativeView = view;
161 QtWindow.this.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
162 m_nativeView.setLayoutParams(new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
163 ViewGroup.LayoutParams.MATCH_PARENT));
164 addView(m_nativeView);
165 });
166 }
167
168 public void bringChildToFront(int id)
169 {
170 QtNative.runAction(()-> {
171 View view = m_childWindows.get(id);
172 if (view != null) {
173 if (getChildCount() > 0)
174 moveChild(view, getChildCount() - 1);
175 }
176 });
177 }
178
179 public void bringChildToBack(int id) {
180 QtNative.runAction(()-> {
181 View view = m_childWindows.get(id);
182 if (view != null) {
183 moveChild(view, 0);
184 }
185 });
186 }
187
188 public void removeNativeView()
189 {
190 QtNative.runAction(()-> {
191 if (m_nativeView != null) {
192 removeView(m_nativeView);
193 m_nativeView = null;
194 }
195 });
196 }
197
198 void setParent(QtWindow parentWindow)
199 {
200 if (m_parentWindow == parentWindow)
201 return;
202
203 if (m_parentWindow != null)
204 m_parentWindow.removeChildWindow(getId());
205
206 m_parentWindow = parentWindow;
207 if (m_parentWindow != null)
208 m_parentWindow.addChildWindow(this);
209 }
210
211 QtWindow parent()
212 {
213 return m_parentWindow;
214 }
215}
employee setId(37)
static void * context
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint y
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
static bool onTop(QWaylandQuickShellSurfaceItem *surf)
aWidget window() -> setWindowTitle("New Window Title")
[2]
file setParent(multiPart)
QQuickView * view
[0]