Qt 4.8
qmdisubwindow.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 
162 #include "qmdisubwindow_p.h"
163 
164 #ifndef QT_NO_MDIAREA
165 
166 #include <QApplication>
167 #include <QStylePainter>
168 #include <QVBoxLayout>
169 #include <QMouseEvent>
170 #include <QWhatsThis>
171 #include <QToolTip>
172 #include <QMainWindow>
173 #include <QScrollBar>
174 #include <QDebug>
175 #include <QScopedValueRollback>
176 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
177 #include <QMacStyle>
178 #endif
179 #include <QMdiArea>
180 
182 
183 using namespace QMdi;
184 
186 {
196 };
197 static const int NumSubControls = sizeof(SubControls) / sizeof(SubControls[0]);
198 
200 {
204 };
205 static const int NumButtonPixmaps = sizeof(ButtonPixmaps) / sizeof(ButtonPixmaps[0]);
206 
207 static const Qt::WindowFlags CustomizeWindowFlags =
215 
216 
217 static const int BoundaryMargin = 5;
218 
219 static inline int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag,
220  int delta, int maxDelta, int minDelta)
221 {
222  if (cflags & moveFlag) {
223  if (delta > 0)
224  return (cflags & resizeFlag) ? qMin(delta, maxDelta) : delta;
225  return (cflags & resizeFlag) ? qMax(delta, minDelta) : delta;
226  }
227  return 0;
228 }
229 
230 static inline int getResizeDeltaComponent(uint cflags, uint resizeFlag,
231  uint resizeReverseFlag, int delta)
232 {
233  if (cflags & resizeFlag) {
234  if (cflags & resizeReverseFlag)
235  return -delta;
236  return delta;
237  }
238  return 0;
239 }
240 
241 static inline bool isChildOfQMdiSubWindow(const QWidget *child)
242 {
243  Q_ASSERT(child);
244  QWidget *parent = child->parentWidget();
245  while (parent) {
246  if (qobject_cast<QMdiSubWindow *>(parent))
247  return true;
248  parent = parent->parentWidget();
249  }
250  return false;
251 }
252 
253 static inline bool isChildOfTabbedQMdiArea(const QMdiSubWindow *child)
254 {
255  Q_ASSERT(child);
256  if (QMdiArea *mdiArea = child->mdiArea()) {
257  if (mdiArea->viewMode() == QMdiArea::TabbedView)
258  return true;
259  }
260  return false;
261 }
262 
263 template<typename T>
265 {
266  if (widget && widget->qt_metacast("ControlElement")
267  && strcmp(widget->metaObject()->className(), T::staticMetaObject.className()) == 0) {
268  return static_cast<ControlElement<T> *>(widget);
269  }
270  return 0;
271 }
272 
274 {
276  if (originalTitle.isNull()) {
277  originalTitle = q->window()->windowTitle();
278  if (originalTitle.isNull())
279  originalTitle = QLatin1String("");
280  }
281  return originalTitle;
282 }
283 
285 {
287  QString childTitle = q->windowTitle();
288  if (childTitle.isEmpty())
289  return;
290  QString original = originalWindowTitle();
291  if (!original.isEmpty()) {
292  if (!original.contains(QMdiSubWindow::tr("- [%1]").arg(childTitle)))
293  q->window()->setWindowTitle(QMdiSubWindow::tr("%1 - [%2]").arg(original, childTitle));
294 
295  } else {
296  q->window()->setWindowTitle(childTitle);
297  }
298 }
299 
300 static inline bool isHoverControl(QStyle::SubControl control)
301 {
302  return control != QStyle::SC_None && control != QStyle::SC_TitleBarLabel;
303 }
304 
305 #if defined(Q_WS_WIN)
306 static inline QRgb colorref2qrgb(COLORREF col)
307 {
308  return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));
309 }
310 #endif
311 
312 #ifndef QT_NO_TOOLTIP
313 static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOptionComplex &opt,
314  QStyle::ComplexControl complexControl, QStyle::SubControl subControl)
315 {
316  Q_ASSERT(helpEvent);
317  Q_ASSERT(helpEvent->type() == QEvent::ToolTip);
318  Q_ASSERT(widget);
319 
320 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
321  // Native Mac windows don't show tool tip.
322  if (qobject_cast<QMacStyle *>(widget->style()))
323  return;
324 #endif
325 
326  // Convert CC_MdiControls to CC_TitleBar. Sub controls of different complex
327  // controls cannot be in the same switch as they might have the same value.
328  if (complexControl == QStyle::CC_MdiControls) {
329  if (subControl == QStyle::SC_MdiMinButton)
330  subControl = QStyle::SC_TitleBarMinButton;
331  else if (subControl == QStyle::SC_MdiCloseButton)
332  subControl = QStyle::SC_TitleBarCloseButton;
333  else if (subControl == QStyle::SC_MdiNormalButton)
334  subControl = QStyle::SC_TitleBarNormalButton;
335  else
336  subControl = QStyle::SC_None;
337  }
338 
339  // Don't change the tooltip for the base widget itself.
340  if (subControl == QStyle::SC_None)
341  return;
342 
343  QString toolTip;
344 
345  switch (subControl) {
347  toolTip = QMdiSubWindow::tr("Minimize");
348  break;
350  toolTip = QMdiSubWindow::tr("Maximize");
351  break;
353  toolTip = QMdiSubWindow::tr("Unshade");
354  break;
356  toolTip = QMdiSubWindow::tr("Shade");
357  break;
359  if (widget->isMaximized() || !qobject_cast<QMdiSubWindow *>(widget))
360  toolTip = QMdiSubWindow::tr("Restore Down");
361  else
362  toolTip = QMdiSubWindow::tr("Restore");
363  break;
365  toolTip = QMdiSubWindow::tr("Close");
366  break;
368  toolTip = QMdiSubWindow::tr("Help");
369  break;
371  toolTip = QMdiSubWindow::tr("Menu");
372  break;
373  default:
374  break;
375  }
376 
377  const QRect rect = widget->style()->subControlRect(complexControl, &opt, subControl, widget);
378  QToolTip::showText(helpEvent->globalPos(), toolTip, widget, rect);
379 }
380 #endif // QT_NO_TOOLTIP
381 
382 namespace QMdi {
383 /*
384  \class ControlLabel
385  \internal
386 */
387 class ControlLabel : public QWidget
388 {
389  Q_OBJECT
390 public:
391  ControlLabel(QMdiSubWindow *subWindow, QWidget *parent = 0);
392 
393  QSize sizeHint() const;
394 
395 signals:
396  void _q_clicked();
397  void _q_doubleClicked();
398 
399 protected:
400  bool event(QEvent *event);
403  void mouseDoubleClickEvent(QMouseEvent *mouseEvent);
404  void mouseReleaseEvent(QMouseEvent *mouseEvent);
405 
406 private:
408  bool isPressed;
409  void updateWindowIcon();
410 };
411 } // namespace QMdi
412 
414  : QWidget(parent), isPressed(false)
415 {
416  Q_UNUSED(subWindow);
420 }
421 
422 /*
423  \internal
424 */
426 {
427  return label.size();
428 }
429 
430 /*
431  \internal
432 */
434 {
435  if (event->type() == QEvent::WindowIconChange)
437 #ifndef QT_NO_TOOLTIP
438  else if (event->type() == QEvent::ToolTip) {
439  QStyleOptionTitleBar options;
440  options.initFrom(this);
441  showToolTip(static_cast<QHelpEvent *>(event), this, options,
443  }
444 #endif
445  return QWidget::event(event);
446 }
447 
448 /*
449  \internal
450 */
451 void ControlLabel::paintEvent(QPaintEvent * /*paintEvent*/)
452 {
453  QPainter painter(this);
454  painter.drawPixmap(0, 0, label);
455 }
456 
457 /*
458  \internal
459 */
461 {
462  if (mouseEvent->button() != Qt::LeftButton) {
463  mouseEvent->ignore();
464  return;
465  }
466  isPressed = true;
467 }
468 
469 /*
470  \internal
471 */
473 {
474  if (mouseEvent->button() != Qt::LeftButton) {
475  mouseEvent->ignore();
476  return;
477  }
478  isPressed = false;
480 }
481 
482 /*
483  \internal
484 */
486 {
487  if (mouseEvent->button() != Qt::LeftButton) {
488  mouseEvent->ignore();
489  return;
490  }
491  if (isPressed) {
492  isPressed = false;
493  emit _q_clicked();
494  }
495 }
496 
497 /*
498  \internal
499 */
501 {
502  QIcon menuIcon = windowIcon();
503  if (menuIcon.isNull())
505  label = menuIcon.pixmap(16, 16);
506  update();
507 }
508 
509 namespace QMdi {
510 /*
511  \class ControllerWidget
512  \internal
513 */
514 class ControllerWidget : public QWidget
515 {
516  Q_OBJECT
517 public:
518  ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent = 0);
519  QSize sizeHint() const;
520  void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible);
521  inline bool hasVisibleControls() const
522  {
523  return (visibleControls & QStyle::SC_MdiMinButton)
524  || (visibleControls & QStyle::SC_MdiNormalButton)
525  || (visibleControls & QStyle::SC_MdiCloseButton);
526  }
527 
528 signals:
529  void _q_minimize();
530  void _q_restore();
531  void _q_close();
532 
533 protected:
535  void mousePressEvent(QMouseEvent *event);
536  void mouseReleaseEvent(QMouseEvent *event);
537  void mouseMoveEvent(QMouseEvent *event);
538  void leaveEvent(QEvent *event);
539  bool event(QEvent *event);
540 
541 private:
545  void initStyleOption(QStyleOptionComplex *option) const;
548  {
550  initStyleOption(&opt);
551  return style()->hitTestComplexControl(QStyle::CC_MdiControls, &opt, pos, mdiArea);
552  }
553 };
554 } // namespace QMdi
555 
556 /*
557  \internal
558 */
560  : QWidget(parent),
561  activeControl(QStyle::SC_None),
562  hoverControl(QStyle::SC_None),
563  visibleControls(QStyle::SC_None),
564  mdiArea(0)
565 {
566  if (subWindow->parentWidget())
567  mdiArea = qobject_cast<QMdiArea *>(subWindow->parentWidget()->parentWidget());
570  setMouseTracking(true);
571 }
572 
573 /*
574  \internal
575 */
577 {
578  ensurePolished();
580  initStyleOption(&opt);
581  QSize size(48, 16);
582  return style()->sizeFromContents(QStyle::CT_MdiControls, &opt, size, mdiArea);
583 }
584 
586 {
587  QStyle::SubControl subControl = QStyle::SC_None;
588 
589  // Map action from QMdiSubWindowPrivate::WindowStateAction to QStyle::SubControl.
591  subControl = QStyle::SC_MdiNormalButton;
592  else if (action == QMdiSubWindowPrivate::CloseAction)
593  subControl = QStyle::SC_MdiCloseButton;
594  else if (action == QMdiSubWindowPrivate::MinimizeAction)
595  subControl = QStyle::SC_MdiMinButton;
596 
597  if (subControl == QStyle::SC_None)
598  return;
599 
600  if (visible && !(visibleControls & subControl))
601  visibleControls |= subControl;
602  else if (!visible && (visibleControls & subControl))
603  visibleControls &= ~subControl;
604 }
605 
606 /*
607  \internal
608 */
610 {
612  initStyleOption(&opt);
613  if (activeControl == hoverControl) {
619  }
620  QPainter painter(this);
622 }
623 
624 /*
625  \internal
626 */
628 {
629  if (event->button() != Qt::LeftButton) {
630  event->ignore();
631  return;
632  }
633  activeControl = getSubControl(event->pos());
634  update();
635 }
636 
637 /*
638  \internal
639 */
641 {
642  if (event->button() != Qt::LeftButton) {
643  event->ignore();
644  return;
645  }
646 
647  QStyle::SubControl under_mouse = getSubControl(event->pos());
648  if (under_mouse == activeControl) {
649  switch (activeControl) {
651  emit _q_close();
652  break;
654  emit _q_restore();
655  break;
657  emit _q_minimize();
658  break;
659  default:
660  break;
661  }
662  }
663 
665  update();
666 }
667 
668 /*
669  \internal
670 */
672 {
673  QStyle::SubControl under_mouse = getSubControl(event->pos());
674  //test if hover state changes
675  if (hoverControl != under_mouse) {
676  hoverControl = under_mouse;
677  update();
678  }
679 }
680 
681 /*
682  \internal
683 */
685 {
687  update();
688 }
689 
690 /*
691  \internal
692 */
694 {
695 #ifndef QT_NO_TOOLTIP
696  if (event->type() == QEvent::ToolTip) {
698  initStyleOption(&opt);
699  QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
700  showToolTip(helpEvent, this, opt, QStyle::CC_MdiControls, getSubControl(helpEvent->pos()));
701  }
702 #endif // QT_NO_TOOLTIP
703  return QWidget::event(event);
704 }
705 
706 /*
707  \internal
708 */
710 {
711  option->initFrom(this);
712  option->subControls = visibleControls;
714 }
715 
716 /*
717  \internal
718 */
720  : QObject(mdiChild),
721  previousLeft(0),
722  previousRight(0),
723 #ifndef QT_NO_MENUBAR
724  m_menuBar(0),
725 #endif
726  mdiChild(mdiChild)
727 {
728  Q_ASSERT(mdiChild);
729 
731  connect(m_controllerWidget, SIGNAL(_q_close()), mdiChild, SLOT(close()));
732  connect(m_controllerWidget, SIGNAL(_q_restore()), mdiChild, SLOT(showNormal()));
733  connect(m_controllerWidget, SIGNAL(_q_minimize()), mdiChild, SLOT(showMinimized()));
734 
736  m_menuLabel->setWindowIcon(mdiChild->windowIcon());
737 #ifndef QT_NO_MENU
738  connect(m_menuLabel, SIGNAL(_q_clicked()), mdiChild, SLOT(showSystemMenu()));
739 #endif
740  connect(m_menuLabel, SIGNAL(_q_doubleClicked()), mdiChild, SLOT(close()));
741 }
742 
744 {
745 #ifndef QT_NO_MENUBAR
747 #endif
748  delete m_menuLabel;
749  m_menuLabel = 0;
750  delete m_controllerWidget;
751  m_controllerWidget = 0;
752 }
753 
754 #ifndef QT_NO_MENUBAR
755 /*
756  \internal
757 */
759 {
760 #if defined(QT_NO_MAINWINDOW)
761  return 0;
762 #else
763  Q_Q(const QMdiSubWindow);
764  if (!q->isMaximized() || drawTitleBarWhenMaximized() || isChildOfTabbedQMdiArea(q))
765  return 0;
766 
767  if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window()))
768  return mainWindow->menuBar();
769 
770  return 0;
771 #endif
772 }
773 
774 /*
775  \internal
776 */
778 {
779  if (!menuBar || !mdiChild || mdiChild->windowFlags() & Qt::FramelessWindowHint)
780  return;
781  m_menuBar = menuBar;
782 
784  QWidget *currentLeft = menuBar->cornerWidget(Qt::TopLeftCorner);
785  if (currentLeft)
786  currentLeft->hide();
787  if (currentLeft != m_menuLabel) {
789  previousLeft = currentLeft;
790  }
791  m_menuLabel->show();
792  }
794  if (controllerWidget && controllerWidget->hasVisibleControls()) {
795  QWidget *currentRight = menuBar->cornerWidget(Qt::TopRightCorner);
796  if (currentRight)
797  currentRight->hide();
798  if (currentRight != m_controllerWidget) {
800  previousRight = currentRight;
801  }
803  }
804  mdiChild->d_func()->setNewWindowTitle();
805 }
806 
807 /*
808  \internal
809 */
811 {
812  if (menuBar && menuBar != m_menuBar) {
813  // m_menubar was deleted while sub-window was maximized
814  previousRight = 0;
815  previousLeft = 0;
816  m_menuBar = menuBar;
817  }
818 
819  if (!m_menuBar || !mdiChild || qt_widget_private(mdiChild->window())->data.in_destructor)
820  return;
821 
822  QMdiSubWindow *child = 0;
823  if (m_controllerWidget) {
825  if (currentRight == m_controllerWidget) {
826  if (ControlElement<ControllerWidget> *ce = ptr<ControllerWidget>(previousRight)) {
827  if (!ce->mdiChild || !ce->mdiChild->isMaximized())
828  previousRight = 0;
829  else
830  child = ce->mdiChild;
831  }
833  if (previousRight) {
834  previousRight->show();
835  previousRight = 0;
836  }
837  }
840  }
841  if (m_menuLabel) {
843  if (currentLeft == m_menuLabel) {
844  if (ControlElement<ControlLabel> *ce = ptr<ControlLabel>(previousLeft)) {
845  if (!ce->mdiChild || !ce->mdiChild->isMaximized())
846  previousLeft = 0;
847  else if (!child)
848  child = mdiChild;
849  }
851  if (previousLeft) {
852  previousLeft->show();
853  previousLeft = 0;
854  }
855  }
856  m_menuLabel->hide();
858  }
859  m_menuBar->update();
860  if (child)
861  child->d_func()->setNewWindowTitle();
862  else if (mdiChild)
863  mdiChild->window()->setWindowTitle(mdiChild->d_func()->originalWindowTitle());
864 }
865 
866 #endif // QT_NO_MENUBAR
867 
869 {
870  if (m_menuLabel)
871  m_menuLabel->setWindowIcon(windowIcon);
872 }
873 
878  : baseWidget(0),
879  restoreFocusWidget(0),
880  controlContainer(0),
881 #ifndef QT_NO_SIZEGRIP
882  sizeGrip(0),
883 #endif
884 #ifndef QT_NO_RUBBERBAND
885  rubberBand(0),
886 #endif
887  userMinimumSize(0,0),
888  resizeEnabled(true),
889  moveEnabled(true),
890  isInInteractiveMode(false),
891 #ifndef QT_NO_RUBBERBAND
892  isInRubberBandMode(false),
893 #endif
894  isShadeMode(false),
895  ignoreWindowTitleChange(false),
896  ignoreNextActivationEvent(false),
897  activationEnabled(true),
898  isShadeRequestFromMinimizeMode(false),
899  isMaximizeMode(false),
900  isWidgetHiddenByUs(false),
901  isActive(false),
902  isExplicitlyDeactivated(false),
903  keyboardSingleStep(5),
904  keyboardPageStep(20),
905  resizeTimerId(-1),
906  currentOperation(None),
907  hoveredSubControl(QStyle::SC_None),
908  activeSubControl(QStyle::SC_None),
909  focusInReason(Qt::ActiveWindowFocusReason)
910 {
912 }
913 
918 {
919 #ifndef QT_NO_ACTION
921  if (QAction *senderAction = qobject_cast<QAction *>(q->sender())) {
922  if (senderAction->isChecked()) {
923  q->setWindowFlags(q->windowFlags() | Qt::WindowStaysOnTopHint);
924  q->raise();
925  } else {
926  q->setWindowFlags(q->windowFlags() & ~Qt::WindowStaysOnTopHint);
927  q->lower();
928  }
929  }
930 #endif // QT_NO_ACTION
931 }
932 
937 {
938 #ifndef QT_NO_ACTION
940  QAction *action = qobject_cast<QAction *>(q->sender());
941  if (!action)
942  return;
943 
944  QPoint pressPos;
945  if (actions[MoveAction] && actions[MoveAction] == action) {
947  pressPos = QPoint(q->width() / 2, titleBarHeight() - 1);
948  } else if (actions[ResizeAction] && actions[ResizeAction] == action) {
949  currentOperation = q->isLeftToRight() ? BottomRightResize : BottomLeftResize;
950  int offset = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q) / 2;
951  int x = q->isLeftToRight() ? q->width() - offset : offset;
952  pressPos = QPoint(x, q->height() - offset);
953  } else {
954  return;
955  }
956 
957  updateCursor();
958 #ifndef QT_NO_CURSOR
959  q->cursor().setPos(q->mapToGlobal(pressPos));
960 #endif
961  mousePressPosition = q->mapToParent(pressPos);
962  oldGeometry = q->geometry();
963  isInInteractiveMode = true;
964  q->setFocus();
965 #ifndef QT_NO_RUBBERBAND
966  if ((q->testOption(QMdiSubWindow::RubberBandResize)
968  || (q->testOption(QMdiSubWindow::RubberBandMove) && currentOperation == Move)) {
970  } else
971 #endif // QT_NO_RUBBERBAND
972  {
973  q->grabMouse();
974  }
975 #endif // QT_NO_ACTION
976 }
977 
982 {
983  Q_UNUSED(old);
985  if (now && (now == q || q->isAncestorOf(now))) {
986  if (now == q && !isInInteractiveMode)
987  setFocusWidget();
988  setActive(true);
989  }
990 }
991 
996 {
998 #ifndef QT_NO_RUBBERBAND
999  if (isInRubberBandMode)
1001  else
1002 #endif
1003  q->releaseMouse();
1004  isInInteractiveMode = false;
1007  updateCursor();
1008  if (baseWidget && baseWidget->focusWidget())
1010 }
1011 
1016 {
1017  if (!baseWidget)
1018  return;
1019 
1020  Q_Q(QMdiSubWindow);
1022  if (layout)
1024  if (baseWidget->windowTitle() == q->windowTitle()) {
1025  ignoreWindowTitleChange = true;
1026  q->setWindowTitle(QString());
1027  ignoreWindowTitleChange = false;
1028  q->setWindowModified(false);
1029  }
1031  baseWidget->setParent(0);
1032  baseWidget = 0;
1033  isWidgetHiddenByUs = false;
1034 }
1035 
1040 {
1053 }
1054 
1055 #ifndef QT_NO_MENU
1056 
1061 {
1062  Q_Q(QMdiSubWindow);
1063  Q_ASSERT_X(q, "QMdiSubWindowPrivate::createSystemMenu",
1064  "You can NOT call this function before QMdiSubWindow's ctor");
1065  systemMenu = new QMenu(q);
1066  const QStyle *style = q->style();
1067  addToSystemMenu(RestoreAction, QMdiSubWindow::tr("&Restore"), SLOT(showNormal()));
1069  actions[RestoreAction]->setEnabled(false);
1072  addToSystemMenu(MinimizeAction, QMdiSubWindow::tr("Mi&nimize"), SLOT(showMinimized()));
1074  addToSystemMenu(MaximizeAction, QMdiSubWindow::tr("Ma&ximize"), SLOT(showMaximized()));
1079  addToSystemMenu(CloseAction, QMdiSubWindow::tr("&Close"), SLOT(close()));
1080  actions[CloseAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarCloseButton, 0, q));
1081 #if !defined(QT_NO_SHORTCUT)
1083 #endif
1084  updateActions();
1085 }
1086 #endif
1087 
1092 {
1093 #ifndef QT_NO_CURSOR
1094  Q_Q(QMdiSubWindow);
1095 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
1096  if (qobject_cast<QMacStyle *>(q->style()))
1097  return;
1098 #endif
1099 
1100  if (currentOperation == None) {
1101  q->unsetCursor();
1102  return;
1103  }
1104 
1105  if (currentOperation == Move || operationMap.find(currentOperation).value().hover) {
1106  q->setCursor(operationMap.find(currentOperation).value().cursorShape);
1107  return;
1108  }
1109 #endif
1110 }
1111 
1116 {
1117  // No update necessary
1118  if (!parent)
1119  return;
1120 
1121  foreach (Operation operation, operationMap.keys())
1122  operationMap.find(operation).value().region = getRegion(operation);
1123 }
1124 
1129 {
1130  Q_Q(QMdiSubWindow);
1131  if (!parent)
1132  return;
1133 
1134  internalMinimumSize = (!q->isMinimized() && !q->minimumSize().isNull())
1135  ? q->minimumSize() : q->minimumSizeHint();
1136  int margin, minWidth;
1137  sizeParameters(&margin, &minWidth);
1138  q->setContentsMargins(margin, titleBarHeight(), margin, margin);
1139  if (q->isMaximized() || (q->isMinimized() && !q->isShaded())) {
1140  moveEnabled = false;
1141  resizeEnabled = false;
1142  } else {
1143  moveEnabled = true;
1144  if ((q->windowFlags() & Qt::MSWindowsFixedSizeDialogHint) || q->isShaded())
1145  resizeEnabled = false;
1146  else
1147  resizeEnabled = true;
1148  }
1150 }
1151 
1156 {
1157  Q_Q(QMdiSubWindow);
1158  if (!q->mask().isEmpty())
1159  q->clearMask();
1160 
1161  if (!parent)
1162  return;
1163 
1164  if ((q->isMaximized() && !drawTitleBarWhenMaximized())
1165  || q->windowFlags() & Qt::FramelessWindowHint)
1166  return;
1167 
1168  if (resizeTimerId == -1)
1170  cachedStyleOptions.rect = q->rect();
1171  QStyleHintReturnMask frameMask;
1172  q->style()->styleHint(QStyle::SH_WindowFrame_Mask, &cachedStyleOptions, q, &frameMask);
1173  if (!frameMask.region.isEmpty())
1174  q->setMask(frameMask.region);
1175 }
1176 
1181 {
1182  Q_Q(QMdiSubWindow);
1184  Q_ASSERT(parent);
1185 
1186  uint cflags = operationMap.find(currentOperation).value().changeFlags;
1187  int posX = pos.x();
1188  int posY = pos.y();
1189 
1190  const bool restrictHorizontal = !q->testOption(QMdiSubWindow::AllowOutsideAreaHorizontally);
1191  const bool restrictVertical = !q->testOption(QMdiSubWindow::AllowOutsideAreaVertically);
1192 
1193  if (restrictHorizontal || restrictVertical) {
1194  QRect parentRect = q->parentWidget()->rect();
1195  if (restrictVertical && (cflags & VResizeReverse || currentOperation == Move)) {
1196  posY = qMin(qMax(mousePressPosition.y() - oldGeometry.y(), posY),
1197  parentRect.height() - BoundaryMargin);
1198  }
1199  if (currentOperation == Move) {
1200  if (restrictHorizontal)
1201  posX = qMin(qMax(BoundaryMargin, posX), parentRect.width() - BoundaryMargin);
1202  if (restrictVertical)
1203  posY = qMin(posY, parentRect.height() - BoundaryMargin);
1204  } else {
1205  if (restrictHorizontal) {
1206  if (cflags & HResizeReverse)
1207  posX = qMax(mousePressPosition.x() - oldGeometry.x(), posX);
1208  else
1209  posX = qMin(parentRect.width() - (oldGeometry.x() + oldGeometry.width()
1210  - mousePressPosition.x()), posX);
1211  }
1212  if (restrictVertical && !(cflags & VResizeReverse)) {
1213  posY = qMin(parentRect.height() - (oldGeometry.y() + oldGeometry.height()
1214  - mousePressPosition.y()), posY);
1215  }
1216  }
1217  }
1218 
1219  QRect geometry;
1220  if (cflags & (HMove | VMove)) {
1221  int dx = getMoveDeltaComponent(cflags, HMove, HResize, posX - mousePressPosition.x(),
1223  oldGeometry.width() - q->maximumWidth());
1224  int dy = getMoveDeltaComponent(cflags, VMove, VResize, posY - mousePressPosition.y(),
1226  oldGeometry.height() - q->maximumHeight());
1227  geometry.setTopLeft(oldGeometry.topLeft() + QPoint(dx, dy));
1228  } else {
1229  geometry.setTopLeft(q->geometry().topLeft());
1230  }
1231 
1232  if (cflags & (HResize | VResize)) {
1234  posX - mousePressPosition.x());
1236  posY - mousePressPosition.y());
1237  geometry.setSize(oldGeometry.size() + QSize(dx, dy));
1238  } else {
1239  geometry.setSize(q->geometry().size());
1240  }
1241 
1242  setNewGeometry(&geometry);
1243 }
1244 
1249 {
1250  Q_Q(QMdiSubWindow);
1251  Q_ASSERT(parent);
1252 
1255  q->showShaded();
1257 
1258  moveEnabled = false;
1259 #ifndef QT_NO_ACTION
1261 #endif
1262 
1263  Q_ASSERT(q->windowState() & Qt::WindowMinimized);
1264  Q_ASSERT(!(q->windowState() & Qt::WindowMaximized));
1265  // This should be a valid assert, but people can actually re-implement
1266  // setVisible and do crazy stuff, so we're not guaranteed that
1267  // the widget is hidden after calling hide().
1268  // Q_ASSERT(baseWidget ? baseWidget->isHidden() : true);
1269 
1270  setActive(true);
1271 }
1272 
1277 {
1278  Q_Q(QMdiSubWindow);
1279  Q_ASSERT(parent);
1280 
1281  isShadeMode = false;
1282  isMaximizeMode = false;
1283 
1285 #ifndef QT_NO_MENUBAR
1287 #endif
1288 
1289  // Hide the window before we change the geometry to avoid multiple resize
1290  // events and wrong window state.
1291  const bool wasVisible = q->isVisible();
1292  if (wasVisible)
1293  q->setVisible(false);
1294 
1295  // Restore minimum size if set by user.
1296  if (!userMinimumSize.isNull()) {
1297  q->setMinimumSize(userMinimumSize);
1298  userMinimumSize = QSize(0, 0);
1299  }
1300 
1301  // Show the internal widget if it was hidden by us,
1302  if (baseWidget && isWidgetHiddenByUs) {
1303  baseWidget->show();
1304  isWidgetHiddenByUs = false;
1305  }
1306 
1308  QRect newGeometry = oldGeometry;
1310  q->setGeometry(newGeometry);
1311 
1312  if (wasVisible)
1313  q->setVisible(true);
1314 
1315  // Invalidate the restore size.
1316  restoreSize.setWidth(-1);
1317  restoreSize.setHeight(-1);
1318 
1319 #ifndef QT_NO_SIZEGRIP
1320  setSizeGripVisible(true);
1321 #endif
1322 
1323 #ifndef QT_NO_ACTION
1324  setEnabled(MoveAction, true);
1325  setEnabled(MaximizeAction, true);
1326  setEnabled(MinimizeAction, true);
1327  setEnabled(RestoreAction, false);
1329 #endif // QT_NO_ACTION
1330 
1331  Q_ASSERT(!(q_func()->windowState() & Qt::WindowMinimized));
1332  // This sub-window can be maximized when shown above if not the
1333  // QMdiArea::DontMaximizeSubWindowOnActionvation is set. Make sure
1334  // the Qt::WindowMaximized flag is set accordingly.
1335  Q_ASSERT((isMaximizeMode && q_func()->windowState() & Qt::WindowMaximized)
1336  || (!isMaximizeMode && !(q_func()->windowState() & Qt::WindowMaximized)));
1338 
1339  setActive(true);
1340  restoreFocus();
1341  updateMask();
1342 }
1343 
1348 {
1349  Q_Q(QMdiSubWindow);
1350  Q_ASSERT(parent);
1351 
1353  isShadeMode = false;
1354  isMaximizeMode = true;
1355 
1358 
1359 #ifndef QT_NO_SIZEGRIP
1360  setSizeGripVisible(false);
1361 #endif
1362 
1363  // Store old geometry and set restore size if not already set.
1364  if (!restoreSize.isValid()) {
1365  oldGeometry = q->geometry();
1368  }
1369 
1370  // Hide the window before we change the geometry to avoid multiple resize
1371  // events and wrong window state.
1372  const bool wasVisible = q->isVisible();
1373  if (wasVisible)
1374  q->setVisible(false);
1375 
1376  // Show the internal widget if it was hidden by us.
1377  if (baseWidget && isWidgetHiddenByUs) {
1378  baseWidget->show();
1379  isWidgetHiddenByUs = false;
1380  }
1381 
1383 
1384  if (wasVisible) {
1385 #ifndef QT_NO_MENUBAR
1386  if (QMenuBar *mBar = menuBar())
1387  showButtonsInMenuBar(mBar);
1388  else
1389 #endif
1390  if (!controlContainer)
1392  }
1393 
1394  QWidget *parent = q->parentWidget();
1395  QRect availableRect = parent->contentsRect();
1396 
1397  // Adjust geometry if the sub-window is inside a scroll area.
1399  if (scrollArea && scrollArea->viewport() == parent) {
1400  QScrollBar *hbar = scrollArea->horizontalScrollBar();
1401  QScrollBar *vbar = scrollArea->verticalScrollBar();
1402  const int xOffset = hbar ? hbar->value() : 0;
1403  const int yOffset = vbar ? vbar->value() : 0;
1404  availableRect.adjust(-xOffset, -yOffset, -xOffset, -yOffset);
1405  oldGeometry.adjust(xOffset, yOffset, xOffset, yOffset);
1406  }
1407 
1408  setNewGeometry(&availableRect);
1409  // QWidget::setGeometry will reset Qt::WindowMaximized so we have to update it here.
1411 
1412  if (wasVisible)
1413  q->setVisible(true);
1414 
1415  resizeEnabled = false;
1416  moveEnabled = false;
1417 
1418 #ifndef QT_NO_ACTION
1420  setEnabled(MaximizeAction, false);
1421  setEnabled(MinimizeAction, true);
1422  setEnabled(RestoreAction, true);
1424 #endif // QT_NO_ACTION
1425 
1426  Q_ASSERT(q->windowState() & Qt::WindowMaximized);
1427  Q_ASSERT(!(q->windowState() & Qt::WindowMinimized));
1428 
1429  restoreFocus();
1430  updateMask();
1431 }
1432 
1436 void QMdiSubWindowPrivate::setActive(bool activate, bool changeFocus)
1437 {
1438  Q_Q(QMdiSubWindow);
1439  if (!parent || !activationEnabled)
1440  return;
1441 
1442  if (activate && !isActive && q->isEnabled()) {
1443  isActive = true;
1444  isExplicitlyDeactivated = false;
1445  Qt::WindowStates oldWindowState = q->windowState();
1447  emit q->aboutToActivate();
1448 #ifndef QT_NO_MENUBAR
1449  if (QMenuBar *mBar = menuBar())
1450  showButtonsInMenuBar(mBar);
1451 #endif
1452  Q_ASSERT(isActive);
1453  emit q->windowStateChanged(oldWindowState, q->windowState());
1454  } else if (!activate && isActive) {
1455  isActive = false;
1456  Qt::WindowStates oldWindowState = q->windowState();
1457  q->overrideWindowState(q->windowState() & ~Qt::WindowActive);
1458  if (changeFocus) {
1459  QWidget *focusWidget = QApplication::focusWidget();
1460  if (focusWidget && (focusWidget == q || q->isAncestorOf(focusWidget)))
1461  focusWidget->clearFocus();
1462  }
1463  if (baseWidget)
1465  Q_ASSERT(!isActive);
1466  emit q->windowStateChanged(oldWindowState, q->windowState());
1467  }
1468 
1469  if (activate && isActive && q->isEnabled() && !q->hasFocus()
1470  && !q->isAncestorOf(QApplication::focusWidget())) {
1471  if (changeFocus)
1472  setFocusWidget();
1474  }
1475 
1476  int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q);
1477  int titleBarHeight = this->titleBarHeight();
1478  QRegion windowDecoration = QRegion(0, 0, q->width(), q->height());
1479  windowDecoration -= QRegion(frameWidth, titleBarHeight, q->width() - 2 * frameWidth,
1480  q->height() - titleBarHeight - frameWidth);
1481 
1482  // Make sure we don't use cached style options if we get
1483  // resize events right before activation/deactivation.
1484  if (resizeTimerId != -1) {
1485  q->killTimer(resizeTimerId);
1486  resizeTimerId = -1;
1488  }
1489 
1490  q->update(windowDecoration);
1491 }
1492 
1497 {
1498  Q_Q(QMdiSubWindow);
1499  switch (activeSubControl) {
1501 #ifndef QT_NO_WHATSTHIS
1503 #endif
1504  break;
1506  q->showShaded();
1508  break;
1510  if (q->isShaded())
1512  q->showNormal();
1513  break;
1515 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
1516  if (qobject_cast<QMacStyle *>(q->style())) {
1517  if (q->isMinimized())
1518  q->showNormal();
1519  else
1520  q->showMinimized();
1521  break;
1522  }
1523 #endif
1524  q->showMinimized();
1525  break;
1527  if (q->isShaded())
1529  q->showNormal();
1530  break;
1532 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
1533  if (qobject_cast<QMacStyle *>(q->style())) {
1534  if (q->isMaximized())
1535  q->showNormal();
1536  else
1537  q->showMaximized();
1538  break;
1539  }
1540 #endif
1541  q->showMaximized();
1542  break;
1544  q->close();
1545  break;
1546  default:
1547  break;
1548  }
1549 }
1550 
1555 {
1556  Q_Q(const QMdiSubWindow);
1557  int width = q->width();
1558  int height = q->height();
1559  int titleBarHeight = this->titleBarHeight();
1560  int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q);
1561  int cornerConst = titleBarHeight - frameWidth;
1562  int titleBarConst = 2 * titleBarHeight;
1563 
1564  if (operation == Move) {
1566  QRegion move(frameWidth, frameWidth, width - 2 * frameWidth, cornerConst);
1567  // Depending on which window flags are set, activated sub controllers will
1568  // be subtracted from the 'move' region.
1569  for (int i = 0; i < NumSubControls; ++i) {
1571  continue;
1572  move -= QRegion(q->style()->subControlRect(QStyle::CC_TitleBar, &titleBarOptions,
1573  SubControls[i]));
1574  }
1575  return move;
1576  }
1577 
1578  QRegion region;
1579 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
1580  if (qobject_cast<QMacStyle *>(q->style()))
1581  return region;
1582 #endif
1583 
1584  switch (operation) {
1585  case TopResize:
1586  region = QRegion(titleBarHeight, 0, width - titleBarConst, frameWidth);
1587  break;
1588  case BottomResize:
1589  region = QRegion(titleBarHeight, height - frameWidth, width - titleBarConst, frameWidth);
1590  break;
1591  case LeftResize:
1592  region = QRegion(0, titleBarHeight, frameWidth, height - titleBarConst);
1593  break;
1594  case RightResize:
1595  region = QRegion(width - frameWidth, titleBarHeight, frameWidth, height - titleBarConst);
1596  break;
1597  case TopLeftResize:
1598  region = QRegion(0, 0, titleBarHeight, titleBarHeight)
1599  - QRegion(frameWidth, frameWidth, cornerConst, cornerConst);
1600  break;
1601  case TopRightResize:
1602  region = QRegion(width - titleBarHeight, 0, titleBarHeight, titleBarHeight)
1603  - QRegion(width - titleBarHeight, frameWidth, cornerConst, cornerConst);
1604  break;
1605  case BottomLeftResize:
1606  region = QRegion(0, height - titleBarHeight, titleBarHeight, titleBarHeight)
1607  - QRegion(frameWidth, height - titleBarHeight, cornerConst, cornerConst);
1608  break;
1609  case BottomRightResize:
1610  region = QRegion(width - titleBarHeight, height - titleBarHeight, titleBarHeight, titleBarHeight)
1611  - QRegion(width - titleBarHeight, height - titleBarHeight, cornerConst, cornerConst);
1612  break;
1613  default:
1614  break;
1615  }
1616 
1617  return region;
1618 }
1619 
1624 {
1626  for (it = operationMap.constBegin(); it != operationMap.constEnd(); ++it)
1627  if (it.value().region.contains(pos))
1628  return it.key();
1629  return None;
1630 }
1631 
1632 extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*);
1633 
1638 {
1639  Q_Q(const QMdiSubWindow);
1641  titleBarOptions.initFrom(q);
1644  titleBarOptions.state |= QStyle::State_Sunken;
1645  titleBarOptions.activeSubControls = activeSubControl;
1646  }
1647  } else if (autoRaise() && hoveredSubControl != QStyle::SC_None
1649  titleBarOptions.state |= QStyle::State_MouseOver;
1650  titleBarOptions.activeSubControls = hoveredSubControl;
1651  } else {
1652  titleBarOptions.state &= ~QStyle::State_MouseOver;
1653  titleBarOptions.activeSubControls = QStyle::SC_None;
1654  }
1655 
1656  titleBarOptions.subControls = QStyle::SC_All;
1657  titleBarOptions.titleBarFlags = q->windowFlags();
1658  titleBarOptions.titleBarState = q->windowState();
1659  titleBarOptions.palette = titleBarPalette;
1660  titleBarOptions.icon = menuIcon;
1661 
1662  if (isActive) {
1663  titleBarOptions.state |= QStyle::State_Active;
1664  titleBarOptions.titleBarState |= QStyle::State_Active;
1666  } else {
1667  titleBarOptions.state &= ~QStyle::State_Active;
1669  }
1670 
1671  int border = hasBorder(titleBarOptions) ? 4 : 0;
1672  int paintHeight = titleBarHeight(titleBarOptions);
1673  paintHeight -= q->isMinimized() ? 2 * border : border;
1674  titleBarOptions.rect = QRect(border, border, q->width() - 2 * border, paintHeight);
1675 
1676  if (!windowTitle.isEmpty()) {
1677  // Set the text here before asking for the width of the title bar label
1678  // in case people uses the actual text to calculate the width.
1679  titleBarOptions.text = windowTitle;
1680  titleBarOptions.fontMetrics = QFontMetrics(font);
1681  int width = q->style()->subControlRect(QStyle::CC_TitleBar, &titleBarOptions,
1682  QStyle::SC_TitleBarLabel, q).width();
1683  // Set elided text if we don't have enough space for the entire title.
1684  titleBarOptions.text = titleBarOptions.fontMetrics.elidedText(windowTitle, Qt::ElideRight, width);
1685  }
1686  return titleBarOptions;
1687 }
1688 
1693 {
1694  Q_Q(QMdiSubWindow);
1695  Qt::WindowStates windowStates = q->windowState() | state;
1696  switch (state) {
1697  case Qt::WindowMinimized:
1698  windowStates &= ~Qt::WindowMaximized;
1699  windowStates &= ~Qt::WindowNoState;
1700  break;
1701  case Qt::WindowMaximized:
1702  windowStates &= ~Qt::WindowMinimized;
1703  windowStates &= ~Qt::WindowNoState;
1704  break;
1705  case Qt::WindowNoState:
1706  windowStates &= ~Qt::WindowMinimized;
1707  windowStates &= ~Qt::WindowMaximized;
1708  break;
1709  default:
1710  break;
1711  }
1712  if (baseWidget) {
1713  if (!(baseWidget->windowState() & Qt::WindowActive) && windowStates & Qt::WindowActive)
1714  baseWidget->overrideWindowState(windowStates & ~Qt::WindowActive);
1715  else
1716  baseWidget->overrideWindowState(windowStates);
1717  }
1718  q->overrideWindowState(windowStates);
1719 }
1720 
1725 {
1726  Q_Q(const QMdiSubWindow);
1727  if (!parent || q->windowFlags() & Qt::FramelessWindowHint
1728  || (q->isMaximized() && !drawTitleBarWhenMaximized())) {
1729  return 0;
1730  }
1731 
1732  int height = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options, q);
1733 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
1734  // ### Fix mac style, the +4 pixels hack is not necessary anymore
1735  if (qobject_cast<QMacStyle *>(q->style()))
1736  height -= 4;
1737 #endif
1738  if (hasBorder(options))
1739  height += q->isMinimized() ? 8 : 4;
1740  return height;
1741 }
1742 
1746 void QMdiSubWindowPrivate::sizeParameters(int *margin, int *minWidth) const
1747 {
1748  Q_Q(const QMdiSubWindow);
1749  Qt::WindowFlags flags = q->windowFlags();
1750  if (!parent || flags & Qt::FramelessWindowHint) {
1751  *margin = 0;
1752  *minWidth = 0;
1753  return;
1754  }
1755 
1756  if (q->isMaximized() && !drawTitleBarWhenMaximized())
1757  *margin = 0;
1758  else
1759  *margin = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q);
1760 
1761  QStyleOptionTitleBar opt = this->titleBarOptions();
1762  int tempWidth = 0;
1763  for (int i = 0; i < NumSubControls; ++i) {
1765  tempWidth += 30;
1766  continue;
1767  }
1768  QRect rect = q->style()->subControlRect(QStyle::CC_TitleBar, &opt, SubControls[i], q);
1769  if (!rect.isValid())
1770  continue;
1771  tempWidth += rect.width();
1772  }
1773  *minWidth = tempWidth;
1774 }
1775 
1780 {
1781  Q_Q(const QMdiSubWindow);
1782  if (q->window()->testAttribute(Qt::WA_CanHostQMdiSubWindowTitleBar))
1783  return false;
1784 
1785  if (isChildOfTabbedQMdiArea(q))
1786  return false;
1787 
1788 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_WS_WINCE_WM)
1789  return true;
1790 #else
1791  if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q))
1792  return true;
1793 #if defined(QT_NO_MENUBAR) || defined(QT_NO_MAINWINDOW)
1794  return true;
1795 #else
1796  QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window());
1797  if (!mainWindow || !qobject_cast<QMenuBar *>(mainWindow->menuWidget())
1798  || mainWindow->menuWidget()->isHidden())
1799  return true;
1800 
1801  return isChildOfQMdiSubWindow(q);
1802 #endif
1803 #endif
1804 }
1805 
1806 #ifndef QT_NO_MENUBAR
1807 
1812 {
1813  Q_Q(QMdiSubWindow);
1814  Q_ASSERT(q->isMaximized() && !drawTitleBarWhenMaximized());
1815 
1816  if (isChildOfTabbedQMdiArea(q))
1817  return;
1818 
1820  if (!controlContainer)
1822 
1823  ignoreWindowTitleChange = true;
1825  ignoreWindowTitleChange = false;
1826 
1827  QWidget *topLevelWindow = q->window();
1828  topLevelWindow->setWindowModified(q->isWindowModified());
1829  topLevelWindow->installEventFilter(q);
1830 
1831  int buttonHeight = 0;
1833  buttonHeight = controlContainer->controllerWidget()->height();
1834  else if (controlContainer->systemMenuLabel())
1835  buttonHeight = controlContainer->systemMenuLabel()->height();
1836 
1837  // This will rarely happen.
1838  if (menuBar && menuBar->height() < buttonHeight
1839  && topLevelWindow->layout()) {
1840  // Make sure topLevelWindow->contentsRect returns correct geometry.
1841  // topLevelWidget->updateGeoemtry will not do the trick here since it will post the event.
1843  QApplication::sendEvent(topLevelWindow, &event);
1844  }
1845 }
1846 
1851 {
1852  Q_Q(QMdiSubWindow);
1853 
1855  return;
1856 
1857  QMenuBar *currentMenuBar = 0;
1858 #ifndef QT_NO_MAINWINDOW
1859  if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window())) {
1860  // NB! We can't use menuBar() here because that one will actually create
1861  // a menubar for us if not set. That's not what we want :-)
1862  currentMenuBar = qobject_cast<QMenuBar *>(mainWindow->menuWidget());
1863  }
1864 #endif
1865 
1866  ignoreWindowTitleChange = true;
1867  controlContainer->removeButtonsFromMenuBar(currentMenuBar);
1868  ignoreWindowTitleChange = false;
1869 
1870  QWidget *topLevelWindow = q->window();
1871  topLevelWindow->removeEventFilter(q);
1873  topLevelWindow->setWindowModified(false);
1875 }
1876 
1877 #endif // QT_NO_MENUBAR
1878 
1879 void QMdiSubWindowPrivate::updateWindowTitle(bool isRequestFromChild)
1880 {
1881  Q_Q(QMdiSubWindow);
1882  if (isRequestFromChild && !q->windowTitle().isEmpty() && !lastChildWindowTitle.isEmpty()
1883  && lastChildWindowTitle != q->windowTitle()) {
1884  return;
1885  }
1886 
1887  QWidget *titleWidget = 0;
1888  if (isRequestFromChild)
1889  titleWidget = baseWidget;
1890  else
1891  titleWidget = q;
1892  if (!titleWidget || titleWidget->windowTitle().isEmpty())
1893  return;
1894 
1895  ignoreWindowTitleChange = true;
1896  q->setWindowTitle(titleWidget->windowTitle());
1897  if (q->maximizedButtonsWidget())
1899  ignoreWindowTitleChange = false;
1900 }
1901 
1902 #ifndef QT_NO_RUBBERBAND
1904 {
1905  Q_Q(QMdiSubWindow);
1906  if (q->isMaximized())
1907  return;
1909  Q_ASSERT(parent);
1910  if (!rubberBand) {
1911  rubberBand = new QRubberBand(QRubberBand::Rectangle, q->parentWidget());
1912  // For accessibility to identify this special widget.
1913  rubberBand->setObjectName(QLatin1String("qt_rubberband"));
1914  }
1915  QPoint rubberBandPos = q->mapToParent(QPoint(0, 0));
1916  rubberBand->setGeometry(rubberBandPos.x(), rubberBandPos.y(),
1918  rubberBand->show();
1919  isInRubberBandMode = true;
1920  q->grabMouse();
1921 }
1922 
1924 {
1925  Q_Q(QMdiSubWindow);
1928  q->releaseMouse();
1929  isInRubberBandMode = false;
1930  q->setGeometry(rubberBand->geometry());
1931  rubberBand->hide();
1933 }
1934 #endif // QT_NO_RUBBERBAND
1935 
1936 // Taken from the old QWorkspace (::readColors())
1938 {
1939  Q_Q(const QMdiSubWindow);
1940  QPalette newPalette = q->palette();
1941 
1942  bool colorsInitialized = false;
1943 #ifdef Q_WS_WIN // ask system properties on windows
1944 #ifndef SPI_GETGRADIENTCAPTIONS
1945 #define SPI_GETGRADIENTCAPTIONS 0x1008
1946 #endif
1947 #ifndef COLOR_GRADIENTACTIVECAPTION
1948 #define COLOR_GRADIENTACTIVECAPTION 27
1949 #endif
1950 #ifndef COLOR_GRADIENTINACTIVECAPTION
1951 #define COLOR_GRADIENTINACTIVECAPTION 28
1952 #endif
1955  colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION)));
1957  colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION)));
1959  colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT)));
1961  colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT)));
1962 
1963  colorsInitialized = true;
1964  BOOL hasGradient = false;
1965  SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &hasGradient, 0);
1966 
1967  if (hasGradient) {
1972  } else {
1977  }
1978  }
1979 #endif // Q_WS_WIN
1980  if (!colorsInitialized) {
1986  newPalette.color(QPalette::Inactive, QPalette::Dark));
1988  newPalette.color(QPalette::Inactive, QPalette::Dark));
1991  }
1992 
1993  return newPalette;
1994 }
1995 
1997 {
1998  Qt::WindowFlags windowFlags = q_func()->windowFlags();
1999  // Hide all
2000  for (int i = 0; i < NumWindowStateActions; ++i)
2001  setVisible(WindowStateAction(i), false);
2002 
2003  if (windowFlags & Qt::FramelessWindowHint)
2004  return;
2005 
2006  setVisible(StayOnTopAction, true);
2009 
2010  // CloseAction
2011  if (windowFlags & Qt::WindowSystemMenuHint)
2012  setVisible(CloseAction, true);
2013 
2014  // RestoreAction
2016  setVisible(RestoreAction, true);
2017 
2018  // MinimizeAction
2019  if (windowFlags & Qt::WindowMinimizeButtonHint)
2020  setVisible(MinimizeAction, true);
2021 
2022  // MaximizeAction
2023  if (windowFlags & Qt::WindowMaximizeButtonHint)
2024  setVisible(MaximizeAction, true);
2025 }
2026 
2028 {
2029  Q_Q(QMdiSubWindow);
2030  if (!baseWidget) {
2031  q->setFocus();
2032  return;
2033  }
2034 
2035  // This will give focus to the next child if possible, otherwise
2036  // do nothing, hence it's not possible to tab between windows with
2037  // just hitting tab (unless Qt::TabFocus is removed from the focus policy).
2039  q->focusNextChild();
2040  return;
2041  }
2042 
2043  // Same as above, but gives focus to the previous child.
2045  q->focusPreviousChild();
2046  return;
2047  }
2048 
2049  if (QWidget *focusWidget = baseWidget->focusWidget()) {
2050  if (!focusWidget->hasFocus() && q->isAncestorOf(focusWidget)
2051  && focusWidget->isVisible() && !q->isMinimized()
2052  && focusWidget->focusPolicy() != Qt::NoFocus) {
2053  focusWidget->setFocus();
2054  } else {
2055  q->setFocus();
2056  }
2057  return;
2058  }
2059 
2060  QWidget *focusWidget = q->nextInFocusChain();
2061  while (focusWidget && focusWidget != q && focusWidget->focusPolicy() == Qt::NoFocus)
2062  focusWidget = focusWidget->nextInFocusChain();
2063  if (focusWidget && q->isAncestorOf(focusWidget))
2064  focusWidget->setFocus();
2065  else if (baseWidget->focusPolicy() != Qt::NoFocus)
2066  baseWidget->setFocus();
2067  else if (!q->hasFocus())
2068  q->setFocus();
2069 }
2070 
2072 {
2073  if (!restoreFocusWidget)
2074  return;
2075  if (!restoreFocusWidget->hasFocus() && q_func()->isAncestorOf(restoreFocusWidget)
2079  }
2080  restoreFocusWidget = 0;
2081 }
2082 
2087 void QMdiSubWindowPrivate::setWindowFlags(Qt::WindowFlags windowFlags)
2088 {
2089  Q_Q(QMdiSubWindow);
2090  if (!parent) {
2091  q->setWindowFlags(windowFlags);
2092  return;
2093  }
2094 
2095  Qt::WindowFlags windowType = windowFlags & Qt::WindowType_Mask;
2096  if (windowType == Qt::Dialog || windowFlags & Qt::MSWindowsFixedSizeDialogHint)
2098 
2099  // Set standard flags if none of the customize flags are set
2100  if (!(windowFlags & CustomizeWindowFlags))
2102  else if (windowFlags & Qt::FramelessWindowHint && windowFlags & Qt::WindowStaysOnTopHint)
2104  else if (windowFlags & Qt::FramelessWindowHint)
2105  windowFlags = Qt::FramelessWindowHint;
2106 
2107  windowFlags &= ~windowType;
2108  windowFlags |= Qt::SubWindow;
2109 
2110 #ifndef QT_NO_ACTION
2111  if (QAction *stayOnTopAction = actions[QMdiSubWindowPrivate::StayOnTopAction]) {
2112  if (windowFlags & Qt::WindowStaysOnTopHint)
2113  stayOnTopAction->setChecked(true);
2114  else
2115  stayOnTopAction->setChecked(false);
2116  }
2117 #endif
2118 
2119 #ifndef QT_NO_SIZEGRIP
2120  if ((windowFlags & Qt::FramelessWindowHint) && sizeGrip)
2121  delete sizeGrip;
2122 #endif
2123 
2124  q->setWindowFlags(windowFlags);
2126  updateActions();
2127  QSize currentSize = q->size();
2128  if (q->isVisible() && (currentSize.width() < internalMinimumSize.width()
2129  || currentSize.height() < internalMinimumSize.height())) {
2130  q->resize(currentSize.expandedTo(internalMinimumSize));
2131  }
2132 }
2133 
2135 {
2136 #ifndef QT_NO_ACTION
2137  if (actions[action])
2138  actions[action]->setVisible(visible);
2139 #endif
2140 
2141  Q_Q(QMdiSubWindow);
2142  if (!controlContainer)
2144 
2145  if (ControllerWidget *ctrlWidget = qobject_cast<ControllerWidget *>
2147  ctrlWidget->setControlVisible(action, visible);
2148  }
2149 }
2150 
2151 #ifndef QT_NO_ACTION
2153 {
2154  if (actions[action])
2155  actions[action]->setEnabled(enable);
2156 }
2157 
2158 #ifndef QT_NO_MENU
2160  const char *slot)
2161 {
2162  if (!systemMenu)
2163  return;
2164  actions[action] = systemMenu->addAction(text, q_func(), slot);
2165 }
2166 #endif
2167 #endif // QT_NO_ACTION
2168 
2173 {
2174  Q_Q(const QMdiSubWindow);
2175  if (!parent || q->windowFlags() & Qt::FramelessWindowHint)
2176  return QSize(-1, -1);
2177  return QSize(q->style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth, 0, q), titleBarHeight());
2178 }
2179 
2180 #ifndef QT_NO_SIZEGRIP
2181 
2186 {
2187  Q_Q(QMdiSubWindow);
2188  if (!newSizeGrip || sizeGrip || q->windowFlags() & Qt::FramelessWindowHint)
2189  return;
2190 
2191  if (layout && layout->indexOf(newSizeGrip) != -1)
2192  return;
2193  newSizeGrip->setFixedSize(newSizeGrip->sizeHint());
2194  bool putSizeGripInLayout = layout ? true : false;
2195 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
2196  if (qobject_cast<QMacStyle *>(q->style()))
2197  putSizeGripInLayout = false;
2198 #endif
2199  if (putSizeGripInLayout) {
2200  layout->addWidget(newSizeGrip);
2202  } else {
2203  newSizeGrip->setParent(q);
2204  newSizeGrip->move(q->isLeftToRight() ? q->width() - newSizeGrip->width() : 0,
2205  q->height() - newSizeGrip->height());
2206  sizeGrip = newSizeGrip;
2207  }
2208  newSizeGrip->raise();
2210  newSizeGrip->installEventFilter(q);
2211 }
2212 
2217 {
2218  // See if we can find any size grips
2219  QList<QSizeGrip *> sizeGrips = q_func()->findChildren<QSizeGrip *>();
2220  foreach (QSizeGrip *grip, sizeGrips)
2221  grip->setVisible(visible);
2222 }
2223 
2224 #endif // QT_NO_SIZEGRIP
2225 
2230 {
2231  Q_Q(QMdiSubWindow);
2232  if (q->isWindowModified()) {
2233  windowTitle = q->windowTitle();
2235  } else {
2236  windowTitle = qt_setWindowTitle_helperHelper(q->windowTitle(), q);
2237  }
2238  q->update(0, 0, q->width(), titleBarHeight());
2239 }
2240 
2259  : QWidget(*new QMdiSubWindowPrivate, parent, 0)
2260 {
2261  Q_D(QMdiSubWindow);
2262 #ifndef QT_NO_MENU
2263  d->createSystemMenu();
2264  addActions(d->systemMenu->actions());
2265 #endif
2266  d->setWindowFlags(flags);
2268  setAutoFillBackground(true);
2269  setMouseTracking(true);
2270  setLayout(new QVBoxLayout);
2272  layout()->setMargin(0);
2273  d->updateGeometryConstraints();
2274  setAttribute(Qt::WA_Resized, false);
2275  d->titleBarPalette = d->desktopPalette();
2276  d->font = QApplication::font("QWorkspaceTitleBar");
2277  // We don't want the menu icon by default on mac.
2278 #ifndef Q_WS_MAC
2279  if (windowIcon().isNull())
2280  d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, this);
2281  else
2282  d->menuIcon = windowIcon();
2283 #endif
2284  connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
2285  this, SLOT(_q_processFocusChanged(QWidget*,QWidget*)));
2286 }
2287 
2294 {
2295  Q_D(QMdiSubWindow);
2296 #ifndef QT_NO_MENUBAR
2297  d->removeButtonsFromMenuBar();
2298 #endif
2299  d->setActive(false);
2300 }
2301 
2314 {
2315  Q_D(QMdiSubWindow);
2316  if (!widget) {
2317  d->removeBaseWidget();
2318  return;
2319  }
2320 
2321  if (widget == d->baseWidget) {
2322  qWarning("QMdiSubWindow::setWidget: widget is already set");
2323  return;
2324  }
2325 
2326  bool wasResized = testAttribute(Qt::WA_Resized);
2327  d->removeBaseWidget();
2328 
2329  if (QLayout *layout = this->layout())
2330  layout->addWidget(widget);
2331  else
2332  widget->setParent(this);
2333 
2334 #ifndef QT_NO_SIZEGRIP
2335  QSizeGrip *sizeGrip = widget->findChild<QSizeGrip *>();
2336  if (sizeGrip)
2337  sizeGrip->installEventFilter(this);
2338  if (d->sizeGrip)
2339  d->sizeGrip->raise();
2340 #endif
2341 
2342  d->baseWidget = widget;
2343  d->baseWidget->installEventFilter(this);
2344 
2345  d->ignoreWindowTitleChange = true;
2346  bool isWindowModified = this->isWindowModified();
2347  if (windowTitle().isEmpty()) {
2348  d->updateWindowTitle(true);
2349  isWindowModified = d->baseWidget->isWindowModified();
2350  }
2351  if (!this->isWindowModified() && isWindowModified
2352  && windowTitle().contains(QLatin1String("[*]"))) {
2353  setWindowModified(isWindowModified);
2354  }
2355  d->lastChildWindowTitle = d->baseWidget->windowTitle();
2356  d->ignoreWindowTitleChange = false;
2357 
2358  if (windowIcon().isNull() && !d->baseWidget->windowIcon().isNull())
2359  setWindowIcon(d->baseWidget->windowIcon());
2360 
2361  d->updateGeometryConstraints();
2362  if (!wasResized && testAttribute(Qt::WA_Resized))
2363  setAttribute(Qt::WA_Resized, false);
2364 }
2365 
2372 {
2373  return d_func()->baseWidget;
2374 }
2375 
2376 
2381 {
2382  Q_D(const QMdiSubWindow);
2383  if (isVisible() && d->controlContainer && isMaximized() && !d->drawTitleBarWhenMaximized()
2384  && !isChildOfTabbedQMdiArea(this)) {
2385  return d->controlContainer->controllerWidget();
2386  }
2387  return 0;
2388 }
2389 
2394 {
2395  Q_D(const QMdiSubWindow);
2396  if (isVisible() && d->controlContainer && isMaximized() && !d->drawTitleBarWhenMaximized()
2397  && !isChildOfTabbedQMdiArea(this)) {
2398  return d->controlContainer->systemMenuLabel();
2399  }
2400  return 0;
2401 }
2402 
2410 {
2411  return d_func()->isShadeMode;
2412 }
2413 
2421 {
2422  Q_D(QMdiSubWindow);
2423  if (on && !(d->options & option))
2424  d->options |= option;
2425  else if (!on && (d->options & option))
2426  d->options &= ~option;
2427 
2428 #ifndef QT_NO_RUBBERBAND
2429  if ((option & (RubberBandResize | RubberBandMove)) && !on && d->isInRubberBandMode)
2430  d->leaveRubberBandMode();
2431 #endif
2432 }
2433 
2440 {
2441  return d_func()->options & option;
2442 }
2443 
2462 {
2463  return d_func()->keyboardSingleStep;
2464 }
2465 
2467 {
2468  // Haven't done any boundary check here since negative step only
2469  // means inverted behavior, which is OK if the user want it.
2470  // A step equal to zero means "do nothing".
2471  d_func()->keyboardSingleStep = step;
2472 }
2473 
2492 {
2493  return d_func()->keyboardPageStep;
2494 }
2495 
2497 {
2498  // Haven't done any boundary check here since negative step only
2499  // means inverted behavior, which is OK if the user want it.
2500  // A step equal to zero means "do nothing".
2501  d_func()->keyboardPageStep = step;
2502 }
2503 
2504 #ifndef QT_NO_MENU
2505 
2523 {
2524  Q_D(QMdiSubWindow);
2525  if (systemMenu && systemMenu == d->systemMenu) {
2526  qWarning("QMdiSubWindow::setSystemMenu: system menu is already set");
2527  return;
2528  }
2529 
2530  if (d->systemMenu) {
2531  delete d->systemMenu;
2532  d->systemMenu = 0;
2533  }
2534 
2535  if (!systemMenu)
2536  return;
2537 
2538  if (systemMenu->parent() != this)
2539  systemMenu->setParent(this);
2540  d->systemMenu = systemMenu;
2541 }
2542 
2551 {
2552  return d_func()->systemMenu;
2553 }
2554 
2561 {
2562  Q_D(QMdiSubWindow);
2563  if (!d->systemMenu)
2564  return;
2565 
2566  QPoint globalPopupPos;
2567  if (QWidget *icon = maximizedSystemMenuIconWidget()) {
2568  if (isLeftToRight())
2569  globalPopupPos = icon->mapToGlobal(QPoint(0, icon->y() + icon->height()));
2570  else
2571  globalPopupPos = icon->mapToGlobal(QPoint(icon->width(), icon->y() + icon->height()));
2572  } else {
2573  if (isLeftToRight())
2574  globalPopupPos = mapToGlobal(contentsRect().topLeft());
2575  else // + QPoint(1, 0) because topRight() == QPoint(left() + width() -1, top())
2576  globalPopupPos = mapToGlobal(contentsRect().topRight()) + QPoint(1, 0);
2577  }
2578 
2579  // Adjust x() with -menuwidth in reverse mode.
2580  if (isRightToLeft())
2581  globalPopupPos -= QPoint(d->systemMenu->sizeHint().width(), 0);
2582  d->systemMenu->installEventFilter(this);
2583  d->systemMenu->popup(globalPopupPos);
2584 }
2585 #endif // QT_NO_MENU
2586 
2598 {
2600  while (parent) {
2601  if (QMdiArea *area = qobject_cast<QMdiArea *>(parent)) {
2602  if (area->viewport() == parentWidget())
2603  return area;
2604  }
2605  parent = parent->parentWidget();
2606  }
2607  return 0;
2608 }
2609 
2624 {
2625  if (!parent())
2626  return;
2627 
2628  Q_D(QMdiSubWindow);
2629  // setMinimizeMode uses this function.
2630  if (!d->isShadeRequestFromMinimizeMode && isShaded())
2631  return;
2632 
2633  d->isMaximizeMode = false;
2634 
2635  QWidget *currentFocusWidget = QApplication::focusWidget();
2636  if (!d->restoreFocusWidget && isAncestorOf(currentFocusWidget))
2637  d->restoreFocusWidget = currentFocusWidget;
2638 
2639  if (!d->isShadeRequestFromMinimizeMode) {
2640  d->isShadeMode = true;
2641  d->ensureWindowState(Qt::WindowMinimized);
2642  }
2643 
2644 #ifndef QT_NO_MENUBAR
2645  d->removeButtonsFromMenuBar();
2646 #endif
2647 
2648  // showMinimized() will reset Qt::WindowActive, which makes sense
2649  // for top level widgets, but in MDI it makes sense to have an
2650  // active window which is minimized.
2651  if (hasFocus() || isAncestorOf(currentFocusWidget))
2652  d->ensureWindowState(Qt::WindowActive);
2653 
2654 #ifndef QT_NO_SIZEGRIP
2655  d->setSizeGripVisible(false);
2656 #endif
2657 
2658  if (!d->restoreSize.isValid() || d->isShadeMode) {
2659  d->oldGeometry = geometry();
2660  d->restoreSize.setWidth(d->oldGeometry.width());
2661  d->restoreSize.setHeight(d->oldGeometry.height());
2662  }
2663 
2664  // Hide the window before we change the geometry to avoid multiple resize
2665  // events and wrong window state.
2666  const bool wasVisible = isVisible();
2667  if (wasVisible)
2668  setVisible(false);
2669 
2670  d->updateGeometryConstraints();
2671  // Update minimum size to internalMinimumSize if set by user.
2672  if (!minimumSize().isNull()) {
2673  d->userMinimumSize = minimumSize();
2674  setMinimumSize(d->internalMinimumSize);
2675  }
2676  resize(d->internalMinimumSize);
2677 
2678  // Hide the internal widget if not already hidden by the user.
2679  if (d->baseWidget && !d->baseWidget->isHidden()) {
2680  d->baseWidget->hide();
2681  d->isWidgetHiddenByUs = true;
2682  }
2683 
2684  if (wasVisible)
2685  setVisible(true);
2686 
2687  d->setFocusWidget();
2688  d->resizeEnabled = false;
2689  d->moveEnabled = true;
2690  d->updateDirtyRegions();
2691  d->updateMask();
2692 
2693 #ifndef QT_NO_ACTION
2694  d->setEnabled(QMdiSubWindowPrivate::MinimizeAction, false);
2695  d->setEnabled(QMdiSubWindowPrivate::ResizeAction, d->resizeEnabled);
2696  d->setEnabled(QMdiSubWindowPrivate::MaximizeAction, true);
2697  d->setEnabled(QMdiSubWindowPrivate::RestoreAction, true);
2698  d->setEnabled(QMdiSubWindowPrivate::MoveAction, d->moveEnabled);
2699 #endif
2700 }
2701 
2706 {
2707  Q_D(QMdiSubWindow);
2708  if (!object)
2709  return QWidget::eventFilter(object, event);
2710 
2711 #ifndef QT_NO_MENU
2712  // System menu events.
2713  if (d->systemMenu && d->systemMenu == object) {
2714  if (event->type() == QEvent::MouseButtonDblClick) {
2715  close();
2716  } else if (event->type() == QEvent::MouseMove) {
2717  QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
2718  d->hoveredSubControl = d->getSubControl(mapFromGlobal(mouseEvent->globalPos()));
2719  } else if (event->type() == QEvent::Hide) {
2720  d->systemMenu->removeEventFilter(this);
2721  d->activeSubControl = QStyle::SC_None;
2722  update(QRegion(0, 0, width(), d->titleBarHeight()));
2723  }
2724  return QWidget::eventFilter(object, event);
2725  }
2726 #endif
2727 
2728 #ifndef QT_NO_SIZEGRIP
2729  if (object != d->baseWidget && parent() && qobject_cast<QSizeGrip *>(object)) {
2731  return QWidget::eventFilter(object, event);
2732  const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
2733  d->mousePressPosition = parentWidget()->mapFromGlobal(mouseEvent->globalPos());
2734  d->oldGeometry = geometry();
2737 #ifndef QT_NO_RUBBERBAND
2738  d->enterRubberBandMode();
2739 #endif
2740  return true;
2741  }
2742 #endif
2743 
2744  if (object != d->baseWidget && event->type() != QEvent::WindowTitleChange)
2745  return QWidget::eventFilter(object, event);
2746 
2747  switch (event->type()) {
2748  case QEvent::Show:
2749  d->setActive(true);
2750  break;
2751  case QEvent::ShowToParent:
2752  if (!d->isWidgetHiddenByUs)
2753  show();
2754  break;
2757  if (changeEvent->isOverride())
2758  break;
2759  Qt::WindowStates oldState = changeEvent->oldState();
2760  Qt::WindowStates newState = d->baseWidget->windowState();
2761  if (!(oldState & Qt::WindowMinimized) && (newState & Qt::WindowMinimized))
2762  showMinimized();
2763  else if (!(oldState & Qt::WindowMaximized) && (newState & Qt::WindowMaximized))
2764  showMaximized();
2765  else if (!(newState & (Qt::WindowMaximized | Qt::WindowMinimized)))
2766  showNormal();
2767  break;
2768  }
2769  case QEvent::Enter:
2770  d->currentOperation = QMdiSubWindowPrivate::None;
2771  d->updateCursor();
2772  break;
2773  case QEvent::LayoutRequest:
2774  d->updateGeometryConstraints();
2775  break;
2777  if (d->ignoreWindowTitleChange)
2778  break;
2779  if (object == d->baseWidget) {
2780  d->updateWindowTitle(true);
2781  d->lastChildWindowTitle = d->baseWidget->windowTitle();
2782 #ifndef QT_NO_MENUBAR
2783  } else if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar()
2784  ->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) {
2785  d->originalTitle = QString::null;
2786  if (d->baseWidget && d->baseWidget->windowTitle() == windowTitle())
2787  d->updateWindowTitle(true);
2788  else
2789  d->updateWindowTitle(false);
2790 #endif
2791  }
2792  break;
2793  case QEvent::ModifiedChange: {
2794  if (object != d->baseWidget)
2795  break;
2796  bool windowModified = d->baseWidget->isWindowModified();
2797  if (!windowModified && d->baseWidget->windowTitle() != windowTitle())
2798  break;
2799  if (windowTitle().contains(QLatin1String("[*]")))
2800  setWindowModified(windowModified);
2801  break;
2802  }
2803  default:
2804  break;
2805  }
2806  return QWidget::eventFilter(object, event);
2807 }
2808 
2813 {
2814  Q_D(QMdiSubWindow);
2815  switch (event->type()) {
2816  case QEvent::StyleChange: {
2817  bool wasShaded = isShaded();
2818  bool wasMinimized = isMinimized();
2819  bool wasMaximized = isMaximized();
2820  // Don't emit subWindowActivated, the app doesn't have to know about our hacks
2821  const QScopedValueRollback<bool> activationEnabledSaver(d->activationEnabled);
2822  d->activationEnabled = false;
2823 
2824  ensurePolished();
2825  setContentsMargins(0, 0, 0, 0);
2826  if (wasMinimized || wasMaximized || wasShaded)
2827  showNormal();
2828  d->updateGeometryConstraints();
2829  resize(d->internalMinimumSize.expandedTo(size()));
2830  d->updateMask();
2831  d->updateDirtyRegions();
2832  if (wasShaded)
2833  showShaded();
2834  else if (wasMinimized)
2835  showMinimized();
2836  else if (wasMaximized)
2837  showMaximized();
2838  break;
2839  }
2841  d->setActive(false);
2842  break;
2843  case QEvent::ParentChange: {
2844  bool wasResized = testAttribute(Qt::WA_Resized);
2845 #ifndef QT_NO_MENUBAR
2846  d->removeButtonsFromMenuBar();
2847 #endif
2848  d->currentOperation = QMdiSubWindowPrivate::None;
2849  d->activeSubControl = QStyle::SC_None;
2850  d->hoveredSubControl = QStyle::SC_None;
2851 #ifndef QT_NO_RUBBERBAND
2852  if (d->isInRubberBandMode)
2853  d->leaveRubberBandMode();
2854 #endif
2855  d->isShadeMode = false;
2856  d->isMaximizeMode = false;
2857  d->isWidgetHiddenByUs = false;
2858  if (!parent()) {
2859 #if !defined(QT_NO_SIZEGRIP) && defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
2860  if (qobject_cast<QMacStyle *>(style()))
2861  delete d->sizeGrip;
2862 #endif
2863  setOption(RubberBandResize, false);
2864  setOption(RubberBandMove, false);
2865  } else {
2866  d->setWindowFlags(windowFlags());
2867  }
2868  setContentsMargins(0, 0, 0, 0);
2869  d->updateGeometryConstraints();
2870  d->updateCursor();
2871  d->updateMask();
2872  d->updateDirtyRegions();
2873  d->updateActions();
2874  if (!wasResized && testAttribute(Qt::WA_Resized))
2875  setAttribute(Qt::WA_Resized, false);
2876  break;
2877  }
2879  if (d->ignoreNextActivationEvent) {
2880  d->ignoreNextActivationEvent = false;
2881  break;
2882  }
2883  d->isExplicitlyDeactivated = false;
2884  d->setActive(true);
2885  break;
2887  if (d->ignoreNextActivationEvent) {
2888  d->ignoreNextActivationEvent = false;
2889  break;
2890  }
2891  d->isExplicitlyDeactivated = true;
2892  d->setActive(false);
2893  break;
2895  if (!d->ignoreWindowTitleChange)
2896  d->updateWindowTitle(false);
2897  d->updateInternalWindowTitle();
2898  break;
2900  if (!windowTitle().contains(QLatin1String("[*]")))
2901  break;
2902 #ifndef QT_NO_MENUBAR
2903  if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar()
2904  ->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) {
2906  }
2907 #endif // QT_NO_MENUBAR
2908  d->updateInternalWindowTitle();
2909  break;
2911  d->updateDirtyRegions();
2912  break;
2913  case QEvent::LayoutRequest:
2914  d->updateGeometryConstraints();
2915  break;
2917  d->menuIcon = windowIcon();
2918  if (d->menuIcon.isNull())
2919  d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, this);
2920  if (d->controlContainer)
2921  d->controlContainer->updateWindowIcon(d->menuIcon);
2923  update(0, 0, width(), d->titleBarHeight());
2924  break;
2925  case QEvent::PaletteChange:
2926  d->titleBarPalette = d->desktopPalette();
2927  break;
2928  case QEvent::FontChange:
2929  d->font = font();
2930  break;
2931 #ifndef QT_NO_TOOLTIP
2932  case QEvent::ToolTip:
2933  showToolTip(static_cast<QHelpEvent *>(event), this, d->titleBarOptions(),
2934  QStyle::CC_TitleBar, d->hoveredSubControl);
2935  break;
2936 #endif
2937  default:
2938  break;
2939  }
2940  return QWidget::event(event);
2941 }
2942 
2947 {
2948  Q_D(QMdiSubWindow);
2949  if (!parent()) {
2950  QWidget::showEvent(showEvent);
2951  return;
2952  }
2953 
2954 #if !defined(QT_NO_SIZEGRIP) && defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
2955  if (qobject_cast<QMacStyle *>(style()) && !d->sizeGrip
2957  d->setSizeGrip(new QSizeGrip(0));
2958  Q_ASSERT(d->sizeGrip);
2959  if (isMinimized())
2960  d->setSizeGripVisible(false);
2961  else
2962  d->setSizeGripVisible(true);
2963  resize(size().expandedTo(d->internalMinimumSize));
2964  }
2965 #endif
2966 
2967  d->updateDirtyRegions();
2968  // Show buttons in the menu bar if they're already not there.
2969  // We want to do this when QMdiSubWindow becomes visible after being hidden.
2970 #ifndef QT_NO_MENUBAR
2971  if (d->controlContainer) {
2972  if (QMenuBar *menuBar = d->menuBar()) {
2973  if (menuBar->cornerWidget(Qt::TopRightCorner) != maximizedButtonsWidget())
2974  d->showButtonsInMenuBar(menuBar);
2975  }
2976  }
2977 #endif
2978  d->setActive(true);
2979 }
2980 
2985 {
2986 #ifndef QT_NO_MENUBAR
2987  d_func()->removeButtonsFromMenuBar();
2988 #endif
2989 }
2990 
2995 {
2996  if (!parent()) {
2997  QWidget::changeEvent(changeEvent);
2998  return;
2999  }
3000 
3001  if (changeEvent->type() != QEvent::WindowStateChange) {
3002  QWidget::changeEvent(changeEvent);
3003  return;
3004  }
3005 
3007  if (event->isOverride()) {
3008  event->ignore();
3009  return;
3010  }
3011 
3012  Qt::WindowStates oldState = event->oldState();
3013  Qt::WindowStates newState = windowState();
3014  if (oldState == newState) {
3015  changeEvent->ignore();
3016  return;
3017  }
3018 
3019  // QWidget ensures that the widget is visible _after_ setWindowState(),
3020  // but we need to ensure that the widget is visible _before_
3021  // setWindowState() returns.
3022  Q_D(QMdiSubWindow);
3023  if (!isVisible()) {
3024  d->ensureWindowState(Qt::WindowNoState);
3025  setVisible(true);
3026  }
3027 
3028  if (!d->oldGeometry.isValid())
3029  d->oldGeometry = geometry();
3030 
3031  if ((oldState & Qt::WindowActive) && (newState & Qt::WindowActive))
3032  d->currentOperation = QMdiSubWindowPrivate::None;
3033 
3034  if (!(oldState & Qt::WindowMinimized) && (newState & Qt::WindowMinimized))
3035  d->setMinimizeMode();
3036  else if (!(oldState & Qt::WindowMaximized) && (newState & Qt::WindowMaximized))
3037  d->setMaximizeMode();
3038  else if (!(newState & (Qt::WindowMaximized | Qt::WindowMinimized)))
3039  d->setNormalMode();
3040 
3041  if (d->isActive)
3042  d->ensureWindowState(Qt::WindowActive);
3043  if (d->activationEnabled)
3044  emit windowStateChanged(oldState, windowState());
3045 }
3046 
3051 {
3052  Q_D(QMdiSubWindow);
3053  bool acceptClose = true;
3054  if (d->baseWidget)
3055  acceptClose = d->baseWidget->close();
3056  if (!acceptClose) {
3057  closeEvent->ignore();
3058  return;
3059  }
3060 #ifndef QT_NO_MENUBAR
3061  d->removeButtonsFromMenuBar();
3062 #endif
3063  d->setActive(false);
3065  QChildEvent childRemoved(QEvent::ChildRemoved, this);
3066  QApplication::sendEvent(parentWidget(), &childRemoved);
3067  }
3068  closeEvent->accept();
3069 }
3070 
3074 void QMdiSubWindow::leaveEvent(QEvent * /*leaveEvent*/)
3075 {
3076  Q_D(QMdiSubWindow);
3077  if (d->hoveredSubControl != QStyle::SC_None) {
3078  d->hoveredSubControl = QStyle::SC_None;
3079  update(QRegion(0, 0, width(), d->titleBarHeight()));
3080  }
3081 }
3082 
3087 {
3088  Q_D(QMdiSubWindow);
3089 #ifndef QT_NO_SIZEGRIP
3090  if (d->sizeGrip) {
3091  d->sizeGrip->move(isLeftToRight() ? width() - d->sizeGrip->width() : 0,
3092  height() - d->sizeGrip->height());
3093  }
3094 #endif
3095 
3096  if (!parent()) {
3097  QWidget::resizeEvent(resizeEvent);
3098  return;
3099  }
3100 
3101  if (d->isMaximizeMode)
3102  d->ensureWindowState(Qt::WindowMaximized);
3103 
3104  d->updateMask();
3105  if (!isVisible())
3106  return;
3107 
3108  if (d->resizeTimerId <= 0)
3109  d->cachedStyleOptions = d->titleBarOptions();
3110  else
3111  killTimer(d->resizeTimerId);
3112  d->resizeTimerId = startTimer(200);
3113 }
3114 
3119 {
3120  Q_D(QMdiSubWindow);
3121  if (timerEvent->timerId() == d->resizeTimerId) {
3122  killTimer(d->resizeTimerId);
3123  d->resizeTimerId = -1;
3124  d->updateDirtyRegions();
3125  }
3126 }
3127 
3132 {
3133  if (!parent()) {
3134  QWidget::moveEvent(moveEvent);
3135  return;
3136  }
3137 
3138  Q_D(QMdiSubWindow);
3139  if (d->isMaximizeMode)
3140  d->ensureWindowState(Qt::WindowMaximized);
3141 }
3142 
3147 {
3148  if (!parent() || (windowFlags() & Qt::FramelessWindowHint)) {
3149  QWidget::paintEvent(paintEvent);
3150  return;
3151  }
3152 
3153  Q_D(QMdiSubWindow);
3154  if (isMaximized() && !d->drawTitleBarWhenMaximized())
3155  return;
3156 
3157  if (d->resizeTimerId != -1) {
3158  // Only update the style option rect and the window title.
3159  int border = d->hasBorder(d->cachedStyleOptions) ? 4 : 0;
3160  int titleBarHeight = d->titleBarHeight(d->cachedStyleOptions);
3161  titleBarHeight -= isMinimized() ? 2 * border : border;
3162  d->cachedStyleOptions.rect = QRect(border, border, width() - 2 * border, titleBarHeight);
3163  if (!d->windowTitle.isEmpty()) {
3164  int width = style()->subControlRect(QStyle::CC_TitleBar, &d->cachedStyleOptions,
3166  d->cachedStyleOptions.text = d->cachedStyleOptions.fontMetrics
3167  .elidedText(d->windowTitle, Qt::ElideRight, width);
3168  }
3169  } else {
3170  // Force full update.
3171  d->cachedStyleOptions = d->titleBarOptions();
3172  }
3173 
3174  QStylePainter painter(this);
3175  if (!d->windowTitle.isEmpty())
3176  painter.setFont(d->font);
3177  painter.drawComplexControl(QStyle::CC_TitleBar, d->cachedStyleOptions);
3178 
3179  if (isMinimized() && !d->hasBorder(d->cachedStyleOptions))
3180  return;
3181 
3182  QStyleOptionFrame frameOptions;
3183  frameOptions.initFrom(this);
3184  frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, this);
3185  if (d->isActive)
3186  frameOptions.state |= QStyle::State_Active;
3187  else
3188  frameOptions.state &= ~QStyle::State_Active;
3189 
3190  // ### Ensure that we do not require setting the cliprect for 4.4
3191  if (!isMinimized() && !d->hasBorder(d->cachedStyleOptions))
3192  painter.setClipRect(rect().adjusted(0, d->titleBarHeight(d->cachedStyleOptions), 0, 0));
3193  if (!isMinimized() || d->hasBorder(d->cachedStyleOptions))
3194  painter.drawPrimitive(QStyle::PE_FrameWindow, frameOptions);
3195 }
3196 
3201 {
3202  if (!parent()) {
3203  QWidget::mousePressEvent(mouseEvent);
3204  return;
3205  }
3206 
3207  Q_D(QMdiSubWindow);
3208  if (d->isInInteractiveMode)
3209  d->leaveInteractiveMode();
3210 #ifndef QT_NO_RUBBERBAND
3211  if (d->isInRubberBandMode)
3212  d->leaveRubberBandMode();
3213 #endif
3214 
3215  if (mouseEvent->button() != Qt::LeftButton) {
3216  mouseEvent->ignore();
3217  return;
3218  }
3219 
3220  if (d->currentOperation != QMdiSubWindowPrivate::None) {
3221  d->updateCursor();
3222  d->mousePressPosition = mapToParent(mouseEvent->pos());
3223  if (d->resizeEnabled || d->moveEnabled)
3224  d->oldGeometry = geometry();
3225 #ifndef QT_NO_RUBBERBAND
3226  if ((testOption(QMdiSubWindow::RubberBandResize) && d->isResizeOperation())
3227  || (testOption(QMdiSubWindow::RubberBandMove) && d->isMoveOperation())) {
3228  d->enterRubberBandMode();
3229  }
3230 #endif
3231  return;
3232  }
3233 
3234  d->activeSubControl = d->hoveredSubControl;
3235 #ifndef QT_NO_MENU
3236  if (d->activeSubControl == QStyle::SC_TitleBarSysMenu)
3237  showSystemMenu();
3238  else
3239 #endif
3240  update(QRegion(0, 0, width(), d->titleBarHeight()));
3241 }
3242 
3247 {
3248  if (!parent()) {
3249  QWidget::mouseDoubleClickEvent(mouseEvent);
3250  return;
3251  }
3252 
3253  if (mouseEvent->button() != Qt::LeftButton) {
3254  mouseEvent->ignore();
3255  return;
3256  }
3257 
3258  Q_D(QMdiSubWindow);
3259  if (!d->isMoveOperation()) {
3260 #ifndef QT_NO_MENU
3261  if (d->hoveredSubControl == QStyle::SC_TitleBarSysMenu)
3262  close();
3263 #endif
3264  return;
3265  }
3266 
3267  Qt::WindowFlags flags = windowFlags();
3268  if (isMinimized()) {
3269  if ((isShaded() && (flags & Qt::WindowShadeButtonHint))
3270  || (flags & Qt::WindowMinimizeButtonHint)) {
3271  showNormal();
3272  }
3273  return;
3274  }
3275 
3276  if (isMaximized()) {
3277  if (flags & Qt::WindowMaximizeButtonHint)
3278  showNormal();
3279  return;
3280  }
3281 
3282  if (flags & Qt::WindowShadeButtonHint)
3283  showShaded();
3284  else if (flags & Qt::WindowMaximizeButtonHint)
3285  showMaximized();
3286 }
3287 
3292 {
3293  if (!parent()) {
3294  QWidget::mouseReleaseEvent(mouseEvent);
3295  return;
3296  }
3297 
3298  if (mouseEvent->button() != Qt::LeftButton) {
3299  mouseEvent->ignore();
3300  return;
3301  }
3302 
3303  Q_D(QMdiSubWindow);
3304  if (d->currentOperation != QMdiSubWindowPrivate::None) {
3305 #ifndef QT_NO_RUBBERBAND
3306  if (d->isInRubberBandMode && !d->isInInteractiveMode)
3307  d->leaveRubberBandMode();
3308 #endif
3309  if (d->resizeEnabled || d->moveEnabled)
3310  d->oldGeometry = geometry();
3311  }
3312 
3313  d->currentOperation = d->getOperation(mouseEvent->pos());
3314  d->updateCursor();
3315 
3316  d->hoveredSubControl = d->getSubControl(mouseEvent->pos());
3317  if (d->activeSubControl != QStyle::SC_None
3318  && d->activeSubControl == d->hoveredSubControl) {
3319  d->processClickedSubControl();
3320  }
3321  d->activeSubControl = QStyle::SC_None;
3322  update(QRegion(0, 0, width(), d->titleBarHeight()));
3323 }
3324 
3329 {
3330  if (!parent()) {
3331  QWidget::mouseMoveEvent(mouseEvent);
3332  return;
3333  }
3334 
3335  Q_D(QMdiSubWindow);
3336  // No update needed if we're in a move/resize operation.
3337  if (!d->isMoveOperation() && !d->isResizeOperation()) {
3338  // Find previous and current hover region.
3339  const QStyleOptionTitleBar options = d->titleBarOptions();
3340  QStyle::SubControl oldHover = d->hoveredSubControl;
3341  d->hoveredSubControl = d->getSubControl(mouseEvent->pos());
3342  QRegion hoverRegion;
3343  if (isHoverControl(oldHover) && oldHover != d->hoveredSubControl)
3344  hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options, oldHover, this);
3345  if (isHoverControl(d->hoveredSubControl) && d->hoveredSubControl != oldHover) {
3346  hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options,
3347  d->hoveredSubControl, this);
3348  }
3349 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
3350  if (qobject_cast<QMacStyle *>(style()) && !hoverRegion.isEmpty())
3351  hoverRegion += QRegion(0, 0, width(), d->titleBarHeight(options));
3352 #endif
3353  if (!hoverRegion.isEmpty())
3354  update(hoverRegion);
3355  }
3356 
3357  if ((mouseEvent->buttons() & Qt::LeftButton) || d->isInInteractiveMode) {
3358  if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled))
3359  d->setNewGeometry(mapToParent(mouseEvent->pos()));
3360  return;
3361  }
3362 
3363  // Do not resize/move if not allowed.
3364  d->currentOperation = d->getOperation(mouseEvent->pos());
3365  if ((d->isResizeOperation() && !d->resizeEnabled) || (d->isMoveOperation() && !d->moveEnabled))
3366  d->currentOperation = QMdiSubWindowPrivate::None;
3367  d->updateCursor();
3368 }
3369 
3374 {
3375  Q_D(QMdiSubWindow);
3376  if (!d->isInInteractiveMode || !parent()) {
3377  keyEvent->ignore();
3378  return;
3379  }
3380 
3381  QPoint delta;
3382  switch (keyEvent->key()) {
3383  case Qt::Key_Right:
3384  if (keyEvent->modifiers() & Qt::ShiftModifier)
3385  delta = QPoint(d->keyboardPageStep, 0);
3386  else
3387  delta = QPoint(d->keyboardSingleStep, 0);
3388  break;
3389  case Qt::Key_Up:
3390  if (keyEvent->modifiers() & Qt::ShiftModifier)
3391  delta = QPoint(0, -d->keyboardPageStep);
3392  else
3393  delta = QPoint(0, -d->keyboardSingleStep);
3394  break;
3395  case Qt::Key_Left:
3396  if (keyEvent->modifiers() & Qt::ShiftModifier)
3397  delta = QPoint(-d->keyboardPageStep, 0);
3398  else
3399  delta = QPoint(-d->keyboardSingleStep, 0);
3400  break;
3401  case Qt::Key_Down:
3402  if (keyEvent->modifiers() & Qt::ShiftModifier)
3403  delta = QPoint(0, d->keyboardPageStep);
3404  else
3405  delta = QPoint(0, d->keyboardSingleStep);
3406  break;
3407  case Qt::Key_Escape:
3408  case Qt::Key_Return:
3409  case Qt::Key_Enter:
3410  d->leaveInteractiveMode();
3411  return;
3412  default:
3413  keyEvent->ignore();
3414  return;
3415  }
3416 
3417 #ifndef QT_NO_CURSOR
3418  QPoint newPosition = parentWidget()->mapFromGlobal(cursor().pos() + delta);
3419  QRect oldGeometry =
3420 #ifndef QT_NO_RUBBERBAND
3421  d->isInRubberBandMode ? d->rubberBand->geometry() :
3422 #endif
3423  geometry();
3424  d->setNewGeometry(newPosition);
3425  QRect currentGeometry =
3426 #ifndef QT_NO_RUBBERBAND
3427  d->isInRubberBandMode ? d->rubberBand->geometry() :
3428 #endif
3429  geometry();
3430  if (currentGeometry == oldGeometry)
3431  return;
3432 
3433  // Update cursor position
3434 
3435  QPoint actualDelta;
3436  if (d->isMoveOperation()) {
3437  actualDelta = QPoint(currentGeometry.x() - oldGeometry.x(),
3438  currentGeometry.y() - oldGeometry.y());
3439  } else {
3440  int dx = isLeftToRight() ? currentGeometry.width() - oldGeometry.width()
3441  : currentGeometry.x() - oldGeometry.x();
3442  actualDelta = QPoint(dx, currentGeometry.height() - oldGeometry.height());
3443  }
3444 
3445  // Adjust in case we weren't able to move as long as wanted.
3446  if (actualDelta != delta)
3447  newPosition += (actualDelta - delta);
3448  cursor().setPos(parentWidget()->mapToGlobal(newPosition));
3449 #endif
3450 }
3451 
3452 #ifndef QT_NO_CONTEXTMENU
3453 
3457 {
3458  Q_D(QMdiSubWindow);
3459  if (!d->systemMenu) {
3460  contextMenuEvent->ignore();
3461  return;
3462  }
3463 
3464  if (d->hoveredSubControl == QStyle::SC_TitleBarSysMenu
3465  || d->getRegion(QMdiSubWindowPrivate::Move).contains(contextMenuEvent->pos())) {
3466  d->systemMenu->exec(contextMenuEvent->globalPos());
3467  } else {
3468  contextMenuEvent->ignore();
3469  }
3470 }
3471 #endif // QT_NO_CONTEXTMENU
3472 
3477 {
3478  d_func()->focusInReason = focusInEvent->reason();
3479 }
3480 
3485 {
3486  // To avoid update() in QWidget::focusOutEvent.
3487 }
3488 
3493 {
3494  if (childEvent->type() != QEvent::ChildPolished)
3495  return;
3496 #ifndef QT_NO_SIZEGRIP
3497  if (QSizeGrip *sizeGrip = qobject_cast<QSizeGrip *>(childEvent->child()))
3498  d_func()->setSizeGrip(sizeGrip);
3499 #endif
3500 }
3501 
3506 {
3507  Q_D(const QMdiSubWindow);
3508  int margin, minWidth;
3509  d->sizeParameters(&margin, &minWidth);
3510  QSize size(2 * margin, d->titleBarHeight() + margin);
3511  if (d->baseWidget && d->baseWidget->sizeHint().isValid())
3512  size += d->baseWidget->sizeHint();
3513  return size.expandedTo(minimumSizeHint());
3514 }
3515 
3520 {
3521  Q_D(const QMdiSubWindow);
3522  if (isVisible())
3523  ensurePolished();
3524 
3525  // Minimized window.
3526  if (parent() && isMinimized() && !isShaded())
3527  return d->iconSize();
3528 
3529  // Calculate window decoration.
3530  int margin, minWidth;
3531  d->sizeParameters(&margin, &minWidth);
3532  int decorationHeight = margin + d->titleBarHeight();
3533  int minHeight = decorationHeight;
3534 
3535  // Shaded window.
3536  if (parent() && isShaded())
3537  return QSize(qMax(minWidth, width()), d->titleBarHeight());
3538 
3539  // Content
3540  if (layout()) {
3541  QSize minLayoutSize = layout()->minimumSize();
3542  if (minLayoutSize.isValid()) {
3543  minWidth = qMax(minWidth, minLayoutSize.width() + 2 * margin);
3544  minHeight += minLayoutSize.height();
3545  }
3546  } else if (d->baseWidget && d->baseWidget->isVisible()) {
3547  QSize minBaseWidgetSize = d->baseWidget->minimumSizeHint();
3548  if (minBaseWidgetSize.isValid()) {
3549  minWidth = qMax(minWidth, minBaseWidgetSize.width() + 2 * margin);
3550  minHeight += minBaseWidgetSize.height();
3551  }
3552  }
3553 
3554 #ifndef QT_NO_SIZEGRIP
3555  // SizeGrip
3556  int sizeGripHeight = 0;
3557  if (d->sizeGrip && d->sizeGrip->isVisibleTo(const_cast<QMdiSubWindow *>(this)))
3558  sizeGripHeight = d->sizeGrip->height();
3559 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
3560  else if (parent() && qobject_cast<QMacStyle *>(style()) && !d->sizeGrip)
3561  sizeGripHeight = style()->pixelMetric(QStyle::PM_SizeGripSize, 0, this);
3562 #endif
3563  minHeight = qMax(minHeight, decorationHeight + sizeGripHeight);
3564 #endif
3565 
3566  return QSize(minWidth, minHeight).expandedTo(QApplication::globalStrut());
3567 }
3568 
3570 
3571 #include "moc_qmdisubwindow.cpp"
3572 #include "qmdisubwindow.moc"
3573 
3574 #endif //QT_NO_MDIAREA
QPoint pos() const
T qobject_cast(QObject *object)
Definition: qobject.h:375
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
void showMaximized()
Shows the widget maximized.
Definition: qwidget.cpp:3218
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void mouseMoveEvent(QMouseEvent *mouseEvent)
Reimplemented Function
ControlLabel(QMdiSubWindow *subWindow, QWidget *parent=0)
double d
Definition: qnumeric_p.h:62
Qt::WindowStates oldState() const
Returns the state of the window before the change.
Definition: qevent.h:712
void windowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState)
QMdiSubWindow emits this signal after the window state changes.
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
static int getResizeDeltaComponent(uint cflags, uint resizeFlag, uint resizeReverseFlag, int delta)
unsigned int QRgb
Definition: qrgb.h:53
#define QT_NO_SIZEGRIP
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QStyle::SubControl getSubControl(const QPoint &pos) const
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition: qwidget.cpp:6863
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
static bool isChildOfTabbedQMdiArea(const QMdiSubWindow *child)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static const Qt::WindowFlags CustomizeWindowFlags
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
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
void setSizeGrip(QSizeGrip *sizeGrip)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QSizeGrip class provides a resize handle for resizing top-level windows.
Definition: qsizegrip.h:55
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
EventRef event
QSize size() const
QPointer< QWidget > widget
void mouseReleaseEvent(QMouseEvent *mouseEvent)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
void resizeEvent(QResizeEvent *resizeEvent)
Reimplemented Function
QCursor cursor() const
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
void setWindowModified(bool)
Definition: qwidget.cpp:11559
void leaveEvent(QEvent *leaveEvent)
Reimplemented Function
static void keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
QPointer< QWidget > restoreFocusWidget
void hideEvent(QHideEvent *hideEvent)
Reimplemented Function
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
#define it(className, varName)
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
static const int NumSubControls
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
Definition: qwidget.cpp:10104
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
QLayout * layout
Definition: qwidget_p.h:704
bool isVisible() const
Definition: qwidget.h:1005
const QPoint & pos() const
Returns the position of the mouse pointer relative to the widget that received the event...
Definition: qevent.h:412
static QSize globalStrut()
void setCheckable(bool)
Definition: qaction.cpp:1094
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
QIcon icon
the icon for the title bar
Definition: qstyleoption.h:823
virtual void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwidget.cpp:9286
ComplexControl
This enum describes the available complex controls.
Definition: qstyle.h:386
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QPointer< QMdiSubWindow > mdiChild
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
QSize sizeHint() const
Reimplemented Function
void mouseDoubleClickEvent(QMouseEvent *mouseEvent)
Reimplemented Function
void changeEvent(QEvent *changeEvent)
Reimplemented Function
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
QMenu * systemMenu() const
Returns a pointer to the current system menu, or zero if no system menu is set.
void removeEventFilter(QObject *)
Removes an event filter object obj from this object.
Definition: qobject.cpp:2099
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
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
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition: qwidget.h:187
bool event(QEvent *event)
This is the main event handler; it handles event event.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOptionComplex &opt, QStyle::ComplexControl complexControl, QStyle::SubControl subControl)
int titleBarHeight() const
bool windowModified
whether the document shown in the window has unsaved changes
Definition: qwidget.h:202
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
void showSystemMenu()
Shows the system menu below the system menu icon in the title bar.
void setKeyboardSingleStep(int step)
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void showShaded()
Calling this function makes the subwindow enter the shaded mode.
void setSystemMenu(QMenu *systemMenu)
Sets systemMenu as the current system menu for this subwindow.
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QWidget * nextInFocusChain() const
Returns the next widget in this widget&#39;s focus chain.
Definition: qwidget.cpp:6873
virtual void moveEvent(QMoveEvent *)
This event handler can be reimplemented in a subclass to receive widget move events which are passed ...
Definition: qwidget.cpp:9566
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setMinimumSize(const QSize &)
Definition: qwidget.h:969
ControlContainer(QMdiSubWindow *mdiChild)
QString text
the text of the title bar
Definition: qstyleoption.h:822
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
bool isOverride() const
Definition: qevent.cpp:4071
void setOption(SubWindowOption option, bool on=true)
If on is true, option is enabled on the subwindow; otherwise it is disabled.
QStyleOptionTitleBar cachedStyleOptions
#define QT_NO_MENUBAR
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QPointer< QWidget > m_controllerWidget
QMdiSubWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
Constructs a new QMdiSubWindow widget.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
void overrideWindowState(Qt::WindowStates state)
Definition: qwidget.cpp:3098
bool hasFocus() const
Definition: qwidget.cpp:6583
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void _q_processFocusChanged(QWidget *old, QWidget *now)
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
void sizeParameters(int *margin, int *minWidth) const
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void leaveEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
#define Q_D(Class)
Definition: qglobal.h:2482
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
int height() const
QMdiSubWindow::SubWindowOptions options
void keyPressEvent(QKeyEvent *keyEvent)
Reimplemented Function
static const QStyle::StandardPixmap ButtonPixmaps[]
QRegion getRegion(Operation operation) const
void paintEvent(QPaintEvent *event)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition: qwidget.cpp:3250
void childEvent(QChildEvent *childEvent)
Reimplemented Function
void setEnabled(bool)
Definition: qaction.cpp:1192
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
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 mouseReleaseEvent(QMouseEvent *mouseEvent)
Reimplemented Function
static QFont font()
Returns the default application font.
void setVisible(WindowStateAction, bool visible=true)
bool event(QEvent *event)
This is the main event handler; it handles event event.
QPointer< QMenuBar > m_menuBar
ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent=0)
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
~QMdiSubWindow()
Destroys the subwindow.
void clearFocus()
Takes keyboard input focus from the widget.
Definition: qwidget.cpp:6757
QWidget * viewport() const
Returns the viewport widget.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
bool isWindowModified() const
Definition: qwidget.cpp:11554
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
virtual void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qwidget.cpp:9548
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QIcon windowIcon() const
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
int width() const
Returns the width.
Definition: qsize.h:126
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
QWidget * cornerWidget(Qt::Corner corner=Qt::TopRightCorner) const
Returns the widget on the left of the first or on the right of the last menu item, depending on corner.
Definition: qmenubar.cpp:2022
void addToSystemMenu(WindowStateAction, const QString &text, const char *slot)
int value() const
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Returns an icon for the given standardIcon.
Definition: qstyle.cpp:2327
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setGeometry(const QRect &r)
Sets the geometry of the rubber band to rect, specified in the coordinate system of its parent widget...
void ensureWindowState(Qt::WindowState state)
The QMoveEvent class contains event parameters for move events.
Definition: qevent.h:334
static bool isEmpty(const char *str)
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 paintEvent(QPaintEvent *paintEvent)
Reimplemented Function
void setKeyboardPageStep(int step)
bool visible
whether the widget is visible
Definition: qwidget.h:191
QStyle::SubControl activeControl
QWidget * widget() const
Returns the current internal widget.
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
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 raise()
Raises this widget to the top of the parent widget&#39;s stack.
Definition: qwidget.cpp:11901
virtual int indexOf(QWidget *) const
Searches for widget widget in this layout (not including child layouts).
Definition: qlayout.cpp:1378
void updateWindowTitle(bool requestFromChild)
void setSizeGripVisible(bool visible=true) const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
#define SPI_GETGRADIENTCAPTIONS
#define qApp
int width() const
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.
Definition: qwidget.cpp:7449
QStyle::SubControls visibleControls
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
The QMdiArea widget provides an area in which MDI windows are displayed.
Definition: qmdiarea.h:59
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
void setWindowFlags(Qt::WindowFlags type)
Definition: qwidget.cpp:10399
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 paintEvent(QPaintEvent *paintEvent)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
void showButtonsInMenuBar(QMenuBar *menuBar)
virtual void mouseDoubleClickEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
Definition: qwidget.cpp:9306
static ControlElement< T > * ptr(QWidget *widget)
bool testOption(SubWindowOption) const
Returns true if option is enabled; otherwise returns false.
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Q_CORE_EXPORT void qWarning(const char *,...)
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
QPointer< QWidget > m_menuLabel
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
T findChild(const QString &aName=QString()) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object.
Definition: qobject.h:158
void setTopLeft(const QPoint &p)
Set the top-left corner of the rectangle to the given position.
Definition: qrect.h:270
QString windowTitle
the window title (caption)
Definition: qwidget.h:198
QPointer< QMdi::ControlContainer > controlContainer
QString windowTitle() const
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool isShaded() const
Returns true if this window is shaded; otherwise returns false.
QWidget * menuWidget() const
Returns the menu bar for the main window.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QPointer< QWidget > previousRight
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
static const int BoundaryMargin
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...
void setWindowIcon(const QIcon &icon)
Definition: qwidget.cpp:6362
#define COLOR_GRADIENTACTIVECAPTION
void show()
Shows the widget and its child widgets.
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
void addActions(QList< QAction *> actions)
Appends the actions actions to this widget&#39;s list of actions.
Definition: qwidget.cpp:3327
QStyleOptionTitleBar titleBarOptions() const
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QRect rect() const
void showMinimized()
Shows the widget minimized, as an icon.
Definition: qwidget.cpp:3038
#define Q_OBJECT
Definition: qobjectdefs.h:157
void updateWindowIcon(const QIcon &windowIcon)
QPointer< QWidget > baseWidget
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
#define None
void hide()
Hides the widget.
Definition: qwidget.h:501
void setShortcuts(const QList< QKeySequence > &shortcuts)
Sets shortcuts as the list of shortcuts that trigger the action.
Definition: qaction.cpp:474
bool isMaximized() const
Definition: qwidget.cpp:3074
virtual bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qobject.cpp:1375
void setMouseTracking(bool enable)
Definition: qwidget.h:990
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
static bool isHoverControl(QStyle::SubControl control)
QPointer< QWidget > previousLeft
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
void closeEvent(QCloseEvent *closeEvent)
Reimplemented Function
QStyle::SubControl hoverControl
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:353
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
void setCornerWidget(QWidget *w, Qt::Corner corner=Qt::TopRightCorner)
This sets the given widget to be shown directly on the left of the first menu item, or on the right of the last menu item, depending on corner.
Definition: qmenubar.cpp:1980
void setNewGeometry(const QPoint &pos)
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
bool event(QEvent *event)
Reimplemented Function
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
void setVisible(bool)
Definition: qaction.cpp:1230
void initStyleOption(QStyleOptionComplex *option) const
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
bool drawTitleBarWhenMaximized() const
QMenuBar * menuBar() const
The QScopedValueRollback class resets a variable to its previous value on destruction.
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
Qt::FocusReason focusInReason
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
#define COLOR_GRADIENTINACTIVECAPTION
The QWindowStateChangeEvent class provides the window state before a window state change...
Definition: qevent.h:705
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
QMenuBar * menuBar() const
static const int NumButtonPixmaps
QMdiArea * mdiArea() const
Returns the area containing this sub-window, or 0 if there is none.
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
bool hasBorder(const QStyleOptionTitleBar &options) const
void focusOutEvent(QFocusEvent *focusOutEvent)
Reimplemented Function
void setFixedSize(const QSize &)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing o...
Definition: qwidget.cpp:4284
void mouseReleaseEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void mousePressEvent(QMouseEvent *mouseEvent)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void setVisible(bool)
Reimplemented Function
Definition: qsizegrip.cpp:529
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
Definition: qlayout.cpp:319
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QStyle::SubControl activeSubControl
void setWidget(QWidget *widget)
Sets widget as the internal widget of this subwindow.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
static const QStyle::SubControl SubControls[]
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
QPoint mapToParent(const QPoint &) const
Translates the widget coordinate pos to a coordinate in the parent widget.
Definition: qwidget.cpp:4459
QPointer< QMenu > systemMenu
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
#define QT_NO_RUBBERBAND
QPalette desktopPalette() const
QSize sizeHint() const
Reimplemented Function
Definition: qsizegrip.cpp:266
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
static bool desktopSettingsAware()
Returns true if Qt is set to use the system&#39;s standard colors, fonts, etc.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
static bool isChildOfQMdiSubWindow(const QWidget *child)
bool isAncestorOf(const QWidget *child) const
Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child...
Definition: qwidget.cpp:8573
QRubberBand * rubberBand
int height() const
Returns the height.
Definition: qsize.h:129
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
Definition: qnamespace.h:54
void setIcon(const QIcon &icon)
Definition: qaction.cpp:772
void setEnabled(WindowStateAction, bool enable=true)
QSize minimumSize() const
Qt::FocusReason reason()
Definition: qevent.cpp:1197
void mouseDoubleClickEvent(QMouseEvent *mouseEvent)
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
QWidget * controllerWidget() const
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
void setActive(bool activate, bool changeFocus=true)
void moveEvent(QMoveEvent *moveEvent)
Reimplemented Function
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=0) const =0
Returns the sub control at the given position in the given complex control (with the style options sp...
QWidget * maximizedSystemMenuIconWidget() const
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
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
QSize minimumSize() const
Returns the minimum size of this layout.
Definition: qlayout.cpp:1166
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
bool isMinimized() const
Definition: qwidget.cpp:3027
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QObject * parent
Definition: qobject.h:92
static QRgb colorref2qrgb(COLORREF col)
void contextMenuEvent(QContextMenuEvent *contextMenuEvent)
Reimplemented Function
bool isLeftToRight() const
Definition: qwidget.h:429
void timerEvent(QTimerEvent *timerEvent)
Reimplemented Function
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition: qicon.cpp:693
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
bool eventFilter(QObject *object, QEvent *event)
Reimplemented Function
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible)
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
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
QPointer< QAction > actions[NumWindowStateActions]
const QFont & font() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
bool isRightToLeft() const
Definition: qwidget.h:428
void mouseMoveEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
Qt::WindowFlags titleBarFlags
the widget flags for the title bar
Definition: qstyleoption.h:825
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413
The QStyleOptionComplex class is used to hold parameters that are common to all complex controls...
Definition: qstyleoption.h:687
QWidget * maximizedButtonsWidget() const
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
static const Null null
Definition: qstring.h:502
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
void setWindowFlags(Qt::WindowFlags windowFlags)
void focusInEvent(QFocusEvent *focusInEvent)
Reimplemented Function
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
QRegion region
the region for style hints that return a QRegion
Definition: qstyleoption.h:930
virtual void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwidget.cpp:9239
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
Use the widget&#39;s style to draw a complex control cc specified by the QStyleOptionComplex option...
Definition: qstylepainter.h:92
void showButtonsInMenuBar(QMenuBar *menuBar)
void mousePressEvent(QMouseEvent *mouseEvent)
Reimplemented Function
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
const QRect & geometry() const
void removeButtonsFromMenuBar(QMenuBar *menuBar=0)
#define signals
Definition: qobjectdefs.h:69
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198
void showEvent(QShowEvent *showEvent)
Reimplemented Function
int titleBarState
the state of the title bar
Definition: qstyleoption.h:824
void setMargin(int)
Definition: qlayout.cpp:464
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
Operation getOperation(const QPoint &pos) const
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
void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
#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
WindowState
Definition: qnamespace.h:366
SubWindowOption
This enum describes options that customize the behavior of QMdiSubWindow.
Definition: qmdisubwindow.h:66
int keyboardSingleStep() const
QWidget * systemMenuLabel() const
QPointer< QSizeGrip > sizeGrip
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
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
QSize minimumSizeHint() const
Reimplemented Function
The QMdiSubWindow class provides a subwindow class for QMdiArea.
Definition: qmdisubwindow.h:60
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 QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
bool setAlignment(QWidget *w, Qt::Alignment alignment)
Sets the alignment for widget w to alignment and returns true if w is found in this layout (not inclu...
Definition: qlayout.cpp:332
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
static void enterWhatsThisMode()
This function switches the user interface into "What&#39;s This?" mode.
Definition: qwhatsthis.cpp:633
bool hasVisibleControls() const
QObject * child() const
Returns the child object that was added or removed.
Definition: qcoreevent.h:358
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
#define text
Definition: qobjectdefs.h:80
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
static int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag, int delta, int maxDelta, int minDelta)
int keyboardPageStep() const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int area(const QSize &s)
Definition: qicon.cpp:155
QStyle::SubControl hoveredSubControl
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
friend class const_iterator
Definition: qmap.h:369
QSize sizeHint() const
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
OperationInfoMap operationMap
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition: qevent.h:597