Back to index

scribus-ng  1.3.4.dfsg+svn20071115
fsize.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: fsize.h 6159 2006-08-17 18:35:05Z jghali $
00003 **
00004 ** Definition of FSize class
00005 **
00006 ** Created : 931028
00007 **
00008 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef FSIZE_H
00039 #define FSIZE_H
00040 
00041 // #ifndef QT_H
00042  #include "../fpoint.h" // ### change to qwindowdefs.h?
00043 // #endif // QT_H
00044 
00045 class FSize
00046 // ### Make FSize inherit Qt in Qt 4.0
00047 {
00048 public:
00049     // ### Move this enum to qnamespace.h in Qt 4.0
00050     enum ScaleMode {
00051        ScaleFree,
00052        ScaleMin,
00053        ScaleMax
00054     };
00055 
00056     FSize();
00057     FSize( double w, double h );
00058 
00059     bool isNull() const;
00060     bool isEmpty() const;
00061     bool isValid() const;
00062 
00063     double width() const;
00064     double height() const;
00065     void setWidth( double w );
00066     void setHeight( double h );
00067     void transpose();
00068 
00069     void scale( double w, double h, ScaleMode mode );
00070     void scale( const FSize &s, ScaleMode mode );
00071 
00072     FSize expandedTo( const FSize & ) const;
00073     FSize boundedTo( const FSize & ) const;
00074 
00075     double &rwidth();
00076     double &rheight();
00077 
00078     FSize &operator+=( const FSize & );
00079     FSize &operator-=( const FSize & );
00080     FSize &operator*=( int c );
00081     FSize &operator*=( double c );
00082     FSize &operator/=( int c );
00083     FSize &operator/=( double c );
00084 
00085     friend inline bool operator==( const FSize &, const FSize & );
00086     friend inline bool operator!=( const FSize &, const FSize & );
00087     friend inline const FSize operator+( const FSize &, const FSize & );
00088     friend inline const FSize operator-( const FSize &, const FSize & );
00089     friend inline const FSize operator*( const FSize &, int );
00090     friend inline const FSize operator*( int, const FSize & );
00091     friend inline const FSize operator*( const FSize &, double );
00092     friend inline const FSize operator*( double, const FSize & );
00093     friend inline const FSize operator/( const FSize &, int );
00094     friend inline const FSize operator/( const FSize &, double );
00095 
00096 private:
00097     static void warningDivByZero();
00098 
00099     double wd;
00100     double ht;
00101 };
00102 
00103 
00104 /*****************************************************************************
00105   FSize stream functions
00106  *****************************************************************************/
00107 
00108 // QDataStream &operator<<( QDataStream &, const FSize & );
00109 // QDataStream &operator>>( QDataStream &, FSize & );
00110 
00111 
00112 /*****************************************************************************
00113   FSize inline functions
00114  *****************************************************************************/
00115 
00116 inline FSize::FSize()
00117 { wd = ht = -1; }
00118 
00119 inline FSize::FSize( double w, double h )
00120 { wd=(double)w; ht=(double)h; }
00121 
00122 inline bool FSize::isNull() const
00123 { return wd==0 && ht==0; }
00124 
00125 inline bool FSize::isEmpty() const
00126 { return wd<1 || ht<1; }
00127 
00128 inline bool FSize::isValid() const
00129 { return wd>=0 && ht>=0; }
00130 
00131 inline double FSize::width() const
00132 { return wd; }
00133 
00134 inline double FSize::height() const
00135 { return ht; }
00136 
00137 inline void FSize::setWidth( double w )
00138 { wd=(double)w; }
00139 
00140 inline void FSize::setHeight( double h )
00141 { ht=(double)h; }
00142 
00143 inline double &FSize::rwidth()
00144 { return wd; }
00145 
00146 inline double &FSize::rheight()
00147 { return ht; }
00148 
00149 inline FSize &FSize::operator+=( const FSize &s )
00150 { wd+=s.wd; ht+=s.ht; return *this; }
00151 
00152 inline FSize &FSize::operator-=( const FSize &s )
00153 { wd-=s.wd; ht-=s.ht; return *this; }
00154 
00155 inline FSize &FSize::operator*=( int c )
00156 { wd*=(double)c; ht*=(double)c; return *this; }
00157 
00158 inline FSize &FSize::operator*=( double c )
00159 { wd=(double)(wd*c); ht=(double)(ht*c); return *this; }
00160 
00161 inline bool operator==( const FSize &s1, const FSize &s2 )
00162 { return s1.wd == s2.wd && s1.ht == s2.ht; }
00163 
00164 inline bool operator!=( const FSize &s1, const FSize &s2 )
00165 { return s1.wd != s2.wd || s1.ht != s2.ht; }
00166 
00167 inline const FSize operator+( const FSize & s1, const FSize & s2 )
00168 { return FSize(s1.wd+s2.wd, s1.ht+s2.ht); }
00169 
00170 inline const FSize operator-( const FSize &s1, const FSize &s2 )
00171 { return FSize(s1.wd-s2.wd, s1.ht-s2.ht); }
00172 
00173 inline const FSize operator*( const FSize &s, int c )
00174 { return FSize(s.wd*c, s.ht*c); }
00175 
00176 inline const FSize operator*( int c, const FSize &s )
00177 {  return FSize(s.wd*c, s.ht*c); }
00178 
00179 inline const FSize operator*( const FSize &s, double c )
00180 { return FSize((double)(s.wd*c), (double)(s.ht*c)); }
00181 
00182 inline const FSize operator*( double c, const FSize &s )
00183 { return FSize((double)(s.wd*c), (double)(s.ht*c)); }
00184 
00185 inline FSize &FSize::operator/=( int c )
00186 {
00187 #if defined(QT_CHECK_MATH)
00188     if ( c == 0 )
00189        warningDivByZero();
00190 #endif
00191     wd/=(double)c; ht/=(double)c;
00192     return *this;
00193 }
00194 
00195 inline FSize &FSize::operator/=( double c )
00196 {
00197 #if defined(QT_CHECK_MATH)
00198     if ( c == 0.0 )
00199        warningDivByZero();
00200 #endif
00201     wd=(double)(wd/c); ht=(double)(ht/c);
00202     return *this;
00203 }
00204 
00205 inline const FSize operator/( const FSize &s, int c )
00206 {
00207 #if defined(QT_CHECK_MATH)
00208     if ( c == 0 )
00209        FSize::warningDivByZero();
00210 #endif
00211     return FSize(s.wd/c, s.ht/c);
00212 }
00213 
00214 inline const FSize operator/( const FSize &s, double c )
00215 {
00216 #if defined(QT_CHECK_MATH)
00217     if ( c == 0.0 )
00218        FSize::warningDivByZero();
00219 #endif
00220     return FSize((double)(s.wd/c), (double)(s.ht/c));
00221 }
00222 
00223 inline FSize FSize::expandedTo( const FSize & otherSize ) const
00224 {
00225     return FSize( QMAX(wd,otherSize.wd), QMAX(ht,otherSize.ht) );
00226 }
00227 
00228 inline FSize FSize::boundedTo( const FSize & otherSize ) const
00229 {
00230     return FSize( QMIN(wd,otherSize.wd), QMIN(ht,otherSize.ht) );
00231 }
00232 
00233 
00234 #endif // QSIZE_H