aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/widgets/mphysics2dpanning.cpp
diff options
context:
space:
mode:
authorMichal Guminiak <michal.guminiak@teleca.com>2010-05-04 13:23:20 +0200
committerDaniel d'Andrada <daniel.dandrada@nokia.com>2010-05-05 14:02:45 +0300
commitf337af5a105323b64e950b9ac546d1f87ff35aa2 (patch)
tree8129683e199c63cfafee3098b94d1b5f21b9ea19 /src/corelib/widgets/mphysics2dpanning.cpp
parent616942c1cf8cd5e7faf92f74445673b63943b135 (diff)
Fixes: NB#160502 Ability to disable physics
RevBy: Daniel d'Andrada Details: This patch adds the posibility to disable the kinetic scrolling of the physics engine. When this is done, the page is scrollable but there is no sliding when the pointer is released.
Diffstat (limited to 'src/corelib/widgets/mphysics2dpanning.cpp')
-rw-r--r--src/corelib/widgets/mphysics2dpanning.cpp57
1 files changed, 52 insertions, 5 deletions
diff --git a/src/corelib/widgets/mphysics2dpanning.cpp b/src/corelib/widgets/mphysics2dpanning.cpp
index 85f7eb3a..2f9ec2aa 100644
--- a/src/corelib/widgets/mphysics2dpanning.cpp
+++ b/src/corelib/widgets/mphysics2dpanning.cpp
@@ -28,6 +28,7 @@ static const int PanningTimelineInterval = 20; /* in ms */
static const int PositionNoiseDampingDelta = 2; /* in px */
MPhysics2DPanningPrivate::MPhysics2DPanningPrivate(MPhysics2DPanning *publicObject) :
+ enabled(true),
range(QRectF(0.0, 0.0, 0.0, 0.0)),
posX(0.0),
posY(0.0),
@@ -143,6 +144,19 @@ MPhysics2DPanning::~MPhysics2DPanning()
delete d_ptr;
}
+bool MPhysics2DPanning::enabled() const
+{
+ return d_ptr->enabled;
+}
+
+void MPhysics2DPanning::setEnabled(bool enabled)
+{
+ Q_D(MPhysics2DPanning);
+
+ d->enabled = enabled;
+ if (d->enabled == false) stop();
+}
+
Qt::Orientations MPhysics2DPanning::panDirection() const
{
return d_ptr->panDirection;
@@ -319,14 +333,43 @@ void MPhysics2DPanning::pointerMove(const QPointF &pos)
Q_D(MPhysics2DPanning);
// Tenses the pointer spring with the amount of movement of the pointer
-
QPointF delta = pos - d->sceneLastPos;
d->sceneLastPos = pos;
- d->pointerSpringX += delta.x();
- d->pointerSpringY += delta.y();
- start();
+ if (d->enabled) {
+ d->pointerSpringX += delta.x();
+ d->pointerSpringY += delta.y();
+ start();
+ } else {
+
+ bool emitSignal = false;
+
+ if (d->panDirection.testFlag(Qt::Horizontal)) {
+
+ qreal prevPosX = d->posX;
+ d->posX -= delta.x();
+
+ if (d->posX < d->range.left()) d->posX = d->range.left();
+ if (d->posX > d->range.right()) d->posX = d->range.right();
+
+ if (prevPosX != d->posX) emitSignal = true;
+ }
+
+ if (d->panDirection.testFlag(Qt::Vertical)) {
+
+ qreal prevPosY = d->posY;
+ d->posY -= delta.y();
+
+ if (d->posY < d->range.top()) d->posY = d->range.top();
+ if (d->posY > d->range.bottom()) d->posY = d->range.bottom();
+
+ if (prevPosY != d->posY) emitSignal = true;
+ }
+
+ if (emitSignal) emit positionChanged(QPointF(d->posX, d->posY));
+ }
+
}
@@ -335,8 +378,12 @@ void MPhysics2DPanning::pointerRelease()
Q_D(MPhysics2DPanning);
// Disables the pointer spring
-
d->pointerPressed = false;
+
+ if (d->enabled == false) {
+ //The physics engine is not working, emitting panning stopped now.
+ emit panningStopped();
+ }
}