Mercurial > hg > syntilista
annotate src/printing.cpp @ 161:eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 19 Sep 2017 12:10:59 +0300 |
parents | 1c2f9d09e87b |
children | 186d0717707f |
rev | line source |
---|---|
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // Syntilista - debt list/management database program |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // Programmed and designed by Matti Hämäläinen <ccr@tnsp.org> |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 // (C) Copyright 2017 Tecnic Software productions (TNSP) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 // Distributed under 3-clause BSD style license, refer to |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 // included file "COPYING" for exact terms. |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 // |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include <QPrintDialog> |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include <QPrintPreviewDialog> |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "main.h" |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
13 #define APP_PRINT_WIDTH 1000 |
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
14 #define APP_PRINT_HEIGHT 1300 |
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
15 |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 void SyntilistaMainWindow::on_button_Print_clicked() |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 // Create a printer object and force some basic settings |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 QPrinter printer(QPrinter::HighResolution); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 printer.setPageSize(QPageSize(QPageSize::A4)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 printer.setColorMode(QPrinter::GrayScale); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 printer.setResolution(300); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 // We need to get the page count here, and also need it again in |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 // printDocument(), but there is no sane way to pass that there, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 // so some code duplication is unfortunately necessary |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 pinfo.npages = 0; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 pinfo.nlinesPerPage = 0; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
31 QPixmap tmpPixmap(APP_PRINT_WIDTH, APP_PRINT_HEIGHT); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 QPainter tmpPainter; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 tmpPainter.begin(&tmpPixmap); |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
34 bool ret = printDocumentPage(true, -1, &tmpPainter, &printer); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 tmpPainter.end(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 if (!ret) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 // Some kind of error occured |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 return; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 // Set available pages |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 printer.setFromTo(1, pinfo.npages); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 // Create print preview dialog and show it |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 QPrintPreviewDialog preview(&printer, this); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 preview.setWindowModality(Qt::ApplicationModal); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 preview.setSizeGripEnabled(true); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 connect( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 &preview, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 SIGNAL(paintRequested(QPrinter *)), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 this, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 SLOT(printDocument(QPrinter *))); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 preview.exec(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 void SyntilistaMainWindow::printDocument(QPrinter *printer) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 // Create progress dialog |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 QProgressDialog progress( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 tr("Tulostetaan ..."), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 tr("Peruuta"), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 0, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 1, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 this); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 progress.setWindowModality(Qt::ApplicationModal); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 // If from and to are 0, we are supposed to print all pages |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 if (printer->fromPage() == 0 && printer->toPage() == 0) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 printer->setFromTo(1, pinfo.npages); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 // Setup rest of the progress dialog here |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 progress.setMinimum(printer->fromPage() - 1); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 progress.setMaximum(printer->toPage()); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 // Begin painting to the printer (or preview) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 QPainter painter; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 painter.begin(printer); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 bool firstPage = true; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 for (int page = printer->fromPage(); page <= printer->toPage(); page++) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 if (!firstPage) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 printer->newPage(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 qApp->processEvents(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 if (progress.wasCanceled()) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 break; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
96 printDocumentPage(false, page, &painter, printer); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 progress.setValue(page); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 firstPage = false; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 painter.end(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
105 bool SyntilistaMainWindow::printDocumentPage(const bool getPageInfo, const int npage, QPainter *pt, QPrinter *printer) |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 // Form the SQL query for list of users |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 QString querystr = QStringLiteral( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 "SELECT id,first_name,last_name,extra_info,added,updated, " |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance " |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 "FROM people ORDER BY last_name ASC,first_name ASC"); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 // If we are fetching page info, we need to process all entries |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 if (!getPageInfo) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 // Otherwise we can limit to given page number |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 querystr += QStringLiteral(" LIMIT %1 OFFSET %2"). |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 arg(pinfo.nlinesPerPage). |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 arg((npage - 1) * pinfo.nlinesPerPage); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 QSqlQuery query; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 query.prepare(querystr); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 query.setForwardOnly(true); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 query.exec(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 if (!slCheckAndReportSQLError("printDocumentPage()", query.lastError())) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 slErrorMsg( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 tr("SQL-tietokantavirhe"), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 tr("Tietokantaa selattaessa tapahtui virhe.")); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 return false; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 pt->save(); |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
137 pt->scale( |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
138 pt->device()->width() / (float) APP_PRINT_WIDTH, |
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
139 pt->device()->height() / (float) APP_PRINT_HEIGHT); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
141 QFont font1; |
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
142 font1.setFamily("Arial"); |
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
143 font1.setPixelSize(24); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 SLDrawContext ctx(pt); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 ctx.setFont(font1); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 int nline = 0; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 while (query.next()) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 PersonInfo info; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 slGetPersonInfoRec(query, info); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 // Check for end of page |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 // KLUDGE for now |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
155 if (getPageInfo && ctx.lfq(10) >= APP_PRINT_HEIGHT - ctx.boundRect().height() * 1.5f) |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 if (nline > pinfo.nlinesPerPage) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 pinfo.nlinesPerPage = nline; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 pinfo.npages++; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 nline = 0; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 if (nline == 0) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 // If we are at the start of the page, we shall draw a header |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 pt->setBrush(QBrush(Qt::black)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 pt->setPen(QPen(Qt::black, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 ctx.setPos(0, 0); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 ctx.drawText( 5, 180, tr("Etunimi")); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 ctx.drawText( 200, 230, tr("Sukunimi")); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 ctx.drawText( 450, 190, tr("Lisätty")); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 ctx.drawText( 650, 190, tr("Päivitetty")); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 ctx.drawText( 870, 120, tr("Tase")); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 ctx.lf(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
178 pt->drawLine(0, ctx.m_pos.y(), APP_PRINT_WIDTH, ctx.m_pos.y()); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 ctx.move(0, 5); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 // Draw a gray bar under every second line |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 if (nline % 2 == 0) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 pt->fillRect( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 0, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 ctx.m_pos.y() - 1, |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
189 APP_PRINT_WIDTH, |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 ctx.boundRect().height() + 4, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 QColor(0, 0, 0, 40)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 ctx.drawText( 5, 180, info.firstName); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 ctx.drawText( 200, 230, info.lastName); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 ctx.drawText( 450, 190, slDateTimeToStr(info.added)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 ctx.drawText( 650, 190, slDateTimeToStr(info.updated)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 ctx.drawText( 870, 120, slMoneyValueToStr(info.balance), Qt::AlignRight); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 ctx.lf(10); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 nline++; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 query.finish(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 if (getPageInfo) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 if (nline > pinfo.nlinesPerPage) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 pinfo.nlinesPerPage = nline; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 pinfo.npages++; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 else |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 { |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
215 ctx.setPos(0, APP_PRINT_HEIGHT - ctx.boundRect().height()); |
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
216 ctx.drawText(0, APP_PRINT_WIDTH, |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 tr("Sivu %1 / %2 (%3 / %4)"). |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 arg(npage - printer->fromPage() + 1). |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 arg(printer->toPage() - printer->fromPage() + 1). |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 arg(npage). |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 arg(printer->toPage()), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 Qt::AlignHCenter); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 pt->restore(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 return true; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 } |