--- a/ginebra2/KineticHelper.cpp Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/KineticHelper.cpp Wed Jun 23 17:59:43 2010 +0300
@@ -1,24 +1,27 @@
/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
*
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
*
-* Description:
+* Description:
*
*/
-
#include <QTimer>
#include <QTime>
#include <QPoint>
-#include <QDebug>
+#include <QDebug>
#include "KineticHelper.h"
@@ -26,7 +29,7 @@
KineticHelper::KineticHelper(KineticScrollable* scrollable, qreal decel, int kineticTimeout) :
m_scrollable(scrollable),
- m_decel(decel),
+ m_decel(decel),
m_kineticTimeout(kineticTimeout)
{
m_kineticTimer = new QTimer(this);
@@ -47,17 +50,17 @@
void KineticHelper::startScrolling()
{
- m_initialSpeed = m_scrollable->getInitialSpeed() * 1000;
- m_initialPos = m_scrollable->getInitialPosition();
- if (m_kineticTimer->isActive()) {
- m_kineticTimer->stop();
- }
- m_kineticSteps = 0;
- m_kineticScrollTime = 0.0;
- m_kineticTimer->start(m_kineticTimeout);
- m_actualTime = QTime::currentTime();
- m_actualTime.start();
- qDebug() << "starting kinetic timer at " << m_initialPos << ", at " << m_actualTime;
+ m_initialSpeed = m_scrollable->getInitialSpeed() * 1000;
+ m_initialPos = m_scrollable->getInitialPosition();
+ if (m_kineticTimer->isActive()) {
+ m_kineticTimer->stop();
+ }
+ m_kineticSteps = 0;
+ m_kineticScrollTime = 0.0;
+ m_kineticTimer->start(m_kineticTimeout);
+ m_actualTime = QTime::currentTime();
+ m_actualTime.start();
+ qDebug() << "starting kinetic timer at " << m_initialPos << ", at " << m_actualTime;
}
@@ -73,8 +76,8 @@
int t = m_actualTime.elapsed();
m_kineticScrollTime += (((qreal)t) / 1000);
-
- qDebug() << "kineticScroll(): elapsed: " << t << ", m_kineticSteps: " << m_kineticSteps <<
+
+ qDebug() << "kineticScroll(): elapsed: " << t << ", m_kineticSteps: " << m_kineticSteps <<
", m_kineticScrollTime: " << m_kineticScrollTime <<
", decelX: "<< decelX << ", decelY: " << decelY << ", m_initialSpeed: " << m_initialSpeed;
if (m_initialSpeed.x()) {
@@ -85,11 +88,11 @@
vx = 0;
}
else {
- dx = m_kineticScrollTime * m_initialSpeed.x() +
+ dx = m_kineticScrollTime * m_initialSpeed.x() +
0.5 * decelX * m_kineticScrollTime * m_kineticScrollTime;
}
}
-
+
if (m_initialSpeed.y()) {
vy = m_initialSpeed.y() + decelY * m_kineticScrollTime;
qDebug() << "vy: " << vy;
@@ -98,19 +101,19 @@
vy = 0;
}
else {
- dy = m_kineticScrollTime * m_initialSpeed.y() +
+ dy = m_kineticScrollTime * m_initialSpeed.y() +
0.5 * decelY * m_kineticScrollTime * m_kineticScrollTime;
}
}
-
+
QPoint scrollPos = m_scrollable->getScrollPosition();
QPoint distPos = m_initialPos + QPointF(dx, dy).toPoint();
-
+
if (vx != 0 || vy != 0) {
qDebug() << "kineticScroll(): scroll from " << scrollPos << " to " << distPos;
m_scrollable->scrollTo(distPos);
}
-
+
if ((vx == 0 && vy == 0) || scrollPos == m_scrollable->getScrollPosition()) {
qDebug() << "kineticScroll(): stopping timer";
stopScrolling();