QList<KoShape*> PrintJob::shapesOnPage(int pageNumber) { // This method is called only for page preparation; to determine the shapes to wait for. int sheetPageNumber = pageNumber; Sheet* sheet = d->getSheetPageNumber(&sheetPageNumber); if (!sheet) return QList<KoShape*>(); const QRect cellRange = d->printManager(sheet)->cellRange(sheetPageNumber); return shapeManager()->shapesAt(sheet->cellCoordinatesToDocument(cellRange)); }
void PrintJob::printPage(int pageNumber, QPainter &painter) { kDebug(36004) << "Printing page" << pageNumber; int sheetPageNumber = pageNumber; Sheet* sheet = d->getSheetPageNumber(&sheetPageNumber); // Print the cells. if (sheet) { // Reset the offset made for shape printing. const double scale = POINT_TO_INCH(printer().resolution()); const QRect cellRange = d->printManager(sheet)->cellRange(sheetPageNumber); const QRectF pageRect = sheet->cellCoordinatesToDocument(cellRange); painter.translate(pageRect.left() * scale, pageRect.top() * scale); // Scale according to the printer's resolution. painter.scale(scale, scale); d->printManager(sheet)->printPage(sheetPageNumber, painter); } }
QRectF PrintJob::preparePage(int pageNumber) { int sheetPageNumber = pageNumber; Sheet* sheet = d->getSheetPageNumber(&sheetPageNumber); if (!sheet) return QRectF(); // Move the painter offset according to the page layout. const double scale = POINT_TO_INCH(printer().resolution()); const KoPageLayout pageLayout = sheet->printSettings()->pageLayout(); painter().translate(pageLayout.left * scale, pageLayout.top * scale); // Apply the print zoom factor, const double zoom = d->printManager(sheet)->zoom(); painter().scale(zoom, zoom); // Prepare the page for shape printing. const QRect cellRange = d->printManager(sheet)->cellRange(sheetPageNumber); QRectF pageRect = sheet->cellCoordinatesToDocument(cellRange); painter().translate(-pageRect.left() * scale, -pageRect.top() * scale); // Center the table on the page. if (sheet->printSettings()->centerHorizontally()) { const double printWidth = sheet->printSettings()->printWidth(); // FIXME respect repeated columns const double offset = 0.5 * (printWidth / zoom - pageRect.width()); painter().translate(offset * scale, 0.0); pageRect.moveLeft(offset); // scale will be applied below } if (sheet->printSettings()->centerVertically()) { const double printHeight = sheet->printSettings()->printHeight(); // FIXME respect repeated rows const double offset = 0.5 * (printHeight / zoom - pageRect.height()); painter().translate(0.0, offset * scale); pageRect.moveTop(offset); // scale will be applied below } return QRectF(pageRect.left() * scale, pageRect.top() * scale, pageRect.width() * scale, pageRect.height() * scale); }