From 3bd1313a365e6e13c4aab209ef596c843b724f31 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 5 Feb 2022 22:07:51 +0200 Subject: [PATCH] drop support for painting widgets outside paint events [ci reset] Signed-off-by: Ivailo Monev --- src/core/global/qnamespace.h | 143 ++++++++++++++--------------- src/core/global/qnamespace.qdoc | 4 - src/gui/kernel/qwidget.cpp | 2 +- src/gui/painting/qbackingstore.cpp | 2 +- src/gui/painting/qpaintengine.cpp | 2 - src/gui/painting/qpaintengine.h | 1 - src/gui/painting/qpainter.cpp | 21 +---- 7 files changed, 76 insertions(+), 99 deletions(-) diff --git a/src/core/global/qnamespace.h b/src/core/global/qnamespace.h index 754d90d78..eee3e7b03 100644 --- a/src/core/global/qnamespace.h +++ b/src/core/global/qnamespace.h @@ -756,82 +756,81 @@ public: WA_NoSystemBackground = 6, WA_UpdatesDisabled = 7, WA_Mapped = 8, - WA_PaintOutsidePaintEvent = 9, - WA_ForceDisabled = 10, - WA_PendingMoveEvent = 11, - WA_PendingResizeEvent = 12, - WA_SetPalette = 13, - WA_SetFont = 14, - WA_SetCursor = 15, - WA_NoChildEventsFromChildren = 16, - WA_WindowModified = 17, - WA_Resized = 18, - WA_Moved = 19, - WA_CustomWhatsThis = 20, - WA_LayoutOnEntireRect = 21, - WA_OutsideWSRange = 22, - WA_TransparentForMouseEvents = 23, - WA_PaintUnclipped = 24, - WA_NoMouseReplay = 25, - WA_DeleteOnClose = 26, - WA_RightToLeft = 27, - WA_NoChildEventsForParent = 28, - WA_ShowModal = 29, // ## deprecated - WA_MouseNoMask = 30, - WA_GroupLeader = 31, // ## deprecated - WA_NoMousePropagation = 32, // ## for now, might go away. - WA_Hover = 33, - WA_QuitOnClose = 34, - WA_KeyboardFocusChange = 35, - WA_AcceptDrops = 36, - WA_WindowPropagation = 37, - WA_AlwaysShowToolTips = 38, - WA_SetStyle = 39, - WA_SetLocale = 40, - WA_LayoutUsesWidgetRect = 41, - WA_ShowWithoutActivating = 42, - WA_NativeWindow = 43, - WA_DontCreateNativeAncestors = 44, - WA_TranslucentBackground = 45, - WA_X11DoNotAcceptFocus = 46, - WA_X11BypassTransientForHint = 47, + WA_ForceDisabled = 9, + WA_PendingMoveEvent = 10, + WA_PendingResizeEvent = 11, + WA_SetPalette = 12, + WA_SetFont = 13, + WA_SetCursor = 14, + WA_NoChildEventsFromChildren = 15, + WA_WindowModified = 16, + WA_Resized = 17, + WA_Moved = 18, + WA_CustomWhatsThis = 19, + WA_LayoutOnEntireRect = 20, + WA_OutsideWSRange = 21, + WA_TransparentForMouseEvents = 22, + WA_PaintUnclipped = 23, + WA_NoMouseReplay = 24, + WA_DeleteOnClose = 25, + WA_RightToLeft = 26, + WA_NoChildEventsForParent = 27, + WA_ShowModal = 28, // ## deprecated + WA_MouseNoMask = 29, + WA_GroupLeader = 30, // ## deprecated + WA_NoMousePropagation = 31, // ## for now, might go away. + WA_Hover = 32, + WA_QuitOnClose = 33, + WA_KeyboardFocusChange = 34, + WA_AcceptDrops = 35, + WA_WindowPropagation = 36, + WA_AlwaysShowToolTips = 37, + WA_SetStyle = 38, + WA_SetLocale = 39, + WA_LayoutUsesWidgetRect = 40, + WA_ShowWithoutActivating = 41, + WA_NativeWindow = 42, + WA_DontCreateNativeAncestors = 43, + WA_TranslucentBackground = 44, + WA_X11DoNotAcceptFocus = 45, + WA_X11BypassTransientForHint = 46, // window types from http://standards.freedesktop.org/wm-spec/ - WA_X11NetWmWindowTypeDesktop = 48, - WA_X11NetWmWindowTypeDock = 49, - WA_X11NetWmWindowTypeToolBar = 50, - WA_X11NetWmWindowTypeMenu = 51, - WA_X11NetWmWindowTypeUtility = 52, - WA_X11NetWmWindowTypeSplash = 53, - WA_X11NetWmWindowTypeDialog = 54, - WA_X11NetWmWindowTypeDropDownMenu = 55, - WA_X11NetWmWindowTypePopupMenu = 56, - WA_X11NetWmWindowTypeToolTip = 57, - WA_X11NetWmWindowTypeNotification = 58, - WA_X11NetWmWindowTypeCombo = 59, - WA_X11NetWmWindowTypeDND = 60, + WA_X11NetWmWindowTypeDesktop = 47, + WA_X11NetWmWindowTypeDock = 48, + WA_X11NetWmWindowTypeToolBar = 49, + WA_X11NetWmWindowTypeMenu = 50, + WA_X11NetWmWindowTypeUtility = 51, + WA_X11NetWmWindowTypeSplash = 52, + WA_X11NetWmWindowTypeDialog = 53, + WA_X11NetWmWindowTypeDropDownMenu = 54, + WA_X11NetWmWindowTypePopupMenu = 55, + WA_X11NetWmWindowTypeToolTip = 56, + WA_X11NetWmWindowTypeNotification = 57, + WA_X11NetWmWindowTypeCombo = 58, + WA_X11NetWmWindowTypeDND = 59, // internal - WA_LaidOut = 61, - WA_GrabbedShortcut = 62, - WA_DontShowOnScreen = 63, - WA_ForceUpdatesDisabled = 64, - WA_StyledBackground = 65, - WA_StyleSheet = 66, - WA_DropSiteRegistered = 67, - WA_WState_Visible = 68, - WA_WState_Hidden = 69, - WA_WState_Created = 70, - WA_WState_InPaintEvent = 71, - WA_WState_Reparented = 72, - WA_WState_Polished = 73, - WA_WState_OwnSizePolicy = 74, - WA_WState_ExplicitShowHide = 75, - WA_WState_ConfigPending = 76, - WA_SetWindowIcon = 77, - WA_SetLayoutDirection = 78, - WA_SetWindowModality = 79, - WA_NoX11EventCompression = 80, + WA_LaidOut = 60, + WA_GrabbedShortcut = 61, + WA_DontShowOnScreen = 62, + WA_ForceUpdatesDisabled = 63, + WA_StyledBackground = 64, + WA_StyleSheet = 65, + WA_DropSiteRegistered = 66, + WA_WState_Visible = 67, + WA_WState_Hidden = 68, + WA_WState_Created = 69, + WA_WState_InPaintEvent = 70, + WA_WState_Reparented = 71, + WA_WState_Polished = 72, + WA_WState_OwnSizePolicy = 73, + WA_WState_ExplicitShowHide = 74, + WA_WState_ConfigPending = 75, + WA_SetWindowIcon = 76, + WA_SetLayoutDirection = 77, + WA_SetWindowModality = 78, + WA_NoX11EventCompression = 79, // Add new attributes before this line WA_AttributeCount diff --git a/src/core/global/qnamespace.qdoc b/src/core/global/qnamespace.qdoc index 94771c8af..bd2e3bec9 100644 --- a/src/core/global/qnamespace.qdoc +++ b/src/core/global/qnamespace.qdoc @@ -781,10 +781,6 @@ require native painting primitives, you need to reimplement QWidget::paintEngine() to return 0 and set this flag. - \value WA_PaintOutsidePaintEvent Makes it possible to use QPainter to - paint on the widget outside \l{QWidget::paintEvent()}{paintEvent()}. - We recommend that you use it only when porting Qt 3 code to Qt 4. - \value WA_PaintUnclipped Makes all painters operating on this widget unclipped. Children of this widget or other widgets in front of it do not clip the area the painter can paint on. This flag is only supported for diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 03d658e5e..c936f4dd1 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4639,7 +4639,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP paintEngine->d_func()->systemClip = QRegion(); } q->setAttribute(Qt::WA_WState_InPaintEvent, false); - if (Q_UNLIKELY(q->paintingActive() && !q->testAttribute(Qt::WA_PaintOutsidePaintEvent))) + if (Q_UNLIKELY(q->paintingActive())) qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); #ifndef QT_NO_DEBUG diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index f31de318d..58616eeec 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -1146,7 +1146,7 @@ void QWidgetPrivate::repaint_sys(const QRegion &rgn) QWidgetBackingStore::unflushPaint(q, toBePainted); #endif - if (!q->testAttribute(Qt::WA_PaintOutsidePaintEvent) && q->paintingActive()) + if (Q_UNLIKELY(q->paintingActive())) qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); } diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index cd2178916..74d173b0a 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -168,8 +168,6 @@ QFont QTextItem::font() const \value ConstantOpacity The engine supports the feature provided by QPainter::setOpacity(). \value PainterPaths The engine has path support. - \value PaintOutsidePaintEvent The engine is capable of painting outside of - paint events. \value PatternTransform The engine has support for transforming brush patterns. \value PerspectiveTransform The engine has support for performing perspective diff --git a/src/gui/painting/qpaintengine.h b/src/gui/painting/qpaintengine.h index 8fa41b230..7053df95c 100644 --- a/src/gui/painting/qpaintengine.h +++ b/src/gui/painting/qpaintengine.h @@ -72,7 +72,6 @@ public: ConstantOpacity = 0x00000040, // Can render at constant opacity PerspectiveTransform = 0x00000080, // Can do perspective transformations BlendModes = 0x00000100, // Can do extended Porter&Duff composition - PaintOutsidePaintEvent = 0x00000200, // Engine is capable of painting outside paint events AllFeatures = 0xffffffff // For convenience }; diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 62c4966f9..fd60b0405 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -144,10 +144,7 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev) return false; // Check if we're attempting to paint outside a paint event. - if (Q_UNLIKELY(!sp->d_ptr->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent) - && !widget->testAttribute(Qt::WA_PaintOutsidePaintEvent) - && !widget->testAttribute(Qt::WA_WState_InPaintEvent))) { - + if (Q_UNLIKELY(!widget->testAttribute(Qt::WA_WState_InPaintEvent))) { qWarning("QPainter::begin: Widget painting can only begin as a result of a paintEvent"); return false; } @@ -591,10 +588,7 @@ void QPainterPrivate::updateState(QPainterState *newState) \warning When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by - paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent - widget attribute is set. On Mac OS X and Windows, you can only - paint in a paintEvent() function regardless of this attribute's - setting. + paintEvent(). \tableofcontents @@ -1359,22 +1353,13 @@ bool QPainter::begin(QPaintDevice *pd) const QWidget *widget = static_cast(pd); Q_ASSERT(widget); - const bool paintOutsidePaintEvent = widget->testAttribute(Qt::WA_PaintOutsidePaintEvent); const bool inPaintEvent = widget->testAttribute(Qt::WA_WState_InPaintEvent); - if(Q_UNLIKELY(!d->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent) - && !paintOutsidePaintEvent && !inPaintEvent)) { + if(Q_UNLIKELY(!inPaintEvent)) { qWarning("QPainter::begin: Widget painting can only begin as a " "result of a paintEvent"); qt_cleanup_painter_state(d); return false; } - - // Adjust offset for alien widgets painting outside the paint event. - if (!inPaintEvent && paintOutsidePaintEvent && !widget->internalWinId() - && widget->testAttribute(Qt::WA_WState_Created)) { - const QPoint offset = widget->mapTo(widget->nativeParentWidget(), QPoint()); - d->state->redirectionMatrix.translate(offset.x(), offset.y()); - } break; } case QInternal::Pixmap: