1 /****************************************************************************
3 ** This file is based on sources of the Qt GUI Toolkit, used under the terms
4 ** of the GNU General Public License version 2 (see the original copyright
6 ** All further contributions to this file are (and are required to be)
7 ** licensed under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
11 ** The original Qt license header follows:
14 ** Definition of QSize class
18 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
20 ** This file is part of the kernel module of the Qt GUI Toolkit.
22 ** This file may be distributed under the terms of the Q Public License
23 ** as defined by Trolltech AS of Norway and appearing in the file
24 ** LICENSE.QPL included in the packaging of this file.
26 ** This file may be distributed and/or modified under the terms of the
27 ** GNU General Public License version 2 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file.
31 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
32 ** licenses may use this file in accordance with the Qt Commercial License
33 ** Agreement provided with the Software.
35 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
36 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
38 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
39 ** information about Qt Commercial License Agreements.
40 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
41 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
43 ** Contact info@trolltech.com if any conditions of this licensing are
46 **********************************************************************/
52 #include "qpoint.h" // ### change to qwindowdefs.h?
56 // ### Make QSize inherit Qt in Qt 4.0
59 // ### Move this enum to qnamespace.h in Qt 4.0
67 QSize( int w
, int h
);
75 void setWidth( int w
);
76 void setHeight( int h
);
79 void scale( int w
, int h
, ScaleMode mode
);
80 void scale( const QSize
&s
, ScaleMode mode
);
82 QSize
expandedTo( const QSize
& ) const;
83 QSize
boundedTo( const QSize
& ) const;
88 QSize
&operator+=( const QSize
& );
89 QSize
&operator-=( const QSize
& );
90 QSize
&operator*=( int c
);
91 QSize
&operator*=( double c
);
92 QSize
&operator/=( int c
);
93 QSize
&operator/=( double c
);
95 friend inline bool operator==( const QSize
&, const QSize
& );
96 friend inline bool operator!=( const QSize
&, const QSize
& );
97 friend inline const QSize
operator+( const QSize
&, const QSize
& );
98 friend inline const QSize
operator-( const QSize
&, const QSize
& );
99 friend inline const QSize
operator*( const QSize
&, int );
100 friend inline const QSize
operator*( int, const QSize
& );
101 friend inline const QSize
operator*( const QSize
&, double );
102 friend inline const QSize
operator*( double, const QSize
& );
103 friend inline const QSize
operator/( const QSize
&, int );
104 friend inline const QSize
operator/( const QSize
&, double );
107 static void warningDivByZero();
114 /*****************************************************************************
115 QSize stream functions
116 *****************************************************************************/
118 #ifndef QT_NO_DATASTREAM
119 Q_EXPORT QDataStream
&operator<<( QDataStream
&, const QSize
& );
120 Q_EXPORT QDataStream
&operator>>( QDataStream
&, QSize
& );
123 /*****************************************************************************
124 QSize inline functions
125 *****************************************************************************/
127 inline QSize::QSize()
130 inline QSize::QSize( int w
, int h
)
131 { wd
=(QCOORD
)w
; ht
=(QCOORD
)h
; }
133 inline bool QSize::isNull() const
134 { return wd
==0 && ht
==0; }
136 inline bool QSize::isEmpty() const
137 { return wd
<1 || ht
<1; }
139 inline bool QSize::isValid() const
140 { return wd
>=0 && ht
>=0; }
142 inline int QSize::width() const
145 inline int QSize::height() const
148 inline void QSize::setWidth( int w
)
151 inline void QSize::setHeight( int h
)
154 inline QCOORD
&QSize::rwidth()
157 inline QCOORD
&QSize::rheight()
160 inline QSize
&QSize::operator+=( const QSize
&s
)
161 { wd
+=s
.wd
; ht
+=s
.ht
; return *this; }
163 inline QSize
&QSize::operator-=( const QSize
&s
)
164 { wd
-=s
.wd
; ht
-=s
.ht
; return *this; }
166 inline QSize
&QSize::operator*=( int c
)
167 { wd
*=(QCOORD
)c
; ht
*=(QCOORD
)c
; return *this; }
169 inline QSize
&QSize::operator*=( double c
)
170 { wd
=(QCOORD
)(wd
*c
); ht
=(QCOORD
)(ht
*c
); return *this; }
172 inline bool operator==( const QSize
&s1
, const QSize
&s2
)
173 { return s1
.wd
== s2
.wd
&& s1
.ht
== s2
.ht
; }
175 inline bool operator!=( const QSize
&s1
, const QSize
&s2
)
176 { return s1
.wd
!= s2
.wd
|| s1
.ht
!= s2
.ht
; }
178 inline const QSize
operator+( const QSize
& s1
, const QSize
& s2
)
179 { return QSize(s1
.wd
+s2
.wd
, s1
.ht
+s2
.ht
); }
181 inline const QSize
operator-( const QSize
&s1
, const QSize
&s2
)
182 { return QSize(s1
.wd
-s2
.wd
, s1
.ht
-s2
.ht
); }
184 inline const QSize
operator*( const QSize
&s
, int c
)
185 { return QSize(s
.wd
*c
, s
.ht
*c
); }
187 inline const QSize
operator*( int c
, const QSize
&s
)
188 { return QSize(s
.wd
*c
, s
.ht
*c
); }
190 inline const QSize
operator*( const QSize
&s
, double c
)
191 { return QSize((QCOORD
)(s
.wd
*c
), (QCOORD
)(s
.ht
*c
)); }
193 inline const QSize
operator*( double c
, const QSize
&s
)
194 { return QSize((QCOORD
)(s
.wd
*c
), (QCOORD
)(s
.ht
*c
)); }
196 inline QSize
&QSize::operator/=( int c
)
198 #if defined(QT_CHECK_MATH)
202 wd
/=(QCOORD
)c
; ht
/=(QCOORD
)c
;
206 inline QSize
&QSize::operator/=( double c
)
208 #if defined(QT_CHECK_MATH)
212 wd
=(QCOORD
)(wd
/c
); ht
=(QCOORD
)(ht
/c
);
216 inline const QSize
operator/( const QSize
&s
, int c
)
218 #if defined(QT_CHECK_MATH)
220 QSize::warningDivByZero();
222 return QSize(s
.wd
/c
, s
.ht
/c
);
225 inline const QSize
operator/( const QSize
&s
, double c
)
227 #if defined(QT_CHECK_MATH)
229 QSize::warningDivByZero();
231 return QSize((QCOORD
)(s
.wd
/c
), (QCOORD
)(s
.ht
/c
));
234 inline QSize
QSize::expandedTo( const QSize
& otherSize
) const
236 return QSize( qMax(wd
,otherSize
.wd
), qMax(ht
,otherSize
.ht
) );
239 inline QSize
QSize::boundedTo( const QSize
& otherSize
) const
241 return QSize( qMin(wd
,otherSize
.wd
), qMin(ht
,otherSize
.ht
) );