diff options
Diffstat (limited to 'src/widgets/widgets/qmdisubwindow.cpp')
-rw-r--r-- | src/widgets/widgets/qmdisubwindow.cpp | 329 |
1 files changed, 140 insertions, 189 deletions
diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index e9511f944f..d8700e3df2 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only /*! \class QMdiSubWindow @@ -154,7 +118,9 @@ #if QT_CONFIG(whatsthis) #include <QWhatsThis> #endif +#if QT_CONFIG(tooltip) #include <QToolTip> +#endif #if QT_CONFIG(mainwindow) #include <QMainWindow> #endif @@ -162,13 +128,18 @@ #include <QDebug> #include <QMdiArea> #include <QScopedValueRollback> -#include <QAction> +#if QT_CONFIG(action) +# include <qaction.h> +#endif #if QT_CONFIG(menu) #include <QMenu> #endif +#include <QProxyStyle> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + using namespace QMdi; static const QStyle::SubControl SubControls[] = @@ -199,7 +170,9 @@ static const int BoundaryMargin = 5; static inline bool isMacStyle(QStyle *style) { - return style->inherits("QMacStyle"); + auto proxyStyle = qobject_cast<QProxyStyle *>(style); + auto styleToCheck = proxyStyle ? proxyStyle->baseStyle() : style; + return styleToCheck->inherits("QMacStyle"); } static inline int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag, @@ -253,16 +226,33 @@ static inline ControlElement<T> *ptr(QWidget *widget) && strcmp(widget->metaObject()->className(), T::staticMetaObject.className()) == 0) { return static_cast<ControlElement<T> *>(widget); } - return 0; + return nullptr; +} + +QString QMdiSubWindowPrivate::originalWindowTitleHelper() const +{ + Q_Q(const QMdiSubWindow); + // QTBUG-92240: When DontMaximizeSubWindowOnActivation is set and + // there is another subwindow maximized, use its original title. + if (auto *mdiArea = q->mdiArea()) { + const auto &subWindows = mdiArea->subWindowList(); + for (auto *subWindow : subWindows) { + if (subWindow != q && subWindow->isMaximized()) { + auto *subWindowD = static_cast<QMdiSubWindowPrivate *>(qt_widget_private(subWindow)); + if (!subWindowD->originalTitle.isNull()) + return subWindowD->originalTitle; + } + } + } + return q->window()->windowTitle(); } QString QMdiSubWindowPrivate::originalWindowTitle() { - Q_Q(QMdiSubWindow); if (originalTitle.isNull()) { - originalTitle = q->window()->windowTitle(); + originalTitle = originalWindowTitleHelper(); if (originalTitle.isNull()) - originalTitle = QLatin1String(""); + originalTitle = ""_L1; } return originalTitle; } @@ -275,11 +265,17 @@ void QMdiSubWindowPrivate::setNewWindowTitle() return; QString original = originalWindowTitle(); if (!original.isEmpty()) { - if (!original.contains(QMdiSubWindow::tr("- [%1]").arg(childTitle))) - q->window()->setWindowTitle(QMdiSubWindow::tr("%1 - [%2]").arg(original, childTitle)); + if (!original.contains(QMdiSubWindow::tr("- [%1]").arg(childTitle))) { + auto title = QMdiSubWindow::tr("%1 - [%2]").arg(original, childTitle); + ignoreWindowTitleChange = true; + q->window()->setWindowTitle(title); + ignoreWindowTitleChange = false; + } } else { + ignoreWindowTitleChange = true; q->window()->setWindowTitle(childTitle); + ignoreWindowTitleChange = false; } } @@ -288,14 +284,7 @@ static inline bool isHoverControl(QStyle::SubControl control) return control != QStyle::SC_None && control != QStyle::SC_TitleBarLabel; } -#if 0 // Used to be included in Qt4 for Q_WS_WIN -static inline QRgb colorref2qrgb(COLORREF col) -{ - return qRgb(GetRValue(col),GetGValue(col),GetBValue(col)); -} -#endif - -#ifndef QT_NO_TOOLTIP +#if QT_CONFIG(tooltip) static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOptionComplex &opt, QStyle::ComplexControl complexControl, QStyle::SubControl subControl) { @@ -360,7 +349,7 @@ static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOpti const QRect rect = widget->style()->subControlRect(complexControl, &opt, subControl, widget); QToolTip::showText(helpEvent->globalPos(), toolTip, widget, rect); } -#endif // QT_NO_TOOLTIP +#endif // QT_CONFIG(tooltip) namespace QMdi { /* @@ -371,7 +360,7 @@ class ControlLabel : public QWidget { Q_OBJECT public: - ControlLabel(QMdiSubWindow *subWindow, QWidget *parent = 0); + ControlLabel(QMdiSubWindow *subWindow, QWidget *parent = nullptr); QSize sizeHint() const override; @@ -399,7 +388,7 @@ ControlLabel::ControlLabel(QMdiSubWindow *subWindow, QWidget *parent) Q_UNUSED(subWindow); setFocusPolicy(Qt::NoFocus); updateWindowIcon(); - setFixedSize(label.size()); + setFixedSize(label.deviceIndependentSize().toSize()); } /* @@ -407,7 +396,7 @@ ControlLabel::ControlLabel(QMdiSubWindow *subWindow, QWidget *parent) */ QSize ControlLabel::sizeHint() const { - return label.size(); + return label.deviceIndependentSize().toSize(); } /* @@ -421,7 +410,7 @@ bool ControlLabel::event(QEvent *event) updateWindowIcon(); setFixedSize(label.size()); } -#ifndef QT_NO_TOOLTIP +#if QT_CONFIG(tooltip) else if (event->type() == QEvent::ToolTip) { QStyleOptionTitleBar options; options.initFrom(this); @@ -488,8 +477,8 @@ void ControlLabel::updateWindowIcon() { QIcon menuIcon = windowIcon(); if (menuIcon.isNull()) - menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, parentWidget()); - const int iconSize = style()->pixelMetric(QStyle::PM_TitleBarButtonIconSize, 0, parentWidget()); + menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, nullptr, parentWidget()); + const int iconSize = style()->pixelMetric(QStyle::PM_TitleBarButtonIconSize, nullptr, parentWidget()); label = menuIcon.pixmap(iconSize); update(); } @@ -503,7 +492,7 @@ class ControllerWidget : public QWidget { Q_OBJECT public: - ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent = 0); + ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent = nullptr); QSize sizeHint() const override; void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible); inline bool hasVisibleControls() const @@ -549,7 +538,7 @@ ControllerWidget::ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent) activeControl(QStyle::SC_None), hoverControl(QStyle::SC_None), visibleControls(QStyle::SC_None), - mdiArea(0) + mdiArea(nullptr) { if (subWindow->parentWidget()) mdiArea = qobject_cast<QMdiArea *>(subWindow->parentWidget()->parentWidget()); @@ -616,7 +605,7 @@ void ControllerWidget::mousePressEvent(QMouseEvent *event) event->ignore(); return; } - activeControl = getSubControl(event->pos()); + activeControl = getSubControl(event->position().toPoint()); update(); } @@ -630,7 +619,7 @@ void ControllerWidget::mouseReleaseEvent(QMouseEvent *event) return; } - QStyle::SubControl under_mouse = getSubControl(event->pos()); + QStyle::SubControl under_mouse = getSubControl(event->position().toPoint()); if (under_mouse == activeControl) { switch (activeControl) { case QStyle::SC_MdiCloseButton: @@ -656,7 +645,7 @@ void ControllerWidget::mouseReleaseEvent(QMouseEvent *event) */ void ControllerWidget::mouseMoveEvent(QMouseEvent *event) { - QStyle::SubControl under_mouse = getSubControl(event->pos()); + QStyle::SubControl under_mouse = getSubControl(event->position().toPoint()); //test if hover state changes if (hoverControl != under_mouse) { hoverControl = under_mouse; @@ -678,14 +667,14 @@ void ControllerWidget::leaveEvent(QEvent * /*event*/) */ bool ControllerWidget::event(QEvent *event) { -#ifndef QT_NO_TOOLTIP +#if QT_CONFIG(tooltip) if (event->type() == QEvent::ToolTip) { QStyleOptionComplex opt; initStyleOption(&opt); QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); showToolTip(helpEvent, this, opt, QStyle::CC_MdiControls, getSubControl(helpEvent->pos())); } -#endif // QT_NO_TOOLTIP +#endif // QT_CONFIG(tooltip) return QWidget::event(event); } @@ -704,10 +693,10 @@ void ControllerWidget::initStyleOption(QStyleOptionComplex *option) const */ ControlContainer::ControlContainer(QMdiSubWindow *mdiChild) : QObject(mdiChild), - previousLeft(0), - previousRight(0), + previousLeft(nullptr), + previousRight(nullptr), #if QT_CONFIG(menubar) - m_menuBar(0), + m_menuBar(nullptr), #endif mdiChild(mdiChild) { @@ -732,9 +721,9 @@ ControlContainer::~ControlContainer() removeButtonsFromMenuBar(); #endif delete m_menuLabel; - m_menuLabel = 0; + m_menuLabel = nullptr; delete m_controllerWidget; - m_controllerWidget = 0; + m_controllerWidget = nullptr; } #if QT_CONFIG(menubar) @@ -744,16 +733,16 @@ ControlContainer::~ControlContainer() QMenuBar *QMdiSubWindowPrivate::menuBar() const { #if !QT_CONFIG(mainwindow) - return 0; + return nullptr; #else Q_Q(const QMdiSubWindow); if (!q->isMaximized() || drawTitleBarWhenMaximized() || isChildOfTabbedQMdiArea(q)) - return 0; + return nullptr; if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window())) return mainWindow->menuBar(); - return 0; + return nullptr; #endif } @@ -797,50 +786,50 @@ void ControlContainer::removeButtonsFromMenuBar(QMenuBar *menuBar) { if (menuBar && menuBar != m_menuBar) { // m_menubar was deleted while sub-window was maximized - previousRight = 0; - previousLeft = 0; + previousRight = nullptr; + previousLeft = nullptr; m_menuBar = menuBar; } if (!m_menuBar || !mdiChild || qt_widget_private(mdiChild->window())->data.in_destructor) return; - QMdiSubWindow *child = 0; + QMdiSubWindow *child = nullptr; if (m_controllerWidget) { QWidget *currentRight = m_menuBar->cornerWidget(Qt::TopRightCorner); if (currentRight == m_controllerWidget) { if (ControlElement<ControllerWidget> *ce = ptr<ControllerWidget>(previousRight)) { if (!ce->mdiChild || !ce->mdiChild->isMaximized()) - previousRight = 0; + previousRight = nullptr; else child = ce->mdiChild; } m_menuBar->setCornerWidget(previousRight, Qt::TopRightCorner); if (previousRight) { previousRight->show(); - previousRight = 0; + previousRight = nullptr; } } m_controllerWidget->hide(); - m_controllerWidget->setParent(0); + m_controllerWidget->setParent(nullptr); } if (m_menuLabel) { QWidget *currentLeft = m_menuBar->cornerWidget(Qt::TopLeftCorner); if (currentLeft == m_menuLabel) { if (ControlElement<ControlLabel> *ce = ptr<ControlLabel>(previousLeft)) { if (!ce->mdiChild || !ce->mdiChild->isMaximized()) - previousLeft = 0; + previousLeft = nullptr; else if (!child) child = mdiChild; } m_menuBar->setCornerWidget(previousLeft, Qt::TopLeftCorner); if (previousLeft) { previousLeft->show(); - previousLeft = 0; + previousLeft = nullptr; } } m_menuLabel->hide(); - m_menuLabel->setParent(0); + m_menuLabel->setParent(nullptr); } m_menuBar->update(); if (child) @@ -861,14 +850,14 @@ void ControlContainer::updateWindowIcon(const QIcon &windowIcon) \internal */ QMdiSubWindowPrivate::QMdiSubWindowPrivate() - : baseWidget(0), - restoreFocusWidget(0), - controlContainer(0), + : baseWidget(nullptr), + restoreFocusWidget(nullptr), + controlContainer(nullptr), #if QT_CONFIG(sizegrip) - sizeGrip(0), + sizeGrip(nullptr), #endif #if QT_CONFIG(rubberband) - rubberBand(0), + rubberBand(nullptr), #endif userMinimumSize(0,0), resizeEnabled(true), @@ -902,7 +891,7 @@ QMdiSubWindowPrivate::QMdiSubWindowPrivate() */ void QMdiSubWindowPrivate::_q_updateStaysOnTopHint() { -#ifndef QT_NO_ACTION +#if QT_CONFIG(action) Q_Q(QMdiSubWindow); if (QAction *senderAction = qobject_cast<QAction *>(q->sender())) { if (senderAction->isChecked()) { @@ -913,7 +902,7 @@ void QMdiSubWindowPrivate::_q_updateStaysOnTopHint() q->lower(); } } -#endif // QT_NO_ACTION +#endif // QT_CONFIG(action) } /*! @@ -933,7 +922,7 @@ void QMdiSubWindowPrivate::_q_enterInteractiveMode() pressPos = QPoint(q->width() / 2, titleBarHeight() - 1); } else if (actions[ResizeAction] && actions[ResizeAction] == action) { currentOperation = q->isLeftToRight() ? BottomRightResize : BottomLeftResize; - int offset = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q) / 2; + int offset = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q) / 2; int x = q->isLeftToRight() ? q->width() - offset : offset; pressPos = QPoint(x, q->height() - offset); } else { @@ -1016,8 +1005,8 @@ void QMdiSubWindowPrivate::removeBaseWidget() lastChildWindowTitle.clear(); // QTBUG-47993: parent widget can be reset before this call if (baseWidget->parentWidget() == q) - baseWidget->setParent(0); - baseWidget = 0; + baseWidget->setParent(nullptr); + baseWidget = nullptr; isWidgetHiddenByUs = false; } @@ -1054,19 +1043,19 @@ void QMdiSubWindowPrivate::createSystemMenu() systemMenu->installEventFilter(q); const QStyle *style = q->style(); addToSystemMenu(RestoreAction, QMdiSubWindow::tr("&Restore"), SLOT(showNormal())); - actions[RestoreAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarNormalButton, 0, q)); + actions[RestoreAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarNormalButton, nullptr, q)); 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, 0, q)); + actions[MinimizeAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarMinButton, nullptr, q)); addToSystemMenu(MaximizeAction, QMdiSubWindow::tr("Ma&ximize"), SLOT(showMaximized())); - actions[MaximizeAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarMaxButton, 0, q)); + actions[MaximizeAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarMaxButton, nullptr, q)); 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, 0, q)); + actions[CloseAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarCloseButton, nullptr, q)); #if !defined(QT_NO_SHORTCUT) actions[CloseAction]->setShortcuts(QKeySequence::Close); #endif @@ -1468,7 +1457,7 @@ void QMdiSubWindowPrivate::setActive(bool activate, bool changeFocus) ensureWindowState(Qt::WindowActive); } - int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q); + int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q); int titleBarHeight = this->titleBarHeight(); QRegion windowDecoration = QRegion(0, 0, q->width(), q->height()); windowDecoration -= QRegion(frameWidth, titleBarHeight, q->width() - 2 * frameWidth, @@ -1550,7 +1539,7 @@ QRegion QMdiSubWindowPrivate::getRegion(Operation operation) const int width = q->width(); int height = q->height(); int titleBarHeight = this->titleBarHeight(); - int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q); + int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q); int cornerConst = titleBarHeight - frameWidth; int titleBarConst = 2 * titleBarHeight; @@ -1745,7 +1734,7 @@ void QMdiSubWindowPrivate::sizeParameters(int *margin, int *minWidth) const if (q->isMaximized() && !drawTitleBarWhenMaximized()) *margin = 0; else - *margin = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q); + *margin = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, q); QStyleOptionTitleBar opt = this->titleBarOptions(); int tempWidth = 0; @@ -1774,7 +1763,7 @@ bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const if (isChildOfTabbedQMdiArea(q)) return false; - if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) + if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, nullptr, q)) return true; #if !QT_CONFIG(menubar) || !QT_CONFIG(mainwindow) Q_UNUSED(isChildOfQMdiSubWindow); @@ -1826,7 +1815,7 @@ void QMdiSubWindowPrivate::showButtonsInMenuBar(QMenuBar *menuBar) // Make sure topLevelWindow->contentsRect returns correct geometry. // topLevelWidget->updateGeoemtry will not do the trick here since it will post the event. QEvent event(QEvent::LayoutRequest); - QApplication::sendEvent(topLevelWindow, &event); + QCoreApplication::sendEvent(topLevelWindow, &event); } } @@ -1840,7 +1829,7 @@ void QMdiSubWindowPrivate::removeButtonsFromMenuBar() if (!controlContainer || isChildOfTabbedQMdiArea(q)) return; - QMenuBar *currentMenuBar = 0; + QMenuBar *currentMenuBar = nullptr; #if QT_CONFIG(mainwindow) if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window())) { // NB! We can't use menuBar() here because that one will actually create @@ -1870,7 +1859,7 @@ void QMdiSubWindowPrivate::updateWindowTitle(bool isRequestFromChild) return; } - QWidget *titleWidget = 0; + QWidget *titleWidget = nullptr; if (isRequestFromChild) titleWidget = baseWidget; else @@ -1896,7 +1885,7 @@ void QMdiSubWindowPrivate::enterRubberBandMode() if (!rubberBand) { rubberBand = new QRubberBand(QRubberBand::Rectangle, q->parentWidget()); // For accessibility to identify this special widget. - rubberBand->setObjectName(QLatin1String("qt_rubberband")); + rubberBand->setObjectName("qt_rubberband"_L1); } QPoint rubberBandPos = q->mapToParent(QPoint(0, 0)); rubberBand->setGeometry(rubberBandPos.x(), rubberBandPos.y(), @@ -1925,56 +1914,16 @@ QPalette QMdiSubWindowPrivate::desktopPalette() const Q_Q(const QMdiSubWindow); QPalette newPalette = q->palette(); - bool colorsInitialized = false; -#if 0 // Used to be included in Qt4 for Q_WS_WIN // ask system properties on windows -#ifndef SPI_GETGRADIENTCAPTIONS -#define SPI_GETGRADIENTCAPTIONS 0x1008 -#endif -#ifndef COLOR_GRADIENTACTIVECAPTION -#define COLOR_GRADIENTACTIVECAPTION 27 -#endif -#ifndef COLOR_GRADIENTINACTIVECAPTION -#define COLOR_GRADIENTINACTIVECAPTION 28 -#endif - if (QApplication::desktopSettingsAware()) { - newPalette.setColor(QPalette::Active, QPalette::Highlight, - colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION))); - newPalette.setColor(QPalette::Inactive, QPalette::Highlight, - colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION))); - newPalette.setColor(QPalette::Active, QPalette::HighlightedText, - colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT))); - newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, - colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT))); - - colorsInitialized = true; - BOOL hasGradient = false; - SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &hasGradient, 0); - - if (hasGradient) { - newPalette.setColor(QPalette::Active, QPalette::Base, - colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION))); - newPalette.setColor(QPalette::Inactive, QPalette::Base, - colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))); - } else { - newPalette.setColor(QPalette::Active, QPalette::Base, - newPalette.color(QPalette::Active, QPalette::Highlight)); - newPalette.setColor(QPalette::Inactive, QPalette::Base, - newPalette.color(QPalette::Inactive, QPalette::Highlight)); - } - } -#endif - if (!colorsInitialized) { - newPalette.setColor(QPalette::Active, QPalette::Highlight, - newPalette.color(QPalette::Active, QPalette::Highlight)); - newPalette.setColor(QPalette::Active, QPalette::Base, - newPalette.color(QPalette::Active, QPalette::Highlight)); - newPalette.setColor(QPalette::Inactive, QPalette::Highlight, - newPalette.color(QPalette::Inactive, QPalette::Dark)); - newPalette.setColor(QPalette::Inactive, QPalette::Base, - newPalette.color(QPalette::Inactive, QPalette::Dark)); - newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, - newPalette.color(QPalette::Inactive, QPalette::Window)); - } + newPalette.setColor(QPalette::Active, QPalette::Highlight, + newPalette.color(QPalette::Active, QPalette::Highlight)); + newPalette.setColor(QPalette::Active, QPalette::Base, + newPalette.color(QPalette::Active, QPalette::Highlight)); + newPalette.setColor(QPalette::Inactive, QPalette::Highlight, + newPalette.color(QPalette::Inactive, QPalette::Dark)); + newPalette.setColor(QPalette::Inactive, QPalette::Base, + newPalette.color(QPalette::Inactive, QPalette::Dark)); + newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, + newPalette.color(QPalette::Inactive, QPalette::Window)); return newPalette; } @@ -1986,7 +1935,7 @@ void QMdiSubWindowPrivate::updateActions() for (int i = 0; i < NumWindowStateActions; ++i) setVisible(WindowStateAction(i), false); -#ifdef Q_OS_MACOS +#if defined(Q_OS_MACOS) && QT_CONFIG(action) if (q_func()->style()->inherits("QMacStyle")) for (int i = 0; i < NumWindowStateActions; ++i) if (QAction *action = actions[i]) @@ -2174,7 +2123,7 @@ QSize QMdiSubWindowPrivate::iconSize() const Q_Q(const QMdiSubWindow); if (!parent || q->windowFlags() & Qt::FramelessWindowHint) return QSize(-1, -1); - return QSize(q->style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth, 0, q), titleBarHeight()); + return QSize(q->style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth, nullptr, q), titleBarHeight()); } #if QT_CONFIG(sizegrip) @@ -2229,7 +2178,7 @@ void QMdiSubWindowPrivate::updateInternalWindowTitle() Q_Q(QMdiSubWindow); if (q->isWindowModified()) { windowTitle = q->windowTitle(); - windowTitle.replace(QLatin1String("[*]"), QLatin1String("*")); + windowTitle.replace("[*]"_L1, "*"_L1); } else { windowTitle = qt_setWindowTitle_helperHelper(q->windowTitle(), q); } @@ -2255,7 +2204,7 @@ void QMdiSubWindowPrivate::updateInternalWindowTitle() \sa QMdiArea::addSubWindow() */ QMdiSubWindow::QMdiSubWindow(QWidget *parent, Qt::WindowFlags flags) - : QWidget(*new QMdiSubWindowPrivate, parent, 0) + : QWidget(*new QMdiSubWindowPrivate, parent, { }) { Q_D(QMdiSubWindow); #if QT_CONFIG(menu) @@ -2268,7 +2217,7 @@ QMdiSubWindow::QMdiSubWindow(QWidget *parent, Qt::WindowFlags flags) setMouseTracking(true); setLayout(new QVBoxLayout); setFocusPolicy(Qt::StrongFocus); - layout()->setMargin(0); + layout()->setContentsMargins(QMargins()); d->updateGeometryConstraints(); setAttribute(Qt::WA_Resized, false); d->titleBarPalette = d->desktopPalette(); @@ -2276,7 +2225,7 @@ QMdiSubWindow::QMdiSubWindow(QWidget *parent, Qt::WindowFlags flags) // We don't want the menu icon by default on mac. #ifndef Q_OS_MAC if (windowIcon().isNull()) - d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, this); + d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, nullptr, this); else d->menuIcon = windowIcon(); #endif @@ -2347,10 +2296,8 @@ void QMdiSubWindow::setWidget(QWidget *widget) d->updateWindowTitle(true); isWindowModified = d->baseWidget->isWindowModified(); } - if (!this->isWindowModified() && isWindowModified - && windowTitle().contains(QLatin1String("[*]"))) { + if (!this->isWindowModified() && isWindowModified && windowTitle().contains("[*]"_L1)) setWindowModified(isWindowModified); - } d->lastChildWindowTitle = d->baseWidget->windowTitle(); d->ignoreWindowTitleChange = false; @@ -2383,7 +2330,7 @@ QWidget *QMdiSubWindow::maximizedButtonsWidget() const && !isChildOfTabbedQMdiArea(this)) { return d->controlContainer->controllerWidget(); } - return 0; + return nullptr; } /*! @@ -2396,7 +2343,7 @@ QWidget *QMdiSubWindow::maximizedSystemMenuIconWidget() const && !isChildOfTabbedQMdiArea(this)) { return d->controlContainer->systemMenuLabel(); } - return 0; + return nullptr; } /*! @@ -2519,7 +2466,7 @@ void QMdiSubWindow::setSystemMenu(QMenu *systemMenu) if (d->systemMenu) { delete d->systemMenu; - d->systemMenu = 0; + d->systemMenu = nullptr; } if (!systemMenu) @@ -2576,7 +2523,8 @@ void QMdiSubWindow::showSystemMenu() /*! \since 4.4 - Returns the area containing this sub-window, or 0 if there is none. + Returns the area containing this sub-window, or \nullptr if there + is none. \sa QMdiArea::addSubWindow() */ @@ -2590,7 +2538,7 @@ QMdiArea *QMdiSubWindow::mdiArea() const } parent = parent->parentWidget(); } - return 0; + return nullptr; } /*! @@ -2697,12 +2645,12 @@ bool QMdiSubWindow::eventFilter(QObject *object, QEvent *event) if (d->systemMenu && d->systemMenu == object) { if (event->type() == QEvent::MouseButtonDblClick) { const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); - const QAction *action = d->systemMenu->actionAt(mouseEvent->pos()); + const QAction *action = d->systemMenu->actionAt(mouseEvent->position().toPoint()); if (!action || action->isEnabled()) close(); } else if (event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); - d->hoveredSubControl = d->getSubControl(mapFromGlobal(mouseEvent->globalPos())); + d->hoveredSubControl = d->getSubControl(mapFromGlobal(mouseEvent->globalPosition().toPoint())); } else if (event->type() == QEvent::Hide) { d->activeSubControl = QStyle::SC_None; update(QRegion(0, 0, width(), d->titleBarHeight())); @@ -2716,7 +2664,7 @@ bool QMdiSubWindow::eventFilter(QObject *object, QEvent *event) if (event->type() != QEvent::MouseButtonPress || !testOption(QMdiSubWindow::RubberBandResize)) return QWidget::eventFilter(object, event); const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); - d->mousePressPosition = parentWidget()->mapFromGlobal(mouseEvent->globalPos()); + d->mousePressPosition = parentWidget()->mapFromGlobal(mouseEvent->globalPosition().toPoint()); d->oldGeometry = geometry(); d->currentOperation = isLeftToRight() ? QMdiSubWindowPrivate::BottomRightResize : QMdiSubWindowPrivate::BottomLeftResize; @@ -2782,7 +2730,7 @@ bool QMdiSubWindow::eventFilter(QObject *object, QEvent *event) bool windowModified = d->baseWidget->isWindowModified(); if (!windowModified && d->baseWidget->windowTitle() != windowTitle()) break; - if (windowTitle().contains(QLatin1String("[*]"))) + if (windowTitle().contains("[*]"_L1)) setWindowModified(windowModified); break; } @@ -2883,7 +2831,7 @@ bool QMdiSubWindow::event(QEvent *event) d->updateInternalWindowTitle(); break; case QEvent::ModifiedChange: - if (!windowTitle().contains(QLatin1String("[*]"))) + if (!windowTitle().contains("[*]"_L1)) break; #if QT_CONFIG(menubar) if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar() @@ -2902,7 +2850,7 @@ bool QMdiSubWindow::event(QEvent *event) case QEvent::WindowIconChange: d->menuIcon = windowIcon(); if (d->menuIcon.isNull()) - d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, this); + d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, nullptr, this); if (d->controlContainer) d->controlContainer->updateWindowIcon(d->menuIcon); if (!maximizedSystemMenuIconWidget()) @@ -2914,7 +2862,7 @@ bool QMdiSubWindow::event(QEvent *event) case QEvent::FontChange: d->font = font(); break; -#ifndef QT_NO_TOOLTIP +#if QT_CONFIG(tooltip) case QEvent::ToolTip: showToolTip(static_cast<QHelpEvent *>(event), this, d->titleBarOptions(), QStyle::CC_TitleBar, d->hoveredSubControl); @@ -3049,7 +2997,7 @@ void QMdiSubWindow::closeEvent(QCloseEvent *closeEvent) d->setActive(false); if (parentWidget() && testAttribute(Qt::WA_DeleteOnClose)) { QChildEvent childRemoved(QEvent::ChildRemoved, this); - QApplication::sendEvent(parentWidget(), &childRemoved); + QCoreApplication::sendEvent(parentWidget(), &childRemoved); } closeEvent->accept(); } @@ -3177,7 +3125,7 @@ void QMdiSubWindow::paintEvent(QPaintEvent *paintEvent) if (isMinimized() && !d->hasBorder(d->cachedStyleOptions)) return; - frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, this); + frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, this); // ### Ensure that we do not require setting the cliprect for 4.4 if (!isMinimized() && !d->hasBorder(d->cachedStyleOptions)) @@ -3211,7 +3159,7 @@ void QMdiSubWindow::mousePressEvent(QMouseEvent *mouseEvent) if (d->currentOperation != QMdiSubWindowPrivate::None) { d->updateCursor(); - d->mousePressPosition = mapToParent(mouseEvent->pos()); + d->mousePressPosition = mapToParent(mouseEvent->position().toPoint()); if (d->resizeEnabled || d->moveEnabled) d->oldGeometry = geometry(); #if QT_CONFIG(rubberband) @@ -3302,10 +3250,10 @@ void QMdiSubWindow::mouseReleaseEvent(QMouseEvent *mouseEvent) d->oldGeometry = geometry(); } - d->currentOperation = d->getOperation(mouseEvent->pos()); + d->currentOperation = d->getOperation(mouseEvent->position().toPoint()); d->updateCursor(); - d->hoveredSubControl = d->getSubControl(mouseEvent->pos()); + d->hoveredSubControl = d->getSubControl(mouseEvent->position().toPoint()); if (d->activeSubControl != QStyle::SC_None && d->activeSubControl == d->hoveredSubControl) { d->processClickedSubControl(); @@ -3330,7 +3278,7 @@ void QMdiSubWindow::mouseMoveEvent(QMouseEvent *mouseEvent) // Find previous and current hover region. const QStyleOptionTitleBar options = d->titleBarOptions(); QStyle::SubControl oldHover = d->hoveredSubControl; - d->hoveredSubControl = d->getSubControl(mouseEvent->pos()); + d->hoveredSubControl = d->getSubControl(mouseEvent->position().toPoint()); QRegion hoverRegion; if (isHoverControl(oldHover) && oldHover != d->hoveredSubControl) hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options, oldHover, this); @@ -3347,13 +3295,16 @@ void QMdiSubWindow::mouseMoveEvent(QMouseEvent *mouseEvent) } if ((mouseEvent->buttons() & Qt::LeftButton) || d->isInInteractiveMode) { - if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled)) - d->setNewGeometry(mapToParent(mouseEvent->pos())); + if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled)) { + // As setNewGeometry moves the window, it invalidates the pos() value of any mouse move events that are + // currently queued in the event loop. Map to parent using globalPos() instead. + d->setNewGeometry(parentWidget()->mapFromGlobal(mouseEvent->globalPosition().toPoint())); + } return; } // Do not resize/move if not allowed. - d->currentOperation = d->getOperation(mouseEvent->pos()); + d->currentOperation = d->getOperation(mouseEvent->position().toPoint()); if ((d->isResizeOperation() && !d->resizeEnabled) || (d->isMoveOperation() && !d->moveEnabled)) d->currentOperation = QMdiSubWindowPrivate::None; d->updateCursor(); @@ -3549,11 +3500,11 @@ QSize QMdiSubWindow::minimumSizeHint() const if (d->sizeGrip && d->sizeGrip->isVisibleTo(const_cast<QMdiSubWindow *>(this))) sizeGripHeight = d->sizeGrip->height(); else if (parent() && isMacStyle(style()) && !d->sizeGrip) - sizeGripHeight = style()->pixelMetric(QStyle::PM_SizeGripSize, 0, this); + sizeGripHeight = style()->pixelMetric(QStyle::PM_SizeGripSize, nullptr, this); minHeight = qMax(minHeight, decorationHeight + sizeGripHeight); #endif - return QSize(minWidth, minHeight).expandedTo(QApplication::globalStrut()); + return QSize(minWidth, minHeight); } QT_END_NAMESPACE |