vcl/inc/qt5/QtInstanceDrawingArea.hxx | 2 +- vcl/inc/qt5/QtInstanceIconView.hxx | 5 ++--- vcl/inc/qt5/QtInstanceTreeView.hxx | 2 +- vcl/inc/qt5/QtInstanceWidget.hxx | 4 ++-- vcl/qt5/QtInstanceDrawingArea.cxx | 11 +++-------- vcl/qt5/QtInstanceIconView.cxx | 23 +++++------------------ vcl/qt5/QtInstanceTreeView.cxx | 8 ++++---- vcl/qt5/QtInstanceWidget.cxx | 6 +++--- 8 files changed, 21 insertions(+), 40 deletions(-)
New commits: commit ca104ee50bcbe259ee8f1e206c4de78bccb482b1 Author: Michael Weghorn <[email protected]> AuthorDate: Thu Oct 2 23:28:37 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Oct 3 01:48:37 2025 +0200 tdf#130857 tdf#168646 qt weld: Call base class tooltip logic Refactor, deduplicate, and refine the custom logic for tooltip handling for QtInstanceWidget and subclasses: First, deduplicate and refactor, by making QtInstanceWidget::handleToolTipEvent virtual and overriding it in QtInstanceDrawingArea and QtInstanceIconView. This also means that their eventFilter overrides no longer need to handle the QToolTip QEvent::ToolTip case directly anymore, as the QtInstanceWidget implementation now calls their QtInstanceWidget::handleToolTipEvent overrides. Rename QtInstanceTreeView::handleToolTipEvent to QtInstanceTreeView::handleViewPortToolTipEvent as that one is different: It handles the tooltip event for its QTreeView's viewPort(), not for the QTreeView widget itself. Second, in QtInstanceIconView::handleToolTipEvent and QtInstanceDrawingArea::handleToolTipEvent, call the base class implementation when there is no tooltip according to the IconView or DrawingArea specific logic, to ensure that the extended tip logic implemented in QtInstanceWidget::handleToolTipEvent gets triggered. The latter is similar to what Change-Id: I2918cc3377ec53e649d54cceaf0c9cb53effe58f Author: Michael Weghorn <[email protected]> Date: Thu Oct 2 23:17:33 2025 +0200 tdf#168646 vcl: Propagate undhandled tooltip event to base class implemented for the SalInstanceDrawing case, i.e. the vcl immplementation. This makes the extended tip for the case of the "Dimension Line" dialog described in tdf#168646 work with qt6 and SAL_VCL_QT_USE_WELDED_WIDGETS=1 in a WIP branch where support for using native Qt widgets for that dialog is declared. Change-Id: I00cd0486911dd65d59315d02c1810ccdcc763d0d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191803 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/inc/qt5/QtInstanceDrawingArea.hxx b/vcl/inc/qt5/QtInstanceDrawingArea.hxx index a43ef98535cf..1975d2c63144 100644 --- a/vcl/inc/qt5/QtInstanceDrawingArea.hxx +++ b/vcl/inc/qt5/QtInstanceDrawingArea.hxx @@ -53,7 +53,7 @@ public: private: void handlePaintEvent(); void handleResizeEvent(); - bool handleToolTipEvent(QHelpEvent& rEvent); + virtual bool handleToolTipEvent(const QHelpEvent& rHelpEvent) override; private: virtual void click(const Point&) override; diff --git a/vcl/inc/qt5/QtInstanceIconView.hxx b/vcl/inc/qt5/QtInstanceIconView.hxx index 772b1cd22065..bc266fa7b788 100644 --- a/vcl/inc/qt5/QtInstanceIconView.hxx +++ b/vcl/inc/qt5/QtInstanceIconView.hxx @@ -72,7 +72,8 @@ public: virtual int n_children() const override; - virtual bool eventFilter(QObject* pObject, QEvent* pEvent) override; +protected: + virtual bool handleToolTipEvent(const QHelpEvent& rHelpEvent) override; private: void insert(int nPos, const OUString* pStr, const OUString* pId, const QPixmap* pIcon, @@ -82,8 +83,6 @@ private: QModelIndex modelIndex(const weld::TreeIter& rIter) const; static int position(const weld::TreeIter& rIter); - bool handleToolTipEvent(const QHelpEvent* pEvent); - private Q_SLOTS: void handleActivated(); void handleSelectionChanged(); diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx index cc36e5bbbea6..d883820b7b66 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -223,7 +223,7 @@ private: void setImage(const weld::TreeIter& rIter, const QPixmap& rPixmap, int nCol); - bool handleToolTipEvent(const QHelpEvent* pEvent); + bool handleViewPortToolTipEvent(const QHelpEvent& rEvent); private Q_SLOTS: void handleActivated(); diff --git a/vcl/inc/qt5/QtInstanceWidget.hxx b/vcl/inc/qt5/QtInstanceWidget.hxx index 99046a627a63..b30b2d3efbab 100644 --- a/vcl/inc/qt5/QtInstanceWidget.hxx +++ b/vcl/inc/qt5/QtInstanceWidget.hxx @@ -184,8 +184,8 @@ public: void setFont(vcl::Font rFont); static void setHelpId(QWidget& rWidget, const OUString& rHelpId); -private: - bool handleToolTipEvent(const QHelpEvent* pEvent); +protected: + virtual bool handleToolTipEvent(const QHelpEvent& rHelpEvent); private Q_SLOTS: void applicationFocusChanged(QWidget* pOldFocus, QWidget* pNewFocus); diff --git a/vcl/qt5/QtInstanceDrawingArea.cxx b/vcl/qt5/QtInstanceDrawingArea.cxx index 598b6ed9f8b7..a9dfb67d1980 100644 --- a/vcl/qt5/QtInstanceDrawingArea.cxx +++ b/vcl/qt5/QtInstanceDrawingArea.cxx @@ -136,11 +136,6 @@ bool QtInstanceDrawingArea::eventFilter(QObject* pObject, QEvent* pEvent) case QEvent::Resize: handleResizeEvent(); return false; - case QEvent::ToolTip: - { - QHelpEvent* pHelpEvent = static_cast<QHelpEvent*>(pEvent); - return handleToolTipEvent(*pHelpEvent); - } default: break; } @@ -175,12 +170,12 @@ void QtInstanceDrawingArea::handleResizeEvent() m_aSizeAllocateHdl.Call(toSize(aLabelSize)); } -bool QtInstanceDrawingArea::handleToolTipEvent(QHelpEvent& rEvent) +bool QtInstanceDrawingArea::handleToolTipEvent(const QHelpEvent& rHelpEvent) { - tools::Rectangle aHelpArea(toPoint(rEvent.pos()), Size(0, 0)); + tools::Rectangle aHelpArea(toPoint(rHelpEvent.pos()), Size(0, 0)); const OUString sToolTipText = signal_query_tooltip(aHelpArea); if (sToolTipText.isEmpty()) - return false; + return QtInstanceWidget::handleToolTipEvent(rHelpEvent); const QPoint aPos = getQWidget()->mapToGlobal(toQRect(aHelpArea).topLeft()); QToolTip::showText(aPos, toQString(sToolTipText), getQWidget()); diff --git a/vcl/qt5/QtInstanceIconView.cxx b/vcl/qt5/QtInstanceIconView.cxx index 4d5aee6caa2e..87cd486f1753 100644 --- a/vcl/qt5/QtInstanceIconView.cxx +++ b/vcl/qt5/QtInstanceIconView.cxx @@ -32,9 +32,6 @@ QtInstanceIconView::QtInstanceIconView(QListView* pListView) m_pSelectionModel = m_pListView->selectionModel(); assert(m_pSelectionModel); - // install event filter to handle tooltip events - m_pListView->installEventFilter(this); - connect(m_pListView, &QListView::activated, this, &QtInstanceIconView::handleActivated); connect(m_pSelectionModel, &QItemSelectionModel::selectionChanged, this, &QtInstanceIconView::handleSelectionChanged); @@ -312,16 +309,6 @@ int QtInstanceIconView::n_children() const return nChildren; } -bool QtInstanceIconView::eventFilter(QObject* pObject, QEvent* pEvent) -{ - assert(pObject == m_pListView); - - if (pEvent->type() == QEvent::ToolTip) - return handleToolTipEvent(static_cast<QHelpEvent*>(pEvent)); - - return QtInstanceWidget::eventFilter(pObject, pEvent); -} - QModelIndex QtInstanceIconView::modelIndex(int nPos) const { return m_pModel->index(nPos, 0); } QModelIndex QtInstanceIconView::modelIndex(const weld::TreeIter& rIter) const @@ -335,19 +322,19 @@ int QtInstanceIconView::position(const weld::TreeIter& rIter) return aModelIndex.row(); } -bool QtInstanceIconView::handleToolTipEvent(const QHelpEvent* pHelpEvent) +bool QtInstanceIconView::handleToolTipEvent(const QHelpEvent& rHelpEvent) { - QModelIndex aIndex = m_pListView->indexAt(pHelpEvent->pos()); + QModelIndex aIndex = m_pListView->indexAt(rHelpEvent.pos()); if (!aIndex.isValid()) - return false; + return QtInstanceWidget::handleToolTipEvent(rHelpEvent); SolarMutexGuard g; const QtInstanceTreeIter aIter(aIndex); const QString sToolTip = toQString(signal_query_tooltip(aIter)); if (sToolTip.isEmpty()) - return false; + return QtInstanceWidget::handleToolTipEvent(rHelpEvent); - QToolTip::showText(pHelpEvent->globalPos(), sToolTip, m_pListView, + QToolTip::showText(rHelpEvent.globalPos(), sToolTip, m_pListView, m_pListView->visualRect(aIndex)); return true; } diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 9c84203f7c97..2316a3d672df 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -1104,7 +1104,7 @@ void QtInstanceTreeView::setColumnRoles(QTreeView& rTreeView, bool QtInstanceTreeView::eventFilter(QObject* pObject, QEvent* pEvent) { if (pEvent->type() == QEvent::ToolTip && pObject == m_pTreeView->viewport()) - return handleToolTipEvent(static_cast<QHelpEvent*>(pEvent)); + return handleViewPortToolTipEvent(static_cast<QHelpEvent&>(*pEvent)); return QtInstanceWidget::eventFilter(pObject, pEvent); } @@ -1170,9 +1170,9 @@ void QtInstanceTreeView::setImage(const weld::TreeIter& rIter, const QPixmap& rP }); } -bool QtInstanceTreeView::handleToolTipEvent(const QHelpEvent* pHelpEvent) +bool QtInstanceTreeView::handleViewPortToolTipEvent(const QHelpEvent& rHelpEvent) { - QModelIndex aIndex = m_pTreeView->indexAt(pHelpEvent->pos()); + QModelIndex aIndex = m_pTreeView->indexAt(rHelpEvent.pos()); if (!aIndex.isValid()) return false; @@ -1182,7 +1182,7 @@ bool QtInstanceTreeView::handleToolTipEvent(const QHelpEvent* pHelpEvent) if (sToolTip.isEmpty()) return false; - QToolTip::showText(pHelpEvent->globalPos(), sToolTip, m_pTreeView, + QToolTip::showText(rHelpEvent.globalPos(), sToolTip, m_pTreeView, m_pTreeView->visualRect(aIndex)); return true; } diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx index cddd02d22ebc..a01df56ace46 100644 --- a/vcl/qt5/QtInstanceWidget.cxx +++ b/vcl/qt5/QtInstanceWidget.cxx @@ -337,7 +337,7 @@ bool QtInstanceWidget::eventFilter(QObject* pObject, QEvent* pEvent) } case QEvent::ToolTip: { - return handleToolTipEvent(static_cast<QHelpEvent*>(pEvent)); + return handleToolTipEvent(static_cast<QHelpEvent&>(*pEvent)); } default: return QObject::eventFilter(pObject, pEvent); @@ -821,7 +821,7 @@ void QtInstanceWidget::draw(OutputDevice&, const Point&, const Size&) assert(false && "Not implemented yet"); } -bool QtInstanceWidget::handleToolTipEvent(const QHelpEvent* pHelpEvent) +bool QtInstanceWidget::handleToolTipEvent(const QHelpEvent& rHelpEvent) { // show extended tip if enabled and set if (!ImplGetSVHelpData().mbBalloonHelp) @@ -832,7 +832,7 @@ bool QtInstanceWidget::handleToolTipEvent(const QHelpEvent* pHelpEvent) if (sExtendedTip.isEmpty()) return false; - QToolTip::showText(pHelpEvent->globalPos(), sExtendedTip, getQWidget()); + QToolTip::showText(rHelpEvent.globalPos(), sExtendedTip, getQWidget()); return true; }
