diff options
Diffstat (limited to 'src/widgets/kernel/qwidget_p.h')
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 197 |
1 files changed, 104 insertions, 93 deletions
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index b63729cd87..9fab9efa62 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** 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. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QWIDGET_P_H #define QWIDGET_P_H @@ -61,7 +25,6 @@ #include "QtCore/qset.h" #include "QtGui/qregion.h" #include "QtGui/qinputmethod.h" -#include "QtGui/qopengl.h" #include "QtGui/qsurfaceformat.h" #include "QtGui/qscreen.h" #include "QtWidgets/qsizepolicy.h" @@ -77,6 +40,10 @@ #endif #include <private/qgesture_p.h> #include <qpa/qplatformbackingstore.h> +#include <QtGui/private/qbackingstorerhisupport_p.h> +#include <private/qapplication_p.h> + +#include <QtCore/qpointer.h> #include <vector> #include <memory> @@ -84,6 +51,7 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcWidgetPainting); +Q_DECLARE_LOGGING_CATEGORY(lcWidgetShowHide); // Extra QWidget data // - to minimize memory usage for members that are seldom used. @@ -94,7 +62,6 @@ class QPixmap; class QWidgetRepaintManager; class QGraphicsProxyWidget; class QWidgetItemV2; -class QOpenGLContext; class QStyle; @@ -102,6 +69,7 @@ class QUnifiedToolbarSurface; // implemented in qshortcut.cpp bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context); +void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType); class QUpdateLaterEvent : public QEvent { @@ -111,13 +79,10 @@ public: { } - ~QUpdateLaterEvent() - { - } - inline const QRegion ®ion() const { return m_region; } protected: + friend class QApplication; QRegion m_region; }; @@ -130,9 +95,6 @@ struct QTLWExtra { QBackingStore *backingStore; QPainter *sharedPainter; QWidgetWindow *window; -#ifndef QT_NO_OPENGL - mutable std::unique_ptr<QOpenGLContext> shareContext; -#endif // Implicit pointers (shared_null). QString caption; // widget caption @@ -149,9 +111,7 @@ struct QTLWExtra { Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen QScreen *initialScreen; // Screen when passing a QDesktop[Screen]Widget as parent. -#ifndef QT_NO_OPENGL std::vector<std::unique_ptr<QPlatformTextureList>> widgetTextures; -#endif // *************************** Cross-platform bit fields **************************** uint opacity : 8; @@ -231,18 +191,12 @@ public: DontSubtractOpaqueChildren = 0x10, DontDrawOpaqueChildren = 0x20, DontDrawNativeChildren = 0x40, - DontSetCompositionMode = 0x80 + DontSetCompositionMode = 0x80, + UseEffectRegionBounds = 0x100 }; Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag) Q_FLAG(DrawWidgetFlags) - enum CloseMode { - CloseNoEvent, - CloseWithEvent, - CloseWithSpontaneousEvent - }; - Q_ENUM(CloseMode) - enum Direction { DirectionNorth = 0x01, DirectionEast = 0x10, @@ -258,6 +212,9 @@ public: static QWidgetPrivate *get(QWidget *w) { return w->d_func(); } static const QWidgetPrivate *get(const QWidget *w) { return w->d_func(); } + static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry, + int frameHeight); + QWExtra *extraData() const; QTLWExtra *topData() const; QTLWExtra *maybeTopData() const; @@ -265,6 +222,8 @@ public: void setSharedPainter(QPainter *painter); QWidgetRepaintManager *maybeRepaintManager() const; + QRhi *rhi() const; + enum class WindowHandleMode { Direct, Closest, @@ -374,7 +333,14 @@ public: const QRegion &getOpaqueChildren() const; void setDirtyOpaqueRegion(); - bool close_helper(CloseMode mode); + bool close(); + enum CloseMode { + CloseNoEvent, + CloseWithEvent, + CloseWithSpontaneousEvent + }; + Q_ENUM(CloseMode) + bool handleClose(CloseMode mode); void setWindowIcon_helper(); void setWindowIcon_sys(); @@ -390,6 +356,7 @@ public: void invalidateBackingStore(const T &); QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const; + bool isOverlapped(const QRect &rect) const { return !overlappedRegion(rect, true).isEmpty(); } void syncBackingStore(); void syncBackingStore(const QRegion ®ion); @@ -404,6 +371,8 @@ public: void showChildren(bool spontaneous); void hideChildren(bool spontaneous); void setParent_sys(QWidget *parent, Qt::WindowFlags); + void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags = {}); + void reparentWidgetWindowChildren(QWidget *parentWithWindow); void scroll_sys(int dx, int dy); void scroll_sys(int dx, int dy, const QRect &r); void deactivateWidgetCleanup(); @@ -416,6 +385,7 @@ public: void show_sys(); void hide_sys(); void hide_helper(); + bool isExplicitlyHidden() const; void _q_showIfNotHidden(); void setVisible(bool); @@ -478,27 +448,22 @@ public: // These helper functions return the (available) geometry for the screen // the widget is on, and takes care if this one is embedded in a QGraphicsView. - static QRect graphicsViewParentRect(const QWidget *widget) + static QWidget *parentGraphicsView(const QWidget *widget) { - QRect rect; #if QT_CONFIG(graphicsview) QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget); //It's embedded if it has an ancestor if (ancestorProxy) { if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != nullptr) { - // One view, let be smart and return the viewport rect then the popup is aligned - if (ancestorProxy->scene()->views().size() == 1) { - QGraphicsView *view = ancestorProxy->scene()->views().at(0); - rect = view->mapToScene(view->viewport()->rect()).boundingRect().toRect(); - } else { - rect = ancestorProxy->scene()->sceneRect().toRect(); + if (!ancestorProxy->scene()->views().empty()) { + return ancestorProxy->scene()->views().at(0); } } } #else Q_UNUSED(widget); #endif - return rect; + return nullptr; } static QRect screenGeometry(const QWidget *widget) @@ -511,11 +476,10 @@ public: return availableScreenGeometry(widget, QPoint(), false); } - static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true) + static QScreen *screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true) { - QRect rect = graphicsViewParentRect(widget); - if (!rect.isNull()) - return rect; + while (QWidget *view = parentGraphicsView(widget)) + widget = view; QScreen *screen = nullptr; if (hasPosition) @@ -523,22 +487,17 @@ public: if (!screen) screen = widget->screen(); - return screen->geometry(); + return screen; } - static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true) + static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true) { - QRect rect = graphicsViewParentRect(widget); - if (!rect.isNull()) - return rect; - - QScreen *screen = nullptr; - if (hasPosition) - screen = widget->screen()->virtualSiblingAt(globalPosition); - if (!screen) - screen = widget->screen(); + return screen(widget, globalPosition, hasPosition)->geometry(); + } - return screen->availableGeometry(); + static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true) + { + return screen(widget, globalPosition, hasPosition)->availableGeometry(); } inline void setRedirected(QPaintDevice *replacement, const QPoint &offset) @@ -596,8 +555,14 @@ public: inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus) { + if (button == Qt::LeftButton) + handleSoftwareInputPanel(clickCausedFocus); + } + + inline void handleSoftwareInputPanel(bool clickCausedFocus = false) + { Q_Q(QWidget); - if (button == Qt::LeftButton && qApp->autoSipEnabled()) { + if (qApp->autoSipEnabled()) { QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) { @@ -620,12 +585,17 @@ public: inline QRect mapFromWS(const QRect &r) const { return r.translated(data.wrect.topLeft()); } - QOpenGLContext *shareContext() const; + virtual QObject *focusObject(); + + virtual QPlatformBackingStoreRhiConfig rhiConfig() const { return {}; } - virtual QObject *focusObject() { return nullptr; } + // Note that textureRight may be null, as it's only used in stereoscopic rendering + struct TextureData { + QRhiTexture *textureLeft = nullptr; + QRhiTexture *textureRight = nullptr; + }; -#ifndef QT_NO_OPENGL - virtual GLuint textureId() const { return 0; } + virtual TextureData texture() const { return {}; } virtual QPlatformTextureList::Flags textureListFlags() { Q_Q(QWidget); return q->testAttribute(Qt::WA_AlwaysStackOnTop) @@ -660,10 +630,18 @@ public: virtual void resizeViewportFramebuffer() { } // Called after each paint event. virtual void resolveSamples() { } -#endif + + // These two are used in QGraphicsView for supporting stereoscopic rendering with a + // QOpenGLWidget viewport. + virtual bool isStereoEnabled() { return false; } // Called in QGraphicsView::setupViewport + virtual bool toggleStereoTargetBuffer() { return false; } // Called in QGraphicsView::paintEvent static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent); + std::string flagsForDumping() const override; + + QWidget *closestParentWidgetWithWindowHandle() const; + // Variables. // Regular pointers (keep them together to avoid gaps on 64 bit architectures). std::unique_ptr<QWExtra> extra; @@ -702,7 +680,7 @@ public: #if QT_CONFIG(whatsthis) QString whatsThis; #endif -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QString accessibleName; QString accessibleDescription; #endif @@ -751,13 +729,45 @@ public: #ifndef QT_NO_IM uint inheritsInputMethodHints : 1; #endif -#ifndef QT_NO_OPENGL uint renderToTextureReallyDirty : 1; - uint renderToTextureComposeActive : 1; -#endif + uint usesRhiFlush : 1; uint childrenHiddenByWState : 1; uint childrenShownByExpose : 1; + // *************************** Focus abstraction ************************************ + enum class FocusDirection { + Previous, + Next, + }; + + enum class FocusChainRemovalRule { + EnsureFocusOut = 0x01, + AssertConsistency = 0x02, + }; + Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule) + + // Getters + QWidget *nextPrevElementInFocusChain(FocusDirection direction) const; + + // manipulators + bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(), + FocusDirection direction = FocusDirection::Next); + bool insertIntoFocusChain(FocusDirection direction, QWidget *position); + static bool insertIntoFocusChain(const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position); + bool insertIntoFocusChainBefore(QWidget *position) + { return insertIntoFocusChain(FocusDirection::Previous, position); } + bool insertIntoFocusChainAfter(QWidget *position) + { return insertIntoFocusChain(FocusDirection::Next, position); } + static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to, + FocusDirection direction = FocusDirection::Next); + void reparentFocusChildren(FocusDirection direction); + QWidget *determineLastFocusChild(QWidget *noFurtherThan); + + // Initialization and tests + void initFocusChain(); + bool isInFocusChain() const; + bool isFocusChainConsistent() const; + // *************************** Platform specific ************************************ #if defined(Q_OS_WIN) uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine() @@ -768,6 +778,7 @@ public: bool stealKeyboardGrab(bool grab); bool stealMouseGrab(bool grab); + bool hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf = nullptr) const; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags) |