Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Types | Public Member Functions | Static Private Member Functions | Private Attributes | Friends | Related Functions
FSize Class Reference

The FSize class defines the size of a two-dimensional object. More...

#include <fsize.h>

List of all members.

Public Types

enum  ScaleMode { ScaleFree, ScaleMin, ScaleMax }
 This enum type defines the different ways of scaling a size. More...

Public Member Functions

 FSize ()
 Constructs a size with invalid (negative) width and height.
 FSize (double w, double h)
 Constructs a size with width w and height h.
bool isNull () const
 Returns TRUE if the width is 0 and the height is 0; otherwise returns FALSE.
bool isEmpty () const
 Returns TRUE if the width is less than or equal to 0, or the height is less than or equal to 0; otherwise returns FALSE.
bool isValid () const
 Returns TRUE if the width is equal to or greater than 0 and the height is equal to or greater than 0; otherwise returns FALSE.
double width () const
 Returns the width.
double height () const
 Returns the height.
void setWidth (double w)
 Sets the width to w.
void setHeight (double h)
 Sets the height to h.
void transpose ()
 Swaps the values of width and height.
void scale (double w, double h, ScaleMode mode)
 Scales the size to a rectangle of width w and height h according to the ScaleMode mode.
void scale (const FSize &s, ScaleMode mode)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to scale({s}.width(), {s}.height(), mode).
FSize expandedTo (const FSize &) const
 Returns a size with the maximum width and height of this size and otherSize.
FSize boundedTo (const FSize &) const
 Returns a size with the minimum width and height of this size and otherSize.
double & rwidth ()
 Returns a reference to the width.
double & rheight ()
 Returns a reference to the height.
FSizeoperator+= (const FSize &)
 Adds s to the size and returns a reference to this size.
FSizeoperator-= (const FSize &)
 Subtracts s from the size and returns a reference to this size.
FSizeoperator*= (int c)
FSizeoperator*= (double c)
 Multiplies both the width and height by c and returns a reference to the size.
FSizeoperator/= (int c)
FSizeoperator/= (double c)
 Divides both the width and height by c and returns a reference to the size.

Static Private Member Functions

static void warningDivByZero ()

Private Attributes

double wd
double ht

Friends

bool operator== (const FSize &, const FSize &)
bool operator!= (const FSize &, const FSize &)
const FSize operator+ (const FSize &, const FSize &)
const FSize operator- (const FSize &, const FSize &)
const FSize operator* (const FSize &, int)
const FSize operator* (int, const FSize &)
const FSize operator* (const FSize &, double)
const FSize operator* (double, const FSize &)
const FSize operator/ (const FSize &, int)
const FSize operator/ (const FSize &, double)

Related Functions

(Note that these are not member functions.)

const FSize operator
const FSize operator
const FSize operator

Detailed Description

The FSize class defines the size of a two-dimensional object.

A size is specified by a width and a height.

The coordinate type is double (defined in <qwindowdefs.h> as double). The minimum value of double is double_MIN (-2147483648) and the maximum value is double_MAX (2147483647).

The size can be set in the constructor and changed with setWidth() and setHeight(), or using operator+=(), operator-=(), operator*=() and operator/=(), etc. You can swap the width and height with transpose(). You can get a size which holds the maximum height and width of two sizes using expandedTo(), and the minimum height and width of two sizes using boundedTo().

See also:
QPoint, QRect

Definition at line 45 of file fsize.h.


Member Enumeration Documentation

This enum type defines the different ways of scaling a size.

scaling.png

ScaleFree The size is scaled freely. The ratio is not preserved. ScaleMin The size is scaled to a rectangle as large as possible inside a given rectangle, preserving the aspect ratio. ScaleMax The size is scaled to a rectangle as small as possible outside a given rectangle, preserving the aspect ratio.

See also:
FSize::scale(), QImage::scale(), QImage::smoothScale()
Enumerator:
ScaleFree 
ScaleMin 
ScaleMax 

Definition at line 50 of file fsize.h.


Constructor & Destructor Documentation

FSize::FSize ( ) [inline]

Constructs a size with invalid (negative) width and height.

Definition at line 116 of file fsize.h.

{ wd = ht = -1; }

Here is the caller graph for this function:

FSize::FSize ( double  w,
double  h 
) [inline]

Constructs a size with width w and height h.

Definition at line 119 of file fsize.h.

{ wd=(double)w; ht=(double)h; }

Member Function Documentation

FSize FSize::boundedTo ( const FSize otherSize) const [inline]

Returns a size with the minimum width and height of this size and otherSize.

Definition at line 228 of file fsize.h.

{
    return FSize( QMIN(wd,otherSize.wd), QMIN(ht,otherSize.ht) );
}

