本文整理汇总了C++中KoShapeSavingContext::xmlWriter方法的典型用法代码示例。如果您正苦于以下问题:C++ KoShapeSavingContext::xmlWriter方法的具体用法?C++ KoShapeSavingContext::xmlWriter怎么用?C++ KoShapeSavingContext::xmlWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KoShapeSavingContext
的用法示例。
在下文中一共展示了KoShapeSavingContext::xmlWriter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveOdf
void MusicShape::saveOdf( KoShapeSavingContext & context ) const
{
// The name of this object in the ODF file.
KoEmbeddedDocumentSaver &fileSaver = context.embeddedSaver();
QString objectName = fileSaver.getFilename("Object");
KoXmlWriter& writer = context.xmlWriter();
writer.startElement("draw:frame");
saveOdfAttributes(context, OdfAllAttributes);
writer.startElement("music:shape");
writer.addAttribute("xmlns:music", "http://www.calligra.org/music");
MusicXmlWriter().writeSheet(writer, m_sheet, false);
writer.endElement(); // music:shape
const qreal previewZoom = 150 / 72.; // 150 DPI
QSizeF imgSize = size(); // in points
imgSize *= previewZoom;
KoViewConverter converter;
// Save a preview SVG image.
// -------------------------
// 1. Set up the svg renderer.
QByteArray svgContents; // The contents
QBuffer svgBuffer(&svgContents); // The corresponding QIODevice
QSvgGenerator svg;
svg.setOutputDevice(&svgBuffer); // Write to the buffer
svg.setSize(imgSize.toSize());
svg.setViewBox(QRect(0, 0, boundingRect().width(), boundingRect().height()));
// 2. Paint the svg preview image.
//
// We need to create all text as paths, because otherwise it
// will be difficult for most people to preview the SVG
// image. Not many people have music fonts installed.
QPainter svgPainter;
svgPainter.begin(&svg);
svgPainter.setRenderHint(QPainter::Antialiasing);
svgPainter.setRenderHint(QPainter::TextAntialiasing);
m_style->setTextAsPath(true);
constPaint(svgPainter, converter);
m_style->setTextAsPath(false);
svgPainter.end();
// 3. Create the xml to embed the svg image and the contents to the file.
writer.startElement("draw:image");
QString name = QString("ObjectReplacements/") + objectName + ".svg";
writer.addAttribute("xlink:type", "simple" );
writer.addAttribute("xlink:show", "embed" );
writer.addAttribute("xlink:actuate", "onLoad");
writer.addAttribute("xlink:href", name);
writer.endElement(); // draw:image
fileSaver.saveFile(name, "image/svg+xml", svgContents);
// Save a preview bitmap image.
// ----------------------------
// 1. Create the image.
QImage img(imgSize.toSize(), QImage::Format_ARGB32);
QPainter painter(&img);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
converter.setZoom(previewZoom);
constPaint(painter, converter);
// 2. Create the xml to embed the svg image and the contents to the file.
writer.startElement("draw:image");
name = context.imageHref(img);
// FIXME: Find out how to save a picture using the embeddedSaver and saveFile()
//name = QString("ObjectReplacements/") + objectName + ".png";
writer.addAttribute("xlink:type", "simple" );
writer.addAttribute("xlink:show", "embed" );
writer.addAttribute("xlink:actuate", "onLoad");
writer.addAttribute("xlink:href", name);
writer.endElement(); // draw:image
saveOdfCommonChildElements(context);
writer.endElement(); // draw:frame
}
示例2: saveOdf
void KoConnectionShape::saveOdf(KoShapeSavingContext & context) const
{
Q_D(const KoConnectionShape);
context.xmlWriter().startElement("draw:connector");
saveOdfAttributes(context, OdfMandatories | OdfAdditionalAttributes);
switch (d->connectionType) {
case Lines:
context.xmlWriter().addAttribute("draw:type", "lines");
break;
case Straight:
context.xmlWriter().addAttribute("draw:type", "line");
break;
case Curve:
context.xmlWriter().addAttribute("draw:type", "curve");
break;
default:
context.xmlWriter().addAttribute("draw:type", "standard");
break;
}
if (d->shape1) {
context.xmlWriter().addAttribute("draw:start-shape", context.xmlid(d->shape1, "shape", KoElementReference::Counter).toString());
context.xmlWriter().addAttribute("draw:start-glue-point", d->connectionPointId1);
} else {
QPointF p(shapeToDocument(d->handles[StartHandle]) * context.shapeOffset(this));
context.xmlWriter().addAttributePt("svg:x1", p.x());
context.xmlWriter().addAttributePt("svg:y1", p.y());
}
if (d->shape2) {
context.xmlWriter().addAttribute("draw:end-shape", context.xmlid(d->shape2, "shape", KoElementReference::Counter).toString());
context.xmlWriter().addAttribute("draw:end-glue-point", d->connectionPointId2);
} else {
QPointF p(shapeToDocument(d->handles[EndHandle]) * context.shapeOffset(this));
context.xmlWriter().addAttributePt("svg:x2", p.x());
context.xmlWriter().addAttributePt("svg:y2", p.y());
}
// write the path data
context.xmlWriter().addAttribute("svg:d", toString());
saveOdfAttributes(context, OdfViewbox);
saveOdfCommonChildElements(context);
saveText(context);
context.xmlWriter().endElement();
}