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
QtLayout.java
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5package org.qtproject.qt.android;
6
7import android.app.Activity;
8import android.content.Context;
9import android.os.Build;
10import android.util.AttributeSet;
11import android.util.DisplayMetrics;
12import android.view.Display;
13import android.view.MotionEvent;
14import android.view.View;
15import android.view.ViewGroup;
16
17class QtLayout extends ViewGroup {
18
19 public QtLayout(Context context)
20 {
21 super(context);
22 }
23
24 public QtLayout(Context context, AttributeSet attrs)
25 {
26 super(context, attrs);
27 }
28
29 public QtLayout(Context context, AttributeSet attrs, int defStyle)
30 {
31 super(context, attrs, defStyle);
32 }
33
34 @Override
35 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
36 {
37 int count = getChildCount();
38
39 int maxHeight = 0;
40 int maxWidth = 0;
41
42 // Find out how big everyone wants to be
43 measureChildren(widthMeasureSpec, heightMeasureSpec);
44
45 // Find rightmost and bottom-most child
46 for (int i = 0; i < count; i++) {
47 View child = getChildAt(i);
48 if (child.getVisibility() != GONE) {
49 int childRight;
50 int childBottom;
51
52 if (child.getLayoutParams() instanceof QtLayout.LayoutParams) {
53 QtLayout.LayoutParams lp
54 = (QtLayout.LayoutParams) child.getLayoutParams();
55 childRight = lp.x + child.getMeasuredWidth();
56 childBottom = lp.y + child.getMeasuredHeight();
57 } else {
58 childRight = child.getMeasuredWidth();
59 childBottom = child.getMeasuredHeight();
60 }
61
62 maxWidth = Math.max(maxWidth, childRight);
63 maxHeight = Math.max(maxHeight, childBottom);
64 }
65 }
66
67 // Check against minimum height and width
68 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
69 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
70
71 setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
72 resolveSize(maxHeight, heightMeasureSpec));
73 }
74
81 @Override
82 protected ViewGroup.LayoutParams generateDefaultLayoutParams()
83 {
84 return new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
85 android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
86 0,
87 0);
88 }
89
90 @Override
91 protected void onLayout(boolean changed, int l, int t, int r, int b)
92 {
93 int count = getChildCount();
94 for (int i = 0; i < count; i++) {
95 View child = getChildAt(i);
96 if (child.getVisibility() != GONE) {
97 QtLayout.LayoutParams lp =
98 (QtLayout.LayoutParams) child.getLayoutParams();
99
100 int childLeft = lp.x;
101 int childTop = lp.y;
102 int childRight = (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) ?
103 r - l : childLeft + child.getMeasuredWidth();
104 int childBottom = (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) ?
105 b - t : childTop + child.getMeasuredHeight();
106 child.layout(childLeft, childTop, childRight, childBottom);
107 }
108 }
109 }
110
111 // Override to allow type-checking of LayoutParams.
112 @Override
113 protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
114 {
115 return p instanceof QtLayout.LayoutParams;
116 }
117
118 @Override
119 protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
120 {
121 return new LayoutParams(p);
122 }
123
129 public static class LayoutParams extends ViewGroup.LayoutParams
130 {
134 public int x;
138 public int y;
139
151 public LayoutParams(int width, int height, int x, int y)
152 {
153 super(width, height);
154 this.x = x;
155 this.y = y;
156 }
157
158 public LayoutParams(int width, int height)
159 {
160 super(width, height);
161 }
162
166 public LayoutParams(ViewGroup.LayoutParams source)
167 {
168 super(source);
169 }
170 }
171
172 public void moveChild(View view, int index)
173 {
174 if (view == null)
175 return;
176
177 if (indexOfChild(view) == -1)
178 return;
179
180 detachViewFromParent(view);
181 requestLayout();
182 invalidate();
183 attachViewToParent(view, index, view.getLayoutParams());
184 }
185
192 public void setLayoutParams(final View childView,
193 final ViewGroup.LayoutParams params,
194 final boolean forceRedraw)
195 {
196 // Invalid view
197 if (childView == null)
198 return;
199
200 // Invalid params
201 if (!checkLayoutParams(params))
202 return;
203
204 // View is already in the layout and can therefore be updated
205 final boolean canUpdate = (this == childView.getParent());
206
207 if (canUpdate) {
208 childView.setLayoutParams(params);
209 if (forceRedraw)
210 invalidate();
211 } else {
212 addView(childView, params);
213 }
214 }
215}
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
LayoutParams(int width, int height, int x, int y)
LayoutParams(ViewGroup.LayoutParams source)
static void * context
static struct AttrInfo attrs[]
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLuint index
[2]
GLboolean r
[2]
GLenum GLenum GLsizei count
GLint GLsizei width
GLint y
GLsizei GLsizei GLchar * source
void ** params
GLdouble GLdouble t
Definition qopenglext.h:243
GLfloat GLfloat p
[1]
QLayoutItem * child
[0]
QQuickView * view
[0]