📄 qpainterpath.cpp
字号:
\sa ElementType, elementAt(), isEmpty()*//*! \fn const QPainterPath::Element &QPainterPath::elementAt(int index) const Returns the element at the given \a index in the painter path. \sa ElementType, elementCount(), isEmpty()*//*! \fn void QPainterPath::setElementPositionAt(int index, qreal x, qreal y) \since 4.2 Sets the x and y coordinate of the element at index \a index to \a x and \a y.*//*### \fn QPainterPath &QPainterPath::operator +=(const QPainterPath &other) Appends the \a other painter path to this painter path and returns a reference to the result.*//*! Constructs an empty QPainterPath object.*/QPainterPath::QPainterPath() : d_ptr(0){}/*! \fn QPainterPath::QPainterPath(const QPainterPath &path) Creates a QPainterPath object that is a copy of the given \a path. \sa operator=()*/QPainterPath::QPainterPath(const QPainterPath &other) : d_ptr(other.d_ptr){ if (d_func()) d_func()->ref.ref();}/*! Creates a QPainterPath object with the given \a startPoint as its current position.*/QPainterPath::QPainterPath(const QPointF &startPoint) : d_ptr(new QPainterPathData){ Element e = { startPoint.x(), startPoint.y(), MoveToElement }; d_func()->elements << e;}/*! \internal*/void QPainterPath::detach_helper(){ QPainterPathPrivate *data = new QPainterPathData(*d_func()); data = qAtomicSetPtr(&d_ptr, data); if (data && !data->ref.deref()) delete (QPainterPathData *) data;}/*! \internal*/void QPainterPath::ensureData_helper(){ QPainterPathPrivate *data = new QPainterPathData; data->elements.reserve(16); QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement }; data->elements << e; data = qAtomicSetPtr(&d_ptr, data); if (data && !data->ref.deref()) delete (QPainterPathData *) data; Q_ASSERT(d_ptr != 0);}/*! \fn QPainterPath &QPainterPath::operator=(const QPainterPath &path) Assigns the given \a path to this painter path. \sa QPainterPath()*/QPainterPath &QPainterPath::operator=(const QPainterPath &other){ if (other.d_func() != d_func()) { QPainterPathPrivate *data = other.d_func(); if (data) data->ref.ref(); data = qAtomicSetPtr(&d_ptr, data); if (data && !data->ref.deref()) delete (QPainterPathData *) data; } return *this;}/*! Destroys this QPainterPath object.*/QPainterPath::~QPainterPath(){ if (d_func() && !d_func()->ref.deref()) delete d_func();}/*! Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path. The current point of the new path is (0, 0). If the subpath does not contain any elements, this function does nothing. \sa moveTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath} */void QPainterPath::closeSubpath(){#ifdef QPP_DEBUG printf("QPainterPath::closeSubpath()\n");#endif if (isEmpty()) return; detach(); d_func()->close();}/*! \fn void QPainterPath::moveTo(qreal x, qreal y) \overload Moves the current position to (\a{x}, \a{y}) and starts a new subpath, implicitly closing the previous path.*//*! \fn void QPainterPath::moveTo(const QPointF &point) Moves the current point to the given \a point, implicitly starting a new subpath and closing the previous one. \sa closeSubpath(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}*/void QPainterPath::moveTo(const QPointF &p){#ifdef QPP_DEBUG printf("QPainterPath::moveTo() (%.2f,%.2f)\n", p.x(), p.y());#endif#ifndef QT_NO_DEBUG if (qt_is_nan(p.x()) || qt_is_nan(p.y())) qWarning("QPainterPath::moveTo: Adding point where x or y is NaN, results are undefined");#endif ensureData(); detach(); QPainterPathData *d = d_func(); Q_ASSERT(!d->elements.isEmpty()); d->require_moveTo = false; if (d->elements.last().type == MoveToElement) { d->elements.last().x = p.x(); d->elements.last().y = p.y(); } else { Element elm = { p.x(), p.y(), MoveToElement }; d->elements.append(elm); } d->cStart = d->elements.size() - 1;}/*! \fn void QPainterPath::lineTo(qreal x, qreal y) \overload Draws a line from the current position to the point (\a{x}, \a{y}).*//*! \fn void QPainterPath::lineTo(const QPointF &endPoint) Adds a straight line from the current position to the given \a endPoint. After the line is drawn, the current position is updated to be at the end point of the line. \sa addPolygon(), addRect(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath} */void QPainterPath::lineTo(const QPointF &p){#ifdef QPP_DEBUG printf("QPainterPath::lineTo() (%.2f,%.2f)\n", p.x(), p.y());#endif#ifndef QT_NO_DEBUG if (qt_is_nan(p.x()) || qt_is_nan(p.y())) qWarning("QPainterPath::lineTo: Adding point where x or y is NaN, results are undefined");#endif ensureData(); detach(); QPainterPathData *d = d_func(); Q_ASSERT(!d->elements.isEmpty()); d->maybeMoveTo(); if (p == QPointF(d->elements.last())) return; Element elm = { p.x(), p.y(), LineToElement }; d->elements.append(elm);}/*! \fn void QPainterPath::cubicTo(qreal c1X, qreal c1Y, qreal c2X, qreal c2Y, qreal endPointX, qreal endPointY); \overload Adds a cubic Bezier curve between the current position and the end point (\a{endPointX}, \a{endPointY}) with control points specified by (\a{c1X}, \a{c1Y}) and (\a{c2X}, \a{c2Y}).*//*! \fn void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &endPoint) Adds a cubic Bezier curve between the current position and the given \a endPoint using the control points specified by \a c1, and \a c2. After the curve is added, the current position is updated to be at the end point of the curve. \table 100% \row \o \inlineimage qpainterpath-cubicto.png \o \code QLinearGradient myGradient; QPen myPen; QPainterPath myPath; myPath.cubicto(c1, c2, endPoint); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); \endcode \endtable \sa quadTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}*/void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &e){#ifdef QPP_DEBUG printf("QPainterPath::cubicTo() (%.2f,%.2f), (%.2f,%.2f), (%.2f,%.2f)\n", c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y());#endif#ifndef QT_NO_DEBUG if (qt_is_nan(c1.x()) || qt_is_nan(c1.y()) || qt_is_nan(c2.x()) || qt_is_nan(c2.y()) || qt_is_nan(e.x()) || qt_is_nan(e.y())) qWarning("QPainterPath::cubicTo: Adding point where x or y is NaN, results are undefined");#endif ensureData(); detach(); QPainterPathData *d = d_func(); Q_ASSERT(!d->elements.isEmpty()); // Abort on empty curve as a stroker cannot handle this and the // curve is irrelevant anyway. if (d->elements.last() == c1 && c1 == c2 && c2 == e) return; d->maybeMoveTo(); Element ce1 = { c1.x(), c1.y(), CurveToElement }; Element ce2 = { c2.x(), c2.y(), CurveToDataElement }; Element ee = { e.x(), e.y(), CurveToDataElement }; d->elements << ce1 << ce2 << ee;}/*! \fn void QPainterPath::quadTo(qreal cx, qreal cy, qreal endPointX, qreal endPointY); \overload Adds a quadratic Bezier curve between the current point and the endpoint (\a{endPointX}, \a{endPointY}) with the control point specified by (\a{cx}, \a{cy}).*//*! \fn void QPainterPath::quadTo(const QPointF &c, const QPointF &endPoint) Adds a quadratic Bezier curve between the current position and the given \a endPoint with the control point specified by \a c. After the curve is added, the current point is updated to be at the end point of the curve. \sa cubicTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}*/void QPainterPath::quadTo(const QPointF &c, const QPointF &e){#ifdef QPP_DEBUG printf("QPainterPath::quadTo() (%.2f,%.2f), (%.2f,%.2f)\n", c.x(), c.y(), e.x(), e.y());#endif#ifndef QT_NO_DEBUG if (qt_is_nan(c.x()) || qt_is_nan(c.y()) || qt_is_nan(e.x()) || qt_is_nan(e.y())) qWarning("QPainterPath::quadTo: Adding point where x or y is NaN, results are undefined");#endif ensureData(); detach(); Q_D(QPainterPath); Q_ASSERT(!d->elements.isEmpty()); const QPainterPath::Element &elm = d->elements.at(elementCount()-1); QPointF prev(elm.x, elm.y); // Abort on empty curve as a stroker cannot handle this and the // curve is irrelevant anyway. if (prev == c && c == e) return; QPointF c1((prev.x() + 2*c.x()) / 3, (prev.y() + 2*c.y()) / 3); QPointF c2((e.x() + 2*c.x()) / 3, (e.y() + 2*c.y()) / 3); cubicTo(c1, c2, e);}/*! \fn void QPainterPath::arcTo(qreal x, qreal y, qreal width, qreal height, qreal startAngle, qreal sweepLength) \overload Creates an arc that occupies the rectangle QRectF(\a x, \a y, \a width, \a height), beginning at the specified \a startAngle and extending \a sweepLength degrees counter-clockwise.*//*! \fn void QPainterPath::arcTo(const QRectF &rectangle, qreal startAngle, qreal sweepLength) Creates an arc that occupies the given \a rectangle, beginning at the specified \a startAngle and extending \a sweepLength degrees counter-clockwise. Angles are specified in degrees. Clockwise arcs can be specified using negative angles. Note that this function connects the starting point of the arc to the current position if they are not already connected. After the arc has been added, the current position is the last point in arc. To draw a line back to the first point, use the closeSubpath() function. \table 100% \row \o \inlineimage qpainterpath-arcto.png \o \code QLinearGradient myGradient; QPen myPen; QPointF center, startPoint; QPainterPath myPath; myPath.moveTo(center); myPath.arcTo(boundingRect, startAngle, sweepLength); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); \endcode \endtable \sa arcMoveTo(), addEllipse(), QPainter::drawArc(), QPainter::drawPie(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}*/void QPainterPath::arcTo(const QRectF &rect, qreal startAngle, qreal sweepLength){#ifdef QPP_DEBUG printf("QPainterPath::arcTo() (%.2f, %.2f, %.2f, %.2f, angle=%.2f, sweep=%.2f\n", rect.x(), rect.y(), rect.width(), rect.height(), startAngle, sweepLength);#endif#ifndef QT_NO_DEBUG if (qt_is_nan(rect.x()) || qt_is_nan(rect.y()) || qt_is_nan(rect.width()) || qt_is_nan(rect.height()) || qt_is_nan(startAngle) || qt_is_nan(sweepLength)) qWarning("QPainterPath::arcTo: Adding arc where a parameter is NaN, results are undefined");#endif if (rect.isNull()) return; ensureData(); detach(); int point_count; QPointF pts[12]; QPointF curve_start = qt_curves_for_arc(rect, startAngle, sweepLength, pts, &point_count); lineTo(curve_start); for (int i=0; i<point_count; i+=3) { cubicTo(pts[i].x(), pts[i].y(), pts[i+1].x(), pts[i+1].y(), pts[i+2].x(), pts[i+2].y()); }}/*!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -