1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | // |
30 | // W A R N I N G |
31 | // ------------- |
32 | // |
33 | // This file is not part of the Qt API. It exists for the convenience |
34 | // of Qt Designer. This header |
35 | // file may change from version to version without notice, or even be removed. |
36 | // |
37 | // We mean it. |
38 | // |
39 | |
40 | #ifndef LAYOUT_H |
41 | #define LAYOUT_H |
42 | |
43 | #include "shared_global_p.h" |
44 | #include "layoutinfo_p.h" |
45 | |
46 | #include <QtCore/qpointer.h> |
47 | #include <QtCore/qobject.h> |
48 | #include <QtCore/qmap.h> |
49 | #include <QtCore/qhash.h> |
50 | |
51 | #include <QtWidgets/qlayout.h> |
52 | #include <QtWidgets/qgridlayout.h> |
53 | #include <QtWidgets/qwidget.h> |
54 | |
55 | QT_BEGIN_NAMESPACE |
56 | |
57 | class QDesignerFormWindowInterface; |
58 | |
59 | namespace qdesigner_internal { |
60 | class QDESIGNER_SHARED_EXPORT Layout : public QObject |
61 | { |
62 | Q_OBJECT |
63 | Q_DISABLE_COPY_MOVE(Layout) |
64 | protected: |
65 | Layout(const QWidgetList &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, LayoutInfo::Type layoutType); |
66 | |
67 | public: |
68 | static Layout* createLayout(const QWidgetList &widgets, QWidget *parentWidget, |
69 | QDesignerFormWindowInterface *fw, |
70 | QWidget *layoutBase, LayoutInfo::Type layoutType); |
71 | |
72 | ~Layout() override; |
73 | |
74 | virtual void sort() = 0; |
75 | virtual void doLayout() = 0; |
76 | |
77 | virtual void setup(); |
78 | virtual void undoLayout(); |
79 | virtual void breakLayout(); |
80 | |
81 | const QWidgetList &widgets() const { return m_widgets; } |
82 | QWidget *parentWidget() const { return m_parentWidget; } |
83 | QWidget *layoutBaseWidget() const { return m_layoutBase; } |
84 | |
85 | /* Determines whether instances of QLayoutWidget are unmanaged/hidden |
86 | * after breaking a layout. Default is true. Can be turned off when |
87 | * morphing */ |
88 | bool reparentLayoutWidget() const { return m_reparentLayoutWidget; } |
89 | void setReparentLayoutWidget(bool v) { m_reparentLayoutWidget = v; } |
90 | |
91 | protected: |
92 | virtual void finishLayout(bool needMove, QLayout *layout = nullptr); |
93 | virtual bool prepareLayout(bool &needMove, bool &needReparent); |
94 | |
95 | void setWidgets(const QWidgetList &widgets) { m_widgets = widgets; } |
96 | QLayout *createLayout(int type); |
97 | void reparentToLayoutBase(QWidget *w); |
98 | |
99 | private slots: |
100 | void widgetDestroyed(); |
101 | |
102 | private: |
103 | QWidgetList m_widgets; |
104 | QWidget *m_parentWidget; |
105 | typedef QHash<QWidget *, QRect> WidgetGeometryHash; |
106 | WidgetGeometryHash m_geometries; |
107 | QWidget *m_layoutBase; |
108 | QDesignerFormWindowInterface *m_formWindow; |
109 | const LayoutInfo::Type m_layoutType; |
110 | QPoint m_startPoint; |
111 | QRect m_oldGeometry; |
112 | |
113 | bool m_reparentLayoutWidget; |
114 | const bool m_isBreak; |
115 | }; |
116 | |
117 | namespace Utils |
118 | { |
119 | |
120 | inline int indexOfWidget(QLayout *layout, QWidget *widget) |
121 | { |
122 | int index = 0; |
123 | while (QLayoutItem *item = layout->itemAt(index)) { |
124 | if (item->widget() == widget) |
125 | return index; |
126 | |
127 | ++index; |
128 | } |
129 | |
130 | return -1; |
131 | } |
132 | |
133 | } // namespace Utils |
134 | |
135 | } // namespace qdesigner_internal |
136 | |
137 | QT_END_NAMESPACE |
138 | |
139 | #endif // LAYOUT_H |
140 | |