Mercurial > hg > syntilista
comparison 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 |
comparison
equal
deleted
inserted
replaced
160:1c2f9d09e87b | 161:eeb3bb877b63 |
---|---|
8 // | 8 // |
9 #include <QPrintDialog> | 9 #include <QPrintDialog> |
10 #include <QPrintPreviewDialog> | 10 #include <QPrintPreviewDialog> |
11 #include "main.h" | 11 #include "main.h" |
12 | 12 |
13 #define APP_PRINT_WIDTH 1000 | |
14 #define APP_PRINT_HEIGHT 1300 | |
15 | |
13 | 16 |
14 void SyntilistaMainWindow::on_button_Print_clicked() | 17 void SyntilistaMainWindow::on_button_Print_clicked() |
15 { | 18 { |
16 // Create a printer object and force some basic settings | 19 // Create a printer object and force some basic settings |
17 QPrinter printer(QPrinter::HighResolution); | 20 QPrinter printer(QPrinter::HighResolution); |
23 // printDocument(), but there is no sane way to pass that there, | 26 // printDocument(), but there is no sane way to pass that there, |
24 // so some code duplication is unfortunately necessary | 27 // so some code duplication is unfortunately necessary |
25 pinfo.npages = 0; | 28 pinfo.npages = 0; |
26 pinfo.nlinesPerPage = 0; | 29 pinfo.nlinesPerPage = 0; |
27 | 30 |
28 QPixmap tmpPixmap(1000, 1300); | 31 QPixmap tmpPixmap(APP_PRINT_WIDTH, APP_PRINT_HEIGHT); |
29 QPainter tmpPainter; | 32 QPainter tmpPainter; |
30 tmpPainter.begin(&tmpPixmap); | 33 tmpPainter.begin(&tmpPixmap); |
31 bool ret = printDocumentPage(true, -1, &tmpPainter, &printer); | 34 bool ret = printDocumentPage(true, -1, &tmpPainter, &printer); |
32 tmpPainter.end(); | 35 tmpPainter.end(); |
33 | 36 |
130 return false; | 133 return false; |
131 } | 134 } |
132 | 135 |
133 pt->save(); | 136 pt->save(); |
134 pt->scale( | 137 pt->scale( |
135 pt->device()->width() / 1000.0f, | 138 pt->device()->width() / (float) APP_PRINT_WIDTH, |
136 pt->device()->height() / 1300.0f); | 139 pt->device()->height() / (float) APP_PRINT_HEIGHT); |
137 | 140 |
138 QFont font1; | 141 QFont font1; |
139 font1.setFamily("Arial"); | 142 font1.setFamily("Arial"); |
140 font1.setPixelSize(24); | 143 font1.setPixelSize(24); |
141 SLDrawContext ctx(pt); | 144 SLDrawContext ctx(pt); |
147 PersonInfo info; | 150 PersonInfo info; |
148 slGetPersonInfoRec(query, info); | 151 slGetPersonInfoRec(query, info); |
149 | 152 |
150 // Check for end of page | 153 // Check for end of page |
151 // KLUDGE for now | 154 // KLUDGE for now |
152 if (getPageInfo && ctx.lfq(10) >= 1300.0f - 50) | 155 if (getPageInfo && ctx.lfq(10) >= APP_PRINT_HEIGHT - ctx.boundRect().height() * 1.5f) |
153 { | 156 { |
154 if (nline > pinfo.nlinesPerPage) | 157 if (nline > pinfo.nlinesPerPage) |
155 pinfo.nlinesPerPage = nline; | 158 pinfo.nlinesPerPage = nline; |
156 | 159 |
157 pinfo.npages++; | 160 pinfo.npages++; |
170 ctx.drawText( 450, 190, tr("Lisätty")); | 173 ctx.drawText( 450, 190, tr("Lisätty")); |
171 ctx.drawText( 650, 190, tr("Päivitetty")); | 174 ctx.drawText( 650, 190, tr("Päivitetty")); |
172 ctx.drawText( 870, 120, tr("Tase")); | 175 ctx.drawText( 870, 120, tr("Tase")); |
173 ctx.lf(); | 176 ctx.lf(); |
174 | 177 |
175 pt->drawLine(0, ctx.m_pos.y(), 1000, ctx.m_pos.y()); | 178 pt->drawLine(0, ctx.m_pos.y(), APP_PRINT_WIDTH, ctx.m_pos.y()); |
176 | 179 |
177 ctx.move(0, 5); | 180 ctx.move(0, 5); |
178 } | 181 } |
179 | 182 |
180 // Draw a gray bar under every second line | 183 // Draw a gray bar under every second line |
181 if (nline % 2 == 0) | 184 if (nline % 2 == 0) |
182 { | 185 { |
183 pt->fillRect( | 186 pt->fillRect( |
184 0, | 187 0, |
185 ctx.m_pos.y() - 1, | 188 ctx.m_pos.y() - 1, |
186 1000, | 189 APP_PRINT_WIDTH, |
187 ctx.boundRect().height() + 4, | 190 ctx.boundRect().height() + 4, |
188 QColor(0, 0, 0, 40)); | 191 QColor(0, 0, 0, 40)); |
189 } | 192 } |
190 | 193 |
191 ctx.drawText( 5, 180, info.firstName); | 194 ctx.drawText( 5, 180, info.firstName); |
207 | 210 |
208 pinfo.npages++; | 211 pinfo.npages++; |
209 } | 212 } |
210 else | 213 else |
211 { | 214 { |
212 ctx.setPos(0, 1240); | 215 ctx.setPos(0, APP_PRINT_HEIGHT - ctx.boundRect().height()); |
213 ctx.drawText(0, 1000, | 216 ctx.drawText(0, APP_PRINT_WIDTH, |
214 tr("Sivu %1 / %2 (%3 / %4)"). | 217 tr("Sivu %1 / %2 (%3 / %4)"). |
215 arg(npage - printer->fromPage() + 1). | 218 arg(npage - printer->fromPage() + 1). |
216 arg(printer->toPage() - printer->fromPage() + 1). | 219 arg(printer->toPage() - printer->fromPage() + 1). |
217 arg(npage). | 220 arg(npage). |
218 arg(printer->toPage()), | 221 arg(printer->toPage()), |