Scribus
Open source desktop publishing at your fingertips
fsize.h
1 /****************************************************************************
2 ** $Id: fsize.h 13161 2009-02-07 00:36:14Z malex $
3 **
4 ** Definition of FSize 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 FSIZE_H
39 #define FSIZE_H
40 
41 // #ifndef QT_H
42  #include "../fpoint.h" // ### change to qwindowdefs.h?
43 // #endif // QT_H
44 
45 class FSize
46 // ### Make FSize inherit Qt in Qt 4.0
47 {
48 public:
49  // ### Move this enum to qnamespace.h in Qt 4.0
50  enum ScaleMode {
51  ScaleFree,
52  ScaleMin,
53  ScaleMax
54  };
55 
56  FSize();
57  FSize( qreal w, qreal h );
58 
59  bool isNull() const;
60  bool isEmpty() const;
61  bool isValid() const;
62 
63  qreal width() const;
64  qreal height() const;
65  void setWidth( qreal w );
66  void setHeight( qreal h );
67  void transpose();
68 
69  void scale( qreal w, qreal h, Qt::AspectRatioMode mode );
70  void scale( const FSize &s, Qt::AspectRatioMode mode );
71 
72  FSize expandedTo( const FSize & ) const;
73  FSize boundedTo( const FSize & ) const;
74 
75  qreal &rwidth();
76  qreal &rheight();
77 
78  FSize &operator+=( const FSize & );
79  FSize &operator-=( const FSize & );
80  FSize &operator*=( int c );
81  FSize &operator*=( qreal c );
82  FSize &operator/=( int c );
83  FSize &operator/=( qreal c );
84 
85  friend inline bool operator==( const FSize &, const FSize & );
86  friend inline bool operator!=( const FSize &, const FSize & );
87  friend inline const FSize operator+( const FSize &, const FSize & );
88  friend inline const FSize operator-( const FSize &, const FSize & );
89  friend inline const FSize operator*( const FSize &, int );
90  friend inline const FSize operator*( int, const FSize & );
91  friend inline const FSize operator*( const FSize &, qreal );
92  friend inline const FSize operator*( qreal, const FSize & );
93  friend inline const FSize operator/( const FSize &, int );
94  friend inline const FSize operator/( const FSize &, qreal );
95 
96 private:
97  static void warningDivByZero();
98 
99  qreal wd;
100  qreal ht;
101 };
102 
103 
104 /*****************************************************************************
105  FSize stream functions
106  *****************************************************************************/
107 
108 // QDataStream &operator<<( QDataStream &, const FSize & );
109 // QDataStream &operator>>( QDataStream &, FSize & );
110 
111 
112 /*****************************************************************************
113  FSize inline functions
114  *****************************************************************************/
115 
116 inline FSize::FSize()
117 { wd = ht = -1; }
118 
119 inline FSize::FSize( qreal w, qreal h )
120 { wd=(qreal)w; ht=(qreal)h; }
121 
122 inline bool FSize::isNull() const
123 { return wd==0 && ht==0; }
124 
125 inline bool FSize::isEmpty() const
126 { return wd<1 || ht<1; }
127 
128 inline bool FSize::isValid() const
129 { return wd>=0 && ht>=0; }
130 
131 inline qreal FSize::width() const
132 { return wd; }
133 
134 inline qreal FSize::height() const
135 { return ht; }
136 
137 inline void FSize::setWidth( qreal w )
138 { wd=(qreal)w; }
139 
140 inline void FSize::setHeight( qreal h )
141 { ht=(qreal)h; }
142 
143 inline qreal &FSize::rwidth()
144 { return wd; }
145 
146 inline qreal &FSize::rheight()
147 { return ht; }
148 
149 inline FSize &FSize::operator+=( const FSize &s )
150 { wd+=s.wd; ht+=s.ht; return *this; }
151 
152 inline FSize &FSize::operator-=( const FSize &s )
153 { wd-=s.wd; ht-=s.ht; return *this; }
154 
155 inline FSize &FSize::operator*=( int c )
156 { wd*=(qreal)c; ht*=(qreal)c; return *this; }
157 
158 inline FSize &FSize::operator*=( qreal c )
159 { wd=(qreal)(wd*c); ht=(qreal)(ht*c); return *this; }
160 
161 inline bool operator==( const FSize &s1, const FSize &s2 )
162 { return s1.wd == s2.wd && s1.ht == s2.ht; }
163 
164 inline bool operator!=( const FSize &s1, const FSize &s2 )
165 { return s1.wd != s2.wd || s1.ht != s2.ht; }
166 
167 inline const FSize operator+( const FSize & s1, const FSize & s2 )
168 { return FSize(s1.wd+s2.wd, s1.ht+s2.ht); }
169 
170 inline const FSize operator-( const FSize &s1, const FSize &s2 )
171 { return FSize(s1.wd-s2.wd, s1.ht-s2.ht); }
172 
173 inline const FSize operator*( const FSize &s, int c )
174 { return FSize(s.wd*c, s.ht*c); }
175 
176 inline const FSize operator*( int c, const FSize &s )
177 { return FSize(s.wd*c, s.ht*c); }
178 
179 inline const FSize operator*( const FSize &s, qreal c )
180 { return FSize((qreal)(s.wd*c), (qreal)(s.ht*c)); }
181 
182 inline const FSize operator*( qreal c, const FSize &s )
183 { return FSize((qreal)(s.wd*c), (qreal)(s.ht*c)); }
184 
185 inline FSize &FSize::operator/=( int c )
186 {
187 #if defined(QT_CHECK_MATH)
188  if ( c == 0 )
189  warningDivByZero();
190 #endif
191  wd/=(qreal)c; ht/=(qreal)c;
192  return *this;
193 }
194 
195 inline FSize &FSize::operator/=( qreal c )
196 {
197 #if defined(QT_CHECK_MATH)
198  if ( c == 0.0 )
199  warningDivByZero();
200 #endif
201  wd=(qreal)(wd/c); ht=(qreal)(ht/c);
202  return *this;
203 }
204 
205 inline const FSize operator/( const FSize &s, int c )
206 {
207 #if defined(QT_CHECK_MATH)
208  if ( c == 0 )
209  FSize::warningDivByZero();
210 #endif
211  return FSize(s.wd/c, s.ht/c);
212 }
213 
214 inline const FSize operator/( const FSize &s, qreal c )
215 {
216 #if defined(QT_CHECK_MATH)
217  if ( c == 0.0 )
218  FSize::warningDivByZero();
219 #endif
220  return FSize((qreal)(s.wd/c), (qreal)(s.ht/c));
221 }
222 
223 inline FSize FSize::expandedTo( const FSize & otherSize ) const
224 {
225  return FSize( qMax(wd,otherSize.wd), qMax(ht,otherSize.ht) );
226 }
227 
228 inline FSize FSize::boundedTo( const FSize & otherSize ) const
229 {
230  return FSize( qMin(wd,otherSize.wd), qMin(ht,otherSize.ht) );
231 }
232 
233 
234 #endif // QSIZE_H
FSize expandedTo(const FSize &) const
Definition: fsize.h:223
bool isNull() const
Definition: fsize.h:122
void setWidth(qreal w)
Definition: fsize.h:137
qreal width() const
Definition: fsize.h:131
FSize & operator-=(const FSize &)
Definition: fsize.h:152
FSize & operator+=(const FSize &)
Definition: fsize.h:149
friend bool operator!=(const FSize &, const FSize &)
Definition: fsize.h:164
The FSize class defines the size of a two-dimensional object.
Definition: fsize.h:45
void transpose()
Definition: fsize.cpp:127
bool isEmpty() const
Definition: fsize.h:125
qreal height() const
Definition: fsize.h:134
void scale(qreal w, qreal h, Qt::AspectRatioMode mode)
Definition: fsize.cpp:176
friend bool operator==(const FSize &, const FSize &)
Definition: fsize.h:161
void setHeight(qreal h)
Definition: fsize.h:140
friend const FSize operator+(const FSize &, const FSize &)
Definition: fsize.h:167
friend const FSize operator-(const FSize &, const FSize &)
Definition: fsize.h:170
FSize boundedTo(const FSize &) const
Definition: fsize.h:228
ScaleMode
Definition: fsize.h:50
qreal & rwidth()
Definition: fsize.h:143
bool isValid() const
Definition: fsize.h:128
qreal & rheight()
Definition: fsize.h:146
FSize()
Definition: fsize.h:116