diff options
Diffstat (limited to 'src/widgets/kernel/qwidget_p.h')
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 539 |
1 files changed, 210 insertions, 329 deletions
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 142d5ef9bb..9fab9efa62 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 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 @@ -51,6 +15,8 @@ // We mean it. // + + #include <QtWidgets/private/qtwidgetsglobal_p.h> #include "QtWidgets/qwidget.h" #include "private/qobject_p.h" @@ -59,8 +25,8 @@ #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" #include "QtWidgets/qstyle.h" #include "QtWidgets/qapplication.h" @@ -74,19 +40,28 @@ #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> 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. // - top-level widgets have extra extra data to reduce cost further class QWidgetWindow; class QPaintEngine; class QPixmap; -class QWidgetBackingStore; +class QWidgetRepaintManager; class QGraphicsProxyWidget; class QWidgetItemV2; -class QOpenGLContext; class QStyle; @@ -94,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 { @@ -103,70 +79,22 @@ public: { } - ~QUpdateLaterEvent() - { - } - inline const QRegion ®ion() const { return m_region; } protected: + friend class QApplication; QRegion m_region; }; - - -class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker -{ - -public: - QWidgetBackingStoreTracker(); - ~QWidgetBackingStoreTracker(); - - void create(QWidget *tlw); - void destroy(); - - void registerWidget(QWidget *w); - void unregisterWidget(QWidget *w); - void unregisterWidgetSubtree(QWidget *w); - - inline QWidgetBackingStore* data() - { - return m_ptr; - } - - inline QWidgetBackingStore* operator->() - { - return m_ptr; - } - - inline QWidgetBackingStore& operator*() - { - return *m_ptr; - } - - inline operator bool() const - { - return (0 != m_ptr); - } - -private: - Q_DISABLE_COPY(QWidgetBackingStoreTracker) - -private: - QWidgetBackingStore* m_ptr; - QSet<QWidget *> m_widgets; -}; - struct QTLWExtra { // *************************** Cross-platform variables ***************************** // Regular pointers (keep them together to avoid gaps on 64 bits architectures). - QIcon *icon; // widget icon - QWidgetBackingStoreTracker backingStoreTracker; + std::unique_ptr<QIcon> icon; // widget icon + std::unique_ptr<QWidgetRepaintManager> repaintManager; QBackingStore *backingStore; QPainter *sharedPainter; QWidgetWindow *window; - QOpenGLContext *shareContext; // Implicit pointers (shared_null). QString caption; // widget caption @@ -181,52 +109,15 @@ struct QTLWExtra { QRect frameStrut; QRect normalGeometry; // used by showMin/maximized/FullScreen Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen - // ### TODO replace initialScreenIndex with QScreen *, in case the screens change at runtime - int initialScreenIndex; // Screen number when passing a QDesktop[Screen]Widget as parent. + QScreen *initialScreen; // Screen when passing a QDesktop[Screen]Widget as parent. - QVector<QPlatformTextureList *> widgetTextures; + std::vector<std::unique_ptr<QPlatformTextureList>> widgetTextures; // *************************** Cross-platform bit fields **************************** uint opacity : 8; uint posIncludesFrame : 1; uint sizeAdjusted : 1; - uint inTopLevelResize : 1; uint embedded : 1; - - // *************************** Platform specific values (bit fields first) ********** -#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <----------------------------------------------------------- X11 - uint spont_unmapped: 1; // window was spontaneously unmapped - uint dnd : 1; // DND properties installed - uint validWMState : 1; // is WM_STATE valid? - uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet - WId parentWinId; // parent window Id (valid after reparenting) - WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom - QPoint fullScreenOffset; -#ifndef QT_NO_XSYNC - WId syncUpdateCounter; - ulong syncRequestTimestamp; - qint32 newCounterValueHi; - quint32 newCounterValueLo; -#endif -#elif 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <--------------------------------------------------------- WIN - uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered. - HICON winIconBig; // internal big Windows icon - HICON winIconSmall; // internal small Windows icon -#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <--------------------------------------------------------- MAC - uint resizer : 4; - uint isSetGeometry : 1; - uint isMove : 1; - quint32 wattr; - quint32 wclass; - WindowGroupRef group; - IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys. - quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys() - // This value is just to make sure we maximize and restore to the right location, yet we allow apps to be maximized and - // manually resized. - // The name is misleading, since this is set when maximizing the window. It is a hint to saveGeometry(..) to record the - // starting position as 0,0 instead of the normal starting position. - bool wasMaximized; -#endif }; struct QWExtra { @@ -234,12 +125,12 @@ struct QWExtra { // Regular pointers (keep them together to avoid gaps on 64 bits architectures). void *glContext; // if the widget is hijacked by QGLWindowSurface - QTLWExtra *topextra; // only useful for TLWs + std::unique_ptr<QTLWExtra> topextra; // only useful for TLWs #if QT_CONFIG(graphicsview) QGraphicsProxyWidget *proxyWidget; // if the widget is embedded #endif #ifndef QT_NO_CURSOR - QCursor *curs; + std::unique_ptr<QCursor> curs; #endif QPointer<QStyle> style; QPointer<QWidget> focus_proxy; @@ -265,21 +156,6 @@ struct QWExtra { uint inRenderWithPainter : 1; uint hasMask : 1; uint hasWindowContainer : 1; - - // *************************** Platform specific values (bit fields first) ********** -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <----------------------------------------------------------- WIN -#if QT_CONFIG(draganddrop) - QOleDropTarget *dropTarget; // drop target - QList<QPointer<QWidget> > oleDropWidgets; -#endif -#elif 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <--------------------------------------------------------- X11 - uint compress_events : 1; - WId xDndProxy; // XDND forwarding to embedded windows -#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <------------------------------------------------------ MAC - // Cocoa Mask stuff - QImage maskBits; - CGImageRef imageMask; -#endif }; /*! @@ -303,10 +179,11 @@ static inline bool bypassGraphicsProxyWidget(const QWidget *p) class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QWidget) + Q_GADGET public: // *************************** Cross-platform *************************************** - enum DrawWidgetFlags { + enum DrawWidgetFlag { DrawAsRoot = 0x01, DrawPaintOnScreen = 0x02, DrawRecursive = 0x04, @@ -314,14 +191,11 @@ public: DontSubtractOpaqueChildren = 0x10, DontDrawOpaqueChildren = 0x20, DontDrawNativeChildren = 0x40, - DontSetCompositionMode = 0x80 - }; - - enum CloseMode { - CloseNoEvent, - CloseWithEvent, - CloseWithSpontaneousEvent + DontSetCompositionMode = 0x80, + UseEffectRegionBounds = 0x100 }; + Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag) + Q_FLAG(DrawWidgetFlags) enum Direction { DirectionNorth = 0x01, @@ -329,6 +203,7 @@ public: DirectionSouth = 0x02, DirectionWest = 0x20 }; + Q_ENUM(Direction) // Functions. explicit QWidgetPrivate(int version = QObjectPrivateVersion); @@ -337,13 +212,27 @@ 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; QPainter *sharedPainter() const; void setSharedPainter(QPainter *painter); - QWidgetBackingStore *maybeBackingStore() const; - QWidgetWindow *windowHandle() const; + QWidgetRepaintManager *maybeRepaintManager() const; + + QRhi *rhi() const; + + enum class WindowHandleMode { + Direct, + Closest, + TopLevel + }; + QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const; + QWindow *_q_closestWindowHandle() const; // Private slot in QWidget + + QScreen *associatedScreen() const; template <typename T> void repaint(T t); @@ -371,7 +260,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 &); @@ -385,7 +274,7 @@ public: void updateFont(const QFont &); inline void setFont_helper(const QFont &font) { - if (directFontResolveMask == font.resolve() && data.fnt == font) + if (directFontResolveMask == font.resolveMask() && data.fnt == font) return; updateFont(font); } @@ -404,38 +293,39 @@ public: void setUpdatesEnabled_helper(bool ); - void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const; + bool updateBrushOrigin(QPainter *, const QBrush &brush) const; + void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags = DrawAsRoot) const; bool isAboutToShow() const; QRegion prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags); void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags); void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags); - void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, - QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0); + void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, + QPainter *sharedPainter = nullptr, QWidgetRepaintManager *repaintManager = nullptr); void sendPaintEvent(const QRegion &toBePainted); void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index, - const QRegion &rgn, const QPoint &offset, int flags, - QPainter *sharedPainter, QWidgetBackingStore *backingStore); + const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, + QPainter *sharedPainter, QWidgetRepaintManager *repaintManager); #if QT_CONFIG(graphicsview) static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin); #endif - void repaint_sys(const QRegion &rgn); + bool shouldPaintOnScreen() const; + void paintOnScreen(const QRegion &rgn); QRect clipRect() const; QRegion clipRegion() const; void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion ®ion); void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const; - void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0, + void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = nullptr, bool alsoNonOpaque = false) const; void clipToEffectiveMask(QRegion ®ion) const; void updateIsOpaque(); void setOpaque(bool opaque); void updateIsTranslucent(); - bool paintOnScreen() const; #if QT_CONFIG(graphicseffect) void invalidateGraphicsEffectsRecursively(); #endif // QT_CONFIG(graphicseffect) @@ -443,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(); @@ -453,25 +350,29 @@ public: void scrollChildren(int dx, int dy); void moveRect(const QRect &, int dx, int dy); void scrollRect(const QRect &, int dx, int dy); - void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize); - // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore). - void invalidateBuffer(const QRegion &); - void invalidateBuffer(const QRect &); + void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize); + + template <class T> + 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); + bool shouldDiscardSyncRequest() const; + // tells the input method about the widgets transform void updateWidgetTransform(QEvent *event); void reparentFocusWidgets(QWidget *oldtlw); - static int pointToRect(const QPoint &p, const QRect &r); - void setWinId(WId); 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(); @@ -484,11 +385,12 @@ public: void show_sys(); void hide_sys(); void hide_helper(); + bool isExplicitlyHidden() const; void _q_showIfNotHidden(); void setVisible(bool); void setEnabled_helper(bool); - static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0); + static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = nullptr); void updateFrameStrut(); QRect frameStrut() const; @@ -525,7 +427,7 @@ public: void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const; void setLayoutItemMargins(int left, int top, int right, int bottom); - void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0); + void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = nullptr); void updateContentsRect(); QMargins safeAreaMargins() const; @@ -544,33 +446,60 @@ public: void setModal_sys(); - // This is an helper function that return the available geometry for - // a widget and takes care is this one is in QGraphicsView. - // If the widget is not embed in a scene then the geometry available is - // null, we let QDesktopWidget decide for us. - static QRect screenGeometry(const QWidget *widget) + // 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 QWidget *parentGraphicsView(const QWidget *widget) { - QRect screen; #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() != 0) { - // 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); - screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect(); - } else { - screen = ancestorProxy->scene()->sceneRect().toRect(); + if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != nullptr) { + if (!ancestorProxy->scene()->views().empty()) { + return ancestorProxy->scene()->views().at(0); } } } #else Q_UNUSED(widget); #endif + return nullptr; + } + + static QRect screenGeometry(const QWidget *widget) + { + return screenGeometry(widget, QPoint(), false); + } + + static QRect availableScreenGeometry(const QWidget *widget) + { + return availableScreenGeometry(widget, QPoint(), false); + } + + static QScreen *screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true) + { + while (QWidget *view = parentGraphicsView(widget)) + widget = view; + + QScreen *screen = nullptr; + if (hasPosition) + screen = widget->screen()->virtualSiblingAt(globalPosition); + if (!screen) + screen = widget->screen(); + return screen; } + static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true) + { + return screen(widget, globalPosition, hasPosition)->geometry(); + } + + 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) { Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent)); @@ -586,7 +515,7 @@ public: } inline void restoreRedirected() - { redirectDev = 0; } + { redirectDev = nullptr; } inline void enforceNativeChildren() { @@ -608,6 +537,11 @@ public: return extra ? extra->nativeChildrenForced : false; } + inline QRect effectiveRectFor(const QRegion ®ion) const + { + return effectiveRectFor(region.boundingRect()); + } + inline QRect effectiveRectFor(const QRect &rect) const { #if QT_CONFIG(graphicseffect) @@ -621,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) { @@ -645,17 +585,22 @@ public: inline QRect mapFromWS(const QRect &r) const { return r.translated(data.wrect.topLeft()); } - QOpenGLContext *shareContext() const; + virtual QObject *focusObject(); - virtual QObject *focusObject() { return 0; } + virtual QPlatformBackingStoreRhiConfig rhiConfig() const { return {}; } -#ifndef QT_NO_OPENGL - virtual GLuint textureId() const { return 0; } + // Note that textureRight may be null, as it's only used in stereoscopic rendering + struct TextureData { + QRhiTexture *textureLeft = nullptr; + QRhiTexture *textureRight = nullptr; + }; + + virtual TextureData texture() const { return {}; } virtual QPlatformTextureList::Flags textureListFlags() { Q_Q(QWidget); return q->testAttribute(Qt::WA_AlwaysStackOnTop) ? QPlatformTextureList::StacksOnTop - : QPlatformTextureList::Flags(0); + : QPlatformTextureList::Flags(); } virtual QImage grabFramebuffer() { return QImage(); } virtual void beginBackingStorePainting() { } @@ -685,13 +630,21 @@ 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). - QWExtra *extra; + std::unique_ptr<QWExtra> extra; QWidget *focus_next; QWidget *focus_prev; QWidget *focus_child; @@ -717,7 +670,7 @@ public: // Implicit pointers (shared_null/shared_empty). QRegion opaqueChildren; QRegion dirty; -#ifndef QT_NO_TOOLTIP +#if QT_CONFIG(tooltip) QString toolTip; int toolTipDuration; #endif @@ -727,7 +680,7 @@ public: #if QT_CONFIG(whatsthis) QString whatsThis; #endif -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QString accessibleName; QString accessibleDescription; #endif @@ -735,7 +688,8 @@ public: // Other variables. uint directFontResolveMask; uint inheritedFontResolveMask; - uint inheritedPaletteResolveMask; + decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask; + QPalette::ResolveMask inheritedPaletteResolveMask; short leftmargin; short topmargin; short rightmargin; @@ -775,138 +729,72 @@ 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() -#endif -#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <----------------------------------------------------------- X11 - Qt::HANDLE picture; - static QWidget *mouseGrabber; - static QWidget *keyboardGrabber; - - void setWindowRole(); - void sendStartupMessage(const char *message) const; - void x11UpdateIsOpaque(); - bool isBackgroundInherited() const; - void updateX11AcceptFocus(); - QPoint mapToGlobal(const QPoint &pos) const; - QPoint mapFromGlobal(const QPoint &pos) const; -#elif 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <--------------------------------------------------------- WIN -#ifndef QT_NO_GESTURES - uint nativeGesturePanEnabled : 1; -#endif - bool shouldShowMaximizeButton(); - void winUpdateIsOpaque(); - void reparentChildren(); -#if QT_CONFIG(draganddrop) - QOleDropTarget *registerOleDnd(QWidget *widget); - void unregisterOleDnd(QWidget *widget, QOleDropTarget *target); -#endif - void grabMouseWhileInWindow(); - void registerTouchWindow(); - void winSetupGestures(); -#elif defined(Q_OS_MAC) // <--------------------------------------------------------- MAC +#elif defined(Q_OS_MAC) void macUpdateSizeAttribute(); -#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <--------------------------------------------------------- MAC (old stuff) - // This is new stuff - uint needWindowChange : 1; - - // Each wiget keeps a list of all its child and grandchild OpenGL widgets. - // This list is used to update the gl context whenever a parent and a granparent - // moves, and also to check for intersections with gl widgets within the window - // when a widget moves. - struct GlWidgetInfo - { - GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { } - bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); } - QWidget * widget; - QWidget * lastUpdateWidget; - }; - - // dirtyOnWidget contains the areas in the widget that needs to be repained, - // in the same way as dirtyOnScreen does for the window. Areas are added in - // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use - // this information repaint invalid areas when widgets are scrolled. - QRegion dirtyOnWidget; - EventHandlerRef window_event; - QList<GlWidgetInfo> glWidgets; - - //these are here just for code compat (HIViews) - Qt::HANDLE qd_hd; - - void macUpdateHideOnSuspend(); - void macUpdateOpaqueSizeGrip(); - void macUpdateIgnoreMouseEvents(); - void macUpdateMetalAttribute(); - void macUpdateIsOpaque(); - void macSetNeedsDisplay(QRegion region); - void setEnabled_helper_sys(bool enable); - bool isRealWindow() const; - void adjustWithinMaxAndMinSize(int &w, int &h); - void applyMaxAndMinSizeOnWindow(); - void update_sys(const QRect &rect); - void update_sys(const QRegion &rgn); - void setGeometry_sys_helper(int, int, int, int, bool); - void updateMaximizeButton_sys(); - void createWindow_sys(); - void recreateMacWindow(); - void setSubWindowStacking(bool set); - void setWindowLevel(); - void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef); - void syncCocoaMask(); - void finishCocoaMaskSetup(); - // Did we add the drawRectOriginal method? - bool drawRectOriginalAdded; - // Is the original drawRect method available? - bool originalDrawMethod; - // Do we need to change the methods? - bool changeMethods; - - // Unified toolbar variables - bool isInUnifiedToolbar; - QUnifiedToolbarSurface *unifiedSurface; - QPoint toolbar_offset; - QWidget *toolbar_ancestor; - bool flushRequested; - bool touchEventsEnabled; - void determineWindowClass(); - void transferChildren(); - bool qt_mac_dnd_event(uint, DragRef); - void toggleDrawers(bool); - //mac event functions - static bool qt_create_root_win(); - static void qt_clean_root_win(); - static bool qt_mac_update_sizer(QWidget *, int up = 0); - static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *); - static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *); - static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool); - void registerTouchWindow(bool enable = true); #endif void setNetWmWindowTypes(bool skipIfMissing = false); 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) + struct QWidgetPaintContext { - inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f, - QPainter *p, QWidgetBackingStore *b) - : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {} + inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f, + QPainter *p, QWidgetRepaintManager *rpm) + : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {} QPaintDevice *pdev; QRegion rgn; QPoint offset; - int flags; + QWidgetPrivate::DrawWidgetFlags flags; QPainter *sharedPainter; - QWidgetBackingStore *backingStore; + QWidgetRepaintManager *repaintManager; QPainter *painter; }; @@ -915,14 +803,14 @@ class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate { public: QWidgetEffectSourcePrivate(QWidget *widget) - : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false) + : QGraphicsEffectSourcePrivate(), m_widget(widget), context(nullptr), updateDueToGraphicsEffect(false) {} void detach() override - { m_widget->d_func()->graphicsEffect = 0; } + { m_widget->d_func()->graphicsEffect = nullptr; } const QGraphicsItem *graphicsItem() const override - { return 0; } + { return nullptr; } const QWidget *widget() const override { return m_widget; } @@ -948,7 +836,7 @@ public: } const QStyleOption *styleOption() const override - { return 0; } + { return nullptr; } QRect deviceRect() const override { return m_widget->window()->rect(); } @@ -967,25 +855,25 @@ public: inline QWExtra *QWidgetPrivate::extraData() const { - return extra; + return extra.get(); } inline QTLWExtra *QWidgetPrivate::topData() const { const_cast<QWidgetPrivate *>(this)->createTLExtra(); - return extra->topextra; + return extra->topextra.get(); } inline QTLWExtra *QWidgetPrivate::maybeTopData() const { - return extra ? extra->topextra : 0; + return extra ? extra->topextra.get() : nullptr; } inline QPainter *QWidgetPrivate::sharedPainter() const { Q_Q(const QWidget); QTLWExtra *x = q->window()->d_func()->maybeTopData(); - return x ? x->sharedPainter : 0; + return x ? x->sharedPainter : nullptr; } inline void QWidgetPrivate::setSharedPainter(QPainter *painter) @@ -1002,18 +890,11 @@ inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const || extra->mask.contains(p)); } -inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const +inline QWidgetRepaintManager *QWidgetPrivate::maybeRepaintManager() const { Q_Q(const QWidget); QTLWExtra *x = q->window()->d_func()->maybeTopData(); - return x ? x->backingStoreTracker.data() : 0; -} - -inline QWidgetWindow *QWidgetPrivate::windowHandle() const -{ - if (QTLWExtra *x = maybeTopData()) - return x->window; - return nullptr; + return x ? x->repaintManager.get() : nullptr; } QT_END_NAMESPACE |