~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/tools/qsize.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the core module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef QSIZE_H
 
30
#define QSIZE_H
 
31
 
 
32
#include "QtCore/qnamespace.h"
 
33
 
 
34
class Q_CORE_EXPORT QSize
 
35
{
 
36
public:
 
37
    QSize();
 
38
    QSize(int w, int h);
 
39
 
 
40
    bool isNull() const;
 
41
    bool isEmpty() const;
 
42
    bool isValid() const;
 
43
 
 
44
    int width() const;
 
45
    int height() const;
 
46
    void setWidth(int w);
 
47
    void setHeight(int h);
 
48
    void transpose();
 
49
 
 
50
    void scale(int w, int h, Qt::AspectRatioMode mode);
 
51
    void scale(const QSize &s, Qt::AspectRatioMode mode);
 
52
 
 
53
    QSize expandedTo(const QSize &) const;
 
54
    QSize boundedTo(const QSize &) const;
 
55
 
 
56
    int &rwidth();
 
57
    int &rheight();
 
58
 
 
59
    QSize &operator+=(const QSize &);
 
60
    QSize &operator-=(const QSize &);
 
61
    QSize &operator*=(qreal c);
 
62
    QSize &operator/=(qreal c);
 
63
 
 
64
    friend inline bool operator==(const QSize &, const QSize &);
 
65
    friend inline bool operator!=(const QSize &, const QSize &);
 
66
    friend inline const QSize operator+(const QSize &, const QSize &);
 
67
    friend inline const QSize operator-(const QSize &, const QSize &);
 
68
    friend inline const QSize operator*(const QSize &, qreal);
 
69
    friend inline const QSize operator*(qreal, const QSize &);
 
70
    friend inline const QSize operator/(const QSize &, qreal);
 
71
 
 
72
private:
 
73
    int wd;
 
74
    int ht;
 
75
};
 
76
Q_DECLARE_TYPEINFO(QSize, Q_MOVABLE_TYPE);
 
77
 
 
78
/*****************************************************************************
 
79
  QSize stream functions
 
80
 *****************************************************************************/
 
81
 
 
82
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSize &);
 
83
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
 
84
 
 
85
 
 
86
/*****************************************************************************
 
87
  QSize inline functions
 
88
 *****************************************************************************/
 
89
 
 
90
inline QSize::QSize()
 
91
{ wd = ht = -1; }
 
92
 
 
93
inline QSize::QSize(int w, int h)
 
94
{ wd = w; ht = h; }
 
95
 
 
96
inline bool QSize::isNull() const
 
97
{ return wd==0 && ht==0; }
 
98
 
 
99
inline bool QSize::isEmpty() const
 
100
{ return wd<1 || ht<1; }
 
101
 
 
102
inline bool QSize::isValid() const
 
103
{ return wd>=0 && ht>=0; }
 
104
 
 
105
inline int QSize::width() const
 
106
{ return wd; }
 
107
 
 
108
inline int QSize::height() const
 
109
{ return ht; }
 
110
 
 
111
inline void QSize::setWidth(int w)
 
112
{ wd = w; }
 
113
 
 
114
inline void QSize::setHeight(int h)
 
115
{ ht = h; }
 
116
 
 
117
inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode)
 
118
{ scale(QSize(w, h), mode); }
 
119
 
 
120
inline int &QSize::rwidth()
 
121
{ return wd; }
 
122
 
 
123
inline int &QSize::rheight()
 
124
{ return ht; }
 
125
 
 
126
inline QSize &QSize::operator+=(const QSize &s)
 
127
{ wd+=s.wd; ht+=s.ht; return *this; }
 
128
 
 
129
inline QSize &QSize::operator-=(const QSize &s)
 
130
{ wd-=s.wd; ht-=s.ht; return *this; }
 
131
 
 
132
inline QSize &QSize::operator*=(qreal c)
 
