From ea790b37d991b6db818ff75f9d28ad10ef865810 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Thu, 7 Nov 2024 22:04:07 +0100 Subject: tdf#130857 qt weld: Add initial SpinButton support Add new class QtInstanceSpinButton that is the weld::SpinButton implementation using native widgets. Initially, implement the actual logic of only some methods, and let the others trigger an assert for now. (These can be implemented once needed to support more dialogs.) Initially, assume that the value is an integer (which is the case for the "Table" -> "Insert" -> "Rows" dialog in Writer, for which support will be declared in an upcoming commit). However, already use a QDoubleSpinBox that supports floating point values instead of QSpinBox (that can only handle integer values) to prepare for extending the implementation accordingly later. In QtBuilder, handle "GtkSpinButton" objects, create a QDoubleSpinBox for them and evaluate the "digits" and "adjustment" properties to set the corresponding values for the QDoubleSpinBox. Let QtInstanceBuilder::weld_spin_button return an instance of the newly added class. Change-Id: I0808589a3e6bece749c0ae4541f2419410ea99bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176248 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- vcl/qt5/QtBuilder.cxx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'vcl/qt5/QtBuilder.cxx') diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index 73ad72ec424b..1b219567c199 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -256,6 +256,12 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, cons pFrame->setFrameShape(bVertical ? QFrame::VLine : QFrame::HLine); pObject = pFrame; } + else if (sName == u"GtkSpinButton") + { + QDoubleSpinBox* pSpinBox = new QDoubleSpinBox(pParentWidget); + setSpinButtonProperties(*pSpinBox, rMap); + pObject = pSpinBox; + } else if (sName == u"GtkTextView") { pObject = new QPlainTextEdit(pParentWidget); @@ -557,6 +563,31 @@ void QtBuilder::setProperties(QObject* pObject, stringmap& rProps) } } +void QtBuilder::setSpinButtonProperties(QDoubleSpinBox& rSpinBox, stringmap& rProps) +{ + auto aDigitsIt = rProps.find(u"digits"_ustr); + sal_Int32 nDigits = (aDigitsIt != rProps.end()) ? aDigitsIt->second.toInt32() : 0; + rSpinBox.setDecimals(nDigits); + + auto aAdjustmentIt = rProps.find("adjustment"); + if (aAdjustmentIt != rProps.end()) + { + const Adjustment* pAdjustment = get_adjustment_by_name(aAdjustmentIt->second); + assert(pAdjustment && "referenced adjustment doesn't exist"); + for (auto const & [ rKey, rValue ] : *pAdjustment) + { + if (rKey == u"upper") + rSpinBox.setMaximum(rValue.toDouble()); + else if (rKey == u"lower") + rSpinBox.setMinimum(rValue.toDouble()); + else if (rKey == "value") + rSpinBox.setValue(rValue.toDouble()); + else if (rKey == "step-increment") + rSpinBox.setSingleStep(rValue.toDouble()); + } + } +} + QWidget* QtBuilder::windowForObject(QObject* pObject) { if (QWidget* pWidget = qobject_cast(pObject)) -- cgit