Q3Painter Class Reference

#include <q3painter.h>

Inheritance diagram for Q3Painter:

Inheritance graph
[legend]
Collaboration diagram for Q3Painter:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3Painter class is a Qt 3 compatibility wrapper for QPainter.

Prior to Qt 4, QPainter specialized the pen drawing for rectangle based functions (in particular: drawRect, drawEllipse, drawRoundRect, drawArc, drawChord and drawPie). When stroking a rectangle of width 10, the pen would draw a rectangle of width 10. Drawing a polygon defined by the corner points of the same rectangle the stroke would have a width of 11.

The reason for this is best explained using the picture below:

q3painter_rationale.png

As we can see, stroking the rectangle so it gets a width of 10, means the pen is drawn on a rectangle on width 9. The polygon, however follows a consistent model.

In Qt 4, all rectangle based functions have changed to follow the polygon approach, which means that the rectangle defines the size of the fill, and the pen follows the edges of the shape. For pen widths of 0 and 1 this means that the stroke will be inside the shape on the left and the top and outside on the bottom and right.

The reason for the change in Qt 4 is so that we provide consistency for all drawing functions even with complex transformations.

Definition at line 33 of file q3painter.h.

Public Member Functions

 Q3Painter ()
 Q3Painter (QPaintDevice *pdev)
void drawRect (const QRect &rect)
void drawRect (int x1, int y1, int w, int h)
void drawRoundRect (const QRect &r, int xround=25, int yround=25)
void drawRoundRect (int x, int y, int w, int h, int xround=25, int yround=25)
void drawEllipse (const QRect &r)
void drawEllipse (int x, int y, int w, int h)
void drawArc (const QRect &r, int a, int alen)
void drawArc (int x, int y, int w, int h, int a, int alen)
void drawPie (const QRect &r, int a, int alen)
void drawPie (int x, int y, int w, int h, int a, int alen)
void drawChord (const QRect &r, int a, int alen)
void drawChord (int x, int y, int w, int h, int a, int alen)

Private Member Functions

QRect adjustedRectangle (const QRect &r)


Constructor & Destructor Documentation

Q3Painter::Q3Painter (  )  [inline]

Constructs a Q3Painter.

Definition at line 36 of file q3painter.h.

00036 : QPainter() { }

Q3Painter::Q3Painter ( QPaintDevice pdev  )  [inline]

Constructs a Q3Painter that operates on device pdev.

Definition at line 37 of file q3painter.h.

00037 : QPainter(pdev) { }


Member Function Documentation

void Q_COMPAT_EXPORT Q3Painter::drawRect ( const QRect r  )  [inline]

Draws a rectangle that fits inside the rectangle r using the current pen and brush.

Reimplemented from QPainter.

Definition at line 67 of file q3painter.h.

References adjustedRectangle(), and QPainter::drawRect().

00068 {
00069     QPainter::drawRect(adjustedRectangle(r));
00070 }

Here is the call graph for this function:

