Mercurial > hg > syntilista
annotate src/printing.cpp @ 217:58af72da7f60
Update copyrights.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Jan 2018 01:47:38 +0200 |
parents | d119235d3df0 |
children | 43a5e09bb832 |
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> |
217 | 4 // (C) Copyright 2017-2018 Tecnic Software productions (TNSP) |
157
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 |
167
c54ad71c1205
Apply (kludgey) adjustment scales for printed page to avoid overflow ..
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
16 #define APP_PRINT_WSCALE 1.01f |
c54ad71c1205
Apply (kludgey) adjustment scales for printed page to avoid overflow ..
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
17 #define APP_PRINT_HSCALE 1.00f |
c54ad71c1205
Apply (kludgey) adjustment scales for printed page to avoid overflow ..
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
18 |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 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
|
21 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 // 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
|
23 QPrinter printer(QPrinter::HighResolution); |
166
9511e2f250be
Force default page margins for printing, this fixes some problems under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
24 printer.setResolution(300); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 printer.setPageSize(QPageSize(QPageSize::A4)); |
166
9511e2f250be
Force default page margins for printing, this fixes some problems under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
26 printer.setPageMargins(QMarginsF(0.25f, 0.5f, 0.25f, 0.5f), QPageLayout::Inch); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 printer.setColorMode(QPrinter::GrayScale); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 |
177
d119235d3df0
This comment was no longer relevant.
Matti Hamalainen <ccr@tnsp.org>
parents:
176
diff
changeset
|
29 // We need to get the page count and line counts per page here |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 pinfo.npages = 0; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 pinfo.nlinesPerPage = 0; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
33 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
|
34 QPainter tmpPainter; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 tmpPainter.begin(&tmpPixmap); |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
36 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
|
37 tmpPainter.end(); |
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 if (!ret) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 // Some kind of error occured |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 return; |
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 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 // Set available pages |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 printer.setFromTo(1, pinfo.npages); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 // 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
|
50 QPrintPreviewDialog preview(&printer, this); |
165
186d0717707f
Add translated window title to print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
51 preview.setWindowTitle(tr("Tulostuksen esikatselu")); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 preview.setWindowModality(Qt::ApplicationModal); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 preview.setSizeGripEnabled(true); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 connect( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 &preview, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 SIGNAL(paintRequested(QPrinter *)), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 this, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 SLOT(printDocument(QPrinter *))); |
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 preview.exec(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 } |
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 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 void SyntilistaMainWindow::printDocument(QPrinter *printer) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 // Create progress dialog |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 QProgressDialog progress( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 tr("Tulostetaan ..."), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 tr("Peruuta"), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 0, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 1, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 this); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 progress.setWindowModality(Qt::ApplicationModal); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 // 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
|
78 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
|
79 printer->setFromTo(1, pinfo.npages); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 // 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
|
82 progress.setMinimum(printer->fromPage() - 1); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 progress.setMaximum(printer->toPage()); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 // 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
|
86 QPainter painter; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 painter.begin(printer); |
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 bool firstPage = true; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 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
|
91 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 if (!firstPage) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 printer->newPage(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 qApp->processEvents(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 if (progress.wasCanceled()) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 break; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
99 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
|
100 progress.setValue(page); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 firstPage = false; |
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 painter.end(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 } |
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 |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
108 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
|
109 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 // 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
|
111 QString querystr = QStringLiteral( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 "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
|
113 "(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
|
114 "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
|
115 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 // If we are fetching page info, we need to process all entries |
175
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
117 int noffset = (npage - 1) * pinfo.nlinesPerPage; |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 if (!getPageInfo) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 // 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
|
121 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
|
122 arg(pinfo.nlinesPerPage). |
175
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
123 arg(noffset); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 QSqlQuery query; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 query.prepare(querystr); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 query.setForwardOnly(true); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 query.exec(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 if (!slCheckAndReportSQLError("printDocumentPage()", query.lastError())) |
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 slErrorMsg( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 tr("SQL-tietokantavirhe"), |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 tr("Tietokantaa selattaessa tapahtui virhe.")); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 return false; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 pt->save(); |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
141 pt->scale( |
167
c54ad71c1205
Apply (kludgey) adjustment scales for printed page to avoid overflow ..
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
142 pt->device()->width() / ((float) APP_PRINT_WIDTH * APP_PRINT_WSCALE), |
c54ad71c1205
Apply (kludgey) adjustment scales for printed page to avoid overflow ..
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
143 pt->device()->height() /((float) APP_PRINT_HEIGHT * APP_PRINT_HSCALE)); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
160
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
145 QFont font1; |
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
146 font1.setFamily("Arial"); |
1c2f9d09e87b
Begin working on printing fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
158
diff
changeset
|
147 font1.setPixelSize(24); |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 SLDrawContext ctx(pt); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 ctx.setFont(font1); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 |
175
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
151 int nline = 0, nperson = noffset; |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 while (query.next()) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 { |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
154 SLPersonInfo info; |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 slGetPersonInfoRec(query, info); |
175
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
156 nperson++; |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 |
176
c29a1078d601
This page end check is not a kludge anymore, really .. I suppose.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
158 // Check for the end of page |
c29a1078d601
This page end check is not a kludge anymore, really .. I suppose.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
159 if (getPageInfo && ctx.lfq(10) >= |
c29a1078d601
This page end check is not a kludge anymore, really .. I suppose.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
160 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
|
161 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 if (nline > pinfo.nlinesPerPage) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 pinfo.nlinesPerPage = nline; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 pinfo.npages++; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 nline = 0; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 if (nline == 0) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 // 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
|
172 pt->setBrush(QBrush(Qt::black)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 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
|
174 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 ctx.setPos(0, 0); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 ctx.lf(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
183 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
|
184 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 ctx.move(0, 5); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 // 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
|
189 if (nline % 2 == 0) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 { |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 pt->fillRect( |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 0, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 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
|
194 APP_PRINT_WIDTH, |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 ctx.boundRect().height() + 4, |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 QColor(0, 0, 0, 40)); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 ctx.lf(10); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 nline++; |
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 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 query.finish(); |
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 if (getPageInfo) |
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 if (nline > pinfo.nlinesPerPage) |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 pinfo.nlinesPerPage = nline; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 pinfo.npages++; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 else |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 { |
161
eeb3bb877b63
More work on printing improvements, make certain hardcoded values #defines.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
220 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
|
221 ctx.drawText(0, APP_PRINT_WIDTH, |
175
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
222 tr("Sivu %1 / %2 (%3 / %4) - Henkilöt %5 - %6 / %7"). |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 arg(npage - printer->fromPage() + 1). |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 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
|
225 arg(npage). |
175
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
226 arg(printer->toPage()). |
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
227 arg(noffset + 1). |
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
228 arg(nperson). |
d61405758cc9
Add person counts summary to printed page summaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
229 arg(totalPeople), |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 Qt::AlignHCenter); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 } |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 pt->restore(); |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 return true; |
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 } |