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>
This commit is contained in:
parent
ed03a08c65
commit
fff036ab4d
|
@ -141,6 +141,7 @@ void QtQuickControls2Plugin::registerTypes(const char *uri)
|
|||
qmlRegisterType<QQuickContainer,1>(uri, 2, 1, "Container");
|
||||
qmlRegisterType(selector.select(QStringLiteral("DialogButtonBox.qml")), uri, 2, 1, "DialogButtonBox");
|
||||
qmlRegisterType(selector.select(QStringLiteral("Slider.qml")), uri, 2, 1, "Slider");
|
||||
qmlRegisterType(selector.select(QStringLiteral("SpinBox.qml")), uri, 2, 1, "SpinBox");
|
||||
qmlRegisterType(selector.select(QStringLiteral("StackView.qml")), uri, 2, 1, "StackView");
|
||||
qmlRegisterType(selector.select(QStringLiteral("SwipeView.qml")), uri, 2, 1, "SwipeView");
|
||||
qmlRegisterType(selector.select(QStringLiteral("Tumbler.qml")), uri, 2, 1, "Tumbler");
|
||||
|
|
|
@ -179,6 +179,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
|
|||
qmlRegisterType<QQuickDialogButtonBox>(uri, 2, 1, "DialogButtonBox");
|
||||
qmlRegisterType<QQuickDialogButtonBoxAttached>();
|
||||
qmlRegisterType<QQuickSlider, 1>(uri, 2, 1, "Slider");
|
||||
qmlRegisterType<QQuickSpinBox, 1>(uri, 2, 1, "SpinBox");
|
||||
qmlRegisterType<QQuickStackView, 1>(uri, 2, 1, "StackView");
|
||||
qmlRegisterType<QQuickSwipeView, 1>(uri, 2, 1, "SwipeView");
|
||||
qmlRegisterType<QQuickTumbler, 1>(uri, 2, 1, "Tumbler");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -118,6 +118,9 @@ Q_SIGNALS:
|
|||
|
||||
protected:
|
||||
bool childMouseEventFilter(QQuickItem *child, QEvent *event) override;
|
||||
void hoverEnterEvent(QHoverEvent *event) override;
|
||||
void hoverMoveEvent(QHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QHoverEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void keyReleaseEvent(QKeyEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
@ -146,6 +149,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSpinButton : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL)
|
||||
Q_PROPERTY(bool hovered READ isHovered WRITE setHovered NOTIFY hoveredChanged FINAL REVISION 1)
|
||||
Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL)
|
||||
|
||||
public:
|
||||
|
@ -154,11 +158,15 @@ public:
|
|||
bool isPressed() const;
|
||||
void setPressed(bool pressed);
|
||||
|
||||
bool isHovered() const;
|
||||
void setHovered(bool hovered);
|
||||
|
||||
QQuickItem *indicator() const;
|
||||
void setIndicator(QQuickItem *indicator);
|
||||
|
||||
Q_SIGNALS:
|
||||
void pressedChanged();
|
||||
Q_REVISION(1) void hoveredChanged();
|
||||
void indicatorChanged();
|
||||
|
||||
private:
|
||||
|
|
|
@ -478,4 +478,33 @@ TestCase {
|
|||
|
||||
control.destroy()
|
||||
}
|
||||
|
||||
function test_hover_data() {
|
||||
return [
|
||||
{ tag: "up:true", button: "up", hoverEnabled: true, value: 50 },
|
||||
{ tag: "up:false", button: "up", hoverEnabled: false, value: 50 },
|
||||
{ tag: "up:max", button: "up", hoverEnabled: true, value: 99 },
|
||||
{ tag: "down:true", button: "down", hoverEnabled: true, value: 50 },
|
||||
{ tag: "down:false", button: "down", hoverEnabled: false, value: 50 },
|
||||
{ tag: "down:min", button: "down", hoverEnabled: true, value: 0 }
|
||||
]
|
||||
}
|
||||
|
||||
function test_hover(data) {
|
||||
var control = spinBox.createObject(testCase, {hoverEnabled: data.hoverEnabled, value: data.value})
|
||||
verify(control)
|
||||
|
||||
var button = control[data.button]
|
||||
compare(control.hovered, false)
|
||||
compare(button.hovered, false)
|
||||
|
||||
mouseMove(control, button.indicator.x + button.indicator.width / 2, button.indicator.y + button.indicator.height / 2)
|
||||
compare(control.hovered, data.hoverEnabled)
|
||||
compare(button.hovered, data.hoverEnabled && button.indicator.enabled)
|
||||
|
||||
mouseMove(control, button.indicator.x - 1, button.indicator.y - 1)
|
||||
compare(button.hovered, false)
|
||||
|
||||
control.destroy()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue