vcl/inc/qt5/QtDoubleSpinBox.hxx |    1 +
 vcl/qt5/QtDoubleSpinBox.cxx     |   14 ++++++++++++++
 2 files changed, 15 insertions(+)

New commits:
commit da5b0c93b24e6b9c73e035237ce472a519176126
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Feb 20 19:37:45 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Feb 20 23:22:55 2025 +0100

    tdf#130857 qt weld: Don't signal spinbox value/text changes while typing
    
    Disable keyboard tracking in QtDoubleSpinBox, the custom QDoubleSpinBox
    subclass used by both, QtInstanceSpinButton and
    QtInstanceFormattedSpinButton.
    
    Quoting the QAbstractSpinBox::keyboardTracking doc [1]:
    
    > This property holds whether keyboard tracking is enabled for the
    > spinbox.
    >
    > If keyboard tracking is enabled (the default), the spinbox emits the
    > valueChanged() and textChanged() signals while the new value is being
    > entered from the keyboard.
    >
    > E.g. when the user enters the value 600 by typing 6, 0, and 0, the
    > spinbox emits 3 signals with the values 6, 60, and 600 respectively.
    >
    > If keyboard tracking is disabled, the spinbox doesn't emit the
    > valueChanged() and textChanged() signals while typing. It emits the
    > signals later, when the return key is pressed, when keyboard focus is
    > lost, or when other spinbox functionality is used, e.g. pressing an
    > arrow key.
    
    Seeing where SalInstanceSpinButton calls `signal_value_changed`
    (in its `ActivateHdl`, `UpDownHdl` and `LoseFocusHdl` handlers)
    suggests that that class also doesn't emit these events while
    typing.
    And debug output in GtkInstanceSpinButton::signalValueChanged
    also suggests that that signal gets triggered when the GtkSpinButton
    loses focus for example, but not while typing.
    
    [1] https://doc.qt.io/qt-6/qabstractspinbox.html#keyboardTracking-prop
    
    Change-Id: I793b245a3848fa37880cb7d857cef160537c153e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181963
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtDoubleSpinBox.cxx b/vcl/qt5/QtDoubleSpinBox.cxx
index cf9cf3507cd6..adf8193a89f7 100644
--- a/vcl/qt5/QtDoubleSpinBox.cxx
+++ b/vcl/qt5/QtDoubleSpinBox.cxx
@@ -18,6 +18,8 @@
 QtDoubleSpinBox::QtDoubleSpinBox(QWidget* pParent)
     : QDoubleSpinBox(pParent)
 {
+    // don't notify about value/text changes while typing
+    setKeyboardTracking(false);
 }
 
 QLineEdit* QtDoubleSpinBox::lineEdit() const { return 
QDoubleSpinBox::lineEdit(); }
commit 210c69cf7aaa314f932a9debe0e64ba2789f2365
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Feb 20 19:22:52 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Feb 20 23:22:46 2025 +0100

    tdf#130857 qt weld: Implement spin button input validation
    
    Override QDoubleSpinBox::validate [1] to validate
    whether a given input text is valid.
    
    If a handler for parsing the text is set and
    it can successfully parse the text, return
    QValidator::Acceptable, otherwise
    QValidator::Intermediate (allowing to continue
    editing/typing).
    
    Without this, in the Impress "Slideshow" -> "Slideshow Settings"
    dialog, modifying the value for the "Loop and repeat after"
    spinbox wasn't possible by typing (as opposed to using the
    up/down arrow keys or buttons) at all in a WIP branch declaring
    support for that dialog, see upcoming
    
        Change-Id: I2d1552d4bc5a97da38ddb3678f20aa2a1faeb014
        Author: Michael Weghorn <m.wegh...@posteo.de>
    
            tdf#130857 qt weld: Support Impress slide show settings dialog
    
    With this change in place, at least selecting a number
    and typing another one to replace the existing one to
    change the time works.
    (Further improvements to come in another commit before
    the dialog will actually be declared supported.)
    
    [1] https://doc.qt.io/qt-6/qdoublespinbox.html#validate
    
    Change-Id: If214119799fdf32f7295cacfab51d2c8ce5ba505
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181962
    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 2ebb97c3d1e9..4e8938f86980 100644
--- a/vcl/inc/qt5/QtDoubleSpinBox.hxx
+++ b/vcl/inc/qt5/QtDoubleSpinBox.hxx
@@ -35,6 +35,7 @@ public:
 
     virtual QString textFromValue(double fValue) const override;
     virtual double valueFromText(const QString& rText) const override;
+    virtual QValidator::State validate(QString& rInput, int& rPos) const 
override;
 
     void setFormatValueFunction(std::function<std::optional<OUString>(double)> 
aFunction)
     {
diff --git a/vcl/qt5/QtDoubleSpinBox.cxx b/vcl/qt5/QtDoubleSpinBox.cxx
index 58214e7e05e5..cf9cf3507cd6 100644
--- a/vcl/qt5/QtDoubleSpinBox.cxx
+++ b/vcl/qt5/QtDoubleSpinBox.cxx
@@ -46,4 +46,16 @@ double QtDoubleSpinBox::valueFromText(const QString& rText) 
const
     return QDoubleSpinBox::valueFromText(rText);
 }
 
+QValidator::State QtDoubleSpinBox::validate(QString& rInput, int& rPos) const
+{
+    if (m_aParseTextFunction)
+    {
+        if (m_aParseTextFunction(rInput).has_value())
+            return QValidator::Acceptable;
+        return QValidator::Intermediate;
+    }
+
+    return QDoubleSpinBox::validate(rInput, rPos);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to