vcl/inc/qt5/QtInstanceToolbar.hxx |    3 +++
 vcl/qt5/QtBuilder.cxx             |    3 +++
 vcl/qt5/QtInstanceToolbar.cxx     |   19 +++++++++++++++++++
 3 files changed, 25 insertions(+)

New commits:
commit 3f69f711a1c3945982c5efcd79a378fb35241629
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 12 02:15:09 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Apr 12 09:11:53 2025 +0200

    tdf#130857 qt weld: Signal when tool button is clicked
    
        Change-Id: I07c406d6257912a64eeaa781edf245ad16c87862
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Sat Apr 12 00:32:01 2025 +0200
    
            tdf#130857 qt weld: Add initial tool button support
    
    implemented support for "GtkToolButton" objects in .ui files
    and inserts the created QToolButtons in the QToolBar parent
    if there is one.
    
    Build upon this and signal when one of the tool buttons
    inside a toolbar is clicked by calling weld::Toolbar::signal_clicked.
    
    Set the GtkBuilder ID as the QObject::objectName for
    all created objects in QtBuilder::makeObject.
    
    Connect to the QToolButton::clicked signal for all
    tool buttons in the toolbar, and retrieve their ID
    using the QObject::objectName to be able to notify what
    is the ID of the clicked button.
    
    In an experimental/WIP branch to support the spelling dialog
    that contains more changes, this commit results in the
    clipboard content to be pasted when clicking the corresponding
    button in the spelling dialog toolbar, and clicking the special
    characters button now results in the special character dialog
    to open as expected, while nothing would happen previously.
    
    Change-Id: I75b5136c85d4d2c44a312e55624c36a12e87dc7c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184085
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtInstanceToolbar.hxx 
b/vcl/inc/qt5/QtInstanceToolbar.hxx
index 70526fb79312..1f49ccd64c12 100644
--- a/vcl/inc/qt5/QtInstanceToolbar.hxx
+++ b/vcl/inc/qt5/QtInstanceToolbar.hxx
@@ -62,6 +62,9 @@ public:
     virtual sal_uInt16 get_modifier_state() const override;
 
     virtual int get_drop_index(const Point& rPoint) const override;
+
+private Q_SLOTS:
+    void toolButtonClicked(const QString& rId);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 84dc10b91073..1f550ab2888f 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -468,6 +468,9 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
             pParentGridLayout->addLayout(pLayout, 
pParentGridLayout->rowCount(), 0);
     }
 
+    if (pObject)
+        pObject->setObjectName(toQString(sID));
+
     if (pWidget)
         m_aWidgets[sID] = pWidget;
 
diff --git a/vcl/qt5/QtInstanceToolbar.cxx b/vcl/qt5/QtInstanceToolbar.cxx
index 69521771c0f7..825f1648ea05 100644
--- a/vcl/qt5/QtInstanceToolbar.cxx
+++ b/vcl/qt5/QtInstanceToolbar.cxx
@@ -10,11 +10,23 @@
 #include <QtInstanceToolbar.hxx>
 #include <QtInstanceToolbar.moc>
 
+#include <QtWidgets/QToolButton>
+
 QtInstanceToolbar::QtInstanceToolbar(QToolBar* pToolBar)
     : QtInstanceWidget(pToolBar)
     , m_pToolBar(pToolBar)
 {
     assert(m_pToolBar);
+
+    const QList<QAction*> aActions = m_pToolBar->actions();
+    for (QAction* pAction : aActions)
+    {
+        if (QToolButton* pButton = 
qobject_cast<QToolButton*>(m_pToolBar->widgetForAction(pAction)))
+        {
+            connect(pButton, &QToolButton::clicked, pButton,
+                    [this, pButton] { 
toolButtonClicked(pButton->objectName()); });
+        }
+    }
 }
 
 void QtInstanceToolbar::set_item_sensitive(const OUString&, bool)
@@ -189,4 +201,11 @@ int QtInstanceToolbar::get_drop_index(const Point&) const
     return -1;
 }
 
+void QtInstanceToolbar::toolButtonClicked(const QString& rId)
+{
+    SolarMutexGuard g;
+
+    signal_clicked(toOUString(rId));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to