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 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)); } }
QImage TextContentsModelImpl::thumbnail(int index, int width) const { KWPage page = d->document->pageManager()->page( index + 1 ); return page.thumbnail(QSize{ width, int((page.height() / page.width()) * width)}, d->canvas->shapeManager()); }