vcl/CustomTarget_qt5_moc.mk            |    1 
 vcl/CustomTarget_qt6_moc.mk            |    1 
 vcl/Library_vclplug_qt5.mk             |    1 
 vcl/Library_vclplug_qt6.mk             |    1 
 vcl/inc/qt5/QtInstanceBuilder.hxx      |    2 -
 vcl/inc/qt5/QtInstanceButton.hxx       |    3 ++
 vcl/inc/qt5/QtInstanceToggleButton.hxx |   30 ++++++++++++++++++++++
 vcl/inc/qt6/QtInstanceToggleButton.hxx |   12 ++++++++
 vcl/qt5/QtBuilder.cxx                  |    5 +++
 vcl/qt5/QtInstanceBuilder.cxx          |   11 +++++---
 vcl/qt5/QtInstanceButton.cxx           |    6 ++++
 vcl/qt5/QtInstanceToggleButton.cxx     |   45 +++++++++++++++++++++++++++++++++
 vcl/qt5/QtInstanceTreeView.cxx         |   20 +++++++++++---
 vcl/qt6/QtInstanceToggleButton.cxx     |   12 ++++++++
 14 files changed, 141 insertions(+), 9 deletions(-)

New commits:
commit 67ee5fc2fdf2c1f7c16a45dfbc6e6e6618fb55ed
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Dec 19 23:08:47 2024 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Fri Dec 20 07:15:24 2024 +0100

    tdf#130857 qt weld: Implement {g,s}etting column width(s)
    
    Change-Id: I954259f1120cf3ea45eb92e5fd9e130c18ce1770
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178849
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index 8baf8d658365..f9173920e5e9 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -703,9 +703,15 @@ void QtInstanceTreeView::columns_autosize()
     });
 }
 
-void QtInstanceTreeView::set_column_fixed_widths(const std::vector<int>&)
+void QtInstanceTreeView::set_column_fixed_widths(const std::vector<int>& 
rWidths)
 {
-    assert(false && "Not implemented yet");
+    SolarMutexGuard g;
+
+    GetQtInstance().RunInMainThread([&] {
+        assert(rWidths.size() <= o3tl::make_unsigned(m_pModel->columnCount()));
+        for (size_t i = 0; i < rWidths.size(); ++i)
+            m_pTreeView->setColumnWidth(i, rWidths.at(i));
+    });
 }
 
 void QtInstanceTreeView::set_column_editables(const std::vector<bool>&)
@@ -713,10 +719,14 @@ void QtInstanceTreeView::set_column_editables(const 
std::vector<bool>&)
     assert(false && "Not implemented yet");
 }
 
