void QTextOdfWriter::writeFormats(QXmlStreamWriter &writer, QSet<int> formats) const { writer.writeStartElement(officeNS, QString::fromLatin1("automatic-styles")); QVector<QTextFormat> allStyles = m_document->allFormats(); QSetIterator<int> formatId(formats); while(formatId.hasNext()) { int formatIndex = formatId.next(); QTextFormat textFormat = allStyles.at(formatIndex); switch (textFormat.type()) { case QTextFormat::CharFormat: if (textFormat.isTableCellFormat()) writeTableCellFormat(writer, textFormat.toTableCellFormat(), formatIndex); else writeCharacterFormat(writer, textFormat.toCharFormat(), formatIndex); break; case QTextFormat::BlockFormat: writeBlockFormat(writer, textFormat.toBlockFormat(), formatIndex); break; case QTextFormat::ListFormat: writeListFormat(writer, textFormat.toListFormat(), formatIndex); break; case QTextFormat::FrameFormat: writeFrameFormat(writer, textFormat.toFrameFormat(), formatIndex); break; case QTextFormat::TableFormat: ;break; } } writer.writeEndElement(); // automatic-styles }
void tst_QTextFormat::toFormat() { { QTextFormat fmt = QTextFrameFormat(); QCOMPARE(fmt.toFrameFormat().type(), int(QTextFormat::FrameFormat)); } { QTextFormat fmt = QTextTableFormat(); QCOMPARE(fmt.toTableFormat().type(), int(QTextFormat::FrameFormat)); QCOMPARE(fmt.toTableFormat().objectType(), int(QTextFormat::TableObject)); } { QTextFormat fmt = QTextBlockFormat(); QCOMPARE(fmt.toBlockFormat().type(), int(QTextFormat::BlockFormat)); } { QTextFormat fmt = QTextCharFormat(); QCOMPARE(fmt.toCharFormat().type(), int(QTextFormat::CharFormat)); } { QTextFormat fmt = QTextListFormat(); QCOMPARE(fmt.toListFormat().type(), int(QTextFormat::ListFormat)); } }
/*! \fn void QAbstractTextDocumentLayout::drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format) This function is called to draw the inline object, \a object, with the given \a painter within the rectangle specified by \a rect using the specified text \a format. \a posInDocument specifies the position of the object within the document. The default implementation calls drawObject() on the object handlers. This function is called only within Qt. Subclasses can reimplement this function to customize the drawing of inline objects. \sa draw() */ void QAbstractTextDocumentLayout::drawInlineObject(QPainter *p, const QRectF &rect, QTextInlineObject item, int posInDocument, const QTextFormat &format) { Q_UNUSED(item); Q_D(QAbstractTextDocumentLayout); QTextCharFormat f = format.toCharFormat(); Q_ASSERT(f.isValid()); QTextObjectHandler handler = d->handlers.value(f.objectType()); if (!handler.component) return; handler.iface->drawObject(p, rect, document(), posInDocument, format); }
/*! Sets the size of the inline object \a item corresponding to the text \a format. \a posInDocument specifies the position of the object within the document. The default implementation resizes the \a item to the size returned by the object handler's intrinsicSize() function. This function is called only within Qt. Subclasses can reimplement this function to customize the resizing of inline objects. */ void QAbstractTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) { Q_D(QAbstractTextDocumentLayout); QTextCharFormat f = format.toCharFormat(); Q_ASSERT(f.isValid()); QTextObjectHandler handler = d->handlers.value(f.objectType()); if (!handler.component) return; QSizeF s = handler.iface->intrinsicSize(document(), posInDocument, format); item.setWidth(s.width()); item.setAscent(s.height()); item.setDescent(0); }