-rw-r--r-- | core/settings/citytime/stylusnormalizer.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/settings/citytime/stylusnormalizer.cpp b/core/settings/citytime/stylusnormalizer.cpp index 62de28b..c6c65d2 100644 --- a/core/settings/citytime/stylusnormalizer.cpp +++ b/core/settings/citytime/stylusnormalizer.cpp | |||
@@ -1,98 +1,99 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qpoint.h> | 21 | #include <qpoint.h> |
22 | #include <qtimer.h> | 22 | #include <qtimer.h> |
23 | 23 | ||
24 | #include "stylusnormalizer.h" | 24 | #include "stylusnormalizer.h" |
25 | 25 | ||
26 | static const int FLUSHTIME = 100; | 26 | static const int FLUSHTIME = 100; |
27 | 27 | ||
28 | _StylusEvent::_StylusEvent( const QPoint& newPt ) | 28 | _StylusEvent::_StylusEvent( const QPoint& newPt ) |
29 | : _pt( newPt ), | 29 | : _pt( newPt ), |
30 | _t( QTime::currentTime() ) | 30 | _t( QTime::currentTime() ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | _StylusEvent::~_StylusEvent() | 34 | _StylusEvent::~_StylusEvent() |
35 | { | 35 | { |
36 | } | 36 | } |
37 | 37 | ||
38 | StylusNormalizer::StylusNormalizer( QWidget *parent, const char* name ) | 38 | StylusNormalizer::StylusNormalizer( QWidget *parent, const char* name ) |
39 | : QWidget( parent, name ), | 39 | : QWidget( parent, name ), |
40 | _next( 0 ), | 40 | _next( 0 ), |
41 | bFirst( true ) | 41 | bFirst( true ) |
42 | { | 42 | { |
43 | // initialize _ptList | 43 | // initialize _ptList |
44 | int i; | 44 | int i; |
45 | for (i = 0; i < SAMPLES; i++ ) { | 45 | for (i = 0; i < SAMPLES; i++ ) { |
46 | _ptList[i].setPoint( -1, -1 ); | 46 | _ptList[i].setPoint( -1, -1 ); |
47 | } | 47 | } |
48 | _tExpire = new QTimer( this ); | 48 | _tExpire = new QTimer( this ); |
49 | QObject::connect( _tExpire, SIGNAL( timeout() ), | 49 | QObject::connect( _tExpire, SIGNAL( timeout() ), |
50 | this, SLOT( slotAveragePoint() ) ); | 50 | this, SLOT( slotAveragePoint() ) ); |
51 | } | 51 | } |
52 | 52 | ||
53 | StylusNormalizer::~StylusNormalizer() | 53 | StylusNormalizer::~StylusNormalizer() |
54 | { | 54 | { |
55 | } | 55 | } |
56 | 56 | ||
57 | void StylusNormalizer::addEvent( const QPoint& pt ) | 57 | void StylusNormalizer::addEvent( const QPoint& pt ) |
58 | { | 58 | { |
59 | _ptList[_next].setPoint( pt ); | 59 | _ptList[_next].setPoint( pt ); |
60 | _ptList[_next++].setTime( QTime::currentTime() ); | 60 | _ptList[_next++].setTime( QTime::currentTime() ); |
61 | if ( _next >= SAMPLES ) { | 61 | if ( _next >= SAMPLES ) { |
62 | _next = 0; | 62 | _next = 0; |
63 | } | 63 | } |
64 | // make a single mouse click work | 64 | // make a single mouse click work |
65 | if ( bFirst ) { | 65 | if ( bFirst ) { |
66 | slotAveragePoint(); | 66 | slotAveragePoint(); |
67 | bFirst = false; | 67 | bFirst = false; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | void StylusNormalizer::slotAveragePoint( void ) | 71 | void StylusNormalizer::slotAveragePoint( void ) |
72 | { | 72 | { |
73 | QPoint pt( 0, 0 ); | 73 | QPoint pt( 0, 0 ); |
74 | QTime tCurr = QTime::currentTime(); | 74 | QTime tCurr = QTime::currentTime(); |
75 | int i, | 75 | int i, |
76 | size; | 76 | size; |
77 | size = 0; | 77 | size = 0; |
78 | for ( i = 0; i < SAMPLES; i++ ) { | 78 | for ( i = 0; i < SAMPLES; i++ ) { |
79 | if ( ( (_ptList[i]).time().msecsTo( tCurr ) < FLUSHTIME ) && | 79 | if ( ( (_ptList[i]).time().msecsTo( tCurr ) < FLUSHTIME ) && |
80 | ( _ptList[i].point() != QPoint( -1, -1 ) ) ) { | 80 | ( _ptList[i].point() != QPoint( -1, -1 ) ) ) { |
81 | pt += _ptList[i].point(); | 81 | pt += _ptList[i].point(); |
82 | size++; | 82 | size++; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | if ( size > 0 ) | 85 | if ( size > 0 ) |
86 | emit signalNewPoint( pt /= size ); | 86 | emit signalNewPoint( pt /= size ); |
87 | } | 87 | } |
88 | 88 | ||
89 | void StylusNormalizer::start( void ) | 89 | void StylusNormalizer::start( void ) |
90 | { | 90 | { |
91 | _tExpire->start( FLUSHTIME ); | 91 | _tExpire->start( FLUSHTIME ); |
92 | } | 92 | } |
93 | 93 | ||
94 | void StylusNormalizer::stop( void ) | 94 | void StylusNormalizer::stop( void ) |
95 | { | 95 | { |
96 | _tExpire->stop(); | 96 | _tExpire->stop(); |
97 | bFirst = true; | 97 | bFirst = true; |
98 | } \ No newline at end of file | 98 | } |
99 | |||