src/corelib/tools/qline.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtCore module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QLINE_H
00025 #define QLINE_H
00026 
00027 #include <QtCore/qpoint.h>
00028 
00029 QT_BEGIN_HEADER
00030 
00031 QT_MODULE(Core)
00032 
00033 /*******************************************************************************
00034  * class QLine
00035  *******************************************************************************/
00036 
00037 class Q_CORE_EXPORT QLine
00038 {
00039 public:
00040     inline QLine();
00041     inline QLine(const QPoint &pt1, const QPoint &pt2);
00042     inline QLine(int x1, int y1, int x2, int y2);
00043 
00044     inline bool isNull() const;
00045 
00046     inline QPoint p1() const;
00047     inline QPoint p2() const;
00048 
00049     inline int x1() const;
00050     inline int y1() const;
00051 
00052     inline int x2() const;
00053     inline int y2() const;
00054 
00055     inline int dx() const;
00056     inline int dy() const;
00057 
00058     inline void translate(const QPoint &p);
00059     inline void translate(int dx, int dy);
00060 
00061     inline bool operator==(const QLine &d) const;
00062     inline bool operator!=(const QLine &d) const { return !(*this == d); }
00063 
00064 private:
00065     QPoint pt1, pt2;
00066 };
00067 Q_DECLARE_TYPEINFO(QLine, Q_MOVABLE_TYPE);
00068 
00069 /*******************************************************************************
00070  * class QLine inline members
00071  *******************************************************************************/
00072 
00073 inline QLine::QLine() { }
00074 
00075 inline QLine::QLine(const QPoint &pt1_, const QPoint &pt2_) : pt1(pt1_), pt2(pt2_) { }
00076 
00077 inline QLine::QLine(int x1pos, int y1pos, int x2pos, int y2pos) : pt1(QPoint(x1pos, y1pos)), pt2(QPoint(x2pos, y2pos)) { }
00078 
00079 inline bool QLine::isNull() const
00080 {
00081     return pt1 == pt2;
00082 }
00083 
00084 inline int QLine::x1() const
00085 {
00086     return pt1.x();
00087 }
00088 
00089 inline int QLine::y1() const
00090 {
00091     return pt1.y();
00092 }
00093 
00094 inline int QLine::x2() const
00095 {
00096     return pt2.x();
00097 }
00098 
00099 inline int QLine::y2() const
00100 {
00101     return pt2.y();
00102 }
00103 
00104 inline QPoint QLine::p1() const
00105 {
00106     return pt1;
00107 }
00108 
00109 inline QPoint QLine::p2() const
00110 {
00111     return pt2;
00112 }
00113 
00114 inline int QLine::dx() const
00115 {
00116     return pt2.x() - pt1.x();
00117 }
00118 
00119 inline int QLine::dy() const
00120 {
00121     return pt2.y() - pt1.y();
00122 }
00123 
00124 inline void QLine::translate(const QPoint &point)
00125 {
00126     pt1 += point;
00127     pt2 += point;
00128 }
00129 
00130 inline void QLine::translate(int adx, int ady)
00131 {
00132     this->translate(QPoint(adx, ady));
00133 }
00134 
00135 inline bool QLine::operator==(const QLine &d) const
00136 {
00137     return pt1 == d.pt1 && pt2 == d.pt2;
00138 }
00139 
00140 #ifndef QT_NO_DEBUG_STREAM
00141 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLine &p);
00142 #endif
00143 
00144 #ifndef QT_NO_DATASTREAM
00145 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLine &);
00146 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLine &);
00147 #endif
00148 
00149 /*******************************************************************************
00150  * class QLineF
00151  *******************************************************************************/
00152 class Q_CORE_EXPORT QLineF {
00153 public:
00154 
00155     enum IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection };
00156 
00157     inline QLineF();
00158     inline QLineF(const QPointF &pt1, const QPointF &pt2);
00159     inline QLineF(qreal x1, qreal y1, qreal x2, qreal y2);
00160     inline QLineF(const QLine &line) : pt1(line.p1()), pt2(line.p2()) { }
00161 
00162     bool isNull() const;
00163 
00164     inline QPointF p1() const;
00165     inline QPointF p2() const;
00166 
00167     inline qreal x1() const;
00168     inline qreal y1() const;
00169 
00170     inline qreal x2() const;
00171     inline qreal y2() const;
00172 
00173     inline qreal dx() const;
00174     inline qreal dy() const;
00175 
00176     qreal length() const;
00177     void setLength(qreal len);
00178 
00179     QLineF unitVector() const;
00180     QLineF normalVector() const;
00181 
00182     // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType
00183     IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const;
00184 
00185     qreal angle(const QLineF &l) const;
00186 
00187     QPointF pointAt(qreal t) const;
00188     inline void translate(const QPointF &p);
00189     inline void translate(qreal dx, qreal dy);
00190 
00191     inline bool operator==(const QLineF &d) const;
00192     inline bool operator!=(const QLineF &d) const { return !(*this == d); }
00193 
00194     QLine toLine() const;
00195 
00196 private:
00197     QPointF pt1, pt2;
00198 };
00199 Q_DECLARE_TYPEINFO(QLineF, Q_MOVABLE_TYPE);
00200 
00201 /*******************************************************************************
00202  * class QLineF inline members
00203  *******************************************************************************/
00204 
00205 inline QLineF::QLineF()
00206 {
00207 }
00208 
00209 inline QLineF::QLineF(const QPointF &apt1, const QPointF &apt2)
00210     : pt1(apt1), pt2(apt2)
00211 {
00212 }
00213 
00214 inline QLineF::QLineF(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos)
00215     : pt1(x1pos, y1pos), pt2(x2pos, y2pos)
00216 {
00217 }
00218 
00219 inline qreal QLineF::x1() const
00220 {
00221     return pt1.x();
00222 }
00223 
00224 inline qreal QLineF::y1() const
00225 {
00226     return pt1.y();
00227 }
00228 
00229 inline qreal QLineF::x2() const
00230 {
00231     return pt2.x();
00232 }
00233 
00234 inline qreal QLineF::y2() const
00235 {
00236     return pt2.y();
00237 }
00238 
00239 inline QPointF QLineF::p1() const
00240 {
00241     return pt1;
00242 }
00243 
00244 inline QPointF QLineF::p2() const
00245 {
00246     return pt2;
00247 }
00248 
00249 inline qreal QLineF::dx() const
00250 {
00251     return pt2.x() - pt1.x();
00252 }
00253 
00254 inline qreal QLineF::dy() const
00255 {
00256     return pt2.y() - pt1.y();
00257 }
00258 
00259 inline QLineF QLineF::normalVector() const
00260 {
00261     return QLineF(p1(), p1() + QPointF(dy(), -dx()));
00262 }
00263 
00264 inline void QLineF::translate(const QPointF &point)
00265 {
00266     pt1 += point;
00267     pt2 += point;
00268 }
00269 
00270 inline void QLineF::translate(qreal adx, qreal ady)
00271 {
00272     this->translate(QPointF(adx, ady));
00273 }
00274 
00275 inline void QLineF::setLength(qreal len)
00276 {
00277     if (isNull())
00278         return;
00279     QLineF v = unitVector();
00280     pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len);
00281 }
00282 
00283 inline QPointF QLineF::pointAt(qreal t) const
00284 {
00285     qreal vx = pt2.x() - pt1.x();
00286     qreal vy = pt2.y() - pt1.y();
00287     return QPointF(pt1.x() + vx * t, pt1.y() + vy * t);
00288 }
00289 
00290 inline QLine QLineF::toLine() const
00291 {
00292     return QLine(pt1.toPoint(), pt2.toPoint());
00293 }
00294 
00295 inline bool QLineF::operator==(const QLineF &d) const
00296 {
00297     return pt1 == d.pt1 && pt2 == d.pt2;
00298 }
00299 
00300 #ifndef QT_NO_DEBUG_STREAM
00301 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLineF &p);
00302 #endif
00303 
00304 #ifndef QT_NO_DATASTREAM
00305 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLineF &);
00306 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLineF &);
00307 #endif
00308 
00309 QT_END_HEADER
00310 
00311 #endif // QLINE_H

Generated on Thu Mar 15 11:53:52 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1