-int QtInstanceTreeView::get_column_width(int) const
+int QtInstanceTreeView::get_column_width(int nCol) const
 {
-    assert(false && "Not implemented yet");
-    return 0;
+    SolarMutexGuard g;
+
+    int nWidth = 0;
+    GetQtInstance().RunInMainThread([&] { nWidth = 
m_pTreeView->columnWidth(nCol); });
+
+    return nWidth;
 }
 
 void QtInstanceTreeView::set_centered_column(int) { assert(false && "Not 
implemented yet"); }
commit feaf080065bb904473cebfe31c0caf5539172ad0
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Dec 19 22:42:04 2024 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Fri Dec 20 07:15:11 2024 +0100

    tdf#130857 qt weld: Add a QtInstanceToggleButton
    
    QAbstractButton, which is a base class for both,
    QPushButton and QToggleButton already provides the
    API needed for toggling.
    
    Use a QToggleButton, as the QPushButton doc [1] says:
    
    > As a general rule, use a push button when the application or dialog
    > window performs an action when the user clicks on it (such as Apply,
    > Cancel, Close and Help) and when the widget is supposed to have
    > a wide, rectangular shape with a text label. Small, typically square
    > buttons that change the state of the window rather than performing an
    > action (such as the buttons in the top-right corner of the QFileDialog)
    > are not command buttons, but tool buttons. Qt provides a special
    > class (QToolButton) for these buttons.
    >
    > If you need toggle behavior (see setCheckable()) or a button that
    > auto-repeats the activation signal when being pushed down like the
    > arrows in a scroll bar (see setAutoRepeat()), a command button is
    > probably not what you want. When in doubt, use a tool button.
    
    For the weld::Toggleable::{g,s}et_inconsistent overrides, it's a bit unclear
    to me what these should reasonably do for a button. Just let
    them trigger an assert for now.
    
    [1] https://doc.qt.io/qt-6/qpushbutton.html
    
    Change-Id: I51605ee02709bd78f77aeddf9c1993f930fcddd8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178848
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk
index 5674b2b64ac0..b6c6ee2b51f4 100644
--- a/vcl/CustomTarget_qt5_moc.mk
+++ b/vcl/CustomTarget_qt5_moc.mk
@@ -36,6 +36,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceScrolledWindow.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceSpinButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceTextView.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceToggleButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceTreeView.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceWidget.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceWindow.moc \
diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk
index 8a6c4369bd0e..5b1c4e351143 100644
--- a/vcl/CustomTarget_qt6_moc.mk
+++ b/vcl/CustomTarget_qt6_moc.mk
@@ -36,6 +36,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceScrolledWindow.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceSpinButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceTextView.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceToggleButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceTreeView.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceWidget.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceWindow.moc \
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index c2a7a9e292df..096cb97ae889 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -122,6 +122,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/QtInstanceScrolledWindow \
     vcl/qt5/QtInstanceSpinButton \
     vcl/qt5/QtInstanceTextView \
+    vcl/qt5/QtInstanceToggleButton \
     vcl/qt5/QtInstanceTreeView \
     vcl/qt5/QtInstanceWidget \
     vcl/qt5/QtInstanceWindow \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index 3bf1f72e4058..910d6367c899 100644
--- a/vcl/Library_vclplug_qt6.mk
+++ b/vcl/Library_vclplug_qt6.mk
@@ -121,6 +121,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\
     vcl/qt6/QtInstanceScrolledWindow \
     vcl/qt6/QtInstanceSpinButton \
     vcl/qt6/QtInstanceTextView \
+    vcl/qt6/QtInstanceToggleButton \
     vcl/qt6/QtInstanceTreeView \
     vcl/qt6/QtInstanceWidget \
     vcl/qt6/QtInstanceWindow \
diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx 
b/vcl/inc/qt5/QtInstanceBuilder.hxx
index 3380b8beb571..57fcfc34ba4f 100644
--- a/vcl/inc/qt5/QtInstanceBuilder.hxx
+++ b/vcl/inc/qt5/QtInstanceBuilder.hxx
@@ -47,7 +47,7 @@ public:
     virtual std::unique_ptr<weld::MenuToggleButton>
     weld_menu_toggle_button(const OUString&) override;
     virtual std::unique_ptr<weld::LinkButton> weld_link_button(const OUString& 
rId) override;
-    virtual std::unique_ptr<weld::ToggleButton> weld_toggle_button(const 
OUString&) override;
+    virtual std::unique_ptr<weld::ToggleButton> weld_toggle_button(const 
OUString& rId) override;
     virtual std::unique_ptr<weld::RadioButton> weld_radio_button(const 
OUString& rId) override;
     virtual std::unique_ptr<weld::CheckButton> weld_check_button(const 
OUString& rId) override;
     virtual std::unique_ptr<weld::Scale> weld_scale(const OUString&) override;
diff --git a/vcl/inc/qt5/QtInstanceButton.hxx b/vcl/inc/qt5/QtInstanceButton.hxx
index d8a285b61615..d79be468c4c0 100644
--- a/vcl/inc/qt5/QtInstanceButton.hxx
+++ b/vcl/inc/qt5/QtInstanceButton.hxx
@@ -36,6 +36,9 @@ public:
     // same result if called on the corresponding QtInstanceButton)
     static bool hasCustomClickHandler(QAbstractButton& rButton);
 
+protected:
+    QAbstractButton& getButton() const;
+
 private slots:
     void buttonClicked();
 };
diff --git a/vcl/inc/qt5/QtInstanceToggleButton.hxx 
b/vcl/inc/qt5/QtInstanceToggleButton.hxx
new file mode 100644
index 000000000000..1f7566c4cd5f
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceToggleButton.hxx
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include "QtInstanceButton.hxx"
+
+#include <QtWidgets/QAbstractButton>
+
+class QtInstanceToggleButton : public QtInstanceButton, public virtual 
weld::ToggleButton
+{
+    Q_OBJECT
+
+public:
+    QtInstanceToggleButton(QAbstractButton* pButton);
+
+    virtual void set_active(bool bActive) override;
+    virtual bool get_active() const override;
+
+    virtual void set_inconsistent(bool bInconsistent) override;
+    virtual bool get_inconsistent() const override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/inc/qt6/QtInstanceToggleButton.hxx 
b/vcl/inc/qt6/QtInstanceToggleButton.hxx
new file mode 100644
index 000000000000..83a0c7ecac77
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceToggleButton.hxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "../qt5/QtInstanceToggleButton.hxx"
+
+/* 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 24accdb4203e..9cbf6ddaf3a4 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -36,6 +36,7 @@
 #include <QtWidgets/QRadioButton>
 #include <QtWidgets/QScrollArea>
 #include <QtWidgets/QTabWidget>
+#include <QtWidgets/QToolButton>
 #include <QtWidgets/QTreeView>
 
 namespace
@@ -303,6 +304,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     {
         pObject = new QPlainTextEdit(pParentWidget);
     }
+    else if (sName == u"GtkToggleButton")
+    {
+        pObject = new QToolButton(pParentWidget);
+    }
     else if (sName == u"GtkTreeView")
     {
         QTreeView* pTreeView = new QTreeView(pParentWidget);
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index b253f53fd6a9..248c0e7a7487 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -31,8 +31,11 @@
 #include <QtInstanceScrolledWindow.hxx>
 #include <QtInstanceSpinButton.hxx>
 #include <QtInstanceTextView.hxx>
+#include <QtInstanceToggleButton.hxx>
 #include <QtInstanceTreeView.hxx>
 
+#include <QtWidgets/QToolButton>
+
 QtInstanceBuilder::QtInstanceBuilder(QWidget* pParent, std::u16string_view 
sUIRoot,
                                      const OUString& rUIFile)
     : m_xBuilder(std::make_unique<QtBuilder>(pParent, sUIRoot, rUIFile))
@@ -219,10 +222,12 @@ std::unique_ptr<weld::LinkButton> 
QtInstanceBuilder::weld_link_button(const OUSt
     return xRet;
 }
 
-std::unique_ptr<weld::ToggleButton> 
QtInstanceBuilder::weld_toggle_button(const OUString&)
+std::unique_ptr<weld::ToggleButton> 
QtInstanceBuilder::weld_toggle_button(const OUString& rId)
 {
-    assert(false && "Not implemented yet");
-    return nullptr;
+    QAbstractButton* pButton = m_xBuilder->get<QAbstractButton>(rId);
+    std::unique_ptr<weld::ToggleButton> xRet(
+        pButton ? std::make_unique<QtInstanceToggleButton>(pButton) : nullptr);
+    return xRet;
 }
 
 std::unique_ptr<weld::RadioButton> QtInstanceBuilder::weld_radio_button(const 
OUString& rId)
diff --git a/vcl/qt5/QtInstanceButton.cxx b/vcl/qt5/QtInstanceButton.cxx
index 0424062a73c1..77cd14cc1d16 100644
--- a/vcl/qt5/QtInstanceButton.cxx
+++ b/vcl/qt5/QtInstanceButton.cxx
@@ -104,6 +104,12 @@ bool 
QtInstanceButton::hasCustomClickHandler(QAbstractButton& rButton)
     return aProp.toBool();
 }
 
+QAbstractButton& QtInstanceButton::getButton() const
+{
+    assert(m_pButton);
+    return *m_pButton;
+}
+
 void QtInstanceButton::buttonClicked()
 {
     SolarMutexGuard g;
diff --git a/vcl/qt5/QtInstanceToggleButton.cxx 
b/vcl/qt5/QtInstanceToggleButton.cxx
new file mode 100644
index 000000000000..38b1c40509fd
--- /dev/null
+++ b/vcl/qt5/QtInstanceToggleButton.cxx
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <QtInstanceToggleButton.hxx>
+#include <QtInstanceToggleButton.moc>
+
+QtInstanceToggleButton::QtInstanceToggleButton(QAbstractButton* pButton)
+    : QtInstanceButton(pButton)
+{
+    assert(pButton);
+    pButton->setCheckable(true);
+}
+
+void QtInstanceToggleButton::set_active(bool bActive)
+{
+    SolarMutexGuard g;
+
+    GetQtInstance().RunInMainThread([&] { getButton().setChecked(bActive); });
+}
+
+bool QtInstanceToggleButton::get_active() const
+{
+    SolarMutexGuard g;
+
+    bool bActive = false;
+    GetQtInstance().RunInMainThread([&] { bActive = getButton().isChecked(); 
});
+
+    return bActive;
+};
+
+void QtInstanceToggleButton::set_inconsistent(bool) { assert(false && "Not 
implemented yet"); };
+
+bool QtInstanceToggleButton::get_inconsistent() const
+{
+    assert(false && "Not implemented yet");
+    return false;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt6/QtInstanceToggleButton.cxx 
b/vcl/qt6/QtInstanceToggleButton.cxx
new file mode 100644
index 000000000000..ca5f3fadf5c7
--- /dev/null
+++ b/vcl/qt6/QtInstanceToggleButton.cxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "../qt5/QtInstanceToggleButton.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to