comparison src/printing.cpp @ 160:1c2f9d09e87b

Begin working on printing fixes.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 19 Sep 2017 11:27:38 +0300
parents f5c1861b48aa
children eeb3bb877b63
comparison
equal deleted inserted replaced
159:d2905ee5ff9c 160:1c2f9d09e87b
20 printer.setResolution(300); 20 printer.setResolution(300);
21 21
22 // We need to get the page count here, and also need it again in 22 // We need to get the page count here, and also need it again in
23 // printDocument(), but there is no sane way to pass that there, 23 // printDocument(), but there is no sane way to pass that there,
24 // so some code duplication is unfortunately necessary 24 // so some code duplication is unfortunately necessary
25 SLPageInfo pinfo;
26 pinfo.npages = 0; 25 pinfo.npages = 0;
27 pinfo.nlinesPerPage = 0; 26 pinfo.nlinesPerPage = 0;
28 27
29 QPixmap tmpPixmap(1000, 1300); 28 QPixmap tmpPixmap(1000, 1300);
30 QPainter tmpPainter; 29 QPainter tmpPainter;
31 tmpPainter.begin(&tmpPixmap); 30 tmpPainter.begin(&tmpPixmap);
32 bool ret = printDocumentPage(pinfo, true, -1, &tmpPainter, &printer); 31 bool ret = printDocumentPage(true, -1, &tmpPainter, &printer);
33 tmpPainter.end(); 32 tmpPainter.end();
34 33
35 if (!ret) 34 if (!ret)
36 { 35 {
37 // Some kind of error occured 36 // Some kind of error occured
67 1, 66 1,
68 this); 67 this);
69 68
70 progress.setWindowModality(Qt::ApplicationModal); 69 progress.setWindowModality(Qt::ApplicationModal);
71 70
72 // Again, get the page info here .. we need the number of lines per page
73 SLPageInfo pinfo;
74 pinfo.npages = 0;
75 pinfo.nlinesPerPage = 0;
76
77 QPixmap tmpPixmap(1000, 1300);
78 QPainter tmpPainter;
79 tmpPainter.begin(&tmpPixmap);
80 bool ret = printDocumentPage(pinfo, true, -1, &tmpPainter, printer);
81 tmpPainter.end();
82
83 if (!ret)
84 return;
85
86 // If from and to are 0, we are supposed to print all pages 71 // If from and to are 0, we are supposed to print all pages
87 if (printer->fromPage() == 0 && printer->toPage() == 0) 72 if (printer->fromPage() == 0 && printer->toPage() == 0)
88 printer->setFromTo(1, pinfo.npages); 73 printer->setFromTo(1, pinfo.npages);
89 74
90 // Setup rest of the progress dialog here 75 // Setup rest of the progress dialog here
103 88
104 qApp->processEvents(); 89 qApp->processEvents();
105 if (progress.wasCanceled()) 90 if (progress.wasCanceled())
106 break; 91 break;
107 92
108 printDocumentPage(pinfo, false, page, &painter, printer); 93 printDocumentPage(false, page, &painter, printer);
109 progress.setValue(page); 94 progress.setValue(page);
110 firstPage = false; 95 firstPage = false;
111 } 96 }
112 97
113 painter.end(); 98 painter.end();
114 } 99 }
115 100
116 101
117 bool SyntilistaMainWindow::printDocumentPage(SLPageInfo &pinfo, const bool getPageInfo, const int npage, QPainter *pt, QPrinter *printer) 102 bool SyntilistaMainWindow::printDocumentPage(const bool getPageInfo, const int npage, QPainter *pt, QPrinter *printer)
118 { 103 {
119 // Form the SQL query for list of users 104 // Form the SQL query for list of users
120 QString querystr = QStringLiteral( 105 QString querystr = QStringLiteral(
121 "SELECT id,first_name,last_name,extra_info,added,updated, " 106 "SELECT id,first_name,last_name,extra_info,added,updated, "
122 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance " 107 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance "
144 129
145 return false; 130 return false;
146 } 131 }
147 132
148 pt->save(); 133 pt->save();
149 if (!getPageInfo) 134 pt->scale(
150 { 135 pt->device()->width() / 1000.0f,
151 pt->scale( 136 pt->device()->height() / 1300.0f);
152 printer->pageRect().width() / 1000.0f, 137
153 printer->pageRect().height() / 1300.0f); 138 QFont font1;
154 } 139 font1.setFamily("Arial");
155 140 font1.setPixelSize(24);
156 QFont font1("Arial", 5);
157 SLDrawContext ctx(pt); 141 SLDrawContext ctx(pt);
158 ctx.setFont(font1); 142 ctx.setFont(font1);
159 143
160 int nline = 0; 144 int nline = 0;
161 while (query.next()) 145 while (query.next())
163 PersonInfo info; 147 PersonInfo info;
164 slGetPersonInfoRec(query, info); 148 slGetPersonInfoRec(query, info);
165 149
166 // Check for end of page 150 // Check for end of page
167 // KLUDGE for now 151 // KLUDGE for now
168 if (getPageInfo && ctx.lfq(10) >= 1300.0f) 152 if (getPageInfo && ctx.lfq(10) >= 1300.0f - 50)
169 { 153 {
170 if (nline > pinfo.nlinesPerPage) 154 if (nline > pinfo.nlinesPerPage)
171 pinfo.nlinesPerPage = nline; 155 pinfo.nlinesPerPage = nline;
172 156
173 pinfo.npages++; 157 pinfo.npages++;