Seamly2D
Code documentation
dialoglayoutsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file dialoglayoutsettings.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 13 1, 2015
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "dialoglayoutsettings.h"
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"
59 
60 #include <QMessageBox>
61 #include <QPushButton>
62 #include <QPrinterInfo>
63 
64 //---------------------------------------------------------------------------------------------------------------------
65 DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent, bool disableSettings)
66  : VAbstractLayoutDialog(parent), disableSettings(disableSettings), ui(new Ui::DialogLayoutSettings), oldPaperUnit(Unit::Mm),
67  oldLayoutUnit(Unit::Mm), generator(generator), isInitialized(false)
68 {
69  ui->setupUi(this);
70  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
71 
72  qApp->Seamly2DSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
73 
74  //moved from ReadSettings - well...it seems it can be done once only (i.e. constructor) because Init funcs dont
75  //even cleanse lists before adding
78  initTemplates(ui->comboBoxTemplates);
81  InitPrinter();
82 
83  //in export console mode going to use defaults
84  if (disableSettings == false)
85  {
86  ReadSettings();
87  }
88  else
89  {
91  }
92 
93  connect(ui->comboBoxPrinter, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
95 
96  connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
98  connect(ui->comboBoxPaperSizeUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
100 
101  connect(ui->doubleSpinBoxPaperWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
103  connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
105 
106  connect(ui->doubleSpinBoxPaperWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
108  connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
110 
111  connect(ui->doubleSpinBoxPaperWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
113  connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
115 
116  connect(ui->checkBoxIgnoreFileds, &QCheckBox::stateChanged, this, &DialogLayoutSettings::IgnoreAllFields);
117 
118  connect(ui->portrait_ToolButton, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
119  connect(ui->landscape_ToolButton, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
120  connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
122 
123  QPushButton *ok_Button = ui->buttonBox->button(QDialogButtonBox::Ok);
124  connect(ok_Button, &QPushButton::clicked, this, &DialogLayoutSettings::DialogAccepted);
125 
126  QPushButton *bRestoreDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults);
127  connect(bRestoreDefaults, &QPushButton::clicked, this, &DialogLayoutSettings::RestoreDefaults);
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
132 {
133  delete ui;
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
138 {
139  return UnitConvertor(ui->doubleSpinBoxPaperHeight->value(), oldPaperUnit, Unit::Px);
140 }
141 
142 //---------------------------------------------------------------------------------------------------------------------
144 {
145  ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, PaperUnit()));
146  ui->doubleSpinBoxPaperHeight->setValue(UnitConvertor(value, Unit::Px, PaperUnit()));
147 }
148 
149 //---------------------------------------------------------------------------------------------------------------------
151 {
152  return UnitConvertor(ui->doubleSpinBoxPaperWidth->value(), oldPaperUnit, Unit::Px);
153 }
154 
155 //---------------------------------------------------------------------------------------------------------------------
157 {
158  ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, PaperUnit()));
159  ui->doubleSpinBoxPaperWidth->setValue(UnitConvertor(value, Unit::Px, PaperUnit()));
160 }
161 
162 //---------------------------------------------------------------------------------------------------------------------
164 {
165  return UnitConvertor(ui->doubleSpinBoxShift->value(), oldLayoutUnit, Unit::Px);
166 }
167 
168 //---------------------------------------------------------------------------------------------------------------------
170 {
171  ui->doubleSpinBoxShift->setValue(UnitConvertor(value, Unit::Px, LayoutUnit()));
172 }
173 
174 //---------------------------------------------------------------------------------------------------------------------
176 {
177  return UnitConvertor(ui->doubleSpinBoxLayoutWidth->value(), oldLayoutUnit, Unit::Px);
178 }
179 
180 //---------------------------------------------------------------------------------------------------------------------
182 {
183  ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(value, Unit::Px, LayoutUnit()));
184 }
185 
186 //---------------------------------------------------------------------------------------------------------------------
188 {
189  QMarginsF fields;
190  fields.setLeft(UnitConvertor(ui->leftField_DoubleSpinBox->value(), oldLayoutUnit, Unit::Px));
191  fields.setRight(UnitConvertor(ui->rightField_DoubleSpinBox->value(), oldLayoutUnit, Unit::Px));
192  fields.setTop(UnitConvertor(ui->topField_DoubleSpinBox->value(), oldLayoutUnit, Unit::Px));
193  fields.setBottom(UnitConvertor(ui->bottomField_DoubleSpinBox->value(), oldLayoutUnit, Unit::Px));
194  return fields;
195 }
196 
197 //---------------------------------------------------------------------------------------------------------------------
198 void DialogLayoutSettings::SetFields(const QMarginsF &value)
199 {
200  ui->leftField_DoubleSpinBox->setValue(UnitConvertor(value.left(), Unit::Px, LayoutUnit()));
201  ui->rightField_DoubleSpinBox->setValue(UnitConvertor(value.right(), Unit::Px, LayoutUnit()));
202  ui->topField_DoubleSpinBox->setValue(UnitConvertor(value.top(), Unit::Px, LayoutUnit()));
203  ui->bottomField_DoubleSpinBox->setValue(UnitConvertor(value.bottom(), Unit::Px, LayoutUnit()));
204 }
205 
206 //---------------------------------------------------------------------------------------------------------------------
208 {
209  if (ui->radioButtonThreeGroups->isChecked())
210  {
211  return Cases::CaseThreeGroup;
212  }
213  else if (ui->radioButtonTwoGroups->isChecked())
214  {
215  return Cases::CaseTwoGroup;
216  }
217  else
218  {
219  return Cases::CaseDesc;
220  }
221 }
222 
223 //---------------------------------------------------------------------------------------------------------------------
224 // cppcheck-suppress unusedFunction
226 {
227  switch (value)
228  {
230  ui->radioButtonThreeGroups->setChecked(true);
231  break;
232  case Cases::CaseTwoGroup:
233  ui->radioButtonTwoGroups->setChecked(true);
234  break;
235  case Cases::CaseDesc:
236  default:
237  ui->radioButtonDescendingArea->setChecked(true);
238  break;
239  }
240 }
241 
242 //---------------------------------------------------------------------------------------------------------------------
244 {
245  return ui->groupBoxRotate->isChecked();
246 }
247 
248 //---------------------------------------------------------------------------------------------------------------------
250 {
251  ui->groupBoxRotate->setChecked(state);
252 }
253 
254 //---------------------------------------------------------------------------------------------------------------------
256 {
257  return ui->comboBoxIncrease->currentText().toInt();
258 }
259 
260 //---------------------------------------------------------------------------------------------------------------------
261 // cppcheck-suppress unusedFunction
263 {
264  int index = ui->comboBoxIncrease->findText(QString::number(increase));
265  bool failed = (index == -1);
266  if (failed)
267  {
268  const QString def = QString::number(VSettings::GetDefLayoutRotationIncrease());// Value by default
269  index = ui->comboBoxIncrease->findText(def);
270  }
271 
272  ui->comboBoxIncrease->setCurrentIndex(index);
273  return failed;
274 }
275 
276 //---------------------------------------------------------------------------------------------------------------------
278 {
279  return ui->checkBoxAutoCrop->isChecked();
280 }
281 
282 //---------------------------------------------------------------------------------------------------------------------
284 {
285  ui->checkBoxAutoCrop->setChecked(autoCrop);
286 }
287 
288 //---------------------------------------------------------------------------------------------------------------------
290 {
291  return ui->checkBoxSaveLength->isChecked();
292 }
293 
294 //---------------------------------------------------------------------------------------------------------------------
296 {
297  ui->checkBoxSaveLength->setChecked(save);
298 }
299 
300 //---------------------------------------------------------------------------------------------------------------------
302 {
303  return ui->checkBoxUnitePages->isChecked();
304 }
305 
306 //---------------------------------------------------------------------------------------------------------------------
308 {
309  ui->checkBoxUnitePages->setChecked(save);
310 }
311 
312 //---------------------------------------------------------------------------------------------------------------------
314 {
315  return ui->groupBoxStrips->isChecked();
316 }
317 
318 //---------------------------------------------------------------------------------------------------------------------
320 {
321  ui->groupBoxStrips->setChecked(save);
322 }
323 
324 //---------------------------------------------------------------------------------------------------------------------
326 {
327  return static_cast<quint8>(ui->spinBoxMultiplier->value());
328 }
329 
330 //---------------------------------------------------------------------------------------------------------------------
331 void DialogLayoutSettings::SetMultiplier(const quint8 &value)
332 {
333  ui->spinBoxMultiplier->setValue(static_cast<int>(value));
334 }
335 
336 //---------------------------------------------------------------------------------------------------------------------
338 {
339  return ui->checkBoxIgnoreFileds->isChecked();
340 }
341 
342 //---------------------------------------------------------------------------------------------------------------------
344 {
345  ui->checkBoxIgnoreFileds->setChecked(value);
346 }
347 
348 //---------------------------------------------------------------------------------------------------------------------
350 {
351  return ui->textAsPaths_Checkbox->isChecked();
352 }
353 
354 //---------------------------------------------------------------------------------------------------------------------
356 {
357  ui->textAsPaths_Checkbox->setChecked(value);
358 }
359 
360 //---------------------------------------------------------------------------------------------------------------------
362 {
363  return ui->comboBoxPrinter->currentText();
364 }
365 
366 //---------------------------------------------------------------------------------------------------------------------
368 {
369  SheetSize(Template());
370 }
371 
372 //---------------------------------------------------------------------------------------------------------------------
374 {
375  const qreal width = ui->doubleSpinBoxPaperWidth->value();
376  const qreal height = ui->doubleSpinBoxPaperHeight->value();
377  QSizeF size(width, height);
378 
379  const Unit paperUnit = PaperUnit();
380 
381  const int max = static_cast<int>(PaperSizeTemplate::Custom);
382  for (int i=0; i < max; ++i)
383  {
384  const QSizeF tmplSize = getTemplateSize(static_cast<PaperSizeTemplate>(i), paperUnit);
385  if (size == tmplSize)
386  {
387  ui->comboBoxTemplates->blockSignals(true);
388  const int index = ui->comboBoxTemplates->findData(i);
389  if (index != -1)
390  {
391  ui->comboBoxTemplates->setCurrentIndex(index);
392  }
393  ui->comboBoxTemplates->blockSignals(false);
394  return;
395  }
396  }
397 
398  ui->comboBoxTemplates->blockSignals(true);
399  const int index = ui->comboBoxTemplates->findData(max);
400  if (index != -1)
401  {
402  ui->comboBoxTemplates->setCurrentIndex(index);
403  }
404  ui->comboBoxTemplates->blockSignals(false);
405 }
406 
407 //---------------------------------------------------------------------------------------------------------------------
409 {
410  const Unit paperUnit = PaperUnit();
411  const qreal width = ui->doubleSpinBoxPaperWidth->value();
412  const qreal height = ui->doubleSpinBoxPaperHeight->value();
413 
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();
418 
419  ui->doubleSpinBoxPaperWidth->blockSignals(true);
420  ui->doubleSpinBoxPaperHeight->blockSignals(true);
421  ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit));
422  ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, paperUnit));
423  ui->doubleSpinBoxPaperWidth->blockSignals(false);
424  ui->doubleSpinBoxPaperHeight->blockSignals(false);
425 
426  const qreal newWidth = UnitConvertor(width, oldPaperUnit, paperUnit);
427  const qreal newHeight = UnitConvertor(height, oldPaperUnit, paperUnit);
428 
429  const qreal newLeft = UnitConvertor(left, oldPaperUnit, paperUnit);
430  const qreal newRight = UnitConvertor(right, oldPaperUnit, paperUnit);
431  const qreal newTop = UnitConvertor(top, oldPaperUnit, paperUnit);
432  const qreal newBottom = UnitConvertor(bottom, oldPaperUnit, paperUnit);
433 
434  oldPaperUnit = paperUnit;
437 
438  ui->doubleSpinBoxPaperWidth->setValue(newWidth);
439  ui->doubleSpinBoxPaperHeight->setValue(newHeight);
440 
441  ui->leftField_DoubleSpinBox->setValue(newLeft);
442  ui->rightField_DoubleSpinBox->setValue(newRight);
443  ui->topField_DoubleSpinBox->setValue(newTop);
444  ui->bottomField_DoubleSpinBox->setValue(newBottom);
445 }
446 
447 //---------------------------------------------------------------------------------------------------------------------
448 bool DialogLayoutSettings::SelectPaperUnit(const QString& units)
449 {
450  qint32 indexUnit = ui->comboBoxPaperSizeUnit->findData(units);
451  if (indexUnit != -1)
452  {
453  ui->comboBoxPaperSizeUnit->setCurrentIndex(indexUnit);
454  }
455  return indexUnit != -1;
456 }
457 
458 //---------------------------------------------------------------------------------------------------------------------
459 bool DialogLayoutSettings::SelectLayoutUnit(const QString &units)
460 {
461  qint32 indexUnit = ui->comboBoxLayoutUnit->findData(units);
462  if (indexUnit != -1)
463  {
464  ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
465  }
466  return indexUnit != -1;
467 }
468 
469 //---------------------------------------------------------------------------------------------------------------------
470 qreal DialogLayoutSettings::LayoutToPixels(qreal value) const
471 {
472  return UnitConvertor(value, LayoutUnit(), Unit::Px);
473 }
474 
475 //---------------------------------------------------------------------------------------------------------------------
476 qreal DialogLayoutSettings::PageToPixels(qreal value) const
477 {
478  return UnitConvertor(value, PaperUnit(), Unit::Px);
479 }
480 
481 //---------------------------------------------------------------------------------------------------------------------
483 {
484  //that is REALLY dummy ... can't figure fast how to automate generation... :/
485  return tr("\n\tThree groups: big, middle, small = 0;\n\tTwo groups: big, small = 1;\n\tDescending area = 2");
486 }
487 
488 //---------------------------------------------------------------------------------------------------------------------
489 void DialogLayoutSettings::showEvent(QShowEvent *event)
490 {
491  QDialog::showEvent( event );
492  if ( event->spontaneous() )
493  {
494  return;
495  }
496 
497  if (isInitialized)
498  {
499  return;
500  }
501  // do your init stuff here
502 
503  setMaximumSize(size());
504  setMinimumSize(size());
505 
506  isInitialized = true;//first show windows are held
507 }
508 
509 //---------------------------------------------------------------------------------------------------------------------
511 {
512  const Unit unit = LayoutUnit();
513  const qreal layoutWidth = ui->doubleSpinBoxLayoutWidth->value();
514  const qreal shift = ui->doubleSpinBoxShift->value();
515 
516  ui->doubleSpinBoxLayoutWidth->setMaximum(FromPixel(QIMAGE_MAX, unit));
517  ui->doubleSpinBoxShift->setMaximum(FromPixel(QIMAGE_MAX, unit));
518 
519  const qreal newLayoutWidth = UnitConvertor(layoutWidth, oldLayoutUnit, unit);
520  const qreal newShift = UnitConvertor(shift, oldLayoutUnit, unit);
521 
522  oldLayoutUnit = unit;
525 
526  ui->doubleSpinBoxLayoutWidth->setValue(newLayoutWidth);
527  ui->doubleSpinBoxShift->setValue(newShift);
528 }
529 
530 //---------------------------------------------------------------------------------------------------------------------
532 {
533  if (ui->doubleSpinBoxPaperHeight->value() > ui->doubleSpinBoxPaperWidth->value())
534  {
535  ui->portrait_ToolButton->blockSignals(true);
536  ui->portrait_ToolButton->setChecked(true);
537  ui->portrait_ToolButton->blockSignals(false);
538  }
539  else
540  {
541  ui->landscape_ToolButton->blockSignals(true);
542  ui->landscape_ToolButton->setChecked(true);
543  ui->landscape_ToolButton->blockSignals(false);
544  }
545 }
546 
547 //---------------------------------------------------------------------------------------------------------------------
549 {
550  int index = ui->comboBoxTemplates->findData(static_cast<VIndexType>(id));
551  if (index > -1)
552  {
553  ui->comboBoxTemplates->setCurrentIndex(index);
554  }
555 
556  return (index > -1);
557 }
558 
559 //---------------------------------------------------------------------------------------------------------------------
560 void DialogLayoutSettings::Swap(bool checked)
561 {
562  if (checked)
563  {
564  const qreal width = ui->doubleSpinBoxPaperWidth->value();
565  const qreal height = ui->doubleSpinBoxPaperHeight->value();
566 
567  ui->doubleSpinBoxPaperWidth->blockSignals(true);
568  ui->doubleSpinBoxPaperWidth->setValue(height);
569  ui->doubleSpinBoxPaperWidth->blockSignals(false);
570 
571  ui->doubleSpinBoxPaperHeight->blockSignals(true);
572  ui->doubleSpinBoxPaperHeight->setValue(width);
573  ui->doubleSpinBoxPaperHeight->blockSignals(false);
574  }
575 }
576 
577 //---------------------------------------------------------------------------------------------------------------------
579 {
580  SCASSERT(generator != nullptr)
585  generator->SetShift(static_cast<quint32>(qFloor(GetShift())));
594 
595  if (IsIgnoreAllFields())
596  {
597  generator->SetPrinterFields(false, QMarginsF());
598  }
599  else
600  {
601  QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
602  if (printer.isNull())
603  {
605  }
606  else
607  {
608  const QMarginsF minFields = MinPrinterFields();
609  const QMarginsF fields = GetFields();
610  if (fields.left() < minFields.left() || fields.right() < minFields.right() ||
611  fields.top() < minFields.top() || fields.bottom() < minFields.bottom())
612  {
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)
618  {
619  if (fields.left() < minFields.left())
620  {
621  ui->leftField_DoubleSpinBox->setValue(UnitConvertor(minFields.left(), Unit::Px, LayoutUnit()));
622  }
623 
624  if (fields.right() < minFields.right())
625  {
626  ui->rightField_DoubleSpinBox->setValue(UnitConvertor(minFields.right(), Unit::Px, LayoutUnit()));
627  }
628 
629  if (fields.top() < minFields.top())
630  {
631  ui->topField_DoubleSpinBox->setValue(UnitConvertor(minFields.top(), Unit::Px, LayoutUnit()));
632  }
633 
634  if (fields.bottom() < minFields.bottom())
635  {
636  ui->bottomField_DoubleSpinBox->setValue(UnitConvertor(minFields.bottom(), Unit::Px,
637  LayoutUnit()));
638  }
639 
641  }
642  else
643  {
645  }
646  }
647  else
648  {
650  }
651  }
652  }
653 
654  //don't want to break visual settings when cmd used
655  if (disableSettings == false)
656  {
657  WriteSettings();
658  }
659  accepted();
660 }
661 
662 //---------------------------------------------------------------------------------------------------------------------
664 {
665  ui->comboBoxTemplates->blockSignals(true);
666  ui->comboBoxTemplates->setCurrentIndex(0);//A0
668  ui->comboBoxTemplates->blockSignals(false);
669 
670  ui->comboBoxPrinter->blockSignals(true);
671  InitPrinter();
672  ui->comboBoxPrinter->blockSignals(false);
673 
682 
684  IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked());
685 
686  ui->textAsPaths_Checkbox->setChecked(false);
687 }
688 
689 //---------------------------------------------------------------------------------------------------------------------
691 {
692  QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
693  if (not printer.isNull())
694  {
695  SetFields(GetPrinterFields(QSharedPointer<QPrinter>(new QPrinter(printer))));
696  }
697  else
698  {
699  SetFields(QMarginsF());
700  }
701 }
702 
703 //---------------------------------------------------------------------------------------------------------------------
705 {
706  const qreal width = ui->doubleSpinBoxPaperWidth->value();
707  const qreal height = ui->doubleSpinBoxPaperHeight->value();
708 
709  // 80%/2 of paper size for each field
710  const qreal widthField = (width*80.0/100.0)/2.0;
711  const qreal heightField = (height*80.0/100.0)/2.0;
712 
713  ui->leftField_DoubleSpinBox->setMaximum(widthField);
714  ui->rightField_DoubleSpinBox->setMaximum(widthField);
715  ui->topField_DoubleSpinBox->setMaximum(heightField);
716  ui->bottomField_DoubleSpinBox->setMaximum(heightField);
717 }
718 
719 //---------------------------------------------------------------------------------------------------------------------
721 {
722  ui->leftField_DoubleSpinBox->setDisabled(state);
723  ui->rightField_DoubleSpinBox->setDisabled(state);
724  ui->topField_DoubleSpinBox->setDisabled(state);
725  ui->bottomField_DoubleSpinBox->setDisabled(state);
726 }
727 
728 //---------------------------------------------------------------------------------------------------------------------
730 {
731  ui->comboBoxPaperSizeUnit->addItem(tr("Millimeters"), QVariant(UnitsToStr(Unit::Mm)));
732  ui->comboBoxPaperSizeUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm)));
733  ui->comboBoxPaperSizeUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch)));
734  ui->comboBoxPaperSizeUnit->addItem(tr("Pixels"), QVariant(UnitsToStr(Unit::Px)));
735 
736  // set default unit
737  oldPaperUnit = StrToUnits(qApp->Seamly2DSettings()->GetUnit());
738  const qint32 indexUnit = ui->comboBoxPaperSizeUnit->findData(qApp->Seamly2DSettings()->GetUnit());
739  if (indexUnit != -1)
740  {
741  ui->comboBoxPaperSizeUnit->setCurrentIndex(indexUnit);
742  }
743 }
744 
745 //---------------------------------------------------------------------------------------------------------------------
747 {
748  ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm)));
749  ui->comboBoxLayoutUnit->addItem(tr("Millimeters"), QVariant(UnitsToStr(Unit::Mm)));
750  ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch)));
751 
752  // set default unit
753  oldLayoutUnit = StrToUnits(qApp->Seamly2DSettings()->GetUnit());
754  const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(qApp->Seamly2DSettings()->GetUnit());
755  if (indexUnit != -1)
756  {
757  ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
758  }
759 }
760 
761 
762 //---------------------------------------------------------------------------------------------------------------------
764 {
765  ui->comboBoxPrinter->clear();
766  QStringList printerNames;
767  printerNames = QPrinterInfo::availablePrinterNames();
768 
769  ui->comboBoxPrinter->addItems(printerNames);
770 
771  if (ui->comboBoxPrinter->count() == 0)
772  {
773  ui->comboBoxPrinter->addItem(tr("None", "Printer"));
774  }
775  else
776  {
777  QString defPrinterName;
778  defPrinterName = QPrinterInfo::defaultPrinterName();
779 
780  const int index = ui->comboBoxPrinter->findText(defPrinterName);
781  if(index != -1)
782  {
783  ui->comboBoxPrinter->setCurrentIndex(index);
784  }
785  }
786 }
787 
788 //---------------------------------------------------------------------------------------------------------------------
790 {
791  QString out = "\n";
792 
793  auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
794  foreach(const auto& v, VAbstractLayoutDialog::pageFormatNames)
795  {
796  if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))// Don't include custom template
797  {
798  out += "\t"+v+" = "+ QString::number(cntr++)+"\n";
799  }
800  }
801  return out;
802 }
803 
804 //---------------------------------------------------------------------------------------------------------------------
806 {
807  PaperSizeTemplate temp;
808  temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt());
809 
810  const Unit paperUnit = PaperUnit();
811 
812  switch (temp)
813  {
820  SetAdditionalOptions(false);
821  return getTemplateSize(temp, paperUnit);
828  SetAdditionalOptions(true);
829  return getTemplateSize(temp, paperUnit);
831  return getTemplateSize(temp, paperUnit);
832  default:
833  break;
834  }
835  return QSizeF();
836 }
837 
838 /**
839  * @brief DialogLayoutSettings::TemplateSize
840  * @param tmpl
841  * @param unit
842  * @return
843  */
844 QSizeF DialogLayoutSettings::getTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
845 {
846  qreal width = 0;
847  qreal height = 0;
848 
849  switch (tmpl)
850  {
852  width = ui->doubleSpinBoxPaperWidth->value();
853  height = ui->doubleSpinBoxPaperHeight->value();
854  return RoundTemplateSize(width, height, unit);
855  default:
856  return VAbstractLayoutDialog::getTemplateSize(tmpl, unit);
857  }
858 }
859 
860 
861 
862 
863 //---------------------------------------------------------------------------------------------------------------------
865 {
866  QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
867  if (not printer.isNull())
868  {
869  QSharedPointer<QPrinter> pr = QSharedPointer<QPrinter>(new QPrinter(printer));
870  return GetMinPrinterFields(pr);
871  }
872  else
873  {
874  return QMarginsF();
875  }
876 }
877 
878 //---------------------------------------------------------------------------------------------------------------------
880 {
881  QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
882  if (not printer.isNull())
883  {
884  return GetPrinterFields(QSharedPointer<QPrinter>(new QPrinter(printer)));
885  }
886  else
887  {
888  return QMarginsF();
889  }
890 }
891 
892 //---------------------------------------------------------------------------------------------------------------------
894 {
895  return StrToUnits(ui->comboBoxPaperSizeUnit->currentData().toString());
896 }
897 
898 //---------------------------------------------------------------------------------------------------------------------
900 {
901  return StrToUnits(ui->comboBoxLayoutUnit->currentData().toString());
902 }
903 
904 //---------------------------------------------------------------------------------------------------------------------
906 {
907  switch (oldPaperUnit)
908  {
909  case Unit::Cm:
910  case Unit::Mm:
911  case Unit::Px:
912  ui->doubleSpinBoxPaperWidth->setDecimals(2);
913  ui->doubleSpinBoxPaperHeight->setDecimals(2);
914 
915  ui->leftField_DoubleSpinBox->setDecimals(4);
916  ui->rightField_DoubleSpinBox->setDecimals(4);
917  ui->topField_DoubleSpinBox->setDecimals(4);
918  ui->bottomField_DoubleSpinBox->setDecimals(4);
919  break;
920  case Unit::Inch:
921  ui->doubleSpinBoxPaperWidth->setDecimals(5);
922  ui->doubleSpinBoxPaperHeight->setDecimals(5);
923 
924  ui->leftField_DoubleSpinBox->setDecimals(5);
925  ui->rightField_DoubleSpinBox->setDecimals(5);
926  ui->topField_DoubleSpinBox->setDecimals(5);
927  ui->bottomField_DoubleSpinBox->setDecimals(5);
928  break;
929  default:
930  break;
931  }
932 }
933 
934 //---------------------------------------------------------------------------------------------------------------------
936 {
937  switch (oldLayoutUnit)
938  {
939  case Unit::Cm:
940  case Unit::Mm:
941  case Unit::Px:
942  ui->doubleSpinBoxLayoutWidth->setDecimals(2);
943  ui->doubleSpinBoxShift->setDecimals(2);
944  break;
945  case Unit::Inch:
946  ui->doubleSpinBoxLayoutWidth->setDecimals(5);
947  ui->doubleSpinBoxShift->setDecimals(5);
948  break;
949  default:
950  break;
951  }
952 }
953 
954 //---------------------------------------------------------------------------------------------------------------------
956 {
957  const qreal value = UnitConvertor(1, Unit::Px, oldPaperUnit);
958  ui->doubleSpinBoxPaperWidth->setMinimum(value);
959  ui->doubleSpinBoxPaperHeight->setMinimum(value);
960 }
961 
962 //---------------------------------------------------------------------------------------------------------------------
964 {
965  const qreal value = UnitConvertor(1, Unit::Px, oldLayoutUnit);
966  ui->doubleSpinBoxLayoutWidth->setMinimum(value);
967 }
968 
969 //---------------------------------------------------------------------------------------------------------------------
971 {
972  const VSettings *settings = qApp->Seamly2DSettings();
973  SetLayoutWidth(settings->GetLayoutWidth());
974  SetShift(settings->GetLayoutShift());
975 
976  const qreal width = UnitConvertor(settings->GetLayoutPaperWidth(), Unit::Px, LayoutUnit());
977  const qreal height = UnitConvertor(settings->GetLayoutPaperHeight(), Unit::Px, LayoutUnit());
978  SheetSize(QSizeF(width, height));
979  SetGroup(settings->GetLayoutGroup());
980  SetRotate(settings->GetLayoutRotate());
982  SetAutoCrop(settings->GetLayoutAutoCrop());
983  SetSaveLength(settings->GetLayoutSaveLength());
984  SetUnitePages(settings->GetLayoutUnitePages());
988  SetMultiplier(settings->GetMultiplier());
989  setTextAsPaths(settings->GetTextAsPaths());
990 
991  FindTemplate();
992 
994  IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked());
995 }
996 
997 //---------------------------------------------------------------------------------------------------------------------
999 {
1000  VSettings *settings = qApp->Seamly2DSettings();
1001  settings->SetLayoutWidth(GetLayoutWidth());
1002  settings->SetLayoutGroup(GetGroup());
1003  settings->SetLayoutPaperHeight(GetPaperHeight());
1004  settings->SetLayoutPaperWidth(GetPaperWidth());
1005  settings->SetLayoutShift(GetShift());
1006  settings->SetLayoutRotate(GetRotate());
1008  settings->SetLayoutAutoCrop(GetAutoCrop());
1009  settings->SetLayoutSaveLength(IsSaveLength());
1010  settings->SetLayoutUnitePages(IsUnitePages());
1011  settings->SetFields(GetFields());
1014  settings->SetMultiplier(GetMultiplier());
1015  settings->setTextAsPaths(isTextAsPaths());
1016 }
1017 
1018 //---------------------------------------------------------------------------------------------------------------------
1019 void DialogLayoutSettings::SheetSize(const QSizeF &size)
1020 {
1021  oldPaperUnit = PaperUnit();
1022  ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, oldPaperUnit));
1023  ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, oldPaperUnit));
1024 
1025  ui->doubleSpinBoxPaperWidth->setValue(size.width());
1026  ui->doubleSpinBoxPaperHeight->setValue(size.height());
1027 
1029  PaperSizeChanged();
1030 }
1031 
1032 //---------------------------------------------------------------------------------------------------------------------
1034 {
1035  SetAutoCrop(value);
1036  SetSaveLength(value);
1037  SetUnitePages(value);
1038  SetStripOptimization(value);
1039 }
qreal PageToPixels(qreal value) const
bool SelectLayoutUnit(const QString &units)
void SheetSize(const QSizeF &size)
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
void SetGroup(const Cases &value)
void SetMultiplier(const quint8 &value)
qreal LayoutToPixels(qreal value) const
void SetIgnoreAllFields(bool value)
void SetAutoCrop(bool autoCrop)
void setTextAsPaths(bool value)
VLayoutGenerator * generator
Ui::DialogLayoutSettings * ui
static QString MakeHelpTemplateList()
static QString MakeGroupsHelp()
QMarginsF MinPrinterFields() const
DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent=nullptr, bool disableSettings=false)
void SetAdditionalOptions(bool value)
void SetLayoutWidth(qreal value)
bool SelectPaperUnit(const QString &units)
QMarginsF GetDefPrinterFields() const
QSizeF getTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
DialogLayoutSettings::TemplateSize.
bool SetIncrease(int increase)
void SetPaperHeight(qreal value)
void SetFields(const QMarginsF &value)
bool SelectTemplate(const PaperSizeTemplate &id)
void SetPaperWidth(qreal value)
void SetStripOptimization(bool save)
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
Definition: vsettings.cpp:531
void SetLayoutGroup(const Cases &value)
Definition: vsettings.cpp:454
static qreal GetDefLayoutWidth()
Definition: vsettings.cpp:396
quint8 GetMultiplier() const
Definition: vsettings.cpp:603
static bool GetDefLayoutRotate()
Definition: vsettings.cpp:466
bool GetStripOptimization() const
Definition: vsettings.cpp:585
static Cases GetDefLayoutGroup()
Definition: vsettings.cpp:448
qreal GetLayoutPaperHeight() const
Definition: vsettings.cpp:308
qreal GetLayoutWidth() const
Definition: vsettings.cpp:380
void setTextAsPaths(bool value)
Definition: vsettings.cpp:633
void SetLayoutPaperHeight(qreal value)
Definition: vsettings.cpp:324
void SetFields(const QMarginsF &value)
Definition: vsettings.cpp:419
Cases GetLayoutGroup() const
Definition: vsettings.cpp:425
void SetLayoutAutoCrop(bool value)
Definition: vsettings.cpp:525
qreal GetLayoutShift() const
Definition: vsettings.cpp:352
static quint8 GetDefMultiplier()
Definition: vsettings.cpp:609
void SetLayoutSaveLength(bool value)
Definition: vsettings.cpp:543
bool GetIgnoreAllFields() const
Definition: vsettings.cpp:567
void SetLayoutRotate(bool value)
Definition: vsettings.cpp:472
void SetMultiplier(quint8 value)
Definition: vsettings.cpp:615
QMarginsF GetFields(const QMarginsF &def=QMarginsF()) const
Definition: vsettings.cpp:408
void SetLayoutRotationIncrease(int value)
Definition: vsettings.cpp:507
void SetLayoutWidth(qreal value)
Definition: vsettings.cpp:402
void SetLayoutPaperWidth(qreal value)
Definition: vsettings.cpp:346
bool GetLayoutAutoCrop() const
Definition: vsettings.cpp:513
static bool GetDefIgnoreAllFields()
Definition: vsettings.cpp:573
static int GetDefLayoutRotationIncrease()
Definition: vsettings.cpp:501
void SetLayoutShift(qreal value)
Definition: vsettings.cpp:374
void SetStripOptimization(bool value)
Definition: vsettings.cpp:597
bool GetLayoutUnitePages() const
Definition: vsettings.cpp:549
bool GetLayoutRotate() const
Definition: vsettings.cpp:460
void SetLayoutUnitePages(bool value)
Definition: vsettings.cpp:561
void SetIgnoreAllFields(bool value)
Definition: vsettings.cpp:579
qreal GetLayoutPaperWidth() const
Definition: vsettings.cpp:330
bool GetTextAsPaths() const
Definition: vsettings.cpp:621
int GetLayoutRotationIncrease() const
Definition: vsettings.cpp:478
static qreal GetDefLayoutShift()
Definition: vsettings.cpp:368
Unit StrToUnits(const QString &unit)
Definition: def.cpp:670
QMarginsF GetPrinterFields(const QSharedPointer< QPrinter > &printer)
Definition: def.cpp:477
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
double FromPixel(double pix, const Unit &unit)
Definition: def.cpp:250
QMarginsF GetMinPrinterFields(const QSharedPointer< QPrinter > &printer)
Definition: def.cpp:463
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
Definition: def.cpp:269
#define SCASSERT(cond)
Definition: def.h:317
Unit
Definition: def.h:105
#define QIMAGE_MAX
Definition: def.h:298
#define qApp
Definition: vapplication.h:67
Cases
Definition: vbank.h:71
@ CaseDesc
@ CaseThreeGroup
@ CaseTwoGroup