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/QtInstanceLevelBar.hxx |   28 ++++++++++++++++++++++++++++
 vcl/inc/qt6/QtInstanceLevelBar.hxx |   12 ++++++++++++
 vcl/qt5/QtBuilder.cxx              |    8 ++++++++
 vcl/qt5/QtInstanceBuilder.cxx      |    9 ++++++---
 vcl/qt5/QtInstanceLevelBar.cxx     |   28 ++++++++++++++++++++++++++++
 vcl/qt6/QtInstanceLevelBar.cxx     |   12 ++++++++++++
 11 files changed, 99 insertions(+), 4 deletions(-)

New commits:
commit d247f2e9e6f488893dbe575d2c6087e7b4a61bb9
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Oct 29 21:13:26 2024 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed Oct 30 09:08:17 2024 +0100

    tdf#130857 qt weld: Add a QtInstanceLevelBar
    
    Add a new QtInstanceLevelBar class that is
    the weld::LevelBar implementation using a native
    Qt widget. The widget used is a QProgressBar.
    
    This is used e.g. in password dialogs where
    the level bar is used as an indicator for the
    password strength, e.g. in Writer:
    "File" -> "Properties" -> "Security", press
    "Protect..." button.
    (But this is not using native Qt widgets yet,
    more needs to be implemented first.)
    
    Change-Id: I4400b8d1a03e8978bc96152166dec87f8134f48f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175805
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk
index 9be6abc8a399..7c451ea8e834 100644
--- a/vcl/CustomTarget_qt5_moc.mk
+++ b/vcl/CustomTarget_qt5_moc.mk
@@ -20,6 +20,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLinkButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceRadioButton.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLevelBar.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtMainWindow.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtMenu.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtTransferable.moc \
diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk
index facb45db49f7..ac1890a3d090 100644
--- a/vcl/CustomTarget_qt6_moc.mk
+++ b/vcl/CustomTarget_qt6_moc.mk
@@ -17,6 +17,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceComboBox.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceEntry.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceLevelBar.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceLinkButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceRadioButton.moc \
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index 2a8441a566b0..66801a8041b3 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -105,6 +105,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/QtInstanceEntry \
     vcl/qt5/QtInstanceFrame \
     vcl/qt5/QtInstanceImage \
+    vcl/qt5/QtInstanceLevelBar \
     vcl/qt5/QtInstanceLinkButton \
     vcl/qt5/QtInstanceMessageDialog \
     vcl/qt5/QtInstanceLabel \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index e5247de86c4e..764b6d9a9a89 100644
--- a/vcl/Library_vclplug_qt6.mk
+++ b/vcl/Library_vclplug_qt6.mk
@@ -105,6 +105,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\
     vcl/qt6/QtInstanceFrame \
     vcl/qt6/QtInstanceImage \
     vcl/qt6/QtInstanceLabel \
+    vcl/qt6/QtInstanceLevelBar \
     vcl/qt6/QtInstanceLinkButton \
     vcl/qt6/QtInstanceMessageDialog \
     vcl/qt6/QtInstanceRadioButton \
diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx 
b/vcl/inc/qt5/QtInstanceBuilder.hxx
index 6df0b81dd335..fecea026c818 100644
--- a/vcl/inc/qt5/QtInstanceBuilder.hxx
+++ b/vcl/inc/qt5/QtInstanceBuilder.hxx
@@ -51,7 +51,7 @@ public:
     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;
+    virtual std::unique_ptr<weld::LevelBar> weld_level_bar(const OUString& 
rId) override;
     virtual std::unique_ptr<weld::Spinner> weld_spinner(const OUString&) 
override;
     virtual std::unique_ptr<weld::Image> weld_image(const OUString& rId) 
override;
     virtual std::unique_ptr<weld::Calendar> weld_calendar(const OUString&) 
