vcl/Library_vclplug_qt5.mk      |    1 
 vcl/Library_vclplug_qt6.mk      |    1 
 vcl/inc/qt5/QtInstanceLabel.hxx |   32 +++++++++++++++++++++++++
 vcl/inc/qt6/QtInstanceLabel.hxx |   12 +++++++++
 vcl/qt5/QtInstanceBuilder.cxx   |    8 +++---
 vcl/qt5/QtInstanceLabel.cxx     |   51 ++++++++++++++++++++++++++++++++++++++++
 vcl/qt6/QtInstanceLabel.cxx     |   12 +++++++++
 7 files changed, 114 insertions(+), 3 deletions(-)

New commits:
commit fd6d5c836ac4439ec44c4633353f73ebfbf97f82
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Oct 1 23:10:42 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Oct 2 07:34:29 2024 +0200

    tdf#130857 qt weld: Add initial QtInstanceLabel implementation
    
    Add a new QtInstanceLabel class as the native Qt
    weld::Label implementation and implement the
    straightforward and most important methods, and let
    the less common ones trigger an assert for now.
    
    Implement QtInstanceBuilder::weld_label to return
    an instance of QtInstanceLabel.
    
    This will e.g. be needed when adding support
    for the "Tools" -> "Word Count" dialog in Writer
    in the future, once more missing aspects have been
    implemented.
    
    Change-Id: I911bd68ad641b15883a0c6aa0707fd590fc05f96
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174366
    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 441405d851ba..f7c388a27ad6 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -100,6 +100,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/QtInstanceContainer \
     vcl/qt5/QtInstanceDialog \
     vcl/qt5/QtInstanceMessageDialog \
+    vcl/qt5/QtInstanceLabel \
     vcl/qt5/QtInstanceWidget \
     vcl/qt5/QtInstanceWindow \
     vcl/qt5/QtMainWindow \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index 67720df8c119..174e798d0c05 100644
--- a/vcl/Library_vclplug_qt6.mk
+++ b/vcl/Library_vclplug_qt6.mk
@@ -98,6 +98,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\
     vcl/qt6/QtInstanceButton \
     vcl/qt6/QtInstanceContainer \
     vcl/qt6/QtInstanceDialog \
+    vcl/qt6/QtInstanceLabel \
     vcl/qt6/QtInstanceMessageDialog \
     vcl/qt6/QtInstanceWidget \
     vcl/qt6/QtInstanceWindow \
diff --git a/vcl/inc/qt5/QtInstanceLabel.hxx b/vcl/inc/qt5/QtInstanceLabel.hxx
new file mode 100644
index 000000000000..08d30322ebac
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceLabel.hxx
@@ -0,0 +1,32 @@
+/* -*- 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/QLabel>
+
+class QtInstanceLabel : public QtInstanceWidget, public virtual weld::Label
+{
+    QLabel* m_pLabel;
+
+public:
+    QtInstanceLabel(QLabel* pLabel);
+
+    virtual void set_label(const OUString& rText) override;
+    virtual OUString get_label() const override;
+    virtual void set_mnemonic_widget(Widget* pTarget) override;
+    virtual void set_font(const vcl::Font& rFont) override;
+    virtual void set_label_type(weld::LabelType eType) override;
+    virtual void set_font_color(const Color& rColor) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt6/QtInstanceLabel.hxx b/vcl/inc/qt6/QtInstanceLabel.hxx
new file mode 100644
index 000000000000..2a67616c812c
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceLabel.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/QtInstanceLabel.hxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 4e791d771125..01f62ceeefd3 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -12,6 +12,7 @@
 #include <unordered_set>
 
 #include <QtBuilder.hxx>
+#include <QtInstanceLabel.hxx>
 #include <QtInstanceMessageDialog.hxx>
 
 QtInstanceBuilder::QtInstanceBuilder(QWidget* pParent, std::u16string_view 
sUIRoot,
@@ -239,10 +240,11 @@ std::unique_ptr<weld::IconView> 
QtInstanceBuilder::weld_icon_view(const OUString
     return nullptr;
 }
 
-std::unique_ptr<weld::Label> QtInstanceBuilder::weld_label(const OUString&)
+std::unique_ptr<weld::Label> QtInstanceBuilder::weld_label(const OUString& rId)
 {
-    assert(false && "Not implemented yet");
-    return nullptr;
+    QLabel* pLabel = m_xBuilder->get<QLabel>(rId);
+    std::unique_ptr<weld::Label> xRet(pLabel ? 
std::make_unique<QtInstanceLabel>(pLabel) : nullptr);
+    return xRet;
 }
 
 std::unique_ptr<weld::TextView> QtInstanceBuilder::weld_text_view(const 
OUString&)
diff --git a/vcl/qt5/QtInstanceLabel.cxx b/vcl/qt5/QtInstanceLabel.cxx
new file mode 100644
index 000000000000..ce0947dc3227
--- /dev/null
+++ b/vcl/qt5/QtInstanceLabel.cxx
@@ -0,0 +1,51 @@
+/* -*- 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 <QtInstanceLabel.hxx>
+
+QtInstanceLabel::QtInstanceLabel(QLabel* pLabel)
+    : QtInstanceWidget(pLabel)
+    , m_pLabel(pLabel)
+{
+    assert(m_pLabel);
+}
+
+void QtInstanceLabel::set_label(const OUString& rText)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pLabel->setText(toQString(rText)); 
});
+}
+
+OUString QtInstanceLabel::get_label() const
+{
+    SolarMutexGuard g;
+    OUString sLabel;
+    GetQtInstance().RunInMainThread([&] { sLabel = 
toOUString(m_pLabel->text()); });
+
+    return sLabel;
+}
+
+void QtInstanceLabel::set_mnemonic_widget(Widget* pTarget)
+{
+    SolarMutexGuard g;
+
+    QtInstanceWidget* pTargetWidget = dynamic_cast<QtInstanceWidget*>(pTarget);
+    if (!pTargetWidget)
+        return;
+
+    GetQtInstance().RunInMainThread([&] { 
m_pLabel->setBuddy(pTargetWidget->getQWidget()); });
+}
+
+void QtInstanceLabel::set_font(const vcl::Font&) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceLabel::set_label_type(weld::LabelType) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceLabel::set_font_color(const Color&) { assert(false && "Not 
implemented yet"); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt6/QtInstanceLabel.cxx b/vcl/qt6/QtInstanceLabel.cxx
new file mode 100644
index 000000000000..2619f8bdca17
--- /dev/null
+++ b/vcl/qt6/QtInstanceLabel.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/QtInstanceLabel.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to