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/QtInstanceScrollbar.hxx | 50 +++++++++++ vcl/inc/qt6/QtInstanceScrollbar.hxx | 12 ++ vcl/qt5/QtBuilder.cxx | 5 + vcl/qt5/QtInstanceBuilder.cxx | 9 +- vcl/qt5/QtInstanceScrollbar.cxx | 162 ++++++++++++++++++++++++++++++++++++ vcl/qt6/QtInstanceScrollbar.cxx | 12 ++ 11 files changed, 252 insertions(+), 4 deletions(-)
New commits: commit 7d467fab95e5814fb0cdc9a2d71af2c55fdd8d9b Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sun Mar 2 01:26:50 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Mar 2 11:52:40 2025 +0100 tdf#130857 qt weld: Introduce QtInstanceScrollbar Add new class QtInstanceScrollbar as the weld::Scrollbar implementation using a native QScrollBar. QtInstanceScrolledWindow already contains similar logic to what is needed for some of the methods. Extend QtBuilder to create a QScrollBar for "GtkScrollbar" objects. Change-Id: Iccb08659852f216df143e2d4293eead2bc9215f5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182401 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk index 9a91050a9d33..95c6b5df86da 100644 --- a/vcl/CustomTarget_qt5_moc.mk +++ b/vcl/CustomTarget_qt5_moc.mk @@ -40,6 +40,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceProgressBar.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceRadioButton.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceScale.moc \ + $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceScrollbar.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceScrolledWindow.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceSpinButton.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceTextView.moc \ diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk index 6e8a1489d0ed..1004e7756966 100644 --- a/vcl/CustomTarget_qt6_moc.mk +++ b/vcl/CustomTarget_qt6_moc.mk @@ -40,6 +40,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceProgressBar.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceRadioButton.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceScale.moc \ + $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceScrollbar.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceScrolledWindow.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceSpinButton.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceTextView.moc \ diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk index 10aa8d90842a..f254fed9ae14 100644 --- a/vcl/Library_vclplug_qt5.mk +++ b/vcl/Library_vclplug_qt5.mk @@ -126,6 +126,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/QtInstanceProgressBar \ vcl/qt5/QtInstanceRadioButton \ vcl/qt5/QtInstanceScale \ + vcl/qt5/QtInstanceScrollbar \ vcl/qt5/QtInstanceScrolledWindow \ vcl/qt5/QtInstanceSpinButton \ vcl/qt5/QtInstanceTextView \ diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk index 98ff590e92b0..74fe907cd458 100644 --- a/vcl/Library_vclplug_qt6.mk +++ b/vcl/Library_vclplug_qt6.mk @@ -125,6 +125,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\ vcl/qt6/QtInstanceProgressBar \ vcl/qt6/QtInstanceRadioButton \ vcl/qt6/QtInstanceScale \ + vcl/qt6/QtInstanceScrollbar \ vcl/qt6/QtInstanceScrolledWindow \ vcl/qt6/QtInstanceSpinButton \ vcl/qt6/QtInstanceTextView \ diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx b/vcl/inc/qt5/QtInstanceBuilder.hxx index 4625af1079d7..c01e705a22fd 100644 --- a/vcl/inc/qt5/QtInstanceBuilder.hxx +++ b/vcl/inc/qt5/QtInstanceBuilder.hxx @@ -77,7 +77,7 @@ public: virtual std::unique_ptr<weld::Menu> weld_menu(const OUString& rId) override; virtual std::unique_ptr<weld::Popover> weld_popover(const OUString& rId) override; virtual std::unique_ptr<weld::Toolbar> weld_toolbar(const OUString& rId) override; - virtual std::unique_ptr<weld::Scrollbar> weld_scrollbar(const OUString&) override; + virtual std::unique_ptr<weld::Scrollbar> weld_scrollbar(const OUString& rId) override; virtual std::unique_ptr<weld::SizeGroup> create_size_group() override; }; diff --git a/vcl/inc/qt5/QtInstanceScrollbar.hxx b/vcl/inc/qt5/QtInstanceScrollbar.hxx new file mode 100644 index 000000000000..4668fcade8a7 --- /dev/null +++ b/vcl/inc/qt5/QtInstanceScrollbar.hxx @@ -0,0 +1,50 @@ +/* -*- 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 "QtInstanceWidget.hxx" + +#include <QtWidgets/QScrollBar> + +class QtInstanceScrollbar : public QtInstanceWidget, public virtual weld::Scrollbar +{ + Q_OBJECT + + QScrollBar* m_pScrollBar; + +public: + QtInstanceScrollbar(QScrollBar* pScrollBar); + + virtual void adjustment_configure(int nValue, int nLower, int nUpper, int nStepIncrement, + int nPageIncrement, int nPageSize) override; + virtual int adjustment_get_value() const override; + virtual void adjustment_set_value(int nValue) override; + virtual int adjustment_get_upper() const override; + virtual void adjustment_set_upper(int nUpper) override; + virtual int adjustment_get_page_size() const override; + virtual void adjustment_set_page_size(int nSize) override; + virtual int adjustment_get_page_increment() const override; + virtual void adjustment_set_page_increment(int nSize) override; + virtual int adjustment_get_step_increment() const override; + virtual void adjustment_set_step_increment(int nSize) override; + virtual int adjustment_get_lower() const override; + virtual void adjustment_set_lower(int nLower) override; + + virtual int get_scroll_thickness() const override; + virtual void set_scroll_thickness(int nThickness) override; + virtual void set_scroll_swap_arrows(bool bSwap) override; + + virtual ScrollType get_scroll_type() const override; + +private Q_SLOTS: + void signalValueChanged(); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/inc/qt6/QtInstanceScrollbar.hxx b/vcl/inc/qt6/QtInstanceScrollbar.hxx new file mode 100644 index 000000000000..c4e800ef5a79 --- /dev/null +++ b/vcl/inc/qt6/QtInstanceScrollbar.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/QtInstanceScrollbar.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 476b7b942715..87a2b048f222 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -35,6 +35,7 @@ #include <QtWidgets/QPushButton> #include <QtWidgets/QRadioButton> #include <QtWidgets/QScrollArea> +#include <QtWidgets/QScrollBar> #include <QtWidgets/QSlider> #include <QtWidgets/QSplitter> #include <QtWidgets/QTabWidget> @@ -314,6 +315,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, std: extractRadioButtonGroup(sID, rMap); pObject = pRadioButton; } + else if (sName == u"GtkScrollbar") + { + pObject = new QScrollBar(pParentWidget); + } else if (sName == u"GtkScrolledWindow") { pObject = new QScrollArea(pParentWidget); diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx index 400eb9d38e3c..b1ca405766a6 100644 --- a/vcl/qt5/QtInstanceBuilder.cxx +++ b/vcl/qt5/QtInstanceBuilder.cxx @@ -35,6 +35,7 @@ #include <QtInstanceProgressBar.hxx> #include <QtInstanceRadioButton.hxx> #include <QtInstanceScale.hxx> +#include <QtInstanceScrollbar.hxx> #include <QtInstanceScrolledWindow.hxx> #include <QtInstanceSpinButton.hxx> #include <QtInstanceTextView.hxx> @@ -456,10 +457,12 @@ std::unique_ptr<weld::Toolbar> QtInstanceBuilder::weld_toolbar(const OUString& r return xRet; } -std::unique_ptr<weld::Scrollbar> QtInstanceBuilder::weld_scrollbar(const OUString&) +std::unique_ptr<weld::Scrollbar> QtInstanceBuilder::weld_scrollbar(const OUString& rId) { - assert(false && "Not implemented yet"); - return nullptr; + QScrollBar* pScrollBar = m_xBuilder->get<QScrollBar>(rId); + std::unique_ptr<weld::Scrollbar> xRet( + pScrollBar ? std::make_unique<QtInstanceScrollbar>(pScrollBar) : nullptr); + return xRet; } std::unique_ptr<weld::SizeGroup> QtInstanceBuilder::create_size_group() diff --git a/vcl/qt5/QtInstanceScrollbar.cxx b/vcl/qt5/QtInstanceScrollbar.cxx new file mode 100644 index 000000000000..c84179a7dc39 --- /dev/null +++ b/vcl/qt5/QtInstanceScrollbar.cxx @@ -0,0 +1,162 @@ +/* -*- 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 <QtInstanceScrollbar.hxx> +#include <QtInstanceScrollbar.moc> + +QtInstanceScrollbar::QtInstanceScrollbar(QScrollBar* pScrollBar) + : QtInstanceWidget(pScrollBar) + , m_pScrollBar(pScrollBar) +{ + assert(m_pScrollBar); + + connect(m_pScrollBar, &QScrollBar::valueChanged, this, + &QtInstanceScrollbar::signalValueChanged); +} + +void QtInstanceScrollbar::adjustment_configure(int, int, int, int, int, int) +{ + assert(false && "not implemented yet"); +} + +int QtInstanceScrollbar::adjustment_get_value() const +{ + SolarMutexGuard g; + + int nValue = 0; + GetQtInstance().RunInMainThread([&] { nValue = m_pScrollBar->value(); }); + + return nValue; +} + +void QtInstanceScrollbar::adjustment_set_value(int nValue) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { m_pScrollBar->setValue(nValue); }); +} + +int QtInstanceScrollbar::adjustment_get_upper() const +{ + SolarMutexGuard g; + + int nMax = 0; + GetQtInstance().RunInMainThread([&] { nMax = m_pScrollBar->maximum(); }); + + return nMax; +} + +void QtInstanceScrollbar::adjustment_set_upper(int nUpper) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { m_pScrollBar->setMaximum(nUpper); }); +} + +int QtInstanceScrollbar::adjustment_get_page_size() const +{ + assert(false && "Not implemented yet"); + return 0; +} + +void QtInstanceScrollbar::adjustment_set_page_size(int) { assert(false && "not implemented yet"); } + +int QtInstanceScrollbar::adjustment_get_page_increment() const +{ + SolarMutexGuard g; + + int nPageStep = 0; + GetQtInstance().RunInMainThread([&] { nPageStep = m_pScrollBar->pageStep(); }); + + return nPageStep; +} + +void QtInstanceScrollbar::adjustment_set_page_increment(int nSize) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { m_pScrollBar->setPageStep(nSize); }); +} + +int QtInstanceScrollbar::adjustment_get_step_increment() const +{ + SolarMutexGuard g; + + int nSingleStep = 0; + GetQtInstance().RunInMainThread([&] { nSingleStep = m_pScrollBar->singleStep(); }); + + return nSingleStep; +} + +void QtInstanceScrollbar::adjustment_set_step_increment(int nSize) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { m_pScrollBar->setSingleStep(nSize); }); +} + +int QtInstanceScrollbar::adjustment_get_lower() const +{ + SolarMutexGuard g; + + int nMin = 0; + GetQtInstance().RunInMainThread([&] { nMin = m_pScrollBar->minimum(); }); + + return nMin; +} + +void QtInstanceScrollbar::adjustment_set_lower(int nLower) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { m_pScrollBar->setMinimum(nLower); }); +} + +int QtInstanceScrollbar::get_scroll_thickness() const +{ + SolarMutexGuard g; + + int nThickness = 0; + GetQtInstance().RunInMainThread([&] { + if (m_pScrollBar->orientation() == Qt::Horizontal) + nThickness = m_pScrollBar->height(); + else + nThickness = m_pScrollBar->width(); + }); + + return nThickness; +} + +void QtInstanceScrollbar::set_scroll_thickness(int nThickness) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (m_pScrollBar->orientation() == Qt::Horizontal) + m_pScrollBar->resize(m_pScrollBar->width(), nThickness); + else + m_pScrollBar->resize(nThickness, m_pScrollBar->height()); + }); +} + +void QtInstanceScrollbar::set_scroll_swap_arrows(bool) { assert(false && "not implemented yet"); } + +ScrollType QtInstanceScrollbar::get_scroll_type() const +{ + assert(false && "not implemented yet"); + return ScrollType::DontKnow; +} + +void QtInstanceScrollbar::signalValueChanged() +{ + SolarMutexGuard g; + signal_adjustment_value_changed(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt6/QtInstanceScrollbar.cxx b/vcl/qt6/QtInstanceScrollbar.cxx new file mode 100644 index 000000000000..b271de4437ef --- /dev/null +++ b/vcl/qt6/QtInstanceScrollbar.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/QtInstanceScrollbar.cxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */