- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qsize.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QSIZE_H
    00043 #define QSIZE_H
    00044
    00045 #include <QtCore/qnamespace.h>
    00046
    00047 QT_BEGIN_HEADER
    00048
    00049 QT_BEGIN_NAMESPACE
    00050
    00051 QT_MODULE(Core)
    00052
    00053 class Q_CORE_EXPORT QSize
    00054 {
    00055 public:
    00056     QSize();
    00057     QSize(int w, int h);
    00058
    00059     bool isNull() const;
    00060     bool isEmpty() const;
    00061     bool isValid() const;
    00062
    00063     int width() const;
    00064     int height() const;
    00065     void setWidth(int w);
    00066     void setHeight(int h);
    00067     void transpose();
    00068
    00069     void scale(int w, int h, Qt::AspectRatioMode mode);
    00070     void scale(const QSize &s, Qt::AspectRatioMode mode);
    00071
    00072     QSize expandedTo(const QSize &) const;
    00073     QSize boundedTo(const QSize &) const;
    00074
    00075     int &rwidth();
    00076     int &rheight();
    00077
    00078     QSize &operator+=(const QSize &);
    00079     QSize &operator-=(const QSize &);
    00080     QSize &operator*=(qreal c);
    00081     QSize &operator/=(qreal c);
    00082
    00083     friend inline bool operator==(const QSize &, const QSize &);
    00084     friend inline bool operator!=(const QSize &, const QSize &);
    00085     friend inline const QSize operator+(const QSize &, const QSize &);
    00086     friend inline const QSize operator-(const QSize &, const QSize &);
    00087     friend inline const QSize operator*(const QSize &, qreal);
    00088     friend inline const QSize operator*(qreal, const QSize &);
    00089     friend inline const QSize operator/(const QSize &, qreal);
    00090
    00091 private:
    00092     int wd;
    00093     int ht;
    00094 };
    00095 Q_DECLARE_TYPEINFO(QSize, Q_MOVABLE_TYPE);
    00096
    00097 /*****************************************************************************
    00098   QSize stream functions
    00099  *****************************************************************************/
    00100
    00101 #ifndef QT_NO_DATASTREAM
    00102 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSize &);
    00103 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
    00104 #endif
    00105
    00106
    00107 /*****************************************************************************
    00108   QSize inline functions
    00109  *****************************************************************************/
    00110
    00111 inline QSize::QSize()
    00112 { wd = ht = -1; }
    00113
    00114 inline QSize::QSize(int w, int h)
    00115 { wd = w; ht = h; }
    00116
    00117 inline bool QSize::isNull() const
    00118 { return wd==0 && ht==0; }
    00119
    00120 inline bool QSize::isEmpty() const
    00121 { return wd<1 || ht<1; }
    00122
    00123 inline bool QSize::isValid() const
    00124 { return wd>=0 && ht>=0; }
    00125
    00126 inline int QSize::width() const
    00127 { return wd; }
    00128
    00129 inline int QSize::height() const
    00130 { return ht; }
    00131
    00132 inline void QSize::setWidth(int w)
    00133 { wd = w; }
    00134
    00135 inline void QSize::setHeight(int h)
    00136 { ht = h; }
    00137
    00138 inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode)
    00139 { scale(QSize(w, h), mode); }
    00140
    00141 inline int &QSize::rwidth()
    00142 { return wd; }
    00143
    00144 inline int &QSize::rheight()
    00145 { return ht; }
    00146
    00147 inline QSize &QSize::operator+=(const QSize &s)
    00148 { wd+=s.wd; ht+=s.ht; return *this; }
    00149
    00150 inline QSize &QSize::operator-=(const QSize &s)
    00151 { wd-=s.wd; ht-=s.ht; return *this; }
    00152
    00153 inline QSize &QSize::operator*=(qreal c)
    00154 { wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
    00155
    00156 inline bool operator==(const QSize &s1, const QSize &s2)
    00157 { return s1.wd == s2.wd && s1.ht == s2.ht; }
    00158
    00159 inline bool operator!=(const QSize &s1, const QSize &s2)
    00160 { return s1.wd != s2.wd || s1.ht != s2.ht; }
    00161
    00162 inline const QSize operator+(const QSize & s1, const QSize & s2)
    00163 { return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
    00164
    00165 inline const QSize operator-(const QSize &s1, const QSize &s2)
    00166 { return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
    00167
    00168 inline const QSize operator*(const QSize &s, qreal c)
    00169 { return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
    00170
    00171 inline const QSize operator*(qreal c, const QSize &s)
    00172 { return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
    00173
    00174 inline QSize &QSize::operator/=(qreal c)
    00175 {
    00176     Q_ASSERT(!qFuzzyIsNull(c));
    00177     wd = qRound(wd/c); ht = qRound(ht/c);
    00178     return *this;
    00179 }
    00180
    00181 inline const QSize operator/(const QSize &s, qreal c)
    00182 {
    00183     Q_ASSERT(!qFuzzyIsNull(c));
    00184     return QSize(qRound(s.wd/c), qRound(s.ht/c));
    00185 }
    00186
    00187 inline QSize QSize::expandedTo(const QSize & otherSize) const
    00188 {
    00189     return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
    00190 }
    00191
    00192 inline QSize QSize::boundedTo(const QSize & otherSize) const
    00193 {
    00194     return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
    00195 }
    00196
    00197 #ifndef QT_NO_DEBUG_STREAM
    00198 Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
    00199 #endif
    00200
    00201
    00202 class Q_CORE_EXPORT QSizeF
    00203 {
    00204 public:
    00205     QSizeF();
    00206     QSizeF(const QSize &sz);
    00207     QSizeF(qreal w, qreal h);
    00208
    00209     bool isNull() const;
    00210     bool isEmpty() const;
    00211     bool isValid() const;
    00212
    00213     qreal width() const;
    00214     qreal height() const;
    00215     void setWidth(qreal w);
    00216     void setHeight(qreal h);
    00217     void transpose();
    00218
    00219     void scale(qreal w, qreal h, Qt::AspectRatioMode mode);
    00220     void scale(const QSizeF &s, Qt::AspectRatioMode mode);
    00221
    00222     QSizeF expandedTo(const QSizeF &) const;
    00223     QSizeF boundedTo(const QSizeF &) const;
    00224
    00225     qreal &rwidth();
    00226     qreal &rheight();
    00227
    00228     QSizeF &operator+=(const QSizeF &);
    00229     QSizeF &operator-=(const QSizeF &);
    00230     QSizeF &operator*=(qreal c);
    00231     QSizeF &operator/=(qreal c);
    00232
    00233     friend inline bool operator==(const QSizeF &, const QSizeF &);
    00234     friend inline bool operator!=(const QSizeF &, const QSizeF &);
    00235     friend inline const QSizeF operator+(const QSizeF &, const QSizeF &);
    00236     friend inline const QSizeF operator-(const QSizeF &, const QSizeF &);
    00237     friend inline const QSizeF operator*(const QSizeF &, qreal);
    00238     friend inline const QSizeF operator*(qreal, const QSizeF &);
    00239     friend inline const QSizeF operator/(const QSizeF &, qreal);
    00240
    00241     inline QSize toSize() const;
    00242
    00243 private:
    00244     qreal wd;
    00245     qreal ht;
    00246 };
    00247 Q_DECLARE_TYPEINFO(QSizeF, Q_MOVABLE_TYPE);
    00248
    00249
    00250 /*****************************************************************************
    00251   QSizeF stream functions
    00252  *****************************************************************************/
    00253
    00254 #ifndef QT_NO_DATASTREAM
    00255 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSizeF &);
    00256 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
    00257 #endif
    00258
    00259
    00260 /*****************************************************************************
    00261   QSizeF inline functions
    00262  *****************************************************************************/
    00263
    00264 inline QSizeF::QSizeF()
    00265 { wd = ht = -1.; }
    00266
    00267 inline QSizeF::QSizeF(const QSize &sz)
    00268     : wd(sz.width()), ht(sz.height())
    00269 {
    00270 }
    00271
    00272 inline QSizeF::QSizeF(qreal w, qreal h)
    00273 { wd = w; ht = h; }
    00274
    00275 inline bool QSizeF::isNull() const
    00276 { return qIsNull(wd) && qIsNull(ht); }
    00277
    00278 inline bool QSizeF::isEmpty() const
    00279 { return wd <= 0. || ht <= 0.; }
    00280
    00281 inline bool QSizeF::isValid() const
    00282 { return wd >= 0. && ht >= 0.; }
    00283
    00284 inline qreal QSizeF::width() const
    00285 { return wd; }
    00286
    00287 inline qreal QSizeF::height() const
    00288 { return ht; }
    00289
    00290 inline void QSizeF::setWidth(qreal w)
    00291 { wd = w; }
    00292
    00293 inline void QSizeF::setHeight(qreal h)
    00294 { ht = h; }
    00295
    00296 inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode)
    00297 { scale(QSizeF(w, h), mode); }
    00298
    00299 inline qreal &QSizeF::rwidth()
    00300 { return wd; }
    00301
    00302 inline qreal &QSizeF::rheight()
    00303 { return ht; }
    00304
    00305 inline QSizeF &QSizeF::operator+=(const QSizeF &s)
    00306 { wd += s.wd; ht += s.ht; return *this; }
    00307
    00308 inline QSizeF &QSizeF::operator-=(const QSizeF &s)
    00309 { wd -= s.wd; ht -= s.ht; return *this; }
    00310
    00311 inline QSizeF &QSizeF::operator*=(qreal c)
    00312 { wd *= c; ht *= c; return *this; }
    00313
    00314 inline bool operator==(const QSizeF &s1, const QSizeF &s2)
    00315 { return qFuzzyCompare(s1.wd, s2.wd) && qFuzzyCompare(s1.ht, s2.ht); }
    00316
    00317 inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
    00318 { return !qFuzzyCompare(s1.wd, s2.wd) || !qFuzzyCompare(s1.ht, s2.ht); }
    00319
    00320 inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2)
    00321 { return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); }
    00322
    00323 inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
    00324 { return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); }
    00325
    00326 inline const QSizeF operator*(const QSizeF &s, qreal c)
    00327 { return QSizeF(s.wd*c, s.ht*c); }
    00328
    00329 inline const QSizeF operator*(qreal c, const QSizeF &s)
    00330 { return QSizeF(s.wd*c, s.ht*c); }
    00331
    00332 inline QSizeF &QSizeF::operator/=(qreal c)
    00333 {
    00334     Q_ASSERT(!qFuzzyIsNull(c));
    00335     wd = wd/c; ht = ht/c;
    00336     return *this;
    00337 }
    00338
    00339 inline const QSizeF operator/(const QSizeF &s, qreal c)
    00340 {
    00341     Q_ASSERT(!qFuzzyIsNull(c));
    00342     return QSizeF(s.wd/c, s.ht/c);
    00343 }
    00344
    00345 inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const
    00346 {
    00347     return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
    00348 }
    00349
    00350 inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const
    00351 {
    00352     return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
    00353 }
    00354
    00355 inline QSize QSizeF::toSize() const
    00356 {
    00357     return QSize(qRound(wd), qRound(ht));
    00358 }
    00359
    00360 #ifndef QT_NO_DEBUG_STREAM
    00361 Q_CORE_EXPORT QDebug operator<<(QDebug, const QSizeF &);
    00362 #endif
    00363
    00364 QT_END_NAMESPACE
    00365
    00366 QT_END_HEADER
    00367
    00368 #endif // QSIZE_H