1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
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 Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QDYNAMICDOCKWIDGET_P_H |
43 | #define QDYNAMICDOCKWIDGET_P_H |
44 | |
45 | // |
46 | // W A R N I N G |
47 | // ------------- |
48 | // |
49 | // This file is not part of the Qt API. It exists purely as an |
50 | // implementation detail. This header file may change from version to |
51 | // version without notice, or even be removed. |
52 | // |
53 | // We mean it. |
54 | // |
55 | |
56 | #include "QtGui/qstyleoption.h" |
57 | #include "private/qwidget_p.h" |
58 | #include "QtGui/qboxlayout.h" |
59 | #include "QtGui/qdockwidget.h" |
60 | |
61 | #ifndef QT_NO_DOCKWIDGET |
62 | |
63 | QT_BEGIN_NAMESPACE |
64 | |
65 | class QGridLayout; |
66 | class QWidgetResizeHandler; |
67 | class QRubberBand; |
68 | class QDockWidgetTitleButton; |
69 | class QSpacerItem; |
70 | class QDockWidgetItem; |
71 | |
72 | class QDockWidgetPrivate : public QWidgetPrivate |
73 | { |
74 | Q_DECLARE_PUBLIC(QDockWidget) |
75 | |
76 | struct DragState { |
77 | QPoint pressPos; |
78 | bool dragging; |
79 | QLayoutItem *widgetItem; |
80 | bool ownWidgetItem; |
81 | bool nca; |
82 | bool ctrlDrag; |
83 | }; |
84 | |
85 | public: |
86 | inline QDockWidgetPrivate() |
87 | : QWidgetPrivate(), state(0), |
88 | features(QDockWidget::DockWidgetClosable |
89 | | QDockWidget::DockWidgetMovable |
90 | | QDockWidget::DockWidgetFloatable), |
91 | allowedAreas(Qt::AllDockWidgetAreas) |
92 | { } |
93 | |
94 | void init(); |
95 | void _q_toggleView(bool); // private slot |
96 | void _q_toggleTopLevel(); // private slot |
97 | |
98 | void updateButtons(); |
99 | DragState *state; |
100 | |
101 | QDockWidget::DockWidgetFeatures features; |
102 | Qt::DockWidgetAreas allowedAreas; |
103 | |
104 | QWidgetResizeHandler *resizer; |
105 | |
106 | #ifndef QT_NO_ACTION |
107 | QAction *toggleViewAction; |
108 | #endif |
109 | |
110 | // QMainWindow *findMainWindow(QWidget *widget) const; |
111 | QRect undockedGeometry; |
112 | QString fixedWindowTitle; |
113 | |
114 | bool mousePressEvent(QMouseEvent *event); |
115 | bool mouseDoubleClickEvent(QMouseEvent *event); |
116 | bool mouseMoveEvent(QMouseEvent *event); |
117 | bool mouseReleaseEvent(QMouseEvent *event); |
118 | void setWindowState(bool floating, bool unplug = false, const QRect &rect = QRect()); |
119 | void nonClientAreaMouseEvent(QMouseEvent *event); |
120 | void initDrag(const QPoint &pos, bool nca); |
121 | void startDrag(); |
122 | void endDrag(bool abort = false); |
123 | void moveEvent(QMoveEvent *event); |
124 | |
125 | void unplug(const QRect &rect); |
126 | void plug(const QRect &rect); |
127 | |
128 | bool isAnimating() const; |
129 | }; |
130 | |
131 | class Q_GUI_EXPORT QDockWidgetLayout : public QLayout |
132 | { |
133 | Q_OBJECT |
134 | public: |
135 | QDockWidgetLayout(QWidget *parent = 0); |
136 | ~QDockWidgetLayout(); |
137 | void addItem(QLayoutItem *item); |
138 | QLayoutItem *itemAt(int index) const; |
139 | QLayoutItem *takeAt(int index); |
140 | int count() const; |
141 | |
142 | QSize maximumSize() const; |
143 | QSize minimumSize() const; |
144 | QSize sizeHint() const; |
145 | |
146 | QSize sizeFromContent(const QSize &content, bool floating) const; |
147 | |
148 | void setGeometry(const QRect &r); |
149 | |
150 | enum Role { Content, CloseButton, FloatButton, TitleBar, RoleCount }; |
151 | QWidget *widgetForRole(Role r) const; |
152 | void setWidgetForRole(Role r, QWidget *w); |
153 | QLayoutItem *itemForRole(Role r) const; |
154 | |
155 | QRect titleArea() const { return _titleArea; } |
156 | |
157 | int minimumTitleWidth() const; |
158 | int titleHeight() const; |
159 | void updateMaxSize(); |
160 | bool nativeWindowDeco() const; |
161 | bool nativeWindowDeco(bool floating) const; |
162 | |
163 | void setVerticalTitleBar(bool b); |
164 | |
165 | bool verticalTitleBar; |
166 | |
167 | private: |
168 | QVector<QLayoutItem*> item_list; |
169 | QRect _titleArea; |
170 | }; |
171 | |
172 | /* The size hints of a QDockWidget will depend on whether it is docked or not. |
173 | This layout item always returns the size hints as if the dock widget was docked. */ |
174 | |
175 | class QDockWidgetItem : public QWidgetItem |
176 | { |
177 | public: |
178 | QDockWidgetItem(QDockWidget *dockWidget); |
179 | QSize minimumSize() const; |
180 | QSize maximumSize() const; |
181 | QSize sizeHint() const; |
182 | |
183 | private: |
184 | inline QLayoutItem *dockWidgetChildItem() const; |
185 | inline QDockWidgetLayout *dockWidgetLayout() const; |
186 | }; |
187 | |
188 | inline QLayoutItem *QDockWidgetItem::dockWidgetChildItem() const |
189 | { |
190 | if (QDockWidgetLayout *layout = dockWidgetLayout()) |
191 | return layout->itemForRole(QDockWidgetLayout::Content); |
192 | return 0; |
193 | } |
194 | |
195 | inline QDockWidgetLayout *QDockWidgetItem::dockWidgetLayout() const |
196 | { |
197 | QWidget *w = const_cast<QDockWidgetItem*>(this)->widget(); |
198 | if (w != 0) |
199 | return qobject_cast<QDockWidgetLayout*>(w->layout()); |
200 | return 0; |
201 | } |
202 | |
203 | QT_END_NAMESPACE |
204 | |
205 | #endif // QT_NO_DOCKWIDGET |
206 | |
207 | #endif // QDYNAMICDOCKWIDGET_P_H |
208 | |