Resolved issue #570. Error: Tiled PDF : field values not taken into account if
one of them is smaller than 0,3. --HG-- branch : develop
This commit is contained in:
parent
bf1e4aeb0c
commit
723d68b245
|
@ -572,44 +572,58 @@ void DialogLayoutSettings::DialogAccepted()
|
|||
|
||||
if (IsIgnoreAllFields())
|
||||
{
|
||||
generator->SetFields(QMarginsF());
|
||||
generator->SetPrinterFields(false, QMarginsF());
|
||||
}
|
||||
else
|
||||
{
|
||||
const QMarginsF minFields = RoundMargins(VSettings::GetDefFields());
|
||||
const QMarginsF fields = RoundMargins(GetFields());
|
||||
if (fields.left() < minFields.left() || fields.right() < minFields.right() ||
|
||||
fields.top() < minFields.top() || fields.bottom() < minFields.bottom())
|
||||
QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
|
||||
if (printer.isNull())
|
||||
{
|
||||
QMessageBox::StandardButton answer;
|
||||
answer = QMessageBox::question(this, tr("Wrong fields."),
|
||||
tr("Fields go beyond printing. \n\nApply settings anyway?"),
|
||||
QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
|
||||
if (answer == QMessageBox::No)
|
||||
generator->SetPrinterFields(true, GetFields());
|
||||
}
|
||||
else
|
||||
{
|
||||
const QMarginsF minFields = RoundMargins(GetMinPrinterFields());
|
||||
const QMarginsF fields = RoundMargins(GetFields());
|
||||
if (fields.left() < minFields.left() || fields.right() < minFields.right() ||
|
||||
fields.top() < minFields.top() || fields.bottom() < minFields.bottom())
|
||||
{
|
||||
if (fields.left() < minFields.left())
|
||||
QMessageBox::StandardButton answer;
|
||||
answer = QMessageBox::question(this, tr("Wrong fields."),
|
||||
tr("Fields go beyond printing. \n\nApply settings anyway?"),
|
||||
QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
|
||||
if (answer == QMessageBox::No)
|
||||
{
|
||||
ui->doubleSpinBoxLeftField->setValue(UnitConvertor(minFields.left(), Unit::Px, LayoutUnit()));
|
||||
}
|
||||
const QMarginsF defFields = RoundMargins(GetDefPrinterFields());
|
||||
if (fields.left() < defFields.left())
|
||||
{
|
||||
ui->doubleSpinBoxLeftField->setValue(UnitConvertor(defFields.left(), Unit::Px, LayoutUnit()));
|
||||
}
|
||||
|
||||
if (fields.right() < minFields.right())
|
||||
{
|
||||
ui->doubleSpinBoxRightField->setValue(UnitConvertor(minFields.right(), Unit::Px, LayoutUnit()));
|
||||
}
|
||||
if (fields.right() < defFields.right())
|
||||
{
|
||||
ui->doubleSpinBoxRightField->setValue(UnitConvertor(defFields.right(), Unit::Px, LayoutUnit()));
|
||||
}
|
||||
|
||||
if (fields.top() < minFields.top())
|
||||
{
|
||||
ui->doubleSpinBoxTopField->setValue(UnitConvertor(minFields.top(), Unit::Px, LayoutUnit()));
|
||||
}
|
||||
if (fields.top() < defFields.top())
|
||||
{
|
||||
ui->doubleSpinBoxTopField->setValue(UnitConvertor(defFields.top(), Unit::Px, LayoutUnit()));
|
||||
}
|
||||
|
||||
if (fields.bottom() < minFields.bottom())
|
||||
if (fields.bottom() < defFields.bottom())
|
||||
{
|
||||
ui->doubleSpinBoxBottomField->setValue(UnitConvertor(defFields.bottom(), Unit::Px,
|
||||
LayoutUnit()));
|
||||
}
|
||||
|
||||
generator->SetPrinterFields(true, GetFields());
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->doubleSpinBoxBottomField->setValue(UnitConvertor(minFields.bottom(), Unit::Px, LayoutUnit()));
|
||||
generator->SetPrinterFields(false, GetFields());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generator->SetFields(GetFields());
|
||||
}
|
||||
|
||||
//don't want to break visual settings when cmd used
|
||||
|
@ -637,7 +651,7 @@ void DialogLayoutSettings::RestoreDefaults()
|
|||
SetGroup(VSettings::GetDefLayoutGroup());
|
||||
SetRotate(VSettings::GetDefLayoutRotate());
|
||||
SetIncrease(VSettings::GetDefLayoutRotationIncrease());
|
||||
SetFields(VSettings::GetDefFields());
|
||||
SetFields(GetDefPrinterFields());
|
||||
SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields());
|
||||
SetMultiplier(VSettings::GetDefMultiplier());
|
||||
|
||||
|
@ -651,7 +665,11 @@ void DialogLayoutSettings::PrinterMargins()
|
|||
QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
|
||||
if (not printer.isNull())
|
||||
{
|
||||
SetFields(VSettings::GetPrinterFields(QSharedPointer<QPrinter>(new QPrinter(printer))));
|
||||
SetFields(GetPrinterFields(QSharedPointer<QPrinter>(new QPrinter(printer))));
|
||||
}
|
||||
else
|
||||
{
|
||||
SetFields(QMarginsF());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -940,6 +958,50 @@ QMarginsF DialogLayoutSettings::RoundMargins(const QMarginsF &margins) const
|
|||
return newMargins;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF DialogLayoutSettings::GetMinPrinterFields() const
|
||||
{
|
||||
QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
|
||||
if (not printer.isNull())
|
||||
{
|
||||
QSharedPointer<QPrinter> pr = QSharedPointer<QPrinter>(new QPrinter(printer));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
|
||||
QPageLayout layout = pr->pageLayout();
|
||||
layout.setUnits(QPageLayout::Millimeter);
|
||||
const QMarginsF minMargins = layout.minimumMargins();
|
||||
|
||||
QMarginsF min;
|
||||
min.setLeft(UnitConvertor(minMargins.left(), Unit::Mm, Unit::Px));
|
||||
min.setRight(UnitConvertor(minMargins.right(), Unit::Mm, Unit::Px));
|
||||
min.setTop(UnitConvertor(minMargins.top(), Unit::Mm, Unit::Px));
|
||||
min.setBottom(UnitConvertor(minMargins.bottom(), Unit::Mm, Unit::Px));
|
||||
return min;
|
||||
#else
|
||||
pr->setFullPage(false);
|
||||
pr->setPageMargins(0, 0, 0, 0, QPrinter::Millimeter);
|
||||
return GetPrinterFields(QSharedPointer<QPrinter>(new QPrinter(printer)));
|
||||
#endif //QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
return QMarginsF();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF DialogLayoutSettings::GetDefPrinterFields() const
|
||||
{
|
||||
QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
|
||||
if (not printer.isNull())
|
||||
{
|
||||
return GetPrinterFields(QSharedPointer<QPrinter>(new QPrinter(printer)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return QMarginsF();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Unit DialogLayoutSettings::PaperUnit() const
|
||||
{
|
||||
|
@ -1043,7 +1105,7 @@ void DialogLayoutSettings::ReadSettings()
|
|||
SetAutoCrop(settings->GetLayoutAutoCrop());
|
||||
SetSaveLength(settings->GetLayoutSaveLength());
|
||||
SetUnitePages(settings->GetLayoutUnitePages());
|
||||
SetFields(settings->GetFields());
|
||||
SetFields(settings->GetFields(GetDefPrinterFields()));
|
||||
SetIgnoreAllFields(settings->GetIgnoreAllFields());
|
||||
SetStripOptimization(settings->GetStripOptimization());
|
||||
SetMultiplier(settings->GetMultiplier());
|
||||
|
@ -1096,3 +1158,25 @@ void DialogLayoutSettings::SetAdditionalOptions(bool value)
|
|||
SetUnitePages(value);
|
||||
SetStripOptimization(value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF DialogLayoutSettings::GetPrinterFields(const QSharedPointer<QPrinter> &printer)
|
||||
{
|
||||
if (printer.isNull())
|
||||
{
|
||||
return QMarginsF();
|
||||
}
|
||||
|
||||
qreal left = 0;
|
||||
qreal top = 0;
|
||||
qreal right = 0;
|
||||
qreal bottom = 0;
|
||||
printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
|
||||
// We can't use Unit::Px because our dpi in most cases is different
|
||||
QMarginsF def;
|
||||
def.setLeft(UnitConvertor(left, Unit::Mm, Unit::Px));
|
||||
def.setRight(UnitConvertor(right, Unit::Mm, Unit::Px));
|
||||
def.setTop(UnitConvertor(top, Unit::Mm, Unit::Px));
|
||||
def.setBottom(UnitConvertor(bottom, Unit::Mm, Unit::Px));
|
||||
return def;
|
||||
}
|
||||
|
|
|
@ -159,6 +159,8 @@ private:
|
|||
QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const;
|
||||
QSizeF RoundTemplateSize(qreal width, qreal height) const;
|
||||
QMarginsF RoundMargins(const QMarginsF &margins) const;
|
||||
QMarginsF GetMinPrinterFields() const;
|
||||
QMarginsF GetDefPrinterFields() const;
|
||||
|
||||
Unit PaperUnit() const;
|
||||
Unit LayoutUnit() const;
|
||||
|
@ -174,6 +176,8 @@ private:
|
|||
|
||||
void SheetSize(const QSizeF &size);
|
||||
void SetAdditionalOptions(bool value);
|
||||
|
||||
static QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer);
|
||||
};
|
||||
|
||||
#endif // DIALOGLAYOUTSETTINGS_H
|
||||
|
|
|
@ -205,6 +205,12 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Printer:</string>
|
||||
</property>
|
||||
|
@ -292,7 +298,7 @@
|
|||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxIgnoreFileds">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@ -726,7 +732,7 @@
|
|||
</connection>
|
||||
</connections>
|
||||
<buttongroups>
|
||||
<buttongroup name="buttonGroupPrinciple"/>
|
||||
<buttongroup name="buttonGroup"/>
|
||||
<buttongroup name="buttonGroupPrinciple"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
|
|
|
@ -65,6 +65,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
|
|||
undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), actionDockWidgetGroups(nullptr),
|
||||
curFile(QString()),
|
||||
isLayoutStale(true),
|
||||
ignorePrinterFields(false),
|
||||
margins(),
|
||||
paperSize(),
|
||||
isTiled(false),
|
||||
|
@ -137,7 +138,8 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
|
|||
CreateShadows();
|
||||
CreateScenes();
|
||||
PrepareSceneList();
|
||||
margins = lGenerator.GetFields();
|
||||
ignorePrinterFields = not lGenerator.IsUsePrinterFields();
|
||||
margins = lGenerator.GetPrinterFields();
|
||||
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
|
||||
isAutoCrop = lGenerator.GetAutoCrop();
|
||||
isUnitePages = lGenerator.IsUnitePages();
|
||||
|
@ -647,6 +649,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const
|
|||
{
|
||||
printer.setOrientation(QPrinter::Landscape);
|
||||
}
|
||||
printer.setFullPage(ignorePrinterFields);
|
||||
printer.setPaperSize ( QSizeF(FromPixel(r.width() + margins.left() + margins.right(), Unit::Mm),
|
||||
FromPixel(r.height() + margins.top() + margins.bottom(), Unit::Mm)),
|
||||
QPrinter::Millimeter );
|
||||
|
@ -955,6 +958,8 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr
|
|||
}
|
||||
}
|
||||
|
||||
printer->setFullPage(ignorePrinterFields);
|
||||
|
||||
const qreal left = FromPixel(margins.left(), Unit::Mm);
|
||||
const qreal top = FromPixel(margins.top(), Unit::Mm);
|
||||
const qreal right = FromPixel(margins.right(), Unit::Mm);
|
||||
|
|
|
@ -86,6 +86,7 @@ protected:
|
|||
QString curFile;
|
||||
|
||||
bool isLayoutStale;
|
||||
bool ignorePrinterFields;
|
||||
QMarginsF margins;
|
||||
QSizeF paperSize;
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ class QMarginsF;
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VLayoutGenerator::VLayoutGenerator(QObject *parent)
|
||||
:QObject(parent), papers(QVector<VLayoutPaper>()), bank(new VBank()), paperHeight(0), paperWidth(0), margins(),
|
||||
stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180),
|
||||
autoCrop(false), saveLength(false), unitePages(false), stripOptimizationEnabled(false), multiplier(1),
|
||||
stripOptimization(false)
|
||||
usePrinterFields(true),stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true),
|
||||
rotationIncrease(180), autoCrop(false), saveLength(false), unitePages(false), stripOptimizationEnabled(false),
|
||||
multiplier(1), stripOptimization(false)
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -499,14 +499,21 @@ void VLayoutGenerator::SetPaperWidth(qreal value)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF VLayoutGenerator::GetFields() const
|
||||
bool VLayoutGenerator::IsUsePrinterFields() const
|
||||
{
|
||||
return usePrinterFields;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF VLayoutGenerator::GetPrinterFields() const
|
||||
{
|
||||
return margins;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VLayoutGenerator::SetFields(const QMarginsF &value)
|
||||
void VLayoutGenerator::SetPrinterFields(bool usePrinterFields, const QMarginsF &value)
|
||||
{
|
||||
this->usePrinterFields = usePrinterFields;
|
||||
margins = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,8 +71,9 @@ public:
|
|||
qreal GetPaperWidth() const;
|
||||
void SetPaperWidth(qreal value);
|
||||
|
||||
QMarginsF GetFields() const;
|
||||
void SetFields(const QMarginsF &value);
|
||||
bool IsUsePrinterFields() const;
|
||||
QMarginsF GetPrinterFields() const;
|
||||
void SetPrinterFields(bool usePrinterFields, const QMarginsF &value);
|
||||
|
||||
quint32 GetShift() const;
|
||||
void SetShift(quint32 shift);
|
||||
|
@ -121,6 +122,7 @@ private:
|
|||
qreal paperHeight;
|
||||
qreal paperWidth;
|
||||
QMarginsF margins;
|
||||
bool usePrinterFields;
|
||||
volatile bool stopGeneration;
|
||||
LayoutErrors state;
|
||||
quint32 shift;
|
||||
|
|
|
@ -362,9 +362,8 @@ void VSettings::SetLayoutWidth(qreal value)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF VSettings::GetFields() const
|
||||
QMarginsF VSettings::GetFields(const QMarginsF &def) const
|
||||
{
|
||||
const QMarginsF def = GetDefFields();
|
||||
const QVariant val = value(SettingFields, QVariant::fromValue(def));
|
||||
if (val.canConvert<QMarginsF>())
|
||||
{
|
||||
|
@ -373,34 +372,6 @@ QMarginsF VSettings::GetFields() const
|
|||
return def;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF VSettings::GetDefFields()
|
||||
{
|
||||
return GetPrinterFields(PreparePrinter(QPrinterInfo::defaultPrinter()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMarginsF VSettings::GetPrinterFields(const QSharedPointer<QPrinter> &printer)
|
||||
{
|
||||
if (printer.isNull())
|
||||
{
|
||||
return QMarginsF();
|
||||
}
|
||||
|
||||
qreal left = 0;
|
||||
qreal top = 0;
|
||||
qreal right = 0;
|
||||
qreal bottom = 0;
|
||||
printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
|
||||
// We can't use Unit::Px because our dpi in most cases is different
|
||||
QMarginsF def;
|
||||
def.setLeft(UnitConvertor(left, Unit::Mm, Unit::Px));
|
||||
def.setRight(UnitConvertor(right, Unit::Mm, Unit::Px));
|
||||
def.setTop(UnitConvertor(top, Unit::Mm, Unit::Px));
|
||||
def.setBottom(UnitConvertor(bottom, Unit::Mm, Unit::Px));
|
||||
return def;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetFields(const QMarginsF &value)
|
||||
{
|
||||
|
|
|
@ -112,9 +112,7 @@ public:
|
|||
static qreal GetDefLayoutWidth();
|
||||
void SetLayoutWidth(qreal value);
|
||||
|
||||
QMarginsF GetFields() const;
|
||||
static QMarginsF GetDefFields();
|
||||
static QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer);
|
||||
QMarginsF GetFields(const QMarginsF &def = QMarginsF()) const;
|
||||
void SetFields(const QMarginsF &value);
|
||||
|
||||
Cases GetLayoutGroup() const;
|
||||
|
|
Loading…
Reference in New Issue
Block a user