void ChangeListLevelCommand::redo()
{
    if (!m_first) {
        KoTextCommandBase::redo();
        UndoRedoFinalizer finalizer(this);
        for (int i = 0; i < m_blocks.size(); ++i) {
            m_lists.value(i)->updateStoredList(m_blocks.at(i));
            QTextBlock currentBlock(m_blocks.at(i));
            KoTextBlockData userData(currentBlock);
            userData.setCounterWidth(-1.0);
        }
    }
    else {
        for (int i = 0; i < m_blocks.size() && m_lists.value(i); ++i) {
            if (!m_lists.value(i)->style()->hasLevelProperties(m_levels.value(i))) {
                KoListLevelProperties llp = m_lists.value(i)->style()->levelProperties(m_levels.value(i));
                if (llp.alignmentMode() == false) {
                    //old list mode, see KoListLevelProperties::alignmentMode() documentation
                    llp.setIndent((m_levels.value(i)-1) * 20); //TODO make this configurable
                } else {
                    llp.setTabStopPosition(MARGIN_DEFAULT*(m_levels.value(i)+1));
                    llp.setMargin(MARGIN_DEFAULT*(m_levels.value(i)+1));
                    llp.setTextIndent(- MARGIN_DEFAULT);
                }
                llp.setDisplayLevel(llp.displayLevel() + m_coefficient);
                llp.setLevel(m_levels.value(i));

                m_lists.value(i)->style()->setLevelProperties(llp);
            }
            m_lists.value(i)->add(m_blocks.at(i), m_levels.value(i));
        }
    }
    m_first = false;
}
Exemplo n.º 2
0
ChangeListCommand::ChangeListCommand(const QTextCursor &cursor, KoListStyle::Style style, int level,
                                     ChangeFlags flags, QUndoCommand *parent)
        : TextCommandBase(parent),
        m_flags(flags),
        m_first(true)
{
    const bool styleCompletelySetAlready = extractTextBlocks(cursor, level, style);
    QSet<int> levels = m_levels.values().toSet();
    KoListStyle listStyle;

    // If the style is already completely set, we unset it instead
    if (styleCompletelySetAlready)
        style = KoListStyle::None;

    foreach (int lev, levels) {
        KoListLevelProperties llp;
        llp.setLevel(lev);
        llp.setStyle(style);
        if (KoListStyle::isNumberingStyle(style)) {
            llp.setStartValue(1);
            llp.setListItemSuffix(".");
        }
        if (lev > 1)
            llp.setIndent((lev-1) * 20); // make this configurable

        listStyle.setLevelProperties(llp);
    }
Exemplo n.º 3
0
void TestDocumentLayout::testMultiLevel()
{
    initForNewTest("ListItem1\n");
    KoListStyle listStyle;
    KoListLevelProperties llp;
    llp.setStyle(KoListStyle::DecimalItem);
    llp.setLevel(3);
    llp.setDisplayLevel(4); // we won't show a .0 at the end so this is truncated to 3
    listStyle.setLevelProperties(llp);

    QTextBlock block = m_doc->begin();
    QVERIFY(block.isValid());
    listStyle.applyStyle(block);
    QVERIFY(block.textList());

    m_layout->layout();

    KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
    QVERIFY(data);
    QVERIFY(data->hasCounterData());
    QCOMPARE(data->counterText(), QString("1.1.1"));
}
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);
}