📄 qmdisubwindow.cpp
字号:
isInInteractiveMode = true; q->setFocus();#ifndef QT_NO_RUBBERBAND if ((q->testOption(QMdiSubWindow::RubberBandResize) && (currentOperation == BottomRightResize || currentOperation == BottomLeftResize)) || (q->testOption(QMdiSubWindow::RubberBandMove) && currentOperation == Move)) { enterRubberBandMode(); } else#endif // QT_NO_RUBBERBAND { q->grabMouse(); }#endif // QT_NO_ACTION}/*! \internal*/void QMdiSubWindowPrivate::_q_processFocusChanged(QWidget *old, QWidget *now){ Q_UNUSED(old); Q_Q(QMdiSubWindow); if (now && (now == q || q->isAncestorOf(now))) { if (now == q && !isInInteractiveMode) setFocusWidget(); setActive(true); }}/*! \internal*/void QMdiSubWindowPrivate::leaveInteractiveMode(){ Q_Q(QMdiSubWindow);#ifndef QT_NO_RUBBERBAND if (isInRubberBandMode) leaveRubberBandMode(); else#endif q->releaseMouse(); isInInteractiveMode = false; currentOperation = None; updateDirtyRegions(); updateCursor(); if (baseWidget && baseWidget->focusWidget()) baseWidget->focusWidget()->setFocus();}/*! \internal*/void QMdiSubWindowPrivate::removeBaseWidget(){ if (!baseWidget) return; Q_Q(QMdiSubWindow); q->removeEventFilter(baseWidget); if (QLayout *layout = q->layout()) layout->removeWidget(baseWidget); if (baseWidget->windowTitle() == q->windowTitle()) { ignoreWindowTitleChange = true; q->setWindowTitle(QString()); ignoreWindowTitleChange = false; q->setWindowModified(false); } lastChildWindowTitle.clear(); baseWidget->setParent(0); baseWidget = 0; isWidgetHiddenByUs = false;}/*! \internal*/void QMdiSubWindowPrivate::initOperationMap(){ operationMap.insert(Move, OperationInfo(HMove | VMove, Qt::ArrowCursor, false)); operationMap.insert(TopResize, OperationInfo(VMove | VResize | VResizeReverse, Qt::SizeVerCursor)); operationMap.insert(BottomResize, OperationInfo(VResize, Qt::SizeVerCursor)); operationMap.insert(LeftResize, OperationInfo(HMove | HResize | HResizeReverse, Qt::SizeHorCursor)); operationMap.insert(RightResize, OperationInfo(HResize, Qt::SizeHorCursor)); operationMap.insert(TopLeftResize, OperationInfo(HMove | VMove | HResize | VResize | VResizeReverse | HResizeReverse, Qt::SizeFDiagCursor)); operationMap.insert(TopRightResize, OperationInfo(VMove | HResize | VResize | VResizeReverse, Qt::SizeBDiagCursor)); operationMap.insert(BottomLeftResize, OperationInfo(HMove | HResize | VResize | HResizeReverse, Qt::SizeBDiagCursor)); operationMap.insert(BottomRightResize, OperationInfo(HResize | VResize, Qt::SizeFDiagCursor));}#ifndef QT_NO_MENU/*! \internal*/void QMdiSubWindowPrivate::createSystemMenu(){ Q_Q(QMdiSubWindow); Q_ASSERT_X(q, "QMdiSubWindowPrivate::createSystemMenu", "You can NOT call this function before QMdiSubWindow's ctor"); systemMenu = new QMenu(q); const QStyle *style = q->style(); addToSystemMenu(RestoreAction, QMdiSubWindow::tr("&Restore"), SLOT(showNormal())); actions[RestoreAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarNormalButton)); actions[RestoreAction]->setEnabled(false); addToSystemMenu(MoveAction, QMdiSubWindow::tr("&Move"), SLOT(_q_enterInteractiveMode())); addToSystemMenu(ResizeAction, QMdiSubWindow::tr("&Size"), SLOT(_q_enterInteractiveMode())); addToSystemMenu(MinimizeAction, QMdiSubWindow::tr("Mi&nimize"), SLOT(showMinimized())); actions[MinimizeAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarMinButton)); addToSystemMenu(MaximizeAction, QMdiSubWindow::tr("Ma&ximize"), SLOT(showMaximized())); actions[MaximizeAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarMaxButton)); addToSystemMenu(StayOnTopAction, QMdiSubWindow::tr("Stay on &Top"), SLOT(_q_updateStaysOnTopHint())); actions[StayOnTopAction]->setCheckable(true); systemMenu->addSeparator(); addToSystemMenu(CloseAction, QMdiSubWindow::tr("&Close"), SLOT(close())); actions[CloseAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarCloseButton));#if !defined(QT_NO_SHORTCUT) actions[CloseAction]->setShortcut(QKeySequence::Close);#endif updateActions();}#endif/*! \internal*/void QMdiSubWindowPrivate::updateCursor(){#ifndef QT_NO_CURSOR Q_Q(QMdiSubWindow);#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) if (qobject_cast<QMacStyle *>(q->style())) return;#endif if (currentOperation == None) { q->unsetCursor(); return; } if (currentOperation == Move || operationMap.find(currentOperation).value().hover) { q->setCursor(operationMap.find(currentOperation).value().cursorShape); return; }#endif}/*! \internal*/void QMdiSubWindowPrivate::updateDirtyRegions(){ // No update necessary if (!q_func()->parent()) return; foreach (Operation operation, operationMap.keys()) operationMap.find(operation).value().region = getRegion(operation);}/*! \internal*/void QMdiSubWindowPrivate::updateGeometryConstraints(){ Q_Q(QMdiSubWindow); if (!q->parent()) return; internalMinimumSize = q->minimumSizeHint(); int margin, minWidth; sizeParameters(&margin, &minWidth); q->setContentsMargins(margin, titleBarHeight(), margin, margin); if (q->isMaximized() || (q->isMinimized() && !q->isShaded())) { moveEnabled = false; resizeEnabled = false; } else { moveEnabled = true; if ((q->windowFlags() & Qt::MSWindowsFixedSizeDialogHint) || q->isShaded()) resizeEnabled = false; else resizeEnabled = true; } updateDirtyRegions();}/*! \internal*/void QMdiSubWindowPrivate::updateMask(){ Q_Q(QMdiSubWindow); if (!q->mask().isEmpty()) q->clearMask(); if (!q->parent()) return; if (q->isMaximized() && !drawTitleBarWhenMaximized() || q->windowFlags() & Qt::FramelessWindowHint) return; if (resizeTimerId == -1) cachedStyleOptions = titleBarOptions(); cachedStyleOptions.rect = q->rect(); QStyleHintReturnMask frameMask; q->style()->styleHint(QStyle::SH_WindowFrame_Mask, &cachedStyleOptions, q, &frameMask); if (!frameMask.region.isEmpty()) q->setMask(frameMask.region);}/*! \internal*/void QMdiSubWindowPrivate::setNewGeometry(const QPoint &pos){ Q_Q(QMdiSubWindow); Q_ASSERT(currentOperation != None); Q_ASSERT(q->parent()); uint cflags = operationMap.find(currentOperation).value().changeFlags; int posX = pos.x(); int posY = pos.y(); const bool restrictHorizontal = !q->testOption(QMdiSubWindow::AllowOutsideAreaHorizontally); const bool restrictVertical = !q->testOption(QMdiSubWindow::AllowOutsideAreaVertically); if (restrictHorizontal || restrictVertical) { QRect parentRect = q->parentWidget()->rect(); if (restrictVertical && (cflags & VResizeReverse || currentOperation == Move)) { posY = qMin(qMax(mousePressPosition.y() - oldGeometry.y(), posY), parentRect.height() - BoundaryMargin); } if (currentOperation == Move) { if (restrictHorizontal) posX = qMin(qMax(BoundaryMargin, posX), parentRect.width() - BoundaryMargin); if (restrictVertical) posY = qMin(posY, parentRect.height() - BoundaryMargin); } else { if (restrictHorizontal) { if (cflags & HResizeReverse) posX = qMax(mousePressPosition.x() - oldGeometry.x(), posX); else posX = qMin(parentRect.width() - (oldGeometry.x() + oldGeometry.width() - mousePressPosition.x()), posX); } if (restrictVertical && !(cflags & VResizeReverse)) { posY = qMin(parentRect.height() - (oldGeometry.y() + oldGeometry.height() - mousePressPosition.y()), posY); } } } QRect geometry; if (cflags & (HMove | VMove)) { int dx = getMoveDeltaComponent(cflags, HMove, HResize, posX - mousePressPosition.x(), oldGeometry.width() - internalMinimumSize.width(), oldGeometry.width() - q->maximumWidth()); int dy = getMoveDeltaComponent(cflags, VMove, VResize, posY - mousePressPosition.y(), oldGeometry.height() - internalMinimumSize.height(), oldGeometry.height() - q->maximumHeight()); geometry.setTopLeft(oldGeometry.topLeft() + QPoint(dx, dy)); } else { geometry.setTopLeft(q->geometry().topLeft()); } if (cflags & (HResize | VResize)) { int dx = getResizeDeltaComponent(cflags, HResize, HResizeReverse, posX - mousePressPosition.x()); int dy = getResizeDeltaComponent(cflags, VResize, VResizeReverse, posY - mousePressPosition.y()); geometry.setSize(oldGeometry.size() + QSize(dx, dy)); } else { geometry.setSize(q->geometry().size()); } setNewGeometry(&geometry);}/*! \internal*/void QMdiSubWindowPrivate::setMinimizeMode(){ Q_Q(QMdiSubWindow); Q_ASSERT(q->parent()); ensureWindowState(Qt::WindowMinimized); isShadeRequestFromMinimizeMode = true; q->showShaded(); isShadeRequestFromMinimizeMode = false; moveEnabled = false;#ifndef QT_NO_ACTION setEnabled(MoveAction, moveEnabled);#endif Q_ASSERT(q->windowState() & Qt::WindowMinimized); Q_ASSERT(!(q->windowState() & Qt::WindowMaximized)); // This should be a valid assert, but people can actually re-implement // setVisible and do crazy stuff, so we're not guaranteed that // the widget is hidden after calling hide(). // Q_ASSERT(baseWidget ? baseWidget->isHidden() : true); setActive(true);}/*! \internal*/void QMdiSubWindowPrivate::setNormalMode(){ Q_Q(QMdiSubWindow); Q_ASSERT(q->parent()); isShadeMode = false; isMaximizeMode = false; ensureWindowState(Qt::WindowNoState);#ifndef QT_NO_MENUBAR removeButtonsFromMenuBar();#endif // Hide the window before we change the geometry to avoid multiple resize // events and wrong window state. const bool wasVisible = q->isVisible(); if (wasVisible) q->setVisible(false); // Restore minimum size if set by user. if (userMinimumSize.isValid()) { q->setMinimumSize(userMinimumSize); userMinimumSize = QSize(-1, -1); } // Show the internal widget if it was hidden by us, if (baseWidget && isWidgetHiddenByUs) { baseWidget->show(); isWidgetHiddenByUs = false; } updateGeometryConstraints(); QRect newGeometry = oldGeometry; newGeometry.setSize(restoreSize.expandedTo(internalMinimumSize)); q->setGeometry(newGeometry); if (wasVisible) q->setVisible(true); // Invalidate the restore size. restoreSize.setWidth(-1); restoreSize.setHeight(-1);#ifndef QT_NO_SIZEGRIP setSizeGripVisible(true);#endif#ifndef QT_NO_ACTION setEnabled(MoveAction, true); setEnabled(MaximizeAction, true); setEnabled(MinimizeAction, true); setEnabled(RestoreAction, false); setEnabled(ResizeAction, resizeEnabled);#endif // QT_NO_ACTION Q_ASSERT(!(q_func()->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized))); Q_ASSERT(!isShadeMode); setActive(true); restoreFocus(); updateMask();}/*! \internal*/void QMdiSubWindowPrivate::setMaximizeMode(){ Q_Q(QMdiSubWindow); Q_ASSERT(q->parent()); ensureWindowState(Qt::WindowMaximized); isShadeMode = false; isMaximizeMode = true; if (!restoreFocusWidget && q->isAncestorOf(QApplication::focusWidget())) restoreFocusWidget = QApplication::focusWidget();#ifndef QT_NO_SIZEGRIP setSizeGripVisible(false);#endif // Store old geometry and set restore size if not already set. if (!restoreSize.isValid()) { oldGeometry = q->geometry(); restoreSize.setWidth(oldGeometry.width()); restoreSize.setHeight(oldGeometry.height()); } // Hide the window before we change the geometry to avoid multiple resize // events and wrong window state. const bool wasVisible = q->isVisible(); if (wasVisible) q->setVisible(false); // Show the internal widget if it was hidden by us. if (baseWidget && isWidgetHiddenByUs) { baseWidget->show(); isWidgetHiddenByUs = false; } updateGeometryConstraints(); if (!drawTitleBarWhenMaximized() && wasVisible) {#ifndef QT_NO_MAINWINDOW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -