Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qmdisubwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
112#include "qmdisubwindow_p.h"
113
114#include <QApplication>
115#include <QStylePainter>
116#include <QVBoxLayout>
117#include <QMouseEvent>
118#if QT_CONFIG(whatsthis)
119#include <QWhatsThis>
120#endif
121#if QT_CONFIG(tooltip)
122#include <QToolTip>
123#endif
124#if QT_CONFIG(mainwindow)
125#include <QMainWindow>
126#endif
127#include <QScrollBar>
128#include <QDebug>
129#include <QMdiArea>
130#include <QScopedValueRollback>
131#if QT_CONFIG(action)
132# include <qaction.h>
133#endif
134#if QT_CONFIG(menu)
135#include <QMenu>
136#endif
137#include <QProxyStyle>
138
140
141using namespace Qt::StringLiterals;
142
143using namespace QMdi;
144
157static const int NumSubControls = sizeof(SubControls) / sizeof(SubControls[0]);
158
159static const Qt::WindowFlags CustomizeWindowFlags =
167
168
169static const int BoundaryMargin = 5;
170
171static inline bool isMacStyle(QStyle *style)
172{
173 auto proxyStyle = qobject_cast<QProxyStyle *>(style);
174 auto styleToCheck = proxyStyle ? proxyStyle->baseStyle() : style;
175 return styleToCheck->inherits("QMacStyle");
176}
177
178static inline int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag,
179 int delta, int maxDelta, int minDelta)
180{
181 if (cflags & moveFlag) {
182 if (delta > 0)
183 return (cflags & resizeFlag) ? qMin(delta, maxDelta) : delta;
184 return (cflags & resizeFlag) ? qMax(delta, minDelta) : delta;
185 }
186 return 0;
187}
188
189static inline int getResizeDeltaComponent(uint cflags, uint resizeFlag,
190 uint resizeReverseFlag, int delta)
191{
192 if (cflags & resizeFlag) {
193 if (cflags & resizeReverseFlag)
194 return -delta;
195 return delta;
196 }
197 return 0;
198}
199
200static inline bool isChildOfQMdiSubWindow(const QWidget *child)
201{
203 QWidget *parent = child->parentWidget();
204 while (parent) {
205 if (qobject_cast<QMdiSubWindow *>(parent))
206 return true;
207 parent = parent->parentWidget();
208 }
209 return false;
210}
211
213{
215 if (QMdiArea *mdiArea = child->mdiArea()) {
216 if (mdiArea->viewMode() == QMdiArea::TabbedView)
217 return true;
218 }
219 return false;
220}
221
222template<typename T>
223static inline ControlElement<T> *ptr(QWidget *widget)
224{
225 if (widget && widget->qt_metacast("ControlElement")
226 && strcmp(widget->metaObject()->className(), T::staticMetaObject.className()) == 0) {
227 return static_cast<ControlElement<T> *>(widget);
228 }
229 return nullptr;
230}
231
233{
234 Q_Q(const QMdiSubWindow);
235 // QTBUG-92240: When DontMaximizeSubWindowOnActivation is set and
236 // there is another subwindow maximized, use its original title.
237 if (auto *mdiArea = q->mdiArea()) {
238 const auto &subWindows = mdiArea->subWindowList();
239 for (auto *subWindow : subWindows) {
240 if (subWindow != q && subWindow->isMaximized()) {
241 auto *subWindowD = static_cast<QMdiSubWindowPrivate *>(qt_widget_private(subWindow));
242 if (!subWindowD->originalTitle.isNull())
243 return subWindowD->originalTitle;
244 }
245 }
246 }
247 return q->window()->windowTitle();
248}
249
259
261{
262 Q_Q(QMdiSubWindow);
263 QString childTitle = q->windowTitle();
264 if (childTitle.isEmpty())
265 return;
266 QString original = originalWindowTitle();
267 if (!original.isEmpty()) {
268 if (!original.contains(QMdiSubWindow::tr("- [%1]").arg(childTitle))) {
269 auto title = QMdiSubWindow::tr("%1 - [%2]").arg(original, childTitle);
271 q->window()->setWindowTitle(title);
273 }
274
275 } else {
277 q->window()->setWindowTitle(childTitle);
279 }
280}
281
282static inline bool isHoverControl(QStyle::SubControl control)
283{
284 return control != QStyle::SC_None && control != QStyle::SC_TitleBarLabel;
285}
286
287#if QT_CONFIG(tooltip)
288static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOptionComplex &opt,
289 QStyle::ComplexControl complexControl, QStyle::SubControl subControl)
290{
291 Q_ASSERT(helpEvent);
292 Q_ASSERT(helpEvent->type() == QEvent::ToolTip);
294
296 return;
297
298 // Convert CC_MdiControls to CC_TitleBar. Sub controls of different complex
299 // controls cannot be in the same switch as they might have the same value.
300 if (complexControl == QStyle::CC_MdiControls) {
301 if (subControl == QStyle::SC_MdiMinButton)
302 subControl = QStyle::SC_TitleBarMinButton;
303 else if (subControl == QStyle::SC_MdiCloseButton)
305 else if (subControl == QStyle::SC_MdiNormalButton)
307 else
308 subControl = QStyle::SC_None;
309 }
310
311 // Don't change the tooltip for the base widget itself.
312 if (subControl == QStyle::SC_None)
313 return;
314
315 QString toolTip;
316
317 switch (subControl) {
319 toolTip = QMdiSubWindow::tr("Minimize");
320 break;
322 toolTip = QMdiSubWindow::tr("Maximize");
323 break;
325 toolTip = QMdiSubWindow::tr("Unshade");
326 break;
328 toolTip = QMdiSubWindow::tr("Shade");
329 break;
331 if (widget->isMaximized() || !qobject_cast<QMdiSubWindow *>(widget))
332 toolTip = QMdiSubWindow::tr("Restore Down");
333 else
334 toolTip = QMdiSubWindow::tr("Restore");
335 break;
337 toolTip = QMdiSubWindow::tr("Close");
338 break;
340 toolTip = QMdiSubWindow::tr("Help");
341 break;
343 toolTip = QMdiSubWindow::tr("Menu");
344 break;
345 default:
346 break;
347 }
348
349 const QRect rect = widget->style()->subControlRect(complexControl, &opt, subControl, widget);
350 QToolTip::showText(helpEvent->globalPos(), toolTip, widget, rect);
351}
352#endif // QT_CONFIG(tooltip)
353
354namespace QMdi {
355/*
356 \class ControlLabel
357 \internal
358*/
359class ControlLabel : public QWidget
360{
362public:
363 ControlLabel(QMdiSubWindow *subWindow, QWidget *parent = nullptr);
364
365 QSize sizeHint() const override;
366
367signals:
370
371protected:
372 bool event(QEvent *event) override;
373 void paintEvent(QPaintEvent *paintEvent) override;
374 void mousePressEvent(QMouseEvent *mouseEvent) override;
375 void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override;
376 void mouseReleaseEvent(QMouseEvent *mouseEvent) override;
377
378private:
380 bool isPressed;
381 void updateWindowIcon();
382};
383} // namespace QMdi
384
386 : QWidget(parent), isPressed(false)
387{
388 Q_UNUSED(subWindow);
390 updateWindowIcon();
391 setFixedSize(label.deviceIndependentSize().toSize());
392}
393
394/*
395 \internal
396*/
398{
399 return label.deviceIndependentSize().toSize();
400}
401
402/*
403 \internal
404*/
406{
407 if (event->type() == QEvent::WindowIconChange)
408 updateWindowIcon();
409 else if (event->type() == QEvent::StyleChange) {
410 updateWindowIcon();
411 setFixedSize(label.size());
412 }
413#if QT_CONFIG(tooltip)
414 else if (event->type() == QEvent::ToolTip) {
415 QStyleOptionTitleBar options;
416 options.initFrom(this);
417 showToolTip(static_cast<QHelpEvent *>(event), this, options,
419 }
420#endif
421 return QWidget::event(event);
422}
423
424/*
425 \internal
426*/
428{
429 QPainter painter(this);
430 painter.drawPixmap(0, 0, label);
431}
432
433/*
434 \internal
435*/
437{
438 if (mouseEvent->button() != Qt::LeftButton) {
439 mouseEvent->ignore();
440 return;
441 }
442 isPressed = true;
443}
444
445/*
446 \internal
447*/
449{
450 if (mouseEvent->button() != Qt::LeftButton) {
451 mouseEvent->ignore();
452 return;
453 }
454 isPressed = false;
456}
457
458/*
459 \internal
460*/
462{
463 if (mouseEvent->button() != Qt::LeftButton) {
464 mouseEvent->ignore();
465 return;
466 }
467 if (isPressed) {
468 isPressed = false;
470 }
471}
472
473/*
474 \internal
475*/
476void ControlLabel::updateWindowIcon()
477{
478 QIcon menuIcon = windowIcon();
479 if (menuIcon.isNull())
482 label = menuIcon.pixmap(iconSize);
483 update();
484}
485
486namespace QMdi {
487/*
488 \class ControllerWidget
489 \internal
490*/
492{
494public:
495 ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent = nullptr);
496 QSize sizeHint() const override;
498 inline bool hasVisibleControls() const
499 {
500 return (visibleControls & QStyle::SC_MdiMinButton)
501 || (visibleControls & QStyle::SC_MdiNormalButton)
502 || (visibleControls & QStyle::SC_MdiCloseButton);
503 }
504
505signals:
508 void _q_close();
509
510protected:
511 void paintEvent(QPaintEvent *event) override;
512 void mousePressEvent(QMouseEvent *event) override;
513 void mouseReleaseEvent(QMouseEvent *event) override;
514 void mouseMoveEvent(QMouseEvent *event) override;
515 void leaveEvent(QEvent *event) override;
516 bool event(QEvent *event) override;
517
518private:
519 QStyle::SubControl activeControl;
520 QStyle::SubControl hoverControl;
521 QStyle::SubControls visibleControls;
522 void initStyleOption(QStyleOptionComplex *option) const;
523 QMdiArea *mdiArea;
524 inline QStyle::SubControl getSubControl(const QPoint &pos) const
525 {
527 initStyleOption(&opt);
529 }
530};
531} // namespace QMdi
532
533/*
534 \internal
535*/
537 : QWidget(parent),
538 activeControl(QStyle::SC_None),
539 hoverControl(QStyle::SC_None),
540 visibleControls(QStyle::SC_None),
541 mdiArea(nullptr)
542{
543 if (subWindow->parentWidget())
544 mdiArea = qobject_cast<QMdiArea *>(subWindow->parentWidget()->parentWidget());
547 setMouseTracking(true);
548}
549
550/*
551 \internal
552*/
554{
557 initStyleOption(&opt);
558 const int buttonSize = style()->pixelMetric(QStyle::PM_TitleBarButtonSize, &opt, mdiArea);
559 QSize size(3 * buttonSize, buttonSize);
561}
562
564{
566
567 // Map action from QMdiSubWindowPrivate::WindowStateAction to QStyle::SubControl.
569 subControl = QStyle::SC_MdiNormalButton;
570 else if (action == QMdiSubWindowPrivate::CloseAction)
571 subControl = QStyle::SC_MdiCloseButton;
572 else if (action == QMdiSubWindowPrivate::MinimizeAction)
573 subControl = QStyle::SC_MdiMinButton;
574
575 if (subControl == QStyle::SC_None)
576 return;
577
578 visibleControls.setFlag(subControl, visible && !(visibleControls & subControl));
579}
580
581/*
582 \internal
583*/
585{
587 initStyleOption(&opt);
588 if (activeControl == hoverControl) {
589 opt.activeSubControls = activeControl;
591 } else if (hoverControl != QStyle::SC_None && (activeControl == QStyle::SC_None)) {
592 opt.activeSubControls = hoverControl;
594 }
595 QPainter painter(this);
597}
598
599/*
600 \internal
601*/
603{
604 if (event->button() != Qt::LeftButton) {
605 event->ignore();
606 return;
607 }
608 activeControl = getSubControl(event->position().toPoint());
609 update();
610}
611
612/*
613 \internal
614*/
616{
617 if (event->button() != Qt::LeftButton) {
618 event->ignore();
619 return;
620 }
621
622 QStyle::SubControl under_mouse = getSubControl(event->position().toPoint());
623 if (under_mouse == activeControl) {
624 switch (activeControl) {
626 emit _q_close();
627 break;
630 break;
633 break;
634 default:
635 break;
636 }
637 }
638
639 activeControl = QStyle::SC_None;
640 update();
641}
642
643/*
644 \internal
645*/
647{
648 QStyle::SubControl under_mouse = getSubControl(event->position().toPoint());
649 //test if hover state changes
650 if (hoverControl != under_mouse) {
651 hoverControl = under_mouse;
652 update();
653 }
654}
655
656/*
657 \internal
658*/
660{
661 hoverControl = QStyle::SC_None;
662 update();
663}
664
665/*
666 \internal
667*/
669{
670#if QT_CONFIG(tooltip)
671 if (event->type() == QEvent::ToolTip) {
673 initStyleOption(&opt);
674 QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
675 showToolTip(helpEvent, this, opt, QStyle::CC_MdiControls, getSubControl(helpEvent->pos()));
676 }
677#endif // QT_CONFIG(tooltip)
678 return QWidget::event(event);
679}
680
681/*
682 \internal
683*/
684void ControllerWidget::initStyleOption(QStyleOptionComplex *option) const
685{
686 option->initFrom(this);
687 option->subControls = visibleControls;
688 option->activeSubControls = QStyle::SC_None;
689}
690
691/*
692 \internal
693*/
695 : QObject(mdiChild),
696 previousLeft(nullptr),
697 previousRight(nullptr),
698#if QT_CONFIG(menubar)
699 m_menuBar(nullptr),
700#endif
701 mdiChild(mdiChild)
702{
703 Q_ASSERT(mdiChild);
704
705 m_controllerWidget = new ControlElement<ControllerWidget>(mdiChild);
706 connect(m_controllerWidget, SIGNAL(_q_close()), mdiChild, SLOT(close()));
707 connect(m_controllerWidget, SIGNAL(_q_restore()), mdiChild, SLOT(showNormal()));
708 connect(m_controllerWidget, SIGNAL(_q_minimize()), mdiChild, SLOT(showMinimized()));
709
710 m_menuLabel = new ControlElement<ControlLabel>(mdiChild);
711 m_menuLabel->setWindowIcon(mdiChild->windowIcon());
712#if QT_CONFIG(menu)
713 connect(m_menuLabel, SIGNAL(_q_clicked()), mdiChild, SLOT(showSystemMenu()));
714#endif
715 connect(m_menuLabel, SIGNAL(_q_doubleClicked()), mdiChild, SLOT(close()));
716}
717
719{
720#if QT_CONFIG(menubar)
721 removeButtonsFromMenuBar();
722#endif
723 delete m_menuLabel;
724 m_menuLabel = nullptr;
725 delete m_controllerWidget;
726 m_controllerWidget = nullptr;
727}
728
729#if QT_CONFIG(menubar)
730/*
731 \internal
732*/
733QMenuBar *QMdiSubWindowPrivate::menuBar() const
734{
735#if !QT_CONFIG(mainwindow)
736 return nullptr;
737#else
738 Q_Q(const QMdiSubWindow);
739 if (!q->isMaximized() || drawTitleBarWhenMaximized() || isChildOfTabbedQMdiArea(q))
740 return nullptr;
741
742 if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window()))
743 return mainWindow->menuBar();
744
745 return nullptr;
746#endif
747}
748
749/*
750 \internal
751*/
752void ControlContainer::showButtonsInMenuBar(QMenuBar *menuBar)
753{
754 if (!menuBar || !mdiChild || mdiChild->windowFlags() & Qt::FramelessWindowHint)
755 return;
756 m_menuBar = menuBar;
757
758 if (m_menuLabel && mdiChild->windowFlags() & Qt::WindowSystemMenuHint) {
760 if (currentLeft)
761 currentLeft->hide();
762 if (currentLeft != m_menuLabel) {
764 previousLeft = currentLeft;
765 }
766 m_menuLabel->show();
767 }
768 ControllerWidget *controllerWidget = qobject_cast<ControllerWidget *>(m_controllerWidget);
769 if (controllerWidget && controllerWidget->hasVisibleControls()) {
771 if (currentRight)
772 currentRight->hide();
773 if (currentRight != m_controllerWidget) {
774 menuBar->setCornerWidget(m_controllerWidget, Qt::TopRightCorner);
775 previousRight = currentRight;
776 }
777 m_controllerWidget->show();
778 }
779 mdiChild->d_func()->setNewWindowTitle();
780}
781
782/*
783 \internal
784*/
785void ControlContainer::removeButtonsFromMenuBar(QMenuBar *menuBar)
786{
787 if (menuBar && menuBar != m_menuBar) {
788 // m_menubar was deleted while sub-window was maximized
789 previousRight = nullptr;
790 previousLeft = nullptr;
791 m_menuBar = menuBar;
792 }
793
794 if (!m_menuBar || !mdiChild || qt_widget_private(mdiChild->window())->data.in_destructor)
795 return;
796
797 QMdiSubWindow *child = nullptr;
798 if (m_controllerWidget) {
799 QWidget *currentRight = m_menuBar->cornerWidget(Qt::TopRightCorner);
800 if (currentRight == m_controllerWidget) {
801 if (ControlElement<ControllerWidget> *ce = ptr<ControllerWidget>(previousRight)) {
802 if (!ce->mdiChild || !ce->mdiChild->isMaximized())
803 previousRight = nullptr;
804 else
805 child = ce->mdiChild;
806 }
807 m_menuBar->setCornerWidget(previousRight, Qt::TopRightCorner);
808 if (previousRight) {
809 previousRight->show();
810 previousRight = nullptr;
811 }
812 }
813 m_controllerWidget->hide();
814 m_controllerWidget->setParent(nullptr);
815 }
816 if (m_menuLabel) {
817 QWidget *currentLeft = m_menuBar->cornerWidget(Qt::TopLeftCorner);
818 if (currentLeft == m_menuLabel) {
819 if (ControlElement<ControlLabel> *ce = ptr<ControlLabel>(previousLeft)) {
820 if (!ce->mdiChild || !ce->mdiChild->isMaximized())
821 previousLeft = nullptr;
822 else if (!child)
823 child = mdiChild;
824 }
825 m_menuBar->setCornerWidget(previousLeft, Qt::TopLeftCorner);
826 if (previousLeft) {
827 previousLeft->show();
828 previousLeft = nullptr;
829 }
830 }
831 m_menuLabel->hide();
832 m_menuLabel->setParent(nullptr);
833 }
834 m_menuBar->update();
835 if (child)
836 child->d_func()->setNewWindowTitle();
837 else if (mdiChild)
838 mdiChild->window()->setWindowTitle(mdiChild->d_func()->originalWindowTitle());
839}
840
841#endif // QT_CONFIG(menubar)
842
844{
845 if (m_menuLabel)
846 m_menuLabel->setWindowIcon(windowIcon);
847}
848
853 : baseWidget(nullptr),
854 restoreFocusWidget(nullptr),
855 controlContainer(nullptr),
856#if QT_CONFIG(sizegrip)
857 sizeGrip(nullptr),
858#endif
859#if QT_CONFIG(rubberband)
860 rubberBand(nullptr),
861#endif
862 userMinimumSize(0,0),
863 resizeEnabled(true),
864 moveEnabled(true),
865 isInInteractiveMode(false),
866#if QT_CONFIG(rubberband)
867 isInRubberBandMode(false),
868#endif
869 isShadeMode(false),
870 ignoreWindowTitleChange(false),
871 ignoreNextActivationEvent(false),
872 activationEnabled(true),
873 isShadeRequestFromMinimizeMode(false),
874 isMaximizeMode(false),
875 isWidgetHiddenByUs(false),
877 isExplicitlyDeactivated(false),
878 keyboardSingleStep(5),
879 keyboardPageStep(20),
880 resizeTimerId(-1),
881 currentOperation(None),
882 hoveredSubControl(QStyle::SC_None),
883 activeSubControl(QStyle::SC_None),
884 focusInReason(Qt::ActiveWindowFocusReason)
885{
887}
888
893{
894#if QT_CONFIG(action)
895 Q_Q(QMdiSubWindow);
896 if (QAction *senderAction = qobject_cast<QAction *>(q->sender())) {
897 if (senderAction->isChecked()) {
898 q->setWindowFlags(q->windowFlags() | Qt::WindowStaysOnTopHint);
899 q->raise();
900 } else {
901 q->setWindowFlags(q->windowFlags() & ~Qt::WindowStaysOnTopHint);
902 q->lower();
903 }
904 }
905#endif // QT_CONFIG(action)
906}
907
912{
913#ifndef QT_NO_ACTION
914 Q_Q(QMdiSubWindow);
915 QAction *action = qobject_cast<QAction *>(q->sender());
916 if (!action)
917 return;
918
919 QPoint pressPos;
920 if (actions[MoveAction] && actions[MoveAction] == action) {
922 pressPos = QPoint(q->width() / 2, titleBarHeight() - 1);
923 } else if (actions[ResizeAction] && actions[ResizeAction] == action) {
925 int offset = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q) / 2;
926 int x = q->isLeftToRight() ? q->width() - offset : offset;
927 pressPos = QPoint(x, q->height() - offset);
928 } else {
929 return;
930 }
931
932 updateCursor();
933#ifndef QT_NO_CURSOR
934 q->cursor().setPos(q->mapToGlobal(pressPos));
935#endif
936 mousePressPosition = q->mapToParent(pressPos);
937 oldGeometry = q->geometry();
938 isInInteractiveMode = true;
939 q->setFocus();
940#if QT_CONFIG(rubberband)
941 if ((q->testOption(QMdiSubWindow::RubberBandResize)
943 || (q->testOption(QMdiSubWindow::RubberBandMove) && currentOperation == Move)) {
944 enterRubberBandMode();
945 } else
946#endif // QT_CONFIG(rubberband)
947 {
948 q->grabMouse();
949 }
950#endif // QT_NO_ACTION
951}
952
957{
958 Q_UNUSED(old);
959 Q_Q(QMdiSubWindow);
960 if (now && (now == q || q->isAncestorOf(now))) {
961 if (now == q && !isInInteractiveMode)
963 setActive(true);
964 }
965}
966
971{
972 Q_Q(QMdiSubWindow);
973#if QT_CONFIG(rubberband)
974 if (isInRubberBandMode)
975 leaveRubberBandMode();
976 else
977#endif
978 q->releaseMouse();
979 isInInteractiveMode = false;
982 updateCursor();
985}
986
991{
992 if (!baseWidget)
993 return;
994
995 Q_Q(QMdiSubWindow);
997 if (layout)
999 if (baseWidget->windowTitle() == q->windowTitle()) {
1001 q->setWindowTitle(QString());
1003 q->setWindowModified(false);
1004 }
1006 // QTBUG-47993: parent widget can be reset before this call
1007 if (baseWidget->parentWidget() == q)
1008 baseWidget->setParent(nullptr);
1009 baseWidget = nullptr;
1010 isWidgetHiddenByUs = false;
1011}
1012
1031
1032#if QT_CONFIG(menu)
1033
1037void QMdiSubWindowPrivate::createSystemMenu()
1038{
1039 Q_Q(QMdiSubWindow);
1040 Q_ASSERT_X(q, "QMdiSubWindowPrivate::createSystemMenu",
1041 "You can NOT call this function before QMdiSubWindow's ctor");
1042 systemMenu = new QMenu(q);
1044 const QStyle *style = q->style();
1045 addToSystemMenu(RestoreAction, QMdiSubWindow::tr("&Restore"), SLOT(showNormal()));
1048 addToSystemMenu(MoveAction, QMdiSubWindow::tr("&Move"), SLOT(_q_enterInteractiveMode()));
1049 addToSystemMenu(ResizeAction, QMdiSubWindow::tr("&Size"), SLOT(_q_enterInteractiveMode()));
1050 addToSystemMenu(MinimizeAction, QMdiSubWindow::tr("Mi&nimize"), SLOT(showMinimized()));
1052 addToSystemMenu(MaximizeAction, QMdiSubWindow::tr("Ma&ximize"), SLOT(showMaximized()));
1054 addToSystemMenu(StayOnTopAction, QMdiSubWindow::tr("Stay on &Top"), SLOT(_q_updateStaysOnTopHint()));
1057 addToSystemMenu(CloseAction, QMdiSubWindow::tr("&Close"), SLOT(close()));
1059#if !defined(QT_NO_SHORTCUT)
1060 actions[CloseAction]->setShortcuts(QKeySequence::Close);
1061#endif
1062 updateActions();
1063}
1064#endif
1065
1070{
1071#ifndef QT_NO_CURSOR
1072 Q_Q(QMdiSubWindow);
1073 if (isMacStyle(q->style()))
1074 return;
1075
1076 if (currentOperation == None) {
1077 q->unsetCursor();
1078 return;
1079 }
1080
1081 if (currentOperation == Move || operationMap.find(currentOperation).value().hover) {
1082 q->setCursor(operationMap.find(currentOperation).value().cursorShape);
1083 return;
1084 }
1085#endif
1086}
1087
1092{
1093 // No update necessary
1094 if (!parent)
1095 return;
1096
1097 for (OperationInfoMap::iterator it = operationMap.begin(), end = operationMap.end(); it != end; ++it)
1098 it.value().region = getRegion(it.key());
1099}
1100
1105{
1106 Q_Q(QMdiSubWindow);
1107 if (!parent)
1108 return;
1109
1110 internalMinimumSize = (!q->isMinimized() && !q->minimumSize().isNull())
1111 ? q->minimumSize() : q->minimumSizeHint();
1112 int margin, minWidth;
1113 sizeParameters(&margin, &minWidth);
1114 q->setContentsMargins(margin, titleBarHeight(), margin, margin);
1115 if (q->isMaximized() || (q->isMinimized() && !q->isShaded())) {
1116 moveEnabled = false;
1117 resizeEnabled = false;
1118 } else {
1119 moveEnabled = true;
1120 if ((q->windowFlags() & Qt::MSWindowsFixedSizeDialogHint) || q->isShaded())
1121 resizeEnabled = false;
1122 else
1123 resizeEnabled = true;
1124 }
1126}
1127
1132{
1133 Q_Q(QMdiSubWindow);
1134 if (!q->mask().isEmpty())
1135 q->clearMask();
1136
1137 if (!parent)
1138 return;
1139
1140 if ((q->isMaximized() && !drawTitleBarWhenMaximized())
1141 || q->windowFlags() & Qt::FramelessWindowHint)
1142 return;
1143
1144 if (resizeTimerId == -1)
1146 cachedStyleOptions.rect = q->rect();
1147 QStyleHintReturnMask frameMask;
1148 q->style()->styleHint(QStyle::SH_WindowFrame_Mask, &cachedStyleOptions, q, &frameMask);
1149 if (!frameMask.region.isEmpty())
1150 q->setMask(frameMask.region);
1151}
1152
1157{
1158 Q_Q(QMdiSubWindow);
1161
1162 uint cflags = operationMap.find(currentOperation).value().changeFlags;
1163 int posX = pos.x();
1164 int posY = pos.y();
1165
1166 const bool restrictHorizontal = !q->testOption(QMdiSubWindow::AllowOutsideAreaHorizontally);
1167 const bool restrictVertical = !q->testOption(QMdiSubWindow::AllowOutsideAreaVertically);
1168
1169 if (restrictHorizontal || restrictVertical) {
1170 QRect parentRect = q->parentWidget()->rect();
1171 if (restrictVertical && (cflags & VResizeReverse || currentOperation == Move)) {
1172 posY = qMin(qMax(mousePressPosition.y() - oldGeometry.y(), posY),
1173 parentRect.height() - BoundaryMargin);
1174 }
1175 if (currentOperation == Move) {
1176 if (restrictHorizontal)
1177 posX = qMin(qMax(BoundaryMargin, posX), parentRect.width() - BoundaryMargin);
1178 if (restrictVertical)
1179 posY = qMin(posY, parentRect.height() - BoundaryMargin);
1180 } else {
1181 if (restrictHorizontal) {
1182 if (cflags & HResizeReverse)
1183 posX = qMax(mousePressPosition.x() - oldGeometry.x(), posX);
1184 else
1185 posX = qMin(parentRect.width() - (oldGeometry.x() + oldGeometry.width()
1186 - mousePressPosition.x()), posX);
1187 }
1188 if (restrictVertical && !(cflags & VResizeReverse)) {
1189 posY = qMin(parentRect.height() - (oldGeometry.y() + oldGeometry.height()
1190 - mousePressPosition.y()), posY);
1191 }
1192 }
1193 }
1194
1195 QRect geometry;
1196 if (cflags & (HMove | VMove)) {
1197 int dx = getMoveDeltaComponent(cflags, HMove, HResize, posX - mousePressPosition.x(),
1199 oldGeometry.width() - q->maximumWidth());
1200 int dy = getMoveDeltaComponent(cflags, VMove, VResize, posY - mousePressPosition.y(),
1202 oldGeometry.height() - q->maximumHeight());
1203 geometry.setTopLeft(oldGeometry.topLeft() + QPoint(dx, dy));
1204 } else {
1205 geometry.setTopLeft(q->geometry().topLeft());
1206 }
1207
1208 if (cflags & (HResize | VResize)) {
1210 posX - mousePressPosition.x());
1212 posY - mousePressPosition.y());
1213 geometry.setSize(oldGeometry.size() + QSize(dx, dy));
1214 } else {
1215 geometry.setSize(q->geometry().size());
1216 }
1217
1218 setNewGeometry(&geometry);
1219}
1220
1225{
1226 Q_Q(QMdiSubWindow);
1228
1231 q->showShaded();
1233
1234 moveEnabled = false;
1235#ifndef QT_NO_ACTION
1237#endif
1238
1239 Q_ASSERT(q->windowState() & Qt::WindowMinimized);
1240 Q_ASSERT(!(q->windowState() & Qt::WindowMaximized));
1241 // This should be a valid assert, but people can actually re-implement
1242 // setVisible and do crazy stuff, so we're not guaranteed that
1243 // the widget is hidden after calling hide().
1244 // Q_ASSERT(baseWidget ? baseWidget->isHidden() : true);
1245
1246 setActive(true);
1247}
1248
1253{
1254 Q_Q(QMdiSubWindow);
1256
1257 isShadeMode = false;
1258 isMaximizeMode = false;
1259
1261#if QT_CONFIG(menubar)
1262 removeButtonsFromMenuBar();
1263#endif
1264
1265 // Hide the window before we change the geometry to avoid multiple resize
1266 // events and wrong window state.
1267 const bool wasVisible = q->isVisible();
1268 if (wasVisible)
1269 q->setVisible(false);
1270
1271 // Restore minimum size if set by user.
1272 if (!userMinimumSize.isNull()) {
1273 q->setMinimumSize(userMinimumSize);
1274 userMinimumSize = QSize(0, 0);
1275 }
1276
1277 // Show the internal widget if it was hidden by us,
1279 baseWidget->show();
1280 isWidgetHiddenByUs = false;
1281 }
1282
1284 QRect newGeometry = oldGeometry;
1286 q->setGeometry(newGeometry);
1287
1288 if (wasVisible)
1289 q->setVisible(true);
1290
1291 // Invalidate the restore size.
1294
1295#if QT_CONFIG(sizegrip)
1296 setSizeGripVisible(true);
1297#endif
1298
1299#ifndef QT_NO_ACTION
1300 setEnabled(MoveAction, true);
1303 setEnabled(RestoreAction, false);
1305#endif // QT_NO_ACTION
1306
1307 Q_ASSERT(!(q_func()->windowState() & Qt::WindowMinimized));
1308 // This sub-window can be maximized when shown above if not the
1309 // QMdiArea::DontMaximizeSubWindowOnActionvation is set. Make sure
1310 // the Qt::WindowMaximized flag is set accordingly.
1311 Q_ASSERT((isMaximizeMode && q_func()->windowState() & Qt::WindowMaximized)
1312 || (!isMaximizeMode && !(q_func()->windowState() & Qt::WindowMaximized)));
1314
1315 setActive(true);
1316 restoreFocus();
1317 updateMask();
1318}
1319
1321{
1323 if (!restoreFocusWidget && q_func()->isAncestorOf(focus))
1325 }
1326}
1327
1332{
1333 Q_Q(QMdiSubWindow);
1335
1337 isShadeMode = false;
1338 isMaximizeMode = true;
1339
1341
1342#if QT_CONFIG(sizegrip)
1343 setSizeGripVisible(false);
1344#endif
1345
1346 // Store old geometry and set restore size if not already set.
1347 if (!restoreSize.isValid()) {
1348 oldGeometry = q->geometry();
1351 }
1352
1353 // Hide the window before we change the geometry to avoid multiple resize
1354 // events and wrong window state.
1355 const bool wasVisible = q->isVisible();
1356 if (wasVisible)
1357 q->setVisible(false);
1358
1359 // Show the internal widget if it was hidden by us.
1361 baseWidget->show();
1362 isWidgetHiddenByUs = false;
1363 }
1364
1366
1367 if (wasVisible) {
1368#if QT_CONFIG(menubar)
1369 if (QMenuBar *mBar = menuBar())
1370 showButtonsInMenuBar(mBar);
1371 else
1372#endif
1373 if (!controlContainer)
1375 }
1376
1377 QWidget *parent = q->parentWidget();
1378 QRect availableRect = parent->contentsRect();
1379
1380 // Adjust geometry if the sub-window is inside a scroll area.
1381 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent->parentWidget());
1382 if (scrollArea && scrollArea->viewport() == parent) {
1383 QScrollBar *hbar = scrollArea->horizontalScrollBar();
1384 QScrollBar *vbar = scrollArea->verticalScrollBar();
1385 const int xOffset = hbar ? hbar->value() : 0;
1386 const int yOffset = vbar ? vbar->value() : 0;
1387 availableRect.adjust(-xOffset, -yOffset, -xOffset, -yOffset);
1388 oldGeometry.adjust(xOffset, yOffset, xOffset, yOffset);
1389 }
1390
1391 setNewGeometry(&availableRect);
1392 // QWidget::setGeometry will reset Qt::WindowMaximized so we have to update it here.
1394
1395 if (wasVisible)
1396 q->setVisible(true);
1397
1398 resizeEnabled = false;
1399 moveEnabled = false;
1400
1401#ifndef QT_NO_ACTION
1403 setEnabled(MaximizeAction, false);
1407#endif // QT_NO_ACTION
1408
1409 Q_ASSERT(q->windowState() & Qt::WindowMaximized);
1410 Q_ASSERT(!(q->windowState() & Qt::WindowMinimized));
1411
1412 restoreFocus();
1413 updateMask();
1414}
1415
1419void QMdiSubWindowPrivate::setActive(bool activate, bool changeFocus)
1420{
1421 Q_Q(QMdiSubWindow);
1422 if (!parent || !activationEnabled)
1423 return;
1424
1425 if (activate && !isActive && q->isEnabled()) {
1426 isActive = true;
1428 Qt::WindowStates oldWindowState = q->windowState();
1430 emit q->aboutToActivate();
1431#if QT_CONFIG(menubar)
1432 if (QMenuBar *mBar = menuBar())
1433 showButtonsInMenuBar(mBar);
1434#endif
1436 emit q->windowStateChanged(oldWindowState, q->windowState());
1437 } else if (!activate && isActive) {
1438 isActive = false;
1439 Qt::WindowStates oldWindowState = q->windowState();
1440 q->overrideWindowState(q->windowState() & ~Qt::WindowActive);
1441 if (changeFocus) {
1443 QWidget *focusWidget = QApplication::focusWidget();
1444 if (focusWidget && (focusWidget == q || q->isAncestorOf(focusWidget)))
1445 focusWidget->clearFocus();
1446 }
1447 if (baseWidget)
1450 emit q->windowStateChanged(oldWindowState, q->windowState());
1451 }
1452
1453 if (activate && isActive && q->isEnabled() && !q->hasFocus()
1454 && !q->isAncestorOf(QApplication::focusWidget())) {
1455 if (changeFocus)
1458 }
1459
1460 int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q);
1461 int titleBarHeight = this->titleBarHeight();
1462 QRegion windowDecoration = QRegion(0, 0, q->width(), q->height());
1463 windowDecoration -= QRegion(frameWidth, titleBarHeight, q->width() - 2 * frameWidth,
1464 q->height() - titleBarHeight - frameWidth);
1465
1466 // Make sure we don't use cached style options if we get
1467 // resize events right before activation/deactivation.
1468 if (resizeTimerId != -1) {
1469 q->killTimer(resizeTimerId);
1470 resizeTimerId = -1;
1472 }
1473
1474 q->update(windowDecoration);
1475}
1476
1481{
1482 Q_Q(QMdiSubWindow);
1483 switch (activeSubControl) {
1485#if QT_CONFIG(whatsthis)
1487#endif
1488 break;
1490 q->showShaded();
1492 break;
1494 if (q->isShaded())
1496 q->showNormal();
1497 break;
1499 if (isMacStyle(q->style())) {
1500 if (q->isMinimized())
1501 q->showNormal();
1502 else
1503 q->showMinimized();
1504 break;
1505 }
1506
1507 q->showMinimized();
1508 break;
1510 if (q->isShaded())
1512 q->showNormal();
1513 break;
1515 if (isMacStyle(q->style())) {
1516 if (q->isMaximized())
1517 q->showNormal();
1518 else
1519 q->showMaximized();
1520 break;
1521 }
1522
1523 q->showMaximized();
1524 break;
1526 q->close();
1527 break;
1528 default:
1529 break;
1530 }
1531}
1532
1537{
1538 Q_Q(const QMdiSubWindow);
1539 int width = q->width();
1540 int height = q->height();
1541 int titleBarHeight = this->titleBarHeight();
1542 int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q);
1543 int cornerConst = titleBarHeight - frameWidth;
1544 int titleBarConst = 2 * titleBarHeight;
1545
1546 if (operation == Move) {
1548 QRegion move(frameWidth, frameWidth, width - 2 * frameWidth, cornerConst);
1549 // Depending on which window flags are set, activated sub controllers will
1550 // be subtracted from the 'move' region.
1551 for (int i = 0; i < NumSubControls; ++i) {
1553 continue;
1554 move -= QRegion(q->style()->subControlRect(QStyle::CC_TitleBar, &titleBarOptions,
1555 SubControls[i]));
1556 }
1557 return move;
1558 }
1559
1560 QRegion region;
1561 if (isMacStyle(q->style()))
1562 return region;
1563
1564 switch (operation) {
1565 case TopResize:
1566 region = QRegion(titleBarHeight, 0, width - titleBarConst, frameWidth);
1567 break;
1568 case BottomResize:
1569 region = QRegion(titleBarHeight, height - frameWidth, width - titleBarConst, frameWidth);
1570 break;
1571 case LeftResize:
1572 region = QRegion(0, titleBarHeight, frameWidth, height - titleBarConst);
1573 break;
1574 case RightResize:
1575 region = QRegion(width - frameWidth, titleBarHeight, frameWidth, height - titleBarConst);
1576 break;
1577 case TopLeftResize:
1578 region = QRegion(0, 0, titleBarHeight, titleBarHeight)
1579 - QRegion(frameWidth, frameWidth, cornerConst, cornerConst);
1580 break;
1581 case TopRightResize:
1583 - QRegion(width - titleBarHeight, frameWidth, cornerConst, cornerConst);
1584 break;
1585 case BottomLeftResize:
1587 - QRegion(frameWidth, height - titleBarHeight, cornerConst, cornerConst);
1588 break;
1589 case BottomRightResize:
1591 - QRegion(width - titleBarHeight, height - titleBarHeight, cornerConst, cornerConst);
1592 break;
1593 default:
1594 break;
1595 }
1596
1597 return region;
1598}
1599
1604{
1605 OperationInfoMap::const_iterator it;
1607 if (it.value().region.contains(pos))
1608 return it.key();
1609 return None;
1610}
1611
1613
1618{
1619 Q_Q(const QMdiSubWindow);
1626 }
1631 } else {
1632 titleBarOptions.state &= ~QStyle::State_MouseOver;
1634 }
1635
1637 titleBarOptions.titleBarFlags = q->windowFlags();
1638 titleBarOptions.titleBarState = q->windowState();
1641
1642 if (isActive) {
1646 } else {
1647 titleBarOptions.state &= ~QStyle::State_Active;
1649 }
1650
1651 int border = hasBorder(titleBarOptions) ? 4 : 0;
1652 int paintHeight = titleBarHeight(titleBarOptions);
1653 paintHeight -= q->isMinimized() ? 2 * border : border;
1654 titleBarOptions.rect = QRect(border, border, q->width() - 2 * border, paintHeight);
1655
1656 if (!windowTitle.isEmpty()) {
1657 // Set the text here before asking for the width of the title bar label
1658 // in case people uses the actual text to calculate the width.
1661 int width = q->style()->subControlRect(QStyle::CC_TitleBar, &titleBarOptions,
1662 QStyle::SC_TitleBarLabel, q).width();
1663 // Set elided text if we don't have enough space for the entire title.
1665 }
1666 return titleBarOptions;
1667}
1668
1673{
1674 Q_Q(QMdiSubWindow);
1675 Qt::WindowStates windowStates = q->windowState() | state;
1676 switch (state) {
1678 windowStates &= ~Qt::WindowMaximized;
1679 windowStates &= ~Qt::WindowFullScreen;
1680 windowStates &= ~Qt::WindowNoState;
1681 break;
1683 windowStates &= ~Qt::WindowMinimized;
1684 windowStates &= ~Qt::WindowFullScreen;
1685 windowStates &= ~Qt::WindowNoState;
1686 break;
1687 case Qt::WindowNoState:
1688 windowStates &= ~Qt::WindowMinimized;
1689 windowStates &= ~Qt::WindowMaximized;
1690 windowStates &= ~Qt::WindowFullScreen;
1691 break;
1692 default:
1693 break;
1694 }
1695 if (baseWidget) {
1696 if (!(baseWidget->windowState() & Qt::WindowActive) && windowStates & Qt::WindowActive)
1698 else
1699 baseWidget->overrideWindowState(windowStates);
1700 }
1701 q->overrideWindowState(windowStates);
1702}
1703
1708{
1709 Q_Q(const QMdiSubWindow);
1710 if (!parent || q->windowFlags() & Qt::FramelessWindowHint
1711 || (q->isMaximized() && !drawTitleBarWhenMaximized())) {
1712 return 0;
1713 }
1714
1715 int height = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options, q);
1716 if (hasBorder(options))
1717 height += q->isMinimized() ? 8 : 4;
1718 return height;
1719}
1720
1724void QMdiSubWindowPrivate::sizeParameters(int *margin, int *minWidth) const
1725{
1726 Q_Q(const QMdiSubWindow);
1727 Qt::WindowFlags flags = q->windowFlags();
1729 *margin = 0;
1730 *minWidth = 0;
1731 return;
1732 }
1733
1734 if (q->isMaximized() && !drawTitleBarWhenMaximized())
1735 *margin = 0;
1736 else
1737 *margin = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q);
1738
1740 int tempWidth = 0;
1741 for (int i = 0; i < NumSubControls; ++i) {
1743 tempWidth += 30;
1744 continue;
1745 }
1746 QRect rect = q->style()->subControlRect(QStyle::CC_TitleBar, &opt, SubControls[i], q);
1747 if (!rect.isValid())
1748 continue;
1749 tempWidth += rect.width();
1750 }
1751 *minWidth = tempWidth;
1752}
1753
1758{
1759 Q_Q(const QMdiSubWindow);
1760 if (q->window()->testAttribute(Qt::WA_CanHostQMdiSubWindowTitleBar))
1761 return false;
1762
1764 return false;
1765
1766 if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, nullptr, q))
1767 return true;
1768#if !QT_CONFIG(menubar) || !QT_CONFIG(mainwindow)
1770 return true;
1771#else
1772 QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window());
1773 if (!mainWindow || !qobject_cast<QMenuBar *>(mainWindow->menuWidget())
1774 || mainWindow->menuWidget()->isHidden())
1775 return true;
1776
1777 return isChildOfQMdiSubWindow(q);
1778#endif
1779}
1780
1781#if QT_CONFIG(menubar)
1782
1786void QMdiSubWindowPrivate::showButtonsInMenuBar(QMenuBar *menuBar)
1787{
1788 Q_Q(QMdiSubWindow);
1789 Q_ASSERT(q->isMaximized() && !drawTitleBarWhenMaximized());
1790
1792 return;
1793
1794 removeButtonsFromMenuBar();
1795 if (!controlContainer)
1797
1799 controlContainer->showButtonsInMenuBar(menuBar);
1801
1802 QWidget *topLevelWindow = q->window();
1803 topLevelWindow->setWindowModified(q->isWindowModified());
1804 topLevelWindow->installEventFilter(q);
1805
1806 int buttonHeight = 0;
1808 buttonHeight = controlContainer->controllerWidget()->height();
1810 buttonHeight = controlContainer->systemMenuLabel()->height();
1811
1812 // This will rarely happen.
1813 if (menuBar && menuBar->height() < buttonHeight
1814 && topLevelWindow->layout()) {
1815 // Make sure topLevelWindow->contentsRect returns correct geometry.
1816 // topLevelWidget->updateGeoemtry will not do the trick here since it will post the event.
1818 QCoreApplication::sendEvent(topLevelWindow, &event);
1819 }
1820}
1821
1825void QMdiSubWindowPrivate::removeButtonsFromMenuBar()
1826{
1827 Q_Q(QMdiSubWindow);
1828
1830 return;
1831
1832 QMenuBar *currentMenuBar = nullptr;
1833#if QT_CONFIG(mainwindow)
1834 if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window())) {
1835 // NB! We can't use menuBar() here because that one will actually create
1836 // a menubar for us if not set. That's not what we want :-)
1837 currentMenuBar = qobject_cast<QMenuBar *>(mainWindow->menuWidget());
1838 }
1839#endif
1840
1842 controlContainer->removeButtonsFromMenuBar(currentMenuBar);
1844
1845 QWidget *topLevelWindow = q->window();
1846 topLevelWindow->removeEventFilter(q);
1848 topLevelWindow->setWindowModified(false);
1850}
1851
1852#endif // QT_CONFIG(menubar)
1853
1854void QMdiSubWindowPrivate::updateWindowTitle(bool isRequestFromChild)
1855{
1856 Q_Q(QMdiSubWindow);
1857 if (isRequestFromChild && !q->windowTitle().isEmpty() && !lastChildWindowTitle.isEmpty()
1858 && lastChildWindowTitle != q->windowTitle()) {
1859 return;
1860 }
1861
1862 QWidget *titleWidget = nullptr;
1863 if (isRequestFromChild)
1864 titleWidget = baseWidget;
1865 else
1866 titleWidget = q;
1867 if (!titleWidget || titleWidget->windowTitle().isEmpty())
1868 return;
1869
1871 q->setWindowTitle(titleWidget->windowTitle());
1872 if (q->maximizedButtonsWidget())
1875}
1876
1877#if QT_CONFIG(rubberband)
1878void QMdiSubWindowPrivate::enterRubberBandMode()
1879{
1880 Q_Q(QMdiSubWindow);
1881 if (q->isMaximized())
1882 return;
1885 if (!rubberBand) {
1886 rubberBand = new QRubberBand(QRubberBand::Rectangle, q->parentWidget());
1887 // For accessibility to identify this special widget.
1888 rubberBand->setObjectName("qt_rubberband"_L1);
1889 }
1890 QPoint rubberBandPos = q->mapToParent(QPoint(0, 0));
1891 rubberBand->setGeometry(rubberBandPos.x(), rubberBandPos.y(),
1893 rubberBand->show();
1894 isInRubberBandMode = true;
1895 q->grabMouse();
1896}
1897
1898void QMdiSubWindowPrivate::leaveRubberBandMode()
1899{
1900 Q_Q(QMdiSubWindow);
1901 Q_ASSERT(rubberBand);
1902 Q_ASSERT(isInRubberBandMode);
1903 q->releaseMouse();
1904 isInRubberBandMode = false;
1905 q->setGeometry(rubberBand->geometry());
1906 rubberBand->hide();
1908}
1909#endif // QT_CONFIG(rubberband)
1910
1911// Taken from the old QWorkspace (::readColors())
1913{
1914 Q_Q(const QMdiSubWindow);
1915 QPalette newPalette = q->palette();
1916
1918 newPalette.color(QPalette::Active, QPalette::Highlight));
1919 newPalette.setColor(QPalette::Active, QPalette::Base,
1920 newPalette.color(QPalette::Active, QPalette::Highlight));
1921 newPalette.setColor(QPalette::Inactive, QPalette::Highlight,
1922 newPalette.color(QPalette::Inactive, QPalette::Dark));
1923 newPalette.setColor(QPalette::Inactive, QPalette::Base,
1924 newPalette.color(QPalette::Inactive, QPalette::Dark));
1925 newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText,
1926 newPalette.color(QPalette::Inactive, QPalette::Window));
1927
1928 return newPalette;
1929}
1930
1932{
1933 Qt::WindowFlags windowFlags = q_func()->windowFlags();
1934 // Hide all
1935 for (int i = 0; i < NumWindowStateActions; ++i)
1937
1938#if defined(Q_OS_MACOS) && QT_CONFIG(action)
1939 if (q_func()->style()->inherits("QMacStyle"))
1940 for (int i = 0; i < NumWindowStateActions; ++i)
1941 if (QAction *action = actions[i])
1942 action->setIconVisibleInMenu(false);
1943#endif
1944
1945 if (windowFlags & Qt::FramelessWindowHint)
1946 return;
1947
1951
1952 // CloseAction
1953 if (windowFlags & Qt::WindowSystemMenuHint)
1954 setVisible(CloseAction, true);
1955
1956 // RestoreAction
1959
1960 // MinimizeAction
1961 if (windowFlags & Qt::WindowMinimizeButtonHint)
1963
1964 // MaximizeAction
1965 if (windowFlags & Qt::WindowMaximizeButtonHint)
1967}
1968
1970{
1971 Q_Q(QMdiSubWindow);
1972 if (!baseWidget) {
1973 q->setFocus();
1974 return;
1975 }
1976
1977 // This will give focus to the next child if possible, otherwise
1978 // do nothing, hence it's not possible to tab between windows with
1979 // just hitting tab (unless Qt::TabFocus is removed from the focus policy).
1981 q->focusNextChild();
1982 return;
1983 }
1984
1985 // Same as above, but gives focus to the previous child.
1987 q->focusPreviousChild();
1988 return;
1989 }
1990
1991 if (!(q->windowState() & Qt::WindowMinimized) && restoreFocus())
1992 return;
1993
1994 if (QWidget *focusWidget = baseWidget->focusWidget()) {
1995 if (!focusWidget->hasFocus() && q->isAncestorOf(focusWidget)
1996 && focusWidget->isVisible() && !q->isMinimized()
1997 && focusWidget->focusPolicy() != Qt::NoFocus) {
1998 focusWidget->setFocus();
1999 } else {
2000 q->setFocus();
2001 }
2002 return;
2003 }
2004
2005 QWidget *focusWidget = q->nextInFocusChain();
2006 while (focusWidget && focusWidget != q && focusWidget->focusPolicy() == Qt::NoFocus)
2007 focusWidget = focusWidget->nextInFocusChain();
2008 if (focusWidget && q->isAncestorOf(focusWidget))
2009 focusWidget->setFocus();
2010 else if (baseWidget->focusPolicy() != Qt::NoFocus)
2012 else if (!q->hasFocus())
2013 q->setFocus();
2014}
2015
2017{
2019 return false;
2020 QWidget *candidate = restoreFocusWidget;
2022 if (!candidate->hasFocus() && q_func()->isAncestorOf(candidate)
2023 && candidate->isVisible()
2024 && candidate->focusPolicy() != Qt::NoFocus) {
2025 candidate->setFocus();
2026 return true;
2027 }
2028 return candidate->hasFocus();
2029}
2030
2034void QMdiSubWindowPrivate::setWindowFlags(Qt::WindowFlags windowFlags)
2035{
2036 Q_Q(QMdiSubWindow);
2037
2038 if (!parent) {
2039 QWidgetPrivate::setWindowFlags(windowFlags);
2040 return;
2041 }
2042
2043 Qt::WindowFlags windowType = windowFlags & Qt::WindowType_Mask;
2044 if (windowType == Qt::Dialog || windowFlags & Qt::MSWindowsFixedSizeDialogHint)
2046
2047 // Set standard flags if none of the customize flags are set
2048 if (!(windowFlags & CustomizeWindowFlags))
2050 else if (windowFlags & Qt::FramelessWindowHint && windowFlags & Qt::WindowStaysOnTopHint)
2052 else if (windowFlags & Qt::FramelessWindowHint)
2053 windowFlags = Qt::FramelessWindowHint;
2054
2055 windowFlags &= ~windowType;
2056 windowFlags &= ~Qt::WindowFullscreenButtonHint;
2057 windowFlags |= Qt::SubWindow;
2058
2059#ifndef QT_NO_ACTION
2060 if (QAction *stayOnTopAction = actions[QMdiSubWindowPrivate::StayOnTopAction]) {
2061 if (windowFlags & Qt::WindowStaysOnTopHint)
2062 stayOnTopAction->setChecked(true);
2063 else
2064 stayOnTopAction->setChecked(false);
2065 }
2066#endif
2067
2068#if QT_CONFIG(sizegrip)
2069 if ((windowFlags & Qt::FramelessWindowHint) && sizeGrip)
2070 delete sizeGrip;
2071#endif
2072
2073 QWidgetPrivate::setWindowFlags(windowFlags);
2075 updateActions();
2076 QSize currentSize = q->size();
2077 if (q->isVisible() && (currentSize.width() < internalMinimumSize.width()
2078 || currentSize.height() < internalMinimumSize.height())) {
2079 q->resize(currentSize.expandedTo(internalMinimumSize));
2080 }
2081}
2082
2084{
2085#ifndef QT_NO_ACTION
2086 if (actions[action])
2087 actions[action]->setVisible(visible);
2088#endif
2089
2090 Q_Q(QMdiSubWindow);
2091 if (!controlContainer)
2093
2094 if (ControllerWidget *ctrlWidget = qobject_cast<ControllerWidget *>
2096 ctrlWidget->setControlVisible(action, visible);
2097 }
2098}
2099
2100#ifndef QT_NO_ACTION
2102{
2103 if (actions[action])
2104 actions[action]->setEnabled(enable);
2105}
2106
2107#if QT_CONFIG(menu)
2108void QMdiSubWindowPrivate::addToSystemMenu(WindowStateAction action, const QString &text,
2109 const char *slot)
2110{
2111 if (!systemMenu)
2112 return;
2113 actions[action] = systemMenu->addAction(text, q_func(), slot);
2114}
2115#endif
2116#endif // QT_NO_ACTION
2117
2122{
2123 Q_Q(const QMdiSubWindow);
2124 if (!parent || q->windowFlags() & Qt::FramelessWindowHint)
2125 return QSize(-1, -1);
2126 return QSize(q->style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth, nullptr, q), titleBarHeight());
2127}
2128
2129#if QT_CONFIG(sizegrip)
2130
2134void QMdiSubWindowPrivate::setSizeGrip(QSizeGrip *newSizeGrip)
2135{
2136 Q_Q(QMdiSubWindow);
2137 if (!newSizeGrip || sizeGrip || q->windowFlags() & Qt::FramelessWindowHint)
2138 return;
2139
2140 if (layout && layout->indexOf(newSizeGrip) != -1)
2141 return;
2142 newSizeGrip->setFixedSize(newSizeGrip->sizeHint());
2143 bool putSizeGripInLayout = layout ? true : false;
2144 if (isMacStyle(q->style()))
2145 putSizeGripInLayout = false;
2146 if (putSizeGripInLayout) {
2147 layout->addWidget(newSizeGrip);
2149 } else {
2150 newSizeGrip->setParent(q);
2151 newSizeGrip->move(q->isLeftToRight() ? q->width() - newSizeGrip->width() : 0,
2152 q->height() - newSizeGrip->height());
2153 sizeGrip = newSizeGrip;
2154 }
2155 newSizeGrip->raise();
2157 newSizeGrip->installEventFilter(q);
2158}
2159
2163void QMdiSubWindowPrivate::setSizeGripVisible(bool visible) const
2164{
2165 // See if we can find any size grips
2166 const QList<QSizeGrip *> sizeGrips = q_func()->findChildren<QSizeGrip *>();
2167 for (QSizeGrip *grip : sizeGrips)
2168 grip->setVisible(visible);
2169}
2170
2171#endif // QT_CONFIG(sizegrip)
2172
2177{
2178 Q_Q(QMdiSubWindow);
2179 if (q->isWindowModified()) {
2180 windowTitle = q->windowTitle();
2181 windowTitle.replace("[*]"_L1, "*"_L1);
2182 } else {
2183 windowTitle = qt_setWindowTitle_helperHelper(q->windowTitle(), q);
2184 }
2185 q->update(0, 0, q->width(), titleBarHeight());
2186}
2187
2207 : QWidget(*new QMdiSubWindowPrivate, parent, { })
2208{
2209 Q_D(QMdiSubWindow);
2210#if QT_CONFIG(menu)
2211 d->createSystemMenu();
2212 addActions(d->systemMenu->actions());
2213#endif
2214 d->setWindowFlags(flags);
2216 setAutoFillBackground(true);
2217 setMouseTracking(true);
2219 setFocusPolicy(Qt::StrongFocus);
2221 d->updateGeometryConstraints();
2223 d->titleBarPalette = d->desktopPalette();
2224 d->font = QApplication::font("QMdiSubWindowTitleBar");
2225 // We don't want the menu icon by default on mac.
2226#ifndef Q_OS_MAC
2227 if (windowIcon().isNull())
2228 d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, nullptr, this);
2229 else
2230 d->menuIcon = windowIcon();
2231#endif
2232 connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
2233 this, SLOT(_q_processFocusChanged(QWidget*,QWidget*)));
2234}
2235
2242{
2243 Q_D(QMdiSubWindow);
2244#if QT_CONFIG(menubar)
2245 d->removeButtonsFromMenuBar();
2246#endif
2247 d->setActive(false);
2248}
2249
2262{
2263 Q_D(QMdiSubWindow);
2264 if (!widget) {
2265 d->removeBaseWidget();
2266 return;
2267 }
2268
2269 if (Q_UNLIKELY(widget == d->baseWidget)) {
2270 qWarning("QMdiSubWindow::setWidget: widget is already set");
2271 return;
2272 }
2273
2274 bool wasResized = testAttribute(Qt::WA_Resized);
2275 d->removeBaseWidget();
2276
2277 if (QLayout *layout = this->layout())
2278 layout->addWidget(widget);
2279 else
2280 widget->setParent(this);
2281
2282#if QT_CONFIG(sizegrip)
2283 QSizeGrip *sizeGrip = widget->findChild<QSizeGrip *>();
2284 if (sizeGrip)
2285 sizeGrip->installEventFilter(this);
2286 if (d->sizeGrip)
2287 d->sizeGrip->raise();
2288#endif
2289
2290 d->baseWidget = widget;
2291 d->baseWidget->installEventFilter(this);
2292
2293 d->ignoreWindowTitleChange = true;
2294 bool isWindowModified = this->isWindowModified();
2295 if (windowTitle().isEmpty()) {
2296 d->updateWindowTitle(true);
2297 isWindowModified = d->baseWidget->isWindowModified();
2298 }
2299 if (!this->isWindowModified() && isWindowModified && windowTitle().contains("[*]"_L1))
2301 d->lastChildWindowTitle = d->baseWidget->windowTitle();
2302 d->ignoreWindowTitleChange = false;
2303
2304 if (windowIcon().isNull() && !d->baseWidget->windowIcon().isNull())
2305 setWindowIcon(d->baseWidget->windowIcon());
2306
2307 d->updateGeometryConstraints();
2308 if (!wasResized && testAttribute(Qt::WA_Resized))
2310}
2311
2318{
2319 return d_func()->baseWidget;
2320}
2321
2322
2327{
2328 Q_D(const QMdiSubWindow);
2329 if (isVisible() && d->controlContainer && isMaximized() && !d->drawTitleBarWhenMaximized()
2330 && !isChildOfTabbedQMdiArea(this)) {
2331 return d->controlContainer->controllerWidget();
2332 }
2333 return nullptr;
2334}
2335
2340{
2341 Q_D(const QMdiSubWindow);
2342 if (isVisible() && d->controlContainer && isMaximized() && !d->drawTitleBarWhenMaximized()
2343 && !isChildOfTabbedQMdiArea(this)) {
2344 return d->controlContainer->systemMenuLabel();
2345 }
2346 return nullptr;
2347}
2348
2356{
2357 return d_func()->isShadeMode;
2358}
2359
2367{
2368 Q_D(QMdiSubWindow);
2369 d->options.setFlag(option, on);
2370
2371#if QT_CONFIG(rubberband)
2372 if ((option & (RubberBandResize | RubberBandMove)) && !on && d->isInRubberBandMode)
2373 d->leaveRubberBandMode();
2374#endif
2375}
2376
2383{
2384 return d_func()->options & option;
2385}
2386
2402{
2403 return d_func()->keyboardSingleStep;
2404}
2405
2407{
2408 // Haven't done any boundary check here since negative step only
2409 // means inverted behavior, which is OK if the user want it.
2410 // A step equal to zero means "do nothing".
2411 d_func()->keyboardSingleStep = step;
2412}
2413
2429{
2430 return d_func()->keyboardPageStep;
2431}
2432
2434{
2435 // Haven't done any boundary check here since negative step only
2436 // means inverted behavior, which is OK if the user want it.
2437 // A step equal to zero means "do nothing".
2438 d_func()->keyboardPageStep = step;
2439}
2440
2441#if QT_CONFIG(menu)
2459void QMdiSubWindow::setSystemMenu(QMenu *systemMenu)
2460{
2461 Q_D(QMdiSubWindow);
2462 if (Q_UNLIKELY(systemMenu && systemMenu == d->systemMenu)) {
2463 qWarning("QMdiSubWindow::setSystemMenu: system menu is already set");
2464 return;
2465 }
2466
2467 if (d->systemMenu) {
2468 delete d->systemMenu;
2469 d->systemMenu = nullptr;
2470 }
2471
2472 if (!systemMenu)
2473 return;
2474
2475 if (systemMenu->parent() != this)
2476 systemMenu->setParent(this);
2477 d->systemMenu = systemMenu;
2478}
2479
2487QMenu *QMdiSubWindow::systemMenu() const
2488{
2489 return d_func()->systemMenu;
2490}
2491
2497void QMdiSubWindow::showSystemMenu()
2498{
2499 Q_D(QMdiSubWindow);
2500 if (!d->systemMenu)
2501 return;
2502
2503 QPoint globalPopupPos;
2505 if (isLeftToRight())
2506 globalPopupPos = icon->mapToGlobal(QPoint(0, icon->y() + icon->height()));
2507 else
2508 globalPopupPos = icon->mapToGlobal(QPoint(icon->width(), icon->y() + icon->height()));
2509 } else {
2510 if (isLeftToRight())
2511 globalPopupPos = mapToGlobal(contentsRect().topLeft());
2512 else // + QPoint(1, 0) because topRight() == QPoint(left() + width() -1, top())
2513 globalPopupPos = mapToGlobal(contentsRect().topRight()) + QPoint(1, 0);
2514 }
2515
2516 // Adjust x() with -menuwidth in reverse mode.
2517 if (isRightToLeft())
2518 globalPopupPos -= QPoint(d->systemMenu->sizeHint().width(), 0);
2519 d->systemMenu->popup(globalPopupPos);
2520}
2521#endif // QT_CONFIG(menu)
2522
2532{
2534 while (parent) {
2535 if (QMdiArea *area = qobject_cast<QMdiArea *>(parent)) {
2536 if (area->viewport() == parentWidget())
2537 return area;
2538 }
2539 parent = parent->parentWidget();
2540 }
2541 return nullptr;
2542}
2543
2558{
2559 if (!parent())
2560 return;
2561
2562 Q_D(QMdiSubWindow);
2563 // setMinimizeMode uses this function.
2564 if (!d->isShadeRequestFromMinimizeMode && isShaded())
2565 return;
2566
2567 d->isMaximizeMode = false;
2568
2569 d->storeFocusWidget();
2570
2571 if (!d->isShadeRequestFromMinimizeMode) {
2572 d->isShadeMode = true;
2573 d->ensureWindowState(Qt::WindowMinimized);
2574 }
2575
2576#if QT_CONFIG(menubar)
2577 d->removeButtonsFromMenuBar();
2578#endif
2579
2580 // showMinimized() will reset Qt::WindowActive, which makes sense
2581 // for top level widgets, but in MDI it makes sense to have an
2582 // active window which is minimized.
2584 d->ensureWindowState(Qt::WindowActive);
2585
2586#if QT_CONFIG(sizegrip)
2587 d->setSizeGripVisible(false);
2588#endif
2589
2590 if (!d->restoreSize.isValid() || d->isShadeMode) {
2591 d->oldGeometry = geometry();
2592 d->restoreSize.setWidth(d->oldGeometry.width());
2593 d->restoreSize.setHeight(d->oldGeometry.height());
2594 }
2595
2596 // Hide the window before we change the geometry to avoid multiple resize
2597 // events and wrong window state.
2598 const bool wasVisible = isVisible();
2599 if (wasVisible)
2600 setVisible(false);
2601
2602 d->updateGeometryConstraints();
2603 // Update minimum size to internalMinimumSize if set by user.
2604 if (!minimumSize().isNull()) {
2605 d->userMinimumSize = minimumSize();
2606 setMinimumSize(d->internalMinimumSize);
2607 }
2608 resize(d->internalMinimumSize);
2609
2610 // Hide the internal widget if not already hidden by the user.
2611 if (d->baseWidget && !d->baseWidget->isHidden() && !(windowFlags() & Qt::FramelessWindowHint)) {
2612 d->baseWidget->hide();
2613 d->isWidgetHiddenByUs = true;
2614 }
2615
2616 if (wasVisible)
2617 setVisible(true);
2618
2619 d->setFocusWidget();
2620 d->resizeEnabled = false;
2621 d->moveEnabled = true;
2622 d->updateDirtyRegions();
2623 d->updateMask();
2624
2625#ifndef QT_NO_ACTION
2626 d->setEnabled(QMdiSubWindowPrivate::MinimizeAction, false);
2627 d->setEnabled(QMdiSubWindowPrivate::ResizeAction, d->resizeEnabled);
2628 d->setEnabled(QMdiSubWindowPrivate::MaximizeAction, true);
2629 d->setEnabled(QMdiSubWindowPrivate::RestoreAction, true);
2630 d->setEnabled(QMdiSubWindowPrivate::MoveAction, d->moveEnabled);
2631#endif
2632}
2633
2638{
2639 Q_D(QMdiSubWindow);
2640 if (!object)
2641 return QWidget::eventFilter(object, event);
2642
2643#if QT_CONFIG(menu)
2644 // System menu events.
2645 if (d->systemMenu && d->systemMenu == object) {
2646 if (event->type() == QEvent::MouseButtonDblClick) {
2647 const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event);
2648 const QAction *action = d->systemMenu->actionAt(mouseEvent->position().toPoint());
2649 if (!action || action->isEnabled())
2650 close();
2651 } else if (event->type() == QEvent::MouseMove) {
2652 QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
2653 d->hoveredSubControl = d->getSubControl(mapFromGlobal(mouseEvent->globalPosition().toPoint()));
2654 } else if (event->type() == QEvent::Hide) {
2655 d->activeSubControl = QStyle::SC_None;
2656 update(QRegion(0, 0, width(), d->titleBarHeight()));
2657 }
2658 return QWidget::eventFilter(object, event);
2659 }
2660#endif
2661
2662#if QT_CONFIG(sizegrip)
2663 if (object != d->baseWidget && parent() && qobject_cast<QSizeGrip *>(object)) {
2665 return QWidget::eventFilter(object, event);
2666 const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
2667 d->mousePressPosition = parentWidget()->mapFromGlobal(mouseEvent->globalPosition().toPoint());
2668 d->oldGeometry = geometry();
2671#if QT_CONFIG(rubberband)
2672 d->enterRubberBandMode();
2673#endif
2674 return true;
2675 }
2676#endif
2677
2678 if (object != d->baseWidget && event->type() != QEvent::WindowTitleChange)
2679 return QWidget::eventFilter(object, event);
2680
2681 switch (event->type()) {
2682 case QEvent::Show:
2683 d->setActive(true);
2684 break;
2686 if (!d->isWidgetHiddenByUs)
2687 show();
2688 break;
2691 if (changeEvent->isOverride())
2692 break;
2693 Qt::WindowStates oldState = changeEvent->oldState();
2694 Qt::WindowStates newState = d->baseWidget->windowState();
2695 if (!(oldState & Qt::WindowMinimized) && (newState & Qt::WindowMinimized))
2696 showMinimized();
2697 else if (!(oldState & Qt::WindowMaximized) && (newState & Qt::WindowMaximized))
2698 showMaximized();
2700 showNormal();
2701 break;
2702 }
2703 case QEvent::Enter:
2704 d->currentOperation = QMdiSubWindowPrivate::None;
2705 d->updateCursor();
2706 break;
2708 d->updateGeometryConstraints();
2709 break;
2711 if (d->ignoreWindowTitleChange)
2712 break;
2713 if (object == d->baseWidget) {
2714 d->updateWindowTitle(true);
2715 d->lastChildWindowTitle = d->baseWidget->windowTitle();
2716#if QT_CONFIG(menubar)
2717 } else if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar()
2718 ->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) {
2719 d->originalTitle.clear();
2720 if (d->baseWidget && d->baseWidget->windowTitle() == windowTitle())
2721 d->updateWindowTitle(true);
2722 else
2723 d->updateWindowTitle(false);
2724#endif
2725 }
2726 break;
2728 if (object != d->baseWidget)
2729 break;
2730 bool windowModified = d->baseWidget->isWindowModified();
2731 if (!windowModified && d->baseWidget->windowTitle() != windowTitle())
2732 break;
2733 if (windowTitle().contains("[*]"_L1))
2735 break;
2736 }
2737 default:
2738 break;
2739 }
2740 return QWidget::eventFilter(object, event);
2741}
2742
2747{
2748 Q_D(QMdiSubWindow);
2749 switch (event->type()) {
2750 case QEvent::StyleChange: {
2751 bool wasShaded = isShaded();
2752 bool wasMinimized = isMinimized();
2753 bool wasMaximized = isMaximized();
2754 // Don't emit subWindowActivated, the app doesn't have to know about our hacks
2755 const QScopedValueRollback<bool> activationEnabledSaver(d->activationEnabled);
2756 d->activationEnabled = false;
2757
2759 setContentsMargins(0, 0, 0, 0);
2760 if (wasMinimized || wasMaximized || wasShaded)
2761 showNormal();
2762 d->updateGeometryConstraints();
2763 resize(d->internalMinimumSize.expandedTo(size()));
2764 d->updateMask();
2765 d->updateDirtyRegions();
2766 if (wasShaded)
2767 showShaded();
2768 else if (wasMinimized)
2769 showMinimized();
2770 else if (wasMaximized)
2771 showMaximized();
2772 break;
2773 }
2775 d->setActive(false);
2776 break;
2777 case QEvent::ParentChange: {
2778 bool wasResized = testAttribute(Qt::WA_Resized);
2779#if QT_CONFIG(menubar)
2780 d->removeButtonsFromMenuBar();
2781#endif
2782 d->currentOperation = QMdiSubWindowPrivate::None;
2783 d->activeSubControl = QStyle::SC_None;
2784 d->hoveredSubControl = QStyle::SC_None;
2785#if QT_CONFIG(rubberband)
2786 if (d->isInRubberBandMode)
2787 d->leaveRubberBandMode();
2788#endif
2789 d->isShadeMode = false;
2790 d->isMaximizeMode = false;
2791 d->isWidgetHiddenByUs = false;
2792 if (!parent()) {
2793#if QT_CONFIG(sizegrip)
2794 if (isMacStyle(style()))
2795 delete d->sizeGrip;
2796#endif
2798 setOption(RubberBandMove, false);
2799 } else {
2800 d->setWindowFlags(windowFlags());
2801 }
2802 setContentsMargins(0, 0, 0, 0);
2803 d->updateGeometryConstraints();
2804 d->updateCursor();
2805 d->updateMask();
2806 d->updateDirtyRegions();
2807 d->updateActions();
2808 if (!wasResized && testAttribute(Qt::WA_Resized))
2810 break;
2811 }
2813 if (d->ignoreNextActivationEvent) {
2814 d->ignoreNextActivationEvent = false;
2815 break;
2816 }
2817 d->isExplicitlyDeactivated = false;
2818 d->setActive(true);
2819 break;
2821 if (d->ignoreNextActivationEvent) {
2822 d->ignoreNextActivationEvent = false;
2823 break;
2824 }
2825 d->isExplicitlyDeactivated = true;
2826 d->setActive(false);
2827 break;
2829 if (!d->ignoreWindowTitleChange)
2830 d->updateWindowTitle(false);
2831 d->updateInternalWindowTitle();
2832 break;
2834 if (!windowTitle().contains("[*]"_L1))
2835 break;
2836#if QT_CONFIG(menubar)
2837 if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar()
2838 ->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) {
2840 }
2841#endif // QT_CONFIG(menubar)
2842 d->updateInternalWindowTitle();
2843 break;
2845 d->updateDirtyRegions();
2846 break;
2848 d->updateGeometryConstraints();
2849 break;
2851 d->menuIcon = windowIcon();
2852 if (d->menuIcon.isNull())
2853 d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, nullptr, this);
2854 if (d->controlContainer)
2855 d->controlContainer->updateWindowIcon(d->menuIcon);
2857 update(0, 0, width(), d->titleBarHeight());
2858 break;
2860 d->titleBarPalette = d->desktopPalette();
2861 break;
2862 case QEvent::FontChange:
2863 d->font = font();
2864 break;
2865#if QT_CONFIG(tooltip)
2866 case QEvent::ToolTip:
2867 showToolTip(static_cast<QHelpEvent *>(event), this, d->titleBarOptions(),
2868 QStyle::CC_TitleBar, d->hoveredSubControl);
2869 break;
2870#endif
2871 default:
2872 break;
2873 }
2874 return QWidget::event(event);
2875}
2876
2881{
2882 Q_D(QMdiSubWindow);
2883 if (!parent()) {
2885 return;
2886 }
2887
2888#if QT_CONFIG(sizegrip)
2889 if (isMacStyle(style()) && !d->sizeGrip
2891 d->setSizeGrip(new QSizeGrip(this));
2892 Q_ASSERT(d->sizeGrip);
2893 if (isMinimized())
2894 d->setSizeGripVisible(false);
2895 else
2896 d->setSizeGripVisible(true);
2897 resize(size().expandedTo(d->internalMinimumSize));
2898 }
2899#endif
2900
2901 d->updateDirtyRegions();
2902 // Show buttons in the menu bar if they're already not there.
2903 // We want to do this when QMdiSubWindow becomes visible after being hidden.
2904#if QT_CONFIG(menubar)
2905 if (d->controlContainer) {
2906 if (QMenuBar *menuBar = d->menuBar()) {
2908 d->showButtonsInMenuBar(menuBar);
2909 }
2910 }
2911#endif
2912 d->setActive(true);
2913}
2914
2919{
2920#if QT_CONFIG(menubar)
2921 d_func()->removeButtonsFromMenuBar();
2922#endif
2923}
2924
2929{
2930 if (!parent()) {
2932 return;
2933 }
2934
2935 if (changeEvent->type() != QEvent::WindowStateChange) {
2937 return;
2938 }
2939
2941 if (event->isOverride()) {
2942 event->ignore();
2943 return;
2944 }
2945
2946 Qt::WindowStates oldState = event->oldState();
2947 Qt::WindowStates newState = windowState();
2948 if (oldState == newState) {
2949 changeEvent->ignore();
2950 return;
2951 }
2952
2953 // QWidget ensures that the widget is visible _after_ setWindowState(),
2954 // but we need to ensure that the widget is visible _before_
2955 // setWindowState() returns.
2956 Q_D(QMdiSubWindow);
2957 if (!isVisible()) {
2958 d->ensureWindowState(Qt::WindowNoState);
2959 setVisible(true);
2960 }
2961
2962 if (!d->oldGeometry.isValid())
2963 d->oldGeometry = geometry();
2964
2965 if ((oldState & Qt::WindowActive) && (newState & Qt::WindowActive))
2966 d->currentOperation = QMdiSubWindowPrivate::None;
2967
2968 if (!(oldState & Qt::WindowMinimized) && (newState & Qt::WindowMinimized))
2969 d->setMinimizeMode();
2970 else if (!(oldState & Qt::WindowMaximized) && (newState & Qt::WindowMaximized))
2971 d->setMaximizeMode();
2973 d->setNormalMode();
2974
2975 if (d->isActive)
2976 d->ensureWindowState(Qt::WindowActive);
2977 if (d->activationEnabled)
2978 emit windowStateChanged(oldState, windowState());
2979}
2980
2985{
2986 Q_D(QMdiSubWindow);
2987 bool acceptClose = true;
2988 if (d->baseWidget)
2989 acceptClose = d->baseWidget->close();
2990 if (!acceptClose) {
2991 closeEvent->ignore();
2992 return;
2993 }
2994#if QT_CONFIG(menubar)
2995 d->removeButtonsFromMenuBar();
2996#endif
2997 d->setActive(false);
2999 QChildEvent childRemoved(QEvent::ChildRemoved, this);
3000 QCoreApplication::sendEvent(parentWidget(), &childRemoved);
3001 }
3002 closeEvent->accept();
3003}
3004
3008void QMdiSubWindow::leaveEvent(QEvent * /*leaveEvent*/)
3009{
3010 Q_D(QMdiSubWindow);
3011 if (d->hoveredSubControl != QStyle::SC_None) {
3012 d->hoveredSubControl = QStyle::SC_None;
3013 update(QRegion(0, 0, width(), d->titleBarHeight()));
3014 }
3015}
3016
3024{
3025 Q_D(QMdiSubWindow);
3026#if QT_CONFIG(sizegrip)
3027 if (d->sizeGrip) {
3028 d->sizeGrip->move(isLeftToRight() ? width() - d->sizeGrip->width() : 0,
3029 height() - d->sizeGrip->height());
3030 }
3031#endif
3032
3033 if (!parent()) {
3035 return;
3036 }
3037
3038 if (d->isMaximizeMode)
3039 d->ensureWindowState(Qt::WindowMaximized);
3040
3041 d->updateMask();
3042 if (!isVisible())
3043 return;
3044
3045 if (d->resizeTimerId <= 0)
3046 d->cachedStyleOptions = d->titleBarOptions();
3047 else
3048 killTimer(d->resizeTimerId);
3049 d->resizeTimerId = startTimer(200);
3050}
3051
3056{
3057 Q_D(QMdiSubWindow);
3058 if (timerEvent->timerId() == d->resizeTimerId) {
3059 killTimer(d->resizeTimerId);
3060 d->resizeTimerId = -1;
3061 d->updateDirtyRegions();
3062 }
3063}
3064
3069{
3070 if (!parent()) {
3072 return;
3073 }
3074
3075 Q_D(QMdiSubWindow);
3076 if (d->isMaximizeMode)
3077 d->ensureWindowState(Qt::WindowMaximized);
3078}
3079
3084{
3085 if (!parent() || (windowFlags() & Qt::FramelessWindowHint)) {
3087 return;
3088 }
3089
3090 Q_D(QMdiSubWindow);
3091
3092 if (d->resizeTimerId != -1) {
3093 // Only update the style option rect and the window title.
3094 int border = d->hasBorder(d->cachedStyleOptions) ? 4 : 0;
3095 int titleBarHeight = d->titleBarHeight(d->cachedStyleOptions);
3096 titleBarHeight -= isMinimized() ? 2 * border : border;
3097 d->cachedStyleOptions.rect = QRect(border, border, width() - 2 * border, titleBarHeight);
3098 if (!d->windowTitle.isEmpty()) {
3099 int width = style()->subControlRect(QStyle::CC_TitleBar, &d->cachedStyleOptions,
3100 QStyle::SC_TitleBarLabel, this).width();
3101 d->cachedStyleOptions.text = d->cachedStyleOptions.fontMetrics
3102 .elidedText(d->windowTitle, Qt::ElideRight, width);
3103 }
3104 } else {
3105 // Force full update.
3106 d->cachedStyleOptions = d->titleBarOptions();
3107 }
3108
3109 QStylePainter painter(this);
3110 QStyleOptionFrame frameOptions;
3111 frameOptions.initFrom(this);
3112 frameOptions.state.setFlag(QStyle::State_Active, d->isActive);
3113 if (isMaximized() && !d->drawTitleBarWhenMaximized()) {
3114 if (!autoFillBackground() && (!widget() || !qt_widget_private(widget())->isOpaque)) {
3115 // make sure we paint all pixels of a maximized QMdiSubWindow if no-one else does
3116 painter.drawPrimitive(QStyle::PE_FrameWindow, frameOptions);
3117 }
3118 return;
3119 }
3120
3121 if (!d->windowTitle.isEmpty())
3122 painter.setFont(d->font);
3123 painter.drawComplexControl(QStyle::CC_TitleBar, d->cachedStyleOptions);
3124
3125 if (isMinimized() && !d->hasBorder(d->cachedStyleOptions))
3126 return;
3127
3128 frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, this);
3129
3130 // ### Ensure that we do not require setting the cliprect for 4.4
3131 if (!isMinimized() && !d->hasBorder(d->cachedStyleOptions))
3132 painter.setClipRect(rect().adjusted(0, d->titleBarHeight(d->cachedStyleOptions), 0, 0));
3133 if (!isMinimized() || d->hasBorder(d->cachedStyleOptions))
3134 painter.drawPrimitive(QStyle::PE_FrameWindow, frameOptions);
3135}
3136
3141{
3142 if (!parent()) {
3143 QWidget::mousePressEvent(mouseEvent);
3144 return;
3145 }
3146
3147 Q_D(QMdiSubWindow);
3148 if (d->isInInteractiveMode)
3149 d->leaveInteractiveMode();
3150#if QT_CONFIG(rubberband)
3151 if (d->isInRubberBandMode)
3152 d->leaveRubberBandMode();
3153#endif
3154
3155 if (mouseEvent->button() != Qt::LeftButton) {
3156 mouseEvent->ignore();
3157 return;
3158 }
3159
3160 if (d->currentOperation != QMdiSubWindowPrivate::None) {
3161 d->updateCursor();
3162 d->mousePressPosition = mapToParent(mouseEvent->position().toPoint());
3163 if (d->resizeEnabled || d->moveEnabled)
3164 d->oldGeometry = geometry();
3165#if QT_CONFIG(rubberband)
3166 if ((testOption(QMdiSubWindow::RubberBandResize) && d->isResizeOperation())
3167 || (testOption(QMdiSubWindow::RubberBandMove) && d->isMoveOperation())) {
3168 d->enterRubberBandMode();
3169 }
3170#endif
3171 return;
3172 }
3173
3174 d->activeSubControl = d->hoveredSubControl;
3175#if QT_CONFIG(menu)
3176 if (d->activeSubControl == QStyle::SC_TitleBarSysMenu)
3178 else
3179#endif
3180 update(QRegion(0, 0, width(), d->titleBarHeight()));
3181}
3182
3187{
3188 if (!parent()) {
3190 return;
3191 }
3192
3193 if (mouseEvent->button() != Qt::LeftButton) {
3194 mouseEvent->ignore();
3195 return;
3196 }
3197
3198 Q_D(QMdiSubWindow);
3199 if (!d->isMoveOperation()) {
3200#if QT_CONFIG(menu)
3201 if (d->hoveredSubControl == QStyle::SC_TitleBarSysMenu)
3202 close();
3203#endif
3204 return;
3205 }
3206
3207 Qt::WindowFlags flags = windowFlags();
3208 if (isMinimized()) {
3211 showNormal();
3212 }
3213 return;
3214 }
3215
3216 if (isMaximized()) {
3218 showNormal();
3219 return;
3220 }
3221
3223 showShaded();
3225 showMaximized();
3226}
3227
3232{
3233 if (!parent()) {
3234 QWidget::mouseReleaseEvent(mouseEvent);
3235 return;
3236 }
3237
3238 if (mouseEvent->button() != Qt::LeftButton) {
3239 mouseEvent->ignore();
3240 return;
3241 }
3242
3243 Q_D(QMdiSubWindow);
3244 if (d->currentOperation != QMdiSubWindowPrivate::None) {
3245#if QT_CONFIG(rubberband)
3246 if (d->isInRubberBandMode && !d->isInInteractiveMode)
3247 d->leaveRubberBandMode();
3248#endif
3249 if (d->resizeEnabled || d->moveEnabled)
3250 d->oldGeometry = geometry();
3251 }
3252
3253 d->currentOperation = d->getOperation(mouseEvent->position().toPoint());
3254 d->updateCursor();
3255
3256 d->hoveredSubControl = d->getSubControl(mouseEvent->position().toPoint());
3257 if (d->activeSubControl != QStyle::SC_None
3258 && d->activeSubControl == d->hoveredSubControl) {
3259 d->processClickedSubControl();
3260 }
3261 d->activeSubControl = QStyle::SC_None;
3262 update(QRegion(0, 0, width(), d->titleBarHeight()));
3263}
3264
3269{
3270 if (!parent()) {
3271 QWidget::mouseMoveEvent(mouseEvent);
3272 return;
3273 }
3274
3275 Q_D(QMdiSubWindow);
3276 // No update needed if we're in a move/resize operation.
3277 if (!d->isMoveOperation() && !d->isResizeOperation()) {
3278 // Find previous and current hover region.
3279 const QStyleOptionTitleBar options = d->titleBarOptions();
3280 QStyle::SubControl oldHover = d->hoveredSubControl;
3281 d->hoveredSubControl = d->getSubControl(mouseEvent->position().toPoint());
3282 QRegion hoverRegion;
3283 if (isHoverControl(oldHover) && oldHover != d->hoveredSubControl)
3284 hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options, oldHover, this);
3285 if (isHoverControl(d->hoveredSubControl) && d->hoveredSubControl != oldHover) {
3286 hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options,
3287 d->hoveredSubControl, this);
3288 }
3289
3290 if (isMacStyle(style()) && !hoverRegion.isEmpty())
3291 hoverRegion += QRegion(0, 0, width(), d->titleBarHeight(options));
3292
3293 if (!hoverRegion.isEmpty())
3294 update(hoverRegion);
3295 }
3296
3297 if ((mouseEvent->buttons() & Qt::LeftButton) || d->isInInteractiveMode) {
3298 if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled)) {
3299 // As setNewGeometry moves the window, it invalidates the pos() value of any mouse move events that are
3300 // currently queued in the event loop. Map to parent using globalPos() instead.
3301 d->setNewGeometry(parentWidget()->mapFromGlobal(mouseEvent->globalPosition().toPoint()));
3302 }
3303 return;
3304 }
3305
3306 // Do not resize/move if not allowed.
3307 d->currentOperation = d->getOperation(mouseEvent->position().toPoint());
3308 if ((d->isResizeOperation() && !d->resizeEnabled) || (d->isMoveOperation() && !d->moveEnabled))
3309 d->currentOperation = QMdiSubWindowPrivate::None;
3310 d->updateCursor();
3311}
3312
3317{
3318 Q_D(QMdiSubWindow);
3319 if (!d->isInInteractiveMode || !parent()) {
3320 keyEvent->ignore();
3321 return;
3322 }
3323
3324 QPoint delta;
3325 switch (keyEvent->key()) {
3326 case Qt::Key_Right:
3327 if (keyEvent->modifiers() & Qt::ShiftModifier)
3328 delta = QPoint(d->keyboardPageStep, 0);
3329 else
3330 delta = QPoint(d->keyboardSingleStep, 0);
3331 break;
3332 case Qt::Key_Up:
3333 if (keyEvent->modifiers() & Qt::ShiftModifier)
3334 delta = QPoint(0, -d->keyboardPageStep);
3335 else
3336 delta = QPoint(0, -d->keyboardSingleStep);
3337 break;
3338 case Qt::Key_Left:
3339 if (keyEvent->modifiers() & Qt::ShiftModifier)
3340 delta = QPoint(-d->keyboardPageStep, 0);
3341 else
3342 delta = QPoint(-d->keyboardSingleStep, 0);
3343 break;
3344 case Qt::Key_Down:
3345 if (keyEvent->modifiers() & Qt::ShiftModifier)
3346 delta = QPoint(0, d->keyboardPageStep);
3347 else
3348 delta = QPoint(0, d->keyboardSingleStep);
3349 break;
3350 case Qt::Key_Escape:
3351 case Qt::Key_Return:
3352 case Qt::Key_Enter:
3353 d->leaveInteractiveMode();
3354 return;
3355 default:
3356 keyEvent->ignore();
3357 return;
3358 }
3359
3360#ifndef QT_NO_CURSOR
3361 QPoint newPosition = parentWidget()->mapFromGlobal(cursor().pos() + delta);
3362 QRect oldGeometry =
3363#if QT_CONFIG(rubberband)
3364 d->isInRubberBandMode ? d->rubberBand->geometry() :
3365#endif
3366 geometry();
3367 d->setNewGeometry(newPosition);
3368 QRect currentGeometry =
3369#if QT_CONFIG(rubberband)
3370 d->isInRubberBandMode ? d->rubberBand->geometry() :
3371#endif
3372 geometry();
3373 if (currentGeometry == oldGeometry)
3374 return;
3375
3376 // Update cursor position
3377
3378 QPoint actualDelta;
3379 if (d->isMoveOperation()) {
3380 actualDelta = QPoint(currentGeometry.x() - oldGeometry.x(),
3381 currentGeometry.y() - oldGeometry.y());
3382 } else {
3383 int dx = isLeftToRight() ? currentGeometry.width() - oldGeometry.width()
3384 : currentGeometry.x() - oldGeometry.x();
3385 actualDelta = QPoint(dx, currentGeometry.height() - oldGeometry.height());
3386 }
3387
3388 // Adjust in case we weren't able to move as long as wanted.
3389 if (actualDelta != delta)
3390 newPosition += (actualDelta - delta);
3391 cursor().setPos(parentWidget()->mapToGlobal(newPosition));
3392#endif
3393}
3394
3395#ifndef QT_NO_CONTEXTMENU
3400{
3401 Q_D(QMdiSubWindow);
3402 if (!d->systemMenu) {
3403 contextMenuEvent->ignore();
3404 return;
3405 }
3406
3407 if (d->hoveredSubControl == QStyle::SC_TitleBarSysMenu
3408 || d->getRegion(QMdiSubWindowPrivate::Move).contains(contextMenuEvent->pos())) {
3409 d->systemMenu->exec(contextMenuEvent->globalPos());
3410 } else {
3411 contextMenuEvent->ignore();
3412 }
3413}
3414#endif // QT_NO_CONTEXTMENU
3415
3420{
3421 d_func()->focusInReason = focusInEvent->reason();
3422}
3423
3428{
3429 // To avoid update() in QWidget::focusOutEvent.
3430}
3431
3436{
3437 if (childEvent->type() != QEvent::ChildPolished)
3438 return;
3439#if QT_CONFIG(sizegrip)
3440 if (QSizeGrip *sizeGrip = qobject_cast<QSizeGrip *>(childEvent->child()))
3441 d_func()->setSizeGrip(sizeGrip);
3442#endif
3443}
3444
3449{
3450 Q_D(const QMdiSubWindow);
3451 int margin, minWidth;
3452 d->sizeParameters(&margin, &minWidth);
3453 QSize size(2 * margin, d->titleBarHeight() + margin);
3454 if (d->baseWidget && d->baseWidget->sizeHint().isValid())
3455 size += d->baseWidget->sizeHint();
3456 return size.expandedTo(minimumSizeHint());
3457}
3458
3463{
3464 Q_D(const QMdiSubWindow);
3465 if (isVisible())
3467
3468 // Minimized window.
3469 if (parent() && isMinimized() && !isShaded())
3470 return d->iconSize();
3471
3472 // Calculate window decoration.
3473 int margin, minWidth;
3474 d->sizeParameters(&margin, &minWidth);
3475 int decorationHeight = margin + d->titleBarHeight();
3476 int minHeight = decorationHeight;
3477
3478 // Shaded window.
3479 if (parent() && isShaded())
3480 return QSize(qMax(minWidth, width()), d->titleBarHeight());
3481
3482 // Content
3483 if (layout()) {
3484 QSize minLayoutSize = layout()->minimumSize();
3485 if (minLayoutSize.isValid()) {
3486 minWidth = qMax(minWidth, minLayoutSize.width() + 2 * margin);
3487 minHeight += minLayoutSize.height();
3488 }
3489 } else if (d->baseWidget && d->baseWidget->isVisible()) {
3490 QSize minBaseWidgetSize = d->baseWidget->minimumSizeHint();
3491 if (minBaseWidgetSize.isValid()) {
3492 minWidth = qMax(minWidth, minBaseWidgetSize.width() + 2 * margin);
3493 minHeight += minBaseWidgetSize.height();
3494 }
3495 }
3496
3497#if QT_CONFIG(sizegrip)
3498 // SizeGrip
3499 int sizeGripHeight = 0;
3500 if (d->sizeGrip && d->sizeGrip->isVisibleTo(const_cast<QMdiSubWindow *>(this)))
3501 sizeGripHeight = d->sizeGrip->height();
3502 else if (parent() && isMacStyle(style()) && !d->sizeGrip)
3503 sizeGripHeight = style()->pixelMetric(QStyle::PM_SizeGripSize, nullptr, this);
3504 minHeight = qMax(minHeight, decorationHeight + sizeGripHeight);
3505#endif
3506
3507 return QSize(minWidth, minHeight);
3508}
3509
3511
3512#include "moc_qmdisubwindow.cpp"
3513#include "qmdisubwindow.moc"
bool isActive
int value
the slider's current value
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
void setIcon(const QIcon &icon)
Definition qaction.cpp:547
void setEnabled(bool)
Definition qaction.cpp:927
void setCheckable(bool)
Definition qaction.cpp:832
void setVisible(bool)
Definition qaction.cpp:990
bool isEnabled() const
Definition qaction.cpp:971
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QFont font()
Returns the default application font.
\inmodule QtCore
Definition qcoreevent.h:379
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static void setPos(int x, int y)
Moves the cursor (hot spot) of the primary screen to the global screen position (x,...
Definition qcursor.cpp:240
\inmodule QtCore
Definition qcoreevent.h:45
@ WindowStateChange
Definition qcoreevent.h:143
@ ParentChange
Definition qcoreevent.h:80
@ ModifiedChange
Definition qcoreevent.h:138
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ ChildPolished
Definition qcoreevent.h:107
@ ChildRemoved
Definition qcoreevent.h:108
@ StyleChange
Definition qcoreevent.h:136
@ LayoutRequest
Definition qcoreevent.h:112
@ FontChange
Definition qcoreevent.h:133
@ MouseMove
Definition qcoreevent.h:63
@ MouseButtonPress
Definition qcoreevent.h:60
@ ParentAboutToChange
Definition qcoreevent.h:81
@ WindowActivate
Definition qcoreevent.h:83
@ WindowIconChange
Definition qcoreevent.h:89
@ PaletteChange
Definition qcoreevent.h:94
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ WindowTitleChange
Definition qcoreevent.h:88
@ ShowToParent
Definition qcoreevent.h:85
@ WindowDeactivate
Definition qcoreevent.h:84
Type type() const
Returns the event type.
Definition qcoreevent.h:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant \inmodule QtGui
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:788
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition qevent.h:799
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:798
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition qicon.cpp:1019
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:834
The QKeyEvent class describes a key event.
Definition qevent.h:424
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1468
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition qlayout.cpp:1323
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
Definition qlayout.cpp:186
QSize minimumSize() const override
Returns the minimum size of this layout.
Definition qlayout.cpp:912
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:199
virtual int indexOf(const QWidget *) const
Searches for widget widget in this layout (not including child layouts).
Definition qlayout.cpp:1177
void setContentsMargins(int left, int top, int right, int bottom)
Definition qlayout.cpp:288
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
iterator insert(const Key &key, const T &value)
Definition qmap.h:688
iterator find(const Key &key)
Definition qmap.h:641
iterator begin()
Definition qmap.h:598
iterator end()
Definition qmap.h:602
const_iterator constBegin() const
Definition qmap.h:600
const_iterator constEnd() const
Definition qmap.h:604
\inmodule QtCore
Definition qmargins.h:24
The QMdiArea widget provides an area in which MDI windows are displayed.
Definition qmdiarea.h:21
@ TabbedView
Definition qmdiarea.h:50
QPointer< QWidget > restoreFocusWidget
QStyle::SubControl hoveredSubControl
void sizeParameters(int *margin, int *minWidth) const
void setVisible(WindowStateAction, bool visible=true)
void updateWindowTitle(bool requestFromChild)
void setEnabled(WindowStateAction, bool enable=true)
QPointer< QMdi::ControlContainer > controlContainer
QRegion getRegion(Operation operation) const
QPointer< QAction > actions[NumWindowStateActions]
QPalette desktopPalette() const
QString originalWindowTitleHelper() const
QStyleOptionTitleBar cachedStyleOptions
Operation getOperation(const QPoint &pos) const
bool drawTitleBarWhenMaximized() const
OperationInfoMap operationMap
void _q_processFocusChanged(QWidget *old, QWidget *now)
QPointer< QMenu > systemMenu
void ensureWindowState(Qt::WindowState state)
QPointer< QWidget > baseWidget
void setActive(bool activate, bool changeFocus=true)
QStyle::SubControl activeSubControl
bool hasBorder(const QStyleOptionTitleBar &options) const
void setNewGeometry(const QPoint &pos)
void setWindowFlags(Qt::WindowFlags windowFlags) override
QStyleOptionTitleBar titleBarOptions() const
Qt::FocusReason focusInReason
QMdiSubWindow::SubWindowOptions options
The QMdiSubWindow class provides a subwindow class for QMdiArea.
void setKeyboardPageStep(int step)
void showShaded()
Calling this function makes the subwindow enter the shaded mode.
void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override
\reimp
void focusInEvent(QFocusEvent *focusInEvent) override
\reimp
void leaveEvent(QEvent *leaveEvent) override
\reimp
void resizeEvent(QResizeEvent *resizeEvent) override
\reimp
QSize minimumSizeHint() const override
\reimp
void childEvent(QChildEvent *childEvent) override
\reimp
bool eventFilter(QObject *object, QEvent *event) override
\reimp
bool event(QEvent *event) override
\reimp
QWidget * maximizedSystemMenuIconWidget() const
void changeEvent(QEvent *changeEvent) override
\reimp
int keyboardSingleStep
sets how far a widget should move or resize when using the keyboard arrow keys.
void mousePressEvent(QMouseEvent *mouseEvent) override
\reimp
void setKeyboardSingleStep(int step)
bool testOption(SubWindowOption) const
Returns true if option is enabled; otherwise returns false.
void focusOutEvent(QFocusEvent *focusOutEvent) override
\reimp
SubWindowOption
This enum describes options that customize the behavior of QMdiSubWindow.
@ AllowOutsideAreaHorizontally
QMdiSubWindow(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructs a new QMdiSubWindow widget.
QWidget * maximizedButtonsWidget() const
void windowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState)
QMdiSubWindow emits this signal after the window state changes.
void hideEvent(QHideEvent *hideEvent) override
\reimp
void closeEvent(QCloseEvent *closeEvent) override
\reimp
QSize sizeHint() const override
\reimp
void setOption(SubWindowOption option, bool on=true)
If on is true, option is enabled on the subwindow; otherwise it is disabled.
bool isShaded() const
Returns true if this window is shaded; otherwise returns false.
void keyPressEvent(QKeyEvent *keyEvent) override
\reimp
void contextMenuEvent(QContextMenuEvent *contextMenuEvent) override
\reimp
QWidget * widget() const
Returns the current internal widget.
~QMdiSubWindow()
Destroys the subwindow.
void showEvent(QShowEvent *showEvent) override
\reimp
QMdiArea * mdiArea() const
void mouseReleaseEvent(QMouseEvent *mouseEvent) override
\reimp
void setWidget(QWidget *widget)
Sets widget as the internal widget of this subwindow.
int keyboardPageStep
sets how far a widget should move or resize when using the keyboard page keys.
void timerEvent(QTimerEvent *timerEvent) override
\reimp
void paintEvent(QPaintEvent *paintEvent) override
\reimp
void mouseMoveEvent(QMouseEvent *mouseEvent) override
\reimp
void moveEvent(QMoveEvent *moveEvent) override
\reimp
QWidget * controllerWidget() const
QWidget * systemMenuLabel() const
void updateWindowIcon(const QIcon &windowIcon)
ControlContainer(QMdiSubWindow *mdiChild)
QSize sizeHint() const override
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void mousePressEvent(QMouseEvent *mouseEvent) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseReleaseEvent(QMouseEvent *mouseEvent) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
ControlLabel(QMdiSubWindow *subWindow, QWidget *parent=nullptr)
void paintEvent(QPaintEvent *paintEvent) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void mousePressEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent=nullptr)
void mouseReleaseEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible)
void mouseMoveEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void leaveEvent(QEvent *event) override
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
QSize sizeHint() const override
bool hasVisibleControls() const
void paintEvent(QPaintEvent *event) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
The QMenuBar class provides a horizontal menu bar.
Definition qmenubar.h:20
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,...
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,...
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition qmenu.cpp:1921
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
\inmodule QtGui
Definition qevent.h:196
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:502
QObject * parent
Definition qobject.h:73
\inmodule QtCore
Definition qobject.h:103
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
This is an overloaded function that will start a timer of type timerType and a timeout of interval mi...
Definition qobject.cpp:1817
T findChild(QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
Definition qobject.h:155
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
Definition qobject.cpp:2339
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
Definition qobject.cpp:1555
void removeEventFilter(QObject *obj)
Removes an event filter object obj from this object.
Definition qobject.cpp:2370
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition qobject.h:348
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition qobject.cpp:1912
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
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.
void setFont(const QFont &f)
Sets the painter's font to the given font.
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.
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
Definition qpalette.h:65
@ Inactive
Definition qpalette.h:49
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:146
@ HighlightedText
Definition qpalette.h:53
@ Highlight
Definition qpalette.h:53
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
void clear() noexcept
Definition qpointer.h:87
bool isNull() const noexcept
Definition qpointer.h:84
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:373
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:170
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:387
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr void setTopLeft(const QPoint &p) noexcept
Set the top-left corner of the rectangle to the given position.
Definition qrect.h:203
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary.
Definition qrubberband.h:18
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition qscrollbar.h:20
bool contains(const T &value) const
Definition qset.h:71
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
Definition qevent.h:123
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:116
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition qevent.h:117
The QSizeGrip class provides a resize handle for resizing top-level windows.
Definition qsizegrip.h:16
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition qsize.h:192
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:136
constexpr bool isNull() const noexcept
Returns true if both the width and height is 0; otherwise returns false.
Definition qsize.h:121
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:127
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3824
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1252
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8870
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.h:1369
The QStyleHintReturnMask class provides style hints that return a QRegion.
\variable QStyleOptionMenuItem::menuItemType
QStyle::SubControls subControls
QStyle::SubControls activeSubControls
\variable QStyleOptionFocusRect::backgroundColor
\variable QStyleOptionToolBox::selectedPosition
Qt::WindowFlags titleBarFlags
QFontMetrics fontMetrics
QStyle::State state
QPalette palette
void initFrom(const QWidget *w)
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
@ State_MouseOver
Definition qstyle.h:80
@ State_Sunken
Definition qstyle.h:69
@ State_Active
Definition qstyle.h:83
@ CT_MdiControls
Definition qstyle.h:568
virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget=nullptr) const =0
Draws the given control using the provided painter with the style options specified by option.
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=nullptr) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
virtual QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ SH_TitleBar_ShowToolTipsOnButtons
Definition qstyle.h:699
@ SH_WindowFrame_Mask
Definition qstyle.h:640
@ SH_Workspace_FillSpaceOnMaximize
Definition qstyle.h:609
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ SP_TitleBarCloseButton
Definition qstyle.h:720
@ SP_TitleBarMenuButton
Definition qstyle.h:717
@ SP_TitleBarMinButton
Definition qstyle.h:718
@ SP_TitleBarMaxButton
Definition qstyle.h:719
@ SP_TitleBarNormalButton
Definition qstyle.h:721
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=nullptr) const =0
Returns the sub control at the given position in the given complex control (with the style options sp...
@ PM_TitleBarButtonIconSize
Definition qstyle.h:533
@ PM_TitleBarButtonSize
Definition qstyle.h:534
@ PM_TitleBarHeight
Definition qstyle.h:448
@ PM_SizeGripSize
Definition qstyle.h:504
@ PM_MdiSubWindowFrameWidth
Definition qstyle.h:473
@ PM_MdiSubWindowMinimizedWidth
Definition qstyle.h:474
ComplexControl
This enum describes the available complex controls.
Definition qstyle.h:331
@ CC_MdiControls
Definition qstyle.h:340
@ CC_TitleBar
Definition qstyle.h:337
@ PE_FrameWindow
Definition qstyle.h:112
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
@ SC_TitleBarMinButton
Definition qstyle.h:377
@ SC_TitleBarLabel
Definition qstyle.h:384
@ SC_TitleBarUnshadeButton
Definition qstyle.h:382
@ SC_MdiMinButton
Definition qstyle.h:395
@ SC_TitleBarNormalButton
Definition qstyle.h:380
@ SC_MdiNormalButton
Definition qstyle.h:396
@ SC_All
Definition qstyle.h:400
@ SC_MdiCloseButton
Definition qstyle.h:397
@ SC_TitleBarShadeButton
Definition qstyle.h:381
@ SC_None
Definition qstyle.h:348
@ SC_TitleBarSysMenu
Definition qstyle.h:376
@ SC_TitleBarMaxButton
Definition qstyle.h:378
@ SC_TitleBarCloseButton
Definition qstyle.h:379
@ SC_TitleBarContextHelpButton
Definition qstyle.h:383
\inmodule QtCore
Definition qcoreevent.h:366
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr, const QRect &rect={}, int msecShowTime=-1)
Shows text as a tool tip, with the global position pos as the point of interest.
Definition qtooltip.cpp:439
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
static void enterWhatsThisMode()
This function switches the user interface into "What's This?" mode.
virtual void setWindowFlags(Qt::WindowFlags windowFlags)
QLayout * layout
Definition qwidget_p.h:651
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
bool windowModified
whether the document shown in the window has unsaved changes
Definition qwidget.h:155
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4313
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.g.
Definition qwidget.h:803
bool autoFillBackground
whether the widget background is filled automatically
Definition qwidget.h:172
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition qwidget.cpp:9461
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,...
Definition qwidget.cpp:7590
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
void setMinimumSize(const QSize &)
Definition qwidget.h:832
void setSizePolicy(QSizePolicy)
bool isMinimized() const
Definition qwidget.cpp:2836
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition qwidget.h:877
QWidget * nextInFocusChain() const
Returns the next widget in this widget's focus chain.
Definition qwidget.cpp:6845
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
void clearFocus()
Takes keyboard input focus from the widget.
Definition qwidget.cpp:6683
QSize minimumSize
the widget's minimum size
Definition qwidget.h:120
friend Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
virtual void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition qwidget.cpp:9483
void showMinimized()
Shows the widget minimized, as an icon.
Definition qwidget.cpp:2847
void setMouseTracking(bool enable)
Definition qwidget.h:853
virtual void mouseDoubleClickEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
Definition qwidget.cpp:9530
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
bool isMaximized() const
Definition qwidget.cpp:2876
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7667
void overrideWindowState(Qt::WindowStates state)
Definition qwidget.cpp:2900
bool close()
Closes this widget.
Definition qwidget.cpp:8562
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6828
virtual void mouseReleaseEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition qwidget.cpp:9508
bool isLeftToRight() const
Definition qwidget.h:420
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7822
virtual void moveEvent(QMoveEvent *event)
This event handler can be reimplemented in a subclass to receive widget move events which are passed ...
Definition qwidget.cpp:9801
void hide()
Hides the widget.
Definition qwidget.cpp:8135
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
virtual void setVisible(bool visible)
Definition qwidget.cpp:8255
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
QIcon windowIcon
the widget's icon
Definition qwidget.h:152
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9382
void showMaximized()
Shows the widget maximized.
Definition qwidget.cpp:3044
bool isRightToLeft() const
Definition qwidget.h:419
void setWindowModified(bool)
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
bool isWindowModified() const
QStyle * style() const
Definition qwidget.cpp:2600
void setWindowIcon(const QIcon &icon)
Definition qwidget.cpp:6174
QFont font
the font currently set for the widget
Definition qwidget.h:133
void resize(int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:883
QString windowTitle
the window title (caption)
Definition qwidget.h:151
bool hasFocus() const
Definition qwidget.cpp:6446
virtual void resizeEvent(QResizeEvent *event)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition qwidget.cpp:9822
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition qwidget.h:140
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QCursor cursor
the cursor shape for this widget
Definition qwidget.h:135
Qt::WindowStates windowState() const
Returns the current window state.
Definition qwidget.cpp:2888
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:8822
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition qwidget.cpp:3060
QPointF mapToParent(const QPointF &) const
Translates the widget coordinate pos to a coordinate in the parent widget.
Definition qwidget.cpp:4263
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:4082
virtual void paintEvent(QPaintEvent *event)
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Definition qwidget.cpp:9783
virtual void showEvent(QShowEvent *event)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
bool isVisible() const
Definition qwidget.h:874
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
bool visible
whether the widget is visible
Definition qwidget.h:144
\inmodule QtGui
Definition qevent.h:899
Qt::WindowStates oldState() const
Returns the state of the window before the change.
Definition qevent.h:904
QOpenGLWidget * widget
[1]
QString text
bool focus
[0]
QSet< QString >::iterator it
opt iconSize
rect
[4]
QStyleOptionButton opt
else opt state
[0]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
Definition qcompare.h:63
WindowState
Definition qnamespace.h:251
@ WindowFullScreen
Definition qnamespace.h:255
@ WindowNoState
Definition qnamespace.h:252
@ WindowMinimized
Definition qnamespace.h:253
@ WindowMaximized
Definition qnamespace.h:254
@ WindowActive
Definition qnamespace.h:256
@ TopRightCorner
@ TopLeftCorner
@ AlignRight
Definition qnamespace.h:146
@ AlignBottom
Definition qnamespace.h:154
@ LeftButton
Definition qnamespace.h:58
@ WA_CanHostQMdiSubWindowTitleBar
Definition qnamespace.h:368
@ WA_Resized
Definition qnamespace.h:308
@ WA_DeleteOnClose
Definition qnamespace.h:321
@ NoFocus
Definition qnamespace.h:107
@ StrongFocus
Definition qnamespace.h:110
@ SizeHorCursor
@ SizeVerCursor
@ SizeFDiagCursor
@ ArrowCursor
@ SizeBDiagCursor
@ Key_Escape
Definition qnamespace.h:663
@ Key_Return
Definition qnamespace.h:667
@ Key_Right
Definition qnamespace.h:679
@ Key_Enter
Definition qnamespace.h:668
@ Key_Left
Definition qnamespace.h:677
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ ShiftModifier
@ CustomizeWindowHint
Definition qnamespace.h:239
@ FramelessWindowHint
Definition qnamespace.h:225
@ MSWindowsFixedSizeDialogHint
Definition qnamespace.h:221
@ WindowType_Mask
Definition qnamespace.h:220
@ WindowStaysOnTopHint
Definition qnamespace.h:233
@ WindowMaximizeButtonHint
Definition qnamespace.h:229
@ WindowMinimizeButtonHint
Definition qnamespace.h:228
@ Dialog
Definition qnamespace.h:208
@ WindowShadeButtonHint
Definition qnamespace.h:232
@ WindowMinMaxButtonsHint
Definition qnamespace.h:230
@ SubWindow
Definition qnamespace.h:216
@ WindowTitleHint
Definition qnamespace.h:226
@ WindowSystemMenuHint
Definition qnamespace.h:227
@ WindowCloseButtonHint
Definition qnamespace.h:241
@ ElideRight
Definition qnamespace.h:190
@ BacktabFocusReason
@ TabFocusReason
#define Q_UNLIKELY(x)
#define qApp
@ None
Definition qhash.cpp:531
static int area(const QSize &s)
Definition qicon.cpp:153
#define qWarning
Definition qlogging.h:166
static bool isChildOfQMdiSubWindow(const QWidget *child)
static const Qt::WindowFlags CustomizeWindowFlags
static const QStyle::SubControl SubControls[]
static int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag, int delta, int maxDelta, int minDelta)
static bool isHoverControl(QStyle::SubControl control)
static int getResizeDeltaComponent(uint cflags, uint resizeFlag, uint resizeReverseFlag, int delta)
static bool isMacStyle(QStyle *style)
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:5992
static const int NumSubControls
static ControlElement< T > * ptr(QWidget *widget)
static const int BoundaryMargin
static bool isChildOfTabbedQMdiArea(const QMdiSubWindow *child)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLint GLenum GLsizei GLsizei GLsizei GLint border
GLint GLsizei width
GLuint GLsizei const GLchar * label
[43]
GLbitfield flags
GLboolean enable
GLenum GLuint GLintptr offset
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint GLenum option
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
#define QT_CONFIG(feature)
#define Q_OBJECT
#define signals
#define emit
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34
QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget)
Returns a modified window title with the [*] place holder replaced according to the rules described i...
Definition qwidget.cpp:5992
Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
static void showSystemMenu(QWindow *w)
if(qFloatDistance(a, b)<(1<< 7))
[0]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QObject::connect nullptr
QVBoxLayout * layout
QString title
[35]
timer inherits("QTimer")
app setAttribute(Qt::AA_DontShowIconsInMenus)
QLayoutItem * child
[0]
QPainter painter(this)
[7]
groupBox setLayout(vbox)
QMenuBar * menuBar
[0]
scrollArea setBackgroundRole(QPalette::Dark)