From 080da6d3e1c3420d66173900154a6e84bf7a952f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 1 Jun 2016 21:55:27 +0300 Subject: [PATCH] Try to fix issue #494. Seems like default constructor on mac creates non-native printer by default or default printer can't be found. --HG-- branch : develop --- src/app/valentina/mainwindowsnogui.cpp | 17 ++++++++++++----- src/libs/vmisc/def.cpp | 4 ++-- src/libs/vmisc/def.h | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 2cbf03c0f..9e1d1c4b8 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -849,15 +849,22 @@ void MainWindowsNoGUI::LayoutPrint() } } // display print dialog and if accepted print - QPrinter printer(QPrinter::HighResolution); - SetPrinterSettings(&printer); - QPrintDialog dialog( &printer, this ); + QSharedPointer printer = DefaultPrinter(QPrinter::HighResolution); + if (printer.isNull()) + { + qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), + qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); + return; + } + + SetPrinterSettings(printer.data()); + QPrintDialog dialog(printer.data(), this ); // If only user couldn't change page margins we could use method setMinMax(); dialog.setOption(QPrintDialog::PrintCurrentPage, false); if ( dialog.exec() == QDialog::Accepted ) { - printer.setResolution(static_cast(PrintDPI)); - PrintPages( &printer ); + printer->setResolution(static_cast(PrintDPI)); + PrintPages(printer.data()); } } diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 9b2d3b430..7810ed974 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -1750,7 +1750,7 @@ QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath) } //--------------------------------------------------------------------------------------------------------------------- -QSharedPointer DefaultPrinter() +QSharedPointer DefaultPrinter(QPrinter::PrinterMode mode) { QPrinterInfo def = QPrinterInfo::defaultPrinter(); @@ -1767,7 +1767,7 @@ QSharedPointer DefaultPrinter() } } - QSharedPointer printer = QSharedPointer(new QPrinter(def, QPrinter::ScreenResolution)); + QSharedPointer printer = QSharedPointer(new QPrinter(def, mode)); printer->setResolution(static_cast(PrintDPI)); return printer; } diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 2353e421f..85530d62e 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef Q_OS_WIN #include #endif /* Q_OS_WIN */ @@ -44,7 +45,6 @@ #endif /* Q_CC_MSVC */ class QComboBox; -class QPrinter; #define SceneSize 50000 #define DefPointRadius 1.5//mm @@ -611,7 +611,7 @@ QString StrippedName(const QString &fullFileName) Q_REQUIRED_RESULT; QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath) Q_REQUIRED_RESULT; QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath) Q_REQUIRED_RESULT; -QSharedPointer DefaultPrinter() Q_REQUIRED_RESULT; +QSharedPointer DefaultPrinter(QPrinter::PrinterMode mode = QPrinter::ScreenResolution) Q_REQUIRED_RESULT; QPixmap darkenPixmap(const QPixmap &pixmap) Q_REQUIRED_RESULT;