Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qapplication.h" | - |
41 | #include "qdebug.h" | - |
42 | #include "qformlayout.h" | - |
43 | #include "qlabel.h" | - |
44 | #include "qlayout_p.h" | - |
45 | #include "qlayoutengine_p.h" | - |
46 | #include "qrect.h" | - |
47 | #include "qvector.h" | - |
48 | #include "qwidget.h" | - |
49 | | - |
50 | QT_BEGIN_NAMESPACE | - |
51 | | - |
52 | namespace { | - |
53 | | - |
54 | | - |
55 | template <class T, int NumColumns> | - |
56 | class FixedColumnMatrix { | - |
57 | public: | - |
58 | typedef QVector<T> Storage; | - |
59 | | - |
60 | FixedColumnMatrix() { } | - |
61 | | - |
62 | void clear() { m_storage.clear(); } | - |
63 | | - |
64 | const T &operator()(int r, int c) const { return m_storage[r * NumColumns + c]; } | - |
65 | T &operator()(int r, int c) { return m_storage[r * NumColumns + c]; } | - |
66 | | - |
67 | int rowCount() const { return m_storage.size() / NumColumns; } | - |
68 | void addRow(const T &value);void insertRow(int r, const T &value); | - |
| void removeRow(int r); | |
| | |
| bool find(const T &value, int *rowPtr, int *colPtr) const ; | |
| int count(const T &value) const { return m_storage.count(value); | |
69 | | - |
70 | } | - |
71 | const Storage &storage() const { return m_storage; } | - |
72 | | - |
73 | static void storageIndexToPosition(int idx, int *rowPtr, int *colPtr); | - |
74 | | - |
75 | private: | - |
76 | Storage m_storage; | - |
77 | }; | - |
78 | | - |
| template <class T, int NumColumns> | |
| void FixedColumnMatrix<T, NumColumns>::addRow(const T &value) | |
| { | |
| for (int i = 0; i < NumColumns; ++i) | |
| m_storage.append(value); | |
| }template <class T, int NumColumns> | |
80 | void FixedColumnMatrix<T, NumColumns>::insertRow(int r, const T &value) | - |
81 | { | - |
82 | typename Storage::iterator it = m_storage.begin(); | - |
83 | it += r * NumColumns; | - |
84 | m_storage.insert(it, NumColumns, value); | - |
| } | |
| | |
| template <class T, int NumColumns> | |
| void FixedColumnMatrix<T, NumColumns>::removeRow(int r) | |
| { | |
| m_storage.remove(r * NumColumns, NumColumns); | |
| } | |
| | |
| template <class T, int NumColumns> | |
| bool FixedColumnMatrix<T, NumColumns>::find(const T &value, int *rowPtr, int *colPtr) const | |
| { | |
| const int idx = m_storage.indexOf(value); | |
| if (idx == -1) | |
| return false; | |
| storageIndexToPosition(idx, rowPtr, colPtr); | |
| return true;} | |
86 | | - |
87 | template <class T, int NumColumns> | - |
88 | void FixedColumnMatrix<T, NumColumns>::storageIndexToPosition(int idx, int *rowPtr, int *colPtr) | - |
89 | { | - |
90 | *rowPtr = idx / NumColumns; | - |
91 | *colPtr = idx % NumColumns; | - |
92 | } | - |
93 | } | - |
94 | | - |
95 | | - |
96 | | - |
97 | const uint DefaultFieldGrowthPolicy = 255; | - |
98 | const uint DefaultRowWrapPolicy = 255; | - |
99 | | - |
100 | enum { ColumnCount = 2 }; | - |
101 | | - |
102 | | - |
103 | | - |
104 | struct QFormLayoutItem | - |
105 | { | - |
106 | QFormLayoutItem(QLayoutItem* i) : item(i), fullRow(false), isHfw(false) { } | - |
107 | ~QFormLayoutItem() { delete item; } | - |
108 | | - |
109 | | - |
110 | QWidget *widget() const { return item->widget(); } | - |
111 | QLayout *layout() const { return item->layout(); } | - |
112 | | - |
113 | bool hasHeightForWidth() const { return item->hasHeightForWidth(); } | - |
114 | int heightForWidth(int width) const { return item->heightForWidth(width); } | - |
115 | int minimumHeightForWidth(int width) const { return item->minimumHeightForWidth(width); } | - |
116 | Qt::Orientations expandingDirections() const { return item->expandingDirections(); } | - |
117 | QSizePolicy::ControlTypes controlTypes() const { return item->controlTypes(); } | - |
118 | int vStretch() const { return widget() ? widget()->sizePolicy().verticalStretch() : 0; } | - |
119 | | - |
120 | void setGeometry(const QRect& r) { item->setGeometry(r); } | - |
121 | QRect geometry() const { return item->geometry(); } | - |
122 | | - |
123 | | - |
124 | bool operator==(const QFormLayoutItem& other) { return item == other.item; } | - |
125 | | - |
126 | QLayoutItem *item; | - |
127 | bool fullRow; | - |
128 | | - |
129 | | - |
130 | bool isHfw; | - |
131 | QSize minSize; | - |
132 | QSize sizeHint; | - |
133 | QSize maxSize; | - |
134 | | - |
135 | | - |
136 | int sbsHSpace; | - |
137 | int vSpace; | - |
138 | | - |
139 | | - |
140 | bool sideBySide; | - |
141 | int vLayoutIndex; | - |
142 | | - |
143 | | - |
144 | int layoutPos; | - |
145 | int layoutWidth; | - |
146 | }; | - |
147 | | - |
148 | class QFormLayoutPrivate : public QLayoutPrivate | - |
149 | { | - |
150 | Q_DECLARE_PUBLIC(QFormLayout) | - |
151 | | - |
152 | public: | - |
153 | typedef FixedColumnMatrix<QFormLayoutItem *, ColumnCount> ItemMatrix; | - |
154 | | - |
155 | QFormLayoutPrivate(); | - |
156 | ~QFormLayoutPrivate() { } | - |
157 | | - |
158 | int insertRow(int row); | - |
159 | void insertRows(int row, int count); | - |
160 | bool setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item); | - |
161 | void setLayout(int row, QFormLayout::ItemRole role, QLayout *layout); | - |
162 | void setWidget(int row, QFormLayout::ItemRole role, QWidget *widget); | - |
163 | | - |
164 | void arrangeWidgets(const QVector<QLayoutStruct>& layouts, QRect &rect); | - |
165 | | - |
166 | void updateSizes(); | - |
167 | | - |
168 | void setupVerticalLayoutData(int width); | - |
169 | void setupHorizontalLayoutData(int width); | - |
170 | | - |
171 | QStyle* getStyle() const; | - |
172 | | - |
173 | inline bool haveHfwCached(int width) const | - |
174 | { | - |
175 | return (hfw_width == width) || (width == sh_width && hfw_sh_height >= 0); | - |
176 | } | - |
177 | | - |
178 | void recalcHFW(int w); | - |
179 | void setupHfwLayoutData(); | - |
180 | | - |
181 | uint fieldGrowthPolicy : 8; | - |
182 | uint rowWrapPolicy : 8; | - |
183 | uint has_hfw : 2; | - |
184 | uint dirty : 2; | - |
185 | uint sizesDirty : 2; | - |
186 | uint expandVertical : 1; | - |
187 | uint expandHorizontal : 1; | - |
188 | Qt::Alignment labelAlignment; | - |
189 | Qt::Alignment formAlignment; | - |
190 | | - |
191 | ItemMatrix m_matrix; | - |
192 | QList<QFormLayoutItem *> m_things; | - |
193 | | - |
194 | int layoutWidth; | - |
195 | | - |
196 | int hfw_width; | - |
197 | int hfw_height; | - |
198 | int hfw_minheight; | - |
199 | | - |
200 | int hfw_sh_height; | - |
201 | int hfw_sh_minheight; | - |
202 | | - |
203 | int min_width; | - |
204 | int sh_width; | - |
205 | int thresh_width; | - |
206 | QSize minSize; | - |
207 | QSize prefSize; | - |
208 | int formMaxWidth; | - |
209 | void calcSizeHints(); | - |
210 | | - |
211 | QVector<QLayoutStruct> vLayouts; | - |
212 | int vLayoutCount; | - |
213 | int maxLabelWidth; | - |
214 | | - |
215 | QVector<QLayoutStruct> hfwLayouts; | - |
216 | | - |
217 | int hSpacing; | - |
218 | int vSpacing; | - |
219 | QLayoutItem* replaceAt(int index, QLayoutItem*) Q_DECL_OVERRIDE; | - |
220 | }; | - |
221 | | - |
222 | QFormLayoutPrivate::QFormLayoutPrivate() | - |
223 | : fieldGrowthPolicy(DefaultFieldGrowthPolicy), | - |
224 | rowWrapPolicy(DefaultRowWrapPolicy), has_hfw(false), dirty(true), sizesDirty(true), | - |
225 | expandVertical(0), expandHorizontal(0), labelAlignment(0), formAlignment(0), | - |
226 | layoutWidth(-1), hfw_width(-1), hfw_sh_height(-1), min_width(-1), | - |
227 | sh_width(-1), thresh_width(QLAYOUTSIZE_MAX), hSpacing(-1), vSpacing(-1) | - |
228 | { | - |
229 | } | - |
230 | | - |
231 | static Qt::Alignment fixedAlignment(Qt::Alignment alignment, Qt::LayoutDirection layoutDirection) | - |
232 | { | - |
233 | if (layoutDirection == Qt::RightToLeft && alignment & Qt::AlignAbsolute) { | - |
234 | | - |
235 | return Qt::Alignment((alignment & ~(Qt::AlignLeft | Qt::AlignRight | Qt::AlignAbsolute)) | - |
236 | | ((alignment & Qt::AlignRight) ? Qt::AlignLeft : 0) | - |
237 | | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0)); | - |
238 | } else { | - |
239 | return alignment & ~Qt::AlignAbsolute; | - |
240 | } | - |
241 | } | - |
242 | | - |
243 | static int storageIndexFromLayoutItem(const QFormLayoutPrivate::ItemMatrix &m, | - |
244 | QFormLayoutItem *item) | - |
245 | { | - |
246 | if (item) { | - |
247 | return m.storage().indexOf(item); | - |
248 | } else { | - |
249 | return -1; | - |
250 | } | - |
251 | } | - |
252 | | - |
253 | static void updateFormLayoutItem(QFormLayoutItem *item, int userVSpacing, | - |
254 | QFormLayout::FieldGrowthPolicy fieldGrowthPolicy, | - |
255 | bool fullRow) | - |
256 | { | - |
257 | item->minSize = item->item->minimumSize(); | - |
258 | item->sizeHint = item->item->sizeHint(); | - |
259 | item->maxSize = item->item->maximumSize(); | - |
260 | | - |
261 | if (!fullRow && (fieldGrowthPolicy == QFormLayout::FieldsStayAtSizeHint | - |
262 | || (fieldGrowthPolicy == QFormLayout::ExpandingFieldsGrow | - |
263 | && !(item->item->expandingDirections() & Qt::Horizontal)))) | - |
264 | item->maxSize.setWidth(item->sizeHint.width()); | - |
265 | | - |
266 | item->isHfw = item->item->hasHeightForWidth(); | - |
267 | item->vSpace = userVSpacing; | - |
268 | } | - |
269 | | - |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | void QFormLayoutPrivate::updateSizes() | - |
277 | { | - |
278 | Q_Q(QFormLayout); | - |
279 | | - |
280 | if (sizesDirty) { | - |
281 | QFormLayout::RowWrapPolicy wrapPolicy = q->rowWrapPolicy(); | - |
282 | bool wrapAllRows = (wrapPolicy == QFormLayout::WrapAllRows); | - |
283 | bool dontWrapRows = (wrapPolicy == QFormLayout::DontWrapRows); | - |
284 | int rr = m_matrix.rowCount(); | - |
285 | | - |
286 | has_hfw = false; | - |
287 | | - |
288 | | - |
289 | | - |
290 | bool expandH = false; | - |
291 | bool expandV = false; | - |
292 | | - |
293 | QFormLayoutItem *prevLbl = 0; | - |
294 | QFormLayoutItem *prevFld = 0; | - |
295 | | - |
296 | QWidget *parent = q->parentWidget(); | - |
297 | QStyle *style = parent ? parent->style() : 0; | - |
298 | | - |
299 | int userVSpacing = q->verticalSpacing(); | - |
300 | int userHSpacing = wrapAllRows ? 0 : q->horizontalSpacing(); | - |
301 | | - |
302 | int maxMinLblWidth = 0; | - |
303 | int maxMinFldWidth = 0; | - |
304 | int maxMinIfldWidth = 0; | - |
305 | | - |
306 | int maxShLblWidth = 0; | - |
307 | int maxShFldWidth = 0; | - |
308 | int maxShIfldWidth = 0; | - |
309 | | - |
310 | for (int i = 0; i < rr; ++i) { | - |
311 | QFormLayoutItem *label = m_matrix(i, 0); | - |
312 | QFormLayoutItem *field = m_matrix(i, 1); | - |
313 | | - |
314 | | - |
315 | if (!label && !field) | - |
316 | continue; | - |
317 | | - |
318 | if (label) { | - |
319 | updateFormLayoutItem(label, userVSpacing, q->fieldGrowthPolicy(), false); | - |
320 | if (label->isHfw) | - |
321 | has_hfw = true; | - |
322 | Qt::Orientations o = label->expandingDirections(); | - |
323 | | - |
324 | if (o & Qt::Vertical) | - |
325 | expandV = true; | - |
326 | if (o & Qt::Horizontal) | - |
327 | expandH = true; | - |
328 | } | - |
329 | if (field) { | - |
330 | updateFormLayoutItem(field, userVSpacing, q->fieldGrowthPolicy(), !label && field->fullRow); | - |
331 | field->sbsHSpace = (!label && field->fullRow) ? 0 : userHSpacing; | - |
332 | if (field->isHfw) | - |
333 | has_hfw = true; | - |
334 | | - |
335 | Qt::Orientations o = field->expandingDirections(); | - |
336 | | - |
337 | if (o & Qt::Vertical) | - |
338 | expandV = true; | - |
339 | if (o & Qt::Horizontal) | - |
340 | expandH = true; | - |
341 | } | - |
342 | | - |
343 | | - |
344 | if ((userHSpacing < 0 || userVSpacing < 0) && style) { | - |
345 | QSizePolicy::ControlTypes lbltypes = | - |
346 | QSizePolicy::ControlTypes(label ? label->controlTypes() : QSizePolicy::DefaultType); | - |
347 | QSizePolicy::ControlTypes fldtypes = | - |
348 | QSizePolicy::ControlTypes(field ? field->controlTypes() : QSizePolicy::DefaultType); | - |
349 | | - |
350 | | - |
351 | if (userVSpacing < 0) { | - |
352 | if (wrapAllRows) { | - |
353 | | - |
354 | QFormLayoutItem *lbltop = prevFld ? prevFld : prevLbl; | - |
355 | | - |
356 | QFormLayoutItem *fldtop = label ? label : lbltop; | - |
357 | QSizePolicy::ControlTypes lbltoptypes = | - |
358 | QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType); | - |
359 | QSizePolicy::ControlTypes fldtoptypes = | - |
360 | QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType); | - |
361 | if (label && lbltop) | - |
362 | label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent); | - |
363 | if (field && fldtop) | - |
364 | field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent); | - |
365 | } else { | - |
366 | | - |
367 | | - |
368 | QFormLayoutItem *lbltop = prevLbl ? prevLbl : prevFld; | - |
369 | QFormLayoutItem *fldtop = prevFld; | - |
370 | QSizePolicy::ControlTypes lbltoptypes = | - |
371 | QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType); | - |
372 | QSizePolicy::ControlTypes fldtoptypes = | - |
373 | QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType); | - |
374 | | - |
375 | | - |
376 | if (label) { | - |
377 | if (!field) { | - |
378 | int lblspacing = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent); | - |
379 | int fldspacing = style->combinedLayoutSpacing(fldtoptypes, lbltypes, Qt::Vertical, 0, parent); | - |
380 | label->vSpace = qMax(lblspacing, fldspacing); | - |
381 | } else | - |
382 | label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent); | - |
383 | } | - |
384 | | - |
385 | if (field) { | - |
386 | | - |
387 | if (!label) { | - |
388 | int lblspacing = style->combinedLayoutSpacing(lbltoptypes, fldtypes, Qt::Vertical, 0, parent); | - |
389 | int fldspacing = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent); | - |
390 | field->vSpace = qMax(lblspacing, fldspacing); | - |
391 | } else | - |
392 | field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent); | - |
393 | } | - |
394 | } | - |
395 | } | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | if (userHSpacing < 0 && !wrapAllRows && (label || !field->fullRow) && field) | - |
401 | field->sbsHSpace = style->combinedLayoutSpacing(QSizePolicy::Label, QSizePolicy::LineEdit, Qt::Horizontal, 0, parent); | - |
402 | } | - |
403 | | - |
404 | | - |
405 | | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | if (label) { | - |
412 | maxMinLblWidth = qMax(maxMinLblWidth, label->minSize.width()); | - |
413 | maxShLblWidth = qMax(maxShLblWidth, label->sizeHint.width()); | - |
414 | if (field) { | - |
415 | maxMinFldWidth = qMax(maxMinFldWidth, field->minSize.width() + field->sbsHSpace); | - |
416 | maxShFldWidth = qMax(maxShFldWidth, field->sizeHint.width() + field->sbsHSpace); | - |
417 | } | - |
418 | } else if (field) { | - |
419 | maxMinIfldWidth = qMax(maxMinIfldWidth, field->minSize.width()); | - |
420 | maxShIfldWidth = qMax(maxShIfldWidth, field->sizeHint.width()); | - |
421 | } | - |
422 | | - |
423 | prevLbl = label; | - |
424 | prevFld = field; | - |
425 | } | - |
426 | | - |
427 | | - |
428 | if (wrapAllRows) { | - |
429 | sh_width = qMax(maxShLblWidth, qMax(maxShIfldWidth, maxShFldWidth)); | - |
430 | min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth)); | - |
431 | | - |
432 | thresh_width = 0; | - |
433 | } else if (dontWrapRows) { | - |
434 | | - |
435 | sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth); | - |
436 | min_width = qMax(maxMinLblWidth + maxMinFldWidth, maxMinIfldWidth); | - |
437 | thresh_width = QWIDGETSIZE_MAX; | - |
438 | } else { | - |
439 | | - |
440 | sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth); | - |
441 | | - |
442 | | - |
443 | min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth)); | - |
444 | | - |
445 | thresh_width = maxShLblWidth + maxMinFldWidth; | - |
446 | } | - |
447 | | - |
448 | | - |
449 | expandVertical = expandV; | - |
450 | expandHorizontal = expandH; | - |
451 | } | - |
452 | sizesDirty = false; | - |
453 | } | - |
454 | | - |
455 | void QFormLayoutPrivate::recalcHFW(int w) | - |
456 | { | - |
457 | setupHfwLayoutData(); | - |
458 | | - |
459 | int h = 0; | - |
460 | int mh = 0; | - |
461 | | - |
462 | for (int r = 0; r < vLayoutCount; ++r) { | - |
463 | int spacing = hfwLayouts.at(r).spacing; | - |
464 | h += hfwLayouts.at(r).sizeHint + spacing; | - |
465 | mh += hfwLayouts.at(r).minimumSize + spacing; | - |
466 | } | - |
467 | | - |
468 | if (sh_width > 0 && sh_width == w) { | - |
469 | hfw_sh_height = qMin(QLAYOUTSIZE_MAX, h); | - |
470 | hfw_sh_minheight = qMin(QLAYOUTSIZE_MAX, mh); | - |
471 | } else { | - |
472 | hfw_width = w; | - |
473 | hfw_height = qMin(QLAYOUTSIZE_MAX, h); | - |
474 | hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh); | - |
475 | } | - |
476 | } | - |
477 | | - |
478 | void QFormLayoutPrivate::setupHfwLayoutData() | - |
479 | { | - |
480 | | - |
481 | | - |
482 | | - |
483 | | - |
484 | | - |
485 | | - |
486 | | - |
487 | | - |
488 | | - |
489 | | - |
490 | | - |
491 | | - |
492 | int i; | - |
493 | int rr = m_matrix.rowCount(); | - |
494 | | - |
495 | hfwLayouts.clear(); | - |
496 | hfwLayouts.resize(vLayoutCount); | - |
497 | for (i = 0; i < vLayoutCount; ++i) | - |
498 | hfwLayouts[i] = vLayouts.at(i); | - |
499 | | - |
500 | for (i = 0; i < rr; ++i) { | - |
501 | QFormLayoutItem *label = m_matrix(i, 0); | - |
502 | QFormLayoutItem *field = m_matrix(i, 1); | - |
503 | | - |
504 | if (label) { | - |
505 | if (label->isHfw) { | - |
506 | | - |
507 | | - |
508 | int hfw = label->heightForWidth(label->layoutWidth); | - |
509 | hfwLayouts[label->vLayoutIndex].minimumSize = hfw; | - |
510 | hfwLayouts[label->vLayoutIndex].sizeHint = hfw; | - |
511 | } else { | - |
512 | | - |
513 | | - |
514 | hfwLayouts[label->vLayoutIndex].sizeHint = label->sizeHint.height(); | - |
515 | hfwLayouts[label->vLayoutIndex].minimumSize = label->minSize.height(); | - |
516 | } | - |
517 | } | - |
518 | | - |
519 | if (field) { | - |
520 | int hfw = field->isHfw ? field->heightForWidth(field->layoutWidth) : 0; | - |
521 | int h = field->isHfw ? hfw : field->sizeHint.height(); | - |
522 | int mh = field->isHfw ? hfw : field->minSize.height(); | - |
523 | | - |
524 | if (field->sideBySide) { | - |
525 | int oh = hfwLayouts.at(field->vLayoutIndex).sizeHint; | - |
526 | int omh = hfwLayouts.at(field->vLayoutIndex).minimumSize; | - |
527 | | - |
528 | hfwLayouts[field->vLayoutIndex].sizeHint = qMax(h, oh); | - |
529 | hfwLayouts[field->vLayoutIndex].minimumSize = qMax(mh, omh); | - |
530 | } else { | - |
531 | hfwLayouts[field->vLayoutIndex].sizeHint = h; | - |
532 | hfwLayouts[field->vLayoutIndex].minimumSize = mh; | - |
533 | } | - |
534 | } | - |
535 | } | - |
536 | } | - |
537 | | - |
538 | | - |
539 | | - |
540 | | - |
541 | | - |
542 | | - |
543 | | - |
544 | | - |
545 | | - |
546 | | - |
547 | | - |
548 | | - |
549 | | - |
550 | | - |
551 | | - |
552 | | - |
553 | | - |
554 | | - |
555 | | - |
556 | | - |
557 | | - |
558 | | - |
559 | | - |
560 | | - |
561 | | - |
562 | | - |
563 | | - |
564 | | - |
565 | | - |
566 | | - |
567 | | - |
568 | | - |
569 | | - |
570 | | - |
571 | | - |
572 | | - |
573 | | - |
574 | | - |
575 | | - |
576 | static inline int spacingHelper(QWidget* parent, QStyle *style, int userVSpacing, bool recalculate, QFormLayoutItem* item1, QFormLayoutItem* item2, QFormLayoutItem* prevItem1, QFormLayoutItem *prevItem2) | - |
577 | { | - |
578 | int spacing = userVSpacing; | - |
579 | if (spacing < 0) { | - |
580 | if (!recalculate) { | - |
581 | if (item1) | - |
582 | spacing = item1->vSpace; | - |
583 | if (item2) | - |
584 | spacing = qMax(spacing, item2->vSpace); | - |
585 | } else { | - |
586 | if (style && prevItem1) { | - |
587 | QSizePolicy::ControlTypes itemtypes = | - |
588 | QSizePolicy::ControlTypes(item1 ? item1->controlTypes() : QSizePolicy::DefaultType); | - |
589 | int spacing2 = 0; | - |
590 | | - |
591 | spacing = style->combinedLayoutSpacing(itemtypes, prevItem1->controlTypes(), Qt::Vertical, 0, parent); | - |
592 | | - |
593 | | - |
594 | if (item2) | - |
595 | spacing2 = style->combinedLayoutSpacing(item2->controlTypes(), prevItem1->controlTypes(), Qt::Vertical, 0, parent); | - |
596 | else if (prevItem2) | - |
597 | spacing2 = style->combinedLayoutSpacing(itemtypes, prevItem2->controlTypes(), Qt::Vertical, 0, parent); | - |
598 | | - |
599 | spacing = qMax(spacing, spacing2); | - |
600 | } | - |
601 | } | - |
602 | } else { | - |
603 | if (prevItem1) { | - |
604 | QWidget *wid = prevItem1->item->widget(); | - |
605 | if (wid) | - |
606 | spacing = qMax(spacing, prevItem1->geometry().top() - wid->geometry().top() ); | - |
607 | } | - |
608 | if (prevItem2) { | - |
609 | QWidget *wid = prevItem2->item->widget(); | - |
610 | if (wid) | - |
611 | spacing = qMax(spacing, prevItem2->geometry().top() - wid->geometry().top() ); | - |
612 | } | - |
613 | } | - |
614 | return qMax(spacing, 0); | - |
615 | } | - |
616 | | - |
617 | static inline void initLayoutStruct(QLayoutStruct& sl, QFormLayoutItem* item) | - |
618 | { | - |
619 | sl.init(item->vStretch(), item->minSize.height()); | - |
620 | sl.sizeHint = item->sizeHint.height(); | - |
621 | sl.maximumSize = item->maxSize.height(); | - |
622 | sl.expansive = (item->expandingDirections() & Qt::Vertical); | - |
623 | sl.empty = false; | - |
624 | } | - |
625 | | - |
626 | void QFormLayoutPrivate::setupVerticalLayoutData(int width) | - |
627 | { | - |
628 | Q_Q(QFormLayout); | - |
629 | | - |
630 | | - |
631 | if ((width == layoutWidth || (width >= thresh_width && layoutWidth >= thresh_width)) && !dirty && !sizesDirty) | - |
632 | return; | - |
633 | | - |
634 | layoutWidth = width; | - |
635 | | - |
636 | int rr = m_matrix.rowCount(); | - |
637 | int vidx = 1; | - |
638 | QFormLayout::RowWrapPolicy rowWrapPolicy = q->rowWrapPolicy(); | - |
639 | bool wrapAllRows = (rowWrapPolicy == QFormLayout::WrapAllRows); | - |
640 | bool addTopBottomStretch = true; | - |
641 | | - |
642 | vLayouts.clear(); | - |
643 | vLayouts.resize((2 * rr) + 2); | - |
644 | | - |
645 | QStyle *style = 0; | - |
646 | | - |
647 | int userVSpacing = q->verticalSpacing(); | - |
648 | | - |
649 | if (userVSpacing < 0) { | - |
650 | if (QWidget *widget = q->parentWidget()) | - |
651 | style = widget->style(); | - |
652 | } | - |
653 | | - |
654 | | - |
655 | updateSizes(); | - |
656 | | - |
657 | | - |
658 | | - |
659 | | - |
660 | | - |
661 | maxLabelWidth = 0; | - |
662 | if (!wrapAllRows) { | - |
663 | for (int i = 0; i < rr; ++i) { | - |
664 | const QFormLayoutItem *label = m_matrix(i, 0); | - |
665 | const QFormLayoutItem *field = m_matrix(i, 1); | - |
666 | if (label && (label->sizeHint.width() + (field ? field->minSize.width() : 0) <= width)) | - |
667 | maxLabelWidth = qMax(maxLabelWidth, label->sizeHint.width()); | - |
668 | } | - |
669 | } else { | - |
670 | maxLabelWidth = width; | - |
671 | } | - |
672 | | - |
673 | QFormLayoutItem *prevItem1 = 0; | - |
674 | QFormLayoutItem *prevItem2 = 0; | - |
675 | bool prevRowSplit = false; | - |
676 | | - |
677 | for (int i = 0; i < rr; ++i) { | - |
678 | QFormLayoutItem *label = m_matrix(i, 0); | - |
679 | QFormLayoutItem *field = m_matrix(i, 1); | - |
680 | | - |
681 | | - |
682 | if (!label && !field) | - |
683 | continue; | - |
684 | | - |
685 | QSize min1; | - |
686 | QSize min2; | - |
687 | QSize sh1; | - |
688 | QSize sh2; | - |
689 | if (label) { | - |
690 | min1 = label->minSize; | - |
691 | sh1 = label->sizeHint; | - |
692 | } | - |
693 | if (field) { | - |
694 | min2 = field->minSize; | - |
695 | sh2 = field->sizeHint; | - |
696 | } | - |
697 | | - |
698 | | - |
699 | | - |
700 | bool splitSideBySide = (rowWrapPolicy == QFormLayout::WrapLongRows) | - |
701 | && ((maxLabelWidth < sh1.width()) || (width < (maxLabelWidth + min2.width()))); | - |
702 | | - |
703 | if (wrapAllRows || splitSideBySide) { | - |
704 | if (label) { | - |
705 | initLayoutStruct(vLayouts[vidx], label); | - |
706 | | - |
707 | if (vidx > 1) | - |
708 | vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, 0, prevItem1, prevItem2); | - |
709 | | - |
710 | label->vLayoutIndex = vidx; | - |
711 | label->sideBySide = false; | - |
712 | | - |
713 | prevItem1 = label; | - |
714 | prevItem2 = 0; | - |
715 | | - |
716 | if (vLayouts[vidx].stretch > 0) | - |
717 | addTopBottomStretch = false; | - |
718 | | - |
719 | ++vidx; | - |
720 | } | - |
721 | | - |
722 | if (field) { | - |
723 | initLayoutStruct(vLayouts[vidx], field); | - |
724 | | - |
725 | if (vidx > 1) | - |
726 | vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, 0, prevItem1, prevItem2); | - |
727 | | - |
728 | field->vLayoutIndex = vidx; | - |
729 | field->sideBySide = false; | - |
730 | | - |
731 | prevItem1 = field; | - |
732 | prevItem2 = 0; | - |
733 | | - |
734 | if (vLayouts[vidx].stretch > 0) | - |
735 | addTopBottomStretch = false; | - |
736 | | - |
737 | ++vidx; | - |
738 | } | - |
739 | | - |
740 | prevRowSplit = splitSideBySide; | - |
741 | } else { | - |
742 | | - |
743 | QSize max1(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); | - |
744 | QSize max2(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); | - |
745 | | - |
746 | int stretch1 = 0; | - |
747 | int stretch2 = 0; | - |
748 | bool expanding = false; | - |
749 | | - |
750 | if (label) { | - |
751 | max1 = label->maxSize; | - |
752 | if (label->expandingDirections() & Qt::Vertical) | - |
753 | expanding = true; | - |
754 | | - |
755 | label->sideBySide = (field != 0); | - |
756 | label->vLayoutIndex = vidx; | - |
757 | stretch1 = label->vStretch(); | - |
758 | } | - |
759 | | - |
760 | if (field) { | - |
761 | max2 = field->maxSize; | - |
762 | if (field->expandingDirections() & Qt::Vertical) | - |
763 | expanding = true; | - |
764 | | - |
765 | field->sideBySide = (label || !field->fullRow); | - |
766 | field->vLayoutIndex = vidx; | - |
767 | stretch2 = field->vStretch(); | - |
768 | } | - |
769 | | - |
770 | vLayouts[vidx].init(qMax(stretch1, stretch2), qMax(min1.height(), min2.height())); | - |
771 | vLayouts[vidx].sizeHint = qMax(sh1.height(), sh2.height()); | - |
772 | vLayouts[vidx].maximumSize = qMin(max1.height(), max2.height()); | - |
773 | vLayouts[vidx].expansive = expanding || (vLayouts[vidx].stretch > 0); | - |
774 | vLayouts[vidx].empty = false; | - |
775 | | - |
776 | if (vLayouts[vidx].stretch > 0) | - |
777 | addTopBottomStretch = false; | - |
778 | | - |
779 | if (vidx > 1) | - |
780 | vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, prevRowSplit, label, field, prevItem1, prevItem2); | - |
781 | | - |
782 | if (label) { | - |
783 | prevItem1 = label; | - |
784 | prevItem2 = field; | - |
785 | } else { | - |
786 | prevItem1 = field; | - |
787 | prevItem2 = 0; | - |
788 | } | - |
789 | | - |
790 | prevRowSplit = false; | - |
791 | ++vidx; | - |
792 | } | - |
793 | } | - |
794 | | - |
795 | if (addTopBottomStretch) { | - |
796 | Qt::Alignment formAlignment = q->formAlignment(); | - |
797 | | - |
798 | if (!(formAlignment & Qt::AlignBottom)) { | - |
799 | | - |
800 | vLayouts[vidx].init(1, 0); | - |
801 | vLayouts[vidx].expansive = true; | - |
802 | ++vidx; | - |
803 | } | - |
804 | | - |
805 | if (formAlignment & (Qt::AlignVCenter | Qt::AlignBottom)) { | - |
806 | | - |
807 | vLayouts[0].init(1, 0); | - |
808 | vLayouts[0].expansive = true; | - |
809 | } else { | - |
810 | vLayouts[0].init(0, 0); | - |
811 | } | - |
812 | } else { | - |
813 | vLayouts[0].init(0, 0); | - |
814 | } | - |
815 | | - |
816 | vLayoutCount = vidx; | - |
817 | dirty = false; | - |
818 | } | - |
819 | | - |
820 | void QFormLayoutPrivate::setupHorizontalLayoutData(int width) | - |
821 | { | - |
822 | Q_Q(QFormLayout); | - |
823 | | - |
824 | | - |
825 | | - |
826 | int fieldMaxWidth = 0; | - |
827 | | - |
828 | int rr = m_matrix.rowCount(); | - |
829 | bool wrapAllRows = (q->rowWrapPolicy() == QFormLayout::WrapAllRows); | - |
830 | | - |
831 | for (int i = 0; i < rr; ++i) { | - |
832 | QFormLayoutItem *label = m_matrix(i, 0); | - |
833 | QFormLayoutItem *field = m_matrix(i, 1); | - |
834 | | - |
835 | | - |
836 | if (!label && !field) | - |
837 | continue; | - |
838 | | - |
839 | if (label) { | - |
840 | | - |
841 | | - |
842 | label->layoutWidth = (field && label->sideBySide) ? maxLabelWidth : label->sizeHint.width(); | - |
843 | label->layoutPos = 0; | - |
844 | } | - |
845 | | - |
846 | if (field) { | - |
847 | | - |
848 | int fldwidth = width - maxLabelWidth - field->sbsHSpace; | - |
849 | | - |
850 | | - |
851 | | - |
852 | | - |
853 | if (!field->sideBySide) { | - |
854 | if (wrapAllRows || (!label && field->fullRow) || field->sizeHint.width() > fldwidth) { | - |
855 | field->layoutWidth = width; | - |
856 | field->layoutPos = 0; | - |
857 | } else { | - |
858 | field->layoutWidth = fldwidth; | - |
859 | field->layoutPos = width - fldwidth; | - |
860 | } | - |
861 | } else { | - |
862 | | - |
863 | field->layoutWidth = fldwidth; | - |
864 | field->layoutPos = width - fldwidth; | - |
865 | } | - |
866 | | - |
867 | fieldMaxWidth = qMax(fieldMaxWidth, field->maxSize.width()); | - |
868 | } | - |
869 | } | - |
870 | | - |
871 | formMaxWidth = maxLabelWidth + fieldMaxWidth; | - |
872 | } | - |
873 | | - |
874 | void QFormLayoutPrivate::calcSizeHints() | - |
875 | { | - |
876 | Q_Q(QFormLayout); | - |
877 | | - |
878 | int leftMargin, topMargin, rightMargin, bottomMargin; | - |
879 | q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - |
880 | | - |
881 | updateSizes(); | - |
882 | setupVerticalLayoutData(QLAYOUTSIZE_MAX); | - |
883 | | - |
884 | | - |
885 | int h = topMargin + bottomMargin; | - |
886 | int mh = topMargin + bottomMargin; | - |
887 | | - |
888 | | - |
889 | int w = sh_width + leftMargin + rightMargin; | - |
890 | int mw = min_width + leftMargin + rightMargin; | - |
891 | | - |
892 | for (int i = 0; i < vLayoutCount; ++i) { | - |
893 | int spacing = vLayouts.at(i).spacing; | - |
894 | h += vLayouts.at(i).sizeHint + spacing; | - |
895 | mh += vLayouts.at(i).minimumSize + spacing; | - |
896 | } | - |
897 | | - |
898 | minSize.rwidth() = qMin(mw, QLAYOUTSIZE_MAX); | - |
899 | minSize.rheight() = qMin(mh, QLAYOUTSIZE_MAX); | - |
900 | prefSize.rwidth() = qMin(w, QLAYOUTSIZE_MAX); | - |
901 | prefSize.rheight() = qMin(h, QLAYOUTSIZE_MAX); | - |
902 | } | - |
903 | | - |
904 | int QFormLayoutPrivate::insertRow(int row) | - |
905 | { | - |
906 | int rowCnt = m_matrix.rowCount(); | - |
907 | if (uint(row) > uint(rowCnt)) | - |
908 | row = rowCnt; | - |
909 | | - |
910 | insertRows(row, 1); | - |
911 | return row; | - |
912 | } | - |
913 | | - |
914 | void QFormLayoutPrivate::insertRows(int row, int count) | - |
915 | { | - |
916 | while (count > 0) { | - |
917 | m_matrix.insertRow(row, 0); | - |
918 | --count; | - |
919 | } | - |
920 | } | - |
921 | | - |
922 | bool QFormLayoutPrivate::setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item) | - |
923 | { | - |
924 | const bool fullRow = role == QFormLayout::SpanningRole; | - |
925 | const int column = role == QFormLayout::SpanningRole ? 1 : static_cast<int>(role);TRUE | never evaluated | FALSE | never evaluated |
| 0 |
926 | if (Q_UNLIKELY(uint(row) >= uint(m_matrix.rowCount()) || uint(column) > 1U))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
927 | qWarning("QFormLayoutPrivate::setItem: Invalid cell (%d, %d)", row, column); | - |
928 | return false; never executed: return false; | 0 |
929 | } | - |
930 | | - |
931 | if (!item)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
932 | return false; never executed: return false; | 0 |
933 | | - |
934 | if (Q_UNLIKELY(m_matrix(row, column))))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
935 | qWarning("QFormLayoutPrivate::setItem: Cell (%d, %d) already occupied", row, column); | - |
936 | return false; never executed: return false; | 0 |
937 | } | - |
938 | | - |
939 | QFormLayoutItem *i = new QFormLayoutItem(item); | - |
940 | i->fullRow = fullRow; | - |
941 | m_matrix(row, column) = i; | - |
942 | | - |
943 | m_things.append(i); | - |
944 | return true; never executed: return true; | 0 |
945 | } | - |
946 | | - |
947 | void QFormLayoutPrivate::setLayout(int row, QFormLayout::ItemRole role, QLayout *layout) | - |
948 | { | - |
949 | if (layout) { | - |
950 | Q_Q(QFormLayout); | - |
951 | if (q->adoptLayout(layout)) | - |
952 | setItem(row, role, layout); | - |
953 | } | - |
954 | } | - |
955 | | - |
956 | void QFormLayoutPrivate::setWidget(int row, QFormLayout::ItemRole role, QWidget *widget) | - |
957 | { | - |
958 | if (widget) { | - |
959 | Q_Q(QFormLayout); | - |
960 | q->addChildWidget(widget); | - |
961 | QWidgetItem *item = QLayoutPrivate::createWidgetItem(q, widget); | - |
962 | if (!setItem(row, role, item)) | - |
963 | delete item; | - |
964 | } | - |
965 | } | - |
966 | | - |
967 | QStyle* QFormLayoutPrivate::getStyle() const | - |
968 | { | - |
969 | Q_Q(const QFormLayout); | - |
970 | | - |
971 | | - |
972 | if (QWidget *parentWidget = q->parentWidget()) | - |
973 | return parentWidget->style(); | - |
974 | else | - |
975 | return QApplication::style(); | - |
976 | } | - |
977 | | - |
978 | QLayoutItem* QFormLayoutPrivate::replaceAt(int index, QLayoutItem *newitem) | - |
979 | { | - |
980 | Q_Q(QFormLayout); | - |
981 | if (!newitem)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
982 | return 0; never executed: return 0; | 0 |
983 | const int storageIndex = storageIndexFromLayoutItem(m_matrix, m_things.value(index)); | - |
984 | if (Q_UNLIKELY(storageIndex == -1))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
985 | | - |
986 | qWarning("QFormLayoutPrivate::replaceAt: Invalid index %d", index); | - |
987 | return 0; never executed: return 0; | 0 |
988 | } | - |
989 | | - |
990 | int row, col; | - |
991 | QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col); | - |
992 | Q_ASSERT(m_matrix(row, col)); | - |
993 | | - |
994 | QFormLayoutItem *item = m_matrix(row, col); | - |
995 | Q_ASSERT(item); | - |
996 | | - |
997 | QLayoutItem *olditem = item->item; | - |
998 | item->item = newitem; | - |
999 | | - |
1000 | q->invalidate(); | - |
1001 | return olditem; never executed: return olditem; | 0 |
1002 | } | - |
1003 | | - |
1004 | | - |
1005 | | - |
1006 | | - |
1007 | | - |
1008 | | - |
1009 | | - |
1010 | | - |
1011 | | - |
1012 | | - |
1013 | | - |
1014 | | - |
1015 | | - |
1016 | | - |
1017 | | - |
1018 | | - |
1019 | | - |
1020 | | - |
1021 | | - |
1022 | | - |
1023 | | - |
1024 | | - |
1025 | | - |
1026 | | - |
1027 | | - |
1028 | | - |
1029 | | - |
1030 | | - |
1031 | | - |
1032 | | - |
1033 | | - |
1034 | | - |
1035 | | - |
1036 | | - |
1037 | | - |
1038 | | - |
1039 | | - |
1040 | | - |
1041 | | - |
1042 | | - |
1043 | | - |
1044 | | - |
1045 | | - |
1046 | | - |
1047 | | - |
1048 | | - |
1049 | | - |
1050 | | - |
1051 | | - |
1052 | | - |
1053 | | - |
1054 | | - |
1055 | | - |
1056 | | - |
1057 | | - |
1058 | | - |
1059 | | - |
1060 | | - |
1061 | | - |
1062 | | - |
1063 | | - |
1064 | | - |
1065 | | - |
1066 | | - |
1067 | | - |
1068 | | - |
1069 | | - |
1070 | | - |
1071 | | - |
1072 | | - |
1073 | | - |
1074 | | - |
1075 | | - |
1076 | | - |
1077 | | - |
1078 | | - |
1079 | | - |
1080 | | - |
1081 | | - |
1082 | | - |
1083 | | - |
1084 | | - |
1085 | | - |
1086 | | - |
1087 | | - |
1088 | | - |
1089 | | - |
1090 | | - |
1091 | | - |
1092 | | - |
1093 | | - |
1094 | | - |
1095 | | - |
1096 | | - |
1097 | | - |
1098 | | - |
1099 | | - |
1100 | | - |
1101 | | - |
1102 | | - |
1103 | | - |
1104 | | - |
1105 | | - |
1106 | | - |
1107 | | - |
1108 | | - |
1109 | | - |
1110 | | - |
1111 | | - |
1112 | | - |
1113 | | - |
1114 | | - |
1115 | | - |
1116 | | - |
1117 | | - |
1118 | | - |
1119 | | - |
1120 | | - |
1121 | | - |
1122 | | - |
1123 | | - |
1124 | | - |
1125 | | - |
1126 | | - |
1127 | | - |
1128 | | - |
1129 | | - |
1130 | | - |
1131 | | - |
1132 | | - |
1133 | | - |
1134 | | - |
1135 | | - |
1136 | | - |
1137 | | - |
1138 | | - |
1139 | | - |
1140 | | - |
1141 | | - |
1142 | | - |
1143 | | - |
1144 | | - |
1145 | | - |
1146 | | - |
1147 | | - |
1148 | | - |
1149 | | - |
1150 | | - |
1151 | | - |
1152 | | - |
1153 | | - |
1154 | | - |
1155 | | - |
1156 | | - |
1157 | | - |
1158 | | - |
1159 | | - |
1160 | QFormLayout::QFormLayout(QWidget *parent) | - |
1161 | : QLayout(*new QFormLayoutPrivate, 0, parent) | - |
1162 | { | - |
1163 | } | - |
1164 | | - |
1165 | | - |
1166 | | - |
1167 | | - |
1168 | QFormLayout::~QFormLayout() | - |
1169 | { | - |
1170 | Q_D(QFormLayout); | - |
1171 | | - |
1172 | | - |
1173 | | - |
1174 | | - |
1175 | | - |
1176 | | - |
1177 | d->m_things.clear(); | - |
1178 | qDeleteAll(d->m_matrix.storage()); | - |
1179 | d->m_matrix.clear(); | - |
1180 | } | - |
1181 | | - |
1182 | | - |
1183 | | - |
1184 | | - |
1185 | | - |
1186 | | - |
1187 | | - |
1188 | void QFormLayout::addRow(QWidget *label, QWidget *field) | - |
1189 | { | - |
1190 | insertRow(-1, label, field); | - |
1191 | } | - |
1192 | | - |
1193 | | - |
1194 | | - |
1195 | | - |
1196 | void QFormLayout::addRow(QWidget *label, QLayout *field) | - |
1197 | { | - |
1198 | insertRow(-1, label, field); | - |
1199 | } | - |
1200 | | - |
1201 | | - |
1202 | | - |
1203 | | - |
1204 | | - |
1205 | | - |
1206 | | - |
1207 | | - |
1208 | void QFormLayout::addRow(const QString &labelText, QWidget *field) | - |
1209 | { | - |
1210 | insertRow(-1, labelText, field); | - |
1211 | } | - |
1212 | | - |
1213 | | - |
1214 | | - |
1215 | | - |
1216 | | - |
1217 | | - |
1218 | | - |
1219 | void QFormLayout::addRow(const QString &labelText, QLayout *field) | - |
1220 | { | - |
1221 | insertRow(-1, labelText, field); | - |
1222 | } | - |
1223 | | - |
1224 | | - |
1225 | | - |
1226 | | - |
1227 | | - |
1228 | | - |
1229 | | - |
1230 | void QFormLayout::addRow(QWidget *widget) | - |
1231 | { | - |
1232 | insertRow(-1, widget); | - |
1233 | } | - |
1234 | | - |
1235 | | - |
1236 | | - |
1237 | | - |
1238 | | - |
1239 | | - |
1240 | | - |
1241 | void QFormLayout::addRow(QLayout *layout) | - |
1242 | { | - |
1243 | insertRow(-1, layout); | - |
1244 | } | - |
1245 | | - |
1246 | | - |
1247 | | - |
1248 | | - |
1249 | | - |
1250 | | - |
1251 | | - |
1252 | | - |
1253 | void QFormLayout::insertRow(int row, QWidget *label, QWidget *field) | - |
1254 | { | - |
1255 | Q_D(QFormLayout); | - |
1256 | if ((label && !d->checkWidget(label)) || (field && !d->checkWidget(field))) | - |
1257 | return; | - |
1258 | | - |
1259 | row = d->insertRow(row); | - |
1260 | if (label) | - |
1261 | d->setWidget(row, LabelRole, label); | - |
1262 | if (field) | - |
1263 | d->setWidget(row, FieldRole, field); | - |
1264 | invalidate(); | - |
1265 | } | - |
1266 | | - |
1267 | | - |
1268 | | - |
1269 | | - |
1270 | void QFormLayout::insertRow(int row, QWidget *label, QLayout *field) | - |
1271 | { | - |
1272 | Q_D(QFormLayout); | - |
1273 | if ((label && !d->checkWidget(label)) || (field && !d->checkLayout(field))) | - |
1274 | return; | - |
1275 | | - |
1276 | row = d->insertRow(row); | - |
1277 | if (label) | - |
1278 | d->setWidget(row, LabelRole, label); | - |
1279 | if (field) | - |
1280 | d->setLayout(row, FieldRole, field); | - |
1281 | invalidate(); | - |
1282 | } | - |
1283 | | - |
1284 | | - |
1285 | | - |
1286 | | - |
1287 | | - |
1288 | | - |
1289 | | - |
1290 | | - |
1291 | void QFormLayout::insertRow(int row, const QString &labelText, QWidget *field) | - |
1292 | { | - |
1293 | Q_D(QFormLayout); | - |
1294 | if (field && !d->checkWidget(field)) | - |
1295 | return; | - |
1296 | | - |
1297 | QLabel *label = 0; | - |
1298 | if (!labelText.isEmpty()) { | - |
1299 | label = new QLabel(labelText); | - |
1300 | #ifndef QT_NO_SHORTCUT | - |
1301 | label->setBuddy(field); | - |
1302 | #endif | - |
1303 | } | - |
1304 | insertRow(row, label, field); | - |
1305 | } | - |
1306 | | - |
1307 | | - |
1308 | | - |
1309 | | - |
1310 | | - |
1311 | | - |
1312 | | - |
1313 | void QFormLayout::insertRow(int row, const QString &labelText, QLayout *field) | - |
1314 | { | - |
1315 | Q_D(QFormLayout); | - |
1316 | if (field && !d->checkLayout(field)) | - |
1317 | return; | - |
1318 | | - |
1319 | insertRow(row, labelText.isEmpty() ? 0 : new QLabel(labelText), field); | - |
1320 | } | - |
1321 | | - |
1322 | | - |
1323 | | - |
1324 | | - |
1325 | | - |
1326 | | - |
1327 | | - |
1328 | | - |
1329 | void QFormLayout::insertRow(int row, QWidget *widget) | - |
1330 | { | - |
1331 | Q_D(QFormLayout); | - |
1332 | if (!d->checkWidget(widget)) | - |
1333 | return; | - |
1334 | | - |
1335 | row = d->insertRow(row); | - |
1336 | d->setWidget(row, SpanningRole, widget); | - |
1337 | invalidate(); | - |
1338 | } | - |
1339 | | - |
1340 | | - |
1341 | | - |
1342 | | - |
1343 | | - |
1344 | | - |
1345 | | - |
1346 | | - |
1347 | void QFormLayout::insertRow(int row, QLayout *layout) | - |
1348 | { | - |
1349 | Q_D(QFormLayout); | - |
1350 | if (!d->checkLayout(layout)) | - |
1351 | return; | - |
1352 | | - |
1353 | row = d->insertRow(row); | - |
1354 | d->setLayout(row, SpanningRole, layout); | - |
1355 | invalidate(); | - |
1356 | } | - |
1357 | | - |
1358 | | - |
1359 | | - |
1360 | | - |
1361 | void QFormLayout::addItem(QLayoutItem *item) | - |
1362 | { | - |
1363 | Q_D(QFormLayout); | - |
1364 | | - |
1365 | int row = d->insertRow(d->m_matrix.rowCount()); | - |
1366 | d->setItem(row, FieldRole, item); | - |
1367 | invalidate(); | - |
1368 | } | - |
1369 | | - |
1370 | | - |
1371 | | - |
1372 | | - |
1373 | int QFormLayout::count() const | - |
1374 | { | - |
1375 | Q_D(const QFormLayout); | - |
1376 | return d->m_things.count(); | - |
1377 | } | - |
1378 | | - |
1379 | | - |
1380 | | - |
1381 | | - |
1382 | QLayoutItem *QFormLayout::itemAt(int index) const | - |
1383 | { | - |
1384 | Q_D(const QFormLayout); | - |
1385 | if (QFormLayoutItem *formItem = d->m_things.value(index)) | - |
1386 | return formItem->item; | - |
1387 | return 0; | - |
1388 | } | - |
1389 | | - |
1390 | | - |
1391 | | - |
1392 | | - |
1393 | QLayoutItem *QFormLayout::takeAt(int index) | - |
1394 | { | - |
1395 | Q_D(QFormLayout); | - |
1396 | | - |
1397 | const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index)); | - |
1398 | if (Q_UNLIKELY(storageIndex == -1))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1399 | qWarning("QFormLayout::takeAt: Invalid index %d", index); | - |
1400 | return 0; never executed: return 0; | 0 |
1401 | } | - |
1402 | | - |
1403 | int row, col; | - |
1404 | QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col); | - |
1405 | Q_ASSERT(d->m_matrix(row, col)); | - |
1406 | | - |
1407 | QFormLayoutItem *item = d->m_matrix(row, col); | - |
1408 | Q_ASSERT(item); | - |
1409 | d->m_things.removeAt(index); | - |
1410 | d->m_matrix(row, col) = 0; | - |
1411 | | - |
1412 | invalidate(); | - |
1413 | | - |
1414 | | - |
1415 | QLayoutItem *i = item->item; | - |
1416 | item->item = 0; | - |
1417 | delete item; | - |
1418 | | - |
1419 | if (QLayout *l = i->layout()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1420 | | - |
1421 | if (l->parent() == this)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1422 | l->setParent(0); never executed: l->setParent(0); | 0 |
1423 | } never executed: end of block | 0 |
1424 | | - |
1425 | return i; never executed: return i; | 0 |
1426 | } | - |
1427 | | - |
1428 | | - |
1429 | | - |
1430 | | - |
1431 | Qt::Orientations QFormLayout::expandingDirections() const | - |
1432 | { | - |
1433 | Q_D(const QFormLayout); | - |
1434 | QFormLayoutPrivate *e = const_cast<QFormLayoutPrivate *>(d); | - |
1435 | e->updateSizes(); | - |
1436 | | - |
1437 | Qt::Orientations o = 0; | - |
1438 | if (e->expandHorizontal) | - |
1439 | o = Qt::Horizontal; | - |
1440 | if (e->expandVertical) | - |
1441 | o |= Qt::Vertical; | - |
1442 | return o; | - |
1443 | } | - |
1444 | | - |
1445 | | - |
1446 | | - |
1447 | | - |
1448 | bool QFormLayout::hasHeightForWidth() const | - |
1449 | { | - |
1450 | Q_D(const QFormLayout); | - |
1451 | QFormLayoutPrivate *e = const_cast<QFormLayoutPrivate *>(d); | - |
1452 | e->updateSizes(); | - |
1453 | return (d->has_hfw || rowWrapPolicy() == WrapLongRows); | - |
1454 | } | - |
1455 | | - |
1456 | | - |
1457 | | - |
1458 | | - |
1459 | int QFormLayout::heightForWidth(int width) const | - |
1460 | { | - |
1461 | Q_D(const QFormLayout); | - |
1462 | if (!hasHeightForWidth()) | - |
1463 | return -1; | - |
1464 | | - |
1465 | int leftMargin, topMargin, rightMargin, bottomMargin; | - |
1466 | getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - |
1467 | | - |
1468 | int targetWidth = width - leftMargin - rightMargin; | - |
1469 | | - |
1470 | if (!d->haveHfwCached(targetWidth)) { | - |
1471 | QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d); | - |
1472 | dat->setupVerticalLayoutData(targetWidth); | - |
1473 | dat->setupHorizontalLayoutData(targetWidth); | - |
1474 | dat->recalcHFW(targetWidth); | - |
1475 | } | - |
1476 | if (targetWidth == d->sh_width) | - |
1477 | return d->hfw_sh_height + topMargin + bottomMargin; | - |
1478 | else | - |
1479 | return d->hfw_height + topMargin + bottomMargin; | - |
1480 | } | - |
1481 | | - |
1482 | | - |
1483 | | - |
1484 | | - |
1485 | void QFormLayout::setGeometry(const QRect &rect) | - |
1486 | { | - |
1487 | Q_D(QFormLayout); | - |
1488 | if (d->dirty || rect != geometry()) { | - |
1489 | QRect cr = rect; | - |
1490 | int leftMargin, topMargin, rightMargin, bottomMargin; | - |
1491 | getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - |
1492 | cr.adjust(+leftMargin, +topMargin, -rightMargin, -bottomMargin); | - |
1493 | | - |
1494 | bool hfw = hasHeightForWidth(); | - |
1495 | d->setupVerticalLayoutData(cr.width()); | - |
1496 | d->setupHorizontalLayoutData(cr.width()); | - |
1497 | if (hfw && (!d->haveHfwCached(cr.width()) || d->hfwLayouts.size() != d->vLayoutCount)) | - |
1498 | d->recalcHFW(cr.width()); | - |
1499 | if (hfw) { | - |
1500 | qGeomCalc(d->hfwLayouts, 0, d->vLayoutCount, cr.y(), cr.height()); | - |
1501 | d->arrangeWidgets(d->hfwLayouts, cr); | - |
1502 | } else { | - |
1503 | qGeomCalc(d->vLayouts, 0, d->vLayoutCount, cr.y(), cr.height()); | - |
1504 | d->arrangeWidgets(d->vLayouts, cr); | - |
1505 | } | - |
1506 | QLayout::setGeometry(rect); | - |
1507 | } | - |
1508 | } | - |
1509 | | - |
1510 | | - |
1511 | | - |
1512 | | - |
1513 | QSize QFormLayout::sizeHint() const | - |
1514 | { | - |
1515 | Q_D(const QFormLayout); | - |
1516 | if (!d->prefSize.isValid()) { | - |
1517 | QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d); | - |
1518 | dat->calcSizeHints(); | - |
1519 | } | - |
1520 | return d->prefSize; | - |
1521 | } | - |
1522 | | - |
1523 | | - |
1524 | | - |
1525 | | - |
1526 | QSize QFormLayout::minimumSize() const | - |
1527 | { | - |
1528 | | - |
1529 | Q_D(const QFormLayout); | - |
1530 | if (!d->minSize.isValid()) { | - |
1531 | QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d); | - |
1532 | dat->calcSizeHints(); | - |
1533 | } | - |
1534 | return d->minSize; | - |
1535 | } | - |
1536 | | - |
1537 | | - |
1538 | | - |
1539 | | - |
1540 | void QFormLayout::invalidate() | - |
1541 | { | - |
1542 | Q_D(QFormLayout); | - |
1543 | d->dirty = true; | - |
1544 | d->sizesDirty = true; | - |
1545 | d->minSize = QSize(); | - |
1546 | d->prefSize = QSize(); | - |
1547 | d->formMaxWidth = -1; | - |
1548 | d->hfw_width = -1; | - |
1549 | d->sh_width = -1; | - |
1550 | d->layoutWidth = -1; | - |
1551 | d->hfw_sh_height = -1; | - |
1552 | QLayout::invalidate(); | - |
1553 | } | - |
1554 | | - |
1555 | | - |
1556 | | - |
1557 | | - |
1558 | | - |
1559 | | - |
1560 | int QFormLayout::rowCount() const | - |
1561 | { | - |
1562 | Q_D(const QFormLayout); | - |
1563 | return d->m_matrix.rowCount(); | - |
1564 | } | - |
1565 | | - |
1566 | | - |
1567 | | - |
1568 | | - |
1569 | | - |
1570 | | - |
1571 | | - |
1572 | QLayoutItem *QFormLayout::itemAt(int row, ItemRole role) const | - |
1573 | { | - |
1574 | Q_D(const QFormLayout); | - |
1575 | if (uint(row) >= uint(d->m_matrix.rowCount())) | - |
1576 | return 0; | - |
1577 | switch (role) { | - |
1578 | case SpanningRole: | - |
1579 | if (QFormLayoutItem *item = d->m_matrix(row, 1)) | - |
1580 | if (item->fullRow) | - |
1581 | return item->item; | - |
1582 | break; | - |
1583 | case LabelRole: | - |
1584 | case FieldRole: | - |
1585 | if (QFormLayoutItem *item = d->m_matrix(row, (role == LabelRole) ? 0 : 1)) | - |
1586 | return item->item; | - |
1587 | break; | - |
1588 | } | - |
1589 | return 0; | - |
1590 | } | - |
1591 | | - |
1592 | | - |
1593 | | - |
1594 | | - |
1595 | | - |
1596 | | - |
1597 | | - |
1598 | | - |
1599 | | - |
1600 | void QFormLayout::getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const | - |
1601 | { | - |
1602 | Q_D(const QFormLayout); | - |
1603 | int col = -1; | - |
1604 | int row = -1; | - |
1605 | | - |
1606 | const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index)); | - |
1607 | if (storageIndex != -1) | - |
1608 | QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col); | - |
1609 | | - |
1610 | if (rowPtr) | - |
1611 | *rowPtr = row; | - |
1612 | if (rolePtr && col != -1) { | - |
1613 | const bool spanning = col == 1 && d->m_matrix(row, col)->fullRow; | - |
1614 | if (spanning) { | - |
1615 | *rolePtr = SpanningRole; | - |
1616 | } else { | - |
1617 | *rolePtr = ItemRole(col); | - |
1618 | } | - |
1619 | } | - |
1620 | } | - |
1621 | | - |
1622 | | - |
1623 | | - |
1624 | | - |
1625 | | - |
1626 | | - |
1627 | | - |
1628 | void QFormLayout::getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const | - |
1629 | { | - |
1630 | int n = count(); | - |
1631 | int index = 0; | - |
1632 | while (index < n) { | - |
1633 | if (itemAt(index) == layout) | - |
1634 | break; | - |
1635 | ++index; | - |
1636 | } | - |
1637 | getItemPosition(index, rowPtr, rolePtr); | - |
1638 | } | - |
1639 | | - |
1640 | | - |
1641 | | - |
1642 | | - |
1643 | | - |
1644 | | - |
1645 | | - |
1646 | | - |
1647 | | - |
1648 | void QFormLayout::getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const | - |
1649 | { | - |
1650 | getItemPosition(indexOf(widget), rowPtr, rolePtr); | - |
1651 | } | - |
1652 | | - |
1653 | | - |
1654 | | - |
1655 | | - |
1656 | | - |
1657 | | - |
1658 | | - |
1659 | | - |
1660 | QWidget *QFormLayout::labelForField(QWidget *field) const | - |
1661 | { | - |
1662 | Q_D(const QFormLayout); | - |
1663 | | - |
1664 | int row; | - |
1665 | ItemRole role = LabelRole; | - |
1666 | | - |
1667 | getWidgetPosition(field, &row, &role); | - |
1668 | | - |
1669 | if (row != -1 && role == FieldRole) { | - |
1670 | if (QFormLayoutItem *label = d->m_matrix(row, LabelRole)) | - |
1671 | return label->widget(); | - |
1672 | } | - |
1673 | return 0; | - |
1674 | } | - |
1675 | | - |
1676 | | - |
1677 | | - |
1678 | | - |
1679 | QWidget *QFormLayout::labelForField(QLayout *field) const | - |
1680 | { | - |
1681 | Q_D(const QFormLayout); | - |
1682 | | - |
1683 | int row; | - |
1684 | ItemRole role; | - |
1685 | | - |
1686 | getLayoutPosition(field, &row, &role); | - |
1687 | | - |
1688 | if (row != -1 && role == FieldRole) { | - |
1689 | if (QFormLayoutItem *label = d->m_matrix(row, LabelRole)) | - |
1690 | return label->widget(); | - |
1691 | } | - |
1692 | return 0; | - |
1693 | } | - |
1694 | | - |
1695 | | - |
1696 | | - |
1697 | | - |
1698 | | - |
1699 | | - |
1700 | | - |
1701 | | - |
1702 | | - |
1703 | | - |
1704 | | - |
1705 | | - |
1706 | | - |
1707 | | - |
1708 | | - |
1709 | | - |
1710 | | - |
1711 | | - |
1712 | void QFormLayout::setFieldGrowthPolicy(FieldGrowthPolicy policy) | - |
1713 | { | - |
1714 | Q_D(QFormLayout); | - |
1715 | if (FieldGrowthPolicy(d->fieldGrowthPolicy) != policy) { | - |
1716 | d->fieldGrowthPolicy = policy; | - |
1717 | invalidate(); | - |
1718 | } | - |
1719 | } | - |
1720 | | - |
1721 | QFormLayout::FieldGrowthPolicy QFormLayout::fieldGrowthPolicy() const | - |
1722 | { | - |
1723 | Q_D(const QFormLayout); | - |
1724 | if (d->fieldGrowthPolicy == DefaultFieldGrowthPolicy) { | - |
1725 | return QFormLayout::FieldGrowthPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutFieldGrowthPolicy)); | - |
1726 | } else { | - |
1727 | return QFormLayout::FieldGrowthPolicy(d->fieldGrowthPolicy); | - |
1728 | } | - |
1729 | } | - |
1730 | | - |
1731 | | - |
1732 | | - |
1733 | | - |
1734 | | - |
1735 | | - |
1736 | | - |
1737 | | - |
1738 | | - |
1739 | | - |
1740 | | - |
1741 | | - |
1742 | | - |
1743 | | - |
1744 | | - |
1745 | void QFormLayout::setRowWrapPolicy(RowWrapPolicy policy) | - |
1746 | { | - |
1747 | Q_D(QFormLayout); | - |
1748 | if (RowWrapPolicy(d->rowWrapPolicy) != policy) { | - |
1749 | d->rowWrapPolicy = policy; | - |
1750 | invalidate(); | - |
1751 | } | - |
1752 | } | - |
1753 | | - |
1754 | QFormLayout::RowWrapPolicy QFormLayout::rowWrapPolicy() const | - |
1755 | { | - |
1756 | Q_D(const QFormLayout); | - |
1757 | if (d->rowWrapPolicy == DefaultRowWrapPolicy) { | - |
1758 | return QFormLayout::RowWrapPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutWrapPolicy)); | - |
1759 | } else { | - |
1760 | return QFormLayout::RowWrapPolicy(d->rowWrapPolicy); | - |
1761 | } | - |
1762 | } | - |
1763 | | - |
1764 | | - |
1765 | | - |
1766 | | - |
1767 | | - |
1768 | | - |
1769 | | - |
1770 | | - |
1771 | | - |
1772 | | - |
1773 | | - |
1774 | | - |
1775 | | - |
1776 | void QFormLayout::setLabelAlignment(Qt::Alignment alignment) | - |
1777 | { | - |
1778 | Q_D(QFormLayout); | - |
1779 | if (d->labelAlignment != alignment) { | - |
1780 | d->labelAlignment = alignment; | - |
1781 | invalidate(); | - |
1782 | } | - |
1783 | } | - |
1784 | | - |
1785 | Qt::Alignment QFormLayout::labelAlignment() const | - |
1786 | { | - |
1787 | Q_D(const QFormLayout); | - |
1788 | if (!d->labelAlignment) { | - |
1789 | return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutLabelAlignment)); | - |
1790 | } else { | - |
1791 | return d->labelAlignment; | - |
1792 | } | - |
1793 | } | - |
1794 | | - |
1795 | | - |
1796 | | - |
1797 | | - |
1798 | | - |
1799 | | - |
1800 | | - |
1801 | | - |
1802 | | - |
1803 | | - |
1804 | | - |
1805 | | - |
1806 | void QFormLayout::setFormAlignment(Qt::Alignment alignment) | - |
1807 | { | - |
1808 | Q_D(QFormLayout); | - |
1809 | if (d->formAlignment != alignment) { | - |
1810 | d->formAlignment = alignment; | - |
1811 | invalidate(); | - |
1812 | } | - |
1813 | } | - |
1814 | | - |
1815 | Qt::Alignment QFormLayout::formAlignment() const | - |
1816 | { | - |
1817 | Q_D(const QFormLayout); | - |
1818 | if (!d->formAlignment) { | - |
1819 | return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutFormAlignment)); | - |
1820 | } else { | - |
1821 | return d->formAlignment; | - |
1822 | } | - |
1823 | } | - |
1824 | | - |
1825 | | - |
1826 | | - |
1827 | | - |
1828 | | - |
1829 | | - |
1830 | | - |
1831 | | - |
1832 | | - |
1833 | | - |
1834 | | - |
1835 | void QFormLayout::setHorizontalSpacing(int spacing) | - |
1836 | { | - |
1837 | Q_D(QFormLayout); | - |
1838 | if (spacing != d->hSpacing) { | - |
1839 | d->hSpacing = spacing; | - |
1840 | invalidate(); | - |
1841 | } | - |
1842 | } | - |
1843 | | - |
1844 | int QFormLayout::horizontalSpacing() const | - |
1845 | { | - |
1846 | Q_D(const QFormLayout); | - |
1847 | if (d->hSpacing >= 0) { | - |
1848 | return d->hSpacing; | - |
1849 | } else { | - |
1850 | return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing); | - |
1851 | } | - |
1852 | } | - |
1853 | | - |
1854 | | - |
1855 | | - |
1856 | | - |
1857 | | - |
1858 | | - |
1859 | | - |
1860 | | - |
1861 | | - |
1862 | | - |
1863 | | - |
1864 | void QFormLayout::setVerticalSpacing(int spacing) | - |
1865 | { | - |
1866 | Q_D(QFormLayout); | - |
1867 | if (spacing != d->vSpacing) { | - |
1868 | d->vSpacing = spacing; | - |
1869 | invalidate(); | - |
1870 | } | - |
1871 | } | - |
1872 | | - |
1873 | int QFormLayout::verticalSpacing() const | - |
1874 | { | - |
1875 | Q_D(const QFormLayout); | - |
1876 | if (d->vSpacing >= 0) { | - |
1877 | return d->vSpacing; | - |
1878 | } else { | - |
1879 | return qSmartSpacing(this, QStyle::PM_LayoutVerticalSpacing); | - |
1880 | } | - |
1881 | } | - |
1882 | | - |
1883 | | - |
1884 | | - |
1885 | | - |
1886 | | - |
1887 | | - |
1888 | | - |
1889 | void QFormLayout::setSpacing(int spacing) | - |
1890 | { | - |
1891 | Q_D(QFormLayout); | - |
1892 | d->vSpacing = d->hSpacing = spacing; | - |
1893 | invalidate(); | - |
1894 | } | - |
1895 | | - |
1896 | | - |
1897 | | - |
1898 | | - |
1899 | | - |
1900 | | - |
1901 | | - |
1902 | int QFormLayout::spacing() const | - |
1903 | { | - |
1904 | int hSpacing = horizontalSpacing(); | - |
1905 | if (hSpacing == verticalSpacing()) { | - |
1906 | return hSpacing; | - |
1907 | } else { | - |
1908 | return -1; | - |
1909 | } | - |
1910 | } | - |
1911 | | - |
1912 | void QFormLayoutPrivate::arrangeWidgets(const QVector<QLayoutStruct>& layouts, QRect &rect) | - |
1913 | { | - |
1914 | Q_Q(QFormLayout); | - |
1915 | | - |
1916 | int i; | - |
1917 | const int rr = m_matrix.rowCount(); | - |
1918 | QWidget *w = q->parentWidget(); | - |
1919 | Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : QApplication::layoutDirection(); | - |
1920 | | - |
1921 | Qt::Alignment formAlignment = fixedAlignment(q->formAlignment(), layoutDirection); | - |
1922 | int leftOffset = 0; | - |
1923 | int delta = rect.width() - formMaxWidth; | - |
1924 | if (formAlignment & (Qt::AlignHCenter | Qt::AlignRight) && delta > 0) { | - |
1925 | leftOffset = delta; | - |
1926 | if (formAlignment & Qt::AlignHCenter) | - |
1927 | leftOffset >>= 1; | - |
1928 | } | - |
1929 | | - |
1930 | for (i = 0; i < rr; ++i) { | - |
1931 | QFormLayoutItem *label = m_matrix(i, 0); | - |
1932 | QFormLayoutItem *field = m_matrix(i, 1); | - |
1933 | | - |
1934 | if (label) { | - |
1935 | int height = layouts.at(label->vLayoutIndex).size; | - |
1936 | if ((label->expandingDirections() & Qt::Vertical) == 0) { | - |
1937 | | - |
1938 | | - |
1939 | | - |
1940 | | - |
1941 | | - |
1942 | | - |
1943 | height = qMin(height, | - |
1944 | qMin(label->sizeHint.height() * 7 / 4, | - |
1945 | label->maxSize.height())); | - |
1946 | } | - |
1947 | | - |
1948 | QSize sz(qMin(label->layoutWidth, label->sizeHint.width()), height); | - |
1949 | int x = leftOffset + rect.x() + label->layoutPos; | - |
1950 | if (fixedAlignment(q->labelAlignment(), layoutDirection) & Qt::AlignRight) | - |
1951 | x += label->layoutWidth - sz.width(); | - |
1952 | QPoint p(x, layouts.at(label->vLayoutIndex).pos); | - |
1953 | | - |
1954 | | - |
1955 | label->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz))); | - |
1956 | } | - |
1957 | | - |
1958 | if (field) { | - |
1959 | QSize sz(field->layoutWidth, layouts.at(field->vLayoutIndex).size); | - |
1960 | QPoint p(field->layoutPos + leftOffset + rect.x(), layouts.at(field->vLayoutIndex).pos); | - |
1961 | | - |
1962 | | - |
1963 | | - |
1964 | | - |
1965 | | - |
1966 | | - |
1967 | if (field->maxSize.isValid()) | - |
1968 | sz = sz.boundedTo(field->maxSize); | - |
1969 | | - |
1970 | field->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz))); | - |
1971 | } | - |
1972 | } | - |
1973 | } | - |
1974 | | - |
1975 | | - |
1976 | | - |
1977 | | - |
1978 | | - |
1979 | | - |
1980 | | - |
1981 | | - |
1982 | | - |
1983 | | - |
1984 | | - |
1985 | | - |
1986 | void QFormLayout::setWidget(int row, ItemRole role, QWidget *widget) | - |
1987 | { | - |
1988 | Q_D(QFormLayout); | - |
1989 | int rowCnt = rowCount(); | - |
1990 | if (row >= rowCnt) | - |
1991 | d->insertRows(rowCnt, row - rowCnt + 1); | - |
1992 | d->setWidget(row, role, widget); | - |
1993 | } | - |
1994 | | - |
1995 | | - |
1996 | | - |
1997 | | - |
1998 | | - |
1999 | | - |
2000 | | - |
2001 | | - |
2002 | | - |
2003 | | - |
2004 | | - |
2005 | | - |
2006 | void QFormLayout::setLayout(int row, ItemRole role, QLayout *layout) | - |
2007 | { | - |
2008 | Q_D(QFormLayout); | - |
2009 | int rowCnt = rowCount(); | - |
2010 | if (row >= rowCnt) | - |
2011 | d->insertRows(rowCnt, row - rowCnt + 1); | - |
2012 | d->setLayout(row, role, layout); | - |
2013 | } | - |
2014 | | - |
2015 | | - |
2016 | | - |
2017 | | - |
2018 | | - |
2019 | | - |
2020 | | - |
2021 | | - |
2022 | | - |
2023 | | - |
2024 | | - |
2025 | | - |
2026 | | - |
2027 | | - |
2028 | void QFormLayout::setItem(int row, ItemRole role, QLayoutItem *item) | - |
2029 | { | - |
2030 | Q_D(QFormLayout); | - |
2031 | int rowCnt = rowCount(); | - |
2032 | if (row >= rowCnt) | - |
2033 | d->insertRows(rowCnt, row - rowCnt + 1); | - |
2034 | d->setItem(row, role, item); | - |
2035 | } | - |
2036 | | - |
2037 | | - |
2038 | | - |
2039 | | - |
2040 | | - |
2041 | void QFormLayout::resetFieldGrowthPolicy() | - |
2042 | { | - |
2043 | Q_D(QFormLayout); | - |
2044 | d->fieldGrowthPolicy = DefaultFieldGrowthPolicy; | - |
2045 | } | - |
2046 | | - |
2047 | | - |
2048 | | - |
2049 | | - |
2050 | | - |
2051 | void QFormLayout::resetRowWrapPolicy() | - |
2052 | { | - |
2053 | Q_D(QFormLayout); | - |
2054 | d->rowWrapPolicy = DefaultRowWrapPolicy; | - |
2055 | } | - |
2056 | | - |
2057 | | - |
2058 | | - |
2059 | | - |
2060 | | - |
2061 | void QFormLayout::resetFormAlignment() | - |
2062 | { | - |
2063 | Q_D(QFormLayout); | - |
2064 | d->formAlignment = 0; | - |
2065 | } | - |
2066 | | - |
2067 | | - |
2068 | | - |
2069 | | - |
2070 | | - |
2071 | void QFormLayout::resetLabelAlignment() | - |
2072 | { | - |
2073 | Q_D(QFormLayout); | - |
2074 | d->labelAlignment = 0; | - |
2075 | } | - |
2076 | | - |
2077 | #if 0 | - |
2078 | void QFormLayout::dump() const | - |
2079 | { | - |
2080 | Q_D(const QFormLayout); | - |
2081 | for (int i = 0; i < rowCount(); ++i) { | - |
2082 | for (int j = 0; j < 2; ++j) { | - |
2083 | qDebug("m_matrix(%d, %d) = %p", i, j, d->m_matrix(i, j)); | - |
2084 | } | - |
2085 | } | - |
2086 | for (int i = 0; i < d->m_things.count(); ++i) | - |
2087 | qDebug("m_things[%d] = %p", i, d->m_things.at(i)); | - |
2088 | } | - |
2089 | #endif | - |
2090 | | - |
2091 | QT_END_NAMESPACE | - |
2092 | | - |
2093 | #include "moc_qformlayout.cpp" | - |
| | |