tdf#120777 KDE5: Dialogs get blank when they are resized

On window resize qt5 only redraws changed parts of widgets.
If resize is minor (i.e. height has increased by 1 pixel, for example),
qt5 may consider most parts of widget not changed and skip redrawing them
and redraw only certain widget elements.

But if cairo is used for drawing, on resize previously drawed image of widget
is discarded and new one of different size is created.
New image is empty, but qt5 doesn't issue redraw for whole widget.
To mitigate this issue, data from old image of widget should be copied over
to image of new widget, qt5 will redraw it partially or fully if necessary.

Change-Id: Id950074efece9072bbfc002dfcb6ead813d5aeff
Reviewed-on: https://gerrit.libreoffice.org/62698
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: Jenkins
diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx
index 1b24f2f..89fe682 100644
--- a/vcl/inc/headless/svpgdi.hxx
+++ b/vcl/inc/headless/svpgdi.hxx
@@ -119,11 +119,12 @@
        double fMiterMinimumAngle,
        bool bPixelSnapHairline);

private:
    void invert(const basegfx::B2DPolygon &rPoly, SalInvert nFlags);
    void copySource(const SalTwoRect& rTR, cairo_surface_t* source);
    void copyWithOperator(const SalTwoRect& rTR, cairo_surface_t* source,
                          cairo_operator_t eOp = CAIRO_OPERATOR_SOURCE);

private:
    void invert(const basegfx::B2DPolygon &rPoly, SalInvert nFlags);
    void applyColor(cairo_t *cr, Color rColor);

protected:
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index a47aaca..1055ccd 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -24,12 +24,14 @@
#include <Qt5Graphics.hxx>
#include <Qt5Tools.hxx>

#include <QtCore/QtGlobal>
#include <QtGui/QFocusEvent>
#include <QtGui/QImage>
#include <QtGui/QKeyEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>
#include <QtGui/QResizeEvent>
#include <QtGui/QShowEvent>
#include <QtGui/QWheelEvent>
#include <QtWidgets/QtWidgets>
@@ -57,7 +59,7 @@
        p.drawImage(pEvent->rect().topLeft(), *m_pFrame->m_pQImage, pEvent->rect());
}

void Qt5Widget::resizeEvent(QResizeEvent* /*event*/)
void Qt5Widget::resizeEvent(QResizeEvent* pEvent)
{
    if (m_pFrame->m_bUseCairo)
    {
@@ -71,7 +73,15 @@
            cairo_surface_set_user_data(pSurface, SvpSalGraphics::getDamageKey(),
                                        &m_pFrame->m_aDamageHandler, nullptr);
            m_pFrame->m_pSvpGraphics->setSurface(pSurface, basegfx::B2IVector(width, height));
            UniqueCairoSurface old_surface(m_pFrame->m_pSurface.release());
            m_pFrame->m_pSurface.reset(pSurface);

            int min_width = qMin(pEvent->oldSize().width(), pEvent->size().width());
            int min_height = qMin(pEvent->oldSize().height(), pEvent->size().height());

            SalTwoRect rect(0, 0, min_width, min_height, 0, 0, min_width, min_height);

            m_pFrame->m_pSvpGraphics->copySource(rect, old_surface.get());
        }
    }
    else