Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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.content.Context;
8import android.util.AttributeSet;
9import android.view.View;
10import android.view.ViewGroup;
11import android.view.ViewParent;
12
13class QtLayout extends ViewGroup {
14
15 QtLayout(Context context)
16 {
17 this(context, View.generateViewId());
18 }
19
20 QtLayout(Context context, int viewId)
21 {
22 super(context);
23 setId(viewId);
24 }
25
26 QtLayout(Context context, AttributeSet attrs)
27 {
28 super(context, attrs);
29 if (getId() == View.NO_ID)
30 setId(View.generateViewId());
31 }
32
33 QtLayout(Context context, AttributeSet attrs, int defStyle)
34 {
35 super(context, attrs, defStyle);
36 if (getId() == View.NO_ID)
37 setId(View.generateViewId());
38 }
39
41 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
42 {
43 int count = getChildCount();
44
45 int maxHeight = 0;
46 int maxWidth = 0;
47
48 // Find out how big everyone wants to be
49 measureChildren(widthMeasureSpec, heightMeasureSpec);
50
51 // Find rightmost and bottom-most child
52 for (int i = 0; i < count; i++) {
53 View child = getChildAt(i);
54 if (child.getVisibility() != GONE) {
55 int childRight;
56 int childBottom;
57
58 if (child.getLayoutParams() instanceof QtLayout.LayoutParams) {
59 QtLayout.LayoutParams lp
60 = (QtLayout.LayoutParams) child.getLayoutParams();
61 childRight = lp.x + child.getMeasuredWidth();
62 childBottom = lp.y + child.getMeasuredHeight();
63 } else {
64 childRight = child.getMeasuredWidth();
65 childBottom = child.getMeasuredHeight();
66 }
67
68 maxWidth = Math.max(maxWidth, childRight);
69 maxHeight = Math.max(maxHeight, childBottom);
70 }
71 }
72
73 // Check against minimum height and width
74 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
75 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
76
77 setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
78 resolveSize(maxHeight, heightMeasureSpec));
79 }
80
88 protected ViewGroup.LayoutParams generateDefaultLayoutParams()
89 {
90 return new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
91 android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
92 0,
93 0);
94 }
95
97 protected void onLayout(boolean changed, int l, int t, int r, int b)
98 {
99 int count = getChildCount();
100 for (int i = 0; i < count; i++) {
101 View child = getChildAt(i);
102 if (child.getVisibility() != GONE) {
103 QtLayout.LayoutParams lp =
104 (QtLayout.LayoutParams) child.getLayoutParams();
105
106 int childLeft = lp.x;
107 int childTop = lp.y;
108 int childRight = (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) ?
109 r - l : childLeft + child.getMeasuredWidth();
110 int childBottom = (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) ?
111 b - t : childTop + child.getMeasuredHeight();
112 child.layout(childLeft, childTop, childRight, childBottom);
113 }
114 }
115 }
116
117 // Override to allow type-checking of LayoutParams.
118 @Override
119 protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
120 {
121 return p instanceof QtLayout.LayoutParams;
122 }
123
124 @Override
125 protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
126 {
127 return new LayoutParams(p);
128 }
129
135 static class LayoutParams extends ViewGroup.LayoutParams
136 {
140 int x;
144 int y;
145
157 LayoutParams(int width, int height, int x, int y)
158 {
159 super(width, height);
160 this.x = x;
161 this.y = y;
162 }
163
164 LayoutParams(int width, int height)
165 {
166 super(width, height);
167 }
168
172 LayoutParams(ViewGroup.LayoutParams source)
173 {
174 super(source);
175 }
176 }
177
178 void moveChild(View view, int index)
179 {
180 if (view == null)
181 return;
182
183 if (indexOfChild(view) == -1)
184 return;
185
186 detachViewFromParent(view);
187 requestLayout();
188 invalidate();
189 attachViewToParent(view, index, view.getLayoutParams());
190 }
191
198 void setLayoutParams(final View childView,
199 final ViewGroup.LayoutParams params,
200 final boolean forceRedraw)
201 {
202 // Invalid view
203 if (childView == null)
204 return;
205
206 // Invalid params
207 if (!checkLayoutParams(params))
208 return;
209
210 final ViewParent parent = childView.getParent();
211
212 // View is already in the layout and can therefore be updated
213 final boolean canUpdate = (this == parent);
214
215 if (canUpdate) {
216 childView.setLayoutParams(params);
217 if (forceRedraw)
218 invalidate();
219 } else {
220 // If the parent was already set it need to be removed first
221 if (parent instanceof ViewGroup)
222 ((ViewGroup)parent).removeView(childView);
223 addView(childView, params);
224 }
225 }
226}
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
QPainter Context
GLvoid ** params
GLenum GLenum GLsizei count
GLboolean GLboolean GLboolean b
GLboolean r
GLuint index
GLint GLsizei width
GLsizei GLsizei GLchar * source
GLfloat GLfloat p
GLdouble GLdouble t
Definition qopenglext.h:243
QLayoutItem * child
[0]
QQuickView * view
[0]