override;
diff --git a/vcl/inc/qt5/QtInstanceLevelBar.hxx 
b/vcl/inc/qt5/QtInstanceLevelBar.hxx
new file mode 100644
index 000000000000..46e10af34c51
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceLevelBar.hxx
@@ -0,0 +1,28 @@
+/* -*- 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 <QtWidgets/QProgressBar>
+
+class QtInstanceLevelBar : public QObject, public QtInstanceWidget, public 
virtual weld::LevelBar
+{
+    Q_OBJECT
+
+    QProgressBar* m_pProgressBar;
+
+public:
+    QtInstanceLevelBar(QProgressBar* pProgressBar);
+
+    virtual void set_percentage(double fPercentage) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt6/QtInstanceLevelBar.hxx 
b/vcl/inc/qt6/QtInstanceLevelBar.hxx
new file mode 100644
index 000000000000..fe382836663d
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceLevelBar.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/QtInstanceLevelBar.hxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 740acb951631..4d500976c160 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -25,6 +25,7 @@
 #include <QtWidgets/QLineEdit>
 #include <QtWidgets/QLayout>
 #include <QtWidgets/QPlainTextEdit>
+#include <QtWidgets/QProgressBar>
 #include <QtWidgets/QPushButton>
 #include <QtWidgets/QRadioButton>
 #include <QtWidgets/QScrollArea>
@@ -201,6 +202,13 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, cons
         extractMnemonicWidget(sID, rMap);
         pObject = new QLabel(pParentWidget);
     }
+    else if (sName == u"GtkLevelBar")
+    {
+        QProgressBar* pProgressBar = new QProgressBar(pParentWidget);
+        // don't show progress in percent as text
+        pProgressBar->setTextVisible(false);
+        pObject = pProgressBar;
+    }
     else if (sName == u"GtkLinkButton")
     {
         QtHyperlinkLabel* pLabel = new QtHyperlinkLabel(pParentWidget);
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 17e8d90d039e..891adaae9c14 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -18,6 +18,7 @@
 #include <QtInstanceFrame.hxx>
 #include <QtInstanceImage.hxx>
 #include <QtInstanceLabel.hxx>
+#include <QtInstanceLevelBar.hxx>
 #include <QtInstanceLinkButton.hxx>
 #include <QtInstanceMessageDialog.hxx>
 #include <QtInstanceRadioButton.hxx>
@@ -198,10 +199,12 @@ std::unique_ptr<weld::ProgressBar> 
QtInstanceBuilder::weld_progress_bar(const OU
     return nullptr;
 }
 
-std::unique_ptr<weld::LevelBar> QtInstanceBuilder::weld_level_bar(const 
OUString&)
+std::unique_ptr<weld::LevelBar> QtInstanceBuilder::weld_level_bar(const 
OUString& rId)
 {
-    assert(false && "Not implemented yet");
-    return nullptr;
+    QProgressBar* pProgressBar = m_xBuilder->get<QProgressBar>(rId);
+    std::unique_ptr<weld::LevelBar> xRet(
+        pProgressBar ? std::make_unique<QtInstanceLevelBar>(pProgressBar) : 
nullptr);
+    return xRet;
 }
 
 std::unique_ptr<weld::Spinner> QtInstanceBuilder::weld_spinner(const OUString&)
diff --git a/vcl/qt5/QtInstanceLevelBar.cxx b/vcl/qt5/QtInstanceLevelBar.cxx
new file mode 100644
index 000000000000..43c9039f5dcd
--- /dev/null
+++ b/vcl/qt5/QtInstanceLevelBar.cxx
@@ -0,0 +1,28 @@
+/* -*- 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 <QtInstanceLevelBar.hxx>
+#include <QtInstanceLevelBar.moc>
+
+#include <vcl/qt/QtUtils.hxx>
+
+QtInstanceLevelBar::QtInstanceLevelBar(QProgressBar* pProgressBar)
+    : QtInstanceWidget(pProgressBar)
+    , m_pProgressBar(pProgressBar)
+{
+    assert(pProgressBar);
+}
+
+void QtInstanceLevelBar::set_percentage(double fPercentage)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { 
m_pProgressBar->setValue(std::round(fPercentage)); });
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt6/QtInstanceLevelBar.cxx b/vcl/qt6/QtInstanceLevelBar.cxx
new file mode 100644
index 000000000000..5205c4200169
--- /dev/null
+++ b/vcl/qt6/QtInstanceLevelBar.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/QtInstanceLevelBar.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to