void Q3Painter::drawRect ( int  x,
int  y,
int  w,
int  h 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws the rectangle that fits inside the bounds specified by x, y, w and h using the current pen and brush.

Reimplemented from QPainter.

Definition at line 40 of file q3painter.h.

00041     { drawRect(QRect(x1, y1, w, h)); }

void Q_COMPAT_EXPORT Q3Painter::drawRoundRect ( const QRect r,
int  xrnd = 25,
int  yrnd = 25 
) [inline]

Draws a rounded rect that fits into the bounds r using the current pen and brush. The parameters xrnd and yrnd specifies the roundness in x and y direction.

Reimplemented from QPainter.

Definition at line 77 of file q3painter.h.

References adjustedRectangle(), and QPainter::drawRoundRect().

00078 {
00079     QPainter::drawRoundRect(adjustedRectangle(r), xrnd, yrnd);
00080 }

Here is the call graph for this function:

void Q3Painter::drawRoundRect ( int  x,
int  y,
int  w,
int  h,
int  xrnd = 25,
int  yrnd = 25 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws a rounded rect that fits into the bounds x, y, w and h using the current pen and brush. The parameters xrnd and yrnd specifies the roundness in x and y direction.

Reimplemented from QPainter.

Definition at line 44 of file q3painter.h.

00045     { drawRoundRect(QRect(x, y, w, h), xround, yround); }

void Q_COMPAT_EXPORT Q3Painter::drawEllipse ( const QRect r  )  [inline]

Draws the ellipse that fits inside the bounds r using the current pen and brush.

Reimplemented from QPainter.

Definition at line 72 of file q3painter.h.

References adjustedRectangle(), and QPainter::drawEllipse().

00073 {
00074     QPainter::drawEllipse(adjustedRectangle(r));
00075 }

Here is the call graph for this function:

Q3Painter::drawEllipse ( int  x,
int  y,
int  width,
int  height 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws an ellipse that fits inside the bounds specified by x, y, width and height using the current pen and brush.

Reimplemented from QPainter.

Definition at line 48 of file q3painter.h.

00049     { drawEllipse(QRect(x, y, w, h)); }

void Q_COMPAT_EXPORT Q3Painter::drawArc ( const QRect r,
int  a,
int  alen 
) [inline]

Draws an arc defined by the rectangle r, the start angle a and the arc length alen.

The angles a and alen are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of a and alen mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

Example:

        QPainter p(myWidget);
        p.drawArc(QRect(10,10, 70,100), 100*16, 160*16); // draws a "(" arc

See also:
drawPie(), drawChord()

Reimplemented from QPainter.

Definition at line 82 of file q3painter.h.

References adjustedRectangle(), and QPainter::drawArc().

00083 {
00084     QPainter::drawArc(adjustedRectangle(r), angle, arcLength);
00085 }

Here is the call graph for this function:

void Q3Painter::drawArc ( int  x,
int  y,
int  w,
int  h,
int  startAngle,
int  spanAngle 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws the arc that fits inside the rectangle ({x}, {y}, {w}, {h}), with the given startAngle and spanAngle.

Reimplemented from QPainter.

Definition at line 52 of file q3painter.h.

00053     { drawArc(QRect(x, y, w, h), a, alen); }

void Q_COMPAT_EXPORT Q3Painter::drawPie ( const QRect r,
int  a,
int  alen 
) [inline]

Draws a pie defined by the rectangle r, the start angle a and the arc length alen.

The pie is filled with the current brush().

The angles a and alen are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of a and alen mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

See also:
drawArc(), drawChord()

Reimplemented from QPainter.

Definition at line 87 of file q3painter.h.

References adjustedRectangle(), and QPainter::drawPie().

00088 {
00089     QPainter::drawPie(adjustedRectangle(r), angle, arcLength);
00090 }

Here is the call graph for this function:

void Q3Painter::drawPie ( int  x,
int  y,
int  w,
int  h,
int  startAngle,
int  spanAngle 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws a pie segment that fits inside the bounds ({x}, {y}, {w}, {h}) with the given startAngle and spanAngle.

Reimplemented from QPainter.

Definition at line 56 of file q3painter.h.

00057     { drawPie(QRect(x, y, w, h), a, alen); }

void Q_COMPAT_EXPORT Q3Painter::drawChord ( const QRect r,
int  a,
int  alen 
) [inline]

Draws a chord defined by the rectangle r, the start angle a and the arc length alen.

The chord is filled with the current brush().

The angles a and alen are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of a and alen mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

See also:
drawArc(), drawPie()

Reimplemented from QPainter.

Definition at line 92 of file q3painter.h.

References adjustedRectangle(), and QPainter::drawChord().

00093 {
00094     QPainter::drawChord(adjustedRectangle(r), angle, arcLength);
00095 }

Here is the call graph for this function:

void Q3Painter::drawChord ( int  x,
int  y,
int  w,
int  h,
int  startAngle,
int  spanAngle 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws a chord that fits inside the rectangle ({x}, {y}, {w}, {h}) with the given startAngle and spanAngle.

Reimplemented from QPainter.

Definition at line 60 of file q3painter.h.

00061     { drawChord(QRect(x, y, w, h), a, alen); }

QRect Q3Painter::adjustedRectangle ( const QRect r  )  [private]

Definition at line 75 of file q3painter.cpp.

References QRect::height(), QRect::normalized(), QRect::setSize(), and QRect::width().

Referenced by drawArc(), drawChord(), drawEllipse(), drawPie(), drawRect(), and drawRoundRect().

00076 {
00077     QRect rect = r.normalized();
00078     int subtract = d_func()->rectSubtraction();
00079     if (subtract != 0)
00080         rect.setSize(QSize(rect.width() - subtract, rect.height() - subtract));
00081     return rect;
00082 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:12:46 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1