void SimpleParagraphWidget::fillListButtons() { KoZoomHandler zoomHandler; zoomHandler.setZoom(1.2); zoomHandler.setDpi(72, 72); KoInlineTextObjectManager itom; KoTextRangeManager tlm; TextShape textShape(&itom, &tlm); textShape.setSize(QSizeF(300, 100)); QTextCursor cursor (textShape.textShapeData()->document()); foreach(const Lists::ListStyleItem &item, Lists::genericListStyleItems()) { QPixmap pm(48,48); pm.fill(Qt::transparent); QPainter p(&pm); p.translate(0, -1.5); p.setRenderHint(QPainter::Antialiasing); if(item.style != KoListStyle::None) { KoListStyle listStyle; KoListLevelProperties llp = listStyle.levelProperties(1); llp.setStyle(item.style); if (KoListStyle::isNumberingStyle(item.style)) { llp.setStartValue(1); llp.setListItemSuffix("."); } listStyle.setLevelProperties(llp); cursor.select(QTextCursor::Document); QTextCharFormat textCharFormat=cursor.blockCharFormat(); textCharFormat.setFontPointSize(11); textCharFormat.setFontWeight(QFont::Normal); cursor.setCharFormat(textCharFormat); QTextBlock cursorBlock = cursor.block(); KoTextBlockData data(cursorBlock); cursor.insertText("----"); listStyle.applyStyle(cursor.block(),1); cursorBlock = cursor.block(); KoTextBlockData data1(cursorBlock); cursor.insertText("\n----"); cursorBlock = cursor.block(); KoTextBlockData data2(cursorBlock); cursor.insertText("\n----"); cursorBlock = cursor.block(); KoTextBlockData data3(cursorBlock); KoTextDocumentLayout *lay = dynamic_cast<KoTextDocumentLayout*>(textShape.textShapeData()->document()->documentLayout()); if(lay) lay->layout(); KoShapePaintingContext paintContext; //FIXME textShape.paintComponent(p, zoomHandler, paintContext); widget.bulletListButton->addItem(pm, static_cast<int> (item.style)); } }
void KoTextLoader::loadBody(const KoXmlElement &bodyElem, QTextCursor &cursor) { const QTextBlockFormat defaultBlockFormat = cursor.blockFormat(); const QTextCharFormat defaultCharFormat = cursor.charFormat(); const QTextDocument *document = cursor.block().document(); d->styleManager = KoTextDocument(document).styleManager(); Q_ASSERT(d->styleManager); d->changeTracker = KoTextDocument(document).changeTracker(); // if (!d->changeTracker) // d->changeTracker = dynamic_cast<KoChangeTracker *>(d->context.dataCenterMap().value("ChangeTracker")); // Q_ASSERT(d->changeTracker); kDebug(32500) << "text-style:" << KoTextDebug::textAttributes( cursor.blockCharFormat() ); #if 0 if ((document->isEmpty()) && (d->styleManager)) { QTextBlock block = cursor.block(); d->styleManager->defaultParagraphStyle()->applyStyle(block); } #endif startBody(KoXml::childNodesCount(bodyElem)); KoXmlElement tag; bool usedParagraph = false; // set to true if we found a tag that used the paragraph, indicating that the next round needs to start a new one. forEachElement(tag, bodyElem) { if (! tag.isNull()) { const QString localName = tag.localName(); if (tag.namespaceURI() == KoXmlNS::text) { if (usedParagraph) cursor.insertBlock(defaultBlockFormat, defaultCharFormat); usedParagraph = true; if (d->changeTracker && localName == "tracked-changes") { d->changeTracker->loadOdfChanges(tag); usedParagraph = false; } else if (d->changeTracker && localName == "change-start") { loadChangedRegion(tag, cursor); usedParagraph = false; } else if (d->changeTracker && localName == "change-end") { d->currentChangeId = 0; usedParagraph = false; } else if (localName == "p") { // text paragraph loadParagraph(tag, cursor); } else if (localName == "h") { // heading loadHeading(tag, cursor); } else if (localName == "unordered-list" || localName == "ordered-list" // OOo-1.1 || localName == "list" || localName == "numbered-paragraph") { // OASIS loadList(tag, cursor); } else if (localName == "section") { // Temporary support (###TODO) loadSection(tag, cursor); } else { KoVariable *var = KoVariableRegistry::instance()->createFromOdf(tag, d->context); if (var) { KoTextDocumentLayout *layout = dynamic_cast<KoTextDocumentLayout*>(cursor.block().document()->documentLayout()); if (layout) { KoInlineTextObjectManager *textObjectManager = layout->inlineTextObjectManager(); if (textObjectManager) { KoVariableManager *varManager = textObjectManager->variableManager(); if (varManager) { textObjectManager->insertInlineObject(cursor, var); } } } } else { usedParagraph = false; kWarning(32500) << "unhandled text:" << localName; } } } else if (tag.namespaceURI() == KoXmlNS::draw) { loadShape(tag, cursor); } else if (tag.namespaceURI() == KoXmlNS::table) { if (localName == "table") { loadTable(tag, cursor); } else { kWarning(32500) << "unhandled table:" << localName; } #if 0 // TODO commented out for now if (localName == "table") { cursor.insertText("\n"); cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1); QTextTable *tbl = cursor.insertTable(1, 1); int rows = 0; int columns = 0; kDebug(32500) << "Table inserted"; KoXmlElement tblTag; forEachElement(tblTag, tag) { if (! tblTag.isNull()) { const QString tblLocalName = tblTag.localName(); if (tblTag.namespaceURI() == KoXmlNS::table) { if (tblLocalName == "table-column") { // Do some parsing with the column, see ยง8.2.1, ODF 1.1 spec int repeatColumn = tblTag.attributeNS(KoXmlNS::table, "number-columns-repeated", "1").toInt(); columns = columns + repeatColumn; if (rows > 0) tbl->resize(rows, columns); else tbl->resize(1, columns); } else if (tblLocalName == "table-row") { // Lot of work to do here... rows++; if (columns > 0) tbl->resize(rows, columns); else tbl->resize(rows, 1); // Added a row int currentCell = 0; KoXmlElement rowTag; forEachElement(rowTag, tblTag) { if (!rowTag.isNull()) { const QString rowLocalName = rowTag.localName(); if (rowTag.namespaceURI() == KoXmlNS::table) { if (rowLocalName == "table-cell") { // Ok, it's a cell... const int currentRow = tbl->rows() - 1; QTextTableCell cell = tbl->cellAt(currentRow, currentCell); if (cell.isValid()) { cursor = cell.firstCursorPosition(); loadBody(context, rowTag, cursor); } else kDebug(32500) << "Invalid table-cell row=" << currentRow << " column=" << currentCell; currentCell++; } } } } } } } } cursor = tbl->lastCursorPosition(); cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 1); } else { kWarning(32500) << "KoTextLoader::loadBody unhandled table::" << localName; } #endif }