Here is the call graph for this function:

FSize FSize::expandedTo ( const FSize otherSize) const [inline]

Returns a size with the maximum width and height of this size and otherSize.

Definition at line 223 of file fsize.h.

{
    return FSize( QMAX(wd,otherSize.wd), QMAX(ht,otherSize.ht) );
}

Here is the call graph for this function:

double FSize::height ( ) const [inline]

Returns the height.

See also:
width()

Definition at line 134 of file fsize.h.

{ return ht; }

Here is the caller graph for this function:

bool FSize::isEmpty ( ) const [inline]

Returns TRUE if the width is less than or equal to 0, or the height is less than or equal to 0; otherwise returns FALSE.

Definition at line 125 of file fsize.h.

{ return wd<1 || ht<1; }
bool FSize::isNull ( ) const [inline]

Returns TRUE if the width is 0 and the height is 0; otherwise returns FALSE.

Definition at line 122 of file fsize.h.

{ return wd==0 && ht==0; }
bool FSize::isValid ( ) const [inline]

Returns TRUE if the width is equal to or greater than 0 and the height is equal to or greater than 0; otherwise returns FALSE.

Definition at line 128 of file fsize.h.

{ return wd>=0 && ht>=0; }
FSize & FSize::operator*= ( int  c) [inline]

Definition at line 155 of file fsize.h.

{ wd*=(double)c; ht*=(double)c; return *this; }
FSize & FSize::operator*= ( double  c) [inline]

Multiplies both the width and height by c and returns a reference to the size.

Definition at line 158 of file fsize.h.

{ wd=(double)(wd*c); ht=(double)(ht*c); return *this; }
FSize & FSize::operator+= ( const FSize s) [inline]

Adds s to the size and returns a reference to this size.

Example:

    FSize s(  3, 7 );
    FSize r( -1, 4 );
    s += r;                 // s becomes (2,11)

Definition at line 149 of file fsize.h.

{ wd+=s.wd; ht+=s.ht; return *this; }
FSize & FSize::operator-= ( const FSize s) [inline]

Subtracts s from the size and returns a reference to this size.

Example:

    FSize s(  3, 7 );
    FSize r( -1, 4 );
    s -= r;                 // s becomes (4,3)

Definition at line 152 of file fsize.h.

{ wd-=s.wd; ht-=s.ht; return *this; }
FSize & FSize::operator/= ( int  c) [inline]

Definition at line 185 of file fsize.h.

{
#if defined(QT_CHECK_MATH)
    if ( c == 0 )
       warningDivByZero();
#endif
    wd/=(double)c; ht/=(double)c;
    return *this;
}

Here is the call graph for this function:

FSize & FSize::operator/= ( double  c) [inline]

Divides both the width and height by c and returns a reference to the size.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Divides both the width and height by c and returns a reference to the size.

Note that the result is truncated.

Definition at line 195 of file fsize.h.

{
#if defined(QT_CHECK_MATH)
    if ( c == 0.0 )
       warningDivByZero();
#endif
    wd=(double)(wd/c); ht=(double)(ht/c);
    return *this;
}

Here is the call graph for this function:

double & FSize::rheight ( ) [inline]

Returns a reference to the height.

Using a reference makes it possible to directly manipulate the height.

Example:

    FSize s( 100, 10 );
    s.rheight() += 5;              // s becomes (100,15)
See also:
rwidth()

Definition at line 146 of file fsize.h.

{ return ht; }
double & FSize::rwidth ( ) [inline]

Returns a reference to the width.

Using a reference makes it possible to directly manipulate the width.

Example:

    FSize s( 100, 10 );
    s.rwidth() += 20;              // s becomes (120,10)
See also:
rheight()

Definition at line 143 of file fsize.h.

{ return wd; }
void FSize::scale ( double  w,
double  h,
ScaleMode  mode 
)

Scales the size to a rectangle of width w and height h according to the ScaleMode mode.

If mode is ScaleFree, the size is set to (w, h). If mode is ScaleMin, the current size is scaled to a rectangle as large as possible inside (w, h), preserving the aspect ratio. If mode is ScaleMax, the current size is scaled to a rectangle as small as possible outside (w, h), preserving the aspect ratio.

Example:

    FSize t1( 10, 12 );
    t1.scale( 60, 60, FSize::ScaleFree );
    // t1 is (60, 60)

    FSize t2( 10, 12 );
    t2.scale( 60, 60, FSize::ScaleMin );
    // t2 is (50, 60)

    FSize t3( 10, 12 );
    t3.scale( 60, 60, FSize::ScaleMax );
    // t3 is (60, 72)

Definition at line 176 of file fsize.cpp.

