tdf#130857 qt weld: Introduce QtInstanceGrid

... as the weld::Grid implementation using
native Qt widgets.

This adds an implementation of the API
newly added in

    commit 7056ea9c29
    Author: Michael Weghorn <m.weghorn@posteo.de>
    Date:   Mon Dec 16 11:02:00 2024 +0100

        weld: Add weld::Grid to handle grid child positions

Change-Id: I3db89aa9fe2986dfa7fc617440f530334d029bc6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178733
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2024-12-19 08:28:18 +01:00
parent 0e553976c2
commit fb3f9d72d1
11 changed files with 193 additions and 6 deletions
+1
View File
@@ -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 \
+1
View File
@@ -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 \
+1
View File
@@ -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 \
+1
View File
@@ -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 \
+2 -2
View File
@@ -28,8 +28,8 @@ public:
virtual void connect_container_focus_changed(const Link<Container&, void>& 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: */
+33
View File
@@ -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 <QtWidgets/QGridLayout>
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: */
+12
View File
@@ -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: */
+12 -3
View File
@@ -18,6 +18,7 @@
#include <QtInstanceEntry.hxx>
#include <QtInstanceExpander.hxx>
#include <QtInstanceFrame.hxx>
#include <QtInstanceGrid.hxx>
#include <QtInstanceImage.hxx>
#include <QtInstanceLabel.hxx>
#include <QtInstanceLevelBar.hxx>
@@ -153,10 +154,18 @@ std::unique_ptr<weld::Box> QtInstanceBuilder::weld_box(const OUString&)
return nullptr;
}
std::unique_ptr<weld::Grid> QtInstanceBuilder::weld_grid(const OUString&)
std::unique_ptr<weld::Grid> QtInstanceBuilder::weld_grid(const OUString& rId)
{
assert(false && "Not implemented yet");
return nullptr;
QGridLayout* pLayout = m_xBuilder->get<QGridLayout>(rId);
if (!pLayout)
return nullptr;
QWidget* pParentWidget = pLayout->parentWidget();
assert(pParentWidget && pParentWidget == pLayout->parent()
&& "layout has no direct widget parent");
std::unique_ptr<weld::Grid> xRet(pParentWidget ? std::make_unique<QtInstanceGrid>(pParentWidget)
: nullptr);
return xRet;
}
std::unique_ptr<weld::Paned> QtInstanceBuilder::weld_paned(const OUString&)
+1 -1
View File
@@ -55,7 +55,7 @@ void QtInstanceContainer::connect_container_focus_changed(const Link<Container&,
weld::Container::connect_container_focus_changed(rLink);
}
QLayout& QtInstanceContainer::getLayout()
QLayout& QtInstanceContainer::getLayout() const
{
QLayout* pLayout = getQWidget()->layout();
assert(pLayout);
+117
View File
@@ -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 <QtInstanceGrid.hxx>
#include <QtInstanceGrid.moc>
QtInstanceGrid::QtInstanceGrid(QWidget* pWidget)
: QtInstanceContainer(pWidget)
{
assert(qobject_cast<QGridLayout*>(pWidget->layout()) && "no grid layout");
}
void QtInstanceGrid::set_child_left_attach(weld::Widget& rWidget, int nAttach)
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] {
QWidget* pWidget = dynamic_cast<QtInstanceWidget&>(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<QtInstanceWidget&>(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<QtInstanceWidget&>(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<QtInstanceWidget&>(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<QtInstanceWidget&>(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<QGridLayout&>(QtInstanceContainer::getLayout());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
+12
View File
@@ -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: */