diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-10-30 09:54:55 +0100 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-10-30 12:08:30 +0100 |
commit | ef1eaad00f3bd2c7536c0b8bcb37f9e3201ced11 (patch) | |
tree | 0aa6e068cba6a32e5403bf7636a2c7b2bc377be5 /vcl | |
parent | af4bc7e3923c1aa7d47c050a6c3ab98523361e62 (diff) |
tdf#130857 qt weld: Add a QtInstanceProgressBar
Add a new QtInstanceProgressBar class that is
the weld::ProgressBar implementation using a native
Qt widget. The widget used is a QProgressBar.
This will be used e.g. by the print progress
dialog, for which support will be declared
in an upcoming commit.
Change-Id: Ic4b162014cd3a09801096cebd38dbdc923f5dbfa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175816
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/CustomTarget_qt5_moc.mk | 3 | ||||
-rw-r--r-- | vcl/CustomTarget_qt6_moc.mk | 1 | ||||
-rw-r--r-- | vcl/Library_vclplug_qt5.mk | 3 | ||||
-rw-r--r-- | vcl/Library_vclplug_qt6.mk | 1 | ||||
-rw-r--r-- | vcl/inc/qt5/QtInstanceBuilder.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/qt5/QtInstanceProgressBar.hxx | 32 | ||||
-rw-r--r-- | vcl/inc/qt6/QtInstanceProgressBar.hxx | 12 | ||||
-rw-r--r-- | vcl/qt5/QtBuilder.cxx | 4 | ||||
-rw-r--r-- | vcl/qt5/QtInstanceBuilder.cxx | 9 | ||||
-rw-r--r-- | vcl/qt5/QtInstanceProgressBar.cxx | 45 | ||||
-rw-r--r-- | vcl/qt6/QtInstanceProgressBar.cxx | 12 |
11 files changed, 116 insertions, 8 deletions
diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk index 7c451ea8e834..0072fa3883ad 100644 --- a/vcl/CustomTarget_qt5_moc.mk +++ b/vcl/CustomTarget_qt5_moc.mk @@ -17,10 +17,11 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceComboBox.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceDialog.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceEntry.moc \ + $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLevelBar.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLinkButton.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMessageDialog.moc \ + $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceProgressBar.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 ac1890a3d090..33e185e4c962 100644 --- a/vcl/CustomTarget_qt6_moc.mk +++ b/vcl/CustomTarget_qt6_moc.mk @@ -20,6 +20,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \ $(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/QtInstanceProgressBar.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceRadioButton.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtMainWindow.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtMenu.moc \ diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk index 66801a8041b3..a5c96989fba9 100644 --- a/vcl/Library_vclplug_qt5.mk +++ b/vcl/Library_vclplug_qt5.mk @@ -105,10 +105,11 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/QtInstanceEntry \ vcl/qt5/QtInstanceFrame \ vcl/qt5/QtInstanceImage \ + vcl/qt5/QtInstanceLabel \ vcl/qt5/QtInstanceLevelBar \ vcl/qt5/QtInstanceLinkButton \ vcl/qt5/QtInstanceMessageDialog \ - vcl/qt5/QtInstanceLabel \ + vcl/qt5/QtInstanceProgressBar \ vcl/qt5/QtInstanceRadioButton \ vcl/qt5/QtInstanceTextView \ vcl/qt5/QtInstanceWidget \ diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk index 764b6d9a9a89..4beecca87c71 100644 --- a/vcl/Library_vclplug_qt6.mk +++ b/vcl/Library_vclplug_qt6.mk @@ -108,6 +108,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\ vcl/qt6/QtInstanceLevelBar \ vcl/qt6/QtInstanceLinkButton \ vcl/qt6/QtInstanceMessageDialog \ + vcl/qt6/QtInstanceProgressBar \ vcl/qt6/QtInstanceRadioButton \ vcl/qt6/QtInstanceTextView \ vcl/qt6/QtInstanceWidget \ diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx b/vcl/inc/qt5/QtInstanceBuilder.hxx index fecea026c818..704d47a01cd8 100644 --- a/vcl/inc/qt5/QtInstanceBuilder.hxx +++ b/vcl/inc/qt5/QtInstanceBuilder.hxx @@ -50,7 +50,7 @@ public: 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; - virtual std::unique_ptr<weld::ProgressBar> weld_progress_bar(const OUString&) override; + virtual std::unique_ptr<weld::ProgressBar> weld_progress_bar(const OUString& rId) 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; diff --git a/vcl/inc/qt5/QtInstanceProgressBar.hxx b/vcl/inc/qt5/QtInstanceProgressBar.hxx new file mode 100644 index 000000000000..b6a8615ccc6f --- /dev/null +++ b/vcl/inc/qt5/QtInstanceProgressBar.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 <QtWidgets/QProgressBar> + +class QtInstanceProgressBar : public QObject, + public QtInstanceWidget, + public virtual weld::ProgressBar +{ + Q_OBJECT + + QProgressBar* m_pProgressBar; + +public: + QtInstanceProgressBar(QProgressBar* pProgressBar); + + virtual void set_percentage(int nValue) override; + virtual OUString get_text() const override; + virtual void set_text(const OUString& rText) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt6/QtInstanceProgressBar.hxx b/vcl/inc/qt6/QtInstanceProgressBar.hxx new file mode 100644 index 000000000000..5eef0213ea86 --- /dev/null +++ b/vcl/inc/qt6/QtInstanceProgressBar.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/QtInstanceProgressBar.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index 2abc2208e64f..88a26661bbad 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -207,10 +207,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, cons extractMnemonicWidget(sID, rMap); pObject = new QLabel(pParentWidget); } - else if (sName == u"GtkLevelBar") + else if (sName == u"GtkLevelBar" || sName == u"GtkProgressBar") { QProgressBar* pProgressBar = new QProgressBar(pParentWidget); - // don't show progress in percent as text + // don't show text (progress in percent) by default pProgressBar->setTextVisible(false); pObject = pProgressBar; } diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx index 5831683f11a4..9101e5509f47 100644 --- a/vcl/qt5/QtInstanceBuilder.cxx +++ b/vcl/qt5/QtInstanceBuilder.cxx @@ -21,6 +21,7 @@ #include <QtInstanceLevelBar.hxx> #include <QtInstanceLinkButton.hxx> #include <QtInstanceMessageDialog.hxx> +#include <QtInstanceProgressBar.hxx> #include <QtInstanceRadioButton.hxx> #include <QtInstanceTextView.hxx> @@ -194,10 +195,12 @@ std::unique_ptr<weld::Scale> QtInstanceBuilder::weld_scale(const OUString&) return nullptr; } -std::unique_ptr<weld::ProgressBar> QtInstanceBuilder::weld_progress_bar(const OUString&) +std::unique_ptr<weld::ProgressBar> QtInstanceBuilder::weld_progress_bar(const OUString& rId) { - assert(false && "Not implemented yet"); - return nullptr; + QProgressBar* pProgressBar = m_xBuilder->get<QProgressBar>(rId); + std::unique_ptr<weld::ProgressBar> xRet( + pProgressBar ? std::make_unique<QtInstanceProgressBar>(pProgressBar) : nullptr); + return xRet; } std::unique_ptr<weld::LevelBar> QtInstanceBuilder::weld_level_bar(const OUString& rId) diff --git a/vcl/qt5/QtInstanceProgressBar.cxx b/vcl/qt5/QtInstanceProgressBar.cxx new file mode 100644 index 000000000000..5c177d5faf52 --- /dev/null +++ b/vcl/qt5/QtInstanceProgressBar.cxx @@ -0,0 +1,45 @@ +/* -*- 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 <QtInstanceProgressBar.hxx> +#include <QtInstanceProgressBar.moc> + +#include <vcl/qt/QtUtils.hxx> + +QtInstanceProgressBar::QtInstanceProgressBar(QProgressBar* pProgressBar) + : QtInstanceWidget(pProgressBar) + , m_pProgressBar(pProgressBar) +{ + assert(pProgressBar); +} + +void QtInstanceProgressBar::set_percentage(int nValue) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pProgressBar->setValue(nValue); }); +} + +OUString QtInstanceProgressBar::get_text() const +{ + SolarMutexGuard g; + OUString sText; + GetQtInstance().RunInMainThread([&] { sText = toOUString(m_pProgressBar->text()); }); + return sText; +} + +void QtInstanceProgressBar::set_text(const OUString& rText) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { + m_pProgressBar->setFormat(toQString(rText)); + m_pProgressBar->setTextVisible(!rText.isEmpty()); + }); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt6/QtInstanceProgressBar.cxx b/vcl/qt6/QtInstanceProgressBar.cxx new file mode 100644 index 000000000000..25e0fd4685f1 --- /dev/null +++ b/vcl/qt6/QtInstanceProgressBar.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/QtInstanceProgressBar.cxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |