source: trunk/include/qsize.h@ 102

Last change on this file since 102 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1/****************************************************************************
2** $Id: qsize.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of QSize 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 QSIZE_H
39#define QSIZE_H
40
41#ifndef QT_H
42#include "qpoint.h" // ### change to qwindowdefs.h?
43#endif // QT_H
44
45class Q_EXPORT QSize
46// ### Make QSize inherit Qt in Qt 4.0
47{
48public:
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
96private:
97 static void warningDivByZero();
98
99 QCOORD wd;
100 QCOORD ht;
101};
102
103
104/*****************************************************************************
105 QSize stream functions
106 *****************************************************************************/
107
108Q_EXPORT QDataStream &operator<<( QDataStream &, const QSize & );
109Q_EXPORT QDataStream &operator>>( QDataStream &, QSize & );
110
111
112/*****************************************************************************
113 QSize inline functions
114 *****************************************************************************/
115
116inline QSize::QSize()
117{ wd = ht = -1; }
118
119inline QSize::QSize( int w, int h )
120{ wd=(QCOORD)w; ht=(QCOORD)h; }
121
122inline bool QSize::isNull() const
123{ return wd==0 && ht==0; }
124
125inline bool QSize::isEmpty() const
126{ return wd<1 || ht<1; }
127
128inline bool QSize::isValid() const
129{ return wd>=0 && ht>=0; }
130
131inline int QSize::width() const
132{ return wd; }
133
134inline int QSize::height() const
135{ return ht; }
136
137inline void QSize::setWidth( int w )
138{ wd=(QCOORD)w; }
139
140inline void QSize::setHeight( int h )
141{ ht=(QCOORD)h; }
142
143inline QCOORD &QSize::rwidth()
144{ return wd; }
145
146inline QCOORD &QSize::rheight()
147{ return ht; }
148
149inline QSize &QSize::operator+=( const QSize &s )
150{ wd+=s.wd; ht+=s.ht; return *this; }
151
152inline QSize &QSize::operator-=( const QSize &s )
153{ wd-=s.wd; ht-=s.ht; return *this; }
154
155inline QSize &QSize::operator*=( int c )
156{ wd*=(QCOORD)c; ht*=(QCOORD)c; return *this; }
157
158inline QSize &QSize::operator*=( double c )
159{ wd=(QCOORD)(wd*c); ht=(QCOORD)(ht*c); return *this; }
160
161inline bool operator==( const QSize &s1, const QSize &s2 )
162{ return s1.wd == s2.wd && s1.ht == s2.ht; }
163
164inline bool operator!=( const QSize &s1, const QSize &s2 )
165{ return s1.wd != s2.wd || s1.ht != s2.ht; }
166
167inline const QSize operator+( const QSize & s1, const QSize & s2 )
168{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
169
170inline const QSize operator-( const QSize &s1, const QSize &s2 )
171{ return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
172
173inline const QSize operator*( const QSize &s, int c )
174{ return QSize(s.wd*c, s.ht*c); }
175
176inline const QSize operator*( int c, const QSize &s )
177{ return QSize(s.wd*c, s.ht*c); }
178
179inline const QSize operator*( const QSize &s, double c )
180{ return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
181
182inline const QSize operator*( double c, const QSize &s )
183{ return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
184
185inline 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
195inline 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
205inline 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
214inline 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
223inline QSize QSize::expandedTo( const QSize & otherSize ) const
224{
225 return QSize( QMAX(wd,otherSize.wd), QMAX(ht,otherSize.ht) );
226}
227
228inline 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
Note: See TracBrowser for help on using the repository browser.