diff options
Diffstat (limited to 'src/widgets/widgets/qmainwindow.cpp')
-rw-r--r-- | src/widgets/widgets/qmainwindow.cpp | 107 |
1 files changed, 44 insertions, 63 deletions
diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 5aeea88e4e..4534058d45 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.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 //#define QT_EXPERIMENTAL_CLIENT_DECORATIONS @@ -61,6 +25,7 @@ #include <qstyle.h> #include <qdebug.h> #include <qpainter.h> +#include <qmimedata.h> #include <private/qwidget_p.h> #if QT_CONFIG(toolbar) @@ -72,6 +37,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QMainWindowPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMainWindow) @@ -82,7 +49,7 @@ public: , useUnifiedToolBar(false) #endif { } - QMainWindowLayout *layout; + QPointer<QMainWindowLayout> layout; QSize iconSize; bool explicitIconSize; Qt::ToolButtonStyle toolButtonStyle; @@ -93,7 +60,7 @@ public: static inline QMainWindowLayout *mainWindowLayout(const QMainWindow *mainWindow) { - return mainWindow ? mainWindow->d_func()->layout : static_cast<QMainWindowLayout *>(nullptr); + return mainWindow ? mainWindow->d_func()->layout.data() : static_cast<QMainWindowLayout *>(nullptr); } }; @@ -157,6 +124,7 @@ void QMainWindowPrivate::init() const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, nullptr, q); iconSize = QSize(metric, metric); q->setAttribute(Qt::WA_Hover); + q->setAcceptDrops(true); } /* @@ -213,9 +181,6 @@ void QMainWindowPrivate::init() \image mainwindowlayout.png - \note Creating a main window without a central widget is not supported. - You must have a central widget even if it is just a placeholder. - \section1 Creating Main Window Components A central widget will typically be a standard Qt widget such @@ -315,9 +280,7 @@ void QMainWindowPrivate::init() is the position and size (relative to the size of the main window) of the toolbars and dock widgets that are stored. - \sa QMenuBar, QToolBar, QStatusBar, QDockWidget, - {Qt Widgets - Application Example}, {Dock Widgets Example}, - {MDI Example}, {SDI Example}, {Menus Example} + \sa QMenuBar, QToolBar, QStatusBar, QDockWidget, {Menus Example} */ /*! @@ -615,7 +578,7 @@ void QMainWindow::setStatusBar(QStatusBar *statusbar) /*! Returns the central widget for the main window. This function - returns zero if the central widget has not been set. + returns \nullptr if the central widget has not been set. \sa setCentralWidget() */ @@ -1160,21 +1123,8 @@ void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second) QList<QDockWidget*> QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const { - QList<QDockWidget*> ret; - const QDockAreaLayoutInfo *info = d_func()->layout->layoutState.dockAreaLayout.info(dockwidget); - if (info && info->tabbed && info->tabBar) { - for(int i = 0; i < info->item_list.count(); ++i) { - const QDockAreaLayoutItem &item = info->item_list.at(i); - if (item.widgetItem) { - if (QDockWidget *dock = qobject_cast<QDockWidget*>(item.widgetItem->widget())) { - if (dock != dockwidget) { - ret += dock; - } - } - } - } - } - return ret; + Q_D(const QMainWindow); + return d->layout ? d->layout->tabifiedDockWidgets(dockwidget) : QList<QDockWidget *>(); } #endif // QT_CONFIG(tabbar) @@ -1256,6 +1206,7 @@ QByteArray QMainWindow::saveState(int version) const { QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); + stream.setVersion(QDataStream::Qt_5_0); stream << QMainWindowLayout::VersionMarker; stream << version; d_func()->layout->saveState(stream); @@ -1284,6 +1235,7 @@ bool QMainWindow::restoreState(const QByteArray &state, int version) return false; QByteArray sd = state; QDataStream stream(&sd, QIODevice::ReadOnly); + stream.setVersion(QDataStream::Qt_5_0); int marker, v; stream >> marker; stream >> v; @@ -1333,6 +1285,28 @@ bool QMainWindow::event(QEvent *event) if (!d->explicitIconSize) setIconSize(QSize()); break; +#if QT_CONFIG(draganddrop) + case QEvent::DragEnter: + case QEvent::Drop: + if (!d->layout->draggingWidget) + break; + event->accept(); + return true; + case QEvent::DragMove: { + if (!d->layout->draggingWidget) + break; + auto dragMoveEvent = static_cast<QDragMoveEvent *>(event); + d->layout->hover(d->layout->draggingWidget, + mapToGlobal(dragMoveEvent->position()).toPoint()); + event->accept(); + return true; + } + case QEvent::DragLeave: + if (!d->layout->draggingWidget) + break; + d->layout->hover(d->layout->draggingWidget, pos() - QPoint(-1, -1)); + return true; +#endif default: break; } @@ -1362,8 +1336,15 @@ void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool enabled) Q_D(QMainWindow); d->useUnifiedToolBar = enabled; - createWinId(); + // The unified toolbar is drawn by the macOS style with a transparent background. + // To ensure a suitable surface format is used we need to first create backing + // QWindow so we have something to update the surface format on, and then let + // QWidget know about the translucency, which it will propagate to the surface. + setAttribute(Qt::WA_NativeWindow); + setAttribute(Qt::WA_TranslucentBackground, enabled); + + d->create(); // Create first, before querying the platform window using namespace QNativeInterface::Private; if (auto *platformWindow = dynamic_cast<QCocoaWindow*>(window()->windowHandle()->handle())) platformWindow->setContentBorderEnabled(enabled); |