aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickspinbox.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-05-23 16:23:16 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2016-05-24 11:53:52 +0000
commit53eefecbaf24077367de12410d1a76a9c0ac1819 (patch)
tree5a7f8189acdba191674d55afec737b4aff0f4d36 /src/quicktemplates2/qquickspinbox.cpp
parent13786e848c102355829f4beb9112c72e46bd9a25 (diff)
SpinBox: disable up and down indicators when appropriate
Change-Id: I6fbfde582723632c9b955a6e7ee380179b7b6a32 Task-number: QTBUG-53519 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickspinbox.cpp')
-rw-r--r--src/quicktemplates2/qquickspinbox.cpp71
1 files changed, 61 insertions, 10 deletions
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp
index 2b58acf2..59f82c22 100644
--- a/src/quicktemplates2/qquickspinbox.cpp
+++ b/src/quicktemplates2/qquickspinbox.cpp
@@ -104,6 +104,11 @@ public:
int effectiveStepSize() const;
+ bool upEnabled() const;
+ void updateUpEnabled();
+ bool downEnabled() const;
+ void updateDownEnabled();
+
void startRepeatDelay();
void startPressRepeat();
void stopPressRepeat();
@@ -154,6 +159,36 @@ int QQuickSpinBoxPrivate::effectiveStepSize() const
return from > to ? -1 * stepSize : stepSize;
}
+bool QQuickSpinBoxPrivate::upEnabled() const
+{
+ const QQuickItem *upIndicator = up->indicator();
+ return upIndicator && upIndicator->isEnabled();
+}
+
+void QQuickSpinBoxPrivate::updateUpEnabled()
+{
+ QQuickItem *upIndicator = up->indicator();
+ if (!upIndicator)
+ return;
+
+ upIndicator->setEnabled(from < to ? value < to : value > to);
+}
+
+bool QQuickSpinBoxPrivate::downEnabled() const
+{
+ const QQuickItem *downIndicator = down->indicator();
+ return downIndicator && downIndicator->isEnabled();
+}
+
+void QQuickSpinBoxPrivate::updateDownEnabled()
+{
+ QQuickItem *downIndicator = down->indicator();
+ if (!downIndicator)
+ return;
+
+ downIndicator->setEnabled(from < to ? value > from : value < from);
+}
+
void QQuickSpinBoxPrivate::startRepeatDelay()
{
Q_Q(QQuickSpinBox);
@@ -186,8 +221,8 @@ bool QQuickSpinBoxPrivate::handleMousePressEvent(QQuickItem *child, QMouseEvent
Q_Q(QQuickSpinBox);
QQuickItem *ui = up->indicator();
QQuickItem *di = down->indicator();
- up->setPressed(ui && ui->contains(ui->mapFromItem(child, event->pos())));
- down->setPressed(di && di->contains(di->mapFromItem(child, event->pos())));
+ up->setPressed(ui && ui->isEnabled() && ui->contains(ui->mapFromItem(child, event->pos())));
+ down->setPressed(di && di->isEnabled() && di->contains(di->mapFromItem(child, event->pos())));
bool pressed = up->isPressed() || down->isPressed();
q->setAccessibleProperty("pressed", pressed);
@@ -201,8 +236,8 @@ bool QQuickSpinBoxPrivate::handleMouseMoveEvent(QQuickItem *child, QMouseEvent *
Q_Q(QQuickSpinBox);
QQuickItem *ui = up->indicator();
QQuickItem *di = down->indicator();
- up->setPressed(ui && ui->contains(ui->mapFromItem(child, event->pos())));
- down->setPressed(di && di->contains(di->mapFromItem(child, event->pos())));
+ up->setPressed(ui && ui->isEnabled() && ui->contains(ui->mapFromItem(child, event->pos())));
+ down->setPressed(di && di->isEnabled() && di->contains(di->mapFromItem(child, event->pos())));
bool pressed = up->isPressed() || down->isPressed();
q->setAccessibleProperty("pressed", pressed);
@@ -325,6 +360,10 @@ void QQuickSpinBox::setValue(int value)
return;
d->value = value;
+
+ d->updateUpEnabled();
+ d->updateDownEnabled();
+
emit valueChanged();
}
@@ -545,15 +584,19 @@ void QQuickSpinBox::keyPressEvent(QKeyEvent *event)
switch (event->key()) {
case Qt::Key_Up:
- increase();
- d->up->setPressed(true);
- event->accept();
+ if (d->upEnabled()) {
+ increase();
+ d->up->setPressed(true);
+ event->accept();
+ }
break;
case Qt::Key_Down:
- decrease();
- d->down->setPressed(true);
- event->accept();
+ if (d->downEnabled()) {
+ decrease();
+ d->down->setPressed(true);
+ event->accept();
+ }
break;
default:
@@ -648,6 +691,14 @@ void QQuickSpinBox::wheelEvent(QWheelEvent *event)
}
}
+void QQuickSpinBox::componentComplete()
+{
+ Q_D(QQuickSpinBox);
+ QQuickControl::componentComplete();
+ d->updateUpEnabled();
+ d->updateDownEnabled();
+}
+
void QQuickSpinBox::itemChange(ItemChange change, const ItemChangeData &value)
{
Q_D(QQuickSpinBox);