diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk index 2c6c566fe8ac..5674b2b64ac0 100644 --- a/vcl/CustomTarget_qt5_moc.mk +++ b/vcl/CustomTarget_qt5_moc.mk @@ -23,6 +23,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceDrawingArea.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceEntry.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceExpander.moc \ + $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceGrid.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceIconView.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceImage.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLabel.moc \ diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk index f0f37b049eef..8a6c4369bd0e 100644 --- a/vcl/CustomTarget_qt6_moc.mk +++ b/vcl/CustomTarget_qt6_moc.mk @@ -23,6 +23,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceDrawingArea.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceEntry.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceExpander.moc \ + $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceGrid.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceIconView.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceImage.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceLabel.moc \ diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk index 38a667c5d896..c2a7a9e292df 100644 --- a/vcl/Library_vclplug_qt5.mk +++ b/vcl/Library_vclplug_qt5.mk @@ -109,6 +109,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/QtInstanceEntry \ vcl/qt5/QtInstanceExpander \ vcl/qt5/QtInstanceFrame \ + vcl/qt5/QtInstanceGrid \ vcl/qt5/QtInstanceIconView \ vcl/qt5/QtInstanceImage \ vcl/qt5/QtInstanceLabel \ diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk index e6d8c893387f..3bf1f72e4058 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/QtInstanceEntry \ vcl/qt6/QtInstanceExpander \ vcl/qt6/QtInstanceFrame \ + vcl/qt6/QtInstanceGrid \ vcl/qt6/QtInstanceIconView \ vcl/qt6/QtInstanceImage \ vcl/qt6/QtInstanceLabel \ diff --git a/vcl/inc/qt5/QtInstanceContainer.hxx b/vcl/inc/qt5/QtInstanceContainer.hxx index 8fea34cd8d74..41f7e31438de 100644 --- a/vcl/inc/qt5/QtInstanceContainer.hxx +++ b/vcl/inc/qt5/QtInstanceContainer.hxx @@ -28,8 +28,8 @@ public: virtual void connect_container_focus_changed(const Link& rLink) override; -private: - QLayout& getLayout(); +protected: + virtual QLayout& getLayout() const; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/inc/qt5/QtInstanceGrid.hxx b/vcl/inc/qt5/QtInstanceGrid.hxx new file mode 100644 index 000000000000..0e0bed771b6d --- /dev/null +++ b/vcl/inc/qt5/QtInstanceGrid.hxx @@ -0,0 +1,33 @@ +/* -*- 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 "QtInstanceContainer.hxx" + +#include + +class QtInstanceGrid : public QtInstanceContainer, public virtual weld::Grid +{ + Q_OBJECT + +public: + QtInstanceGrid(QWidget* pWidget); + + virtual void set_child_left_attach(weld::Widget& rWidget, int nAttach) override; + virtual int get_child_left_attach(weld::Widget& rWidget) const override; + virtual void set_child_column_span(weld::Widget& rWidget, int nCols) override; + virtual void set_child_top_attach(weld::Widget& rWidget, int nAttach) override; + virtual int get_child_top_attach(weld::Widget& rWidget) const override; + +protected: + virtual QGridLayout& getLayout() const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/inc/qt6/QtInstanceGrid.hxx b/vcl/inc/qt6/QtInstanceGrid.hxx new file mode 100644 index 000000000000..2859bdd536bc --- /dev/null +++ b/vcl/inc/qt6/QtInstanceGrid.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/QtInstanceGrid.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx index 342986862de4..b76a0ad344d6 100644 --- a/vcl/qt5/QtInstanceBuilder.cxx +++ b/vcl/qt5/QtInstanceBuilder.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -153,10 +154,18 @@ std::unique_ptr QtInstanceBuilder::weld_box(const OUString&) return nullptr; } -std::unique_ptr QtInstanceBuilder::weld_grid(const OUString&) +std::unique_ptr QtInstanceBuilder::weld_grid(const OUString& rId) { - assert(false && "Not implemented yet"); - return nullptr; + QGridLayout* pLayout = m_xBuilder->get(rId); + if (!pLayout) + return nullptr; + + QWidget* pParentWidget = pLayout->parentWidget(); + assert(pParentWidget && pParentWidget == pLayout->parent() + && "layout has no direct widget parent"); + std::unique_ptr xRet(pParentWidget ? std::make_unique(pParentWidget) + : nullptr); + return xRet; } std::unique_ptr QtInstanceBuilder::weld_paned(const OUString&) diff --git a/vcl/qt5/QtInstanceContainer.cxx b/vcl/qt5/QtInstanceContainer.cxx index 4c2f8001f58f..a3f431444d4c 100644 --- a/vcl/qt5/QtInstanceContainer.cxx +++ b/vcl/qt5/QtInstanceContainer.cxx @@ -55,7 +55,7 @@ void QtInstanceContainer::connect_container_focus_changed(const Linklayout(); assert(pLayout); diff --git a/vcl/qt5/QtInstanceGrid.cxx b/vcl/qt5/QtInstanceGrid.cxx new file mode 100644 index 000000000000..fd882bea779a --- /dev/null +++ b/vcl/qt5/QtInstanceGrid.cxx @@ -0,0 +1,117 @@ +/* -*- 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 +#include + +QtInstanceGrid::QtInstanceGrid(QWidget* pWidget) + : QtInstanceContainer(pWidget) +{ + assert(qobject_cast(pWidget->layout()) && "no grid layout"); +} + +void QtInstanceGrid::set_child_left_attach(weld::Widget& rWidget, int nAttach) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + QWidget* pWidget = dynamic_cast(rWidget).getQWidget(); + assert(pWidget && pWidget->parentWidget() == getQWidget() + && "widget it is not a grid child"); + int nRow = 0; + int nCol = 0; + int nRowSpan = 0; + int nColSpan = 0; + getLayout().getItemPosition(getLayout().indexOf(pWidget), &nRow, &nCol, &nRowSpan, + &nColSpan); + getLayout().removeWidget(pWidget); + getLayout().addWidget(pWidget, nRow, nAttach, nRowSpan, nColSpan); + }); +} + +int QtInstanceGrid::get_child_left_attach(weld::Widget& rWidget) const +{ + SolarMutexGuard g; + + int nCol; + GetQtInstance().RunInMainThread([&] { + QWidget* pWidget = dynamic_cast(rWidget).getQWidget(); + assert(pWidget && pWidget->parentWidget() == getQWidget() + && "widget it is not a grid child"); + int nRow = 0; + int nRowSpan = 0; + int nColSpan = 0; + getLayout().getItemPosition(getLayout().indexOf(pWidget), &nRow, &nCol, &nRowSpan, + &nColSpan); + }); + return nCol; +} + +void QtInstanceGrid::set_child_column_span(weld::Widget& rWidget, int nCols) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + QWidget* pWidget = dynamic_cast(rWidget).getQWidget(); + assert(pWidget && pWidget->parentWidget() == getQWidget() + && "widget it is not a grid child"); + int nRow = 0; + int nCol = 0; + int nRowSpan = 0; + int nColSpan = 0; + getLayout().getItemPosition(getLayout().indexOf(pWidget), &nRow, &nCol, &nRowSpan, + &nColSpan); + getLayout().removeWidget(pWidget); + getLayout().addWidget(pWidget, nRow, nCol, nRowSpan, nCols); + }); +} + +void QtInstanceGrid::set_child_top_attach(weld::Widget& rWidget, int nAttach) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + QWidget* pWidget = dynamic_cast(rWidget).getQWidget(); + assert(pWidget && pWidget->parentWidget() == getQWidget() + && "widget it is not a grid child"); + int nRow = 0; + int nCol = 0; + int nRowSpan = 0; + int nColSpan = 0; + getLayout().getItemPosition(getLayout().indexOf(pWidget), &nRow, &nCol, &nRowSpan, + &nColSpan); + getLayout().removeWidget(pWidget); + getLayout().addWidget(pWidget, nAttach, nCol, nRowSpan, nColSpan); + }); +} + +int QtInstanceGrid::get_child_top_attach(weld::Widget& rWidget) const +{ + SolarMutexGuard g; + + int nRow; + GetQtInstance().RunInMainThread([&] { + QWidget* pWidget = dynamic_cast(rWidget).getQWidget(); + assert(pWidget && pWidget->parentWidget() == getQWidget() + && "widget it is not a grid child"); + int nCol = 0; + int nRowSpan = 0; + int nColSpan = 0; + getLayout().getItemPosition(getLayout().indexOf(pWidget), &nRow, &nCol, &nRowSpan, + &nColSpan); + }); + return nRow; +} + +QGridLayout& QtInstanceGrid::getLayout() const +{ + return static_cast(QtInstanceContainer::getLayout()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt6/QtInstanceGrid.cxx b/vcl/qt6/QtInstanceGrid.cxx new file mode 100644 index 000000000000..9f741c22df71 --- /dev/null +++ b/vcl/qt6/QtInstanceGrid.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/QtInstanceGrid.cxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */