summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp128
1 files changed, 65 insertions, 63 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 2c84ff7161..89a8a7be0f 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -511,10 +511,10 @@ void QWidget::setAutoFillBackground(bool enabled)
Every widget's constructor accepts one or two standard arguments:
\list 1
- \li \c{QWidget *parent = 0} is the parent of the new widget. If it is 0
- (the default), the new widget will be a window. If not, it will be
- a child of \e parent, and be constrained by \e parent's geometry
- (unless you specify Qt::Window as window flag).
+ \li \c{QWidget *parent = \nullptr} is the parent of the new widget.
+ If it is \nullptr (the default), the new widget will be a window.
+ If not, it will be a child of \e parent, and be constrained by
+ \e parent's geometry (unless you specify Qt::Window as window flag).
\li \c{Qt::WindowFlags f = 0} (where available) sets the window flags;
the default is suitable for almost all widgets, but to get, for
example, a window without a window system frame, you must use
@@ -1003,14 +1003,14 @@ struct QWidgetExceptionCleaner
Constructs a widget which is a child of \a parent, with widget
flags set to \a f.
- If \a parent is 0, the new widget becomes a window. If
+ If \a parent is \nullptr, the new widget becomes a window. If
\a parent is another widget, this widget becomes a child window
inside \a parent. The new widget is deleted when its \a parent is
deleted.
The widget flags argument, \a f, is normally 0, but it can be set
- to customize the frame of a window (i.e. \a
- parent must be 0). To customize the frame, use a value composed
+ to customize the frame of a window (i.e. \a parent must be
+ \nullptr). To customize the frame, use a value composed
from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}.
If you add a child widget to an already visible widget you must
@@ -2418,29 +2418,34 @@ static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrus
}
}
-void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const
+bool QWidgetPrivate::updateBrushOrigin(QPainter *painter, const QBrush &brush) const
{
- Q_Q(const QWidget);
-
#if QT_CONFIG(scrollarea)
- bool resetBrushOrigin = false;
- QPointF oldBrushOrigin;
+ Q_Q(const QWidget);
//If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
+ if (brush.style() == Qt::NoBrush || brush.style() == Qt::SolidPattern)
+ return false;
QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent);
if (scrollArea && scrollArea->viewport() == q) {
QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
- oldBrushOrigin = painter->brushOrigin();
- resetBrushOrigin = true;
painter->setBrushOrigin(-priv->contentsOffset());
-
}
#endif // QT_CONFIG(scrollarea)
+ return true;
+}
+
+void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const
+{
+ Q_Q(const QWidget);
+ bool brushOriginSet = false;
const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
const QBrush bg = q->palette().brush(QPalette::Window);
+ if (!brushOriginSet)
+ brushOriginSet = updateBrushOrigin(painter, bg);
if (!(flags & DontSetCompositionMode)) {
//copy alpha straight in
QPainter::CompositionMode oldMode = painter->compositionMode();
@@ -2452,8 +2457,11 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
}
}
- if (q->autoFillBackground())
+ if (q->autoFillBackground()) {
+ if (!brushOriginSet)
+ brushOriginSet = updateBrushOrigin(painter, autoFillBrush);
fillRegion(painter, rgn, autoFillBrush);
+ }
if (q->testAttribute(Qt::WA_StyledBackground)) {
painter->setClipRegion(rgn);
@@ -2461,11 +2469,6 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
opt.initFrom(q);
q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
}
-
-#if QT_CONFIG(scrollarea)
- if (resetBrushOrigin)
- painter->setBrushOrigin(oldBrushOrigin);
-#endif // QT_CONFIG(scrollarea)
}
/*
@@ -2499,12 +2502,12 @@ void QWidgetPrivate::deactivateWidgetCleanup()
The window identifier type depends on the underlying window
system, see \c qwindowdefs.h for the actual definition. If there
- is no widget with this identifier, 0 is returned.
+ is no widget with this identifier, \nullptr is returned.
*/
QWidget *QWidget::find(WId id)
{
- return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0;
+ return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : nullptr;
}
@@ -3281,7 +3284,7 @@ void QWidget::addActions(QList<QAction*> actions)
/*!
Inserts the action \a action to this widget's list of actions,
- before the action \a before. It appends the action if \a before is 0 or
+ before the action \a before. It appends the action if \a before is \nullptr or
\a before is not a valid action for this widget.
A QWidget should only have one of each action.
@@ -3315,7 +3318,7 @@ void QWidget::insertAction(QAction *before, QAction *action)
/*!
Inserts the actions \a actions to this widget's list of actions,
- before the action \a before. It appends the action if \a before is 0 or
+ before the action \a before. It appends the action if \a before is \nullptr or
\a before is not a valid action for this widget.
A QWidget can have at most one of each action.
@@ -4234,7 +4237,7 @@ void QWidget::setFixedHeight(int h)
/*!
Translates the widget coordinate \a pos to the coordinate system
- of \a parent. The \a parent must not be 0 and must be a parent
+ of \a parent. The \a parent must not be \nullptr and must be a parent
of the calling widget.
\sa mapFrom(), mapToParent(), mapToGlobal(), underMouse()
@@ -4259,7 +4262,7 @@ QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const
/*!
Translates the widget coordinate \a pos from the coordinate system
of \a parent to this widget's coordinate system. The \a parent
- must not be 0 and must be a parent of the calling widget.
+ must not be \nullptr and must be a parent of the calling widget.
\sa mapTo(), mapFromParent(), mapFromGlobal(), underMouse()
*/
@@ -4338,7 +4341,8 @@ QWidget *QWidget::window() const
\since 4.4
Returns the native parent for this widget, i.e. the next ancestor widget
- that has a system identifier, or 0 if it does not have any native parent.
+ that has a system identifier, or \nullptr if it does not have any native
+ parent.
\sa effectiveWinId()
*/
@@ -4959,9 +4963,9 @@ void QWidget::unsetLayoutDirection()
Some underlying window implementations will reset the cursor if it
leaves a widget even if the mouse is grabbed. If you want to have
a cursor set for all widgets, even when outside the window, consider
- QApplication::setOverrideCursor().
+ QGuiApplication::setOverrideCursor().
- \sa QApplication::setOverrideCursor()
+ \sa QGuiApplication::setOverrideCursor()
*/
#ifndef QT_NO_CURSOR
@@ -5274,7 +5278,7 @@ QPixmap QWidget::grab(const QRect &rectangle)
\brief The graphicsEffect function returns a pointer to the
widget's graphics effect.
- If the widget has no graphics effect, 0 is returned.
+ If the widget has no graphics effect, \nullptr is returned.
\since 4.6
@@ -5318,7 +5322,7 @@ void QWidget::setGraphicsEffect(QGraphicsEffect *effect)
return;
if (d->graphicsEffect) {
- d->invalidateBuffer(rect());
+ d->invalidateBackingStore(rect());
delete d->graphicsEffect;
d->graphicsEffect = 0;
}
@@ -5738,12 +5742,10 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
QPoint offset = targetOffset;
offset -= paintRegion.boundingRect().topLeft();
QPoint redirectionOffset;
- QPaintDevice *redirected = 0;
+ QPaintDevice *redirected = nullptr;
if (target->devType() == QInternal::Widget)
redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
- if (!redirected)
- redirected = QPainter::redirected(target, &redirectionOffset);
if (redirected) {
target = redirected;
@@ -5920,10 +5922,10 @@ QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *
Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this
widget and its ancestors. The search starts at \a origin (inclusive).
- If successful, the function returns the proxy that embeds the widget, or 0 if no embedded
- widget was found.
+ If successful, the function returns the proxy that embeds the widget, or \nullptr if no
+ embedded widget was found.
*/
-QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
+QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
{
if (origin) {
QWExtra *extra = origin->d_func()->extra;
@@ -5931,7 +5933,7 @@ QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget
return extra->proxyWidget;
return nearestGraphicsProxyWidget(origin->parentWidget());
}
- return 0;
+ return nullptr;
}
#endif
@@ -6403,7 +6405,7 @@ void QWidget::setWindowRole(const QString &role)
/*!
- Sets the widget's focus proxy to widget \a w. If \a w is 0, the
+ Sets the widget's focus proxy to widget \a w. If \a w is \nullptr, the
function resets this widget to have no focus proxy.
Some widgets can "have focus", but create a child widget, such as
@@ -6436,15 +6438,15 @@ void QWidget::setFocusProxy(QWidget * w)
/*!
- Returns the focus proxy, or 0 if there is no focus proxy.
+ Returns the focus proxy, or \nullptr if there is no focus proxy.
\sa setFocusProxy()
*/
-QWidget * QWidget::focusProxy() const
+QWidget *QWidget::focusProxy() const
{
Q_D(const QWidget);
- return d->extra ? (QWidget *)d->extra->focus_proxy : 0;
+ return d->extra ? (QWidget *)d->extra->focus_proxy : nullptr;
}
@@ -7343,11 +7345,11 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
if (renderToTexture) {
QRegion updateRegion(q->geometry());
updateRegion += QRect(oldPos, olds);
- q->parentWidget()->d_func()->invalidateBuffer(updateRegion);
+ q->parentWidget()->d_func()->invalidateBackingStore(updateRegion);
} else if (isMove && !isResize) {
moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
} else {
- invalidateBuffer_resizeHelper(oldPos, olds);
+ invalidateBackingStore_resizeHelper(oldPos, olds);
}
}
}
@@ -8109,7 +8111,7 @@ void QWidgetPrivate::show_sys()
QWidgetWindow *window = windowHandle();
if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
q->setAttribute(Qt::WA_Mapped);
// add our window the modal window list (native dialogs)
if (window && q->isWindow()
@@ -8152,7 +8154,7 @@ void QWidgetPrivate::show_sys()
#ifndef QT_NO_CURSOR
qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show
#endif
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
window->setNativeWindowVisibility(true);
// Was the window moved by the Window system or QPlatformWindow::initialGeometry() ?
if (window->isTopLevel()) {
@@ -8266,12 +8268,12 @@ void QWidgetPrivate::hide_sys()
QWidget *p = q->parentWidget();
if (p &&p->isVisible()) {
if (renderToTexture)
- p->d_func()->invalidateBuffer(q->geometry());
+ p->d_func()->invalidateBackingStore(q->geometry());
else
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
}
} else {
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
}
if (window)
@@ -8825,7 +8827,7 @@ QSize QWidget::minimumSizeHint() const
/*!
\fn QWidget *QWidget::parentWidget() const
- Returns the parent of this widget, or 0 if it does not have any
+ Returns the parent of this widget, or \nullptr if it does not have any
parent widget.
*/
@@ -10235,7 +10237,7 @@ QRegion QWidget::mask() const
}
/*!
- Returns the layout manager that is installed on this widget, or 0
+ Returns the layout manager that is installed on this widget, or \nullptr
if no layout manager is installed.
The layout manager sets the geometry of the widget's children
@@ -11907,7 +11909,7 @@ void QWidget::raise()
QRegion region(rect());
d->subtractOpaqueSiblings(region);
- d->invalidateBuffer(region);
+ d->invalidateBackingStore(region);
}
if (testAttribute(Qt::WA_WState_Created))
d->raise_sys();
@@ -11927,7 +11929,7 @@ void QWidgetPrivate::raise_sys()
} else if (renderToTexture) {
if (QWidget *p = q->parentWidget()) {
setDirtyOpaqueRegion();
- p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
+ p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
}
}
}
@@ -11977,7 +11979,7 @@ void QWidgetPrivate::lower_sys()
q->windowHandle()->lower();
} else if (QWidget *p = q->parentWidget()) {
setDirtyOpaqueRegion();
- p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
+ p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
}
}
@@ -12021,7 +12023,7 @@ void QWidgetPrivate::stackUnder_sys(QWidget*)
Q_Q(QWidget);
if (QWidget *p = q->parentWidget()) {
setDirtyOpaqueRegion();
- p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
+ p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
}
}
@@ -12123,14 +12125,14 @@ bool QWidgetPrivate::navigateToDirection(Direction direction)
Searches for a widget that is positioned in the \a direction, starting
from the current focusWidget.
- Returns the pointer to a found widget or 0, if there was no widget in
- that direction.
+ Returns the pointer to a found widget or \nullptr, if there was no widget
+ in that direction.
*/
QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
{
const QWidget *sourceWidget = QApplication::focusWidget();
if (!sourceWidget)
- return 0;
+ return nullptr;
const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
const int sourceX =
(direction == DirectionNorth || direction == DirectionSouth) ?
@@ -12144,7 +12146,7 @@ QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
const QPoint sourceCenter = sourceRect.center();
const QWidget *sourceWindow = sourceWidget->window();
- QWidget *targetWidget = 0;
+ QWidget *targetWidget = nullptr;
int shortestDistance = INT_MAX;
const auto targetCandidates = QApplication::allWidgets();
@@ -12463,7 +12465,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
d->aboutToDestroy();
if (!isWindow() && parentWidget())
- parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
+ parentWidget()->d_func()->invalidateBackingStore(d->effectiveRectFor(geometry()));
d->deactivateWidgetCleanup();
if ((windowType() == Qt::Popup) && qApp)
@@ -12811,7 +12813,7 @@ void QWidget::releaseKeyboard()
Returns the widget that is currently grabbing the mouse input.
If no widget in this application is currently grabbing the mouse,
- 0 is returned.
+ \nullptr is returned.
\sa grabMouse(), keyboardGrabber()
*/
@@ -12828,7 +12830,7 @@ QWidget *QWidget::mouseGrabber()
Returns the widget that is currently grabbing the keyboard input.
If no widget in this application is currently grabbing the
- keyboard, 0 is returned.
+ keyboard, \nullptr is returned.
\sa grabMouse(), mouseGrabber()
*/