Windows/Vista style: Fix painting of QGroupBox.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Thu, 26 Apr 2012 13:38:17 +0000 (15:38 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 27 Apr 2012 08:37:02 +0000 (10:37 +0200)
QGroupBox in Vista style does not show a frame, currently.

drawBackgroundDirectly should also be called if the paintDevice
is a backing store.

Task-number: QTBUG-25395
Change-Id: Ifa20802dea6c182904f68271ddd0d175007e4b0e
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/widgets/styles/qwindowsxpstyle.cpp

index 288863c..f9b7939 100644 (file)
@@ -53,6 +53,7 @@
 #include <qpainter.h>
 #include <qpaintengine.h>
 #include <qwidget.h>
+#include <qbackingstore.>
 #include <qapplication.h>
 #include <qpixmapcache.h>
 
@@ -708,24 +709,36 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData)
 
     bool complexXForm = painter->deviceTransform().type() > QTransform::TxTranslate;
 
+    // Access paintDevice via engine since the painter may
+    // return the clip device which can still be a widget device in case of grabWidget().
+
     bool translucentToplevel = false;
-    QPaintDevice *pdev = painter->device();
-    if (pdev->devType() == QInternal::Widget) {
-        QWidget *win = ((QWidget *) pdev)->window();
-        translucentToplevel = win->testAttribute(Qt::WA_TranslucentBackground);
+    const QPaintDevice *paintDevice = painter->device();
+    if (paintDevice->devType() == QInternal::Widget) {
+        const QWidget *window = static_cast<const QWidget *>(paintDevice)->window();
+        translucentToplevel = window->testAttribute(Qt::WA_TranslucentBackground);
     }
 
-    // Draw on backing store DC only for real widgets.
-    // Access paintDevice via engine since the painter may
-    // return the clip device which can still be a widget device in case of grabWidget().
-    const bool useFallback = !themeData.widget
-        || painter->paintEngine()->paintDevice()->devType() != QInternal::Widget
-        || painter->opacity() != 1.0 || themeData.rotate
-        || complexXForm  || themeData.mirrorVertically
-        || (themeData.mirrorHorizontally && pDrawThemeBackgroundEx == 0)
-        || translucentToplevel;
-    const HDC dc = useFallback ? HDC(0) : hdcForWidgetBackingStore(themeData.widget);
-    if (dc && !useFallback) {
+    bool canDrawDirectly = false;
+    if (themeData.widget && painter->opacity() == 1.0 && !themeData.rotate
+        && !complexXForm && !themeData.mirrorVertically
+        && (!themeData.mirrorHorizontally || pDrawThemeBackgroundEx)
+        && !translucentToplevel) {
+        // Draw on backing store DC only for real widgets or backing store images.
+        const QPaintDevice *enginePaintDevice = painter->paintEngine()->paintDevice();
+        switch (enginePaintDevice->devType()) {
+        case QInternal::Widget:
+            canDrawDirectly = true;
+            break;
+        case QInternal::Image:
+            if (QBackingStore *bs = backingStoreForWidget(themeData.widget))
+                if (bs->paintDevice() == enginePaintDevice)
+                    canDrawDirectly = true;
+        }
+    }
+
+    const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : HDC(0);
+    if (dc) {
         drawBackgroundDirectly(themeData);
     } else {
         drawBackgroundThruNativeBuffer(themeData);
@@ -1961,7 +1974,7 @@ case PE_Frame:
         break;
     }
 
-    XPThemeData theme(0, p, themeNumber, partId, stateId, rect);
+    XPThemeData theme(widget, p, themeNumber, partId, stateId, rect);
     if (!theme.isValid()) {
         QWindowsStyle::drawPrimitive(pe, option, p, widget);
         return;