vcl/inc/qt5/QtTools.hxx | 2 ++ vcl/qt5/QtInstanceDrawingArea.cxx | 14 +++++++++++++- vcl/qt5/QtInstanceMenu.cxx | 27 ++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-)
New commits: commit 18269932655afdbfece1ce1d57da9e86fa760065 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Tue Jul 29 20:10:37 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Jul 30 14:29:55 2025 +0200 tdf#130857 qt weld: Implement QtInstanceMenu::popup_at_rect Together with previous commit Change-Id: If8cfff809878d43e6b45b0b8317d1bb8738397d6 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Tue Jul 29 20:01:25 2025 +0200 tdf#130857 qt weld: Forward DrawingArea context menu event , this is needed to make the context menu in the Base "Tools" -> "SQL" dialog show when right-clicking into the "Command to execute" edit view in a local WIP branch containing more changes to prepare support for that dialog. Change-Id: I66d273895e55698427343caf688b88b2e56e3993 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188541 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtTools.hxx b/vcl/inc/qt5/QtTools.hxx index a30e3fdf4bd9..e88759d220b6 100644 --- a/vcl/inc/qt5/QtTools.hxx +++ b/vcl/inc/qt5/QtTools.hxx @@ -75,6 +75,8 @@ inline QSize toQSize(const Size& rSize) { return QSize(rSize.Width(), rSize.Heig inline Size toSize(const QSize& rSize) { return Size(rSize.width(), rSize.height()); } +inline QPoint toQPoint(const Point& rPoint) { return QPoint(rPoint.X(), rPoint.Y()); } + inline Point toPoint(const QPoint& rPoint) { return Point(rPoint.x(), rPoint.y()); } inline QColor toQColor(const Color& rColor) diff --git a/vcl/qt5/QtInstanceMenu.cxx b/vcl/qt5/QtInstanceMenu.cxx index b416792da74d..ba5184e4e422 100644 --- a/vcl/qt5/QtInstanceMenu.cxx +++ b/vcl/qt5/QtInstanceMenu.cxx @@ -11,6 +11,8 @@ #include <QtInstanceMenu.moc> #include <QtInstance.hxx> +#include <QtInstanceWidget.hxx> +#include <QtTools.hxx> #include <vcl/svapp.hxx> #include <vcl/qt/QtUtils.hxx> @@ -24,10 +26,29 @@ QtInstanceMenu::QtInstanceMenu(QMenu* pMenu) assert(m_pMenu); } -OUString QtInstanceMenu::popup_at_rect(weld::Widget*, const tools::Rectangle&, weld::Placement) +OUString QtInstanceMenu::popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect, + weld::Placement ePlace) { - assert(false && "Not implemented yet"); - return OUString(); + SolarMutexGuard g; + + assert(ePlace == weld::Placement::Under && "placement type not supported yet"); + (void)ePlace; + + OUString sActionId; + GetQtInstance().RunInMainThread([&] { + m_pMenu->adjustSize(); + + QtInstanceWidget* pQtParent = dynamic_cast<QtInstanceWidget*>(pParent); + assert(pQtParent && "No parent"); + QWidget* pParentWidget = pQtParent->getQWidget(); + assert(pParentWidget); + const QPoint aPos = pParentWidget->mapToGlobal(toQPoint(rRect.TopLeft())); + + if (const QAction* pTriggeredAction = m_pMenu->exec(aPos)) + sActionId = toOUString(pTriggeredAction->objectName()); + }); + + return sActionId; } void QtInstanceMenu::set_sensitive(const OUString& rIdent, bool bSensitive) commit 25b4bb19decc61dcceffd99f7480e93793ca424b Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Tue Jul 29 20:01:25 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Jul 30 14:29:47 2025 +0200 tdf#130857 qt weld: Forward DrawingArea context menu event Intercept QContextMenuEvent for the QtInstanceDrawingArea widget, convert to a corresponding vcl CommandEvent and and call the corresponding handler. This will e.g. be needed to make the context menu in the Base "Tools" -> "SQL" dialog work when right-clicking into the "Command to execute" edit view. In a WIP branch where support for that dialog is declared, this now results in - the not yet implemented - QtInstanceMenu::popup_at_rect getting called when on right click. Change-Id: If8cfff809878d43e6b45b0b8317d1bb8738397d6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188540 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtInstanceDrawingArea.cxx b/vcl/qt5/QtInstanceDrawingArea.cxx index b41081c16709..598b6ed9f8b7 100644 --- a/vcl/qt5/QtInstanceDrawingArea.cxx +++ b/vcl/qt5/QtInstanceDrawingArea.cxx @@ -13,6 +13,7 @@ #include <QtAccessibleWidget.hxx> #include <QtData.hxx> +#include <vcl/commandevent.hxx> #include <vcl/qt/QtUtils.hxx> #include <QtGui/QHelpEvent> @@ -120,6 +121,15 @@ bool QtInstanceDrawingArea::eventFilter(QObject* pObject, QEvent* pEvent) switch (pEvent->type()) { + case QEvent::ContextMenu: + { + QContextMenuEvent* pContextMenuEvent = static_cast<QContextMenuEvent*>(pEvent); + const Point aPos = toPoint(pContextMenuEvent->pos()); + const CommandEvent aEvent(aPos, CommandEventId::ContextMenu); + if (m_aCommandHdl.Call(aEvent)) + return true; + break; + } case QEvent::Paint: handlePaintEvent(); return false; @@ -132,8 +142,10 @@ bool QtInstanceDrawingArea::eventFilter(QObject* pObject, QEvent* pEvent) return handleToolTipEvent(*pHelpEvent); } default: - return QtInstanceWidget::eventFilter(pObject, pEvent); + break; } + + return QtInstanceWidget::eventFilter(pObject, pEvent); } void QtInstanceDrawingArea::handlePaintEvent()