Back to index

scribus-ng  1.3.4.dfsg+svn20071115
fsize.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: fsize.cpp 6144 2006-08-15 23:30:58Z avox $
00003 **
00004 ** Implementation 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 #include "fsize.h"
00039 //#include "qdatastream.h"
00040 
00041 
00067 /*****************************************************************************
00068   FSize member functions
00069  *****************************************************************************/
00070 
00127 void FSize::transpose()
00128 {
00129     double tmp = wd;
00130     wd = ht;
00131     ht = tmp;
00132 }
00133 
00176 void FSize::scale( double w, double h, ScaleMode mode )
00177 {
00178     if ( mode == ScaleFree ) {
00179        wd = (double)w;
00180        ht = (double)h;
00181     } else {
00182        bool useHeight = TRUE;
00183        double w0 = width();
00184        double h0 = height();
00185        double rw = h * w0 / h0;
00186 
00187        if ( mode == ScaleMin ) {
00188            useHeight = ( rw <= w );
00189        } else { // mode == ScaleMax
00190            useHeight = ( rw >= w );
00191        }
00192 
00193        if ( useHeight ) {
00194            wd = (double)rw;
00195            ht = (double)h;
00196        } else {
00197            wd = (double)w;
00198            ht = (double)( w * h0 / w0 );
00199        }
00200     }
00201 }
00202 
00208 void FSize::scale( const FSize &s, ScaleMode mode )
00209 {
00210     scale( s.width(), s.height(), mode );
00211 }
00212 
00378 void FSize::warningDivByZero()
00379 {
00380 #if defined(QT_CHECK_MATH)
00381     qWarning( "FSize: Division by zero error" );
00382 #endif
00383 }
00384 
00385 
00386 /*****************************************************************************
00387   FSize stream functions
00388  *****************************************************************************/
00389 // #ifndef QT_NO_DATASTREAM
00390 // /*!
00391 //   \relates FSize
00392 //   Writes the size \a sz to the stream \a s and returns a reference to
00393 //   the stream.
00394 //
00395 //   \sa \link datastreamformat.html Format of the QDataStream operators \endlink
00396 // */
00397 //
00398 // QDataStream &operator<<( QDataStream &s, const FSize &sz )
00399 // {
00400 //     if ( s.version() == 1 )
00401 //     s << (Q_INT16)sz.width() << (Q_INT16)sz.height();
00402 //     else
00403 //     s << (Q_INT32)sz.width() << (Q_INT32)sz.height();
00404 //     return s;
00405 // }
00406 //
00407 // /*!
00408 //   \relates FSize
00409 //   Reads the size from the stream \a s into size \a sz and returns a
00410 //   reference to the stream.
00411 //
00412 //   \sa \link datastreamformat.html Format of the QDataStream operators \endlink
00413 // */
00414 //
00415 // QDataStream &operator>>( QDataStream &s, FSize &sz )
00416 // {
00417 //     if ( s.version() == 1 ) {
00418 //     Q_INT16 w, h;
00419 //     s >> w;  sz.rwidth() = w;
00420 //     s >> h;  sz.rheight() = h;
00421 //     }
00422 //     else {
00423 //     Q_INT32 w, h;
00424 //     s >> w;  sz.rwidth() = w;
00425 //     s >> h;  sz.rheight() = h;
00426 //     }
00427 //     return s;
00428 // }
00429 // #endif // QT_NO_DATASTREAM