aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-06-22 20:59:07 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-06-22 20:59:07 +0200
commita31a5ade38ad13b699039239343f154dc1504f50 (patch)
treeb36e6b8c6d79209ac0f165a4cb1e52edaf8ce7e1 /src/quicktemplates2
parent6d9d5d41151e790f26ba59bd88d6515485326a57 (diff)
parentc11ef4ffa905ac9ba5e5af89ed03b1786b5187a8 (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/quicktemplates2/qquickspinbox.cpp tests/auto/controls/data/tst_scrollbar.qml Change-Id: Ief9481cb648076a951db0aeffaeb11aeaf392677
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickrangeslider.cpp7
-rw-r--r--src/quicktemplates2/qquickspinbox.cpp57
2 files changed, 38 insertions, 26 deletions
diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp
index c1cf13db..3c9065db 100644
--- a/src/quicktemplates2/qquickrangeslider.cpp
+++ b/src/quicktemplates2/qquickrangeslider.cpp
@@ -68,6 +68,13 @@ QT_BEGIN_NAMESPACE
}
\endcode
+ In order to perform an action when the value for a particular handle changes,
+ use the following syntax:
+
+ \code
+ first.onValueChanged: console.log("first.value changed to " + first.value)
+ \endcode
+
The \l {first.position} and \l {second.position} properties are expressed as
fractions of the control's size, in the range \c {0.0 - 1.0}.
The \l {first.visualPosition} and \l {second.visualPosition} properties are
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp
index f7458011..69b315b2 100644
--- a/src/quicktemplates2/qquickspinbox.cpp
+++ b/src/quicktemplates2/qquickspinbox.cpp
@@ -124,8 +124,10 @@ public:
int boundValue(int value, bool wrap) const;
void updateValue();
- bool setValue(int value, bool wrap);
- bool stepBy(int steps);
+ bool setValue(int value, bool wrap, bool modified);
+ bool stepBy(int steps, bool modified);
+ void increase(bool modified);
+ void decrease(bool modified);
int effectiveStepSize() const;
@@ -187,16 +189,13 @@ void QQuickSpinBoxPrivate::updateValue()
QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(engine);
QJSValue loc(v4, QQmlLocale::wrap(v4, locale));
QJSValue val = q->valueFromText().call(QJSValueList() << text.toString() << loc);
- const int oldValue = value;
- setValue(val.toInt(), /* allowWrap = */ false);
- if (oldValue != value)
- emit q->valueModified();
+ setValue(val.toInt(), /* modified = */ true, /* allowWrap = */ false);
}
}
}
}
-bool QQuickSpinBoxPrivate::setValue(int newValue, bool allowWrap)
+bool QQuickSpinBoxPrivate::setValue(int newValue, bool allowWrap, bool modified)
{
Q_Q(QQuickSpinBox);
if (q->isComponentComplete())
@@ -211,12 +210,24 @@ bool QQuickSpinBoxPrivate::setValue(int newValue, bool allowWrap)
updateDownEnabled();
emit q->valueChanged();
+ if (modified)
+ emit q->valueModified();
return true;
}
-bool QQuickSpinBoxPrivate::stepBy(int steps)
+bool QQuickSpinBoxPrivate::stepBy(int steps, bool modified)
+{
+ return setValue(value + steps, wrap, modified);
+}
+
+void QQuickSpinBoxPrivate::increase(bool modified)
+{
+ setValue(value + effectiveStepSize(), wrap, modified);
+}
+
+void QQuickSpinBoxPrivate::decrease(bool modified)
{
- return setValue(value + steps, wrap);
+ setValue(value - effectiveStepSize(), wrap, modified);
}
int QQuickSpinBoxPrivate::effectiveStepSize() const
@@ -392,7 +403,7 @@ void QQuickSpinBox::setFrom(int from)
d->from = from;
emit fromChanged();
if (isComponentComplete()) {
- if (!d->setValue(d->value, /* allowWrap = */ false)) {
+ if (!d->setValue(d->value, /* allowWrap = */ false, /* modified = */ false)) {
d->updateUpEnabled();
d->updateDownEnabled();
}
@@ -421,7 +432,7 @@ void QQuickSpinBox::setTo(int to)
d->to = to;
emit toChanged();
if (isComponentComplete()) {
- if (!d->setValue(d->value, /* allowWrap = */false)) {
+ if (!d->setValue(d->value, /* allowWrap = */false, /* modified = */ false)) {
d->updateUpEnabled();
d->updateDownEnabled();
}
@@ -442,7 +453,7 @@ int QQuickSpinBox::value() const
void QQuickSpinBox::setValue(int value)
{
Q_D(QQuickSpinBox);
- d->setValue(value, /* allowWrap = */ false);
+ d->setValue(value, /* allowWrap = */ false, /* modified = */ false);
}
/*!
@@ -751,7 +762,7 @@ void QQuickSpinBox::setWrap(bool wrap)
void QQuickSpinBox::increase()
{
Q_D(QQuickSpinBox);
- d->stepBy(d->effectiveStepSize());
+ d->increase(false);
}
/*!
@@ -764,7 +775,7 @@ void QQuickSpinBox::increase()
void QQuickSpinBox::decrease()
{
Q_D(QQuickSpinBox);
- d->stepBy(-d->effectiveStepSize());
+ d->decrease(false);
}
void QQuickSpinBox::focusInEvent(QFocusEvent *event)
@@ -804,11 +815,10 @@ void QQuickSpinBox::keyPressEvent(QKeyEvent *event)
Q_D(QQuickSpinBox);
QQuickControl::keyPressEvent(event);
- const int oldValue = d->value;
switch (event->key()) {
case Qt::Key_Up:
if (d->upEnabled()) {
- increase();
+ d->increase(true);
d->up->setPressed(true);
event->accept();
}
@@ -816,7 +826,7 @@ void QQuickSpinBox::keyPressEvent(QKeyEvent *event)
case Qt::Key_Down:
if (d->downEnabled()) {
- decrease();
+ d->decrease(true);
d->down->setPressed(true);
event->accept();
}
@@ -825,8 +835,6 @@ void QQuickSpinBox::keyPressEvent(QKeyEvent *event)
default:
break;
}
- if (d->value != oldValue)
- emit valueModified();
setAccessibleProperty("pressed", d->up->isPressed() || d->down->isPressed());
}
@@ -852,9 +860,9 @@ void QQuickSpinBox::timerEvent(QTimerEvent *event)
d->startPressRepeat();
} else if (event->timerId() == d->repeatTimer) {
if (d->up->isPressed())
- increase();
+ d->increase(true);
else if (d->down->isPressed())
- decrease();
+ d->decrease(true);
}
}
@@ -864,13 +872,10 @@ void QQuickSpinBox::wheelEvent(QWheelEvent *event)
Q_D(QQuickSpinBox);
QQuickControl::wheelEvent(event);
if (d->wheelEnabled) {
- const int oldValue = d->value;
const QPointF angle = event->angleDelta();
const qreal delta = (qFuzzyIsNull(angle.y()) ? angle.x() : angle.y()) / QWheelEvent::DefaultDeltasPerStep;
- d->stepBy(qRound(d->effectiveStepSize() * delta));
- if (d->value != oldValue)
- emit valueModified();
- event->setAccepted(d->value != oldValue);
+ if (!d->stepBy(qRound(d->effectiveStepSize() * delta), true))
+ event->ignore();
}
}
#endif