Fix the ignored Qt::WA_StaticContents on Windows

This restores the ability from the Qt 4.x series to honor the static
contents region in the backbuffer when resizing a widget. The fix
only applies when running under Windows.

Task-number: QTBUG-34799

[ChangeLog][QtWidgets][Windows] Update QWidgetBackingStore and QWindowsBackingStore to support Qt::WA_StaticContents
QWidgetBackingStore::staticContents() was updated for windows to *not* unconditionally return false. It now
returns true if it has a non-empty static widgets list. QWindowsBackingStore::resize(...) was updated to honor
the provided static contents region. It now copies the static region into the new backbuffer in a manner similar
to what was done in Qt4. The difference is that this version accounts for the possibility of the new buffer having
a smaller region than the old buffer. In Qt4 the ::prepareBuffer method was only called when the buffer was resized
larger.

Change-Id: I135ff8fb16f52759089f1e7353426303c4504db3
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
Chris Colbert 2013-11-18 21:49:21 -05:00 committed by The Qt Project
parent 7b6253efbf
commit ab76593f18
2 changed files with 24 additions and 2 deletions

View File

@ -149,7 +149,23 @@ void QWindowsBackingStore::resize(const QSize &size, const QRegion &region)
QImage::Format format = QWindowsNativeImage::systemFormat();
if (format == QImage::Format_RGB32 && rasterWindow()->window()->format().hasAlpha())
format = QImage::Format_ARGB32_Premultiplied;
m_image.reset(new QWindowsNativeImage(size.width(), size.height(), format));
QWindowsNativeImage *oldwni = m_image.data();
QWindowsNativeImage *newwni = new QWindowsNativeImage(size.width(), size.height(), format);
if (oldwni && !region.isEmpty()) {
const QImage &oldimg(oldwni->image());
QImage &newimg(newwni->image());
QRegion staticRegion(region);
staticRegion &= QRect(0, 0, oldimg.width(), oldimg.height());
staticRegion &= QRect(0, 0, newimg.width(), newimg.height());
QPainter painter(&newimg);
painter.setCompositionMode(QPainter::CompositionMode_Source);
foreach (const QRect &rect, staticRegion.rects())
painter.drawImage(rect, oldimg, rect);
}
m_image.reset(newwni);
}
}

View File

@ -240,7 +240,13 @@ private:
}
inline bool hasStaticContents() const
{ return !staticWidgets.isEmpty() && false; }
{
#if defined(Q_OS_WIN)
return !staticWidgets.isEmpty();
#else
return !staticWidgets.isEmpty() && false;
#endif
}
friend QRegion qt_dirtyRegion(QWidget *);
friend class QWidgetPrivate;