Esempio n. 1
0
void KWDocStructRootItem::setupTextFrameSets()
{

    // Delete Empty item from list.
    QListViewItem* lvItem = firstChild();
    if (lvItem && (lvItem->text(0) == i18n("Empty"))) delete lvItem;

    // Build a list of framesets ordered by their screen position (top left corner).
    KWDocument* dok = doc();
    QValueList<KWOrderedFrameSet> orderedFrameSets;
    for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) {
        KWFrameSet* frameset = dok->frameSet(i);
        if ( frameset->type() == FT_TEXT && frameset->frameSetInfo() == KWFrameSet::FI_BODY &&
            !frameset->groupmanager() && frameset->frameCount()>0)

            orderedFrameSets.append(KWOrderedFrameSet(frameset));
    }
    qHeapSort(orderedFrameSets);

    // Build a list of frameset pointers from the sorted list.
    QPtrList<KWTextFrameSet> frameSetPtrs;
    frameSetPtrs.setAutoDelete(false);
    for ( uint i = 0; i < orderedFrameSets.count(); i++ )
        frameSetPtrs.append(dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet()));

    // Remove deleted framesets from the listview.
    KWDocStructTextFrameSetItem* item = dynamic_cast<KWDocStructTextFrameSetItem *>(firstChild());
    KWDocStructTextFrameSetItem* delItem;
    while (item) {
        delItem = item;
        item = dynamic_cast<KWDocStructTextFrameSetItem *>(item->nextSibling());
        if (frameSetPtrs.containsRef(delItem->frameSet()) == 0) delete delItem;
    }

    // Add new framesets to the list or update existing ones.
    KWDocStructTextFrameSetItem* after = 0L;
    for ( uint i = 0; i < orderedFrameSets.count(); i++ )
    {
        KWTextFrameSet* textFrameset = dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet());
        item = findTextFrameSetItem(textFrameset);
        if (item)
            item->setText(0, textFrameset->name());
        else {
            if (after)
                item = new KWDocStructTextFrameSetItem(
                    this, after, textFrameset->name(), textFrameset);
            else
                item = new KWDocStructTextFrameSetItem(this, textFrameset->name(), textFrameset);
        }
        after = item;
        item->setupTextFrames();
    }

    if ( childCount() == 0 )
        ( void )new KListViewItem( this, i18n( "Empty" ) );
}
Esempio n. 2
0
void KWDocStructRootItem::setupArrangement()
{
    deleteAllChildren();

    QIntDict<KWDocStructParagItem> parags;
    parags.setAutoDelete( false );

    KWFrameSet* frameset = 0L;
    KWTextParag* parag = 0L;
    KoTextDocument* textdoc = 0L;

    KWDocument* dok = doc();
    KWDocStructTextFrameSetItem *item = 0L;
    QString _name;

    for ( int i = dok->frameSetCount() - 1; i >= 0; i-- )
    {
        frameset = dok->frameSet( i );
        if ( frameset->type() == FT_TEXT && frameset->frameSetInfo() == KWFrameSet::FI_BODY && !frameset->groupmanager() && frameset->frameCount()>0)
        {
            KWTextFrameSet *tmpParag = dynamic_cast<KWTextFrameSet*> (frameset) ;
            item = new KWDocStructTextFrameSetItem( this, frameset->name(), tmpParag);
            textdoc= tmpParag->textDocument();
            parag = static_cast<KWTextParag *>(textdoc->firstParag());
            while ( parag )
            {
                KoParagCounter *tmpCounter = parag->counter();
                if (tmpCounter !=0  && (tmpCounter->style() != KoParagCounter::STYLE_NONE) &&  (tmpCounter->numbering() == KoParagCounter::NUM_CHAPTER) )
                {
                    int _depth = tmpCounter->depth();
                    if ( _depth == 0 )
                    {
                        if ( item->childCount() == 0 )
                            parags.replace( _depth, new KWDocStructParagItem( item,QString( tmpCounter->text(parag) + "  " +parag->string()->toString().mid( 0, parag->string()->length() ) ),parag) );
                        else
                            parags.replace( _depth, new KWDocStructParagItem( item, parags[ _depth ],QString( tmpCounter->text(parag) + "  " +parag->string()->toString().mid( 0, parag->string()->length() ) ),parag) );
                    }
                    else
                    {
                        if (parags[ _depth - 1 ]==0)
                            parags.replace( _depth, new KWDocStructParagItem( item,QString( tmpCounter->text(parag) + "  " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) );
                        else if ( parags[ _depth - 1 ]->childCount() == 0 )
                            parags.replace( _depth, new KWDocStructParagItem( parags[ _depth - 1 ],QString( tmpCounter->text(parag) + "  " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) );
                        else
                            parags.replace( _depth, new KWDocStructParagItem( parags[ _depth - 1 ], parags[ _depth ],QString( tmpCounter->text(parag) + "  " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) );
                    }
                }
                parag = static_cast<KWTextParag *>(parag->next());
            }
        }
    }

    if ( childCount() == 0 )
        ( void )new KListViewItem( this, i18n( "Empty" ) );

}
Esempio n. 3
0
bool KWStatisticsDialog::docHasSelection()const
{
    QPtrListIterator<KWFrameSet> fsIt( m_doc->framesetsIterator() );

    for ( ; fsIt.current(); ++fsIt ) {
        KWFrameSet *fs = fsIt.current();
        if ( fs->paragraphsSelected() ) {
            return true;
        }
    }
    return false;
}
void TestPageCommands::testRemovePageCommand4() // auto remove of frames
{
    KWDocument document;
    KWPageInsertCommand insertCommand(&document, 0);
    insertCommand.redo();

    KWFrameSet *fs = new KWFrameSet();
    document.addFrameSet(fs);
    MockShape *shape1 = new MockShape();
    new KWFrame(shape1, fs);

    KWTextFrameSet *tfs = new KWTextFrameSet(&document, Words::MainTextFrameSet);
    document.addFrameSet(tfs);
    MockShape *shape2 = new MockShape();
    shape2->setUserData(new KoTextShapeData());
    new KWTextFrame(shape2, tfs);

    KWTextFrameSet *header = new KWTextFrameSet(&document, Words::EvenPagesHeaderTextFrameSet);
    document.addFrameSet(header);
    MockShape *shape3 = new MockShape();
    shape3->setUserData(new KoTextShapeData());
    new KWTextFrame(shape3, header);

    KWPageRemoveCommand command(&document, insertCommand.page());
    QCOMPARE(document.frameSetCount(), 3);
    command.redo();

    QCOMPARE(document.frameSetCount(), 2); // only the main&header framesets are left
    QVERIFY(document.frameSets().contains(tfs));
    QVERIFY(document.frameSets().contains(header));
    QCOMPARE(fs->frameCount(), 0);
    QCOMPARE(tfs->frameCount(), 0);
    QCOMPARE(header->frameCount(), 0);

    command.undo();

    QCOMPARE(document.frameSetCount(), 3);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(tfs->frameCount(), 0); // doesn't get auto-added
    QCOMPARE(header->frameCount(), 0); // doesn't get auto-added
}
Esempio n. 5
0
void KWStatisticsDialog::calcGeneral( QLabel **resultLabel )
{
    KLocale *locale = KGlobal::locale();

    resultLabel[0]->setText( locale->formatNumber( m_doc->pageCount(), 0) );
    int table =0;
    int picture = 0;
    int part = 0;
    int nbFrameset = 0;
    int nbFormula = 0;
    QPtrListIterator<KWFrameSet> framesetIt( m_doc->framesetsIterator() );
    for ( framesetIt.toFirst(); framesetIt.current(); ++framesetIt ) {
        KWFrameSet *frameSet = framesetIt.current();
        if ( frameSet && frameSet->isVisible())
        {
            if ( frameSet->type() == FT_TABLE)
                table++;
            else if ( frameSet->type() == FT_PICTURE)
                picture++;
            else if ( frameSet->type() == FT_PART )
                part++;
            else if ( frameSet->type() == FT_FORMULA )
                nbFormula++;
            nbFrameset++;
        }
    }

    resultLabel[1]->setText( locale->formatNumber( nbFrameset, 0 ) );
    resultLabel[2]->setText( locale->formatNumber( picture, 0 ) );
    resultLabel[3]->setText( locale->formatNumber( table, 0 ) );
    resultLabel[4]->setText( locale->formatNumber( part, 0 ) );
    resultLabel[5]->setText( locale->formatNumber( nbFormula, 0 ) );
}
void TestPageCommands::testInsertPageCommand() // move of frames
{
    KWDocument document;
    KWPageInsertCommand command1(&document, 0);
    QCOMPARE(document.pageCount(), 0);
    QCOMPARE(document.frameSetCount(), 0);
    command1.redo();
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 0);

    KWFrameSet *fs = new KWFrameSet();
    MockShape *shape = new MockShape();
    KWFrame *frame = new KWFrame(shape, fs);
    Q_UNUSED(frame);
    document.addFrameSet(fs);
    QPointF startPos = shape->position();

    KWPageInsertCommand command2(&document, 0);
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    command2.redo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(command2.page().pageNumber(), 1);
    QCOMPARE(command1.page().pageNumber(), 2);
    QPointF newPos = shape->position();
    QCOMPARE(newPos, QPointF(0, command2.page().height()) + startPos); // it moved ;)

    KWPageInsertCommand command3(&document, 2);
    command3.redo();
    QCOMPARE(document.pageCount(), 3);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(newPos, shape->position()); // it has not moved from page 2

    command3.undo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(newPos, shape->position()); // it has not moved from page 2
    QCOMPARE(command2.page().pageNumber(), 1);
    QCOMPARE(command1.page().pageNumber(), 2);

    command2.undo();
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(command1.page().pageNumber(), 1);
    QCOMPARE(startPos, shape->position()); // it has been moved back

    command2.redo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(command2.page().pageNumber(), 1);
    QCOMPARE(command1.page().pageNumber(), 2);
    QCOMPARE(QPointF(0, command2.page().height()) + startPos, newPos); // it moved again ;)
}
void TestPageCommands::testInsertPageCommand2() // auto remove of frames
{
    KWDocument document;
    KWFrameSet *fs = new KWFrameSet();
    document.addFrameSet(fs);
    KWTextFrameSet *tfs = new KWTextFrameSet(&document, Words::MainTextFrameSet);
    document.addFrameSet(tfs);

    KWPageInsertCommand command1(&document, 0);
    command1.redo();

    MockShape *shape1 = new MockShape();
    new KWFrame(shape1, fs);

    MockShape *shape2 = new MockShape();
    shape2->setUserData(new KoTextShapeData());
    new KWTextFrame(shape2, tfs);

    KWPageInsertCommand command2(&document, 1); // append a page
    command2.redo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 2);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(tfs->frameCount(), 1);

    // add a new frame for the page we just created.
    MockShape *shape3 = new MockShape();
    QPointF position(30, command2.page().offsetInDocument());
    shape3->setPosition(position);
    new KWTextFrame(shape3, tfs);
    QCOMPARE(tfs->frameCount(), 2);

    command2.undo(); // remove the page again.
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 2);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(tfs->frameCount(), 1); // the text frame is an auto-generated one, so it should be removed.
}
Esempio n. 8
0
void KWDocStructRootItem::setupEmbedded()
{
    deleteAllChildren();

    KWFrameSet* frameset = 0L;
    QString _name;
    KWDocStructPartItem* child;
    KWDocument* dok = doc();

    for ( int i = dok->frameSetCount() - 1; i >= 0; i-- )
    {
        frameset = dok->frameSet( i );
        if ( frameset->type() == FT_PART && frameset->frameCount()>0)
        {
            // Use the name of the frameset as the entry for the object.
            _name=frameset->name();
            child = new KWDocStructPartItem(this, _name, dynamic_cast<KWPartFrameSet*>( frameset ));
        }
    }

    if ( childCount() == 0 )
        ( void )new KListViewItem( this, i18n( "Empty" ) );
}
Esempio n. 9
0
void KWDocStructRootItem::setupPictures()
{
    deleteAllChildren();

    KWFrameSet* frameset = 0L;
    QString _name;
    KWDocStructPictureItem* child;
    KWDocument* dok = doc();

    int j = 0;
    for ( int i = dok->frameSetCount() - 1; i >= 0; i-- )
    {
        frameset = dok->frameSet( i );
        if ( frameset->type() == FT_PICTURE && frameset->frameCount()>0)
        {
            _name=i18n("Picture (%1) %2").arg(dynamic_cast<KWPictureFrameSet*>( frameset )->key().filename()).arg(++j);
            child = new KWDocStructPictureItem(this, _name, dynamic_cast<KWPictureFrameSet*>( frameset ));
        }
    }

    if ( childCount() == 0 )
        ( void )new KListViewItem( this, i18n( "Empty" ) );
}
Esempio n. 10
0
void KWDocStructRootItem::setupFormulaFrames()
{
    deleteAllChildren();

    KWFrameSet* frameset = 0L;
    QString _name;
    KWDocStructFormulaItem* child;
    KWDocument* dok = doc();

    for ( int i = dok->frameSetCount() - 1; i >= 0; i-- )
    {
        frameset = dok->frameSet( i );
        if ( frameset->type() == FT_FORMULA &&
            frameset->frameCount()>0  )
        {
            _name=i18n("Formula Frame %1").arg(QString::number(i+1));
            child = new KWDocStructFormulaItem(this, _name, dynamic_cast<KWFormulaFrameSet*>( frameset ));
        }
    }

    if ( childCount() == 0 )
        ( void )new KListViewItem( this, i18n( "Empty" ) );
}
Esempio n. 11
0
void TestPageCommands::testRemovePageCommand2() // auto remove of frames
{
    // In contrary to the insert command the remove command will remove frames
    // of all types and reinsert only non-auto-generated ones.
    // lets make sure we it does that.
    KWDocument document;
    KWFrameSet *fs = new KWFrameSet();
    document.addFrameSet(fs);
    KWTextFrameSet *tfs = new KWTextFrameSet(&document, Words::MainTextFrameSet);
    document.addFrameSet(tfs);

    KWPageInsertCommand insertCommand(&document, 0);
    insertCommand.redo();

    MockShape *shape1 = new MockShape();
    new KWFrame(shape1, fs);

    MockShape *shape2 = new MockShape();
    shape2->setUserData(new KoTextShapeData());
    new KWTextFrame(shape2, tfs);

    KWPageRemoveCommand command(&document, insertCommand.page());
    QCOMPARE(document.frameSetCount(), 2);
    command.redo();

    QCOMPARE(document.frameSetCount(), 1); // only the main frameset is left
    QCOMPARE(document.frameSets().first(), tfs);
    QCOMPARE(fs->frameCount(), 0);
    QCOMPARE(tfs->frameCount(), 0);

    command.undo();

    QCOMPARE(document.frameSetCount(), 2);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(tfs->frameCount(), 0); // doesn't get auto-added
}
Esempio n. 12
0
void TestPageCommands::testPageSpread()
{
    // setup a doc with multiple pages like;
    //   1: S1, 2: S1, 3: S1, 4: S2, 5: S1, 6:S2, 7: S2

    KWDocument document;
    KWPageManager *manager = document.pageManager();

    KWPageStyle style("pagestyle1");
    KoPageLayout lay = style.pageLayout();
    lay.width = 300;
    lay.height = 500;
    style.setPageLayout(lay);

    KWPageStyle style2("pagestyle2");
    lay = style.pageLayout();
    lay.width = 400;
    lay.height = 400;
    style2.setPageLayout(lay);
    KWPage p1 = manager->appendPage(style);
    KWPage p2 = manager->appendPage(style);
    KWPage p3 = manager->appendPage(style);
    KWPage p4 = manager->appendPage(style2);
    KWPage p5 = manager->appendPage(style);
    KWPage p6 = manager->appendPage(style2);
    KWPage p7 = manager->appendPage(style2);

    KWFrameSet *fs = new KWFrameSet();
    for (int i = 1; i <= manager->pageCount(); ++i) {
        // create one frame per page. Positioned relative to the top of the page.
        KWPage page = manager->page(i);
        QVERIFY(page.isValid());
        MockShape *shape = new MockShape();
        new KWFrame(shape, fs);
        shape->setPosition(QPointF(-10, page.offsetInDocument() + 10));
    }
    document.addFrameSet(fs);

    // when changing S1 from normal to pagespread I expect
    //  page 1 to stay the same.
    //  page 2 to become a pagespread
    //  page 3 to be deleted
    //  page 4 to stay the same.
    //  page 5 to become a page spread and gets pageNumber 6
    //  page 6 to become page 7 and become a Right page
    //  page 7 to become page 8 and become a Left page
    //  there will be a new KWPage for page 5
    // all frames to be moved so they are still at the same relative location
    // to their original page' top

    KWPageStyle style3("dummy");
    lay.leftMargin = -1;
    lay.rightMargin = -1;
    lay.pageEdge = 7;
    lay.bindingSide = 13;
    style2.setPageLayout(lay);
    KWPageStylePropertiesCommand cmd(&document, style, style3);
    cmd.redo();

    QCOMPARE(manager->pageCount(), 7);
QEXPECT_FAIL("", "Not done yet", Abort);
    QCOMPARE(p1.height(), 500.);
    QCOMPARE(p1.width(), 300.);
    QCOMPARE(p1.pageSide(), KWPage::Right);
    QCOMPARE(p1.pageNumber(), 1);
    QCOMPARE(p2.height(), 500.);
    QCOMPARE(p2.width(), 600.);
    QCOMPARE(p2.pageSide(), KWPage::PageSpread);
    QCOMPARE(p2.pageNumber(), 2);
    QVERIFY(!p3.isValid());
    QCOMPARE(p4.pageSide(), KWPage::Left);
    QCOMPARE(p4.width(), 300.);
    QCOMPARE(p4.height(), 500.);
    QCOMPARE(p4.pageNumber(), 4);
    QCOMPARE(p5.width(), 600.);
    QCOMPARE(p5.height(), 500.);
    QCOMPARE(p5.pageSide(), KWPage::PageSpread);
    QCOMPARE(p5.pageNumber(), 6);
    QCOMPARE(p6.pageSide(), KWPage::Right);
    QCOMPARE(p6.width(), 400.);
    QCOMPARE(p6.pageNumber(), 7);
    QCOMPARE(p7.pageSide(), KWPage::Left);
    QCOMPARE(p7.width(), 400.);
    QCOMPARE(p7.pageNumber(), 8);

    KWPage newPage5 = manager->page(5);
    QCOMPARE(newPage5.pageStyle(), style);
    QCOMPARE(newPage5.width(), 400.);
    QCOMPARE(newPage5.height(), 400.);
    QCOMPARE(newPage5.pageSide(), KWPage::Left);

    QCOMPARE(fs->frames()[0]->shape()->position(), QPointF(-10, 10));
    // TODO figure out what the actual numbers should be below
    QCOMPARE(fs->frames()[1]->shape()->position(), QPointF(-10, 10));
    QCOMPARE(fs->frames()[2]->shape()->position(), QPointF(-10, 10));
    QCOMPARE(fs->frames()[3]->shape()->position(), QPointF(-10, 10));
    QCOMPARE(fs->frames()[4]->shape()->position(), QPointF(-10, 10));
    QCOMPARE(fs->frames()[5]->shape()->position(), QPointF(-10, 10));
    QCOMPARE(fs->frames()[6]->shape()->position(), QPointF(-10, 10));
}
Esempio n. 13
0
void TestPageCommands::testPageStylePropertiesCommand2()
{
    /*
      make setup where multiple, interspaced pages use the style we want to change.
      add some frames.
      check if the frames moved properly when the page gets a new size
      check that all pages got their new size
      check that the name of the style did not change
    */
    KWDocument document;
    KWPageManager *manager = document.pageManager();

    KWPageStyle style("pagestyle1");
    KoPageLayout lay = style.pageLayout();
    lay.width = 300;
    lay.height = 500;
    style.setPageLayout(lay);

    KWPageStyle style2("pagestyle2");
    lay = style.pageLayout();
    lay.width = 400;
    lay.height = 400;
    style2.setPageLayout(lay);
    KWPage p1 = manager->appendPage(style2);
    KWPage p2 = manager->appendPage(style);
    KWPage p3 = manager->appendPage(style);
    KWPage p4 = manager->appendPage(style2);
    KWPage p5 = manager->appendPage(style2);
    KWPage p6 = manager->appendPage(style);
    KWPage p7 = manager->appendPage(style);
    KWPage p8 = manager->appendPage(style);
    KWPage p9 = manager->appendPage(style2);
    QCOMPARE(manager->pageCount(), 9);

    KWFrameSet *fs = new KWFrameSet();
    for (int i = 1; i <= manager->pageCount(); ++i) {
        // create one frame per page. Positioned relative to the top of the page.
        KWPage page = manager->page(i);
        QVERIFY(page.isValid());
        MockShape *shape = new MockShape();
        new KWFrame(shape, fs);
        shape->setPosition(QPointF(-10, page.offsetInDocument() + 10));
    }
    document.addFrameSet(fs);

    // lets prepare to change the style to a new page size.
    KWPageStyle newStyle("foo");
    lay = newStyle.pageLayout();
    lay.width = 350;
    lay.height = 1000;
    newStyle.setPageLayout(lay);

    KWPageStylePropertiesCommand command(&document, style, newStyle);

    // nothing happens in constructor before redo;
    for (int i = 1; i <= manager->pageCount(); ++i) {
        KWPage page = manager->page(i);
        QVERIFY(page.height() <= 500); // not 1000 yet
        QVERIFY(page.isValid());
        KoShape *shape = fs->frames().at(i-1)->shape();
        QCOMPARE(shape->position(), QPointF(-10, page.offsetInDocument() + 10));
    }

    const qreal lastPageOffset = p9.offsetInDocument();

    command.redo();
    QCOMPARE(manager->pageCount(), 9);
    QCOMPARE(p1.height(), 400.);
    QCOMPARE(p4.height(), 400.);
    QCOMPARE(p5.height(), 400.);
    QCOMPARE(p9.height(), 400.);
    QCOMPARE(p2.height(), 1000.);
    QCOMPARE(p3.height(), 1000.);
    QCOMPARE(p6.height(), 1000.);
    QCOMPARE(p7.height(), 1000.);
    QCOMPARE(p8.height(), 1000.);
    QCOMPARE(lastPageOffset + 2500, p9.offsetInDocument());
    for (int i = 1; i <= manager->pageCount(); ++i) {
        KWPage page = manager->page(i);
        QVERIFY(page.isValid());
        KoShape *shape = fs->frames().at(i-1)->shape();
        QCOMPARE(shape->position(), QPointF(-10, page.offsetInDocument() + 10));
    }
}
Esempio n. 14
0
void TestPageCommands::testRemovePageCommand() // move of frames
{
    KWDocument document;
    KWPageInsertCommand insertCommand(&document, 0);
    insertCommand.redo();

    KWFrameSet *fs = new KWFrameSet();
    MockShape *shape = new MockShape();
    KWFrame *frame = new KWFrame(shape, fs);
    Q_UNUSED(frame);
    document.addFrameSet(fs);
    KWPageInsertCommand insertCommand2(&document, 1);
    insertCommand2.redo();
    MockShape *shape2 = new MockShape();
    QPointF pos = QPointF(20, insertCommand2.page().offsetInDocument() + 10);
    shape2->setPosition(pos);
    KWFrame *frame2 = new KWFrame(shape2, fs);
    Q_UNUSED(frame2);
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 2);

    // remove page2
    KWPageRemoveCommand command1(&document, insertCommand2.page());
    command1.redo();

    QCOMPARE(insertCommand.page().pageNumber(), 1);
    QCOMPARE(insertCommand2.page().isValid(), false);

    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);

    QCOMPARE(shape2->position(), pos); // shapes are not deleted, just removed from the document

    command1.undo();
    QCOMPARE(insertCommand.page().pageNumber(), 1);
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 2);

    QCOMPARE(shape2->position(), pos); // not moved.

    // remove page 1
    KWPageRemoveCommand command2(&document, insertCommand.page());
    command2.redo();

    QCOMPARE(insertCommand.page().isValid(), false);
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);

    QCOMPARE(shape->position(), QPointF(0,0));
    QCOMPARE(shape2->position(), QPointF(20, 10)); // moved!

    command2.undo();

    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 2);
    QCOMPARE(shape->position(), QPointF(0,0));
    QCOMPARE(shape2->position(), pos); // moved back!
}
Esempio n. 15
0
void KWFrameViewTester::testGetView() {
    TestFrameViewManager fvm;
    KWFrameSet *fs = new TestFrameSet();
    KWFrame *frame = new KWFrame(fs, 0, 0, 100, 100);
    fs->addFrame(frame);

    fvm.slotFrameAdded(frame);
    KWFrameView *fv = fvm.view(frame);
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame);

    fv = fvm.view( KoPoint(0,0), KWFrameViewManager::frameOnTop);
    CHECK(fv != 0, true); // should exist
    if(!fv) return;
    CHECK(fv->frame(), frame);

    fv = fvm.view( KoPoint(1,1), KWFrameViewManager::frameOnTop);
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame);

    fv = fvm.view( KoPoint(110,110), KWFrameViewManager::frameOnTop);
    CHECK(fv == 0, true);

    fv = fvm.view( KoPoint(100,100), KWFrameViewManager::frameOnTop); // note that 100,100 _is_ inside 0,0 100x100
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame);

    fv->setSelected(true);
    fv = fvm.view( KoPoint(1,1), KWFrameViewManager::unselected);
    CHECK(fv == 0, true);

    frame->setZOrder(4);
    KWFrame *frame2 = new KWFrame(fs, 80, 50, 60, 60);
    frame2->setZOrder(2);
    fvm.slotFrameAdded(frame2);
    KWFrame *frame3 = new KWFrame(fs, 30, 60, 60, 60);
    frame3->setZOrder(5);
    fvm.slotFrameAdded(frame3);
    KWFrame *frame4 = new KWFrame(fs, 200, 0, 100, 100);
    fvm.slotFrameAdded(frame4);
    frame4->setZOrder(1);

