vcl/Library_vclplug_qt5.mk            |    1 
 vcl/Library_vclplug_qt6.mk            |    1 
 vcl/inc/qt5/QtInstanceBuilder.hxx     |    2 
 vcl/inc/qt5/QtInstanceCheckButton.hxx |   36 +++++++++++++++++
 vcl/inc/qt6/QtInstanceCheckButton.hxx |   12 +++++
 vcl/qt5/QtBuilder.cxx                 |   15 +++++++
 vcl/qt5/QtInstanceBuilder.cxx         |    9 ++--
 vcl/qt5/QtInstanceCheckButton.cxx     |   72 ++++++++++++++++++++++++++++++++++
 vcl/qt6/QtInstanceCheckButton.cxx     |   12 +++++
 9 files changed, 156 insertions(+), 4 deletions(-)

New commits:
commit cc7f535f1615f65ce276eb9e9d27b8a6b11aaa3a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Oct 2 17:36:21 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Oct 2 22:11:19 2024 +0200

    tdf#130857 qt weld: Add QtInstanceCheckButton
    
    Add a QtInstanceCheckButton as the native Qt
    implementation for a weld::CheckButton.
    This uses a QCheckBox.
    
    Handle the "GtkCheckButton" object type from .ui
    files in QtBuilder.
    
    This will e.g. be needed for the "Insert" -> "Axes..."
    dialog seen in Calc after a chart has been inserted
    and double-clicked -- once further
    remaining aspects needed to be able to support that dialog
    has been implemented and it will be enabled
    in QtInstanceBuilder::IsUIFileSupported.
    
    The handling for the "inconsistent" state
    is mostly based on the the VCL implementation,
    see SalInstanceCheckButton::set_inconsistent etc.
    
    QtInstanceCheckButton::QtInstanceCheckButton::set_label_wrap
    remains unimplemented for now and triggers an assert,
    can be implemented when adding support for a dialog
    that actually makes use of it.
    
    Change-Id: I1e43ba25a23312534ee7cc0e650cd6e7aae20000
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174398
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index f7c388a27ad6..b17b5d336462 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -97,6 +97,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/QtInstance_Print \
     vcl/qt5/QtInstanceBuilder \
     vcl/qt5/QtInstanceButton \
+    vcl/qt5/QtInstanceCheckButton \
     vcl/qt5/QtInstanceContainer \
     vcl/qt5/QtInstanceDialog \
     vcl/qt5/QtInstanceMessageDialog \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index 174e798d0c05..684c7d409e1f 100644
--- a/vcl/Library_vclplug_qt6.mk
+++ b/vcl/Library_vclplug_qt6.mk
@@ -96,6 +96,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\
     vcl/qt6/QtInstance_Print \
     vcl/qt6/QtInstanceBuilder \
     vcl/qt6/QtInstanceButton \
+    vcl/qt6/QtInstanceCheckButton \
     vcl/qt6/QtInstanceContainer \
     vcl/qt6/QtInstanceDialog \
     vcl/qt6/QtInstanceLabel \
diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx 
b/vcl/inc/qt5/QtInstanceBuilder.hxx
index d98c85c1dee4..ff5d9e83fc68 100644
--- a/vcl/inc/qt5/QtInstanceBuilder.hxx
+++ b/vcl/inc/qt5/QtInstanceBuilder.hxx
@@ -48,7 +48,7 @@ public:
     virtual std::unique_ptr<weld::LinkButton> weld_link_button(const 
OUString&) override;
     virtual std::unique_ptr<weld::ToggleButton> weld_toggle_button(const 
OUString&) override;
     virtual std::unique_ptr<weld::RadioButton> weld_radio_button(const 
OUString&) override;
-    virtual std::unique_ptr<weld::CheckButton> weld_check_button(const 
OUString&) 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;
     virtual std::unique_ptr<weld::ProgressBar> weld_progress_bar(const 
OUString&) override;
     virtual std::unique_ptr<weld::LevelBar> weld_level_bar(const OUString&) 
override;
diff --git a/vcl/inc/qt5/QtInstanceCheckButton.hxx 
b/vcl/inc/qt5/QtInstanceCheckButton.hxx
new file mode 100644
index 000000000000..f6dbe2ee662a
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceCheckButton.hxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 "QtInstanceWidget.hxx"
+
+#include <QtCore/QObject>
+#include <QtWidgets/QCheckBox>
+
+class QtInstanceCheckButton : public QtInstanceWidget, public virtual 
weld::CheckButton
+{
+    QCheckBox* m_pCheckBox;
+
+public:
+    QtInstanceCheckButton(QCheckBox* pCheckBox);
+
+    // weld::Toggleable methods
+    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;
+
+    // weld::CheckButton methods
+    virtual void set_label(const OUString& rText) override;
+    virtual OUString get_label() const override;
+    virtual void set_label_wrap(bool bWrap) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt6/QtInstanceCheckButton.hxx 
b/vcl/inc/qt6/QtInstanceCheckButton.hxx
new file mode 100644
index 000000000000..e2a012e235d6
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceCheckButton.hxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/QtInstanceCheckButton.hxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 6fde9cb7575e..09d445e16740 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -14,6 +14,7 @@
 
 #include <rtl/ustrbuf.hxx>
 
+#include <QtWidgets/QCheckBox>
 #include <QtWidgets/QDialog>
 #include <QtWidgets/QDialogButtonBox>
 #include <QtWidgets/QLabel>
@@ -134,6 +135,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, cons
             pObject = new QPushButton(pParentWidget);
         }
     }
