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 super(context);
18 }
19
20 QtLayout(Context context, AttributeSet attrs)
21 {
22 super(context, attrs);
23 }
24
25 QtLayout(Context context, AttributeSet attrs, int defStyle)
26 {
27 super(context, attrs, defStyle);
28 }
29
30 @Override
31 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
32 {
33 int count = getChildCount();
34
35 int maxHeight = 0;
36 int maxWidth = 0;
37
38 // Find out how big everyone wants to be
39 measureChildren(widthMeasureSpec, heightMeasureSpec);
40
41 // Find rightmost and bottom-most child
42 for (int i = 0; i < count; i++) {
43 View child = getChildAt(i);
44 if (child.getVisibility() != GONE) {
45 int childRight;
46 int childBottom;
47
48 if (child.getLayoutParams() instanceof QtLayout.LayoutParams) {
49 QtLayout.LayoutParams lp
50 = (QtLayout.LayoutParams) child.getLayoutParams();
51 childRight = lp.x + child.getMeasuredWidth();
52 childBottom = lp.y + child.getMeasuredHeight();
53 } else {
54 childRight = child.getMeasuredWidth();
55 childBottom = child.getMeasuredHeight();
56 }
57
58 maxWidth = Math.max(maxWidth, childRight);
59 maxHeight = Math.max(maxHeight, childBottom);
60 }
61 }
62
63 // Check against minimum height and width
64 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
65 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
66
67 setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
68 resolveSize(maxHeight, heightMeasureSpec));
69 }
70
77 @Override
78 protected ViewGroup.LayoutParams generateDefaultLayoutParams()
79 {
80 return new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
81 android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
82 0,
83 0);
84 }
85
86 @Override
87 protected void onLayout(boolean changed, int l, int t, int r, int b)
88 {
89 int count = getChildCount();
90 for (int i = 0; i < count; i++) {
91 View child = getChildAt(i);
92 if (child.getVisibility() != GONE) {
93 QtLayout.LayoutParams lp =
94 (QtLayout.LayoutParams) child.getLayoutParams();
95
96 int childLeft = lp.x;
97 int childTop = lp.y;
98 int childRight = (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) ?
99 r - l : childLeft + child.getMeasuredWidth();
100 int childBottom = (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) ?
101 b - t : childTop + child.getMeasuredHeight();
102 child.layout(childLeft, childTop, childRight, childBottom);
103 }
104 }
105 }
106
107 // Override to allow type-checking of LayoutParams.
108 @Override
109 protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
110 {
111 return p instanceof QtLayout.LayoutParams;
112 }
113
114 @Override
115 protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
116 {
117 return new LayoutParams(p);
118 }
119
125 static class LayoutParams extends ViewGroup.LayoutParams
126 {
130 int x;
134 int y;
135
147 LayoutParams(int width, int height, int x, int y)
148 {
149 super(width, height);
150 this.x = x;
151 this.y = y;
152 }
153
154 LayoutParams(int width, int height)
155 {
156 super(width, height);
157 }
158
162 LayoutParams(ViewGroup.LayoutParams source)
163 {
164 super(source);
165 }
166 }
167
168 void moveChild(View view, int index)
169 {
170 if (view == null)
171 return;
172
173 if (indexOfChild(view) == -1)
174 return;
175
176 detachViewFromParent(view);
177 requestLayout();
178 invalidate();
179 attachViewToParent(view, index, view.getLayoutParams());
180 }
181
188 void setLayoutParams(final View childView,
189 final ViewGroup.LayoutParams params,
190 final boolean forceRedraw)
191 {
192 // Invalid view
193 if (childView == null)
194 return;
195
196 // Invalid params
197 if (!checkLayoutParams(params))
198 return;
199
200 final ViewParent parent = childView.getParent();
201
202 // View is already in the layout and can therefore be updated
203 final boolean canUpdate = (this == parent);
204
205 if (canUpdate) {
206 childView.setLayoutParams(params);
207 if (forceRedraw)
208 invalidate();
209 } else {
210 // If the parent was already set it need to be removed first
211 if (parent instanceof ViewGroup)
212 ((ViewGroup)parent).removeView(childView);
213 addView(childView, params);
214 }
215 }
216}
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
QPainter Context
static const QString context()
Definition java.cpp:398
static struct AttrInfo attrs[]
GLboolean GLboolean GLboolean b
GLboolean r
GLenum GLenum GLsizei count
GLuint index
GLint GLsizei width
GLsizei GLsizei GLchar * source
void ** params
GLfloat GLfloat p
GLdouble GLdouble t
Definition qopenglext.h:243
QLayoutItem * child
[0]
QQuickView * view
[0]