[Libreoffice-commits] core.git: vcl/inc vcl/qt5

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Sun Jun 28 10:53:06 UTC 2020


 vcl/inc/qt5/Qt5Widget.hxx |    5 +++++
 vcl/qt5/Qt5Widget.cxx     |   46 +++++++++++++++++++++-------------------------
 2 files changed, 26 insertions(+), 25 deletions(-)

New commits:
commit a3634fe80fa5578774df07a2dc327de730f11348
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sun Jun 28 03:00:50 2020 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Sun Jun 28 12:52:30 2020 +0200

    Qt5 refactor mouse event fill code
    
    Adds Qt5Widget::fillSalAbstractMouseEvent to set the common
    Sal*MouseEvent members. While the member functions of QMouseEvent
    and QWheelEvent have the same name, they aren't shared via
    QInputEvent, so this uses a small FILL_SAME macro for less code,
    
    Change-Id: I3e5aa52b1bf2774251d97534ce0106a27ef5899b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97343
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx
index 159794b2d2a3..7bf7ead6ae9a 100644
--- a/vcl/inc/qt5/Qt5Widget.hxx
+++ b/vcl/inc/qt5/Qt5Widget.hxx
@@ -25,8 +25,10 @@
 #include <com/sun/star/uno/Reference.hxx>
 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
 
+class QInputEvent;
 class Qt5Frame;
 class Qt5Object;
+struct SalAbstractMouseEvent;
 
 class Qt5Widget : public QWidget
 {
@@ -46,6 +48,9 @@ class Qt5Widget : public QWidget
     static void commitText(Qt5Frame&, const QString& aText);
     static bool handleKeyEvent(Qt5Frame&, const QWidget&, QKeyEvent*, const ButtonKeyState);
     static void handleMouseButtonEvent(const Qt5Frame&, const QMouseEvent*, const ButtonKeyState);
+    static void fillSalAbstractMouseEvent(const Qt5Frame& rFrame, const QInputEvent* pQEvent,
+                                          const QPoint& rPos, Qt::MouseButtons eButtons, int nWidth,
+                                          SalAbstractMouseEvent& aSalEvent);
 
     virtual bool event(QEvent*) override;
 
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index 0ef305f42949..2d3951ad8203 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -127,10 +127,28 @@ void Qt5Widget::resizeEvent(QResizeEvent* pEvent)
     m_rFrame.CallCallback(SalEvent::Resize, nullptr);
 }
 
+void Qt5Widget::fillSalAbstractMouseEvent(const Qt5Frame& rFrame, const QInputEvent* pQEvent,
+                                          const QPoint& rPos, Qt::MouseButtons eButtons, int nWidth,
+                                          SalAbstractMouseEvent& aSalEvent)
+{
+    const qreal fRatio = rFrame.devicePixelRatioF();
+    const Point aPos = toPoint(rPos * fRatio);
+
+    aSalEvent.mnX = QGuiApplication::isLeftToRight() ? aPos.X() : round(nWidth * fRatio) - aPos.X();
+    aSalEvent.mnY = aPos.Y();
+    aSalEvent.mnTime = pQEvent->timestamp();
+    aSalEvent.mnCode = GetKeyModCode(pQEvent->modifiers()) | GetMouseModCode(eButtons);
+}
+
+#define FILL_SAME(rFrame, nWidth)                                                                  \
+    fillSalAbstractMouseEvent(rFrame, pEvent, pEvent->pos(), pEvent->buttons(), nWidth, aEvent)
+
 void Qt5Widget::handleMouseButtonEvent(const Qt5Frame& rFrame, const QMouseEvent* pEvent,
                                        const ButtonKeyState eState)
 {
     SalMouseEvent aEvent;
+    FILL_SAME(rFrame, rFrame.GetQWidget()->width());
+
     switch (pEvent->button())
     {
         case Qt::LeftButton:
@@ -146,16 +164,6 @@ void Qt5Widget::handleMouseButtonEvent(const Qt5Frame& rFrame, const QMouseEvent
             return;
     }
 
-    const qreal fRatio = rFrame.devicePixelRatioF();
-    const Point aPos = toPoint(pEvent->pos() * fRatio);
-
-    aEvent.mnX = QGuiApplication::isLeftToRight()
-                     ? aPos.X()
-                     : round(rFrame.GetQWidget()->width() * fRatio) - aPos.X();
-    aEvent.mnY = aPos.Y();
-    aEvent.mnTime = pEvent->timestamp();
-    aEvent.mnCode = GetKeyModCode(pEvent->modifiers()) | GetMouseModCode(pEvent->buttons());
-
     SalEvent nEventType;
     if (eState == ButtonKeyState::Pressed)
         nEventType = SalEvent::MouseButtonDown;
@@ -173,14 +181,9 @@ void Qt5Widget::mouseReleaseEvent(QMouseEvent* pEvent)
 
 void Qt5Widget::mouseMoveEvent(QMouseEvent* pEvent)
 {
-    const qreal fRatio = m_rFrame.devicePixelRatioF();
-    const Point aPos = toPoint(pEvent->pos() * fRatio);
-
     SalMouseEvent aEvent;
-    aEvent.mnX = QGuiApplication::isLeftToRight() ? aPos.X() : round(width() * fRatio) - aPos.X();
-    aEvent.mnY = aPos.Y();
-    aEvent.mnTime = pEvent->timestamp();
-    aEvent.mnCode = GetKeyModCode(pEvent->modifiers()) | GetMouseModCode(pEvent->buttons());
+    FILL_SAME(m_rFrame, width());
+
     aEvent.mnButton = 0;
 
     m_rFrame.CallCallback(SalEvent::MouseMove, &aEvent);
@@ -189,15 +192,8 @@ void Qt5Widget::mouseMoveEvent(QMouseEvent* pEvent)
 
 void Qt5Widget::wheelEvent(QWheelEvent* pEvent)
 {
-    const Point aPos = toPoint(pEvent->pos() * m_rFrame.devicePixelRatioF());
-
     SalWheelMouseEvent aEvent;
-    aEvent.mnX = QGuiApplication::isLeftToRight()
-                     ? aPos.X()
-                     : round(width() * m_rFrame.devicePixelRatioF()) - aPos.X();
-    aEvent.mnY = aPos.Y();
-    aEvent.mnTime = pEvent->timestamp();
-    aEvent.mnCode = GetKeyModCode(pEvent->modifiers()) | GetMouseModCode(pEvent->buttons());
+    FILL_SAME(m_rFrame, width());
 
     // mouse wheel ticks are 120, which we map to 3 lines.
     // we have to accumulate for touch scroll to keep track of the absolute delta.


More information about the Libreoffice-commits mailing list