void KoTextWriter::Private::writeBlocks(QTextDocument *document, int from, int to, QHash<QTextList *, QString> &listStyles, QTextTable *currentTable, QTextList *currentList) { pairedInlineObjectsStackStack.push(currentPairedInlineObjectsStack); currentPairedInlineObjectsStack = new QStack<KoInlineObject*>(); QTextBlock block = document->findBlock(from); int sectionLevel = 0; while (block.isValid() && ((to == -1) || (block.position() <= to))) { QTextCursor cursor(block); int frameType = cursor.currentFrame()->format().intProperty(KoText::SubFrameType); if (frameType == KoText::AuxillaryFrameType) { break; // we've reached the "end" (end/footnotes saved by themselves) // note how NoteFrameType passes through here so the notes can // call writeBlocks to save their contents. } QTextBlockFormat format = block.blockFormat(); if (format.hasProperty(KoParagraphStyle::SectionStartings)) { QVariant v = format.property(KoParagraphStyle::SectionStartings); QList<QVariant> sectionStarts = v.value<QList<QVariant> >(); foreach (const QVariant &sv, sectionStarts) { KoSection* section = (KoSection*)(sv.value<void*>()); if (section) { ++sectionLevel; section->saveOdf(context); } } }
void TestStyles::testApplyParagraphStyle() { KoParagraphStyle style; style.setStyleId(1001); QTextBlockFormat format; QCOMPARE(format.properties().count(), 0); style.applyStyle(format); QCOMPARE(format.properties().count(), 2); // the styleId and nextStyleId QCOMPARE(format.property(KoParagraphStyle::StyleId).toInt(), 1001); QCOMPARE(format.property(KoParagraphStyle::NextStyle).toInt(), 1001); style.setName("name"); style.setAlignment(Qt::AlignRight); style.applyStyle(format); QCOMPARE(format.properties().count(), 3); QCOMPARE(format.alignment(), Qt::AlignRight); }
void TestStyles::testApplyParagraphStyleWithParent() { KoParagraphStyle style1; style1.setStyleId(1002); KoParagraphStyle style2; style2.setStyleId(1003); KoParagraphStyle style3; style3.setStyleId(1004); style3.setParentStyle(&style2); style2.setParentStyle(&style1); style1.setAlignment(Qt::AlignRight); QCOMPARE(style1.alignment(), Qt::AlignRight); QCOMPARE(style2.alignment(), Qt::AlignRight); QCOMPARE(style3.alignment(), Qt::AlignRight); style2.setAlignment(Qt::AlignCenter); QCOMPARE(style1.alignment(), Qt::AlignRight); QCOMPARE(style2.alignment(), Qt::AlignCenter); QCOMPARE(style3.alignment(), Qt::AlignCenter); style3.setAlignment(Qt::AlignLeft | Qt::AlignAbsolute); QCOMPARE(style1.alignment(), Qt::AlignRight); QCOMPARE(style2.alignment(), Qt::AlignCenter); QCOMPARE(style3.alignment(), Qt::AlignLeft | Qt::AlignAbsolute); style3.setLineSpacing(23.45); style3.setLineHeightPercent(150); style3.setLineHeightAbsolute(8.0); QCOMPARE(style3.lineHeightPercent(), 0.0); QCOMPARE(style3.lineHeightAbsolute(), 8.0); QCOMPARE(style3.lineSpacing(), 23.45); QVERIFY(!style3.hasNormalLineHeight()); style3.setNormalLineHeight(); QCOMPARE(style3.lineHeightPercent(), 0.0); QCOMPARE(style3.lineHeightAbsolute(), 0.0); QCOMPARE(style3.lineSpacing(), 0.0); QVERIFY(style3.hasNormalLineHeight()); style3.setLineHeightPercent(150); style3.setLineSpacing(56.78); QCOMPARE(style3.lineHeightPercent(), 150.0); QCOMPARE(style3.lineHeightAbsolute(), 0.0); QCOMPARE(style3.lineSpacing(), 56.78); QVERIFY(!style3.hasNormalLineHeight()); QTextLength length0(QTextLength::FixedLength, 0.0); QTextLength length1(QTextLength::FixedLength, 10.0); QTextLength length2(QTextLength::FixedLength, 20.0); style1.setLeftMargin(length1); QCOMPARE(style1.leftMargin(), 10.0); QCOMPARE(style2.leftMargin(), 10.0); QCOMPARE(style3.leftMargin(), 10.0); style2.setRightMargin(length2); QCOMPARE(style1.rightMargin(), 0.0); QCOMPARE(style2.rightMargin(), 20.0); QCOMPARE(style3.rightMargin(), 20.0); // now actually apply it. QTextBlockFormat rawFormat; style1.applyStyle(rawFormat); KoParagraphStyle format(rawFormat, rawFormat.toCharFormat()); QCOMPARE(rawFormat.properties().count(), 4); QCOMPARE(format.alignment(), Qt::AlignRight); QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), 1002); //since we have not specified any NextStyle it should be the same as the current style QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), rawFormat.property(KoParagraphStyle::NextStyle).toInt()); QCOMPARE(format.leftMargin(), 10.0); QCOMPARE(format.rightMargin(), 0.0); style2.applyStyle(rawFormat); KoParagraphStyle format2(rawFormat, rawFormat.toCharFormat()); QCOMPARE(rawFormat.properties().count(), 5); QCOMPARE(format2.alignment(), Qt::AlignCenter); QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), 1003); //since we have not specified any NextStyle it should be the same as the current style QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), rawFormat.property(KoParagraphStyle::NextStyle).toInt()); QCOMPARE(format2.leftMargin(), 10.0); QCOMPARE(format2.rightMargin(), 20.0); style3.applyStyle(rawFormat); KoParagraphStyle format3(rawFormat, rawFormat.toCharFormat()); QCOMPARE(rawFormat.properties().count(), 9); QCOMPARE(rawFormat.property(KoParagraphStyle::LineSpacing).toReal(), 56.78); QCOMPARE(format3.alignment(), Qt::AlignLeft | Qt::AlignAbsolute); QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), 1004); //since we have not specified any NextStyle it should be the same as the current style QCOMPARE(rawFormat.property(KoParagraphStyle::StyleId).toInt(), rawFormat.property(KoParagraphStyle::NextStyle).toInt()); QCOMPARE(format3.leftMargin(), 10.0); QCOMPARE(format3.rightMargin(), 20.0); }
bool IndexGeneratorManager::generate() { if (m_state == Resting || m_state == FirstRunLayouting || m_state == SecondRunLayouting) { return false; } if (m_state == FirstRun || m_state == SecondRun) { return true; } if (m_document->characterCount() < 2) { return false; } if (m_state == FirstRunNeeded) { m_state = FirstRun; } if (m_state == SecondRunNeeded) { m_state = SecondRun; } QTextBlock block = m_document->firstBlock(); bool success = true; while (block.isValid()) { QTextBlockFormat format = block.blockFormat(); if (format.hasProperty(KoParagraphStyle::TableOfContentsData)) { QVariant data = format.property(KoParagraphStyle::TableOfContentsData); KoTableOfContentsGeneratorInfo *tocInfo = data.value<KoTableOfContentsGeneratorInfo *>(); data = format.property(KoParagraphStyle::GeneratedDocument); QTextDocument *tocDocument = data.value<QTextDocument *>(); ToCGenerator *generator = m_generators[tocInfo]; if (!generator) { generator = new ToCGenerator(tocDocument, tocInfo); m_generators[tocInfo] = generator; } generator->setBlock(block); success &= generator->generate(); } block = block.next(); } if (m_state == FirstRun) { m_state = FirstRunLayouting; } if (m_state == SecondRun) { if (success) { m_state = SecondRunLayouting; } else { m_state = FirstRunLayouting; } } return false; }