vcl/inc/qt5/QtBuilder.hxx | 4 ++ vcl/qt5/QtBuilder.cxx | 61 ++++++++++++++++++++++++++++++++++++++++-- vcl/qt5/QtInstanceBuilder.cxx | 1 3 files changed, 64 insertions(+), 2 deletions(-)
New commits: commit 0cfa901448b8a2b979778fd066e1eda8a729def6 Author: Michael Weghorn <[email protected]> AuthorDate: Mon Oct 21 18:42:40 2024 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Oct 22 07:16:26 2024 +0200 tdf#130857 qt weld: Declare support for "Word count" dialog Add .ui file of Writer's "Tools" -> "Word Count" dialog to the list of files supported by QtInstanceBuilder. This means that native Qt widgets are used for that dialog now by the qt5/qt6 VCL plugins, unless environment variable SAL_VCL_QT_NO_WELDED_WIDGETS=1 is set. Change-Id: Id25d0de657dfa9acbc0d71cc3a851b2eb17c6059 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175367 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx index c5aa49acbb98..83ef9656670d 100644 --- a/vcl/qt5/QtInstanceBuilder.cxx +++ b/vcl/qt5/QtInstanceBuilder.cxx @@ -39,6 +39,7 @@ bool QtInstanceBuilder::IsUIFileSupported(const OUString& rUIFile) u"modules/scalc/ui/inputstringdialog.ui"_ustr, u"modules/schart/ui/insertaxisdlg.ui"_ustr, u"modules/swriter/ui/inforeadonlydialog.ui"_ustr, + u"modules/swriter/ui/wordcount.ui"_ustr, u"sfx/ui/licensedialog.ui"_ustr, u"sfx/ui/querysavedialog.ui"_ustr, u"svt/ui/restartdialog.ui"_ustr, commit 5794432281ccc6f8d3a5659d742113ca51807c8d Author: Michael Weghorn <[email protected]> AuthorDate: Mon Oct 21 18:40:50 2024 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Oct 22 07:16:20 2024 +0200 tdf#130857 qt weld: Evaluate grid positions Implement handling for the "left-attach" and "top-attach" packing properties of "GtkGrid" children, which describe the column and row of these children within the grid. Introduce a new static helper method QtBuilder::applyGridPackingProperties that implements the handling for QWidget children for now. (Support for QLayout items within a grid will have to be added later in order to supported cases where e.g. a "GtkBox" is located inside of a "GtkGrid" in a .ui file.) In order to move the item to the proper position within the grid, first locate it to determine it's current row and column index, remove the item from the layout, and re-insert it at the new position. While this might not be the most efficient way of doing this, it is fairly easy to implement, without having to change the overall approach that QtBuilder, VclBuilder and the WidgetBuilder base currently process .ui files. This is sufficient for Writer's "Word Count" dialog, for which support will be declared in an upcoming commit. Change-Id: Ia296373c408e6cd84ffcc29b9d9a03d3c2441816 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175366 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx index 7e74f96bdfef..51a59d47a712 100644 --- a/vcl/inc/qt5/QtBuilder.hxx +++ b/vcl/inc/qt5/QtBuilder.hxx @@ -14,6 +14,7 @@ #include <QtCore/QObject> #include <QtWidgets/QDialog> #include <QtWidgets/QDialogButtonBox> +#include <QtWidgets/QGridLayout> #include <QtWidgets/QMessageBox> #include <QtWidgets/QPushButton> @@ -73,6 +74,9 @@ private: static void setProperties(QObject* obj, stringmap& rProps); static QWidget* windowForObject(QObject* pObject); static QDialogButtonBox* findButtonBox(QDialog* pDialog); + + static void applyGridPackingProperties(QObject& rCurrentChild, QGridLayout& rGrid, + const stringmap& rPackingProperties); }; template <typename T> inline T* QtBuilder::get(std::u16string_view sID) diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index b2c009c61e56..bc1241d8bd56 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -17,7 +17,6 @@ #include <QtWidgets/QCheckBox> #include <QtWidgets/QDialog> #include <QtWidgets/QDialogButtonBox> -#include <QtWidgets/QGridLayout> #include <QtWidgets/QGroupBox> #include <QtWidgets/QLabel> #include <QtWidgets/QLineEdit> @@ -291,9 +290,62 @@ void QtBuilder::applyAtkProperties(QObject* pObject, const stringmap& rPropertie } } -void QtBuilder::applyPackingProperties(QObject*, QObject*, const stringmap&) +void QtBuilder::applyGridPackingProperties(QObject& rCurrentChild, QGridLayout& rGrid, + const stringmap& rPackingProperties) { - SAL_WARN("vcl.qt", "QtBuilder::applyPackingProperties not implemented yet"); + if (!rCurrentChild.isWidgetType()) + return; + + QWidget& rCurrentWidget = static_cast<QWidget&>(rCurrentChild); + + int nCurrentRow = -1; + int nCurrentColumn = -1; + for (int i = 0; i < rGrid.rowCount(); i++) + { + for (int j = 0; j < rGrid.columnCount(); j++) + { + if (QLayoutItem* pLayoutItem = rGrid.itemAtPosition(i, j)) + { + if (pLayoutItem->widget() == &rCurrentWidget) + { + nCurrentRow = i; + nCurrentColumn = j; + break; + } + } + } + } + assert(nCurrentRow >= 0 && nCurrentColumn >= 0 && "Widget not contained in parent grid layout"); + + for (auto const & [ rKey, rValue ] : rPackingProperties) + { + if (rKey == u"left-attach") + { + const sal_Int32 nNewColumn = rValue.toInt32(); + rGrid.removeWidget(&rCurrentWidget); + rGrid.addWidget(&rCurrentWidget, nCurrentRow, nNewColumn); + nCurrentColumn = nNewColumn; + } + else if (rKey == u"top-attach") + { + const sal_Int32 nNewRow = rValue.toInt32(); + rGrid.removeWidget(&rCurrentWidget); + rGrid.addWidget(&rCurrentWidget, nNewRow, nCurrentColumn); + nCurrentRow = nNewRow; + } + } +} + +void QtBuilder::applyPackingProperties(QObject* pCurrentChild, QObject* pParent, + const stringmap& rPackingProperties) +{ + if (!pCurrentChild) + return; + + if (QGridLayout* pGrid = qobject_cast<QGridLayout*>(pParent)) + applyGridPackingProperties(*pCurrentChild, *pGrid, rPackingProperties); + else + SAL_WARN("vcl.qt", "QtBuilder::applyPackingProperties not yet implemented for this case"); } void QtBuilder::set_response(std::u16string_view sID, short nResponse) commit afb980283a9909aaecb6737018a05c891c9dc2b8 Author: Michael Weghorn <[email protected]> AuthorDate: Mon Oct 21 18:16:22 2024 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Oct 22 07:16:13 2024 +0200 tdf#130857 qt weld: Create QGridLayout for "GtkGrid" Create a QGridLayout [1] when encountering a "GtkGrid" object in a .ui file. This will be needed e.g. by Writer's "Tools" -> "Word Count" dialog. With this commit in place, adding "modules/swriter/ui/wordcount.ui" to the list of supported .ui files in QtInstanceBuilder::IsUIFileSupported would already result in each of the labels in the dialog showing up, but each one as a single row rather than they being properly arranged in rows and columns. (That will be handled in an upcoming commit.) [1] https://doc.qt.io/qt-6/qgridlayout.html Change-Id: Ib9a9de4aa2820ac7e6771acf884072768508fe59 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175365 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index 10c2c49bb6ec..b2c009c61e56 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -17,6 +17,7 @@ #include <QtWidgets/QCheckBox> #include <QtWidgets/QDialog> #include <QtWidgets/QDialogButtonBox> +#include <QtWidgets/QGridLayout> #include <QtWidgets/QGroupBox> #include <QtWidgets/QLabel> #include <QtWidgets/QLineEdit> @@ -155,6 +156,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, cons { pObject = new QGroupBox(pParentWidget); } + else if (sName == u"GtkGrid") + { + pObject = new QGridLayout(pParentWidget); + } else if (sName == u"GtkLabel") { extractMnemonicWidget(sID, rMap);
