Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

stylusnormalizer.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include <qtimer.h>
00022 
00023 #include "stylusnormalizer.h"
00024 
00025 static const int FLUSHTIME = 100;
00026 
00027 _StylusEvent::_StylusEvent( const QPoint& newPt )
00028     : _pt( newPt ),
00029       _t( QTime::currentTime() )
00030 {
00031 }
00032 
00033 _StylusEvent::~_StylusEvent()
00034 {
00035 }
00036 
00037 StylusNormalizer::StylusNormalizer( QWidget *parent, const char* name )
00038     : QWidget( parent, name ),
00039       _next( 0 ),
00040       bFirst( true )
00041 {
00042     // initialize _ptList
00043     int i;
00044     for (i = 0; i < SAMPLES; i++ ) {
00045         _ptList[i].setPoint( -1, -1 );
00046     }
00047     _tExpire = new QTimer( this );
00048     QObject::connect( _tExpire, SIGNAL( timeout() ),
00049                       this, SLOT( slotAveragePoint() ) );
00050 }
00051 
00052 StylusNormalizer::~StylusNormalizer()
00053 {
00054 }
00055 
00056 void StylusNormalizer::addEvent( const QPoint& pt )
00057 {
00058     _ptList[_next].setPoint( pt );
00059     _ptList[_next++].setTime( QTime::currentTime() );
00060     if ( _next >= SAMPLES ) {
00061         _next = 0;
00062     }
00063     // make a single mouse click work
00064     if ( bFirst ) {
00065         slotAveragePoint();
00066         bFirst = false;
00067     }
00068 }
00069 
00070 void StylusNormalizer::slotAveragePoint( void )
00071 {
00072     QPoint pt( 0, 0 );
00073     QTime tCurr = QTime::currentTime();
00074     int i,
00075         size;
00076     size = 0;
00077     for ( i = 0; i < SAMPLES; i++ ) {
00078         if ( ( (_ptList[i]).time().msecsTo( tCurr ) < FLUSHTIME ) &&
00079              ( _ptList[i].point() != QPoint( -1, -1 ) ) ) {
00080             pt += _ptList[i].point();
00081             size++;
00082         }
00083     }
00084     if ( size > 0 )
00085         emit signalNewPoint( pt /= size );
00086 }
00087 
00088 void StylusNormalizer::start( void )
00089 {
00090     _tExpire->start( FLUSHTIME );
00091 }
00092 
00093 void StylusNormalizer::stop( void )
00094 {
00095     _tExpire->stop();
00096     bFirst = true;
00097 }
00098 

Generated on Sat Nov 5 16:15:57 2005 for OPIE by  doxygen 1.4.2