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 | |
41 | #ifndef SPACER_WIDGET_H |
42 | #define SPACER_WIDGET_H |
43 | |
44 | #include "shared_global_p.h" |
45 | |
46 | #include <QtWidgets/qwidget.h> |
47 | #include <QtWidgets/qsizepolicy.h> |
48 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | class QDesignerFormWindowInterface; |
52 | |
53 | class QDESIGNER_SHARED_EXPORT Spacer: public QWidget |
54 | { |
55 | Q_OBJECT |
56 | |
57 | // Special hack: Make name appear as "spacer name" |
58 | Q_PROPERTY(QString spacerName READ objectName WRITE setObjectName) |
59 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) |
60 | Q_PROPERTY(QSizePolicy::Policy sizeType READ sizeType WRITE setSizeType) |
61 | Q_PROPERTY(QSize sizeHint READ sizeHintProperty WRITE setSizeHintProperty DESIGNABLE true STORED true) |
62 | |
63 | public: |
64 | Spacer(QWidget *parent = nullptr); |
65 | |
66 | QSize sizeHint() const override; |
67 | |
68 | QSize sizeHintProperty() const; |
69 | void setSizeHintProperty(const QSize &s); |
70 | |
71 | QSizePolicy::Policy sizeType() const; |
72 | void setSizeType(QSizePolicy::Policy t); |
73 | |
74 | Qt::Alignment alignment() const; |
75 | Qt::Orientation orientation() const; |
76 | |
77 | void setOrientation(Qt::Orientation o); |
78 | void setInteractiveMode(bool b) { m_interactive = b; }; |
79 | |
80 | bool event(QEvent *e) override; |
81 | |
82 | protected: |
83 | void paintEvent(QPaintEvent *e) override; |
84 | void resizeEvent(QResizeEvent* e) override; |
85 | void updateMask(); |
86 | |
87 | private: |
88 | bool isInLayout() const; |
89 | void updateToolTip(); |
90 | |
91 | const QSize m_SizeOffset = QSize(3, 3); // A small offset to ensure the spacer is still visible when reset to size 0,0 |
92 | QDesignerFormWindowInterface *m_formWindow; |
93 | Qt::Orientation m_orientation = Qt::Vertical; |
94 | bool m_interactive = true; |
95 | // Cache information about 'being in layout' which is expensive to calculate. |
96 | enum LayoutState { InLayout, OutsideLayout, UnknownLayoutState }; |
97 | mutable LayoutState m_layoutState = UnknownLayoutState; |
98 | QSize m_sizeHint = QSize(0, 0); |
99 | }; |
100 | |
101 | QT_END_NAMESPACE |
102 | |
103 | #endif // SPACER_WIDGET_H |
104 | |