vcl/inc/qt5/QtFrame.hxx  |    3 +
 vcl/qt5/QtFrame.cxx      |   76 +++++++++++++++++++++++++++++++++++++++++++++++
 vcl/qt5/QtMainWindow.cxx |    7 ----
 vcl/qt5/QtWidget.cxx     |   72 +-------------------------------------------
 4 files changed, 83 insertions(+), 75 deletions(-)

New commits:
commit 7511fd100d0b4e4b10f3e0a986a4cb1db7a1637c
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Sep 25 15:36:49 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Sep 26 07:11:07 2024 +0200

    tdf#160837 qt: Move logic for QPaintEvent handling to QtFrame
    
    Add a new QtFrame::handlePaintEvent and move the
    logic from QtWidget::paintEvent to the new method
    and call the new method in QtWidget instead.
    
    This decouples QtFrame and (its friend class) QtWidget
    a bit more.
    
    Change-Id: I974a55d8f967dd85c3dd98e2ac8e28fa53c38c77
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173953
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx
index 12c63349e518..044a4a68b7a3 100644
--- a/vcl/inc/qt5/QtFrame.hxx
+++ b/vcl/inc/qt5/QtFrame.hxx
@@ -170,6 +170,7 @@ public:
     void handleDragMove(QDragMoveEvent* pEvent);
     void handleDrop(QDropEvent* pEvent);
     void handleMoveEvent(QMoveEvent* pEvent);
+    void handlePaintEvent(QPaintEvent* pEvent, QWidget* pWidget);
     void handleResizeEvent(QResizeEvent* pEvent);
 
     virtual void SetExtendedFrameStyle(SalExtStyle nExtStyle) override;
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index a5f355c62f48..2e2bd9dd59ec 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -1582,6 +1582,31 @@ void QtFrame::handleMoveEvent(QMoveEvent* pEvent)
     CallCallback(SalEvent::Move, nullptr);
 }
 
+void QtFrame::handlePaintEvent(QPaintEvent* pEvent, QWidget* pWidget)
+{
+    QPainter p(pWidget);
+    if (!m_bNullRegion)
+        p.setClipRegion(m_aRegion);
+
+    QImage aImage;
+    if (m_bUseCairo)
+    {
+        cairo_surface_t* pSurface = m_pSurface.get();
+        cairo_surface_flush(pSurface);
+
+        aImage = QImage(cairo_image_surface_get_data(pSurface),
+                        cairo_image_surface_get_width(pSurface),
+                        cairo_image_surface_get_height(pSurface), 
Qt_DefaultFormat32);
+    }
+    else
+        aImage = *m_pQImage;
+
+    const qreal fRatio = devicePixelRatioF();
+    aImage.setDevicePixelRatio(fRatio);
+    QRectF source(pEvent->rect().topLeft() * fRatio, pEvent->rect().size() * 
fRatio);
+    p.drawImage(pEvent->rect(), aImage, source);
+}
+
 void QtFrame::handleResizeEvent(QResizeEvent* pEvent)
 {
     const qreal fRatio = devicePixelRatioF();
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index acaa1d3fee7e..5bd44267c860 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -62,30 +62,7 @@
 
 using namespace com::sun::star;
 
-void QtWidget::paintEvent(QPaintEvent* pEvent)
-{
-    QPainter p(this);
-    if (!m_rFrame.m_bNullRegion)
-        p.setClipRegion(m_rFrame.m_aRegion);
-
-    QImage aImage;
-    if (m_rFrame.m_bUseCairo)
-    {
-        cairo_surface_t* pSurface = m_rFrame.m_pSurface.get();
-        cairo_surface_flush(pSurface);
-
-        aImage = QImage(cairo_image_surface_get_data(pSurface),
-                        cairo_image_surface_get_width(pSurface),
-                        cairo_image_surface_get_height(pSurface), 
Qt_DefaultFormat32);
-    }
-    else
-        aImage = *m_rFrame.m_pQImage;
-
-    const qreal fRatio = m_rFrame.devicePixelRatioF();
-    aImage.setDevicePixelRatio(fRatio);
-    QRectF source(pEvent->rect().topLeft() * fRatio, pEvent->rect().size() * 
fRatio);
-    p.drawImage(pEvent->rect(), aImage, source);
-}
+void QtWidget::paintEvent(QPaintEvent* pEvent) { 
m_rFrame.handlePaintEvent(pEvent, this); }
 
 void QtWidget::resizeEvent(QResizeEvent* pEvent) { 
m_rFrame.handleResizeEvent(pEvent); }
 
commit f5a20c68b3ed72bdb81bf8a6533f793520bd72c7
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Sep 25 15:20:37 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Sep 26 07:10:59 2024 +0200

    tdf#160837 qt: Move logic for resize event handling to QtFrame
    
    Add a new QtFrame::handleResizeEvent and move the
    logic from QtWidget::resizeEvent to the new method
    and call the new method from QtWidget::resizeEvent.
    
    This decouples QtFrame and (its friend class) QtWidget
    a bit more, and also prevents direct access to the
    (currently public) SalFrame::maGeometry member from
    QtWidget.
    
    Change-Id: I8969687c64b87677836b436b7815298a8e8d5cf3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173952
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx
index 3675df555384..12c63349e518 100644
--- a/vcl/inc/qt5/QtFrame.hxx
+++ b/vcl/inc/qt5/QtFrame.hxx
@@ -170,6 +170,7 @@ public:
     void handleDragMove(QDragMoveEvent* pEvent);
     void handleDrop(QDropEvent* pEvent);
     void handleMoveEvent(QMoveEvent* pEvent);
+    void handleResizeEvent(QResizeEvent* pEvent);
 
     virtual void SetExtendedFrameStyle(SalExtStyle nExtStyle) override;
     virtual void Show(bool bVisible, bool bNoActivate = false) override;
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 7420278b2b88..a5f355c62f48 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -1582,4 +1582,48 @@ void QtFrame::handleMoveEvent(QMoveEvent* pEvent)
     CallCallback(SalEvent::Move, nullptr);
 }
 
