diff options
Diffstat (limited to 'src/widgets/widgets/qmdisubwindow.cpp')
-rw-r--r-- | src/widgets/widgets/qmdisubwindow.cpp | 122 |
1 files changed, 54 insertions, 68 deletions
diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index 82f72065e0..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 @@ -170,9 +134,12 @@ #if QT_CONFIG(menu) #include <QMenu> #endif +#include <QProxyStyle> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + using namespace QMdi; static const QStyle::SubControl SubControls[] = @@ -203,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, @@ -260,13 +229,30 @@ static inline ControlElement<T> *ptr(QWidget *widget) 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; } @@ -279,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; } } @@ -396,7 +388,7 @@ ControlLabel::ControlLabel(QMdiSubWindow *subWindow, QWidget *parent) Q_UNUSED(subWindow); setFocusPolicy(Qt::NoFocus); updateWindowIcon(); - setFixedSize(label.size()); + setFixedSize(label.deviceIndependentSize().toSize()); } /* @@ -404,7 +396,7 @@ ControlLabel::ControlLabel(QMdiSubWindow *subWindow, QWidget *parent) */ QSize ControlLabel::sizeHint() const { - return label.size(); + return label.deviceIndependentSize().toSize(); } /* @@ -741,7 +733,7 @@ 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)) @@ -1893,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(), @@ -1922,20 +1914,16 @@ QPalette QMdiSubWindowPrivate::desktopPalette() const Q_Q(const QMdiSubWindow); QPalette newPalette = q->palette(); - bool colorsInitialized = false; - - 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; } @@ -2190,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); } @@ -2308,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; @@ -2744,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; } @@ -2845,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() |