{
    if ( mode == ScaleFree ) {
       wd = (double)w;
       ht = (double)h;
    } else {
       bool useHeight = TRUE;
       double w0 = width();
       double h0 = height();
       double rw = h * w0 / h0;

       if ( mode == ScaleMin ) {
           useHeight = ( rw <= w );
       } else { // mode == ScaleMax
           useHeight = ( rw >= w );
       }

       if ( useHeight ) {
           wd = (double)rw;
           ht = (double)h;
       } else {
           wd = (double)w;
           ht = (double)( w * h0 / w0 );
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FSize::scale ( const FSize s,
ScaleMode  mode 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to scale({s}.width(), {s}.height(), mode).

Definition at line 208 of file fsize.cpp.

{
    scale( s.width(), s.height(), mode );
}

Here is the call graph for this function:

void FSize::setHeight ( double  h) [inline]

Sets the height to h.

See also:
height(), setWidth()

Definition at line 140 of file fsize.h.

{ ht=(double)h; }
void FSize::setWidth ( double  w) [inline]

Sets the width to w.

See also:
width(), setHeight()

Definition at line 137 of file fsize.h.

{ wd=(double)w; }
void FSize::transpose ( )

Swaps the values of width and height.

Definition at line 127 of file fsize.cpp.

{
    double tmp = wd;
    wd = ht;
    ht = tmp;
}
void FSize::warningDivByZero ( ) [static, private]

Definition at line 378 of file fsize.cpp.

{
#if defined(QT_CHECK_MATH)
    qWarning( "FSize: Division by zero error" );
#endif
}

Here is the caller graph for this function:

double FSize::width ( ) const [inline]

Returns the width.

See also:
height()

Definition at line 131 of file fsize.h.

{ return wd; }

Here is the caller graph for this function:


Friends And Related Function Documentation

const FSize operator [related]

Multiplies s by c and returns the result.

const FSize operator [related]

Multiplies s by c and returns the result.

const FSize operator [related]

Multiplies s by c and returns the result.

bool operator!= ( const FSize s1,
const FSize s2 
) [friend]

Returns TRUE if s1 and s2 are different; otherwise returns FALSE.

Definition at line 164 of file fsize.h.

{ return s1.wd != s2.wd || s1.ht != s2.ht; }
const FSize operator* ( const FSize s,
int  c 
) [friend]

Definition at line 173 of file fsize.h.

{ return FSize(s.wd*c, s.ht*c); }
const FSize operator* ( int  c,
const FSize s 
) [friend]

Definition at line 176 of file fsize.h.

{  return FSize(s.wd*c, s.ht*c); }
const FSize operator* ( const FSize s,
double  c 
) [friend]

Multiplies s by c and returns the result.

Definition at line 179 of file fsize.h.

{ return FSize((double)(s.wd*c), (double)(s.ht*c)); }
const FSize operator* ( double  c,
const FSize s 
) [friend]

Definition at line 182 of file fsize.h.

{ return FSize((double)(s.wd*c), (double)(s.ht*c)); }
const FSize operator+ ( const FSize s1,
const FSize s2 
) [friend]

Returns the sum of s1 and s2; each component is added separately.

Definition at line 167 of file fsize.h.

{ return FSize(s1.wd+s2.wd, s1.ht+s2.ht); }
const FSize operator- ( const FSize s1,
const FSize s2 
) [friend]

Returns s2 subtracted from s1; each component is subtracted separately.

Definition at line 170 of file fsize.h.

{ return FSize(s1.wd-s2.wd, s1.ht-s2.ht); }
const FSize operator/ ( const FSize s,
int  c 
) [friend]

Definition at line 205 of file fsize.h.

{
#if defined(QT_CHECK_MATH)
    if ( c == 0 )
       FSize::warningDivByZero();
#endif
    return FSize(s.wd/c, s.ht/c);
}
const FSize operator/ ( const FSize s,
double  c 
) [friend]

Divides s by c and returns the result.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Divides s by c and returns the result.

Note that the result is truncated.

Definition at line 214 of file fsize.h.

{
#if defined(QT_CHECK_MATH)
    if ( c == 0.0 )
       FSize::warningDivByZero();
#endif
    return FSize((double)(s.wd/c), (double)(s.ht/c));
}
bool operator== ( const FSize s1,
const FSize s2 
) [friend]

Returns TRUE if s1 and s2 are equal; otherwise returns FALSE.

Definition at line 161 of file fsize.h.

{ return s1.wd == s2.wd && s1.ht == s2.ht; }

Member Data Documentation

double FSize::ht [private]

Definition at line 100 of file fsize.h.

double FSize::wd [private]

Definition at line 99 of file fsize.h.


The documentation for this class was generated from the following files: