Qt 4.8
qdockwidget.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 "qdockwidget.h"
43 
44 #ifndef QT_NO_DOCKWIDGET
45 #include <qaction.h>
46 #include <qapplication.h>
47 #include <qdesktopwidget.h>
48 #include <qdrawutil.h>
49 #include <qevent.h>
50 #include <qfontmetrics.h>
51 #include <qmainwindow.h>
52 #include <qrubberband.h>
53 #include <qstylepainter.h>
54 #include <qtoolbutton.h>
55 #include <qdebug.h>
56 
57 #include <private/qwidgetresizehandler_p.h>
58 
59 #include "qdockwidget_p.h"
60 #include "qmainwindowlayout_p.h"
61 #ifdef Q_WS_MAC
62 #include <private/qapplication_p.h>
63 #include <private/qt_mac_p.h>
64 #include <qmacstyle_mac.h>
65 #endif
66 
68 
69 extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); // qwidget.cpp
70 
71 // qmainwindow.cpp
73 
75 { return (priv->features & feature) == feature; }
76 
77 static inline bool hasFeature(const QDockWidget *dockwidget, QDockWidget::DockWidgetFeature feature)
78 { return (dockwidget->features() & feature) == feature; }
79 
80 
81 /*
82  A Dock Window:
83 
84  [+] is the float button
85  [X] is the close button
86 
87  +-------------------------------+
88  | Dock Window Title [+][X]|
89  +-------------------------------+
90  | |
91  | place to put the single |
92  | QDockWidget child (this space |
93  | does not yet have a name) |
94  | |
95  | |
96  | |
97  | |
98  | |
99  | |
100  | |
101  | |
102  | |
103  +-------------------------------+
104 
105 */
106 
107 /******************************************************************************
108 ** QDockWidgetTitleButton
109 */
110 
112 {
113  Q_OBJECT
114 
115 public:
116  QDockWidgetTitleButton(QDockWidget *dockWidget);
117 
118  QSize sizeHint() const;
119  inline QSize minimumSizeHint() const
120  { return sizeHint(); }
121 
122  void enterEvent(QEvent *event);
123  void leaveEvent(QEvent *event);
124  void paintEvent(QPaintEvent *event);
125 };
126 
127 
129  : QAbstractButton(dockWidget)
130 {
132 }
133 
135 {
136  ensurePolished();
137 
139  if (!icon().isNull()) {
141  QSize sz = icon().actualSize(QSize(iconSize, iconSize));
142  size += qMax(sz.width(), sz.height());
143  }
144 
145  return QSize(size, size);
146 }
147 
149 {
150  if (isEnabled()) update();
152 }
153 
155 {
156  if (isEnabled()) update();
158 }
159 
161 {
162  QPainter p(this);
163 
165  opt.init(this);
167 
169  {
170  if (isEnabled() && underMouse() && !isChecked() && !isDown())
172  if (isChecked())
173  opt.state |= QStyle::State_On;
174  if (isDown())
176  style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, &p, this);
177  }
178 
179  opt.icon = icon();
180  opt.subControls = 0;
181  opt.activeSubControls = 0;
183  opt.arrowType = Qt::NoArrow;
184  int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
185  opt.iconSize = QSize(size, size);
186  style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this);
187 }
188 
189 /******************************************************************************
190 ** QDockWidgetLayout
191 */
192 
194  : QLayout(parent), verticalTitleBar(false), item_list(RoleCount, 0)
195 {
196 }
197 
199 {
201 }
202 
204 {
205  return nativeWindowDeco(parentWidget()->isWindow());
206 }
207 
208 bool QDockWidgetLayout::nativeWindowDeco(bool floating) const
209 {
210 #if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_WINCE)
211  Q_UNUSED(floating);
212  return false;
213 #else
214  return floating && item_list[QDockWidgetLayout::TitleBar] == 0;
215 #endif
216 }
217 
218 
220 {
221  qWarning() << "QDockWidgetLayout::addItem(): please use QDockWidgetLayout::setWidget()";
222  return;
223 }
224 
226 {
227  int cnt = 0;
228  for (int i = 0; i < item_list.count(); ++i) {
229  QLayoutItem *item = item_list.at(i);
230  if (item == 0)
231  continue;
232  if (index == cnt++)
233  return item;
234  }
235  return 0;
236 }
237 
239 {
240  int j = 0;
241  for (int i = 0; i < item_list.count(); ++i) {
242  QLayoutItem *item = item_list.at(i);
243  if (item == 0)
244  continue;
245  if (index == j) {
246  item_list[i] = 0;
247  invalidate();
248  return item;
249  }
250  ++j;
251  }
252  return 0;
253 }
254 
256 {
257  int result = 0;
258  for (int i = 0; i < item_list.count(); ++i) {
259  if (item_list.at(i))
260  ++result;
261  }
262  return result;
263 }
264 
265 QSize QDockWidgetLayout::sizeFromContent(const QSize &content, bool floating) const
266 {
267  QSize result = content;
268 
269  if (verticalTitleBar) {
270  result.setHeight(qMax(result.height(), minimumTitleWidth()));
271  result.setWidth(qMax(content.width(), 0));
272  } else {
273  result.setHeight(qMax(result.height(), 0));
274  result.setWidth(qMax(content.width(), minimumTitleWidth()));
275  }
276 
278  const bool nativeDeco = nativeWindowDeco(floating);
279 
280  int fw = floating && !nativeDeco
282  : 0;
283 
284  const int th = titleHeight();
285  if (!nativeDeco) {
286  if (verticalTitleBar)
287  result += QSize(th + 2*fw, 2*fw);
288  else
289  result += QSize(2*fw, th + 2*fw);
290  }
291 
292  result.setHeight(qMin(result.height(), (int) QWIDGETSIZE_MAX));
293  result.setWidth(qMin(result.width(), (int) QWIDGETSIZE_MAX));
294 
295  if (content.width() < 0)
296  result.setWidth(-1);
297  if (content.height() < 0)
298  result.setHeight(-1);
299 
300  int left, top, right, bottom;
301  w->getContentsMargins(&left, &top, &right, &bottom);
302  //we need to substract the contents margin (it will be added by the caller)
303  QSize min = w->minimumSize() - QSize(left + right, top + bottom);
304  QSize max = w->maximumSize() - QSize(left + right, top + bottom);
305 
306  /* A floating dockwidget will automatically get its minimumSize set to the layout's
307  minimum size + deco. We're *not* interested in this, we only take minimumSize()
308  into account if the user set it herself. Otherwise we end up expanding the result
309  of a calculation for a non-floating dock widget to a floating dock widget's
310  minimum size + window decorations. */
311 
312  uint explicitMin = 0;
313  uint explicitMax = 0;
314  if (w->d_func()->extra != 0) {
315  explicitMin = w->d_func()->extra->explicitMinSize;
316  explicitMax = w->d_func()->extra->explicitMaxSize;
317  }
318 
319  if (!(explicitMin & Qt::Horizontal) || min.width() == 0)
320  min.setWidth(-1);
321  if (!(explicitMin & Qt::Vertical) || min.height() == 0)
322  min.setHeight(-1);
323 
324  if (!(explicitMax & Qt::Horizontal))
326  if (!(explicitMax & Qt::Vertical))
328 
329  return result.boundedTo(max).expandedTo(min);
330 }
331 
333 {
335 
336  QSize content(-1, -1);
337  if (item_list[Content] != 0)
338  content = item_list[Content]->sizeHint();
339 
340  return sizeFromContent(content, w->isFloating());
341 }
342 
344 {
345  if (item_list[Content] != 0) {
346  const QSize content = item_list[Content]->maximumSize();
347  return sizeFromContent(content, parentWidget()->isWindow());
348  } else {
349  return parentWidget()->maximumSize();
350  }
351 
352 }
353 
355 {
357 
358  QSize content(0, 0);
359  if (item_list[Content] != 0)
360  content = item_list[Content]->minimumSize();
361 
362  return sizeFromContent(content, w->isFloating());
363 }
364 
366 {
367  QLayoutItem *item = item_list.at(r);
368  return item == 0 ? 0 : item->widget();
369 }
370 
372 {
373  return item_list.at(r);
374 }
375 
377 {
378  QWidget *old = widgetForRole(r);
379  if (old != 0) {
380  old->hide();
381  removeWidget(old);
382  }
383 
384  if (w != 0) {
385  addChildWidget(w);
386  item_list[r] = new QWidgetItemV2(w);
387  w->show();
388  } else {
389  item_list[r] = 0;
390  }
391 
392  invalidate();
393 }
394 
395 static inline int pick(bool vertical, const QSize &size)
396 {
397  return vertical ? size.height() : size.width();
398 }
399 
400 static inline int perp(bool vertical, const QSize &size)
401 {
402  return vertical ? size.width() : size.height();
403 }
404 
406 {
408 
409  if (QWidget *title = widgetForRole(TitleBar))
410  return pick(verticalTitleBar, title->minimumSizeHint());
411 
412  QSize closeSize(0, 0);
413  QSize floatSize(0, 0);
415  if (QLayoutItem *item = item_list[CloseButton])
416  closeSize = item->widget()->sizeHint();
417  }
419  if (QLayoutItem *item = item_list[FloatButton])
420  floatSize = item->widget()->sizeHint();
421  }
422 
423  int titleHeight = this->titleHeight();
424 
425  int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
426  int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q);
427 
428  return pick(verticalTitleBar, closeSize)
429  + pick(verticalTitleBar, floatSize)
430  + titleHeight + 2*fw + 3*mw;
431 }
432 
434 {
436 
437  if (QWidget *title = widgetForRole(TitleBar))
438  return perp(verticalTitleBar, title->sizeHint());
439 
440  QSize closeSize(0, 0);
441  QSize floatSize(0, 0);
442  if (QLayoutItem *item = item_list[CloseButton])
443  closeSize = item->widget()->sizeHint();
444  if (QLayoutItem *item = item_list[FloatButton])
445  floatSize = item->widget()->sizeHint();
446 
447  int buttonHeight = qMax(perp(verticalTitleBar, closeSize),
448  perp(verticalTitleBar, floatSize));
449 
450  QFontMetrics titleFontMetrics = q->fontMetrics();
451 #ifdef Q_WS_MAC
452  if (qobject_cast<QMacStyle *>(q->style())) {
453  //### this breaks on proxy styles. (But is this code still called?)
454  QFont font = qt_app_fonts_hash()->value("QToolButton", q->font());
455  titleFontMetrics = QFontMetrics(font);
456  }
457 #endif
458 
459  int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
460 
461  return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw);
462 }
463 
465 {
467 
468  bool nativeDeco = nativeWindowDeco();
469 
470  int fw = q->isFloating() && !nativeDeco
472  : 0;
473 
474  if (nativeDeco) {
475  if (QLayoutItem *item = item_list[Content])
476  item->setGeometry(geometry);
477  } else {
478  int titleHeight = this->titleHeight();
479 
480  if (verticalTitleBar) {
481  _titleArea = QRect(QPoint(fw, fw),
482  QSize(titleHeight, geometry.height() - (fw * 2)));
483  } else {
484  _titleArea = QRect(QPoint(fw, fw),
485  QSize(geometry.width() - (fw * 2), titleHeight));
486  }
487 
488  if (QLayoutItem *item = item_list[TitleBar]) {
489  item->setGeometry(_titleArea);
490  } else {
492  q->initStyleOption(&opt);
493 
494  if (QLayoutItem *item = item_list[CloseButton]) {
495  if (!item->isEmpty()) {
496  QRect r = q->style()
498  &opt, q);
499  if (!r.isNull())
500  item->setGeometry(r);
501  }
502  }
503 
504  if (QLayoutItem *item = item_list[FloatButton]) {
505  if (!item->isEmpty()) {
506  QRect r = q->style()
508  &opt, q);
509  if (!r.isNull())
510  item->setGeometry(r);
511  }
512  }
513  }
514 
515  if (QLayoutItem *item = item_list[Content]) {
516  QRect r = geometry;
517  if (verticalTitleBar) {
518  r.setLeft(_titleArea.right() + 1);
519  r.adjust(0, fw, -fw, -fw);
520  } else {
521  r.setTop(_titleArea.bottom() + 1);
522  r.adjust(fw, 0, -fw, -fw);
523  }
524  item->setGeometry(r);
525  }
526  }
527 }
528 
530 {
531  if (b == verticalTitleBar)
532  return;
533  verticalTitleBar = b;
534  invalidate();
535  parentWidget()->update();
536 }
537 
538 /******************************************************************************
539 ** QDockWidgetItem
540 */
541 
543  : QWidgetItem(dockWidget)
544 {
545 }
546 
548 {
549  QSize widgetMin(0, 0);
550  if (QLayoutItem *item = dockWidgetChildItem())
551  widgetMin = item->minimumSize();
552  return dockWidgetLayout()->sizeFromContent(widgetMin, false);
553 }
554 
556 {
557  if (QLayoutItem *item = dockWidgetChildItem()) {
558  return dockWidgetLayout()->sizeFromContent(item->maximumSize(), false);
559  } else {
561  }
562 }
563 
564 
566 {
567  if (QLayoutItem *item = dockWidgetChildItem()) {
568  return dockWidgetLayout()->sizeFromContent(item->sizeHint(), false);
569  } else {
570  return QWidgetItem::sizeHint();
571  }
572 }
573 
574 /******************************************************************************
575 ** QDockWidgetPrivate
576 */
577 
579 {
580  Q_Q(QDockWidget);
581 
584 
585  QAbstractButton *button = new QDockWidgetTitleButton(q);
586  button->setObjectName(QLatin1String("qt_dockwidget_floatbutton"));
587  QObject::connect(button, SIGNAL(clicked()), q, SLOT(_q_toggleTopLevel()));
589 
590  button = new QDockWidgetTitleButton(q);
591  button->setObjectName(QLatin1String("qt_dockwidget_closebutton"));
592  QObject::connect(button, SIGNAL(clicked()), q, SLOT(close()));
594 
595  resizer = new QWidgetResizeHandler(q);
596  resizer->setMovingEnabled(false);
597  resizer->setActive(false);
598 
599 #ifndef QT_NO_ACTION
600  toggleViewAction = new QAction(q);
601  toggleViewAction->setCheckable(true);
602  fixedWindowTitle = qt_setWindowTitle_helperHelper(q->windowTitle(), q);
603  toggleViewAction->setText(fixedWindowTitle);
604  QObject::connect(toggleViewAction, SIGNAL(triggered(bool)),
605  q, SLOT(_q_toggleView(bool)));
606 #endif
607 
608  updateButtons();
609 }
610 
619 {
620  Q_D(const QDockWidget);
621 
622  if (!option)
623  return;
625 
626  option->initFrom(this);
627  option->rect = dwlayout->titleArea();
628  option->title = d->fixedWindowTitle;
632 
636  if (v2 != 0)
638 }
639 
641 {
642  Q_Q(QDockWidget);
643  if (b == q->isHidden()) {
644  if (b)
645  q->show();
646  else
647  q->close();
648  }
649 }
650 
652 {
653  Q_Q(QDockWidget);
655 
657  q->initStyleOption(&opt);
658 
659  bool customTitleBar = dwLayout->widgetForRole(QDockWidgetLayout::TitleBar) != 0;
660  bool nativeDeco = dwLayout->nativeWindowDeco();
661  bool hideButtons = nativeDeco || customTitleBar;
662 
663  bool canClose = hasFeature(this, QDockWidget::DockWidgetClosable);
664  bool canFloat = hasFeature(this, QDockWidget::DockWidgetFloatable);
665 
666  QAbstractButton *button
668  button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarNormalButton, &opt, q));
669  button->setVisible(canFloat && !hideButtons);
670 
671  button
673  button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarCloseButton, &opt, q));
674  button->setVisible(canClose && !hideButtons);
675 
676  q->setAttribute(Qt::WA_ContentsPropagated,
677  (canFloat || canClose) && !hideButtons);
678 
679  layout->invalidate();
680 }
681 
683 {
684  Q_Q(QDockWidget);
685  q->setFloating(!q->isFloating());
686 }
687 
688 void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca)
689 {
690  if (state != 0)
691  return;
692 
693  Q_Q(QDockWidget);
694  QMainWindow *win = qobject_cast<QMainWindow*>(parent);
695  Q_ASSERT(win != 0);
697  Q_ASSERT(layout != 0);
698  if (layout->pluggingWidget != 0) // the main window is animating a docking operation
699  return;
700 
701  state = new QDockWidgetPrivate::DragState;
702  state->dragging = false;
703  state->widgetItem = 0;
704  state->ownWidgetItem = false;
705  state->nca = nca;
706  state->ctrlDrag = false;
707 
708  if (!q->isFloating()) {
709  // When dragging the widget out of the docking area,
710  // use the middle of title area as pressPos
711  QDockWidgetLayout *dwlayout = qobject_cast<QDockWidgetLayout*>(q->layout());
712  Q_ASSERT(dwlayout != 0);
713  int width = undockedGeometry.isNull() ? q->width() : undockedGeometry.width();
714  state->pressPos.setY(dwlayout->titleArea().height() / 2);
715  state->pressPos.setX(width / 2);
716  } else {
717  state->pressPos = pos;
718  }
719 }
720 
722 {
723  Q_Q(QDockWidget);
724 
725  if (state == 0 || state->dragging)
726  return;
727 
728  QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
729  Q_ASSERT(layout != 0);
730 
731  state->widgetItem = layout->unplug(q);
732  if (state->widgetItem == 0) {
733  /* I have a QMainWindow parent, but I was never inserted with
734  QMainWindow::addDockWidget, so the QMainWindowLayout has no
735  widget item for me. :( I have to create it myself, and then
736  delete it if I don't get dropped into a dock area. */
737  state->widgetItem = new QDockWidgetItem(q);
738  state->ownWidgetItem = true;
739  }
740 
741  if (state->ctrlDrag)
742  layout->restore();
743 
744  state->dragging = true;
745 }
746 
748 {
749  Q_Q(QDockWidget);
750  Q_ASSERT(state != 0);
751 
752  q->releaseMouse();
753 
754  if (state->dragging) {
755  QMainWindowLayout *mwLayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
756  Q_ASSERT(mwLayout != 0);
757 
758  if (abort || !mwLayout->plug(state->widgetItem)) {
760  if (state->ownWidgetItem)
761  delete state->widgetItem;
762  mwLayout->restore();
763 #ifdef Q_WS_X11
764  // get rid of the X11BypassWindowManager window flag and activate the resizer
765  Qt::WindowFlags flags = q->windowFlags();
767  q->setWindowFlags(flags);
768  resizer->setActive(QWidgetResizeHandler::Resize, true);
769  q->show();
770 #else
771  QDockWidgetLayout *myLayout
773  resizer->setActive(QWidgetResizeHandler::Resize,
775 #endif
776  undockedGeometry = q->geometry();
777  q->activateWindow();
778  } else {
779  mwLayout->revert(state->widgetItem);
780  }
781  }
782  }
783  delete state;
784  state = 0;
785 }
786 
788 {
789  Q_Q(const QDockWidget);
790 
791  QMainWindow *mainWin = qobject_cast<QMainWindow*>(parent);
792  if (mainWin == 0)
793  return false;
794 
795  QMainWindowLayout *mainWinLayout = qt_mainwindow_layout(mainWin);
796  if (mainWinLayout == 0)
797  return false;
798 
799  return (void*)mainWinLayout->pluggingWidget == (void*)q;
800 }
801 
803 {
804 #if !defined(QT_NO_MAINWINDOW)
805  Q_Q(QDockWidget);
806 
807  QDockWidgetLayout *dwLayout
809 
810  if (!dwLayout->nativeWindowDeco()) {
811  QRect titleArea = dwLayout->titleArea();
812 
813  if (event->button() != Qt::LeftButton ||
814  !titleArea.contains(event->pos()) ||
815  // check if the tool window is movable... do nothing if it
816  // is not (but allow moving if the window is floating)
817  (!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) ||
818  qobject_cast<QMainWindow*>(parent) == 0 ||
819  isAnimating() || state != 0) {
820  return false;
821  }
822 
823  initDrag(event->pos(), false);
824 
825  if (state)
826  state->ctrlDrag = hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier;
827 
828  return true;
829  }
830 
831 #endif // !defined(QT_NO_MAINWINDOW)
832  return false;
833 }
834 
836 {
838 
839  if (!dwLayout->nativeWindowDeco()) {
840  QRect titleArea = dwLayout->titleArea();
841 
842  if (event->button() == Qt::LeftButton && titleArea.contains(event->pos()) &&
844  _q_toggleTopLevel();
845  return true;
846  }
847  }
848  return false;
849 }
850 
852 {
853  bool ret = false;
854 #if !defined(QT_NO_MAINWINDOW)
855  Q_Q(QDockWidget);
856 
857  if (!state)
858  return ret;
859 
860  QDockWidgetLayout *dwlayout
862  QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
863  if (!dwlayout->nativeWindowDeco()) {
864  if (!state->dragging
865  && mwlayout->pluggingWidget == 0
866  && (event->pos() - state->pressPos).manhattanLength()
868  startDrag();
869 #ifdef Q_OS_WIN
870  grabMouseWhileInWindow();
871 #else
872  q->grabMouse();
873 #endif
874  ret = true;
875  }
876  }
877 
878  if (state->dragging && !state->nca) {
879  QPoint pos = event->globalPos() - state->pressPos;
880  q->move(pos);
881 
882  if (!state->ctrlDrag)
883  mwlayout->hover(state->widgetItem, event->globalPos());
884 
885  ret = true;
886  }
887 
888 #endif // !defined(QT_NO_MAINWINDOW)
889  return ret;
890 }
891 
893 {
894 #if !defined(QT_NO_MAINWINDOW)
895 
896  if (event->button() == Qt::LeftButton && state && !state->nca) {
897  endDrag();
898  return true; //filter out the event
899  }
900 
901 #endif // !defined(QT_NO_MAINWINDOW)
902  return false;
903 }
904 
906 {
907  Q_Q(QDockWidget);
908 
909  int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q);
910 
911  QRect geo = q->geometry();
912  QRect titleRect = q->frameGeometry();
913 #ifdef Q_WS_MAC
914  if ((features & QDockWidget::DockWidgetVerticalTitleBar)) {
915  titleRect.setTop(geo.top());
916  titleRect.setBottom(geo.bottom());
917  titleRect.setRight(geo.left() - 1);
918  } else
919 #endif
920  {
921  titleRect.setLeft(geo.left());
922  titleRect.setRight(geo.right());
923  titleRect.setBottom(geo.top() - 1);
924  titleRect.adjust(0, fw, 0, 0);
925  }
926 
927  switch (event->type()) {
929  if (!titleRect.contains(event->globalPos()))
930  break;
931  if (state != 0)
932  break;
933  if (qobject_cast<QMainWindow*>(parent) == 0)
934  break;
935  if (isAnimating())
936  break;
937  initDrag(event->pos(), true);
938  if (state == 0)
939  break;
940 #ifdef Q_OS_WIN
941  // On Windows, NCA mouse events don't contain modifier info
942  state->ctrlDrag = GetKeyState(VK_CONTROL) & 0x8000;
943 #else
944  state->ctrlDrag = event->modifiers() & Qt::ControlModifier;
945 #endif
946  startDrag();
947  break;
949  if (state == 0 || !state->dragging)
950  break;
951  if (state->nca) {
952  endDrag();
953  }
954 #ifdef Q_OS_MAC
955  else { // workaround for lack of mouse-grab on Mac
956  QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
957  Q_ASSERT(layout != 0);
958 
959  q->move(event->globalPos() - state->pressPos);
960  if (!state->ctrlDrag)
961  layout->hover(state->widgetItem, event->globalPos());
962  }
963 #endif
964  break;
966 #ifdef Q_OS_MAC
967  if (state)
968  endDrag();
969 #endif
970  break;
972  _q_toggleTopLevel();
973  break;
974  default:
975  break;
976  }
977 }
978 
980 {
981  Q_Q(QDockWidget);
982 
983  if (state == 0 || !state->dragging || !state->nca || !q->isWindow())
984  return;
985 
986  // When the native window frame is being dragged, all we get is these mouse
987  // move events.
988 
989  if (state->ctrlDrag)
990  return;
991 
992  QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
993  Q_ASSERT(layout != 0);
994 
995  QPoint globalMousePos = event->pos() + state->pressPos;
996  layout->hover(state->widgetItem, globalMousePos);
997 }
998 
1000 {
1001  Q_Q(QDockWidget);
1002  QRect r;
1003  if (!undockedGeometry.isNull()) {
1004  r = undockedGeometry;
1005  } else {
1006  r = rect;
1007  r.moveTopLeft(q->mapToGlobal(QPoint(0, 0)));
1009  if (dwLayout->nativeWindowDeco(true))
1010  r.adjust(0, dwLayout->titleHeight(), 0, 0);
1011  }
1012 
1013  setWindowState(true, true, r);
1014 }
1015 
1017 {
1018  setWindowState(false, false, rect);
1019 }
1020 
1021 void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect &rect)
1022 {
1023  Q_Q(QDockWidget);
1024 
1025  if (!floating && parent) {
1026  QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
1027  if (mwlayout && mwlayout->dockWidgetArea(q) == Qt::NoDockWidgetArea)
1028  return; // this dockwidget can't be redocked
1029  }
1030 
1031  bool wasFloating = q->isFloating();
1032  bool hidden = q->isHidden();
1033 
1034  if (q->isVisible())
1035  q->hide();
1036 
1037  Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget;
1038 
1040  const bool nativeDeco = dwLayout->nativeWindowDeco(floating);
1041 
1042  if (nativeDeco) {
1045  flags |= Qt::WindowCloseButtonHint;
1046  } else {
1047  flags |= Qt::FramelessWindowHint;
1048  }
1049 
1050  if (unplug)
1052 
1053  q->setWindowFlags(flags);
1054 
1055 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
1056  if (floating && nativeDeco && (q->features() & QDockWidget::DockWidgetVerticalTitleBar)) {
1057  ChangeWindowAttributes(HIViewGetWindow(HIViewRef(q->winId())), kWindowSideTitlebarAttribute, 0);
1058  }
1059 #endif
1060 
1061  if (!rect.isNull())
1062  q->setGeometry(rect);
1063 
1064  updateButtons();
1065 
1066  if (!hidden)
1067  q->show();
1068 
1069  if (floating != wasFloating) {
1070  emit q->topLevelChanged(floating);
1071  if (!floating && parent) {
1072  QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
1073  if (mwlayout)
1074  emit q->dockLocationChanged(mwlayout->dockWidgetArea(q));
1075  }
1076  }
1077 
1078  resizer->setActive(QWidgetResizeHandler::Resize, !unplug && floating && !nativeDeco);
1079 }
1080 
1171 QDockWidget::QDockWidget(QWidget *parent, Qt::WindowFlags flags)
1172  : QWidget(*new QDockWidgetPrivate, parent, flags)
1173 {
1174  Q_D(QDockWidget);
1175  d->init();
1176 }
1177 
1189 QDockWidget::QDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
1190  : QWidget(*new QDockWidgetPrivate, parent, flags)
1191 {
1192  Q_D(QDockWidget);
1193  d->init();
1194  setWindowTitle(title);
1195 }
1196 
1201 { }
1202 
1210 {
1212  return layout->widgetForRole(QDockWidgetLayout::Content);
1213 }
1214 
1227 {
1230 }
1231 
1245 void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features)
1246 {
1247  Q_D(QDockWidget);
1248  features &= DockWidgetFeatureMask;
1249  if (d->features == features)
1250  return;
1251  const bool closableChanged = (d->features ^ features) & DockWidgetClosable;
1252  d->features = features;
1254  = qobject_cast<QDockWidgetLayout*>(this->layout());
1255  layout->setVerticalTitleBar(features & DockWidgetVerticalTitleBar);
1256  d->updateButtons();
1257  d->toggleViewAction->setEnabled((d->features & DockWidgetClosable) == DockWidgetClosable);
1258  emit featuresChanged(d->features);
1259  update();
1260  if (closableChanged && layout->nativeWindowDeco()) {
1261  //this ensures the native decoration is drawn
1262  d->setWindowState(true /*floating*/, true /*unplug*/);
1263  }
1264 }
1265 
1266 QDockWidget::DockWidgetFeatures QDockWidget::features() const
1267 {
1268  Q_D(const QDockWidget);
1269  return d->features;
1270 }
1271 
1288 {
1289  Q_D(QDockWidget);
1290 
1291  // the initial click of a double-click may have started a drag...
1292  if (d->state != 0)
1293  d->endDrag(true);
1294 
1295  QRect r = d->undockedGeometry;
1296  // Keep position when undocking for the first time.
1297  if (floating && isVisible() && !r.isValid())
1298  r = QRect(mapToGlobal(QPoint(0, 0)), size());
1299 
1300  d->setWindowState(floating, false, floating ? r : QRect());
1301 
1302  if (floating && r.isNull()) {
1303  if (x() < 0 || y() < 0) //may happen if we have been hidden
1304  move(QPoint());
1305  setAttribute(Qt::WA_Moved, false); //we want it at the default position
1306  }
1307 }
1308 
1321 void QDockWidget::setAllowedAreas(Qt::DockWidgetAreas areas)
1322 {
1323  Q_D(QDockWidget);
1324  areas &= Qt::DockWidgetArea_Mask;
1325  if (areas == d->allowedAreas)
1326  return;
1327  d->allowedAreas = areas;
1328  emit allowedAreasChanged(d->allowedAreas);
1329 }
1330 
1331 Qt::DockWidgetAreas QDockWidget::allowedAreas() const
1332 {
1333  Q_D(const QDockWidget);
1334  return d->allowedAreas;
1335 }
1336 
1349 {
1350  Q_D(QDockWidget);
1352 
1353  switch (event->type()) {
1356  update(layout->titleArea());
1357 #ifndef QT_NO_ACTION
1358  d->fixedWindowTitle = qt_setWindowTitle_helperHelper(windowTitle(), this);
1359  d->toggleViewAction->setText(d->fixedWindowTitle);
1360 #endif
1361 #ifndef QT_NO_TABBAR
1362  {
1364  if (QMainWindowLayout *winLayout = qt_mainwindow_layout(win)) {
1365  if (QDockAreaLayoutInfo *info = winLayout->layoutState.dockAreaLayout.info(this))
1366  info->updateTabBar();
1367  }
1368  }
1369 #endif // QT_NO_TABBAR
1370  break;
1371  default:
1372  break;
1373  }
1374  QWidget::changeEvent(event);
1375 }
1376 
1379 {
1380  Q_D(QDockWidget);
1381  if (d->state)
1382  d->endDrag(true);
1383  QWidget::closeEvent(event);
1384 }
1385 
1388 {
1389  Q_UNUSED(event)
1390 
1392  = qobject_cast<QDockWidgetLayout*>(this->layout());
1393  bool customTitleBar = layout->widgetForRole(QDockWidgetLayout::TitleBar) != 0;
1394  bool nativeDeco = layout->nativeWindowDeco();
1395 
1396  if (!nativeDeco && !customTitleBar) {
1397  QStylePainter p(this);
1398  // ### Add PixelMetric to change spacers, so style may show border
1399  // when not floating.
1400  if (isFloating()) {
1401  QStyleOptionFrame framOpt;
1402  framOpt.init(this);
1404  }
1405 
1406  // Title must be painted after the frame, since the areas overlap, and
1407  // the title may wish to extend out to all sides (eg. XP style)
1408  QStyleOptionDockWidgetV2 titleOpt;
1409  initStyleOption(&titleOpt);
1411  }
1412 }
1413 
1416 {
1417  Q_D(QDockWidget);
1418 
1421 
1422  switch (event->type()) {
1423 #ifndef QT_NO_ACTION
1424  case QEvent::Hide:
1425  if (layout != 0)
1426  layout->keepSize(this);
1427  d->toggleViewAction->setChecked(false);
1428  emit visibilityChanged(false);
1429  break;
1430  case QEvent::Show: {
1431  d->toggleViewAction->setChecked(true);
1432  const QPoint parentTopLeft = isWindow() ?
1434  emit visibilityChanged(geometry().right() >= parentTopLeft.x() && geometry().bottom() >= parentTopLeft.y());
1435 }
1436  break;
1437 #endif
1440  case QEvent::StyleChange:
1441  case QEvent::ParentChange:
1442  d->updateButtons();
1443  break;
1444  case QEvent::ZOrderChange: {
1445  bool onTop = false;
1446  if (win != 0) {
1447  const QObjectList &siblings = win->children();
1448  onTop = siblings.count() > 0 && siblings.last() == (QObject*)this;
1449  }
1450  if (!isFloating() && layout != 0 && onTop)
1451  layout->raise(this);
1452  break;
1453  }
1456  update(qobject_cast<QDockWidgetLayout *>(this->layout())->titleArea());
1457  break;
1458  case QEvent::ContextMenu:
1459  if (d->state) {
1460  event->accept();
1461  return true;
1462  }
1463  break;
1464  // return true after calling the handler since we don't want
1465  // them to be passed onto the default handlers
1467  if (d->mousePressEvent(static_cast<QMouseEvent *>(event)))
1468  return true;
1469  break;
1471  if (d->mouseDoubleClickEvent(static_cast<QMouseEvent *>(event)))
1472  return true;
1473  break;
1474  case QEvent::MouseMove:
1475  if (d->mouseMoveEvent(static_cast<QMouseEvent *>(event)))
1476  return true;
1477  break;
1478 #ifdef Q_OS_WIN
1479  case QEvent::Leave:
1480  if (d->state != 0 && d->state->dragging && !d->state->nca) {
1481  // This is a workaround for loosing the mouse on Vista.
1482  QPoint pos = QCursor::pos();
1485  d->mouseMoveEvent(&fake);
1486  }
1487  break;
1488 #endif
1490  if (d->mouseReleaseEvent(static_cast<QMouseEvent *>(event)))
1491  return true;
1492  break;
1497  d->nonClientAreaMouseEvent(static_cast<QMouseEvent*>(event));
1498  return true;
1499  case QEvent::Move:
1500  d->moveEvent(static_cast<QMoveEvent*>(event));
1501  break;
1502  case QEvent::Resize:
1503  // if the mainwindow is plugging us, we don't want to update undocked geometry
1504  if (isFloating() && layout != 0 && layout->pluggingWidget != this)
1505  d->undockedGeometry = geometry();
1506  break;
1507  default:
1508  break;
1509  }
1510  return QWidget::event(event);
1511 }
1512 
1513 #ifndef QT_NO_ACTION
1514 
1523 {
1524  Q_D(const QDockWidget);
1525  return d->toggleViewAction;
1526 }
1527 #endif // QT_NO_ACTION
1528 
1633 {
1634  Q_D(QDockWidget);
1636  = qobject_cast<QDockWidgetLayout*>(this->layout());
1638  d->updateButtons();
1639  if (isWindow()) {
1640  //this ensures the native decoration is drawn
1641  d->setWindowState(true /*floating*/, true /*unplug*/);
1642  }
1643 }
1644 
1657 {
1659  = qobject_cast<QDockWidgetLayout*>(this->layout());
1661 }
1662 
1664 
1665 #include "qdockwidget.moc"
1666 #include "moc_qdockwidget.cpp"
1667 
1668 #endif // QT_NO_DOCKWIDGET
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
QPoint pos() const
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QDockWidgetItem(QDockWidget *dockWidget)
double d
Definition: qnumeric_p.h:62
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
void initDrag(const QPoint &pos, bool nca)
QSize sizeFromContent(const QSize &content, bool floating) const
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
void allowedAreasChanged(Qt::DockWidgetAreas allowedAreas)
This signal is emitted when the allowedAreas property changes.
bool isChecked() const
int y() const
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
static mach_timebase_info_data_t info
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QDockWidgetTitleButton(QDockWidget *dockWidget)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QStyleOptionDockWidget class is used to describe the parameters for drawing a dock widget...
Definition: qstyleoption.h:504
QSize sizeHint() const
EventRef event
QSize size() const
void unplug(const QRect &rect)
void drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
Use the widget&#39;s style to draw a control element ce specified by QStyleOption option.
Definition: qstylepainter.h:87
void revert(QLayoutItem *widgetItem)
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
QSize sizeHint() const
Reimplemented Function
void featuresChanged(QDockWidget::DockWidgetFeatures features)
This signal is emitted when the features property changes.
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
Qt::ArrowType arrowType
the direction of the arrow for the tool button
Definition: qstyleoption.h:782
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void visibilityChanged(bool visible)
This signal is emitted when the dock widget becomes visible (or invisible).
DockWidgetFeatures features() const
QAction * toggleViewAction() const
Returns a checkable action that can be used to show or close this dock widget.
bool isVisible() const
Definition: qwidget.h:1005
int count() const
Must be implemented in subclasses to return the number of items in the layout.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
bool closable
whether the dock window is closable
Definition: qstyleoption.h:511
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual void leaveEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition: qwidget.cpp:9491
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QSize maximumSize() const
Returns the maximum size of this layout.
bool isDown() const
QDockWidget(const QString &title, QWidget *parent=0, Qt::WindowFlags flags=0)
Constructs a QDockWidget with parent parent and window flags flags.
void changeEvent(QEvent *event)
Reimplemented Function
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
void init(const QWidget *w)
Use initFrom(widget) instead.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setWidgetForRole(Role r, QWidget *w)
QLayoutItem * dockWidgetChildItem() const
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QWidget * widget() const
Returns the widget for the dock widget.
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
bool underMouse() const
Returns true if the widget is under the mouse cursor; otherwise returns false.
Definition: qwidget.h:996
QList< int > hover(QLayoutItem *widgetItem, const QPoint &mousePos)
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
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
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
The QStyleOptionToolButton class is used to describe the parameters for drawing a tool button...
Definition: qstyleoption.h:768
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
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
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QDockWidgetLayout * dockWidgetLayout() const
bool movable
whether the dock window is movable
Definition: qstyleoption.h:512
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void leaveEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
bool event(QEvent *e)
Reimplemented Function
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
DockWidgetFeatures features
whether the dock widget is movable, closable, and floatable
Definition: qdockwidget.h:66
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QMoveEvent class contains event parameters for move events.
Definition: qevent.h:334
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt)
Use the widget&#39;s style to draw a primitive element pe specified by QStyleOption option.
Definition: qstylepainter.h:82
void addItem(QLayoutItem *item)
Implemented in subclasses to add an item.
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
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
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
QSize sizeHint() const
Implemented in subclasses to return the preferred size of this item.
QString qt_setWindowTitle_helperHelper(const QString &, const QWidget *)
Returns a modified window title with the [*] place holder replaced according to the rules described i...
Definition: qwidget.cpp:6240
struct OpaqueControlRef * HIViewRef
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
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 setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
QVector< QLayoutItem * > item_list
const char * styleHint(const QFontDef &request)
Q_CORE_EXPORT void qWarning(const char *,...)
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
unsigned int uint
Definition: qglobal.h:996
bool mouseMoveEvent(QMouseEvent *event)
FontHash * qt_app_fonts_hash()
QSize maximumSize() const
Reimplemented Function
QSize sizeHint() const
Reimplemented Function
bool mouseReleaseEvent(QMouseEvent *event)
QString windowTitle() const
QDockWidgetLayout(QWidget *parent=0)
void setWidget(QWidget *widget)
Sets the widget for the dock widget to widget.
QLayoutItem * itemAt(int index) const
Must be implemented in subclasses to return the layout item at index.
void paintEvent(QPaintEvent *event)
Reimplemented Function
void restore(bool keepSavedState=false)
int titleHeight() const
virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget=0) const =0
Draws the given control using the provided painter with the style options specified by option...
static int startDragDistance()
QDockWidget::DockWidgetFeatures features
void setAllowedAreas(Qt::DockWidgetAreas areas)
void show()
Shows the widget and its child widgets.
Qt::DockWidgetAreas allowedAreas() const
The QWidgetItem class is a layout item that represents a widget.
Definition: qlayoutitem.h:122
QSize minimumSizeHint() const
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
int minimumTitleWidth() const
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
bool isEnabled() const
Definition: qwidget.h:948
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
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QSize iconSize
the size of the icon for the tool button
Definition: qstyleoption.h:780
static int perp(bool vertical, const QSize &size)
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
bool floatable
whether the dock window is floatable
Definition: qstyleoption.h:513
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
void moveEvent(QMoveEvent *event)
static bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
Definition: qdockwidget.cpp:74
void setFeatures(DockWidgetFeatures features)
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QSize iconSize() const
bool isAnimating() const
QWidget * titleBarWidget() const
Returns the custom title bar widget set on the QDockWidget, or 0 if no custom title bar has been set...
QRect titleArea() const
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
QIcon icon
the icon for the tool button
Definition: qstyleoption.h:779
QSize minimumSize() const
Reimplemented Function
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
void plug(const QRect &rect)
ToolButtonFeatures features
an OR combination of the tool button&#39;s features
Definition: qstyleoption.h:778
int x() const
void _q_toggleView(bool)
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
void setFloating(bool floating)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QLayoutItem * itemForRole(Role r) const
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
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
void enterEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
bool plug(QLayoutItem *widgetItem)
T qstyleoption_cast(const QStyleOption *opt)
Definition: qstyleoption.h:885
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
Definition: qicon.cpp:730
Qt::DockWidgetArea dockWidgetArea(QDockWidget *dockwidget) const
void closeEvent(QCloseEvent *event)
Reimplemented Function
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool mouseDoubleClickEvent(QMouseEvent *event)
bool mousePressEvent(QMouseEvent *event)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual void closeEvent(QCloseEvent *)
This event handler is called with the given event when Qt receives a window close request for a top-l...
Definition: qwidget.cpp:9626
QSize maximumSize() const
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
void endDrag(bool abort=false)
static const QMetaObjectPrivate * priv(const uint *data)
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
void setTitleBarWidget(QWidget *widget)
Sets an arbitrary widget as the dock widget&#39;s title bar.
Definition: qnamespace.h:54
bool isFloating() const
Definition: qdockwidget.h:96
QFactoryLoader * l
QSize minimumSize() const
void setVerticalTitleBar(bool b)
bool floating
whether the dock widget is floating
Definition: qdockwidget.h:65
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QLayoutItem * takeAt(int index)
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item.
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
quint16 index
QString title
the title of the dock window
Definition: qstyleoption.h:510
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
static int pick(bool vertical, const QSize &size)
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
QWidget * widgetForRole(Role r) const
bool event(QEvent *event)
Reimplemented Function
QSize minimumSize() const
Returns the minimum size of this layout.
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
const QFont & font() const
void setSizeConstraint(SizeConstraint)
Definition: qlayout.cpp:1435
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QRect availableGeometry(int screen=-1) const
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
void nonClientAreaMouseEvent(QMouseEvent *event)
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
QRect geometry() const
Reimplemented Function
Definition: qlayout.cpp:664
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
int height() const
Returns the height of the font.
const QRect & geometry() const
~QDockWidget()
Destroys the dock widget.
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void setIcon(const QIcon &icon)
void initStyleOption(QStyleOptionDockWidget *option) const
Initialize option with the values from this QDockWidget.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#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
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
void setGeometry(const QRect &r)
Reimplemented Function
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:364
void paintEvent(QPaintEvent *event)
Reimplemented Function
void setWindowState(bool floating, bool unplug=false, const QRect &rect=QRect())
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
virtual void enterEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition: qwidget.cpp:9475
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition: qlayout.cpp:1516
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
QIcon icon() const
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
QLayoutItem * unplug(QWidget *widget)