aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickspinbox.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-06-28 14:53:11 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-06-28 18:00:13 +0000
commitfff036ab4d755bce4d1e4d1fbfb5ac1b79bf8150 (patch)
tree9679d66705fa6f3c3a21af218624fee99abb464d /src/quicktemplates2/qquickspinbox.cpp
parented03a08c65ec796288a802da1edd6ec4fbe77db2 (diff)
SpinBox: add up.hovered and down.hovered properties
The actual hover effects are coming in separate patches. [ChangeLog][SpinBox] Added up.hovered and down.hovered properties that hold whether the respective buttons are hovered. Task-number: QTBUG-50003 Change-Id: Ie47329e23326f40e4c807703ff7a97437f68deb4 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickspinbox.cpp')
-rw-r--r--src/quicktemplates2/qquickspinbox.cpp59
1 files changed, 56 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp
index b2d88d3b..634e3732 100644
--- a/src/quicktemplates2/qquickspinbox.cpp
+++ b/src/quicktemplates2/qquickspinbox.cpp
@@ -109,6 +109,7 @@ public:
void updateUpEnabled();
bool downEnabled() const;
void updateDownEnabled();
+ void updateHover(const QPointF &pos);
void startRepeatDelay();
void startPressRepeat();
@@ -190,6 +191,15 @@ void QQuickSpinBoxPrivate::updateDownEnabled()
downIndicator->setEnabled(from < to ? value > from : value < from);
}
+void QQuickSpinBoxPrivate::updateHover(const QPointF &pos)
+{
+ Q_Q(QQuickSpinBox);
+ QQuickItem *ui = up->indicator();
+ QQuickItem *di = down->indicator();
+ up->setHovered(ui && ui->isEnabled() && ui->contains(q->mapToItem(ui, pos)));
+ down->setHovered(di && di->isEnabled() && di->contains(q->mapToItem(di, pos)));
+}
+
void QQuickSpinBoxPrivate::startRepeatDelay()
{
Q_Q(QQuickSpinBox);
@@ -526,8 +536,10 @@ void QQuickSpinBox::setValueFromText(const QJSValue &callback)
\qmlpropertygroup QtQuick.Controls::SpinBox::up
\qmlproperty bool QtQuick.Controls::SpinBox::up.pressed
\qmlproperty Item QtQuick.Controls::SpinBox::up.indicator
+ \qmlproperty bool QtQuick.Controls::SpinBox::up.hovered
- These properties hold the up indicator item and whether it is pressed.
+ These properties hold the up indicator item and whether it is pressed or
+ hovered. The \c up.hovered property was introduced in QtQuick.Controls 2.1.
\sa increase()
*/
@@ -541,8 +553,10 @@ QQuickSpinButton *QQuickSpinBox::up() const
\qmlpropertygroup QtQuick.Controls::SpinBox::down
\qmlproperty bool QtQuick.Controls::SpinBox::down.pressed
\qmlproperty Item QtQuick.Controls::SpinBox::down.indicator
+ \qmlproperty bool QtQuick.Controls::SpinBox::down.hovered
- These properties hold the down indicator item and whether it is pressed.
+ These properties hold the down indicator item and whether it is pressed or
+ hovered. The \c down.hovered property was introduced in QtQuick.Controls 2.1.
\sa decrease()
*/
@@ -578,6 +592,28 @@ void QQuickSpinBox::decrease()
setValue(d->value - d->effectiveStepSize());
}
+void QQuickSpinBox::hoverEnterEvent(QHoverEvent *event)
+{
+ Q_D(QQuickSpinBox);
+ QQuickControl::hoverEnterEvent(event);
+ d->updateHover(event->posF());
+}
+
+void QQuickSpinBox::hoverMoveEvent(QHoverEvent *event)
+{
+ Q_D(QQuickSpinBox);
+ QQuickControl::hoverMoveEvent(event);
+ d->updateHover(event->posF());
+}
+
+void QQuickSpinBox::hoverLeaveEvent(QHoverEvent *event)
+{
+ Q_D(QQuickSpinBox);
+ QQuickControl::hoverLeaveEvent(event);
+ d->down->setHovered(false);
+ d->up->setHovered(false);
+}
+
void QQuickSpinBox::keyPressEvent(QKeyEvent *event)
{
Q_D(QQuickSpinBox);
@@ -730,8 +766,9 @@ QAccessible::Role QQuickSpinBox::accessibleRole() const
class QQuickSpinButtonPrivate : public QObjectPrivate
{
public:
- QQuickSpinButtonPrivate() : pressed(false), indicator(nullptr) { }
+ QQuickSpinButtonPrivate() : pressed(false), hovered(false), indicator(nullptr) { }
bool pressed;
+ bool hovered;
QQuickItem *indicator;
};
@@ -756,6 +793,22 @@ void QQuickSpinButton::setPressed(bool pressed)
emit pressedChanged();
}
+bool QQuickSpinButton::isHovered() const
+{
+ Q_D(const QQuickSpinButton);
+ return d->hovered;
+}
+
+void QQuickSpinButton::setHovered(bool hovered)
+{
+ Q_D(QQuickSpinButton);
+ if (d->hovered == hovered)
+ return;
+
+ d->hovered = hovered;
+ emit hoveredChanged();
+}
+
QQuickItem *QQuickSpinButton::indicator() const
{
Q_D(const QQuickSpinButton);