Back to index

scribus-ng  1.3.4.dfsg+svn20071115
frect.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: frect.h 6159 2006-08-17 18:35:05Z jghali $
00003 **
00004 ** Definition of FRect class
00005 **
00006 ** Created : 931028
00007 **
00008 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef FRECT_H
00039 #define FRECT_H
00040 
00041 //#ifndef QT_H
00042 #include "fsize.h"
00043 //#endif // QT_H
00044 
00045 #if defined(topLeft)
00046 #error "Macro definition of topLeft conflicts with FRect"
00047 // don't just silently undo people's defines: #undef topLeft
00048 #endif
00049 
00050 class FRect                               // rectangle class
00051 {
00052 public:
00053     FRect()   { x1 = y1 = 0; x2 = y2 = -1; }
00054     FRect( FPoint &topleft, FPoint &bottomright );
00055     FRect( FPoint &topleft, FSize &size );
00056     FRect( double left, double top, double width, double height );
00057 
00058     bool   isNull()  const;
00059     bool   isEmpty() const;
00060     bool   isValid() const;
00061     FRect  normalize()      const;
00062 
00063     double       left()     const;
00064     double       top()      const;
00065     double       right()    const;
00066     double       bottom()   const;
00067 
00068     double &rLeft();
00069     double &rTop();
00070     double &rRight();
00071     double &rBottom();
00072 
00073     double       x()        const;
00074     double       y()        const;
00075     void   setLeft( double pos );
00076     void   setTop( double pos );
00077     void   setRight( double pos );
00078     void   setBottom( double pos );
00079     void   setX( double x );
00080     void   setY( double y );
00081 
00082     void   setTopLeft( FPoint &p );
00083     void   setBottomRight( FPoint &p );
00084     void   setTopRight( FPoint &p );
00085     void   setBottomLeft( FPoint &p );
00086 
00087     FPoint topLeft()  const;
00088     FPoint bottomRight() const;
00089     FPoint topRight()        const;
00090     FPoint bottomLeft()      const;
00091     FPoint center()   const;
00092 
00093     void   rect( double *x, double *y, double *w, double *h ) const;
00094     void   coords( double *x1, double *y1, double *x2, double *y2 ) const;
00095 
00096     void   moveLeft( double pos );
00097     void   moveTop( double pos );
00098     void   moveRight( double pos );
00099     void   moveBottom( double pos );
00100     void   moveTopLeft( FPoint &p );
00101     void   moveBottomRight( FPoint &p );
00102     void   moveTopRight( FPoint &p );
00103     void   moveBottomLeft( FPoint &p );
00104     void   moveCenter( FPoint &p );
00105     void   moveBy( double dx, double dy );
00106 
00107     void   setRect( double x, double y, double w, double h );
00108     void   setCoords( double x1, double y1, double x2, double y2 );
00109     void   addCoords( double x1, double y1, double x2, double y2 );
00110 
00111     FSize  size()    const;
00112     double       width()    const;
00113     double       height()   const;
00114     void   setWidth( double w );
00115     void   setHeight( double h );
00116     void   setSize( const FSize &s );
00117 
00118     FRect  operator|(const FRect &r) const;
00119     FRect  operator&(const FRect &r) const;
00120     FRect&  operator|=(const FRect &r);
00121     FRect&  operator&=(const FRect &r);
00122 
00123     bool   contains( FPoint &p, bool proper=FALSE ) const;
00124     bool   contains( double x, double y ) const; // inline methods, _don't_ merge these
00125     bool   contains( double x, double y, bool proper ) const;
00126     bool   contains( const FRect &r, bool proper=FALSE ) const;
00127     FRect  unite( const FRect &r ) const;
00128     FRect  intersect( const FRect &r ) const;
00129     bool   intersects( const FRect &r ) const;
00130 
00131     friend bool operator==( const FRect &, const FRect & );
00132     friend bool operator!=( const FRect &, const FRect & );
00133 
00134 private:
00135 #if defined(Q_WS_X11) || defined(Q_OS_TEMP)
00136     friend void qt_setCoords( FRect *r, double xp1, double yp1, double xp2, double yp2 );
00137 #endif
00138 
00139     double x1;
00140     double y1;
00141     double x2;
00142     double y2;
00143 
00144 };
00145 
00146 bool operator==( const FRect &, const FRect & );
00147 bool operator!=( const FRect &, const FRect & );
00148 
00149 
00150 /*****************************************************************************
00151   FRect stream functions
00152  *****************************************************************************/
00153 // #ifndef QT_NO_DATASTREAM
00154 // Q_EXPORT QDataStream &operator<<( QDataStream &, const FRect & );
00155 // Q_EXPORT QDataStream &operator>>( QDataStream &, FRect & );
00156 // #endif
00157 
00158 /*****************************************************************************
00159   FRect inline member functions
00160  *****************************************************************************/
00161 
00162 inline FRect::FRect( double left, double top, double width, double height )
00163 {
00164     x1 = (double)left;
00165     y1 = (double)top;
00166     x2 = (double)(left+width-1);
00167     y2 = (double)(top+height-1);
00168 }
00169 
00170 inline bool FRect::isNull() const
00171 { return x2 == x1-1 && y2 == y1-1; }
00172 
00173 inline bool FRect::isEmpty() const
00174 { return x1 > x2 || y1 > y2; }
00175 
00176 inline bool FRect::isValid() const
00177 { return x1 <= x2 && y1 <= y2; }
00178 
00179 inline double FRect::left() const
00180 { return x1; }
00181 
00182 inline double FRect::top() const
00183 { return y1; }
00184 
00185 inline double FRect::right() const
00186 { return x2; }
00187 
00188 inline double FRect::bottom() const
00189 { return y2; }
00190 
00191 inline double &FRect::rLeft()
00192 { return x1; }
00193 
00194 inline double & FRect::rTop()
00195 { return y1; }
00196 
00197 inline double & FRect::rRight()
00198 { return x2; }
00199 
00200 inline double & FRect::rBottom()
00201 { return y2; }
00202 
00203 inline double FRect::x() const
00204 { return x1; }
00205 
00206 inline double FRect::y() const
00207 { return y1; }
00208 
00209 inline void FRect::setLeft( double pos )
00210 { x1 = (double)pos; }
00211 
00212 inline void FRect::setTop( double pos )
00213 { y1 = (double)pos; }
00214 
00215 inline void FRect::setRight( double pos )
00216 { x2 = (double)pos; }
00217 
00218 inline void FRect::setBottom( double pos )
00219 { y2 = (double)pos; }
00220 
00221 inline void FRect::setX( double x )
00222 { x1 = (double)x; }
00223 
00224 inline void FRect::setY( double y )
00225 { y1 = (double)y; }
00226 
00227 inline FPoint FRect::topLeft() const
00228 { return FPoint(x1, y1); }
00229 
00230 inline FPoint FRect::bottomRight() const
00231 { return FPoint(x2, y2); }
00232 
00233 inline FPoint FRect::topRight() const
00234 { return FPoint(x2, y1); }
00235 
00236 inline FPoint FRect::bottomLeft() const
00237 { return FPoint(x1, y2); }
00238 
00239 inline FPoint FRect::center() const
00240 { return FPoint((x1+x2)/2, (y1+y2)/2); }
00241 
00242 inline double FRect::width() const
00243 { return  x2 - x1 + 1; }
00244 
00245 inline double FRect::height() const
00246 { return  y2 - y1 + 1; }
00247 
00248 inline FSize FRect::size() const
00249 { return FSize(x2-x1+1, y2-y1+1); }
00250 
00251 inline bool FRect::contains( double x, double y, bool proper ) const
00252 {
00253     if ( proper )
00254         return x > x1 && x < x2 &&
00255                y > y1 && y < y2;
00256     else
00257         return x >= x1 && x <= x2 &&
00258                y >= y1 && y <= y2;
00259 }
00260 
00261 inline bool FRect::contains( double x, double y ) const
00262 {
00263     return x >= x1 && x <= x2 &&
00264           y >= y1 && y <= y2;
00265 }
00266 // #define Q_DEFINED_QRECT
00267 // #include "qwinexport.h"
00268  #endif // QRECT_H