1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
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.
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.
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.
21
** Contact info@trolltech.com if any conditions of this licensing are
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.
27
****************************************************************************/
32
#include "QtCore/qnamespace.h"
34
class Q_CORE_EXPORT QSize
47
void setHeight(int h);
50
void scale(int w, int h, Qt::AspectRatioMode mode);
51
void scale(const QSize &s, Qt::AspectRatioMode mode);
53
QSize expandedTo(const QSize &) const;
54
QSize boundedTo(const QSize &) const;
59
QSize &operator+=(const QSize &);
60
QSize &operator-=(const QSize &);
61
QSize &operator*=(qreal c);
62
QSize &operator/=(qreal c);
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);
76
Q_DECLARE_TYPEINFO(QSize, Q_MOVABLE_TYPE);
78
/*****************************************************************************
79
QSize stream functions
80
*****************************************************************************/
82
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSize &);
83
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
86
/*****************************************************************************
87
QSize inline functions
88
*****************************************************************************/
93
inline QSize::QSize(int w, int h)
96
inline bool QSize::isNull() const
97
{ return wd==0 && ht==0; }
99
inline bool QSize::isEmpty() const
100
{ return wd<1 || ht<1; }
102
inline bool QSize::isValid() const
103
{ return wd>=0 && ht>=0; }
105
inline int QSize::width() const
108
inline int QSize::height() const
111
inline void QSize::setWidth(int w)
114
inline void QSize::setHeight(int h)
117
inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode)
118
{ scale(QSize(w, h), mode); }
120
inline int &QSize::rwidth()
123
inline int &QSize::rheight()
126
inline QSize &QSize::operator+=(const QSize &s)
127
{ wd+=s.wd; ht+=s.ht; return *this; }
129
inline QSize &QSize::operator-=(const QSize &s)
130
{ wd-=s.wd; ht-=s.ht; return *this; }
132
inline QSize &QSize::operator*=(qreal c)
133
{ wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
135
inline bool operator==(const QSize &s1, const QSize &s2)
136
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
138
inline bool operator!=(const QSize &s1, const QSize &s2)
139
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
141
inline const QSize operator+(const QSize & s1, const QSize & s2)
142
{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
144
inline const QSize operator-(const QSize &s1, const QSize &s2)
145
{ return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
147
inline const QSize operator*(const QSize &s, qreal c)
148
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
150
inline const QSize operator*(qreal c, const QSize &s)
151
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
153
inline QSize &QSize::operator/=(qreal c)
156
wd = qRound(wd/c); ht = qRound(ht/c);
160
inline const QSize operator/(const QSize &s, qreal c)
163
return QSize(qRound(s.wd/c), qRound(s.ht/c));
166
inline QSize QSize::expandedTo(const QSize & otherSize) const
168
return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
171
inline QSize QSize::boundedTo(const QSize & otherSize) const
173
return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
176
#ifndef QT_NO_DEBUG_STREAM
177
Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
181
class Q_CORE_EXPORT QSizeF
185
QSizeF(const QSize &sz);
186
QSizeF(qreal w, qreal h);
189
bool isEmpty() const;
190
bool isValid() const;
193
qreal height() const;
194
void setWidth(qreal w);
195
void setHeight(qreal h);
198
void scale(qreal w, qreal h, Qt::AspectRatioMode mode);
199
void scale(const QSizeF &s, Qt::AspectRatioMode mode);
201
QSizeF expandedTo(const QSizeF &) const;
202
QSizeF boundedTo(const QSizeF &) const;
207
QSizeF &operator+=(const QSizeF &);
208
QSizeF &operator-=(const QSizeF &);
209
QSizeF &operator*=(qreal c);
210
QSizeF &operator/=(qreal c);
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);
220
inline QSize toSize() const;
226
Q_DECLARE_TYPEINFO(QSizeF, Q_MOVABLE_TYPE);
229
/*****************************************************************************
230
QSizeF stream functions
231
*****************************************************************************/
233
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSizeF &);
234
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
237
/*****************************************************************************
238
QSizeF inline functions
239
*****************************************************************************/
241
inline QSizeF::QSizeF()
244
inline QSizeF::QSizeF(const QSize &sz)
245
: wd(sz.width()), ht(sz.height())
249
inline QSizeF::QSizeF(qreal w, qreal h)
252
inline bool QSizeF::isNull() const
253
{ return wd == 0 && ht == 0; }
255
inline bool QSizeF::isEmpty() const
256
{ return wd <= 0. || ht <= 0.; }
258
inline bool QSizeF::isValid() const
259
{ return wd >= 0. && ht >= 0.; }
261
inline qreal QSizeF::width() const
264
inline qreal QSizeF::height() const
267
inline void QSizeF::setWidth(qreal w)
270
inline void QSizeF::setHeight(qreal h)
273
inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode)
274
{ scale(QSizeF(w, h), mode); }
276
inline qreal &QSizeF::rwidth()
279
inline qreal &QSizeF::rheight()
282
inline QSizeF &QSizeF::operator+=(const QSizeF &s)
283
{ wd += s.wd; ht += s.ht; return *this; }
285
inline QSizeF &QSizeF::operator-=(const QSizeF &s)
286
{ wd -= s.wd; ht -= s.ht; return *this; }
288
inline QSizeF &QSizeF::operator*=(qreal c)
289
{ wd *= c; ht *= c; return *this; }
291
inline bool operator==(const QSizeF &s1, const QSizeF &s2)
292
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
294
inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
295
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
297
inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2)
298
{ return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); }
300
inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
301
{ return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); }
303
inline const QSizeF operator*(const QSizeF &s, qreal c)
304
{ return QSizeF(s.wd*c, s.ht*c); }
306
inline const QSizeF operator*(qreal c, const QSizeF &s)
307
{ return QSizeF(s.wd*c, s.ht*c); }
309
inline QSizeF &QSizeF::operator/=(qreal c)
312
wd = wd/c; ht = ht/c;
316
inline const QSizeF operator/(const QSizeF &s, qreal c)
319
return QSizeF(s.wd/c, s.ht/c);
322
inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const
324
return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
327
inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const
329
return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
332
inline QSize QSizeF::toSize() const
334
return QSize(qRound(wd), qRound(ht));
337
#ifndef QT_NO_DEBUG_STREAM
338
Q_CORE_EXPORT QDebug operator<<(QDebug, const QSizeF &);