Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); | - |
14 | | - |
15 | | - |
16 | extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window); | - |
17 | | - |
18 | static inline QMainWindowLayout *qt_mainwindow_layout_from_dock(const QDockWidget *dock) | - |
19 | { | - |
20 | const QWidget *p = dock->parentWidget(); | - |
21 | while (p) { | - |
22 | const QMainWindow *window = qobject_cast<const QMainWindow*>(p); | - |
23 | if (window) | - |
24 | return qt_mainwindow_layout(window); | - |
25 | p = p->parentWidget(); | - |
26 | } | - |
27 | return nullptr; | - |
28 | } | - |
29 | | - |
30 | static inline bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature) | - |
31 | { return (priv->features & feature) == feature; } | - |
32 | | - |
33 | static inline bool hasFeature(const QDockWidget *dockwidget, QDockWidget::DockWidgetFeature feature) | - |
34 | { return (dockwidget->features() & feature) == feature; } | - |
35 | class QDockWidgetTitleButton : public QAbstractButton | - |
36 | { | - |
37 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - |
38 | #pragma GCC diagnostic push | - |
39 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - |
40 | #pragma GCC diagnostic pop | - |
41 | struct QPrivateSignal {}; | - |
42 | | - |
43 | public: | - |
44 | QDockWidgetTitleButton(QDockWidget *dockWidget); | - |
45 | | - |
46 | QSize sizeHint() const override; | - |
47 | QSize minimumSizeHint() const override | - |
48 | { return sizeHint(); } | - |
49 | | - |
50 | void enterEvent(QEvent *event) override; | - |
51 | void leaveEvent(QEvent *event) override; | - |
52 | void paintEvent(QPaintEvent *event) override; | - |
53 | }; | - |
54 | | - |
55 | | - |
56 | QDockWidgetTitleButton::QDockWidgetTitleButton(QDockWidget *dockWidget) | - |
57 | : QAbstractButton(dockWidget) | - |
58 | { | - |
59 | setFocusPolicy(Qt::NoFocus); | - |
60 | } | - |
61 | | - |
62 | QSize QDockWidgetTitleButton::sizeHint() const | - |
63 | { | - |
64 | ensurePolished(); | - |
65 | | - |
66 | int size = 2*style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this); | - |
67 | if (!icon().isNull()) { | - |
68 | int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); | - |
69 | QSize sz = icon().actualSize(QSize(iconSize, iconSize)); | - |
70 | size += qMax(sz.width(), sz.height()); | - |
71 | } | - |
72 | | - |
73 | return QSize(size, size); | - |
74 | } | - |
75 | | - |
76 | void QDockWidgetTitleButton::enterEvent(QEvent *event) | - |
77 | { | - |
78 | if (isEnabled()) update(); | - |
79 | QAbstractButton::enterEvent(event); | - |
80 | } | - |
81 | | - |
82 | void QDockWidgetTitleButton::leaveEvent(QEvent *event) | - |
83 | { | - |
84 | if (isEnabled()) update(); | - |
85 | QAbstractButton::leaveEvent(event); | - |
86 | } | - |
87 | | - |
88 | void QDockWidgetTitleButton::paintEvent(QPaintEvent *) | - |
89 | { | - |
90 | QPainter p(this); | - |
91 | | - |
92 | QStyleOptionToolButton opt; | - |
93 | opt.init(this); | - |
94 | opt.state |= QStyle::State_AutoRaise; | - |
95 | | - |
96 | if (style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) | - |
97 | { | - |
98 | if (isEnabled() && underMouse() && !isChecked() && !isDown()) | - |
99 | opt.state |= QStyle::State_Raised; | - |
100 | if (isChecked()) | - |
101 | opt.state |= QStyle::State_On; | - |
102 | if (isDown()) | - |
103 | opt.state |= QStyle::State_Sunken; | - |
104 | style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, &p, this); | - |
105 | } | - |
106 | | - |
107 | opt.icon = icon(); | - |
108 | opt.subControls = 0; | - |
109 | opt.activeSubControls = 0; | - |
110 | opt.features = QStyleOptionToolButton::None; | - |
111 | opt.arrowType = Qt::NoArrow; | - |
112 | int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); | - |
113 | opt.iconSize = QSize(size, size); | - |
114 | style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this); | - |
115 | } | - |
116 | | - |
117 | | - |
118 | | - |
119 | | - |
120 | | - |
121 | QDockWidgetLayout::QDockWidgetLayout(QWidget *parent) | - |
122 | : QLayout(parent), verticalTitleBar(false), item_list(RoleCount, 0) | - |
123 | { | - |
124 | } | - |
125 | | - |
126 | QDockWidgetLayout::~QDockWidgetLayout() | - |
127 | { | - |
128 | qDeleteAll(item_list); | - |
129 | } | - |
130 | | - |
131 | | - |
132 | | - |
133 | | - |
134 | | - |
135 | bool QDockWidgetLayout::nativeWindowDeco() const | - |
136 | { | - |
137 | bool floating = parentWidget()->isWindow(); | - |
138 | if (!floating && qobject_cast<QDockWidgetGroupWindow*>(parentWidget()->parentWidget())) | - |
139 | return wmSupportsNativeWindowDeco(); | - |
140 | return nativeWindowDeco(floating); | - |
141 | } | - |
142 | | - |
143 | | - |
144 | | - |
145 | | - |
146 | | - |
147 | bool QDockWidgetLayout::wmSupportsNativeWindowDeco() | - |
148 | { | - |
149 | | - |
150 | | - |
151 | | - |
152 | static const bool xcb = !QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive); | - |
153 | return !xcb; | - |
154 | | - |
155 | } | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
160 | | - |
161 | | - |
162 | bool QDockWidgetLayout::nativeWindowDeco(bool floating) const | - |
163 | { | - |
164 | return wmSupportsNativeWindowDeco() && floating && item_list.at(QDockWidgetLayout::TitleBar) == 0; | - |
165 | } | - |
166 | | - |
167 | | - |
168 | void QDockWidgetLayout::addItem(QLayoutItem*) | - |
169 | { | - |
170 | QMessageLogger(__FILE__, 248254, __PRETTY_FUNCTION__).warning("QDockWidgetLayout::addItem(): please use QDockWidgetLayout::setWidget()"); | - |
171 | return; | - |
172 | } | - |
173 | | - |
174 | QLayoutItem *QDockWidgetLayout::itemAt(int index) const | - |
175 | { | - |
176 | int cnt = 0; | - |
177 | for (int i = 0; i < item_list.count(); ++i) { | - |
178 | QLayoutItem *item = item_list.at(i); | - |
179 | if (item == 0) | - |
180 | continue; | - |
181 | if (index == cnt++) | - |
182 | return item; | - |
183 | } | - |
184 | return 0; | - |
185 | } | - |
186 | | - |
187 | QLayoutItem *QDockWidgetLayout::takeAt(int index) | - |
188 | { | - |
189 | int j = 0; | - |
190 | for (int i = 0; i < item_list.count(); ++i) { | - |
191 | QLayoutItem *item = item_list.at(i); | - |
192 | if (item == 0) | - |
193 | continue; | - |
194 | if (index == j) { | - |
195 | item_list[i] = 0; | - |
196 | invalidate(); | - |
197 | return item; | - |
198 | } | - |
199 | ++j; | - |
200 | } | - |
201 | return 0; | - |
202 | } | - |
203 | | - |
204 | int QDockWidgetLayout::count() const | - |
205 | { | - |
206 | int result = 0; | - |
207 | for (int i = 0; i < item_list.count(); ++i) { | - |
208 | if (item_list.at(i)) | - |
209 | ++result; | - |
210 | } | - |
211 | return result; | - |
212 | } | - |
213 | | - |
214 | QSize QDockWidgetLayout::sizeFromContent(const QSize &content, bool floating) const | - |
215 | { | - |
216 | QSize result = content; | - |
217 | | - |
218 | if (verticalTitleBar) { | - |
219 | result.setHeight(qMax(result.height(), minimumTitleWidth())); | - |
220 | result.setWidth(qMax(content.width(), 0)); | - |
221 | } else { | - |
222 | result.setHeight(qMax(result.height(), 0)); | - |
223 | result.setWidth(qMax(content.width(), minimumTitleWidth())); | - |
224 | } | - |
225 | | - |
226 | QDockWidget *w = qobject_cast<QDockWidget*>(parentWidget()); | - |
227 | const bool nativeDeco = nativeWindowDeco(floating); | - |
228 | | - |
229 | int fw = floating && !nativeDeco | - |
230 | ? w->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, w) | - |
231 | : 0; | - |
232 | | - |
233 | const int th = titleHeight(); | - |
234 | if (!nativeDeco) { | - |
235 | if (verticalTitleBar) | - |
236 | result += QSize(th + 2*fw, 2*fw); | - |
237 | else | - |
238 | result += QSize(2*fw, th + 2*fw); | - |
239 | } | - |
240 | | - |
241 | result.setHeight(qMin(result.height(), (int) ((1<<24)-1))); | - |
242 | result.setWidth(qMin(result.width(), (int) ((1<<24)-1))); | - |
243 | | - |
244 | if (content.width() < 0) | - |
245 | result.setWidth(-1); | - |
246 | if (content.height() < 0) | - |
247 | result.setHeight(-1); | - |
248 | | - |
249 | int left, top, right, bottom; | - |
250 | w->getContentsMargins(&left, &top, &right, &bottom); | - |
251 | | - |
252 | QSize min = w->minimumSize() - QSize(left + right, top + bottom); | - |
253 | QSize max = w->maximumSize() - QSize(left + right, top + bottom); | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | uint explicitMin = 0; | - |
262 | uint explicitMax = 0; | - |
263 | if (w->d_func()->extra != 0) { | - |
264 | explicitMin = w->d_func()->extra->explicitMinSize; | - |
265 | explicitMax = w->d_func()->extra->explicitMaxSize; | - |
266 | } | - |
267 | | - |
268 | if (!(explicitMin & Qt::Horizontal) || min.width() == 0) | - |
269 | min.setWidth(-1); | - |
270 | if (!(explicitMin & Qt::Vertical) || min.height() == 0) | - |
271 | min.setHeight(-1); | - |
272 | | - |
273 | if (!(explicitMax & Qt::Horizontal)) | - |
274 | max.setWidth(((1<<24)-1)); | - |
275 | if (!(explicitMax & Qt::Vertical)) | - |
276 | max.setHeight(((1<<24)-1)); | - |
277 | | - |
278 | return result.boundedTo(max).expandedTo(min); | - |
279 | } | - |
280 | | - |
281 | QSize QDockWidgetLayout::sizeHint() const | - |
282 | { | - |
283 | QDockWidget *w = qobject_cast<QDockWidget*>(parentWidget()); | - |
284 | | - |
285 | QSize content(-1, -1); | - |
286 | if (item_list[Content] != 0) | - |
287 | content = item_list[Content]->sizeHint(); | - |
288 | | - |
289 | return sizeFromContent(content, w->isFloating()); | - |
290 | } | - |
291 | | - |
292 | QSize QDockWidgetLayout::maximumSize() const | - |
293 | { | - |
294 | if (item_list[Content] != 0) { | - |
295 | const QSize content = item_list[Content]->maximumSize(); | - |
296 | return sizeFromContent(content, parentWidget()->isWindow()); | - |
297 | } else { | - |
298 | return parentWidget()->maximumSize(); | - |
299 | } | - |
300 | | - |
301 | } | - |
302 | | - |
303 | QSize QDockWidgetLayout::minimumSize() const | - |
304 | { | - |
305 | QDockWidget *w = qobject_cast<QDockWidget*>(parentWidget()); | - |
306 | | - |
307 | QSize content(0, 0); | - |
308 | if (item_list[Content] != 0) | - |
309 | content = item_list[Content]->minimumSize(); | - |
310 | | - |
311 | return sizeFromContent(content, w->isFloating()); | - |
312 | } | - |
313 | | - |
314 | QWidget *QDockWidgetLayout::widgetForRole(Role r) const | - |
315 | { | - |
316 | QLayoutItem *item = item_list.at(r); | - |
317 | return item == 0 ? 0 : item->widget(); | - |
318 | } | - |
319 | | - |
320 | QLayoutItem *QDockWidgetLayout::itemForRole(Role r) const | - |
321 | { | - |
322 | return item_list.at(r); | - |
323 | } | - |
324 | | - |
325 | void QDockWidgetLayout::setWidgetForRole(Role r, QWidget *w) | - |
326 | { | - |
327 | QWidget *old = widgetForRole(r); | - |
328 | if (old != 0) { | - |
329 | old->hide(); | - |
330 | removeWidget(old); | - |
331 | } | - |
332 | | - |
333 | if (w != 0) { | - |
334 | addChildWidget(w); | - |
335 | item_list[r] = new QWidgetItemV2(w); | - |
336 | w->show(); | - |
337 | } else { | - |
338 | item_list[r] = 0; | - |
339 | } | - |
340 | | - |
341 | invalidate(); | - |
342 | } | - |
343 | | - |
344 | static inline int pick(bool vertical, const QSize &size) | - |
345 | { | - |
346 | return vertical ? size.height() : size.width(); | - |
347 | } | - |
348 | | - |
349 | static inline int perp(bool vertical, const QSize &size) | - |
350 | { | - |
351 | return vertical ? size.width() : size.height(); | - |
352 | } | - |
353 | | - |
354 | int QDockWidgetLayout::minimumTitleWidth() const | - |
355 | { | - |
356 | QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); | - |
357 | | - |
358 | if (QWidget *title = widgetForRole(TitleBar)) | - |
359 | return pick(verticalTitleBar, title->minimumSizeHint()); | - |
360 | | - |
361 | QSize closeSize(0, 0); | - |
362 | QSize floatSize(0, 0); | - |
363 | if (hasFeature(q, QDockWidget::DockWidgetClosable)) { | - |
364 | if (QLayoutItem *item = item_list[CloseButton]) | - |
365 | closeSize = item->widget()->sizeHint(); | - |
366 | } | - |
367 | if (hasFeature(q, QDockWidget::DockWidgetFloatable)) { | - |
368 | if (QLayoutItem *item = item_list[FloatButton]) | - |
369 | floatSize = item->widget()->sizeHint(); | - |
370 | } | - |
371 | | - |
372 | int titleHeight = this->titleHeight(); | - |
373 | | - |
374 | int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); | - |
375 | int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q); | - |
376 | | - |
377 | return pick(verticalTitleBar, closeSize) | - |
378 | + pick(verticalTitleBar, floatSize) | - |
379 | + titleHeight + 2*fw + 3*mw; | - |
380 | } | - |
381 | | - |
382 | int QDockWidgetLayout::titleHeight() const | - |
383 | { | - |
384 | QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); | - |
385 | | - |
386 | if (QWidget *title = widgetForRole(TitleBar)) | - |
387 | return perp(verticalTitleBar, title->sizeHint()); | - |
388 | | - |
389 | QSize closeSize(0, 0); | - |
390 | QSize floatSize(0, 0); | - |
391 | if (QLayoutItem *item = item_list[CloseButton]) | - |
392 | closeSize = item->widget()->sizeHint(); | - |
393 | if (QLayoutItem *item = item_list[FloatButton]) | - |
394 | floatSize = item->widget()->sizeHint(); | - |
395 | | - |
396 | int buttonHeight = qMax(perp(verticalTitleBar, closeSize), | - |
397 | perp(verticalTitleBar, floatSize)); | - |
398 | | - |
399 | QFontMetrics titleFontMetrics = q->fontMetrics(); | - |
400 | int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); | - |
401 | | - |
402 | return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw); | - |
403 | } | - |
404 | | - |
405 | void QDockWidgetLayout::setGeometry(const QRect &geometry) | - |
406 | { | - |
407 | QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); | - |
408 | | - |
409 | bool nativeDeco = nativeWindowDeco(); | - |
410 | | - |
411 | int fw = q->isFloating() && !nativeDeco | - |
412 | ? q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q) | - |
413 | : 0; | - |
414 | | - |
415 | if (nativeDeco) { | - |
416 | if (QLayoutItem *item = item_list[Content]) | - |
417 | item->setGeometry(geometry); | - |
418 | } else { | - |
419 | int titleHeight = this->titleHeight(); | - |
420 | | - |
421 | if (verticalTitleBar) { | - |
422 | _titleArea = QRect(QPoint(fw, fw), | - |
423 | QSize(titleHeight, geometry.height() - (fw * 2))); | - |
424 | } else { | - |
425 | _titleArea = QRect(QPoint(fw, fw), | - |
426 | QSize(geometry.width() - (fw * 2), titleHeight)); | - |
427 | } | - |
428 | | - |
429 | if (QLayoutItem *item = item_list[TitleBar]) { | - |
430 | item->setGeometry(_titleArea); | - |
431 | } else { | - |
432 | QStyleOptionDockWidget opt; | - |
433 | q->initStyleOption(&opt); | - |
434 | | - |
435 | if (QLayoutItem *item = item_list[CloseButton]) { | - |
436 | if (!item->isEmpty()) { | - |
437 | QRect r = q->style() | - |
438 | ->subElementRect(QStyle::SE_DockWidgetCloseButton, | - |
439 | &opt, q); | - |
440 | if (!r.isNull()) | - |
441 | item->setGeometry(r); | - |
442 | } | - |
443 | } | - |
444 | | - |
445 | if (QLayoutItem *item = item_list[FloatButton]) { | - |
446 | if (!item->isEmpty()) { | - |
447 | QRect r = q->style() | - |
448 | ->subElementRect(QStyle::SE_DockWidgetFloatButton, | - |
449 | &opt, q); | - |
450 | if (!r.isNull()) | - |
451 | item->setGeometry(r); | - |
452 | } | - |
453 | } | - |
454 | } | - |
455 | | - |
456 | if (QLayoutItem *item = item_list[Content]) { | - |
457 | QRect r = geometry; | - |
458 | if (verticalTitleBar) { | - |
459 | r.setLeft(_titleArea.right() + 1); | - |
460 | r.adjust(0, fw, -fw, -fw); | - |
461 | } else { | - |
462 | r.setTop(_titleArea.bottom() + 1); | - |
463 | r.adjust(fw, 0, -fw, -fw); | - |
464 | } | - |
465 | item->setGeometry(r); | - |
466 | } | - |
467 | } | - |
468 | } | - |
469 | | - |
470 | void QDockWidgetLayout::setVerticalTitleBar(bool b) | - |
471 | { | - |
472 | if (b == verticalTitleBar) | - |
473 | return; | - |
474 | verticalTitleBar = b; | - |
475 | invalidate(); | - |
476 | parentWidget()->update(); | - |
477 | } | - |
478 | | - |
479 | | - |
480 | | - |
481 | | - |
482 | | - |
483 | QDockWidgetItem::QDockWidgetItem(QDockWidget *dockWidget) | - |
484 | : QWidgetItem(dockWidget) | - |
485 | { | - |
486 | } | - |
487 | | - |
488 | QSize QDockWidgetItem::minimumSize() const | - |
489 | { | - |
490 | QSize widgetMin(0, 0); | - |
491 | if (QLayoutItem *item = dockWidgetChildItem()) | - |
492 | widgetMin = item->minimumSize(); | - |
493 | return dockWidgetLayout()->sizeFromContent(widgetMin, false); | - |
494 | } | - |
495 | | - |
496 | QSize QDockWidgetItem::maximumSize() const | - |
497 | { | - |
498 | if (QLayoutItem *item = dockWidgetChildItem()) { | - |
499 | return dockWidgetLayout()->sizeFromContent(item->maximumSize(), false); | - |
500 | } else { | - |
501 | return QSize(((1<<24)-1), ((1<<24)-1)); | - |
502 | } | - |
503 | } | - |
504 | | - |
505 | | - |
506 | QSize QDockWidgetItem::sizeHint() const | - |
507 | { | - |
508 | if (QLayoutItem *item = dockWidgetChildItem()) { | - |
509 | return dockWidgetLayout()->sizeFromContent(item->sizeHint(), false); | - |
510 | } else { | - |
511 | return QWidgetItem::sizeHint(); | - |
512 | } | - |
513 | } | - |
514 | | - |
515 | | - |
516 | | - |
517 | | - |
518 | | - |
519 | void QDockWidgetPrivate::init() | - |
520 | { | - |
521 | QDockWidget * const q = q_func(); | - |
522 | | - |
523 | QDockWidgetLayout *layout = new QDockWidgetLayout(q); | - |
524 | layout->setSizeConstraint(QLayout::SetMinAndMaxSize); | - |
525 | | - |
526 | QAbstractButton *button = new QDockWidgetTitleButton(q); | - |
527 | button->setObjectName(QLatin1String("qt_dockwidget_floatbutton")); | - |
528 | QObject::connect(button, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "606""612"), q, qFlagLocation("1""_q_toggleTopLevel()" "\0" __FILE__ ":" "606""612")); | - |
529 | layout->setWidgetForRole(QDockWidgetLayout::FloatButton, button); | - |
530 | | - |
531 | button = new QDockWidgetTitleButton(q); | - |
532 | button->setObjectName(QLatin1String("qt_dockwidget_closebutton")); | - |
533 | QObject::connect(button, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "611""617"), q, qFlagLocation("1""close()" "\0" __FILE__ ":" "611""617")); | - |
534 | layout->setWidgetForRole(QDockWidgetLayout::CloseButton, button); | - |
535 | | - |
536 | | - |
537 | toggleViewAction = new QAction(q); | - |
538 | toggleViewAction->setCheckable(true); | - |
539 | toggleViewAction->setMenuRole(QAction::NoRole); | - |
540 | fixedWindowTitle = qt_setWindowTitle_helperHelper(q->windowTitle(), q); | - |
541 | toggleViewAction->setText(fixedWindowTitle); | - |
542 | QObject::connect(toggleViewAction, qFlagLocation("2""triggered(bool)" "\0" __FILE__ ":" "620""626"), | - |
543 | q, qFlagLocation("1""_q_toggleView(bool)" "\0" __FILE__ ":" "621""627")); | - |
544 | | - |
545 | | - |
546 | updateButtons(); | - |
547 | } | - |
548 | void QDockWidget::initStyleOption(QStyleOptionDockWidget *option) const | - |
549 | { | - |
550 | const QDockWidgetPrivate * const d = d_func(); | - |
551 | | - |
552 | if (!option) | - |
553 | return; | - |
554 | QDockWidgetLayout *dwlayout = qobject_cast<QDockWidgetLayout*>(layout()); | - |
555 | | - |
556 | QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent()); | - |
557 | | - |
558 | | - |
559 | option->initFrom(floatingTab && !isFloating() ? parentWidget() : this); | - |
560 | option->rect = dwlayout->titleArea(); | - |
561 | option->title = d->fixedWindowTitle; | - |
562 | option->closable = hasFeature(this, QDockWidget::DockWidgetClosable); | - |
563 | option->movable = hasFeature(this, QDockWidget::DockWidgetMovable); | - |
564 | option->floatable = hasFeature(this, QDockWidget::DockWidgetFloatable); | - |
565 | | - |
566 | QDockWidgetLayout *l = qobject_cast<QDockWidgetLayout*>(layout()); | - |
567 | option->verticalTitleBar = l->verticalTitleBar; | - |
568 | } | - |
569 | | - |
570 | void QDockWidgetPrivate::_q_toggleView(bool b) | - |
571 | { | - |
572 | QDockWidget * const q = q_func(); | - |
573 | if (b == q->isHidden()) { | - |
574 | if (b) | - |
575 | q->show(); | - |
576 | else | - |
577 | q->close(); | - |
578 | } | - |
579 | } | - |
580 | | - |
581 | void QDockWidgetPrivate::updateButtons() | - |
582 | { | - |
583 | QDockWidget * const q = q_func(); | - |
584 | QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); | - |
585 | | - |
586 | QStyleOptionDockWidget opt; | - |
587 | q->initStyleOption(&opt); | - |
588 | | - |
589 | bool customTitleBar = dwLayout->widgetForRole(QDockWidgetLayout::TitleBar) != 0; | - |
590 | bool nativeDeco = dwLayout->nativeWindowDeco(); | - |
591 | bool hideButtons = nativeDeco || customTitleBar; | - |
592 | | - |
593 | bool canClose = hasFeature(this, QDockWidget::DockWidgetClosable); | - |
594 | bool canFloat = hasFeature(this, QDockWidget::DockWidgetFloatable); | - |
595 | | - |
596 | QAbstractButton *button | - |
597 | = qobject_cast<QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::FloatButton)); | - |
598 | button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarNormalButton, &opt, q)); | - |
599 | button->setVisible(canFloat && !hideButtons); | - |
600 | | - |
601 | | - |
602 | button->setAccessibleName(QDockWidget::tr("Float")); | - |
603 | button->setAccessibleDescription(QDockWidget::tr("Undocks and re-attaches the dock widget")); | - |
604 | | - |
605 | button | - |
606 | = qobject_cast <QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::CloseButton)); | - |
607 | button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarCloseButton, &opt, q)); | - |
608 | button->setVisible(canClose && !hideButtons); | - |
609 | | - |
610 | | - |
611 | button->setAccessibleName(QDockWidget::tr("Close")); | - |
612 | button->setAccessibleDescription(QDockWidget::tr("Closes the dock widget")); | - |
613 | | - |
614 | q->setAttribute(Qt::WA_ContentsPropagated, | - |
615 | (canFloat || canClose) && !hideButtons); | - |
616 | | - |
617 | layout->invalidate(); | - |
618 | } | - |
619 | | - |
620 | void QDockWidgetPrivate::_q_toggleTopLevel() | - |
621 | { | - |
622 | QDockWidget * const q = q_func(); | - |
623 | q->setFloating(!q->isFloating()); | - |
624 | } | - |
625 | | - |
626 | | - |
627 | | - |
628 | | - |
629 | | - |
630 | | - |
631 | | - |
632 | void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca) | - |
633 | { | - |
634 | QDockWidget * const q = q_func(); | - |
635 | | - |
636 | if (state != 0) | - |
637 | return; | - |
638 | | - |
639 | QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); | - |
640 | ((!(layout != 0)) ? qt_assert("layout != 0",__FILE__,726732) : qt_noop()); | - |
641 | if (layout->pluggingWidget != 0) | - |
642 | return; | - |
643 | | - |
644 | state = new QDockWidgetPrivate::DragState; | - |
645 | state->pressPos = pos; | - |
646 | state->dragging = false; | - |
647 | state->widgetItem = 0; | - |
648 | state->ownWidgetItem = false; | - |
649 | state->nca = nca; | - |
650 | state->ctrlDrag = false; | - |
651 | } | - |
652 | | - |
653 | | - |
654 | | - |
655 | | - |
656 | | - |
657 | | - |
658 | | - |
659 | void QDockWidgetPrivate::startDrag(bool group) | - |
660 | { | - |
661 | QDockWidget * const q = q_func(); | - |
662 | | - |
663 | if (state == 0 || state->dragging) | - |
664 | return; | - |
665 | | - |
666 | QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); | - |
667 | ((!(layout != 0)) ? qt_assert("layout != 0",__FILE__,753759) : qt_noop()); | - |
668 | | - |
669 | state->widgetItem = layout->unplug(q, group); | - |
670 | if (state->widgetItem == 0) { | - |
671 | | - |
672 | | - |
673 | | - |
674 | | - |
675 | QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent); | - |
676 | if (floatingTab && !q->isFloating()) | - |
677 | state->widgetItem = new QDockWidgetGroupWindowItem(floatingTab); | - |
678 | else | - |
679 | state->widgetItem = new QDockWidgetItem(q); | - |
680 | state->ownWidgetItem = true; | - |
681 | } | - |
682 | | - |
683 | if (state->ctrlDrag) | - |
684 | layout->restore(); | - |
685 | | - |
686 | state->dragging = true; | - |
687 | } | - |
688 | | - |
689 | | - |
690 | | - |
691 | | - |
692 | | - |
693 | | - |
694 | void QDockWidgetPrivate::endDrag(bool abort) | - |
695 | { | - |
696 | QDockWidget * const q = q_func(); | - |
697 | ((!(state != 0)) ? qt_assert("state != 0",__FILE__,783789) : qt_noop()); | - |
698 | | - |
699 | q->releaseMouse(); | - |
700 | | - |
701 | if (state->draggingTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
702 | QMainWindowLayout *mwLayout = qt_mainwindow_layout_from_dock(q); | - |
703 | ((!(mwLayout != 0)) ? qt_assert("mwLayout != 0",__FILE__,789795) : qt_noop()); | - |
704 | | - |
705 | if (abortTRUE | never evaluated | FALSE | never evaluated |
|| !mwLayout->plug(state->widgetItem)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
706 | if (hasFeature(this, QDockWidget::DockWidgetFloatable)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
707 | | - |
708 | if (state->ownWidgetItemTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
709 | {delete state->widgetItem;state->widgetItem= nullptr; never executed: delete state->widgetItem; | 0 |
710 | }mwLayout->restore(); | - |
711 | QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); | - |
712 | if (!dwLayout->nativeWindowDeco()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
713 | | - |
714 | Qt::WindowFlags flags = q->windowFlags(); | - |
715 | flags &= ~Qt::X11BypassWindowManagerHint; | - |
716 | q->setWindowFlags(flags); | - |
717 | setResizerActive(q->isFloating()); | - |
718 | q->show(); | - |
719 | } never executed: end of block else { | 0 |
720 | setResizerActive(false); | - |
721 | } never executed: end of block | 0 |
722 | if (q->isFloating()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
723 | undockedGeometry = q->geometry(); never executed: undockedGeometry = q->geometry(); | 0 |
724 | q->activateWindow(); | - |
725 | } never executed: end of block else { | 0 |
726 | | - |
727 | | - |
728 | mwLayout->revert(state->widgetItem); | - |
729 | } never executed: end of block | 0 |
730 | } | - |
731 | } never executed: end of block | 0 |
732 | delete state; | - |
733 | state = 0; | - |
734 | } never executed: end of block | 0 |
735 | | - |
736 | void QDockWidgetPrivate::setResizerActive(bool active) | - |
737 | { | - |
738 | QDockWidget * const q = q_func(); | - |
739 | if (active && !resizer) { | - |
740 | resizer = new QWidgetResizeHandler(q); | - |
741 | resizer->setMovingEnabled(false); | - |
742 | } | - |
743 | if (resizer) | - |
744 | resizer->setActive(QWidgetResizeHandler::Resize, active); | - |
745 | } | - |
746 | | - |
747 | bool QDockWidgetPrivate::isAnimating() const | - |
748 | { | - |
749 | const QDockWidget * const q = q_func(); | - |
750 | | - |
751 | QMainWindowLayout *mainWinLayout = qt_mainwindow_layout_from_dock(q); | - |
752 | if (mainWinLayout == 0) | - |
753 | return false; | - |
754 | | - |
755 | return (const void*)mainWinLayout->pluggingWidget == (const void*)q; | - |
756 | } | - |
757 | | - |
758 | bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event) | - |
759 | { | - |
760 | | - |
761 | QDockWidget * const q = q_func(); | - |
762 | | - |
763 | QDockWidgetLayout *dwLayout | - |
764 | = qobject_cast<QDockWidgetLayout*>(layout); | - |
765 | | - |
766 | if (!dwLayout->nativeWindowDeco()) { | - |
767 | QRect titleArea = dwLayout->titleArea(); | - |
768 | | - |
769 | QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent); | - |
770 | | - |
771 | if (event->button() != Qt::LeftButton || | - |
772 | !titleArea.contains(event->pos()) || | - |
773 | | - |
774 | | - |
775 | (!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) || | - |
776 | (qobject_cast<QMainWindow*>(parent) == 0 && !floatingTab) || | - |
777 | isAnimating() || state != 0) { | - |
778 | return false; | - |
779 | } | - |
780 | | - |
781 | initDrag(event->pos(), false); | - |
782 | | - |
783 | if (state) | - |
784 | state->ctrlDrag = hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier; | - |
785 | | - |
786 | return true; | - |
787 | } | - |
788 | | - |
789 | | - |
790 | return false; | - |
791 | } | - |
792 | | - |
793 | bool QDockWidgetPrivate::mouseDoubleClickEvent(QMouseEvent *event) | - |
794 | { | - |
795 | QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); | - |
796 | | - |
797 | if (!dwLayout->nativeWindowDeco()) { | - |
798 | QRect titleArea = dwLayout->titleArea(); | - |
799 | | - |
800 | if (event->button() == Qt::LeftButton && titleArea.contains(event->pos()) && | - |
801 | hasFeature(this, QDockWidget::DockWidgetFloatable)) { | - |
802 | _q_toggleTopLevel(); | - |
803 | return true; | - |
804 | } | - |
805 | } | - |
806 | return false; | - |
807 | } | - |
808 | | - |
809 | bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event) | - |
810 | { | - |
811 | bool ret = false; | - |
812 | | - |
813 | QDockWidget * const q = q_func(); | - |
814 | | - |
815 | if (!state) | - |
816 | return ret; | - |
817 | | - |
818 | QDockWidgetLayout *dwlayout | - |
819 | = qobject_cast<QDockWidgetLayout *>(layout); | - |
820 | QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q); | - |
821 | if (!dwlayout->nativeWindowDeco()) { | - |
822 | if (!state->dragging | - |
823 | && mwlayout->pluggingWidget == 0 | - |
824 | && (event->pos() - state->pressPos).manhattanLength() | - |
825 | > QApplication::startDragDistance()) { | - |
826 | startDrag(); | - |
827 | | - |
828 | | - |
829 | | - |
830 | q->grabMouse(); | - |
831 | | - |
832 | ret = true; | - |
833 | } | - |
834 | } | - |
835 | | - |
836 | if (state->dragging && !state->nca) { | - |
837 | QPoint pos = event->globalPos() - state->pressPos; | - |
838 | | - |
839 | QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent); | - |
840 | if (floatingTab && !q->isFloating()) | - |
841 | floatingTab->move(pos); | - |
842 | else | - |
843 | q->move(pos); | - |
844 | | - |
845 | if (state && !state->ctrlDrag) | - |
846 | mwlayout->hover(state->widgetItem, event->globalPos()); | - |
847 | | - |
848 | ret = true; | - |
849 | } | - |
850 | | - |
851 | | - |
852 | return ret; | - |
853 | } | - |
854 | | - |
855 | bool QDockWidgetPrivate::mouseReleaseEvent(QMouseEvent *event) | - |
856 | { | - |
857 | | - |
858 | | - |
859 | if (event->button() == Qt::LeftButton && state && !state->nca) { | - |
860 | endDrag(); | - |
861 | return true; | - |
862 | } | - |
863 | | - |
864 | | - |
865 | return false; | - |
866 | } | - |
867 | | - |
868 | void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) | - |
869 | { | - |
870 | QDockWidget * const q = q_func(); | - |
871 | | - |
872 | int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q); | - |
873 | | - |
874 | QWidget *tl = q->topLevelWidget(); | - |
875 | QRect geo = tl->geometry(); | - |
876 | QRect titleRect = tl->frameGeometry(); | - |
877 | | - |
878 | | - |
879 | | - |
880 | | - |
881 | | - |
882 | | - |
883 | | - |
884 | { | - |
885 | titleRect.setLeft(geo.left()); | - |
886 | titleRect.setRight(geo.right()); | - |
887 | titleRect.setBottom(geo.top() - 1); | - |
888 | titleRect.adjust(0, fw, 0, 0); | - |
889 | } | - |
890 | | - |
891 | switch (event->type()) { | - |
892 | case QEvent::NonClientAreaMouseButtonPress: | - |
893 | if (!titleRect.contains(event->globalPos())) | - |
894 | break; | - |
895 | if (state != 0) | - |
896 | break; | - |
897 | if (qobject_cast<QMainWindow*>(parent) == 0 && qobject_cast<QDockWidgetGroupWindow*>(parent) == 0) | - |
898 | break; | - |
899 | if (isAnimating()) | - |
900 | break; | - |
901 | initDrag(event->pos(), true); | - |
902 | if (state == 0) | - |
903 | break; | - |
904 | state->ctrlDrag = event->modifiers() & Qt::ControlModifier; | - |
905 | startDrag(); | - |
906 | break; | - |
907 | case QEvent::NonClientAreaMouseMove: | - |
908 | if (state == 0 || !state->dragging) | - |
909 | break; | - |
910 | | - |
911 | | - |
912 | if (state->nca) { | - |
913 | endDrag(); | - |
914 | } | - |
915 | | - |
916 | break; | - |
917 | case QEvent::NonClientAreaMouseButtonRelease: | - |
918 | | - |
919 | | - |
920 | | - |
921 | | - |
922 | break; | - |
923 | case QEvent::NonClientAreaMouseButtonDblClick: | - |
924 | _q_toggleTopLevel(); | - |
925 | break; | - |
926 | default: | - |
927 | break; | - |
928 | } | - |
929 | } | - |
930 | | - |
931 | | - |
932 | | - |
933 | | - |
934 | void QDockWidgetPrivate::moveEvent(QMoveEvent *event) | - |
935 | { | - |
936 | QDockWidget * const q = q_func(); | - |
937 | | - |
938 | if (state == 0 || !state->dragging || !state->nca) | - |
939 | return; | - |
940 | | - |
941 | if (!q->isWindow() && qobject_cast<QDockWidgetGroupWindow*>(parent) == 0) | - |
942 | return; | - |
943 | | - |
944 | | - |
945 | | - |
946 | | - |
947 | if (state->ctrlDrag) | - |
948 | return; | - |
949 | | - |
950 | QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); | - |
951 | ((!(layout != 0)) ? qt_assert("layout != 0",__FILE__,10391043) : qt_noop()); | - |
952 | | - |
953 | QPoint globalMousePos = event->pos() + state->pressPos; | - |
954 | layout->hover(state->widgetItem, globalMousePos); | - |
955 | } | - |
956 | | - |
957 | void QDockWidgetPrivate::unplug(const QRect &rect) | - |
958 | { | - |
959 | QDockWidget * const q = q_func(); | - |
960 | QRect r = rect; | - |
961 | r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); | - |
962 | QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); | - |
963 | if (dwLayout->nativeWindowDeco(true)) | - |
964 | r.adjust(0, dwLayout->titleHeight(), 0, 0); | - |
965 | setWindowState(true, true, r); | - |
966 | } | - |
967 | | - |
968 | void QDockWidgetPrivate::plug(const QRect &rect) | - |
969 | { | - |
970 | setWindowState(false, false, rect); | - |
971 | } | - |
972 | | - |
973 | void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect &rect) | - |
974 | { | - |
975 | QDockWidget * const q = q_func(); | - |
976 | | - |
977 | if (!floating && parent) { | - |
978 | QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q); | - |
979 | if (mwlayout && mwlayout->dockWidgetArea(q) == Qt::NoDockWidgetArea | - |
980 | && !qobject_cast<QDockWidgetGroupWindow *>(parent)) | - |
981 | return; | - |
982 | } | - |
983 | | - |
984 | bool wasFloating = q->isFloating(); | - |
985 | if (wasFloating) | - |
986 | unplug = false; | - |
987 | bool hidden = q->isHidden(); | - |
988 | | - |
989 | if (q->isVisible()) | - |
990 | q->hide(); | - |
991 | | - |
992 | Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget; | - |
993 | | - |
994 | QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); | - |
995 | const bool nativeDeco = dwLayout->nativeWindowDeco(floating); | - |
996 | | - |
997 | if (nativeDeco) { | - |
998 | flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint; | - |
999 | if (hasFeature(this, QDockWidget::DockWidgetClosable)) | - |
1000 | flags |= Qt::WindowCloseButtonHint; | - |
1001 | } else { | - |
1002 | flags |= Qt::FramelessWindowHint; | - |
1003 | } | - |
1004 | | - |
1005 | if (unplug) | - |
1006 | flags |= Qt::X11BypassWindowManagerHint; | - |
1007 | | - |
1008 | q->setWindowFlags(flags); | - |
1009 | | - |
1010 | | - |
1011 | if (!rect.isNull()) | - |
1012 | q->setGeometry(rect); | - |
1013 | | - |
1014 | updateButtons(); | - |
1015 | | - |
1016 | if (!hidden) | - |
1017 | q->show(); | - |
1018 | | - |
1019 | if (floating != wasFloating) { | - |
1020 | q->topLevelChanged(floating); | - |
1021 | if (!floating && parent) { | - |
1022 | QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q); | - |
1023 | if (mwlayout) | - |
1024 | q->dockLocationChanged(mwlayout->dockWidgetArea(q)); | - |
1025 | } | - |
1026 | } | - |
1027 | | - |
1028 | setResizerActive(!unplug && floating && !nativeDeco); | - |
1029 | } | - |
1030 | QDockWidget::QDockWidget(QWidget *parent, Qt::WindowFlags flags) | - |
1031 | : QWidget(*new QDockWidgetPrivate, parent, flags) | - |
1032 | { | - |
1033 | QDockWidgetPrivate * const d = d_func(); | - |
1034 | d->init(); | - |
1035 | } | - |
1036 | QDockWidget::QDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags) | - |
1037 | : QWidget(*new QDockWidgetPrivate, parent, flags) | - |
1038 | { | - |
1039 | QDockWidgetPrivate * const d = d_func(); | - |
1040 | d->init(); | - |
1041 | setWindowTitle(title); | - |
1042 | } | - |
1043 | | - |
1044 | | - |
1045 | | - |
1046 | | - |
1047 | QDockWidget::~QDockWidget() | - |
1048 | { } | - |
1049 | | - |
1050 | | - |
1051 | | - |
1052 | | - |
1053 | | - |
1054 | | - |
1055 | | - |
1056 | QWidget *QDockWidget::widget() const | - |
1057 | { | - |
1058 | QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout()); | - |
1059 | return layout->widgetForRole(QDockWidgetLayout::Content); | - |
1060 | } | - |
1061 | void QDockWidget::setWidget(QWidget *widget) | - |
1062 | { | - |
1063 | QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout()); | - |
1064 | layout->setWidgetForRole(QDockWidgetLayout::Content, widget); | - |
1065 | } | - |
1066 | void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features) | - |
1067 | { | - |
1068 | QDockWidgetPrivate * const d = d_func(); | - |
1069 | features &= DockWidgetFeatureMask; | - |
1070 | if (d->features == features) | - |
1071 | return; | - |
1072 | const bool closableChanged = (d->features ^ features) & DockWidgetClosable; | - |
1073 | d->features = features; | - |
1074 | QDockWidgetLayout *layout | - |
1075 | = qobject_cast<QDockWidgetLayout*>(this->layout()); | - |
1076 | layout->setVerticalTitleBar(features & DockWidgetVerticalTitleBar); | - |
1077 | d->updateButtons(); | - |
1078 | d->toggleViewAction->setEnabled((d->features & DockWidgetClosable) == DockWidgetClosable); | - |
1079 | featuresChanged(d->features); | - |
1080 | update(); | - |
1081 | if (closableChanged && layout->nativeWindowDeco()) { | - |
1082 | QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow *>(parent()); | - |
1083 | if (floatingTab && !isFloating()) | - |
1084 | floatingTab->adjustFlags(); | - |
1085 | else | - |
1086 | d->setWindowState(true , true ); | - |
1087 | } | - |
1088 | } | - |
1089 | | - |
1090 | QDockWidget::DockWidgetFeatures QDockWidget::features() const | - |
1091 | { | - |
1092 | const QDockWidgetPrivate * const d = d_func(); | - |
1093 | return d->features; | - |
1094 | } | - |
1095 | void QDockWidget::setFloating(bool floating) | - |
1096 | { | - |
1097 | QDockWidgetPrivate * const d = d_func(); | - |
1098 | | - |
1099 | | - |
1100 | if (d->state != 0) | - |
1101 | d->endDrag(true); | - |
1102 | | - |
1103 | QRect r = d->undockedGeometry; | - |
1104 | | - |
1105 | if (floating && isVisible() && !r.isValid()) | - |
1106 | r = QRect(mapToGlobal(QPoint(0, 0)), size()); | - |
1107 | | - |
1108 | d->setWindowState(floating, false, floating ? r : QRect()); | - |
1109 | | - |
1110 | if (floating && r.isNull()) { | - |
1111 | if (x() < 0 || y() < 0) | - |
1112 | move(QPoint()); | - |
1113 | setAttribute(Qt::WA_Moved, false); | - |
1114 | } | - |
1115 | } | - |
1116 | void QDockWidget::setAllowedAreas(Qt::DockWidgetAreas areas) | - |
1117 | { | - |
1118 | QDockWidgetPrivate * const d = d_func(); | - |
1119 | areas &= Qt::DockWidgetArea_Mask; | - |
1120 | if (areas == d->allowedAreas) | - |
1121 | return; | - |
1122 | d->allowedAreas = areas; | - |
1123 | allowedAreasChanged(d->allowedAreas); | - |
1124 | } | - |
1125 | | - |
1126 | Qt::DockWidgetAreas QDockWidget::allowedAreas() const | - |
1127 | { | - |
1128 | const QDockWidgetPrivate * const d = d_func(); | - |
1129 | return d->allowedAreas; | - |
1130 | } | - |
1131 | void QDockWidget::changeEvent(QEvent *event) | - |
1132 | { | - |
1133 | QDockWidgetPrivate * const d = d_func(); | - |
1134 | QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout()); | - |
1135 | | - |
1136 | switch (event->type()) { | - |
1137 | case QEvent::ModifiedChange: | - |
1138 | case QEvent::WindowTitleChange: | - |
1139 | update(layout->titleArea()); | - |
1140 | | - |
1141 | d->fixedWindowTitle = qt_setWindowTitle_helperHelper(windowTitle(), this); | - |
1142 | d->toggleViewAction->setText(d->fixedWindowTitle); | - |
1143 | | - |
1144 | | - |
1145 | { | - |
1146 | if (QMainWindowLayout *winLayout = qt_mainwindow_layout_from_dock(this)) { | - |
1147 | if (QDockAreaLayoutInfo *info = winLayout->layoutState.dockAreaLayout.info(this)) | - |
1148 | info->updateTabBar(); | - |
1149 | } | - |
1150 | } | - |
1151 | | - |
1152 | break; | - |
1153 | default: | - |
1154 | break; | - |
1155 | } | - |
1156 | QWidget::changeEvent(event); | - |
1157 | } | - |
1158 | | - |
1159 | | - |
1160 | void QDockWidget::closeEvent(QCloseEvent *event) | - |
1161 | { | - |
1162 | QDockWidgetPrivate * const d = d_func(); | - |
1163 | if (d->state) | - |
1164 | d->endDrag(true); | - |
1165 | QWidget::closeEvent(event); | - |
1166 | } | - |
1167 | | - |
1168 | | - |
1169 | void QDockWidget::paintEvent(QPaintEvent *event) | - |
1170 | { | - |
1171 | (void)event; | - |
1172 | | - |
1173 | QDockWidgetLayout *layout | - |
1174 | = qobject_cast<QDockWidgetLayout*>(this->layout()); | - |
1175 | bool customTitleBar = layout->widgetForRole(QDockWidgetLayout::TitleBar) != 0; | - |
1176 | bool nativeDeco = layout->nativeWindowDeco(); | - |
1177 | | - |
1178 | if (!nativeDeco && !customTitleBar) { | - |
1179 | QStylePainter p(this); | - |
1180 | | - |
1181 | | - |
1182 | if (isFloating()) { | - |
1183 | QStyleOptionFrame framOpt; | - |
1184 | framOpt.init(this); | - |
1185 | p.drawPrimitive(QStyle::PE_FrameDockWidget, framOpt); | - |
1186 | } | - |
1187 | | - |
1188 | | - |
1189 | | - |
1190 | QStyleOptionDockWidget titleOpt; | - |
1191 | initStyleOption(&titleOpt); | - |
1192 | p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt); | - |
1193 | } | - |
1194 | } | - |
1195 | | - |
1196 | | - |
1197 | bool QDockWidget::event(QEvent *event) | - |
1198 | { | - |
1199 | QDockWidgetPrivate * const d = d_func(); | - |
1200 | | - |
1201 | QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget()); | - |
1202 | QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(this); | - |
1203 | | - |
1204 | switch (event->type()) { | - |
1205 | | - |
1206 | case QEvent::Hide: | - |
1207 | if (layout != 0) | - |
1208 | layout->keepSize(this); | - |
1209 | d->toggleViewAction->setChecked(false); | - |
1210 | visibilityChanged(false); | - |
1211 | break; | - |
1212 | case QEvent::Show: { | - |
1213 | d->toggleViewAction->setChecked(true); | - |
1214 | QPoint parentTopLeft(0, 0); | - |
1215 | if (isWindow()) { | - |
1216 | if (const QWindow *window = windowHandle()) | - |
1217 | parentTopLeft = window->screen()->availableVirtualGeometry().topLeft(); | - |
1218 | else | - |
1219 | parentTopLeft = QGuiApplication::primaryScreen()->availableVirtualGeometry().topLeft(); | - |
1220 | } | - |
1221 | visibilityChanged(geometry().right() >= parentTopLeft.x() && geometry().bottom() >= parentTopLeft.y()); | - |
1222 | } | - |
1223 | break; | - |
1224 | | - |
1225 | case QEvent::ApplicationLayoutDirectionChange: | - |
1226 | case QEvent::LayoutDirectionChange: | - |
1227 | case QEvent::StyleChange: | - |
1228 | case QEvent::ParentChange: | - |
1229 | d->updateButtons(); | - |
1230 | break; | - |
1231 | case QEvent::ZOrderChange: { | - |
1232 | bool onTop = false; | - |
1233 | if (win != 0) { | - |
1234 | const QObjectList &siblings = win->children(); | - |
1235 | onTop = siblings.count() > 0 && siblings.last() == (QObject*)this; | - |
1236 | } | - |
1237 | if (!isFloating() && layout != 0 && onTop) | - |
1238 | layout->raise(this); | - |
1239 | break; | - |
1240 | } | - |
1241 | case QEvent::WindowActivate: | - |
1242 | case QEvent::WindowDeactivate: | - |
1243 | update(qobject_cast<QDockWidgetLayout *>(this->layout())->titleArea()); | - |
1244 | break; | - |
1245 | case QEvent::ContextMenu: | - |
1246 | if (d->state) { | - |
1247 | event->accept(); | - |
1248 | return true; | - |
1249 | } | - |
1250 | break; | - |
1251 | | - |
1252 | | - |
1253 | case QEvent::MouseButtonPress: | - |
1254 | if (d->mousePressEvent(static_cast<QMouseEvent *>(event))) | - |
1255 | return true; | - |
1256 | break; | - |
1257 | case QEvent::MouseButtonDblClick: | - |
1258 | if (d->mouseDoubleClickEvent(static_cast<QMouseEvent *>(event))) | - |
1259 | return true; | - |
1260 | break; | - |
1261 | case QEvent::MouseMove: | - |
1262 | if (d->mouseMoveEvent(static_cast<QMouseEvent *>(event))) | - |
1263 | return true; | - |
1264 | break; | - |
1265 | case QEvent::MouseButtonRelease: | - |
1266 | if (d->mouseReleaseEvent(static_cast<QMouseEvent *>(event))) | - |
1267 | return true; | - |
1268 | break; | - |
1269 | case QEvent::NonClientAreaMouseMove: | - |
1270 | case QEvent::NonClientAreaMouseButtonPress: | - |
1271 | case QEvent::NonClientAreaMouseButtonRelease: | - |
1272 | case QEvent::NonClientAreaMouseButtonDblClick: | - |
1273 | d->nonClientAreaMouseEvent(static_cast<QMouseEvent*>(event)); | - |
1274 | return true; | - |
1275 | case QEvent::Move: | - |
1276 | d->moveEvent(static_cast<QMoveEvent*>(event)); | - |
1277 | break; | - |
1278 | case QEvent::Resize: | - |
1279 | | - |
1280 | if (isFloating() && layout != 0 && layout->pluggingWidget != this) | - |
1281 | d->undockedGeometry = geometry(); | - |
1282 | break; | - |
1283 | default: | - |
1284 | break; | - |
1285 | } | - |
1286 | return QWidget::event(event); | - |
1287 | } | - |
1288 | QAction * QDockWidget::toggleViewAction() const | - |
1289 | { | - |
1290 | const QDockWidgetPrivate * const d = d_func(); | - |
1291 | return d->toggleViewAction; | - |
1292 | } | - |
1293 | void QDockWidget::setTitleBarWidget(QWidget *widget) | - |
1294 | { | - |
1295 | QDockWidgetPrivate * const d = d_func(); | - |
1296 | QDockWidgetLayout *layout | - |
1297 | = qobject_cast<QDockWidgetLayout*>(this->layout()); | - |
1298 | layout->setWidgetForRole(QDockWidgetLayout::TitleBar, widget); | - |
1299 | d->updateButtons(); | - |
1300 | if (isWindow()) { | - |
1301 | | - |
1302 | d->setWindowState(true , true ); | - |
1303 | } | - |
1304 | } | - |
1305 | QWidget *QDockWidget::titleBarWidget() const | - |
1306 | { | - |
1307 | QDockWidgetLayout *layout | - |
1308 | = qobject_cast<QDockWidgetLayout*>(this->layout()); | - |
1309 | return layout->widgetForRole(QDockWidgetLayout::TitleBar); | - |
1310 | } | - |
1311 | | - |
1312 | | - |
1313 | | - |
| | |