00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00042
00043
00044
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