+    else if (sName == u"GtkCheckButton")
+    {
+        pObject = new QCheckBox(pParentWidget);
+    }
     else if (sName == u"GtkDialog")
     {
         pObject = new QDialog(pParentWidget);
@@ -267,6 +272,16 @@ void QtBuilder::setProperties(QObject* pObject, stringmap& 
rProps)
             }
         }
     }
+    else if (QCheckBox* pCheckBox = qobject_cast<QCheckBox*>(pObject))
+    {
+        for (auto const & [ rKey, rValue ] : rProps)
+        {
+            if (rKey == u"active")
+                pCheckBox->setChecked(toBool(rValue));
+            else if (rKey == u"label")
+                pCheckBox->setText(toQString(rValue));
+        }
+    }
     else if (QDialog* pDialog = qobject_cast<QDialog*>(pObject))
     {
         for (auto const & [ rKey, rValue ] : rProps)
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 01f62ceeefd3..84ba44341790 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -12,6 +12,7 @@
 #include <unordered_set>
 
 #include <QtBuilder.hxx>
+#include <QtInstanceCheckButton.hxx>
 #include <QtInstanceLabel.hxx>
 #include <QtInstanceMessageDialog.hxx>
 
@@ -147,10 +148,12 @@ std::unique_ptr<weld::RadioButton> 
QtInstanceBuilder::weld_radio_button(const OU
     return nullptr;
 }
 
-std::unique_ptr<weld::CheckButton> QtInstanceBuilder::weld_check_button(const 
OUString&)
+std::unique_ptr<weld::CheckButton> QtInstanceBuilder::weld_check_button(const 
OUString& rId)
 {
-    assert(false && "Not implemented yet");
-    return nullptr;
+    QCheckBox* pCheckBox = m_xBuilder->get<QCheckBox>(rId);
+    std::unique_ptr<weld::CheckButton> xRet(
+        pCheckBox ? std::make_unique<QtInstanceCheckButton>(pCheckBox) : 
nullptr);
+    return xRet;
 }
 
 std::unique_ptr<weld::Scale> QtInstanceBuilder::weld_scale(const OUString&)
diff --git a/vcl/qt5/QtInstanceCheckButton.cxx 
b/vcl/qt5/QtInstanceCheckButton.cxx
new file mode 100644
index 000000000000..f30febec0120
--- /dev/null
+++ b/vcl/qt5/QtInstanceCheckButton.cxx
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <QtInstanceCheckButton.hxx>
+
+QtInstanceCheckButton::QtInstanceCheckButton(QCheckBox* pCheckBox)
+    : QtInstanceWidget(pCheckBox)
+    , m_pCheckBox(pCheckBox)
+{
+    assert(m_pCheckBox);
+}
+
+void QtInstanceCheckButton::set_active(bool bActive)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] {
+        m_pCheckBox->setTristate(false);
+        m_pCheckBox->setChecked(bActive);
+    });
+}
+
+bool QtInstanceCheckButton::get_active() const
+{
+    SolarMutexGuard g;
+    bool bActive;
+    GetQtInstance().RunInMainThread([&] { bActive = m_pCheckBox->isChecked(); 
});
+    return bActive;
+}
+
+void QtInstanceCheckButton::set_inconsistent(bool bInconsistent)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] {
+        m_pCheckBox->setTristate(true);
+        m_pCheckBox->setCheckState(bInconsistent ? Qt::PartiallyChecked : 
Qt::Unchecked);
+    });
+}
+
+bool QtInstanceCheckButton::get_inconsistent() const
+{
+    SolarMutexGuard g;
+    bool bInconsistent;
+    GetQtInstance().RunInMainThread(
+        [&] { bInconsistent = m_pCheckBox->checkState() == 
Qt::PartiallyChecked; });
+    return bInconsistent;
+}
+
+void QtInstanceCheckButton::set_label(const OUString& rText)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { 
m_pCheckBox->setText(toQString(rText)); });
+}
+OUString QtInstanceCheckButton::get_label() const
+{
+    SolarMutexGuard g;
+    OUString sLabel;
+    GetQtInstance().RunInMainThread([&] { sLabel = 
toOUString(m_pCheckBox->text()); });
+    return sLabel;
+}
+
+void QtInstanceCheckButton::QtInstanceCheckButton::set_label_wrap(bool 
/*bWrap*/)
+{
+    assert(false && "Not implemented yet");
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt6/QtInstanceCheckButton.cxx 
b/vcl/qt6/QtInstanceCheckButton.cxx
new file mode 100644
index 000000000000..9a230d9cea60
--- /dev/null
+++ b/vcl/qt6/QtInstanceCheckButton.cxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/QtInstanceCheckButton.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to