summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/kernel.pri25
-rw-r--r--src/widgets/kernel/qaction.cpp1367
-rw-r--r--src/widgets/kernel/qaction.h228
-rw-r--r--src/widgets/kernel/qaction_widgets.cpp (renamed from src/widgets/kernel/qactiongroup.h)113
-rw-r--r--src/widgets/kernel/qaction_widgets_p.h (renamed from src/widgets/kernel/qaction_p.h)85
-rw-r--r--src/widgets/kernel/qactiongroup.cpp445
-rw-r--r--src/widgets/kernel/qapplication.cpp214
-rw-r--r--src/widgets/kernel/qapplication.h38
-rw-r--r--src/widgets/kernel/qapplication_p.h7
-rw-r--r--src/widgets/kernel/qopenglwidget.cpp1471
-rw-r--r--src/widgets/kernel/qopenglwidget.h115
-rw-r--r--src/widgets/kernel/qshortcut.cpp753
-rw-r--r--src/widgets/kernel/qshortcut.h161
-rw-r--r--src/widgets/kernel/qshortcut_widgets.cpp358
-rw-r--r--src/widgets/kernel/qsizepolicy.cpp2
-rw-r--r--src/widgets/kernel/qsizepolicy.h4
-rw-r--r--src/widgets/kernel/qt_widgets_pch.h4
-rw-r--r--src/widgets/kernel/qwidget.cpp64
-rw-r--r--src/widgets/kernel/qwidget.h8
-rw-r--r--src/widgets/kernel/qwidget_p.h5
-rw-r--r--src/widgets/kernel/qwidgetaction.cpp4
-rw-r--r--src/widgets/kernel/qwidgetaction.h9
-rw-r--r--src/widgets/kernel/qwidgetaction_p.h6
-rw-r--r--src/widgets/kernel/qwidgetsvariant.cpp73
24 files changed, 535 insertions, 5024 deletions
diff --git a/src/widgets/kernel/kernel.pri b/src/widgets/kernel/kernel.pri
index 693af7eb80..b9dfdef5ee 100644
--- a/src/widgets/kernel/kernel.pri
+++ b/src/widgets/kernel/kernel.pri
@@ -7,9 +7,6 @@ KERNEL_P= kernel
HEADERS += \
kernel/qtwidgetsglobal.h \
kernel/qtwidgetsglobal_p.h \
- kernel/qaction.h \
- kernel/qaction_p.h \
- kernel/qactiongroup.h \
kernel/qapplication.h \
kernel/qapplication_p.h \
kernel/qwidgetrepaintmanager_p.h \
@@ -20,13 +17,10 @@ HEADERS += \
kernel/qlayout_p.h \
kernel/qlayoutengine_p.h \
kernel/qlayoutitem.h \
- kernel/qshortcut.h \
- kernel/qsizepolicy.h \
+ kernel/qsizepolicy.h \
kernel/qstackedlayout.h \
kernel/qwidget.h \
kernel/qwidget_p.h \
- kernel/qwidgetaction.h \
- kernel/qwidgetaction_p.h \
kernel/qgesture.h \
kernel/qgesture_p.h \
kernel/qstandardgestures_p.h \
@@ -38,8 +32,6 @@ HEADERS += \
kernel/qtestsupport_widgets.h
SOURCES += \
- kernel/qaction.cpp \
- kernel/qactiongroup.cpp \
kernel/qapplication.cpp \
kernel/qwidgetrepaintmanager.cpp \
kernel/qboxlayout.cpp \
@@ -47,11 +39,9 @@ SOURCES += \
kernel/qlayout.cpp \
kernel/qlayoutengine.cpp \
kernel/qlayoutitem.cpp \
- kernel/qshortcut.cpp \
kernel/qsizepolicy.cpp \
kernel/qstackedlayout.cpp \
kernel/qwidget.cpp \
- kernel/qwidgetaction.cpp \
kernel/qgesture.cpp \
kernel/qstandardgestures.cpp \
kernel/qgesturerecognizer.cpp \
@@ -67,9 +57,12 @@ macx: {
SOURCES += kernel/qmacgesturerecognizer.cpp
}
-qtConfig(opengl) {
- HEADERS += kernel/qopenglwidget.h
- SOURCES += kernel/qopenglwidget.cpp
+qtConfig(action) {
+ HEADERS += kernel/qaction_widgets_p.h \
+ kernel/qwidgetaction.h \
+ kernel/qwidgetaction_p.h
+ SOURCES += kernel/qaction_widgets.cpp \
+ kernel/qwidgetaction.cpp
}
qtConfig(formlayout) {
@@ -77,6 +70,10 @@ qtConfig(formlayout) {
SOURCES += kernel/qformlayout.cpp
}
+qtConfig(shortcut) {
+ SOURCES += kernel/qshortcut_widgets.cpp
+}
+
qtConfig(tooltip) {
HEADERS += kernel/qtooltip.h
SOURCES += kernel/qtooltip.cpp
diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp
deleted file mode 100644
index 64b0d69f6d..0000000000
--- a/src/widgets/kernel/qaction.cpp
+++ /dev/null
@@ -1,1367 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include "qaction.h"
-#include "qactiongroup.h"
-
-#ifndef QT_NO_ACTION
-#include "qaction_p.h"
-#include "qapplication.h"
-#include "qevent.h"
-#include "qlist.h"
-#include "qstylehints.h"
-#include <private/qshortcutmap_p.h>
-#include <private/qguiapplication_p.h>
-#if QT_CONFIG(menu)
-#include <private/qmenu_p.h>
-#endif
-#include <private/qdebug_p.h>
-
-#define QAPP_CHECK(functionName) \
- if (Q_UNLIKELY(!QCoreApplication::instance())) { \
- qWarning("QAction: Initialize Q(Gui)Application before calling '" functionName "'."); \
- return; \
- }
-
-QT_BEGIN_NAMESPACE
-
-/*
- internal: guesses a descriptive text from a text suited for a menu entry
- */
-static QString qt_strippedText(QString s)
-{
- s.remove(QLatin1String("..."));
- for (int i = 0; i < s.size(); ++i) {
- if (s.at(i) == QLatin1Char('&'))
- s.remove(i, 1);
- }
- return s.trimmed();
-}
-
-
-QActionPrivate::QActionPrivate() :
-#if QT_CONFIG(shortcut)
- autorepeat(1),
-#endif
- enabled(1), forceDisabled(0), visible(1), forceInvisible(0), checkable(0),
- checked(0), separator(0), fontSet(false),
- iconVisibleInMenu(-1), shortcutVisibleInContextMenu(-1)
-{
-}
-
-QActionPrivate::~QActionPrivate() = default;
-
-bool QActionPrivate::showStatusText(QWidget *widget, const QString &str)
-{
-#if !QT_CONFIG(statustip)
- Q_UNUSED(widget);
- Q_UNUSED(str);
-#else
- if(QObject *object = widget ? widget : parent) {
- QStatusTipEvent tip(str);
- QCoreApplication::sendEvent(object, &tip);
- return true;
- }
-#endif
- return false;
-}
-
-void QActionPrivate::sendDataChanged()
-{
- Q_Q(QAction);
- QActionEvent e(QEvent::ActionChanged, q);
- for (int i = 0; i < widgets.size(); ++i) {
- QWidget *w = widgets.at(i);
- QCoreApplication::sendEvent(w, &e);
- }
-#if QT_CONFIG(graphicsview)
- for (int i = 0; i < graphicsWidgets.size(); ++i) {
- QGraphicsWidget *w = graphicsWidgets.at(i);
- QCoreApplication::sendEvent(w, &e);
- }
-#endif
- QCoreApplication::sendEvent(q, &e);
-
- emit q->changed();
-}
-
-#if QT_CONFIG(shortcut)
-void QActionPrivate::redoGrab(QShortcutMap &map)
-{
- Q_Q(QAction);
- if (shortcutId)
- map.removeShortcut(shortcutId, q);
- if (shortcut.isEmpty())
- return;
- shortcutId = map.addShortcut(q, shortcut, shortcutContext, qWidgetShortcutContextMatcher);
- if (!enabled)
- map.setShortcutEnabled(false, shortcutId, q);
- if (!autorepeat)
- map.setShortcutAutoRepeat(false, shortcutId, q);
-}
-
-void QActionPrivate::redoGrabAlternate(QShortcutMap &map)
-{
- Q_Q(QAction);
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- if (const int id = alternateShortcutIds.at(i))
- map.removeShortcut(id, q);
- }
- alternateShortcutIds.clear();
- if (alternateShortcuts.isEmpty())
- return;
- for(int i = 0; i < alternateShortcuts.count(); ++i) {
- const QKeySequence& alternate = alternateShortcuts.at(i);
- if (!alternate.isEmpty())
- alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext, qWidgetShortcutContextMatcher));
- else
- alternateShortcutIds.append(0);
- }
- if (!enabled) {
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- const int id = alternateShortcutIds.at(i);
- map.setShortcutEnabled(false, id, q);
- }
- }
- if (!autorepeat) {
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- const int id = alternateShortcutIds.at(i);
- map.setShortcutAutoRepeat(false, id, q);
- }
- }
-}
-
-void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
-{
- Q_Q(QAction);
- if (shortcutId)
- map.setShortcutEnabled(enable, shortcutId, q);
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- if (const int id = alternateShortcutIds.at(i))
- map.setShortcutEnabled(enable, id, q);
- }
-}
-#endif // QT_NO_SHORTCUT
-
-
-/*!
- \class QAction
- \brief The QAction class provides an abstract user interface
- action that can be inserted into widgets.
-
- \ingroup mainwindow-classes
- \inmodule QtWidgets
-
- \omit
- * parent and widget are different
- * parent does not define context
- \endomit
-
- In applications many common commands can be invoked via menus,
- toolbar buttons, and keyboard shortcuts. Since the user expects
- each command to be performed in the same way, regardless of the
- user interface used, it is useful to represent each command as
- an \e action.
-
- Actions can be added to menus and toolbars, and will
- automatically keep them in sync. For example, in a word processor,
- if the user presses a Bold toolbar button, the Bold menu item
- will automatically be checked.
-
- Actions can be created as independent objects, but they may
- also be created during the construction of menus; the QMenu class
- contains convenience functions for creating actions suitable for
- use as menu items.
-
- A QAction may contain an icon, menu text, a shortcut, status text,
- "What's This?" text, and a tooltip. Most of these can be set in
- the constructor. They can also be set independently with
- setIcon(), setText(), setIconText(), setShortcut(),
- setStatusTip(), setWhatsThis(), and setToolTip(). For menu items,
- it is possible to set an individual font with setFont().
-
- Actions are added to widgets using QWidget::addAction() or
- QGraphicsWidget::addAction(). Note that an action must be added to a
- widget before it can be used; this is also true when the shortcut should
- be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext).
-
- Once a QAction has been created it should be added to the relevant
- menu and toolbar, then connected to the slot which will perform
- the action. For example:
-
- \snippet mainwindows/application/mainwindow.cpp 19
-
- We recommend that actions are created as children of the window
- they are used in. In most cases actions will be children of
- the application's main window.
-
- \sa QMenu, QToolBar, {Application Example}
-*/
-
-/*!
- \fn void QAction::trigger()
-
- This is a convenience slot that calls activate(Trigger).
-*/
-
-/*!
- \fn void QAction::hover()
-
- This is a convenience slot that calls activate(Hover).
-*/
-
-/*!
- \enum QAction::MenuRole
-
- This enum describes how an action should be moved into the application menu on \macos.
-
- \value NoRole This action should not be put into the application menu
- \value TextHeuristicRole This action should be put in the application menu based on the action's text
- as described in the QMenuBar documentation.
- \value ApplicationSpecificRole This action should be put in the application menu with an application specific role
- \value AboutQtRole This action handles the "About Qt" menu item.
- \value AboutRole This action should be placed where the "About" menu item is in the application menu. The text of
- the menu item will be set to "About <application name>". The application name is fetched from the
- \c{Info.plist} file in the application's bundle (See \l{Qt for macOS - Deployment}).
- \value PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu.
- \value QuitRole This action should be placed where the Quit menu item is in the application menu.
-
- Setting this value only has effect on items that are in the immediate menus
- of the menubar, not the submenus of those menus. For example, if you have
- File menu in your menubar and the File menu has a submenu, setting the
- MenuRole for the actions in that submenu have no effect. They will never be moved.
-*/
-
-/*!
- Constructs an action with \a parent. If \a parent is an action
- group the action will be automatically inserted into the group.
-
- \note The \a parent argument is optional since Qt 5.7.
-*/
-QAction::QAction(QObject* parent)
- : QAction(*new QActionPrivate, parent)
-{
-}
-
-
-/*!
- Constructs an action with some \a text and \a parent. If \a
- parent is an action group the action will be automatically
- inserted into the group.
-
- The action uses a stripped version of \a text (e.g. "\&Menu
- Option..." becomes "Menu Option") as descriptive text for
- tool buttons. You can override this by setting a specific
- description with setText(). The same text will be used for
- tooltips unless you specify a different text using
- setToolTip().
-
-*/
-QAction::QAction(const QString &text, QObject* parent)
- : QAction(parent)
-{
- Q_D(QAction);
- d->text = text;
-}
-
-/*!
- Constructs an action with an \a icon and some \a text and \a
- parent. If \a parent is an action group the action will be
- automatically inserted into the group.
-
- The action uses a stripped version of \a text (e.g. "\&Menu
- Option..." becomes "Menu Option") as descriptive text for
- tool buttons. You can override this by setting a specific
- description with setText(). The same text will be used for
- tooltips unless you specify a different text using
- setToolTip().
-*/
-QAction::QAction(const QIcon &icon, const QString &text, QObject* parent)
- : QAction(text, parent)
-{
- Q_D(QAction);
- d->icon = icon;
-}
-
-/*!
- \internal
-*/
-QAction::QAction(QActionPrivate &dd, QObject *parent)
- : QObject(dd, parent)
-{
- Q_D(QAction);
- d->group = qobject_cast<QActionGroup *>(parent);
- if (d->group)
- d->group->addAction(this);
-}
-
-/*!
- Returns the parent widget.
-*/
-QWidget *QAction::parentWidget() const
-{
- QObject *ret = parent();
- while (ret && !ret->isWidgetType())
- ret = ret->parent();
- return static_cast<QWidget*>(ret);
-}
-
-/*!
- \since 4.2
- Returns a list of widgets this action has been added to.
-
- \sa QWidget::addAction(), associatedGraphicsWidgets()
-*/
-QList<QWidget *> QAction::associatedWidgets() const
-{
- Q_D(const QAction);
- return d->widgets;
-}
-
-#if QT_CONFIG(graphicsview)
-/*!
- \since 4.5
- Returns a list of widgets this action has been added to.
-
- \sa QWidget::addAction(), associatedWidgets()
-*/
-QList<QGraphicsWidget *> QAction::associatedGraphicsWidgets() const
-{
- Q_D(const QAction);
- return d->graphicsWidgets;
-}
-#endif
-
-#if QT_CONFIG(shortcut)
-/*!
- \property QAction::shortcut
- \brief the action's primary shortcut key
-
- Valid keycodes for this property can be found in \l Qt::Key and
- \l Qt::Modifier. There is no default shortcut key.
-*/
-void QAction::setShortcut(const QKeySequence &shortcut)
-{
- QAPP_CHECK("setShortcut");
-
- Q_D(QAction);
- if (d->shortcut == shortcut)
- return;
-
- d->shortcut = shortcut;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->sendDataChanged();
-}
-
-/*!
- \since 4.2
-
- Sets \a shortcuts as the list of shortcuts that trigger the
- action. The first element of the list is the primary shortcut.
-
- \sa shortcut
-*/
-void QAction::setShortcuts(const QList<QKeySequence> &shortcuts)
-{
- Q_D(QAction);
-
- QList <QKeySequence> listCopy = shortcuts;
-
- QKeySequence primary;
- if (!listCopy.isEmpty())
- primary = listCopy.takeFirst();
-
- if (d->shortcut == primary && d->alternateShortcuts == listCopy)
- return;
-
- QAPP_CHECK("setShortcuts");
-
- d->shortcut = primary;
- d->alternateShortcuts = listCopy;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap);
- d->sendDataChanged();
-}
-
-/*!
- \since 4.2
-
- Sets a platform dependent list of shortcuts based on the \a key.
- The result of calling this function will depend on the currently running platform.
- Note that more than one shortcut can assigned by this action.
- If only the primary shortcut is required, use setShortcut instead.
-
- \sa QKeySequence::keyBindings()
-*/
-void QAction::setShortcuts(QKeySequence::StandardKey key)
-{
- QList <QKeySequence> list = QKeySequence::keyBindings(key);
- setShortcuts(list);
-}
-
-/*!
- Returns the primary shortcut.
-
- \sa setShortcuts()
-*/
-QKeySequence QAction::shortcut() const
-{
- Q_D(const QAction);
- return d->shortcut;
-}
-
-/*!
- \since 4.2
-
- Returns the list of shortcuts, with the primary shortcut as
- the first element of the list.
-
- \sa setShortcuts()
-*/
-QList<QKeySequence> QAction::shortcuts() const
-{
- Q_D(const QAction);
- QList <QKeySequence> shortcuts;
- if (!d->shortcut.isEmpty())
- shortcuts << d->shortcut;
- if (!d->alternateShortcuts.isEmpty())
- shortcuts << d->alternateShortcuts;
- return shortcuts;
-}
-
-/*!
- \property QAction::shortcutContext
- \brief the context for the action's shortcut
-
- Valid values for this property can be found in \l Qt::ShortcutContext.
- The default value is Qt::WindowShortcut.
-*/
-void QAction::setShortcutContext(Qt::ShortcutContext context)
-{
- Q_D(QAction);
- if (d->shortcutContext == context)
- return;
- QAPP_CHECK("setShortcutContext");
- d->shortcutContext = context;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap);
- d->sendDataChanged();
-}
-
-Qt::ShortcutContext QAction::shortcutContext() const
-{
- Q_D(const QAction);
- return d->shortcutContext;
-}
-
-/*!
- \property QAction::autoRepeat
- \brief whether the action can auto repeat
- \since 4.2
-
- If true, the action will auto repeat when the keyboard shortcut
- combination is held down, provided that keyboard auto repeat is
- enabled on the system.
- The default value is true.
-*/
-void QAction::setAutoRepeat(bool on)
-{
- Q_D(QAction);
- if (d->autorepeat == on)
- return;
- QAPP_CHECK("setAutoRepeat");
- d->autorepeat = on;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap);
- d->sendDataChanged();
-}
-
-bool QAction::autoRepeat() const
-{
- Q_D(const QAction);
- return d->autorepeat;
-}
-#endif // QT_NO_SHORTCUT
-
-/*!
- \property QAction::font
- \brief the action's font
-
- The font property is used to render the text set on the
- QAction. The font will can be considered a hint as it will not be
- consulted in all cases based upon application and style.
-
- By default, this property contains the application's default font.
-
- \sa QAction::setText(), QStyle
-*/
-void QAction::setFont(const QFont &font)
-{
- Q_D(QAction);
- if (d->font == font)
- return;
-
- d->fontSet = true;
- d->font = font;
- d->sendDataChanged();
-}
-
-QFont QAction::font() const
-{
- Q_D(const QAction);
- return d->font;
-}
-
-
-/*!
- Destroys the object and frees allocated resources.
-*/
-QAction::~QAction()
-{
- Q_D(QAction);
- for (int i = d->widgets.size()-1; i >= 0; --i) {
- QWidget *w = d->widgets.at(i);
- w->removeAction(this);
- }
-#if QT_CONFIG(graphicsview)
- for (int i = d->graphicsWidgets.size()-1; i >= 0; --i) {
- QGraphicsWidget *w = d->graphicsWidgets.at(i);
- w->removeAction(this);
- }
-#endif
- if (d->group)
- d->group->removeAction(this);
-#if QT_CONFIG(shortcut)
- if (d->shortcutId && qApp) {
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(d->shortcutId, this);
- for(int i = 0; i < d->alternateShortcutIds.count(); ++i) {
- const int id = d->alternateShortcutIds.at(i);
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this);
- }
- }
-#endif
-}
-
-/*!
- Sets this action group to \a group. The action will be automatically
- added to the group's list of actions.
-
- Actions within the group will be mutually exclusive.
-
- \sa QActionGroup, QAction::actionGroup()
-*/
-void QAction::setActionGroup(QActionGroup *group)
-{
- Q_D(QAction);
- if(group == d->group)
- return;
-
- if(d->group)
- d->group->removeAction(this);
- d->group = group;
- if(group)
- group->addAction(this);
- d->sendDataChanged();
-}
-
-/*!
- Returns the action group for this action. If no action group manages
- this action then 0 will be returned.
-
- \sa QActionGroup, QAction::setActionGroup()
-*/
-QActionGroup *QAction::actionGroup() const
-{
- Q_D(const QAction);
- return d->group;
-}
-
-
-/*!
- \property QAction::icon
- \brief the action's icon
-
- In toolbars, the icon is used as the tool button icon; in menus,
- it is displayed to the left of the menu text. There is no default
- icon.
-
- If a null icon (QIcon::isNull()) is passed into this function,
- the icon of the action is cleared.
-*/
-void QAction::setIcon(const QIcon &icon)
-{
- Q_D(QAction);
- d->icon = icon;
- d->sendDataChanged();
-}
-
-QIcon QAction::icon() const
-{
- Q_D(const QAction);
- return d->icon;
-}
-
-#if QT_CONFIG(menu)
-/*!
- Returns the menu contained by this action. Actions that contain
- menus can be used to create menu items with submenus, or inserted
- into toolbars to create buttons with popup menus.
-
- \sa QMenu::addAction()
-*/
-QMenu *QAction::menu() const
-{
- Q_D(const QAction);
- return d->menu;
-}
-
-/*!
- Sets the menu contained by this action to the specified \a menu.
-*/
-void QAction::setMenu(QMenu *menu)
-{
- Q_D(QAction);
- if (d->menu)
- d->menu->d_func()->setOverrideMenuAction(nullptr); //we reset the default action of any previous menu
- d->menu = menu;
- if (menu)
- menu->d_func()->setOverrideMenuAction(this);
- d->sendDataChanged();
-}
-#endif // QT_CONFIG(menu)
-
-/*!
- If \a b is true then this action will be considered a separator.
-
- How a separator is represented depends on the widget it is inserted
- into. Under most circumstances the text, submenu, and icon will be
- ignored for separator actions.
-
- \sa QAction::isSeparator()
-*/
-void QAction::setSeparator(bool b)
-{
- Q_D(QAction);
- if (d->separator == b)
- return;
-
- d->separator = b;
- d->sendDataChanged();
-}
-
-/*!
- Returns \c true if this action is a separator action; otherwise it
- returns \c false.
-
- \sa QAction::setSeparator()
-*/
-bool QAction::isSeparator() const
-{
- Q_D(const QAction);
- return d->separator;
-}
-
-/*!
- \property QAction::text
- \brief the action's descriptive text
-
- If the action is added to a menu, the menu option will consist of
- the icon (if there is one), the text, and the shortcut (if there
- is one). If the text is not explicitly set in the constructor, or
- by using setText(), the action's description icon text will be
- used as text. There is no default text.
-
- \sa iconText
-*/
-void QAction::setText(const QString &text)
-{
- Q_D(QAction);
- if (d->text == text)
- return;
-
- d->text = text;
- d->sendDataChanged();
-}
-
-QString QAction::text() const
-{
- Q_D(const QAction);
- QString s = d->text;
- if(s.isEmpty()) {
- s = d->iconText;
- s.replace(QLatin1Char('&'), QLatin1String("&&"));
- }
- return s;
-}
-
-
-
-
-
-/*!
- \property QAction::iconText
- \brief the action's descriptive icon text
-
- If QToolBar::toolButtonStyle is set to a value that permits text to
- be displayed, the text defined held in this property appears as a
- label in the relevant tool button.
-
- It also serves as the default text in menus and tooltips if the action
- has not been defined with setText() or setToolTip(), and will
- also be used in toolbar buttons if no icon has been defined using setIcon().
-
- If the icon text is not explicitly set, the action's normal text will be
- used for the icon text.
-
- By default, this property contains an empty string.
-
- \sa setToolTip(), setStatusTip()
-*/
-void QAction::setIconText(const QString &text)
-{
- Q_D(QAction);
- if (d->iconText == text)
- return;
-
- d->iconText = text;
- d->sendDataChanged();
-}
-
-QString QAction::iconText() const
-{
- Q_D(const QAction);
- if (d->iconText.isEmpty())
- return qt_strippedText(d->text);
- return d->iconText;
-}
-
-/*!
- \property QAction::toolTip
- \brief the action's tooltip
-
- This text is used for the tooltip. If no tooltip is specified,
- the action's text is used.
-
- By default, this property contains the action's text.
-
- \sa setStatusTip(), setShortcut()
-*/
-void QAction::setToolTip(const QString &tooltip)
-{
- Q_D(QAction);
- if (d->tooltip == tooltip)
- return;
-
- d->tooltip = tooltip;
- d->sendDataChanged();
-}
-
-QString QAction::toolTip() const
-{
- Q_D(const QAction);
- if (d->tooltip.isEmpty()) {
- if (!d->text.isEmpty())
- return qt_strippedText(d->text);
- return qt_strippedText(d->iconText);
- }
- return d->tooltip;
-}
-
-/*!
- \property QAction::statusTip
- \brief the action's status tip
-
- The status tip is displayed on all status bars provided by the
- action's top-level parent widget.
-
- By default, this property contains an empty string.
-
- \sa setToolTip(), showStatusText()
-*/
-void QAction::setStatusTip(const QString &statustip)
-{
- Q_D(QAction);
- if (d->statustip == statustip)
- return;
-
- d->statustip = statustip;
- d->sendDataChanged();
-}
-
-QString QAction::statusTip() const
-{
- Q_D(const QAction);
- return d->statustip;
-}
-
-/*!
- \property QAction::whatsThis
- \brief the action's "What's This?" help text
-
- The "What's This?" text is used to provide a brief description of
- the action. The text may contain rich text. There is no default
- "What's This?" text.
-
- \sa QWhatsThis
-*/
-void QAction::setWhatsThis(const QString &whatsthis)
-{
- Q_D(QAction);
- if (d->whatsthis == whatsthis)
- return;
-
- d->whatsthis = whatsthis;
- d->sendDataChanged();
-}
-
-QString QAction::whatsThis() const
-{
- Q_D(const QAction);
- return d->whatsthis;
-}
-
-/*!
- \enum QAction::Priority
- \since 4.6
-
- This enum defines priorities for actions in user interface.
-
- \value LowPriority The action should not be prioritized in
- the user interface.
-
- \value NormalPriority
-
- \value HighPriority The action should be prioritized in
- the user interface.
-
- \sa priority
-*/
-
-
-/*!
- \property QAction::priority
- \since 4.6
-
- \brief the actions's priority in the user interface.
-
- This property can be set to indicate how the action should be prioritized
- in the user interface.
-
- For instance, when toolbars have the Qt::ToolButtonTextBesideIcon
- mode set, then actions with LowPriority will not show the text
- labels.
-*/
-void QAction::setPriority(Priority priority)
-{
- Q_D(QAction);
- if (d->priority == priority)
- return;
-
- d->priority = priority;
- d->sendDataChanged();
-}
-
-QAction::Priority QAction::priority() const
-{
- Q_D(const QAction);
- return d->priority;
-}
-
-/*!
- \property QAction::checkable
- \brief whether the action is a checkable action
-
- A checkable action is one which has an on/off state. For example,
- in a word processor, a Bold toolbar button may be either on or
- off. An action which is not a toggle action is a command action;
- a command action is simply executed, e.g. file save.
- By default, this property is \c false.
-
- In some situations, the state of one toggle action should depend
- on the state of others. For example, "Left Align", "Center" and
- "Right Align" toggle actions are mutually exclusive. To achieve
- exclusive toggling, add the relevant toggle actions to a
- QActionGroup with the QActionGroup::exclusive property set to
- true.
-
- \sa QAction::setChecked()
-*/
-void QAction::setCheckable(bool b)
-{
- Q_D(QAction);
- if (d->checkable == b)
- return;
-
- d->checkable = b;
- d->checked = false;
- d->sendDataChanged();
-}
-
-bool QAction::isCheckable() const
-{
- Q_D(const QAction);
- return d->checkable;
-}
-
-/*!
- \fn void QAction::toggle()
-
- This is a convenience function for the \l checked property.
- Connect to it to change the checked state to its opposite state.
-*/
-void QAction::toggle()
-{
- Q_D(QAction);
- setChecked(!d->checked);
-}
-
-/*!
- \property QAction::checked
- \brief whether the action is checked.
-
- Only checkable actions can be checked. By default, this is false
- (the action is unchecked).
-
- \note The notifier signal for this property is toggled(). As toggling
- a QAction changes its state, it will also emit a changed() signal.
-
- \sa checkable, toggled()
-*/
-void QAction::setChecked(bool b)
-{
- Q_D(QAction);
- if (!d->checkable || d->checked == b)
- return;
-
- QPointer<QAction> guard(this);
- d->checked = b;
- d->sendDataChanged();
- if (guard)
- emit toggled(b);
-}
-
-bool QAction::isChecked() const
-{
- Q_D(const QAction);
- return d->checked;
-}
-
-/*!
- \fn void QAction::setDisabled(bool b)
-
- This is a convenience function for the \l enabled property, that
- is useful for signals--slots connections. If \a b is true the
- action is disabled; otherwise it is enabled.
-*/
-
-/*!
- \property QAction::enabled
- \brief whether the action is enabled
-
- Disabled actions cannot be chosen by the user. They do not
- disappear from menus or toolbars, but they are displayed in a way
- which indicates that they are unavailable. For example, they might
- be displayed using only shades of gray.
-
- \uicontrol{What's This?} help on disabled actions is still available, provided
- that the QAction::whatsThis property is set.
-
- An action will be disabled when all widgets to which it is added
- (with QWidget::addAction()) are disabled or not visible. When an
- action is disabled, it is not possible to trigger it through its
- shortcut.
-
- By default, this property is \c true (actions are enabled).
-
- \sa text
-*/
-void QAction::setEnabled(bool b)
-{
- Q_D(QAction);
- if (b == d->enabled && b != d->forceDisabled)
- return;
- d->forceDisabled = !b;
- if (b && (!d->visible || (d->group && !d->group->isEnabled())))
- return;
- QAPP_CHECK("setEnabled");
- d->enabled = b;
-#if QT_CONFIG(shortcut)
- d->setShortcutEnabled(b, QGuiApplicationPrivate::instance()->shortcutMap);
-#endif
- d->sendDataChanged();
-}
-
-bool QAction::isEnabled() const
-{
- Q_D(const QAction);
- return d->enabled;
-}
-
-/*!
- \property QAction::visible
- \brief whether the action can be seen (e.g. in menus and toolbars)
-
- If \e visible is true the action can be seen (e.g. in menus and
- toolbars) and chosen by the user; if \e visible is false the
- action cannot be seen or chosen by the user.
-
- Actions which are not visible are \e not grayed out; they do not
- appear at all.
-
- By default, this property is \c true (actions are visible).
-*/
-void QAction::setVisible(bool b)
-{
- Q_D(QAction);
- if (b == d->visible && b != d->forceInvisible)
- return;
- QAPP_CHECK("setVisible");
- d->forceInvisible = !b;
- d->visible = b;
- d->enabled = b && !d->forceDisabled && (!d->group || d->group->isEnabled()) ;
-#if QT_CONFIG(shortcut)
- d->setShortcutEnabled(d->enabled, QGuiApplicationPrivate::instance()->shortcutMap);
-#endif
- d->sendDataChanged();
-}
-
-
-bool QAction::isVisible() const
-{
- Q_D(const QAction);
- return d->visible;
-}
-
-/*!
- \reimp
-*/
-bool
-QAction::event(QEvent *e)
-{
-#if QT_CONFIG(shortcut)
- if (e->type() == QEvent::Shortcut) {
- QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
- Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()),
- "QAction::event",
- "Received shortcut event from incorrect shortcut");
- if (se->isAmbiguous())
- qWarning("QAction::event: Ambiguous shortcut overload: %s", se->key().toString(QKeySequence::NativeText).toLatin1().constData());
- else
- activate(Trigger);
- return true;
- }
-#endif
- return QObject::event(e);
-}
-
-/*!
- Returns the user data as set in QAction::setData.
-
- \sa setData()
-*/
-QVariant
-QAction::data() const
-{
- Q_D(const QAction);
- return d->userData;
-}
-
-/*!
- \fn void QAction::setData(const QVariant &userData)
-
- Sets the action's internal data to the given \a userData.
-
- \sa data()
-*/
-void
-QAction::setData(const QVariant &data)
-{
- Q_D(QAction);
- if (d->userData == data)
- return;
- d->userData = data;
- d->sendDataChanged();
-}
-
-
-/*!
- Updates the relevant status bar for the \a widget specified by sending a
- QStatusTipEvent to its parent widget. Returns \c true if an event was sent;
- otherwise returns \c false.
-
- If a null widget is specified, the event is sent to the action's parent.
-
- \sa statusTip
-*/
-bool
-QAction::showStatusText(QWidget *widget)
-{
- return d_func()->showStatusText(widget, statusTip());
-}
-
-/*!
- Sends the relevant signals for ActionEvent \a event.
-
- Action based widgets use this API to cause the QAction
- to emit signals as well as emitting their own.
-*/
-void QAction::activate(ActionEvent event)
-{
- Q_D(QAction);
- if(event == Trigger) {
- QPointer<QObject> guard = this;
- if(d->checkable) {
- // the checked action of an exclusive group may not be unchecked
- if (d->checked && (d->group
- && d->group->exclusionPolicy() == QActionGroup::ExclusionPolicy::Exclusive
- && d->group->checkedAction() == this)) {
- if (!guard.isNull())
- emit triggered(true);
- return;
- }
- setChecked(!d->checked);
- }
- if (!guard.isNull())
- emit triggered(d->checked);
- } else if(event == Hover) {
- emit hovered();
- }
-}
-
-/*!
- \fn void QAction::triggered(bool checked)
-
- This signal is emitted when an action is activated by the user;
- for example, when the user clicks a menu option, toolbar button,
- or presses an action's shortcut key combination, or when trigger()
- was called. Notably, it is \e not emitted when setChecked() or
- toggle() is called.
-
- If the action is checkable, \a checked is true if the action is
- checked, or false if the action is unchecked.
-
- \sa QAction::activate(), QAction::toggled(), checked
-*/
-
-/*!
- \fn void QAction::toggled(bool checked)
-
- This signal is emitted whenever a checkable action changes its
- isChecked() status. This can be the result of a user interaction,
- or because setChecked() was called. As setChecked() changes the
- QAction, it emits changed() in addition to toggled().
-
- \a checked is true if the action is checked, or false if the
- action is unchecked.
-
- \sa QAction::activate(), QAction::triggered(), checked
-*/
-
-/*!
- \fn void QAction::hovered()
-
- This signal is emitted when an action is highlighted by the user;
- for example, when the user pauses with the cursor over a menu option,
- toolbar button, or presses an action's shortcut key combination.
-
- \sa QAction::activate()
-*/
-
-/*!
- \fn void QAction::changed()
-
- This signal is emitted when an action has changed. If you
- are only interested in actions in a given widget, you can
- watch for QWidget::actionEvent() sent with an
- QEvent::ActionChanged.
-
- \sa QWidget::actionEvent()
-*/
-
-/*!
- \enum QAction::ActionEvent
-
- This enum type is used when calling QAction::activate()
-
- \value Trigger this will cause the QAction::triggered() signal to be emitted.
-
- \value Hover this will cause the QAction::hovered() signal to be emitted.
-*/
-
-/*!
- \property QAction::menuRole
- \brief the action's menu role
- \since 4.2
-
- This indicates what role the action serves in the application menu on
- \macos. By default all actions have the TextHeuristicRole, which means that
- the action is added based on its text (see QMenuBar for more information).
-
- The menu role can only be changed before the actions are put into the menu
- bar in \macos (usually just before the first application window is
- shown).
-*/
-void QAction::setMenuRole(MenuRole menuRole)
-{
- Q_D(QAction);
- if (d->menuRole == menuRole)
- return;
-
- d->menuRole = menuRole;
- d->sendDataChanged();
-}
-
-QAction::MenuRole QAction::menuRole() const
-{
- Q_D(const QAction);
- return d->menuRole;
-}
-
-/*!
- \property QAction::iconVisibleInMenu
- \brief Whether or not an action should show an icon in a menu
- \since 4.4
-
- In some applications, it may make sense to have actions with icons in the
- toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it
- is false, it is not shown.
-
- The default is to follow whether the Qt::AA_DontShowIconsInMenus attribute
- is set for the application. Explicitly settings this property overrides
- the presence (or abscence) of the attribute.
-
- For example:
- \snippet code/src_gui_kernel_qaction.cpp 0
-
- \sa QAction::icon, QCoreApplication::setAttribute()
-*/
-void QAction::setIconVisibleInMenu(bool visible)
-{
- Q_D(QAction);
- if (d->iconVisibleInMenu == -1 || visible != bool(d->iconVisibleInMenu)) {
- int oldValue = d->iconVisibleInMenu;
- d->iconVisibleInMenu = visible;
- // Only send data changed if we really need to.
- if (oldValue != -1
- || visible == !QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus)) {
- d->sendDataChanged();
- }
- }
-}
-
-bool QAction::isIconVisibleInMenu() const
-{
- Q_D(const QAction);
- if (d->iconVisibleInMenu == -1) {
- return !QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus);
- }
- return d->iconVisibleInMenu;
-}
-
-/*!
- \property QAction::shortcutVisibleInContextMenu
- \brief Whether or not an action should show a shortcut in a context menu
- \since 5.10
-
- In some applications, it may make sense to have actions with shortcuts in
- context menus. If true, the shortcut (if valid) is shown when the action is
- shown via a context menu, when it is false, it is not shown.
-
- The default is to follow whether the Qt::AA_DontShowShortcutsInContextMenus attribute
- is set for the application, falling back to the widget style hint.
- Explicitly setting this property overrides the presence (or abscence) of the attribute.
-
- \sa QAction::shortcut, QCoreApplication::setAttribute()
-*/
-void QAction::setShortcutVisibleInContextMenu(bool visible)
-{
- Q_D(QAction);
- if (d->shortcutVisibleInContextMenu == -1 || visible != bool(d->shortcutVisibleInContextMenu)) {
- int oldValue = d->shortcutVisibleInContextMenu;
- d->shortcutVisibleInContextMenu = visible;
- // Only send data changed if we really need to.
- if (oldValue != -1
- || visible == !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus)) {
- d->sendDataChanged();
- }
- }
-}
-
-bool QAction::isShortcutVisibleInContextMenu() const
-{
- Q_D(const QAction);
- if (d->shortcutVisibleInContextMenu == -1) {
- return !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus)
- && QGuiApplication::styleHints()->showShortcutsInContextMenus();
- }
- return d->shortcutVisibleInContextMenu;
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QAction *action)
-{
- QDebugStateSaver saver(d);
- d.nospace();
- d << "QAction(" << static_cast<const void *>(action);
- if (action) {
- d << " text=" << action->text();
- if (!action->toolTip().isEmpty())
- d << " toolTip=" << action->toolTip();
- if (action->isCheckable())
- d << " checked=" << action->isChecked();
-#if QT_CONFIG(shortcut)
- if (!action->shortcut().isEmpty())
- d << " shortcut=" << action->shortcut();
-#endif
- d << " menuRole=";
- QtDebugUtils::formatQEnum(d, action->menuRole());
- d << " visible=" << action->isVisible();
- } else {
- d << '0';
- }
- d << ')';
- return d;
-}
-#endif // QT_NO_DEBUG_STREAM
-
-QT_END_NAMESPACE
-
-#include "moc_qaction.cpp"
-
-#endif // QT_NO_ACTION
diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction.h
deleted file mode 100644
index 258a1ea0a0..0000000000
--- a/src/widgets/kernel/qaction.h
+++ /dev/null
@@ -1,228 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#ifndef QACTION_H
-#define QACTION_H
-
-#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtGui/qkeysequence.h>
-#include <QtCore/qstring.h>
-#include <QtWidgets/qwidget.h>
-#include <QtCore/qvariant.h>
-#include <QtGui/qicon.h>
-
-QT_BEGIN_NAMESPACE
-
-
-#ifndef QT_NO_ACTION
-
-class QMenu;
-class QActionGroup;
-class QActionPrivate;
-class QGraphicsWidget;
-
-class Q_WIDGETS_EXPORT QAction : public QObject
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QAction)
-
- Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
- Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed)
- Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
- Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
- Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed)
- Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed)
- Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed)
- Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed)
- Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
-#if QT_CONFIG(shortcut)
- Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
- Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
- Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
-#endif
- Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed)
- Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed)
- Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed)
- Q_PROPERTY(bool shortcutVisibleInContextMenu READ isShortcutVisibleInContextMenu WRITE setShortcutVisibleInContextMenu NOTIFY changed)
- Q_PROPERTY(Priority priority READ priority WRITE setPriority)
-
-public:
- // note this is copied into qplatformmenu.h, which must stay in sync
- enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
- AboutRole, PreferencesRole, QuitRole };
- Q_ENUM(MenuRole)
- enum Priority { LowPriority = 0,
- NormalPriority = 128,
- HighPriority = 256};
- Q_ENUM(Priority)
- explicit QAction(QObject *parent = nullptr);
- explicit QAction(const QString &text, QObject *parent = nullptr);
- explicit QAction(const QIcon &icon, const QString &text, QObject *parent = nullptr);
-
- ~QAction();
-
- void setActionGroup(QActionGroup *group);
- QActionGroup *actionGroup() const;
- void setIcon(const QIcon &icon);
- QIcon icon() const;
-
- void setText(const QString &text);
- QString text() const;
-
- void setIconText(const QString &text);
- QString iconText() const;
-
- void setToolTip(const QString &tip);
- QString toolTip() const;
-
- void setStatusTip(const QString &statusTip);
- QString statusTip() const;
-
- void setWhatsThis(const QString &what);
- QString whatsThis() const;
-
- void setPriority(Priority priority);
- Priority priority() const;
-
-#if QT_CONFIG(menu)
- QMenu *menu() const;
- void setMenu(QMenu *menu);
-#endif
-
- void setSeparator(bool b);
- bool isSeparator() const;
-
-#if QT_CONFIG(shortcut)
- void setShortcut(const QKeySequence &shortcut);
- QKeySequence shortcut() const;
-
- void setShortcuts(const QList<QKeySequence> &shortcuts);
- void setShortcuts(QKeySequence::StandardKey);
- QList<QKeySequence> shortcuts() const;
-
- void setShortcutContext(Qt::ShortcutContext context);
- Qt::ShortcutContext shortcutContext() const;
-
- void setAutoRepeat(bool);
- bool autoRepeat() const;
-#endif
-
- void setFont(const QFont &font);
- QFont font() const;
-
- void setCheckable(bool);
- bool isCheckable() const;
-
- QVariant data() const;
- void setData(const QVariant &var);
-
- bool isChecked() const;
-
- bool isEnabled() const;
-
- bool isVisible() const;
-
- enum ActionEvent { Trigger, Hover };
- void activate(ActionEvent event);
- bool showStatusText(QWidget *widget = nullptr);
-
- void setMenuRole(MenuRole menuRole);
- MenuRole menuRole() const;
-
- void setIconVisibleInMenu(bool visible);
- bool isIconVisibleInMenu() const;
-
- void setShortcutVisibleInContextMenu(bool show);
- bool isShortcutVisibleInContextMenu() const;
-
- QWidget *parentWidget() const;
-
- QList<QWidget *> associatedWidgets() const;
-#if QT_CONFIG(graphicsview)
- QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
-#endif
-
-protected:
- bool event(QEvent *) override;
- QAction(QActionPrivate &dd, QObject *parent);
-
-public Q_SLOTS:
- void trigger() { activate(Trigger); }
- void hover() { activate(Hover); }
- void setChecked(bool);
- void toggle();
- void setEnabled(bool);
- inline void setDisabled(bool b) { setEnabled(!b); }
- void setVisible(bool);
-
-Q_SIGNALS:
- void changed();
- void triggered(bool checked = false);
- void hovered();
- void toggled(bool);
-
-private:
- Q_DISABLE_COPY(QAction)
-
- friend class QGraphicsWidget;
- friend class QWidget;
- friend class QActionGroup;
- friend class QMenu;
- friend class QMenuPrivate;
- friend class QMenuBar;
- friend class QToolButton;
-#ifdef Q_OS_MAC
- friend void qt_mac_clear_status_text(QAction *action);
-#endif
-};
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QAction *);
-#endif
-
-QT_BEGIN_INCLUDE_NAMESPACE
-#include <QtWidgets/qactiongroup.h>
-QT_END_INCLUDE_NAMESPACE
-
-#endif // QT_NO_ACTION
-
-QT_END_NAMESPACE
-
-#endif // QACTION_H
diff --git a/src/widgets/kernel/qactiongroup.h b/src/widgets/kernel/qaction_widgets.cpp
index 90f488bedb..ff609a66a1 100644
--- a/src/widgets/kernel/qactiongroup.h
+++ b/src/widgets/kernel/qaction_widgets.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -37,72 +37,67 @@
**
****************************************************************************/
-#ifndef QACTIONGROUP_H
-#define QACTIONGROUP_H
+#include "qaction.h"
-#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtWidgets/qaction.h>
-
-QT_BEGIN_NAMESPACE
+#include <private/qapplication_p.h>
+#include "qaction_widgets_p.h"
+#if QT_CONFIG(menu)
+#include <private/qmenu_p.h>
+#endif
+#if QT_CONFIG(graphicsview)
+#include "qgraphicswidget.h"
+#endif
-#ifndef QT_NO_ACTION
-
-class QActionGroupPrivate;
+QT_BEGIN_NAMESPACE
-class Q_WIDGETS_EXPORT QActionGroup : public QObject
+QActionPrivate *QApplicationPrivate::createActionPrivate() const
{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QActionGroup)
-
- Q_PROPERTY(QActionGroup::ExclusionPolicy exclusionPolicy READ exclusionPolicy WRITE setExclusionPolicy)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
- Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
-
-public:
- enum class ExclusionPolicy {
- None,
- Exclusive,
- ExclusiveOptional
- };
- Q_ENUM(ExclusionPolicy)
-
- explicit QActionGroup(QObject* parent);
- ~QActionGroup();
-
- QAction *addAction(QAction* a);
- QAction *addAction(const QString &text);
- QAction *addAction(const QIcon &icon, const QString &text);
- void removeAction(QAction *a);
- QList<QAction*> actions() const;
+ return new QtWidgetsActionPrivate;
+}
- QAction *checkedAction() const;
- bool isExclusive() const;
- bool isEnabled() const;
- bool isVisible() const;
- ExclusionPolicy exclusionPolicy() const;
+QtWidgetsActionPrivate::~QtWidgetsActionPrivate() = default;
+// we can't do this in the destructor, as it would only be called by ~QObject
+void QtWidgetsActionPrivate::destroy()
+{
+ Q_Q(QAction);
+ const auto objects = associatedObjects;
+ for (int i = objects.size()-1; i >= 0; --i) {
+ QObject *object = objects.at(i);
+ if (QWidget *widget = qobject_cast<QWidget*>(object))
+ widget->removeAction(q);
+#if QT_CONFIG(graphicsview)
+ else if (QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget*>(object))
+ graphicsWidget->removeAction(q);
+#endif
+ }
+}
+
+QShortcutMap::ContextMatcher QtWidgetsActionPrivate::contextMatcher() const
+{
+ return qWidgetShortcutContextMatcher;
+}
-public Q_SLOTS:
- void setEnabled(bool);
- inline void setDisabled(bool b) { setEnabled(!b); }
- void setVisible(bool);
- void setExclusive(bool);
- void setExclusionPolicy(ExclusionPolicy policy);
-
-Q_SIGNALS:
- void triggered(QAction *);
- void hovered(QAction *);
-
-private:
- Q_DISABLE_COPY(QActionGroup)
- Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())
- Q_PRIVATE_SLOT(d_func(), void _q_actionChanged())
- Q_PRIVATE_SLOT(d_func(), void _q_actionHovered())
-};
+#if QT_CONFIG(menu)
+QObject *QtWidgetsActionPrivate::menu() const
+{
+ return m_menu;
+}
-#endif // QT_NO_ACTION
+void QtWidgetsActionPrivate::setMenu(QObject *menu)
+{
+ Q_Q(QAction);
+ QMenu *theMenu = qobject_cast<QMenu*>(menu);
+ Q_ASSERT_X(!menu || theMenu, "QAction::setMenu",
+ "QAction::setMenu expects a QMenu* in widget applications");
+ if (m_menu)
+ m_menu->d_func()->setOverrideMenuAction(nullptr); //we reset the default action of any previous menu
+ m_menu = theMenu;
+ if (m_menu)
+ m_menu->d_func()->setOverrideMenuAction(q);
+ sendDataChanged();
+}
+#endif // QT_CONFIG(menu)
QT_END_NAMESPACE
-
-#endif // QACTIONGROUP_H
diff --git a/src/widgets/kernel/qaction_p.h b/src/widgets/kernel/qaction_widgets_p.h
index 6b6ca8076f..02387c7371 100644
--- a/src/widgets/kernel/qaction_p.h
+++ b/src/widgets/kernel/qaction_widgets_p.h
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the QtWidgets module of the Qt Toolkit.
+** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QACTION_P_H
-#define QACTION_P_H
+#ifndef QACTION_WIDGETS_P_H
+#define QACTION_WIDGETS_P_H
//
// W A R N I N G
@@ -51,85 +51,34 @@
// We mean it.
//
-#include <QtWidgets/private/qtwidgetsglobal_p.h>
-#include "QtWidgets/qaction.h"
-#if QT_CONFIG(menu)
-#include "QtWidgets/qmenu.h"
-#endif
-#if QT_CONFIG(graphicsview)
-#include "private/qgraphicswidget_p.h"
-#endif
-#include "private/qobject_p.h"
-
-QT_BEGIN_NAMESPACE
+#include <QtGui/private/qaction_p.h>
+#include <QtWidgets/qmenu.h>
-#ifndef QT_NO_ACTION
+QT_REQUIRE_CONFIG(action);
+QT_BEGIN_NAMESPACE
class QShortcutMap;
-class Q_WIDGETS_EXPORT QActionPrivate : public QObjectPrivate
+class Q_WIDGETS_EXPORT QtWidgetsActionPrivate : public QActionPrivate
{
Q_DECLARE_PUBLIC(QAction)
public:
- QActionPrivate();
- ~QActionPrivate();
-
- static QActionPrivate *get(QAction *q)
- {
- return q->d_func();
- }
+ QtWidgetsActionPrivate() = default;
+ ~QtWidgetsActionPrivate();
- bool showStatusText(QWidget *w, const QString &str);
+ void destroy() override;
- QPointer<QActionGroup> group;
- QString text;
- QString iconText;
- QIcon icon;
- QString tooltip;
- QString statustip;
- QString whatsthis;
#if QT_CONFIG(shortcut)
- QKeySequence shortcut;
- QList<QKeySequence> alternateShortcuts;
+ QShortcutMap::ContextMatcher contextMatcher() const override;
#endif
- QVariant userData;
-#if QT_CONFIG(shortcut)
- int shortcutId = 0;
- QVector<int> alternateShortcutIds;
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut;
- uint autorepeat : 1;
-#endif
- QFont font;
- QPointer<QMenu> menu;
- uint enabled : 1, forceDisabled : 1;
- uint visible : 1, forceInvisible : 1;
- uint checkable : 1;
- uint checked : 1;
- uint separator : 1;
- uint fontSet : 1;
-
- int iconVisibleInMenu : 2; // Only has values -1, 0, and 1
- int shortcutVisibleInContextMenu : 2; // Only has values -1, 0, and 1
-
- QAction::MenuRole menuRole = QAction::TextHeuristicRole;
- QAction::Priority priority = QAction::NormalPriority;
- QWidgetList widgets;
-#if QT_CONFIG(graphicsview)
- QList<QGraphicsWidget *> graphicsWidgets;
-#endif
-#if QT_CONFIG(shortcut)
- void redoGrab(QShortcutMap &map);
- void redoGrabAlternate(QShortcutMap &map);
- void setShortcutEnabled(bool enable, QShortcutMap &map);
-#endif // QT_NO_SHORTCUT
+ QPointer<QMenu> m_menu;
- void sendDataChanged();
+ QObject *menu() const override;
+ void setMenu(QObject *menu) override;
};
-#endif // QT_NO_ACTION
-
QT_END_NAMESPACE
-#endif // QACTION_P_H
+#endif // QACTION_WIDGETS_P_H
diff --git a/src/widgets/kernel/qactiongroup.cpp b/src/widgets/kernel/qactiongroup.cpp
deleted file mode 100644
index d51fb778c4..0000000000
--- a/src/widgets/kernel/qactiongroup.cpp
+++ /dev/null
@@ -1,445 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include "qactiongroup.h"
-
-#ifndef QT_NO_ACTION
-
-#include "qaction_p.h"
-#include "qevent.h"
-#include "qlist.h"
-
-QT_BEGIN_NAMESPACE
-
-class QActionGroupPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QActionGroup)
-public:
- QActionGroupPrivate() : enabled(1),
- visible(1),
- exclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive)
- {
- }
- QList<QAction *> actions;
- QPointer<QAction> current;
- uint enabled : 1;
- uint visible : 1;
- QActionGroup::ExclusionPolicy exclusionPolicy;
-
-private:
- void _q_actionTriggered(); //private slot
- void _q_actionChanged(); //private slot
- void _q_actionHovered(); //private slot
-};
-
-void QActionGroupPrivate::_q_actionChanged()
-{
- Q_Q(QActionGroup);
- QAction *action = qobject_cast<QAction*>(q->sender());
- Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionChanged", "internal error");
- if (exclusionPolicy != QActionGroup::ExclusionPolicy::None) {
- if (action->isChecked()) {
- if (action != current) {
- if(current)
- current->setChecked(false);
- current = action;
- }
- } else if (action == current) {
- current = nullptr;
- }
- }
-}
-
-void QActionGroupPrivate::_q_actionTriggered()
-{
- Q_Q(QActionGroup);
- QAction *action = qobject_cast<QAction*>(q->sender());
- Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionTriggered", "internal error");
- emit q->triggered(action);
-}
-
-void QActionGroupPrivate::_q_actionHovered()
-{
- Q_Q(QActionGroup);
- QAction *action = qobject_cast<QAction*>(q->sender());
- Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionHovered", "internal error");
- emit q->hovered(action);
-}
-
-/*!
- \class QActionGroup
- \brief The QActionGroup class groups actions together.
-
- \ingroup mainwindow-classes
- \inmodule QtWidgets
-
- In some situations it is useful to group QAction objects together.
- For example, if you have a \uicontrol{Left Align} action, a \uicontrol{Right
- Align} action, a \uicontrol{Justify} action, and a \uicontrol{Center} action,
- only one of these actions should be active at any one time. One
- simple way of achieving this is to group the actions together in
- an action group.
-
- Here's a example (from the \l{mainwindows/menus}{Menus} example):
-
- \snippet mainwindows/menus/mainwindow.cpp 6
-
- Here we create a new action group. Since the action group is
- exclusive by default, only one of the actions in the group is
- checked at any one time.
-
- \image qactiongroup-align.png Alignment options in a QMenu
-
- A QActionGroup emits an triggered() signal when one of its
- actions is chosen. Each action in an action group emits its
- triggered() signal as usual.
-
- As stated above, an action group is exclusive by default; it
- ensures that at most only one checkable action is active at any one time.
- If you want to group checkable actions without making them
- exclusive, you can turn off exclusiveness by calling
- setExclusive(false).
-
- By default the active action of an exclusive group cannot be unchecked.
- In some cases it may be useful to allow unchecking all the actions,
- you can allow this by calling
- setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional).
-
- Actions can be added to an action group using addAction(), but it
- is usually more convenient to specify a group when creating
- actions; this ensures that actions are automatically created with
- a parent. Actions can be visually separated from each other by
- adding a separator action to the group; create an action and use
- QAction's \l {QAction::}{setSeparator()} function to make it
- considered a separator. Action groups are added to widgets with
- the QWidget::addActions() function.
-
- \sa QAction
-*/
-
-/*!
- \enum QActionGroup::ExclusionPolicy
-
- This enum specifies the different policies that can be used to
- control how the group performs exclusive checking on checkable actions.
-
- \value None
- The actions in the group can be checked independently of each other.
-
- \value Exclusive
- Exactly one action can be checked at any one time.
- This is the default policy.
-
- \value ExclusiveOptional
- At most one action can be checked at any one time. The actions
- can also be all unchecked.
-
- \sa exclusionPolicy
- \since 5.14
-*/
-
-/*!
- Constructs an action group for the \a parent object.
-
- The action group is exclusive by default. Call setExclusive(false)
- to make the action group non-exclusive. To make the group exclusive
- but allow unchecking the active action call instead
- setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional)
-*/
-QActionGroup::QActionGroup(QObject* parent) : QObject(*new QActionGroupPrivate, parent)
-{
-}
-
-/*!
- Destroys the action group.
-*/
-QActionGroup::~QActionGroup()
-{
-}
-
-/*!
- \fn QAction *QActionGroup::addAction(QAction *action)
-
- Adds the \a action to this group, and returns it.
-
- Normally an action is added to a group by creating it with the
- group as its parent, so this function is not usually used.
-
- \sa QAction::setActionGroup()
-*/
-QAction *QActionGroup::addAction(QAction* a)
-{
- Q_D(QActionGroup);
- if(!d->actions.contains(a)) {
- d->actions.append(a);
- QObject::connect(a, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
- QObject::connect(a, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
- QObject::connect(a, SIGNAL(hovered()), this, SLOT(_q_actionHovered()));
- }
- if(!a->d_func()->forceDisabled) {
- a->setEnabled(d->enabled);
- a->d_func()->forceDisabled = false;
- }
- if(!a->d_func()->forceInvisible) {
- a->setVisible(d->visible);
- a->d_func()->forceInvisible = false;
- }
- if(a->isChecked())
- d->current = a;
- QActionGroup *oldGroup = a->d_func()->group;
- if(oldGroup != this) {
- if (oldGroup)
- oldGroup->removeAction(a);
- a->d_func()->group = this;
- a->d_func()->sendDataChanged();
- }
- return a;
-}
-
-/*!
- Creates and returns an action with \a text. The newly created
- action is a child of this action group.
-
- Normally an action is added to a group by creating it with the
- group as parent, so this function is not usually used.
-
- \sa QAction::setActionGroup()
-*/
-QAction *QActionGroup::addAction(const QString &text)
-{
- return new QAction(text, this);
-}
-
-/*!
- Creates and returns an action with \a text and an \a icon. The
- newly created action is a child of this action group.
-
- Normally an action is added to a group by creating it with the
- group as its parent, so this function is not usually used.
-
- \sa QAction::setActionGroup()
-*/
-QAction *QActionGroup::addAction(const QIcon &icon, const QString &text)
-{
- return new QAction(icon, text, this);
-}
-
-/*!
- Removes the \a action from this group. The action will have no
- parent as a result.
-
- \sa QAction::setActionGroup()
-*/
-void QActionGroup::removeAction(QAction *action)
-{
- Q_D(QActionGroup);
- if (d->actions.removeAll(action)) {
- if (action == d->current)
- d->current = nullptr;
- QObject::disconnect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
- QObject::disconnect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
- QObject::disconnect(action, SIGNAL(hovered()), this, SLOT(_q_actionHovered()));
- action->d_func()->group = nullptr;
- }
-}
-
-/*!
- Returns the list of this groups's actions. This may be empty.
-*/
-QList<QAction*> QActionGroup::actions() const
-{
- Q_D(const QActionGroup);
- return d->actions;
-}
-
-/*!
- \brief Enable or disable the group exclusion checking
-
- This is a convenience method that calls
- setExclusionPolicy(ExclusionPolicy::Exclusive) when \a b is true,
- else setExclusionPolicy(QActionGroup::ExclusionPolicy::None).
-
- \sa QActionGroup::exclusionPolicy
-*/
-void QActionGroup::setExclusive(bool b)
-{
- setExclusionPolicy(b ? QActionGroup::ExclusionPolicy::Exclusive
- : QActionGroup::ExclusionPolicy::None);
-}
-
-/*!
- \brief Returns true if the group is exclusive
-
- The group is exclusive if the ExclusionPolicy is either Exclusive
- or ExclusionOptional.
-
-*/
-bool QActionGroup::isExclusive() const
-{
- return exclusionPolicy() != QActionGroup::ExclusionPolicy::None;
-}
-
-/*!
- \property QActionGroup::exclusionPolicy
- \brief This property holds the group exclusive checking policy
-
- If exclusionPolicy is set to Exclusive, only one checkable
- action in the action group can ever be active at any time. If the user
- chooses another checkable action in the group, the one they chose becomes
- active and the one that was active becomes inactive. If exclusionPolicy is
- set to ExclusionOptional the group is exclusive but the active checkable
- action in the group can be unchecked leaving the group with no actions
- checked.
-
- \sa QAction::checkable
- \since 5.14
-*/
-void QActionGroup::setExclusionPolicy(QActionGroup::ExclusionPolicy policy)
-{
- Q_D(QActionGroup);
- d->exclusionPolicy = policy;
-}
-
-QActionGroup::ExclusionPolicy QActionGroup::exclusionPolicy() const
-{
- Q_D(const QActionGroup);
- return d->exclusionPolicy;
-}
-
-/*!
- \fn void QActionGroup::setDisabled(bool b)
-
- This is a convenience function for the \l enabled property, that
- is useful for signals--slots connections. If \a b is true the
- action group is disabled; otherwise it is enabled.
-*/
-
-/*!
- \property QActionGroup::enabled
- \brief whether the action group is enabled
-
- Each action in the group will be enabled or disabled unless it
- has been explicitly disabled.
-
- \sa QAction::setEnabled()
-*/
-void QActionGroup::setEnabled(bool b)
-{
- Q_D(QActionGroup);
- d->enabled = b;
- for (auto action : qAsConst(d->actions)) {
- if (!action->d_func()->forceDisabled) {
- action->setEnabled(b);
- action->d_func()->forceDisabled = false;
- }
- }
-}
-
-bool QActionGroup::isEnabled() const
-{
- Q_D(const QActionGroup);
- return d->enabled;
-}
-
-/*!
- Returns the currently checked action in the group, or \nullptr if
- none are checked.
-*/
-QAction *QActionGroup::checkedAction() const
-{
- Q_D(const QActionGroup);
- return d->current;
-}
-
-/*!
- \property QActionGroup::visible
- \brief whether the action group is visible
-
- Each action in the action group will match the visible state of
- this group unless it has been explicitly hidden.
-
- \sa QAction::setEnabled()
-*/
-void QActionGroup::setVisible(bool b)
-{
- Q_D(QActionGroup);
- d->visible = b;
- for (auto action : qAsConst(d->actions)) {
- if (!action->d_func()->forceInvisible) {
- action->setVisible(b);
- action->d_func()->forceInvisible = false;
- }
- }
-}
-
-bool QActionGroup::isVisible() const
-{
- Q_D(const QActionGroup);
- return d->visible;
-}
-
-/*!
- \fn void QActionGroup::triggered(QAction *action)
-
- This signal is emitted when the given \a action in the action
- group is activated by the user; for example, when the user clicks
- a menu option, toolbar button, or presses an action's shortcut key
- combination.
-
- Connect to this signal for command actions.
-
- \sa QAction::activate()
-*/
-
-/*!
- \fn void QActionGroup::hovered(QAction *action)
-
- This signal is emitted when the given \a action in the action
- group is highlighted by the user; for example, when the user
- pauses with the cursor over a menu option, toolbar button, or
- presses an action's shortcut key combination.
-
- \sa QAction::activate()
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qactiongroup.cpp"
-
-#endif // QT_NO_ACTION
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 4ea70096e8..c5577e2772 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -90,6 +90,7 @@
#include <private/qthread_p.h>
#include <private/qfont_p.h>
+#include <private/qaction_p.h>
#include <stdlib.h>
@@ -101,10 +102,6 @@
#include "private/qgesturemanager_p.h"
#include <qpa/qplatformfontdatabase.h>
-#ifdef Q_OS_WIN
-#include <QtCore/qt_windows.h> // for qt_win_display_dc()
-#endif
-
#include "qdatetime.h"
#include <qpa/qplatformwindow.h>
@@ -308,22 +305,6 @@ void QApplicationPrivate::createEventDispatcher()
\sa QCoreApplication, QAbstractEventDispatcher, QEventLoop, QSettings
*/
-#if QT_DEPRECATED_SINCE(5, 8)
-// ### fixme: Qt 6: Remove ColorSpec and accessors.
-/*!
- \enum QApplication::ColorSpec
- \obsolete
-
- \value NormalColor the default color allocation policy
- \value CustomColor the same as NormalColor for X11; allocates colors
- to a palette on demand under Windows
- \value ManyColor the right choice for applications that use thousands of
- colors
-
- See setColorSpec() for full details.
-*/
-#endif
-
/*!
\fn QWidget *QApplication::topLevelAt(const QPoint &point)
@@ -369,7 +350,6 @@ QPointer<QWidget> QApplicationPrivate::wheel_widget;
#endif
bool qt_in_tab_key_event = false;
int qt_antialiasing_threshold = -1;
-QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut
int QApplicationPrivate::enabledAnimations = QPlatformTheme::GeneralUiEffect;
bool QApplicationPrivate::widgetCount = false;
#ifdef QT_KEYPAD_NAVIGATION
@@ -760,7 +740,6 @@ QApplication::~QApplication()
QApplicationPrivate::obey_desktop_settings = true;
- QApplicationPrivate::app_strut = QSize(0, 0);
QApplicationPrivate::enabledAnimations = QPlatformTheme::GeneralUiEffect;
QApplicationPrivate::widgetCount = false;
@@ -770,35 +749,12 @@ QApplication::~QApplication()
#endif
}
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
-// #fixme: Remove.
-static HDC displayDC = 0; // display device context
-
-Q_WIDGETS_EXPORT HDC qt_win_display_dc() // get display DC
-{
- Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());
- if (!displayDC)
- displayDC = GetDC(0);
- return displayDC;
-}
-#endif
-#endif
-
void qt_cleanup()
{
QPixmapCache::clear();
QColormap::cleanup();
QApplicationPrivate::active_window = nullptr; //### this should not be necessary
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
- if (displayDC) {
- ReleaseDC(0, displayDC);
- displayDC = 0;
- }
-#endif
-#endif
}
/*!
@@ -1143,109 +1099,6 @@ QStyle* QApplication::setStyle(const QString& style)
return s;
}
-#if QT_DEPRECATED_SINCE(5, 8)
-/*!
- Returns the color specification.
- \obsolete
-
- \sa QApplication::setColorSpec()
-*/
-
-int QApplication::colorSpec()
-{
- return QApplication::NormalColor;
-}
-
-/*!
- Sets the color specification for the application to \a spec.
- \obsolete
-
- This call has no effect.
-
- The color specification controls how the application allocates colors when
- run on a display with a limited amount of colors, e.g. 8 bit / 256 color
- displays.
-
- The color specification must be set before you create the QApplication
- object.
-
- The options are:
- \list
- \li QApplication::NormalColor. This is the default color allocation
- strategy. Use this option if your application uses buttons, menus,
- texts and pixmaps with few colors. With this option, the
- application uses system global colors. This works fine for most
- applications under X11, but on the Windows platform, it may cause
- dithering of non-standard colors.
- \li QApplication::CustomColor. Use this option if your application
- needs a small number of custom colors. On X11, this option is the
- same as NormalColor. On Windows, Qt creates a Windows palette, and
- allocates colors to it on demand.
- \li QApplication::ManyColor. Use this option if your application is
- very color hungry, e.g., it requires thousands of colors. \br
- Under X11 the effect is:
- \list
- \li For 256-color displays which have at best a 256 color true
- color visual, the default visual is used, and colors are
- allocated from a color cube. The color cube is the 6x6x6
- (216 color) "Web palette" (the red, green, and blue
- components always have one of the following values: 0x00,
- 0x33, 0x66, 0x99, 0xCC, or 0xFF), but the number of colors
- can be changed by the \e -ncols option. The user can force
- the application to use the true color visual with the
- \l{QApplication::QApplication()}{-visual} option.
- \li For 256-color displays which have a true color visual with
- more than 256 colors, use that visual. Silicon Graphics X
- servers this feature, for example. They provide an 8 bit
- visual by default but can deliver true color when asked.
- \endlist
- On Windows, Qt creates a Windows palette, and fills it with a color
- cube.
- \endlist
-
- Be aware that the CustomColor and ManyColor choices may lead to colormap
- flashing: The foreground application gets (most) of the available colors,
- while the background windows will look less attractive.
-
- Example:
-
- \snippet code/src_gui_kernel_qapplication.cpp 2
-
- \sa colorSpec()
-*/
-
-void QApplication::setColorSpec(int spec)
-{
- Q_UNUSED(spec)
-}
-#endif
-
-/*!
- \property QApplication::globalStrut
- \brief the minimum size that any GUI element that the user can interact
- with should have
- \deprecated
-
- For example, no button should be resized to be smaller than the global
- strut size. The strut size should be considered when reimplementing GUI
- controls that may be used on touch-screens or similar I/O devices.
-
- Example:
-
- \snippet code/src_gui_kernel_qapplication.cpp 3
-
- By default, this property contains a QSize object with zero width and height.
-*/
-QSize QApplication::globalStrut()
-{
- return QApplicationPrivate::app_strut;
-}
-
-void QApplication::setGlobalStrut(const QSize& strut)
-{
- QApplicationPrivate::app_strut = strut;
-}
-
// Widget specific palettes
QApplicationPrivate::PaletteHash QApplicationPrivate::widgetPalettes;
@@ -1571,24 +1424,6 @@ QString QApplicationPrivate::desktopStyleKey()
return QString();
}
-#if QT_VERSION < 0x060000 // remove these forwarders in Qt 6
-/*!
- \property QApplication::windowIcon
- \brief the default window icon
-
- \sa QWidget::setWindowIcon(), {Setting the Application Icon}
-*/
-QIcon QApplication::windowIcon()
-{
- return QGuiApplication::windowIcon();
-}
-
-void QApplication::setWindowIcon(const QIcon &icon)
-{
- QGuiApplication::setWindowIcon(icon);
-}
-#endif
-
void QApplicationPrivate::notifyWindowIconChanged()
{
QEvent ev(QEvent::ApplicationWindowIconChange);
@@ -1696,7 +1531,7 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
//send events
if (prev) {
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keyboardNavigationEnabled()) {
if (prev->hasEditFocus() && reason != Qt::PopupFocusReason)
prev->setEditFocus(false);
}
@@ -3821,51 +3656,6 @@ Qt::NavigationMode QApplication::navigationMode()
{
return QApplicationPrivate::navigationMode;
}
-
-# if QT_DEPRECATED_SINCE(5, 13)
-/*!
- Sets whether Qt should use focus navigation suitable for use with a
- minimal keypad.
-
- This feature is available in Qt for Embedded Linux, and Windows CE only.
-
- \note On Windows CE this feature is disabled by default for touch device
- mkspecs. To enable keypad navigation, build Qt with
- QT_KEYPAD_NAVIGATION defined.
-
- \deprecated
-
- \sa setNavigationMode()
-*/
-void QApplication::setKeypadNavigationEnabled(bool enable)
-{
- if (enable) {
- QApplication::setNavigationMode(Qt::NavigationModeKeypadTabOrder);
- } else {
- QApplication::setNavigationMode(Qt::NavigationModeNone);
- }
-}
-
-/*!
- Returns \c true if Qt is set to use keypad navigation; otherwise returns
- false. The default value is false.
-
- This feature is available in Qt for Embedded Linux, and Windows CE only.
-
- \note On Windows CE this feature is disabled by default for touch device
- mkspecs. To enable keypad navigation, build Qt with
- QT_KEYPAD_NAVIGATION defined.
-
- \deprecated
-
- \sa navigationMode()
-*/
-bool QApplication::keypadNavigationEnabled()
-{
- return QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadTabOrder ||
- QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadDirectional;
-}
-# endif
#endif
/*!
diff --git a/src/widgets/kernel/qapplication.h b/src/widgets/kernel/qapplication.h
index 6de72899f1..974c789e08 100644
--- a/src/widgets/kernel/qapplication.h
+++ b/src/widgets/kernel/qapplication.h
@@ -58,7 +58,6 @@ class QDesktopWidget;
class QStyle;
class QEventLoop;
class QIcon;
-template <typename T> class QList;
class QLocale;
class QPlatformNativeInterface;
@@ -72,16 +71,12 @@ class QApplicationPrivate;
class Q_WIDGETS_EXPORT QApplication : public QGuiApplication
{
Q_OBJECT
- Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
Q_PROPERTY(int cursorFlashTime READ cursorFlashTime WRITE setCursorFlashTime)
Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval)
Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
#if QT_CONFIG(wheelevent)
Q_PROPERTY(int wheelScrollLines READ wheelScrollLines WRITE setWheelScrollLines)
#endif
-#if QT_DEPRECATED_SINCE(5, 15)
- Q_PROPERTY(QSize globalStrut READ globalStrut WRITE setGlobalStrut)
-#endif
Q_PROPERTY(int startDragTime READ startDragTime WRITE setStartDragTime)
Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance)
#ifndef QT_NO_STYLE_STYLESHEET
@@ -100,14 +95,6 @@ public:
static QStyle *style();
static void setStyle(QStyle*);
static QStyle *setStyle(const QString&);
- enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
-#if QT_DEPRECATED_SINCE(5, 8)
- QT_DEPRECATED static int colorSpec();
- QT_DEPRECATED static void setColorSpec(int);
-#endif // QT_DEPRECATED_SINCE(5, 8)
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED static inline void setGraphicsSystem(const QString &) {}
-#endif
using QGuiApplication::palette;
static QPalette palette(const QWidget *);
@@ -119,11 +106,6 @@ public:
static void setFont(const QFont &, const char* className = nullptr);
static QFontMetrics fontMetrics();
-#if QT_VERSION < 0x060000 // remove these forwarders in Qt 6
- static void setWindowIcon(const QIcon &icon);
- static QIcon windowIcon();
-#endif
-
static QWidgetList allWidgets();
static QWidgetList topLevelWidgets();
@@ -141,9 +123,6 @@ public:
static QWidget *topLevelAt(const QPoint &p);
static inline QWidget *topLevelAt(int x, int y) { return topLevelAt(QPoint(x, y)); }
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED static inline void syncX() {}
-#endif
static void beep();
static void alert(QWidget *widget, int duration = 0);
@@ -160,10 +139,6 @@ public:
static void setWheelScrollLines(int);
static int wheelScrollLines();
#endif
-#if QT_DEPRECATED_SINCE(5, 15)
- static void setGlobalStrut(const QSize &);
- static QSize globalStrut();
-#endif
static void setStartDragTime(int ms);
static int startDragTime();
@@ -173,23 +148,10 @@ public:
static bool isEffectEnabled(Qt::UIEffect);
static void setEffectEnabled(Qt::UIEffect, bool enable = true);
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED static QLocale keyboardInputLocale()
- { return qApp ? QGuiApplication::inputMethod()->locale() : QLocale::c(); }
- QT_DEPRECATED static Qt::LayoutDirection keyboardInputDirection()
- { return qApp ? QGuiApplication::inputMethod()->inputDirection() : Qt::LeftToRight; }
-#endif
-
static int exec();
bool notify(QObject *, QEvent *) override;
#ifdef QT_KEYPAD_NAVIGATION
-# if QT_DEPRECATED_SINCE(5, 13)
- static QT_DEPRECATED_X ("Use QApplication::setNavigationMode() instead")
- void setKeypadNavigationEnabled(bool);
- static QT_DEPRECATED_X ("Use QApplication::navigationMode() instead")
- bool keypadNavigationEnabled();
-# endif
static void setNavigationMode(Qt::NavigationMode mode);
static Qt::NavigationMode navigationMode();
#endif
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index ab6d85aeb9..e1e391b13d 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -117,6 +117,13 @@ public:
void notifyWindowIconChanged() override;
+#ifndef QT_NO_ACTION
+ QActionPrivate *createActionPrivate() const override;
+#endif
+#ifndef QT_NO_SHORTCUT
+ QShortcutPrivate *createShortcutPrivate() const override;
+#endif
+
//modality
bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const override;
static bool isBlockedByModal(QWidget *widget);
diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp
deleted file mode 100644
index 9b4955320b..0000000000
--- a/src/widgets/kernel/qopenglwidget.cpp
+++ /dev/null
@@ -1,1471 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include "qopenglwidget.h"
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QOpenGLFramebufferObject>
-#include <QtGui/QOffscreenSurface>
-#include <QtGui/QOpenGLFunctions>
-#include <QtGui/QWindow>
-#include <QtGui/QGuiApplication>
-#include <QtGui/QScreen>
-#include <QtGui/QOpenGLPaintDevice>
-#include <QtGui/qpa/qplatformwindow.h>
-#include <QtGui/qpa/qplatformintegration.h>
-#include <QtGui/private/qguiapplication_p.h>
-#include <QtGui/private/qopenglextensions_p.h>
-#include <QtGui/private/qfont_p.h>
-#include <QtGui/private/qopenglpaintdevice_p.h>
-#include <QtGui/private/qopenglcontext_p.h>
-#include <QtWidgets/private/qwidget_p.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QOpenGLWidget
- \inmodule QtWidgets
- \since 5.4
-
- \brief The QOpenGLWidget class is a widget for rendering OpenGL graphics.
-
- QOpenGLWidget provides functionality for displaying OpenGL graphics
- integrated into a Qt application. It is very simple to use: Make
- your class inherit from it and use the subclass like any other
- QWidget, except that you have the choice between using QPainter and
- standard OpenGL rendering commands.
-
- QOpenGLWidget provides three convenient virtual functions that you
- can reimplement in your subclass to perform the typical OpenGL
- tasks:
-
- \list
- \li paintGL() - Renders the OpenGL scene. Gets called whenever the widget
- needs to be updated.
- \li resizeGL() - Sets up the OpenGL viewport, projection, etc. Gets
- called whenever the widget has been resized (and also when it
- is shown for the first time because all newly created widgets get a
- resize event automatically).
- \li initializeGL() - Sets up the OpenGL resources and state. Gets called
- once before the first time resizeGL() or paintGL() is called.
- \endlist
-
- If you need to trigger a repaint from places other than paintGL() (a
- typical example is when using \l{QTimer}{timers} to animate scenes),
- you should call the widget's update() function to schedule an update.
-
- Your widget's OpenGL rendering context is made current when
- paintGL(), resizeGL(), or initializeGL() is called. If you need to
- call the standard OpenGL API functions from other places (e.g. in
- your widget's constructor or in your own paint functions), you
- must call makeCurrent() first.
-
- All rendering happens into an OpenGL framebuffer
- object. makeCurrent() ensure that it is bound in the context. Keep
- this in mind when creating and binding additional framebuffer
- objects in the rendering code in paintGL(). Never re-bind the
- framebuffer with ID 0. Instead, call defaultFramebufferObject() to
- get the ID that should be bound.
-
- QOpenGLWidget allows using different OpenGL versions and profiles
- when the platform supports it. Just set the requested format via
- setFormat(). Keep in mind however that having multiple QOpenGLWidget
- instances in the same window requires that they all use the same
- format, or at least formats that do not make the contexts
- non-sharable. To overcome this issue, prefer using
- QSurfaceFormat::setDefaultFormat() instead of setFormat().
-
- \note Calling QSurfaceFormat::setDefaultFormat() before constructing
- the QApplication instance is mandatory on some platforms (for example,
- \macos) when an OpenGL core profile context is requested. This is to
- ensure that resource sharing between contexts stays functional as all
- internal contexts are created using the correct version and profile.
-
- \section1 Painting Techniques
-
- As described above, subclass QOpenGLWidget to render pure 3D content in the
- following way:
-
- \list
-
- \li Reimplement the initializeGL() and resizeGL() functions to
- set up the OpenGL state and provide a perspective transformation.
-
- \li Reimplement paintGL() to paint the 3D scene, calling only
- OpenGL functions.
-
- \endlist
-
- It is also possible to draw 2D graphics onto a QOpenGLWidget subclass using QPainter:
-
- \list
-
- \li In paintGL(), instead of issuing OpenGL commands, construct a QPainter
- object for use on the widget.
-
- \li Draw primitives using QPainter's member functions.
-
- \li Direct OpenGL commands can still be issued. However, you must make sure
- these are enclosed by a call to the painter's beginNativePainting() and
- endNativePainting().
-
- \endlist
-
- When performing drawing using QPainter only, it is also possible to perform
- the painting like it is done for ordinary widgets: by reimplementing paintEvent().
-
- \list
-
- \li Reimplement the paintEvent() function.
-
- \li Construct a QPainter object targeting the widget. Either pass the widget to the
- constructor or the QPainter::begin() function.
-
- \li Draw primitives using QPainter's member functions.
-
- \li Painting finishes then the QPainter instance is destroyed. Alternatively,
- call QPainter::end() explicitly.
-
- \endlist
-
- \section1 OpenGL Function Calls, Headers and QOpenGLFunctions
-
- When making OpenGL function calls, it is strongly recommended to avoid calling
- the functions directly. Instead, prefer using QOpenGLFunctions (when making
- portable applications) or the versioned variants (for example,
- QOpenGLFunctions_3_2_Core and similar, when targeting modern, desktop-only
- OpenGL). This way the application will work correctly in all Qt build
- configurations, including the ones that perform dynamic OpenGL implementation
- loading which means applications are not directly linking to an GL
- implementation and thus direct function calls are not feasible.
-
- In paintGL() the current context is always accessible by caling
- QOpenGLContext::currentContext(). From this context an already initialized,
- ready-to-be-used QOpenGLFunctions instance is retrievable by calling
- QOpenGLContext::functions(). An alternative to prefixing every GL call is to
- inherit from QOpenGLFunctions and call
- QOpenGLFunctions::initializeOpenGLFunctions() in initializeGL().
-
- As for the OpenGL headers, note that in most cases there will be no need to
- directly include any headers like GL.h. The OpenGL-related Qt headers will
- include qopengl.h which will in turn include an appropriate header for the
- system. This might be an OpenGL ES 3.x or 2.0 header, the highest version that
- is available, or a system-provided gl.h. In addition, a copy of the extension
- headers (called glext.h on some systems) is provided as part of Qt both for
- OpenGL and OpenGL ES. These will get included automatically on platforms where
- feasible. This means that constants and function pointer typedefs from ARB,
- EXT, OES extensions are automatically available.
-
- \section1 Code Examples
-
- To get started, the simplest QOpenGLWidget subclass could like like the following:
-
- \snippet code/doc_gui_widgets_qopenglwidget.cpp 0
-
- Alternatively, the prefixing of each and every OpenGL call can be avoided by deriving
- from QOpenGLFunctions instead:
-
- \snippet code/doc_gui_widgets_qopenglwidget.cpp 1
-
- To get a context compatible with a given OpenGL version or profile, or to
- request depth and stencil buffers, call setFormat():
-
- \snippet code/doc_gui_widgets_qopenglwidget.cpp 2
-
- With OpenGL 3.0+ contexts, when portability is not important, the versioned
- QOpenGLFunctions variants give easy access to all the modern OpenGL functions
- available in a given version:
-
- \snippet code/doc_gui_widgets_qopenglwidget.cpp 3
-
- As described above, it is simpler and more robust to set the requested format
- globally so that it applies to all windows and contexts during the lifetime of
- the application. Below is an example of this:
-
- \snippet code/doc_gui_widgets_qopenglwidget.cpp 6
-
- \section1 Relation to QGLWidget
-
- The legacy QtOpenGL module (classes prefixed with QGL) provides a widget
- called QGLWidget. QOpenGLWidget is intended to be a modern replacement for
- it. Therefore, especially in new applications, the general recommendation is
- to use QOpenGLWidget.
-
- While the API is very similar, there is an important difference between the
- two: QOpenGLWidget always renders offscreen, using framebuffer
- objects. QGLWidget on the other hand uses a native window and surface. The
- latter causes issues when using it in complex user interfaces since, depending
- on the platform, such native child widgets may have various limitations,
- regarding stacking orders for example. QOpenGLWidget avoids this by not
- creating a separate native window.
-
- Due to being backed by a framebuffer object, the behavior of QOpenGLWidget is
- very similar to QOpenGLWindow with the update behavior set to \c
- PartialUpdateBlit or \c PartialUpdateBlend. This means that the contents are
- preserved between paintGL() calls so that incremental rendering is
- possible. With QGLWidget (and naturally QOpenGLWindow with the default update
- behavior) this is usually not the case because swapping the buffers leaves the
- back buffer with undefined contents.
-
- \note Most applications do not need incremental rendering because they will
- render everything in the view on every paint call. In this case it is
- important to call glClear() as early as possible in paintGL(). This helps
- mobile GPUs that use a tile-based architecture to recognize that the tile
- buffer does not need to be reloaded with the framebuffer's previous
- contents. Omitting the clear call can lead to significant performance drops on
- such systems.
-
- \note Avoid calling winId() on a QOpenGLWidget. This function triggers the creation of
- a native window, resulting in reduced performance and possibly rendering glitches.
-
- \section1 Differences to QGLWidget
-
- Besides the main conceptual difference of being backed by a framebuffer object, there
- are a number of smaller, internal differences between QOpenGLWidget and the older
- QGLWidget:
-
- \list
-
- \li OpenGL state when invoking paintGL(). QOpenGLWidget sets up the viewport via
- glViewport(). It does not perform any clearing.
-
- \li Clearing when starting to paint via QPainter. Unlike regular widgets, QGLWidget
- defaulted to a value of \c true for
- \l{QWidget::autoFillBackground()}{autoFillBackground}. It then performed clearing to the
- palette's background color every time QPainter::begin() was used. QOpenGLWidget does not
- follow this: \l{QWidget::autoFillBackground()}{autoFillBackground} defaults to false,
- like for any other widget. The only exception is when being used as a viewport for other
- widgets like QGraphicsView. In such a case autoFillBackground will be automatically set
- to true to ensure compatibility with QGLWidget-based viewports.
-
- \endlist
-
- \section1 Multisampling
-
- To enable multisampling, set the number of requested samples on the
- QSurfaceFormat that is passed to setFormat(). On systems that do not support
- it the request may get ignored.
-
- Multisampling support requires support for multisampled renderbuffers and
- framebuffer blits. On OpenGL ES 2.0 implementations it is likely that these
- will not be present. This means that multisampling will not be available. With
- modern OpenGL versions and OpenGL ES 3.0 and up this is usually not a problem
- anymore.
-
- \section1 Threading
-
- Performing offscreen rendering on worker threads, for example to generate
- textures that are then used in the GUI/main thread in paintGL(), are supported
- by exposing the widget's QOpenGLContext so that additional contexts sharing
- with it can be created on each thread.
-
- Drawing directly to the QOpenGLWidget's framebuffer outside the GUI/main
- thread is possible by reimplementing paintEvent() to do nothing. The context's
- thread affinity has to be changed via QObject::moveToThread(). After that,
- makeCurrent() and doneCurrent() are usable on the worker thread. Be careful to
- move the context back to the GUI/main thread afterwards.
-
- Unlike QGLWidget, triggering a buffer swap just for the QOpenGLWidget is not
- possible since there is no real, onscreen native surface for it. Instead, it
- is up to the widget stack to manage composition and buffer swaps on the gui
- thread. When a thread is done updating the framebuffer, call update() \b{on
- the GUI/main thread} to schedule composition.
-
- Extra care has to be taken to avoid using the framebuffer when the GUI/main
- thread is performing compositing. The signals aboutToCompose() and
- frameSwapped() will be emitted when the composition is starting and
- ending. They are emitted on the GUI/main thread. This means that by using a
- direct connection aboutToCompose() can block the GUI/main thread until the
- worker thread has finished its rendering. After that, the worker thread must
- perform no further rendering until the frameSwapped() signal is emitted. If
- this is not acceptable, the worker thread has to implement a double buffering
- mechanism. This involves drawing using an alternative render target, that is
- fully controlled by the thread, e.g. an additional framebuffer object, and
- blitting to the QOpenGLWidget's framebuffer at a suitable time.
-
- \section1 Context Sharing
-
- When multiple QOpenGLWidgets are added as children to the same top-level
- widget, their contexts will share with each other. This does not apply for
- QOpenGLWidget instances that belong to different windows.
-
- This means that all QOpenGLWidgets in the same window can access each other's
- sharable resources, like textures, and there is no need for an extra "global
- share" context, as was the case with QGLWidget.
-
- To set up sharing between QOpenGLWidget instances belonging to different
- windows, set the Qt::AA_ShareOpenGLContexts application attribute before
- instantiating QApplication. This will trigger sharing between all
- QOpenGLWidget instances without any further steps.
-
- Creating extra QOpenGLContext instances that share resources like textures
- with the QOpenGLWidget's context is also possible. Simply pass the pointer
- returned from context() to QOpenGLContext::setShareContext() before calling
- QOpenGLContext::create(). The resulting context can also be used on a
- different thread, allowing threaded generation of textures and asynchronous
- texture uploads.
-
- Note that QOpenGLWidget expects a standard conformant implementation of
- resource sharing when it comes to the underlying graphics drivers. For
- example, some drivers, in particular for mobile and embedded hardware, have
- issues with setting up sharing between an existing context and others that are
- created later. Some other drivers may behave in unexpected ways when trying to
- utilize shared resources between different threads.
-
- \section1 Resource Initialization and Cleanup
-
- The QOpenGLWidget's associated OpenGL context is guaranteed to be current
- whenever initializeGL() and paintGL() are invoked. Do not attempt to create
- OpenGL resources before initializeGL() is called. For example, attempting to
- compile shaders, initialize vertex buffer objects or upload texture data will
- fail when done in a subclass's constructor. These operations must be deferred
- to initializeGL(). Some of Qt's OpenGL helper classes, like QOpenGLBuffer or
- QOpenGLVertexArrayObject, have a matching deferred behavior: they can be
- instantiated without a context, but all initialization is deferred until a
- create(), or similar, call. This means that they can be used as normal
- (non-pointer) member variables in a QOpenGLWidget subclass, but the create()
- or similar function can only be called from initializeGL(). Be aware however
- that not all classes are designed like this. When in doubt, make the member
- variable a pointer and create and destroy the instance dynamically in
- initializeGL() and the destructor, respectively.
-
- Releasing the resources also needs the context to be current. Therefore
- destructors that perform such cleanup are expected to call makeCurrent()
- before moving on to destroy any OpenGL resources or wrappers. Avoid deferred
- deletion via \l{QObject::deleteLater()}{deleteLater()} or the parenting
- mechanism of QObject. There is no guarantee the correct context will be
- current at the time the instance in question is really destroyed.
-
- A typical subclass will therefore often look like the following when it comes
- to resource initialization and destruction:
-
- \snippet code/doc_gui_widgets_qopenglwidget.cpp 4
-
- This is naturally not the only possible solution. One alternative is to use
- the \l{QOpenGLContext::aboutToBeDestroyed()}{aboutToBeDestroyed()} signal of
- QOpenGLContext. By connecting a slot, using direct connection, to this signal,
- it is possible to perform cleanup whenever the underlying native context
- handle, or the entire QOpenGLContext instance, is going to be released. The
- following snippet is in principle equivalent to the previous one:
-
- \snippet code/doc_gui_widgets_qopenglwidget.cpp 5
-
- \note For widgets that change their associated top-level window multiple times
- during their lifetime, a combined approach is essential. Whenever the widget
- or a parent of it gets reparented so that the top-level window becomes
- different, the widget's associated context is destroyed and a new one is
- created. This is then followed by a call to initializeGL() where all OpenGL
- resources must get reinitialized. Due to this the only option to perform
- proper cleanup is to connect to the context's aboutToBeDestroyed()
- signal. Note that the context in question may not be the current one when the
- signal gets emitted. Therefore it is good practice to call makeCurrent() in
- the connected slot. Additionally, the same cleanup steps must be performed
- from the derived class' destructor, since the slot connected to the signal
- will not get invoked when the widget is being destroyed.
-
- \note When Qt::AA_ShareOpenGLContexts is set, the widget's context never
- changes, not even when reparenting because the widget's associated texture is
- guaranteed to be accessible also from the new top-level's context.
-
- Proper cleanup is especially important due to context sharing. Even though
- each QOpenGLWidget's associated context is destroyed together with the
- QOpenGLWidget, the sharable resources in that context, like textures, will
- stay valid until the top-level window, in which the QOpenGLWidget lived, is
- destroyed. Additionally, settings like Qt::AA_ShareOpenGLContexts and some Qt
- modules may trigger an even wider scope for sharing contexts, potentially
- leading to keeping the resources in question alive for the entire lifetime of
- the application. Therefore the safest and most robust is always to perform
- explicit cleanup for all resources and resource wrappers used in the
- QOpenGLWidget.
-
- \section1 Limitations
-
- Putting other widgets underneath and making the QOpenGLWidget transparent will
- not lead to the expected results: The widgets underneath will not be
- visible. This is because in practice the QOpenGLWidget is drawn before all
- other regular, non-OpenGL widgets, and so see-through type of solutions are
- not feasible. Other type of layouts, like having widgets on top of the
- QOpenGLWidget, will function as expected.
-
- When absolutely necessary, this limitation can be overcome by setting the
- Qt::WA_AlwaysStackOnTop attribute on the QOpenGLWidget. Be aware however that
- this breaks stacking order, for example it will not be possible to have other
- widgets on top of the QOpenGLWidget, so it should only be used in situations
- where a semi-transparent QOpenGLWidget with other widgets visible underneath
- is required.
-
- Note that this does not apply when there are no other widgets underneath and
- the intention is to have a semi-transparent window. In that case the
- traditional approach of setting Qt::WA_TranslucentBackground
- on the top-level window is sufficient. Note that if the transparent areas are
- only desired in the QOpenGLWidget, then Qt::WA_NoSystemBackground will need
- to be turned back to \c false after enabling Qt::WA_TranslucentBackground.
- Additionally, requesting an alpha channel for the QOpenGLWidget's context via
- setFormat() may be necessary too, depending on the system.
-
- QOpenGLWidget supports multiple update behaviors, just like QOpenGLWindow. In
- preserved mode the rendered content from the previous paintGL() call is
- available in the next one, allowing incremental rendering. In non-preserved
- mode the content is lost and paintGL() implementations are expected to redraw
- everything in the view.
-
- Before Qt 5.5 the default behavior of QOpenGLWidget was to preserve the
- rendered contents between paintGL() calls. Since Qt 5.5 the default behavior
- is non-preserved because this provides better performance and the majority of
- applications have no need for the previous content. This also resembles the
- semantics of an OpenGL-based QWindow and matches the default behavior of
- QOpenGLWindow in that the color and ancillary buffers are invalidated for
- each frame. To restore the preserved behavior, call setUpdateBehavior() with
- \c PartialUpdate.
-
- \section1 Alternatives
-
- Adding a QOpenGLWidget into a window turns on OpenGL-based
- compositing for the entire window. In some special cases this may
- not be ideal, and the old QGLWidget-style behavior with a separate,
- native child window is desired. Desktop applications that understand
- the limitations of this approach (for example when it comes to
- overlaps, transparency, scroll views and MDI areas), can use
- QOpenGLWindow with QWidget::createWindowContainer(). This is a
- modern alternative to QGLWidget and is faster than QOpenGLWidget due
- to the lack of the additional composition step. It is strongly
- recommended to limit the usage of this approach to cases where there
- is no other choice. Note that this option is not suitable for most
- embedded and mobile platforms, and it is known to have issues on
- certain desktop platforms (e.g. \macos) too. The stable,
- cross-platform solution is always QOpenGLWidget.
-
- \e{OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other
- countries.}
-
- \sa QOpenGLFunctions, QOpenGLWindow, Qt::AA_ShareOpenGLContexts, UpdateBehavior
-*/
-
-/*!
- \fn void QOpenGLWidget::aboutToCompose()
-
- This signal is emitted when the widget's top-level window is about to begin
- composing the textures of its QOpenGLWidget children and the other widgets.
-*/
-
-/*!
- \fn void QOpenGLWidget::frameSwapped()
-
- This signal is emitted after the widget's top-level window has finished
- composition and returned from its potentially blocking
- QOpenGLContext::swapBuffers() call.
-*/
-
-/*!
- \fn void QOpenGLWidget::aboutToResize()
-
- This signal is emitted when the widget's size is changed and therefore the
- framebuffer object is going to be recreated.
-*/
-
-/*!
- \fn void QOpenGLWidget::resized()
-
- This signal is emitted right after the framebuffer object has been recreated
- due to resizing the widget.
-*/
-
-/*!
- \enum QOpenGLWidget::UpdateBehavior
- \since 5.5
-
- This enum describes the update semantics of QOpenGLWidget.
-
- \value NoPartialUpdate QOpenGLWidget will discard the
- contents of the color buffer and the ancillary buffers after the
- QOpenGLWidget is rendered to screen. This is the same behavior that can be
- expected by calling QOpenGLContext::swapBuffers with a default opengl
- enabled QWindow as the argument. NoPartialUpdate can have some performance
- benefits on certain hardware architectures common in the mobile and
- embedded space when a framebuffer object is used as the rendering target.
- The framebuffer object is invalidated between frames with
- glDiscardFramebufferEXT if supported or a glClear. Please see the
- documentation of EXT_discard_framebuffer for more information:
- https://www.khronos.org/registry/gles/extensions/EXT/EXT_discard_framebuffer.txt
-
- \value PartialUpdate The framebuffer objects color buffer and ancillary
- buffers are not invalidated between frames.
-
- \sa updateBehavior(), setUpdateBehavior()
-*/
-
-class QOpenGLWidgetPaintDevicePrivate : public QOpenGLPaintDevicePrivate
-{
-public:
- QOpenGLWidgetPaintDevicePrivate(QOpenGLWidget *widget)
- : QOpenGLPaintDevicePrivate(QSize()),
- w(widget) { }
-
- void beginPaint() override;
- void endPaint() override;
-
- QOpenGLWidget *w;
-};
-
-class QOpenGLWidgetPaintDevice : public QOpenGLPaintDevice
-{
-public:
- QOpenGLWidgetPaintDevice(QOpenGLWidget *widget)
- : QOpenGLPaintDevice(*new QOpenGLWidgetPaintDevicePrivate(widget)) { }
- void ensureActiveTarget() override;
-};
-
-class QOpenGLWidgetPrivate : public QWidgetPrivate
-{
- Q_DECLARE_PUBLIC(QOpenGLWidget)
-public:
- QOpenGLWidgetPrivate()
- : context(nullptr),
- fbo(nullptr),
- resolvedFbo(nullptr),
- surface(nullptr),
- initialized(false),
- fakeHidden(false),
- inBackingStorePaint(false),
- hasBeenComposed(false),
- flushPending(false),
- paintDevice(nullptr),
- updateBehavior(QOpenGLWidget::NoPartialUpdate),
- requestedSamples(0),
- inPaintGL(false),
- textureFormat(0)
- {
- requestedFormat = QSurfaceFormat::defaultFormat();
- }
-
- void reset();
- void recreateFbo();
-
- GLuint textureId() const override;
- QPlatformTextureList::Flags textureListFlags() override;
-
- void initialize();
- void invokeUserPaint();
- void render();
-
- void invalidateFbo();
-
- QImage grabFramebuffer() override;
- void beginBackingStorePainting() override { inBackingStorePaint = true; }
- void endBackingStorePainting() override { inBackingStorePaint = false; }
- void beginCompose() override;
- void endCompose() override;
- void initializeViewportFramebuffer() override;
- void resizeViewportFramebuffer() override;
- void resolveSamples() override;
-
- QOpenGLContext *context;
- QOpenGLFramebufferObject *fbo;
- QOpenGLFramebufferObject *resolvedFbo;
- QOffscreenSurface *surface;
- bool initialized;
- bool fakeHidden;
- bool inBackingStorePaint;
- bool hasBeenComposed;
- bool flushPending;
- QOpenGLPaintDevice *paintDevice;
- QSurfaceFormat requestedFormat;
- QOpenGLWidget::UpdateBehavior updateBehavior;
- int requestedSamples;
- bool inPaintGL;
- GLenum textureFormat;
-};
-
-void QOpenGLWidgetPaintDevicePrivate::beginPaint()
-{
- // NB! autoFillBackground is and must be false by default. Otherwise we would clear on
- // every QPainter begin() which is not desirable. This is only for legacy use cases,
- // like using QOpenGLWidget as the viewport of a graphics view, that expect clearing
- // with the palette's background color.
- if (w->autoFillBackground()) {
- QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- if (w->format().hasAlpha()) {
- f->glClearColor(0, 0, 0, 0);
- } else {
- QColor c = w->palette().brush(w->backgroundRole()).color();
- float alpha = c.alphaF();
- f->glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha);
- }
- f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- }
-}
-
-void QOpenGLWidgetPaintDevicePrivate::endPaint()
-{
- QOpenGLWidgetPrivate *wd = static_cast<QOpenGLWidgetPrivate *>(QWidgetPrivate::get(w));
- if (!wd->initialized)
- return;
-
- if (!wd->inPaintGL)
- QOpenGLContextPrivate::get(wd->context)->defaultFboRedirect = 0;
-}
-
-void QOpenGLWidgetPaintDevice::ensureActiveTarget()
-{
- QOpenGLWidgetPaintDevicePrivate *d = static_cast<QOpenGLWidgetPaintDevicePrivate *>(d_ptr.data());
- QOpenGLWidgetPrivate *wd = static_cast<QOpenGLWidgetPrivate *>(QWidgetPrivate::get(d->w));
- if (!wd->initialized)
- return;
-
- if (QOpenGLContext::currentContext() != wd->context)
- d->w->makeCurrent();
- else
- wd->fbo->bind();
-
- if (!wd->inPaintGL)
- QOpenGLContextPrivate::get(wd->context)->defaultFboRedirect = wd->fbo->handle();
-
- // When used as a viewport, drawing is done via opening a QPainter on the widget
- // without going through paintEvent(). We will have to make sure a glFlush() is done
- // before the texture is accessed also in this case.
- wd->flushPending = true;
-}
-
-GLuint QOpenGLWidgetPrivate::textureId() const
-{
- return resolvedFbo ? resolvedFbo->texture() : (fbo ? fbo->texture() : 0);
-}
-
-#ifndef GL_SRGB
-#define GL_SRGB 0x8C40
-#endif
-#ifndef GL_SRGB8
-#define GL_SRGB8 0x8C41
-#endif
-#ifndef GL_SRGB_ALPHA
-#define GL_SRGB_ALPHA 0x8C42
-#endif
-#ifndef GL_SRGB8_ALPHA8
-#define GL_SRGB8_ALPHA8 0x8C43
-#endif
-
-QPlatformTextureList::Flags QOpenGLWidgetPrivate::textureListFlags()
-{
- QPlatformTextureList::Flags flags = QWidgetPrivate::textureListFlags();
- switch (textureFormat) {
- case GL_SRGB:
- case GL_SRGB8:
- case GL_SRGB_ALPHA:
- case GL_SRGB8_ALPHA8:
- flags |= QPlatformTextureList::TextureIsSrgb;
- break;
- default:
- break;
- }
- return flags;
-}
-
-void QOpenGLWidgetPrivate::reset()
-{
- Q_Q(QOpenGLWidget);
-
- // Destroy the OpenGL resources first. These need the context to be current.
- if (initialized)
- q->makeCurrent();
-
- delete paintDevice;
- paintDevice = nullptr;
- delete fbo;
- fbo = nullptr;
- delete resolvedFbo;
- resolvedFbo = nullptr;
-
- if (initialized)
- q->doneCurrent();
-
- // Delete the context first, then the surface. Slots connected to
- // the context's aboutToBeDestroyed() may still call makeCurrent()
- // to perform some cleanup.
- delete context;
- context = nullptr;
- delete surface;
- surface = nullptr;
- initialized = fakeHidden = inBackingStorePaint = false;
-}
-
-void QOpenGLWidgetPrivate::recreateFbo()
-{
- Q_Q(QOpenGLWidget);
-
- emit q->aboutToResize();
-
- context->makeCurrent(surface);
-
- delete fbo;
- fbo = nullptr;
- delete resolvedFbo;
- resolvedFbo = nullptr;
-
- int samples = requestedSamples;
- QOpenGLExtensions *extfuncs = static_cast<QOpenGLExtensions *>(context->functions());
- if (!extfuncs->hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample))
- samples = 0;
-
- QOpenGLFramebufferObjectFormat format;
- format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
- format.setSamples(samples);
- if (textureFormat)
- format.setInternalTextureFormat(textureFormat);
-
- const QSize deviceSize = q->size() * q->devicePixelRatioF();
- fbo = new QOpenGLFramebufferObject(deviceSize, format);
- if (samples > 0)
- resolvedFbo = new QOpenGLFramebufferObject(deviceSize);
-
- textureFormat = fbo->format().internalTextureFormat();
-
- fbo->bind();
- context->functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- flushPending = true; // Make sure the FBO is initialized before use
-
- paintDevice->setSize(deviceSize);
- paintDevice->setDevicePixelRatio(q->devicePixelRatioF());
-
- emit q->resized();
-}
-
-void QOpenGLWidgetPrivate::beginCompose()
-{
- Q_Q(QOpenGLWidget);
- if (flushPending) {
- flushPending = false;
- q->makeCurrent();
- static_cast<QOpenGLExtensions *>(context->functions())->flushShared();
- }
- hasBeenComposed = true;
- emit q->aboutToCompose();
-}
-
-void QOpenGLWidgetPrivate::endCompose()
-{
- Q_Q(QOpenGLWidget);
- emit q->frameSwapped();
-}
-
-void QOpenGLWidgetPrivate::initialize()
-{
- Q_Q(QOpenGLWidget);
- if (initialized)
- return;
-
- // If no global shared context get our toplevel's context with which we
- // will share in order to make the texture usable by the underlying window's backingstore.
- QWidget *tlw = q->window();
- QOpenGLContext *shareContext = qt_gl_global_share_context();
- if (!shareContext)
- shareContext = get(tlw)->shareContext();
- // If shareContext is null, showing content on-screen will not work.
- // However, offscreen rendering and grabFramebuffer() will stay fully functional.
-
- // Do not include the sample count. Requesting a multisampled context is not necessary
- // since we render into an FBO, never to an actual surface. What's more, attempting to
- // create a pbuffer with a multisampled config crashes certain implementations. Just
- // avoid the entire hassle, the result is the same.
- requestedSamples = requestedFormat.samples();
- requestedFormat.setSamples(0);
-
- QScopedPointer<QOpenGLContext> ctx(new QOpenGLContext);
- ctx->setFormat(requestedFormat);
- if (shareContext) {
- ctx->setShareContext(shareContext);
- ctx->setScreen(shareContext->screen());
- }
- if (Q_UNLIKELY(!ctx->create())) {
- qWarning("QOpenGLWidget: Failed to create context");
- return;
- }
-
- // Propagate settings that make sense only for the tlw. Note that this only
- // makes sense for properties that get picked up even after the native
- // window is created.
- if (tlw->windowHandle()) {
- QSurfaceFormat tlwFormat = tlw->windowHandle()->format();
- if (requestedFormat.swapInterval() != tlwFormat.swapInterval()) {
- // Most platforms will pick up the changed swap interval on the next
- // makeCurrent or swapBuffers.
- tlwFormat.setSwapInterval(requestedFormat.swapInterval());
- tlw->windowHandle()->setFormat(tlwFormat);
- }
- if (requestedFormat.swapBehavior() != tlwFormat.swapBehavior()) {
- tlwFormat.setSwapBehavior(requestedFormat.swapBehavior());
- tlw->windowHandle()->setFormat(tlwFormat);
- }
- }
-
- // The top-level window's surface is not good enough since it causes way too
- // much trouble with regards to the QSurfaceFormat for example. So just like
- // in QQuickWidget, use a dedicated QOffscreenSurface.
- surface = new QOffscreenSurface;
- surface->setFormat(ctx->format());
- surface->setScreen(ctx->screen());
- surface->create();
-
- if (Q_UNLIKELY(!ctx->makeCurrent(surface))) {
- qWarning("QOpenGLWidget: Failed to make context current");
- return;
- }
-
- paintDevice = new QOpenGLWidgetPaintDevice(q);
- paintDevice->setSize(q->size() * q->devicePixelRatioF());
- paintDevice->setDevicePixelRatio(q->devicePixelRatioF());
-
- context = ctx.take();
- initialized = true;
-
- q->initializeGL();
-}
-
-void QOpenGLWidgetPrivate::resolveSamples()
-{
- Q_Q(QOpenGLWidget);
- if (resolvedFbo) {
- q->makeCurrent();
- QRect rect(QPoint(0, 0), fbo->size());
- QOpenGLFramebufferObject::blitFramebuffer(resolvedFbo, rect, fbo, rect);
- flushPending = true;
- }
-}
-
-void QOpenGLWidgetPrivate::invokeUserPaint()
-{
- Q_Q(QOpenGLWidget);
-
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
- Q_ASSERT(ctx && fbo);
-
- QOpenGLFunctions *f = ctx->functions();
- QOpenGLContextPrivate::get(ctx)->defaultFboRedirect = fbo->handle();
-
- f->glViewport(0, 0, q->width() * q->devicePixelRatioF(), q->height() * q->devicePixelRatioF());
- inPaintGL = true;
- q->paintGL();
- inPaintGL = false;
- flushPending = true;
-
- QOpenGLContextPrivate::get(ctx)->defaultFboRedirect = 0;
-}
-
-void QOpenGLWidgetPrivate::render()
-{
- Q_Q(QOpenGLWidget);
-
- if (fakeHidden || !initialized)
- return;
-
- q->makeCurrent();
-
- if (updateBehavior == QOpenGLWidget::NoPartialUpdate && hasBeenComposed) {
- invalidateFbo();
- hasBeenComposed = false;
- }
-
- invokeUserPaint();
-}
-
-void QOpenGLWidgetPrivate::invalidateFbo()
-{
- QOpenGLExtensions *f = static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions());
- if (f->hasOpenGLExtension(QOpenGLExtensions::DiscardFramebuffer)) {
- const int gl_color_attachment0 = 0x8CE0; // GL_COLOR_ATTACHMENT0
- const int gl_depth_attachment = 0x8D00; // GL_DEPTH_ATTACHMENT
- const int gl_stencil_attachment = 0x8D20; // GL_STENCIL_ATTACHMENT
-#ifdef Q_OS_WASM
- // webgl does not allow separate depth and stencil attachments
- // QTBUG-69913
- const int gl_depth_stencil_attachment = 0x821A; // GL_DEPTH_STENCIL_ATTACHMENT
-
- const GLenum attachments[] = {
- gl_color_attachment0, gl_depth_attachment, gl_stencil_attachment, gl_depth_stencil_attachment
- };
-#else
- const GLenum attachments[] = {
- gl_color_attachment0, gl_depth_attachment, gl_stencil_attachment
- };
-#endif
- f->glDiscardFramebufferEXT(GL_FRAMEBUFFER, sizeof attachments / sizeof *attachments, attachments);
- } else {
- f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- }
-}
-
-extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
-
-QImage QOpenGLWidgetPrivate::grabFramebuffer()
-{
- Q_Q(QOpenGLWidget);
-
- initialize();
- if (!initialized)
- return QImage();
-
- if (!fbo) // could be completely offscreen, without ever getting a resize event
- recreateFbo();
-
- if (!inPaintGL)
- render();
-
- if (resolvedFbo) {
- resolveSamples();
- resolvedFbo->bind();
- } else {
- q->makeCurrent();
- }
-
- const bool hasAlpha = q->format().hasAlpha();
- QImage res = qt_gl_read_framebuffer(q->size() * q->devicePixelRatioF(), hasAlpha, hasAlpha);
- res.setDevicePixelRatio(q->devicePixelRatioF());
-
- // While we give no guarantees of what is going to be left bound, prefer the
- // multisample fbo instead of the resolved one. Clients may continue to
- // render straight after calling this function.
- if (resolvedFbo)
- q->makeCurrent();
-
- return res;
-}
-
-void QOpenGLWidgetPrivate::initializeViewportFramebuffer()
-{
- Q_Q(QOpenGLWidget);
- // Legacy behavior for compatibility with QGLWidget when used as a graphics view
- // viewport: enable clearing on each painter begin.
- q->setAutoFillBackground(true);
-}
-
-void QOpenGLWidgetPrivate::resizeViewportFramebuffer()
-{
- Q_Q(QOpenGLWidget);
- if (!initialized)
- return;
-
- if (!fbo || q->size() * q->devicePixelRatioF() != fbo->size()) {
- recreateFbo();
- q->update();
- }
-}
-
-/*!
- Constructs a widget which is a child of \a parent, with widget flags set to \a f.
- */
-QOpenGLWidget::QOpenGLWidget(QWidget *parent, Qt::WindowFlags f)
- : QWidget(*(new QOpenGLWidgetPrivate), parent, f)
-{
- Q_D(QOpenGLWidget);
- if (Q_UNLIKELY(!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface)))
- qWarning("QOpenGLWidget is not supported on this platform.");
- else
- d->setRenderToTexture();
-}
-
-/*!
- Destroys the QOpenGLWidget instance, freeing its resources.
-
- The QOpenGLWidget's context is made current in the destructor, allowing for
- safe destruction of any child object that may need to release OpenGL
- resources belonging to the context provided by this widget.
-
- \warning if you have objects wrapping OpenGL resources (such as
- QOpenGLBuffer, QOpenGLShaderProgram, etc.) as members of a OpenGLWidget
- subclass, you may need to add a call to makeCurrent() in that subclass'
- destructor as well. Due to the rules of C++ object destruction, those objects
- will be destroyed \e{before} calling this function (but after that the
- destructor of the subclass has run), therefore making the OpenGL context
- current in this function happens too late for their safe disposal.
-
- \sa makeCurrent
-*/
-QOpenGLWidget::~QOpenGLWidget()
-{
- Q_D(QOpenGLWidget);
- d->reset();
-}
-
-/*!
- Sets this widget's update behavior to \a updateBehavior.
- \since 5.5
-*/
-void QOpenGLWidget::setUpdateBehavior(UpdateBehavior updateBehavior)
-{
- Q_D(QOpenGLWidget);
- d->updateBehavior = updateBehavior;
-}
-
-/*!
- \return the update behavior of the widget.
- \since 5.5
-*/
-QOpenGLWidget::UpdateBehavior QOpenGLWidget::updateBehavior() const
-{
- Q_D(const QOpenGLWidget);
- return d->updateBehavior;
-}
-
-/*!
- Sets the requested surface \a format.
-
- When the format is not explicitly set via this function, the format returned by
- QSurfaceFormat::defaultFormat() will be used. This means that when having multiple
- OpenGL widgets, individual calls to this function can be replaced by one single call to
- QSurfaceFormat::setDefaultFormat() before creating the first widget.
-
- \note Requesting an alpha buffer via this function will not lead to the
- desired results when the intention is to make other widgets beneath visible.
- Instead, use Qt::WA_AlwaysStackOnTop to enable semi-transparent QOpenGLWidget
- instances with other widgets visible underneath. Keep in mind however that
- this breaks the stacking order, so it will no longer be possible to have
- other widgets on top of the QOpenGLWidget.
-
- \sa format(), Qt::WA_AlwaysStackOnTop, QSurfaceFormat::setDefaultFormat()
- */
-void QOpenGLWidget::setFormat(const QSurfaceFormat &format)
-{
- Q_D(QOpenGLWidget);
- if (Q_UNLIKELY(d->initialized)) {
- qWarning("QOpenGLWidget: Already initialized, setting the format has no effect");
- return;
- }
-
- d->requestedFormat = format;
-}
-
-/*!
- Returns the context and surface format used by this widget and its toplevel
- window.
-
- After the widget and its toplevel have both been created, resized and shown,
- this function will return the actual format of the context. This may differ
- from the requested format if the request could not be fulfilled by the
- platform. It is also possible to get larger color buffer sizes than
- requested.
-
- When the widget's window and the related OpenGL resources are not yet
- initialized, the return value is the format that has been set via
- setFormat().
-
- \sa setFormat(), context()
- */
-QSurfaceFormat QOpenGLWidget::format() const
-{
- Q_D(const QOpenGLWidget);
- return d->initialized ? d->context->format() : d->requestedFormat;
-}
-
-/*!
- Sets a custom internal texture format of \a texFormat.
-
- When working with sRGB framebuffers, it will be necessary to specify a
- format like \c{GL_SRGB8_ALPHA8}. This can be achieved by calling this
- function.
-
- \note This function has no effect if called after the widget has already
- been shown and thus it performed initialization.
-
- \note This function will typically have to be used in combination with a
- QSurfaceFormat::setDefaultFormat() call that sets the color space to
- QSurfaceFormat::sRGBColorSpace.
-
- \since 5.10
- */
-void QOpenGLWidget::setTextureFormat(GLenum texFormat)
-{
- Q_D(QOpenGLWidget);
- if (Q_UNLIKELY(d->initialized)) {
- qWarning("QOpenGLWidget: Already initialized, setting the internal texture format has no effect");
- return;
- }
-
- d->textureFormat = texFormat;
-}
-
-/*!
- \return the active internal texture format if the widget has already
- initialized, the requested format if one was set but the widget has not yet
- been made visible, or \nullptr if setTextureFormat() was not called and the
- widget has not yet been made visible.
-
- \since 5.10
- */
-GLenum QOpenGLWidget::textureFormat() const
-{
- Q_D(const QOpenGLWidget);
- return d->textureFormat;
-}
-
-/*!
- \return \e true if the widget and OpenGL resources, like the context, have
- been successfully initialized. Note that the return value is always false
- until the widget is shown.
-*/
-bool QOpenGLWidget::isValid() const
-{
- Q_D(const QOpenGLWidget);
- return d->initialized && d->context->isValid();
-}
-
-/*!
- Prepares for rendering OpenGL content for this widget by making the
- corresponding context current and binding the framebuffer object in that
- context.
-
- It is not necessary to call this function in most cases, because it
- is called automatically before invoking paintGL().
-
- \sa context(), paintGL(), doneCurrent()
- */
-void QOpenGLWidget::makeCurrent()
-{
- Q_D(QOpenGLWidget);
- if (!d->initialized)
- return;
-
- d->context->makeCurrent(d->surface);
-
- if (d->fbo) // there may not be one if we are in reset()
- d->fbo->bind();
-}
-
-/*!
- Releases the context.
-
- It is not necessary to call this function in most cases, since the
- widget will make sure the context is bound and released properly
- when invoking paintGL().
- */
-void QOpenGLWidget::doneCurrent()
-{
- Q_D(QOpenGLWidget);
- if (!d->initialized)
- return;
-
- d->context->doneCurrent();
-}
-
-/*!
- \return The QOpenGLContext used by this widget or \c 0 if not yet initialized.
-
- \note The context and the framebuffer object used by the widget changes when
- reparenting the widget via setParent().
-
- \sa QOpenGLContext::setShareContext(), defaultFramebufferObject()
- */
-QOpenGLContext *QOpenGLWidget::context() const
-{
- Q_D(const QOpenGLWidget);
- return d->context;
-}
-
-/*!
- \return The framebuffer object handle or \c 0 if not yet initialized.
-
- \note The framebuffer object belongs to the context returned by context()
- and may not be accessible from other contexts.
-
- \note The context and the framebuffer object used by the widget changes when
- reparenting the widget via setParent(). In addition, the framebuffer object
- changes on each resize.
-
- \sa context()
- */
-GLuint QOpenGLWidget::defaultFramebufferObject() const
-{
- Q_D(const QOpenGLWidget);
- return d->fbo ? d->fbo->handle() : 0;
-}
-
-/*!
- This virtual function is called once before the first call to
- paintGL() or resizeGL(). Reimplement it in a subclass.
-
- This function should set up any required OpenGL resources and state.
-
- There is no need to call makeCurrent() because this has already been
- done when this function is called. Note however that the framebuffer
- is not yet available at this stage, so avoid issuing draw calls from
- here. Defer such calls to paintGL() instead.
-
- \sa paintGL(), resizeGL()
-*/
-void QOpenGLWidget::initializeGL()
-{
-}
-
-/*!
- This virtual function is called whenever the widget has been
- resized. Reimplement it in a subclass. The new size is passed in
- \a w and \a h.
-
- There is no need to call makeCurrent() because this has already been
- done when this function is called. Additionally, the framebuffer is
- also bound.
-
- \sa initializeGL(), paintGL()
-*/
-void QOpenGLWidget::resizeGL(int w, int h)
-{
- Q_UNUSED(w);
- Q_UNUSED(h);
-}
-
-/*!
- This virtual function is called whenever the widget needs to be
- painted. Reimplement it in a subclass.
-
- There is no need to call makeCurrent() because this has already
- been done when this function is called.
-
- Before invoking this function, the context and the framebuffer are
- bound, and the viewport is set up by a call to glViewport(). No
- other state is set and no clearing or drawing is performed by the
- framework.
-
- \sa initializeGL(), resizeGL()
-*/
-void QOpenGLWidget::paintGL()
-{
-}
-
-/*!
- Handles resize events that are passed in the \a e event parameter.
- Calls the virtual function resizeGL().
-
- \note Avoid overriding this function in derived classes. If that is not
- feasible, make sure that QOpenGLWidget's implementation is invoked
- too. Otherwise the underlying framebuffer object and related resources will
- not get resized properly and will lead to incorrect rendering.
-*/
-void QOpenGLWidget::resizeEvent(QResizeEvent *e)
-{
- Q_D(QOpenGLWidget);
-
- if (e->size().isEmpty()) {
- d->fakeHidden = true;
- return;
- }
- d->fakeHidden = false;
-
- d->initialize();
- if (!d->initialized)
- return;
-
- d->recreateFbo();
- resizeGL(width(), height());
- d->sendPaintEvent(QRect(QPoint(0, 0), size()));
-}
-
-/*!
- Handles paint events.
-
- Calling QWidget::update() will lead to sending a paint event \a e,
- and thus invoking this function. (NB this is asynchronous and will
- happen at some point after returning from update()). This function
- will then, after some preparation, call the virtual paintGL() to
- update the contents of the QOpenGLWidget's framebuffer. The widget's
- top-level window will then composite the framebuffer's texture with
- the rest of the window.
-*/
-void QOpenGLWidget::paintEvent(QPaintEvent *e)
-{
- Q_UNUSED(e);
- Q_D(QOpenGLWidget);
- if (!d->initialized)
- return;
-
- if (updatesEnabled())
- d->render();
-}
-
-/*!
- Renders and returns a 32-bit RGB image of the framebuffer.
-
- \note This is a potentially expensive operation because it relies on glReadPixels()
- to read back the pixels. This may be slow and can stall the GPU pipeline.
-*/
-QImage QOpenGLWidget::grabFramebuffer()
-{
- Q_D(QOpenGLWidget);
- return d->grabFramebuffer();
-}
-
-/*!
- \internal
-*/
-int QOpenGLWidget::metric(QPaintDevice::PaintDeviceMetric metric) const
-{
- Q_D(const QOpenGLWidget);
- if (d->inBackingStorePaint)
- return QWidget::metric(metric);
-
- auto window = d->windowHandle(QWidgetPrivate::WindowHandleMode::TopLevel);
- QScreen *screen = window ? window->screen() : QGuiApplication::primaryScreen();
-
- const float dpmx = qt_defaultDpiX() * 100. / 2.54;
- const float dpmy = qt_defaultDpiY() * 100. / 2.54;
-
- switch (metric) {
- case PdmWidth:
- return width();
- case PdmHeight:
- return height();
- case PdmDepth:
- return 32;
- case PdmWidthMM:
- if (screen)
- return width() * screen->physicalSize().width() / screen->geometry().width();
- else
- return width() * 1000 / dpmx;
- case PdmHeightMM:
- if (screen)
- return height() * screen->physicalSize().height() / screen->geometry().height();
- else
- return height() * 1000 / dpmy;
- case PdmNumColors:
- return 0;
- case PdmDpiX:
- if (screen)
- return qRound(screen->logicalDotsPerInchX());
- else
- return qRound(dpmx * 0.0254);
- case PdmDpiY:
- if (screen)
- return qRound(screen->logicalDotsPerInchY());
- else
- return qRound(dpmy * 0.0254);
- case PdmPhysicalDpiX:
- if (screen)
- return qRound(screen->physicalDotsPerInchX());
- else
- return qRound(dpmx * 0.0254);
- case PdmPhysicalDpiY:
- if (screen)
- return qRound(screen->physicalDotsPerInchY());
- else
- return qRound(dpmy * 0.0254);
- case PdmDevicePixelRatio:
- if (window)
- return int(window->devicePixelRatio());
- else
- return 1.0;
- case PdmDevicePixelRatioScaled:
- if (window)
- return int(window->devicePixelRatio() * devicePixelRatioFScale());
- else
- return int(devicePixelRatioFScale());
- default:
- qWarning("QOpenGLWidget::metric(): unknown metric %d", metric);
- return 0;
- }
-}
-
-/*!
- \internal
-*/
-QPaintDevice *QOpenGLWidget::redirected(QPoint *p) const
-{
- Q_D(const QOpenGLWidget);
- if (d->inBackingStorePaint)
- return QWidget::redirected(p);
-
- return d->paintDevice;
-}
-
-/*!
- \internal
-*/
-QPaintEngine *QOpenGLWidget::paintEngine() const
-{
- Q_D(const QOpenGLWidget);
- // QWidget needs to "punch a hole" into the backingstore. This needs the
- // normal paint engine and device, not the GL one. So in this mode, behave
- // like a normal widget.
- if (d->inBackingStorePaint)
- return QWidget::paintEngine();
-
- if (!d->initialized)
- return nullptr;
-
- return d->paintDevice->paintEngine();
-}
-
-/*!
- \internal
-*/
-bool QOpenGLWidget::event(QEvent *e)
-{
- Q_D(QOpenGLWidget);
- switch (e->type()) {
- case QEvent::WindowChangeInternal:
- if (QCoreApplication::testAttribute(Qt::AA_ShareOpenGLContexts))
- break;
- if (d->initialized)
- d->reset();
- if (isHidden())
- break;
- Q_FALLTHROUGH();
- case QEvent::Show: // reparenting may not lead to a resize so reinitalize on Show too
- if (d->initialized && window()->windowHandle()
- && d->context->shareContext() != QWidgetPrivate::get(window())->shareContext())
- {
- // Special case: did grabFramebuffer() for a hidden widget that then became visible.
- // Recreate all resources since the context now needs to share with the TLW's.
- if (!QCoreApplication::testAttribute(Qt::AA_ShareOpenGLContexts))
- d->reset();
- }
- if (!d->initialized && !size().isEmpty() && window()->windowHandle()) {
- d->initialize();
- if (d->initialized)
- d->recreateFbo();
- }
- break;
- case QEvent::ScreenChangeInternal:
- if (d->initialized && d->paintDevice->devicePixelRatioF() != devicePixelRatioF())
- d->recreateFbo();
- break;
- default:
- break;
- }
- return QWidget::event(e);
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qopenglwidget.cpp"
diff --git a/src/widgets/kernel/qopenglwidget.h b/src/widgets/kernel/qopenglwidget.h
deleted file mode 100644
index 9eb4a9ba5a..0000000000
--- a/src/widgets/kernel/qopenglwidget.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#ifndef QOPENGLWIDGET_H
-#define QOPENGLWIDGET_H
-
-#include <QtWidgets/qtwidgetsglobal.h>
-
-#ifndef QT_NO_OPENGL
-
-#include <QtWidgets/QWidget>
-#include <QtGui/QSurfaceFormat>
-#include <QtGui/qopengl.h>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLWidgetPrivate;
-
-class Q_WIDGETS_EXPORT QOpenGLWidget : public QWidget
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QOpenGLWidget)
-
-public:
- enum UpdateBehavior {
- NoPartialUpdate,
- PartialUpdate
- };
-
- explicit QOpenGLWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
- ~QOpenGLWidget();
-
- void setUpdateBehavior(UpdateBehavior updateBehavior);
- UpdateBehavior updateBehavior() const;
-
- void setFormat(const QSurfaceFormat &format);
- QSurfaceFormat format() const;
-
- GLenum textureFormat() const;
- void setTextureFormat(GLenum texFormat);
-
- bool isValid() const;
-
- void makeCurrent();
- void doneCurrent();
-
- QOpenGLContext *context() const;
- GLuint defaultFramebufferObject() const;
-
- QImage grabFramebuffer();
-
-Q_SIGNALS:
- void aboutToCompose();
- void frameSwapped();
- void aboutToResize();
- void resized();
-
-protected:
- virtual void initializeGL();
- virtual void resizeGL(int w, int h);
- virtual void paintGL();
-
- void paintEvent(QPaintEvent *e) override;
- void resizeEvent(QResizeEvent *e) override;
- bool event(QEvent *e) override;
-
- int metric(QPaintDevice::PaintDeviceMetric metric) const override;
- QPaintDevice *redirected(QPoint *p) const override;
- QPaintEngine *paintEngine() const override;
-
-private:
- Q_DISABLE_COPY(QOpenGLWidget)
-};
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_OPENGL
-
-#endif // QOPENGLWIDGET_H
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp
deleted file mode 100644
index 039699a004..0000000000
--- a/src/widgets/kernel/qshortcut.cpp
+++ /dev/null
@@ -1,753 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include "qshortcut.h"
-#include "private/qwidget_p.h"
-
-#ifndef QT_NO_SHORTCUT
-#include <qevent.h>
-#if QT_CONFIG(whatsthis)
-#include <qwhatsthis.h>
-#endif
-#if QT_CONFIG(menu)
-#include <qmenu.h>
-#endif
-#if QT_CONFIG(menubar)
-#include <qmenubar.h>
-#endif
-#include <qapplication.h>
-#include <private/qapplication_p.h>
-#include <private/qshortcutmap_p.h>
-#include <private/qaction_p.h>
-#include <private/qwidgetwindow_p.h>
-#include <qpa/qplatformmenu.h>
-
-QT_BEGIN_NAMESPACE
-
-#define QAPP_CHECK(functionName) \
- if (Q_UNLIKELY(!qApp)) { \
- qWarning("QShortcut: Initialize QApplication before calling '" functionName "'."); \
- return; \
- }
-
-
-static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window);
-#if QT_CONFIG(graphicsview)
-static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window);
-#endif
-#ifndef QT_NO_ACTION
-static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window);
-#endif
-
-
-/*! \internal
- Returns \c true if the widget \a w is a logical sub window of the current
- top-level widget.
-*/
-bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
-{
- Q_ASSERT_X(object, "QShortcutMap", "Shortcut has no owner. Illegal map state!");
-
- QWidget *active_window = QApplication::activeWindow();
-
- // popups do not become the active window,
- // so we fake it here to get the correct context
- // for the shortcut system.
- if (QApplication::activePopupWidget())
- active_window = QApplication::activePopupWidget();
-
- if (!active_window) {
- QWindow *qwindow = QGuiApplication::focusWindow();
- if (qwindow && qwindow->isActive()) {
- while (qwindow) {
- if (auto widgetWindow = qobject_cast<QWidgetWindow *>(qwindow)) {
- active_window = widgetWindow->widget();
- break;
- }
- qwindow = qwindow->parent();
- }
- }
- }
-
- if (!active_window)
- return false;
-
-#ifndef QT_NO_ACTION
- if (auto a = qobject_cast<QAction *>(object))
- return correctActionContext(context, a, active_window);
-#endif
-
-#if QT_CONFIG(graphicsview)
- if (auto gw = qobject_cast<QGraphicsWidget *>(object))
- return correctGraphicsWidgetContext(context, gw, active_window);
-#endif
-
- auto w = qobject_cast<QWidget *>(object);
- if (!w) {
- if (auto s = qobject_cast<QShortcut *>(object))
- w = s->parentWidget();
- }
-
- if (!w) {
- auto qwindow = qobject_cast<QWindow *>(object);
- while (qwindow) {
- if (auto widget_window = qobject_cast<QWidgetWindow *>(qwindow)) {
- w = widget_window->widget();
- break;
- }
- qwindow = qwindow->parent();
- }
- }
-
- if (!w)
- return false;
-
- return correctWidgetContext(context, w, active_window);
-}
-
-static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window)
-{
- bool visible = w->isVisible();
-#if QT_CONFIG(menubar)
- if (auto menuBar = qobject_cast<QMenuBar *>(w)) {
- if (auto *pmb = menuBar->platformMenuBar()) {
- if (menuBar->parentWidget()) {
- visible = true;
- } else {
- if (auto *ww = qobject_cast<QWidgetWindow *>(pmb->parentWindow()))
- w = ww->widget(); // Good enough since we only care about the window
- else
- return false; // This is not a QWidget window. We won't deliver
- }
- }
- }
-#endif
-
- if (!visible || !w->isEnabled())
- return false;
-
- if (context == Qt::ApplicationShortcut)
- return QApplicationPrivate::tryModalHelper(w, nullptr); // true, unless w is shadowed by a modal dialog
-
- if (context == Qt::WidgetShortcut)
- return w == QApplication::focusWidget();
-
- if (context == Qt::WidgetWithChildrenShortcut) {
- const QWidget *tw = QApplication::focusWidget();
- while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup || tw->windowType() == Qt::SubWindow))
- tw = tw->parentWidget();
- return tw == w;
- }
-
- // Below is Qt::WindowShortcut context
- QWidget *tlw = w->window();
-#if QT_CONFIG(graphicsview)
- if (auto topData = static_cast<QWidgetPrivate *>(QObjectPrivate::get(tlw))->extra.get()) {
- if (topData->proxyWidget) {
- bool res = correctGraphicsWidgetContext(context, topData->proxyWidget, active_window);
- return res;
- }
- }
-#endif
-
- if (active_window && active_window != tlw) {
- /* if a floating tool window is active, keep shortcuts on the parent working.
- * and if a popup window is active (f.ex a completer), keep shortcuts on the
- * focus proxy working */
- if (active_window->windowType() == Qt::Tool && active_window->parentWidget()) {
- active_window = active_window->parentWidget()->window();
- } else if (active_window->windowType() == Qt::Popup && active_window->focusProxy()) {
- active_window = active_window->focusProxy()->window();
- }
- }
-
- if (active_window != tlw) {
-#if QT_CONFIG(menubar)
- // If the tlw is a QMenuBar then we allow it to proceed as this indicates that
- // the QMenuBar is a parentless one and is therefore used for multiple top level
- // windows in the application. This is common on macOS platforms for example.
- if (!qobject_cast<QMenuBar *>(tlw))
-#endif
- return false;
- }
-
- /* if we live in a MDI subwindow, ignore the event if we are
- not the active document window */
- const QWidget* sw = w;
- while (sw && !(sw->windowType() == Qt::SubWindow) && !sw->isWindow())
- sw = sw->parentWidget();
- if (sw && (sw->windowType() == Qt::SubWindow)) {
- QWidget *focus_widget = QApplication::focusWidget();
- while (focus_widget && focus_widget != sw)
- focus_widget = focus_widget->parentWidget();
- return sw == focus_widget;
- }
-
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug().nospace() << "..true [Pass-through]";
-#endif
- return QApplicationPrivate::tryModalHelper(w, nullptr);
-}
-
-#if QT_CONFIG(graphicsview)
-static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window)
-{
- bool visible = w->isVisible();
-#if defined(Q_OS_DARWIN) && QT_CONFIG(menubar)
- if (!QCoreApplication::testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
- visible = true;
-#endif
-
- if (!visible || !w->isEnabled() || !w->scene())
- return false;
-
- if (context == Qt::ApplicationShortcut) {
- // Applicationwide shortcuts are always reachable unless their owner
- // is shadowed by modality. In QGV there's no modality concept, but we
- // must still check if all views are shadowed.
- const auto &views = w->scene()->views();
- for (auto view : views) {
- if (QApplicationPrivate::tryModalHelper(view, nullptr))
- return true;
- }
- return false;
- }
-
- if (context == Qt::WidgetShortcut)
- return static_cast<QGraphicsItem *>(w) == w->scene()->focusItem();
-
- if (context == Qt::WidgetWithChildrenShortcut) {
- const QGraphicsItem *ti = w->scene()->focusItem();
- if (ti && ti->isWidget()) {
- const auto *tw = static_cast<const QGraphicsWidget *>(ti);
- while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup))
- tw = tw->parentWidget();
- return tw == w;
- }
- return false;
- }
-
- // Below is Qt::WindowShortcut context
-
- // Find the active view (if any).
- const auto &views = w->scene()->views();
- QGraphicsView *activeView = nullptr;
- for (auto view : views) {
- if (view->window() == active_window) {
- activeView = view;
- break;
- }
- }
- if (!activeView)
- return false;
-
- // The shortcut is reachable if owned by a windowless widget, or if the
- // widget's window is the same as the focus item's window.
- QGraphicsWidget *a = w->scene()->activeWindow();
- return !w->window() || a == w->window();
-}
-#endif
-
-#ifndef QT_NO_ACTION
-static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window)
-{
- const QWidgetList &widgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->widgets;
-#if defined(DEBUG_QSHORTCUTMAP)
- if (widgets.isEmpty())
- qDebug() << a << "not connected to any widgets; won't trigger";
-#endif
- for (auto w : widgets) {
-#if QT_CONFIG(menu)
- if (auto menu = qobject_cast<QMenu *>(w)) {
-#ifdef Q_OS_DARWIN
- // On Mac, menu item shortcuts are processed before reaching any window.
- // That means that if a menu action shortcut has not been already processed
- // (and reaches this point), then the menu item itself has been disabled.
- // This occurs at the QPA level on Mac, where we disable all the Cocoa menus
- // when showing a modal window. (Notice that only the QPA menu is disabled,
- // not the QMenu.) Since we can also reach this code by climbing the menu
- // hierarchy (see below), or when the shortcut is not a key-equivalent, we
- // need to check whether the QPA menu is actually disabled.
- // When there is no QPA menu, there will be no QCocoaMenuDelegate checking
- // for the actual shortcuts. We can then fallback to our own logic.
- QPlatformMenu *pm = menu->platformMenu();
- if (pm && !pm->isEnabled())
- continue;
-#endif
- QAction *a = menu->menuAction();
- if (correctActionContext(context, a, active_window))
- return true;
- } else
-#endif
- if (correctWidgetContext(context, w, active_window))
- return true;
- }
-
-#if QT_CONFIG(graphicsview)
- const auto &graphicsWidgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->graphicsWidgets;
-#if defined(DEBUG_QSHORTCUTMAP)
- if (graphicsWidgets.isEmpty())
- qDebug() << a << "not connected to any widgets; won't trigger";
-#endif
- for (auto graphicsWidget : graphicsWidgets) {
- if (correctGraphicsWidgetContext(context, graphicsWidget, active_window))
- return true;
- }
-#endif
- return false;
-}
-#endif // QT_NO_ACTION
-
-
-/*!
- \class QShortcut
- \brief The QShortcut class is used to create keyboard shortcuts.
-
- \ingroup events
- \inmodule QtWidgets
-
- The QShortcut class provides a way of connecting keyboard
- shortcuts to Qt's \l{signals and slots} mechanism, so that
- objects can be informed when a shortcut is executed. The shortcut
- can be set up to contain all the key presses necessary to
- describe a keyboard shortcut, including the states of modifier
- keys such as \uicontrol Shift, \uicontrol Ctrl, and \uicontrol Alt.
-
- \target mnemonic
-
- On certain widgets, using '&' in front of a character will
- automatically create a mnemonic (a shortcut) for that character,
- e.g. "E&xit" will create the shortcut \uicontrol Alt+X (use '&&' to
- display an actual ampersand). The widget might consume and perform
- an action on a given shortcut. On X11 the ampersand will not be
- shown and the character will be underlined. On Windows, shortcuts
- are normally not displayed until the user presses the \uicontrol Alt
- key, but this is a setting the user can change. On Mac, shortcuts
- are disabled by default. Call \l qt_set_sequence_auto_mnemonic() to
- enable them. However, because mnemonic shortcuts do not fit in
- with Aqua's guidelines, Qt will not show the shortcut character
- underlined.
-
- For applications that use menus, it may be more convenient to
- use the convenience functions provided in the QMenu class to
- assign keyboard shortcuts to menu items as they are created.
- Alternatively, shortcuts may be associated with other types of
- actions in the QAction class.
-
- The simplest way to create a shortcut for a particular widget is
- to construct the shortcut with a key sequence. For example:
-
- \snippet code/src_gui_kernel_qshortcut.cpp 0
-
- When the user types the \l{QKeySequence}{key sequence}
- for a given shortcut, the shortcut's activated() signal is
- emitted. (In the case of ambiguity, the activatedAmbiguously()
- signal is emitted.) A shortcut is "listened for" by Qt's event
- loop when the shortcut's parent widget is receiving events.
-
- A shortcut's key sequence can be set with setKey() and retrieved
- with key(). A shortcut can be enabled or disabled with
- setEnabled(), and can have "What's This?" help text set with
- setWhatsThis().
-
- \sa QShortcutEvent, QKeySequence, QAction
-*/
-
-/*!
- \fn QWidget *QShortcut::parentWidget() const
-
- Returns the shortcut's parent widget.
-*/
-
-/*!
- \fn void QShortcut::activated()
-
- This signal is emitted when the user types the shortcut's key
- sequence.
-
- \sa activatedAmbiguously()
-*/
-
-/*!
- \fn void QShortcut::activatedAmbiguously()
-
- When a key sequence is being typed at the keyboard, it is said to
- be ambiguous as long as it matches the start of more than one
- shortcut.
-
- When a shortcut's key sequence is completed,
- activatedAmbiguously() is emitted if the key sequence is still
- ambiguous (i.e., it is the start of one or more other shortcuts).
- The activated() signal is not emitted in this case.
-
- \sa activated()
-*/
-
-/*!
- \fn template<typename Functor>
- QShortcut(const QKeySequence &key, QWidget *parent,
- Functor functor,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
- \since 5.15
- \overload
-
- This is a QShortcut convenience constructor which connects the shortcut's
- \l{QShortcut::activated()}{activated()} signal to the \a functor.
-*/
-/*!
- \fn template<typename Functor>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const QObject *context, Functor functor,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
- \since 5.15
- \overload
-
- This is a QShortcut convenience constructor which connects the shortcut's
- \l{QShortcut::activated()}{activated()} signal to the \a functor.
-
- The \a functor can be a pointer to a member function of the \a context object.
-
- If the \a context object is destroyed, the \a functor will not be called.
-*/
-/*!
- \fn template<typename Functor, typename FunctorAmbiguous>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const QObject *context1, Functor functor,
- FunctorAmbiguous functorAmbiguous,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
- \since 5.15
- \overload
-
- This is a QShortcut convenience constructor which connects the shortcut's
- \l{QShortcut::activated()}{activated()} signal to the \a functor and
- \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()}
- signal to the \a FunctorAmbiguous.
-
- The \a functor and \a FunctorAmbiguous can be a pointer to a member
- function of the \a context object.
-
- If the \a context object is destroyed, the \a functor and
- \a FunctorAmbiguous will not be called.
-*/
-/*!
- \fn template<typename Functor, typename FunctorAmbiguous>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const QObject *context1, Functor functor,
- const QObject *context2, FunctorAmbiguous functorAmbiguous,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
- \since 5.15
- \overload
-
- This is a QShortcut convenience constructor which connects the shortcut's
- \l{QShortcut::activated()}{activated()} signal to the \a functor and
- \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()}
- signal to the \a FunctorAmbiguous.
-
- The \a functor can be a pointer to a member function of the
- \a context1 object.
- The \a FunctorAmbiguous can be a pointer to a member function of the
- \a context2 object.
-
- If the \a context1 object is destroyed, the \a functor will not be called.
- If the \a context2 object is destroyed, the \a FunctorAmbiguous
- will not be called.
-*/
-
-/*
- \internal
- Private data accessed through d-pointer.
-*/
-class QShortcutPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QShortcut)
-public:
- QShortcutPrivate() = default;
- QKeySequence sc_sequence;
- Qt::ShortcutContext sc_context = Qt::WindowShortcut;
- bool sc_enabled = true;
- bool sc_autorepeat = true;
- int sc_id = 0;
- QString sc_whatsthis;
- void redoGrab(QShortcutMap &map);
-};
-
-void QShortcutPrivate::redoGrab(QShortcutMap &map)
-{
- Q_Q(QShortcut);
- if (Q_UNLIKELY(!parent)) {
- qWarning("QShortcut: No widget parent defined");
- return;
- }
-
- if (sc_id)
- map.removeShortcut(sc_id, q);
- if (sc_sequence.isEmpty())
- return;
- sc_id = map.addShortcut(q, sc_sequence, sc_context, qWidgetShortcutContextMatcher);
- if (!sc_enabled)
- map.setShortcutEnabled(false, sc_id, q);
- if (!sc_autorepeat)
- map.setShortcutAutoRepeat(false, sc_id, q);
-}
-
-/*!
- Constructs a QShortcut object for the \a parent widget. Since no
- shortcut key sequence is specified, the shortcut will not emit any
- signals.
-
- \sa setKey()
-*/
-QShortcut::QShortcut(QWidget *parent)
- : QObject(*new QShortcutPrivate, parent)
-{
- Q_ASSERT(parent != nullptr);
-}
-
-/*!
- Constructs a QShortcut object for the \a parent widget. The shortcut
- operates on its parent, listening for \l{QShortcutEvent}s that
- match the \a key sequence. Depending on the ambiguity of the
- event, the shortcut will call the \a member function, or the \a
- ambiguousMember function, if the key press was in the shortcut's
- \a shortcutContext.
-*/
-QShortcut::QShortcut(const QKeySequence &key, QWidget *parent,
- const char *member, const char *ambiguousMember,
- Qt::ShortcutContext shortcutContext)
- : QShortcut(parent)
-{
- QAPP_CHECK("QShortcut");
-
- Q_D(QShortcut);
- d->sc_context = shortcutContext;
- d->sc_sequence = key;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- if (member)
- connect(this, SIGNAL(activated()), parent, member);
- if (ambiguousMember)
- connect(this, SIGNAL(activatedAmbiguously()), parent, ambiguousMember);
-}
-
-/*!
- Destroys the shortcut.
-*/
-QShortcut::~QShortcut()
-{
- Q_D(QShortcut);
- if (qApp)
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(d->sc_id, this);
-}
-
-/*!
- \property QShortcut::key
- \brief the shortcut's key sequence
-
- This is a key sequence with an optional combination of Shift, Ctrl,
- and Alt. The key sequence may be supplied in a number of ways:
-
- \snippet code/src_gui_kernel_qshortcut.cpp 1
-
- By default, this property contains an empty key sequence.
-*/
-void QShortcut::setKey(const QKeySequence &key)
-{
- Q_D(QShortcut);
- if (d->sc_sequence == key)
- return;
- QAPP_CHECK("setKey");
- d->sc_sequence = key;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
-}
-
-QKeySequence QShortcut::key() const
-{
- Q_D(const QShortcut);
- return d->sc_sequence;
-}
-
-/*!
- \property QShortcut::enabled
- \brief whether the shortcut is enabled
-
- An enabled shortcut emits the activated() or activatedAmbiguously()
- signal when a QShortcutEvent occurs that matches the shortcut's
- key() sequence.
-
- If the application is in \c WhatsThis mode the shortcut will not emit
- the signals, but will show the "What's This?" text instead.
-
- By default, this property is \c true.
-
- \sa whatsThis
-*/
-void QShortcut::setEnabled(bool enable)
-{
- Q_D(QShortcut);
- if (d->sc_enabled == enable)
- return;
- QAPP_CHECK("setEnabled");
- d->sc_enabled = enable;
- QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enable, d->sc_id, this);
-}
-
-bool QShortcut::isEnabled() const
-{
- Q_D(const QShortcut);
- return d->sc_enabled;
-}
-
-/*!
- \property QShortcut::context
- \brief the context in which the shortcut is valid
-
- A shortcut's context decides in which circumstances a shortcut is
- allowed to be triggered. The normal context is Qt::WindowShortcut,
- which allows the shortcut to trigger if the parent (the widget
- containing the shortcut) is a subwidget of the active top-level
- window.
-
- By default, this property is set to Qt::WindowShortcut.
-*/
-void QShortcut::setContext(Qt::ShortcutContext context)
-{
- Q_D(QShortcut);
- if(d->sc_context == context)
- return;
- QAPP_CHECK("setContext");
- d->sc_context = context;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
-}
-
-Qt::ShortcutContext QShortcut::context() const
-{
- Q_D(const QShortcut);
- return d->sc_context;
-}
-
-/*!
- \property QShortcut::whatsThis
- \brief the shortcut's "What's This?" help text
-
- The text will be shown when the application is in "What's
- This?" mode and the user types the shortcut key() sequence.
-
- To set "What's This?" help on a menu item (with or without a
- shortcut key), set the help on the item's action.
-
- By default, this property contains an empty string.
-
- \sa QWhatsThis::inWhatsThisMode(), QAction::setWhatsThis()
-*/
-void QShortcut::setWhatsThis(const QString &text)
-{
- Q_D(QShortcut);
- d->sc_whatsthis = text;
-}
-
-QString QShortcut::whatsThis() const
-{
- Q_D(const QShortcut);
- return d->sc_whatsthis;
-}
-
-/*!
- \property QShortcut::autoRepeat
- \brief whether the shortcut can auto repeat
- \since 4.2
-
- If true, the shortcut will auto repeat when the keyboard shortcut
- combination is held down, provided that keyboard auto repeat is
- enabled on the system.
- The default value is true.
-*/
-void QShortcut::setAutoRepeat(bool on)
-{
- Q_D(QShortcut);
- if (d->sc_autorepeat == on)
- return;
- QAPP_CHECK("setAutoRepeat");
- d->sc_autorepeat = on;
- QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(on, d->sc_id, this);
-}
-
-bool QShortcut::autoRepeat() const
-{
- Q_D(const QShortcut);
- return d->sc_autorepeat;
-}
-
-/*!
- Returns the shortcut's ID.
-
- \sa QShortcutEvent::shortcutId()
-*/
-int QShortcut::id() const
-{
- Q_D(const QShortcut);
- return d->sc_id;
-}
-
-/*!
- \internal
-*/
-bool QShortcut::event(QEvent *e)
-{
- Q_D(QShortcut);
- if (d->sc_enabled && e->type() == QEvent::Shortcut) {
- auto se = static_cast<QShortcutEvent *>(e);
- if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){
-#if QT_CONFIG(whatsthis)
- if (QWhatsThis::inWhatsThisMode()) {
- QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis);
- } else
-#endif
- if (se->isAmbiguous())
- emit activatedAmbiguously();
- else
- emit activated();
- return true;
- }
- }
- return QObject::event(e);
-}
-#endif // QT_NO_SHORTCUT
-
-QT_END_NAMESPACE
-
-#include "moc_qshortcut.cpp"
diff --git a/src/widgets/kernel/qshortcut.h b/src/widgets/kernel/qshortcut.h
deleted file mode 100644
index 384f1967c9..0000000000
--- a/src/widgets/kernel/qshortcut.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#ifndef QSHORTCUT_H
-#define QSHORTCUT_H
-
-#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtWidgets/qwidget.h>
-#include <QtGui/qkeysequence.h>
-
-QT_BEGIN_NAMESPACE
-
-
-#ifndef QT_NO_SHORTCUT
-
-class QShortcutPrivate;
-class Q_WIDGETS_EXPORT QShortcut : public QObject
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QShortcut)
- Q_PROPERTY(QKeySequence key READ key WRITE setKey)
- Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
- Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
- Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext)
-public:
- explicit QShortcut(QWidget *parent);
- QShortcut(const QKeySequence &key, QWidget *parent,
- const char *member = nullptr, const char *ambiguousMember = nullptr,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
-#ifdef Q_CLANG_QDOC
- template<typename Functor>
- QShortcut(const QKeySequence &key, QWidget *parent,
- Functor functor,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
- template<typename Functor>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const QObject *context, Functor functor,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
- template<typename Functor, typename FunctorAmbiguous>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const QObject *context1, Functor functor,
- FunctorAmbiguous functorAmbiguous,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
- template<typename Functor, typename FunctorAmbiguous>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const QObject *context1, Functor functor,
- const QObject *context2, FunctorAmbiguous functorAmbiguous,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
-#else
- template<typename Func1>
- QShortcut(const QKeySequence &key, QWidget *parent,
- Func1 slot1,
- Qt::ShortcutContext context = Qt::WindowShortcut)
- : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
- {
- connect(this, &QShortcut::activated, std::move(slot1));
- }
- template<class Obj1, typename Func1>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const Obj1 *object1, Func1 slot1,
- Qt::ShortcutContext context = Qt::WindowShortcut,
- typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0)
- : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
- {
- connect(this, &QShortcut::activated, object1, std::move(slot1));
- }
- template<class Obj1, typename Func1, typename Func2>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const Obj1 *object1, Func1 slot1, Func2 slot2,
- Qt::ShortcutContext context = Qt::WindowShortcut,
- typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0)
- : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
- {
- connect(this, &QShortcut::activated, object1, std::move(slot1));
- connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2));
- }
- template<class Obj1, typename Func1, class Obj2, typename Func2>
- QShortcut(const QKeySequence &key, QWidget *parent,
- const Obj1 *object1, Func1 slot1,
- const Obj2 *object2, Func2 slot2,
- Qt::ShortcutContext context = Qt::WindowShortcut,
- typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0,
- typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj2*>::Value>::type* = 0)
- : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
- {
- connect(this, &QShortcut::activated, object1, std::move(slot1));
- connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2));
- }
-#endif
- ~QShortcut();
-
- void setKey(const QKeySequence& key);
- QKeySequence key() const;
-
- void setEnabled(bool enable);
- bool isEnabled() const;
-
- void setContext(Qt::ShortcutContext context);
- Qt::ShortcutContext context() const;
-
- void setWhatsThis(const QString &text);
- QString whatsThis() const;
-
- void setAutoRepeat(bool on);
- bool autoRepeat() const;
-
- int id() const;
-
- inline QWidget *parentWidget() const
- { return static_cast<QWidget *>(QObject::parent()); }
-
-Q_SIGNALS:
- void activated();
- void activatedAmbiguously();
-
-protected:
- bool event(QEvent *e) override;
-};
-
-#endif // QT_NO_SHORTCUT
-
-QT_END_NAMESPACE
-
-#endif // QSHORTCUT_H
diff --git a/src/widgets/kernel/qshortcut_widgets.cpp b/src/widgets/kernel/qshortcut_widgets.cpp
new file mode 100644
index 0000000000..9e64376fce
--- /dev/null
+++ b/src/widgets/kernel/qshortcut_widgets.cpp
@@ -0,0 +1,358 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include "qshortcut.h"
+#include "private/qshortcut_p.h"
+
+#include "private/qwidget_p.h"
+
+#include <qevent.h>
+#if QT_CONFIG(whatsthis)
+#include <qwhatsthis.h>
+#endif
+#if QT_CONFIG(menu)
+#include <qmenu.h>
+#endif
+#if QT_CONFIG(menubar)
+#include <qmenubar.h>
+#endif
+#include <qapplication.h>
+#include <private/qapplication_p.h>
+#include <private/qshortcutmap_p.h>
+#if QT_CONFIG(action)
+# include <private/qaction_p.h>
+#endif
+#include <private/qwidgetwindow_p.h>
+#include <qpa/qplatformmenu.h>
+
+QT_BEGIN_NAMESPACE
+
+static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window);
+#if QT_CONFIG(graphicsview)
+static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window);
+#endif
+#if QT_CONFIG(action)
+static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window);
+#endif
+
+
+/*! \internal
+ Returns \c true if the widget \a w is a logical sub window of the current
+ top-level widget.
+*/
+bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
+{
+ Q_ASSERT_X(object, "QShortcutMap", "Shortcut has no owner. Illegal map state!");
+
+ QWidget *active_window = QApplication::activeWindow();
+
+ // popups do not become the active window,
+ // so we fake it here to get the correct context
+ // for the shortcut system.
+ if (QApplication::activePopupWidget())
+ active_window = QApplication::activePopupWidget();
+
+ if (!active_window) {
+ QWindow *qwindow = QGuiApplication::focusWindow();
+ if (qwindow && qwindow->isActive()) {
+ while (qwindow) {
+ if (auto widgetWindow = qobject_cast<QWidgetWindow *>(qwindow)) {
+ active_window = widgetWindow->widget();
+ break;
+ }
+ qwindow = qwindow->parent();
+ }
+ }
+ }
+
+ if (!active_window)
+ return false;
+
+#if QT_CONFIG(action)
+ if (auto a = qobject_cast<QAction *>(object))
+ return correctActionContext(context, a, active_window);
+#endif
+
+#if QT_CONFIG(graphicsview)
+ if (auto gw = qobject_cast<QGraphicsWidget *>(object))
+ return correctGraphicsWidgetContext(context, gw, active_window);
+#endif
+
+ auto w = qobject_cast<QWidget *>(object);
+ if (!w) {
+ if (auto s = qobject_cast<QShortcut *>(object))
+ w = s->parentWidget();
+ }
+
+ if (!w) {
+ auto qwindow = qobject_cast<QWindow *>(object);
+ while (qwindow) {
+ if (auto widget_window = qobject_cast<QWidgetWindow *>(qwindow)) {
+ w = widget_window->widget();
+ break;
+ }
+ qwindow = qwindow->parent();
+ }
+ }
+
+ if (!w)
+ return false;
+
+ return correctWidgetContext(context, w, active_window);
+}
+
+static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window)
+{
+ bool visible = w->isVisible();
+#if QT_CONFIG(menubar)
+ if (auto menuBar = qobject_cast<QMenuBar *>(w)) {
+ if (auto *pmb = menuBar->platformMenuBar()) {
+ if (menuBar->parentWidget()) {
+ visible = true;
+ } else {
+ if (auto *ww = qobject_cast<QWidgetWindow *>(pmb->parentWindow()))
+ w = ww->widget(); // Good enough since we only care about the window
+ else
+ return false; // This is not a QWidget window. We won't deliver
+ }
+ }
+ }
+#endif
+
+ if (!visible || !w->isEnabled())
+ return false;
+
+ if (context == Qt::ApplicationShortcut)
+ return QApplicationPrivate::tryModalHelper(w, nullptr); // true, unless w is shadowed by a modal dialog
+
+ if (context == Qt::WidgetShortcut)
+ return w == QApplication::focusWidget();
+
+ if (context == Qt::WidgetWithChildrenShortcut) {
+ const QWidget *tw = QApplication::focusWidget();
+ while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup || tw->windowType() == Qt::SubWindow))
+ tw = tw->parentWidget();
+ return tw == w;
+ }
+
+ // Below is Qt::WindowShortcut context
+ QWidget *tlw = w->window();
+#if QT_CONFIG(graphicsview)
+ if (auto topData = static_cast<QWidgetPrivate *>(QObjectPrivate::get(tlw))->extra.get()) {
+ if (topData->proxyWidget) {
+ bool res = correctGraphicsWidgetContext(context, topData->proxyWidget, active_window);
+ return res;
+ }
+ }
+#endif
+
+ if (active_window && active_window != tlw) {
+ /* if a floating tool window is active, keep shortcuts on the parent working.
+ * and if a popup window is active (f.ex a completer), keep shortcuts on the
+ * focus proxy working */
+ if (active_window->windowType() == Qt::Tool && active_window->parentWidget()) {
+ active_window = active_window->parentWidget()->window();
+ } else if (active_window->windowType() == Qt::Popup && active_window->focusProxy()) {
+ active_window = active_window->focusProxy()->window();
+ }
+ }
+
+ if (active_window != tlw) {
+#if QT_CONFIG(menubar)
+ // If the tlw is a QMenuBar then we allow it to proceed as this indicates that
+ // the QMenuBar is a parentless one and is therefore used for multiple top level
+ // windows in the application. This is common on macOS platforms for example.
+ if (!qobject_cast<QMenuBar *>(tlw))
+#endif
+ return false;
+ }
+
+ /* if we live in a MDI subwindow, ignore the event if we are
+ not the active document window */
+ const QWidget* sw = w;
+ while (sw && !(sw->windowType() == Qt::SubWindow) && !sw->isWindow())
+ sw = sw->parentWidget();
+ if (sw && (sw->windowType() == Qt::SubWindow)) {
+ QWidget *focus_widget = QApplication::focusWidget();
+ while (focus_widget && focus_widget != sw)
+ focus_widget = focus_widget->parentWidget();
+ return sw == focus_widget;
+ }
+
+#if defined(DEBUG_QSHORTCUTMAP)
+ qDebug().nospace() << "..true [Pass-through]";
+#endif
+ return QApplicationPrivate::tryModalHelper(w, nullptr);
+}
+
+#if QT_CONFIG(graphicsview)
+static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window)
+{
+ bool visible = w->isVisible();
+#if defined(Q_OS_DARWIN) && QT_CONFIG(menubar)
+ if (!QCoreApplication::testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
+ visible = true;
+#endif
+
+ if (!visible || !w->isEnabled() || !w->scene())
+ return false;
+
+ if (context == Qt::ApplicationShortcut) {
+ // Applicationwide shortcuts are always reachable unless their owner
+ // is shadowed by modality. In QGV there's no modality concept, but we
+ // must still check if all views are shadowed.
+ const auto &views = w->scene()->views();
+ for (auto view : views) {
+ if (QApplicationPrivate::tryModalHelper(view, nullptr))
+ return true;
+ }
+ return false;
+ }
+
+ if (context == Qt::WidgetShortcut)
+ return static_cast<QGraphicsItem *>(w) == w->scene()->focusItem();
+
+ if (context == Qt::WidgetWithChildrenShortcut) {
+ const QGraphicsItem *ti = w->scene()->focusItem();
+ if (ti && ti->isWidget()) {
+ const auto *tw = static_cast<const QGraphicsWidget *>(ti);
+ while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup))
+ tw = tw->parentWidget();
+ return tw == w;
+ }
+ return false;
+ }
+
+ // Below is Qt::WindowShortcut context
+
+ // Find the active view (if any).
+ const auto &views = w->scene()->views();
+ QGraphicsView *activeView = nullptr;
+ for (auto view : views) {
+ if (view->window() == active_window) {
+ activeView = view;
+ break;
+ }
+ }
+ if (!activeView)
+ return false;
+
+ // The shortcut is reachable if owned by a windowless widget, or if the
+ // widget's window is the same as the focus item's window.
+ QGraphicsWidget *a = w->scene()->activeWindow();
+ return !w->window() || a == w->window();
+}
+#endif
+
+#if QT_CONFIG(action)
+static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window)
+{
+ const QObjectList associatedObjects = a->associatedObjects();
+#if defined(DEBUG_QSHORTCUTMAP)
+ if (associatedObjects.isEmpty())
+ qDebug() << a << "not connected to any widgets; won't trigger";
+#endif
+ for (auto object : associatedObjects) {
+#if QT_CONFIG(menu)
+ if (auto menu = qobject_cast<QMenu *>(object)) {
+#ifdef Q_OS_DARWIN
+ // On Mac, menu item shortcuts are processed before reaching any window.
+ // That means that if a menu action shortcut has not been already processed
+ // (and reaches this point), then the menu item itself has been disabled.
+ // This occurs at the QPA level on Mac, where we disable all the Cocoa menus
+ // when showing a modal window. (Notice that only the QPA menu is disabled,
+ // not the QMenu.) Since we can also reach this code by climbing the menu
+ // hierarchy (see below), or when the shortcut is not a key-equivalent, we
+ // need to check whether the QPA menu is actually disabled.
+ // When there is no QPA menu, there will be no QCocoaMenuDelegate checking
+ // for the actual shortcuts. We can then fallback to our own logic.
+ QPlatformMenu *pm = menu->platformMenu();
+ if (pm && !pm->isEnabled())
+ continue;
+#endif
+ QAction *a = menu->menuAction();
+ if (correctActionContext(context, a, active_window))
+ return true;
+ } else
+#endif
+ if (auto widget = qobject_cast<QWidget*>(object)) {
+ if (correctWidgetContext(context, widget, active_window))
+ return true;
+ }
+#if QT_CONFIG(graphicsview)
+ else if (auto graphicsWidget = qobject_cast<QGraphicsWidget*>(object)) {
+ if (correctGraphicsWidgetContext(context, graphicsWidget, active_window))
+ return true;
+ }
+#endif
+ }
+
+ return false;
+}
+#endif // QT_CONFIG(action)
+
+class QtWidgetsShortcutPrivate : public QShortcutPrivate
+{
+ Q_DECLARE_PUBLIC(QShortcut)
+public:
+ QtWidgetsShortcutPrivate() = default;
+
+ QShortcutMap::ContextMatcher contextMatcher() const override
+ { return qWidgetShortcutContextMatcher; }
+
+ bool handleWhatsThis() override;
+};
+
+bool QtWidgetsShortcutPrivate::handleWhatsThis()
+{
+#if QT_CONFIG(whatsthis)
+ if (QWhatsThis::inWhatsThisMode()) {
+ QWhatsThis::showText(QCursor::pos(), sc_whatsthis);
+ return true;
+ }
+#endif
+ return false;
+}
+
+QShortcutPrivate *QApplicationPrivate::createShortcutPrivate() const
+{
+ return new QtWidgetsShortcutPrivate;
+}
+
+QT_END_NAMESPACE
diff --git a/src/widgets/kernel/qsizepolicy.cpp b/src/widgets/kernel/qsizepolicy.cpp
index c4372a9fbc..bf3eb34d23 100644
--- a/src/widgets/kernel/qsizepolicy.cpp
+++ b/src/widgets/kernel/qsizepolicy.cpp
@@ -317,7 +317,7 @@ void QSizePolicy::setControlType(ControlType type) noexcept
*/
/*!
- \fn uint qHash(QSizePolicy key, uint seed = 0)
+ \fn size_t qHash(QSizePolicy key, size_t seed = 0)
\since 5.6
\relates QSizePolicy
diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h
index f26923eeb0..f4d0b2faa9 100644
--- a/src/widgets/kernel/qsizepolicy.h
+++ b/src/widgets/kernel/qsizepolicy.h
@@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE
class QVariant;
class QSizePolicy;
-Q_DECL_CONST_FUNCTION inline uint qHash(QSizePolicy key, uint seed = 0) noexcept;
+Q_DECL_CONST_FUNCTION inline size_t qHash(QSizePolicy key, size_t seed = 0) noexcept;
class Q_WIDGETS_EXPORT QSizePolicy
{
@@ -146,7 +146,7 @@ public:
QT_SIZEPOLICY_CONSTEXPR bool operator==(const QSizePolicy& s) const noexcept { return data == s.data; }
QT_SIZEPOLICY_CONSTEXPR bool operator!=(const QSizePolicy& s) const noexcept { return data != s.data; }
- friend Q_DECL_CONST_FUNCTION uint qHash(QSizePolicy key, uint seed) noexcept { return qHash(key.data, seed); }
+ friend Q_DECL_CONST_FUNCTION size_t qHash(QSizePolicy key, size_t seed) noexcept { return qHash(key.data, seed); }
operator QVariant() const;
diff --git a/src/widgets/kernel/qt_widgets_pch.h b/src/widgets/kernel/qt_widgets_pch.h
index b70941950b..3551f19e80 100644
--- a/src/widgets/kernel/qt_widgets_pch.h
+++ b/src/widgets/kernel/qt_widgets_pch.h
@@ -53,7 +53,9 @@
#include <qabstractbutton.h>
#include <qabstractscrollarea.h>
#include <qabstractslider.h>
-#include <qaction.h>
+#if QT_CONFIG(action)
+# include <qaction.h>
+#endif
#include <qcommonstyle.h>
#include <qlayout.h>
#include <qstyle.h>
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index fe57ac3a7e..08479a4a37 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -88,7 +88,9 @@
#include "qwidget_p.h"
#include <QtGui/private/qwindow_p.h>
-#include "qaction_p.h"
+#if QT_CONFIG(action)
+# include "QtGui/private/qaction_p.h"
+#endif
#include "qlayout_p.h"
#if QT_CONFIG(graphicsview)
#include "QtWidgets/qgraphicsproxywidget.h"
@@ -192,7 +194,15 @@ QWidgetPrivate::QWidgetPrivate(int version)
return;
}
- checkForIncompatibleLibraryVersion(version);
+#ifdef QT_BUILD_INTERNAL
+ // Don't check the version parameter in internal builds.
+ // This allows incompatible versions to be loaded, possibly for testing.
+ Q_UNUSED(version);
+#else
+ if (Q_UNLIKELY(version != QObjectPrivateVersion))
+ qFatal("Cannot mix incompatible Qt library (version 0x%x) with this library (version 0x%x)",
+ version, QObjectPrivateVersion);
+#endif
isWidget = true;
memset(high_attributes, 0, sizeof(high_attributes));
@@ -957,18 +967,11 @@ void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w)
flags |= Qt::WindowSystemMenuHint;
flags |= Qt::WindowTitleHint;
}
- if (customize)
- ; // don't modify window flags if the user explicitly set them.
- else if (type == Qt::Dialog || type == Qt::Sheet) {
- flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
- // ### fixme: Qt 6: Never set Qt::WindowContextHelpButtonHint flag automatically
- if (!QApplicationPrivate::testAttribute(Qt::AA_DisableWindowContextHelpButton))
- flags |= Qt::WindowContextHelpButtonHint;
- } else if (type == Qt::Tool)
+ if (!customize) { // don't modify window flags if the user explicitly set them.
flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
- else
- flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint |
- Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint;
+ if (type != Qt::Dialog && type != Qt::Sheet && type != Qt::Tool)
+ flags |= Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowFullscreenButtonHint;
+ }
if (w->testAttribute(Qt::WA_TransparentForMouseEvents))
flags |= Qt::WindowTransparentForInput;
}
@@ -1102,6 +1105,17 @@ QWindow *QWidgetPrivate::windowHandle(WindowHandleMode mode) const
return nullptr;
}
+/*!
+ \internal
+
+ Used by clients outside of widgets to get a handle to the
+ closest QWindow without having to link to widgets.
+*/
+QWindow *QWidgetPrivate::_q_closestWindowHandle() const
+{
+ return windowHandle(QWidgetPrivate::WindowHandleMode::Closest);
+}
+
QScreen *QWidgetPrivate::associatedScreen() const
{
if (auto window = windowHandle(WindowHandleMode::Closest))
@@ -1419,9 +1433,9 @@ QWidget::~QWidget()
#ifndef QT_NO_ACTION
// remove all actions from this widget
- for (int i = 0; i < d->actions.size(); ++i) {
- QActionPrivate *apriv = d->actions.at(i)->d_func();
- apriv->widgets.removeAll(this);
+ for (auto action : qAsConst(d->actions)) {
+ QActionPrivate *apriv = action->d_func();
+ apriv->associatedObjects.removeAll(this);
}
d->actions.clear();
#endif
@@ -1506,13 +1520,8 @@ QWidget::~QWidget()
if (d->declarativeData) {
d->wasDeleted = true; // needed, so that destroying the declarative data does the right thing
- if (static_cast<QAbstractDeclarativeDataImpl*>(d->declarativeData)->ownedByQml1) {
- if (QAbstractDeclarativeData::destroyed_qml1)
- QAbstractDeclarativeData::destroyed_qml1(d->declarativeData, this);
- } else {
- if (QAbstractDeclarativeData::destroyed)
- QAbstractDeclarativeData::destroyed(d->declarativeData, this);
- }
+ if (QAbstractDeclarativeData::destroyed)
+ QAbstractDeclarativeData::destroyed(d->declarativeData, this);
d->declarativeData = nullptr; // don't activate again in ~QObject
d->wasDeleted = false;
}
@@ -3127,7 +3136,7 @@ void QWidget::insertAction(QAction *before, QAction *action)
d->actions.insert(pos, action);
QActionPrivate *apriv = action->d_func();
- apriv->widgets.append(this);
+ apriv->associatedObjects.append(this);
QActionEvent e(QEvent::ActionAdded, action, before);
QCoreApplication::sendEvent(this, &e);
@@ -3164,7 +3173,7 @@ void QWidget::removeAction(QAction *action)
Q_D(QWidget);
QActionPrivate *apriv = action->d_func();
- apriv->widgets.removeAll(this);
+ apriv->associatedObjects.removeAll(this);
if (d->actions.removeAll(action)) {
QActionEvent e(QEvent::ActionRemoved, action);
@@ -4373,7 +4382,7 @@ void QWidget::setPalette(const QPalette &palette)
widget's palette are implicitly imposed on this widget by the user). Note
that this font does not take into account the palette set on \a w itself.
*/
-QPalette QWidgetPrivate::naturalWidgetPalette(uint inheritedMask) const
+QPalette QWidgetPrivate::naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const
{
Q_Q(const QWidget);
@@ -4910,9 +4919,6 @@ void qt_qpa_set_cursor(QWidget *w, bool force)
\note To obtain the contents of a QOpenGLWidget, use QOpenGLWidget::grabFramebuffer()
instead.
-
- \note To obtain the contents of a QGLWidget (deprecated), use
- QGLWidget::grabFrameBuffer() or QGLWidget::renderPixmap() instead.
*/
void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
const QRegion &sourceRegion, RenderFlags renderFlags)
diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h
index 415a738eb4..68a9b7ca9b 100644
--- a/src/widgets/kernel/qwidget.h
+++ b/src/widgets/kernel/qwidget.h
@@ -53,7 +53,9 @@
#include <QtGui/qregion.h>
#include <QtGui/qbrush.h>
#include <QtGui/qcursor.h>
-#include <QtGui/qkeysequence.h>
+#if QT_CONFIG(shortcut)
+# include <QtGui/qkeysequence.h>
+#endif
#ifdef QT_INCLUDE_COMPAT
#include <QtGui/qevent.h>
@@ -713,9 +715,6 @@ private:
friend class QLayout;
friend class QWidgetItem;
friend class QWidgetItemV2;
- friend class QGLContext;
- friend class QGLWidget;
- friend class QGLWindowSurface;
friend class QX11PaintEngine;
friend class QWin32PaintEngine;
friend class QShortcutPrivate;
@@ -743,6 +742,7 @@ private:
private:
Q_DISABLE_COPY(QWidget)
Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden())
+ Q_PRIVATE_SLOT(d_func(), QWindow *_q_closestWindowHandle())
QWidgetData *data;
};
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 6aadfe13f7..b71b72fe13 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -269,6 +269,7 @@ public:
TopLevel
};
QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const;
+ QWindow *_q_closestWindowHandle() const; // Private slot in QWidget
QScreen *associatedScreen() const;
@@ -298,7 +299,7 @@ public:
void setPalette_helper(const QPalette &);
void resolvePalette();
- QPalette naturalWidgetPalette(uint inheritedMask) const;
+ QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const;
void setMask_sys(const QRegion &);
@@ -672,7 +673,7 @@ public:
uint directFontResolveMask;
uint inheritedFontResolveMask;
decltype(std::declval<QPalette>().resolve()) directPaletteResolveMask;
- uint inheritedPaletteResolveMask;
+ QPalette::ResolveMask inheritedPaletteResolveMask;
short leftmargin;
short topmargin;
short rightmargin;
diff --git a/src/widgets/kernel/qwidgetaction.cpp b/src/widgets/kernel/qwidgetaction.cpp
index 9649e51b92..88e71fd800 100644
--- a/src/widgets/kernel/qwidgetaction.cpp
+++ b/src/widgets/kernel/qwidgetaction.cpp
@@ -38,9 +38,9 @@
****************************************************************************/
#include "qwidgetaction.h"
+#include "qwidget.h"
#include "qdebug.h"
-#ifndef QT_NO_ACTION
#include "qwidgetaction_p.h"
QT_BEGIN_NAMESPACE
@@ -282,5 +282,3 @@ QList<QWidget *> QWidgetAction::createdWidgets() const
QT_END_NAMESPACE
#include "moc_qwidgetaction.cpp"
-
-#endif // QT_NO_ACTION
diff --git a/src/widgets/kernel/qwidgetaction.h b/src/widgets/kernel/qwidgetaction.h
index 4769332a23..e3bfc62ca7 100644
--- a/src/widgets/kernel/qwidgetaction.h
+++ b/src/widgets/kernel/qwidgetaction.h
@@ -41,12 +41,11 @@
#define QWIDGETACTION_H
#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtWidgets/qaction.h>
-
-QT_BEGIN_NAMESPACE
+#include <QtGui/qaction.h>
+QT_REQUIRE_CONFIG(action);
-#ifndef QT_NO_ACTION
+QT_BEGIN_NAMESPACE
class QWidgetActionPrivate;
@@ -78,8 +77,6 @@ private:
friend class QToolBar;
};
-#endif // QT_NO_ACTION
-
QT_END_NAMESPACE
#endif // QWIDGETACTION_H
diff --git a/src/widgets/kernel/qwidgetaction_p.h b/src/widgets/kernel/qwidgetaction_p.h
index 1fbcf236a1..4b118c45c5 100644
--- a/src/widgets/kernel/qwidgetaction_p.h
+++ b/src/widgets/kernel/qwidgetaction_p.h
@@ -52,11 +52,13 @@
//
#include <QtWidgets/private/qtwidgetsglobal_p.h>
-#include "private/qaction_p.h"
+#include "private/qaction_widgets_p.h"
+
+QT_REQUIRE_CONFIG(action);
QT_BEGIN_NAMESPACE
-class QWidgetActionPrivate : public QActionPrivate
+class QWidgetActionPrivate : public QtWidgetsActionPrivate
{
Q_DECLARE_PUBLIC(QWidgetAction)
public:
diff --git a/src/widgets/kernel/qwidgetsvariant.cpp b/src/widgets/kernel/qwidgetsvariant.cpp
index edb166e8d5..45a3bb3f7a 100644
--- a/src/widgets/kernel/qwidgetsvariant.cpp
+++ b/src/widgets/kernel/qwidgetsvariant.cpp
@@ -48,36 +48,6 @@
QT_BEGIN_NAMESPACE
namespace {
-static void construct(QVariant::Private *x, const void *copy)
-{
- switch (x->type) {
- case QMetaType::QSizePolicy:
- v_construct<QSizePolicy>(x, copy);
- break;
- default:
- qWarning("Trying to construct an instance of an invalid type, type id: %i", x->type);
- x->type = QMetaType::UnknownType;
- return;
- }
- x->is_null = !copy;
-}
-
-static void clear(QVariant::Private *d)
-{
- switch (d->type) {
- case QMetaType::QSizePolicy:
- v_clear<QSizePolicy>(d);
- break;
- default:
- Q_ASSERT(false);
- return;
- }
-
- d->type = QMetaType::UnknownType;
- d->is_null = true;
- d->is_shared = false;
-}
-
static bool isNull(const QVariant::Private *)
{
@@ -86,8 +56,8 @@ static bool isNull(const QVariant::Private *)
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
{
- Q_ASSERT(a->type == b->type);
- switch(a->type) {
+ Q_ASSERT(a->type() == b->type());
+ switch (a->type().id()) {
case QMetaType::QSizePolicy:
return *v_cast<QSizePolicy>(a) == *v_cast<QSizePolicy>(b);
default:
@@ -110,19 +80,17 @@ static bool convert(const QVariant::Private *d, int type, void *result, bool *ok
static void streamDebug(QDebug dbg, const QVariant &v)
{
QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr());
- switch (d->type) {
+ switch (d->type().id()) {
case QMetaType::QSizePolicy:
dbg.nospace() << *v_cast<QSizePolicy>(d);
break;
default:
- dbg.nospace() << "QMetaType::Type(" << d->type << ')';
+ dbg.nospace() << "QMetaType::Type(" << d->type().id() << ')';
}
}
#endif
static const QVariant::Handler widgets_handler = {
- construct,
- clear,
isNull,
#ifndef QT_NO_DATASTREAM
nullptr,
@@ -138,23 +106,42 @@ static const QVariant::Handler widgets_handler = {
#endif
};
-#define QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES(MetaTypeName, MetaTypeId, RealName) \
- QT_METATYPE_INTERFACE_INIT(RealName),
+static const struct : QMetaTypeModuleHelper
+{
+ QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override {
+ switch (type) {
+ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE)
+ default: return nullptr;
+ }
+ }
+#ifndef QT_NO_DATASTREAM
+ bool save(QDataStream &stream, int type, const void *data) const override {
+ switch (type) {
+ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_DATASTREAM_SAVE)
+ default: return false;
+ }
+ }
+ bool load(QDataStream &stream, int type, void *data) const override {
+ switch (type) {
+ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_DATASTREAM_LOAD)
+ default: return false;
+ }
+ }
+#endif
+
+} qVariantWidgetsHelper;
-static const QMetaTypeInterface qVariantWidgetsHelper[] = {
- QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES)
-};
#undef QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES
} // namespace
-extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper;
+extern Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeWidgetsHelper;
void qRegisterWidgetsVariant()
{
qRegisterMetaType<QWidget*>();
- qMetaTypeWidgetsHelper = qVariantWidgetsHelper;
+ qMetaTypeWidgetsHelper = &qVariantWidgetsHelper;
QVariantPrivate::registerHandler(QModulesPrivate::Widgets, &widgets_handler);
}
Q_CONSTRUCTOR_FUNCTION(qRegisterWidgetsVariant)