133
{ wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
 
134
 
 
135
inline bool operator==(const QSize &s1, const QSize &s2)
 
136
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
 
137
 
 
138
inline bool operator!=(const QSize &s1, const QSize &s2)
 
139
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
 
140
 
 
141
inline const QSize operator+(const QSize & s1, const QSize & s2)
 
142
{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
 
143
 
 
144
inline const QSize operator-(const QSize &s1, const QSize &s2)
 
145
{ return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
 
146
 
 
147
inline const QSize operator*(const QSize &s, qreal c)
 
148
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
 
149
 
 
150
inline const QSize operator*(qreal c, const QSize &s)
 
151
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
 
152
 
 
153
inline QSize &QSize::operator/=(qreal c)
 
154
{
 
155
    Q_ASSERT(c != 0.0);
 
156
    wd = qRound(wd/c); ht = qRound(ht/c);
 
157
    return *this;
 
158
}
 
159
 
 
160
inline const QSize operator/(const QSize &s, qreal c)
 
161
{
 
162
    Q_ASSERT(c != 0.0);
 
163
    return QSize(qRound(s.wd/c), qRound(s.ht/c));
 
164
}
 
165
 
 
166
inline QSize QSize::expandedTo(const QSize & otherSize) const
 
167
{
 
168
    return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
 
169
}
 
170
 
 
171
inline QSize QSize::boundedTo(const QSize & otherSize) const
 
172
{
 
173
    return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
 
174
}
 
175
 
 
176
#ifndef QT_NO_DEBUG_STREAM
 
177
Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
 
178
#endif
 
179
 
 
180
 
 
181
class Q_CORE_EXPORT QSizeF
 
182
{
 
183
public:
 
184
    QSizeF();
 
185
    QSizeF(const QSize &sz);
 
186
    QSizeF(qreal w, qreal h);
 
187
 
 
188
    bool isNull() const;
 
189
    bool isEmpty() const;
 
190
    bool isValid() const;
 
191
 
 
192
    qreal width() const;
 
193
    qreal height() const;
 
194
    void setWidth(qreal w);
 
195
    void setHeight(qreal h);
 
196
    void transpose();
 
197
 
 
198
    void scale(qreal w, qreal h, Qt::AspectRatioMode mode);
 
199
    void scale(const QSizeF &s, Qt::AspectRatioMode mode);
 
200
 
 
201
    QSizeF expandedTo(const QSizeF &) const;
 
202
    QSizeF boundedTo(const QSizeF &) const;
 
203
 
 
204
    qreal &rwidth();
 
205
    qreal &rheight();
 
206
 
 
207
    QSizeF &operator+=(const QSizeF &);
 
208
    QSizeF &operator-=(const QSizeF &);
 
209
    QSizeF &operator*=(qreal c);
 
210
    QSizeF &operator/=(qreal c);
 
211
 
 
212
    friend inline bool operator==(const QSizeF &, const QSizeF &);
 
213
    friend inline bool operator!=(const QSizeF &, const QSizeF &);
 
214
    friend inline const QSizeF operator+(const QSizeF &, const QSizeF &);
 
215
    friend inline const QSizeF operator-(const QSizeF &, const QSizeF &);
 
216
    friend inline const QSizeF operator*(const QSizeF &, qreal);
 
217
    friend inline const QSizeF operator*(qreal, const QSizeF &);
 
218
    friend inline const QSizeF operator/(const QSizeF &, qreal);
 
219
 
 
220
    inline QSize toSize() const;
 
221
 
 
222
private:
 
223
    qreal wd;
 
224
    qreal ht;
 
225
};
 
226
Q_DECLARE_TYPEINFO(QSizeF, Q_MOVABLE_TYPE);
 
227
 
 
228
 
 
229
/*****************************************************************************
 
230
  QSizeF stream functions
 
231
 *****************************************************************************/
 
232
 
 
233
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSizeF &);
 
234
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
 
235
 
 
236
 
 
237
/*****************************************************************************
 
238
  QSizeF inline functions
 
239
 *****************************************************************************/
 
240
 
 
241
inline QSizeF::QSizeF()
 
242
{ wd = ht = -1.; }
 
243
 
 
244
inline QSizeF::QSizeF(const QSize &sz)
 
245
    : wd(sz.width()), ht(sz.height())
 
246
{
 
247
}
 
248
 
 
249
inline QSizeF::QSizeF(qreal w, qreal h)
 
250
{ wd = w; ht = h; }
 
251
 
 
252
inline bool QSizeF::isNull() const
 
253
{ return wd == 0 && ht == 0; }
 
254
 
 
255
inline bool QSizeF::isEmpty() const
 
256
{ return wd <= 0. || ht <= 0.; }
 
257
 
 
258
inline bool QSizeF::isValid() const
 
259
{ return wd >= 0. && ht >= 0.; }
 
260
 
 
261
inline qreal QSizeF::width() const
 
262
{ return wd; }
 
263
 
 
264
inline qreal QSizeF::height() const
 
265
{ return ht; }
 
266
 
 
267
inline void QSizeF::setWidth(qreal w)
 
268
{ wd = w; }
 
269
 
 
270
inline void QSizeF::setHeight(qreal h)
 
271
{ ht = h; }
 
272
 
 
273
inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode)
 
274
{ scale(QSizeF(w, h), mode); }
 
275
 
 
276
inline qreal &QSizeF::rwidth()
 
277
{ return wd; }
 
278
 
 
279
inline qreal &QSizeF::rheight()
 
280
{ return ht; }
 
281
 
 
282
inline QSizeF &QSizeF::operator+=(const QSizeF &s)
 
283
{ wd += s.wd; ht += s.ht; return *this; }
 
284
 
 
285
inline QSizeF &QSizeF::operator-=(const QSizeF &s)
 
286
{ wd -= s.wd; ht -= s.ht; return *this; }
 
287
 
 
288
inline QSizeF &QSizeF::operator*=(qreal c)
 
289
{ wd *= c; ht *= c; return *this; }
 
290
 
 
291
inline bool operator==(const QSizeF &s1, const QSizeF &s2)
 
292
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
 
293
 
 
294
inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
 
295
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
 
296
 
 
297
inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2)
 
298
{ return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); }
 
299
 
 
300
inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
 
301
{ return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); }
 
302
 
 
303
inline const QSizeF operator*(const QSizeF &s, qreal c)
 
304
{ return QSizeF(s.wd*c, s.ht*c); }
 
305
 
 
306
inline const QSizeF operator*(qreal c, const QSizeF &s)
 
307
{ return QSizeF(s.wd*c, s.ht*c); }
 
308
 
 
309
inline QSizeF &QSizeF::operator/=(qreal c)
 
310
{
 
311
    Q_ASSERT(c != 0.0);
 
312
    wd = wd/c; ht = ht/c;
 
313
    return *this;
 
314
}
 
315
 
 
316
inline const QSizeF operator/(const QSizeF &s, qreal c)
 
317
{
 
318
    Q_ASSERT(c != 0.0);
 
319
    return QSizeF(s.wd/c, s.ht/c);
 
320
}
 
321
 
 
322
inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const
 
323
{
 
324
    return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
 
325
}
 
326
 
 
327
inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const
 
328
{
 
329
    return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
 
330
}
 
331
 
 
332
inline QSize QSizeF::toSize() const
 
333
{
 
334
    return QSize(qRound(wd), qRound(ht));
 
335
}
 
336
 
 
337
#ifndef QT_NO_DEBUG_STREAM
 
338
Q_CORE_EXPORT QDebug operator<<(QDebug, const QSizeF &);
 
339
#endif
 
340
 
 
341
#endif // QSIZE_H