void TestStyleManager::testAddRemoveParagraphStyle()
{
    // Add paragraph style.
    KoParagraphStyle paragraphStyle;
    paragraphStyle.setName("Test Paragraph Style");
    QSignalSpy addSignalSpy(m_styleManager, SIGNAL(styleAdded(KoParagraphStyle*)));
    m_styleManager->beginEdit();
    m_styleManager->add(&paragraphStyle);
    m_styleManager->endEdit();
    QVERIFY(paragraphStyle.styleId() > 0);
    QVERIFY(!m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId()));
    QCOMPARE(m_styleManager->paragraphStyles().count(&paragraphStyle), 1);
    QCOMPARE(m_styleManager->paragraphStyle(paragraphStyle.styleId()), &paragraphStyle);
    QCOMPARE(m_styleManager->paragraphStyle("Test Paragraph Style"), &paragraphStyle);
    QCOMPARE(addSignalSpy.count(), 1);
    QCOMPARE(addSignalSpy.at(0).at(0).value<KoParagraphStyle *>(), &paragraphStyle);

    // Remove paragraph style.
    QSignalSpy removeSignalSpy(m_styleManager, SIGNAL(styleRemoved(KoParagraphStyle*)));
    m_styleManager->beginEdit();
    m_styleManager->remove(&paragraphStyle);
    m_styleManager->endEdit();
    QVERIFY(!m_styleManager->paragraphStyles().contains(&paragraphStyle));
    QVERIFY(!m_styleManager->paragraphStyle(paragraphStyle.styleId()));
    QVERIFY(!m_styleManager->paragraphStyle("Test Paragraph Style"));
    QCOMPARE(removeSignalSpy.count(), 1);
    QCOMPARE(removeSignalSpy.at(0).at(0).value<KoParagraphStyle *>(), &paragraphStyle);
}
Exemple #2
0
void NewStyleWidget::createButtonPressed()
{
    if (widget.character->isChecked()) {
        KoCharacterStyle *style = new KoCharacterStyle();
        style->setName(widget.name->text());
        emit newCharacterStyle(style);
    } else {
        KoParagraphStyle *style = new KoParagraphStyle();
        style->setName(widget.name->text());
        emit newParagraphStyle(style);
    }
}
Exemple #3
0
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);
}