void KWGui::pageSetupChanged() { const KWPageManager *pm = m_view->kwdocument()->pageManager(); const KWPage firstPage = pm->begin(); const KWPage lastPage = pm->last(); int height = 0; if (lastPage.isValid()) height = lastPage.offsetInDocument() + lastPage.height(); m_verticalRuler->setRulerLength(height); updateRulers(); int width = 0; if (firstPage.isValid()) width = firstPage.width(); m_horizontalRuler->setRulerLength(width); m_horizontalRuler->setActiveRange(0, width); m_verticalRuler->setActiveRange(0, height); updateRulers(); }
void TestTextFrameSorting::testSortingOnPagespread() { KWTextFrameSet tfs(0); KWFrame * frame1 = createFrame(QPointF(10, 200), tfs); KWFrame * frame2 = createFrame(QPointF(120, 10), tfs); KWFrame * frame3 = createFrame(QPointF(10, 10), tfs); KWFrame * frame4 = createFrame(QPointF(340, 10), tfs); KWFrame * frame5 = createFrame(QPointF(230, 10), tfs); KWPageManager pm; KWPage page = pm.appendPage(); page.setPageNumber(2); KOdfPageLayoutData layout = page.pageStyle().pageLayout(); layout.width = 450; layout.height = 150; page.setDirectionHint(KOdfText::LeftRightTopBottom); page.setPageSide(KWPage::PageSpread); page.pageStyle().setPageLayout(layout); page = pm.appendPage(); page.setDirectionHint(KOdfText::LeftRightTopBottom); layout.width = 200; page.pageStyle().setPageLayout(layout); tfs.setPageManager(&pm); QCOMPARE(page.offsetInDocument(), 150.); // test KWPageManager::pageNumber first QCOMPARE(pm.begin().pageNumber(), 2); QCOMPARE(pm.pageNumber(frame2->shape()), 2); QCOMPARE(pm.pageNumber(frame1->shape()), 4); QCOMPARE(KWTextFrameSet::sortTextFrames(frame4, frame5), false); QCOMPARE(KWTextFrameSet::sortTextFrames(frame5, frame4), true); QCOMPARE(KWTextFrameSet::sortTextFrames(frame2, frame4), true); QCOMPARE(KWTextFrameSet::sortTextFrames(frame1, frame4), false); qSort(tfs.m_frames.begin(), tfs.m_frames.end(), KWTextFrameSet::sortTextFrames); QCOMPARE(tfs.m_frames[0], frame3); QCOMPARE(tfs.m_frames[1], frame2); QCOMPARE(tfs.m_frames[2], frame5); QCOMPARE(tfs.m_frames[3], frame4); QCOMPARE(tfs.m_frames[4], frame1); }
void KWFrameGeometry::open(KShape *shape) { KWPage page = m_state->document()->pageManager()->page(shape); m_topOfPage = page.offsetInDocument(); m_originalPosition = shape->position(); m_originalSize = shape->size(); QPointF position = shape->absolutePosition(widget.positionSelector->position()); widget.xPos->changeValue(position.x()); widget.yPos->changeValue(position.y() - m_topOfPage); widget.width->changeValue(m_originalSize.width()); widget.height->changeValue(m_originalSize.height()); if (m_frame == 0) { // default values for new frames widget.leftMargin->changeValue(MM_TO_POINT(3)); widget.rightMargin->changeValue(MM_TO_POINT(3)); widget.topMargin->changeValue(MM_TO_POINT(3)); widget.bottomMargin->changeValue(MM_TO_POINT(3)); } connect(widget.protectSize, SIGNAL(stateChanged(int)), this, SLOT(protectSizeChanged(int))); m_originalGeometryLock = shape->isGeometryProtected(); if (m_originalGeometryLock) { widget.protectSize->setCheckState(Qt::Checked); KWTextFrame *tf = dynamic_cast<KWTextFrame*>(shape->applicationData()); if (tf && static_cast<KWTextFrameSet*>(tf->frameSet())->textFrameSetType() != KWord::OtherTextFrameSet) widget.protectSize->setEnabled(false); // auto-generated frame, can't edit } connect(widget.xPos, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); connect(widget.yPos, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); connect(widget.width, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); connect(widget.height, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); }
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)); } }