KUrl DocumentSyncManager::urlOf( AbstractDocument* document ) const { AbstractModelSynchronizer* synchronizer = document->synchronizer(); return synchronizer ? synchronizer->url() : KUrl(); }
void PrintTool::print() { const QString processTitle = i18nc( "@title:window", "Print Byte Array %1", mDocument->title() ); QPrinter printer; // LayoutDialogPage* layoutPage = new LayoutDialogPage(); QList<QWidget*> customDialogPages; // customDialogPages << layoutPage; QPrintDialog *printDialog = new QPrintDialog( &printer, 0 ); // Disable PrintPageRange, this tells Qt we can't do client-side page selection, // so it will try do server-side page selection if supported printDialog->setOption(QPrintDialog::PrintPageRange, false); // printDialog->setOptionTabs(customDialogPages); printDialog->setWindowTitle( processTitle ); if( printDialog->exec() ) { QString creator = QString::fromLatin1( "Print Plugin for Okteta " ); // no i18n(), keep space at end as separator // creator += KDEUTILS_VERSION_STRING; // TODO: change to OKTETA_VERSION_STRING printer.setCreator( creator ); FramesToPaperPrinter framesPrinter; framesPrinter.setPaperRect( printer.paperRect() ); framesPrinter.setPageRect( printer.pageRect() ); printer.setFullPage( true ); PrintInfo info; const QRect pageRect = framesPrinter.pageRect(); const int left = pageRect.left(); const int width = pageRect.width(); HeaderFooterFrameRenderer *headerFrameRenderer = new HeaderFooterFrameRenderer( &info ); headerFrameRenderer->setTexts( QStringLiteral("%d"), QStringLiteral("%f"), i18nc("in the header of the printed page, e.g. Page 2 of 20","Page %p of %P") ); headerFrameRenderer->setWidth( width ); headerFrameRenderer->setPos( pageRect.topLeft() ); HeaderFooterFrameRenderer *footerFrameRenderer = new HeaderFooterFrameRenderer( &info ); footerFrameRenderer->setTexts( i18nc("in the footer of the printed page, e.g. Printed by: Joe User", "Printed by: %U"), QString(), QStringLiteral("%F") ); footerFrameRenderer->setWidth( width ); const int footerTop = pageRect.bottom() - footerFrameRenderer->height(); footerFrameRenderer->setPos( left, footerTop ); const int contentHeight = pageRect.height() - footerFrameRenderer->height() - headerFrameRenderer->height(); const int contentTop = pageRect.top() + headerFrameRenderer->height(); ByteArrayFrameRenderer *byteArrayFrameRenderer = new ByteArrayFrameRenderer; byteArrayFrameRenderer->setPos( left, contentTop ); byteArrayFrameRenderer->setWidth( width ); byteArrayFrameRenderer->setHeight( contentHeight ); Okteta::AddressRange range = mByteArrayView->selection(); if( ! range.isValid() ) range.setByWidth( 0, mByteArrayModel->size() ); byteArrayFrameRenderer->setByteArrayModel( mByteArrayModel, range.start(), range.width() ); // TODO: use noOfBytesPerLine of view, scale resolution down if it does not fit the page const int noOfBytesPerLine = mByteArrayView->noOfBytesPerLine(); // byteArrayFrameRenderer->setNoOfBytesPerLine( mByteArrayView->noOfBytesPerLine() ); const Okteta::Address startOffset = mByteArrayView->startOffset() + range.start(); const int line = startOffset / noOfBytesPerLine; const Okteta::Address firstLineOffset = mByteArrayView->firstLineOffset() + line*noOfBytesPerLine; byteArrayFrameRenderer->setFirstLineOffset( firstLineOffset ); byteArrayFrameRenderer->setStartOffset( startOffset ); byteArrayFrameRenderer->setCharCoding( mByteArrayView->charCodingName() ); byteArrayFrameRenderer->setBufferSpacing( mByteArrayView->byteSpacingWidth(), mByteArrayView->noOfGroupedBytes(), mByteArrayView->groupSpacingWidth() ); byteArrayFrameRenderer->setBinaryGapWidth( mByteArrayView->binaryGapWidth() ); byteArrayFrameRenderer->setValueCoding( (Okteta::ValueCoding)mByteArrayView->valueCoding() ); byteArrayFrameRenderer->setShowsNonprinting( mByteArrayView->showsNonprinting() ); byteArrayFrameRenderer->setSubstituteChar( mByteArrayView->substituteChar() ); byteArrayFrameRenderer->setUndefinedChar( mByteArrayView->undefinedChar() ); byteArrayFrameRenderer->showByteArrayColumns( mByteArrayView->visibleByteArrayCodings() ); // if( !confirmPrintPageNumber( byteArrayFrameRenderer->framesCount()) ) // return; framesPrinter.addFrameRenderer( headerFrameRenderer ); framesPrinter.addFrameRenderer( byteArrayFrameRenderer ); framesPrinter.addFrameRenderer( footerFrameRenderer ); info.setNoOfPages( byteArrayFrameRenderer->framesCount() ); AbstractModelSynchronizer* synchronizer = mDocument->synchronizer(); if (synchronizer) { info.setUrl( synchronizer->url() ); } QApplication::setOverrideCursor( Qt::WaitCursor ); PrintJob *printJob = new PrintJob( &framesPrinter, 0, byteArrayFrameRenderer->framesCount()-1, &printer ); const bool success = printJob->exec(); QApplication::restoreOverrideCursor(); if( ! success ) { const QString message = i18nc( "@info","Could not print." ); KMessageBox::sorry( 0, message, processTitle ); } } delete printDialog; }