void TableShape::setRows(int rows) { Q_ASSERT(rows > 0); if(!sheet()) return; const double factor = (double) d->rows / rows; d->rows = rows; d->adjustRowDimensions(qobject_cast<Sheet*>(KoShape::userData()), factor); setVisibleCellRange(QRect(1, 1, d->columns, d->rows)); d->sheetView->invalidate(); if (!d->pageManager) { return; } PrintSettings settings = *sheet()->printSettings(); settings.setPrintRegion(Region(1, 1, d->columns, d->rows, sheet())); d->pageManager->setPrintSettings(settings); }
void SheetPrint::removeRow(int row, int nbRow) { PrintSettings settings = *d->m_settings; //update print range, when it has been defined const QRect printRange = d->m_settings->printRegion().lastRange(); if (printRange != QRect(QPoint(1, 1), QPoint(KS_colMax, KS_rowMax))) { int top = printRange.top(); int bottom = printRange.bottom(); for (int i = 0; i < nbRow; i++) { if (top > row) top--; if (bottom >= row) bottom--; } //Validity checks if (top < 1) top = 1; if (bottom < 1) bottom = 1; const Region region(QRect(QPoint(printRange.left(), top), QPoint(printRange.right(), bottom)), d->m_pSheet); settings.setPrintRegion(region); } //update repeat rows, when it has been defined const QPair<int, int> repeatedRows = d->m_settings->repeatedRows(); if (repeatedRows.first != 0) { int top = repeatedRows.first; int bottom = repeatedRows.second; for (int i = 0; i < nbRow; i++) { if (top > row) top--; if (bottom >= row) bottom--; } //Validity checks if (top < 1) top = 1; if (bottom < 1) bottom = 1; settings.setRepeatedRows(qMakePair(top, bottom)); } // Trigger an update by setting them indirectly. setSettings(settings); }
void SheetPrint::removeColumn(int col, int nbCol) { PrintSettings settings = *d->m_settings; //update print range, when it has been defined const QRect printRange = d->m_settings->printRegion().lastRange(); if (printRange != QRect(QPoint(1, 1), QPoint(KS_colMax, KS_rowMax))) { int left = printRange.left(); int right = printRange.right(); for (int i = 0; i < nbCol; i++) { if (left > col) left--; if (right >= col) right--; } //Validity checks if (left < 1) left = 1; if (right < 1) right = 1; const Region region(QRect(QPoint(left, printRange.top()), QPoint(right, printRange.bottom())), d->m_pSheet); settings.setPrintRegion(region); } //update repeat columns, when it has been defined const QPair<int, int> repeatedColumns = d->m_settings->repeatedColumns(); if (repeatedColumns.first != 0) { int left = repeatedColumns.first; int right = repeatedColumns.second; for (int i = 0; i < nbCol; i++) { if (left > col) left--; if (right >= col) right--; } //Validity checks if (left < 1) left = 1; if (right < 1) right = 1; settings.setRepeatedColumns(qMakePair(left, right)); } // Trigger an update by setting them indirectly. setSettings(settings); }
int PrintJob::Private::setupPages(const QPrinter& printer, bool forceRecreation) { // Create the list of sheet, that should be printed. selectedSheets.clear(); if (printer.printRange() == QPrinter::Selection) selectedSheets.append(view->activeSheet()); else if (sheetSelectPage->allSheetsButton->isChecked()) selectedSheets = view->doc()->map()->sheetList(); else if (sheetSelectPage->activeSheetButton->isChecked()) selectedSheets.append(view->activeSheet()); else if (sheetSelectPage->selectedSheetsButton->isChecked()) { const QStringList sheetNames = sheetSelectPage->selectedSheets(); for (int i = 0; i < sheetNames.count(); ++i) { Sheet* sheet = view->doc()->map()->findSheet(sheetNames[i]); if (sheet == 0) { kWarning(36005) << i18n("Sheet %1 could not be found for printing", sheetNames[i]); continue; } selectedSheets.append(sheet); } } // (Re-)Create the pages of the sheets. int pageCount = 0; for (int i = 0; i < selectedSheets.count(); ++i) { PrintSettings settings = *selectedSheets[i]->printSettings(); // Set the print region, if the selection should be painted. if (printer.printRange() == QPrinter::Selection) settings.setPrintRegion(*view->selection()); printManager(selectedSheets[i])->setPrintSettings(settings, forceRecreation); pageCount += printManager(selectedSheets[i])->pageCount(); } return pageCount; }
void SheetPrint::insertRow(int row, int nbRow) { //update print range, when it has been defined const QRect printRange = d->m_settings->printRegion().lastRange(); if (printRange != QRect(QPoint(1, 1), QPoint(KS_colMax, KS_rowMax))) { int top = printRange.top(); int bottom = printRange.bottom(); for (int i = 0; i < nbRow; i++) { if (top >= row) top++; if (bottom >= row) bottom++; } //Validity checks if (top > KS_rowMax) top = KS_rowMax; if (bottom > KS_rowMax) bottom = KS_rowMax; const Region region(QRect(QPoint(printRange.left(), top), QPoint(printRange.right(), bottom)), d->m_pSheet); // Trigger an update by setting it indirectly. PrintSettings settings = *d->m_settings; settings.setPrintRegion(region); setSettings(settings); } }
void SheetPrint::insertColumn(int col, int nbCol) { //update print range, when it has been defined const QRect printRange = d->m_settings->printRegion().lastRange(); if (printRange != QRect(QPoint(1, 1), QPoint(KS_colMax, KS_rowMax))) { int left = printRange.left(); int right = printRange.right(); for (int i = 0; i < nbCol; i++) { if (left >= col) left++; if (right >= col) right++; } //Validity checks if (left > KS_colMax) left = KS_colMax; if (right > KS_colMax) right = KS_colMax; const Region region(QRect(QPoint(left, printRange.top()), QPoint(right, printRange.bottom())), d->m_pSheet); // Trigger an update by setting it indirectly. PrintSettings settings = *d->m_settings; settings.setPrintRegion(region); setSettings(settings); } }
void PageManager::layoutPages() { const Sheet* sheet = d->sheet; const PrintSettings settings = d->settings; d->pages.clear(); clearPages(); int pageNumber = 1; preparePage(pageNumber); if (settings.pageOrder() == PrintSettings::LeftToRight) { // kDebug() << "processing printRanges" << settings.printRegion(); // iterate over the print ranges Region::ConstIterator end = settings.printRegion().constEnd(); for (Region::ConstIterator it = settings.printRegion().constBegin(); it != end; ++it) { if (!(*it)->isValid()) continue; // limit the print range to the used area const QRect printRange = (*it)->rect() & sheet->usedArea(true); // kDebug() << "processing printRange" << printRange; int rows = 0; double height = 0.0; for (int row = printRange.top(); row <= printRange.bottom(); ++row) { rows++; height += sheet->rowFormats()->visibleHeight(row); // 1. find the number of rows per page if (row == printRange.bottom()) // always iterate over the last 'page row' ; else if (height + sheet->rowFormats()->visibleHeight(row + 1) <= size(pageNumber).height()) continue; // kDebug() << "1. done: row" << row << "rows" << rows << "height" << height; int columns = 0; double width = 0.0; // 2. iterate over the columns and create the pages for (int col = printRange.left(); col < printRange.right(); ++col) { columns++; width += sheet->columnFormat(col)->visibleWidth(); // Does the next column fit too? if (width + sheet->columnFormat(col + 1)->visibleWidth() <= size(pageNumber).width()) continue; // kDebug() << "col" << col << "columns" << columns << "width" << width; const QRect cellRange(col - columns + 1, row - rows + 1, columns, rows); if (pageNeedsPrinting(cellRange)) { d->pages.append(cellRange); insertPage(pageNumber++); preparePage(pageNumber); // prepare the next page } columns = 0; width = 0.0; } // Always insert a page for the last column columns++; const QRect cellRange(printRange.right() - columns + 1, row - rows + 1, columns, rows); if (pageNeedsPrinting(cellRange)) { d->pages.append(cellRange); insertPage(pageNumber); pageNumber++; } // 3. prepare for the next row of pages if (row != printRange.bottom()) { preparePage(pageNumber); } rows = 0; height = 0.0; } } } else { // if (settings.pageOrder() == PrintSettings::TopToBottom) // kDebug() << "processing printRanges" << settings.printRegion(); // iterate over the print ranges Region::ConstIterator end = settings.printRegion().constEnd(); for (Region::ConstIterator it = settings.printRegion().constBegin(); it != end; ++it) { if (!(*it)->isValid()) continue; // limit the print range to the used area const QRect printRange = (*it)->rect() & sheet->usedArea(); kDebug() << "processing printRange" << printRange; int columns = 0; double width = 0.0; for (int col = printRange.left(); col <= printRange.right(); ++col) { columns++; width += sheet->columnFormat(col)->visibleWidth(); // 1. find the number of columns per page if (col == printRange.right()) // always iterate over the last 'page column' ; else if (width + sheet->columnFormat(col + 1)->visibleWidth() <= size(pageNumber).width()) continue; // kDebug() << "1. done: col" << col << "columns" << columns << "width" << width; int rows = 0; double height = 0.0; // 2. iterate over the rows and create the pages for (int row = printRange.top(); row < printRange.bottom(); ++row) { rows++; height += sheet->rowFormats()->visibleHeight(row); // Does the next row fit too? if (height + sheet->rowFormats()->visibleHeight(row + 1) <= size(pageNumber).height()) continue; // kDebug() << "row" << row << "rows" << rows << "height" << height; const QRect cellRange(col - columns + 1, row - rows + 1, columns, rows); if (pageNeedsPrinting(cellRange)) { d->pages.append(cellRange); insertPage(pageNumber++); preparePage(pageNumber); // prepare the next page } rows = 0; height = 0.0; } // Always insert a page for the last row rows++; const QRect cellRange(col - columns + 1, printRange.bottom() - rows + 1, columns, rows); if (pageNeedsPrinting(cellRange)) { d->pages.append(cellRange); insertPage(pageNumber); pageNumber++; } // 3. prepare for the next column of pages if (col != printRange.right()) { preparePage(pageNumber); } columns = 0; width = 0.0; } } } kDebug() << d->pages.count() << "page(s) created"; }
void PageLayoutDialog::accept() { PrintSettings settings; settings.setPageLayout(pageLayout()); settings.setPrintGrid(d->sheetPage.gridCheckBox->isChecked()); settings.setPrintCommentIndicator(d->sheetPage.commentCheckBox->isChecked()); settings.setPrintFormulaIndicator(d->sheetPage.formulaCheckBox->isChecked()); settings.setPrintCharts(d->sheetPage.chartsCheckBox->isChecked()); settings.setPrintGraphics(d->sheetPage.drawingsCheckBox->isChecked()); settings.setPrintObjects(d->sheetPage.objectsCheckBox->isChecked()); settings.setPrintZeroValues(d->sheetPage.zeroValuesCheckBox->isChecked()); settings.setPrintHeaders(d->sheetPage.headersCheckBox->isChecked()); settings.setPageOrder(d->sheetPage.ltrButton->isChecked() ? PrintSettings::LeftToRight : PrintSettings::TopToBottom); settings.setCenterHorizontally(d->sheetPage.horizontalCheckBox->isChecked()); settings.setCenterVertically(d->sheetPage.verticalCheckBox->isChecked()); // Set the repeated columns. if (d->sheetPage.columnsCheckBox->isChecked()) { // TODO Stefan: Check if width of repeated columns exceeds page width. const int startColumn = Util::decodeColumnLabelText(d->sheetPage.startColumnComboBox->currentText()); const int endColumn = Util::decodeColumnLabelText(d->sheetPage.endColumnComboBox->currentText()); settings.setRepeatedColumns(qMakePair(qMin(startColumn, endColumn), qMax(startColumn, endColumn))); } else settings.setRepeatedColumns(QPair<int, int>()); // Set the repeated rows. if (d->sheetPage.rowsCheckBox->isChecked()) { // TODO Stefan: Check if height of repeated rows exceeds page height. const int startRow = d->sheetPage.startRowComboBox->currentText().toInt(); const int endRow = d->sheetPage.endRowComboBox->currentText().toInt(); settings.setRepeatedRows(qMakePair(qMin(startRow, endRow), qMax(startRow, endRow))); } else settings.setRepeatedRows(QPair<int, int>()); bool isValid = false; settings.setZoom(0.01 * d->sheetPage.zoomComboBox->currentText().remove('%').toDouble(&isValid)); if (!isValid) settings.setZoom(1.0); QSize pageLimits; if (d->sheetPage.pageLimitsButton->isChecked()) { pageLimits.setWidth(d->sheetPage.horizontalComboBox->currentText().toInt(&isValid)); if (!isValid) pageLimits.setWidth(0); pageLimits.setHeight(d->sheetPage.verticalComboBox->currentText().toInt(&isValid)); if (!isValid) pageLimits.setHeight(0); } settings.setPageLimits(pageLimits); if (applyToDocument()) { // Apply to all sheets. KUndo2Command* macroCommand = new KUndo2Command(kundo2_i18n("Set Page Layout")); const QList<Sheet*> sheets = d->sheet->map()->sheetList(); for (int i = 0; i < sheets.count(); ++i) { PageLayoutCommand* command = new PageLayoutCommand(sheets[i], settings, macroCommand); Q_UNUSED(command); } d->sheet->doc()->addCommand(macroCommand); } else { PageLayoutCommand* command = new PageLayoutCommand(d->sheet, settings); d->sheet->doc()->addCommand(command); } KoPageLayoutDialog::accept(); }
void SheetPrint::setSettings(const PrintSettings &settings, bool force) { // Relayout forced? if (force) { *d->m_settings = settings; d->updateRepeatedColumnsWidth(); d->updateRepeatedRowsHeight(); const QSize pageLimits = settings.pageLimits(); const QSize usedArea = d->m_pSheet->usedArea(true).size(); if (pageLimits.width() > 0) { d->calculateZoomForPageLimitX(); } else { updateHorizontalPageParameters(0); d->calculateHorizontalPageParameters(usedArea.width()); } if (pageLimits.height() > 0) { d->calculateZoomForPageLimitY(); } else { updateVerticalPageParameters(0); d->calculateVerticalPageParameters(usedArea.height()); } return; } const KoPageLayout oldPageLayout = d->m_settings->pageLayout(); const KoPageLayout pageLayout = settings.pageLayout(); const QRect oldPrintRange = d->m_settings->printRegion().lastRange(); const QRect printRange = settings.printRegion().lastRange(); const QSize oldPageLimits = d->m_settings->pageLimits(); const QSize pageLimits = settings.pageLimits(); const QPair<int, int> oldRepeatedColumns = d->m_settings->repeatedColumns(); const QPair<int, int> repeatedColumns = settings.repeatedColumns(); const QPair<int, int> oldRepeatedRows = d->m_settings->repeatedRows(); const QPair<int, int> repeatedRows = settings.repeatedRows(); const bool pageWidthChanged = oldPageLayout.width != pageLayout.width; const bool pageHeightChanged = oldPageLayout.height != pageLayout.height; const bool horizontalLimitChanged = oldPageLimits.width() != pageLimits.width(); const bool verticalLimitChanged = oldPageLimits.height() != pageLimits.height(); const bool repeatedColumnsChanged = oldRepeatedColumns != repeatedColumns; const bool repeatedRowsChanged = oldRepeatedRows != repeatedRows; const bool zoomChanged = d->m_settings->zoom() != settings.zoom(); *d->m_settings = settings; // The starting column/row for the page parameter updates. int column = KS_colMax + 1; int row = KS_rowMax + 1; // The print range. if (oldPrintRange.left() != printRange.left()) { column = qMin(oldPrintRange.left(), printRange.left()); } if (oldPrintRange.top() != printRange.top()) { row = qMin(oldPrintRange.top(), printRange.top()); } // The zoom. if (zoomChanged) { column = 0; row = 0; } // The page limits. if (horizontalLimitChanged && pageLimits.width() <= 0) { column = 0; } if (verticalLimitChanged && pageLimits.height() <= 0) { row = 0; } // The page dimensions. if (pageWidthChanged) { column = 0; } if (pageHeightChanged) { row = 0; } // The column/row repetitions. if (repeatedColumnsChanged) { d->updateRepeatedColumnsWidth(); column = qMin(column, oldRepeatedColumns.first); column = qMin(column, repeatedColumns.first); } if (repeatedRowsChanged) { d->updateRepeatedRowsHeight(); row = qMin(row, oldRepeatedRows.first); row = qMin(row, repeatedRows.first); } // Update the page parameters. // If page limits are set to non-zero, call the special methods. if (horizontalLimitChanged && pageLimits.width() > 0) { d->calculateZoomForPageLimitX(); } else if (column <= KS_colMax) { updateHorizontalPageParameters(column); } if (verticalLimitChanged && pageLimits.height() > 0) { d->calculateZoomForPageLimitY(); } else if (row <= KS_rowMax) { updateVerticalPageParameters(row); } }