Upgrade QWidgetPrivate::DrawWidgetFlag to QFlags

Allows for easier debugging of the paint cycle.

Change-Id: Iab85bccb99198a02f33c0beeccd4e3914375358d
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2019-08-14 14:32:56 +02:00
parent 6d9d4e6817
commit 14fc3f4b0d
3 changed files with 20 additions and 13 deletions

View File

@ -2353,7 +2353,7 @@ bool QWidgetPrivate::updateBrushOrigin(QPainter *painter, const QBrush &brush) c
return true; 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); Q_Q(const QWidget);
@ -5410,7 +5410,7 @@ void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset
#endif #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) QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
{ {
if (rgn.isEmpty()) if (rgn.isEmpty())
@ -5508,7 +5508,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
beginBackingStorePainting(); beginBackingStorePainting();
#endif #endif
QPainter p(q); QPainter p(q);
paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0); paintBackground(&p, toBePainted, (asRoot || onScreen) ? (flags | DrawAsRoot) : DrawWidgetFlags());
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
endBackingStorePainting(); endBackingStorePainting();
#endif #endif
@ -5691,7 +5691,7 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
} }
// Set backingstore flags. // Set backingstore flags.
int flags = DrawPaintOnScreen | DrawInvisible; DrawWidgetFlags flags = DrawPaintOnScreen | DrawInvisible;
if (renderFlags & QWidget::DrawWindowBackground) if (renderFlags & QWidget::DrawWindowBackground)
flags |= DrawAsRoot; 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, 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) , QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
{ {
QWidget *w = 0; QWidget *w = 0;

View File

@ -266,10 +266,11 @@ static inline bool bypassGraphicsProxyWidget(const QWidget *p)
class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
{ {
Q_DECLARE_PUBLIC(QWidget) Q_DECLARE_PUBLIC(QWidget)
Q_GADGET
public: public:
// *************************** Cross-platform *************************************** // *************************** Cross-platform ***************************************
enum DrawWidgetFlags { enum DrawWidgetFlag {
DrawAsRoot = 0x01, DrawAsRoot = 0x01,
DrawPaintOnScreen = 0x02, DrawPaintOnScreen = 0x02,
DrawRecursive = 0x04, DrawRecursive = 0x04,
@ -279,12 +280,15 @@ public:
DontDrawNativeChildren = 0x40, DontDrawNativeChildren = 0x40,
DontSetCompositionMode = 0x80 DontSetCompositionMode = 0x80
}; };
Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag)
Q_FLAG(DrawWidgetFlags)
enum CloseMode { enum CloseMode {
CloseNoEvent, CloseNoEvent,
CloseWithEvent, CloseWithEvent,
CloseWithSpontaneousEvent CloseWithSpontaneousEvent
}; };
Q_ENUM(CloseMode)
enum Direction { enum Direction {
DirectionNorth = 0x01, DirectionNorth = 0x01,
@ -292,6 +296,7 @@ public:
DirectionSouth = 0x02, DirectionSouth = 0x02,
DirectionWest = 0x20 DirectionWest = 0x20
}; };
Q_ENUM(Direction)
// Functions. // Functions.
explicit QWidgetPrivate(int version = QObjectPrivateVersion); explicit QWidgetPrivate(int version = QObjectPrivateVersion);
@ -376,20 +381,20 @@ public:
void setUpdatesEnabled_helper(bool ); void setUpdatesEnabled_helper(bool );
bool updateBrushOrigin(QPainter *, const QBrush &brush) const; 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; bool isAboutToShow() const;
QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags); QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
QWidget::RenderFlags renderFlags); QWidget::RenderFlags renderFlags);
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
QWidget::RenderFlags renderFlags); 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); QPainter *sharedPainter = nullptr, QWidgetRepaintManager *repaintManager = nullptr);
void sendPaintEvent(const QRegion &toBePainted); void sendPaintEvent(const QRegion &toBePainted);
void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index, 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); QPainter *sharedPainter, QWidgetRepaintManager *repaintManager);
#if QT_CONFIG(graphicsview) #if QT_CONFIG(graphicsview)
@ -873,16 +878,18 @@ public:
bool stealMouseGrab(bool grab); bool stealMouseGrab(bool grab);
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags)
struct QWidgetPaintContext 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) QPainter *p, QWidgetRepaintManager *rpm)
: pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {} : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {}
QPaintDevice *pdev; QPaintDevice *pdev;
QRegion rgn; QRegion rgn;
QPoint offset; QPoint offset;
int flags; QWidgetPrivate::DrawWidgetFlags flags;
QPainter *sharedPainter; QPainter *sharedPainter;
QWidgetRepaintManager *repaintManager; QWidgetRepaintManager *repaintManager;
QPainter *painter; QPainter *painter;

View File

@ -1335,7 +1335,7 @@ void QWidgetRepaintManager::doSync()
QWidget *w = opaqueNonOverlappedWidgets[i]; QWidget *w = opaqueNonOverlappedWidgets[i];
QWidgetPrivate *wd = w->d_func(); QWidgetPrivate *wd = w->d_func();
int flags = QWidgetPrivate::DrawRecursive; QWidgetPrivate::DrawWidgetFlags flags = QWidgetPrivate::DrawRecursive;
// Scrolled and moved widgets must draw all children. // Scrolled and moved widgets must draw all children.
if (!wd->isScrolled && !wd->isMoved) if (!wd->isScrolled && !wd->isMoved)
flags |= QWidgetPrivate::DontDrawOpaqueChildren; flags |= QWidgetPrivate::DontDrawOpaqueChildren;
@ -1353,7 +1353,7 @@ void QWidgetRepaintManager::doSync()
// Paint the rest with composition. // Paint the rest with composition.
if (repaintAllWidgets || !dirtyCopy.isEmpty()) { 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); tlw->d_func()->drawWidget(store->paintDevice(), dirtyCopy, QPoint(), flags, 0, this);
} }