1 /****************************************************************************
2 ** $Id: fsize.h 20691 2016-01-17 14:41:01Z craig $
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 m_wd;
100 	qreal m_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 
FSize()116 inline FSize::FSize()
117 { m_wd = m_ht = -1; }
118 
FSize(qreal w,qreal h)119 inline FSize::FSize( qreal w, qreal h )
120 { m_wd=(qreal)w; m_ht=(qreal)h; }
121 
isNull()122 inline bool FSize::isNull() const
123 { return m_wd==0 && m_ht==0; }
124 
isEmpty()125 inline bool FSize::isEmpty() const
126 { return m_wd<1 || m_ht<1; }
127 
isValid()128 inline bool FSize::isValid() const
129 { return m_wd>=0 && m_ht>=0; }
130 
width()131 inline qreal FSize::width() const
132 { return m_wd; }
133 
height()134 inline qreal FSize::height() const
135 { return m_ht; }
136 
setWidth(qreal w)137 inline void FSize::setWidth( qreal w )
138 { m_wd=(qreal)w; }
139 
setHeight(qreal h)140 inline void FSize::setHeight( qreal h )
141 { m_ht=(qreal)h; }
142 
rwidth()143 inline qreal &FSize::rwidth()
144 { return m_wd; }
145 
rheight()146 inline qreal &FSize::rheight()
147 { return m_ht; }
148 
149 inline FSize &FSize::operator+=( const FSize &s )
150 { m_wd+=s.m_wd; m_ht+=s.m_ht; return *this; }
151 
152 inline FSize &FSize::operator-=( const FSize &s )
153 { m_wd-=s.m_wd; m_ht-=s.m_ht; return *this; }
154 
155 inline FSize &FSize::operator*=( int c )
156 { m_wd*=(qreal)c; m_ht*=(qreal)c; return *this; }
157 
158 inline FSize &FSize::operator*=( qreal c )
159 { m_wd=(qreal)(m_wd*c); m_ht=(qreal)(m_ht*c); return *this; }
160 
161 inline bool operator==( const FSize &s1, const FSize &s2 )
162 { return s1.m_wd == s2.m_wd && s1.m_ht == s2.m_ht; }
163 
164 inline bool operator!=( const FSize &s1, const FSize &s2 )
165 { return s1.m_wd != s2.m_wd || s1.m_ht != s2.m_ht; }
166 
167 inline const FSize operator+( const FSize & s1, const FSize & s2 )
168 { return FSize(s1.m_wd+s2.m_wd, s1.m_ht+s2.m_ht); }
169 
170 inline const FSize operator-( const FSize &s1, const FSize &s2 )
171 { return FSize(s1.m_wd-s2.m_wd, s1.m_ht-s2.m_ht); }
172 
173 inline const FSize operator*( const FSize &s, int c )
174 { return FSize(s.m_wd*c, s.m_ht*c); }
175 
176 inline const FSize operator*( int c, const FSize &s )
177 {  return FSize(s.m_wd*c, s.m_ht*c); }
178 
179 inline const FSize operator*( const FSize &s, qreal c )
180 { return FSize((qreal)(s.m_wd*c), (qreal)(s.m_ht*c)); }
181 
182 inline const FSize operator*( qreal c, const FSize &s )
183 { return FSize((qreal)(s.m_wd*c), (qreal)(s.m_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 	m_wd/=(qreal)c; m_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 	m_wd=(qreal)(m_wd/c); m_ht=(qreal)(m_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.m_wd/c, s.m_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.m_wd/c), (qreal)(s.m_ht/c));
221 }
222 
expandedTo(const FSize & otherSize)223 inline FSize FSize::expandedTo( const FSize & otherSize ) const
224 {
225 	return FSize( qMax(m_wd,otherSize.m_wd), qMax(m_ht,otherSize.m_ht) );
226 }
227 
boundedTo(const FSize & otherSize)228 inline FSize FSize::boundedTo( const FSize & otherSize ) const
229 {
230 	return FSize( qMin(m_wd,otherSize.m_wd), qMin(m_ht,otherSize.m_ht) );
231 }
232 
233 
234 #endif // QSIZE_H
235