From 20804b16d333f0a9d8b9f5e6eba05eddd60cc68e Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Wed, 10 Jul 2013 16:04:00 +0300 Subject: Print: add a setup() method to PrintLayout The setup() method will be called each time to obtain the current printer settings. Also it calculates required scalling based on screen agains printer DPI. Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 5 ++++- qt-ui/printlayout.cpp | 17 +++++++++++++++++ qt-ui/printlayout.h | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 9774a79f6..5652101ff 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -43,6 +43,9 @@ void PrintDialog::runDialog() void PrintDialog::printClicked(void) { - // nop for now + // temporary + printer.setOutputFileName("print.pdf"); + printer.setOutputFormat(QPrinter::PdfFormat); + // --------- printLayout->print(); } diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index 7716883e8..be5d955ea 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "mainwindow.h" #include "printlayout.h" @@ -21,6 +23,8 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op void PrintLayout::print() { + // we call setup each time to check if the printer properties have changed + setup(); switch (printOptions->type) { case options::PRETTY: printSixDives(); @@ -34,6 +38,19 @@ void PrintLayout::print() } } +void PrintLayout::setup() +{ + QDesktopWidget *desktop = QApplication::desktop(); + screenDpiX = desktop->physicalDpiX(); + screenDpiY = desktop->physicalDpiX(); + + printerDpi = printer->resolution(); + pageRect = printer->pageRect(); + + scaleX = (qreal)printerDpi/(qreal)screenDpiX; + scaleY = (qreal)printerDpi/(qreal)screenDpiY; +} + void PrintLayout::printSixDives() { // nop diff --git a/qt-ui/printlayout.h b/qt-ui/printlayout.h index e9129bff6..120f50d61 100644 --- a/qt-ui/printlayout.h +++ b/qt-ui/printlayout.h @@ -20,7 +20,11 @@ private: struct options *printOptions; QPainter painter; + int screenDpiX, screenDpiY, printerDpi; + qreal scaleX, scaleY; + QRect pageRect; + void setup(); void printSixDives(); void printTwoDives(); void printTable(); -- cgit v1.2.3-70-g09d2