diff --git a/core/document.h b/core/document.h --- a/core/document.h +++ b/core/document.h @@ -401,6 +401,21 @@ Rotation rotation() const; /** + * Returns the last printing option used when printing this document: all pages, selection, page range, current page, .. etc + */ + QPrinter::PrintRange lastPrintRangeOption() const; + + /** + * Returns the first page of the print range when priting this document the last time + */ + int lastPrintFromPage() const; + + /** + * Returns the last page of the print range when priting this document the last time + */ + int lastPrintToPage() const; + + /** * If all pages have the same size this method returns it, if the page sizes * differ an empty size object is returned. */ @@ -463,6 +478,16 @@ void setZoom( int factor, DocumentObserver *excludeObserver = nullptr ); /** + * Sets the last printing option used when printing the current document: all pages, selection, page range, current page, .. etc + */ + void setLastPrintRangeOption(QPrinter::PrintRange rangeOption); + + /** + * Sets the last page range used when printing the current document + */ + void setLastPrintRange(int from, int to); + + /** * Describes the possible options for the pixmap requests. */ enum PixmapRequestFlag diff --git a/core/document.cpp b/core/document.cpp --- a/core/document.cpp +++ b/core/document.cpp @@ -638,6 +638,25 @@ loadedAnything = true; } } + else if ( infoElement.tagName() == QLatin1String("printing") ) + { + QDomNode printNode = infoElement.firstChild(); + while ( printNode.isElement() ) + { + QDomElement printElement = printNode.toElement(); + if ( printElement.tagName() == QLatin1String("rangeOption") ) + { + QString str = printElement.text(); + m_lastPrintRangeOption = (QPrinter::PrintRange)str.toInt(); + } + else if ( printElement.tagName() == QLatin1String("printRange") ) + { + m_lastPrintFromPage = printElement.attribute("from").toInt(); + m_lastPrintToPage = printElement.attribute("to").toInt(); + } + printNode = printNode.nextSibling(); + } + } else if ( infoElement.tagName() == QLatin1String("views") ) { QDomNode viewNode = infoNode.firstChild(); @@ -1222,6 +1241,21 @@ generalInfo.appendChild( rotationNode ); rotationNode.appendChild( doc.createTextNode( QString::number( (int)m_rotation ) ) ); } + // create printing node + if ( m_lastPrintRangeOption != QPrinter::AllPages ) + { + QDomElement printingNode = doc.createElement( QStringLiteral("printing") ); + generalInfo.appendChild( printingNode ); + + QDomElement rangeOptionNode = doc.createElement( QStringLiteral("rangeOption") ); + printingNode.appendChild( rangeOptionNode ); + rangeOptionNode.appendChild( doc.createTextNode( QString::number( (int)m_lastPrintRangeOption ) ) ); + + QDomElement printRangeNode = doc.createElement( QStringLiteral("printRange") ); + printingNode.appendChild( printRangeNode ); + printRangeNode.setAttribute( "from", QString::number( m_lastPrintFromPage ) ); + printRangeNode.setAttribute( "to", QString::number(m_lastPrintToPage ) ); + } // ... save history up to OKULAR_HISTORY_SAVEDSTEPS viewports QLinkedList< DocumentViewport >::const_iterator backIterator = m_viewportIterator; if ( backIterator != m_viewportHistory.constEnd() ) @@ -2698,6 +2732,9 @@ d->m_fontsCached = false; d->m_fontsCache.clear(); d->m_rotation = Rotation0; + d->m_lastPrintRangeOption = QPrinter::AllPages; + d->m_lastPrintFromPage = -1; + d->m_lastPrintToPage = -1; // send an empty list to observers (to free their data) foreachObserver( notifySetup( QVector< Page * >(), DocumentObserver::DocumentChanged | DocumentObserver::UrlChanged ) ); @@ -3163,6 +3200,21 @@ return d->m_rotation; } +QPrinter::PrintRange Document::lastPrintRangeOption() const +{ + return d->m_lastPrintRangeOption; +} + +int Document::lastPrintFromPage() const +{ + return d->m_lastPrintFromPage; +} + +int Document::lastPrintToPage() const +{ + return d->m_lastPrintToPage; +} + QSizeF Document::allPagesSize() const { bool allPagesSameSize = true; @@ -3724,6 +3776,17 @@ o->notifyZoom( factor ); } +void Document::setLastPrintRangeOption(QPrinter::PrintRange rangeOption) +{ + d->m_lastPrintRangeOption = rangeOption; +} + +void Document::setLastPrintRange(int from, int to) +{ + d->m_lastPrintFromPage = from; + d->m_lastPrintToPage = to; +} + void Document::setPrevViewport() // restore viewport from the history { diff --git a/core/document_p.h b/core/document_p.h --- a/core/document_p.h +++ b/core/document_p.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -94,6 +95,9 @@ m_maxAllocatedTextPages( 0 ), m_warnedOutOfMemory( false ), m_rotation( Rotation0 ), + m_lastPrintRangeOption( QPrinter::AllPages ), + m_lastPrintFromPage( -1 ), + m_lastPrintToPage( -1 ), m_exportCached( false ), m_bookmarkManager( nullptr ), m_memCheckTimer( nullptr ), @@ -243,6 +247,11 @@ // the rotation applied to the document Rotation m_rotation; + // Printing options + QPrinter::PrintRange m_lastPrintRangeOption; + int m_lastPrintFromPage; + int m_lastPrintToPage; + // the current size of the pages (if available), and the cache of the // available page sizes PageSize m_pageSize; diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -3238,8 +3238,13 @@ { // Set the available Print Range + if(m_document->lastPrintFromPage() == -1 || m_document->lastPrintToPage() == -1) + { + m_document->setLastPrintRange( 1, m_document->pages() ); + } + printDialog->setMinMax( 1, m_document->pages() ); - printDialog->setFromTo( 1, m_document->pages() ); + printDialog->setFromTo( m_document->lastPrintFromPage(), m_document->lastPrintToPage() ); // If the user has bookmarked pages for printing, then enable Selection if ( !m_document->bookmarkedPageRange().isEmpty() ) @@ -3262,7 +3267,18 @@ bool success = true; if ( printDialog->exec() ) + { + QPrinter::PrintRange printRangeOption = (QPrinter::PrintRange)printDialog->printRange(); + + m_document->setLastPrintRangeOption( printRangeOption ); + + if( printRangeOption == QPrinter::PageRange ) + { + m_document->setLastPrintRange( printDialog->fromPage(), printDialog->toPage() ); + } + success = doPrint( printer ); + } delete printDialog; if ( m_cliPrintAndExit ) exit ( success ? EXIT_SUCCESS : EXIT_FAILURE ); @@ -3273,6 +3289,7 @@ void Part::setupPrint( QPrinter &printer ) { printer.setOrientation(m_document->orientation()); + printer.setPrintRange(m_document->lastPrintRangeOption()); // title QString title = m_document->metaData( QStringLiteral("DocumentTitle") ).toString();