+void QtFrame::handleResizeEvent(QResizeEvent* pEvent)
+{
+    const qreal fRatio = devicePixelRatioF();
+    const int nWidth = ceil(pEvent->size().width() * fRatio);
+    const int nHeight = ceil(pEvent->size().height() * fRatio);
+
+    maGeometry.setSize({ nWidth, nHeight });
+
+    if (m_bUseCairo)
+    {
+        if (m_pSurface)
+        {
+            const int nOldWidth = 
cairo_image_surface_get_width(m_pSurface.get());
+            const int nOldHeight = 
cairo_image_surface_get_height(m_pSurface.get());
+            if (nOldWidth != nWidth || nOldHeight != nHeight)
+            {
+                cairo_surface_t* pSurface
+                    = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, 
nHeight);
+                cairo_surface_set_user_data(pSurface, 
SvpSalGraphics::getDamageKey(),
+                                            &m_aDamageHandler, nullptr);
+                m_pSvpGraphics->setSurface(pSurface, 
basegfx::B2IVector(nWidth, nHeight));
+                UniqueCairoSurface old_surface(m_pSurface.release());
+                m_pSurface.reset(pSurface);
+
+                const int nMinWidth = qMin(nOldWidth, nWidth);
+                const int nMinHeight = qMin(nOldHeight, nHeight);
+                SalTwoRect rect(0, 0, nMinWidth, nMinHeight, 0, 0, nMinWidth, 
nMinHeight);
+                m_pSvpGraphics->copySource(rect, old_surface.get());
+            }
+        }
+    }
+    else
+    {
+        if (m_pQImage && m_pQImage->size() != QSize(nWidth, nHeight))
+        {
+            QImage* pImage = new QImage(m_pQImage->copy(0, 0, nWidth, 
nHeight));
+            m_pQtGraphics->ChangeQImage(pImage);
+            m_pQImage.reset(pImage);
+        }
+    }
+
+    CallCallback(SalEvent::Resize, nullptr);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 4989a17546d5..acaa1d3fee7e 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -87,49 +87,7 @@ void QtWidget::paintEvent(QPaintEvent* pEvent)
     p.drawImage(pEvent->rect(), aImage, source);
 }
 
