vcl/inc/qt5/QtDoubleSpinBox.hxx | 23 +++++++++++++++++++++++ vcl/qt5/QtDoubleSpinBox.cxx | 30 ++++++++++++++++++++++++++++++ vcl/qt5/QtInstanceBuilder.cxx | 1 + vcl/qt5/QtInstanceEntry.cxx | 5 ++++- vcl/qt5/QtInstanceSpinButton.cxx | 5 +++++ 5 files changed, 63 insertions(+), 1 deletion(-)
New commits: commit 1d5af8d4cd693a0ee37a592843aa971620d36358 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Feb 15 18:12:41 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Feb 16 11:12:19 2025 +0100 tdf#130857 qt weld: Support Math "Font Size" dialog Declare support for the "Format" -> "Font Size" dialog in Math. This means that native Qt widgets are used for that dialog now when using the qt5 or qt6 VCL plugin and starting LO with environment variable SAL_VCL_QT_USE_WELDED_WIDGETS=1 set. This dialog uses weld::MetricSpinButton, and is therefore the first supported dialog making use of the logic implemented in Change-Id: Ifb24da2bcf37c2a769d22d5aa33b69929ca8cb11 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Sat Feb 15 17:47:01 2025 +0100 tdf#130857 qt weld: Implement SpinButton text <-> value conversion Change-Id: Idaaa07ae3da884436af4b97fc06886098db45936 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181717 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx index d4f01952a3fd..007d6605de73 100644 --- a/vcl/qt5/QtInstanceBuilder.cxx +++ b/vcl/qt5/QtInstanceBuilder.cxx @@ -83,6 +83,7 @@ bool QtInstanceBuilder::IsUIFileSupported(const OUString& rUIFile) u"modules/scalc/ui/showsheetdialog.ui"_ustr, u"modules/schart/ui/insertaxisdlg.ui"_ustr, u"modules/smath/ui/alignmentdialog.ui"_ustr, + u"modules/smath/ui/fontsizedialog.ui"_ustr, u"modules/swriter/ui/authenticationsettingsdialog.ui"_ustr, u"modules/swriter/ui/endnotepage.ui"_ustr, u"modules/swriter/ui/footendnotedialog.ui"_ustr, commit 14d01d78ca82a57080fd9582e362b45780961540 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Feb 15 18:06:58 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Feb 16 11:12:13 2025 +0100 tdf#130857 qt weld: Demote assert in QtInstanceEntry::set_width_chars Switch the assert that the method isn't implemented to a SAL_WARN for now, to not block other Qt welding work at the moment (like adding support for the Math "Format" -> "Font Size" dialog). This method is for adjusting the size of the widget, so not having it implemented should have "only" a visual effect, while at this stage, my primary focus is on implementing missing logic and dialogs are added one at a time, so any major issues will be noted while working on adding support for them. Come back to this later. Change-Id: I65bed22716db92a04da2a41dc1966ab5635b0482 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181716 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtInstanceEntry.cxx b/vcl/qt5/QtInstanceEntry.cxx index 2228b9b67223..446e8bf71e2f 100644 --- a/vcl/qt5/QtInstanceEntry.cxx +++ b/vcl/qt5/QtInstanceEntry.cxx @@ -40,7 +40,10 @@ OUString QtInstanceEntry::get_text() const return sText; } -void QtInstanceEntry::set_width_chars(int) { assert(false && "Not implemented yet"); } +void QtInstanceEntry::set_width_chars(int) +{ + SAL_WARN("vcl.qt", "QtInstanceEntry::set_width_chars not implemented yet"); +} int QtInstanceEntry::get_width_chars() const { commit 6871b55b6915396caa3e5aca7e233f6a5efc7864 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Feb 15 17:47:01 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Feb 16 11:12:05 2025 +0100 tdf#130857 qt weld: Implement SpinButton text <-> value conversion In order to implement custom conversion between the current value of a spin box and the text to display as well as from the user-entered text to the value to use, methods QDoubleSpinBox::textFromValue [1] and QDoubleSpinBox::valueFromText [2] can be overriden. Implement these methods and use the existing methods in QtInstanceSpinButton's weld::SpinButton base class to implement the logic. In order to be able to use those in QtDoubleSpinBox, add two new members and setters for those functions, and call them in the QtInstanceSpinButton ctor. See also previous commit Change-Id: If4cd12ef947233331a5deccba5c14a15e30a30c8 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Sat Feb 15 13:44:50 2025 +0100 tdf#130857 weld: Abstract from "input"/"output" SpinButton signals and the commits mentioned therein for more background, as those commits were in preparation for this one. In a WIP branch adding support for the "Format" -> "Font Size" dialog in Math, this commit makes the text in the spin boxes show the units as expected, e.g. "12 pt", "100 %" when using SAL_VCL_QT_USE_WELDED_WIDGETS=1. (Support for that dialog will be declared in an upcoming commit.) [1] https://doc.qt.io/qt-6/qdoublespinbox.html#textFromValue [2] https://doc.qt.io/qt-6/qdoublespinbox.html#valueFromText Change-Id: Ifb24da2bcf37c2a769d22d5aa33b69929ca8cb11 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181715 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtDoubleSpinBox.hxx b/vcl/inc/qt5/QtDoubleSpinBox.hxx index 5c9cac5930d7..1eaaefe54751 100644 --- a/vcl/inc/qt5/QtDoubleSpinBox.hxx +++ b/vcl/inc/qt5/QtDoubleSpinBox.hxx @@ -9,19 +9,42 @@ #pragma once +class QtInstanceSpinButton; + +#include <rtl/ustring.hxx> +#include <tools/gen.hxx> + #include <QtWidgets/QDoubleSpinBox> #include <QtWidgets/QLineEdit> #include <QtWidgets/QWidget> +#include <optional> + class QtDoubleSpinBox : public QDoubleSpinBox { Q_OBJECT + std::function<std::optional<OUString>(int)> m_aFormatValueFunction; + std::function<TriState(const OUString&, int*)> m_aParseTextFunction; + public: QtDoubleSpinBox(QWidget* pParent); // public override of the protected base class method QLineEdit* lineEdit() const; + + virtual QString textFromValue(double fValue) const override; + virtual double valueFromText(const QString& rText) const override; + + void setFormatValueFunction(std::function<std::optional<OUString>(int)> aFunction) + { + m_aFormatValueFunction = aFunction; + } + + void setParseTextFunction(std::function<TriState(const OUString&, int*)> aFunction) + { + m_aParseTextFunction = aFunction; + } }; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt5/QtDoubleSpinBox.cxx b/vcl/qt5/QtDoubleSpinBox.cxx index 730b29919ee3..8936145984ed 100644 --- a/vcl/qt5/QtDoubleSpinBox.cxx +++ b/vcl/qt5/QtDoubleSpinBox.cxx @@ -9,6 +9,11 @@ #include <QtDoubleSpinBox.hxx> #include <QtDoubleSpinBox.moc> +#include <QtInstanceSpinButton.hxx> + +#include <QtTools.hxx> + +#include <vcl/qt/QtUtils.hxx> QtDoubleSpinBox::QtDoubleSpinBox(QWidget* pParent) : QDoubleSpinBox(pParent) @@ -17,4 +22,29 @@ QtDoubleSpinBox::QtDoubleSpinBox(QWidget* pParent) QLineEdit* QtDoubleSpinBox::lineEdit() const { return QDoubleSpinBox::lineEdit(); } +QString QtDoubleSpinBox::textFromValue(double fValue) const +{ + if (m_aFormatValueFunction) + { + std::optional<OUString> aText = m_aFormatValueFunction(std::round(fValue)); + if (aText.has_value()) + return toQString(aText.value()); + } + + return QDoubleSpinBox::textFromValue(fValue); +} + +double QtDoubleSpinBox::valueFromText(const QString& rText) const +{ + if (m_aParseTextFunction) + { + int nValue = 0; + TriState eState = m_aParseTextFunction(toOUString(rText), &nValue); + if (eState == TRISTATE_TRUE) + return nValue; + } + + return QDoubleSpinBox::valueFromText(rText); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt5/QtInstanceSpinButton.cxx b/vcl/qt5/QtInstanceSpinButton.cxx index 22b4ba401c25..936d0f2ab692 100644 --- a/vcl/qt5/QtInstanceSpinButton.cxx +++ b/vcl/qt5/QtInstanceSpinButton.cxx @@ -33,6 +33,11 @@ QtInstanceSpinButton::QtInstanceSpinButton(QtDoubleSpinBox* pSpinBox) disconnect(pSpinBox->lineEdit(), &QLineEdit::textChanged, this, nullptr); connect(m_pSpinBox, &QDoubleSpinBox::textChanged, this, &QtInstanceSpinButton::handleTextChanged); + + // set functions to convert between value and formatted text + m_pSpinBox->setFormatValueFunction([this](int nValue) { return format_value(nValue); }); + m_pSpinBox->setParseTextFunction( + [this](const OUString& rText, int* pResult) { return parse_text(rText, pResult); }); } QWidget* QtInstanceSpinButton::getQWidget() const { return m_pSpinBox; }