changeset 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 a0b8bf6f0776
files src/printing.cpp
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/printing.cpp	Tue Sep 19 11:27:38 2017 +0300
+++ b/src/printing.cpp	Tue Sep 19 12:10:59 2017 +0300
@@ -10,6 +10,9 @@
 #include <QPrintPreviewDialog>
 #include "main.h"
 
+#define APP_PRINT_WIDTH        1000
+#define APP_PRINT_HEIGHT       1300
+
 
 void SyntilistaMainWindow::on_button_Print_clicked()
 {
@@ -25,7 +28,7 @@
     pinfo.npages = 0;
     pinfo.nlinesPerPage = 0;
 
-    QPixmap tmpPixmap(1000, 1300);
+    QPixmap tmpPixmap(APP_PRINT_WIDTH, APP_PRINT_HEIGHT);
     QPainter tmpPainter;
     tmpPainter.begin(&tmpPixmap);
     bool ret = printDocumentPage(true, -1, &tmpPainter, &printer);
@@ -132,8 +135,8 @@
 
     pt->save();
     pt->scale(
-        pt->device()->width() / 1000.0f,
-        pt->device()->height() / 1300.0f);
+        pt->device()->width() / (float) APP_PRINT_WIDTH,
+        pt->device()->height() / (float) APP_PRINT_HEIGHT);
 
     QFont font1;
     font1.setFamily("Arial");
@@ -149,7 +152,7 @@
 
         // Check for end of page
         // KLUDGE for now
-        if (getPageInfo && ctx.lfq(10) >= 1300.0f - 50)
+        if (getPageInfo && ctx.lfq(10) >= APP_PRINT_HEIGHT - ctx.boundRect().height() * 1.5f)
         {
             if (nline > pinfo.nlinesPerPage)
                 pinfo.nlinesPerPage = nline;
@@ -172,7 +175,7 @@
             ctx.drawText( 870,  120, tr("Tase"));
             ctx.lf();
 
-            pt->drawLine(0, ctx.m_pos.y(), 1000, ctx.m_pos.y());
+            pt->drawLine(0, ctx.m_pos.y(), APP_PRINT_WIDTH, ctx.m_pos.y());
 
             ctx.move(0, 5);
         }
@@ -183,7 +186,7 @@
             pt->fillRect(
                 0,
                 ctx.m_pos.y() - 1,
-                1000,
+                APP_PRINT_WIDTH,
                 ctx.boundRect().height() + 4,
                 QColor(0, 0, 0, 40));
         }
@@ -209,8 +212,8 @@
     }
     else
     {
-        ctx.setPos(0, 1240);
-        ctx.drawText(0, 1000,
+        ctx.setPos(0, APP_PRINT_HEIGHT - ctx.boundRect().height());
+        ctx.drawText(0, APP_PRINT_WIDTH,
             tr("Sivu %1 / %2 (%3 / %4)").
             arg(npage - printer->fromPage() + 1).
             arg(printer->toPage() - printer->fromPage() + 1).