diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-04-12 00:29:56 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-04-12 14:09:00 +0200 |
commit | af6dd54d53eee0d0de1164bff0a77c6b433b3935 (patch) | |
tree | 01346b6ab1e9b6c9b94aef8d36de3499b5345d05 /vcl | |
parent | ea68de2968c0dbcd8e7549435e829db06795c16d (diff) |
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.weghorn@posteo.de>
Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/qt5/QtFrame.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/qt5/QtWidget.hxx | 2 | ||||
-rw-r--r-- | vcl/qt5/QtFrame.cxx | 8 | ||||
-rw-r--r-- | vcl/qt5/QtWidget.cxx | 19 |
4 files changed, 29 insertions, 3 deletions
diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx index a873cec76ad6..2d7c5718d6cf 100644 --- a/vcl/inc/qt5/QtFrame.hxx +++ b/vcl/inc/qt5/QtFrame.hxx @@ -110,6 +110,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 91361311d60e..440cd8048d76 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -173,7 +173,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); @@ -859,7 +864,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 612682ae987f..33320c577f94 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; } |