diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-29 14:27:47 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-11-29 15:19:32 +0000 |
commit | 0b189ba2eac70185f052840267572f52380e8f22 (patch) | |
tree | 89a21263e9d49e36c3f7a399823341db18751f33 /src | |
parent | b216ab66d82cd183028bffaa018566dd6d29b275 (diff) |
SpinBox: add inputMethodHints and inputMethodComposing
Needed for controlling the input method. Editors and editable ComboBox
have these also.
[ChangeLog][Controls][SpinBox] Added inputMethodHints and
inputMethodComposing properties for controlling the input
method when using editable spin boxes.
Task-number: QTBUG-56837
Change-Id: I1df21341c9a10c1baa1eaa259a5bbab7145e87c8
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/SpinBox.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/material/SpinBox.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/universal/SpinBox.qml | 2 | ||||
-rw-r--r-- | src/quicktemplates2/qquickspinbox.cpp | 58 | ||||
-rw-r--r-- | src/quicktemplates2/qquickspinbox_p.h | 9 |
5 files changed, 67 insertions, 6 deletions
diff --git a/src/imports/controls/SpinBox.qml b/src/imports/controls/SpinBox.qml index 80b19839..09d59264 100644 --- a/src/imports/controls/SpinBox.qml +++ b/src/imports/controls/SpinBox.qml @@ -76,7 +76,7 @@ T.SpinBox { readOnly: !control.editable validator: control.validator - inputMethodHints: Qt.ImhFormattedNumbersOnly + inputMethodHints: control.inputMethodHints Rectangle { x: -6 - (down.indicator ? 1 : 0) diff --git a/src/imports/controls/material/SpinBox.qml b/src/imports/controls/material/SpinBox.qml index 203a8f8d..11d0f0dc 100644 --- a/src/imports/controls/material/SpinBox.qml +++ b/src/imports/controls/material/SpinBox.qml @@ -78,7 +78,7 @@ T.SpinBox { readOnly: !control.editable validator: control.validator - inputMethodHints: Qt.ImhFormattedNumbersOnly + inputMethodHints: control.inputMethodHints } up.indicator: Item { diff --git a/src/imports/controls/universal/SpinBox.qml b/src/imports/controls/universal/SpinBox.qml index facc7bdd..3d582b89 100644 --- a/src/imports/controls/universal/SpinBox.qml +++ b/src/imports/controls/universal/SpinBox.qml @@ -79,7 +79,7 @@ T.SpinBox { readOnly: !control.editable validator: control.validator - inputMethodHints: Qt.ImhFormattedNumbersOnly + inputMethodHints: control.inputMethodHints } up.indicator: Item { diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 506405fe..829c64cc 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -43,6 +43,7 @@ #include <QtQml/qqmlinfo.h> #include <QtQml/private/qqmllocale_p.h> #include <QtQml/private/qqmlengine_p.h> +#include <QtQuick/private/qquicktextinput_p.h> QT_BEGIN_NAMESPACE @@ -98,7 +99,7 @@ class QQuickSpinBoxPrivate : public QQuickControlPrivate public: QQuickSpinBoxPrivate() : editable(false), from(0), to(99), value(0), stepSize(1), - delayTimer(0), repeatTimer(0), up(nullptr), down(nullptr), validator(nullptr) { } + delayTimer(0), repeatTimer(0), up(nullptr), down(nullptr), validator(nullptr), inputMethodHints(Qt::ImhDigitsOnly) { } int boundValue(int value) const; void updateValue(); @@ -132,6 +133,7 @@ public: QValidator *validator; mutable QJSValue textFromValue; mutable QJSValue valueFromText; + Qt::InputMethodHints inputMethodHints; }; int QQuickSpinBoxPrivate::boundValue(int value) const @@ -594,6 +596,50 @@ QQuickSpinButton *QQuickSpinBox::down() const } /*! + \since QtQuick.Controls 2.2 + \qmlproperty flags QtQuick.Controls::SpinBox::inputMethodHints + + This property provides hints to the input method about the expected content + of the spin box and how it should operate. + + The default value is \c Qt.ImhDigitsOnly. + + \include inputmethodhints.qdocinc +*/ +Qt::InputMethodHints QQuickSpinBox::inputMethodHints() const +{ + Q_D(const QQuickSpinBox); + return d->inputMethodHints; +} + +void QQuickSpinBox::setInputMethodHints(Qt::InputMethodHints hints) +{ + Q_D(QQuickSpinBox); + if (d->inputMethodHints == hints) + return; + + d->inputMethodHints = hints; + emit inputMethodHintsChanged(); +} + +/*! + \since QtQuick.Controls 2.2 + \qmlproperty bool QtQuick.Controls::SpinBox::inputMethodComposing + \readonly + + This property holds whether an editable spin box has partial text input from an input method. + + While it is composing, an input method may rely on mouse or key events from the spin box to + edit or commit the partial text. This property can be used to determine when to disable event + handlers that may interfere with the correct operation of an input method. +*/ +bool QQuickSpinBox::isInputMethodComposing() const +{ + Q_D(const QQuickSpinBox); + return d->contentItem && d->contentItem->property("inputMethodComposing").toBool(); +} + +/*! \qmlmethod void QtQuick.Controls::SpinBox::increase() Increases the value by \l stepSize, or \c 1 if stepSize is not defined. @@ -773,9 +819,15 @@ void QQuickSpinBox::itemChange(ItemChange change, const ItemChangeData &value) void QQuickSpinBox::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { - Q_UNUSED(oldItem); - if (newItem) + if (QQuickTextInput *oldInput = qobject_cast<QQuickTextInput *>(oldItem)) + disconnect(oldInput, &QQuickTextInput::inputMethodComposingChanged, this, &QQuickSpinBox::inputMethodComposingChanged); + + if (newItem) { newItem->setActiveFocusOnTab(true); + + if (QQuickTextInput *newInput = qobject_cast<QQuickTextInput *>(newItem)) + connect(newInput, &QQuickTextInput::inputMethodComposingChanged, this, &QQuickSpinBox::inputMethodComposingChanged); + } } QFont QQuickSpinBox::defaultFont() const diff --git a/src/quicktemplates2/qquickspinbox_p.h b/src/quicktemplates2/qquickspinbox_p.h index b34f81a2..c3cd7ca8 100644 --- a/src/quicktemplates2/qquickspinbox_p.h +++ b/src/quicktemplates2/qquickspinbox_p.h @@ -71,6 +71,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSpinBox : public QQuickControl Q_PROPERTY(QJSValue valueFromText READ valueFromText WRITE setValueFromText NOTIFY valueFromTextChanged FINAL) Q_PROPERTY(QQuickSpinButton *up READ up CONSTANT FINAL) Q_PROPERTY(QQuickSpinButton *down READ down CONSTANT FINAL) + Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION 2) + Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION 2) public: explicit QQuickSpinBox(QQuickItem *parent = nullptr); @@ -102,6 +104,11 @@ public: QQuickSpinButton *up() const; QQuickSpinButton *down() const; + Qt::InputMethodHints inputMethodHints() const; + void setInputMethodHints(Qt::InputMethodHints hints); + + bool isInputMethodComposing() const; + public Q_SLOTS: void increase(); void decrease(); @@ -115,6 +122,8 @@ Q_SIGNALS: void validatorChanged(); void textFromValueChanged(); void valueFromTextChanged(); + Q_REVISION(2) void inputMethodHintsChanged(); + Q_REVISION(2) void inputMethodComposingChanged(); protected: bool childMouseEventFilter(QQuickItem *child, QEvent *event) override; |