Scribus
Open source desktop publishing at your fingertips
FSize Class Reference

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

Public Types

enum  ScaleMode { ScaleFree, ScaleMin, ScaleMax }
 

Public Member Functions

 FSize ()
 
 FSize (qreal w, qreal h)
 
bool isNull () const
 
bool isEmpty () const
 
bool isValid () const
 
qreal width () const
 
qreal height () const
 
void setWidth (qreal w)
 
void setHeight (qreal h)
 
void transpose ()
 
void scale (qreal w, qreal h, Qt::AspectRatioMode mode)
 
void scale (const FSize &s, Qt::AspectRatioMode mode)
 
FSize expandedTo (const FSize &) const
 
FSize boundedTo (const FSize &) const
 
qreal & rwidth ()
 
qreal & rheight ()
 
FSizeoperator+= (const FSize &)
 
FSizeoperator-= (const FSize &)
 
FSizeoperator*= (int c)
 
FSizeoperator*= (qreal c)
 
FSizeoperator/= (int c)
 
FSizeoperator/= (qreal c)
 

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 &, qreal)
 
const FSize operator* (qreal, const FSize &)
 
const FSize operator/ (const FSize &, int)
 
const FSize operator/ (const FSize &, qreal)
 

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 qreal (defined in <qwindowdefs.h> as qreal). The minimum value of qreal is qreal_MIN (-2147483648) and the maximum value is qreal_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

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()

Constructor & Destructor Documentation

FSize::FSize ( )
inline

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

FSize::FSize ( qreal  w,
qreal  h 
)
inline

Constructs a size with width w and height 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.

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

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

qreal FSize::height ( ) const
inline

Returns the height.

See also
width()
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.

bool FSize::isNull ( void  ) const
inline

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

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.

FSize & FSize::operator*= ( qreal  c)
inline

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

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)
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)
FSize & FSize::operator/= ( qreal  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.

qreal & 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()
qreal & 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()
void FSize::scale ( qreal  w,
qreal  h,
Qt::AspectRatioMode  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)
void FSize::scale ( const FSize s,
Qt::AspectRatioMode  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).

void FSize::setHeight ( qreal  h)
inline

Sets the height to h.

See also
height(), setWidth()
void FSize::setWidth ( qreal  w)
inline

Sets the width to w.

See also
width(), setHeight()
void FSize::transpose ( )

Swaps the values of width and height.

qreal FSize::width ( ) const
inline

Returns the width.

See also
height()

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.

const FSize operator* ( const FSize s,
qreal  c 
)
friend

Multiplies s by c and returns the result.

const FSize operator+ ( const FSize s1,
const FSize s2 
)
friend

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

const FSize operator- ( const FSize s1,
const FSize s2 
)
friend

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

const FSize operator/ ( const FSize s,
qreal  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.

bool operator== ( const FSize s1,
const FSize s2 
)
friend

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


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