Scribus
Open source desktop publishing at your fingertips
frect.h
1 /****************************************************************************
2 ** $Id: frect.h 18204 2013-03-12 22:26:54Z fschmid $
3 **
4 ** Definition of FRect class
5 **
6 ** Created : 931028
7 **
8 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9 **
10 ** This file is part of the kernel module of the Qt GUI Toolkit.
11 **
12 ** This file may be distributed under the terms of the Q Public License
13 ** as defined by Trolltech AS of Norway and appearing in the file
14 ** LICENSE.QPL included in the packaging of this file.
15 **
16 ** This file may be distributed and/or modified under the terms of the
17 ** GNU General Public License version 2 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.GPL included in the
19 ** packaging of this file.
20 **
21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22 ** licenses may use this file in accordance with the Qt Commercial License
23 ** Agreement provided with the Software.
24 **
25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 **
28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29 ** information about Qt Commercial License Agreements.
30 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
31 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
32 **
33 ** Contact info@trolltech.com if any conditions of this licensing are
34 ** not clear to you.
35 **
36 **********************************************************************/
37 
38 #ifndef FRECT_H
39 #define FRECT_H
40 
41 //#ifndef QT_H
42 #include "fsize.h"
43 //#endif // QT_H
44 
45 #if defined(topLeft)
46 #error "Macro definition of topLeft conflicts with FRect"
47 // don't just silently undo people's defines: #undef topLeft
48 #endif
49 
50 class FRect // rectangle class
51 {
52 public:
53  FRect() { x1 = y1 = 0; x2 = y2 = -1; }
54  FRect( FPoint &topleft, FPoint &bottomright );
55  FRect( FPoint &topleft, FSize &size );
56  FRect( qreal left, qreal top, qreal width, qreal height );
57 
58  bool isNull() const;
59  bool isEmpty() const;
60  bool isValid() const;
61  FRect normalize() const;
62 
63  qreal left() const;
64  qreal top() const;
65  qreal right() const;
66  qreal bottom() const;
67 
68  qreal &rLeft();
69  qreal &rTop();
70  qreal &rRight();
71  qreal &rBottom();
72 
73  qreal x() const;
74  qreal y() const;
75  void setLeft( qreal pos );
76  void setTop( qreal pos );
77  void setRight( qreal pos );
78  void setBottom( qreal pos );
79  void setX( qreal x );
80  void setY( qreal y );
81 
82  void setTopLeft( FPoint &p );
83  void setBottomRight( FPoint &p );
84  void setTopRight( FPoint &p );
85  void setBottomLeft( FPoint &p );
86 
87  FPoint topLeft() const;
88  FPoint bottomRight() const;
89  FPoint topRight() const;
90  FPoint bottomLeft() const;
91  FPoint center() const;
92 
93  void rect( qreal *x, qreal *y, qreal *w, qreal *h ) const;
94  void coords( qreal *x1, qreal *y1, qreal *x2, qreal *y2 ) const;
95 
96  void moveLeft( qreal pos );
97  void moveTop( qreal pos );
98  void moveRight( qreal pos );
99  void moveBottom( qreal pos );
100  void moveTopLeft( FPoint &p );
101  void moveBottomRight( FPoint &p );
102  void moveTopRight( FPoint &p );
103  void moveBottomLeft( FPoint &p );
104  void moveCenter( FPoint &p );
105  void moveBy( qreal dx, qreal dy );
106 
107  void setRect( qreal x, qreal y, qreal w, qreal h );
108  void setCoords( qreal x1, qreal y1, qreal x2, qreal y2 );
109  void addCoords( qreal x1, qreal y1, qreal x2, qreal y2 );
110 
111  FSize size() const;
112  qreal width() const;
113  qreal height() const;
114  void setWidth( qreal w );
115  void setHeight( qreal h );
116  void setSize( const FSize &s );
117 
118  FRect operator|(const FRect &r) const;
119  FRect operator&(const FRect &r) const;
120  FRect& operator|=(const FRect &r);
121  FRect& operator&=(const FRect &r);
122 
123  bool contains( FPoint &p, bool proper=false ) const;
124  bool contains( qreal x, qreal y ) const; // inline methods, _don't_ merge these
125  bool contains( qreal x, qreal y, bool proper ) const;
126  bool contains( const FRect &r, bool proper=false ) const;
127  FRect unite( const FRect &r ) const;
128  FRect intersect( const FRect &r ) const;
129  bool intersects( const FRect &r ) const;
130 
131  friend bool operator==( const FRect &, const FRect & );
132  friend bool operator!=( const FRect &, const FRect & );
133 
134 private:
135 #if defined(Q_OS_LINUX) || defined(Q_OS_TEMP)
136  friend void qt_setCoords( FRect *r, qreal xp1, qreal yp1, qreal xp2, qreal yp2 );
137 #endif
138 
139  qreal x1;
140  qreal y1;
141  qreal x2;
142  qreal y2;
143 
144 };
145 
146 bool operator==( const FRect &, const FRect & );
147 bool operator!=( const FRect &, const FRect & );
148 
149 
150 /*****************************************************************************
151  FRect stream functions
152  *****************************************************************************/
153 // #ifndef QT_NO_DATASTREAM
154 // Q_EXPORT QDataStream &operator<<( QDataStream &, const FRect & );
155 // Q_EXPORT QDataStream &operator>>( QDataStream &, FRect & );
156 // #endif
157 
158 /*****************************************************************************
159  FRect inline member functions
160  *****************************************************************************/
161 
162 inline FRect::FRect( qreal left, qreal top, qreal width, qreal height )
163 {
164  x1 = (qreal)left;
165  y1 = (qreal)top;
166  x2 = (qreal)(left+width-1);
167  y2 = (qreal)(top+height-1);
168 }
169 
170 inline bool FRect::isNull() const
171 { return x2 == x1-1 && y2 == y1-1; }
172 
173 inline bool FRect::isEmpty() const
174 { return x1 > x2 || y1 > y2; }
175 
176 inline bool FRect::isValid() const
177 { return x1 <= x2 && y1 <= y2; }
178 
179 inline qreal FRect::left() const
180 { return x1; }
181 
182 inline qreal FRect::top() const
183 { return y1; }
184 
185 inline qreal FRect::right() const
186 { return x2; }
187 
188 inline qreal FRect::bottom() const
189 { return y2; }
190 
191 inline qreal &FRect::rLeft()
192 { return x1; }
193 
194 inline qreal & FRect::rTop()
195 { return y1; }
196 
197 inline qreal & FRect::rRight()
198 { return x2; }
199 
200 inline qreal & FRect::rBottom()
201 { return y2; }
202 
203 inline qreal FRect::x() const
204 { return x1; }
205 
206 inline qreal FRect::y() const
207 { return y1; }
208 
209 inline void FRect::setLeft( qreal pos )
210 { x1 = (qreal)pos; }
211 
212 inline void FRect::setTop( qreal pos )
213 { y1 = (qreal)pos; }
214 
215 inline void FRect::setRight( qreal pos )
216 { x2 = (qreal)pos; }
217 
218 inline void FRect::setBottom( qreal pos )
219 { y2 = (qreal)pos; }
220 
221 inline void FRect::setX( qreal x )
222 { x1 = (qreal)x; }
223 
224 inline void FRect::setY( qreal y )
225 { y1 = (qreal)y; }
226 
227 inline FPoint FRect::topLeft() const
228 { return FPoint(x1, y1); }
229 
231 { return FPoint(x2, y2); }
232 
233 inline FPoint FRect::topRight() const
234 { return FPoint(x2, y1); }
235 
236 inline FPoint FRect::bottomLeft() const
237 { return FPoint(x1, y2); }
238 
239 inline FPoint FRect::center() const
240 { return FPoint((x1+x2)/2, (y1+y2)/2); }
241 
242 inline qreal FRect::width() const
243 { return x2 - x1 + 1; }
244 
245 inline qreal FRect::height() const
246 { return y2 - y1 + 1; }
247 
248 inline FSize FRect::size() const
249 { return FSize(x2-x1+1, y2-y1+1); }
250 
251 inline bool FRect::contains( qreal x, qreal y, bool proper ) const
252 {
253  if ( proper )
254  return x > x1 && x < x2 &&
255  y > y1 && y < y2;
256  else
257  return x >= x1 && x <= x2 &&
258  y >= y1 && y <= y2;
259 }
260 
261 inline bool FRect::contains( qreal x, qreal y ) const
262 {
263  return x >= x1 && x <= x2 &&
264  y >= y1 && y <= y2;
265 }
266 // #define Q_DEFINED_QRECT
267 // #include "qwinexport.h"
268  #endif // QRECT_H
FRect operator&(const FRect &r) const
Definition: frect.cpp:853
void setBottomRight(FPoint &p)
Definition: frect.cpp:384
FRect operator|(const FRect &r) const
Definition: frect.cpp:817
FPoint topRight() const
Definition: frect.h:233
void setX(qreal x)
Definition: frect.h:221
void coords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const
Definition: frect.cpp:479
qreal right() const
Definition: frect.h:185
void moveCenter(FPoint &p)
Definition: frect.cpp:599
void setHeight(qreal h)
Definition: frect.cpp:715
FRect & operator|=(const FRect &r)
Definition: frect.cpp:791
void moveTop(qreal pos)
Definition: frect.cpp:507
bool contains(FPoint &p, bool proper=false) const
Definition: frect.cpp:741
void setCoords(qreal x1, qreal y1, qreal x2, qreal y2)
Definition: frect.cpp:649
void moveBottom(qreal pos)
Definition: frect.cpp:533
The FSize class defines the size of a two-dimensional object.
Definition: fsize.h:45
void moveTopLeft(FPoint &p)
Definition: frect.cpp:546
FRect normalize() const
Definition: frect.cpp:199
qreal height() const
Definition: frect.h:245
qreal & rLeft()
Definition: frect.h:191
FSize size() const
Definition: frect.h:248
void setRect(qreal x, qreal y, qreal w, qreal h)
Definition: frect.cpp:633
A point with floating point precision.
Definition: fpoint.h:43
void moveLeft(qreal pos)
Definition: frect.cpp:494
qreal & rBottom()
Definition: frect.h:200
qreal left() const
Definition: frect.h:179
FPoint bottomRight() const
Definition: frect.h:230
void moveTopRight(FPoint &p)
Definition: frect.cpp:572
qreal y() const
Definition: frect.h:206
qreal bottom() const
Definition: frect.h:188
bool isValid() const
Definition: frect.h:176
FPoint center() const
Definition: frect.h:239
bool isEmpty() const
Definition: frect.h:173
qreal & rTop()
Definition: frect.h:194
qreal width() const
Definition: frect.h:242
void moveBy(qreal dx, qreal dy)
Definition: frect.cpp:618
bool intersects(const FRect &r) const
Definition: frect.cpp:880
FPoint bottomLeft() const
Definition: frect.h:236
void setRight(qreal pos)
Definition: frect.h:215
void moveRight(qreal pos)
Definition: frect.cpp:520
FRect & operator&=(const FRect &r)
Definition: frect.cpp:800
qreal & rRight()
Definition: frect.h:197
qreal top() const
Definition: frect.h:182
FPoint topLeft() const
Definition: frect.h:227
void setLeft(qreal pos)
Definition: frect.h:209
void moveBottomLeft(FPoint &p)
Definition: frect.cpp:585
void addCoords(qreal x1, qreal y1, qreal x2, qreal y2)
Definition: frect.cpp:662
void setY(qreal y)
Definition: frect.h:224
void setTopRight(FPoint &p)
Definition: frect.cpp:397
void setBottomLeft(FPoint &p)
Definition: frect.cpp:410
void setBottom(qreal pos)
Definition: frect.h:218
void setTop(qreal pos)
Definition: frect.h:212
FRect()
Definition: frect.h:53
void setWidth(qreal w)
Definition: frect.cpp:703
void setSize(const FSize &s)
Definition: frect.cpp:727
The FRect class defines a rectangle in the plane.
Definition: frect.h:50
friend bool operator==(const FRect &, const FRect &)
Definition: frect.cpp:893
void moveBottomRight(FPoint &p)
Definition: frect.cpp:559
void setTopLeft(FPoint &p)
Definition: frect.cpp:371
friend bool operator!=(const FRect &, const FRect &)
Definition: frect.cpp:904
bool isNull() const
Definition: frect.h:170
void rect(qreal *x, qreal *y, qreal *w, qreal *h) const
Definition: frect.cpp:464
qreal x() const
Definition: frect.h:203
FRect unite(const FRect &r) const
Definition: frect.cpp:839
FRect intersect(const FRect &r) const
Definition: frect.cpp:867