home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qsize.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  6KB  |  225 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qsize.h   3.0.0   edited Jun 22 12:24 $
  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 windowdefs.h?
  43. #endif // QT_H
  44.  
  45.  
  46. class Q_EXPORT QSize
  47. {
  48. public:
  49.     QSize();
  50.     QSize( int w, int h );
  51.  
  52.     bool   isNull()    const;
  53.     bool   isEmpty()    const;
  54.     bool   isValid()    const;
  55.  
  56.     int       width()    const;
  57.     int       height()    const;
  58.     void   setWidth( int w );
  59.     void   setHeight( int h );
  60.     void   transpose();
  61.  
  62.     QSize expandedTo( const QSize & ) const;
  63.     QSize boundedTo( const QSize & ) const;
  64.  
  65.     QCOORD &rwidth();
  66.     QCOORD &rheight();
  67.  
  68.     QSize &operator+=( const QSize & );
  69.     QSize &operator-=( const QSize & );
  70.     QSize &operator*=( int c );
  71.     QSize &operator*=( double c );
  72.     QSize &operator/=( int c );
  73.     QSize &operator/=( double c );
  74.  
  75.     friend inline bool    operator==( const QSize &, const QSize & );
  76.     friend inline bool    operator!=( const QSize &, const QSize & );
  77.     friend inline const QSize operator+( const QSize &, const QSize & );
  78.     friend inline const QSize operator-( const QSize &, const QSize & );
  79.     friend inline const QSize operator*( const QSize &, int );
  80.     friend inline const QSize operator*( int, const QSize & );
  81.     friend inline const QSize operator*( const QSize &, double );
  82.     friend inline const QSize operator*( double, const QSize & );
  83.     friend inline const QSize operator/( const QSize &, int );
  84.     friend inline const QSize operator/( const QSize &, double );
  85.  
  86. private:
  87.     static void warningDivByZero();
  88.  
  89.     QCOORD wd;
  90.     QCOORD ht;
  91. };
  92.  
  93.  
  94. /*****************************************************************************
  95.   QSize stream functions
  96.  *****************************************************************************/
  97.  
  98. Q_EXPORT QDataStream &operator<<( QDataStream &, const QSize & );
  99. Q_EXPORT QDataStream &operator>>( QDataStream &, QSize & );
  100.  
  101.  
  102. /*****************************************************************************
  103.   QSize inline functions
  104.  *****************************************************************************/
  105.  
  106. inline QSize::QSize()
  107. { wd = ht = -1; }
  108.  
  109. inline QSize::QSize( int w, int h )
  110. { wd=(QCOORD)w; ht=(QCOORD)h; }
  111.  
  112. inline bool QSize::isNull() const
  113. { return wd==0 && ht==0; }
  114.  
  115. inline bool QSize::isEmpty() const
  116. { return wd<1 || ht<1; }
  117.  
  118. inline bool QSize::isValid() const
  119. { return wd>=0 && ht>=0; }
  120.  
  121. inline int QSize::width() const
  122. { return wd; }
  123.  
  124. inline int QSize::height() const
  125. { return ht; }
  126.  
  127. inline void QSize::setWidth( int w )
  128. { wd=(QCOORD)w; }
  129.  
  130. inline void QSize::setHeight( int h )
  131. { ht=(QCOORD)h; }
  132.  
  133. inline QCOORD &QSize::rwidth()
  134. { return wd; }
  135.  
  136. inline QCOORD &QSize::rheight()
  137. { return ht; }
  138.  
  139. inline QSize &QSize::operator+=( const QSize &s )
  140. { wd+=s.wd; ht+=s.ht; return *this; }
  141.  
  142. inline QSize &QSize::operator-=( const QSize &s )
  143. { wd-=s.wd; ht-=s.ht; return *this; }
  144.  
  145. inline QSize &QSize::operator*=( int c )
  146. { wd*=(QCOORD)c; ht*=(QCOORD)c; return *this; }
  147.  
  148. inline QSize &QSize::operator*=( double c )
  149. { wd=(QCOORD)(wd*c); ht=(QCOORD)(ht*c); return *this; }
  150.  
  151. inline bool operator==( const QSize &s1, const QSize &s2 )
  152. { return s1.wd == s2.wd && s1.ht == s2.ht; }
  153.  
  154. inline bool operator!=( const QSize &s1, const QSize &s2 )
  155. { return s1.wd != s2.wd || s1.ht != s2.ht; }
  156.  
  157. inline const QSize operator+( const QSize & s1, const QSize & s2 )
  158. { return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
  159.  
  160. inline const QSize operator-( const QSize &s1, const QSize &s2 )
  161. { return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
  162.  
  163. inline const QSize operator*( const QSize &s, int c )
  164. { return QSize(s.wd*c, s.ht*c); }
  165.  
  166. inline const QSize operator*( int c, const QSize &s )
  167. {  return QSize(s.wd*c, s.ht*c); }
  168.  
  169. inline const QSize operator*( const QSize &s, double c )
  170. { return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
  171.  
  172. inline const QSize operator*( double c, const QSize &s )
  173. { return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
  174.  
  175. inline QSize &QSize::operator/=( int c )
  176. {
  177. #if defined(QT_CHECK_MATH)
  178.     if ( c == 0 )
  179.     warningDivByZero();
  180. #endif
  181.     wd/=(QCOORD)c; ht/=(QCOORD)c;
  182.     return *this;
  183. }
  184.  
  185. inline QSize &QSize::operator/=( double c )
  186. {
  187. #if defined(QT_CHECK_MATH)
  188.     if ( c == 0.0 )
  189.     warningDivByZero();
  190. #endif
  191.     wd=(QCOORD)(wd/c); ht=(QCOORD)(ht/c);
  192.     return *this;
  193. }
  194.  
  195. inline const QSize operator/( const QSize &s, int c )
  196. {
  197. #if defined(QT_CHECK_MATH)
  198.     if ( c == 0 )
  199.     QSize::warningDivByZero();
  200. #endif
  201.     return QSize(s.wd/c, s.ht/c);
  202. }
  203.  
  204. inline const QSize operator/( const QSize &s, double c )
  205. {
  206. #if defined(QT_CHECK_MATH)
  207.     if ( c == 0.0 )
  208.     QSize::warningDivByZero();
  209. #endif
  210.     return QSize((QCOORD)(s.wd/c), (QCOORD)(s.ht/c));
  211. }
  212.  
  213. inline QSize QSize::expandedTo( const QSize & otherSize ) const
  214. {
  215.     return QSize( QMAX(wd,otherSize.wd), QMAX(ht,otherSize.ht) );
  216. }
  217.  
  218. inline QSize QSize::boundedTo( const QSize & otherSize ) const
  219. {
  220.     return QSize( QMIN(wd,otherSize.wd), QMIN(ht,otherSize.ht) );
  221. }
  222.  
  223.  
  224. #endif // QSIZE_H
  225.