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 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 TestDocumentLayout::testAutoRestartList() { initForNewTest("Humans\nGandhi\nEinstein\nInventions\nCar\nToilet\nLaboratory\n"); KoParagraphStyle h1; m_styleManager->add(&h1); KoParagraphStyle h2; m_styleManager->add(&h2); KoListStyle listStyle; KoListLevelProperties llp = listStyle.levelProperties(1); llp.setStyle(KoListStyle::DecimalItem); llp.setStartValue(1); llp.setListItemSuffix("."); listStyle.setLevelProperties(llp); h1.setListStyle(&listStyle); KoListStyle listStyle2; KoListLevelProperties llp2 = listStyle2.levelProperties(2); llp2.setStyle(KoListStyle::DecimalItem); llp2.setStartValue(1); llp2.setDisplayLevel(2); llp2.setListItemSuffix("."); listStyle2.setLevelProperties(llp2); h2.setListStyle(&listStyle2); QTextBlock block = m_doc->begin(); h1.applyStyle(block); block = block.next(); h2.applyStyle(block); block = block.next(); h2.applyStyle(block); block = block.next(); h1.applyStyle(block); // inventions block = block.next(); h2.applyStyle(block); QTextBlock car = block; block = block.next(); h2.applyStyle(block); block = block.next(); h2.applyStyle(block); m_layout->layout(); KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(car.userData()); QVERIFY(data); // qDebug() << data->counterText(); QCOMPARE(data->counterText(), QString("2.1.")); }
void ParagraphBulletsNumbers::setDisplay(KoParagraphStyle *style, int level) { KoListStyle *listStyle = style->listStyle(); widget.listPropertiesPane->setEnabled(listStyle != 0); widget.customCharacter->setText("-"); if (listStyle == 0) { widget.listTypes->setCurrentRow(0); return; } KoListLevelProperties llp = listStyle->levelProperties(level); m_previousLevel = llp.level(); widget.prefix->setText(llp.listItemPrefix()); widget.suffix->setText(llp.listItemSuffix()); widget.letterSynchronization->setChecked(llp.letterSynchronization()); KoListStyle::Style s = llp.style(); foreach(int row, m_mapping.keys()) { if (m_mapping[row] == s) { widget.listTypes->setCurrentRow(row); break; } } int align; if (llp.alignment() == (Qt::AlignLeft | Qt::AlignAbsolute)) align = 1; else if (llp.alignment() == (Qt::AlignRight | Qt::AlignAbsolute)) align = 2; else if (llp.alignment() == Qt::AlignCenter) align = 3; else align = 0; widget.alignment->setCurrentIndex(align); widget.depth->setValue(llp.level()); widget.levels->setValue(llp.displayLevel()); widget.startValue->setValue(llp.startValue()); if (s == KoListStyle::CustomCharItem) widget.customCharacter->setText(llp.bulletCharacter()); if (s == KoListStyle::ImageItem) { m_data = llp.bulletImage(); widget.imageHeight->setValue(llp.height()); widget.imageWidth->setValue(llp.width()); } else { m_data = 0; widget.imageHeight->setValue(0); widget.imageWidth->setValue(0); } if(llp.alignmentMode()==false) {//for list-level-position-and-space-mode=label-width-and-position disable the following options widget.label_8->setEnabled(false); widget.label_9->setEnabled(false); widget.label_10->setEnabled(false); widget.label_11->setEnabled(false); widget.labelFollowedBy->setEnabled(false); widget.doubleSpinBox->setEnabled(false); widget.doubleSpinBox_2->setEnabled(false); widget.doubleSpinBox_3->setEnabled(false); } else { m_alignmentMode=true; switch(llp.labelFollowedBy()) { case KoListStyle::ListTab: widget.doubleSpinBox->setEnabled(true); widget.labelFollowedBy->setCurrentIndex(0); widget.doubleSpinBox->setValue(KoUnit::toCentimeter(llp.tabStopPosition())); break; case KoListStyle::Space: widget.doubleSpinBox->setEnabled(false); widget.labelFollowedBy->setCurrentIndex(1); break; case KoListStyle::Nothing: widget.doubleSpinBox->setEnabled(false); widget.labelFollowedBy->setCurrentIndex(2); break; default: Q_ASSERT(false); } widget.doubleSpinBox_2->setValue(KoUnit::toCentimeter(llp.margin())); widget.doubleSpinBox_3->setValue(KoUnit::toCentimeter(llp.margin())+KoUnit::toCentimeter(llp.textIndent())); } // *** features not in GUI; // character style // relative bullet size (percent) // minimum label width recalcPreview(); }
void ParagraphBulletsNumbers::save(KoParagraphStyle *savingStyle) { Q_ASSERT(savingStyle); KoUnit unit(KoUnit::Centimeter); const int currentRow = widget.listTypes->currentRow(); KoListStyle::Style style = m_mapping[currentRow]; if (style == KoListStyle::None) { savingStyle->setListStyle(0); return; } if (savingStyle->listStyle() == 0) { KoListStyle *listStyle = new KoListStyle(savingStyle); savingStyle->setListStyle(listStyle); } KoListStyle *listStyle = savingStyle->listStyle(); KoListLevelProperties llp = listStyle->levelProperties(widget.depth->value()); llp.setStyle(style); llp.setLevel(widget.depth->value()); llp.setDisplayLevel(widget.levels->value()); llp.setStartValue(widget.startValue->value()); llp.setListItemPrefix(widget.prefix->text()); llp.setListItemSuffix(widget.suffix->text()); llp.setLetterSynchronization(widget.letterSynchronization->isVisible() && widget.letterSynchronization->isChecked()); if(m_alignmentMode==true) { llp.setAlignmentMode(true); switch(widget.labelFollowedBy->currentIndex()) { case 0: llp.setLabelFollowedBy(KoListStyle::ListTab); llp.setTabStopPosition(unit.fromUserValue(widget.doubleSpinBox->value())); break; case 1: llp.setLabelFollowedBy(KoListStyle::Space); break; case 2: llp.setLabelFollowedBy(KoListStyle::Nothing); break; default: Q_ASSERT(false); } llp.setMargin(unit.fromUserValue(widget.doubleSpinBox_2->value())); llp.setTextIndent(unit.fromUserValue(widget.doubleSpinBox_3->value())-unit.fromUserValue(widget.doubleSpinBox_2->value())); } if (style == KoListStyle::ImageItem) { if (m_data) { llp.setBulletImage(m_data); } llp.setWidth(widget.imageWidth->value()); llp.setHeight(widget.imageHeight->value()); } else if (style == KoListStyle::CustomCharItem) { llp.setBulletCharacter((currentRow == m_blankCharIndex) ? QChar() : widget.customCharacter->text().remove('&').at(0)); } // it is important to not use 45 for CustomCharItem as it is also char based else if (!KoListStyle::isNumberingStyle(style)) { llp.setRelativeBulletSize(45); //for non-numbering bullets the default relative bullet size is 45%(The spec does not say it; we take it) } Qt::Alignment align; switch (widget.alignment->currentIndex()) { case 0: align = Qt::AlignLeft; break; case 1: align = Qt::AlignLeft | Qt::AlignAbsolute; break; case 2: align = Qt::AlignRight | Qt::AlignAbsolute; break; case 3: align = Qt::AlignCenter; break; default: Q_ASSERT(false); } llp.setAlignment(align); if (llp.level() != m_previousLevel) listStyle->removeLevelProperties(m_previousLevel); listStyle->setLevelProperties(llp); }
void TestDocumentLayout::testInterruptedLists() { initForNewTest("ListItem1\nListItem2\nNormal Parag\nAnother parag\nListItem3\n"); // expect that normal paragraphs do not break a list (i.e not restart it) KoParagraphStyle style; KoListStyle listStyle; KoListLevelProperties llp = listStyle.levelProperties(1); llp.setStyle(KoListStyle::DecimalItem); llp.setStartValue(1); llp.setListItemSuffix("."); listStyle.setLevelProperties(llp); style.setListStyle(&listStyle); QTextBlock block = m_doc->begin(); style.applyStyle(block); block = block.next(); style.applyStyle(block); block = block.next(); block = block.next(); block = block.next(); style.applyStyle(block); m_layout->layout(); block = m_doc->begin(); KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(data); QVERIFY(data->counterText() == "1."); block = block.next(); data = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(data); QVERIFY(data->counterText() == "2."); block = block.next(); QCOMPARE(block.layout()->lineAt(0).x(), 0.0); QVERIFY(block.userData() == 0); block = block.next(); QCOMPARE(block.layout()->lineAt(0).x(), 0.0); QVERIFY(block.userData() == 0); block = block.next(); // list item 3 data = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(data); //qDebug() << data->counterText(); QVERIFY(data->counterText() == "3."); // I have doubts what consecutiveNumbering should do. Disable the feature for now. #if 0 // now the other way around block = m_doc->begin(); listStyle.setConsecutiveNumbering(false); listStyle.applyStyle(block); m_layout->layout(); data = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(data); QVERIFY(data->counterText() == "1."); block = block.next(); data = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(data); QVERIFY(data->counterText() == "2."); block = block.next(); QCOMPARE(block.layout()->lineAt(0).x(), 0.0); QVERIFY(block.userData() == 0); block = block.next(); QCOMPARE(block.layout()->lineAt(0).x(), 0.0); QVERIFY(block.userData() == 0); block = block.next(); // list item 3 data = dynamic_cast<KoTextBlockData *>(block.userData()); QVERIFY(data); qDebug() << data->counterText(); QVERIFY(data->counterText() == "1."); #endif }