1 /****************************************************************************
2 ** $Id: qt/qsize.h 3.3.8 edited Jan 11 14:38 $
3 **
4 ** Definition of QSize class
5 **
6 ** Created : 931028
7 **
8 ** Copyright (C) 1992-2007 Trolltech ASA. 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 ASA 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 QSIZE_H
39 #define QSIZE_H
40
41 #ifndef QT_H
42 #include "qpoint.h" // ### change to qwindowdefs.h?
43 #endif // QT_H
44
45 class Q_EXPORT QSize
46 // ### Make QSize 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 QSize();
57 QSize( int w, int h );
58
59 bool isNull() const;
60 bool isEmpty() const;
61 bool isValid() const;
62
63 int width() const;
64 int height() const;
65 void setWidth( int w );
66 void setHeight( int h );
67 void transpose();
68
69 void scale( int w, int h, ScaleMode mode );
70 void scale( const QSize &s, ScaleMode mode );
71
72 QSize expandedTo( const QSize & ) const;
73 QSize boundedTo( const QSize & ) const;
74
75 QCOORD &rwidth();
76 QCOORD &rheight();
77
78 QSize &operator+=( const QSize & );
79 QSize &operator-=( const QSize & );
80 QSize &operator*=( int c );
81 QSize &operator*=( double c );
82 QSize &operator/=( int c );
83 QSize &operator/=( double c );
84
85 friend inline bool operator==( const QSize &, const QSize & );
86 friend inline bool operator!=( const QSize &, const QSize & );
87 friend inline const QSize operator+( const QSize &, const QSize & );
88 friend inline const QSize operator-( const QSize &, const QSize & );
89 friend inline const QSize operator*( const QSize &, int );
90 friend inline const QSize operator*( int, const QSize & );
91 friend inline const QSize operator*( const QSize &, double );
92 friend inline const QSize operator*( double, const QSize & );
93 friend inline const QSize operator/( const QSize &, int );
94 friend inline const QSize operator/( const QSize &, double );
95
96 private:
97 static void warningDivByZero();
98
99 QCOORD wd;
100 QCOORD ht;
101 };
102
103
104 /*****************************************************************************
105 QSize stream functions
106 *****************************************************************************/
107
108 Q_EXPORT QDataStream &operator<<( QDataStream &, const QSize & );
109 Q_EXPORT QDataStream &operator>>( QDataStream &, QSize & );
110
111
112 /*****************************************************************************
113 QSize inline functions
114 *****************************************************************************/
115
QSize()116 inline QSize::QSize()
117 { wd = ht = -1; }
118
QSize(int w,int h)119 inline QSize::QSize( int w, int h )
120 { wd=(QCOORD)w; ht=(QCOORD)h; }
121
isNull()122 inline bool QSize::isNull() const
123 { return wd==0 && ht==0; }
124
isEmpty()125 inline bool QSize::isEmpty() const
126 { return wd<1 || ht<1; }
127
isValid()128 inline bool QSize::isValid() const
129 { return wd>=0 && ht>=0; }
130
width()131 inline int QSize::width() const
132 { return wd; }
133
height()134 inline int QSize::height() const
135 { return ht; }
136
setWidth(int w)137 inline void QSize::setWidth( int w )
138 { wd=(QCOORD)w; }
139
setHeight(int h)140 inline void QSize::setHeight( int h )
141 { ht=(QCOORD)h; }
142
rwidth()143 inline QCOORD &QSize::rwidth()
144 { return wd; }
145
rheight()146 inline QCOORD &QSize::rheight()
147 { return ht; }
148
149 inline QSize &QSize::operator+=( const QSize &s )
150 { wd+=s.wd; ht+=s.ht; return *this; }
151
152 inline QSize &QSize::operator-=( const QSize &s )
153 { wd-=s.wd; ht-=s.ht; return *this; }
154
155 inline QSize &QSize::operator*=( int c )
156 { wd*=(QCOORD)c; ht*=(QCOORD)c; return *this; }
157
158 inline QSize &QSize::operator*=( double c )
159 { wd=(QCOORD)(wd*c); ht=(QCOORD)(ht*c); return *this; }
160
161 inline bool operator==( const QSize &s1, const QSize &s2 )
162 { return s1.wd == s2.wd && s1.ht == s2.ht; }
163
164 inline bool operator!=( const QSize &s1, const QSize &s2 )
165 { return s1.wd != s2.wd || s1.ht != s2.ht; }
166
167 inline const QSize operator+( const QSize & s1, const QSize & s2 )
168 { return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
169
170 inline const QSize operator-( const QSize &s1, const QSize &s2 )
171 { return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
172
173 inline const QSize operator*( const QSize &s, int c )
174 { return QSize(s.wd*c, s.ht*c); }
175
176 inline const QSize operator*( int c, const QSize &s )
177 { return QSize(s.wd*c, s.ht*c); }
178
179 inline const QSize operator*( const QSize &s, double c )
180 { return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
181
182 inline const QSize operator*( double c, const QSize &s )
183 { return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
184
185 inline QSize &QSize::operator/=( int c )
186 {
187 #if defined(QT_CHECK_MATH)
188 if ( c == 0 )
189 warningDivByZero();
190 #endif
191 wd/=(QCOORD)c; ht/=(QCOORD)c;
192 return *this;
193 }
194
195 inline QSize &QSize::operator/=( double c )
196 {
197 #if defined(QT_CHECK_MATH)
198 if ( c == 0.0 )
199 warningDivByZero();
200 #endif
201 wd=(QCOORD)(wd/c); ht=(QCOORD)(ht/c);
202 return *this;
203 }
204
205 inline const QSize operator/( const QSize &s, int c )
206 {
207 #if defined(QT_CHECK_MATH)
208 if ( c == 0 )
209 QSize::warningDivByZero();
210 #endif
211 return QSize(s.wd/c, s.ht/c);
212 }
213
214 inline const QSize operator/( const QSize &s, double c )
215 {
216 #if defined(QT_CHECK_MATH)
217 if ( c == 0.0 )
218 QSize::warningDivByZero();
219 #endif
220 return QSize((QCOORD)(s.wd/c), (QCOORD)(s.ht/c));
221 }
222
expandedTo(const QSize & otherSize)223 inline QSize QSize::expandedTo( const QSize & otherSize ) const
224 {
225 return QSize( QMAX(wd,otherSize.wd), QMAX(ht,otherSize.ht) );
226 }
227
boundedTo(const QSize & otherSize)228 inline QSize QSize::boundedTo( const QSize & otherSize ) const
229 {
230 return QSize( QMIN(wd,otherSize.wd), QMIN(ht,otherSize.ht) );
231 }
232
233
234 #endif // QSIZE_H
235