void TestDocumentLayout::testRightToLeftList() { initForNewTest("a\nb\nc"); KoParagraphStyle h1; h1.setTextProgressionDirection(KoText::RightLeftTopBottom); m_styleManager->add(&h1); KoListStyle listStyle; KoListLevelProperties llp = listStyle.levelProperties(1); llp.setStyle(KoListStyle::DecimalItem); listStyle.setLevelProperties(llp); h1.setListStyle(&listStyle); QTextBlock block = m_doc->begin(); h1.applyStyle(block); block = block.next(); h1.applyStyle(block); block = block.next(); h1.applyStyle(block); block = block.next(); m_layout->layout(); block = m_doc->begin(); while (block.isValid()) { KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(data); QVERIFY(data->counterWidth() > 2); QVERIFY(data->counterPosition().x() > 100); QTextLine line = block.layout()->lineAt(0); QVERIFY(line.isValid()); QCOMPARE(line.x(), (qreal)0); QCOMPARE(line.width() + data->counterWidth() + data->counterSpacing(), (qreal)200); block = block.next(); } }
void TestDocumentLayout::testCenteredItems() { initForNewTest("ListItem\nListItem\nListItem"); KoListStyle listStyle; KoListLevelProperties llp; llp.setStyle(KoListStyle::DecimalItem); listStyle.setLevelProperties(llp); QTextBlock block = m_doc->begin(); // normal block QVERIFY(block.isValid()); listStyle.applyStyle(block); block = block.next(); // centered block QVERIFY(block.isValid()); listStyle.applyStyle(block); QTextBlockFormat fmt; fmt.setAlignment(Qt::AlignHCenter); QTextCursor cursor(block); cursor.mergeBlockFormat(fmt); block = block.next(); // centered RTL text. listStyle.applyStyle(block); cursor = QTextCursor(block); fmt.setProperty(KoParagraphStyle::TextProgressionDirection, KoText::RightLeftTopBottom); cursor.mergeBlockFormat(fmt); m_layout->layout(); block = m_doc->begin(); QTextLayout *layout = block.layout(); QTextLine line1 = layout->lineAt(0); KoTextBlockData *data1 = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(line1.isValid()); QVERIFY(line1.width() < 200); // the counter takes some space. block = block.next(); layout = block.layout(); QTextLine line2 = layout->lineAt(0); KoTextBlockData *data2 = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(line2.isValid()); QVERIFY(line2.width() < 200); // the counter takes some space. QCOMPARE(line1.width(), line2.width()); const qreal width1 = line1.naturalTextWidth() + data1->counterWidth() + data1->counterSpacing(); const qreal width2 = line2.naturalTextWidth() + data2->counterWidth() + data2->counterSpacing(); QCOMPARE(width1, width2); QVERIFY(data1->counterPosition().x() < data2->counterPosition().x()); const qreal padding = (200 - width2) / 2; QVERIFY(padding > 0);// not really a layout test, but the rest will be bogus otherwise. QCOMPARE(data2->counterPosition().x(), padding); // close to the centered text. // right to left parag places the counter on the right. Its centered, so not the far right. block = block.next(); layout = block.layout(); QTextLine line = layout->lineAt(0); KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData()); QCOMPARE(data->counterPosition().x(), 200 - padding - data->counterWidth()); }
void TestDocumentLayout::testNestedLists() { initForNewTest("Root\nplants\nherbs\ncinnamon\ncurry\nroses\nhumans\nFrank\nAnkje\nOther\nSkip\nLastItem"); KoParagraphStyle h1; m_styleManager->add(&h1); KoParagraphStyle h2; m_styleManager->add(&h2); KoParagraphStyle h3; m_styleManager->add(&h3); KoParagraphStyle h4; m_styleManager->add(&h4); KoListStyle listStyle; KoListLevelProperties llp1; llp1.setStartValue(1); llp1.setStyle(KoListStyle::DecimalItem); listStyle.setLevelProperties(llp1); h1.setListStyle(&listStyle); KoListStyle listStyle2; KoListLevelProperties llp2; llp2.setStartValue(1); llp2.setStyle(KoListStyle::DecimalItem); llp2.setLevel(2); llp2.setListItemSuffix("."); llp2.setDisplayLevel(2); listStyle2.setLevelProperties(llp2); h2.setListStyle(&listStyle2); // purpusfully leave this one out, as it should default to the only known one: // h2.setListLevel(2); KoListLevelProperties llp3; llp3.setStartValue(1); llp3.setStyle(KoListStyle::DecimalItem); llp3.setLevel(3); llp3.setListItemSuffix(""); llp3.setDisplayLevel(3); KoListStyle listStyle3; listStyle3.setLevelProperties(llp3); h3.setListStyle(&listStyle3); h3.setListLevel(3); KoListStyle listStyle4; KoListLevelProperties llp4; llp4.setStartValue(1); llp4.setStyle(KoListStyle::DecimalItem); llp4.setLevel(4); llp4.setDisplayLevel(2); listStyle4.setLevelProperties(llp4); h4.setListStyle(&listStyle4); h4.setListLevel(4); QTextBlock block = m_doc->begin().next(); h1.applyStyle(block); block = block.next(); h2.applyStyle(block); block = block.next(); h3.applyStyle(block); block = block.next(); h3.applyStyle(block); block = block.next(); // roses h2.applyStyle(block); block = block.next(); h1.applyStyle(block); // humans block = block.next(); h2.applyStyle(block); block = block.next(); h2.applyStyle(block); block = block.next(); h1.applyStyle(block); block = block.next(); h3.applyStyle(block); // notice missing h2 block = block.next(); QVERIFY(block.isValid()); h4.applyStyle(block); m_layout->layout(); block = m_doc->begin(); QVERIFY(block.userData() == 0); block = block.next(); static const char *const texts[] = { "1", "1.1.", "1.1.1", "1.1.2", "1.2.", "2", "2.1.", "2.2.", "3", "3.1.1", "1.1" }; int i = 0; qreal indent = 0.0; while (block.isValid()) { KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData()); //qDebug() << "text: " << block.text(); //qDebug() << "expected: " << texts[i]; QVERIFY(data); //qDebug() << data->counterText(); QCOMPARE(data->counterText(), QString(texts[i++])); if (i < 3) { //qDebug() << "indent:" << data->counterWidth(); QVERIFY(indent < data->counterWidth()); // deeper indent, larger width indent = data->counterWidth(); } block = block.next(); } }