void TestDocumentLayout::noRunAroundFrame() { // With this test we want to make sure a shape that is set to not run around // will simply put the text further down. initForNewTest(loremIpsum); MockShape *picture = new MockShape(); KWFrame frame(picture, frameSet); frame.setTextRunAround(KWord::NoRunAround); picture->setSize(QSizeF(100, 100)); picture->setPosition(QPointF(0, 0)); MockLayoutState *state = new MockLayoutState(doc); layout->setLayout(state); state->shape = shape1; layout->layout(); QTextLayout *lay = doc->begin().layout(); QVERIFY(lay->lineCount() >= 4); QTextLine line = doc->begin().layout()->lineAt(0); QVERIFY(line.isValid()); double preY = line.position().y(); int linenumber=1; line = doc->begin().layout()->lineAt(linenumber); while(linenumber < lay->lineCount()) { qDebug() << line.position().y() << (preY + 14.4); QVERIFY(line.position().y() > (preY + 14.4 - ROUNDING)); preY = line.position().y(); ++linenumber; line = doc->begin().layout()->lineAt(linenumber); } }
void TestSnapStrategy::testOrhogonalDecoration() { //Making sure the decoration is created but is empty OrthogonalSnapStrategy toTestTwo; const QPointF paramMousePositionTwo(3,3); MockShapeController fakeShapeControllerBaseTwo; MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo); KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager(); MockShape fakeShapeOne; QList<QPointF> firstSnapPointList; firstSnapPointList.push_back(QPointF(1,2)); firstSnapPointList.push_back(QPointF(2,2)); firstSnapPointList.push_back(QPointF(3,2)); firstSnapPointList.push_back(QPointF(4,2)); fakeShapeOne.snapData().setSnapPoints(firstSnapPointList); fakeShapeOne.isVisible(true); fakeShapeManager->addShape(&fakeShapeOne); KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo); KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo); //Make sure at least one point in firstSnapPointList is within this distance of //paramMousePoint to trigger the branches if (dx < minHorzDist && dx < maxSnapDistance) //and if (dy < minVertDist && dy < maxSnapDistance) WHICH IS WHERE minVertDist and minHorzDist //ARE CHANGED FROM HUGE_VAL qreal paramSnapDistanceTwo = 4; toTestTwo.snap(paramMousePositionTwo, ¶mProxyTwo, paramSnapDistanceTwo); KoViewConverter irrelevantParameter; QPainterPath resultingDecoration = toTestTwo.decoration(irrelevantParameter); QVERIFY( resultingDecoration.isEmpty() ); }
KWTextFrame * TestTextFrameSorting::createFrame(const QPointF &position, KWTextFrameSet &fs) { MockShape *shape = new MockShape(); shape->setUserData(new KTextShapeData()); KWTextFrame *frame = new KWTextFrame(shape, &fs); shape->setPosition(position); return frame; }
void TestSnapStrategy::testOrthogonalSnap() { //Test case one - expected not to snap OrthogonalSnapStrategy toTest; const QPointF paramMousePosition; MockShapeController fakeShapeControllerBase; MockCanvas fakeKoCanvasBase(&fakeShapeControllerBase); //the shapeManager() function of this will be called KoSnapGuide aKoSnapGuide(&fakeKoCanvasBase); //the call that will be made to the snap guide created is m_snapGuide->canvas()->shapeManager()->shapes(); KoSnapProxy paramProxy(&aKoSnapGuide); //param proxy will have no shapes hence it will not snap qreal paramSnapDistance = 0; bool didSnap = toTest.snap(paramMousePosition, ¶mProxy, paramSnapDistance); QVERIFY(!didSnap); //Second test case - makes sure the there are shapes in the fakeShapeControllerBase thus it should snap OrthogonalSnapStrategy toTestTwo; //paramMousePosition must be within paramSnapDistance of the points in firstSnapPointList const QPointF paramMousePositionTwo(3,3); MockShapeController fakeShapeControllerBaseTwo; //This call will be made on the paramProxy: proxy->pointsFromShape(shape) which in turn //will make this call shape->snapData().snapPoints(); so the shapes have to have snapPoints //In order to have snapPoints we have to use the call //shape->snapData().setSnapPoints() for each fakeShape, where we send in a const //QList<QPointF> &snapPoints in order to have snapPoints to iterate - which is the only //way to change the value of minHorzDist and minVertDist in KoSnapStrategy.cpp so it //differs from HUGE_VAL - i.e. gives us the true value for the snap function. //creating the lists of points //example QList<QPointF> pts; pts.push_back(QPointF(0.2, 0.3)); pts.push_back(QPointF(0.5, 0.7)); MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo); //the shapeManager() function of this will be called KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager(); MockShape fakeShapeOne; QList<QPointF> firstSnapPointList; firstSnapPointList.push_back(QPointF(1,2)); firstSnapPointList.push_back(QPointF(2,2)); firstSnapPointList.push_back(QPointF(3,2)); firstSnapPointList.push_back(QPointF(4,2)); fakeShapeOne.snapData().setSnapPoints(firstSnapPointList); fakeShapeOne.isVisible(true); fakeShapeManager->addShape(&fakeShapeOne); KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo); //the call that will be made to the snap guide created is m_snapGuide->canvas()->shapeManager()->shapes(); KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo); //param proxy will have shapes now //Make sure at least one point in firstSnapPointList is within this distance of //paramMousePoint to trigger the branches if (dx < minHorzDist && dx < maxSnapDistance) //and if (dy < minVertDist && dy < maxSnapDistance) WHICH IS WHERE minVertDist and minHorzDist //ARE CHANGED FROM HUGE_VAL qreal paramSnapDistanceTwo = 4; bool didSnapTwo = toTestTwo.snap(paramMousePositionTwo, ¶mProxyTwo, paramSnapDistanceTwo); QVERIFY(didSnapTwo); }
void TestShapeContainer::testSetParent2() { MockContainerModel *model = new MockContainerModel(); MockContainer container(model); MockShape *shape = new MockShape(); shape->setParent(&container); QCOMPARE(model->shapes().count(), 1); shape->setParent(0); QCOMPARE(model->shapes().count(), 0); }
void TestDocumentLayout::placeAnchoredFrame3() { // basic inline frame that acts like a really big character initForNewTest(QString(loremIpsum)); MockShape *picture = new MockShape(); picture->setSize(QSizeF(100, 100)); KTextAnchor *anchor = new KTextAnchor(picture); anchor->setAlignment(KTextAnchor::VerticalOffset); anchor->setAlignment(KTextAnchor::HorizontalOffset); QTextCursor cursor(doc); KInlineTextObjectManager *manager = new KInlineTextObjectManager(); layout->setInlineTextObjectManager(manager); MockLayoutState *state = new MockLayoutState(doc); layout->setLayout(state); state->shape = shape1; manager->insertInlineObject(cursor, anchor); layout->layout(); /* I have two goals with 'offset'. One is that I want to be able to change the baseline of my anchored object. The other is that OOo / ODF allows me to have an arbitairy distance from my anchor so I can place something at the center of my page or whatever. So what about I switch from the first to the latter based on the font height. If my offset 'x' != 0, make the image floating. If my offset 'y' is such that it would be above or below my line; make floating. */ QTextLayout *lay = doc->begin().layout(); QVERIFY(lay->lineCount() >= 2); QTextLine line = lay->lineAt(0); QCOMPARE(line.descent(), (qreal) 100); QCOMPARE(line.position(), QPointF()); line = lay->lineAt(1); QVERIFY(line.height() < 20); // now move the character which makes it a shape to run around and no longer // a big character. anchor->setOffset(QPointF(50, 20)); layout->layout(); lay = doc->begin().layout(); QVERIFY(lay->lineCount() >= 2); line = lay->lineAt(0); QVERIFY(line.height() < 20); QCOMPARE(line.position(), QPointF()); line = lay->lineAt(1); QVERIFY(line.height() < 20); QCOMPARE(line.position().x(), 0.); QVERIFY(qAbs(line.position().y() - 14.4) < 0.125); }
void TestDocumentLayout::placeAnchoredFrame() { initForNewTest(QString()); MockShape *picture = new MockShape(); picture->setSize(QSizeF(100, 100)); KTextAnchor *anchor = new KTextAnchor(picture); anchor->setOffset(QPointF(23, 45)); QTextCursor cursor(doc); KInlineTextObjectManager *manager = new KInlineTextObjectManager(); layout->setInlineTextObjectManager(manager); MockLayoutState *state = new MockLayoutState(doc); layout->setLayout(state); state->shape = shape1; QCOMPARE(doc->begin().text().length(), 0); manager->insertInlineObject(cursor, anchor); QCOMPARE(doc->begin().text().length(), 1); QCOMPARE(cursor.position(), 1); shape1->setPosition(QPointF(300, 300)); layout->layout(); QCOMPARE(picture->parent(), shape1); QCOMPARE(picture->position(), QPointF(23, 59.4)); cursor.setPosition(0); cursor.insertText("foo"); // moves my anchors slightly to the right/down and gives line height layout->layout(); QCOMPARE(picture->parent(), shape1); QPointF newPos = picture->position(); QVERIFY(newPos.x() > 23); QVERIFY(newPos.y() > 45); // it adds the baseline now cursor.movePosition(QTextCursor::End); cursor.insertText("\nNew Line\nAnd another"); layout->layout(); QCOMPARE(picture->position(), newPos); QTextLayout *firstLineLayout = doc->begin().layout(); QTextOption option = firstLineLayout->textOption(); option.setAlignment(Qt::AlignHCenter); firstLineLayout->setTextOption(option); layout->layout(); QTextLine first = doc->begin().layout()->lineAt(0); QVERIFY(first.isValid()); QVERIFY(first.naturalTextRect().x() > 10); newPos.setX(newPos.x() + first.naturalTextRect().x()); // text is moved due to alignment QCOMPARE(picture->position(), newPos); anchor->setOffset(QPointF()); anchor->setAlignment(KTextAnchor::Left); anchor->setAlignment(KTextAnchor::TopOfParagraph); layout->layout(); // image is 100 wide, now centered in a parent of 200 so X = 50 QCOMPARE(picture->position(), QPointF(50, 0)); }
void TestShapeAnimations::initTestCase() { //Initialize Animations QTextBlockUserData *textBlockUserData = 0; for (int i = 0; i < 9; i++) { MockShape *shape = new MockShape(); shape->setSize(QSizeF(100, 100)); shapes.append(shape); MockShapeAnimation *animation = new MockShapeAnimation(shape, textBlockUserData); animation->setPresetClass(KPrShapeAnimation::Entrance); m_animation.append(animation); } }
void TestShapeAt::testShadow() { QRectF bbox(20, 30, 50, 70); MockShape shape; shape.setPosition(bbox.topLeft()); shape.setSize(bbox.size()); QCOMPARE(shape.boundingRect(), bbox); KoLineBorder *border = new KoLineBorder(); border->setLineWidth(20); // which means the shape grows 10 in all directions. shape.setBorder(border); KoInsets borderInsets; border->borderInsets(&shape, borderInsets); bbox.adjust(-borderInsets.left, -borderInsets.top, borderInsets.right, borderInsets.bottom); QCOMPARE(shape.boundingRect(), bbox); KoShapeShadow *shadow = new KoShapeShadow(); shadow->setOffset(QPointF(5, 9)); shape.setShadow(shadow); KoInsets shadowInsets; shadow->insets(&shape, shadowInsets); bbox.adjust(-shadowInsets.left, -shadowInsets.top, shadowInsets.right, shadowInsets.bottom); QCOMPARE(shape.boundingRect(), bbox); }
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)); }
void TestSnapStrategy::testNodeSnap() { //Test case one - expected to not snap NodeSnapStrategy toTest; const QPointF paramMousePos; MockShapeController fakeShapeControllerBase; MockCanvas fakeKoCanvasBase(&fakeShapeControllerBase); KoSnapGuide aKoSnapGuide(&fakeKoCanvasBase); KoSnapProxy paramProxy(&aKoSnapGuide); qreal paramSnapDistance = 0; bool didSnap = toTest.snap(paramMousePos, ¶mProxy, paramSnapDistance); QVERIFY(!didSnap); //Test case two - exercising the branches by putting a shape and snap points into the ShapeManager NodeSnapStrategy toTestTwo; const QPointF paramMousePosTwo; MockShapeController fakeShapeControllerBaseTwo; MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo); KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager(); MockShape fakeShapeOne; QList<QPointF> firstSnapPointList; firstSnapPointList.push_back(QPointF(1,2)); firstSnapPointList.push_back(QPointF(2,2)); firstSnapPointList.push_back(QPointF(3,2)); firstSnapPointList.push_back(QPointF(4,2)); qreal paramSnapDistanceTwo = 4; fakeShapeOne.snapData().setSnapPoints(firstSnapPointList); fakeShapeOne.isVisible(true); fakeShapeManager->addShape(&fakeShapeOne); KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo); KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo); bool didSnapTwo = toTestTwo.snap(paramMousePosTwo, ¶mProxyTwo, paramSnapDistanceTwo); QVERIFY(didSnapTwo); }
void TestFrames::testCopyShapes() { KWTextFrameSet *fs = new KWTextFrameSet(0, KWord::OddPagesHeaderTextFrameSet); MockShape *orig = new MockShape(); orig->setUserData(new KTextShapeData()); KWTextFrame *tf = new KWTextFrame(orig, fs); orig->setPosition(QPointF(10, 10)); KWCopyShape *copy = new KWCopyShape(orig); new KWFrame(copy, fs); copy->setPosition(QPointF(20, 100)); QCOMPARE(fs->frameCount(), 2); delete tf->shape(); // causes the first frame to be deleted. QCOMPARE(fs->frameCount(), 1); // the deletion of the orig should have caused the copy shape to be disconnected QVERIFY(copy->original() == 0); // please don't crash.. copy->outline(); }
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 TestShapeContainer::testSetParent() { MockContainerModel *model1 = new MockContainerModel(); MockContainer container1(model1); MockContainerModel *model2 = new MockContainerModel(); MockContainer container2(model2); MockShape shape; // init test QCOMPARE(model1->shapes().count(), 0); QCOMPARE(model2->shapes().count(), 0); shape.setParent(&container1); QCOMPARE(model1->shapes().count(), 1); QCOMPARE(model2->shapes().count(), 0); QCOMPARE(shape.parent(), &container1); shape.setParent(&container2); QCOMPARE(model1->shapes().count(), 0); QCOMPARE(container1.shapes().count(), 0); QCOMPARE(model2->shapes().count(), 1); QCOMPARE(container2.shapes().count(), 1); QCOMPARE(shape.parent(), &container2); }
void TestDocumentLayout::placeAnchoredFrame2() { QFETCH(int, horizontalAlignment); QFETCH(int, verticalAlignment); QFETCH(QPointF, startPosition); QFETCH(QPointF, imagePosition); initForNewTest(QString(loremIpsum)); MockShape *picture = new MockShape(); picture->setSize(QSizeF(198, 400)); KTextAnchor *anchor = new KTextAnchor(picture); anchor->setAlignment(KTextAnchor::AnchorHorizontal(horizontalAlignment)); anchor->setAlignment(KTextAnchor::AnchorVertical(verticalAlignment)); picture->setPosition(startPosition); QTextCursor cursor(doc); KInlineTextObjectManager *manager = new KInlineTextObjectManager(); layout->setInlineTextObjectManager(manager); MockLayoutState *state = new MockLayoutState(doc); layout->setLayout(state); state->shape = shape1; manager->insertInlineObject(cursor, anchor); QCOMPARE(cursor.position(), 1); layout->layout(); QCOMPARE(picture->parent(), shape1); QCOMPARE(picture->position(), imagePosition); // test if rest of text is below picture. QTextLayout *lay = doc->begin().layout(); QVERIFY(lay->lineCount() >= 1); QTextLine line = lay->lineForTextPosition(1); // the first char of real text. QVERIFY(line.isValid()); // qDebug() << line.y() << line.height(); QVERIFY(line.y() + line.height() >= 412); // test that text is below image }
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)); }
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)); } }
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! }