diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-22 14:13:39 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-23 09:26:12 +0000 |
commit | 9d32fd6f446844a713d520fe02aa8c5c2104898d (patch) | |
tree | bed3c531e4651271619bec74253899f7c5af2b61 /src | |
parent | 95168d58afb13409c07375eafd6897b4097e4287 (diff) |
Add SpinBox::editable property
The default value is false, which is more mobile/embedded/touch
friendly choice, and will be also in line with ComboBox::editable
when it gets introduced sometime in the future.
Change-Id: Iaaad8f5533100c2d5c4b49d1ef8ee849cf31feff
Task-number: QTBUG-51114
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/SpinBox.qml | 1 | ||||
-rw-r--r-- | src/imports/controls/material/SpinBox.qml | 1 | ||||
-rw-r--r-- | src/imports/controls/plugins.qmltypes | 1 | ||||
-rw-r--r-- | src/imports/controls/universal/SpinBox.qml | 1 | ||||
-rw-r--r-- | src/imports/templates/plugins.qmltypes | 1 | ||||
-rw-r--r-- | src/templates/qquickspinbox.cpp | 37 | ||||
-rw-r--r-- | src/templates/qquickspinbox_p.h | 5 |
7 files changed, 41 insertions, 6 deletions
diff --git a/src/imports/controls/SpinBox.qml b/src/imports/controls/SpinBox.qml index 77f89206..d3184626 100644 --- a/src/imports/controls/SpinBox.qml +++ b/src/imports/controls/SpinBox.qml @@ -74,6 +74,7 @@ T.SpinBox { horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter + readOnly: !control.editable validator: control.validator inputMethodHints: Qt.ImhFormattedNumbersOnly } diff --git a/src/imports/controls/material/SpinBox.qml b/src/imports/controls/material/SpinBox.qml index 5d2044e6..f6aba60d 100644 --- a/src/imports/controls/material/SpinBox.qml +++ b/src/imports/controls/material/SpinBox.qml @@ -75,6 +75,7 @@ T.SpinBox { horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter + readOnly: !control.editable validator: control.validator inputMethodHints: Qt.ImhFormattedNumbersOnly } diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 62206af5..efe56ce8 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -579,6 +579,7 @@ Module { Property { name: "to"; type: "int" } Property { name: "value"; type: "int" } Property { name: "stepSize"; type: "int" } + Property { name: "editable"; type: "bool" } Property { name: "validator"; type: "QValidator"; isPointer: true } Property { name: "textFromValue"; type: "QJSValue" } Property { name: "valueFromText"; type: "QJSValue" } diff --git a/src/imports/controls/universal/SpinBox.qml b/src/imports/controls/universal/SpinBox.qml index 77eb241e..b3185452 100644 --- a/src/imports/controls/universal/SpinBox.qml +++ b/src/imports/controls/universal/SpinBox.qml @@ -80,6 +80,7 @@ T.SpinBox { verticalAlignment: TextInput.AlignVCenter renderType: Text.NativeRendering + readOnly: !control.editable validator: control.validator inputMethodHints: Qt.ImhFormattedNumbersOnly } diff --git a/src/imports/templates/plugins.qmltypes b/src/imports/templates/plugins.qmltypes index 7c0add11..05ea33ec 100644 --- a/src/imports/templates/plugins.qmltypes +++ b/src/imports/templates/plugins.qmltypes @@ -573,6 +573,7 @@ Module { Property { name: "to"; type: "int" } Property { name: "value"; type: "int" } Property { name: "stepSize"; type: "int" } + Property { name: "editable"; type: "bool" } Property { name: "validator"; type: "QValidator"; isPointer: true } Property { name: "textFromValue"; type: "QJSValue" } Property { name: "valueFromText"; type: "QJSValue" } diff --git a/src/templates/qquickspinbox.cpp b/src/templates/qquickspinbox.cpp index a0c94101..821c4fd0 100644 --- a/src/templates/qquickspinbox.cpp +++ b/src/templates/qquickspinbox.cpp @@ -61,8 +61,9 @@ static const int AUTO_REPEAT_INTERVAL = 100; \image qtlabscontrols-spinbox.png SpinBox allows the user to choose an integer value by clicking the up - or down indicator buttons, by pressing up or down on the keyboard, or - by entering a text value in the input field. + or down indicator buttons, or by pressing up or down on the keyboard. + Optionally, SpinBox can be also made \l editable, so the user can enter + a text value in the input field. By default, SpinBox provides discrete values in the range of \c [0-99] with a \l stepSize of \c 1. @@ -90,7 +91,7 @@ class QQuickSpinBoxPrivate : public QQuickControlPrivate Q_DECLARE_PUBLIC(QQuickSpinBox) public: - QQuickSpinBoxPrivate() : from(0), to(99), value(0), stepSize(1), + QQuickSpinBoxPrivate() : editable(false), from(0), to(99), value(0), stepSize(1), delayTimer(0), repeatTimer(0), up(nullptr), down(nullptr), validator(nullptr) { } int boundValue(int value) const; @@ -107,6 +108,7 @@ public: bool handleMouseReleaseEvent(QQuickItem *child, QMouseEvent *event); bool handleMouseUngrabEvent(QQuickItem *child); + bool editable; int from; int to; int value; @@ -342,14 +344,37 @@ void QQuickSpinBox::setStepSize(int step) } /*! + \qmlproperty bool Qt.labs.controls::SpinBox::editable + + This property holds whether the spinbox is editable. The default value is \c false. + + \sa validator +*/ +bool QQuickSpinBox::isEditable() const +{ + Q_D(const QQuickSpinBox); + return d->editable; +} + +void QQuickSpinBox::setEditable(bool editable) +{ + Q_D(QQuickSpinBox); + if (d->editable == editable) + return; + + d->editable = editable; + emit editableChanged(); +} + +/*! \qmlproperty Validator Qt.labs.controls::SpinBox::validator - This property holds the input text validator. By default, SpinBox uses - \l IntValidator to accept input of integer numbers. + This property holds the input text validator for editable spinboxes. By + default, SpinBox uses \l IntValidator to accept input of integer numbers. \snippet SpinBox.qml validator - \sa textFromValue, valueFromText, {Control::locale}{locale} + \sa editable, textFromValue, valueFromText, {Control::locale}{locale} */ QValidator *QQuickSpinBox::validator() const { diff --git a/src/templates/qquickspinbox_p.h b/src/templates/qquickspinbox_p.h index 831c73c2..67a1772c 100644 --- a/src/templates/qquickspinbox_p.h +++ b/src/templates/qquickspinbox_p.h @@ -65,6 +65,7 @@ class Q_LABSTEMPLATES_EXPORT QQuickSpinBox : public QQuickControl Q_PROPERTY(int to READ to WRITE setTo NOTIFY toChanged FINAL) Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged FINAL) Q_PROPERTY(int stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) + Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL) Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL) Q_PROPERTY(QJSValue textFromValue READ textFromValue WRITE setTextFromValue NOTIFY textFromValueChanged FINAL) Q_PROPERTY(QJSValue valueFromText READ valueFromText WRITE setValueFromText NOTIFY valueFromTextChanged FINAL) @@ -86,6 +87,9 @@ public: int stepSize() const; void setStepSize(int step); + bool isEditable() const; + void setEditable(bool editable); + QValidator *validator() const; void setValidator(QValidator *validator); @@ -107,6 +111,7 @@ Q_SIGNALS: void toChanged(); void valueChanged(); void stepSizeChanged(); + void editableChanged(); void validatorChanged(); void textFromValueChanged(); void valueFromTextChanged(); |