summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocument.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-08-16 14:04:48 +0200
committerLars Knoll <lars.knoll@nokia.com>2011-08-19 09:16:22 +0200
commit699e8fe3a6724dd8288dd6a55b25e070eb198c9d (patch)
treec6928eb3928f2e687e4050e9f409a0afa2e7828a /src/gui/text/qtextdocument.cpp
parent9ebdc333a6a6485fd60a50a742a1d6edec211f53 (diff)
Use the paged paintdevice in the print() method of QTextDocument.
This is required to be able to move the printing system into it's own library. Change-Id: If70a55be4c4413f9cd917a30d1b368f32c1145e4 Reviewed-on: http://codereview.qt.nokia.com/3207 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src/gui/text/qtextdocument.cpp')
-rw-r--r--src/gui/text/qtextdocument.cpp103
1 files changed, 38 insertions, 65 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 08b6e0bf14..c3dd72ad41 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -65,6 +65,7 @@
#include "qtextdocument_p.h"
#include <private/qprinter_p.h>
#include <private/qabstracttextdocumentlayout_p.h>
+#include "qpagedpaintdevice.h"
#include <limits.h>
@@ -1694,7 +1695,7 @@ static void printPage(int index, QPainter *painter, const QTextDocument *doc, co
}
/*!
- Prints the document to the given \a printer. The QPrinter must be
+ Prints the document to the given \a device. The QPageablePaintDevice must be
set up before being used with this function.
This is only a convenience method to print the whole document to the printer.
@@ -1704,33 +1705,30 @@ static void printPage(int index, QPainter *painter, const QTextDocument *doc, co
If the document is not paginated, like for example a document used in a QTextEdit,
then a temporary copy of the document is created and the copy is broken into
- multiple pages according to the size of the QPrinter's paperRect(). By default
+ multiple pages according to the size of the paint device's paperRect(). By default
a 2 cm margin is set around the document contents. In addition the current page
number is printed at the bottom of each page.
- Note that QPrinter::Selection is not supported as print range with this function since
- the selection is a property of QTextCursor. If you have a QTextEdit associated with
- your QTextDocument then you can use QTextEdit's print() function because QTextEdit has
- access to the user's selection.
-
\sa QTextEdit::print()
*/
-void QTextDocument::print(QPrinter *printer) const
+void QTextDocument::print(QPagedPaintDevice *printer) const
{
Q_D(const QTextDocument);
- if (!printer || !printer->isValid())
+ if (!printer)
return;
- if (!d->title.isEmpty())
- printer->setDocName(d->title);
+ // ###
+// if (!d->title.isEmpty())
+// printer->setDocName(d->title);
bool documentPaginated = d->pageSize.isValid() && !d->pageSize.isNull()
&& d->pageSize.height() != INT_MAX;
- if (!documentPaginated && !printer->fullPage() && !printer->d_func()->hasCustomPageMargins)
- printer->setPageMargins(23.53, 23.53, 23.53, 23.53, QPrinter::Millimeter);
+ // ### set page size to paginated size?
+// if (!documentPaginated && !printer->fullPage() && !printer->d_func()->hasCustomPageMargins)
+// printer->setPageMargins(23.53, 23.53, 23.53, 23.53, QPrinter::Millimeter);
QPainter p(printer);
@@ -1765,7 +1763,7 @@ void QTextDocument::print(QPrinter *printer) const
scaledPageSize.rwidth() *= dpiScaleX;
scaledPageSize.rheight() *= dpiScaleY;
- const QSizeF printerPageSize(printer->pageRect().size());
+ const QSizeF printerPageSize(printer->width(), printer->height());
// scale to page
p.scale(printerPageSize.width() / scaledPageSize.width(),
@@ -1787,17 +1785,12 @@ void QTextDocument::print(QPrinter *printer) const
layout->d_func()->handlers = documentLayout()->d_func()->handlers;
int dpiy = p.device()->logicalDpiY();
- int margin = 0;
- if (printer->fullPage() && !printer->d_func()->hasCustomPageMargins) {
- // for compatibility
- margin = (int) ((2/2.54)*dpiy); // 2 cm margins
- QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
- fmt.setMargin(margin);
- doc->rootFrame()->setFrameFormat(fmt);
- }
+ int margin = (int) ((2/2.54)*dpiy); // 2 cm margins
+ QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
+ fmt.setMargin(margin);
+ doc->rootFrame()->setFrameFormat(fmt);
- QRectF pageRect(printer->pageRect());
- body = QRectF(0, 0, pageRect.width(), pageRect.height());
+ body = QRectF(0, 0, printer->width(), printer->height());
pageNumberPos = QPointF(body.width() - margin,
body.height() - margin
+ QFontMetrics(doc->defaultFont(), p.device()).ascent()
@@ -1805,18 +1798,10 @@ void QTextDocument::print(QPrinter *printer) const
clonedDoc->setPageSize(body.size());
}
- int docCopies;
- int pageCopies;
- if (printer->collateCopies() == true){
- docCopies = 1;
- pageCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
- } else {
- docCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
- pageCopies = 1;
- }
-
- int fromPage = printer->fromPage();
- int toPage = printer->toPage();
+ int fromPage = 0;
+ int toPage = 0;
+// int fromPage = printer->fromPage();
+// int toPage = printer->toPage();
bool ascending = true;
if (fromPage == 0 && toPage == 0) {
@@ -1833,39 +1818,27 @@ void QTextDocument::print(QPrinter *printer) const
return;
}
- if (printer->pageOrder() == QPrinter::LastPageFirst) {
- int tmp = fromPage;
- fromPage = toPage;
- toPage = tmp;
- ascending = false;
- }
-
- for (int i = 0; i < docCopies; ++i) {
+// if (printer->pageOrder() == QPrinter::LastPageFirst) {
+// int tmp = fromPage;
+// fromPage = toPage;
+// toPage = tmp;
+// ascending = false;
+// }
- int page = fromPage;
- while (true) {
- for (int j = 0; j < pageCopies; ++j) {
- if (printer->printerState() == QPrinter::Aborted
- || printer->printerState() == QPrinter::Error)
- return;
- printPage(page, &p, doc, body, pageNumberPos);
- if (j < pageCopies - 1)
- printer->newPage();
- }
+ int page = fromPage;
+ while (true) {
+ printPage(page, &p, doc, body, pageNumberPos);
- if (page == toPage)
- break;
-
- if (ascending)
- ++page;
- else
- --page;
+ if (page == toPage)
+ break;
- printer->newPage();
- }
+ if (ascending)
+ ++page;
+ else
+ --page;
- if ( i < docCopies - 1)
- printer->newPage();
+ if (!printer->newPage())
+ return;
}
}
#endif