53 #include "ui_dialoglayoutsettings.h"
54 #include "../core/vapplication.h"
55 #include "../ifc/xml/vdomdocument.h"
56 #include "../vmisc/vsettings.h"
57 #include "../vmisc/vmath.h"
58 #include "../vlayout/vlayoutgenerator.h"
60 #include <QMessageBox>
61 #include <QPushButton>
62 #include <QPrinterInfo>
67 oldLayoutUnit(
Unit::
Mm), generator(generator), isInitialized(false)
70 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
72 qApp->Seamly2DSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
93 connect(
ui->comboBoxPrinter,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
96 connect(
ui->comboBoxTemplates,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
98 connect(
ui->comboBoxPaperSizeUnit,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
101 connect(
ui->doubleSpinBoxPaperWidth,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
103 connect(
ui->doubleSpinBoxPaperHeight,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
106 connect(
ui->doubleSpinBoxPaperWidth,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
108 connect(
ui->doubleSpinBoxPaperHeight,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
111 connect(
ui->doubleSpinBoxPaperWidth,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
113 connect(
ui->doubleSpinBoxPaperHeight,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
120 connect(
ui->comboBoxLayoutUnit,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
123 QPushButton *ok_Button =
ui->buttonBox->button(QDialogButtonBox::Ok);
126 QPushButton *bRestoreDefaults =
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults);
209 if (
ui->radioButtonThreeGroups->isChecked())
213 else if (
ui->radioButtonTwoGroups->isChecked())
230 ui->radioButtonThreeGroups->setChecked(
true);
233 ui->radioButtonTwoGroups->setChecked(
true);
237 ui->radioButtonDescendingArea->setChecked(
true);
245 return ui->groupBoxRotate->isChecked();
251 ui->groupBoxRotate->setChecked(state);
257 return ui->comboBoxIncrease->currentText().toInt();
264 int index =
ui->comboBoxIncrease->findText(QString::number(increase));
265 bool failed = (index == -1);
269 index =
ui->comboBoxIncrease->findText(def);
272 ui->comboBoxIncrease->setCurrentIndex(index);
279 return ui->checkBoxAutoCrop->isChecked();
285 ui->checkBoxAutoCrop->setChecked(autoCrop);
291 return ui->checkBoxSaveLength->isChecked();
297 ui->checkBoxSaveLength->setChecked(save);
303 return ui->checkBoxUnitePages->isChecked();
309 ui->checkBoxUnitePages->setChecked(save);
315 return ui->groupBoxStrips->isChecked();
321 ui->groupBoxStrips->setChecked(save);
327 return static_cast<quint8
>(
ui->spinBoxMultiplier->value());
333 ui->spinBoxMultiplier->setValue(
static_cast<int>(value));
339 return ui->checkBoxIgnoreFileds->isChecked();
345 ui->checkBoxIgnoreFileds->setChecked(value);
351 return ui->textAsPaths_Checkbox->isChecked();
357 ui->textAsPaths_Checkbox->setChecked(value);
363 return ui->comboBoxPrinter->currentText();
375 const qreal width =
ui->doubleSpinBoxPaperWidth->value();
376 const qreal height =
ui->doubleSpinBoxPaperHeight->value();
377 QSizeF size(width, height);
382 for (
int i=0; i < max; ++i)
385 if (size == tmplSize)
387 ui->comboBoxTemplates->blockSignals(
true);
388 const int index =
ui->comboBoxTemplates->findData(i);
391 ui->comboBoxTemplates->setCurrentIndex(index);
393 ui->comboBoxTemplates->blockSignals(
false);
398 ui->comboBoxTemplates->blockSignals(
true);
399 const int index =
ui->comboBoxTemplates->findData(max);
402 ui->comboBoxTemplates->setCurrentIndex(index);
404 ui->comboBoxTemplates->blockSignals(
false);
411 const qreal width =
ui->doubleSpinBoxPaperWidth->value();
412 const qreal height =
ui->doubleSpinBoxPaperHeight->value();
414 const qreal left =
ui->leftField_DoubleSpinBox->value();
415 const qreal right =
ui->rightField_DoubleSpinBox->value();
416 const qreal top =
ui->topField_DoubleSpinBox->value();
417 const qreal bottom =
ui->bottomField_DoubleSpinBox->value();
419 ui->doubleSpinBoxPaperWidth->blockSignals(
true);
420 ui->doubleSpinBoxPaperHeight->blockSignals(
true);
423 ui->doubleSpinBoxPaperWidth->blockSignals(
false);
424 ui->doubleSpinBoxPaperHeight->blockSignals(
false);
438 ui->doubleSpinBoxPaperWidth->setValue(newWidth);
439 ui->doubleSpinBoxPaperHeight->setValue(newHeight);
441 ui->leftField_DoubleSpinBox->setValue(newLeft);
442 ui->rightField_DoubleSpinBox->setValue(newRight);
443 ui->topField_DoubleSpinBox->setValue(newTop);
444 ui->bottomField_DoubleSpinBox->setValue(newBottom);
450 qint32 indexUnit =
ui->comboBoxPaperSizeUnit->findData(units);
453 ui->comboBoxPaperSizeUnit->setCurrentIndex(indexUnit);
455 return indexUnit != -1;
461 qint32 indexUnit =
ui->comboBoxLayoutUnit->findData(units);
464 ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
466 return indexUnit != -1;
485 return tr(
"\n\tThree groups: big, middle, small = 0;\n\tTwo groups: big, small = 1;\n\tDescending area = 2");
491 QDialog::showEvent( event );
492 if ( event->spontaneous() )
503 setMaximumSize(size());
504 setMinimumSize(size());
513 const qreal layoutWidth =
ui->doubleSpinBoxLayoutWidth->value();
514 const qreal shift =
ui->doubleSpinBoxShift->value();
526 ui->doubleSpinBoxLayoutWidth->setValue(newLayoutWidth);
527 ui->doubleSpinBoxShift->setValue(newShift);
533 if (
ui->doubleSpinBoxPaperHeight->value() >
ui->doubleSpinBoxPaperWidth->value())
535 ui->portrait_ToolButton->blockSignals(
true);
536 ui->portrait_ToolButton->setChecked(
true);
537 ui->portrait_ToolButton->blockSignals(
false);
541 ui->landscape_ToolButton->blockSignals(
true);
542 ui->landscape_ToolButton->setChecked(
true);
543 ui->landscape_ToolButton->blockSignals(
false);
550 int index =
ui->comboBoxTemplates->findData(
static_cast<VIndexType>(
id));
553 ui->comboBoxTemplates->setCurrentIndex(index);
564 const qreal width =
ui->doubleSpinBoxPaperWidth->value();
565 const qreal height =
ui->doubleSpinBoxPaperHeight->value();
567 ui->doubleSpinBoxPaperWidth->blockSignals(
true);
568 ui->doubleSpinBoxPaperWidth->setValue(height);
569 ui->doubleSpinBoxPaperWidth->blockSignals(
false);
571 ui->doubleSpinBoxPaperHeight->blockSignals(
true);
572 ui->doubleSpinBoxPaperHeight->setValue(width);
573 ui->doubleSpinBoxPaperHeight->blockSignals(
false);
601 QPrinterInfo printer = QPrinterInfo::printerInfo(
ui->comboBoxPrinter->currentText());
602 if (printer.isNull())
610 if (fields.left() < minFields.left() || fields.right() < minFields.right() ||
611 fields.top() < minFields.top() || fields.bottom() < minFields.bottom())
613 QMessageBox::StandardButton answer;
614 answer = QMessageBox::question(
this, tr(
"Wrong fields."),
615 tr(
"Margins go beyond printing. \n\nApply settings anyway?"),
616 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
617 if (answer == QMessageBox::No)
619 if (fields.left() < minFields.left())
624 if (fields.right() < minFields.right())
629 if (fields.top() < minFields.top())
634 if (fields.bottom() < minFields.bottom())
665 ui->comboBoxTemplates->blockSignals(
true);
666 ui->comboBoxTemplates->setCurrentIndex(0);
668 ui->comboBoxTemplates->blockSignals(
false);
670 ui->comboBoxPrinter->blockSignals(
true);
672 ui->comboBoxPrinter->blockSignals(
false);
686 ui->textAsPaths_Checkbox->setChecked(
false);
692 QPrinterInfo printer = QPrinterInfo::printerInfo(
ui->comboBoxPrinter->currentText());
693 if (not printer.isNull())
706 const qreal width =
ui->doubleSpinBoxPaperWidth->value();
707 const qreal height =
ui->doubleSpinBoxPaperHeight->value();
710 const qreal widthField = (width*80.0/100.0)/2.0;
711 const qreal heightField = (height*80.0/100.0)/2.0;
713 ui->leftField_DoubleSpinBox->setMaximum(widthField);
714 ui->rightField_DoubleSpinBox->setMaximum(widthField);
715 ui->topField_DoubleSpinBox->setMaximum(heightField);
716 ui->bottomField_DoubleSpinBox->setMaximum(heightField);
722 ui->leftField_DoubleSpinBox->setDisabled(state);
723 ui->rightField_DoubleSpinBox->setDisabled(state);
724 ui->topField_DoubleSpinBox->setDisabled(state);
725 ui->bottomField_DoubleSpinBox->setDisabled(state);
738 const qint32 indexUnit =
ui->comboBoxPaperSizeUnit->findData(
qApp->Seamly2DSettings()->GetUnit());
741 ui->comboBoxPaperSizeUnit->setCurrentIndex(indexUnit);
754 const qint32 indexUnit =
ui->comboBoxLayoutUnit->findData(
qApp->Seamly2DSettings()->GetUnit());
757 ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
765 ui->comboBoxPrinter->clear();
766 QStringList printerNames;
767 printerNames = QPrinterInfo::availablePrinterNames();
769 ui->comboBoxPrinter->addItems(printerNames);
771 if (
ui->comboBoxPrinter->count() == 0)
773 ui->comboBoxPrinter->addItem(tr(
"None",
"Printer"));
777 QString defPrinterName;
778 defPrinterName = QPrinterInfo::defaultPrinterName();
780 const int index =
ui->comboBoxPrinter->findText(defPrinterName);
783 ui->comboBoxPrinter->setCurrentIndex(index);
798 out +=
"\t"+v+
" = "+ QString::number(cntr++)+
"\n";
852 width =
ui->doubleSpinBoxPaperWidth->value();
853 height =
ui->doubleSpinBoxPaperHeight->value();
866 QPrinterInfo printer = QPrinterInfo::printerInfo(
ui->comboBoxPrinter->currentText());
867 if (not printer.isNull())
881 QPrinterInfo printer = QPrinterInfo::printerInfo(
ui->comboBoxPrinter->currentText());
882 if (not printer.isNull())
895 return StrToUnits(
ui->comboBoxPaperSizeUnit->currentData().toString());
901 return StrToUnits(
ui->comboBoxLayoutUnit->currentData().toString());
912 ui->doubleSpinBoxPaperWidth->setDecimals(2);
913 ui->doubleSpinBoxPaperHeight->setDecimals(2);
915 ui->leftField_DoubleSpinBox->setDecimals(4);
916 ui->rightField_DoubleSpinBox->setDecimals(4);
917 ui->topField_DoubleSpinBox->setDecimals(4);
918 ui->bottomField_DoubleSpinBox->setDecimals(4);
921 ui->doubleSpinBoxPaperWidth->setDecimals(5);
922 ui->doubleSpinBoxPaperHeight->setDecimals(5);
924 ui->leftField_DoubleSpinBox->setDecimals(5);
925 ui->rightField_DoubleSpinBox->setDecimals(5);
926 ui->topField_DoubleSpinBox->setDecimals(5);
927 ui->bottomField_DoubleSpinBox->setDecimals(5);
942 ui->doubleSpinBoxLayoutWidth->setDecimals(2);
943 ui->doubleSpinBoxShift->setDecimals(2);
946 ui->doubleSpinBoxLayoutWidth->setDecimals(5);
947 ui->doubleSpinBoxShift->setDecimals(5);
958 ui->doubleSpinBoxPaperWidth->setMinimum(value);
959 ui->doubleSpinBoxPaperHeight->setMinimum(value);
966 ui->doubleSpinBoxLayoutWidth->setMinimum(value);
1025 ui->doubleSpinBoxPaperWidth->setValue(size.width());
1026 ui->doubleSpinBoxPaperHeight->setValue(size.height());
bool IsStripOptimization() const
qreal PageToPixels(qreal value) const
void WriteSettings() const
bool SelectLayoutUnit(const QString &units)
void SheetSize(const QSizeF &size)
bool isTextAsPaths() const
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
void SetGroup(const Cases &value)
void SetMultiplier(const quint8 &value)
bool IsSaveLength() const
void CorrectPaperDecimals()
void IgnoreAllFields(int state)
qreal LayoutToPixels(qreal value) const
void SetIgnoreAllFields(bool value)
void SetAutoCrop(bool autoCrop)
void setTextAsPaths(bool value)
void SetUnitePages(bool save)
VLayoutGenerator * generator
Ui::DialogLayoutSettings * ui
static QString MakeHelpTemplateList()
static QString MakeGroupsHelp()
qreal GetPaperWidth() const
QMarginsF MinPrinterFields() const
DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent=nullptr, bool disableSettings=false)
void SetAdditionalOptions(bool value)
QMarginsF GetFields() const
void SetLayoutWidth(qreal value)
bool SelectPaperUnit(const QString &units)
QMarginsF GetDefPrinterFields() const
QSizeF getTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
DialogLayoutSettings::TemplateSize.
void SetShift(qreal value)
void SetSaveLength(bool save)
bool SetIncrease(int increase)
bool IsIgnoreAllFields() const
virtual ~DialogLayoutSettings()
QString SelectedPrinter() const
void SetRotate(bool state)
void CorrectLayoutDecimals()
quint8 GetMultiplier() const
void SetPaperHeight(qreal value)
bool IsUnitePages() const
void SetFields(const QMarginsF &value)
bool SelectTemplate(const PaperSizeTemplate &id)
qreal GetLayoutWidth() const
void SetPaperWidth(qreal value)
void SetStripOptimization(bool save)
qreal GetPaperHeight() const
void initTemplates(QComboBox *comboBoxTemplates)
QSizeF RoundTemplateSize(qreal width, qreal height, Unit unit) const
QSizeF getTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
DialogLayoutSettings::TemplateSize.
static const FormatsVector pageFormatNames
void SetPaperHeight(qreal value)
void SetLayoutWidth(qreal width)
void SetPaperWidth(qreal value)
void SetAutoCrop(bool value)
void SetUnitePages(bool value)
void SetRotationIncrease(int value)
void SetRotate(bool value)
void SetTestAsPaths(bool value)
void SetPrinterFields(bool usePrinterFields, const QMarginsF &value)
void SetCaseType(Cases caseType)
void SetMultiplier(const quint8 &value)
void SetStripOptimization(bool value)
void SetShift(quint32 shift)
void SetSaveLength(bool value)
bool GetLayoutSaveLength() const
void SetLayoutGroup(const Cases &value)
static qreal GetDefLayoutWidth()
quint8 GetMultiplier() const
static bool GetDefLayoutRotate()
bool GetStripOptimization() const
static Cases GetDefLayoutGroup()
qreal GetLayoutPaperHeight() const
qreal GetLayoutWidth() const
void setTextAsPaths(bool value)
void SetLayoutPaperHeight(qreal value)
void SetFields(const QMarginsF &value)
Cases GetLayoutGroup() const
void SetLayoutAutoCrop(bool value)
qreal GetLayoutShift() const
static quint8 GetDefMultiplier()
void SetLayoutSaveLength(bool value)
bool GetIgnoreAllFields() const
void SetLayoutRotate(bool value)
void SetMultiplier(quint8 value)
QMarginsF GetFields(const QMarginsF &def=QMarginsF()) const
void SetLayoutRotationIncrease(int value)
void SetLayoutWidth(qreal value)
void SetLayoutPaperWidth(qreal value)
bool GetLayoutAutoCrop() const
static bool GetDefIgnoreAllFields()
static int GetDefLayoutRotationIncrease()
void SetLayoutShift(qreal value)
void SetStripOptimization(bool value)
bool GetLayoutUnitePages() const
bool GetLayoutRotate() const
void SetLayoutUnitePages(bool value)
void SetIgnoreAllFields(bool value)
qreal GetLayoutPaperWidth() const
bool GetTextAsPaths() const
int GetLayoutRotationIncrease() const
static qreal GetDefLayoutShift()
Unit StrToUnits(const QString &unit)
QMarginsF GetPrinterFields(const QSharedPointer< QPrinter > &printer)
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
double FromPixel(double pix, const Unit &unit)
QMarginsF GetMinPrinterFields(const QSharedPointer< QPrinter > &printer)
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)