vcl/inc/qt5/QtFrame.hxx  |    3 +++
 vcl/inc/qt5/QtWidget.hxx |    2 +-
 vcl/qt5/QtFrame.cxx      |    8 +++++++-
 vcl/qt5/QtWidget.cxx     |   19 ++++++++++++++++++-
 4 files changed, 29 insertions(+), 3 deletions(-)

New commits:
commit 7fc871299080427587307932c505d3ae93d6a357
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Tue Apr 12 00:29:56 2022 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Wed Apr 13 22:31:30 2022 +0200

    tdf#148115 Qt handle tooltips via event loop
    
    Instead of calling QToolTip::showText directly from LO, this
    defers showing the tooltip to the QEvent processing, which takes
    the tooltip timeouts into account. So tooltips are shown with
    a slight delay, therefore they happen less fast on mouse move,
    reducing / avoiding artifacts of fast changing windows.
    
    This unfortunately comes with yet an other hack in the area of
    our fake popup windows...
    
    New handling is based on the code of the Qt Tool Tips example.
    
    Change-Id: I42634ad36dd12171c30f52f07a02a88d3c48a718
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132841
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins
    (cherry picked from commit af6dd54d53eee0d0de1164bff0a77c6b433b3935)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132864
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx
index 5ffaacf3ad94..23a4fd9887f1 100644
--- a/vcl/inc/qt5/QtFrame.hxx
+++ b/vcl/inc/qt5/QtFrame.hxx
@@ -111,6 +111,9 @@ class VCLPLUG_QT_PUBLIC QtFrame : public QObject, public 
SalFrame
 
     LanguageType m_nInputLanguage;
 
+    OUString m_aTooltipText;
+    QRect m_aTooltipArea;
+
     void SetDefaultPos();
     Size CalcDefaultSize();
     void SetDefaultSize();
diff --git a/vcl/inc/qt5/QtWidget.hxx b/vcl/inc/qt5/QtWidget.hxx
index 575cef11014f..878c8b1229ce 100644
--- a/vcl/inc/qt5/QtWidget.hxx
+++ b/vcl/inc/qt5/QtWidget.hxx
@@ -87,7 +87,7 @@ public:
     void endExtTextInput();
     void fakeResize();
 
-    static bool handleEvent(QtFrame&, const QWidget&, QEvent*);
+    static bool handleEvent(QtFrame&, QWidget&, QEvent*);
     // key events might be propagated further down => call base on false
     static inline bool handleKeyReleaseEvent(QtFrame&, const QWidget&, 
QKeyEvent*);
     // mouse events are always accepted
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index c78417b3070a..f6f4b6c2611d 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -175,7 +175,12 @@ QtFrame::QtFrame(QtFrame* pParent, SalFrameStyleFlags 
nStyle, bool bUseCairo)
         m_pTopLevel->setFocusProxy(m_pQWidget);
     }
     else
+    {
         m_pQWidget = new QtWidget(*this, aWinFlags);
+        // from Qt's POV the popup window doesn't have the input focus, so we 
must force tooltips...
+        if (isPopup())
+            m_pQWidget->setAttribute(Qt::WA_AlwaysShowToolTips);
+    }
 
     QWindow* pChildWindow = windowHandle();
     connect(pChildWindow, &QWindow::screenChanged, this, 
&QtFrame::screenChanged);
@@ -855,7 +860,8 @@ bool QtFrame::ShowTooltip(const OUString& rText, const 
tools::Rectangle& rHelpAr
     QRect aHelpArea(toQRect(rHelpArea));
     if (QGuiApplication::isRightToLeft())
         aHelpArea.moveLeft(maGeometry.nWidth - aHelpArea.width() - 
aHelpArea.left() - 1);
-    QToolTip::showText(QCursor::pos(), toQString(rText), m_pQWidget, 
aHelpArea);
+    m_aTooltipText = rText;
+    m_aTooltipArea = aHelpArea;
     return true;
 }
 
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 1fe2ce9a7159..017249b05434 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -42,6 +42,7 @@
 #include <QtGui/QTextCharFormat>
 #include <QtGui/QWheelEvent>
 #include <QtWidgets/QMainWindow>
+#include <QtWidgets/QToolTip>
 #include <QtWidgets/QWidget>
 
 #include <cairo.h>
@@ -562,7 +563,7 @@ bool QtWidget::handleKeyEvent(QtFrame& rFrame, const 
QWidget& rWidget, QKeyEvent
     return bStopProcessingKey;
 }
 
-bool QtWidget::handleEvent(QtFrame& rFrame, const QWidget& rWidget, QEvent* 
pEvent)
+bool QtWidget::handleEvent(QtFrame& rFrame, QWidget& rWidget, QEvent* pEvent)
 {
     if (pEvent->type() == QEvent::ShortcutOverride)
     {
@@ -589,6 +590,22 @@ bool QtWidget::handleEvent(QtFrame& rFrame, const QWidget& 
rWidget, QEvent* pEve
                            ButtonKeyState::Pressed))
             return true;
     }
+    else if (pEvent->type() == QEvent::ToolTip)
+    {
+        // Qt's POV on focus is wrong for our fake popup windows, so check 
LO's state.
+        // Otherwise Qt will continue handling ToolTip events from the 
"parent" window.
+        const vcl::Window* pFocusWin = Application::GetFocusWindow();
+        if (!rFrame.m_aTooltipText.isEmpty() && pFocusWin
+            && pFocusWin->GetFrameWindow() == rFrame.GetWindow())
+            QToolTip::showText(QCursor::pos(), 
toQString(rFrame.m_aTooltipText), &rWidget,
+                               rFrame.m_aTooltipArea);
+        else
+        {
+            QToolTip::hideText();
+            pEvent->ignore();
+        }
+        return true;
+    }
     return false;
 }
 

Reply via email to