diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-09-18 10:56:51 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-10-27 11:06:24 +0000 |
commit | 6115585477bea66d90acbbd8a25b898d121bd50e (patch) | |
tree | e768a73536e7f4219c6e2b2c8eadf88fb931100f /src/quicktemplates2/qquickabstractbutton.cpp | |
parent | 960798f9117bc5aa4aa55bf868cbb0286f8e99b6 (diff) |
QQuickAbstractButton: expose the press point
This has been frequently requested to make it possible to position
context menus, for example. The initial press point is used for drag
threshold, so we need to maintain the current press point separately.
[ChangeLog][Controls][AbstractButton] Added pressX and pressY
properties.
Task-number: QTBUG-62811
Change-Id: Ibb7b9d254ccf68876d5a3049881fee29a45530e4
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickabstractbutton.cpp')
-rw-r--r-- | src/quicktemplates2/qquickabstractbutton.cpp | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index 82147c06..e5a563f9 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -192,11 +192,29 @@ QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() { } +void QQuickAbstractButtonPrivate::setPressPoint(const QPointF &point) +{ + pressPoint = point; + setMovePoint(point); +} + +void QQuickAbstractButtonPrivate::setMovePoint(const QPointF &point) +{ + Q_Q(QQuickAbstractButton); + bool xChange = !qFuzzyCompare(point.x(), movePoint.x()); + bool yChange = !qFuzzyCompare(point.y(), movePoint.y()); + movePoint = point; + if (xChange) + emit q->pressXChanged(); + if (yChange) + emit q->pressYChanged(); +} + void QQuickAbstractButtonPrivate::handlePress(const QPointF &point) { Q_Q(QQuickAbstractButton); QQuickControlPrivate::handlePress(point); - pressPoint = point; + setPressPoint(point); q->setPressed(true); emit q->pressed(); @@ -213,6 +231,7 @@ void QQuickAbstractButtonPrivate::handleMove(const QPointF &point) { Q_Q(QQuickAbstractButton); QQuickControlPrivate::handleMove(point); + setMovePoint(point); q->setPressed(keepPressed || q->contains(point)); if (!pressed && autoRepeat) @@ -226,6 +245,7 @@ void QQuickAbstractButtonPrivate::handleRelease(const QPointF &point) Q_Q(QQuickAbstractButton); QQuickControlPrivate::handleRelease(point); bool wasPressed = pressed; + setPressPoint(point); q->setPressed(false); pressButtons = Qt::NoButton; @@ -894,6 +914,40 @@ void QQuickAbstractButton::setShortcut(const QKeySequence &shortcut) #endif /*! + \readonly + \since QtQuick.Controls 2.4 (Qt 5.11) + \qmlproperty real QtQuick.Controls::AbstractButton::pressX + + This property holds the x-coordinate of the last press. + + \note The value is updated on touch moves, but left intact after touch release. + + \sa pressY +*/ +qreal QQuickAbstractButton::pressX() const +{ + Q_D(const QQuickAbstractButton); + return d->movePoint.x(); +} + +/*! + \readonly + \since QtQuick.Controls 2.4 (Qt 5.11) + \qmlproperty real QtQuick.Controls::AbstractButton::pressY + + This property holds the y-coordinate of the last press. + + \note The value is updated on touch moves, but left intact after touch release. + + \sa pressX +*/ +qreal QQuickAbstractButton::pressY() const +{ + Q_D(const QQuickAbstractButton); + return d->movePoint.y(); +} + +/*! \qmlmethod void QtQuick.Controls::AbstractButton::toggle() Toggles the checked state of the button. @@ -932,7 +986,7 @@ void QQuickAbstractButton::keyPressEvent(QKeyEvent *event) Q_D(QQuickAbstractButton); QQuickControl::keyPressEvent(event); if (event->key() == Qt::Key_Space) { - d->pressPoint = QPoint(qRound(width() / 2), qRound(height() / 2)); + d->setPressPoint(QPoint(qRound(width() / 2), qRound(height() / 2))); setPressed(true); if (d->autoRepeat) |