aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickdrawer.cpp150
-rw-r--r--src/quicktemplates2/qquickdrawer_p.h1
-rw-r--r--src/quicktemplates2/qquickdrawer_p_p.h2
3 files changed, 66 insertions, 87 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp
index 7ecd1558..02281d5e 100644
--- a/src/quicktemplates2/qquickdrawer.cpp
+++ b/src/quicktemplates2/qquickdrawer.cpp
@@ -333,66 +333,6 @@ bool QQuickDrawerPrivate::grabMouse(QMouseEvent *event)
static const qreal openCloseVelocityThreshold = 300;
-bool QQuickDrawerPrivate::ungrabMouse(QMouseEvent *event)
-{
- bool wasGrabbed = popupItem->keepMouseGrab();
- if (wasGrabbed) {
- const QPointF releasePoint = event->windowPos();
- velocityCalculator.stopMeasuring(releasePoint, event->timestamp());
-
- qreal velocity = 0;
- if (edge == Qt::LeftEdge || edge == Qt::RightEdge)
- velocity = velocityCalculator.velocity().x();
- else
- velocity = velocityCalculator.velocity().y();
-
- // the velocity is calculated so that swipes from left to right
- // and top to bottom have positive velocity, and swipes from right
- // to left and bottom to top have negative velocity.
- //
- // - top/left edge: positive velocity opens, negative velocity closes
- // - bottom/right edge: negative velocity opens, positive velocity closes
- //
- // => invert the velocity for bottom and right edges, for the threshold comparison below
- if (edge == Qt::RightEdge || edge == Qt::BottomEdge)
- velocity = -velocity;
-
- if (position > 0.7 || velocity > openCloseVelocityThreshold) {
- transitionManager.transitionEnter();
- } else if (position < 0.3 || velocity < -openCloseVelocityThreshold) {
- transitionManager.transitionExit();
- } else {
- switch (edge) {
- case Qt::LeftEdge:
- if (releasePoint.x() - pressPoint.x() > 0)
- transitionManager.transitionEnter();
- else
- transitionManager.transitionExit();
- break;
- case Qt::RightEdge:
- if (releasePoint.x() - pressPoint.x() < 0)
- transitionManager.transitionEnter();
- else
- transitionManager.transitionExit();
- break;
- case Qt::TopEdge:
- if (releasePoint.y() - pressPoint.y() > 0)
- transitionManager.transitionEnter();
- else
- transitionManager.transitionExit();
- break;
- case Qt::BottomEdge:
- if (releasePoint.y() - pressPoint.y() < 0)
- transitionManager.transitionEnter();
- else
- transitionManager.transitionExit();
- break;
- }
- }
- }
- return wasGrabbed;
-}
-
void QQuickDrawerPrivate::handlePress(const QPointF &point, ulong timestamp)
{
QQuickPopupPrivate::handlePress(point, timestamp);
@@ -409,7 +349,68 @@ void QQuickDrawerPrivate::handleMove(const QPointF &point, ulong timestamp)
void QQuickDrawerPrivate::handleRelease(const QPointF &point, ulong timestamp)
{
- QQuickPopupPrivate::handleRelease(point, timestamp);
+ pressPoint = QPointF();
+
+ if (!popupItem->keepMouseGrab() && !popupItem->keepTouchGrab()) {
+ velocityCalculator.reset();
+ QQuickPopupPrivate::handleRelease(point, timestamp);
+ return;
+ }
+
+ velocityCalculator.stopMeasuring(point, timestamp);
+
+ qreal velocity = 0;
+ if (edge == Qt::LeftEdge || edge == Qt::RightEdge)
+ velocity = velocityCalculator.velocity().x();
+ else
+ velocity = velocityCalculator.velocity().y();
+
+ // the velocity is calculated so that swipes from left to right
+ // and top to bottom have positive velocity, and swipes from right
+ // to left and bottom to top have negative velocity.
+ //
+ // - top/left edge: positive velocity opens, negative velocity closes
+ // - bottom/right edge: negative velocity opens, positive velocity closes
+ //
+ // => invert the velocity for bottom and right edges, for the threshold comparison below
+ if (edge == Qt::RightEdge || edge == Qt::BottomEdge)
+ velocity = -velocity;
+
+ if (position > 0.7 || velocity > openCloseVelocityThreshold) {
+ transitionManager.transitionEnter();
+ } else if (position < 0.3 || velocity < -openCloseVelocityThreshold) {
+ transitionManager.transitionExit();
+ } else {
+ switch (edge) {
+ case Qt::LeftEdge:
+ if (point.x() - pressPoint.x() > 0)
+ transitionManager.transitionEnter();
+ else
+ transitionManager.transitionExit();
+ break;
+ case Qt::RightEdge:
+ if (point.x() - pressPoint.x() < 0)
+ transitionManager.transitionEnter();
+ else
+ transitionManager.transitionExit();
+ break;
+ case Qt::TopEdge:
+ if (point.y() - pressPoint.y() > 0)
+ transitionManager.transitionEnter();
+ else
+ transitionManager.transitionExit();
+ break;
+ case Qt::BottomEdge:
+ if (point.y() - pressPoint.y() < 0)
+ transitionManager.transitionEnter();
+ else
+ transitionManager.transitionExit();
+ break;
+ }
+ }
+
+ popupItem->setKeepMouseGrab(false);
+ popupItem->setKeepTouchGrab(false);
}
void QQuickDrawerPrivate::handleUngrab()
@@ -469,19 +470,6 @@ bool QQuickDrawerPrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEvent *ev
return popupItem->keepMouseGrab();
}
-bool QQuickDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event)
-{
- const bool wasGrabbed = ungrabMouse(event);
- if (!wasGrabbed)
- handleRelease(item->mapToScene(event->localPos()), event->timestamp());
-
- popupItem->setKeepMouseGrab(false);
- pressPoint = QPoint();
- event->accept();
-
- return wasGrabbed;
-}
-
static QList<QQuickStateAction> prepareTransition(QQuickDrawer *drawer, QQuickTransition *transition, qreal to)
{
QList<QQuickStateAction> actions;
@@ -667,10 +655,12 @@ bool QQuickDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event)
case QEvent::MouseMove:
return d->handleMouseMoveEvent(child, static_cast<QMouseEvent *>(event));
case QEvent::MouseButtonRelease:
- return d->handleMouseReleaseEvent(child, static_cast<QMouseEvent *>(event));
+ d->handleMouseEvent(child, static_cast<QMouseEvent *>(event));
+ break;
default:
- return false;
+ break;
}
+ return false;
}
void QQuickDrawer::mousePressEvent(QMouseEvent *event)
@@ -685,12 +675,6 @@ void QQuickDrawer::mouseMoveEvent(QMouseEvent *event)
d->handleMouseMoveEvent(d->popupItem, event);
}
-void QQuickDrawer::mouseReleaseEvent(QMouseEvent *event)
-{
- Q_D(QQuickDrawer);
- d->handleMouseReleaseEvent(d->popupItem, event);
-}
-
bool QQuickDrawer::overlayEvent(QQuickItem *item, QEvent *event)
{
Q_D(QQuickDrawer);
@@ -707,8 +691,6 @@ bool QQuickDrawer::overlayEvent(QQuickItem *item, QEvent *event)
return d->handleMousePressEvent(item, static_cast<QMouseEvent *>(event));
case QEvent::MouseMove:
return d->handleMouseMoveEvent(item, static_cast<QMouseEvent *>(event));
- case QEvent::MouseButtonRelease:
- return d->handleMouseReleaseEvent(item, static_cast<QMouseEvent *>(event));
default:
return QQuickPopup::overlayEvent(item, event);
}
diff --git a/src/quicktemplates2/qquickdrawer_p.h b/src/quicktemplates2/qquickdrawer_p.h
index f4987e8b..74b92717 100644
--- a/src/quicktemplates2/qquickdrawer_p.h
+++ b/src/quicktemplates2/qquickdrawer_p.h
@@ -88,7 +88,6 @@ protected:
bool childMouseEventFilter(QQuickItem *child, QEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
bool overlayEvent(QQuickItem *item, QEvent *event) override;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
diff --git a/src/quicktemplates2/qquickdrawer_p_p.h b/src/quicktemplates2/qquickdrawer_p_p.h
index bb341d50..5117ef77 100644
--- a/src/quicktemplates2/qquickdrawer_p_p.h
+++ b/src/quicktemplates2/qquickdrawer_p_p.h
@@ -72,7 +72,6 @@ public:
bool startDrag(QEvent *event);
bool grabMouse(QMouseEvent *event);
- bool ungrabMouse(QMouseEvent *event);
void handlePress(const QPointF &point, ulong timestamp) override;
void handleMove(const QPointF &point, ulong timestamp) override;
@@ -81,7 +80,6 @@ public:
bool handleMousePressEvent(QQuickItem *item, QMouseEvent *event);
bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event);
- bool handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event);
bool prepareEnterTransition() override;
bool prepareExitTransition() override;