From 14fc3f4b0d69a2395dc734d9bf72b943508e0450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 14 Aug 2019 14:32:56 +0200 Subject: [PATCH] Upgrade QWidgetPrivate::DrawWidgetFlag to QFlags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows for easier debugging of the paint cycle. Change-Id: Iab85bccb99198a02f33c0beeccd4e3914375358d Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 10 +++++----- src/widgets/kernel/qwidget_p.h | 19 +++++++++++++------ src/widgets/kernel/qwidgetrepaintmanager.cpp | 4 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index d1ad0c0a01..d792b48467 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2353,7 +2353,7 @@ bool QWidgetPrivate::updateBrushOrigin(QPainter *painter, const QBrush &brush) c return true; } -void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const +void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, DrawWidgetFlags flags) const { Q_Q(const QWidget); @@ -5410,7 +5410,7 @@ void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset #endif } -void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, +void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter, QWidgetRepaintManager *repaintManager) { if (rgn.isEmpty()) @@ -5508,7 +5508,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP beginBackingStorePainting(); #endif QPainter p(q); - paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0); + paintBackground(&p, toBePainted, (asRoot || onScreen) ? (flags | DrawAsRoot) : DrawWidgetFlags()); #ifndef QT_NO_OPENGL endBackingStorePainting(); #endif @@ -5691,7 +5691,7 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, } // Set backingstore flags. - int flags = DrawPaintOnScreen | DrawInvisible; + DrawWidgetFlags flags = DrawPaintOnScreen | DrawInvisible; if (renderFlags & QWidget::DrawWindowBackground) flags |= DrawAsRoot; @@ -5711,7 +5711,7 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, } void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, - const QPoint &offset, int flags + const QPoint &offset, DrawWidgetFlags flags , QPainter *sharedPainter, QWidgetRepaintManager *repaintManager) { QWidget *w = 0; diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index c3b3a2ed93..1cb9769d4d 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -266,10 +266,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, @@ -279,12 +280,15 @@ public: DontDrawNativeChildren = 0x40, DontSetCompositionMode = 0x80 }; + Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag) + Q_FLAG(DrawWidgetFlags) enum CloseMode { CloseNoEvent, CloseWithEvent, CloseWithSpontaneousEvent }; + Q_ENUM(CloseMode) enum Direction { DirectionNorth = 0x01, @@ -292,6 +296,7 @@ public: DirectionSouth = 0x02, DirectionWest = 0x20 }; + Q_ENUM(Direction) // Functions. explicit QWidgetPrivate(int version = QObjectPrivateVersion); @@ -376,20 +381,20 @@ public: void setUpdatesEnabled_helper(bool ); bool updateBrushOrigin(QPainter *, const QBrush &brush) const; - void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) 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, + 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, + const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter, QWidgetRepaintManager *repaintManager); #if QT_CONFIG(graphicsview) @@ -873,16 +878,18 @@ public: bool stealMouseGrab(bool grab); }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags) + struct QWidgetPaintContext { - inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f, + 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; QWidgetRepaintManager *repaintManager; QPainter *painter; diff --git a/src/widgets/kernel/qwidgetrepaintmanager.cpp b/src/widgets/kernel/qwidgetrepaintmanager.cpp index 30d92551f7..76b591aa2c 100644 --- a/src/widgets/kernel/qwidgetrepaintmanager.cpp +++ b/src/widgets/kernel/qwidgetrepaintmanager.cpp @@ -1335,7 +1335,7 @@ void QWidgetRepaintManager::doSync() QWidget *w = opaqueNonOverlappedWidgets[i]; QWidgetPrivate *wd = w->d_func(); - int flags = QWidgetPrivate::DrawRecursive; + QWidgetPrivate::DrawWidgetFlags flags = QWidgetPrivate::DrawRecursive; // Scrolled and moved widgets must draw all children. if (!wd->isScrolled && !wd->isMoved) flags |= QWidgetPrivate::DontDrawOpaqueChildren; @@ -1353,7 +1353,7 @@ void QWidgetRepaintManager::doSync() // Paint the rest with composition. if (repaintAllWidgets || !dirtyCopy.isEmpty()) { - const int flags = QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawRecursive; + QWidgetPrivate::DrawWidgetFlags flags = QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawRecursive; tlw->d_func()->drawWidget(store->paintDevice(), dirtyCopy, QPoint(), flags, 0, this); }