summaryrefslogtreecommitdiff
path: root/core/settings/citytime/stylusnormalizer.cpp
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/settings/citytime/stylusnormalizer.cpp
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'core/settings/citytime/stylusnormalizer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/citytime/stylusnormalizer.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/core/settings/citytime/stylusnormalizer.cpp b/core/settings/citytime/stylusnormalizer.cpp
new file mode 100644
index 0000000..62de28b
--- a/dev/null
+++ b/core/settings/citytime/stylusnormalizer.cpp
@@ -0,0 +1,98 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpoint.h>
22#include <qtimer.h>
23
24#include "stylusnormalizer.h"
25
26static const int FLUSHTIME = 100;
27
28_StylusEvent::_StylusEvent( const QPoint& newPt )
29 : _pt( newPt ),
30 _t( QTime::currentTime() )
31{
32}
33
34_StylusEvent::~_StylusEvent()
35{
36}
37
38StylusNormalizer::StylusNormalizer( QWidget *parent, const char* name )
39 : QWidget( parent, name ),
40 _next( 0 ),
41 bFirst( true )
42{
43 // initialize _ptList
44 int i;
45 for (i = 0; i < SAMPLES; i++ ) {
46 _ptList[i].setPoint( -1, -1 );
47 }
48 _tExpire = new QTimer( this );
49 QObject::connect( _tExpire, SIGNAL( timeout() ),
50 this, SLOT( slotAveragePoint() ) );
51}
52
53StylusNormalizer::~StylusNormalizer()
54{
55}
56
57void StylusNormalizer::addEvent( const QPoint& pt )
58{
59 _ptList[_next].setPoint( pt );
60 _ptList[_next++].setTime( QTime::currentTime() );
61 if ( _next >= SAMPLES ) {
62 _next = 0;
63 }
64 // make a single mouse click work
65 if ( bFirst ) {
66 slotAveragePoint();
67 bFirst = false;
68 }
69}
70
71void StylusNormalizer::slotAveragePoint( void )
72{
73 QPoint pt( 0, 0 );
74 QTime tCurr = QTime::currentTime();
75 int i,
76 size;
77 size = 0;
78 for ( i = 0; i < SAMPLES; i++ ) {
79 if ( ( (_ptList[i]).time().msecsTo( tCurr ) < FLUSHTIME ) &&
80 ( _ptList[i].point() != QPoint( -1, -1 ) ) ) {
81 pt += _ptList[i].point();
82 size++;
83 }
84 }
85 if ( size > 0 )
86 emit signalNewPoint( pt /= size );
87}
88
89void StylusNormalizer::start( void )
90{
91 _tExpire->start( FLUSHTIME );
92}
93
94void StylusNormalizer::stop( void )
95{
96 _tExpire->stop();
97 bFirst = true;
98} \ No newline at end of file