本文整理汇总了C++中KWDocument类的典型用法代码示例。如果您正苦于以下问题:C++ KWDocument类的具体用法?C++ KWDocument怎么用?C++ KWDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KWDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deleteAllChildren
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" ) );
}
示例2: firstChild
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" ) );
}
示例3: KoTextCustomItem
KWTextImage::KWTextImage( KWTextDocument *textdoc, const QString & filename )
: KoTextCustomItem( textdoc ), place( PlaceInline )
{
KWDocument * doc = textdoc->textFrameSet()->kWordDocument();
if ( !filename.isEmpty() )
{
m_image = doc->pictureCollection()->loadPicture( filename );
Q_ASSERT( !m_image.isNull() );
resize(); // Zoom if necessary
}
}
示例4: strcmp
KParts::Part* KWFactory::createPartObject( QWidget *parentWidget, const char *widname, QObject* parent, const char* name, const char* classname, const QStringList & )
{
bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 );
KWDocument *doc = new KWDocument( parentWidget, widname, parent, name, !bWantKoDocument );
if ( !bWantKoDocument )
doc->setReadWrite( false );
return doc;
}
示例5: save
void KWTextImage::save( QDomElement & parentElem )
{
// This code is similar to KWPictureFrameSet::save
KWDocument * doc = static_cast<KWTextDocument *>(parent)->textFrameSet()->kWordDocument();
QDomElement imageElem = parentElem.ownerDocument().createElement( "PICTURE" );
parentElem.appendChild( imageElem );
//imageElem.setAttribute( "keepAspectRatio", "true" );
QDomElement elem = parentElem.ownerDocument().createElement( "KEY" );
imageElem.appendChild( elem );
image().getKey().saveAttributes( elem );
// Now we must take care that a <KEY> element will be written as a child of <PICTURES>
doc->addTextImageRequest( this );
}
示例6: testNewPageStyleCommand
void TestPageCommands::testNewPageStyleCommand()
{
KWDocument document;
KWPageManager *manager = document.pageManager();
KWPageStyle style("pagestyle1");
KWNewPageStyleCommand cmd(&document, style);
QCOMPARE(manager->pageStyle("pagestyle1").isValid(), false);
cmd.redo();
QVERIFY(manager->pageStyle("pagestyle1").isValid());
QCOMPARE(manager->pageStyle("pagestyle1"), style);
cmd.undo();
QCOMPARE(manager->pageStyle("pagestyle1").isValid(), false);
}
示例7: testClipToPage
void TestClipToPage::testClipToPage()
{
KWDocument doc;
KWPage page1 = doc.appendPage("Standard");
KOdfPageLayoutData layout = page1.pageStyle().pageLayout();
layout.width = 300;
layout.height = 410;
page1.pageStyle().setPageLayout(layout);
KWCanvas canvas("bla", &doc, 0, 0);
MockShape shape;
shape.setPosition(QPointF(50, 50));
shape.setSize(QSizeF(100, 100));
QPointF distance(0, 0);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(0, 0));
distance = QPointF(-200, -500);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(-145, -145));
distance = QPointF(1000, 2000);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(245, 355));
distance = QPointF(50, 50);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(50, 50));
// test when we start outside the page
shape.setPosition(QPointF(-200, -100));
distance = QPointF(0, 0);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(105, 5));
distance = QPointF(120, 120);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(120, 120));
shape.setPosition(QPointF(400, 200));
distance = QPointF(0, 0);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(-105, 0));
distance = QPointF(-110, -50);
canvas.clipToDocument(&shape, distance);
QCOMPARE(distance, QPointF(-110, -50));
}
示例8: while
void KWDocStructTextFrameSetItem::setupTextFrames()
{
// TODO: KWTextFrameSet::frame() method returns frames in screen order?
// Build a list of frame pointers.
QPtrList<KWFrame> framePtrs;
framePtrs.setAutoDelete(false);
for (uint j = 0; j < m_frameset->frameCount(); j++)
framePtrs.append(m_frameset->frame(j));
// Remove deleted frames from the listview.
KWDocStructTextFrameItem* item = dynamic_cast<KWDocStructTextFrameItem *>(firstChild());
KWDocStructTextFrameItem* delItem;
while (item) {
delItem = item;
item = dynamic_cast<KWDocStructTextFrameItem *>(item->nextSibling());
if (framePtrs.containsRef(delItem->frame()) == 0) delete delItem;
}
// Add new frames to the list or update existing ones.
KWDocument* dok = doc();
KWDocStructTextFrameItem* after = 0;
for (uint j = 0; j < framePtrs.count(); j++)
{
KWFrame* frame = framePtrs.at(j);
QString name;
if ( KListViewItem::parent()->firstChild() == this && dok->processingType() == KWDocument::WP )
{
if ( dok->numColumns() == 1 )
name=i18n( "Page %1" ).arg(QString::number(j + 1));
else
name=i18n( "Column %1" ).arg(QString::number(j + 1));
}
else
name=i18n( "Text Frame %1" ).arg(QString::number(j + 1));
KWDocStructTextFrameItem* child = findTextFrameItem(frame);
if (child)
child->setText(0, name);
else {
if (after)
child = new KWDocStructTextFrameItem(this, after, name, m_frameset, frame);
else
child = new KWDocStructTextFrameItem(this, name, m_frameset, frame);
}
child->setupTextParags();
after = child;
}
}
示例9: insertCommand
void TestPageCommands::testRemovePageCommand3() // test restore all properties
{
KWDocument document;
KWPageInsertCommand insertCommand(&document, 0);
insertCommand.redo();
KWPage page = insertCommand.page();
KWPageStyle style = page.pageStyle();
style.setHasMainTextFrame(false);
style.setFootnoteDistance(10);
KoPageLayout layout;
layout.width = 400;
layout.height = 300;
layout.leftMargin = 4;
layout.rightMargin = 6;
layout.topMargin = 7;
layout.bottomMargin = 5;
style.setPageLayout(layout);
page.setPageStyle(style);
KWPageRemoveCommand command(&document, page);
command.redo();
QVERIFY(!page.isValid());
command.undo();
page = document.pageManager()->begin();
QVERIFY(page.isValid());
QVERIFY(insertCommand.page() != page);
QCOMPARE(page.pageNumber(), 1);
KWPageStyle style2 = page.pageStyle();
QCOMPARE(style2, style);
QCOMPARE(style2.hasMainTextFrame(), false);
QCOMPARE(style2.footnoteDistance(), 10.);
KoPageLayout layout2 = style2.pageLayout();
QCOMPARE(layout2, layout);
QCOMPARE(page.pageStyle(), style);
QCOMPARE(page.width(), 400.);
}
示例10: load
void KWTextImage::load( QDomElement & parentElem )
{
// This code is similar to KWPictureFrameSet::load
KWDocument * doc = static_cast<KWTextDocument *>(parent)->textFrameSet()->kWordDocument();
// <IMAGE> (KOffice 1.0) or <PICTURE> (KWord 1.2)
QDomNode node=parentElem.namedItem( "PICTURE" );
if ( node.isNull() )
{
node=parentElem.namedItem( "IMAGE" );
}
QDomElement image = node.toElement();
if ( image.isNull() )
image = parentElem; // The data is directly child of <FORMAT>
// <KEY>
QDomElement keyElement = image.namedItem( "KEY" ).toElement();
if ( !keyElement.isNull() )
{
KoPictureKey key;
key.loadAttributes( keyElement );
m_image.setKey(key);
doc->addTextImageRequest( this );
}
else
{
// <FILENAME> (old format, up to KWord-1.1-beta2)
QDomElement filenameElement = image.namedItem( "FILENAME" ).toElement();
if ( !filenameElement.isNull() )
{
QString filename = filenameElement.attribute( "value" );
m_image.setKey( KoPictureKey( filename ) );
doc->addTextImageRequest( this );
}
else
{
kdError(32001) << "Missing KEY or FILENAME tag in IMAGE (KWTextImage::load)" << endl;
}
}
}
示例11: KWFrame
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.
}
示例12: testPageSpread
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));
}
示例13: style
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));
}
}
示例14: testPageStylePropertiesCommand
void TestPageCommands::testPageStylePropertiesCommand() // basic properties change
{
KWDocument document;
KWPageManager *manager = document.pageManager();
KWPageStyle style("pagestyle1");
KoPageLayout oldLayout;
oldLayout.format = KoPageFormat::IsoA4Size;
oldLayout.width = 101;
oldLayout.height = 102;
oldLayout.leftMargin = -1;
oldLayout.rightMargin = -1;
oldLayout.pageEdge = 7;
oldLayout.bindingSide = 13;
style.setPageLayout(oldLayout);
KoColumns oldColumns;
oldColumns.count = 4;
oldColumns.gapWidth = 21;
style.setColumns(oldColumns);
KWPage page1 = manager->appendPage(style);
page1.setDirectionHint(KoText::LeftRightTopBottom);
QCOMPARE(page1.pageNumber(), 1);
QCOMPARE(page1.width(), 101.);
QCOMPARE(page1.height(), 102.);
QCOMPARE(page1.leftMargin(), 13.); // its a right-sided page
QCOMPARE(page1.pageEdgeMargin(), 7.);
QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);
QCOMPARE(page1.pageStyle().columns().count, 4);
QCOMPARE(page1.pageSide(), KWPage::Right);
// new ;)
KWPageStyle style2("pagestyle2");
KoPageLayout newLayout;
newLayout.width = 401;
newLayout.height = 405;
newLayout.leftMargin = 11;
newLayout.rightMargin = 18;
newLayout.pageEdge = -1;
newLayout.bindingSide = -1;
style2.setPageLayout(newLayout);
KoColumns newColumns;
newColumns.count = 2;
newColumns.columnData.append(ColumnDatum(1.0, 2.0, 1.0, 1.0, 25));
newColumns.columnData.append(ColumnDatum(1.0, 1.0, 1.0, 1.0, 50));
style2.setColumns(newColumns);
style2.setDirection(KoText::RightLeftTopBottom);
KWPageStylePropertiesCommand command1(&document, style, style2);
// nothing changed before the redo
QCOMPARE(page1.width(), 101.);
QCOMPARE(page1.height(), 102.);
QCOMPARE(page1.leftMargin(), 13.); // its a right-sided page
QCOMPARE(page1.pageEdgeMargin(), 7.);
QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);
// redo
command1.redo();
QCOMPARE(page1.pageStyle().name(), QString("pagestyle1")); // name didn't change
QCOMPARE(page1.width(), 401.);
QCOMPARE(page1.height(), 405.);
QCOMPARE(page1.leftMargin(), 11.);
QCOMPARE(page1.pageEdgeMargin(), -1.); // its a right-sided page
QCOMPARE(page1.pageStyle().direction(), KoText::RightLeftTopBottom);
QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);
page1.setDirectionHint(KoText::InheritDirection); // reset to what the style says
QCOMPARE(page1.directionHint(), KoText::RightLeftTopBottom);
QCOMPARE(style.pageLayout().width, 401.); // style changed
QCOMPARE(page1.pageStyle().columns().count, 2);
QCOMPARE(page1.pageNumber(), 1);
QCOMPARE(page1.pageSide(), KWPage::Right);
QCOMPARE(manager->pageCount(), 1);
QVERIFY(manager->page(1).isValid());
QVERIFY(!manager->page(2).isValid());
KWPage page2 = manager->appendPage(style);
QCOMPARE(manager->pageCount(), 2);
QVERIFY(manager->page(1).isValid());
QVERIFY(manager->page(2).isValid());
QVERIFY(!manager->page(3).isValid());
QCOMPARE(page2.pageNumber(), 2);
QCOMPARE(page2.pageSide(), KWPage::Left);
// undo
command1.undo();
QCOMPARE(page1.pageStyle().name(), QString("pagestyle1")); // name didn't change
QCOMPARE(page1.width(), 101.);
QCOMPARE(page1.height(), 102.);
QCOMPARE(page1.leftMargin(), 13.);
QCOMPARE(page1.directionHint(), KoText::AutoDirection);
QCOMPARE(style.pageLayout().width, 101.);
QCOMPARE(page1.pageStyle().columns().count, 4);
QCOMPARE(page1.pageNumber(), 1);
QCOMPARE(page1.pageSide(), KWPage::Right);
QCOMPARE(manager->pageCount(), 2);
QVERIFY(manager->page(1).isValid());
QVERIFY(manager->page(2).isValid());
//.........这里部分代码省略.........
示例15: documentPages
void TestPageCommands::documentPages()
{
KWDocument document;
QCOMPARE(document.pageCount(), 0);
KWPage page1 = document.appendPage("pagestyle1");
QVERIFY(page1.isValid());
QCOMPARE(page1.pageStyle().name(), QString("Standard")); // doesn't auto-create styles
QCOMPARE(page1.pageNumber(), 1);
KWPage page2 = document.appendPage("pagestyle1");
QVERIFY(page2.isValid());
QCOMPARE(page2.pageStyle().name(), QString("Standard"));
QCOMPARE(page2.pageNumber(), 2);
KWPage page3 = document.appendPage("pagestyle2");
QCOMPARE(page3.pageStyle().name(), QString("Standard"));
QCOMPARE(page3.pageNumber(), 3);
KWPage page4 = document.appendPage("pagestyle2");
QCOMPARE(page4.pageStyle().name(), QString("Standard"));
QCOMPARE(page4.pageNumber(), 4);
KWPage page5 = document.insertPage(-99);
QVERIFY(page5.isValid());
QCOMPARE(page5.pageNumber(), 5);
KWPage page6 = document.insertPage(99);
QVERIFY(page6.isValid());
QCOMPARE(page6.pageNumber(), 6);
KWPage page7 = document.appendPage("pagestyle2");
QVERIFY(page7.isValid());
QCOMPARE(page7.pageNumber(), 7);
KWPage page8 = document.appendPage("pagestyle1");
QVERIFY(page8.isValid());
QCOMPARE(page8.pageNumber(), 8);
KWPage page9 = document.appendPage();
QCOMPARE(page9.pageNumber(), 9);
QCOMPARE(document.pageCount(), 9);
document.removePage(3);
QCOMPARE(document.pageCount(), 8);
QVERIFY(! page3.isValid());
QCOMPARE(document.pageManager()->page(2), page2);
QCOMPARE(document.pageManager()->page(5), page6);
document.removePage(3);
QVERIFY(! page3.isValid());
QVERIFY(! page4.isValid());
QCOMPARE(document.pageCount(), 7);
QCOMPARE(document.pageManager()->page(2), page2);
QCOMPARE(document.pageManager()->page(4), page6);
page4 = document.insertPage(2); // kwdocument uses 'after' instead of 'as' that the pageManager uses
QCOMPARE(page4.pageNumber(), 3);
page3 = document.insertPage(2);
QCOMPARE(page3.pageNumber(), 3);
QCOMPARE(page4.pageNumber(), 4);
QCOMPARE(document.pageManager()->page(2), page2);
QCOMPARE(document.pageManager()->page(3), page3);
QCOMPARE(document.pageManager()->page(4), page4);
QCOMPARE(document.pageManager()->page(5), page5);
document.removePage(-16);
document.removePage(16);
QCOMPARE(document.pageCount(), 9);
for (int i = document.pageCount() - 1; i >= 1; --i)
document.removePage(1);
QCOMPARE(document.pageCount(), 1);
QCOMPARE(document.pageManager()->page(1), page9);
QCOMPARE(document.pageCount(), 1);
document.removePage(1); //we can't remove the last page
QCOMPARE(document.pageCount(), 1);
}