diff options
Diffstat (limited to 'src/widgets/widgets/qmenu_p.h')
-rw-r--r-- | src/widgets/widgets/qmenu_p.h | 69 |
1 files changed, 23 insertions, 46 deletions
diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index efbbc099a1..1e32fbcdfa 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -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 #ifndef QMENU_P_H #define QMENU_P_H @@ -52,6 +16,7 @@ // #include <QtWidgets/private/qtwidgetsglobal_p.h> +#include "QtWidgets/qmenu.h" #if QT_CONFIG(menubar) #include "QtWidgets/qmenubar.h" #endif @@ -64,6 +29,10 @@ #include <qpa/qplatformmenu.h> +#include <QtCore/qpointer.h> + +#include <functional> + QT_REQUIRE_CONFIG(menu); QT_BEGIN_NAMESPACE @@ -302,6 +271,8 @@ class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: + using PositionFunction = std::function<QPoint(const QSize &)>; + QMenuPrivate() : itemsDirty(false), hasCheckableItems(false), @@ -331,7 +302,7 @@ public: void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item); QPlatformMenuItem *insertActionInPlatformMenu(const QAction *action, QPlatformMenuItem *beforeItem); -#ifdef Q_OS_OSX +#ifdef Q_OS_MACOS void moveWidgetToPlatformItem(QWidget *w, QPlatformMenuItem* item); #endif @@ -343,14 +314,15 @@ public: //item calculations QRect actionRect(QAction *) const; - mutable QVector<QRect> actionRects; + mutable QList<QRect> actionRects; mutable QHash<QAction *, QWidget *> widgetItems; void updateActionRects() const; void updateActionRects(const QRect &screen) const; - QRect popupGeometry() const; - QRect popupGeometry(int screen) const; + QRect popupGeometry(QScreen *screen = nullptr) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; + void popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction = {}); + QAction *exec(const QPoint &p, QAction *action, PositionFunction positionFunction = {}); //selection static QMenu *mouseDown; @@ -430,10 +402,11 @@ public: QPointer<QWidget> widget; QPointer<QAction> action; }; - virtual QVector<QPointer<QWidget> > calcCausedStack() const; + virtual QList<QPointer<QWidget>> calcCausedStack() const; QMenuCaused causedPopup; void hideUpToMenuBar(); void hideMenu(QMenu *menu); + QWindow *transientParentWindow() const; //index mappings inline QAction *actionAt(int i) const { return q_func()->actions().at(i); } @@ -455,7 +428,8 @@ public: //firing of events void activateAction(QAction *, QAction::ActionEvent, bool self=true); - void activateCausedStack(const QVector<QPointer<QWidget> > &, QAction *, QAction::ActionEvent, bool); + void activateCausedStack(const QList<QPointer<QWidget>> &, QAction *, QAction::ActionEvent, + bool); void _q_actionTriggered(); void _q_actionHovered(); @@ -499,6 +473,11 @@ public: mutable quint8 ncols = 0; // "255cols ought to be enough for anybody." + // Contains the screen of the popup point during popup(QPoint). + // This is to make sure the screen is remembered, + // when the menu contains many items on multiple screens + QPointer<QScreen> popupScreen; + mutable bool itemsDirty : 1; mutable bool hasCheckableItems : 1; bool lastContextMenu : 1; @@ -515,8 +494,6 @@ public: bool tearoffHighlighted : 1; //menu fading/scrolling effects bool doChildEffects : 1; - - int popupScreen = -1; }; QT_END_NAMESPACE |