Gesture/strokelist.h

Go to the documentation of this file.
00001 /*  -*- c++ -*-  (for Emacs)
00002  *
00003  *  strokelist.h
00004  *  Digest
00005  * 
00006  *  Created by Aidan Lane on Thu Jul 7 2005.
00007  *  Copyright (c) 2005 Optimisation and Constraint Solving Group,
00008  *  Monash University. All rights reserved.
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00023  */
00024 
00025 #ifndef STROKELIST_H
00026 #define STROKELIST_H
00027 
00028 
00029 #include <QList>
00030 #include <QMetaType>
00031 #include <QPointF>
00032 #include <QString>
00033 
00034 
00035 typedef QPointF   StrokePointBase;
00036 typedef float     StrokeCoordT;
00037 typedef float     StrokePressureT;
00038 typedef uint32_t  StrokeTimeT;
00039 
00040 
00041 /* WARNING! Using floats for x and y may be overkill, but it provides a lot of
00042  *          flexibility. However the strokes editor should provide an option to
00043  *          record rounded or truncated values, which when coded as a string
00044  *          (using QString::number()), will use the same # of chars as an integer.
00045  */
00046 class StrokePoint : public StrokePointBase {
00047 public:
00048   StrokePoint( StrokeCoordT x = 0.0,
00049                StrokeCoordT y = 0.0,
00050                StrokePressureT pressure = 0.0,
00051                StrokeTimeT milliTime = 0 )
00052     : StrokePointBase(x,y),
00053       pressure(pressure),
00054       milliTime(milliTime) {}
00055   StrokePoint( const StrokePointBase& pt,
00056                StrokePressureT pressure = 0.0,
00057                StrokeTimeT milliTime = 0 )
00058     : StrokePointBase(pt),
00059       pressure(pressure),
00060       milliTime(milliTime) {}
00061   StrokePressureT pressure;  
00063   StrokeTimeT     milliTime; 
00064 #if 0
00065   float rotation;
00066   float xTilt;
00067   float yTilt;
00068 #endif
00069 };
00070 
00071 
00072 
00073 class Stroke : public QList<StrokePoint> {
00074 
00075 public:
00076   inline void translate( StrokeCoordT dx, StrokeCoordT dy );
00077   inline void translate( const StrokePointBase& p );
00078   inline Stroke translated( StrokeCoordT dx, StrokeCoordT dy ) const;
00079   inline Stroke translated( const StrokePointBase& p ) const;
00080 };
00081 
00082 inline void Stroke::translate( StrokeCoordT dx, StrokeCoordT dy )
00083 { translate( StrokePointBase(dx, dy) ); }
00084 
00085 inline void Stroke::translate( const StrokePointBase& p ) {
00086   QMutableListIterator<StrokePoint> it( *this );
00087   while ( it.hasNext() ) it.next() += p;
00088 }
00089 
00090 inline Stroke Stroke::translated( StrokeCoordT dx, StrokeCoordT dy ) const
00091 { return translated( StrokePointBase(dx, dy) ); }
00092 
00093 inline Stroke Stroke::translated( const StrokePointBase& p ) const {
00094   Stroke t;
00095   QListIterator<StrokePoint> it( *this );
00096   while ( it.hasNext() ) t.append( it.next() + p );
00097   return t;
00098 }
00099 
00100 
00101 
00102 class StrokeList : public QList<Stroke> {
00103 
00104 public:
00105   StrokeList();
00106   StrokeList( const StrokeList& other );
00107   StrokeList( const QList<Stroke>& other );
00108 
00109   inline void translate( StrokeCoordT dx, StrokeCoordT dy );
00110   inline void translate( const StrokePointBase& p );
00111   inline StrokeList translated( StrokeCoordT dx, StrokeCoordT dy ) const;
00112   inline StrokeList translated( const StrokePointBase& p ) const;
00113 
00114   QString toString() const;
00115 
00116   static StrokeList fromString( const QString& str );
00117 
00118 private:
00119   void init();
00120 };
00121 Q_DECLARE_METATYPE( StrokeList );
00122 
00123 
00124 inline void StrokeList::translate( StrokeCoordT dx, StrokeCoordT dy )
00125 { translate( StrokePointBase(dx, dy) ); }
00126 
00127 inline void StrokeList::translate( const StrokePointBase& p ) {
00128   QMutableListIterator<Stroke> it( *this );
00129   while ( it.hasNext() ) it.next().translate(p);
00130 }
00131 
00132 inline StrokeList StrokeList::translated( StrokeCoordT dx, StrokeCoordT dy ) const
00133 { return translated( StrokePointBase(dx, dy) ); }
00134 
00135 inline StrokeList StrokeList::translated( const StrokePointBase& p ) const {
00136   StrokeList t;
00137   QListIterator<Stroke> it( *this );
00138   while ( it.hasNext() ) t.append( it.next().translated(p) );
00139   return t;
00140 }
00141 
00142 
00143 #endif  // ! STROKELIST_H

Generated on Mon Jul 30 09:46:50 2007 for Digest by  doxygen 1.5.2