QLine Class Reference

#include <qline.h>

Collaboration diagram for QLine:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QLine class provides a two-dimensional vector using integer precision.

A QLine describes a finite length line (or a line segment) on a two-dimensional surface. The start and end points of the line are specified using integer point accuracy for coordinates. Use the QLineF constructor to retrieve a floating point copy.

qline-point.png qline-coordinates.png

The positions of the line's start and end points can be retrieved using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The dx() and dy() functions return the horizontal and vertical components of the line. Use isNull() to determine whether the QLine represents a valid line or a null line.

Finally, the line can be translated a given offset using the translate() function.

See also:
QLineF, QPolygon, QRect

Definition at line 37 of file qline.h.

Public Member Functions

 QLine ()
 QLine (const QPoint &pt1, const QPoint &pt2)
 QLine (int x1, int y1, int x2, int y2)
bool isNull () const
QPoint p1 () const
QPoint p2 () const
int x1 () const
int y1 () const
int x2 () const
int y2 () const
int dx () const
int dy () const
void translate (const QPoint &p)
void translate (int dx, int dy)
bool operator== (const QLine &d) const
bool operator!= (const QLine &d) const

Private Attributes

QPoint pt1
QPoint pt2

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QLine &line)
QDataStreamoperator>> (QDataStream &stream, QLine &line)


Constructor & Destructor Documentation

QLine::QLine (  )  [inline]

Constructs a null line.

Definition at line 73 of file qline.h.

00073 { }

QLine::QLine ( const QPoint p1,
const QPoint p2 
) [inline]

Constructs a line object that represents the line between p1 and p2.

Definition at line 75 of file qline.h.

00075 : pt1(pt1_), pt2(pt2_) { }

QLine::QLine ( int  x1,
int  y1,
int  x2,
int  y2 
) [inline]

Constructs a line object that represents the line between (x1, y1) and (x2, y2).

Definition at line 77 of file qline.h.

00077 : pt1(QPoint(x1pos, y1pos)), pt2(QPoint(x2pos, y2pos)) { }


Member Function Documentation

bool QLine::isNull (  )  const [inline]

Returns true if the line is not set up with valid start and end point; otherwise returns false.

Definition at line 79 of file qline.h.

References pt1, and pt2.

00080 {
00081     return pt1 == pt2;
00082 }

QPoint QLine::p1 (  )  const [inline]

Returns the line's start point.

See also:
x1(), y1(), p2()

Definition at line 104 of file qline.h.

References pt1.

Referenced by QPlastiqueStyle::drawControl(), QX11PaintEngine::drawLines(), QPainter::drawLines(), QCleanlooksStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QMatrix::map(), operator<<(), and operator<<().

00105 {
00106     return pt1;
00107 }

QPoint QLine::p2 (  )  const [inline]

Returns the line's end point.

See also:
x2(), y2(), p1()

Definition at line 109 of file qline.h.

References pt2.

Referenced by QPlastiqueStyle::drawControl(), QX11PaintEngine::drawLines(), QCleanlooksStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QMatrix::map(), operator<<(), and operator<<().

00110 {
00111     return pt2;
00112 }

int QLine::x1 (  )  const [inline]

Returns the x-coordinate of the line's start point.

See also:
p1()

Definition at line 84 of file qline.h.

References pt1, and QPoint::x().

Referenced by QPaintEngine::drawLines().

00085 {
00086     return pt1.x();
00087 }

Here is the call graph for this function:

int QLine::y1 (  )  const [inline]

Returns the y-coordinate of the line's start point.

See also:
p1()

Definition at line 89 of file qline.h.

References pt1, and QPoint::y().

Referenced by QPaintEngine::drawLines().

00090 {
00091     return pt1.y();
00092 }

Here is the call graph for this function:

int QLine::x2 (  )  const [inline]

Returns the x-coordinate of the line's end point.

See also:
p2()

Definition at line 94 of file qline.h.

References pt2, and QPoint::x().

Referenced by QPaintEngine::drawLines().

00095 {
00096     return pt2.x();
00097 }

Here is the call graph for this function:

int QLine::y2 (  )  const [inline]

Returns the y-coordinate of the line's end point.

See also:
p2()

Definition at line 99 of file qline.h.

References pt2, and QPoint::y().

Referenced by QPaintEngine::drawLines().

00100 {
00101     return pt2.y();
00102 }

Here is the call graph for this function:

int QLine::dx (  )  const [inline]

Returns the horizontal component of the line's vector.

See also:
dy()

Definition at line 114 of file qline.h.

References pt1, pt2, and QPoint::x().

00115 {
00116     return pt2.x() - pt1.x();
00117 }

Here is the call graph for this function:

int QLine::dy (  )  const [inline]

Returns the vertical component of the line's vector.

See also:
dx()

Definition at line 119 of file qline.h.

References pt1, pt2, and QPoint::y().

00120 {
00121     return pt2.y() - pt1.y();
00122 }

Here is the call graph for this function:

void QLine::translate ( const QPoint offset  )  [inline]

Translates this line by the given offset.

Definition at line 124 of file qline.h.

References pt1, and pt2.

Referenced by QPainter::drawLines(), and translate().

00125 {
00126     pt1 += point;
00127     pt2 += point;
00128 }

void QLine::translate ( int  dx,
int  dy 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Translates this line the distance specified by dx and dy.

Definition at line 130 of file qline.h.

References translate().

00131 {
00132     this->translate(QPoint(adx, ady));
00133 }

Here is the call graph for this function:

bool QLine::operator== ( const QLine line  )  const [inline]

Returns true if the given line is the same as this line.

A line is identical to another line if the start and end points are identical, and the internal order of the points is the same.

Definition at line 135 of file qline.h.

References d, pt1, and pt2.

00136 {
00137     return pt1 == d.pt1 && pt2 == d.pt2;
00138 }

bool QLine::operator!= ( const QLine line  )  const [inline]

Returns true if the given line is not the same as this line.

A line is different from another line if any of their start or end points differ, or the internal order of the points is different.

Definition at line 62 of file qline.h.

References d.

00062 { return !(*this == d); }


Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QLine line 
) [related]

Writes the given line to the given stream and returns a reference to the stream.

See also:
{Format of the QDataStream Operators}

Definition at line 201 of file qline.cpp.

References p1(), p2(), and QTest::stream.

00202 {
00203     stream << line.p1() << line.p2();
00204     return stream;
00205 }

Here is the call graph for this function:

QDataStream & operator>> ( QDataStream stream,
QLine line 
) [related]

Reads a line from the given stream into the given line and returns a reference to the stream.

See also:
{Format of the QDataStream Operators}

Definition at line 216 of file qline.cpp.

References QTest::stream.

00217 {
00218     QPoint p1, p2;
00219     stream >> p1;
00220     stream >> p2;
00221     line = QLine(p1, p2);
00222 
00223     return stream;
00224 }


Member Data Documentation

QPoint QLine::pt1 [private]

Definition at line 65 of file qline.h.

Referenced by dx(), dy(), isNull(), operator==(), p1(), translate(), x1(), and y1().

QPoint QLine::pt2 [private]

Definition at line 65 of file qline.h.

Referenced by dx(), dy(), isNull(), operator==(), p2(), translate(), x2(), and y2().


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