1// Copyright (C) 2016 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
4#ifndef QLAYOUTENGINE_P_H
5#define QLAYOUTENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "QtWidgets/qlayoutitem.h"
20#include "QtWidgets/qstyle.h"
21#include <QtCore/qcontainerfwd.h>
22
23QT_BEGIN_NAMESPACE
24
25struct QLayoutStruct
26{
27 inline void init(int stretchFactor = 0, int minSize = 0) {
28 stretch = stretchFactor;
29 minimumSize = sizeHint = minSize;
30 maximumSize = QLAYOUTSIZE_MAX;
31 expansive = false;
32 empty = true;
33 spacing = 0;
34 }
35
36 int smartSizeHint() {
37 return (stretch > 0) ? minimumSize : sizeHint;
38 }
39 int effectiveSpacer(int uniformSpacer) const {
40 Q_ASSERT(uniformSpacer >= 0 || spacing >= 0);
41 return (uniformSpacer >= 0) ? uniformSpacer : spacing;
42 }
43
44 // parameters
45 int stretch;
46 int sizeHint;
47 int maximumSize;
48 int minimumSize;
49 int spacing;
50 bool expansive;
51 bool empty;
52
53 // temporary storage
54 bool done;
55
56 // result
57 int pos;
58 int size;
59};
60
61Q_WIDGETS_EXPORT void qGeomCalc(QList<QLayoutStruct> &chain, int start, int count, int pos,
62 int space, int spacer = -1);
63Q_WIDGETS_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint,
64 const QSize &minSize, const QSize &maxSize,
65 const QSizePolicy &sizePolicy);
66Q_WIDGETS_EXPORT QSize qSmartMinSize(const QWidgetItem *i);
67Q_WIDGETS_EXPORT QSize qSmartMinSize(const QWidget *w);
68Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QSize &sizeHint,
69 const QSize &minSize, const QSize &maxSize,
70 const QSizePolicy &sizePolicy, Qt::Alignment align = { });
71Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QWidgetItem *i, Qt::Alignment align = { });
72Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QWidget *w, Qt::Alignment align = { });
73
74Q_WIDGETS_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm);
75
76/*
77 Modify total maximum (max), total expansion (exp), and total empty
78 when adding boxmax/boxexp.
79
80 Expansive boxes win over non-expansive boxes.
81 Non-empty boxes win over empty boxes.
82*/
83static inline void qMaxExpCalc(int & max, bool &exp, bool &empty,
84 int boxmax, bool boxexp, bool boxempty)
85{
86 if (exp) {
87 if (boxexp)
88 max = qMax(a: max, b: boxmax);
89 } else {
90 if (boxexp || (empty && (!boxempty || max == 0)))
91 max = boxmax;
92 else if (empty == boxempty)
93 max = qMin(a: max, b: boxmax);
94 }
95 exp = exp || boxexp;
96 empty = empty && boxempty;
97}
98
99QT_END_NAMESPACE
100
101#endif // QLAYOUTENGINE_P_H
102

source code of qtbase/src/widgets/kernel/qlayoutengine_p.h