equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef HGSPRING_H |
|
19 #define HGSPRING_H |
|
20 |
|
21 #include <qpoint> |
|
22 #include <qobject> |
|
23 #include <qtime> |
|
24 |
|
25 class QTimer; |
|
26 |
|
27 /** |
|
28 * Spring physics class. |
|
29 */ |
|
30 class HgSpring : public QObject |
|
31 { |
|
32 Q_OBJECT |
|
33 public: |
|
34 |
|
35 explicit HgSpring(); |
|
36 virtual ~HgSpring(); |
|
37 |
|
38 void setK(qreal K); |
|
39 void setDamping(qreal damping); |
|
40 |
|
41 void animateToPos(const QPointF& pos); |
|
42 void gotoPos(const QPointF& pos); |
|
43 void cancel(); |
|
44 bool isActive() const; |
|
45 |
|
46 const QPointF& startPos() const; |
|
47 const QPointF& pos() const; |
|
48 const QPointF& endPos() const; |
|
49 const QPointF& velocity() const; |
|
50 |
|
51 bool updatePositionIfNeeded(); |
|
52 |
|
53 signals: |
|
54 void updated(); |
|
55 void started(); |
|
56 void ended(); |
|
57 private slots: |
|
58 void update(); |
|
59 private: |
|
60 Q_DISABLE_COPY(HgSpring) |
|
61 |
|
62 QPointF mStartPos; |
|
63 QPointF mPos; |
|
64 QPointF mEndPos; |
|
65 QPointF mVelocity; |
|
66 qreal mK; |
|
67 qreal mDamping; |
|
68 int mAccumulator; |
|
69 QTimer* mTimer; |
|
70 QTime mPrevTime; |
|
71 bool mDoNotUpdate; |
|
72 }; |
|
73 |
|
74 #endif |