Qt 4.8
qmainwindowlayout.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qmainwindowlayout_p.h"
43 #include "qdockarealayout_p.h"
44 
45 #ifndef QT_NO_MAINWINDOW
46 #include "qdockwidget.h"
47 #include "qdockwidget_p.h"
48 #include "qtoolbar_p.h"
49 #include "qmainwindow.h"
50 #include "qmainwindowlayout_p.h"
51 #include "qtoolbar.h"
52 #include "qtoolbarlayout_p.h"
53 #include "qwidgetanimator_p.h"
54 #include "qrubberband.h"
55 #include "qdockwidget_p.h"
56 #include "qtabbar_p.h"
57 
58 #include <qapplication.h>
59 #include <qstatusbar.h>
60 #include <qstring.h>
61 #include <qstyle.h>
62 #include <qvarlengtharray.h>
63 #include <qstack.h>
64 #include <qmap.h>
65 #include <qtimer.h>
66 
67 #include <qdebug.h>
68 
69 #include <private/qapplication_p.h>
70 #include <private/qlayoutengine_p.h>
71 #ifdef Q_WS_MAC
72 # include <private/qcore_mac_p.h>
73 # include <private/qt_cocoa_helpers_mac_p.h>
74 #endif
75 
76 #ifdef QT_NO_DOCKWIDGET
78 #endif
79 
80 #ifdef Q_DEBUG_MAINWINDOW_LAYOUT
81 # include <QTextStream>
82 #endif
83 
85 
86 /******************************************************************************
87 ** debug
88 */
89 
90 #if defined(Q_DEBUG_MAINWINDOW_LAYOUT) && !defined(QT_NO_DOCKWIDGET)
91 
92 static QTextStream qout(stderr, QIODevice::WriteOnly);
93 
94 static void dumpLayout(QTextStream &qout, const QDockAreaLayoutInfo &layout, QString indent);
95 
96 static void dumpLayout(QTextStream &qout, const QDockAreaLayoutItem &item, QString indent)
97 {
98  qout << indent << "QDockAreaLayoutItem: "
99  << "pos: " << item.pos << " size:" << item.size
100  << " gap:" << (item.flags & QDockAreaLayoutItem::GapItem)
101  << " keepSize:" << (item.flags & QDockAreaLayoutItem::KeepSize) << '\n';
102  indent += QLatin1String(" ");
103  if (item.widgetItem != 0) {
104  qout << indent << "widget: "
105  << item.widgetItem->widget()->metaObject()->className()
106  << ' ' << item.widgetItem->widget()->windowTitle() << '\n';
107  } else if (item.subinfo != 0) {
108  qout << indent << "subinfo:\n";
109  dumpLayout(qout, *item.subinfo, indent + QLatin1String(" "));
110  } else if (item.placeHolderItem != 0) {
112  qout << indent << "placeHolder: "
113  << "pos: " << item.pos << " size:" << item.size
114  << " gap:" << (item.flags & QDockAreaLayoutItem::GapItem)
115  << " keepSize:" << (item.flags & QDockAreaLayoutItem::KeepSize)
116  << " objectName:" << item.placeHolderItem->objectName
117  << " hidden:" << item.placeHolderItem->hidden
118  << " window:" << item.placeHolderItem->window
119  << " rect:" << r.x() << ',' << r.y() << ' '
120  << r.width() << 'x' << r.height() << '\n';
121  }
122  qout.flush();
123 }
124 
125 static void dumpLayout(QTextStream &qout, const QDockAreaLayoutInfo &layout, QString indent)
126 {
127  qout << indent << "QDockAreaLayoutInfo: "
128  << layout.rect.left() << ','
129  << layout.rect.top() << ' '
130  << layout.rect.width() << 'x'
131  << layout.rect.height()
132  << " orient:" << layout.o
133  << " tabbed:" << layout.tabbed
134  << " tbshape:" << layout.tabBarShape << '\n';
135 
136  indent += QLatin1String(" ");
137 
138  for (int i = 0; i < layout.item_list.count(); ++i) {
139  qout << indent << "Item: " << i << '\n';
140  dumpLayout(qout, layout.item_list.at(i), indent + QLatin1String(" "));
141  }
142  qout.flush();
143 };
144 
145 static void dumpLayout(QTextStream &qout, const QDockAreaLayout &layout, QString indent)
146 {
147  qout << indent << "QDockAreaLayout: "
148  << layout.rect.left() << ','
149  << layout.rect.top() << ' '
150  << layout.rect.width() << 'x'
151  << layout.rect.height() << '\n';
152 
153  qout << indent << "TopDockArea:\n";
154  dumpLayout(qout, layout.docks[QInternal::TopDock], indent + QLatin1String(" "));
155  qout << indent << "LeftDockArea:\n";
156  dumpLayout(qout, layout.docks[QInternal::LeftDock], indent + QLatin1String(" "));
157  qout << indent << "RightDockArea:\n";
158  dumpLayout(qout, layout.docks[QInternal::RightDock], indent + QLatin1String(" "));
159  qout << indent << "BottomDockArea:\n";
160  dumpLayout(qout, layout.docks[QInternal::BottomDock], indent + QLatin1String(" "));
161 
162  qout.flush();
163 };
164 
165 void qt_dumpLayout(QTextStream &qout, QMainWindow *window)
166 {
167  QMainWindowLayout *layout = qt_mainwindow_layout(window);
168  dumpLayout(qout, layout->layoutState.dockAreaLayout, QString());
169 }
170 
171 #endif // Q_DEBUG_MAINWINDOW_LAYOUT && !QT_NO_DOCKWIDGET
172 
173 /******************************************************************************
174 ** QMainWindowLayoutState
175 */
176 
177 // we deal with all the #ifndefferry here so QMainWindowLayout code is clean
178 
180  :
181 #ifndef QT_NO_TOOLBAR
182  toolBarAreaLayout(win),
183 #endif
184 #ifndef QT_NO_DOCKWIDGET
185  dockAreaLayout(win)
186 #else
187  centralWidgetItem(0)
188 #endif
189 
190 {
191  mainWindow = win;
192 }
193 
195 {
196 
197  QSize result(0, 0);
198 
199 #ifndef QT_NO_DOCKWIDGET
200  result = dockAreaLayout.sizeHint();
201 #else
202  if (centralWidgetItem != 0)
203  result = centralWidgetItem->sizeHint();
204 #endif
205 
206 #ifndef QT_NO_TOOLBAR
207  result = toolBarAreaLayout.sizeHint(result);
208 #endif // QT_NO_TOOLBAR
209 
210  return result;
211 }
212 
214 {
215  QSize result(0, 0);
216 
217 #ifndef QT_NO_DOCKWIDGET
218  result = dockAreaLayout.minimumSize();
219 #else
220  if (centralWidgetItem != 0)
221  result = centralWidgetItem->minimumSize();
222 #endif
223 
224 #ifndef QT_NO_TOOLBAR
225  result = toolBarAreaLayout.minimumSize(result);
226 #endif // QT_NO_TOOLBAR
227 
228  return result;
229 }
230 
231 void QMainWindowLayoutState::apply(bool animated)
232 {
233 #ifndef QT_NO_TOOLBAR
234  toolBarAreaLayout.apply(animated);
235 #endif
236 
237 #ifndef QT_NO_DOCKWIDGET
238 // dumpLayout(dockAreaLayout, QString());
239  dockAreaLayout.apply(animated);
240 #else
241  if (centralWidgetItem != 0) {
243  Q_ASSERT(layout != 0);
244  layout->widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect, animated);
245  }
246 #endif
247 }
248 
250 {
251  QRect r;
252 #ifdef QT_NO_TOOLBAR
253  r = rect;
254 #else
257 #endif // QT_NO_TOOLBAR
258 
259 #ifndef QT_NO_DOCKWIDGET
260  dockAreaLayout.rect = r;
262 #else
263  centralWidgetRect = r;
264 #endif
265 }
266 
268 {
269 #ifndef QT_NO_TOOLBAR
271 #endif
272 
273 #ifndef QT_NO_DOCKWIDGET
275 #endif
276 }
277 
279 {
280 #ifndef QT_NO_DOCKWIDGET
283 #else
284  delete centralWidgetItem;
285  centralWidgetItem = 0;
286 #endif
287 }
288 
290 {
291 #ifndef QT_NO_TOOLBAR
292  if (QLayoutItem *ret = toolBarAreaLayout.itemAt(x, index))
293  return ret;
294 #endif
295 
296 #ifndef QT_NO_DOCKWIDGET
297  if (QLayoutItem *ret = dockAreaLayout.itemAt(x, index))
298  return ret;
299 #else
300  if (centralWidgetItem != 0 && (*x)++ == index)
301  return centralWidgetItem;
302 #endif
303 
304  return 0;
305 }
306 
308 {
309 #ifndef QT_NO_TOOLBAR
310  if (QLayoutItem *ret = toolBarAreaLayout.takeAt(x, index))
311  return ret;
312 #endif
313 
314 #ifndef QT_NO_DOCKWIDGET
315  if (QLayoutItem *ret = dockAreaLayout.takeAt(x, index))
316  return ret;
317 #else
318  if (centralWidgetItem != 0 && (*x)++ == index) {
319  QLayoutItem *ret = centralWidgetItem;
320  centralWidgetItem = 0;
321  return ret;
322  }
323 #endif
324 
325  return 0;
326 }
327 
329 {
330  QList<int> result;
331 
332 #ifndef QT_NO_TOOLBAR
333  // is it a toolbar?
334  if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) {
335  result = toolBarAreaLayout.indexOf(toolBar);
336  if (!result.isEmpty())
337  result.prepend(0);
338  return result;
339  }
340 #endif
341 
342 #ifndef QT_NO_DOCKWIDGET
343  // is it a dock widget?
344  if (QDockWidget *dockWidget = qobject_cast<QDockWidget *>(widget)) {
345  result = dockAreaLayout.indexOf(dockWidget);
346  if (!result.isEmpty())
347  result.prepend(1);
348  return result;
349  }
350 #endif //QT_NO_DOCKWIDGET
351 
352  return result;
353 }
354 
356 {
357 #ifndef QT_NO_DOCKWIDGET
359  return true;
360  if (!dockAreaLayout.indexOf(widget).isEmpty())
361  return true;
362 #else
363  if (centralWidgetItem != 0 && centralWidgetItem->widget() == widget)
364  return true;
365 #endif
366 
367 #ifndef QT_NO_TOOLBAR
368  if (!toolBarAreaLayout.indexOf(widget).isEmpty())
369  return true;
370 #endif
371  return false;
372 }
373 
375 {
376  QLayoutItem *item = 0;
377  //make sure we remove the widget
379 
380  if (widget != 0)
381  item = new QWidgetItemV2(widget);
382 
383 #ifndef QT_NO_DOCKWIDGET
385 #else
386  centralWidgetItem = item;
387 #endif
388 }
389 
391 {
392  QLayoutItem *item = 0;
393 
394 #ifndef QT_NO_DOCKWIDGET
396 #else
397  item = centralWidgetItem;
398 #endif
399 
400  if (item != 0)
401  return item->widget();
402  return 0;
403 }
404 
406  const QPoint &pos) const
407 {
408  QList<int> result;
409 
410 #ifndef QT_NO_TOOLBAR
411  // is it a toolbar?
412  if (qobject_cast<QToolBar*>(widget) != 0) {
413  result = toolBarAreaLayout.gapIndex(pos);
414  if (!result.isEmpty())
415  result.prepend(0);
416  return result;
417  }
418 #endif
419 
420 #ifndef QT_NO_DOCKWIDGET
421  // is it a dock widget?
422  if (qobject_cast<QDockWidget *>(widget) != 0) {
423  result = dockAreaLayout.gapIndex(pos);
424  if (!result.isEmpty())
425  result.prepend(1);
426  return result;
427  }
428 #endif //QT_NO_DOCKWIDGET
429 
430  return result;
431 }
432 
434 {
435  if (path.isEmpty())
436  return false;
437 
438  int i = path.first();
439 
440 #ifndef QT_NO_TOOLBAR
441  if (i == 0) {
442  Q_ASSERT(qobject_cast<QToolBar*>(item->widget()) != 0);
443  return toolBarAreaLayout.insertGap(path.mid(1), item);
444  }
445 #endif
446 
447 #ifndef QT_NO_DOCKWIDGET
448  if (i == 1) {
449  Q_ASSERT(qobject_cast<QDockWidget*>(item->widget()) != 0);
450  return dockAreaLayout.insertGap(path.mid(1), item);
451  }
452 #endif //QT_NO_DOCKWIDGET
453 
454  return false;
455 }
456 
458 {
459  int i = path.first();
460 
461 #ifndef QT_NO_TOOLBAR
462  if (i == 0)
463  toolBarAreaLayout.remove(path.mid(1));
464 #endif
465 
466 #ifndef QT_NO_DOCKWIDGET
467  if (i == 1)
468  dockAreaLayout.remove(path.mid(1));
469 #endif //QT_NO_DOCKWIDGET
470 }
471 
473 {
474 #ifndef QT_NO_TOOLBAR
476 #endif
477 
478 #ifndef QT_NO_DOCKWIDGET
479  // is it a dock widget?
480  if (QDockWidget *dockWidget = qobject_cast<QDockWidget *>(item->widget())) {
481  QList<int> path = dockAreaLayout.indexOf(dockWidget);
482  if (!path.isEmpty())
483  dockAreaLayout.remove(path);
484  }
485 #endif //QT_NO_DOCKWIDGET
486 }
487 
489 {
490 #ifndef QT_NO_TOOLBAR
492 #endif
493 
494 #ifndef QT_NO_DOCKWIDGET
496 #else
497  centralWidgetRect = QRect();
498 #endif
499 
500  rect = QRect();
501 }
502 
504 {
505  return rect.isValid();
506 }
507 
509 {
510  int i = path.first();
511 
512 #ifndef QT_NO_TOOLBAR
513  if (i == 0) {
514  const QToolBarAreaLayoutItem *tbItem = toolBarAreaLayout.item(path.mid(1));
515  Q_ASSERT(tbItem);
516  return tbItem->widgetItem;
517  }
518 #endif
519 
520 #ifndef QT_NO_DOCKWIDGET
521  if (i == 1)
522  return dockAreaLayout.item(path.mid(1)).widgetItem;
523 #endif //QT_NO_DOCKWIDGET
524 
525  return 0;
526 }
527 
529 {
530  int i = path.first();
531 
532 #ifndef QT_NO_TOOLBAR
533  if (i == 0)
534  return toolBarAreaLayout.itemRect(path.mid(1));
535 #endif
536 
537 #ifndef QT_NO_DOCKWIDGET
538  if (i == 1)
539  return dockAreaLayout.itemRect(path.mid(1));
540 #endif //QT_NO_DOCKWIDGET
541 
542  return QRect();
543 }
544 
546 {
547  int i = path.first();
548 
549 #ifndef QT_NO_TOOLBAR
550  if (i == 0)
551  return toolBarAreaLayout.itemRect(path.mid(1));
552 #endif
553 
554 #ifndef QT_NO_DOCKWIDGET
555  if (i == 1)
556  return dockAreaLayout.gapRect(path.mid(1));
557 #endif //QT_NO_DOCKWIDGET
558 
559  return QRect();
560 }
561 
563 {
564  int i = path.first();
565 
566 #ifndef QT_NO_TOOLBAR
567  if (i == 0)
568  return toolBarAreaLayout.plug(path.mid(1));
569 #endif
570 
571 #ifndef QT_NO_DOCKWIDGET
572  if (i == 1)
573  return dockAreaLayout.plug(path.mid(1));
574 #endif //QT_NO_DOCKWIDGET
575 
576  return 0;
577 }
578 
580 {
581  int i = path.first();
582 
583 #ifdef QT_NO_TOOLBAR
584  Q_UNUSED(other);
585 #else
586  if (i == 0)
587  return toolBarAreaLayout.unplug(path.mid(1), other ? &other->toolBarAreaLayout : 0);
588 #endif
589 
590 #ifndef QT_NO_DOCKWIDGET
591  if (i == 1)
592  return dockAreaLayout.unplug(path.mid(1));
593 #endif //QT_NO_DOCKWIDGET
594 
595  return 0;
596 }
597 
599 {
600 #ifndef QT_NO_DOCKWIDGET
601  dockAreaLayout.saveState(stream);
602 #endif
603 #ifndef QT_NO_TOOLBAR
605 #endif
606 }
607 
608 template <typename T>
610 {
611  const QObjectList &list = o->children();
612  QList<T> result;
613 
614  for (int i=0; i < list.size(); ++i) {
615  if (T t = qobject_cast<T>(list[i])) {
616  result.append(t);
617  }
618  }
619 
620  return result;
621 }
622 
623 //pre4.3 tests the format that was used before 4.3
625 {
626 #ifdef QT_NO_TOOLBAR
627  Q_UNUSED(pre43);
628 #endif
629  while (!stream.atEnd()) {
630  uchar marker;
631  stream >> marker;
632  switch(marker)
633  {
634 #ifndef QT_NO_TOOLBAR
637  {
638  QList<QToolBar *> toolBars = findChildrenHelper<QToolBar*>(mainWindow);
639  if (!toolBarAreaLayout.restoreState(stream, toolBars, marker,
640  pre43 /*testing 4.3 format*/, true /*testing*/)) {
641  return false;
642  }
643  }
644  break;
645 #endif // QT_NO_TOOLBAR
646 
647 #ifndef QT_NO_DOCKWIDGET
649  {
650  QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
651  if (!dockAreaLayout.restoreState(stream, dockWidgets, true /*testing*/)) {
652  return false;
653  }
654  }
655  break;
656 #endif
657  default:
658  //there was an error during the parsing
659  return false;
660  }// switch
661  } //while
662 
663  //everything went fine: it must be a pre-4.3 saved state
664  return true;
665 }
666 
668  const QMainWindowLayoutState &oldState)
669 {
670  //make a copy of the data so that we can read it more than once
671  QByteArray copy;
672  while(!_stream.atEnd()) {
673  int length = 1024;
674  QByteArray ba(length, '\0');
675  length = _stream.readRawData(ba.data(), ba.size());
676  ba.resize(length);
677  copy += ba;
678  }
679 
680  QDataStream ds(copy);
681  const bool oldFormat = !checkFormat(ds, false);
682  if (oldFormat) {
683  //we should try with the old format
684  QDataStream ds2(copy);
685  if (!checkFormat(ds2, true)) {
686  return false; //format unknown
687  }
688  }
689 
690  QDataStream stream(copy);
691 
692  while (!stream.atEnd()) {
693  uchar marker;
694  stream >> marker;
695  switch(marker)
696  {
697 #ifndef QT_NO_DOCKWIDGET
699  {
700  QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
701  if (!dockAreaLayout.restoreState(stream, dockWidgets))
702  return false;
703 
704  for (int i = 0; i < dockWidgets.size(); ++i) {
705  QDockWidget *w = dockWidgets.at(i);
707  if (path.isEmpty()) {
708  QList<int> oldPath = oldState.dockAreaLayout.indexOf(w);
709  if (oldPath.isEmpty()) {
710  continue;
711  }
713  if (info == 0) {
714  continue;
715  }
717  }
718  }
719  }
720  break;
721 #endif // QT_NO_DOCKWIDGET
722 
723 #ifndef QT_NO_TOOLBAR
726  {
727  QList<QToolBar *> toolBars = findChildrenHelper<QToolBar*>(mainWindow);
728  if (!toolBarAreaLayout.restoreState(stream, toolBars, marker, oldFormat))
729  return false;
730 
731  for (int i = 0; i < toolBars.size(); ++i) {
732  QToolBar *w = toolBars.at(i);
734  if (path.isEmpty()) {
735  QList<int> oldPath = oldState.toolBarAreaLayout.indexOf(w);
736  if (oldPath.isEmpty()) {
737  continue;
738  }
739  toolBarAreaLayout.docks[oldPath.at(0)].insertToolBar(0, w);
740  }
741  }
742  }
743  break;
744 #endif //QT_NO_TOOLBAR
745  default:
746  return false;
747  }// switch
748  } //while
749 
750 
751  return true;
752 }
753 
754 /******************************************************************************
755 ** QMainWindowLayoutState - toolbars
756 */
757 
758 #ifndef QT_NO_TOOLBAR
759 
761 {
762  switch (area) {
763  case Qt::LeftToolBarArea:
765  case Qt::TopToolBarArea:
767  break;
768  default:
769  area = Qt::TopToolBarArea;
770  }
771 }
772 
774 {
775  switch (area) {
780  default:
781  break;
782  }
783 
784  return QInternal::DockCount;
785 }
786 
788 {
789  switch (pos) {
794  default: break;
795  }
796  return Qt::NoToolBarArea;
797 }
798 
799 static inline Qt::ToolBarArea toToolBarArea(int pos)
800 {
801  return toToolBarArea(static_cast<QInternal::DockPosition>(pos));
802 }
803 
805 {
806  validateToolBarArea(area);
807 
808  layoutState.toolBarAreaLayout.addToolBarBreak(toDockPos(area));
809  if (savedState.isValid())
810  savedState.toolBarAreaLayout.addToolBarBreak(toDockPos(area));
811 
812  invalidate();
813 }
814 
816 {
817  layoutState.toolBarAreaLayout.insertToolBarBreak(before);
818  if (savedState.isValid())
819  savedState.toolBarAreaLayout.insertToolBarBreak(before);
820  invalidate();
821 }
822 
824 {
825  layoutState.toolBarAreaLayout.removeToolBarBreak(before);
826  if (savedState.isValid())
827  savedState.toolBarAreaLayout.removeToolBarBreak(before);
828  invalidate();
829 }
830 
832 {
833  layoutState.toolBarAreaLayout.moveToolBar(toolbar, pos);
834  if (savedState.isValid())
835  savedState.toolBarAreaLayout.moveToolBar(toolbar, pos);
836  invalidate();
837 }
838 
839 /* Removes the toolbar from the mainwindow so that it can be added again. Does not
840  explicitly hide the toolbar. */
842 {
843  if (toolbar) {
844  QObject::disconnect(parentWidget(), SIGNAL(iconSizeChanged(QSize)),
845  toolbar, SLOT(_q_updateIconSize(QSize)));
846  QObject::disconnect(parentWidget(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
847  toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));
848 
849 #ifdef Q_WS_MAC
850  if (usesHIToolBar(toolbar)) {
851  removeFromMacToolbar(toolbar);
852  } else
853 #endif // Q_WS_MAC
854  {
855  removeWidget(toolbar);
856  }
857  }
858 }
859 
864  QToolBar *toolbar,
865  bool)
866 {
867  validateToolBarArea(area);
868 #ifdef Q_WS_MAC
869  if ((area == Qt::TopToolBarArea)
870  && layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) {
871  insertIntoMacToolbar(0, toolbar);
872  } else
873 #endif
874  {
875  //let's add the toolbar to the layout
876  addChildWidget(toolbar);
877  QLayoutItem * item = layoutState.toolBarAreaLayout.addToolBar(toDockPos(area), toolbar);
878  if (savedState.isValid() && item) {
879  // copy the toolbar also in the saved state
880  savedState.toolBarAreaLayout.insertItem(toDockPos(area), item);
881  }
882  invalidate();
883 
884  //this ensures that the toolbar has the right window flags (not floating any more)
885  toolbar->d_func()->updateWindowFlags(false /*floating*/);
886  }
887 }
888 
893 {
894 #ifdef Q_WS_MAC
895  if (usesHIToolBar(before)) {
896  insertIntoMacToolbar(before, toolbar);
897  } else
898 #endif // Q_WS_MAC
899  {
900  addChildWidget(toolbar);
901  QLayoutItem * item = layoutState.toolBarAreaLayout.insertToolBar(before, toolbar);
902  if (savedState.isValid() && item) {
903  // copy the toolbar also in the saved state
904  savedState.toolBarAreaLayout.insertItem(before, item);
905  }
906  if (!currentGapPos.isEmpty() && currentGapPos.first() == 0) {
907  currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex();
908  if (!currentGapPos.isEmpty()) {
909  currentGapPos.prepend(0);
910  currentGapRect = layoutState.itemRect(currentGapPos);
911  }
912  }
913  invalidate();
914  }
915 }
916 
918 {
919  QInternal::DockPosition pos = layoutState.toolBarAreaLayout.findToolBar(toolbar);
920  switch (pos) {
925  default: break;
926  }
927 #ifdef Q_WS_MAC
928  if (pos == QInternal::DockCount) {
929  if (qtoolbarsInUnifiedToolbarList.contains(toolbar))
930  return Qt::TopToolBarArea;
931  }
932 #endif
933  return Qt::NoToolBarArea;
934 }
935 
937 {
938  return layoutState.toolBarAreaLayout.toolBarBreak(toolBar);
939 }
940 
942 {
943  option->toolBarArea = toolBarArea(toolBar);
944  layoutState.toolBarAreaLayout.getStyleOptionInfo(option, toolBar);
945 }
946 
948 {
949  bool updateNonUnifiedParts = true;
950 #ifdef Q_WS_MAC
951  if (layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) {
952  // If we hit this case, someone has pressed the "toolbar button" which will
953  // toggle the unified toolbar visibility, because that's what the user wants.
954  // We might be in a situation where someone has hidden all the toolbars
955  // beforehand (maybe in construction), but now they've hit this button and
956  // and are expecting the items to show. What do we do?
957  // 1) Check the visibility of all the toolbars, if one is visible, do nothing, this
958  // preserves what people would expect (these toolbars were visible when I clicked last time).
959  // 2) If NONE are visible, then show them all. Again, this preserves the user expectation
960  // of, "I want to see the toolbars." The user may get more toolbars than expected, but this
961  // is better seeing nothing.
962  // Don't worry about any of this if we are going invisible. This does mean we may get
963  // into issues when switching into and out of fullscreen mode, but this is probably minor.
964  // If we ever need to do hiding, that would have to be taken care of after the unified toolbar
965  // has finished hiding.
966  // People can of course handle the QEvent::ToolBarChange event themselves and do
967  // WHATEVER they want if they don't like what we are doing (though the unified toolbar
968  // will fire regardless).
969 
970  // Check if we REALLY need to update the geometry below. If we only have items in the
971  // unified toolbar, all the docks will be empty, so there's very little point
972  // in doing the geometry as Apple will do it (we also avoid flicker in Cocoa as well).
973  // FWIW, layoutState.toolBarAreaLayout.visible and the state of the unified toolbar
974  // visibility can get out of sync. I really don't think it's a big issue. It is kept
975  // to a minimum because we only change the visibility if we absolutely must.
976  // update the "non unified parts."
977  updateNonUnifiedParts = !layoutState.toolBarAreaLayout.isEmpty();
978 
979  // We get this function before the unified toolbar does its thing.
980  // So, the value will be opposite of what we expect.
981  bool goingVisible = !macWindowToolbarIsVisible(qt_mac_window_for(layoutState.mainWindow));
982  if (goingVisible) {
983  const int ToolBarCount = qtoolbarsInUnifiedToolbarList.size();
984  bool needAllVisible = true;
985  for (int i = 0; i < ToolBarCount; ++i) {
986  if (!qtoolbarsInUnifiedToolbarList.at(i)->isHidden()) {
987  needAllVisible = false;
988  break;
989  }
990  }
991  if (needAllVisible) {
992  QBoolBlocker blocker(blockVisiblityCheck); // Disable the visibilty check because
993  // the toggle has already happened.
994  for (int i = 0; i < ToolBarCount; ++i)
995  qtoolbarsInUnifiedToolbarList.at(i)->setVisible(true);
996  }
997  }
998  if (!updateNonUnifiedParts)
999  layoutState.toolBarAreaLayout.visible = goingVisible;
1000  }
1001 #endif
1002  if (updateNonUnifiedParts) {
1003  layoutState.toolBarAreaLayout.visible = !layoutState.toolBarAreaLayout.visible;
1004  if (!layoutState.mainWindow->isMaximized()) {
1005  QPoint topLeft = parentWidget()->geometry().topLeft();
1006  QRect r = parentWidget()->geometry();
1007  r = layoutState.toolBarAreaLayout.rectHint(r);
1008  r.moveTo(topLeft);
1009  parentWidget()->setGeometry(r);
1010  } else {
1011  update();
1012  }
1013  }
1014 }
1015 
1016 #endif // QT_NO_TOOLBAR
1017 
1018 /******************************************************************************
1019 ** QMainWindowLayoutState - dock areas
1020 */
1021 
1022 #ifndef QT_NO_DOCKWIDGET
1023 
1025 {
1026  switch (area) {
1029  case Qt::TopDockWidgetArea:
1031  break;
1032  default:
1033  area = Qt::LeftDockWidgetArea;
1034  }
1035 }
1036 
1038 {
1039  switch (area) {
1044  default:
1045  break;
1046  }
1047 
1048  return QInternal::DockCount;
1049 }
1050 
1052 {
1053  switch (pos) {
1058  default:
1059  break;
1060  }
1061 
1062  return Qt::NoDockWidgetArea;
1063 }
1064 
1065 inline static Qt::DockWidgetArea toDockWidgetArea(int pos)
1066 {
1067  return toDockWidgetArea(static_cast<QInternal::DockPosition>(pos));
1068 }
1069 
1071 {
1072  if (layoutState.dockAreaLayout.corners[corner] == area)
1073  return;
1074  layoutState.dockAreaLayout.corners[corner] = area;
1075  if (savedState.isValid())
1076  savedState.dockAreaLayout.corners[corner] = area;
1077  invalidate();
1078 }
1079 
1081 {
1082  return layoutState.dockAreaLayout.corners[corner];
1083 }
1084 
1086  QDockWidget *dockwidget,
1087  Qt::Orientation orientation)
1088 {
1089  addChildWidget(dockwidget);
1090 
1091  // If we are currently moving a separator, then we need to abort the move, since each
1092  // time we move the mouse layoutState is replaced by savedState modified by the move.
1093  if (!movingSeparator.isEmpty())
1094  endSeparatorMove(movingSeparatorPos);
1095 
1096  layoutState.dockAreaLayout.addDockWidget(toDockPos(area), dockwidget, orientation);
1097  emit dockwidget->dockLocationChanged(area);
1098  invalidate();
1099 }
1100 
1102 {
1103  addChildWidget(second);
1104  layoutState.dockAreaLayout.tabifyDockWidget(first, second);
1105  emit second->dockLocationChanged(dockWidgetArea(first));
1106  invalidate();
1107 }
1108 
1110 {
1111  addChildWidget(dockwidget);
1112  if (!layoutState.dockAreaLayout.restoreDockWidget(dockwidget))
1113  return false;
1114  emit dockwidget->dockLocationChanged(dockWidgetArea(dockwidget));
1115  invalidate();
1116  return true;
1117 }
1118 
1119 #ifndef QT_NO_TABBAR
1121 {
1122  return _documentMode;
1123 }
1124 
1126 {
1127  if (_documentMode == enabled)
1128  return;
1129 
1130  _documentMode = enabled;
1131 
1132  // Update the document mode for all tab bars
1133  foreach (QTabBar *bar, usedTabBars)
1134  bar->setDocumentMode(_documentMode);
1135  foreach (QTabBar *bar, unusedTabBars)
1136  bar->setDocumentMode(_documentMode);
1137 }
1138 #endif // QT_NO_TABBAR
1139 
1141 {
1142 #ifdef QT_NO_TABBAR
1143  Q_UNUSED(enabled);
1144 #else
1145  if (verticalTabsEnabled == enabled)
1146  return;
1147 
1148  verticalTabsEnabled = enabled;
1149 
1150  updateTabBarShapes();
1151 #endif // QT_NO_TABBAR
1152 }
1153 
1154 #ifndef QT_NO_TABWIDGET
1156 {
1157  return _tabShape;
1158 }
1159 
1161 {
1162  if (_tabShape == tabShape)
1163  return;
1164 
1165  _tabShape = tabShape;
1166 
1167  updateTabBarShapes();
1168 }
1169 
1171 {
1172  return tabPositions[toDockPos(area)];
1173 }
1174 
1175 void QMainWindowLayout::setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition)
1176 {
1177  const Qt::DockWidgetArea dockWidgetAreas[] = {
1182  };
1183  const QInternal::DockPosition dockPositions[] = {
1188  };
1189 
1190  for (int i = 0; i < QInternal::DockCount; ++i)
1191  if (areas & dockWidgetAreas[i])
1192  tabPositions[dockPositions[i]] = tabPosition;
1193 
1194  updateTabBarShapes();
1195 }
1196 
1198 {
1199  const bool rounded = (shape == QTabWidget::Rounded);
1200  if (position == QTabWidget::North)
1202  if (position == QTabWidget::South)
1204  if (position == QTabWidget::East)
1205  return rounded ? QTabBar::RoundedEast : QTabBar::TriangularEast;
1206  if (position == QTabWidget::West)
1207  return rounded ? QTabBar::RoundedWest : QTabBar::TriangularWest;
1208  return QTabBar::RoundedNorth;
1209 }
1210 #endif // QT_NO_TABWIDGET
1211 
1212 #ifndef QT_NO_TABBAR
1214 {
1215 #ifndef QT_NO_TABWIDGET
1216  const QTabWidget::TabPosition vertical[] = {
1221  };
1222 #else
1223  const QTabBar::Shape vertical[] = {
1228  };
1229 #endif
1230 
1231  QDockAreaLayout &layout = layoutState.dockAreaLayout;
1232 
1233  for (int i = 0; i < QInternal::DockCount; ++i) {
1234 #ifndef QT_NO_TABWIDGET
1235  QTabWidget::TabPosition pos = verticalTabsEnabled ? vertical[i] : tabPositions[i];
1236  QTabBar::Shape shape = tabBarShapeFrom(_tabShape, pos);
1237 #else
1238  QTabBar::Shape shape = verticalTabsEnabled ? vertical[i] : QTabBar::RoundedSouth;
1239 #endif
1240  layout.docks[i].setTabBarShape(shape);
1241  }
1242 }
1243 #endif // QT_NO_TABBAR
1244 
1246  QDockWidget *dockwidget,
1247  Qt::Orientation orientation)
1248 {
1249  addChildWidget(dockwidget);
1250  layoutState.dockAreaLayout.splitDockWidget(after, dockwidget, orientation);
1251  emit dockwidget->dockLocationChanged(dockWidgetArea(after));
1252  invalidate();
1253 }
1254 
1256 {
1257  QList<int> pathToWidget = layoutState.dockAreaLayout.indexOf(widget);
1258  if (pathToWidget.isEmpty())
1259  return Qt::NoDockWidgetArea;
1260  return toDockWidgetArea(pathToWidget.first());
1261 }
1262 
1264 {
1265  layoutState.dockAreaLayout.keepSize(w);
1266 }
1267 
1268 #ifndef QT_NO_TABBAR
1269 
1271 {
1272 public:
1273  QMainWindowTabBar(QWidget *parent);
1274 protected:
1275  bool event(QEvent *e);
1276 };
1277 
1279  : QTabBar(parent)
1280 {
1281  setExpanding(false);
1282 }
1283 
1285 {
1286  // show the tooltip if tab is too small to fit label
1287 
1288  if (e->type() != QEvent::ToolTip)
1289  return QTabBar::event(e);
1290  QSize size = this->size();
1291  QSize hint = sizeHint();
1293  size.transpose();
1294  hint.transpose();
1295  }
1296  if (size.width() < hint.width())
1297  return QTabBar::event(e);
1298  e->accept();
1299  return true;
1300 }
1301 
1303 {
1304  QTabBar *result = 0;
1305  if (!unusedTabBars.isEmpty()) {
1306  result = unusedTabBars.takeLast();
1307  } else {
1308  result = new QMainWindowTabBar(parentWidget());
1309  result->setDrawBase(true);
1310  result->setElideMode(Qt::ElideRight);
1311  result->setDocumentMode(_documentMode);
1312  connect(result, SIGNAL(currentChanged(int)), this, SLOT(tabChanged()));
1313  }
1314 
1315  usedTabBars.insert(result);
1316  return result;
1317 }
1318 
1319 // Allocates a new separator widget if needed
1321 {
1322  QWidget *result = 0;
1323  if (!unusedSeparatorWidgets.isEmpty()) {
1324  result = unusedSeparatorWidgets.takeLast();
1325  } else {
1326  result = new QWidget(parentWidget());
1327  result->setAttribute(Qt::WA_MouseNoMask, true);
1328  result->setAutoFillBackground(false);
1329  result->setObjectName(QLatin1String("qt_qmainwindow_extended_splitter"));
1330  }
1331  usedSeparatorWidgets.insert(result);
1332  return result;
1333 }
1334 
1336 {
1337  QTabBar *tb = qobject_cast<QTabBar*>(sender());
1338  if (tb == 0)
1339  return;
1340  QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(tb);
1341  if (info == 0)
1342  return;
1343  info->apply(false);
1344 
1345  if (QWidget *w = centralWidget())
1346  w->raise();
1347 }
1348 #endif // QT_NO_TABBAR
1349 
1351 {
1352  movingSeparator = layoutState.dockAreaLayout.findSeparator(pos);
1353 
1354  if (movingSeparator.isEmpty())
1355  return false;
1356 
1357  savedState = layoutState;
1358  movingSeparatorPos = movingSeparatorOrigin = pos;
1359 
1360  return true;
1361 }
1362 
1364 {
1365  if (movingSeparator.isEmpty())
1366  return false;
1367  movingSeparatorPos = pos;
1368  separatorMoveTimer.start(0, this);
1369  return true;
1370 }
1371 
1373 {
1374  if (movingSeparator.isEmpty())
1375  return false;
1376  movingSeparator.clear();
1377  savedState.clear();
1378  return true;
1379 }
1380 
1382 {
1383  QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget);
1384  if (info == 0)
1385  return;
1386 #ifndef QT_NO_TABBAR
1387  if (!info->tabbed)
1388  return;
1389  info->setCurrentTab(widget);
1390 #endif
1391 }
1392 
1393 #endif // QT_NO_DOCKWIDGET
1394 
1395 
1396 /******************************************************************************
1397 ** QMainWindowLayoutState - layout interface
1398 */
1399 
1401 {
1402  qWarning("QMainWindowLayout::count: ?");
1403  return 0; //#################################################
1404 }
1405 
1407 {
1408  int x = 0;
1409 
1410  if (QLayoutItem *ret = layoutState.itemAt(index, &x))
1411  return ret;
1412 
1413  if (statusbar && x++ == index)
1414  return statusbar;
1415 
1416  return 0;
1417 }
1418 
1420 {
1421  int x = 0;
1422 
1423  if (QLayoutItem *ret = layoutState.takeAt(index, &x)) {
1424  // the widget might in fact have been destroyed by now
1425  if (QWidget *w = ret->widget()) {
1426  widgetAnimator.abort(w);
1427  if (w == pluggingWidget)
1428  pluggingWidget = 0;
1429  }
1430 
1431  if (savedState.isValid() ) {
1432  //we need to remove the item also from the saved state to prevent crash
1433  savedState.remove(ret);
1434  //Also, the item may be contained several times as a gap item.
1435  layoutState.remove(ret);
1436  }
1437 
1438 #ifndef QT_NO_TOOLBAR
1439  if (!currentGapPos.isEmpty() && currentGapPos.first() == 0) {
1440  currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex();
1441  if (!currentGapPos.isEmpty()) {
1442  currentGapPos.prepend(0);
1443  currentGapRect = layoutState.itemRect(currentGapPos);
1444  }
1445  }
1446 #endif
1447 
1448  return ret;
1449  }
1450 
1451  if (statusbar && x++ == index) {
1452  QLayoutItem *ret = statusbar;
1453  statusbar = 0;
1454  return ret;
1455  }
1456 
1457  return 0;
1458 }
1459 
1461 {
1462  if (savedState.isValid())
1463  return;
1464 
1465  QRect r = _r;
1466 
1468 
1469  if (statusbar) {
1470  QRect sbr(QPoint(0, 0),
1471  QSize(r.width(), statusbar->heightForWidth(r.width()))
1472  .expandedTo(statusbar->minimumSize()));
1473  sbr.moveBottom(r.bottom());
1475  statusbar->setGeometry(vr);
1476  r.setBottom(sbr.top() - 1);
1477  }
1478 
1479  layoutState.rect = r;
1480  layoutState.fitLayout();
1481  applyState(layoutState, false);
1482 }
1483 
1485 { qWarning("QMainWindowLayout::addItem: Please use the public QMainWindow API instead"); }
1486 
1488 {
1489  if (!szHint.isValid()) {
1490  szHint = layoutState.sizeHint();
1491  const QSize sbHint = statusbar ? statusbar->sizeHint() : QSize(0, 0);
1492  szHint = QSize(qMax(sbHint.width(), szHint.width()),
1493  sbHint.height() + szHint.height());
1494  }
1495  return szHint;
1496 }
1497 
1499 {
1500  if (!minSize.isValid()) {
1501  minSize = layoutState.minimumSize();
1502  const QSize sbMin = statusbar ? statusbar->minimumSize() : QSize(0, 0);
1503  minSize = QSize(qMax(sbMin.width(), minSize.width()),
1504  sbMin.height() + minSize.height());
1505 #ifdef Q_WS_MAC
1506  const QSize storedSize = minSize;
1507  int minWidth = 0;
1508  foreach (QToolBar *toolbar, qtoolbarsInUnifiedToolbarList) {
1509  minWidth += toolbar->sizeHint().width() + 20;
1510  }
1511  minSize = QSize(qMax(minWidth, storedSize.width()), storedSize.height());
1512 #endif
1513  }
1514  return minSize;
1515 }
1516 
1518 {
1520  minSize = szHint = QSize();
1521 }
1522 
1523 /******************************************************************************
1524 ** QMainWindowLayout - remaining stuff
1525 */
1526 
1527 static void fixToolBarOrientation(QLayoutItem *item, int dockPos)
1528 {
1529 #ifndef QT_NO_TOOLBAR
1530  QToolBar *toolBar = qobject_cast<QToolBar*>(item->widget());
1531  if (toolBar == 0)
1532  return;
1533 
1534  QRect oldGeo = toolBar->geometry();
1535 
1537  = static_cast<QInternal::DockPosition>(dockPos);
1540  if (o != toolBar->orientation())
1541  toolBar->setOrientation(o);
1542 
1543  QSize hint = toolBar->sizeHint().boundedTo(toolBar->maximumSize())
1544  .expandedTo(toolBar->minimumSize());
1545 
1546  if (toolBar->size() != hint) {
1547  QRect newGeo(oldGeo.topLeft(), hint);
1548  if (toolBar->layoutDirection() == Qt::RightToLeft)
1549  newGeo.moveRight(oldGeo.right());
1550  toolBar->setGeometry(newGeo);
1551  }
1552 
1553 #else
1554  Q_UNUSED(item);
1555  Q_UNUSED(dockPos);
1556 #endif
1557 }
1558 
1560 {
1561  if (!savedState.isValid())
1562  return;
1563 
1564  QWidget *widget = widgetItem->widget();
1565  layoutState = savedState;
1566  currentGapPos = layoutState.indexOf(widget);
1567  fixToolBarOrientation(widgetItem, currentGapPos.at(1));
1568  layoutState.unplug(currentGapPos);
1569  layoutState.fitLayout();
1570  currentGapRect = layoutState.itemRect(currentGapPos);
1571 
1572  plug(widgetItem);
1573 }
1574 
1576 {
1577  if (!parentWidget()->isVisible() || parentWidget()->isMinimized() || currentGapPos.isEmpty())
1578  return false;
1579 
1580  fixToolBarOrientation(widgetItem, currentGapPos.at(1));
1581 
1582  QWidget *widget = widgetItem->widget();
1583 
1584  QList<int> previousPath = layoutState.indexOf(widget);
1585 
1586  const QLayoutItem *it = layoutState.plug(currentGapPos);
1587  if (!it)
1588  return false;
1589  Q_ASSERT(it == widgetItem);
1590  if (!previousPath.isEmpty())
1591  layoutState.remove(previousPath);
1592 
1593  pluggingWidget = widget;
1594  QRect globalRect = currentGapRect;
1595  globalRect.moveTopLeft(parentWidget()->mapToGlobal(globalRect.topLeft()));
1596 #ifndef QT_NO_DOCKWIDGET
1597  if (qobject_cast<QDockWidget*>(widget) != 0) {
1598  QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(widget->layout());
1599  if (layout->nativeWindowDeco()) {
1600  globalRect.adjust(0, layout->titleHeight(), 0, 0);
1601  } else {
1602  int fw = widget->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, widget);
1603  globalRect.adjust(-fw, -fw, fw, fw);
1604  }
1605  }
1606 #endif
1607  widgetAnimator.animate(widget, globalRect, dockOptions & QMainWindow::AnimatedDocks);
1608 
1609  return true;
1610 }
1611 
1613 {
1614  //this function is called from within the Widget Animator whenever an animation is finished
1615  //on a certain widget
1616 #ifndef QT_NO_TOOLBAR
1617  if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) {
1618  QToolBarLayout *tbl = qobject_cast<QToolBarLayout*>(tb->layout());
1619  if (tbl->animating) {
1620  tbl->animating = false;
1621  if (tbl->expanded)
1622  tbl->layoutActions(tb->size());
1623  tb->update();
1624  }
1625  }
1626 #endif
1627 
1628  if (widget == pluggingWidget) {
1629 
1630 #ifndef QT_NO_DOCKWIDGET
1631  if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget))
1632  dw->d_func()->plug(currentGapRect);
1633 #endif
1634 #ifndef QT_NO_TOOLBAR
1635  if (QToolBar *tb = qobject_cast<QToolBar*>(widget))
1636  tb->d_func()->plug(currentGapRect);
1637 #endif
1638 
1639  savedState.clear();
1640  currentGapPos.clear();
1641  pluggingWidget = 0;
1642  //applying the state will make sure that the currentGap is updated correctly
1643  //and all the geometries (especially the one from the central widget) is correct
1644  layoutState.apply(false);
1645 
1646 #ifndef QT_NO_DOCKWIDGET
1647 #ifndef QT_NO_TABBAR
1648  if (qobject_cast<QDockWidget*>(widget) != 0) {
1649  // info() might return null if the widget is destroyed while
1650  // animating but before the animationFinished signal is received.
1651  if (QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget))
1652  info->setCurrentTab(widget);
1653  }
1654 #endif
1655 #endif
1656  }
1657 
1658  if (!widgetAnimator.animating()) {
1659  //all animations are finished
1660 #ifndef QT_NO_DOCKWIDGET
1661  parentWidget()->update(layoutState.dockAreaLayout.separatorRegion());
1662 #ifndef QT_NO_TABBAR
1663  foreach (QTabBar *tab_bar, usedTabBars)
1664  tab_bar->show();
1665 #endif // QT_NO_TABBAR
1666 #endif // QT_NO_DOCKWIDGET
1667  }
1668 
1669  updateGapIndicator();
1670 }
1671 
1672 void QMainWindowLayout::restore(bool keepSavedState)
1673 {
1674  if (!savedState.isValid())
1675  return;
1676 
1677  layoutState = savedState;
1678  applyState(layoutState);
1679  if (!keepSavedState)
1680  savedState.clear();
1681  currentGapPos.clear();
1682  pluggingWidget = 0;
1683  updateGapIndicator();
1684 }
1685 
1687  : QLayout(parentLayout ? static_cast<QWidget *>(0) : mainwindow)
1688  , layoutState(mainwindow)
1689  , savedState(mainwindow)
1690  , dockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowTabbedDocks)
1691  , statusbar(0)
1692 #ifndef QT_NO_DOCKWIDGET
1693 #ifndef QT_NO_TABBAR
1694  , _documentMode(false)
1695  , verticalTabsEnabled(false)
1696 #ifndef QT_NO_TABWIDGET
1697  , _tabShape(QTabWidget::Rounded)
1698 #endif
1699 #endif
1700 #endif // QT_NO_DOCKWIDGET
1701  , widgetAnimator(this)
1702  , pluggingWidget(0)
1703 #ifndef QT_NO_RUBBERBAND
1704  , gapIndicator(new QRubberBand(QRubberBand::Rectangle, mainwindow))
1705 #endif //QT_NO_RUBBERBAND
1706 #ifdef Q_WS_MAC
1707  , activateUnifiedToolbarAfterFullScreen(false)
1708  , blockVisiblityCheck(false)
1709 #endif
1710 {
1711  if (parentLayout)
1712  setParent(parentLayout);
1713 
1714 #ifndef QT_NO_DOCKWIDGET
1715 #ifndef QT_NO_TABBAR
1716  sep = mainwindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainwindow);
1717 #endif
1718 
1719 #ifndef QT_NO_TABWIDGET
1720  for (int i = 0; i < QInternal::DockCount; ++i)
1722 #endif
1723 #endif // QT_NO_DOCKWIDGET
1724 
1725 #ifndef QT_NO_RUBBERBAND
1726  // For accessibility to identify this special widget.
1727  gapIndicator->setObjectName(QLatin1String("qt_rubberband"));
1728  gapIndicator->hide();
1729 #endif
1730  pluggingWidget = 0;
1731 
1732  setObjectName(mainwindow->objectName() + QLatin1String("_layout"));
1733 }
1734 
1736 {
1739 
1740 #ifdef Q_WS_MAC
1742 #endif
1743 
1744  delete statusbar;
1745 }
1746 
1747 void QMainWindowLayout::setDockOptions(QMainWindow::DockOptions opts)
1748 {
1749  if (opts == dockOptions)
1750  return;
1751 
1752  dockOptions = opts;
1753 
1754 #ifndef QT_NO_DOCKWIDGET
1756 #endif
1757 
1758  invalidate();
1759 }
1760 
1761 #ifndef QT_NO_STATUSBAR
1763 { return statusbar ? qobject_cast<QStatusBar *>(statusbar->widget()) : 0; }
1764 
1766 {
1767  if (sb)
1768  addChildWidget(sb);
1769  delete statusbar;
1770  statusbar = sb ? new QWidgetItemV2(sb) : 0;
1771  invalidate();
1772 }
1773 #endif // QT_NO_STATUSBAR
1774 
1776 {
1777  return layoutState.centralWidget();
1778 }
1779 
1781 {
1782  if (widget != 0)
1783  addChildWidget(widget);
1784  layoutState.setCentralWidget(widget);
1785  if (savedState.isValid()) {
1786 #ifndef QT_NO_DOCKWIDGET
1789 #else
1790  savedState.centralWidgetItem = layoutState.centralWidgetItem;
1791 #endif
1792  }
1793  invalidate();
1794 }
1795 
1797 {
1798  QList<int> path = layoutState.indexOf(widget);
1799  if (path.isEmpty())
1800  return 0;
1801 
1802  QLayoutItem *item = layoutState.item(path);
1803  if (widget->isWindow())
1804  return item;
1805 
1806  QRect r = layoutState.itemRect(path);
1808 
1809 #ifndef QT_NO_DOCKWIDGET
1810  if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) {
1811  dw->d_func()->unplug(r);
1812  }
1813 #endif
1814 #ifndef QT_NO_TOOLBAR
1815  if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) {
1816  tb->d_func()->unplug(r);
1817  }
1818 #endif
1819 
1820 
1821  layoutState.unplug(path ,&savedState);
1823  currentGapPos = path;
1824  currentGapRect = r;
1826 
1828 
1829  return item;
1830 }
1831 
1833 {
1834 #ifndef QT_NO_RUBBERBAND
1837 #endif
1838 }
1839 
1841 {
1842  if (!parentWidget()->isVisible() || parentWidget()->isMinimized()
1843  || pluggingWidget != 0 || widgetItem == 0)
1844  return QList<int>();
1845 
1846  QWidget *widget = widgetItem->widget();
1847  QPoint pos = parentWidget()->mapFromGlobal(mousePos);
1848 
1849  if (!savedState.isValid())
1851 
1852  QList<int> path = savedState.gapIndex(widget, pos);
1853 
1854  if (!path.isEmpty()) {
1855  bool allowed = false;
1856 
1857 #ifndef QT_NO_DOCKWIDGET
1858  if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget))
1859  allowed = dw->isAreaAllowed(toDockWidgetArea(path.at(1)));
1860 #endif
1861 #ifndef QT_NO_TOOLBAR
1862  if (QToolBar *tb = qobject_cast<QToolBar*>(widget))
1863  allowed = tb->isAreaAllowed(toToolBarArea(path.at(1)));
1864 #endif
1865 
1866  if (!allowed)
1867  path.clear();
1868  }
1869 
1870  if (path == currentGapPos)
1871  return currentGapPos; // the gap is already there
1872 
1873  currentGapPos = path;
1874  if (path.isEmpty()) {
1875  fixToolBarOrientation(widgetItem, 2); // 2 = top dock, ie. horizontal
1876  restore(true);
1877  return QList<int>();
1878  }
1879 
1880  fixToolBarOrientation(widgetItem, currentGapPos.at(1));
1881 
1883 
1884  if (!newState.insertGap(path, widgetItem)) {
1885  restore(true); // not enough space
1886  return QList<int>();
1887  }
1888 
1889  QSize min = newState.minimumSize();
1890  QSize size = newState.rect.size();
1891 
1892  if (min.width() > size.width() || min.height() > size.height()) {
1893  restore(true);
1894  return QList<int>();
1895  }
1896 
1897  newState.fitLayout();
1898 
1899  currentGapRect = newState.gapRect(currentGapPos);
1900 
1901 #ifndef QT_NO_DOCKWIDGET
1903 #endif
1904  layoutState = newState;
1906 
1908 
1909  return path;
1910 }
1911 
1913 {
1914 #ifndef QT_NO_DOCKWIDGET
1915 #ifndef QT_NO_TABBAR
1916  QSet<QTabBar*> used = newState.dockAreaLayout.usedTabBars();
1917  QSet<QTabBar*> retired = usedTabBars - used;
1918  usedTabBars = used;
1919  foreach (QTabBar *tab_bar, retired) {
1920  tab_bar->hide();
1921  while (tab_bar->count() > 0)
1922  tab_bar->removeTab(0);
1923  unusedTabBars.append(tab_bar);
1924  }
1925 
1926  if (sep == 1) {
1927  QSet<QWidget*> usedSeps = newState.dockAreaLayout.usedSeparatorWidgets();
1928  QSet<QWidget*> retiredSeps = usedSeparatorWidgets - usedSeps;
1929  usedSeparatorWidgets = usedSeps;
1930  foreach (QWidget *sepWidget, retiredSeps) {
1931  unusedSeparatorWidgets.append(sepWidget);
1932  }
1933  }
1934 
1935 
1936 #endif // QT_NO_TABBAR
1937 #endif // QT_NO_DOCKWIDGET
1938  newState.apply(dockOptions & QMainWindow::AnimatedDocks && animate);
1939 }
1940 
1942 {
1943  layoutState.saveState(stream);
1944 }
1945 
1947 {
1949  layoutState.clear();
1951 
1952  if (!layoutState.restoreState(stream, savedState)) {
1955  if (parentWidget()->isVisible())
1956  applyState(layoutState, false); // hides tabBars allocated by newState
1957  return false;
1958  }
1959 
1960  if (parentWidget()->isVisible()) {
1962  applyState(layoutState, false);
1963  }
1964 
1966  savedState.clear();
1967 
1968 #ifndef QT_NO_DOCKWIDGET
1969  if (parentWidget()->isVisible()) {
1970 #ifndef QT_NO_TABBAR
1971  foreach (QTabBar *tab_bar, usedTabBars)
1972  tab_bar->show();
1973 
1974 #endif
1975  }
1976 #endif // QT_NO_DOCKWIDGET
1977 
1978  return true;
1979 }
1980 
1981 
1982 // Returns if this toolbar *should* be using HIToolbar. Won't work for all in between cases
1983 // for example, you have a toolbar in the top area and then you suddenly turn on
1984 // HIToolbar.
1986 {
1987 #ifndef Q_WS_MAC
1988  Q_UNUSED(toolbar);
1989  return false;
1990 #else
1991  return qtoolbarsInUnifiedToolbarList.contains(toolbar)
1992  || ((toolBarArea(toolbar) == Qt::TopToolBarArea)
1994 #endif
1995 }
1996 
1998 {
1999 #ifndef QT_NO_DOCKWIDGET
2000  if (e->timerId() == separatorMoveTimer.timerId()) {
2001  //let's move the separators
2003  if (movingSeparator.isEmpty())
2004  return;
2006  return;
2007 
2008  //when moving the separator, we need to update the previous position
2010 
2015  }
2016 #endif
2018 }
2019 
2020 
2022 
2023 #endif // QT_NO_MAINWINDOW
void setDrawBase(bool drawTheBase)
Definition: qtabbar.cpp:800
QPoint pos() const
QMainWindowLayoutState(QMainWindow *win)
QSet< QTabBar * > usedTabBars() const
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
Qt::ToolBarArea toolBarArea(QToolBar *toolbar) const
QSet< QTabBar * > usedTabBars
QList< QDockAreaLayoutItem > item_list
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
bool event(QEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:1490
static mach_timebase_info_data_t info
void currentChanged(int index)
This signal is emitted when the tab bar&#39;s current tab changes.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void addToolBarBreak(Qt::ToolBarArea area)
QSize size() const
EventRef event
QPointer< QWidget > widget
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QWidget * getSeparatorWidget()
QToolBarAreaLayoutItem * item(const QList< int > &path)
void revert(QLayoutItem *widgetItem)
void setGeometry(const QRect &r)
Reimplemented Function
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
QLayoutItem * itemAt(int index, int *x) const
void remove(const QList< int > &path)
QLayoutItem * plug(const QList< int > &path)
#define it(className, varName)
void saveState(QDataStream &stream) const
QRect itemRect(const QList< int > &path) const
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
void setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition)
QList< int > currentGapPos
QTabWidget::TabShape tabShape() const
bool isVisible() const
Definition: qwidget.h:1005
TabPosition
This enum type defines where QTabWidget draws the tab row:
Definition: qtabwidget.h:112
void dockLocationChanged(Qt::DockWidgetArea area)
This signal is emitted when the dock widget is moved to another dock area, or is moved to a different...
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
void setStatusBar(QStatusBar *sb)
static QList< T > findChildrenHelper(const QObject *o)
void keepSize(QDockWidget *w)
bool checkFormat(QDataStream &stream, bool pre43)
#define QT_NO_TOOLBAR
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setDockOptions(QMainWindow::DockOptions opts)
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QTabBar::Shape tabBarShapeFrom(QTabWidget::TabShape shape, QTabWidget::TabPosition position)
QList< int > gapIndex(QWidget *widget, const QPoint &pos) const
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s right edge at the given x coordinate...
Definition: qrect.h:356
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
QMainWindowLayoutState layoutState
void timerEvent(QTimerEvent *e)
This event handler can be reimplemented in a subclass to receive timer events for the object...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setOrientation(Qt::Orientation orientation)
Definition: qtoolbar.cpp:750
static void validateToolBarArea(Qt::ToolBarArea &area)
virtual void setGeometry(const QRect &)
Reimplemented Function
Definition: qlayout.cpp:655
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
QTabWidget::TabPosition tabPosition(Qt::DockWidgetArea area) const
void setCentralWidget(QWidget *cw)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void raise(QDockWidget *widget)
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
The QTabBar class provides a tab bar, e.g.
Definition: qtabbar.h:59
QPlaceHolderItem * placeHolderItem
QList< int > hover(QLayoutItem *widgetItem, const QPoint &mousePos)
QSize sizeHint(const QSize &center) const
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget, Qt::Orientation orientation)
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void saveState(QDataStream &stream) const
QLayoutItem * plug(const QList< int > &path)
int count() const
Must be implemented in subclasses to return the number of items in the layout.
QRect itemRect(const QList< int > &path) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QSize sizeHint() const
em>Reimplemented Function
Definition: qtabbar.cpp:1317
void removeTab(int index)
Removes the tab at position index.
Definition: qtabbar.cpp:902
void moveBottom(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s bottom edge at the given y coordinate...
Definition: qrect.h:362
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
bool macWindowToolbarIsVisible(void *window)
bool insertGap(const QList< int > &path, QLayoutItem *item)
NSToolbar * toolbar
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void apply(bool animated)
QDockAreaLayout dockAreaLayout
virtual QSize sizeHint() const
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QStyle * style() const
Definition: qwidget.cpp:2742
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
QList< T > mid(int pos, int length=-1) const
Returns a list whose elements are copied from this list, starting at position pos.
Definition: qlist.h:637
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
void setCentralWidget(QWidget *widget)
void apply(bool animate)
The QStatusBar class provides a horizontal bar suitable for presenting status information.
Definition: qstatusbar.h:57
void getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const
QRect gapRect(const QList< int > &path) const
QSet< QWidget * > usedSeparatorWidgets() const
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
QToolBarAreaLayoutInfo docks[4]
QLayoutItem * centralWidgetItem
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void invalidate()
Reimplemented Function
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QMainWindow::DockOptions dockOptions
unsigned char uchar
Definition: qglobal.h:994
void setCorner(Qt::Corner corner, Qt::DockWidgetArea area)
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar, bool needAddChildWidget=true)
Adds toolbar to area, continuing the current line.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QLayoutItem * takeAt(int index, int *x)
static void validateDockWidgetArea(Qt::DockWidgetArea &area)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QRect gapRect(const QList< int > &path) const
void setGeometry(const QRect &r)
Sets the geometry of the rubber band to rect, specified in the coordinate system of its parent widget...
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
Shape
This enum type lists the built-in shapes supported by QTabBar.
Definition: qtabbar.h:81
void setVerticalTabsEnabled(bool enabled)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
static FILE * stream
QLayoutItem * takeAt(int *x, int index)
QWidget * centralWidget() const
int readRawData(char *, int len)
Reads at most len bytes from the stream into s and returns the number of bytes read.
void setCurrentTab(QWidget *widget)
QSize sizeHint() const
static void fixToolBarOrientation(QLayoutItem *item, int dockPos)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The Rectangle item provides a filled rectangle with an optional border.
QLayoutItem * insertToolBar(QToolBar *before, QToolBar *toolBar)
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
void setExpanding(bool enabled)
Definition: qtabbar.cpp:2271
void removeToolBar(QToolBar *toolbar)
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
bool toolBarBreak(QToolBar *toolBar) const
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QLayoutItem * takeAt(int *x, int index)
const char * layout
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void setDocumentMode(bool set)
Definition: qtabbar.cpp:2325
QRubberBand * gapIndicator
void setElideMode(Qt::TextElideMode)
Definition: qtabbar.cpp:2077
QDockAreaLayoutInfo * info(const QList< int > &path)
Q_CORE_EXPORT void qWarning(const char *,...)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
void transpose()
Swaps the width and height values.
Definition: qsize.cpp:196
void setTabBarShape(int shape)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QList< QToolBar * > qtoolbarsInUnifiedToolbarList
QString windowTitle
the window title (caption)
Definition: qwidget.h:198
QList< int > indexOf(QWidget *toolBar) const
bool layoutActions(const QSize &size)
QRegion separatorRegion() const
void restore(bool keepSavedState=false)
int titleHeight() const
QLayoutItem * itemAt(int *x, int index) const
void clear()
Removes all items from the list.
Definition: qlist.h:764
void insertToolBarBreak(QToolBar *before)
QList< int > indexOf(QWidget *dockWidget) const
QSet< QWidget * > usedSeparatorWidgets
void show()
Shows the widget and its child widgets.
QList< int > gapIndex(const QPoint &pos) const
bool restoreState(QDataStream &stream, const QMainWindowLayoutState &oldState)
bool insertGap(const QList< int > &path, QLayoutItem *item)
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
void hide()
Hides the widget.
Definition: qwidget.h:501
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
#define QT_NO_DOCKWIDGET
ToolBarArea
Definition: qnamespace.h:1353
bool restoreState(QDataStream &stream, const QList< QToolBar *> &toolBars, uchar tmarker, bool pre43, bool testing=false)
static QWidget * parentWidget(const QWidget *w)
bool animating() const
void saveState(QDataStream &stream) const
void stop()
Stops the timer.
Corner
Definition: qnamespace.h:1456
#define QT_NO_TABWIDGET
static Qt::ToolBarArea toToolBarArea(QInternal::DockPosition pos)
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
void moveToolBar(QToolBar *toolbar, int pos)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void addItem(QLayoutItem *item)
Implemented in subclasses to add an item.
static QInternal::DockPosition toDockPos(Qt::ToolBarArea area)
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
bool unifiedTitleAndToolBarOnMac
whether the window uses the unified title and toolbar look on Mac OS X
Definition: qmainwindow.h:83
QTabWidget::TabPosition tabPositions[4]
DockWidgetArea
Definition: qnamespace.h:1337
QLayoutItem * unplug(const QList< int > &path)
bool insertGap(const QList< int > &path, QLayoutItem *dockWidgetItem)
void remove(const QList< int > &path)
QDockAreaLayoutInfo docks[4]
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
QLayoutItem * unplug(const QList< int > &path, QToolBarAreaLayout *other)
Qt::DockWidgetArea corner(Qt::Corner corner) const
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
bool restoreState(QDataStream &stream, const QList< QDockWidget *> &widgets, bool testing=false)
int x() const
int count
the number of tabs in the tab bar
Definition: qtabbar.h:66
Qt::LayoutDirection layoutDirection() const
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
QLayoutItem * item(const QList< int > &path)
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
Definition: qlayout.cpp:1045
bool nativeWindowDeco() const
void insertToolBar(QToolBar *before, QToolBar *toolbar)
Adds toolbar before before.
QMainWindowLayout(QMainWindow *mainwindow, QLayout *parentLayout)
bool plug(QLayoutItem *widgetItem)
int separatorMove(const QList< int > &separator, const QPoint &origin, const QPoint &dest)
bool event(QEvent *e)
This is the main event handler; it handles event event.
Qt::DockWidgetArea dockWidgetArea(QDockWidget *dockwidget) const
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QList< QWidget * > unusedSeparatorWidgets
bool contains(QWidget *widget) const
QSize minimumSize(const QSize &centerMin) const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QSize maximumSize() const
void resize(int size)
Sets the size of the byte array to size bytes.
QDockAreaLayoutInfo * subinfo
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
#define QT_NO_RUBBERBAND
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void apply(bool animate)
QDockAreaLayoutItem & item(const QList< int > &path)
QLayoutItem * itemAt(int index) const
Must be implemented in subclasses to return the layout item at index.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QList< int > indexOf(QWidget *widget) const
void splitDockWidget(QDockWidget *after, QDockWidget *dockwidget, Qt::Orientation orientation)
QString objectName() const
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int timerId() const
Returns the timer&#39;s ID.
Definition: qbasictimer.h:63
QSize minimumSize() const
QSize minimumSize() const
QWidget * centralWidget() const
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
QStatusBar * statusBar() const
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
void applyState(QMainWindowLayoutState &newState, bool animate=true)
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
QList< QTabBar * > unusedTabBars
quint16 index
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
bool isMinimized() const
Definition: qwidget.cpp:3027
QBasicTimer separatorMoveTimer
QList< int > gapIndex(const QPoint &pos) const
void flush()
Flushes any buffered data waiting to be written to the device.
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
QWidgetAnimator widgetAnimator
QMainWindowTabBar(QWidget *parent)
void removeToolBarBreak(QToolBar *before)
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
QSize minimumSize() const
Returns the minimum size of this layout.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
ToolButtonStyle
Definition: qnamespace.h:1572
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos)
The QTabWidget class provides a stack of tabbed widgets.
Definition: qtabwidget.h:60
Shape shape() const
Qt::ToolBarArea toolBarArea
This variable holds the location for drawing the toolbar.
Definition: qstyleoption.h:379
void saveState(QDataStream &stream) const
QLayoutItem * itemAt(int *x, int index) const
void setTabShape(QTabWidget::TabShape tabShape)
void setDocumentMode(bool enabled)
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
const QRect & geometry() const
void apply(bool animate)
QLayoutItem * plug(const QList< int > &path)
QLayoutItem * takeAt(int index)
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item.
void remove(const QList< int > &path)
QRect itemRect(const QList< int > &path) const
Orientation
Definition: qnamespace.h:174
QToolBarAreaLayout toolBarAreaLayout
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary...
Definition: qrubberband.h:58
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void animationFinished(QWidget *widget)
QSize sizeHint() const
Implemented in subclasses to return the preferred size of this item.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
QMainWindowLayoutState savedState
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
QLayoutItem * unplug(const QList< int > &path, QMainWindowLayoutState *savedState=0)
#define enabled
TabShape
This enum type defines the shape of the tabs:
Definition: qtabwidget.h:126
bool restoreState(QDataStream &stream)
bool startSeparatorMove(const QPoint &pos)
bool separatorMove(const QPoint &pos)
bool usesHIToolBar(QToolBar *toolbar) const
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
#define QT_NO_TABBAR
void tabifyDockWidget(QDockWidget *first, QDockWidget *second)
bool restoreDockWidget(QDockWidget *dockwidget)
void animate(QWidget *widget, const QRect &final_geometry, bool animate)
QList< int > movingSeparator
static int area(const QSize &s)
Definition: qicon.cpp:155
QLayoutItem * widgetItem
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
QLayoutItem * unplug(QWidget *widget)
bool endSeparatorMove(const QPoint &pos)