changeset 160:1c2f9d09e87b

Begin working on printing fixes.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 19 Sep 2017 11:27:38 +0300
parents d2905ee5ff9c
children eeb3bb877b63
files src/main.h src/printing.cpp
diffstat 2 files changed, 13 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.h	Mon Sep 18 09:50:23 2017 +0300
+++ b/src/main.h	Tue Sep 19 11:27:38 2017 +0300
@@ -165,7 +165,7 @@
     void updateMiscValues();
     void backupDatabase();
 
-    bool printDocumentPage(SLPageInfo &pinfo, const bool getPageInfo, const int page, QPainter *pt, QPrinter *printer);
+    bool printDocumentPage(const bool getPageInfo, const int page, QPainter *pt, QPrinter *printer);
 
     PersonSQLModel *model_People;
 
@@ -224,6 +224,8 @@
     int peopleSortIndex;
     Qt::SortOrder peopleSortOrder;
     QString peopleFilter;
+
+    SLPageInfo pinfo;
 };
 
 
--- a/src/printing.cpp	Mon Sep 18 09:50:23 2017 +0300
+++ b/src/printing.cpp	Tue Sep 19 11:27:38 2017 +0300
@@ -22,14 +22,13 @@
     // We need to get the page count here, and also need it again in
     // printDocument(), but there is no sane way to pass that there,
     // so some code duplication is unfortunately necessary
-    SLPageInfo pinfo;
     pinfo.npages = 0;
     pinfo.nlinesPerPage = 0;
 
     QPixmap tmpPixmap(1000, 1300);
     QPainter tmpPainter;
     tmpPainter.begin(&tmpPixmap);
-    bool ret = printDocumentPage(pinfo, true, -1, &tmpPainter, &printer);
+    bool ret = printDocumentPage(true, -1, &tmpPainter, &printer);
     tmpPainter.end();
 
     if (!ret)
@@ -69,20 +68,6 @@
 
     progress.setWindowModality(Qt::ApplicationModal);
 
-    // Again, get the page info here .. we need the number of lines per page
-    SLPageInfo pinfo;
-    pinfo.npages = 0;
-    pinfo.nlinesPerPage = 0;
-
-    QPixmap tmpPixmap(1000, 1300);
-    QPainter tmpPainter;
-    tmpPainter.begin(&tmpPixmap);
-    bool ret = printDocumentPage(pinfo, true, -1, &tmpPainter, printer);
-    tmpPainter.end();
-
-    if (!ret)
-        return;
-
     // If from and to are 0, we are supposed to print all pages
     if (printer->fromPage() == 0 && printer->toPage() == 0)
         printer->setFromTo(1, pinfo.npages);
@@ -105,7 +90,7 @@
         if (progress.wasCanceled())
             break;
 
-        printDocumentPage(pinfo, false, page, &painter, printer);
+        printDocumentPage(false, page, &painter, printer);
         progress.setValue(page);
         firstPage = false;
     }
@@ -114,7 +99,7 @@
 }
 
 
-bool SyntilistaMainWindow::printDocumentPage(SLPageInfo &pinfo, const bool getPageInfo, const int npage, QPainter *pt, QPrinter *printer)
+bool SyntilistaMainWindow::printDocumentPage(const bool getPageInfo, const int npage, QPainter *pt, QPrinter *printer)
 {
     // Form the SQL query for list of users
     QString querystr = QStringLiteral(
@@ -146,14 +131,13 @@
     }
 
     pt->save();
-    if (!getPageInfo)
-    {
-        pt->scale(
-            printer->pageRect().width() / 1000.0f,
-            printer->pageRect().height() / 1300.0f);
-    }
+    pt->scale(
+        pt->device()->width() / 1000.0f,
+        pt->device()->height() / 1300.0f);
 
-    QFont font1("Arial", 5);
+    QFont font1;
+    font1.setFamily("Arial");
+    font1.setPixelSize(24);
     SLDrawContext ctx(pt);
     ctx.setFont(font1);
 
@@ -165,7 +149,7 @@
 
         // Check for end of page
         // KLUDGE for now
-        if (getPageInfo && ctx.lfq(10) >= 1300.0f)
+        if (getPageInfo && ctx.lfq(10) >= 1300.0f - 50)
         {
             if (nline > pinfo.nlinesPerPage)
                 pinfo.nlinesPerPage = nline;