kdDebug() << "frame:" << frame << ", frame2:" << frame2<< ", frame2:" << frame3<< ", frame2:" << frame4 << endl;
    fv = fvm.view( KoPoint(90,60), KWFrameViewManager::frameOnTop);
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame3);
    fv = fvm.view( KoPoint(90,60), KWFrameViewManager::frameOnTop); // second time should give the same results
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame3);
    fv = fvm.view( KoPoint(90,60), KWFrameViewManager::selected);
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame);
    fv = fvm.view( KoPoint(90,60), KWFrameViewManager::selected); // second time should give the same results
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame);

    fv = fvm.view( KoPoint(90,60), KWFrameViewManager::nextUnselected);
    CHECK(fv != 0, true);
    if(!fv) return;
    CHECK(fv->frame(), frame2); // the one directly below the selected frame
}
Esempio n. 16
0
bool KWStatisticsDialog::calcStats( QLabel **resultLabel, bool selection, bool useFootEndNote  )
{
    ulong charsWithSpace = 0L;
    ulong charsWithoutSpace = 0L;
    ulong words = 0L;
    ulong sentences = 0L;
    ulong lines = 0L;
    ulong syllables = 0L;

    // safety check result labels
    for (int i=0; i < 7; ++i) {
        if ( !resultLabel[i] ) {
            kdDebug() << "Warning: KWStatisticsDiaolog::calcStats result table not initialized." << endl;
            return false;
        }
    }

    // count paragraphs for progress dialog:
    ulong paragraphs = 0L;
    QPtrListIterator<KWFrameSet> framesetIt( m_doc->framesetsIterator() );
    for ( framesetIt.toFirst(); framesetIt.current(); ++framesetIt ) {
        KWFrameSet *frameSet = framesetIt.current();
        if ( (frameSet->frameSetInfo() == KWFrameSet::FI_FOOTNOTE || frameSet->frameSetInfo() == KWFrameSet::FI_BODY) && frameSet->isVisible() )
        {
            if ( (useFootEndNote && frameSet->frameSetInfo() == KWFrameSet::FI_FOOTNOTE) ||
                    frameSet->frameSetInfo() == KWFrameSet::FI_BODY ) {
                paragraphs += frameSet->paragraphs();
            }
        }
    }
    QProgressDialog progress( i18n( "Counting..." ), i18n( "Cancel" ), paragraphs, this, "count", true );
    progress.setMinimumDuration( 1000 );
    progress.setProgress( 0 );

    // do the actual counting
    for ( framesetIt.toFirst(); framesetIt.current(); ++framesetIt ) {
        KWFrameSet *frameSet = framesetIt.current();
        // Exclude headers and footers
        if ( (frameSet->frameSetInfo() == KWFrameSet::FI_FOOTNOTE || frameSet->frameSetInfo() == KWFrameSet::FI_BODY) && frameSet->isVisible() ) {
            if ( (useFootEndNote && frameSet->frameSetInfo() == KWFrameSet::FI_FOOTNOTE) || frameSet->frameSetInfo() == KWFrameSet::FI_BODY )
            {

                if( ! frameSet->statistics( &progress, charsWithSpace, charsWithoutSpace,
                                            words, sentences, syllables, lines, selection ) ) {
                    // someone pressed "Cancel"
                    return false;
                }
            }
        }
    }

    // assign results
    KLocale *locale = KGlobal::locale();
    resultLabel[0]->setText( locale->formatNumber( charsWithSpace, 0) );
    resultLabel[1]->setText( locale->formatNumber( charsWithoutSpace, 0 ) );
    resultLabel[2]->setText( locale->formatNumber( syllables, 0 ) );
    resultLabel[3]->setText( locale->formatNumber( words, 0 ) );
    resultLabel[4]->setText( locale->formatNumber( sentences, 0 ) );
    resultLabel[5]->setText( locale->formatNumber( lines, 0 ) );
    // add flesch
    double f = calcFlesch( sentences, words, syllables );
    QString flesch = locale->formatNumber( f , 1 );
    if( words < 200 ) {
        // a kind of warning if too few words:
        flesch = i18n("approximately %1").arg( flesch );
    }
    resultLabel[6]->setText( flesch );
    return true;
}