00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QSCOORD_H
00020 #define QSCOORD_H
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025
00026 #include<qwindowdefs.h>
00027 #include<qrect.h>
00028 #include<qpoint.h>
00029
00030
00036 class QSCoord {
00037 public:
00038 static inline double mmToPixels( double mm, double dpi=72.0 ) { return mm*dpi/25.4; }
00039 static inline double pixelsToMM( double pixels, double dpi=72.0 ) { return pixels*25.4/dpi; }
00040 static inline double pointsToPixels( double points, double dpi=72.0 ) { return points*dpi/72.0; }
00041 static inline double pixelsToPoints( double pixels, double dpi=72.0 ) { return pixels*72.0/dpi; }
00042 };
00043
00044
00045
00046
00053 class QSPt2 : public QSCoord {
00054 public:
00055
00056 #if defined(_OS_MAC_)
00057 QCOORD y;
00058 QCOORD x;
00059 #else
00060 QCOORD x;
00061 QCOORD y;
00062 #endif
00063
00064 explicit QSPt2( const QPoint& p ) {
00065 set( p.x(), p.y() );
00066 }
00067 QSPt2( int newX=0, int newY=0 ) {
00068 set( newX, newY );
00069 }
00070 ~QSPt2() {
00071 }
00072 QSPt2 &set( int newX, int newY ) {
00073 x=newX;
00074 y=newY;
00075 return *this;
00076 }
00077 QPoint point() const {
00078 return QPoint( x, y );
00079 }
00080
00081 friend QSPt2 operator+ ( const QSPt2& p1, const QSPt2& p2 );
00082 friend QSPt2 operator- ( const QSPt2& p1, const QSPt2& p2 );
00083 friend bool operator==( const QSPt2& p1, const QSPt2& p2 );
00084 friend bool operator!=( const QSPt2& p1, const QSPt2& p2 );
00085 };
00086
00087
00088
00095 class QSPt3 : public QSCoord {
00096 public:
00097
00098 int x;
00099 int y;
00100 int z;
00101
00102 QSPt3( int newX=0, int newY=0, int newZ=0 ) {
00103 set( newX, newY, newZ );
00104 }
00105 ~QSPt3() {
00106 }
00107 QSPt3 &set( int newX, int newY, int newZ ) {
00108 x=newX;
00109 y=newY;
00110 z=newZ;
00111 return *this;
00112 }
00113
00114 friend QSPt3 operator+ ( const QSPt3& p1, const QSPt3& p2 );
00115 friend QSPt3 operator- ( const QSPt3& p1, const QSPt3& p2 );
00116 friend bool operator==( const QSPt3& p1, const QSPt3& p2 );
00117 friend bool operator!=( const QSPt3& p1, const QSPt3& p2 );
00118 };
00119
00120
00121
00128 class QSPt2f : public QSCoord {
00129 public:
00130 double x;
00131 double y;
00132
00133 explicit QSPt2f( const QPoint& p ) {
00134 set( p.x(), p.y() );
00135 }
00136 QSPt2f( double newX=0.0, double newY=0.0 ) {
00137 set( newX, newY );
00138 }
00139 ~QSPt2f() {
00140 }
00141 QSPt2f &set( double newX, double newY ) {
00142 x=newX;
00143 y=newY;
00144 return *this;
00145 }
00146 QPoint point() const {
00147 return QPoint( int(x+0.5), int(y+0.5) );
00148 }
00149
00150 friend QSPt2f operator+ ( const QSPt2f& p1, const QSPt2f& p2 );
00151 friend QSPt2f operator- ( const QSPt2f& p1, const QSPt2f& p2 );
00152 friend bool operator==( const QSPt2f& p1, const QSPt2f& p2 );
00153 friend bool operator!=( const QSPt2f& p1, const QSPt2f& p2 );
00154 };
00155
00156
00157
00164 class QSPt3f : public QSCoord {
00165 public:
00166
00167 double x;
00168 double y;
00169 double z;
00170
00171 QSPt3f( double newX=0.0, double newY=0.0, double newZ=0.0 ) {
00172 set( newX, newY, newZ );
00173 }
00174 ~QSPt3f() {
00175 }
00176 QSPt3f &set( double newX, double newY, double newZ ) {
00177 x=newX;
00178 y=newY;
00179 z=newZ;
00180 return *this;
00181 }
00182
00183 friend QSPt3f operator+ ( const QSPt3f& p1, const QSPt3f& p2 );
00184 friend QSPt3f operator- ( const QSPt3f& p1, const QSPt3f& p2 );
00185 friend bool operator==( const QSPt3f& p1, const QSPt3f& p2 );
00186 friend bool operator!=( const QSPt3f& p1, const QSPt3f& p2 );
00187 };
00188
00189
00190
00191
00195 class QSRectf : public QSCoord
00196 {
00197 public:
00201 QSPt2f pos;
00205 QSPt2f size;
00209 QSRectf() {
00210 }
00214 explicit QSRectf( const QRect& r ) {
00215 pos.x = r.left(); pos.y = r.top(); size.x = r.width(); size.y = r.height();
00216 }
00220 QSRectf( const QSPt2f& p2, const QSPt2f& p1, bool norm ) {
00221 pos = p1;
00222 size = p2-p1;
00223 if ( norm ) { QSRectf r = normalize(); pos = r.pos; size = r.size; }
00224 }
00228 QSRectf( const QSPt2f& initPos, const QSPt2f& initSize ) {
00229 pos = initPos;
00230 size = initSize;
00231 }
00235 QSRectf( double x, double y, double w, double h ) {
00236 pos.x = x;
00237 pos.y = y;
00238 size.x = w;
00239 size.y = h;
00240 }
00244 ~QSRectf() {
00245 }
00250 void setP1( const QSPt2f& p ) {
00251 size = size - (p-pos);
00252 pos = p;
00253 }
00258 void setP2( const QSPt2f& p ) {
00259 size = p-pos;
00260 }
00264 QSPt2f p1() const {
00265 return pos;
00266 }
00270 QSPt2f p2() const {
00271 return pos+size;
00272 }
00276 void setTopLeft( const QSPt2f& p );
00281 void setBottomRight( const QSPt2f& p );
00285 QSPt2f topLeft() const;
00289 QSPt2f bottomRight() const;
00293 bool contains( const QSPt2f& pos ) const;
00297 void unite( const QSRectf& rect );
00301 QSRectf normalize() const;
00305 QSRectf normalizeWidth() const;
00309 QSRectf normalizeHeight() const;
00313 QRect rect() const;
00314 friend bool operator==( const QSRectf& r1, const QSRectf& r2 );
00315 friend bool operator!=( const QSRectf& r1, const QSRectf& r2 );
00316 };
00317
00318 #endif
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329