vcl/inc/qt5/QtInstanceMenu.hxx | 2 +- vcl/qt5/QtInstanceMenu.cxx | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-)
New commits: commit ab9aa88000cca4a8611fa140eae502f590842f8c Author: Michael Weghorn <[email protected]> AuthorDate: Fri Jun 20 19:33:11 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Jun 20 21:22:02 2025 +0200 tdf#130857 qt weld: Implement QtInstanceMenu::insert See also QtBuilder::insertMenuObject. This will be needed e.g. when adding support for the Impress "Bullets and Numbering" dialog (SvxBulletAndPositionDlg) that can be triggered as follows: * Select text in a slide * right-click to open context menu * select the "Bullets and Numbering" context menu entry Change-Id: I0b7163653265847ac0ab6e0a153eaabdbb60a960 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186774 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/inc/qt5/QtInstanceMenu.hxx b/vcl/inc/qt5/QtInstanceMenu.hxx index a4194a159edd..c943e9d4340c 100644 --- a/vcl/inc/qt5/QtInstanceMenu.hxx +++ b/vcl/inc/qt5/QtInstanceMenu.hxx @@ -33,7 +33,7 @@ public: virtual bool get_active(const OUString& rIdent) const override; virtual void set_visible(const OUString& rIdent, bool bVisible) override; - virtual void insert(int pos, const OUString& rId, const OUString& rStr, + virtual void insert(int nPos, const OUString& rId, const OUString& rStr, const OUString* pIconName, VirtualDevice* pImageSurface, const css::uno::Reference<css::graphic::XGraphic>& rImage, TriState eCheckRadioFalse) override; diff --git a/vcl/qt5/QtInstanceMenu.cxx b/vcl/qt5/QtInstanceMenu.cxx index d7f15d3e6f12..b416792da74d 100644 --- a/vcl/qt5/QtInstanceMenu.cxx +++ b/vcl/qt5/QtInstanceMenu.cxx @@ -109,10 +109,34 @@ void QtInstanceMenu::set_visible(const OUString& rIdent, bool bVisible) }); } -void QtInstanceMenu::insert(int, const OUString&, const OUString&, const OUString*, VirtualDevice*, - const css::uno::Reference<css::graphic::XGraphic>&, TriState) +void QtInstanceMenu::insert(int nPos, const OUString& rId, const OUString& rStr, + const OUString* pIconName, VirtualDevice* pImageSurface, + const css::uno::Reference<css::graphic::XGraphic>& rImage, + TriState eCheckRadioFalse) { - assert(false && "Not implemented yet"); + assert(eCheckRadioFalse == TRISTATE_INDET && "Not implemented yet"); + (void)eCheckRadioFalse; + + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + const int nCount = m_pMenu->actions().size(); + if (nPos == -1) + nPos = nCount; + + QAction* pAction = new QAction(toQString(rStr)); + QAction* pInsertBefore = nPos < nCount ? m_pMenu->actions().at(nPos) : nullptr; + m_pMenu->insertAction(pInsertBefore, pAction); + + pAction->setObjectName(toQString(rId)); + + if (pIconName && !pIconName->isEmpty()) + pAction->setIcon(loadQPixmapIcon(*pIconName)); + else if (pImageSurface) + pAction->setIcon(toQPixmap(*pImageSurface)); + else if (rImage.is()) + pAction->setIcon(toQPixmap(rImage)); + }); } void QtInstanceMenu::set_item_help_id(const OUString&, const OUString&)
