vcl/inc/qt5/QtWidget.hxx |    7 +++++++
 vcl/qt5/QtWidget.cxx     |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

New commits:
commit 00f9671624e676f34c9039d7b0b0ebba6034f05c
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Tue Apr 19 16:03:56 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Apr 21 11:31:13 2022 +0200

    tdf#140463 Qt handle mouse enter+leave events
    
    Currently just implemented for the QtWidget, but still as a static
    function, so it may be used for QtObject at some point too.
    
    But there is no (mouse) enter or leave event function in QWindow,
    so no way to handle these there. And since we can't modify the
    returned QWidget from QWidget::createWindowContainer, the only way
    would be to expand the static QtWidget::handleEvent used by
    QtObjectWindow::event ... if it's actually needed at some point.
    
    Includes squashed commit 5d56255c22c79b72c1cedb48cfe0a200f89bdc66
    ("qt6: Fix build (QtWidget::enterEvent)").
    
    Change-Id: If9009e5dfca508acd1e702df1a17eb8ad7c29690
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133190
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>
    (cherry picked from commit dc886bc6de2c0061a840bea2426663c3be2ecd26)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133149
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtWidget.hxx b/vcl/inc/qt5/QtWidget.hxx
index 878c8b1229ce..4a40589b16ba 100644
--- a/vcl/inc/qt5/QtWidget.hxx
+++ b/vcl/inc/qt5/QtWidget.hxx
@@ -51,6 +51,7 @@ class QtWidget : public QWidget
     static void commitText(QtFrame&, const QString& aText);
     static bool handleKeyEvent(QtFrame&, const QWidget&, QKeyEvent*, const 
ButtonKeyState);
     static void handleMouseButtonEvent(const QtFrame&, const QMouseEvent*, 
const ButtonKeyState);
+    static void handleMouseEnterLeaveEvents(const QtFrame&, QEvent*);
     static void fillSalAbstractMouseEvent(const QtFrame& rFrame, const 
QInputEvent* pQEvent,
                                           const QPoint& rPos, Qt::MouseButtons 
eButtons, int nWidth,
                                           SalAbstractMouseEvent& aSalEvent);
@@ -75,6 +76,12 @@ class QtWidget : public QWidget
     virtual void wheelEvent(QWheelEvent*) override;
     virtual void closeEvent(QCloseEvent*) override;
     virtual void changeEvent(QEvent*) override;
+    virtual void leaveEvent(QEvent*) override;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+    virtual void enterEvent(QEnterEvent*) override;
+#else
+    virtual void enterEvent(QEvent*) override;
+#endif
 
     void inputMethodEvent(QInputMethodEvent*) override;
     QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 017249b05434..5f07974600e8 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -208,6 +208,41 @@ void QtWidget::mouseMoveEvent(QMouseEvent* pEvent)
     pEvent->accept();
 }
 
+void QtWidget::handleMouseEnterLeaveEvents(const QtFrame& rFrame, QEvent* 
pQEvent)
+{
+    const qreal fRatio = rFrame.devicePixelRatioF();
+    const QWidget* pWidget = rFrame.GetQWidget();
+    const Point aPos = toPoint(pWidget->mapFromGlobal(QCursor::pos()) * 
fRatio);
+
+    SalMouseEvent aEvent;
+    aEvent.mnX
+        = QGuiApplication::isLeftToRight() ? aPos.X() : round(pWidget->width() 
* fRatio) - aPos.X();
+    aEvent.mnY = aPos.Y();
+    aEvent.mnTime = 0;
+    aEvent.mnButton = 0;
+    aEvent.mnCode = GetKeyModCode(QGuiApplication::keyboardModifiers())
+                    | GetMouseModCode(QGuiApplication::mouseButtons());
+
+    SalEvent nEventType;
+    if (pQEvent->type() == QEvent::Enter)
+        nEventType = SalEvent::MouseMove;
+    else
+        nEventType = SalEvent::MouseLeave;
+    rFrame.CallCallback(nEventType, &aEvent);
+    pQEvent->accept();
+}
+
+void QtWidget::leaveEvent(QEvent* pEvent) { 
handleMouseEnterLeaveEvents(m_rFrame, pEvent); }
+
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+void QtWidget::enterEvent(QEnterEvent* pEvent)
+#else
+void QtWidget::enterEvent(QEvent* pEvent)
+#endif
+{
+    handleMouseEnterLeaveEvents(m_rFrame, pEvent);
+}
+
 void QtWidget::wheelEvent(QWheelEvent* pEvent)
 {
     SalWheelMouseEvent aEvent;

Reply via email to