diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index df271b77c..8ad40ce3c 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -35,6 +35,7 @@ #include #include +#include //must be the same order as PaperSizeTemplate constants const DialogLayoutSettings::FormatsVector DialogLayoutSettings::pageFormatNames = @@ -68,6 +69,7 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget InitTemplates(); MinimumPaperSize(); MinimumLayoutSize(); + InitPrinter(); //in export console mode going to use defaults if (disableSettings == false) @@ -79,24 +81,27 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget RestoreDefaults(); } - connect(ui->comboBoxTemplates, static_cast(&QComboBox::currentIndexChanged), + connect(ui->comboBoxPrinter, static_cast(&QComboBox::currentIndexChanged), + this, &DialogLayoutSettings::PrinterMargins); + + connect(ui->comboBoxTemplates, static_cast(&QComboBox::currentIndexChanged), this, &DialogLayoutSettings::TemplateSelected); - connect(ui->comboBoxPaperSizeUnit, static_cast(&QComboBox::currentIndexChanged), + connect(ui->comboBoxPaperSizeUnit, static_cast(&QComboBox::currentIndexChanged), this, &DialogLayoutSettings::ConvertPaperSize); - connect(ui->doubleSpinBoxPaperWidth, static_cast(&QDoubleSpinBox::valueChanged), + connect(ui->doubleSpinBoxPaperWidth, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogLayoutSettings::PaperSizeChanged); - connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), + connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogLayoutSettings::PaperSizeChanged); - connect(ui->doubleSpinBoxPaperWidth, static_cast(&QDoubleSpinBox::valueChanged), + connect(ui->doubleSpinBoxPaperWidth, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogLayoutSettings::FindTemplate); - connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), + connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogLayoutSettings::FindTemplate); - connect(ui->doubleSpinBoxPaperWidth, static_cast(&QDoubleSpinBox::valueChanged), + connect(ui->doubleSpinBoxPaperWidth, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogLayoutSettings::CorrectMaxFileds); - connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), + connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogLayoutSettings::CorrectMaxFileds); connect(ui->checkBoxIgnoreFileds, &QCheckBox::stateChanged, this, &DialogLayoutSettings::IgnoreAllFields); @@ -333,6 +338,12 @@ void DialogLayoutSettings::SetIgnoreAllFields(bool value) ui->checkBoxIgnoreFileds->setChecked(value); } +//--------------------------------------------------------------------------------------------------------------------- +QString DialogLayoutSettings::SelectedPrinter() const +{ + return ui->comboBoxPrinter->currentText(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::TemplateSelected() { @@ -617,6 +628,10 @@ void DialogLayoutSettings::RestoreDefaults() TemplateSelected(); ui->comboBoxTemplates->blockSignals(false); + ui->comboBoxPrinter->blockSignals(true); + InitPrinter(); + ui->comboBoxPrinter->blockSignals(false); + SetLayoutWidth(VSettings::GetDefLayoutWidth()); SetShift(VSettings::GetDefLayoutShift()); SetGroup(VSettings::GetDefLayoutGroup()); @@ -630,6 +645,16 @@ void DialogLayoutSettings::RestoreDefaults() IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked()); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::PrinterMargins() +{ + QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText()); + if (not printer.isNull()) + { + SetFields(VSettings::GetPrinterFields(QSharedPointer(new QPrinter(printer)))); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::CorrectMaxFileds() { @@ -714,6 +739,51 @@ void DialogLayoutSettings::InitTemplates() ui->comboBoxTemplates->setCurrentIndex(-1); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::InitPrinter() +{ + ui->comboBoxPrinter->clear(); + QStringList printerNames; +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) + const QList printers = QPrinterInfo::availablePrinters(); + for(int i = 0; i < printers.size(); ++i) + { + const QString name = printers.at(i).printerName(); + if (not name.isEmpty()) + { + printerNames.append(name); + } + } +#else + printerNames = QPrinterInfo::availablePrinterNames(); +#endif + + ui->comboBoxPrinter->addItems(printerNames); + + if (ui->comboBoxPrinter->count() == 0) + { + ui->comboBoxPrinter->addItem(tr("None", "Printer")); + } + else + { + QString defPrinterName; +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) + const QPrinterInfo def = QPrinterInfo::defaultPrinter(); + if(not def.isNull()) + { + defPrinterName = def.printerName(); + } +#else + defPrinterName = QPrinterInfo::defaultPrinterName(); +#endif + const int index = ui->comboBoxPrinter->findText(defPrinterName); + if(index != -1) + { + ui->comboBoxPrinter->setCurrentIndex(index); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogLayoutSettings::MakeHelpTemplateList() { diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index c5d2ca605..982b0608f 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -111,6 +111,8 @@ public: bool IsIgnoreAllFields() const; void SetIgnoreAllFields(bool value); + QString SelectedPrinter() const; + //support functions for the command line parser which uses invisible dialog to properly build layout generator bool SelectTemplate(const PaperSizeTemplate& id); static QString MakeHelpTemplateList(); @@ -131,6 +133,7 @@ private slots: void PaperSizeChanged(); void Swap(bool checked); void RestoreDefaults(); + void PrinterMargins(); void CorrectMaxFileds(); void IgnoreAllFields(int state); @@ -151,6 +154,7 @@ private: void InitPaperUnits(); void InitLayoutUnits(); void InitTemplates(); + void InitPrinter(); QSizeF Template(); QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const; QSizeF RoundTemplateSize(qreal width, qreal height) const; diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.ui b/src/app/valentina/dialogs/dialoglayoutsettings.ui index 639c95100..1cbf210e8 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.ui +++ b/src/app/valentina/dialogs/dialoglayoutsettings.ui @@ -6,7 +6,7 @@ 0 0 - 632 + 600 531 @@ -72,64 +72,6 @@ - - - - - 0 - 0 - - - - Width: - - - - - - - - 0 - 0 - - - - Height: - - - - - - - - 94 - 0 - - - - 2 - - - 99999.000000000000000 - - - - - - - - 94 - 0 - - - - 2 - - - 99999.990000000005239 - - - @@ -180,6 +122,32 @@ + + + + + 0 + 0 + + + + Width: + + + + + + + + 0 + 0 + + + + Height: + + + @@ -196,13 +164,65 @@ + + + + + 94 + 0 + + + + 2 + + + 99999.000000000000000 + + + + + + + + 94 + 0 + + + + 2 + + + 99999.990000000005239 + + + + + + + + + Printer: + + + + + + + + + + + 0 + 0 + + Fields @@ -210,72 +230,78 @@ QFormLayout::ExpandingFieldsGrow - + Left: - + 5 - + Right: - + 5 - + Top: - + 5 - + Bottom: - + 5 - - - - Ignore fileds - - - + + + + + 0 + 0 + + + + Ignore fileds + + + @@ -700,7 +726,7 @@ - + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index c0dcf2379..5259e4250 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -69,7 +69,8 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) paperSize(), isTiled(false), isAutoCrop(false), - isUnitePages(false) + isUnitePages(false), + layoutPrinterName() { InitTempLayoutScene(); @@ -98,6 +99,7 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked) tButton->setChecked(false); return; } + layoutPrinterName = layout.SelectedPrinter(); LayoutSettings(lGenerator); tButton->setChecked(false); } @@ -854,7 +856,12 @@ void MainWindowsNoGUI::PrintPreview() } } - QSharedPointer printer = DefaultPrinter(); + QPrinterInfo info = QPrinterInfo::printerInfo(layoutPrinterName); + if(info.isNull() || info.printerName().isEmpty()) + { + info = QPrinterInfo::defaultPrinter(); + } + QSharedPointer printer = PreparePrinter(info); if (printer.isNull()) { qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), @@ -881,7 +888,12 @@ void MainWindowsNoGUI::LayoutPrint() } } // display print dialog and if accepted print - QSharedPointer printer = DefaultPrinter(QPrinter::HighResolution); + QPrinterInfo info = QPrinterInfo::printerInfo(layoutPrinterName); + if(info.isNull() || info.printerName().isEmpty()) + { + info = QPrinterInfo::defaultPrinter(); + } + QSharedPointer printer = PreparePrinter(info, QPrinter::HighResolution); if (printer.isNull()) { qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 84394802a..208828f9d 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -109,6 +109,8 @@ private: bool isAutoCrop; bool isUnitePages; + QString layoutPrinterName; + void CreateShadows(); void CreateScenes(); diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index d029584c9..3af5215fd 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -1813,24 +1813,35 @@ QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath) } //--------------------------------------------------------------------------------------------------------------------- -QSharedPointer DefaultPrinter(QPrinter::PrinterMode mode) +QSharedPointer PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) { - QPrinterInfo def = QPrinterInfo::defaultPrinter(); - - //if there is no default printer set the print preview won't show - if(def.isNull() || def.printerName().isEmpty()) + QPrinterInfo tmpInfo = info; + if(tmpInfo.isNull() || tmpInfo.printerName().isEmpty()) { - if(QPrinterInfo::availablePrinters().isEmpty()) +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) + const QList list = QPrinterInfo::availablePrinters(); + if(list.isEmpty()) { return QSharedPointer(); } else { - def = QPrinterInfo::availablePrinters().first(); + tmpInfo = list.first(); } +#else + const QStringList list = QPrinterInfo::availablePrinterNames(); + if(list.isEmpty()) + { + return QSharedPointer(); + } + else + { + tmpInfo = QPrinterInfo::printerInfo(list.first()); + } +#endif } - auto printer = QSharedPointer(new QPrinter(def, mode)); + auto printer = QSharedPointer(new QPrinter(tmpInfo, mode)); printer->setResolution(static_cast(PrintDPI)); return printer; } diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 1d3003616..9a9d385b1 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -620,7 +620,8 @@ 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(QPrinter::PrinterMode mode = QPrinter::ScreenResolution) Q_REQUIRED_RESULT; +QSharedPointer PreparePrinter(const QPrinterInfo &info, + QPrinter::PrinterMode mode = QPrinter::ScreenResolution) Q_REQUIRED_RESULT; QPixmap darkenPixmap(const QPixmap &pixmap) Q_REQUIRED_RESULT; diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index a00f73bed..1340562e2 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -375,7 +376,12 @@ QMarginsF VSettings::GetFields() const //--------------------------------------------------------------------------------------------------------------------- QMarginsF VSettings::GetDefFields() { - QSharedPointer printer = DefaultPrinter(); + return GetPrinterFields(PreparePrinter(QPrinterInfo::defaultPrinter())); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VSettings::GetPrinterFields(const QSharedPointer &printer) +{ if (printer.isNull()) { return QMarginsF(); diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index ec978e1db..f1cf57cd8 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -39,6 +39,8 @@ #include "vcommonsettings.h" class QMarginsF; +class QPrinter; +template class QSharedPointer; #if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) # include "../vmisc/backport/qmarginsf.h" @@ -112,6 +114,7 @@ public: QMarginsF GetFields() const; static QMarginsF GetDefFields(); + static QMarginsF GetPrinterFields(const QSharedPointer &printer); void SetFields(const QMarginsF &value); Cases GetLayoutGroup() const;