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 DESIGNERWIDGETITEM_H
41#define DESIGNERWIDGETITEM_H
42
43#include "shared_global_p.h"
44
45#include <QtWidgets/qlayoutitem.h>
46#include <QtCore/qobject.h>
47
48QT_BEGIN_NAMESPACE
49
50class QDesignerFormEditorInterface;
51
52namespace qdesigner_internal {
53
54// QDesignerWidgetItem: A Layout Item that is used for non-containerextension-
55// containers (QFrame, etc) on Designer forms. It prevents its widget
56// from being slammed to size 0 if the widget has no layout:
57// Pre 4.5, this item ensured only that QWidgets and QFrames were not squeezed
58// to size 0 since they have an invalid size hint when non-laid out.
59// Since 4.5, the item is used for every non-containerextension-container.
60// In case the container has itself a layout, it merely tracks the minimum
61// size. If the container has no layout and is not subject to some stretch
62// factor, it will return the last valid size. The effect is that after
63// breaking a layout on a container within a layout, it just maintains its
64// last size and is not slammed to 0,0. In addition, it can be resized.
65// The class keeps track of the containing layout by tracking widget reparent
66// and destroyed slots as Designer will for example re-create grid layouts to
67// shrink them.
68
69class QDESIGNER_SHARED_EXPORT QDesignerWidgetItem : public QObject, public QWidgetItemV2 {
70 Q_DISABLE_COPY_MOVE(QDesignerWidgetItem)
71 Q_OBJECT
72public:
73 explicit QDesignerWidgetItem(const QLayout *containingLayout, QWidget *w, Qt::Orientations o = Qt::Horizontal|Qt::Vertical);
74
75 const QLayout *containingLayout() const;
76
77 inline QWidget *constWidget() const { return const_cast<QDesignerWidgetItem*>(this)->widget(); }
78
79 QSize minimumSize() const override;
80 QSize sizeHint() const override;
81
82 // Resize: Takes effect if the contained widget does not have a layout
83 QSize nonLaidOutMinSize() const;
84 void setNonLaidOutMinSize(const QSize &s);
85
86 QSize nonLaidOutSizeHint() const;
87 void setNonLaidOutSizeHint(const QSize &s);
88
89 // Check whether a QDesignerWidgetItem should be installed
90 static bool check(const QLayout *layout, QWidget *w, Qt::Orientations *ptrToOrientations = nullptr);
91
92 // Register itself using QLayoutPrivate's widget item factory method hook
93 static void install();
94 static void deinstall();
95
96 // Check for a non-container extension container
97 static bool isContainer(const QDesignerFormEditorInterface *core, QWidget *w);
98
99 static bool subjectToStretch(const QLayout *layout, QWidget *w);
100
101 bool eventFilter(QObject * watched, QEvent * event) override;
102
103private slots:
104 void layoutChanged();
105
106private:
107 void expand(QSize *s) const;
108 bool subjectToStretch() const;
109
110 const Qt::Orientations m_orientations;
111 mutable QSize m_nonLaidOutMinSize;
112 mutable QSize m_nonLaidOutSizeHint;
113 mutable const QLayout *m_cachedContainingLayout;
114};
115
116// Helper class that ensures QDesignerWidgetItem is installed while an
117// instance is in scope.
118
119class QDESIGNER_SHARED_EXPORT QDesignerWidgetItemInstaller {
120 Q_DISABLE_COPY_MOVE(QDesignerWidgetItemInstaller)
121
122public:
123 QDesignerWidgetItemInstaller();
124 ~QDesignerWidgetItemInstaller();
125
126private:
127 static int m_instanceCount;
128};
129
130} // namespace qdesigner_internal
131
132QT_END_NAMESPACE
133
134#endif
135

source code of qttools/src/designer/src/lib/shared/qdesigner_widgetitem_p.h