vcl/inc/qt5/QtInstanceMenuButton.hxx |    2 +-
 vcl/qt5/QtInstanceMenuButton.cxx     |   23 ++++++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

New commits:
commit 1b14aced2b382eb876f27f17c251060361905a4a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Jan 14 17:00:53 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Jan 15 11:13:08 2025 +0100

    tdf#130857 qt weld: Implement QtInstanceMenuButton::insert_item
    
    Add initial implementation for QtInstanceMenuButton::insert_item.
    See also QtBuilder::insertMenuObject which partially has the
    same logic.
    
    Handling for radio or check items is not implemented yet,
    so assert that `eCheckRadioFalse` is `TRISTATE_INDET` for now.
    
    This will e.g. be used by the "File" -> "Templates"
    -> "Manage Templates" dialog once that one is supported.
    
    Change-Id: Ib34d6b61b26ae900eac3b34b68224e6ac2e11711
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180250
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtInstanceMenuButton.hxx 
b/vcl/inc/qt5/QtInstanceMenuButton.hxx
index 1388bf29f688..398488076d30 100644
--- a/vcl/inc/qt5/QtInstanceMenuButton.hxx
+++ b/vcl/inc/qt5/QtInstanceMenuButton.hxx
@@ -22,7 +22,7 @@ class QtInstanceMenuButton : public QtInstanceToggleButton, 
public virtual weld:
 public:
     QtInstanceMenuButton(QToolButton* pButton);
 
-    virtual void insert_item(int pos, const OUString& rId, const OUString& 
rStr,
+    virtual void insert_item(int nPos, const OUString& rId, const OUString& 
rStr,
                              const OUString* pIconName, VirtualDevice* 
pImageSurface,
                              TriState eCheckRadioFalse) override;
 
diff --git a/vcl/qt5/QtInstanceMenuButton.cxx b/vcl/qt5/QtInstanceMenuButton.cxx
index 8223e65b80ca..45191ef937f9 100644
--- a/vcl/qt5/QtInstanceMenuButton.cxx
+++ b/vcl/qt5/QtInstanceMenuButton.cxx
@@ -23,10 +23,27 @@ QtInstanceMenuButton::QtInstanceMenuButton(QToolButton* 
pButton)
     assert(m_pToolButton);
 }
 
-void QtInstanceMenuButton::insert_item(int, const OUString&, const OUString&, 
const OUString*,
-                                       VirtualDevice*, TriState)
+void QtInstanceMenuButton::insert_item(int nPos, const OUString& rId, const 
OUString& rStr,
+                                       const OUString* pIconName, 
VirtualDevice* pImageSurface,
+                                       TriState eCheckRadioFalse)
 {
-    assert(false && "Not implemented yet");
+    SolarMutexGuard g;
+
+    assert(eCheckRadioFalse == TRISTATE_INDET && "Param not handled yet");
+    (void)eCheckRadioFalse;
+
+    GetQtInstance().RunInMainThread([&] {
+        if (nPos == -1)
+            nPos = getMenu().actions().count();
+
+        QAction* pAction = 
getMenu().addAction(vclToQtStringWithAccelerator(rStr));
+        pAction->setObjectName(toQString(rId));
+
+        if (pIconName)
+            pAction->setIcon(loadQPixmapIcon(*pIconName));
+        else if (pImageSurface)
+            pAction->setIcon(toQPixmap(*pImageSurface));
+    });
 }
 
 void QtInstanceMenuButton::insert_separator(int, const OUString&)

Reply via email to