- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qline.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QLINE_H
    00043 #define QLINE_H
    00044
    00045 #include <QtCore/qpoint.h>
    00046
    00047 QT_BEGIN_HEADER
    00048
    00049 QT_BEGIN_NAMESPACE
    00050
    00051 QT_MODULE(Core)
    00052
    00053 /*******************************************************************************
    00054  * class QLine
    00055  *******************************************************************************/
    00056
    00057 class Q_CORE_EXPORT QLine
    00058 {
    00059 public:
    00060     inline QLine();
    00061     inline QLine(const QPoint &pt1, const QPoint &pt2);
    00062     inline QLine(int x1, int y1, int x2, int y2);
    00063
    00064     inline bool isNull() const;
    00065
    00066     inline QPoint p1() const;
    00067     inline QPoint p2() const;
    00068
    00069     inline int x1() const;
    00070     inline int y1() const;
    00071
    00072     inline int x2() const;
    00073     inline int y2() const;
    00074
    00075     inline int dx() const;
    00076     inline int dy() const;
    00077
    00078     inline void translate(const QPoint &p);
    00079     inline void translate(int dx, int dy);
    00080
    00081     inline QLine translated(const QPoint &p) const;
    00082     inline QLine translated(int dx, int dy) const;
    00083
    00084     inline void setP1(const QPoint &p1);
    00085     inline void setP2(const QPoint &p2);
    00086     inline void setPoints(const QPoint &p1, const QPoint &p2);
    00087     inline void setLine(int x1, int y1, int x2, int y2);
    00088
    00089     inline bool operator==(const QLine &d) const;
    00090     inline bool operator!=(const QLine &d) const { return !(*this == d); }
    00091
    00092 private:
    00093     QPoint pt1, pt2;
    00094 };
    00095 Q_DECLARE_TYPEINFO(QLine, Q_MOVABLE_TYPE);
    00096
    00097 /*******************************************************************************
    00098  * class QLine inline members
    00099  *******************************************************************************/
    00100
    00101 inline QLine::QLine() { }
    00102
    00103 inline QLine::QLine(const QPoint &pt1_, const QPoint &pt2_) : pt1(pt1_), pt2(pt2_) { }
    00104
    00105 inline QLine::QLine(int x1pos, int y1pos, int x2pos, int y2pos) : pt1(QPoint(x1pos, y1pos)), pt2(QPoint(x2pos, y2pos)) { }
    00106
    00107 inline bool QLine::isNull() const
    00108 {
    00109     return pt1 == pt2;
    00110 }
    00111
    00112 inline int QLine::x1() const
    00113 {
    00114     return pt1.x();
    00115 }
    00116
    00117 inline int QLine::y1() const
    00118 {
    00119     return pt1.y();
    00120 }
    00121
    00122 inline int QLine::x2() const
    00123 {
    00124     return pt2.x();
    00125 }
    00126
    00127 inline int QLine::y2() const
    00128 {
    00129     return pt2.y();
    00130 }
    00131
    00132 inline QPoint QLine::p1() const
    00133 {
    00134     return pt1;
    00135 }
    00136
    00137 inline QPoint QLine::p2() const
    00138 {
    00139     return pt2;
    00140 }
    00141
    00142 inline int QLine::dx() const
    00143 {
    00144     return pt2.x() - pt1.x();
    00145 }
    00146
    00147 inline int QLine::dy() const
    00148 {
    00149     return pt2.y() - pt1.y();
    00150 }
    00151
    00152 inline void QLine::translate(const QPoint &point)
    00153 {
    00154     pt1 += point;
    00155     pt2 += point;
    00156 }
    00157
    00158 inline void QLine::translate(int adx, int ady)
    00159 {
    00160     this->translate(QPoint(adx, ady));
    00161 }
    00162
    00163 inline QLine QLine::translated(const QPoint &p) const
    00164 {
    00165     return QLine(pt1 + p, pt2 + p);
    00166 }
    00167
    00168 inline QLine QLine::translated(int adx, int ady) const
    00169 {
    00170     return translated(QPoint(adx, ady));
    00171 }
    00172
    00173 inline void QLine::setP1(const QPoint &aP1)
    00174 {
    00175     pt1 = aP1;
    00176 }
    00177
    00178 inline void QLine::setP2(const QPoint &aP2)
    00179 {
    00180     pt2 = aP2;
    00181 }
    00182
    00183 inline void QLine::setPoints(const QPoint &aP1, const QPoint &aP2)
    00184 {
    00185     pt1 = aP1;
    00186     pt2 = aP2;
    00187 }
    00188
    00189 inline void QLine::setLine(int aX1, int aY1, int aX2, int aY2)
    00190 {
    00191     pt1 = QPoint(aX1, aY1);
    00192     pt2 = QPoint(aX2, aY2);
    00193 }
    00194
    00195 inline bool QLine::operator==(const QLine &d) const
    00196 {
    00197     return pt1 == d.pt1 && pt2 == d.pt2;
    00198 }
    00199
    00200 #ifndef QT_NO_DEBUG_STREAM
    00201 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLine &p);
    00202 #endif
    00203
    00204 #ifndef QT_NO_DATASTREAM
    00205 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLine &);
    00206 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLine &);
    00207 #endif
    00208
    00209 /*******************************************************************************
    00210  * class QLineF
    00211  *******************************************************************************/
    00212 class Q_CORE_EXPORT QLineF {
    00213 public:
    00214
    00215     enum IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection };
    00216
    00217     inline QLineF();
    00218     inline QLineF(const QPointF &pt1, const QPointF &pt2);
    00219     inline QLineF(qreal x1, qreal y1, qreal x2, qreal y2);
    00220     inline QLineF(const QLine &line) : pt1(line.p1()), pt2(line.p2()) { }
    00221
    00222     static QLineF fromPolar(qreal length, qreal angle);
    00223
    00224     bool isNull() const;
    00225
    00226     inline QPointF p1() const;
    00227     inline QPointF p2() const;
    00228
    00229     inline qreal x1() const;
    00230     inline qreal y1() const;
    00231
    00232     inline qreal x2() const;
    00233     inline qreal y2() const;
    00234
    00235     inline qreal dx() const;
    00236     inline qreal dy() const;
    00237
    00238     qreal length() const;
    00239     void setLength(qreal len);
    00240
    00241     qreal angle() const;
    00242     void setAngle(qreal angle);
    00243
    00244     qreal angleTo(const QLineF &l) const;
    00245
    00246     QLineF unitVector() const;
    00247     QLineF normalVector() const;
    00248
    00249     // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType
    00250     IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const;
    00251
    00252     qreal angle(const QLineF &l) const;
    00253
    00254     QPointF pointAt(qreal t) const;
    00255     inline void translate(const QPointF &p);
    00256     inline void translate(qreal dx, qreal dy);
    00257
    00258     inline QLineF translated(const QPointF &p) const;
    00259     inline QLineF translated(qreal dx, qreal dy) const;
    00260
    00261     inline void setP1(const QPointF &p1);
    00262     inline void setP2(const QPointF &p2);
    00263     inline void setPoints(const QPointF &p1, const QPointF &p2);
    00264     inline void setLine(qreal x1, qreal y1, qreal x2, qreal y2);
    00265
    00266     inline bool operator==(const QLineF &d) const;
    00267     inline bool operator!=(const QLineF &d) const { return !(*this == d); }
    00268
    00269     QLine toLine() const;
    00270
    00271 private:
    00272     QPointF pt1, pt2;
    00273 };
    00274 Q_DECLARE_TYPEINFO(QLineF, Q_MOVABLE_TYPE);
    00275
    00276 /*******************************************************************************
    00277  * class QLineF inline members
    00278  *******************************************************************************/
    00279
    00280 inline QLineF::QLineF()
    00281 {
    00282 }
    00283
    00284 inline QLineF::QLineF(const QPointF &apt1, const QPointF &apt2)
    00285     : pt1(apt1), pt2(apt2)
    00286 {
    00287 }
    00288
    00289 inline QLineF::QLineF(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos)
    00290     : pt1(x1pos, y1pos), pt2(x2pos, y2pos)
    00291 {
    00292 }
    00293
    00294 inline qreal QLineF::x1() const
    00295 {
    00296     return pt1.x();
    00297 }
    00298
    00299 inline qreal QLineF::y1() const
    00300 {
    00301     return pt1.y();
    00302 }
    00303
    00304 inline qreal QLineF::x2() const
    00305 {
    00306     return pt2.x();
    00307 }
    00308
    00309 inline qreal QLineF::y2() const
    00310 {
    00311     return pt2.y();
    00312 }
    00313
    00314 inline QPointF QLineF::p1() const
    00315 {
    00316     return pt1;
    00317 }
    00318
    00319 inline QPointF QLineF::p2() const
    00320 {
    00321     return pt2;
    00322 }
    00323
    00324 inline qreal QLineF::dx() const
    00325 {
    00326     return pt2.x() - pt1.x();
    00327 }
    00328
    00329 inline qreal QLineF::dy() const
    00330 {
    00331     return pt2.y() - pt1.y();
    00332 }
    00333
    00334 inline QLineF QLineF::normalVector() const
    00335 {
    00336     return QLineF(p1(), p1() + QPointF(dy(), -dx()));
    00337 }
    00338
    00339 inline void QLineF::translate(const QPointF &point)
    00340 {
    00341     pt1 += point;
    00342     pt2 += point;
    00343 }
    00344
    00345 inline void QLineF::translate(qreal adx, qreal ady)
    00346 {
    00347     this->translate(QPointF(adx, ady));
    00348 }
    00349
    00350 inline QLineF QLineF::translated(const QPointF &p) const
    00351 {
    00352     return QLineF(pt1 + p, pt2 + p);
    00353 }
    00354
    00355 inline QLineF QLineF::translated(qreal adx, qreal ady) const
    00356 {
    00357     return translated(QPointF(adx, ady));
    00358 }
    00359
    00360 inline void QLineF::setLength(qreal len)
    00361 {
    00362     if (isNull())
    00363         return;
    00364     QLineF v = unitVector();
    00365     pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len);
    00366 }
    00367
    00368 inline QPointF QLineF::pointAt(qreal t) const
    00369 {
    00370     qreal vx = pt2.x() - pt1.x();
    00371     qreal vy = pt2.y() - pt1.y();
    00372     return QPointF(pt1.x() + vx * t, pt1.y() + vy * t);
    00373 }
    00374
    00375 inline QLine QLineF::toLine() const
    00376 {
    00377     return QLine(pt1.toPoint(), pt2.toPoint());
    00378 }
    00379
    00380
    00381 inline void QLineF::setP1(const QPointF &aP1)
    00382 {
    00383     pt1 = aP1;
    00384 }
    00385
    00386 inline void QLineF::setP2(const QPointF &aP2)
    00387 {
    00388     pt2 = aP2;
    00389 }
    00390
    00391 inline void QLineF::setPoints(const QPointF &aP1, const QPointF &aP2)
    00392 {
    00393     pt1 = aP1;
    00394     pt2 = aP2;
    00395 }
    00396
    00397 inline void QLineF::setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2)
    00398 {
    00399     pt1 = QPointF(aX1, aY1);
    00400     pt2 = QPointF(aX2, aY2);
    00401 }
    00402
    00403
    00404 inline bool QLineF::operator==(const QLineF &d) const
    00405 {
    00406     return pt1 == d.pt1 && pt2 == d.pt2;
    00407 }
    00408
    00409
    00410
    00411 #ifndef QT_NO_DEBUG_STREAM
    00412 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLineF &p);
    00413 #endif
    00414
    00415 #ifndef QT_NO_DATASTREAM
    00416 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLineF &);
    00417 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLineF &);
    00418 #endif
    00419
    00420 QT_END_NAMESPACE
    00421
    00422 QT_END_HEADER
    00423
    00424 #endif // QLINE_H