QPainterPath SmoothCurveCreator::createSmoothCurve(const QList<QPointF> &points) { QPainterPath path; int len = points.size(); if (len < 2) { return path; } QList<QPointF> firstControlPoints; QList<QPointF> secondControlPoints; calculateControlPoints(points, &firstControlPoints, &secondControlPoints); path.moveTo(points[0].x(), points[0].y()); // Using bezier curve to gelnerate a smooth curve. for (int i = 0; i < len - 1; ++i) { path.cubicTo(firstControlPoints[i], secondControlPoints[i], points[i+1]); } return path; }
void QNEConnection::updatePath() { QPainterPath p; //QPointF pos1(m_port1->scenePos()); //QPointF pos2(m_port2->scenePos()); p.moveTo(m_pos1); QPointF ctrl1, ctrl2; ctrl1.setX(m_pos1.x() + (m_port1 ? m_port1->dir().x() : -m_port2->dir().x()) * 50.f); ctrl1.setY(m_pos1.y()); ctrl2.setX(m_pos2.x() + (m_port2 ? m_port2->dir().x() : -m_port1->dir().x()) * 50.f); ctrl2.setY(m_pos2.y()); p.cubicTo(ctrl1, ctrl2, m_pos2); setPath(p); }
void YigModField::redrawArc() { qreal arcAngle; float arcWidth, arcHeight; arcAngle = rotationAngle; QPainterPath arcPath; arcPath.moveTo(boundingRect().center()); /* //arcPath.moveTo((YigSynthGraphic::MOD_FIELD_SIZE/2) - (YigSynthGraphic::MOD_FIELD_2_SIZE/2), YigSynthGraphic::MOD_FIELD_SIZE/2); arcPath.cubicTo(boundingRect().center(), QPointF(0, 0), QPointF(0, boundingRect().height()/2)); //QPointF endPoint(0, boundingRect().height()/2); */ float size = rotationAngle/360; QRectF angleRect = QRectF((boundingRect().width()/2) - ((boundingRect().width()/2) * size), (boundingRect().height()/2) - ((boundingRect().height()/2) * size), boundingRect().width() * size, boundingRect().height() * size); /* //arcPath.addEllipse(angleRect.center(), angleRect.width() * size /2, angleRect.height() * size /2); arcPath.cubicTo(angleRect.topLeft() * size, angleRect.bottomRight() * size, angleRect.bottomRight()); arcPath.cubicTo(angleRect.topLeft() * size, angleRect.bottomRight() * size, angleRect.center()); arcPath.setFillRule(Qt::OddEvenFill);*/ arcPath.arcTo(boundingRect(), -180, rotationAngle); arcPath.cubicTo(boundingRect().bottomLeft(), boundingRect().topRight(), boundingRect().center()); QPolygonF arcPolygon = arcPath.toFillPolygon(); modArc.setPolygon(arcPolygon); }
QPainterPath GraphScene::makePath(TimeLine * l, int minidx, int maxidx, bool zero_edges) { QPainterPath path; QPointF p1; QPointF p2; for (int j=minidx;j<=maxidx;j++) { p2.setX(((TimeIndex*)l->at(j))->getTime()); p2.setY(l->at(j)->getData()->getValue()); if (zero_edges==true && j==minidx) { path.moveTo(QPointF(p2.x(),0)); } if (draw_smooth==false) { if (j==minidx && zero_edges ==false) { path.moveTo(p2); } else { path.lineTo(p2); } } else { if (j==minidx) { if (zero_edges) { path.lineTo(p2); } else { path.moveTo(p2); } } else { double distance = p2.x() - p1.x(); path.cubicTo(p1.x() + distance / 2, p1.y(), p1.x() + distance / 2, p2.y(), p2.x(), p2.y()); } } if (zero_edges==true && j==maxidx) { path.lineTo(QPointF(p2.x(),0)); } p1=p2; } return path; }
void Tweener::press(const TupInputDeviceInformation *input, TupBrushManager *brushManager, TupGraphicsScene *scene) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[Tweener::press()]"; #else T_FUNCINFO; #endif #endif Q_UNUSED(brushManager); Q_UNUSED(scene); if (k->editMode == TupToolPlugin::Properties && k->scene->currentFrameIndex() == k->initFrame) { if (k->path) { QPointF point = k->path->mapFromParent(input->pos()); QPainterPath path = k->path->path(); path.cubicTo(point, point, point); k->path->setPath(path); } } }
void DrawableSpline2D::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if (!isDisplayed()) return; if (_object->nbMarkers() >= 2) // we must have at least 2 points { if(_currentShapePath) delete _currentShapePath; _currentShapePath = new QPainterPath; QPen pen = (isSelected() && isEditable() ? _penList[DrawableObject2D::Selected] : _penList[DrawableObject2D::Unselected]); painter->setPen(pen); painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform); double *tcp = static_cast<Spline2D*>(_object.get())->getControlPoints(); QPainterPath path; for (unsigned int i=0; i<_object->nbMarkers()-1; i++, tcp+=9) { /* * Cubic Bezier curve: * tcp[0] = x0, tcp[1] = y0 -> starting point * tcp[3] = x1, tcp[4] = y1 -> control point 1 * tcp[6] = x2, tcp[7] = y2 -> control point 2 * tcp[9] = x3, tcp[10] = y3 -> ending point * */ double x0, y0, x1, y1, x2, y2, x3, y3; transformCoord(tcp[0], tcp[1], x0, y0); transformCoord(tcp[3], tcp[4], x1, y1); transformCoord(tcp[6], tcp[7], x2, y2); transformCoord(tcp[9], tcp[10], x3, y3); path.moveTo(x0, y0); path.cubicTo(x1, y1, x2, y2, x3, y3); } painter->drawPath(path); updateShapePath(path); } DrawableObject2D::paint(painter, option, widget); }
void PainterBezier::paint(QPainter * painter) { painter->setBrush(Qt::transparent); QRectF rect = calculateBoundingBox(); setX(rect.topLeft().x() - 10); setY( rect.topLeft().y() - 10); setWidth( rect.width() + 20); setHeight( rect.height() + 20); QPen pen; pen.setWidthF(m_OutlineWidth); pen.setBrush(m_OutlineColor); painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); painter->setPen(pen); painter->setBrush(m_FillColor); QPainterPath bezierPath; QPointF pos(x(),y()); bezierPath.moveTo(m_p1 - pos); bezierPath.cubicTo( m_p2 - pos, m_p3 - pos, m_p4 - pos ); QPainterPathStroker outliner; outliner.setWidth(m_FillWidth); outliner.setCapStyle( Qt::FlatCap ); m_Path = outliner.createStroke(bezierPath); painter->drawPath(m_Path); }
extern "C" void pathext_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *, const fz_matrix *ctm, fz_colorspace *, float *, float) { PathExt *ext = static_cast<PathExt*>(dev->user); if( ext == 0 ) { return; } QPainterPath qPath; float *c = path->coords; for(int i = 0; i < path->cmd_len; i++) { if( path->cmds[i] == FZ_MOVETO ) { qPath.moveTo(c[0], c[1]); c += 2; } else if( path->cmds[i] == FZ_LINETO ) { qPath.lineTo(c[0], c[1]); c += 2; } else if( path->cmds[i] == FZ_CURVETO ) { qPath.cubicTo(c[0], c[1], c[2], c[3], c[4], c[5]); c += 6; } else if( path->cmds[i] == FZ_CLOSE_PATH ) { if( !ext->closed ) { return; } qPath.closeSubpath(); } else { return; } } const QTransform qCtm = toTransform(ctm); qPath = qCtm.map(qPath); ext->paths.push_back(qPath); }
void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); QPainterPath path; //移动当前点到点(50, 250) path.moveTo(50, 250); //从当前点即(50, 250)绘制一条直线到点(50, 230),完成后当前点更改为(50, 230) path.lineTo(50, 230); //从当前点和点(120, 60)之间绘制一条三次贝塞尔曲线 path.cubicTo(QPointF(105, 40), QPointF(115, 80), QPointF(120, 60)); path.lineTo(130, 130); //向路径中添加一个椭圆 path.addEllipse(QPoint(130, 130), 30, 30); painter.setPen(Qt::darkYellow); //绘制路径 painter.drawPath(path); //平移坐标系统后重新绘制路径 path.translate(200,0); painter.setPen(Qt::darkBlue); painter.drawPath(path); }
QPainterPath LinkConnectionGraphicsItem::obtainCurvePath() const { QPointF inRight = inLink_->getRightPos(); QPointF inLeft = inLink_->getLeftPos(); QPointF outRight = outLink_->getRightPos(); QPointF outLeft = outLink_->getLeftPos(); QPointF start; QPointF stop; QPointF ctrlPointStart; QPointF ctrlPointStop; QPointF qp = QPointF(1, 0); QPainterPath bezierCurve; if (outLeft.x() <= inRight.x()) { start = outLeft; stop = inRight; ctrlPointStart = qp; ctrlPointStop = -qp; } else if (outRight.x() >= inLeft.x()) { start = outRight; stop = inLeft; ctrlPointStart = -qp; ctrlPointStop = qp; } else { start = outLeft; stop = inLeft; ctrlPointStart = qp; ctrlPointStop = qp; } float dist = 1.0f + std::min(50.0f, 2.0f * static_cast<float>(QVector2D(start - stop).length())); bezierCurve.moveTo(start); bezierCurve.cubicTo(start + dist * ctrlPointStart, stop + dist * ctrlPointStop, stop); return bezierCurve; }
void PathStrokeRenderer::paint(QPainter *painter) { if (m_points.isEmpty()) initializePoints(); painter->setRenderHint(QPainter::Antialiasing); QPalette pal = palette(); painter->setPen(Qt::NoPen); // Construct the path QPainterPath path; path.moveTo(m_points.at(0)); if (m_pathMode == LineMode) { for (int i=1; i<m_points.size(); ++i) path.lineTo(m_points.at(i)); } else { int i=1; while (i + 2 < m_points.size()) { path.cubicTo(m_points.at(i), m_points.at(i+1), m_points.at(i+2)); i += 3; } while (i < m_points.size()) { path.lineTo(m_points.at(i)); ++i; } } // Draw the path { QColor lg = Qt::red; // The "custom" pen if (m_penStyle == Qt::NoPen) { QPainterPathStroker stroker; stroker.setWidth(m_penWidth); stroker.setJoinStyle(m_joinStyle); stroker.setCapStyle(m_capStyle); QVector<qreal> dashes; qreal space = 4; dashes << 1 << space << 3 << space << 9 << space << 27 << space << 9 << space << 3 << space; stroker.setDashPattern(dashes); QPainterPath stroke = stroker.createStroke(path); painter->fillPath(stroke, lg); } else { QPen pen(lg, m_penWidth, m_penStyle, m_capStyle, m_joinStyle); painter->strokePath(path, pen); } } if (1) { // Draw the control points painter->setPen(QColor(50, 100, 120, 200)); painter->setBrush(QColor(200, 200, 210, 120)); for (int i=0; i<m_points.size(); ++i) { QPointF pos = m_points.at(i); painter->drawEllipse(QRectF(pos.x() - m_pointSize, pos.y() - m_pointSize, m_pointSize*2, m_pointSize*2)); } painter->setPen(QPen(Qt::lightGray, 0, Qt::SolidLine)); painter->setBrush(Qt::NoBrush); painter->drawPolyline(m_points); } }
QImage ShapeState::buildShape(const std::vector<Point>& _points) { if (_points.empty()) { return QImage(); } size_t n = _points.size(); std::vector<Point> points = _points; QColor shapeColor(84, 84, 84); QPointF min, max; min.setX(std::numeric_limits<float>::max()); min.setY(std::numeric_limits<float>::max()); max.setX(std::numeric_limits<float>::lowest()); max.setY(std::numeric_limits<float>::lowest()); for (const auto& p: points) { max.setX(std::max(max.x(), p.point.x())); max.setY(std::max(max.y(), p.point.y())); min.setX(std::min(min.x(), p.point.x())); min.setY(std::min(min.y(), p.point.y())); } { //re-center the points QPointF center = (max + min) / 2.f; for (auto& p: points) { p.point -= center; } } QSizeF imageSize((max - min).x(), (max - min).y()); imageSize += QSize(200, 200); QPointF imageCenter(imageSize.width() / 2.f, imageSize.height() / 2.f); QImage image = QImage(imageSize.toSize(), QImage::Format_RGBA8888_Premultiplied); image.fill(0); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing, true); QPen pen(shapeColor, 3.f); pen.setCapStyle(Qt::RoundCap); pen.setJoinStyle(Qt::RoundJoin); painter.setPen(pen); QPainterPath path; // Append and prepend knots and control points to close the curve { auto last = points.back(); points.push_back(*(points.begin() + 0)); points.push_back(*(points.begin() + 1)); points.insert(points.begin(), last); } std::vector<QPointF> cp; for(size_t i = 0; i < n; i++) { QPointF cp0, cp1; getControlPoints(points[i].point, points[i + 1].point, points[i + 2].point, points[i].t, cp0, cp1); cp.push_back(cp0); cp.push_back(cp1); } cp.push_back(cp.front()); for(size_t i = 1; i < n + 1; i++) { //var color=HSVtoRGB(Math.floor(240*(i-2)/(n-2)),0.8,0.8); //if(!showDetails){color="#555555"} //ctx.strokeStyle=hexToCanvasColor(color,0.75); path.moveTo(imageCenter + points[i].point); path.cubicTo(imageCenter + cp[i*2 - 1], imageCenter + cp[i*2], imageCenter + points[i + 1].point); } path.setFillRule(Qt::WindingFill); painter.drawPath(path); return floodFill(image, imageCenter.toPoint(), shapeColor.rgb()); }
void SdfRenderer::path_draw(QDomElement &element) { QPointF end_point; QPointF c1; QPointF c2; QDomElement elem = element; QPainterPath path; if (!elem.isNull()) { QString d_cont; d_cont = elem.attribute("d").remove(0, 1); d_cont.append(" Z"); for (i = 0; i < d_cont.length() - 1;) { if (d_cont[i] == 'M') { j = i + 2; while (isNotLCMZ(d_cont, j)) { while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); ++j; s1.clear(); } path.moveTo(end_point); i = j; } else if (d_cont[i] == 'L') { j = i + 2; while (isNotLCMZ(d_cont, j)) { while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); ++j; s1.clear(); } path.lineTo(end_point); i = j; } else if (d_cont[i] == 'C') { j = i + 2; while(isNotLCMZ(d_cont, j)) { while (!(d_cont[j] == ' ')) { s1.append(d_cont[j]); ++j; } c1.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } c1.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } c2.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } c2.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); s1.clear(); ++j; } path.cubicTo(c1, c2, end_point); i = j; } else if (d_cont[i] == 'Z') { path.closeSubpath(); logger ("loggerZ.txt", "DONE"); } } } parsestyle(element); painter->drawPath(path); }
bool QQuickSvgParser::parsePathDataFast(const QString &dataStr, QPainterPath &path) { qreal x0 = 0, y0 = 0; // starting point qreal x = 0, y = 0; // current point char lastMode = 0; QPointF ctrlPt; const QChar *str = dataStr.constData(); const QChar *end = str + dataStr.size(); while (str != end) { while (str->isSpace()) ++str; QChar pathElem = *str; ++str; QChar endc = *end; *const_cast<QChar *>(end) = 0; // parseNumbersArray requires 0-termination that QStringRef cannot guarantee QVarLengthArray<qreal, 8> arg; parseNumbersArray(str, arg); *const_cast<QChar *>(end) = endc; if (pathElem == QLatin1Char('z') || pathElem == QLatin1Char('Z')) arg.append(0);//dummy const qreal *num = arg.constData(); int count = arg.count(); while (count > 0) { qreal offsetX = x; // correction offsets qreal offsetY = y; // for relative commands switch (pathElem.unicode()) { case 'm': { if (count < 2) { num++; count--; break; } x = x0 = num[0] + offsetX; y = y0 = num[1] + offsetY; num += 2; count -= 2; path.moveTo(x0, y0); // As per 1.2 spec 8.3.2 The "moveto" commands // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands, // the subsequent pairs shall be treated as implicit 'lineto' commands. pathElem = QLatin1Char('l'); } break; case 'M': { if (count < 2) { num++; count--; break; } x = x0 = num[0]; y = y0 = num[1]; num += 2; count -= 2; path.moveTo(x0, y0); // As per 1.2 spec 8.3.2 The "moveto" commands // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands, // the subsequent pairs shall be treated as implicit 'lineto' commands. pathElem = QLatin1Char('L'); } break; case 'z': case 'Z': { x = x0; y = y0; count--; // skip dummy num++; path.closeSubpath(); } break; case 'l': { if (count < 2) { num++; count--; break; } x = num[0] + offsetX; y = num[1] + offsetY; num += 2; count -= 2; path.lineTo(x, y); } break; case 'L': { if (count < 2) { num++; count--; break; } x = num[0]; y = num[1]; num += 2; count -= 2; path.lineTo(x, y); } break; case 'h': { x = num[0] + offsetX; num++; count--; path.lineTo(x, y); } break; case 'H': { x = num[0]; num++; count--; path.lineTo(x, y); } break; case 'v': { y = num[0] + offsetY; num++; count--; path.lineTo(x, y); } break; case 'V': { y = num[0]; num++; count--; path.lineTo(x, y); } break; case 'c': { if (count < 6) { num += count; count = 0; break; } QPointF c1(num[0] + offsetX, num[1] + offsetY); QPointF c2(num[2] + offsetX, num[3] + offsetY); QPointF e(num[4] + offsetX, num[5] + offsetY); num += 6; count -= 6; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 'C': { if (count < 6) { num += count; count = 0; break; } QPointF c1(num[0], num[1]); QPointF c2(num[2], num[3]); QPointF e(num[4], num[5]); num += 6; count -= 6; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 's': { if (count < 4) { num += count; count = 0; break; } QPointF c1; if (lastMode == 'c' || lastMode == 'C' || lastMode == 's' || lastMode == 'S') c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c1 = QPointF(x, y); QPointF c2(num[0] + offsetX, num[1] + offsetY); QPointF e(num[2] + offsetX, num[3] + offsetY); num += 4; count -= 4; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 'S': { if (count < 4) { num += count; count = 0; break; } QPointF c1; if (lastMode == 'c' || lastMode == 'C' || lastMode == 's' || lastMode == 'S') c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c1 = QPointF(x, y); QPointF c2(num[0], num[1]); QPointF e(num[2], num[3]); num += 4; count -= 4; path.cubicTo(c1, c2, e); ctrlPt = c2; x = e.x(); y = e.y(); break; } case 'q': { if (count < 4) { num += count; count = 0; break; } QPointF c(num[0] + offsetX, num[1] + offsetY); QPointF e(num[2] + offsetX, num[3] + offsetY); num += 4; count -= 4; path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 'Q': { if (count < 4) { num += count; count = 0; break; } QPointF c(num[0], num[1]); QPointF e(num[2], num[3]); num += 4; count -= 4; path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 't': { if (count < 2) { num += count; count = 0; break; } QPointF e(num[0] + offsetX, num[1] + offsetY); num += 2; count -= 2; QPointF c; if (lastMode == 'q' || lastMode == 'Q' || lastMode == 't' || lastMode == 'T') c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c = QPointF(x, y); path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 'T': { if (count < 2) { num += count; count = 0; break; } QPointF e(num[0], num[1]); num += 2; count -= 2; QPointF c; if (lastMode == 'q' || lastMode == 'Q' || lastMode == 't' || lastMode == 'T') c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y()); else c = QPointF(x, y); path.quadTo(c, e); ctrlPt = c; x = e.x(); y = e.y(); break; } case 'a': { if (count < 7) { num += count; count = 0; break; } qreal rx = (*num++); qreal ry = (*num++); qreal xAxisRotation = (*num++); qreal largeArcFlag = (*num++); qreal sweepFlag = (*num++); qreal ex = (*num++) + offsetX; qreal ey = (*num++) + offsetY; count -= 7; qreal curx = x; qreal cury = y; pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag), int(sweepFlag), ex, ey, curx, cury); x = ex; y = ey; } break; case 'A': { if (count < 7) { num += count; count = 0; break; } qreal rx = (*num++); qreal ry = (*num++); qreal xAxisRotation = (*num++); qreal largeArcFlag = (*num++); qreal sweepFlag = (*num++); qreal ex = (*num++); qreal ey = (*num++); count -= 7; qreal curx = x; qreal cury = y; pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag), int(sweepFlag), ex, ey, curx, cury); x = ex; y = ey; } break; default: return false; } lastMode = pathElem.toLatin1(); } } return true; }
//! //! Updates the path end points according to the positions of start and end //! nodes. //! void ConnectionGraphicsItem::updatePath () { prepareGeometryChange(); // calculate positions of the end points QPointF startPoint = m_startPoint; QPointF endPoint = m_endPoint; if (m_startNodeItem) startPoint += m_startNodeItem->pos(); if (m_endNodeItem) endPoint += m_endNodeItem->pos(); // calculate the rectangles to help calculating the positions of the node's anchor points const qreal offset = 10; QRectF baseAnchorRect = QRectF(-offset, -offset, 2 * offset, 2 * offset); QRectF startAnchorRect = baseAnchorRect.translated(startPoint); QRectF endAnchorRect = baseAnchorRect.translated(endPoint); if (m_startNodeItem) startAnchorRect = m_startNodeItem->rect().adjusted(-offset, -offset, offset, offset).translated(m_startNodeItem->pos()); if (m_endNodeItem) endAnchorRect = m_endNodeItem->rect().adjusted(-offset, -offset, offset, offset).translated(m_endNodeItem->pos()); // // Diagram of anchor points for start and end nodes: // // x x sU2, sU1 eU1, eU2 x x // ,----, ,----, // | | | | // | | | | // | x| x sP, sO eO, eP x |x | // '----' '----' // x x sL2, sL1 eL1, eL2 x x // QPointF sP = startPoint; QPointF sO = QPointF(startAnchorRect.right(), startPoint.y()); QPointF sU1 = startAnchorRect.topRight(); QPointF sU2 = startAnchorRect.topLeft(); QPointF sL1 = startAnchorRect.bottomRight(); QPointF sL2 = startAnchorRect.bottomLeft(); QPointF eP = endPoint; QPointF eO = QPointF(endAnchorRect.left(), endPoint.y()); QPointF eU1 = endAnchorRect.topLeft(); QPointF eU2 = endAnchorRect.topRight(); QPointF eL1 = endAnchorRect.bottomLeft(); QPointF eL2 = endAnchorRect.bottomRight(); // declare path segments QList<QPointF> startPoints; QPainterPath cubicPath; QList<QPointF> endPoints; // construct the path segments if (eO.x() < sO.x() && eU2.x() > sL2.x() && eU2.y() < sL2.y() && eL2.y() > sU2.y()) { //> case 1V: elements very close to each other startPoints << sP << sO; QPointF offsetVector = QPointF(0, 0.75 * (eO.y() - sO.y())); cubicPath.moveTo(sO); cubicPath.cubicTo(sO + offsetVector, eO - offsetVector, eO); endPoints << eO << eP; } else if (eO.x() >= sO.x()) { //> case 1H: end node is right of start node startPoints << sP << sO; QPointF offsetVector = QPointF(0.75 * (eO.x() - sO.x()), 0); cubicPath.moveTo(sO); cubicPath.cubicTo(sO + offsetVector, eO - offsetVector, eO); endPoints << eO << eP; } else if (eU1.y() >= sL1.y()) { //> case 2LV startPoints << sP << sO << sL1; QPointF offsetVector = QPointF(0, 0.75 * (eU1.y() - sL1.y())); cubicPath.moveTo(sL1); cubicPath.cubicTo(sL1 + offsetVector, eU1 - offsetVector, eU1); endPoints << eU1 << eO << eP; } else if (eL1.y() <= sU1.y()) { //> case 2UV startPoints << sP << sO << sU1; QPointF offsetVector = QPointF(0, 0.75 * (eL1.y() - sU1.y())); cubicPath.moveTo(sU1); cubicPath.cubicTo(sU1 + offsetVector, eL1 - offsetVector, eL1); endPoints << eL1 << eO << eP; } else if (eP.y() >= sP.y()) { //> case 3L startPoints << sP << sO << sL1 << sL2; QPointF offsetVector = QPointF(0.75 * (eU2.x() - sL2.x()), 0); cubicPath.moveTo(sL2); cubicPath.cubicTo(sL2 + offsetVector, eU2 - offsetVector, eU2); endPoints << eU2 << eU1 << eO << eP; } else { //> case 3U startPoints << sP << sO << sU1 << sU2; QPointF offsetVector = QPointF(0.75 * (eL2.x() - sU2.x()), 0); cubicPath.moveTo(sU2); cubicPath.cubicTo(sU2 + offsetVector, eL2 - offsetVector, eL2); endPoints << eL2 << eL1 << eO << eP; } // build the main path from the path segments m_mainPath = QPainterPath(); for (int i = 0; i < startPoints.size(); ++i) if (i == 0) m_mainPath.moveTo(startPoints[0]); else m_mainPath.lineTo(startPoints[i]); m_mainPath.addPath(cubicPath); for (int i = 0; i < endPoints.size(); ++i) if (i == 0) m_mainPath.moveTo(endPoints[0]); else m_mainPath.lineTo(endPoints[i]); // create the shadow path as a copy of the main path m_shadowPath = QPainterPath(m_mainPath); // move the path elements of the shadow path one pixel down and to the right for (int i = 1; i < m_shadowPath.elementCount(); ++i) { QPainterPath::Element element = m_shadowPath.elementAt(i); m_shadowPath.setElementPositionAt(i, element.x + 1, element.y + 1); } // get the center point for the arrow and the angle at that point static const qreal t = 0.5; QPointF arrowPoint = cubicPath.pointAtPercent(t); qreal angle = cubicPath.angleAtPercent(t) * Pi / 180; // calculate the polygon for the arrow head qreal pathLengthFraction = m_mainPath.length() / 10; static const qreal maxArrowSize = 10; qreal arrowSize = pathLengthFraction < maxArrowSize ? pathLengthFraction : maxArrowSize; QPointF arrowPoint1 = arrowPoint - QPointF(arrowSize * sin(angle - Pi / 2), arrowSize * cos(angle - Pi / 2)); QPointF arrowPoint2 = arrowPoint - QPointF(arrowSize * sin(angle + Pi / 3), arrowSize * cos(angle + Pi / 3)); QPointF arrowPoint3 = arrowPoint - QPointF(arrowSize * sin(angle + Pi - Pi / 3), arrowSize * cos(angle + Pi - Pi / 3)); m_arrowHeadPolygon.clear(); m_arrowHeadPolygon << arrowPoint1 << arrowPoint2 << arrowPoint3; // repaint the graphics item update(); }
QPainterPath Paths::fire() { QPainterPath path; path.moveTo(362.83759,116.70426); path.cubicTo(342.56574,131.59686, 300.71403,161.23127, 311.38454,218.12635); path.cubicTo(322.05506,275.02144, 358.53432,301.66527, 328.90674,328.73285); path.cubicTo(299.27916,355.80044, 251.48877,339.59410, 255.46042,288.61972); path.cubicTo(258.22374,253.15368, 278.34141,205.10942, 278.34141,205.10942); path.cubicTo(278.34141,205.10942, 234.02455,233.13427, 219.68939,254.01270); path.cubicTo(205.35424,274.89113, 189.71452,330.07842, 208.58356,373.33974); path.cubicTo(227.45261,416.60109, 316.46286,456.33444, 351.12048,514.32780); path.cubicTo(374.10258,552.78425, 355.05815,613.59741, 310.80422,636.59310); path.cubicTo(256.63287,664.74219, 299.16588,580.49238, 285.22551,523.86186); path.cubicTo(273.46790,476.09839, 265.70022,445.12001, 188.03132,432.51681); path.cubicTo(233.72591,465.34901, 242.16068,495.04075, 241.45928,524.11772); path.cubicTo(240.78648,552.00862, 214.39595,634.57293, 177.39967,596.79021); path.cubicTo(140.72642,559.33737, 214.27071,512.68654, 170.92945,471.62081); path.cubicTo(174.73284,501.40284, 145.30515,514.98828, 131.55318,544.54392); path.cubicTo(118.22673,573.18509, 123.55251,610.30651, 139.07596,645.41379); path.cubicTo(181.14122,740.38745, 266.95518,726.23964, 208.75321,797.88229); path.cubicTo(164.01134,852.95649, 162.90150,907.45084, 205.60384,970.81121); path.cubicTo(240.06795,1021.9479, 371.11663,1060.7652, 432.20697,960.93460); path.cubicTo(501.87852,820.00694, 357.14883,780.33174, 386.29974,732.84721); path.cubicTo(405.70205,701.24238, 472.56601,668.86516, 501.09199,644.21233); path.cubicTo(564.18184,587.55421, 561.84437,497.32621, 522.74229,471.25817); path.cubicTo(530.19030,501.05022, 514.99952,542.79339, 483.67099,551.29691); path.cubicTo(423.41173,567.65308, 458.18351,411.79373, 564.02075,393.61925); path.cubicTo(530.91135,366.44998, 501.31413,367.33484, 454.91711,379.11707); path.cubicTo(397.61736,393.57908, 407.64322,315.40944, 494.34643,262.67861); path.cubicTo(549.19500,229.32101, 499.11573,147.63302, 491.66772,136.46100); path.cubicTo(485.38713,213.93294, 435.43515,233.35601, 409.98053,235.72292); path.cubicTo(375.27049,238.95043, 377.84554,214.33812, 396.75003,178.92950); path.cubicTo(416.21172,142.47722, 448.15395,89.429942, 376.51366,44.060977); path.cubicTo(388.13560,71.270572, 395.93673,94.012962, 362.83759,116.70426); path.closeSubpath(); return path; }
void FlowDesigner::paintComponentLinks(QPainter *painter, const QRectF &bounds, const Component &comp) { QFontMetrics metrics = painter->fontMetrics(); QPen pen(Qt::red, 1); QBrush brush(Qt::red); painter->setPen(pen); float xPos = 0; float yPos = 0; // Draw any connections QPainterPath linkPath; int idx = 0; for (Port *port : comp.getPorts()) { const std::set<Port *> &connections = port->getConnections(); if (connections.size() > 0) { QRectF portBounds = calculatePortBoundingBox(*port, bounds); for (const Port *conn : connections) { // Determine who should draw the link if (comp.getProperty("id") > conn->getComponent()->getProperty("id")) continue; QRectF receivingCompBounds = calculateBoundingBox(*conn->getComponent()); QRectF receivingBounds = calculatePortBoundingBox(*conn, receivingCompBounds); float startX = portBounds.x() + 0.5f * portBounds.width(); float startY = portBounds.y() + 0.5f * portBounds.height(); float endX = receivingBounds.x() + 0.5f * receivingBounds.width(); float endY = receivingBounds.y() + 0.5f * receivingBounds.height(); float middleX = (startX + endX) / 2; float middleY = (startY + endY) / 2; linkPath.moveTo(startX, startY); linkPath.cubicTo(startX, startY, middleX, startY, middleX, middleY); linkPath.cubicTo(middleX, middleY, middleX, endY, endX, endY); } } idx++; } painter->drawPath(linkPath); // // Now draw the input/output circles // QPainterPath circlePath; QPainterPath circlePathFilled; idx = 0; for (Port *port : comp.getPorts()) { QString text = QString::fromStdString(port->getName()); QRectF portBounds = calculatePortBoundingBox(*port, bounds); if (port->isConnected()) { circlePathFilled.addEllipse(portBounds); } else { circlePath.addEllipse(portBounds); } idx++; } painter->drawPath(circlePath); painter->fillPath(circlePathFilled, brush); }
void TrafficGraph::drawBeams(QPainter *p, int top, int w, int h, int horizontalScale) { Q_ASSERT(mNiceRange != 0); if(mNiceRange == 0) mNiceRange = 1; double scaleFac = (h-1) / mNiceRange; int xPos = 0; QLinkedList< QList<double> >::Iterator it = mBeamData.begin(); p->setPen(Qt::NoPen); /* In autoRange mode we determine the range and plot the values in * one go. This is more efficiently than running through the * buffers twice but we do react on recently discarded samples as * well as new samples one plot too late. So the range is not * correct if the recently discarded samples are larger or smaller * than the current extreme values. But we can probably live with * this. * * These values aren't used directly anywhere. Instead we call * calculateNiceRange() which massages these values into a nicer * values. Rounding etc. This means it's safe to change these values * without affecting any other drawings * */ if ( mUseAutoRange ) mMinValue = mMaxValue = 0.0; /* mBezierCurveOffset is how many points we have at the start. * All the bezier curves are in groups of 3, with the first of the next group being the last point * of the previous group-> * * Example, when mBezierCurveOffset == 0, and we have data, then just plot a normal bezier curve * (we will have at least 3 points in this case) * When mBezierCurveOffset == 1, then we want a bezier curve that uses the first data point and * the second data point. Then the next group starts from the second data point. * When mBezierCurveOffset == 2, then we want a bezier curve that uses the first, second and third data * */ for (unsigned int i = 0; it != mBeamData.end() && i < mSamples; ++i) { QPen pen; pen.setWidth(1); pen.setCapStyle(Qt::FlatCap); /** * We will plot 1 bezier curve for every 3 points, with the 4th point being the end * of one bezier curve and the start of the second. * This does means the bezier curves will not join nicely, * but it should be better than nothing. */ QList<double> datapoints = *it; QList<double> prev_datapoints = datapoints; QList<double> prev_prev_datapoints = datapoints; QList<double> prev_prev_prev_datapoints = datapoints; if (i == 0 && mBezierCurveOffset>0) { /** * We are plotting an incomplete bezier curve - we don't have all the data we want. * Try to cope */ xPos += horizontalScale*mBezierCurveOffset; if (mBezierCurveOffset == 1) { prev_datapoints = *it; ++it; //Now we are on the first element of the next group, if it exists if (it != mBeamData.end()) { prev_prev_prev_datapoints = prev_prev_datapoints = *it; } else { prev_prev_prev_datapoints = prev_prev_datapoints = prev_datapoints; } } else { // mBezierCurveOffset must be 2 now prev_datapoints = *it; Q_ASSERT(it != mBeamData.end()); ++it; prev_prev_datapoints = *it; Q_ASSERT(it != mBeamData.end()); ++it; //Now we are on the first element of the next group, if it exists if (it != mBeamData.end()) { prev_prev_prev_datapoints = *it; } else { prev_prev_prev_datapoints = prev_prev_datapoints; } } } else { /** * We have a group of 3 points at least. That's 1 start point and 2 control points. */ xPos += horizontalScale*3; it++; if (it != mBeamData.end()) { prev_datapoints = *it; it++; if (it != mBeamData.end()) { prev_prev_datapoints = *it; it++; //We are now on the next set of data points if (it != mBeamData.end()) { // We have this datapoint, so use it for our finish point prev_prev_prev_datapoints = *it; } else { // We don't have the next set, so use our last control point as our finish point prev_prev_prev_datapoints = prev_prev_datapoints; } } else { prev_prev_prev_datapoints = prev_prev_datapoints = prev_datapoints; } } else { prev_prev_prev_datapoints = prev_prev_datapoints = prev_datapoints = datapoints; } } float x0 = w - xPos + 3.0*horizontalScale; float x1 = w - xPos + 2.0*horizontalScale; float x2 = w - xPos + 1.0*horizontalScale; float x3 = w - xPos; float y0 = h -1 + top; float y1 = y0; float y2 = y0; float y3 = y0; int offset = 0; //Our line is 2 pixels thick. This means that when we draw the area, we need to offset double max_y=0; double min_y=0; for (int j = qMin(datapoints.size(), mBeamColors.size())-1; j >=0 ; --j) { if ( mUseAutoRange) { //If we use autorange, then we need to prepare the min and max values for _next_ time we paint //if we are stacking the beams, then we need to add the maximums together double current_maxvalue = qMax(datapoints[j], qMax(prev_datapoints[j], qMax(prev_prev_datapoints[j], prev_prev_prev_datapoints[j]))); double current_minvalue = qMin(datapoints[j], qMin(prev_datapoints[j], qMin(prev_prev_datapoints[j], prev_prev_prev_datapoints[j]))); mMaxValue = qMax(mMaxValue, current_maxvalue); mMinValue = qMin(mMinValue, current_maxvalue); if( mStackBeams ) { max_y += current_maxvalue; min_y += current_minvalue; } } /* * Draw polygon only if enough data points are available. */ if ( j < prev_prev_prev_datapoints.count() && j < prev_prev_datapoints.count() && j < prev_datapoints.count() ) { QPolygon curve( 4 ); /* The height of the whole widget is h+top-> The height of the area we are plotting in is just h. * The y coordinate system starts from the top, so at the bottom the y coordinate is h+top * So to draw a point at value y', we need to put this at h+top-y' */ float delta_y0; delta_y0 = (datapoints[j] - mNiceMinValue)*scaleFac; float delta_y1; delta_y1 = (prev_datapoints[j] - mNiceMinValue)*scaleFac; float delta_y2; delta_y2 = (prev_prev_datapoints[j] - mNiceMinValue)*scaleFac; float delta_y3; delta_y3 = (prev_prev_prev_datapoints[j] - mNiceMinValue)*scaleFac; QPainterPath path; if(mStackBeams && offset) { //we don't want the lines to overdraw each other. This isn't a great solution though :( if(delta_y0 < 3) delta_y0=3; if(delta_y1 < 3) delta_y1=3; if(delta_y2 < 3) delta_y2=3; if(delta_y3 < 3) delta_y3=3; } path.moveTo( x0,y0-delta_y0); path.cubicTo( x1,y1-delta_y1,x2,y2-delta_y2,x3,y3-delta_y3 ); if(mFillBeams) { QPainterPath path2(path); QLinearGradient myGradient(0,(h-1+top),0,(h-1+top)/5); Q_ASSERT(mBeamColorsDark.size() >= j); Q_ASSERT(mBeamColors.size() >= j); QColor c0(mBeamColorsDark[j]); QColor c1(mBeamColors[j]); c0.setAlpha(150); c1.setAlpha(150); myGradient.setColorAt(0, c0); myGradient.setColorAt(1, c1); path2.lineTo( x3,y3-offset); if(mStackBeams) path2.cubicTo( x2,y2-offset,x1,y1-offset,x0,y0-offset); //offset is set to 1 after the first beam is drawn, so we don't trample on top of the 2pt thick line else path2.lineTo(x0,y0-1); p->setBrush(myGradient); p->setPen(Qt::NoPen); p->drawPath( path2 ); } p->setBrush(Qt::NoBrush); Q_ASSERT(mBeamColors.size() >= j); pen.setColor(mBeamColors[j]); p->setPen(pen); p->drawPath( path ); if(mStackBeams) { //We can draw the beams stacked on top of each other. This means that say beam 0 has the value 2 and beam // 1 has the value 3, then we plot beam 0 at 2 and beam 1 at 2+3 = 5. y0-=delta_y0; y1-=delta_y1; y2-=delta_y2; y3-=delta_y3; offset = 1; //see the comment further up for int offset; } } if ( mUseAutoRange && mStackBeams) { mMaxValue = qMax(max_y, mMaxValue); mMinValue = qMin(min_y, mMinValue); } } } }
// Draw curve. void samplv1widget_filt::paintEvent ( QPaintEvent *pPaintEvent ) { QPainter painter(this); const QRect& rect = QWidget::rect(); const int h = rect.height(); const int w = rect.width(); const int h2 = h >> 1; const int h4 = h >> 2; const int w4 = w >> 2; const int w8 = w >> 3; const int iSlope = int(m_fSlope); const int ws = w8 - (iSlope == 1 ? (w8 >> 1) : 0); int x = w8 + int(m_fCutoff * float(w - w4)); int y = h2 - int(m_fReso * float(h + h4)); QPolygon poly(6); QPainterPath path; const int iType = (iSlope == 3 ? 4 : int(m_fType)); // Low, Notch if (iType == 0 || iType == 3) { if (iType == 3) x -= w8; poly.putPoints(0, 6, 0, h2, x - w8, h2, x, h2, x, y, x + ws, h, 0, h); path.moveTo(poly.at(0)); path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); path.lineTo(poly.at(5)); if (iType == 3) x += w8; } // Band if (iType == 1) { const int y2 = (y + h4) >> 1; poly.putPoints(0, 6, 0, h, x - w8 - ws, h, x - ws, y2, x + ws, y2, x + w8 + ws, h, 0, h); path.moveTo(poly.at(0)); path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); path.lineTo(poly.at(5)); } // High, Notch if (iType == 2 || iType == 3) { if (iType == 3) { x += w8; y = h2; } poly.putPoints(0, 6, x - ws, h, x, y, x, h2, x + w8, h2, w, h2, w, h); path.moveTo(poly.at(0)); path.cubicTo(poly.at(1), poly.at(2), poly.at(3)); path.lineTo(poly.at(4)); path.lineTo(poly.at(5)); if (iType == 3) x -= w8; } // Formant if (iType == 4) { const int x2 = (x - w4) >> 2; const int y2 = (y - h4) >> 2; poly.putPoints(0, 6, 0, h2, x2, h2, x - ws, h2, x, y2, x + ws, h, 0, h); path.moveTo(poly.at(0)); #if 0 path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); #else const int n3 = 5; // num.formants const int w3 = (x + ws - x2) / n3 - 1; const int w6 = (w3 >> 1); const int h3 = (h4 >> 1); int x3 = x2; int y3 = y2; for (int i = 0; i < n3; ++i) { poly.putPoints(1, 3, x3, h2, x3 + w6, y3, x3 + w3, y3 + h2); path.cubicTo(poly.at(1), poly.at(2), poly.at(3)); x3 += w3; y3 += h3; } path.lineTo(poly.at(4)); #endif path.lineTo(poly.at(5)); } const QPalette& pal = palette(); const bool bDark = (pal.window().color().value() < 0x7f); const QColor& rgbLite = (isEnabled() ? (bDark ? Qt::darkYellow : Qt::yellow) : pal.mid().color()); const QColor& rgbDark = pal.window().color().darker(180); painter.fillRect(rect, rgbDark); painter.setPen(bDark ? Qt::gray : Qt::darkGray); QLinearGradient grad(0, 0, w << 1, h << 1); grad.setColorAt(0.0f, rgbLite); grad.setColorAt(1.0f, Qt::black); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(grad); painter.drawPath(path); #ifdef CONFIG_DEBUG_0 painter.drawText(QFrame::rect(), Qt::AlignTop|Qt::AlignHCenter, tr("Cutoff(%1) Reso(%2)") .arg(int(100.0f * cutoff())) .arg(int(100.0f * reso()))); #endif painter.setRenderHint(QPainter::Antialiasing, false); painter.end(); QFrame::paintEvent(pPaintEvent); }
void LibraryFilterLineEdit::paintEvent(QPaintEvent *) { QStylePainter p(this); QStyleOptionFrame o; initStyleOption(&o); o.palette = QApplication::palette(); //o.rect.adjust(0, 0, -1, 0); p.fillRect(rect(), o.palette.base().color()); QRect rLeft = QRect(o.rect.x(), o.rect.y() + 1, o.rect.height(), o.rect.y() + o.rect.height() - 2); QRect rRight = QRect(o.rect.x() + o.rect.width() - o.rect.height(), o.rect.y() + 1, o.rect.height(), o.rect.y() + o.rect.height() - 2); QRect rText = QRect(rLeft.x() + rLeft.width(), rLeft.y(), rRight.x(), rRight.y() + rRight.height()); //rLeft.adjust(0, 1, 0, -1); //rRight.adjust(0, 1, 0, -1); if (hasFocus()) { p.setPen(QPen(o.palette.highlight().color())); } else { p.setPen(QPen(o.palette.mid().color())); } p.save(); p.setRenderHint(QPainter::Antialiasing, true); QPainterPath painterPath; // 2---1----> Left curve is painted with 2 calls to cubicTo, starting in 1 <----10--9 // | | First cubic call is with points p1, p2 and p3 | | // 3 + Second is with points p3, p4 and p5 + 8 // | | With that, a half circle can be filled with linear gradient | | // 4---5----> <----6---7 painterPath.moveTo(rLeft.x() + rLeft.width(), rLeft.y()); painterPath.cubicTo(rLeft.x() + rLeft.width(), rLeft.y(), rLeft.x() + rLeft.width() / 2.0f, rLeft.y(), rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height() / 2.0f); painterPath.cubicTo(rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height() / 2.0f, rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height(), rLeft.x() + rLeft.width(), rLeft.y() + rLeft.height()); painterPath.lineTo(rRight.x(), rRight.y() + rRight.height()); painterPath.cubicTo(rRight.x(), rRight.y() + rRight.height(), rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height(), rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height() / 2.0f); painterPath.cubicTo(rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height() / 2.0f, rRight.x() + rRight.width() / 2.0f, rRight.y(), rRight.x(), rRight.y()); painterPath.closeSubpath(); p.drawPath(painterPath); p.setRenderHint(QPainter::Antialiasing, false); p.restore(); // Paint text and cursor if (hasFocus() || !text().isEmpty()) { // Highlight selected text p.setPen(o.palette.text().color()); if (hasSelectedText()) { QRect rectTextLeft, rectTextMid, rectTextRight; QString leftText, midText, rightText; int sStart = selectionStart(); int sEnd = selectedText().length() - 1; // Four uses cases to highlight a text if (sStart > 0 && sEnd < text().size() - 1) { // a[b]cd leftText = text().left(sStart); midText = selectedText(); rightText = text().mid(sStart + selectedText().length()); rectTextLeft.setX(rText.x()); rectTextLeft.setY(rText.y()); rectTextLeft.setWidth(fontMetrics().width(leftText)); rectTextLeft.setHeight(rText.height()); rectTextMid.setX(rectTextLeft.x() + rectTextLeft.width()); rectTextMid.setY(rText.y()); rectTextMid.setWidth(fontMetrics().width(midText)); rectTextMid.setHeight(rText.height()); rectTextRight.setX(rectTextMid.x() + rectTextMid.width()); rectTextRight.setY(rText.y()); rectTextRight.setWidth(fontMetrics().width(rightText)); rectTextRight.setHeight(rText.height()); p.fillRect(rectTextLeft, o.palette.base()); p.fillRect(rectTextMid, o.palette.highlight()); p.fillRect(rectTextRight, o.palette.base()); p.drawText(rectTextLeft, Qt::AlignLeft | Qt::AlignVCenter, leftText); p.save(); p.setPen(o.palette.highlightedText().color()); p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText); p.restore(); p.drawText(rectTextRight, Qt::AlignLeft | Qt::AlignVCenter, rightText); } else if (sStart == 0 && sEnd < text().size() - 1) { // [ab]cd midText = selectedText(); rightText = text().mid(sStart + selectedText().length()); rectTextMid.setX(rText.x()); rectTextMid.setY(rText.y()); rectTextMid.setWidth(fontMetrics().width(midText)); rectTextMid.setHeight(rText.height()); rectTextRight.setX(rectTextMid.x() + rectTextMid.width()); rectTextRight.setY(rText.y()); rectTextRight.setWidth(fontMetrics().width(rightText)); rectTextRight.setHeight(rText.height()); p.fillRect(rectTextMid, o.palette.highlight()); p.fillRect(rectTextRight, o.palette.base()); p.save(); p.setPen(o.palette.highlightedText().color()); p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText); p.restore(); p.drawText(rectTextRight, Qt::AlignLeft | Qt::AlignVCenter, rightText); } else if (sStart == 0 && sEnd == text().size() - 1) { // [abcd] midText = selectedText(); rectTextMid.setX(rText.x()); rectTextMid.setY(rText.y()); rectTextMid.setWidth(fontMetrics().width(midText)); rectTextMid.setHeight(rText.height()); p.fillRect(rectTextMid, o.palette.highlight()); p.save(); p.setPen(o.palette.highlightedText().color()); p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText); p.restore(); } else { // ab[cd] // never? } } else { p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, text()); } rText.adjust(0, 2, 0, -2); this->drawCursor(&p, rText); } else { p.setPen(o.palette.mid().color()); p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, placeholderText()); } }
void XmlLoader::readPath(QDomElement const &element) { QString tempStr; QPointF endPoint; QPointF c1; QPointF c2; QDomElement elem = element; QPainterPath path; if (!elem.isNull()) { QString dCont; dCont = elem.attribute("d").remove(0, 1); dCont.append(" Z"); for (int i = 0; i < dCont.length() - 1;) { int j = 0; if (dCont[i] == 'M') { j = i + 2; while (isNotLCMZ(dCont, j)) { while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setY(tempStr.toFloat()); ++j; tempStr.clear(); } path.moveTo(endPoint); i = j; } else if (dCont[i] == 'L') { j = i + 2; while (isNotLCMZ(dCont, j)) { while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setY(tempStr.toFloat()); ++j; tempStr.clear(); } path.lineTo(endPoint); i = j; } else if (dCont[i] == 'C') { j = i + 2; while(isNotLCMZ(dCont, j)) { while (!(dCont[j] == ' ')) { tempStr.append(dCont[j]); ++j; } c1.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } c1.setY(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } c2.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } c2.setY(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setY(tempStr.toFloat()); tempStr.clear(); ++j; } path.cubicTo(c1, c2, endPoint); i = j; } else if (dCont[i] == 'Z') { path.closeSubpath(); } } } Path *item = new Path(path); item->translate(mDrift.x(), mDrift.y()); item->readPenBrush(elem); mScene->addItem(item); mScene->setZValue(item); }
QPainterPath Paths::random1() { QPainterPath path; path.moveTo(65.714286,91.428571); path.lineTo(217.14286, 102.85714); path.cubicTo(219.04762, 106.66666, 220.95238, 110.47619, 222.85714,114.28571); path.cubicTo(231.2679, 131.10723, 214.72525, 138.24185, 211.42857,151.42857); path.cubicTo(207.25902, 168.10676, 213.24674, 175.8441, 217.14286,191.42857); path.cubicTo(221.088, 207.20915, 201.21538,205.71429, 188.57143,205.71429); path.cubicTo(170.18303, 205.71429, 161.42918, 197.50045, 145.71429,185.71429); path.cubicTo(113.93441, 161.87938, 132.73699, 182.37652, 137.14286, 200); path.cubicTo(140.37884, 212.94392, 128.50252, 217.16009, 117.14286, 220); path.cubicTo(98.323209, 224.70491, 91.206108, 205.41767, 82.857143, 194.28571); path.cubicTo(77.307286, 186.8859, 84.541768, 158.97578, 85.714286, 154.28571); path.cubicTo(87.843677, 145.76815, 67.066253, 132.78054, 60 , 125.71429); path.cubicTo(54.074503, 119.78879, 64.646395, 95.700137, 65.714286, 91.428571); path.closeSubpath(); return path; }
void tst_QPainterPath::contains_QPointF_data() { QTest::addColumn<QPainterPath>("path"); QTest::addColumn<QPointF>("pt"); QTest::addColumn<bool>("contained"); QPainterPath path; path.addRect(0, 0, 100, 100); // ##### // # # // # # // # # // ##### QTest::newRow("[0,0] in [0,0,100,100]") << path << QPointF(0, 0) << true; QTest::newRow("[99,0] in [0,0,100,100]") << path << QPointF(99, 0) << true; QTest::newRow("[0,99] in [0,0,100,100]") << path << QPointF(0, 99) << true; QTest::newRow("[99,99] in [0,0,100,100]") << path << QPointF(99, 99) << true; QTest::newRow("[99.99,0] in [0,0,100,100]") << path << QPointF(99.99, 0) << true; QTest::newRow("[0,99.99] in [0,0,100,100]") << path << QPointF(0, 99.99) << true; QTest::newRow("[99.99,99.99] in [0,0,100,100]") << path << QPointF(99.99, 99.99) << true; QTest::newRow("[0.01,0.01] in [0,0,100,100]") << path << QPointF(0.01, 0.01) << true; QTest::newRow("[0,0.01] in [0,0,100,100]") << path << QPointF(0, 0.01) << true; QTest::newRow("[0.01,0] in [0,0,100,100]") << path << QPointF(0.01, 0) << true; QTest::newRow("[-0.01,-0.01] in [0,0,100,100]") << path << QPointF(-0.01, -0.01) << false; QTest::newRow("[-0,-0.01] in [0,0,100,100]") << path << QPointF(0, -0.01) << false; QTest::newRow("[-0.01,0] in [0,0,100,100]") << path << QPointF(-0.01, 0) << false; QTest::newRow("[-10,0] in [0,0,100,100]") << path << QPointF(-10, 0) << false; QTest::newRow("[100,0] in [0,0,100,100]") << path << QPointF(100, 0) << false; QTest::newRow("[0,-10] in [0,0,100,100]") << path << QPointF(0, -10) << false; QTest::newRow("[0,100] in [0,0,100,100]") << path << QPointF(0, 100) << false; QTest::newRow("[100.1,0] in [0,0,100,100]") << path << QPointF(100.1, 0) << false; QTest::newRow("[0,100.1] in [0,0,100,100]") << path << QPointF(0, 100.1) << false; path.addRect(50, 50, 100, 100); // ##### // # # // # ##### // # # # # // ##### # // # # // ##### QTest::newRow("[49,49] in 2 rects") << path << QPointF(49,49) << true; QTest::newRow("[50,50] in 2 rects") << path << QPointF(50,50) << false; QTest::newRow("[100,100] in 2 rects") << path << QPointF(100,100) << true; path.setFillRule(Qt::WindingFill); QTest::newRow("[50,50] in 2 rects (winding)") << path << QPointF(50,50) << true; path.addEllipse(0, 0, 150, 150); // ##### // ## ## // # ##### // # # # # // ##### # // ## ## // ##### QTest::newRow("[50,50] in complex (winding)") << path << QPointF(50, 50) << true; path.setFillRule(Qt::OddEvenFill); QTest::newRow("[50,50] in complex (windinf)") << path << QPointF(50, 50) << true; QTest::newRow("[49,49] in complex") << path << QPointF(49,49) << false; QTest::newRow("[100,100] in complex") << path << QPointF(49,49) << false; // unclosed triangle path = QPainterPath(); path.moveTo(100, 100); path.lineTo(130, 70); path.lineTo(150, 110); QTest::newRow("[100,100] in triangle") << path << QPointF(100, 100) << true; QTest::newRow("[140,100] in triangle") << path << QPointF(140, 100) << true; QTest::newRow("[130,80] in triangle") << path << QPointF(130, 80) << true; QTest::newRow("[110,80] in triangle") << path << QPointF(110, 80) << false; QTest::newRow("[150,100] in triangle") << path << QPointF(150, 100) << false; QTest::newRow("[120,110] in triangle") << path << QPointF(120, 110) << false; QRectF base_rect(0, 0, 20, 20); path = QPainterPath(); path.addEllipse(base_rect); // not strictly precise, but good enougth to verify fair precision. QPainterPath inside; inside.addEllipse(base_rect.adjusted(5, 5, -5, -5)); QPolygonF inside_poly = inside.toFillPolygon(); for (int i=0; i<inside_poly.size(); ++i) QTest::newRow("inside_ellipse") << path << inside_poly.at(i) << true; QPainterPath outside; outside.addEllipse(base_rect.adjusted(-5, -5, 5, 5)); QPolygonF outside_poly = outside.toFillPolygon(); for (int i=0; i<outside_poly.size(); ++i) QTest::newRow("outside_ellipse") << path << outside_poly.at(i) << false; path = QPainterPath(); base_rect = QRectF(50, 50, 200, 200); path.addEllipse(base_rect); path.setFillRule(Qt::WindingFill); QTest::newRow("topleft outside ellipse") << path << base_rect.topLeft() << false; QTest::newRow("topright outside ellipse") << path << base_rect.topRight() << false; QTest::newRow("bottomright outside ellipse") << path << base_rect.bottomRight() << false; QTest::newRow("bottomleft outside ellipse") << path << base_rect.bottomLeft() << false; // Test horizontal curve segment path = QPainterPath(); path.moveTo(100, 100); path.cubicTo(120, 100, 180, 100, 200, 100); path.lineTo(150, 200); path.closeSubpath(); QTest::newRow("horizontal cubic, out left") << path << QPointF(0, 100) << false; QTest::newRow("horizontal cubic, out right") << path << QPointF(300, 100) <<false; QTest::newRow("horizontal cubic, in mid") << path << QPointF(150, 100) << true; }
void Cqtpainter::Paint() { static const QPoint points[4] = { QPoint(10, 80), QPoint(20, 10), QPoint(80, 30), QPoint(90, 70) }; QRect rect(10, 20, 80, 60); QPainterPath path; path.moveTo(20, 80); path.lineTo(20, 30); path.cubicTo(80, 0, 50, 50, 80, 80); int startAngle = 20 * 16;//ÓëGDI+²»Í¬ int arcLength = 120 * 16; QFont myfont = m_painter->font(); myfont.setBold(m_fontOptions.blod); myfont.setItalic(m_fontOptions.italic); myfont.setUnderline(m_fontOptions.underline); myfont.setStrikeOut(m_fontOptions.strikeout); m_painter->setFont(myfont); //! [10] for (int x = 0; x < m_nWidth; x += 100) { for (int y = 0; y < m_nHeigth; y += 100) { m_painter->save(); m_painter->translate(x, y); //! [10] //! [11] if (m_transformed) { m_painter->translate(50, 50); m_painter->rotate(60.0); m_painter->scale(0.6, 0.9); m_painter->translate(-50, -50); } switch (m_shape) { case TypeLine: m_painter->drawLine(rect.bottomLeft(), rect.topRight()); break; case Points: m_painter->drawPoints(points, 4); break; case TypePolyline: m_painter->drawPolyline(points, 4); break; case TypePolygon: m_painter->drawPolygon(points, 4); break; case TypeRect: m_painter->drawRect(rect); break; case RoundedRect: m_painter->drawRoundedRect(rect, 25, 25, Qt::RelativeSize); break; case TypeEllipse: m_painter->drawEllipse(rect); break; case TypeArc: m_painter->drawArc(rect, startAngle, arcLength); break; case TypeChord: m_painter->drawChord(rect, startAngle, arcLength); break; case TypePie: m_painter->drawPie(rect, startAngle, arcLength); break; case Path: m_painter->drawPath(path); break; case Text: m_painter->drawText(rect, Qt::AlignCenter, QString("hello\nÄãºÃ\n")); break; case TypePixmap: m_painter->drawPixmap(10, 10, pixmap); } //! [12] //! [13] m_painter->restore(); } } m_painter->setRenderHint(QPainter::Antialiasing, false); QColor clr(200); if (m_painter->device()->devType() == QInternal::Widget) clr = static_cast<QWidget*>(m_painter->device())->palette().dark().color(); m_painter->setPen(clr); m_painter->setBrush(Qt::NoBrush); m_painter->drawRect(QRect(0, 0, m_nWidth - 1, m_nHeigth - 1)); }
void MathPlot::setupScatterStyleDemo(QCustomPlot *customPlot) { customPlot->legend->setVisible(true); customPlot->legend->setFont(QFont("Helvetica", 9)); customPlot->legend->setRowSpacing(-3); QVector<QCPScatterStyle::ScatterShape> shapes; shapes << QCPScatterStyle::ssCross; shapes << QCPScatterStyle::ssPlus; shapes << QCPScatterStyle::ssCircle; shapes << QCPScatterStyle::ssDisc; shapes << QCPScatterStyle::ssSquare; shapes << QCPScatterStyle::ssDiamond; shapes << QCPScatterStyle::ssStar; shapes << QCPScatterStyle::ssTriangle; shapes << QCPScatterStyle::ssTriangleInverted; shapes << QCPScatterStyle::ssCrossSquare; shapes << QCPScatterStyle::ssPlusSquare; shapes << QCPScatterStyle::ssCrossCircle; shapes << QCPScatterStyle::ssPlusCircle; shapes << QCPScatterStyle::ssPeace; shapes << QCPScatterStyle::ssCustom; QPen pen; // add graphs with different scatter styles: for (int i=0; i<shapes.size(); ++i) { customPlot->addGraph(); pen.setColor(QColor(sin(i*0.3)*100+100, sin(i*0.6+0.7)*100+100, sin(i*0.4+0.6)*100+100)); // generate data: QVector<double> x(10), y(10); for (int k=0; k<10; ++k) { x[k] = k/10.0 * 4*3.14 + 0.01; y[k] = 7*sin(x[k])/x[k] + (shapes.size()-i)*5; } customPlot->graph()->setData(x, y); customPlot->graph()->rescaleAxes(true); customPlot->graph()->setPen(pen); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) customPlot->graph()->setName(QCPScatterStyle::staticMetaObject.enumerator(QCPScatterStyle::staticMetaObject.indexOfEnumerator("ScatterShape")).valueToKey(shapes.at(i))); #endif customPlot->graph()->setLineStyle(QCPGraph::lsLine); // set scatter style: if (shapes.at(i) != QCPScatterStyle::ssCustom) { customPlot->graph()->setScatterStyle(QCPScatterStyle(shapes.at(i), 10)); } else { QPainterPath customScatterPath; for (int i=0; i<3; ++i) customScatterPath.cubicTo(qCos(2*M_PI*i/3.0)*9, qSin(2*M_PI*i/3.0)*9, qCos(2*M_PI*(i+0.9)/3.0)*9, qSin(2*M_PI*(i+0.9)/3.0)*9, 0, 0); customPlot->graph()->setScatterStyle(QCPScatterStyle(customScatterPath, QPen(), QColor(40, 70, 255, 50), 10)); } } // set blank axis lines: customPlot->rescaleAxes(); customPlot->xAxis->setTicks(false); customPlot->yAxis->setTicks(false); customPlot->xAxis->setTickLabels(false); customPlot->yAxis->setTickLabels(false); // make top right axes clones of bottom left axes: customPlot->axisRect()->setupFullAxesBox(); }
void ChordLine::editDrag(const EditData& ed) { int n = path.elementCount(); QPainterPath p; qreal sp = spatium(); _lengthX += ed.delta.x(); _lengthY += ed.delta.y(); // used to limit how grips can affect the slide, stops the user from being able to turn one kind of slide into another int slideBoundary = 5; if ((_chordLineType == ChordLineType::PLOP || _chordLineType == ChordLineType::FALL) && _lengthY < -slideBoundary) _lengthY = -slideBoundary; else if ((_chordLineType == ChordLineType::FALL || _chordLineType == ChordLineType::DOIT) && _lengthX < -slideBoundary) _lengthX = -slideBoundary; else if ((_chordLineType == ChordLineType::DOIT || _chordLineType == ChordLineType::SCOOP) && _lengthY > slideBoundary) _lengthY = slideBoundary; else if ((_chordLineType == ChordLineType::SCOOP || _chordLineType == ChordLineType::PLOP) && _lengthX > slideBoundary) _lengthX = slideBoundary; qreal dx = ed.delta.x() / sp; qreal dy = ed.delta.y() / sp; for (int i = 0; i < n; ++i) { const QPainterPath::Element& e = (_straight ? path.elementAt(1) : path.elementAt(i)); if (_straight) { if (i > 0) break; // check the gradient of the line const QPainterPath::Element& startPoint = path.elementAt(0); if ( (_chordLineType == ChordLineType::FALL && (e.x + dx < startPoint.x || e.y + dy < startPoint.y)) || (_chordLineType == ChordLineType::DOIT && (e.x + dx < startPoint.x || e.y + dy > startPoint.y)) || (_chordLineType == ChordLineType::SCOOP && (e.x + dx > startPoint.x || e.y + dy < startPoint.y)) || (_chordLineType == ChordLineType::PLOP && (e.x + dx > startPoint.x || e.y + dy > startPoint.y)) ) return; } qreal x = e.x; qreal y = e.y; if (ed.curGrip == Grip(i)) { x += dx; y += dy; } switch(e.type) { case QPainterPath::CurveToDataElement: break; case QPainterPath::MoveToElement: p.moveTo(x, y); break; case QPainterPath::LineToElement: p.lineTo(x, y); break; case QPainterPath::CurveToElement: { qreal x2 = path.elementAt(i+1).x; qreal y2 = path.elementAt(i+1).y; qreal x3 = path.elementAt(i+2).x; qreal y3 = path.elementAt(i+2).y; if (Grip(i + 1) == ed.curGrip) { x2 += dx; y2 += dy; } else if (Grip(i + 2) == ed.curGrip) { x3 += dx; y3 += dy; } p.cubicTo(x, y, x2, y2, x3, y3); i += 2; } break; } } path = p; modified = true; }
//! [1] Window::Window() { QPainterPath rectPath; rectPath.moveTo(20.0, 30.0); rectPath.lineTo(80.0, 30.0); rectPath.lineTo(80.0, 70.0); rectPath.lineTo(20.0, 70.0); rectPath.closeSubpath(); //! [1] //! [2] QPainterPath roundRectPath; roundRectPath.moveTo(80.0, 35.0); roundRectPath.arcTo(70.0, 30.0, 10.0, 10.0, 0.0, 90.0); roundRectPath.lineTo(25.0, 30.0); roundRectPath.arcTo(20.0, 30.0, 10.0, 10.0, 90.0, 90.0); roundRectPath.lineTo(20.0, 65.0); roundRectPath.arcTo(20.0, 60.0, 10.0, 10.0, 180.0, 90.0); roundRectPath.lineTo(75.0, 70.0); roundRectPath.arcTo(70.0, 60.0, 10.0, 10.0, 270.0, 90.0); roundRectPath.closeSubpath(); //! [2] //! [3] QPainterPath ellipsePath; ellipsePath.moveTo(80.0, 50.0); ellipsePath.arcTo(20.0, 30.0, 60.0, 40.0, 0.0, 360.0); //! [3] //! [4] QPainterPath piePath; piePath.moveTo(50.0, 50.0); piePath.arcTo(20.0, 30.0, 60.0, 40.0, 60.0, 240.0); piePath.closeSubpath(); //! [4] //! [5] QPainterPath polygonPath; polygonPath.moveTo(10.0, 80.0); polygonPath.lineTo(20.0, 10.0); polygonPath.lineTo(80.0, 30.0); polygonPath.lineTo(90.0, 70.0); polygonPath.closeSubpath(); //! [5] //! [6] QPainterPath groupPath; groupPath.moveTo(60.0, 40.0); groupPath.arcTo(20.0, 20.0, 40.0, 40.0, 0.0, 360.0); groupPath.moveTo(40.0, 40.0); groupPath.lineTo(40.0, 80.0); groupPath.lineTo(80.0, 80.0); groupPath.lineTo(80.0, 40.0); groupPath.closeSubpath(); //! [6] //! [7] QPainterPath textPath; QFont timesFont("Times", 50); timesFont.setStyleStrategy(QFont::ForceOutline); textPath.addText(10, 70, timesFont, tr("Qt")); //! [7] //! [8] QPainterPath bezierPath; bezierPath.moveTo(20, 30); bezierPath.cubicTo(80, 0, 50, 50, 80, 80); //! [8] //! [9] QPainterPath starPath; starPath.moveTo(90, 50); for (int i = 1; i < 5; ++i) { starPath.lineTo(50 + 40 * cos(0.8 * i * Pi), 50 + 40 * sin(0.8 * i * Pi)); } starPath.closeSubpath(); //! [9] //! [10] #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) renderAreas.push_back(new RenderArea(rectPath)); renderAreas.push_back(new RenderArea(roundRectPath)); renderAreas.push_back(new RenderArea(ellipsePath)); renderAreas.push_back(new RenderArea(piePath)); renderAreas.push_back(new RenderArea(polygonPath)); renderAreas.push_back(new RenderArea(groupPath)); #endif renderAreas.push_back(new RenderArea(textPath)); renderAreas.push_back(new RenderArea(bezierPath)); renderAreas.push_back(new RenderArea(starPath)); //! [10] //! [11] fillRuleComboBox = new QComboBox; fillRuleComboBox->addItem(tr("Odd Even"), Qt::OddEvenFill); fillRuleComboBox->addItem(tr("Winding"), Qt::WindingFill); fillRuleLabel = new QLabel(tr("Fill &Rule:")); fillRuleLabel->setBuddy(fillRuleComboBox); //! [11] //! [12] fillColor1ComboBox = new QComboBox; populateWithColors(fillColor1ComboBox); fillColor1ComboBox->setCurrentIndex( fillColor1ComboBox->findText("mediumslateblue")); fillColor2ComboBox = new QComboBox; populateWithColors(fillColor2ComboBox); fillColor2ComboBox->setCurrentIndex( fillColor2ComboBox->findText("cornsilk")); fillGradientLabel = new QLabel(tr("&Fill Gradient:")); fillGradientLabel->setBuddy(fillColor1ComboBox); fillToLabel = new QLabel(tr("to")); fillToLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); penWidthSpinBox = new QSpinBox; penWidthSpinBox->setRange(0, 20); penWidthLabel = new QLabel(tr("&Pen Width:")); penWidthLabel->setBuddy(penWidthSpinBox); penColorComboBox = new QComboBox; populateWithColors(penColorComboBox); penColorComboBox->setCurrentIndex( penColorComboBox->findText("darkslateblue")); penColorLabel = new QLabel(tr("Pen &Color:")); penColorLabel->setBuddy(penColorComboBox); rotationAngleSpinBox = new QSpinBox; rotationAngleSpinBox->setRange(0, 359); rotationAngleSpinBox->setWrapping(true); rotationAngleSpinBox->setSuffix("\xB0"); rotationAngleLabel = new QLabel(tr("&Rotation Angle:")); rotationAngleLabel->setBuddy(rotationAngleSpinBox); //! [12] //! [16] connect(fillRuleComboBox, SIGNAL(activated(int)), this, SLOT(fillRuleChanged())); connect(fillColor1ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); connect(fillColor2ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); connect(penColorComboBox, SIGNAL(activated(int)), this, SLOT(penColorChanged())); for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) { connect(penWidthSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setPenWidth(int))); connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setRotationAngle(int))); } //! [16] //! [17] QGridLayout *topLayout = new QGridLayout; #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) topLayout->setSizeConstraint(QLayout::SetNoConstraint); #endif int i=0; for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++, i++) topLayout->addWidget(*it, i / 3, i % 3); QGridLayout *mainLayout = new QGridLayout; #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) mainLayout->setSizeConstraint(QLayout::SetNoConstraint); #endif mainLayout->addLayout(topLayout, 0, 0, 1, 4); mainLayout->addWidget(fillRuleLabel, 1, 0); mainLayout->addWidget(fillRuleComboBox, 1, 1, 1, 3); mainLayout->addWidget(fillGradientLabel, 2, 0); mainLayout->addWidget(fillColor1ComboBox, 2, 1); mainLayout->addWidget(fillToLabel, 2, 2); mainLayout->addWidget(fillColor2ComboBox, 2, 3); mainLayout->addWidget(penWidthLabel, 3, 0); mainLayout->addWidget(penWidthSpinBox, 3, 1, 1, 3); mainLayout->addWidget(penColorLabel, 4, 0); mainLayout->addWidget(penColorComboBox, 4, 1, 1, 3); #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) mainLayout->addWidget(rotationAngleLabel, 5, 0); mainLayout->addWidget(rotationAngleSpinBox, 5, 1, 1, 3); #endif setLayout(mainLayout); //! [17] //! [18] fillRuleChanged(); fillGradientChanged(); penColorChanged(); penWidthSpinBox->setValue(2); setWindowTitle(tr("Painter Paths")); }
void XFormView::drawVectorType(QPainter *painter) { QPainterPath path; painter->translate(ctrlPoints.at(0) - QPointF(250,250)); painter->scale(0.77, 0.77); painter->translate(98.9154 + 30 , -217.691 - 20); QRect br(-55, 275, 500, 590); QPoint center = br.center(); painter->translate(center.x(), center.y()); painter->rotate(m_rotation); painter->scale(m_scale, m_scale); painter->shear(0, m_shear); painter->translate(-center.x(), -center.y()); painter->setPen(Qt::NoPen); path.moveTo(120, 470); path.lineTo(60+245, 470); path.lineTo(60+245, 470+350); path.lineTo(60, 470+350); path.lineTo(60, 470+80); painter->setBrush(Qt::white); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor( 193, 193, 191, 255)); path.moveTo(329.336, 727.552); path.cubicTo(QPointF(315.224, 726.328), QPointF(304.136, 715.816), QPointF(303.128, 694.936)); path.cubicTo(QPointF(306.368, 639.496), QPointF(309.608, 582.112), QPointF(271.232, 545.104)); path.cubicTo(QPointF(265.256, 499.024), QPointF(244.016, 482.104), QPointF(234.008, 452.512)); path.lineTo(218.24, 441.208); path.lineTo(237.104, 411.688); path.lineTo(245.168, 411.904); path.lineTo(323.936, 571.168); path.lineTo(340.424, 651.448); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(136.232, 439.696); path.cubicTo(QPointF(133.856, 455.248), QPointF(132.56, 470.512), QPointF(134.792, 485.272)); path.cubicTo(QPointF(118.376, 507.592), QPointF(105.92, 530.128), QPointF(104.48, 553.312)); path.cubicTo(QPointF(92.024, 586.504), QPointF(62.432, 614.584), QPointF(67.544, 680.104)); path.cubicTo(QPointF(84.176, 697.456), QPointF(107.432, 713.584), QPointF(127.376, 730.36)); path.cubicTo(QPointF(152.432, 751.312), QPointF(137.528, 778.96), QPointF(102.248, 772.408)); path.cubicTo(QPointF(94.4, 763.768), QPointF(76.616, 709.624), QPointF(42.92, 676.288)); path.lineTo(49.544, 632.584); path.lineTo(81.368, 547.408); path.lineTo(120.968, 484.048); path.lineTo(125.36, 456.688); path.lineTo(119.816, 386.776); path.lineTo(124.424, 361.216); path.lineTo(136.232, 439.696); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(115.64, 341.416); path.cubicTo(QPointF(116.576, 336.376), QPointF(117.8, 331.624), QPointF(119.312, 327.16)); path.lineTo(121.688, 342.784); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(120.968, 500.464); path.cubicTo(QPointF(108.368, 523.792), QPointF(103.976, 546.256), QPointF(132.92, 550.216)); path.cubicTo(QPointF(117.008, 553.888), QPointF(97.208, 568.648), QPointF(77.192, 593.488)); path.lineTo(77.624, 543.016); path.lineTo(101.456, 503.272); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(-33.256, 818.488); path.cubicTo(QPointF(10.52, 838.144), QPointF(41.408, 837.064), QPointF(69.272, 850.96)); path.cubicTo(QPointF(91.304, 862.552), QPointF(113.552, 861.184), QPointF(126.944, 847.144)); path.cubicTo(QPointF(138.32, 832.456), QPointF(146.744, 831.736), QPointF(163.52, 830.224)); path.cubicTo(QPointF(190.952, 828.568), QPointF(217.736, 828.28), QPointF(241.928, 830.8)); path.lineTo(269.576, 833.032); path.cubicTo(QPointF(269.072, 864.064), QPointF(328.04, 867.88), QPointF(345.392, 844.336)); path.cubicTo(QPointF(366.344, 819.424), QPointF(395.144, 808.264), QPointF(419.84, 790.192)); path.lineTo(289.304, 725.536); path.cubicTo(QPointF(255.824, 806.464), QPointF(131.048, 827.632), QPointF(113.768, 763.264)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(286.424, 711.568); path.cubicTo(QPointF(273.824, 711.496), QPointF(260.936, 715.6), QPointF(261.944, 732.16)); path.lineTo(266.192, 776.44); path.lineTo(304.424, 756.64); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(0, 0, 0, 255)); path.moveTo(-37.36, 821.224); path.cubicTo(QPointF(7.136, 840.88), QPointF(38.6, 839.728), QPointF(66.968, 853.696)); path.cubicTo(QPointF(89.36, 865.216), QPointF(111.968, 863.92), QPointF(125.648, 849.808)); path.cubicTo(QPointF(137.24, 835.192), QPointF(145.808, 834.472), QPointF(162.872, 832.96)); path.cubicTo(QPointF(190.736, 831.232), QPointF(218.024, 831.016), QPointF(242.648, 833.464)); path.lineTo(270.728, 835.768); path.cubicTo(QPointF(270.224, 866.8), QPointF(330.272, 870.544), QPointF(347.912, 847)); path.cubicTo(QPointF(369.224, 822.088), QPointF(398.528, 811), QPointF(423.656, 792.856)); path.lineTo(290.816, 728.272); path.cubicTo(QPointF(256.76, 809.128), QPointF(129.824, 830.296), QPointF(112.256, 766)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(183, 114, 0, 255)); path.moveTo(382.328, 691.984); path.cubicTo(QPointF(403.64, 698.968), QPointF(389.888, 720.28), QPointF(400.76, 732.52)); path.cubicTo(QPointF(405.44, 742.888), QPointF(415.304, 752.032), QPointF(431.792, 760.528)); path.cubicTo(QPointF(459.368, 774.424), QPointF(426.248, 799.336), QPointF(392.768, 812.08)); path.cubicTo(QPointF(351.944, 825.616), QPointF(344.024, 862.912), QPointF(299.312, 851.896)); path.cubicTo(QPointF(283.112, 846.496), QPointF(278.36, 831.808), QPointF(278.864, 809.128)); path.cubicTo(QPointF(284.264, 762.76), QPointF(277.784, 730.432), QPointF(278.792, 698.824)); path.cubicTo(QPointF(278.72, 686.152), QPointF(283.544, 684.64), QPointF(307.232, 687.952)); path.cubicTo(QPointF(310.04, 726.328), QPointF(352.376, 727.336), QPointF(382.328, 691.984)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(242, 183, 0, 255)); path.moveTo(339.632, 826.624); path.cubicTo(QPointF(371.6, 814.312), QPointF(403.856, 798.112), QPointF(429.848, 782.128)); path.cubicTo(QPointF(437.84, 777.448), QPointF(438.92, 765.928), QPointF(427.688, 762.328)); path.cubicTo(QPointF(403.352, 748.504), QPointF(390.104, 731.224), QPointF(392.912, 708.76)); path.cubicTo(QPointF(393.344, 700.912), QPointF(383.696, 692.56), QPointF(381.104, 700.048)); path.cubicTo(QPointF(359.864, 771.472), QPointF(291.32, 767.656), QPointF(300.752, 696.952)); path.cubicTo(QPointF(301.256, 694.864), QPointF(301.76, 692.776), QPointF(302.264, 690.76)); path.cubicTo(QPointF(289.952, 688.24), QPointF(285.2, 690.976), QPointF(285.776, 700.408)); path.lineTo(295.28, 806.608); path.cubicTo(QPointF(297.656, 830.8), QPointF(317.312, 836.128), QPointF(339.632, 826.624)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(0, 0, 0, 255)); path.moveTo(354.464, 537.544); path.cubicTo(QPointF(379.16, 569.8), QPointF(404.432, 651.088), QPointF(384.416, 691.552)); path.cubicTo(QPointF(360.944, 737.776), QPointF(307.808, 743.248), QPointF(305.504, 695.8)); path.cubicTo(QPointF(308.816, 639.64), QPointF(311.984, 581.536), QPointF(273.68, 544.096)); path.cubicTo(QPointF(267.704, 497.368), QPointF(246.392, 480.232), QPointF(236.384, 450.28)); path.lineTo(203.12, 426.088); path.lineTo(133.568, 435.088); path.cubicTo(QPointF(130.76, 452.152), QPointF(129.104, 468.784), QPointF(131.552, 484.912)); path.cubicTo(QPointF(115.064, 507.376), QPointF(102.608, 530.056), QPointF(101.168, 553.312)); path.cubicTo(QPointF(88.712, 586.648), QPointF(59.12, 614.944), QPointF(64.232, 680.752)); path.cubicTo(QPointF(80.864, 698.248), QPointF(104.12, 714.448), QPointF(124.064, 731.296)); path.cubicTo(QPointF(149.12, 752.392), QPointF(135.512, 776.296), QPointF(100.232, 769.672)); path.cubicTo(QPointF(78.848, 746.056), QPointF(56.744, 722.872), QPointF(35.288, 699.328)); path.cubicTo(QPointF(12.392, 683.056), QPointF(3.896, 662.176), QPointF(27.368, 630.496)); path.cubicTo(QPointF(43.424, 609.04), QPointF(47.96, 562.456), QPointF(62, 543.664)); path.cubicTo(QPointF(74.312, 525.16), QPointF(92.24, 508.6), QPointF(105.272, 490.096)); path.cubicTo(QPointF(112.184, 477.928), QPointF(114.344, 468.568), QPointF(113.264, 454.456)); path.lineTo(110.312, 369.136); path.cubicTo(QPointF(108.368, 307.216), QPointF(142.424, 274.24), QPointF(189.8, 275.248)); path.cubicTo(QPointF(243.512, 275.752), QPointF(287.576, 312.472), QPointF(288.152, 378.28)); path.cubicTo(QPointF(292.688, 410.32), QPointF(283.256, 428.68), QPointF(308.672, 474.472)); path.cubicTo(QPointF(334.52, 522.712), QPointF(338.552, 520.12), QPointF(354.464, 537.544)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(261.296, 503.632); path.lineTo(263.528, 512.2); path.cubicTo(QPointF(257.696, 501.688), QPointF(250.712, 483.616), QPointF(241.928, 475.696)); path.cubicTo(QPointF(239.264, 473.536), QPointF(235.808, 473.608), QPointF(233.72, 475.624)); path.cubicTo(QPointF(222.056, 486.928), QPointF(193.112, 510.112), QPointF(169.928, 507.088)); path.cubicTo(QPointF(152.072, 505.288), QPointF(134.648, 493.264), QPointF(130.832, 480.232)); path.cubicTo(QPointF(128.816, 470.872), QPointF(129.752, 463.168), QPointF(130.976, 455.32)); path.lineTo(240.704, 453.52); path.cubicTo(QPointF(238.472, 463.168), QPointF(253.088, 487), QPointF(261.296, 503.632)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(143.144, 363.232); path.cubicTo(QPointF(154.088, 363.232), QPointF(163.88, 376.84), QPointF(163.808, 395.632)); path.cubicTo(QPointF(163.736, 408.232), QPointF(155.528, 411.472), QPointF(149.336, 417.016)); path.cubicTo(QPointF(146.6, 419.536), QPointF(145.952, 433.144), QPointF(142.568, 433.144)); path.cubicTo(QPointF(131.696, 433.144), QPointF(123.488, 413.776), QPointF(123.488, 395.632)); path.cubicTo(QPointF(123.488, 377.56), QPointF(132.272, 363.232), QPointF(143.144, 363.232)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(255, 255, 255, 255)); path.moveTo(144.368, 375.04); path.cubicTo(QPointF(154.088, 375.04), QPointF(160.856, 379.936), QPointF(161.648, 391.312)); path.cubicTo(QPointF(162.224, 399.16), QPointF(160.136, 411.76), QPointF(154.664, 414.424)); path.cubicTo(QPointF(152.144, 415.648), QPointF(143.432, 426.664), QPointF(140.408, 426.52)); path.cubicTo(QPointF(128.096, 425.944), QPointF(125, 402.112), QPointF(125.936, 390.736)); path.cubicTo(QPointF(126.8, 379.36), QPointF(134.72, 375.04), QPointF(144.368, 375.04)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(0, 0, 0, 255)); path.moveTo(141.848, 382.672); path.cubicTo(QPointF(148.544, 382.096), QPointF(154.736, 389.728), QPointF(155.6, 399.664)); path.cubicTo(QPointF(156.464, 409.6), QPointF(151.64, 418.24), QPointF(144.944, 418.816)); path.cubicTo(QPointF(138.248, 419.392), QPointF(132.056, 411.76), QPointF(131.192, 401.752)); path.cubicTo(QPointF(130.328, 391.816), QPointF(135.152, 383.248), QPointF(141.848, 382.672)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(151.064, 397.288); path.cubicTo(QPointF(151.424, 399.088), QPointF(149.408, 400.024), QPointF(148.832, 398.224)); path.cubicTo(QPointF(148.256, 395.992), QPointF(146.888, 393.328), QPointF(145.088, 391.168)); path.cubicTo(QPointF(143.936, 389.872), QPointF(145.088, 388.432), QPointF(146.528, 389.44)); path.cubicTo(QPointF(149.048, 391.528), QPointF(150.488, 394.12), QPointF(151.064, 397.288)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(216.944, 360.712); path.cubicTo(QPointF(232.712, 360.712), QPointF(245.6, 377.416), QPointF(245.6, 397.792)); path.cubicTo(QPointF(245.6, 418.24), QPointF(232.712, 434.872), QPointF(216.944, 434.872)); path.cubicTo(QPointF(201.176, 434.872), QPointF(188.432, 418.24), QPointF(188.432, 397.792)); path.cubicTo(QPointF(188.432, 377.416), QPointF(201.176, 360.712), QPointF(216.944, 360.712)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(255, 255, 255, 255)); path.moveTo(224.792, 374.968); path.cubicTo(QPointF(235.664, 378.856), QPointF(241.928, 387.424), QPointF(242.72, 396.568)); path.cubicTo(QPointF(243.656, 407.08), QPointF(239.408, 418.96), QPointF(230.264, 425.944)); path.cubicTo(QPointF(227.672, 427.888), QPointF(197.72, 416.08), QPointF(195.992, 411.616)); path.cubicTo(QPointF(193.4, 405.208), QPointF(191.816, 392.896), QPointF(193.76, 385.624)); path.cubicTo(QPointF(194.552, 382.744), QPointF(197.216, 378.568), QPointF(201.176, 376.336)); path.cubicTo(QPointF(207.44, 372.808), QPointF(216.656, 372.088), QPointF(224.792, 374.968)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(0, 0, 0, 255)); path.moveTo(216.872, 380.944); path.cubicTo(QPointF(225.584, 380.944), QPointF(232.712, 389.296), QPointF(232.712, 399.448)); path.cubicTo(QPointF(232.712, 409.672), QPointF(225.584, 418.024), QPointF(216.872, 418.024)); path.cubicTo(QPointF(208.16, 418.024), QPointF(201.032, 409.672), QPointF(201.032, 399.448)); path.cubicTo(QPointF(201.032, 389.296), QPointF(208.16, 380.944), QPointF(216.872, 380.944)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(227.096, 392.392); path.cubicTo(QPointF(228.104, 394.048), QPointF(226.448, 395.776), QPointF(225.224, 394.12)); path.cubicTo(QPointF(223.784, 392.104), QPointF(221.408, 389.944), QPointF(218.888, 388.432)); path.cubicTo(QPointF(217.232, 387.568), QPointF(217.808, 385.624), QPointF(219.68, 386.2)); path.cubicTo(QPointF(222.92, 387.28), QPointF(225.368, 389.368), QPointF(227.096, 392.392)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(183, 114, 0, 255)); path.moveTo(164.96, 404.488); path.cubicTo(QPointF(172.376, 402.328), QPointF(184.112, 403.048), QPointF(192.248, 404.632)); path.cubicTo(QPointF(200.384, 406.792), QPointF(222.056, 418.24), QPointF(245.024, 430.696)); path.cubicTo(QPointF(247.976, 432.208), QPointF(248.84, 437.104), QPointF(245.024, 438.688)); path.cubicTo(QPointF(239.12, 439.12), QPointF(249.272, 453.664), QPointF(238.904, 458.848)); path.cubicTo(QPointF(223.352, 462.88), QPointF(198.44, 485.992), QPointF(186.128, 487.864)); path.cubicTo(QPointF(179.288, 489.376), QPointF(172.232, 489.592), QPointF(164.6, 487.864)); path.cubicTo(QPointF(140.552, 482.968), QPointF(134.216, 455.608), QPointF(122.912, 450.064)); path.cubicTo(QPointF(119.816, 446.824), QPointF(121.4, 441.208), QPointF(122.408, 440.056)); path.cubicTo(QPointF(123.632, 434.224), QPointF(149.696, 406.216), QPointF(164.96, 404.488)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(242, 183, 0, 255)); path.moveTo(185.408, 405.856); path.cubicTo(QPointF(198.44, 407.296), QPointF(226.088, 423.928), QPointF(239.408, 430.624)); path.cubicTo(QPointF(242.72, 432.424), QPointF(242.504, 437.824), QPointF(239.552, 438.688)); path.cubicTo(QPointF(236.384, 440.488), QPointF(235.448, 438.256), QPointF(232.928, 437.896)); path.cubicTo(QPointF(228.896, 435.736), QPointF(222.272, 440.92), QPointF(217.016, 444.88)); path.cubicTo(QPointF(186.704, 467.776), QPointF(180.656, 465.256), QPointF(156.176, 462.664)); path.cubicTo(QPointF(147.68, 460.576), QPointF(142.136, 457.984), QPointF(139.688, 455.968)); path.cubicTo(QPointF(141.488, 445.888), QPointF(160.496, 407.656), QPointF(166.76, 406.792)); path.cubicTo(QPointF(168.344, 404.704), QPointF(179.936, 404.632), QPointF(185.408, 405.856)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(183, 114, 0, 255)); path.moveTo(190.664, 412.048); path.lineTo(193.76, 413.416); path.cubicTo(QPointF(196.064, 414.712), QPointF(193.256, 418.168), QPointF(190.736, 417.088)); path.lineTo(186.2, 415.504); path.cubicTo(QPointF(183.536, 413.272), QPointF(186.704, 410.104), QPointF(190.664, 412.048)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(268.568, 452.368); path.cubicTo(QPointF(273.032, 454.384), QPointF(279.224, 457.192), QPointF(282.536, 460.144)); path.cubicTo(QPointF(285.488, 464.104), QPointF(286.784, 468.064), QPointF(286.424, 472.024)); path.cubicTo(QPointF(285.776, 474.544), QPointF(284.12, 476.344), QPointF(281.24, 477.424)); path.cubicTo(QPointF(277.856, 478.216), QPointF(273.68, 477.424), QPointF(271.376, 474.112)); path.cubicTo(QPointF(269.864, 471.448), QPointF(265.256, 462.16), QPointF(263.96, 460.576)); path.cubicTo(QPointF(262.232, 457.12), QPointF(261.944, 454.456), QPointF(262.88, 452.368)); path.cubicTo(QPointF(264.032, 451.288), QPointF(266.048, 451), QPointF(268.568, 452.368)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(255, 255, 255, 255)); path.moveTo(273.752, 461.584); path.cubicTo(QPointF(275.48, 462.376), QPointF(277.928, 463.456), QPointF(279.224, 464.68)); path.cubicTo(QPointF(280.376, 466.264), QPointF(280.88, 467.776), QPointF(280.736, 469.36)); path.cubicTo(QPointF(280.52, 470.296), QPointF(279.8, 471.016), QPointF(278.72, 471.448)); path.cubicTo(QPointF(277.352, 471.808), QPointF(275.768, 471.448), QPointF(274.832, 470.152)); path.cubicTo(QPointF(274.256, 469.144), QPointF(272.456, 465.472), QPointF(271.952, 464.824)); path.cubicTo(QPointF(271.232, 463.456), QPointF(271.088, 462.448), QPointF(271.448, 461.584)); path.cubicTo(QPointF(271.952, 461.152), QPointF(272.744, 461.08), QPointF(273.752, 461.584)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(238.616, 358.552); path.cubicTo(QPointF(239.048, 359.2), QPointF(238.976, 359.776), QPointF(238.4, 360.28)); path.cubicTo(QPointF(237.896, 360.784), QPointF(237.176, 360.712), QPointF(236.24, 360.208)); path.lineTo(231.632, 356.248); path.cubicTo(QPointF(231.056, 355.744), QPointF(230.912, 354.952), QPointF(231.272, 354.088)); path.cubicTo(QPointF(232.28, 353.44), QPointF(233.144, 353.44), QPointF(233.936, 354.088)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(235.592, 305.992); path.cubicTo(QPointF(239.624, 308.224), QPointF(240.848, 313.912), QPointF(238.184, 318.592)); path.cubicTo(QPointF(235.592, 323.2), QPointF(230.12, 325.144), QPointF(226.016, 322.84)); path.cubicTo(QPointF(221.984, 320.536), QPointF(220.76, 314.92), QPointF(223.424, 310.24)); path.cubicTo(QPointF(226.016, 305.56), QPointF(231.488, 303.688), QPointF(235.592, 305.992)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(374.912, 680.536); path.cubicTo(QPointF(378.296, 683.128), QPointF(373.256, 687.376), QPointF(371.024, 686.296)); path.cubicTo(QPointF(369.152, 685.648), QPointF(367.784, 683.488), QPointF(366.92, 682.408)); path.cubicTo(QPointF(366.128, 681.184), QPointF(366.2, 679.168), QPointF(366.92, 678.448)); path.cubicTo(QPointF(367.712, 677.44), QPointF(369.728, 677.656), QPointF(371.024, 678.52)); path.cubicTo(QPointF(372.32, 679.168), QPointF(373.616, 679.888), QPointF(374.912, 680.536)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(297.44, 551.512); path.cubicTo(QPointF(338.984, 572.896), QPointF(350, 611.56), QPointF(332.072, 664.192)); path.cubicTo(QPointF(330.992, 666.64), QPointF(334.16, 668.368), QPointF(335.24, 666.064)); path.cubicTo(QPointF(354.824, 610.336), QPointF(341.432, 571.312), QPointF(299.024, 548.56)); path.cubicTo(QPointF(296.864, 547.552), QPointF(295.28, 550.432), QPointF(297.44, 551.512)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(72.008, 569.512); path.cubicTo(QPointF(38.312, 627.256), QPointF(38.096, 662.68), QPointF(62.504, 681.328)); path.cubicTo(QPointF(63.728, 682.264), QPointF(64.448, 680.032), QPointF(63.296, 679.168)); path.cubicTo(QPointF(36.296, 655.48), QPointF(48.896, 615.52), QPointF(74.168, 570.88)); path.cubicTo(QPointF(74.888, 569.584), QPointF(72.512, 568.432), QPointF(72.008, 569.512)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(289.376, 586.864); path.cubicTo(QPointF(289.232, 589.168), QPointF(288.368, 589.528), QPointF(286.424, 587.368)); path.cubicTo(QPointF(279.8, 575.848), QPointF(235.088, 551.44), QPointF(213.344, 548.704)); path.cubicTo(QPointF(209.24, 547.264), QPointF(209.456, 545.392), QPointF(213.488, 544.816)); path.cubicTo(QPointF(229.184, 544.816), QPointF(241.28, 537.904), QPointF(254.96, 537.904)); path.cubicTo(QPointF(258.704, 538.048), QPointF(262.304, 539.488), QPointF(264.392, 541.648)); path.cubicTo(QPointF(269.504, 544.96), QPointF(288.08, 570.592), QPointF(289.376, 586.864)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(180.152, 546.832); path.cubicTo(QPointF(180.872, 550.792), QPointF(163.808, 545.68), QPointF(164.744, 556.696)); path.cubicTo(QPointF(165.032, 559.72), QPointF(160.496, 561.376), QPointF(160.64, 556.696)); path.cubicTo(QPointF(160.64, 548.272), QPointF(161.072, 548.416), QPointF(152.72, 546.832)); path.cubicTo(QPointF(151.208, 546.76), QPointF(151.352, 544.528), QPointF(152.72, 544.816)); path.lineTo(152.72, 544.816); path.cubicTo(QPointF(158.696, 546.472), QPointF(166.76, 542.872), QPointF(166.4, 538.84)); path.cubicTo(QPointF(166.256, 537.472), QPointF(168.56, 537.688), QPointF(168.488, 538.84)); path.cubicTo(QPointF(167.984, 545.248), QPointF(181.664, 542.152), QPointF(180.152, 546.832)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(193, 193, 191, 255)); path.moveTo(151.568, 705.376); path.cubicTo(QPointF(151.64, 708.328), QPointF(148.76, 707.68), QPointF(148.544, 705.592)); path.cubicTo(QPointF(140.192, 680.536), QPointF(143.72, 618.832), QPointF(151.856, 598.96)); path.cubicTo(QPointF(152.432, 596.08), QPointF(156.248, 596.944), QPointF(155.744, 598.96)); path.cubicTo(QPointF(147.104, 635.464), QPointF(147.248, 673.048), QPointF(151.568, 705.376)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(183, 114, 0, 255)); path.moveTo(51.704, 684.424); path.cubicTo(QPointF(75.68, 707.824), QPointF(91.376, 743.248), QPointF(114.632, 775.288)); path.cubicTo(QPointF(148.472, 816.04), QPointF(121.472, 858.304), QPointF(66.464, 845.56)); path.cubicTo(QPointF(38.888, 835.192), QPointF(-0.784, 836.344), QPointF(-32.68, 825.832)); path.cubicTo(QPointF(-55.072, 820.36), QPointF(-55.864, 809.272), QPointF(-44.416, 787.6)); path.cubicTo(QPointF(-40.384, 773.776), QPointF(-40.024, 751.312), QPointF(-43.768, 732.592)); path.cubicTo(QPointF(-45.784, 718.408), QPointF(-39.232, 710.488), QPointF(-24.112, 708.832)); path.lineTo(-24.112, 708.832); path.cubicTo(QPointF(-11.296, 708.688), QPointF(6.56, 713.872), QPointF(16.28, 686.44)); path.cubicTo(QPointF(23.552, 673.336), QPointF(40.976, 672.976), QPointF(51.704, 684.424)); path.closeSubpath(); painter->drawPath(path); path = QPainterPath(); painter->setBrush(QColor(242, 183, 0, 255)); path.moveTo(24.632, 699.04); path.cubicTo(QPointF(23.84, 680.968), QPointF(39.32, 677.296), QPointF(49.688, 688.312)); path.cubicTo(QPointF(68.192, 710.992), QPointF(85.112, 736.048), QPointF(100.376, 764.992)); path.cubicTo(QPointF(124.712, 804.16), QPointF(104.624, 842.68), QPointF(67.904, 828.064)); path.cubicTo(QPointF(49.688, 817.84), QPointF(6.128, 813.304), QPointF(-17.344, 809.128)); path.cubicTo(QPointF(-33.04, 807.832), QPointF(-35.128, 797.608), QPointF(-29.152, 791.848)); path.cubicTo(QPointF(-20.944, 782.416), QPointF(-20.08, 759.808), QPointF(-27.856, 740.512)); path.cubicTo(QPointF(-35.56, 728.56), QPointF(-21.088, 715.384), QPointF(-9.712, 720.856)); path.cubicTo(QPointF(0.8, 727.048), QPointF(25.64, 713.08), QPointF(24.632, 699.04)); path.closeSubpath(); painter->drawPath(path); painter->setPen(QPen(QColor(255, 0, 0, alpha), 0.25, Qt::SolidLine, Qt::FlatCap, Qt::BevelJoin)); painter->setBrush(Qt::NoBrush); painter->drawRect(br.adjusted(-1, -1, 1, 1)); }
void render_qt_text(QPainter *painter, int w, int h, const QColor &color) { QPainterPath path; path.moveTo(-0.083695, 0.283849); path.cubicTo(-0.049581, 0.349613, -0.012720, 0.397969, 0.026886, 0.428917); path.cubicTo(0.066493, 0.459865, 0.111593, 0.477595, 0.162186, 0.482108); path.lineTo(0.162186, 0.500000); path.cubicTo(0.115929, 0.498066, 0.066565, 0.487669, 0.014094, 0.468810); path.cubicTo(-0.038378, 0.449952, -0.088103, 0.423839, -0.135082, 0.390474); path.cubicTo(-0.182061, 0.357108, -0.222608, 0.321567, -0.256722, 0.283849); path.cubicTo(-0.304712, 0.262250, -0.342874, 0.239362, -0.371206, 0.215184); path.cubicTo(-0.411969, 0.179078, -0.443625, 0.134671, -0.466175, 0.081963); path.cubicTo(-0.488725, 0.029255, -0.500000, -0.033043, -0.500000, -0.104932); path.cubicTo(-0.500000, -0.218407, -0.467042, -0.312621, -0.401127, -0.387573); path.cubicTo(-0.335212, -0.462524, -0.255421, -0.500000, -0.161752, -0.500000); path.cubicTo(-0.072998, -0.500000, 0.003903, -0.462444, 0.068951, -0.387331); path.cubicTo(0.133998, -0.312218, 0.166522, -0.217440, 0.166522, -0.102998); path.cubicTo(0.166522, -0.010155, 0.143394, 0.071325, 0.097138, 0.141441); path.cubicTo(0.050882, 0.211557, -0.009396, 0.259026, -0.083695, 0.283849); path.moveTo(-0.167823, -0.456963); path.cubicTo(-0.228823, -0.456963, -0.277826, -0.432624, -0.314831, -0.383946); path.cubicTo(-0.361665, -0.323340, -0.385082, -0.230335, -0.385082, -0.104932); path.cubicTo(-0.385082, 0.017569, -0.361376, 0.112025, -0.313964, 0.178433); path.cubicTo(-0.277248, 0.229368, -0.228534, 0.254836, -0.167823, 0.254836); path.cubicTo(-0.105088, 0.254836, -0.054496, 0.229368, -0.016045, 0.178433); path.cubicTo(0.029055, 0.117827, 0.051605, 0.028691, 0.051605, -0.088975); path.cubicTo(0.051605, -0.179562, 0.039318, -0.255803, 0.014744, -0.317698); path.cubicTo(-0.004337, -0.365409, -0.029705, -0.400548, -0.061362, -0.423114); path.cubicTo(-0.093018, -0.445680, -0.128505, -0.456963, -0.167823, -0.456963); path.moveTo(0.379011, -0.404739); path.lineTo(0.379011, -0.236460); path.lineTo(0.486123, -0.236460); path.lineTo(0.486123, -0.197292); path.lineTo(0.379011, -0.197292); path.lineTo(0.379011, 0.134913); path.cubicTo(0.379011, 0.168117, 0.383276, 0.190442, 0.391804, 0.201886); path.cubicTo(0.400332, 0.213330, 0.411246, 0.219052, 0.424545, 0.219052); path.cubicTo(0.435531, 0.219052, 0.446227, 0.215264, 0.456635, 0.207689); path.cubicTo(0.467042, 0.200113, 0.474993, 0.188910, 0.480486, 0.174081); path.lineTo(0.500000, 0.174081); path.cubicTo(0.488436, 0.210509, 0.471957, 0.237911, 0.450564, 0.256286); path.cubicTo(0.429170, 0.274662, 0.407054, 0.283849, 0.384215, 0.283849); path.cubicTo(0.368893, 0.283849, 0.353859, 0.279094, 0.339115, 0.269584); path.cubicTo(0.324371, 0.260074, 0.313530, 0.246534, 0.306592, 0.228965); path.cubicTo(0.299653, 0.211396, 0.296184, 0.184075, 0.296184, 0.147002); path.lineTo(0.296184, -0.197292); path.lineTo(0.223330, -0.197292); path.lineTo(0.223330, -0.215667); path.cubicTo(0.241833, -0.224049, 0.260697, -0.237992, 0.279922, -0.257495); path.cubicTo(0.299147, -0.276999, 0.316276, -0.300129, 0.331310, -0.326886); path.cubicTo(0.338826, -0.341070, 0.349523, -0.367021, 0.363400, -0.404739); path.lineTo(0.379011, -0.404739); path.moveTo(-0.535993, 0.275629); painter->translate(w / 2, h / 2); double scale = qMin(w, h) * 8 / 10.0; painter->scale(scale, scale); painter->setRenderHint(QPainter::Antialiasing); painter->save(); painter->translate(.1, .1); painter->fillPath(path, QColor(0, 0, 0, 63)); painter->restore(); painter->setBrush(color); painter->setPen(QPen(Qt::black, 0.02, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin)); painter->drawPath(path); }
QPainterPath BezierCurve::getStrokedPath(qreal width, bool usePressure) { QPainterPath path; QPointF tangentVec, normalVec, normalVec2, normalVec2_1, normalVec2_2; qreal width2 = width; path.setFillRule(Qt::WindingFill); int n = vertex.size(); normalVec = QPointF(-(c1.at(0) - origin).y(), (c1.at(0) - origin).x()); normalise(normalVec); if (usePressure) width2 = width * 0.5 * pressure.at(0); if (n==1 && width2 == 0.0) width2 = 0.15 * width; path.moveTo(origin + width2*normalVec); for(int i=0; i<n; i++) { if (i==n-1) { normalVec2 = QPointF(-(vertex.at(i) - c2.at(i)).y(), (vertex.at(i) - c2.at(i)).x()); } else { normalVec2_1 = QPointF(-(vertex.at(i) - c2.at(i)).y(), (vertex.at(i) - c2.at(i)).x()); normalise(normalVec2_1); normalVec2_2 = QPointF(-(c1.at(i+1) - vertex.at(i)).y(), (c1.at(i+1) - vertex.at(i)).x()); normalise(normalVec2_2); normalVec2 = normalVec2_1 + normalVec2_2; } normalise(normalVec2); if (usePressure) width2 = width * 0.5 * pressure.at(i); if (n==1 && width2 == 0.0) width2 = 0.15 * width; //if (i==n-1) width2 = 0.0; path.cubicTo(c1.at(i) + width2*normalVec, c2.at(i) + width2*normalVec2, vertex.at(i) + width2*normalVec2); //path.moveTo(vertex.at(i) + width*normalVec2); //path.lineTo(vertex.at(i) - width*normalVec2); normalVec = normalVec2; } if (usePressure) width2 = width * 0.5 * pressure.at(n-1); if (n==1 && width2 == 0.0) width2 = 0.15 * width; //path.lineTo(vertex.at(n-1) - width2*normalVec); tangentVec = (vertex.at(n-1)-c2.at(n-1)); normalise(tangentVec); path.cubicTo(vertex.at(n-1) + width2*(normalVec+1.8*tangentVec), vertex.at(n-1) + width2*(-normalVec+1.8*tangentVec), vertex.at(n-1) - width2*normalVec); for(int i=n-2; i>-1; i--) { normalVec2_1 = QPointF((vertex.at(i) - c1.at(i+1)).y(), -(vertex.at(i) - c1.at(i+1)).x()); normalise(normalVec2_1); normalVec2_2 = QPointF((c2.at(i) - vertex.at(i)).y(), -(c2.at(i) - vertex.at(i)).x()); normalise(normalVec2_2); normalVec2 = normalVec2_1 + normalVec2_2; normalise(normalVec2); if (usePressure) width2 = width * 0.5 * pressure.at(i); if (n==1 && width2 == 0.0) width2 = 0.15 * width; path.cubicTo(c2.at(i+1) - width2*normalVec, c1.at(i+1) - width2*normalVec2, vertex.at(i) - width2*normalVec2); normalVec = normalVec2; } normalVec2 = QPointF((origin - c1.at(0)).y(), -(origin - c1.at(0)).x()); normalise(normalVec2); if (usePressure) width2 = width * 0.5 * pressure.at(0); if (n==1 && width2 == 0.0) width2 = 0.15 * width; path.cubicTo(c2.at(0) - width2*normalVec, c1.at(0) - width2*normalVec2, origin - width2*normalVec2); path.closeSubpath(); return path; }