void SdfRenderer::draw_text(QDomElement &element) { parsestyle(element); pen.setStyle(Qt::SolidLine); painter->setPen(pen); float x1 = x1_def(element); float y1 = y1_def(element); QString str = element.text(); // delete "\n" from the beginning of the string if (str[0] == '\n') str.remove(0, 1); // delete "\n" from the end of the string if (str[str.length() - 1] == '\n') str.remove(str.length() - 1, 1); while (str.contains('\n')) { int i = str.indexOf('\n'); QString temp = str.left(i); str.remove(0, i + 1); painter->drawText(static_cast<int>(x1), static_cast<int>(y1), temp); y1 += painter->font().pixelSize() ; } QPointF point(x1, y1); painter->drawText(point, str); defaultstyle(); }
void SdfRenderer::curve_draw(QDomElement &element) { QDomNode node = element.firstChild(); QPointF start(0, 0); QPointF end(0, 0); QPoint c1(0, 0); while(!node.isNull()) { QDomElement elem = node.toElement(); if(!elem.isNull()) { if (elem.tagName() == "start") { start.setX(elem.attribute("startx").toDouble() * current_size_x / first_size_x); start.setY(elem.attribute("starty").toDouble() * current_size_y / first_size_y); } else if (elem.tagName() == "end") { end.setX(elem.attribute("endx").toDouble() * current_size_x / first_size_x); end.setY(elem.attribute("endy").toDouble() * current_size_y / first_size_y); } else if (elem.tagName() == "ctrl") { c1.setX(elem.attribute("x").toDouble() * current_size_x / first_size_x); c1.setY(elem.attribute("y").toDouble() * current_size_y / first_size_y); } } node = node.nextSibling(); } QPainterPath path(start); path.quadTo(c1, end); parsestyle(element); painter->drawPath(path); }
void SdfRenderer::background(QDomElement &element) { parsestyle(element); painter->setPen(brush.color()); painter->drawRect(painter->window()); defaultstyle(); }
void SdfRenderer::point(QDomElement &element) { parsestyle(element); float x = x1_def(element); float y = y1_def(element); QPointF pointf(x,y); painter->drawLine(QPointF(pointf.x()-0.1, pointf.y()-0.1), QPointF(pointf.x()+0.1, pointf.y()+0.1)); defaultstyle(); }
void SdfRenderer::point(QDomElement &element) { toGen << "{\n"; toGen << QString("\tfloat x = x_def(\"%1\");\n").arg(element.attribute("x1")); toGen << QString("\tfloat y = y_def(\"%1\");\n").arg(element.attribute("y1")); parsestyle(element); toGen << "\tQPointF point(x,y);\n"; toGen << "\tpainter->drawPoint(point);\n"; toGen << "};\n\n"; }
void SdfRenderer::ellipse(QDomElement &element) { float x1 = x1_def(element); float y1 = y1_def(element); float x2 = x2_def(element); float y2 = y2_def(element); QRectF rect(x1, y1, x2-x1, y2-y1); parsestyle(element); painter->drawEllipse(rect); }
void SdfRenderer::line(QDomElement &element) { float x1 = x1_def(element); float y1 = y1_def(element); float x2 = x2_def(element); float y2 = y2_def(element); QLineF line (x1,y1,x2,y2); parsestyle(element); painter->drawLine(line); }
void SdfRenderer::rectangle(QDomElement &element) { toGen << "{\n"; toGen << QString("\tfloat x1 = x_def(\"%1\");\n").arg(element.attribute("x1")); toGen << QString("\tfloat y1 = y_def(\"%1\");\n").arg(element.attribute("y1")); toGen << QString("\tfloat x2 = x_def(\"%1\");\n").arg(element.attribute("x2")); toGen << QString("\tfloat y2 = y_def(\"%1\");\n").arg(element.attribute("y2")); toGen << "\tQRectF rect;\n"; toGen << "\trect.adjust(x1, y1, x2, y2);\n"; parsestyle(element); toGen << "\n\tpainter->drawRect(rect);\n"; toGen << "};\n\n"; }
void SdfRenderer::line(QDomElement &element) { toGen << "{\n"; toGen << QString("\tfloat x1 = x_def(\"%1\");\n").arg(element.attribute("x1")); toGen << QString("\tfloat y1 = y_def(\"%1\");\n").arg(element.attribute("y1")); toGen << QString("\tfloat x2 = x_def(\"%1\");\n").arg(element.attribute("x2")); toGen << QString("\tfloat y2 = y_def(\"%1\");\n").arg(element.attribute("y2")); toGen <<"\tQLineF line (x1,y1,x2,y2);\n\n"; parsestyle(element); toGen <<"\tpainter->drawLine(line);\n"; toGen << "};\n\n"; }
void SdfRenderer::rectangle(QDomElement &element) { float x1 = x1_def(element); float y1 = y1_def(element); float x2 = x2_def(element); float y2 = y2_def(element); QRectF rect; rect.adjust(x1, y1, x2, y2); parsestyle(element); painter->drawRect(rect); defaultstyle(); }
void SdfRenderer::arc(QDomElement &element) { float x1 = x1_def(element); float y1 = y1_def(element); float x2 = x2_def(element); float y2 = y2_def(element); int startAngle = element.attribute("startAngle").toInt(); int spanAngle = element.attribute("spanAngle").toInt(); QRectF rect(x1, y1, x2-x1, y2-y1); parsestyle(element); painter->drawArc(rect, startAngle, spanAngle); }
void SdfRenderer::polygon(QDomElement &element) { parsestyle(element); // FIXME: init points array here QPoint *points = NULL; int n = element.attribute("n").toInt(); if (!element.isNull()) { points = getpoints(element, n); } if (points != NULL) { // painter->drawConvexPolygon(points, n); delete[] points; } defaultstyle(); }
void SdfRenderer::path_draw(QDomElement &element) { QDomElement elem = element; toGen << "{\n"; toGen << QString("\tQPainterPath path;\n"); toGen << QString("\tQPointF end_point;\n"); toGen << QString("\tQPointF c1;\n"); toGen << QString("\tQPointF c2;\n\n"); 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 (while_condition(d_cont, j)) { while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "end_point.setX(x_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "end_point.setY(y_def(\"" << s1 << "\"));\n"; ++j; s1.clear(); } toGen << QString("path.moveTo(end_point);\n\n"); i = j; } else if (d_cont[i] == 'L') { j = i + 2; while (while_condition(d_cont, j)) { while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "\tend_point.setX(x_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "\tend_point.setY(y_def(\"" << s1 << "\"));\n"; ++j; s1.clear(); } toGen << QString("\tpath.lineTo(end_point);\n\n"); i = j; } else if (d_cont[i] == 'C') { j = i + 2; while(while_condition(d_cont, j)) { while (!(d_cont[j] == ' ')) { s1.append(d_cont[j]); ++j; } toGen << "\tc1.setX(x_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "\tc1.setY(y_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "\tc2.setX(x_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "\tc2.setY(y_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "\tend_point.setX(x_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } toGen << "\tend_point.setY(y_def(\"" << s1 << "\"));\n"; s1.clear(); ++j; } toGen << QString("\tpath.cubicTo(c1, c2, end_point);\n\n"); i = j; } else if (d_cont[i] == 'Z') { toGen << "path.closeSubpath();\n"; } } } parsestyle(element); toGen << QString("\tpainter->drawPath(path);\n"); toGen << "};\n\n"; }
void SdfRenderer::background(QDomElement &element)//FIXME: { parsestyle(element); toGen << "\tpainter->setPen(brush.color());\n"; toGen << "\tpainter->drawRect(painter->window());\n"; }
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); }