-void QtWidget::resizeEvent(QResizeEvent* pEvent)
-{
-    const qreal fRatio = m_rFrame.devicePixelRatioF();
-    const int nWidth = ceil(pEvent->size().width() * fRatio);
-    const int nHeight = ceil(pEvent->size().height() * fRatio);
-
-    m_rFrame.maGeometry.setSize({ nWidth, nHeight });
-
-    if (m_rFrame.m_bUseCairo)
-    {
-        if (m_rFrame.m_pSurface)
-        {
-            const int nOldWidth = 
cairo_image_surface_get_width(m_rFrame.m_pSurface.get());
-            const int nOldHeight = 
cairo_image_surface_get_height(m_rFrame.m_pSurface.get());
-            if (nOldWidth != nWidth || nOldHeight != nHeight)
-            {
-                cairo_surface_t* pSurface
-                    = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, 
nHeight);
-                cairo_surface_set_user_data(pSurface, 
SvpSalGraphics::getDamageKey(),
-                                            &m_rFrame.m_aDamageHandler, 
nullptr);
-                m_rFrame.m_pSvpGraphics->setSurface(pSurface, 
basegfx::B2IVector(nWidth, nHeight));
-                UniqueCairoSurface old_surface(m_rFrame.m_pSurface.release());
-                m_rFrame.m_pSurface.reset(pSurface);
-
-                const int nMinWidth = qMin(nOldWidth, nWidth);
-                const int nMinHeight = qMin(nOldHeight, nHeight);
-                SalTwoRect rect(0, 0, nMinWidth, nMinHeight, 0, 0, nMinWidth, 
nMinHeight);
-                m_rFrame.m_pSvpGraphics->copySource(rect, old_surface.get());
-            }
-        }
-    }
-    else
-    {
-        if (m_rFrame.m_pQImage && m_rFrame.m_pQImage->size() != QSize(nWidth, 
nHeight))
-        {
-            QImage* pImage = new QImage(m_rFrame.m_pQImage->copy(0, 0, nWidth, 
nHeight));
-            m_rFrame.m_pQtGraphics->ChangeQImage(pImage);
-            m_rFrame.m_pQImage.reset(pImage);
-        }
-    }
-
-    m_rFrame.CallCallback(SalEvent::Resize, nullptr);
-}
+void QtWidget::resizeEvent(QResizeEvent* pEvent) { 
m_rFrame.handleResizeEvent(pEvent); }
 
 void QtWidget::fakeResize()
 {
commit 79773cf27636a99c2a37373046fb448e1d754c0d
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Sep 25 15:06:21 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Sep 26 07:10:52 2024 +0200

    tdf#160837 qt: Move logic for move event handling to QtFrame
    
    Add a new QtFrame::handleMoveEvent and move the
    logic previously duplicated in both,
    QtMainWindow::moveEvent and QtWidget::moveEvent
    there, then call the new method from these two.
    
    this also prevents direct access to the
    (currently public) SalFrame::maGeometry
    member from QtWidget and lets the subclass
    do it instead.
    
    Change-Id: I468802f204d3ac5869d833526286ca8ab349697b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173951
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx
index 147c44b58085..3675df555384 100644
--- a/vcl/inc/qt5/QtFrame.hxx
+++ b/vcl/inc/qt5/QtFrame.hxx
@@ -169,6 +169,7 @@ public:
     void handleDragLeave();
     void handleDragMove(QDragMoveEvent* pEvent);
     void handleDrop(QDropEvent* pEvent);
+    void handleMoveEvent(QMoveEvent* pEvent);
 
     virtual void SetExtendedFrameStyle(SalExtStyle nExtStyle) override;
     virtual void Show(bool bVisible, bool bNoActivate = false) override;
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 52fe03543c9a..7420278b2b88 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -1575,4 +1575,11 @@ void QtFrame::handleDragLeave()
     m_bInDrag = false;
 }
 
+void QtFrame::handleMoveEvent(QMoveEvent* pEvent)
+{
+    const qreal fRatio = devicePixelRatioF();
+    maGeometry.setPos(toPoint(pEvent->pos() * fRatio));
+    CallCallback(SalEvent::Move, nullptr);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtMainWindow.cxx b/vcl/qt5/QtMainWindow.cxx
index 5ff9ac9a8116..94f019735917 100644
--- a/vcl/qt5/QtMainWindow.cxx
+++ b/vcl/qt5/QtMainWindow.cxx
@@ -38,9 +38,4 @@ void QtMainWindow::closeEvent(QCloseEvent* pEvent)
         pEvent->ignore();
 }
 
-void QtMainWindow::moveEvent(QMoveEvent* pEvent)
-{
-    const qreal fRatio = m_rFrame.devicePixelRatioF();
-    m_rFrame.maGeometry.setPos(toPoint(pEvent->pos() * fRatio));
-    m_rFrame.CallCallback(SalEvent::Move, nullptr);
-}
+void QtMainWindow::moveEvent(QMoveEvent* pEvent) { 
m_rFrame.handleMoveEvent(pEvent); }
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 4ee96c1dbf8c..4989a17546d5 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -294,8 +294,7 @@ void QtWidget::moveEvent(QMoveEvent* pEvent)
     if (m_rFrame.m_pTopLevel)
         return;
 
-    m_rFrame.maGeometry.setPos(toPoint(pEvent->pos() * 
m_rFrame.devicePixelRatioF()));
-    m_rFrame.CallCallback(SalEvent::Move, nullptr);
+    m_rFrame.handleMoveEvent(pEvent);
 }
 
 void QtWidget::showEvent(QShowEvent*)

Reply via email to