qdockarealayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qdockarealayout.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com>-
5** Contact: https://www.qt.io/licensing/-
6**-
7** This file is part of the QtWidgets module of the Qt Toolkit.-
8**-
9** $QT_BEGIN_LICENSE:LGPL$-
10** Commercial License Usage-
11** Licensees holding valid commercial Qt licenses may use this file in-
12** accordance with the commercial license agreement provided with the-
13** Software or, alternatively, in accordance with the terms contained in-
14** a written agreement between you and The Qt Company. For licensing terms-
15** and conditions see https://www.qt.io/terms-conditions. For further-
16** information use the contact form at https://www.qt.io/contact-us.-
17**-
18** GNU Lesser General Public License Usage-
19** Alternatively, this file may be used under the terms of the GNU Lesser-
20** General Public License version 3 as published by the Free Software-
21** Foundation and appearing in the file LICENSE.LGPL3 included in the-
22** packaging of this file. Please review the following information to-
23** ensure the GNU Lesser General Public License version 3 requirements-
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
25**-
26** GNU General Public License Usage-
27** Alternatively, this file may be used under the terms of the GNU-
28** General Public License version 2.0 or (at your option) the GNU General-
29** Public license version 3 or any later version approved by the KDE Free-
30** Qt Foundation. The licenses are as published by the Free Software-
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
32** included in the packaging of this file. Please review the following-
33** information to ensure the GNU General Public License requirements will-
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
35** https://www.gnu.org/licenses/gpl-3.0.html.-
36**-
37** $QT_END_LICENSE$-
38**-
39****************************************************************************/-
40-
41#include "QtWidgets/qapplication.h"-
42#include "QtWidgets/qwidget.h"-
43#include "QtWidgets/qtabbar.h"-
44#include "QtWidgets/qstyle.h"-
45#include "QtWidgets/qdesktopwidget.h"-
46#include "QtWidgets/qapplication.h"-
47#include "QtCore/qvariant.h"-
48#include "qdockarealayout_p.h"-
49#include "qdockwidget.h"-
50#include "qmainwindow.h"-
51#include "qwidgetanimator_p.h"-
52#include "qmainwindowlayout_p.h"-
53#include "qdockwidget_p.h"-
54#include <private/qlayoutengine_p.h>-
55-
56#include <qpainter.h>-
57#include <qstyleoption.h>-
58-
59#ifndef QT_NO_DOCKWIDGET-
60-
61QT_BEGIN_NAMESPACE-
62-
63// qmainwindow.cpp-
64extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);-
65-
66enum { StateFlagVisible = 1, StateFlagFloating = 2 };-
67-
68/******************************************************************************-
69** QPlaceHolderItem-
70*/-
71-
72QPlaceHolderItem::QPlaceHolderItem(QWidget *w)-
73{-
74 objectName = w->objectName();-
75 hidden = w->isHidden();-
76 window = w->isWindow();-
77 if (window)-
78 topLevelRect = w->geometry();-
79}-
80-
81/******************************************************************************-
82** QDockAreaLayoutItem-
83*/-
84-
85QDockAreaLayoutItem::QDockAreaLayoutItem(QLayoutItem *_widgetItem)-
86 : widgetItem(_widgetItem), subinfo(0), placeHolderItem(0), pos(0), size(-1), flags(NoFlags)-
87{-
88}-
89-
90QDockAreaLayoutItem::QDockAreaLayoutItem(QDockAreaLayoutInfo *_subinfo)-
91 : widgetItem(0), subinfo(_subinfo), placeHolderItem(0), pos(0), size(-1), flags(NoFlags)-
92{-
93}-
94-
95QDockAreaLayoutItem::QDockAreaLayoutItem(QPlaceHolderItem *_placeHolderItem)-
96 : widgetItem(0), subinfo(0), placeHolderItem(_placeHolderItem), pos(0), size(-1), flags(NoFlags)-
97{-
98}-
99-
100QDockAreaLayoutItem::QDockAreaLayoutItem(const QDockAreaLayoutItem &other)-
101 : widgetItem(other.widgetItem), subinfo(0), placeHolderItem(0), pos(other.pos),-
102 size(other.size), flags(other.flags)-
103{-
104 if (other.subinfo != 0)-
105 subinfo = new QDockAreaLayoutInfo(*other.subinfo);-
106 else if (other.placeHolderItem != 0)-
107 placeHolderItem = new QPlaceHolderItem(*other.placeHolderItem);-
108}-
109-
110QDockAreaLayoutItem::~QDockAreaLayoutItem()-
111{-
112 delete subinfo;-
113 delete placeHolderItem;-
114}-
115-
116bool QDockAreaLayoutItem::skip() const-
117{-
118 if (placeHolderItem != 0)-
119 return true;-
120-
121 if (flags & GapItem)-
122 return false;-
123-
124 if (widgetItem != 0)-
125 return widgetItem->isEmpty();-
126-
127 if (subinfo != 0) {-
128 for (int i = 0; i < subinfo->item_list.count(); ++i) {-
129 if (!subinfo->item_list.at(i).skip())-
130 return false;-
131 }-
132 }-
133-
134 return true;-
135}-
136-
137QSize QDockAreaLayoutItem::minimumSize() const-
138{-
139 if (widgetItem != 0) {-
140 int left, top, right, bottom;-
141 widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom);-
142 return widgetItem->minimumSize() + QSize(left+right, top+bottom);-
143 }-
144 if (subinfo != 0)-
145 return subinfo->minimumSize();-
146 return QSize(0, 0);-
147}-
148-
149QSize QDockAreaLayoutItem::maximumSize() const-
150{-
151 if (widgetItem != 0) {-
152 int left, top, right, bottom;-
153 widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom);-
154 return widgetItem->maximumSize()+ QSize(left+right, top+bottom);-
155 }-
156 if (subinfo != 0)-
157 return subinfo->maximumSize();-
158 return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);-
159}-
160-
161bool QDockAreaLayoutItem::hasFixedSize(Qt::Orientation o) const-
162{-
163 return perp(o, minimumSize()) == perp(o, maximumSize());-
164}-
165-
166bool QDockAreaLayoutItem::expansive(Qt::Orientation o) const-
167{-
168 if ((flags & GapItem) || placeHolderItem != 0)-
169 return false;-
170 if (widgetItem != 0)-
171 return ((widgetItem->expandingDirections() & o) == o);-
172 if (subinfo != 0)-
173 return subinfo->expansive(o);-
174 return false;-
175}-
176-
177QSize QDockAreaLayoutItem::sizeHint() const-
178{-
179 if (placeHolderItem != 0)-
180 return QSize(0, 0);-
181 if (widgetItem != 0) {-
182 int left, top, right, bottom;-
183 widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom);-
184 return widgetItem->sizeHint() + QSize(left+right, top+bottom);-
185 }-
186 if (subinfo != 0)-
187 return subinfo->sizeHint();-
188 return QSize(-1, -1);-
189}-
190-
191QDockAreaLayoutItem-
192 &QDockAreaLayoutItem::operator = (const QDockAreaLayoutItem &other)-
193{-
194 widgetItem = other.widgetItem;-
195 if (other.subinfo == 0)-
196 subinfo = 0;-
197 else-
198 subinfo = new QDockAreaLayoutInfo(*other.subinfo);-
199-
200 delete placeHolderItem;-
201 if (other.placeHolderItem == 0)-
202 placeHolderItem = 0;-
203 else-
204 placeHolderItem = new QPlaceHolderItem(*other.placeHolderItem);-
205-
206 pos = other.pos;-
207 size = other.size;-
208 flags = other.flags;-
209-
210 return *this;-
211}-
212-
213/******************************************************************************-
214** QDockAreaLayoutInfo-
215*/-
216-
217#ifndef QT_NO_TABBAR-
218static quintptr tabId(const QDockAreaLayoutItem &item)-
219{-
220 if (item.widgetItem == 0)-
221 return 0;-
222 return reinterpret_cast<quintptr>(item.widgetItem->widget());-
223}-
224#endif-
225-
226static const int zero = 0;-
227-
228QDockAreaLayoutInfo::QDockAreaLayoutInfo()-
229 : sep(&zero), dockPos(QInternal::LeftDock), o(Qt::Horizontal), mainWindow(0)-
230#ifndef QT_NO_TABBAR-
231 , tabbed(false), tabBar(0), tabBarShape(QTabBar::RoundedSouth)-
232#endif-
233{-
234}-
235-
236QDockAreaLayoutInfo::QDockAreaLayoutInfo(const int *_sep, QInternal::DockPosition _dockPos,-
237 Qt::Orientation _o, int tbshape,-
238 QMainWindow *window)-
239 : sep(_sep), dockPos(_dockPos), o(_o), mainWindow(window)-
240#ifndef QT_NO_TABBAR-
241 , tabbed(false), tabBar(0), tabBarShape(static_cast<QTabBar::Shape>(tbshape))-
242#endif-
243{-
244#ifdef QT_NO_TABBAR-
245 Q_UNUSED(tbshape);-
246#endif-
247}-
248-
249QSize QDockAreaLayoutInfo::size() const-
250{-
251 return isEmpty() ? QSize(0, 0) : rect.size();-
252}-
253-
254void QDockAreaLayoutInfo::clear()-
255{-
256 item_list.clear();-
257 rect = QRect();-
258#ifndef QT_NO_TABBAR-
259 tabbed = false;-
260 tabBar = 0;-
261#endif-
262}-
263-
264bool QDockAreaLayoutInfo::isEmpty() const-
265{-
266 return next(-1) == -1;-
267}-
268-
269QSize QDockAreaLayoutInfo::minimumSize() const-
270{-
271 if (isEmpty())-
272 return QSize(0, 0);-
273-
274 int a = 0, b = 0;-
275 bool first = true;-
276 for (int i = 0; i < item_list.size(); ++i) {-
277 const QDockAreaLayoutItem &item = item_list.at(i);-
278 if (item.skip())-
279 continue;-
280-
281 QSize min_size = item.minimumSize();-
282#ifndef QT_NO_TABBAR-
283 if (tabbed) {-
284 a = qMax(a, pick(o, min_size));-
285 } else-
286#endif-
287 {-
288 if (!first)-
289 a += *sep;-
290 a += pick(o, min_size);-
291 }-
292 b = qMax(b, perp(o, min_size));-
293-
294 first = false;-
295 }-
296-
297 QSize result;-
298 rpick(o, result) = a;-
299 rperp(o, result) = b;-
300-
301#ifndef QT_NO_TABBAR-
302 QSize tbm = tabBarMinimumSize();-
303 if (!tbm.isNull()) {-
304 switch (tabBarShape) {-
305 case QTabBar::RoundedNorth:-
306 case QTabBar::RoundedSouth:-
307 case QTabBar::TriangularNorth:-
308 case QTabBar::TriangularSouth:-
309 result.rheight() += tbm.height();-
310 result.rwidth() = qMax(tbm.width(), result.width());-
311 break;-
312 case QTabBar::RoundedEast:-
313 case QTabBar::RoundedWest:-
314 case QTabBar::TriangularEast:-
315 case QTabBar::TriangularWest:-
316 result.rheight() = qMax(tbm.height(), result.height());-
317 result.rwidth() += tbm.width();-
318 break;-
319 default:-
320 break;-
321 }-
322 }-
323#endif // QT_NO_TABBAR-
324-
325 return result;-
326}-
327-
328QSize QDockAreaLayoutInfo::maximumSize() const-
329{-
330 if (isEmpty())-
331 return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);-
332-
333 int a = 0, b = QWIDGETSIZE_MAX;-
334#ifndef QT_NO_TABBAR-
335 if (tabbed)-
336 a = QWIDGETSIZE_MAX;-
337#endif-
338-
339 int min_perp = 0;-
340-
341 bool first = true;-
342 for (int i = 0; i < item_list.size(); ++i) {-
343 const QDockAreaLayoutItem &item = item_list.at(i);-
344 if (item.skip())-
345 continue;-
346-
347 QSize max_size = item.maximumSize();-
348 min_perp = qMax(min_perp, perp(o, item.minimumSize()));-
349-
350#ifndef QT_NO_TABBAR-
351 if (tabbed) {-
352 a = qMin(a, pick(o, max_size));-
353 } else-
354#endif-
355 {-
356 if (!first)-
357 a += *sep;-
358 a += pick(o, max_size);-
359 }-
360 b = qMin(b, perp(o, max_size));-
361-
362 a = qMin(a, int(QWIDGETSIZE_MAX));-
363 b = qMin(b, int(QWIDGETSIZE_MAX));-
364-
365 first = false;-
366 }-
367-
368 b = qMax(b, min_perp);-
369-
370 QSize result;-
371 rpick(o, result) = a;-
372 rperp(o, result) = b;-
373-
374#ifndef QT_NO_TABBAR-
375 QSize tbh = tabBarSizeHint();-
376 if (!tbh.isNull()) {-
377 switch (tabBarShape) {-
378 case QTabBar::RoundedNorth:-
379 case QTabBar::RoundedSouth:-
380 result.rheight() += tbh.height();-
381 break;-
382 case QTabBar::RoundedEast:-
383 case QTabBar::RoundedWest:-
384 result.rwidth() += tbh.width();-
385 break;-
386 default:-
387 break;-
388 }-
389 }-
390#endif // QT_NO_TABBAR-
391-
392 return result;-
393}-
394-
395QSize QDockAreaLayoutInfo::sizeHint() const-
396{-
397 if (isEmpty())-
398 return QSize(0, 0);-
399-
400 int a = 0, b = 0;-
401 int min_perp = 0;-
402 int max_perp = QWIDGETSIZE_MAX;-
403 const QDockAreaLayoutItem *previous = 0;-
404 for (int i = 0; i < item_list.size(); ++i) {-
405 const QDockAreaLayoutItem &item = item_list.at(i);-
406 if (item.skip())-
407 continue;-
408-
409 bool gap = item.flags & QDockAreaLayoutItem::GapItem;-
410-
411 QSize size_hint = item.sizeHint();-
412 min_perp = qMax(min_perp, perp(o, item.minimumSize()));-
413 max_perp = qMin(max_perp, perp(o, item.maximumSize()));-
414-
415#ifndef QT_NO_TABBAR-
416 if (tabbed) {-
417 a = qMax(a, gap ? item.size : pick(o, size_hint));-
418 } else-
419#endif-
420 {-
421 if (previous && !gap && !(previous->flags & QDockAreaLayoutItem::GapItem)-
422 && !previous->hasFixedSize(o)) {-
423 a += *sep;-
424 }-
425 a += gap ? item.size : pick(o, size_hint);-
426 }-
427 b = qMax(b, perp(o, size_hint));-
428-
429 previous = &item;-
430 }-
431-
432 max_perp = qMax(max_perp, min_perp);-
433 b = qMax(b, min_perp);-
434 b = qMin(b, max_perp);-
435-
436 QSize result;-
437 rpick(o, result) = a;-
438 rperp(o, result) = b;-
439-
440#ifndef QT_NO_TABBAR-
441 if (tabbed) {-
442 QSize tbh = tabBarSizeHint();-
443 switch (tabBarShape) {-
444 case QTabBar::RoundedNorth:-
445 case QTabBar::RoundedSouth:-
446 case QTabBar::TriangularNorth:-
447 case QTabBar::TriangularSouth:-
448 result.rheight() += tbh.height();-
449 result.rwidth() = qMax(tbh.width(), result.width());-
450 break;-
451 case QTabBar::RoundedEast:-
452 case QTabBar::RoundedWest:-
453 case QTabBar::TriangularEast:-
454 case QTabBar::TriangularWest:-
455 result.rheight() = qMax(tbh.height(), result.height());-
456 result.rwidth() += tbh.width();-
457 break;-
458 default:-
459 break;-
460 }-
461 }-
462#endif // QT_NO_TABBAR-
463-
464 return result;-
465}-
466-
467bool QDockAreaLayoutInfo::expansive(Qt::Orientation o) const-
468{-
469 for (int i = 0; i < item_list.size(); ++i) {-
470 if (item_list.at(i).expansive(o))-
471 return true;-
472 }-
473 return false;-
474}-
475-
476/* QDockAreaLayoutInfo::maximumSize() doesn't return the real max size. For example,-
477 if the layout is empty, it returns QWIDGETSIZE_MAX. This is so that empty dock areas-
478 don't constrain the size of the QMainWindow, but sometimes we really need to know the-
479 maximum size. Also, these functions take into account widgets that want to keep their-
480 size (f.ex. when they are hidden and then shown, they should not change size).-
481*/-
482-
483static int realMinSize(const QDockAreaLayoutInfo &info)-
484{-
485 int result = 0;-
486 bool first = true;-
487 for (int i = 0; i < info.item_list.size(); ++i) {-
488 const QDockAreaLayoutItem &item = info.item_list.at(i);-
489 if (item.skip())-
490 continue;-
491-
492 int min = 0;-
493 if ((item.flags & QDockAreaLayoutItem::KeepSize) && item.size != -1)-
494 min = item.size;-
495 else-
496 min = pick(info.o, item.minimumSize());-
497-
498 if (!first)-
499 result += *info.sep;-
500 result += min;-
501-
502 first = false;-
503 }-
504-
505 return result;-
506}-
507-
508static int realMaxSize(const QDockAreaLayoutInfo &info)-
509{-
510 int result = 0;-
511 bool first = true;-
512 for (int i = 0; i < info.item_list.size(); ++i) {-
513 const QDockAreaLayoutItem &item = info.item_list.at(i);-
514 if (item.skip())-
515 continue;-
516-
517 int max = 0;-
518 if ((item.flags & QDockAreaLayoutItem::KeepSize) && item.size != -1)-
519 max = item.size;-
520 else-
521 max = pick(info.o, item.maximumSize());-
522-
523 if (!first)-
524 result += *info.sep;-
525 result += max;-
526-
527 if (result >= QWIDGETSIZE_MAX)-
528 return QWIDGETSIZE_MAX;-
529-
530 first = false;-
531 }-
532-
533 return result;-
534}-
535-
536void QDockAreaLayoutInfo::fitItems()-
537{-
538#ifndef QT_NO_TABBAR-
539 if (tabbed) {-
540 return;-
541 }-
542#endif-
543-
544 QVector<QLayoutStruct> layout_struct_list(item_list.size()*2);-
545 int j = 0;-
546-
547 int size = pick(o, rect.size());-
548 int min_size = realMinSize(*this);-
549 int max_size = realMaxSize(*this);-
550 int last_index = -1;-
551-
552 const QDockAreaLayoutItem *previous = 0;-
553 for (int i = 0; i < item_list.size(); ++i) {-
554 QDockAreaLayoutItem &item = item_list[i];-
555 if (item.skip())-
556 continue;-
557-
558 bool gap = item.flags & QDockAreaLayoutItem::GapItem;-
559 if (previous && !gap) {-
560 if (!(previous->flags & QDockAreaLayoutItem::GapItem)) {-
561 QLayoutStruct &ls = layout_struct_list[j++];-
562 ls.init();-
563 ls.minimumSize = ls.maximumSize = ls.sizeHint = previous->hasFixedSize(o) ? 0 : *sep;-
564 ls.empty = false;-
565 }-
566 }-
567-
568 if (item.flags & QDockAreaLayoutItem::KeepSize) {-
569 // Check if the item can keep its size, without violating size constraints-
570 // of other items.-
571-
572 if (size < min_size) {-
573 // There is too little space to keep this widget's size-
574 item.flags &= ~QDockAreaLayoutItem::KeepSize;-
575 min_size -= item.size;-
576 min_size += pick(o, item.minimumSize());-
577 min_size = qMax(0, min_size);-
578 } else if (size > max_size) {-
579 // There is too much space to keep this widget's size-
580 item.flags &= ~QDockAreaLayoutItem::KeepSize;-
581 max_size -= item.size;-
582 max_size += pick(o, item.maximumSize());-
583 max_size = qMin<int>(QWIDGETSIZE_MAX, max_size);-
584 }-
585 }-
586-
587 last_index = j;-
588 QLayoutStruct &ls = layout_struct_list[j++];-
589 ls.init();-
590 ls.empty = false;-
591 if (item.flags & QDockAreaLayoutItem::KeepSize) {-
592 ls.minimumSize = ls.maximumSize = ls.sizeHint = item.size;-
593 ls.expansive = false;-
594 ls.stretch = 0;-
595 } else {-
596 ls.maximumSize = pick(o, item.maximumSize());-
597 ls.expansive = item.expansive(o);-
598 ls.minimumSize = pick(o, item.minimumSize());-
599 ls.sizeHint = item.size == -1 ? pick(o, item.sizeHint()) : item.size;-
600 ls.stretch = ls.expansive ? ls.sizeHint : 0;-
601 }-
602-
603 item.flags &= ~QDockAreaLayoutItem::KeepSize;-
604 previous = &item;-
605 }-
606 layout_struct_list.resize(j);-
607-
608 // If there is more space than the widgets can take (due to maximum size constraints),-
609 // we detect it here and stretch the last widget to take up the rest of the space.-
610 if (size > max_size && last_index != -1) {-
611 layout_struct_list[last_index].maximumSize = QWIDGETSIZE_MAX;-
612 layout_struct_list[last_index].expansive = true;-
613 }-
614-
615 qGeomCalc(layout_struct_list, 0, j, pick(o, rect.topLeft()), size, 0);-
616-
617 j = 0;-
618 bool prev_gap = false;-
619 bool first = true;-
620 for (int i = 0; i < item_list.size(); ++i) {-
621 QDockAreaLayoutItem &item = item_list[i];-
622 if (item.skip())-
623 continue;-
624-
625 bool gap = item.flags & QDockAreaLayoutItem::GapItem;-
626 if (!first && !gap && !prev_gap)-
627 ++j;-
628-
629 const QLayoutStruct &ls = layout_struct_list.at(j++);-
630 item.size = ls.size;-
631 item.pos = ls.pos;-
632-
633 if (item.subinfo != 0) {-
634 item.subinfo->rect = itemRect(i);-
635 item.subinfo->fitItems();-
636 }-
637-
638 prev_gap = gap;-
639 first = false;-
640 }-
641}-
642-
643static QInternal::DockPosition dockPosHelper(const QRect &rect, const QPoint &_pos,-
644 Qt::Orientation o,-
645 bool nestingEnabled,-
646 QDockAreaLayoutInfo::TabMode tabMode)-
647{-
648 if (tabMode == QDockAreaLayoutInfo::ForceTabs)-
649 return QInternal::DockCount;-
650-
651 QPoint pos = _pos - rect.topLeft();-
652-
653 int x = pos.x();-
654 int y = pos.y();-
655 int w = rect.width();-
656 int h = rect.height();-
657-
658 if (tabMode != QDockAreaLayoutInfo::NoTabs) {-
659 // is it in the center?-
660 if (nestingEnabled) {-
661 /* 2/3-
662 +--------------+-
663 | |-
664 | CCCCCCCC |-
665 2/3 | CCCCCCCC |-
666 | CCCCCCCC |-
667 | |-
668 +--------------+ */-
669-
670 QRect center(w/6, h/6, 2*w/3, 2*h/3);-
671 if (center.contains(pos))-
672 return QInternal::DockCount;-
673 } else if (o == Qt::Horizontal) {-
674 /* 2/3-
675 +--------------+-
676 | CCCCCCCC |-
677 | CCCCCCCC |-
678 | CCCCCCCC |-
679 | CCCCCCCC |-
680 | CCCCCCCC |-
681 +--------------+ */-
682-
683 if (x > w/6 && x < w*5/6)-
684 return QInternal::DockCount;-
685 } else {-
686 /*-
687 +--------------+-
688 | |-
689 2/3 |CCCCCCCCCCCCCC|-
690 |CCCCCCCCCCCCCC|-
691 | |-
692 +--------------+ */-
693 if (y > h/6 && y < 5*h/6)-
694 return QInternal::DockCount;-
695 }-
696 }-
697-
698 // not in the center. which edge?-
699 if (nestingEnabled) {-
700 if (o == Qt::Horizontal) {-
701 /* 1/3 1/3 1/3-
702 +------------+ (we've already ruled out the center)-
703 |LLLLTTTTRRRR|-
704 |LLLLTTTTRRRR|-
705 |LLLLBBBBRRRR|-
706 |LLLLBBBBRRRR|-
707 +------------+ */-
708-
709 if (x < w/3)-
710 return QInternal::LeftDock;-
711 if (x > 2*w/3)-
712 return QInternal::RightDock;-
713 if (y < h/2)-
714 return QInternal::TopDock;-
715 return QInternal::BottomDock;-
716 } else {-
717 /* +------------+ (we've already ruled out the center)-
718 1/3 |TTTTTTTTTTTT|-
719 |LLLLLLRRRRRR|-
720 1/3 |LLLLLLRRRRRR|-
721 1/3 |BBBBBBBBBBBB|-
722 +------------+ */-
723-
724 if (y < h/3)-
725 return QInternal::TopDock;-
726 if (y > 2*h/3)-
727 return QInternal::BottomDock;-
728 if (x < w/2)-
729 return QInternal::LeftDock;-
730 return QInternal::RightDock;-
731 }-
732 } else {-
733 if (o == Qt::Horizontal) {-
734 return x < w/2-
735 ? QInternal::LeftDock-
736 : QInternal::RightDock;-
737 } else {-
738 return y < h/2-
739 ? QInternal::TopDock-
740 : QInternal::BottomDock;-
741 }-
742 }-
743}-
744-
745QList<int> QDockAreaLayoutInfo::gapIndex(const QPoint& _pos,-
746 bool nestingEnabled, TabMode tabMode) const-
747{-
748 QList<int> result;-
749 QRect item_rect;-
750 int item_index = 0;-
751-
752#ifndef QT_NO_TABBAR-
753 if (tabbed) {-
754 item_rect = tabContentRect();-
755 } else-
756#endif-
757 {-
758 int pos = pick(o, _pos);-
759-
760 int last = -1;-
761 for (int i = 0; i < item_list.size(); ++i) {-
762 const QDockAreaLayoutItem &item = item_list.at(i);-
763 if (item.skip())-
764 continue;-
765-
766 last = i;-
767-
768 if (item.pos + item.size < pos)-
769 continue;-
770-
771 if (item.subinfo != 0-
772#ifndef QT_NO_TABBAR-
773 && !item.subinfo->tabbed-
774#endif-
775 ) {-
776 result = item.subinfo->gapIndex(_pos, nestingEnabled,-
777 tabMode);-
778 result.prepend(i);-
779 return result;-
780 }-
781-
782 item_rect = itemRect(i);-
783 item_index = i;-
784 break;-
785 }-
786-
787 if (item_rect.isNull()) {-
788 result.append(last + 1);-
789 return result;-
790 }-
791 }-
792-
793 Q_ASSERT(!item_rect.isNull());-
794-
795 QInternal::DockPosition dock_pos-
796 = dockPosHelper(item_rect, _pos, o, nestingEnabled, tabMode);-
797-
798 switch (dock_pos) {-
799 case QInternal::LeftDock:-
800 if (o == Qt::Horizontal)-
801 result << item_index;-
802 else-
803 result << item_index << 0; // this subinfo doesn't exist yet, but insertGap()-
804 // handles this by inserting it-
805 break;-
806 case QInternal::RightDock:-
807 if (o == Qt::Horizontal)-
808 result << item_index + 1;-
809 else-
810 result << item_index << 1;-
811 break;-
812 case QInternal::TopDock:-
813 if (o == Qt::Horizontal)-
814 result << item_index << 0;-
815 else-
816 result << item_index;-
817 break;-
818 case QInternal::BottomDock:-
819 if (o == Qt::Horizontal)-
820 result << item_index << 1;-
821 else-
822 result << item_index + 1;-
823 break;-
824 case QInternal::DockCount:-
825 result << (-item_index - 1) << 0; // negative item_index means "on top of"-
826 // -item_index - 1, insertGap()-
827 // will insert a tabbed subinfo-
828 break;-
829 default:-
830 break;-
831 }-
832-
833 return result;-
834}-
835-
836static inline int shrink(QLayoutStruct &ls, int delta)-
837{-
838 if (ls.empty)-
839 return 0;-
840 int old_size = ls.size;-
841 ls.size = qMax(ls.size - delta, ls.minimumSize);-
842 return old_size - ls.size;-
843}-
844-
845static inline int grow(QLayoutStruct &ls, int delta)-
846{-
847 if (ls.empty)-
848 return 0;-
849 int old_size = ls.size;-
850 ls.size = qMin(ls.size + delta, ls.maximumSize);-
851 return ls.size - old_size;-
852}-
853-
854static int separatorMoveHelper(QVector<QLayoutStruct> &list, int index, int delta, int sep)-
855{-
856 // adjust sizes-
857 int pos = -1;-
858 for (int i = 0; i < list.size(); ++i) {-
859 const QLayoutStruct &ls = list.at(i);-
860 if (!ls.empty) {-
861 pos = ls.pos;-
862 break;-
863 }-
864 }-
865 if (pos == -1)-
866 return 0;-
867-
868 if (delta > 0) {-
869 int growlimit = 0;-
870 for (int i = 0; i<=index; ++i) {-
871 const QLayoutStruct &ls = list.at(i);-
872 if (ls.empty)-
873 continue;-
874 if (ls.maximumSize == QLAYOUTSIZE_MAX) {-
875 growlimit = QLAYOUTSIZE_MAX;-
876 break;-
877 }-
878 growlimit += ls.maximumSize - ls.size;-
879 }-
880 if (delta > growlimit)-
881 delta = growlimit;-
882-
883 int d = 0;-
884 for (int i = index + 1; d < delta && i < list.count(); ++i)-
885 d += shrink(list[i], delta - d);-
886 delta = d;-
887 d = 0;-
888 for (int i = index; d < delta && i >= 0; --i)-
889 d += grow(list[i], delta - d);-
890 } else if (delta < 0) {-
891 int growlimit = 0;-
892 for (int i = index + 1; i < list.count(); ++i) {-
893 const QLayoutStruct &ls = list.at(i);-
894 if (ls.empty)-
895 continue;-
896 if (ls.maximumSize == QLAYOUTSIZE_MAX) {-
897 growlimit = QLAYOUTSIZE_MAX;-
898 break;-
899 }-
900 growlimit += ls.maximumSize - ls.size;-
901 }-
902 if (-delta > growlimit)-
903 delta = -growlimit;-
904-
905 int d = 0;-
906 for (int i = index; d < -delta && i >= 0; --i)-
907 d += shrink(list[i], -delta - d);-
908 delta = -d;-
909 d = 0;-
910 for (int i = index + 1; d < -delta && i < list.count(); ++i)-
911 d += grow(list[i], -delta - d);-
912 }-
913-
914 // adjust positions-
915 bool first = true;-
916 for (int i = 0; i < list.size(); ++i) {-
917 QLayoutStruct &ls = list[i];-
918 if (ls.empty) {-
919 ls.pos = pos + (first ? 0 : sep);-
920 continue;-
921 }-
922 if (!first)-
923 pos += sep;-
924 ls.pos = pos;-
925 pos += ls.size;-
926 first = false;-
927 }-
928-
929 return delta;-
930}-
931-
932int QDockAreaLayoutInfo::separatorMove(int index, int delta)-
933{-
934#ifndef QT_NO_TABBAR-
935 Q_ASSERT(!tabbed);-
936#endif-
937-
938 QVector<QLayoutStruct> list(item_list.size());-
939 for (int i = 0; i < list.size(); ++i) {-
940 const QDockAreaLayoutItem &item = item_list.at(i);-
941 QLayoutStruct &ls = list[i];-
942 Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem));-
943 if (item.skip()) {-
944 ls.empty = true;-
945 } else {-
946 const int separatorSpace = item.hasFixedSize(o) ? 0 : *sep;-
947 ls.empty = false;-
948 ls.pos = item.pos;-
949 ls.size = item.size + separatorSpace;-
950 ls.minimumSize = pick(o, item.minimumSize()) + separatorSpace;-
951 ls.maximumSize = pick(o, item.maximumSize()) + separatorSpace;-
952-
953 }-
954 }-
955-
956 //the separator space has been added to the size, so we pass 0 as a parameter-
957 delta = separatorMoveHelper(list, index, delta, 0 /*separator*/);-
958-
959 for (int i = 0; i < list.size(); ++i) {-
960 QDockAreaLayoutItem &item = item_list[i];-
961 if (item.skip())-
962 continue;-
963 QLayoutStruct &ls = list[i];-
964 const int separatorSpace = item.hasFixedSize(o) ? 0 : *sep;-
965 item.size = ls.size - separatorSpace;-
966 item.pos = ls.pos;-
967 if (item.subinfo != 0) {-
968 item.subinfo->rect = itemRect(i);-
969 item.subinfo->fitItems();-
970 }-
971 }-
972-
973 return delta;-
974}-
975-
976void QDockAreaLayoutInfo::unnest(int index)-
977{-
978 QDockAreaLayoutItem &item = item_list[index];-
979 if (item.subinfo == 0)-
980 return;-
981 if (item.subinfo->item_list.count() > 1)-
982 return;-
983-
984 if (item.subinfo->item_list.count() == 0) {-
985 item_list.removeAt(index);-
986 } else if (item.subinfo->item_list.count() == 1) {-
987 QDockAreaLayoutItem &child = item.subinfo->item_list.first();-
988 if (child.widgetItem != 0) {-
989 item.widgetItem = child.widgetItem;-
990 delete item.subinfo;-
991 item.subinfo = 0;-
992 } else if (child.subinfo != 0) {-
993 QDockAreaLayoutInfo *tmp = item.subinfo;-
994 item.subinfo = child.subinfo;-
995 child.subinfo = 0;-
996 tmp->item_list.clear();-
997 delete tmp;-
998 }-
999 }-
1000}-
1001-
1002void QDockAreaLayoutInfo::remove(const QList<int> &path)-
1003{-
1004 Q_ASSERT(!path.isEmpty());-
1005-
1006 if (path.count() > 1) {-
1007 const int index = path.first();-
1008 QDockAreaLayoutItem &item = item_list[index];-
1009 Q_ASSERT(item.subinfo != 0);-
1010 item.subinfo->remove(path.mid(1));-
1011 unnest(index);-
1012 } else {-
1013 int index = path.first();-
1014 item_list.removeAt(index);-
1015 }-
1016}-
1017-
1018QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path)-
1019{-
1020 Q_ASSERT(!path.isEmpty());-
1021-
1022 int index = path.first();-
1023 if (index < 0)-
1024 index = -index - 1;-
1025-
1026 if (path.count() > 1) {-
1027 QDockAreaLayoutItem &item = item_list[index];-
1028 Q_ASSERT(item.subinfo != 0);-
1029 return item.subinfo->plug(path.mid(1));-
1030 }-
1031-
1032 QDockAreaLayoutItem &item = item_list[index];-
1033-
1034 Q_ASSERT(item.widgetItem != 0);-
1035 Q_ASSERT(item.flags & QDockAreaLayoutItem::GapItem);-
1036 item.flags &= ~QDockAreaLayoutItem::GapItem;-
1037-
1038 QRect result;-
1039-
1040#ifndef QT_NO_TABBAR-
1041 if (tabbed) {-
1042 } else-
1043#endif-
1044 {-
1045 int prev = this->prev(index);-
1046 int next = this->next(index);-
1047-
1048 if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) {-
1049 item.pos += *sep;-
1050 item.size -= *sep;-
1051 }-
1052 if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem))-
1053 item.size -= *sep;-
1054-
1055 QPoint pos;-
1056 rpick(o, pos) = item.pos;-
1057 rperp(o, pos) = perp(o, rect.topLeft());-
1058 QSize s;-
1059 rpick(o, s) = item.size;-
1060 rperp(o, s) = perp(o, rect.size());-
1061 result = QRect(pos, s);-
1062 }-
1063-
1064 return item.widgetItem;-
1065}-
1066-
1067QLayoutItem *QDockAreaLayoutInfo::unplug(const QList<int> &path)-
1068{-
1069 Q_ASSERT(!path.isEmpty());-
1070-
1071 const int index = path.first();-
1072 if (path.count() > 1) {-
1073 QDockAreaLayoutItem &item = item_list[index];-
1074 Q_ASSERT(item.subinfo != 0);-
1075 return item.subinfo->unplug(path.mid(1));-
1076 }-
1077-
1078 QDockAreaLayoutItem &item = item_list[index];-
1079 int prev = this->prev(index);-
1080 int next = this->next(index);-
1081-
1082 Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem));-
1083 item.flags |= QDockAreaLayoutItem::GapItem;-
1084-
1085#ifndef QT_NO_TABBAR-
1086 if (tabbed) {-
1087 } else-
1088#endif-
1089 {-
1090 if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) {-
1091 item.pos -= *sep;-
1092 item.size += *sep;-
1093 }-
1094 if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem))-
1095 item.size += *sep;-
1096 }-
1097-
1098 return item.widgetItem;-
1099}-
1100-
1101#ifndef QT_NO_TABBAR-
1102-
1103quintptr QDockAreaLayoutInfo::currentTabId() const-
1104{-
1105 if (!tabbed || tabBar == 0)-
1106 return 0;-
1107-
1108 int index = tabBar->currentIndex();-
1109 if (index == -1)-
1110 return 0;-
1111-
1112 return qvariant_cast<quintptr>(tabBar->tabData(index));-
1113}-
1114-
1115void QDockAreaLayoutInfo::setCurrentTab(QWidget *widget)-
1116{-
1117 setCurrentTabId(reinterpret_cast<quintptr>(widget));-
1118}-
1119-
1120void QDockAreaLayoutInfo::setCurrentTabId(quintptr id)-
1121{-
1122 if (!tabbed || tabBar == 0)-
1123 return;-
1124-
1125 for (int i = 0; i < tabBar->count(); ++i) {-
1126 if (qvariant_cast<quintptr>(tabBar->tabData(i)) == id) {-
1127 tabBar->setCurrentIndex(i);-
1128 return;-
1129 }-
1130 }-
1131}-
1132-
1133#endif // QT_NO_TABBAR-
1134-
1135static QRect dockedGeometry(QWidget *widget)-
1136{-
1137 int titleHeight = 0;-
1138-
1139 QDockWidgetLayout *layout-
1140 = qobject_cast<QDockWidgetLayout*>(widget->layout());-
1141 if(layout != 0 && layout->nativeWindowDeco())-
1142 titleHeight = layout->titleHeight();-
1143-
1144 QRect result = widget->geometry();-
1145 result.adjust(0, -titleHeight, 0, 0);-
1146 return result;-
1147}-
1148-
1149bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem)-
1150{-
1151 Q_ASSERT(!path.isEmpty());-
1152-
1153 bool insert_tabbed = false;-
1154 int index = path.first();-
1155 if (index < 0) {-
1156 insert_tabbed = true;-
1157 index = -index - 1;-
1158 }-
1159-
1160// dump(qDebug() << "insertGap() before:" << index << tabIndex, *this, QString());-
1161-
1162 if (path.count() > 1) {-
1163 QDockAreaLayoutItem &item = item_list[index];-
1164-
1165 if (item.subinfo == 0-
1166#ifndef QT_NO_TABBAR-
1167 || (item.subinfo->tabbed && !insert_tabbed)-
1168#endif-
1169 ) {-
1170-
1171 // this is not yet a nested layout - make it-
1172-
1173 QDockAreaLayoutInfo *subinfo = item.subinfo;-
1174 QLayoutItem *widgetItem = item.widgetItem;-
1175 QPlaceHolderItem *placeHolderItem = item.placeHolderItem;-
1176 QRect r = subinfo == 0 ? widgetItem ? dockedGeometry(widgetItem->widget()) : placeHolderItem->topLevelRect : subinfo->rect;-
1177-
1178 Qt::Orientation opposite = o == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal;-
1179#ifdef QT_NO_TABBAR-
1180 const int tabBarShape = 0;-
1181#endif-
1182 QDockAreaLayoutInfo *new_info-
1183 = new QDockAreaLayoutInfo(sep, dockPos, opposite, tabBarShape, mainWindow);-
1184-
1185 //item become a new top-level-
1186 item.subinfo = new_info;-
1187 item.widgetItem = 0;-
1188 item.placeHolderItem = 0;-
1189-
1190 QDockAreaLayoutItem new_item-
1191 = widgetItem == 0-
1192 ? QDockAreaLayoutItem(subinfo)-
1193 : widgetItem ? QDockAreaLayoutItem(widgetItem) : QDockAreaLayoutItem(placeHolderItem);-
1194 new_item.size = pick(opposite, r.size());-
1195 new_item.pos = pick(opposite, r.topLeft());-
1196 new_info->item_list.append(new_item);-
1197#ifndef QT_NO_TABBAR-
1198 if (insert_tabbed) {-
1199 new_info->tabbed = true;-
1200 }-
1201#endif-
1202 }-
1203-
1204 return item.subinfo->insertGap(path.mid(1), dockWidgetItem);-
1205 }-
1206-
1207 // create the gap item-
1208 QDockAreaLayoutItem gap_item;-
1209 gap_item.flags |= QDockAreaLayoutItem::GapItem;-
1210 gap_item.widgetItem = dockWidgetItem; // so minimumSize(), maximumSize() and-
1211 // sizeHint() will work-
1212#ifndef QT_NO_TABBAR-
1213 if (!tabbed)-
1214#endif-
1215 {-
1216 int prev = this->prev(index);-
1217 int next = this->next(index - 1);-
1218 // find out how much space we have in the layout-
1219 int space = 0;-
1220 if (isEmpty()) {-
1221 // I am an empty dock area, therefore I am a top-level dock area.-
1222 switch (dockPos) {-
1223 case QInternal::LeftDock:-
1224 case QInternal::RightDock:-
1225 if (o == Qt::Vertical) {-
1226 // the "size" is the height of the dock area (remember we are empty)-
1227 space = pick(Qt::Vertical, rect.size());-
1228 } else {-
1229 space = pick(Qt::Horizontal, dockWidgetItem->widget()->size());-
1230 }-
1231 break;-
1232 case QInternal::TopDock:-
1233 case QInternal::BottomDock:-
1234 default:-
1235 if (o == Qt::Horizontal) {-
1236 // the "size" is width of the dock area-
1237 space = pick(Qt::Horizontal, rect.size());-
1238 } else {-
1239 space = pick(Qt::Vertical, dockWidgetItem->widget()->size());-
1240 }-
1241 break;-
1242 }-
1243 } else {-
1244 for (int i = 0; i < item_list.count(); ++i) {-
1245 const QDockAreaLayoutItem &item = item_list.at(i);-
1246 if (item.skip())-
1247 continue;-
1248 Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem));-
1249 space += item.size - pick(o, item.minimumSize());-
1250 }-
1251 }-
1252-
1253 // find the actual size of the gap-
1254 int gap_size = 0;-
1255 int sep_size = 0;-
1256 if (isEmpty()) {-
1257 gap_size = space;-
1258 sep_size = 0;-
1259 } else {-
1260 QRect r = dockedGeometry(dockWidgetItem->widget());-
1261 gap_size = pick(o, r.size());-
1262 if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem))-
1263 sep_size += *sep;-
1264 if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem))-
1265 sep_size += *sep;-
1266 }-
1267 if (gap_size + sep_size > space)-
1268 gap_size = pick(o, gap_item.minimumSize());-
1269 gap_item.size = gap_size + sep_size;-
1270 }-
1271-
1272 // finally, insert the gap-
1273 item_list.insert(index, gap_item);-
1274-
1275// dump(qDebug() << "insertGap() after:" << index << tabIndex, *this, QString());-
1276-
1277 return true;-
1278}-
1279-
1280QDockAreaLayoutInfo *QDockAreaLayoutInfo::info(QWidget *widget)-
1281{-
1282 for (int i = 0; i < item_list.count(); ++i) {-
1283 const QDockAreaLayoutItem &item = item_list.at(i);-
1284 if (item.skip())-
1285 continue;-
1286-
1287#ifndef QT_NO_TABBAR-
1288 if (tabbed && widget == tabBar)-
1289 return this;-
1290#endif-
1291-
1292 if (item.widgetItem != 0 && item.widgetItem->widget() == widget)-
1293 return this;-
1294-
1295 if (item.subinfo != 0) {-
1296 if (QDockAreaLayoutInfo *result = item.subinfo->info(widget))-
1297 return result;-
1298 }-
1299 }-
1300-
1301 return 0;-
1302}-
1303-
1304QDockAreaLayoutInfo *QDockAreaLayoutInfo::info(const QList<int> &path)-
1305{-
1306 int index = path.first();-
1307 if (index < 0)-
1308 index = -index - 1;-
1309 if (index >= item_list.count())-
1310 return this;-
1311 if (path.count() == 1 || item_list[index].subinfo == 0)-
1312 return this;-
1313 return item_list[index].subinfo->info(path.mid(1));-
1314}-
1315-
1316QRect QDockAreaLayoutInfo::itemRect(int index) const-
1317{-
1318 const QDockAreaLayoutItem &item = item_list.at(index);-
1319-
1320 if (item.skip())-
1321 return QRect();-
1322-
1323 QRect result;-
1324-
1325#ifndef QT_NO_TABBAR-
1326 if (tabbed) {-
1327 if (tabId(item) == currentTabId())-
1328 result = tabContentRect();-
1329 } else-
1330#endif-
1331 {-
1332 QPoint pos;-
1333 rpick(o, pos) = item.pos;-
1334 rperp(o, pos) = perp(o, rect.topLeft());-
1335 QSize s;-
1336 rpick(o, s) = item.size;-
1337 rperp(o, s) = perp(o, rect.size());-
1338 result = QRect(pos, s);-
1339 }-
1340-
1341 return result;-
1342}-
1343-
1344QRect QDockAreaLayoutInfo::itemRect(const QList<int> &path) const-
1345{-
1346 Q_ASSERT(!path.isEmpty());-
1347-
1348 const int index = path.first();-
1349 if (path.count() > 1) {-
1350 const QDockAreaLayoutItem &item = item_list.at(index);-
1351 Q_ASSERT(item.subinfo != 0);-
1352 return item.subinfo->itemRect(path.mid(1));-
1353 }-
1354-
1355 return itemRect(index);-
1356}-
1357-
1358QRect QDockAreaLayoutInfo::separatorRect(int index) const-
1359{-
1360#ifndef QT_NO_TABBAR-
1361 if (tabbed)-
1362 return QRect();-
1363#endif-
1364-
1365 const QDockAreaLayoutItem &item = item_list.at(index);-
1366 if (item.skip())-
1367 return QRect();-
1368-
1369 QPoint pos = rect.topLeft();-
1370 rpick(o, pos) = item.pos + item.size;-
1371 QSize s = rect.size();-
1372 rpick(o, s) = *sep;-
1373-
1374 return QRect(pos, s);-
1375}-
1376-
1377QRect QDockAreaLayoutInfo::separatorRect(const QList<int> &path) const-
1378{-
1379 Q_ASSERT(!path.isEmpty());-
1380-
1381 const int index = path.first();-
1382 if (path.count() > 1) {-
1383 const QDockAreaLayoutItem &item = item_list.at(index);-
1384 Q_ASSERT(item.subinfo != 0);-
1385 return item.subinfo->separatorRect(path.mid(1));-
1386 }-
1387 return separatorRect(index);-
1388}-
1389-
1390QList<int> QDockAreaLayoutInfo::findSeparator(const QPoint &_pos) const-
1391{-
1392#ifndef QT_NO_TABBAR-
1393 if (tabbed)-
1394 return QList<int>();-
1395#endif-
1396-
1397 int pos = pick(o, _pos);-
1398-
1399 for (int i = 0; i < item_list.size(); ++i) {-
1400 const QDockAreaLayoutItem &item = item_list.at(i);-
1401 if (item.skip() || (item.flags & QDockAreaLayoutItem::GapItem))-
1402 continue;-
1403-
1404 if (item.pos + item.size > pos) {-
1405 if (item.subinfo != 0) {-
1406 QList<int> result = item.subinfo->findSeparator(_pos);-
1407 if (!result.isEmpty()) {-
1408 result.prepend(i);-
1409 return result;-
1410 } else {-
1411 return QList<int>();-
1412 }-
1413 }-
1414 }-
1415-
1416 int next = this->next(i);-
1417 if (next == -1 || (item_list.at(next).flags & QDockAreaLayoutItem::GapItem))-
1418 continue;-
1419-
1420 QRect sepRect = separatorRect(i);-
1421 if (!sepRect.isNull() && *sep == 1)-
1422 sepRect.adjust(-2, -2, 2, 2);-
1423 //we also make sure we don't find a separator that's not there-
1424 if (sepRect.contains(_pos) && !item.hasFixedSize(o)) {-
1425 return QList<int>() << i;-
1426 }-
1427-
1428 }-
1429-
1430 return QList<int>();-
1431}-
1432-
1433QList<int> QDockAreaLayoutInfo::indexOfPlaceHolder(const QString &objectName) const-
1434{-
1435 for (int i = 0; i < item_list.size(); ++i) {-
1436 const QDockAreaLayoutItem &item = item_list.at(i);-
1437-
1438 if (item.subinfo != 0) {-
1439 QList<int> result = item.subinfo->indexOfPlaceHolder(objectName);-
1440 if (!result.isEmpty()) {-
1441 result.prepend(i);-
1442 return result;-
1443 }-
1444 continue;-
1445 }-
1446-
1447 if (item.placeHolderItem != 0 && item.placeHolderItem->objectName == objectName) {-
1448 QList<int> result;-
1449 result << i;-
1450 return result;-
1451 }-
1452 }-
1453-
1454 return QList<int>();-
1455}-
1456-
1457QList<int> QDockAreaLayoutInfo::indexOf(QWidget *widget) const-
1458{-
1459 for (int i = 0; i < item_list.size(); ++i) {-
1460 const QDockAreaLayoutItem &item = item_list.at(i);-
1461-
1462 if (item.placeHolderItem != 0)-
1463 continue;-
1464-
1465 if (item.subinfo != 0) {-
1466 QList<int> result = item.subinfo->indexOf(widget);-
1467 if (!result.isEmpty()) {-
1468 result.prepend(i);-
1469 return result;-
1470 }-
1471 continue;-
1472 }-
1473-
1474 if (!(item.flags & QDockAreaLayoutItem::GapItem) && item.widgetItem && item.widgetItem->widget() == widget) {-
1475 QList<int> result;-
1476 result << i;-
1477 return result;-
1478 }-
1479 }-
1480-
1481 return QList<int>();-
1482}-
1483-
1484QMainWindowLayout *QDockAreaLayoutInfo::mainWindowLayout() const-
1485{-
1486 QMainWindowLayout *result = qt_mainwindow_layout(mainWindow);-
1487 Q_ASSERT(result != 0);-
1488 return result;-
1489}-
1490-
1491bool QDockAreaLayoutInfo::hasFixedSize() const-
1492{-
1493 return perp(o, minimumSize()) == perp(o, maximumSize());-
1494}-
1495-
1496-
1497void QDockAreaLayoutInfo::apply(bool animate)-
1498{-
1499 QWidgetAnimator &widgetAnimator = mainWindowLayout()->widgetAnimator;-
1500-
1501#ifndef QT_NO_TABBAR-
1502 if (tabbed) {-
1503 QRect tab_rect;-
1504 QSize tbh = tabBarSizeHint();-
1505-
1506 if (!tbh.isNull()) {-
1507 switch (tabBarShape) {-
1508 case QTabBar::RoundedNorth:-
1509 case QTabBar::TriangularNorth:-
1510 tab_rect = QRect(rect.left(), rect.top(), rect.width(), tbh.height());-
1511 break;-
1512 case QTabBar::RoundedSouth:-
1513 case QTabBar::TriangularSouth:-
1514 tab_rect = QRect(rect.left(), rect.bottom() - tbh.height() + 1,-
1515 rect.width(), tbh.height());-
1516 break;-
1517 case QTabBar::RoundedEast:-
1518 case QTabBar::TriangularEast:-
1519 tab_rect = QRect(rect.right() - tbh.width() + 1, rect.top(),-
1520 tbh.width(), rect.height());-
1521 break;-
1522 case QTabBar::RoundedWest:-
1523 case QTabBar::TriangularWest:-
1524 tab_rect = QRect(rect.left(), rect.top(),-
1525 tbh.width(), rect.height());-
1526 break;-
1527 default:-
1528 break;-
1529 }-
1530 }-
1531-
1532 widgetAnimator.animate(tabBar, tab_rect, animate);-
1533 }-
1534#endif // QT_NO_TABBAR-
1535-
1536 for (int i = 0; i < item_list.size(); ++i) {-
1537 QDockAreaLayoutItem &item = item_list[i];-
1538-
1539 if (item.flags & QDockAreaLayoutItem::GapItem)-
1540 continue;-
1541-
1542 if (item.subinfo != 0) {-
1543 item.subinfo->apply(animate);-
1544 continue;-
1545 }-
1546-
1547 if (item.skip())-
1548 continue;-
1549-
1550 Q_ASSERT(item.widgetItem);-
1551 QRect r = itemRect(i);-
1552 QWidget *w = item.widgetItem->widget();-
1553-
1554 QRect geo = w->geometry();-
1555 widgetAnimator.animate(w, r, animate);-
1556 if (!w->isHidden() && w->window()->isVisible()) {-
1557 QDockWidget *dw = qobject_cast<QDockWidget*>(w);-
1558 if (!r.isValid() && geo.right() >= 0 && geo.bottom() >= 0) {-
1559 dw->lower();-
1560 emit dw->visibilityChanged(false);-
1561 } else if (r.isValid()-
1562 && (geo.right() < 0 || geo.bottom() < 0)) {-
1563 emit dw->visibilityChanged(true);-
1564 }-
1565 }-
1566 }-
1567#ifndef QT_NO_TABBAR-
1568 if (*sep == 1)-
1569 updateSeparatorWidgets();-
1570#endif //QT_NO_TABBAR-
1571}-
1572-
1573static void paintSep(QPainter *p, QWidget *w, const QRect &r, Qt::Orientation o, bool mouse_over)-
1574{-
1575 QStyleOption opt(0);-
1576 opt.state = QStyle::State_None;-
1577 if (w->isEnabled())-
1578 opt.state |= QStyle::State_Enabled;-
1579 if (o != Qt::Horizontal)-
1580 opt.state |= QStyle::State_Horizontal;-
1581 if (mouse_over)-
1582 opt.state |= QStyle::State_MouseOver;-
1583 opt.rect = r;-
1584 opt.palette = w->palette();-
1585-
1586 w->style()->drawPrimitive(QStyle::PE_IndicatorDockWidgetResizeHandle, &opt, p, w);-
1587}-
1588-
1589QRegion QDockAreaLayoutInfo::separatorRegion() const-
1590{-
1591 QRegion result;-
1592-
1593 if (isEmpty())-
1594 return result;-
1595#ifndef QT_NO_TABBAR-
1596 if (tabbed)-
1597 return result;-
1598#endif-
1599-
1600 for (int i = 0; i < item_list.count(); ++i) {-
1601 const QDockAreaLayoutItem &item = item_list.at(i);-
1602-
1603 if (item.skip())-
1604 continue;-
1605-
1606 int next = this->next(i);-
1607-
1608 if (item.subinfo)-
1609 result |= item.subinfo->separatorRegion();-
1610-
1611 if (next == -1)-
1612 break;-
1613 result |= separatorRect(i);-
1614 }-
1615-
1616 return result;-
1617}-
1618-
1619void QDockAreaLayoutInfo::paintSeparators(QPainter *p, QWidget *widget,-
1620 const QRegion &clip,-
1621 const QPoint &mouse) const-
1622{-
1623 if (isEmpty())-
1624 return;-
1625#ifndef QT_NO_TABBAR-
1626 if (tabbed)-
1627 return;-
1628#endif-
1629-
1630 for (int i = 0; i < item_list.count(); ++i) {-
1631 const QDockAreaLayoutItem &item = item_list.at(i);-
1632-
1633 if (item.skip())-
1634 continue;-
1635-
1636 int next = this->next(i);-
1637 if ((item.flags & QDockAreaLayoutItem::GapItem)-
1638 || (next != -1 && (item_list.at(next).flags & QDockAreaLayoutItem::GapItem)))-
1639 continue;-
1640-
1641 if (item.subinfo) {-
1642 if (clip.contains(item.subinfo->rect))-
1643 item.subinfo->paintSeparators(p, widget, clip, mouse);-
1644 }-
1645-
1646 if (next == -1)-
1647 break;-
1648 QRect r = separatorRect(i);-
1649 if (clip.contains(r) && !item.hasFixedSize(o))-
1650 paintSep(p, widget, r, o, r.contains(mouse));-
1651 }-
1652}-
1653-
1654int QDockAreaLayoutInfo::next(int index) const-
1655{-
1656 for (int i = index + 1; i < item_list.size(); ++i) {-
1657 if (!item_list.at(i).skip())-
1658 return i;-
1659 }-
1660 return -1;-
1661}-
1662-
1663int QDockAreaLayoutInfo::prev(int index) const-
1664{-
1665 for (int i = index - 1; i >= 0; --i) {-
1666 if (!item_list.at(i).skip())-
1667 return i;-
1668 }-
1669 return -1;-
1670}-
1671-
1672void QDockAreaLayoutInfo::tab(int index, QLayoutItem *dockWidgetItem)-
1673{-
1674#ifdef QT_NO_TABBAR-
1675 Q_UNUSED(index);-
1676 Q_UNUSED(dockWidgetItem);-
1677#else-
1678 if (tabbed) {
tabbedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1679 item_list.append(QDockAreaLayoutItem(dockWidgetItem));-
1680 updateTabBar();-
1681 setCurrentTab(dockWidgetItem->widget());-
1682 } else {
never executed: end of block
0
1683 QDockAreaLayoutInfo *new_info-
1684 = new QDockAreaLayoutInfo(sep, dockPos, o, tabBarShape, mainWindow);-
1685 item_list[index].subinfo = new_info;-
1686 new_info->item_list.append(QDockAreaLayoutItem(item_list.at(index).widgetItem);));-
1687 item_list[index].widgetItem = 0;-
1688 new_info->item_list.append(QDockAreaLayoutItem(dockWidgetItem);));-
1689 new_info->tabbed = true;-
1690 new_info->updateTabBar();-
1691 new_info->setCurrentTab(dockWidgetItem->widget());-
1692 }
never executed: end of block
0
1693#endif // QT_NO_TABBAR-
1694}-
1695-
1696void QDockAreaLayoutInfo::split(int index, Qt::Orientation orientation,-
1697 QLayoutItem *dockWidgetItem)-
1698{-
1699 if (orientation == o) {
orientation == oDescription
TRUEnever evaluated
FALSEnever evaluated
0
1700 item_list.insert(index + 1, QDockAreaLayoutItem(dockWidgetItem));-
1701 } else {
never executed: end of block
0
1702#ifdef QT_NO_TABBAR-
1703 const int tabBarShape = 0;-
1704#endif-
1705 QDockAreaLayoutInfo *new_info-
1706 = new QDockAreaLayoutInfo(sep, dockPos, orientation, tabBarShape, mainWindow);-
1707 item_list[index].subinfo = new_info;-
1708 new_info->item_list.append(QDockAreaLayoutItem(item_list.at(index).widgetItem);));-
1709 item_list[index].widgetItem = 0;-
1710 new_info->item_list.append(QDockAreaLayoutItem(dockWidgetItem);));-
1711 }
never executed: end of block
0
1712}-
1713-
1714QDockAreaLayoutItem &QDockAreaLayoutInfo::item(const QList<int> &path)-
1715{-
1716 Q_ASSERT(!path.isEmpty());-
1717 const int index = path.first();-
1718 if (path.count() > 1) {-
1719 const QDockAreaLayoutItem &item = item_list[index];-
1720 Q_ASSERT(item.subinfo != 0);-
1721 return item.subinfo->item(path.mid(1));-
1722 }-
1723 return item_list[index];-
1724}-
1725-
1726QLayoutItem *QDockAreaLayoutInfo::itemAt(int *x, int index) const-
1727{-
1728 for (int i = 0; i < item_list.count(); ++i) {-
1729 const QDockAreaLayoutItem &item = item_list.at(i);-
1730 if (item.placeHolderItem != 0)-
1731 continue;-
1732 if (item.subinfo) {-
1733 if (QLayoutItem *ret = item.subinfo->itemAt(x, index))-
1734 return ret;-
1735 } else if (item.widgetItem) {-
1736 if ((*x)++ == index)-
1737 return item.widgetItem;-
1738 }-
1739 }-
1740 return 0;-
1741}-
1742-
1743QLayoutItem *QDockAreaLayoutInfo::takeAt(int *x, int index)-
1744{-
1745 for (int i = 0; i < item_list.count(); ++i) {-
1746 QDockAreaLayoutItem &item = item_list[i];-
1747 if (item.placeHolderItem != 0)-
1748 continue;-
1749 else if (item.subinfo) {-
1750 if (QLayoutItem *ret = item.subinfo->takeAt(x, index)) {-
1751 unnest(i);-
1752 return ret;-
1753 }-
1754 } else if (item.widgetItem) {-
1755 if ((*x)++ == index) {-
1756 item.placeHolderItem = new QPlaceHolderItem(item.widgetItem->widget());-
1757 QLayoutItem *ret = item.widgetItem;-
1758 item.widgetItem = 0;-
1759 if (item.size != -1)-
1760 item.flags |= QDockAreaLayoutItem::KeepSize;-
1761 return ret;-
1762 }-
1763 }-
1764 }-
1765 return 0;-
1766}-
1767-
1768void QDockAreaLayoutInfo::deleteAllLayoutItems()-
1769{-
1770 for (int i = 0; i < item_list.count(); ++i) {-
1771 QDockAreaLayoutItem &item= item_list[i];-
1772 if (item.subinfo) {-
1773 item.subinfo->deleteAllLayoutItems();-
1774 } else {-
1775 delete item.widgetItem;-
1776 item.widgetItem = 0;-
1777 }-
1778 }-
1779}-
1780-
1781void QDockAreaLayoutInfo::saveState(QDataStream &stream) const-
1782{-
1783#ifndef QT_NO_TABBAR-
1784 if (tabbed) {
tabbedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1785 stream << (uchar) TabMarker;-
1786-
1787 // write the index in item_list of the widget that's currently on top.-
1788 quintptr id = currentTabId();-
1789 int index = -1;-
1790 for (int i = 0; i < item_list.count(); ++i) {
i < item_list.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1791 if (tabId(item_list.at(i)) == id) {
tabId(item_list.at(i)) == idDescription
TRUEnever evaluated
FALSEnever evaluated
0
1792 index = i;-
1793 break;
never executed: break;
0
1794 }-
1795 }
never executed: end of block
0
1796 stream << index;-
1797 } else
never executed: end of block
0
1798#endif // QT_NO_TABBAR-
1799 {-
1800 stream << (uchar) SequenceMarker;-
1801 }
never executed: end of block
0
1802-
1803 stream << (uchar) o << item_list.count();-
1804-
1805 for (int i = 0; i < item_list.count(); ++i) {
i < item_list.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1806 const QDockAreaLayoutItem &item = item_list.at(i);-
1807 if (item.widgetItem != 0) {
item.widgetItem != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1808 stream << (uchar) WidgetMarker;-
1809 QWidget *w = item.widgetItem->widget();-
1810 QString name = w->objectName();-
1811 if (Q_UNLIKELY(name.isEmpty())())) {
__builtin_expe...pty()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1812 qWarning("QMainWindow::saveState(): 'objectName' not set for QDockWidget %p '%s'%ls;",-
1813 w, qPrintableqUtf16Printable(w->windowTitle()));-
1814 }
never executed: end of block
0
1815 stream << name;-
1816-
1817 uchar flags = 0;-
1818 if (!w->isHidden())
!w->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
1819 flags |= StateFlagVisible;
never executed: flags |= StateFlagVisible;
0
1820 if (w->isWindow())
w->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
1821 flags |= StateFlagFloating;
never executed: flags |= StateFlagFloating;
0
1822 stream << flags;-
1823-
1824 if (w->isWindow()) {
w->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
1825 const QRect geometry = w->geometry();-
1826 stream << geometry.x() << geometry.y() << geometry.width() << geometry.height();-
1827 } else {
never executed: end of block
0
1828 stream << item.pos << item.size << pick(o, item.minimumSize())-
1829 << pick(o, item.maximumSize());-
1830 }
never executed: end of block
0
1831 } else if (item.placeHolderItem != 0) {
item.placeHolderItem != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1832 stream << (uchar) WidgetMarker;-
1833 stream << item.placeHolderItem->objectName;-
1834 uchar flags = 0;-
1835 if (!item.placeHolderItem->hidden)
!item.placeHolderItem->hiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1836 flags |= StateFlagVisible;
never executed: flags |= StateFlagVisible;
0
1837 if (item.placeHolderItem->window)
item.placeHolderItem->windowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1838 flags |= StateFlagFloating;
never executed: flags |= StateFlagFloating;
0
1839 stream << flags;-
1840 if (item.placeHolderItem->window) {
item.placeHolderItem->windowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1841 QRect r = item.placeHolderItem->topLevelRect;-
1842 stream << r.x() << r.y() << r.width() << r.height();-
1843 } else {
never executed: end of block
0
1844 stream << item.pos << item.size << (int)0 << (int)0;-
1845 }
never executed: end of block
0
1846 } else if (item.subinfo != 0) {
item.subinfo != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1847 stream << (uchar) SequenceMarker << item.pos << item.size << pick(o, item.minimumSize()) << pick(o, item.maximumSize());-
1848 item.subinfo->saveState(stream);-
1849 }
never executed: end of block
0
1850 }
never executed: end of block
0
1851}
never executed: end of block
0
1852-
1853static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos)-
1854{-
1855 switch (pos) {-
1856 case QInternal::LeftDock: return Qt::LeftDockWidgetArea;-
1857 case QInternal::RightDock: return Qt::RightDockWidgetArea;-
1858 case QInternal::TopDock: return Qt::TopDockWidgetArea;-
1859 case QInternal::BottomDock: return Qt::BottomDockWidgetArea;-
1860 default: break;-
1861 }-
1862 return Qt::NoDockWidgetArea;-
1863}-
1864-
1865bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> &widgets, bool testing)-
1866{-
1867 uchar marker;-
1868 stream >> marker;-
1869 if (marker != TabMarker && marker != SequenceMarker)-
1870 return false;-
1871-
1872#ifndef QT_NO_TABBAR-
1873 tabbed = marker == TabMarker;-
1874-
1875 int index = -1;-
1876 if (tabbed)-
1877 stream >> index;-
1878#endif-
1879-
1880 uchar orientation;-
1881 stream >> orientation;-
1882 o = static_cast<Qt::Orientation>(orientation);-
1883-
1884 int cnt;-
1885 stream >> cnt;-
1886-
1887 for (int i = 0; i < cnt; ++i) {-
1888 uchar nextMarker;-
1889 stream >> nextMarker;-
1890 if (nextMarker == WidgetMarker) {-
1891 QString name;-
1892 uchar flags;-
1893 stream >> name >> flags;-
1894 if (name.isEmpty()) {-
1895 int dummy;-
1896 stream >> dummy >> dummy >> dummy >> dummy;-
1897 continue;-
1898 }-
1899-
1900 QDockWidget *widget = 0;-
1901 for (int j = 0; j < widgets.count(); ++j) {-
1902 if (widgets.at(j)->objectName() == name) {-
1903 widget = widgets.takeAt(j);-
1904 break;-
1905 }-
1906 }-
1907-
1908 if (widget == 0) {-
1909 QPlaceHolderItem *placeHolder = new QPlaceHolderItem;-
1910 QDockAreaLayoutItem item(placeHolder);-
1911-
1912 placeHolder->objectName = name;-
1913 placeHolder->window = flags & StateFlagFloating;-
1914 placeHolder->hidden = !(flags & StateFlagVisible);-
1915 if (placeHolder->window) {-
1916 int x, y, w, h;-
1917 stream >> x >> y >> w >> h;-
1918 placeHolder->topLevelRect = QRect(x, y, w, h);-
1919 } else {-
1920 int dummy;-
1921 stream >> item.pos >> item.size >> dummy >> dummy;-
1922 }-
1923 if (item.size != -1)-
1924 item.flags |= QDockAreaLayoutItem::KeepSize;-
1925 if (!testing)-
1926 item_list.append(item);-
1927 } else {-
1928 QDockAreaLayoutItem item(new QDockWidgetItem(widget));-
1929 if (flags & StateFlagFloating) {-
1930 bool drawer = false;-
1931#ifdef Q_DEAD_CODE_FROM_QT4_MAC // drawer support-
1932 extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp-
1933 extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp-
1934 drawer = qt_mac_is_macdrawer(widget);-
1935#endif-
1936-
1937 if (!testing) {-
1938 widget->hide();-
1939 if (!drawer)-
1940 widget->setFloating(true);-
1941 }-
1942-
1943 int x, y, w, h;-
1944 stream >> x >> y >> w >> h;-
1945-
1946#ifdef Q_DEAD_CODE_FROM_QT4_MAC // drawer support-
1947 if (drawer) {-
1948 mainWindow->window()->createWinId();-
1949 widget->window()->createWinId();-
1950 qt_mac_set_drawer_preferred_edge(widget, toDockWidgetArea(dockPos));-
1951 } else-
1952#endif-
1953 if (!testing)-
1954 widget->setGeometry(QDockAreaLayout::constrainedRect(QRect(x, y, w, h), widget));-
1955-
1956 if (!testing) {-
1957 widget->setVisible(flags & StateFlagVisible);-
1958 item_list.append(item);-
1959 }-
1960 } else {-
1961 int dummy;-
1962 stream >> item.pos >> item.size >> dummy >> dummy;-
1963 if (!testing) {-
1964 item_list.append(item);-
1965 widget->setFloating(false);-
1966 widget->setVisible(flags & StateFlagVisible);-
1967 emit widget->dockLocationChanged(toDockWidgetArea(dockPos));-
1968 }-
1969 }-
1970 if (testing) {-
1971 //was it is not really added to the layout, we need to delete the object here-
1972 delete item.widgetItem;-
1973 }-
1974 }-
1975 } else if (nextMarker == SequenceMarker) {-
1976 int dummy;-
1977#ifdef QT_NO_TABBAR-
1978 const int tabBarShape = 0;-
1979#endif-
1980 QDockAreaLayoutItem item(new QDockAreaLayoutInfo(sep, dockPos, o,-
1981 tabBarShape, mainWindow));-
1982 stream >> item.pos >> item.size >> dummy >> dummy;-
1983 //we need to make sure the element is in the list so the dock widget can eventually be docked correctly-
1984 if (!testing)-
1985 item_list.append(item);-
1986-
1987 //here we need to make sure we change the item in the item_list-
1988 QDockAreaLayoutItem &lastItem = testing ? item : item_list.last();-
1989-
1990 if (!lastItem.subinfo->restoreState(stream, widgets, testing))-
1991 return false;-
1992-
1993 } else {-
1994 return false;-
1995 }-
1996 }-
1997-
1998#ifndef QT_NO_TABBAR-
1999 if (!testing && tabbed && index >= 0 && index < item_list.count()) {-
2000 updateTabBar();-
2001 setCurrentTabId(tabId(item_list.at(index)));-
2002 }-
2003 if (!testing && *sep == 1)-
2004 updateSeparatorWidgets();-
2005#endif-
2006-
2007 return true;-
2008}-
2009-
2010#ifndef QT_NO_TABBAR-
2011void QDockAreaLayoutInfo::updateSeparatorWidgets() const-
2012{-
2013 if (tabbed) {-
2014 separatorWidgets.clear();-
2015 return;-
2016 }-
2017-
2018 int j = 0;-
2019 for (int i = 0; i < item_list.count(); ++i) {-
2020 const QDockAreaLayoutItem &item = item_list.at(i);-
2021-
2022 if (item.skip())-
2023 continue;-
2024-
2025 int next = this->next(i);-
2026 if ((item.flags & QDockAreaLayoutItem::GapItem)-
2027 || (next != -1 && (item_list.at(next).flags & QDockAreaLayoutItem::GapItem)))-
2028 continue;-
2029-
2030 if (item.subinfo) {-
2031 item.subinfo->updateSeparatorWidgets();-
2032 }-
2033-
2034 if (next == -1)-
2035 break;-
2036-
2037 QWidget *sepWidget;-
2038 if (j < separatorWidgets.size() && separatorWidgets.at(j)) {-
2039 sepWidget = separatorWidgets.at(j);-
2040 } else {-
2041 sepWidget = mainWindowLayout()->getSeparatorWidget();-
2042 separatorWidgets.append(sepWidget);-
2043 }-
2044 j++;-
2045-
2046#ifndef Q_DEAD_CODE_FROM_QT4_MAC-
2047 sepWidget->raise();-
2048#endif-
2049 QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2);-
2050 sepWidget->setGeometry(sepRect);-
2051 sepWidget->setMask( QRegion(separatorRect(i).translated( - sepRect.topLeft())));-
2052 sepWidget->show();-
2053 }-
2054-
2055 for (int k = j; k < separatorWidgets.size(); ++k) {-
2056 separatorWidgets[k]->hide();-
2057 }-
2058 separatorWidgets.resize(j);-
2059 Q_ASSERT(separatorWidgets.size() == j);-
2060}-
2061#endif //QT_NO_TABBAR-
2062-
2063#ifndef QT_NO_TABBAR-
2064/*! \internal-
2065 reparent all the widgets contained in this layout portion to the-
2066 specified parent. This is used to reparent dock widgets and tabbars-
2067 to the floating window or the main window-
2068 */-
2069void QDockAreaLayoutInfo::reparentWidgets(QWidget *parent)-
2070{-
2071 if (tabBar)
tabBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
2072 tabBar->setParent(parent);
never executed: tabBar->setParent(parent);
0
2073-
2074 for (int i = 0; i < item_list.count(); ++i) {
i < item_list.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2075 const QDockAreaLayoutItem &item = item_list.at(i);-
2076 if (item.flags & QDockAreaLayoutItem::GapItem)
item.flags & Q...tItem::GapItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2077 continue;
never executed: continue;
0
2078 if (item.skip())
item.skip()Description
TRUEnever evaluated
FALSEnever evaluated
0
2079 continue;
never executed: continue;
0
2080 if (item.subinfo)
item.subinfoDescription
TRUEnever evaluated
FALSEnever evaluated
0
2081 item.subinfo->reparentWidgets(parent);
never executed: item.subinfo->reparentWidgets(parent);
0
2082 if (item.widgetItem) {
item.widgetItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2083 QWidget *w = item.widgetItem->widget();-
2084 if (qobject_cast<QDockWidgetGroupWindow *>(w))
w->parent() != parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
continue;
w->parent() != parentDescription
TRUEnever evaluated
FALSEnever evaluated
if (w->parent() != parent) {
w->parent() != parentDescription
TRUEnever evaluated
FALSEnever evaluated
2085 bool hidden = w->isHidden();-
2086 w->setParent(parent, w->windowFlags()););-
2087 if (!hidden)
!hiddenDescription
TRUEnever evaluated
FALSEnever evaluated
0
2088 w->show();
never executed: w->show();
0
2089 }
never executed: end of block
0
2090 }
never executed: end of block
0
2091 }
never executed: end of block
0
2092}
never executed: end of block
0
2093-
2094//returns whether the tabbar is visible or not-
2095bool QDockAreaLayoutInfo::updateTabBar() const-
2096{-
2097 if (!tabbed)-
2098 return false;-
2099-
2100 QDockAreaLayoutInfo *that = const_cast<QDockAreaLayoutInfo*>(this);-
2101-
2102 if (that->tabBar == 0) {-
2103 that->tabBar = mainWindowLayout()->getTabBar();-
2104 that->tabBar->setShape(static_cast<QTabBar::Shape>(tabBarShape));-
2105 that->tabBar->setDrawBase(true);-
2106 }-
2107-
2108 const QSignalBlocker blocker(tabBar);-
2109 bool gap = false;-
2110-
2111 const quintptr oldCurrentId = currentTabId();-
2112-
2113 int tab_idx = 0;-
2114 for (int i = 0; i < item_list.count(); ++i) {-
2115 const QDockAreaLayoutItem &item = item_list.at(i);-
2116 if (item.skip())-
2117 continue;-
2118 if (item.flags & QDockAreaLayoutItem::GapItem) {-
2119 gap = true;-
2120 continue;-
2121 }-
2122 if (item.widgetItem == 0)-
2123 continue;-
2124-
2125 QDockWidget *dw = qobject_cast<QDockWidget*>(item.widgetItem->widget());-
2126 QString title = dw->d_func()->fixedWindowTitle;-
2127 quintptr id = tabId(item);-
2128 if (tab_idx == tabBar->count()) {-
2129 tabBar->insertTab(tab_idx, title);-
2130#ifndef QT_NO_TOOLTIP-
2131 tabBar->setTabToolTip(tab_idx, title);-
2132#endif-
2133 tabBar->setTabData(tab_idx, id);-
2134 } else if (qvariant_cast<quintptr>(tabBar->tabData(tab_idx)) != id) {-
2135 if (tab_idx + 1 < tabBar->count()-
2136 && qvariant_cast<quintptr>(tabBar->tabData(tab_idx + 1)) == id)-
2137 tabBar->removeTab(tab_idx);-
2138 else {-
2139 tabBar->insertTab(tab_idx, title);-
2140#ifndef QT_NO_TOOLTIP-
2141 tabBar->setTabToolTip(tab_idx, title);-
2142#endif-
2143 tabBar->setTabData(tab_idx, id);-
2144 }-
2145 }-
2146-
2147 if (title != tabBar->tabText(tab_idx)) {-
2148 tabBar->setTabText(tab_idx, title);-
2149#ifndef QT_NO_TOOLTIP-
2150 tabBar->setTabToolTip(tab_idx, title);-
2151#endif-
2152 }-
2153-
2154 ++tab_idx;-
2155 }-
2156-
2157 while (tab_idx < tabBar->count()) {-
2158 tabBar->removeTab(tab_idx);-
2159 }-
2160-
2161 if (oldCurrentId > 0 && currentTabId() != oldCurrentId)-
2162 that->setCurrentTabId(oldCurrentId);-
2163-
2164 if (QDockWidgetGroupWindow *dwgw = qobject_cast<QDockWidgetGroupWindow *>(tabBar->parent()))-
2165 dwgw->adjustFlags();-
2166-
2167 //returns if the tabbar is visible or not-
2168 return ( (gap ? 1 : 0) + tabBar->count()) > 1;-
2169}-
2170-
2171void QDockAreaLayoutInfo::setTabBarShape(int shape)-
2172{-
2173 if (shape == tabBarShape)-
2174 return;-
2175 tabBarShape = shape;-
2176 if (tabBar != 0)-
2177 tabBar->setShape(static_cast<QTabBar::Shape>(shape));-
2178-
2179 for (int i = 0; i < item_list.count(); ++i) {-
2180 QDockAreaLayoutItem &item = item_list[i];-
2181 if (item.subinfo != 0)-
2182 item.subinfo->setTabBarShape(shape);-
2183 }-
2184}-
2185-
2186QSize QDockAreaLayoutInfo::tabBarMinimumSize() const-
2187{-
2188 if (!updateTabBar())-
2189 return QSize(0, 0);-
2190-
2191 return tabBar->minimumSizeHint();-
2192}-
2193-
2194QSize QDockAreaLayoutInfo::tabBarSizeHint() const-
2195{-
2196 if (!updateTabBar())-
2197 return QSize(0, 0);-
2198-
2199 return tabBar->sizeHint();-
2200}-
2201-
2202QSet<QTabBar*> QDockAreaLayoutInfo::usedTabBars() const-
2203{-
2204 QSet<QTabBar*> result;-
2205-
2206 if (tabbed) {-
2207 updateTabBar();-
2208 result.insert(tabBar);-
2209 }-
2210-
2211 for (int i = 0; i < item_list.count(); ++i) {-
2212 const QDockAreaLayoutItem &item = item_list.at(i);-
2213 if (item.subinfo != 0)-
2214 result += item.subinfo->usedTabBars();-
2215 }-
2216-
2217 return result;-
2218}-
2219-
2220// returns a set of all used separator widgets for this dockarelayout info-
2221// and all subinfos-
2222QSet<QWidget*> QDockAreaLayoutInfo::usedSeparatorWidgets() const-
2223{-
2224 QSet<QWidget*> result;-
2225 const int numSeparatorWidgets = separatorWidgets.count();-
2226 result.reserve(numSeparatorWidgets);-
2227-
2228 for (int i = 0; i < numSeparatorWidgets; ++i)-
2229 result << separatorWidgets.at(i);-
2230-
2231 for (int i = 0; i < item_list.count(); ++i) {-
2232 const QDockAreaLayoutItem &item = item_list.at(i);-
2233 if (item.subinfo != 0)-
2234 result += item.subinfo->usedSeparatorWidgets();-
2235 }-
2236-
2237 return result;-
2238}-
2239-
2240QRect QDockAreaLayoutInfo::tabContentRect() const-
2241{-
2242 if (!tabbed)-
2243 return QRect();-
2244-
2245 QRect result = rect;-
2246 QSize tbh = tabBarSizeHint();-
2247-
2248 if (!tbh.isNull()) {-
2249 switch (tabBarShape) {-
2250 case QTabBar::RoundedNorth:-
2251 case QTabBar::TriangularNorth:-
2252 result.adjust(0, tbh.height(), 0, 0);-
2253 break;-
2254 case QTabBar::RoundedSouth:-
2255 case QTabBar::TriangularSouth:-
2256 result.adjust(0, 0, 0, -tbh.height());-
2257 break;-
2258 case QTabBar::RoundedEast:-
2259 case QTabBar::TriangularEast:-
2260 result.adjust(0, 0, -tbh.width(), 0);-
2261 break;-
2262 case QTabBar::RoundedWest:-
2263 case QTabBar::TriangularWest:-
2264 result.adjust(tbh.width(), 0, 0, 0);-
2265 break;-
2266 default:-
2267 break;-
2268 }-
2269 }-
2270-
2271 return result;-
2272}-
2273-
2274int QDockAreaLayoutInfo::tabIndexToListIndex(int tabIndex) const-
2275{-
2276 Q_ASSERT(tabbed && tabBar);-
2277 quintptr data = qvariant_cast<quintptr>(tabBar->tabData(tabIndex));-
2278 for (int i = 0; i < item_list.count(); ++i) {-
2279 if (tabId(item_list.at(i)) == data)-
2280 return i;-
2281 }-
2282 return -1;-
2283}-
2284-
2285void QDockAreaLayoutInfo::moveTab(int from, int to)-
2286{-
2287 item_list.move(tabIndexToListIndex(from), tabIndexToListIndex(to));-
2288}-
2289#endif // QT_NO_TABBAR-
2290-
2291/******************************************************************************-
2292** QDockAreaLayout-
2293*/-
2294-
2295QDockAreaLayout::QDockAreaLayout(QMainWindow *win) : fallbackToSizeHints(true)-
2296{-
2297 mainWindow = win;-
2298 sep = win->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, win);-
2299#ifndef QT_NO_TABBAR-
2300 const int tabShape = QTabBar::RoundedSouth;-
2301#else-
2302 const int tabShape = 0;-
2303#endif-
2304 docks[QInternal::LeftDock]-
2305 = QDockAreaLayoutInfo(&sep, QInternal::LeftDock, Qt::Vertical, tabShape, win);-
2306 docks[QInternal::RightDock]-
2307 = QDockAreaLayoutInfo(&sep, QInternal::RightDock, Qt::Vertical, tabShape, win);-
2308 docks[QInternal::TopDock]-
2309 = QDockAreaLayoutInfo(&sep, QInternal::TopDock, Qt::Horizontal, tabShape, win);-
2310 docks[QInternal::BottomDock]-
2311 = QDockAreaLayoutInfo(&sep, QInternal::BottomDock, Qt::Horizontal, tabShape, win);-
2312 centralWidgetItem = 0;-
2313-
2314-
2315 corners[Qt::TopLeftCorner] = Qt::TopDockWidgetArea;-
2316 corners[Qt::TopRightCorner] = Qt::TopDockWidgetArea;-
2317 corners[Qt::BottomLeftCorner] = Qt::BottomDockWidgetArea;-
2318 corners[Qt::BottomRightCorner] = Qt::BottomDockWidgetArea;-
2319}-
2320-
2321bool QDockAreaLayout::isValid() const-
2322{-
2323 return rect.isValid();-
2324}-
2325-
2326void QDockAreaLayout::saveState(QDataStream &stream) const-
2327{-
2328 stream << (uchar) DockWidgetStateMarker;-
2329 int cnt = 0;-
2330 for (int i = 0; i < QInternal::DockCount; ++i) {-
2331 if (!docks[i].item_list.isEmpty())-
2332 ++cnt;-
2333 }-
2334 stream << cnt;-
2335 for (int i = 0; i < QInternal::DockCount; ++i) {-
2336 if (docks[i].item_list.isEmpty())-
2337 continue;-
2338 stream << i << docks[i].rect.size();-
2339 docks[i].saveState(stream);-
2340 }-
2341-
2342 stream << centralWidgetRect.size();-
2343-
2344 for (int i = 0; i < 4; ++i)-
2345 stream << static_cast<int>(corners[i]);-
2346}-
2347-
2348bool QDockAreaLayout::restoreState(QDataStream &stream, const QList<QDockWidget*> &_dockwidgets, bool testing)-
2349{-
2350 QList<QDockWidget*> dockwidgets = _dockwidgets;-
2351-
2352 int cnt;-
2353 stream >> cnt;-
2354 for (int i = 0; i < cnt; ++i) {-
2355 int pos;-
2356 stream >> pos;-
2357 QSize size;-
2358 stream >> size;-
2359 if (!testing) {-
2360 docks[pos].rect = QRect(QPoint(0, 0), size);-
2361 }-
2362 if (!docks[pos].restoreState(stream, dockwidgets, testing)) {-
2363 stream.setStatus(QDataStream::ReadCorruptData);-
2364 return false;-
2365 }-
2366 }-
2367-
2368 QSize size;-
2369 stream >> size;-
2370 centralWidgetRect = QRect(QPoint(0, 0), size);-
2371-
2372 bool ok = stream.status() == QDataStream::Ok;-
2373-
2374 if (ok) {-
2375 int cornerData[4];-
2376 for (int i = 0; i < 4; ++i)-
2377 stream >> cornerData[i];-
2378 if (stream.status() == QDataStream::Ok) {-
2379 for (int i = 0; i < 4; ++i)-
2380 corners[i] = static_cast<Qt::DockWidgetArea>(cornerData[i]);-
2381 }-
2382-
2383 if (!testing)-
2384 fallbackToSizeHints = false;-
2385 }-
2386-
2387 return ok;-
2388}-
2389-
2390QList<int> QDockAreaLayout::indexOfPlaceHolder(const QString &objectName) const-
2391{-
2392 for (int i = 0; i < QInternal::DockCount; ++i) {-
2393 QList<int> result = docks[i].indexOfPlaceHolder(objectName);-
2394 if (!result.isEmpty()) {-
2395 result.prepend(i);-
2396 return result;-
2397 }-
2398 }-
2399 return QList<int>();-
2400}-
2401-
2402QList<int> QDockAreaLayout::indexOf(QWidget *dockWidget) const-
2403{-
2404 for (int i = 0; i < QInternal::DockCount; ++i) {-
2405 QList<int> result = docks[i].indexOf(dockWidget);-
2406 if (!result.isEmpty()) {-
2407 result.prepend(i);-
2408 return result;-
2409 }-
2410 }-
2411 return QList<int>();-
2412}-
2413-
2414QList<int> QDockAreaLayout::gapIndex(const QPoint &pos) const-
2415{-
2416 QMainWindow::DockOptions opts = mainWindow->dockOptions();-
2417 bool nestingEnabled = opts & QMainWindow::AllowNestedDocks;-
2418 QDockAreaLayoutInfo::TabMode tabMode = QDockAreaLayoutInfo::NoTabs;-
2419#ifndef QT_NO_TABBAR-
2420 if (opts & QMainWindow::AllowTabbedDocks-
2421 || opts & QMainWindow::VerticalTabs)-
2422 tabMode = QDockAreaLayoutInfo::AllowTabs;-
2423 if (opts & QMainWindow::ForceTabbedDocks)-
2424 tabMode = QDockAreaLayoutInfo::ForceTabs;-
2425-
2426 if (tabMode == QDockAreaLayoutInfo::ForceTabs)-
2427 nestingEnabled = false;-
2428#endif-
2429-
2430-
2431 for (int i = 0; i < QInternal::DockCount; ++i) {-
2432 const QDockAreaLayoutInfo &info = docks[i];-
2433-
2434 if (!info.isEmpty() && info.rect.contains(pos)) {-
2435 QList<int> result-
2436 = docks[i].gapIndex(pos, nestingEnabled, tabMode);-
2437 if (!result.isEmpty())-
2438 result.prepend(i);-
2439 return result;-
2440 }-
2441 }-
2442-
2443 for (int i = 0; i < QInternal::DockCount; ++i) {-
2444 const QDockAreaLayoutInfo &info = docks[i];-
2445-
2446 if (info.isEmpty()) {-
2447 QRect r;-
2448 switch (i) {-
2449 case QInternal::LeftDock:-
2450 r = QRect(rect.left(), rect.top(), EmptyDropAreaSize, rect.height());-
2451 break;-
2452 case QInternal::RightDock:-
2453 r = QRect(rect.right() - EmptyDropAreaSize, rect.top(),-
2454 EmptyDropAreaSize, rect.height());-
2455 break;-
2456 case QInternal::TopDock:-
2457 r = QRect(rect.left(), rect.top(), rect.width(), EmptyDropAreaSize);-
2458 break;-
2459 case QInternal::BottomDock:-
2460 r = QRect(rect.left(), rect.bottom() - EmptyDropAreaSize,-
2461 rect.width(), EmptyDropAreaSize);-
2462 break;-
2463 }-
2464 if (r.contains(pos)) {-
2465 if (opts & QMainWindow::ForceTabbedDocks && !info.item_list.isEmpty()) {-
2466 //in case of ForceTabbedDocks, we pass -1 in order to force the gap to be tabbed-
2467 //it mustn't be completely empty otherwise it won't work-
2468 return QList<int>() << i << -1 << 0;-
2469 } else {-
2470 return QList<int>() << i << 0;-
2471 }-
2472 }-
2473 }-
2474 }-
2475-
2476 return QList<int>();-
2477}-
2478-
2479QList<int> QDockAreaLayout::findSeparator(const QPoint &pos) const-
2480{-
2481 QList<int> result;-
2482 for (int i = 0; i < QInternal::DockCount; ++i) {-
2483 const QDockAreaLayoutInfo &info = docks[i];-
2484 if (info.isEmpty())-
2485 continue;-
2486 QRect rect = separatorRect(i);-
2487 if (!rect.isNull() && sep == 1)-
2488 rect.adjust(-2, -2, 2, 2);-
2489 if (rect.contains(pos) && !info.hasFixedSize()) {-
2490 result << i;-
2491 break;-
2492 } else if (info.rect.contains(pos)) {-
2493 result = docks[i].findSeparator(pos);-
2494 if (!result.isEmpty()) {-
2495 result.prepend(i);-
2496 break;-
2497 }-
2498 }-
2499 }-
2500-
2501 return result;-
2502}-
2503-
2504QDockAreaLayoutInfo *QDockAreaLayout::info(QWidget *widget)-
2505{-
2506 for (int i = 0; i < QInternal::DockCount; ++i) {-
2507 if (QDockAreaLayoutInfo *result = docks[i].info(widget))-
2508 return result;-
2509 }-
2510-
2511 return 0;-
2512}-
2513-
2514QDockAreaLayoutInfo *QDockAreaLayout::info(const QList<int> &path)-
2515{-
2516 Q_ASSERT(!path.isEmpty());-
2517 const int index = path.first();-
2518 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2519-
2520 if (path.count() == 1)-
2521 return &docks[index];-
2522-
2523 return docks[index].info(path.mid(1));-
2524}-
2525-
2526const QDockAreaLayoutInfo *QDockAreaLayout::info(const QList<int> &path) const-
2527{-
2528 return const_cast<QDockAreaLayout*>(this)->info(path);-
2529}-
2530-
2531QDockAreaLayoutItem &QDockAreaLayout::item(const QList<int> &path)-
2532{-
2533 Q_ASSERT(!path.isEmpty());-
2534 const int index = path.first();-
2535 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2536 return docks[index].item(path.mid(1));-
2537}-
2538-
2539QRect QDockAreaLayout::itemRect(const QList<int> &path) const-
2540{-
2541 Q_ASSERT(!path.isEmpty());-
2542 const int index = path.first();-
2543 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2544 return docks[index].itemRect(path.mid(1));-
2545}-
2546-
2547QRect QDockAreaLayout::separatorRect(int index) const-
2548{-
2549 const QDockAreaLayoutInfo &dock = docks[index];-
2550 if (dock.isEmpty())-
2551 return QRect();-
2552 QRect r = dock.rect;-
2553 switch (index) {-
2554 case QInternal::LeftDock:-
2555 return QRect(r.right() + 1, r.top(), sep, r.height());-
2556 case QInternal::RightDock:-
2557 return QRect(r.left() - sep, r.top(), sep, r.height());-
2558 case QInternal::TopDock:-
2559 return QRect(r.left(), r.bottom() + 1, r.width(), sep);-
2560 case QInternal::BottomDock:-
2561 return QRect(r.left(), r.top() - sep, r.width(), sep);-
2562 default:-
2563 break;-
2564 }-
2565 return QRect();-
2566}-
2567-
2568QRect QDockAreaLayout::separatorRect(const QList<int> &path) const-
2569{-
2570 Q_ASSERT(!path.isEmpty());-
2571-
2572 const int index = path.first();-
2573 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2574-
2575 if (path.count() == 1)-
2576 return separatorRect(index);-
2577 else-
2578 return docks[index].separatorRect(path.mid(1));-
2579}-
2580-
2581bool QDockAreaLayout::insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem)-
2582{-
2583 Q_ASSERT(!path.isEmpty());-
2584 const int index = path.first();-
2585 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2586 return docks[index].insertGap(path.mid(1), dockWidgetItem);-
2587}-
2588-
2589QLayoutItem *QDockAreaLayout::plug(const QList<int> &path)-
2590{-
2591 Q_ASSERT(!path.isEmpty());-
2592 const int index = path.first();-
2593 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2594 QLayoutItem *item =return docks[index].plug(path.mid(1));
never executed: return docks[index].plug(path.mid(1));
0
docks[index].reparentWidgets(mainWindow);
return item;}
2596-
2597QLayoutItem *QDockAreaLayout::unplug(const QList<int> &path)-
2598{-
2599 Q_ASSERT(!path.isEmpty());-
2600 const int index = path.first();-
2601 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2602 return docks[index].unplug(path.mid(1));-
2603}-
2604-
2605void QDockAreaLayout::remove(const QList<int> &path)-
2606{-
2607 Q_ASSERT(!path.isEmpty());-
2608 const int index = path.first();-
2609 Q_ASSERT(index >= 0 && index < QInternal::DockCount);-
2610 docks[index].remove(path.mid(1));-
2611}-
2612-
2613void QDockAreaLayout::removePlaceHolder(const QString &name)-
2614{-
2615 QList<int> index = indexOfPlaceHolder(name);-
2616 if (!index.isEmpty())-
2617 remove(index);-
2618 foreach (QDockWidgetGroupWindow *dwgw, mainWindow->findChildren<QDockWidgetGroupWindow *>(-
2619 QString(), Qt::FindDirectChildrenOnly)) {-
2620 index = dwgw->layoutInfo()->indexOfPlaceHolder(name);-
2621 if (!index.isEmpty()) {-
2622 dwgw->layoutInfo()->remove(index);-
2623 dwgw->destroyOrHideIfEmpty();-
2624 }-
2625 }-
2626}-
2627-
2628static inline int qMax(int i1, int i2, int i3) { return qMax(i1, qMax(i2, i3)); }-
2629-
2630void QDockAreaLayout::getGrid(QVector<QLayoutStruct> *_ver_struct_list,-
2631 QVector<QLayoutStruct> *_hor_struct_list)-
2632{-
2633 QSize center_hint(0, 0);-
2634 QSize center_min(0, 0);-
2635 QSize center_max(0, 0);-
2636 const bool have_central = centralWidgetItem != 0 && !centralWidgetItem->isEmpty();-
2637 if (have_central) {-
2638 center_hint = centralWidgetRect.size();-
2639 if (!center_hint.isValid())-
2640 center_hint = centralWidgetItem->sizeHint();-
2641 center_min = centralWidgetItem->minimumSize();-
2642 center_max = centralWidgetItem->maximumSize();-
2643 }-
2644-
2645 QRect center_rect = rect;-
2646 if (!docks[QInternal::LeftDock].isEmpty())-
2647 center_rect.setLeft(rect.left() + docks[QInternal::LeftDock].rect.width() + sep);-
2648 if (!docks[QInternal::TopDock].isEmpty())-
2649 center_rect.setTop(rect.top() + docks[QInternal::TopDock].rect.height() + sep);-
2650 if (!docks[QInternal::RightDock].isEmpty())-
2651 center_rect.setRight(rect.right() - docks[QInternal::RightDock].rect.width() - sep);-
2652 if (!docks[QInternal::BottomDock].isEmpty())-
2653 center_rect.setBottom(rect.bottom() - docks[QInternal::BottomDock].rect.height() - sep);-
2654-
2655 QSize left_hint = docks[QInternal::LeftDock].size();-
2656 if (left_hint.isNull() || fallbackToSizeHints)-
2657 left_hint = docks[QInternal::LeftDock].sizeHint();-
2658 QSize left_min = docks[QInternal::LeftDock].minimumSize();-
2659 QSize left_max = docks[QInternal::LeftDock].maximumSize();-
2660 left_hint = left_hint.boundedTo(left_max).expandedTo(left_min);-
2661-
2662 QSize right_hint = docks[QInternal::RightDock].size();-
2663 if (right_hint.isNull() || fallbackToSizeHints)-
2664 right_hint = docks[QInternal::RightDock].sizeHint();-
2665 QSize right_min = docks[QInternal::RightDock].minimumSize();-
2666 QSize right_max = docks[QInternal::RightDock].maximumSize();-
2667 right_hint = right_hint.boundedTo(right_max).expandedTo(right_min);-
2668-
2669 QSize top_hint = docks[QInternal::TopDock].size();-
2670 if (top_hint.isNull() || fallbackToSizeHints)-
2671 top_hint = docks[QInternal::TopDock].sizeHint();-
2672 QSize top_min = docks[QInternal::TopDock].minimumSize();-
2673 QSize top_max = docks[QInternal::TopDock].maximumSize();-
2674 top_hint = top_hint.boundedTo(top_max).expandedTo(top_min);-
2675-
2676 QSize bottom_hint = docks[QInternal::BottomDock].size();-
2677 if (bottom_hint.isNull() || fallbackToSizeHints)-
2678 bottom_hint = docks[QInternal::BottomDock].sizeHint();-
2679 QSize bottom_min = docks[QInternal::BottomDock].minimumSize();-
2680 QSize bottom_max = docks[QInternal::BottomDock].maximumSize();-
2681 bottom_hint = bottom_hint.boundedTo(bottom_max).expandedTo(bottom_min);-
2682-
2683 if (_ver_struct_list != 0) {-
2684 QVector<QLayoutStruct> &ver_struct_list = *_ver_struct_list;-
2685 ver_struct_list.resize(3);-
2686-
2687 // top ---------------------------------------------------
2688 ver_struct_list[0].init();-
2689 ver_struct_list[0].stretch = 0;-
2690 ver_struct_list[0].sizeHint = top_hint.height();-
2691 ver_struct_list[0].minimumSize = top_min.height();-
2692 ver_struct_list[0].maximumSize = top_max.height();-
2693 ver_struct_list[0].expansive = false;-
2694 ver_struct_list[0].empty = docks[QInternal::TopDock].isEmpty();-
2695 ver_struct_list[0].pos = docks[QInternal::TopDock].rect.top();-
2696 ver_struct_list[0].size = docks[QInternal::TopDock].rect.height();-
2697-
2698 // center ---------------------------------------------------
2699 ver_struct_list[1].init();-
2700 ver_struct_list[1].stretch = center_hint.height();-
2701-
2702 bool tl_significant = corners[Qt::TopLeftCorner] == Qt::TopDockWidgetArea-
2703 || docks[QInternal::TopDock].isEmpty();-
2704 bool bl_significant = corners[Qt::BottomLeftCorner] == Qt::BottomDockWidgetArea-
2705 || docks[QInternal::BottomDock].isEmpty();-
2706 bool tr_significant = corners[Qt::TopRightCorner] == Qt::TopDockWidgetArea-
2707 || docks[QInternal::TopDock].isEmpty();-
2708 bool br_significant = corners[Qt::BottomRightCorner] == Qt::BottomDockWidgetArea-
2709 || docks[QInternal::BottomDock].isEmpty();-
2710-
2711 int left = (tl_significant && bl_significant) ? left_hint.height() : 0;-
2712 int right = (tr_significant && br_significant) ? right_hint.height() : 0;-
2713 ver_struct_list[1].sizeHint = qMax(left, center_hint.height(), right);-
2714-
2715 left = (tl_significant && bl_significant) ? left_min.height() : 0;-
2716 right = (tr_significant && br_significant) ? right_min.height() : 0;-
2717 ver_struct_list[1].minimumSize = qMax(left, center_min.height(), right);-
2718 ver_struct_list[1].maximumSize = center_max.height();-
2719 ver_struct_list[1].expansive = have_central;-
2720 ver_struct_list[1].empty = docks[QInternal::LeftDock].isEmpty()-
2721 && !have_central-
2722 && docks[QInternal::RightDock].isEmpty();-
2723 ver_struct_list[1].pos = center_rect.top();-
2724 ver_struct_list[1].size = center_rect.height();-
2725-
2726 // bottom ---------------------------------------------------
2727 ver_struct_list[2].init();-
2728 ver_struct_list[2].stretch = 0;-
2729 ver_struct_list[2].sizeHint = bottom_hint.height();-
2730 ver_struct_list[2].minimumSize = bottom_min.height();-
2731 ver_struct_list[2].maximumSize = bottom_max.height();-
2732 ver_struct_list[2].expansive = false;-
2733 ver_struct_list[2].empty = docks[QInternal::BottomDock].isEmpty();-
2734 ver_struct_list[2].pos = docks[QInternal::BottomDock].rect.top();-
2735 ver_struct_list[2].size = docks[QInternal::BottomDock].rect.height();-
2736-
2737 for (int i = 0; i < 3; ++i) {-
2738 ver_struct_list[i].sizeHint-
2739 = qMax(ver_struct_list[i].sizeHint, ver_struct_list[i].minimumSize);-
2740 }-
2741 if (have_central && ver_struct_list[0].empty && ver_struct_list[2].empty)-
2742 ver_struct_list[1].maximumSize = QWIDGETSIZE_MAX;-
2743 }-
2744-
2745 if (_hor_struct_list != 0) {-
2746 QVector<QLayoutStruct> &hor_struct_list = *_hor_struct_list;-
2747 hor_struct_list.resize(3);-
2748-
2749 // left ---------------------------------------------------
2750 hor_struct_list[0].init();-
2751 hor_struct_list[0].stretch = 0;-
2752 hor_struct_list[0].sizeHint = left_hint.width();-
2753 hor_struct_list[0].minimumSize = left_min.width();-
2754 hor_struct_list[0].maximumSize = left_max.width();-
2755 hor_struct_list[0].expansive = false;-
2756 hor_struct_list[0].empty = docks[QInternal::LeftDock].isEmpty();-
2757 hor_struct_list[0].pos = docks[QInternal::LeftDock].rect.left();-
2758 hor_struct_list[0].size = docks[QInternal::LeftDock].rect.width();-
2759-
2760 // center ---------------------------------------------------
2761 hor_struct_list[1].init();-
2762 hor_struct_list[1].stretch = center_hint.width();-
2763-
2764 bool tl_significant = corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea-
2765 || docks[QInternal::LeftDock].isEmpty();-
2766 bool tr_significant = corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea-
2767 || docks[QInternal::RightDock].isEmpty();-
2768 bool bl_significant = corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea-
2769 || docks[QInternal::LeftDock].isEmpty();-
2770 bool br_significant = corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea-
2771 || docks[QInternal::RightDock].isEmpty();-
2772-
2773 int top = (tl_significant && tr_significant) ? top_hint.width() : 0;-
2774 int bottom = (bl_significant && br_significant) ? bottom_hint.width() : 0;-
2775 hor_struct_list[1].sizeHint = qMax(top, center_hint.width(), bottom);-
2776-
2777 top = (tl_significant && tr_significant) ? top_min.width() : 0;-
2778 bottom = (bl_significant && br_significant) ? bottom_min.width() : 0;-
2779 hor_struct_list[1].minimumSize = qMax(top, center_min.width(), bottom);-
2780-
2781 hor_struct_list[1].maximumSize = center_max.width();-
2782 hor_struct_list[1].expansive = have_central;-
2783 hor_struct_list[1].empty = !have_central;-
2784 hor_struct_list[1].pos = center_rect.left();-
2785 hor_struct_list[1].size = center_rect.width();-
2786-
2787 // right ---------------------------------------------------
2788 hor_struct_list[2].init();-
2789 hor_struct_list[2].stretch = 0;-
2790 hor_struct_list[2].sizeHint = right_hint.width();-
2791 hor_struct_list[2].minimumSize = right_min.width();-
2792 hor_struct_list[2].maximumSize = right_max.width();-
2793 hor_struct_list[2].expansive = false;-
2794 hor_struct_list[2].empty = docks[QInternal::RightDock].isEmpty();-
2795 hor_struct_list[2].pos = docks[QInternal::RightDock].rect.left();-
2796 hor_struct_list[2].size = docks[QInternal::RightDock].rect.width();-
2797-
2798 for (int i = 0; i < 3; ++i) {-
2799 hor_struct_list[i].sizeHint-
2800 = qMax(hor_struct_list[i].sizeHint, hor_struct_list[i].minimumSize);-
2801 }-
2802 if (have_central && hor_struct_list[0].empty && hor_struct_list[2].empty)-
2803 hor_struct_list[1].maximumSize = QWIDGETSIZE_MAX;-
2804-
2805 }-
2806}-
2807-
2808void QDockAreaLayout::setGrid(QVector<QLayoutStruct> *ver_struct_list,-
2809 QVector<QLayoutStruct> *hor_struct_list)-
2810{-
2811-
2812 // top ----------------------------------------------------
2813-
2814 if (!docks[QInternal::TopDock].isEmpty()) {-
2815 QRect r = docks[QInternal::TopDock].rect;-
2816 if (hor_struct_list != 0) {-
2817 r.setLeft(corners[Qt::TopLeftCorner] == Qt::TopDockWidgetArea-
2818 || docks[QInternal::LeftDock].isEmpty()-
2819 ? rect.left() : hor_struct_list->at(1).pos);-
2820 r.setRight(corners[Qt::TopRightCorner] == Qt::TopDockWidgetArea-
2821 || docks[QInternal::RightDock].isEmpty()-
2822 ? rect.right() : hor_struct_list->at(2).pos - sep - 1);-
2823 }-
2824 if (ver_struct_list != 0) {-
2825 r.setTop(rect.top());-
2826 r.setBottom(ver_struct_list->at(1).pos - sep - 1);-
2827 }-
2828 docks[QInternal::TopDock].rect = r;-
2829 docks[QInternal::TopDock].fitItems();-
2830 }-
2831-
2832 // bottom ----------------------------------------------------
2833-
2834 if (!docks[QInternal::BottomDock].isEmpty()) {-
2835 QRect r = docks[QInternal::BottomDock].rect;-
2836 if (hor_struct_list != 0) {-
2837 r.setLeft(corners[Qt::BottomLeftCorner] == Qt::BottomDockWidgetArea-
2838 || docks[QInternal::LeftDock].isEmpty()-
2839 ? rect.left() : hor_struct_list->at(1).pos);-
2840 r.setRight(corners[Qt::BottomRightCorner] == Qt::BottomDockWidgetArea-
2841 || docks[QInternal::RightDock].isEmpty()-
2842 ? rect.right() : hor_struct_list->at(2).pos - sep - 1);-
2843 }-
2844 if (ver_struct_list != 0) {-
2845 r.setTop(ver_struct_list->at(2).pos);-
2846 r.setBottom(rect.bottom());-
2847 }-
2848 docks[QInternal::BottomDock].rect = r;-
2849 docks[QInternal::BottomDock].fitItems();-
2850 }-
2851-
2852 // left ----------------------------------------------------
2853-
2854 if (!docks[QInternal::LeftDock].isEmpty()) {-
2855 QRect r = docks[QInternal::LeftDock].rect;-
2856 if (hor_struct_list != 0) {-
2857 r.setLeft(rect.left());-
2858 r.setRight(hor_struct_list->at(1).pos - sep - 1);-
2859 }-
2860 if (ver_struct_list != 0) {-
2861 r.setTop(corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea-
2862 || docks[QInternal::TopDock].isEmpty()-
2863 ? rect.top() : ver_struct_list->at(1).pos);-
2864 r.setBottom(corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea-
2865 || docks[QInternal::BottomDock].isEmpty()-
2866 ? rect.bottom() : ver_struct_list->at(2).pos - sep - 1);-
2867 }-
2868 docks[QInternal::LeftDock].rect = r;-
2869 docks[QInternal::LeftDock].fitItems();-
2870 }-
2871-
2872 // right ----------------------------------------------------
2873-
2874 if (!docks[QInternal::RightDock].isEmpty()) {-
2875 QRect r = docks[QInternal::RightDock].rect;-
2876 if (hor_struct_list != 0) {-
2877 r.setLeft(hor_struct_list->at(2).pos);-
2878 r.setRight(rect.right());-
2879 }-
2880 if (ver_struct_list != 0) {-
2881 r.setTop(corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea-
2882 || docks[QInternal::TopDock].isEmpty()-
2883 ? rect.top() : ver_struct_list->at(1).pos);-
2884 r.setBottom(corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea-
2885 || docks[QInternal::BottomDock].isEmpty()-
2886 ? rect.bottom() : ver_struct_list->at(2).pos - sep - 1);-
2887 }-
2888 docks[QInternal::RightDock].rect = r;-
2889 docks[QInternal::RightDock].fitItems();-
2890 }-
2891-
2892 // center ----------------------------------------------------
2893-
2894 if (hor_struct_list != 0) {-
2895 centralWidgetRect.setLeft(hor_struct_list->at(1).pos);-
2896 centralWidgetRect.setWidth(hor_struct_list->at(1).size);-
2897 }-
2898 if (ver_struct_list != 0) {-
2899 centralWidgetRect.setTop(ver_struct_list->at(1).pos);-
2900 centralWidgetRect.setHeight(ver_struct_list->at(1).size);-
2901 }-
2902}-
2903-
2904void QDockAreaLayout::fitLayout()-
2905{-
2906 QVector<QLayoutStruct> ver_struct_list(3);-
2907 QVector<QLayoutStruct> hor_struct_list(3);-
2908 getGrid(&ver_struct_list, &hor_struct_list);-
2909-
2910 qGeomCalc(ver_struct_list, 0, 3, rect.top(), rect.height(), sep);-
2911 qGeomCalc(hor_struct_list, 0, 3, rect.left(), rect.width(), sep);-
2912-
2913 setGrid(&ver_struct_list, &hor_struct_list);-
2914}-
2915-
2916void QDockAreaLayout::clear()-
2917{-
2918 for (int i = 0; i < QInternal::DockCount; ++i)-
2919 docks[i].clear();-
2920-
2921 rect = QRect();-
2922 centralWidgetRect = QRect();-
2923}-
2924-
2925QSize QDockAreaLayout::sizeHint() const-
2926{-
2927 int left_sep = 0;-
2928 int right_sep = 0;-
2929 int top_sep = 0;-
2930 int bottom_sep = 0;-
2931-
2932 if (centralWidgetItem != 0) {-
2933 left_sep = docks[QInternal::LeftDock].isEmpty() ? 0 : sep;-
2934 right_sep = docks[QInternal::RightDock].isEmpty() ? 0 : sep;-
2935 top_sep = docks[QInternal::TopDock].isEmpty() ? 0 : sep;-
2936 bottom_sep = docks[QInternal::BottomDock].isEmpty() ? 0 : sep;-
2937 }-
2938-
2939 QSize left = docks[QInternal::LeftDock].sizeHint() + QSize(left_sep, 0);-
2940 QSize right = docks[QInternal::RightDock].sizeHint() + QSize(right_sep, 0);-
2941 QSize top = docks[QInternal::TopDock].sizeHint() + QSize(0, top_sep);-
2942 QSize bottom = docks[QInternal::BottomDock].sizeHint() + QSize(0, bottom_sep);-
2943 QSize center = centralWidgetItem == 0 ? QSize(0, 0) : centralWidgetItem->sizeHint();-
2944-
2945 int row1 = top.width();-
2946 int row2 = left.width() + center.width() + right.width();-
2947 int row3 = bottom.width();-
2948 int col1 = left.height();-
2949 int col2 = top.height() + center.height() + bottom.height();-
2950 int col3 = right.height();-
2951-
2952 if (corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea)-
2953 row1 += left.width();-
2954 else-
2955 col1 += top.height();-
2956-
2957 if (corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea)-
2958 row1 += right.width();-
2959 else-
2960 col3 += top.height();-
2961-
2962 if (corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea)-
2963 row3 += left.width();-
2964 else-
2965 col1 += bottom.height();-
2966-
2967 if (corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea)-
2968 row3 += right.width();-
2969 else-
2970 col3 += bottom.height();-
2971-
2972 return QSize(qMax(row1, row2, row3), qMax(col1, col2, col3));-
2973}-
2974-
2975QSize QDockAreaLayout::minimumSize() const-
2976{-
2977 int left_sep = 0;-
2978 int right_sep = 0;-
2979 int top_sep = 0;-
2980 int bottom_sep = 0;-
2981-
2982 if (centralWidgetItem != 0) {-
2983 left_sep = docks[QInternal::LeftDock].isEmpty() ? 0 : sep;-
2984 right_sep = docks[QInternal::RightDock].isEmpty() ? 0 : sep;-
2985 top_sep = docks[QInternal::TopDock].isEmpty() ? 0 : sep;-
2986 bottom_sep = docks[QInternal::BottomDock].isEmpty() ? 0 : sep;-
2987 }-
2988-
2989 QSize left = docks[QInternal::LeftDock].minimumSize() + QSize(left_sep, 0);-
2990 QSize right = docks[QInternal::RightDock].minimumSize() + QSize(right_sep, 0);-
2991 QSize top = docks[QInternal::TopDock].minimumSize() + QSize(0, top_sep);-
2992 QSize bottom = docks[QInternal::BottomDock].minimumSize() + QSize(0, bottom_sep);-
2993 QSize center = centralWidgetItem == 0 ? QSize(0, 0) : centralWidgetItem->minimumSize();-
2994-
2995 int row1 = top.width();-
2996 int row2 = left.width() + center.width() + right.width();-
2997 int row3 = bottom.width();-
2998 int col1 = left.height();-
2999 int col2 = top.height() + center.height() + bottom.height();-
3000 int col3 = right.height();-
3001-
3002 if (corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea)-
3003 row1 += left.width();-
3004 else-
3005 col1 += top.height();-
3006-
3007 if (corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea)-
3008 row1 += right.width();-
3009 else-
3010 col3 += top.height();-
3011-
3012 if (corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea)-
3013 row3 += left.width();-
3014 else-
3015 col1 += bottom.height();-
3016-
3017 if (corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea)-
3018 row3 += right.width();-
3019 else-
3020 col3 += bottom.height();-
3021-
3022 return QSize(qMax(row1, row2, row3), qMax(col1, col2, col3));-
3023}-
3024-
3025/*! \internal-
3026 Try to fit the given rectangle \a rect on the screen which contains-
3027 the window \a widget.-
3028 Used to compute the geometry of a dragged a dock widget that should-
3029 be shown with \a rect, but needs to be visible on the screen-
3030 */-
3031QRect QDockAreaLayout::constrainedRect(QRect rect, QWidget* widget)-
3032{-
3033 QRect desktop;-
3034 QDesktopWidget *desktopW = QApplication::desktop();-
3035 if (desktopW->isVirtualDesktop())-
3036 desktop = desktopW->screenGeometry(rect.topLeft());-
3037 else-
3038 desktop = desktopW->screenGeometry(widget);-
3039-
3040 if (desktop.isValid()) {-
3041 rect.setWidth(qMin(rect.width(), desktop.width()));-
3042 rect.setHeight(qMin(rect.height(), desktop.height()));-
3043 rect.moveLeft(qMax(rect.left(), desktop.left()));-
3044 rect.moveTop(qMax(rect.top(), desktop.top()));-
3045 rect.moveRight(qMin(rect.right(), desktop.right()));-
3046 rect.moveBottom(qMin(rect.bottom(), desktop.bottom()));-
3047 }-
3048-
3049 return rect;-
3050}-
3051-
3052bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget)-
3053{-
3054 QDockAreaLayoutItem *item = 0;-
3055 foreach (QDockWidgetGroupWindow *dwgw, mainWindow->findChildren<QDockWidgetGroupWindow *>(-
3056 QString(), Qt::FindDirectChildrenOnly)) {-
3057 QList<int> index = dwgw->layoutInfo()->indexOfPlaceHolder(dockWidget->objectName());-
3058 if (!index.isEmpty()) {-
3059 dockWidget->setParent(dwgw);-
3060 item = const_cast<QDockAreaLayoutItem *>(&dwgw->layoutInfo()->item(index));-
3061 break;-
3062 }-
3063 }-
3064 if (!item) {-
3065 QList<int> index = indexOfPlaceHolder(dockWidget->objectName());-
3066 if (index.isEmpty())-
3067 return false;-
3068 item = const_cast<QDockAreaLayoutItem *>(&this->item(index));-
3069 }-
3070-
3071 QPlaceHolderItem *placeHolder = item->placeHolderItem;-
3072 Q_ASSERT(placeHolder != 0);-
3073-
3074 item->widgetItem = new QDockWidgetItem(dockWidget);-
3075-
3076 if (placeHolder->window) {-
3077 const QRect r = constrainedRect(placeHolder->topLevelRect, dockWidget);-
3078 dockWidget->d_func()->setWindowState(true, true, r);-
3079 }-
3080 dockWidget->setVisible(!placeHolder->hidden);-
3081#ifdef Q_DEAD_CODE_FROM_QT4_X11-
3082 if (placeHolder->window) // gets rid of the X11BypassWindowManager window flag-
3083 dockWidget->d_func()->setWindowState(true);-
3084#endif-
3085-
3086 item->placeHolderItem = 0;-
3087 delete placeHolder;-
3088-
3089 return true;-
3090}-
3091-
3092void QDockAreaLayout::addDockWidget(QInternal::DockPosition pos, QDockWidget *dockWidget,-
3093 Qt::Orientation orientation)-
3094{-
3095 QLayoutItem *dockWidgetItem = new QDockWidgetItem(dockWidget);-
3096 QDockAreaLayoutInfo &info = docks[pos];-
3097 if (orientation == info.o || info.item_list.count() <= 1) {
orientation == info.oDescription
TRUEnever evaluated
FALSEnever evaluated
info.item_list.count() <= 1Description
TRUEnever evaluated
FALSEnever evaluated
0
3098 // empty dock areas, or dock areas containing exactly one widget can have their orientation-
3099 // switched.-
3100 info.o = orientation;-
3101-
3102 QDockAreaLayoutItem new_item(dockWidgetItem);-
3103 info.item_list.append(new_item);-
3104#ifndef QT_NO_TABBAR-
3105 if (info.tabbed && !new_item.skip()) {
info.tabbedDescription
TRUEnever evaluated
FALSEnever evaluated
!new_item.skip()Description
TRUEnever evaluated
FALSEnever evaluated
0
3106 info.updateTabBar();-
3107 info.setCurrentTabId(tabId(new_item));-
3108 }
never executed: end of block
0
3109#endif-
3110 } else {
never executed: end of block
0
3111#ifndef QT_NO_TABBAR-
3112 int tbshape = info.tabBarShape;-
3113#else-
3114 int tbshape = 0;-
3115#endif-
3116 QDockAreaLayoutInfo new_info(&sep, pos, orientation, tbshape, mainWindow);-
3117 new_info.item_list.append(QDockAreaLayoutItem(new QDockAreaLayoutInfo(info));)));-
3118 new_info.item_list.append(QDockAreaLayoutItem(dockWidgetItem);));-
3119 info = new_info;-
3120 }
never executed: end of block
0
3121-
3122 removePlaceHolder(dockWidget->objectName());-
3123}
never executed: end of block
0
3124-
3125void QDockAreaLayout::tabifyDockWidget(QDockWidget *first, QDockWidget *second)-
3126{-
3127 const QList<int> path = indexOf(first);-
3128 if (path.isEmpty())
path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3129 return;
never executed: return;
0
3130-
3131 QDockAreaLayoutInfo *info = this->info(path);-
3132 Q_ASSERT(info != 0);-
3133 info->tab(path.last(), new QDockWidgetItem(second));-
3134-
3135 removePlaceHolder(second->objectName());-
3136}
never executed: end of block
0
3137-
3138void QDockAreaLayout::resizeDocks(const QList<QDockWidget *> &docks,-
3139 const QList<int> &sizes, Qt::Orientation o)-
3140{-
3141 if (Q_UNLIKELY(docks.count() != sizes.count())())) {
__builtin_expe...unt()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
3142 qWarning("QMainWidget::resizeDocks: size of the lists are not the same");-
3143 return;
never executed: return;
0
3144 }-
3145 int count = docks.count();-
3146 fallbackToSizeHints = false;-
3147 for (int i = 0; i < count; ++i) {
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
3148 QList<int> path = indexOf(docks[i]);-
3149 if (Q_UNLIKELY(path.isEmpty())())) {
__builtin_expe...pty()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
3150 qWarning("QMainWidget::resizeDocks: one QDockWidget is not part of the layout");-
3151 continue;
never executed: continue;
0
3152 }-
3153 int size = sizes[i];-
3154 if (Q_UNLIKELY(size <= 0))) {
__builtin_expe... <= 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
3155 qWarning("QMainWidget::resizeDocks: all sizes need to be larger than 0");-
3156 size = 1;-
3157 }
never executed: end of block
0
3158-
3159 while (path.size() > 1) {
path.size() > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
3160 QDockAreaLayoutInfo *info = this->info(path);-
3161 if (!info->tabbed && info->o == o) {
!info->tabbedDescription
TRUEnever evaluated
FALSEnever evaluated
info->o == oDescription
TRUEnever evaluated
FALSEnever evaluated
0
3162 info->item_list[path.lastconstLast()].size = size;-
3163 int totalSize = 0;-
3164 foreach (const QDockAreaLayoutItem &item, info->item_list) {-
3165 if (!item.skip()) {
!item.skip()Description
TRUEnever evaluated
FALSEnever evaluated
0
3166 if (totalSize != 0)
totalSize != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
3167 totalSize += sep;
never executed: totalSize += sep;
0
3168 totalSize += item.size == -1 ? pick(o, item.sizeHint()) : item.size;
item.size == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
3169 }
never executed: end of block
0
3170 }
never executed: end of block
0
3171 size = totalSize;-
3172 }
never executed: end of block
0
3173 path.removeLast();-
3174 }
never executed: end of block
0
3175-
3176 const int dockNum = path.firstconstFirst();-
3177 Q_ASSERT(dockNum < QInternal::DockCount);-
3178 QRect &r = this->docks[dockNum].rect;-
3179 QSize s = r.size();-
3180 rpick(o, s) = size;-
3181 r.setSize(s);-
3182 }
never executed: end of block
0
3183}
never executed: end of block
0
3184-
3185void QDockAreaLayout::splitDockWidget(QDockWidget *after,-
3186 QDockWidget *dockWidget,-
3187 Qt::Orientation orientation)-
3188{-
3189 const QList<int> path = indexOf(after);-
3190 if (path.isEmpty())
path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3191 return;
never executed: return;
0
3192-
3193 QDockAreaLayoutInfo *info = this->info(path);-
3194 Q_ASSERT(info != 0);-
3195 info->split(path.last(), orientation, new QDockWidgetItem(dockWidget));-
3196-
3197 removePlaceHolder(dockWidget->objectName());-
3198}
never executed: end of block
0
3199-
3200void QDockAreaLayout::apply(bool animate)-
3201{-
3202 QWidgetAnimator &widgetAnimator = qt_mainwindow_layout(mainWindow)->widgetAnimator;-
3203-
3204 for (int i = 0; i < QInternal::DockCount; ++i)-
3205 docks[i].apply(animate);-
3206 if (centralWidgetItem != 0 && !centralWidgetItem->isEmpty()) {-
3207 widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect,-
3208 animate);-
3209 }-
3210#ifndef QT_NO_TABBAR-
3211 if (sep == 1)-
3212 updateSeparatorWidgets();-
3213#endif //QT_NO_TABBAR-
3214}-
3215-
3216void QDockAreaLayout::paintSeparators(QPainter *p, QWidget *widget,-
3217 const QRegion &clip,-
3218 const QPoint &mouse) const-
3219{-
3220 for (int i = 0; i < QInternal::DockCount; ++i) {-
3221 const QDockAreaLayoutInfo &dock = docks[i];-
3222 if (dock.isEmpty())-
3223 continue;-
3224 QRect r = separatorRect(i);-
3225 if (clip.contains(r) && !dock.hasFixedSize()) {-
3226 Qt::Orientation opposite = dock.o == Qt::Horizontal-
3227 ? Qt::Vertical : Qt::Horizontal;-
3228 paintSep(p, widget, r, opposite, r.contains(mouse));-
3229 }-
3230 if (clip.contains(dock.rect))-
3231 dock.paintSeparators(p, widget, clip, mouse);-
3232 }-
3233}-
3234-
3235QRegion QDockAreaLayout::separatorRegion() const-
3236{-
3237 QRegion result;-
3238-
3239 for (int i = 0; i < QInternal::DockCount; ++i) {-
3240 const QDockAreaLayoutInfo &dock = docks[i];-
3241 if (dock.isEmpty())-
3242 continue;-
3243 result |= separatorRect(i);-
3244 result |= dock.separatorRegion();-
3245 }-
3246-
3247 return result;-
3248}-
3249-
3250int QDockAreaLayout::separatorMove(const QList<int> &separator, const QPoint &origin,-
3251 const QPoint &dest)-
3252{-
3253 int delta = 0;-
3254 int index = separator.last();-
3255-
3256 if (separator.count() > 1) {-
3257 QDockAreaLayoutInfo *info = this->info(separator);-
3258 delta = pick(info->o, dest - origin);-
3259 if (delta != 0)-
3260 delta = info->separatorMove(index, delta);-
3261 info->apply(false);-
3262 return delta;-
3263 }-
3264-
3265 QVector<QLayoutStruct> list;-
3266-
3267 if (index == QInternal::LeftDock || index == QInternal::RightDock)-
3268 getGrid(0, &list);-
3269 else-
3270 getGrid(&list, 0);-
3271-
3272 int sep_index = index == QInternal::LeftDock || index == QInternal::TopDock-
3273 ? 0 : 1;-
3274 Qt::Orientation o = index == QInternal::LeftDock || index == QInternal::RightDock-
3275 ? Qt::Horizontal-
3276 : Qt::Vertical;-
3277-
3278 delta = pick(o, dest - origin);-
3279 delta = separatorMoveHelper(list, sep_index, delta, sep);-
3280-
3281 if (index == QInternal::LeftDock || index == QInternal::RightDock)-
3282 setGrid(0, &list);-
3283 else-
3284 setGrid(&list, 0);-
3285-
3286 apply(false);-
3287-
3288 return delta;-
3289}-
3290-
3291#ifndef QT_NO_TABBAR-
3292// Sets the correct positions for the separator widgets-
3293// Allocates new sepearator widgets with getSeparatorWidget-
3294void QDockAreaLayout::updateSeparatorWidgets() const-
3295{-
3296 int j = 0;-
3297-
3298 for (int i = 0; i < QInternal::DockCount; ++i) {-
3299 const QDockAreaLayoutInfo &dock = docks[i];-
3300 if (dock.isEmpty())-
3301 continue;-
3302-
3303 QWidget *sepWidget;-
3304 if (j < separatorWidgets.size()) {-
3305 sepWidget = separatorWidgets.at(j);-
3306 } else {-
3307 sepWidget = qt_mainwindow_layout(mainWindow)->getSeparatorWidget();-
3308 separatorWidgets.append(sepWidget);-
3309 }-
3310 j++;-
3311-
3312#ifndef Q_DEAD_CODE_FROM_QT4_MAC-
3313 sepWidget->raise();-
3314#endif-
3315 QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2);-
3316 sepWidget->setGeometry(sepRect);-
3317 sepWidget->setMask( QRegion(separatorRect(i).translated( - sepRect.topLeft())));-
3318 sepWidget->show();-
3319 }-
3320 for (int i = j; i < separatorWidgets.size(); ++i)-
3321 separatorWidgets.at(i)->hide();-
3322-
3323 separatorWidgets.resize(j);-
3324}-
3325#endif //QT_NO_TABBAR-
3326-
3327QLayoutItem *QDockAreaLayout::itemAt(int *x, int index) const-
3328{-
3329 Q_ASSERT(x != 0);-
3330-
3331 for (int i = 0; i < QInternal::DockCount; ++i) {-
3332 const QDockAreaLayoutInfo &dock = docks[i];-
3333 if (QLayoutItem *ret = dock.itemAt(x, index))-
3334 return ret;-
3335 }-
3336-
3337 if (centralWidgetItem && (*x)++ == index)-
3338 return centralWidgetItem;-
3339-
3340 return 0;-
3341}-
3342-
3343QLayoutItem *QDockAreaLayout::takeAt(int *x, int index)-
3344{-
3345 Q_ASSERT(x != 0);-
3346-
3347 for (int i = 0; i < QInternal::DockCount; ++i) {-
3348 QDockAreaLayoutInfo &dock = docks[i];-
3349 if (QLayoutItem *ret = dock.takeAt(x, index))-
3350 return ret;-
3351 }-
3352-
3353 if (centralWidgetItem && (*x)++ == index) {-
3354 QLayoutItem *ret = centralWidgetItem;-
3355 centralWidgetItem = 0;-
3356 return ret;-
3357 }-
3358-
3359 return 0;-
3360}-
3361-
3362void QDockAreaLayout::deleteAllLayoutItems()-
3363{-
3364 for (int i = 0; i < QInternal::DockCount; ++i)-
3365 docks[i].deleteAllLayoutItems();-
3366}-
3367-
3368#ifndef QT_NO_TABBAR-
3369QSet<QTabBar*> QDockAreaLayout::usedTabBars() const-
3370{-
3371 QSet<QTabBar*> result;-
3372 for (int i = 0; i < QInternal::DockCount; ++i) {-
3373 const QDockAreaLayoutInfo &dock = docks[i];-
3374 result += dock.usedTabBars();-
3375 }-
3376 return result;-
3377}-
3378-
3379// Returns the set of all used separator widgets-
3380QSet<QWidget*> QDockAreaLayout::usedSeparatorWidgets() const-
3381{-
3382 QSet<QWidget*> result;-
3383 const int numSeparators = separatorWidgets.count();-
3384 result.reserve(numSeparators);-
3385 for (int i = 0; i < numSeparators; ++i)-
3386 result << separatorWidgets.at(i);-
3387 for (int i = 0; i < QInternal::DockCount; ++i) {-
3388 const QDockAreaLayoutInfo &dock = docks[i];-
3389 result += dock.usedSeparatorWidgets();-
3390 }-
3391 return result;-
3392}-
3393#endif-
3394-
3395QRect QDockAreaLayout::gapRect(const QList<int> &path) const-
3396{-
3397 const QDockAreaLayoutInfo *info = this->info(path);-
3398 if (info == 0)-
3399 return QRect();-
3400 const QList<QDockAreaLayoutItem> &item_list = info->item_list;-
3401 Qt::Orientation o = info->o;-
3402 int index = path.last();-
3403 if (index < 0 || index >= item_list.count())-
3404 return QRect();-
3405 const QDockAreaLayoutItem &item = item_list.at(index);-
3406 if (!(item.flags & QDockAreaLayoutItem::GapItem))-
3407 return QRect();-
3408-
3409 QRect result;-
3410-
3411#ifndef QT_NO_TABBAR-
3412 if (info->tabbed) {-
3413 result = info->tabContentRect();-
3414 } else-
3415#endif-
3416 {-
3417 int pos = item.pos;-
3418 int size = item.size;-
3419-
3420 int prev = info->prev(index);-
3421 int next = info->next(index);-
3422-
3423 if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) {-
3424 pos += sep;-
3425 size -= sep;-
3426 }-
3427 if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem))-
3428 size -= sep;-
3429-
3430 QPoint p;-
3431 rpick(o, p) = pos;-
3432 rperp(o, p) = perp(o, info->rect.topLeft());-
3433 QSize s;-
3434 rpick(o, s) = size;-
3435 rperp(o, s) = perp(o, info->rect.size());-
3436-
3437 result = QRect(p, s);-
3438 }-
3439-
3440 return result;-
3441}-
3442-
3443void QDockAreaLayout::keepSize(QDockWidget *w)-
3444{-
3445 QList<int> path = indexOf(w);-
3446 if (path.isEmpty())-
3447 return;-
3448 QDockAreaLayoutItem &item = this->item(path);-
3449 if (item.size != -1)-
3450 item.flags |= QDockAreaLayoutItem::KeepSize;-
3451}-
3452-
3453void QDockAreaLayout::styleChangedEvent()-
3454{-
3455 sep = mainWindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainWindow);-
3456 if (isValid())-
3457 fitLayout();-
3458}-
3459-
3460QT_END_NAMESPACE-
3461-
3462#endif // QT_NO_DOCKWIDGET-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9