include/vcl/builderbase.hxx   |    1 +
 vcl/qt5/QtBuilder.cxx         |   14 +++++++++++++-
 vcl/source/window/builder.cxx |   10 +++++-----
 3 files changed, 19 insertions(+), 6 deletions(-)

New commits:
commit 0f3cf3091666ef393e189b539aa9a808e168df81
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Dec 20 23:48:25 2024 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Dec 21 09:31:03 2024 +0100

    tdf#130857 qt weld: Set menu button's menu defined in .ui file
    
    Make the existing local helper function `extractPopupMenu`
    used by VclBuilder a static method in the BuilderBase base
    class for reuse by QtBuilder.
    
    Use it in QtBuilder::makeObject to evaluate
    the "popup" property for a "GtkMenuButton"
    object, get the corresponding QMenu and set
    it for the button.
    
    The code currently assumes that the corresponding
    menu is aleady known, i.e. was defined earlier in
    the .ui file than the menu button it belongs to.
    VclBuilder doesn't rely on that, so a handling
    similar to there could be implemented as and when
    needed.
    
    Change-Id: I95446fb7a369f2cfee0d8d51432933582bbfd570
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178972
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/include/vcl/builderbase.hxx b/include/vcl/builderbase.hxx
index 2632dd6417af..7e892b387aac 100644
--- a/include/vcl/builderbase.hxx
+++ b/include/vcl/builderbase.hxx
@@ -90,6 +90,7 @@ protected:
     static bool extractEntry(stringmap& rMap);
     static OUString extractIconName(stringmap& rMap);
     static OUString extractLabel(stringmap& rMap);
+    static OUString extractPopupMenu(stringmap& rMap);
     static bool extractShowExpanders(stringmap& rMap);
     static OUString extractTitle(stringmap& rMap);
     static OUString extractTooltipText(stringmap& rMap);
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 6cfe11612b00..9e8985d04d60 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -278,6 +278,18 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
 
         pObject = pLabel;
     }
+    else if (sName == u"GtkMenuButton")
+    {
+        QToolButton* pMenuButton = new QToolButton(pParentWidget);
+        const OUString sMenu = extractPopupMenu(rMap);
+        if (!sMenu.isEmpty())
+        {
+            QMenu* pMenu = get_menu(sMenu);
+            assert(pMenu && "menu button references non-existing menu");
+            pMenuButton->setMenu(pMenu);
+        }
+        pObject = pMenuButton;
+    }
     else if (sName == u"GtkNotebook")
     {
         pObject = new QTabWidget(pParentWidget);
@@ -318,7 +330,7 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     {
         pObject = new QPlainTextEdit(pParentWidget);
     }
-    else if (sName == u"GtkToggleButton" || sName == u"GtkMenuButton")
+    else if (sName == u"GtkToggleButton")
     {
         pObject = new QToolButton(pParentWidget);
     }
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index ed59785cc791..df2df8235f68 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -878,11 +878,6 @@ namespace
         return extractBoolEntry(rMap, u"draw-value"_ustr, true);
     }
 
-    OUString extractPopupMenu(VclBuilder::stringmap& rMap)
-    {
-        return extractStringEntry(rMap, u"popup"_ustr);
-    }
-
     OUString extractWidgetName(VclBuilder::stringmap& rMap)
     {
         return extractStringEntry(rMap, u"name"_ustr);
@@ -3407,6 +3402,11 @@ OUString 
BuilderBase::extractLabel(VclBuilder::stringmap& rMap)
     return extractStringEntry(rMap, u"label"_ustr);
 }
 
+OUString BuilderBase::extractPopupMenu(stringmap& rMap)
+{
+    return extractStringEntry(rMap, u"popup"_ustr);
+}
+
 bool BuilderBase::extractResizable(stringmap& rMap)
 {
     return extractBoolEntry(rMap, u"resizable"_ustr, true);

Reply via email to