Seamly2D
Code documentation
dialogpatternproperties.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 dialogpatternproperties.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 18 2, 2014
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 
53 #include "ui_dialogpatternproperties.h"
54 #include <QBuffer>
55 #include <QPushButton>
56 #include <QFileDialog>
57 #include <QMenu>
58 #include <QDate>
59 #include <QMessageBox>
60 
61 #include "../xml/vpattern.h"
62 #include "../vpatterndb/vcontainer.h"
63 #include "../core/vapplication.h"
64 #include "../vtools/dialogs/support/editlabeltemplate_dialog.h"
65 
66 // calc how many combinations we have
67 static const int heightsCount = (static_cast<int>(GHeights::H200) -
68  (static_cast<int>(GHeights::H50) - heightStep))/heightStep;
69 static const int sizesCount = (static_cast<int>(GSizes::S72) - (static_cast<int>(GSizes::S22) - sizeStep))/sizeStep;
70 
71 //---------------------------------------------------------------------------------------------------------------------
73  : QDialog(parent),
74  ui(new Ui::DialogPatternProperties),
75  doc(doc),
76  pattern(pattern),
77  heightsChecked(heightsCount),
78  sizesChecked(sizesCount),
79  heights (QMap<GHeights, bool>()),
80  sizes(QMap<GSizes, bool>()),
81  data(QMap<QCheckBox *, int>()),
82  descriptionChanged(false),
83  gradationChanged(false),
84  defaultChanged(false),
85  securityChanged(false),
86  labelDataChanged(false),
87  askSaveLabelData(false),
88  templateDataChanged(false),
89  deleteAction(nullptr),
90  changeImageAction(nullptr),
91  saveImageAction(nullptr),
92  showImageAction(nullptr),
93  templateLines()
94 {
95  ui->setupUi(this);
96 
97  SCASSERT(doc != nullptr)
98 
99  VSettings *settings = qApp->Seamly2DSettings();
100  settings->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
101 
102  if (qApp->getFilePath().isEmpty())
103  {
104  ui->lineEditPathToFile->setText(tr("<Empty>"));
105  ui->lineEditPathToFile->setToolTip(tr("File was not saved yet."));
106  ui->pushButtonShowInExplorer->setEnabled(false);
107  }
108  else
109  {
110  ui->lineEditPathToFile->setText(QDir::toNativeSeparators(qApp->getFilePath()));
111  ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(qApp->getFilePath()));
112  ui->pushButtonShowInExplorer->setEnabled(true);
113  }
114  ui->lineEditPathToFile->setCursorPosition(0);
115 
116  connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, this, [this]()
117  {
118  ShowInGraphicalShell(qApp->getFilePath());
119  });
120 #if defined(Q_OS_MAC)
121  ui->pushButtonShowInExplorer->setText(tr("Show in Finder"));
122 #endif //defined(Q_OS_MAC)
123 
124  ui->plainTextEditDescription->setPlainText(doc->GetDescription());
125  connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited);
126 
127  ui->plainTextEditTechNotes->setPlainText(doc->GetNotes());
128  connect(ui->plainTextEditTechNotes, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited);
129 
130  InitImage();
131 
132  connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &DialogPatternProperties::Ok);
133  connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this,
135 
136  QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
137  SCASSERT(bCancel != nullptr)
138  connect(bCancel, &QPushButton::clicked, this, &DialogPatternProperties::close);
139 
140  ui->tabWidget->setCurrentIndex(0);
141  if (qApp->patternType() != MeasurementsType::Multisize)
142  {
143  ui->tabWidget->setTabEnabled(1, false);
144  }
145 
146  InitHeights();
147  InitSizes();
148 
151 
153  SetOptions(sizes);
154 
155  InitComboBox(ui->comboBoxHeight, heights);
156  InitComboBox(ui->comboBoxSize, sizes);
157 
158  const QString height = QString().setNum(doc->GetDefCustomHeight());
159  SetDefaultHeight(height);
160 
161  const QString size = QString().setNum(doc->GetDefCustomSize());
162  SetDefaultSize(size);
163 
164  connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, [this]()
165  {
166  ui->comboBoxHeight->setEnabled(ui->radioButtonDefFromP->isChecked());
167  ui->comboBoxSize->setEnabled(ui->radioButtonDefFromP->isChecked());
168  });
169 
170  auto DefValueChanged = [this](){defaultChanged = true;};
171 
172  connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, DefValueChanged);
173 
174  ui->radioButtonDefFromP->setChecked(doc->IsDefCustom());
175 
176  connect(ui->comboBoxHeight, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
177  this, DefValueChanged);
178  connect(ui->comboBoxSize, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
179  this, DefValueChanged);
180 
181  const bool readOnly = doc->IsReadOnly();
182  ui->checkBoxPatternReadOnly->setChecked(readOnly);
183  if (not readOnly)
184  {
185  connect(ui->checkBoxPatternReadOnly, &QRadioButton::toggled, this, [this](){securityChanged = true;});
186  }
187  else
188  {
189  ui->checkBoxPatternReadOnly->setDisabled(true);
190  }
191 
192  //Initialization change value. Set to default value after initialization
193  gradationChanged = false;
194  defaultChanged = false;
195  securityChanged = false;
196 
197  ui->lineEditPatternName->setText(doc->GetPatternName());
198  ui->lineEditPatternNumber->setText(doc->GetPatternNumber());
199  ui->lineEditCompanyName->setText(doc->GetCompanyName());
200  ui->lineEditCustomerName->setText(doc->GetCustomerName());
201 
202  connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
203  connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
204  connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
205  connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
206  connect(ui->pushButtonEditPatternLabel, &QPushButton::clicked, this, &DialogPatternProperties::EditLabel);
207 
208  initComboBoxFormats(ui->comboBoxDateFormat,
211  initComboBoxFormats(ui->comboBoxTimeFormat,
214 
215  connect(ui->comboBoxDateFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
217  connect(ui->comboBoxTimeFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
219 }
220 
221 //---------------------------------------------------------------------------------------------------------------------
223 {
224  delete ui;
225 }
226 
227 //---------------------------------------------------------------------------------------------------------------------
229 {
230  switch (ui->tabWidget->currentIndex())
231  {
232  case 0:
233  SaveDescription();
234  break;
235  case 1:
236  SaveGradation();
237  SaveDefValues();
238  break;
239  case 2:
241  break;
242  case 3:
243  SaveLabelData();
245  emit doc->UpdatePatternLabel();
246  break;
247  default:
248  break;
249  }
250 }
251 
252 //---------------------------------------------------------------------------------------------------------------------
254 {
255  SaveDescription();
256  SaveGradation();
257  SaveDefValues();
259  SaveLabelData();
261 
262  emit doc->UpdatePatternLabel();
263 
264  close();
265 }
266 
267 //---------------------------------------------------------------------------------------------------------------------
269 {
270  QCheckBox* box = qobject_cast<QCheckBox*>(sender());
271  if (box)
272  {
273  if (box == ui->checkBoxAllHeights)
274  {
275  if (state == Qt::Checked)
276  {
277  SetHeightsChecked(true);
278  }
279  else if (state == Qt::Unchecked)
280  {
281  SetHeightsChecked(false);
282  }
283 
284  if (data.contains(box))
285  {
286  heights.insert(static_cast<GHeights>(data.value(box)), box->isChecked());
287  }
288  }
289 
290  if (box == ui->checkBoxAllSizes)
291  {
292  if (state == Qt::Checked)
293  {
294  SetSizesChecked(true);
295  }
296  else if (state == Qt::Unchecked)
297  {
298  SetSizesChecked(false);
299  }
300 
301  if (data.contains(box))
302  {
303  sizes.insert(static_cast<GSizes>(data.value(box)), box->isChecked());
304  }
305  }
306  }
307 }
308 
309 //---------------------------------------------------------------------------------------------------------------------
311 {
312  QCheckBox* box = qobject_cast<QCheckBox*>(sender());
313  if (box)
314  {
315  if (state == Qt::Checked)
316  {
317  ++heightsChecked;
319  {
320  ui->checkBoxAllHeights->blockSignals(true);//don't touch anothers checkboxes
321  ui->checkBoxAllHeights->setCheckState(Qt::Checked);
322  heights.insert(GHeights::ALL, true);
323  ui->checkBoxAllHeights->blockSignals(false);
324  }
325  }
326  else if (state == Qt::Unchecked)
327  {
329  {
330  ui->checkBoxAllHeights->blockSignals(true);//don't touch anothers checkboxes
331  ui->checkBoxAllHeights->setCheckState(Qt::Unchecked);
332  heights.insert(GHeights::ALL, false);
333  ui->checkBoxAllHeights->blockSignals(false);
334  }
335  --heightsChecked;
336  }
337 
338  if (data.contains(box))
339  {
340  heights.insert(static_cast<GHeights>(data.value(box)), box->isChecked());
341  }
342 
343  UpdateDefHeight();
344 
345  CheckApplyOk();
346  gradationChanged = true;
347  }
348 }
349 
350 //---------------------------------------------------------------------------------------------------------------------
352 {
353  QCheckBox* box = qobject_cast<QCheckBox*>(sender());
354  if (box)
355  {
356 
357  if (state == Qt::Checked)
358  {
359  ++sizesChecked;
360  if (sizesChecked == sizesCount)
361  {
362  ui->checkBoxAllSizes->blockSignals(true);//don't touch anothers checkboxes
363  ui->checkBoxAllSizes->setCheckState(Qt::Checked);
364  sizes.insert(GSizes::ALL, true);
365  ui->checkBoxAllSizes->blockSignals(false);
366  }
367  }
368  else if (state == Qt::Unchecked)
369  {
370  if (sizesChecked == sizesCount)
371  {
372  ui->checkBoxAllSizes->blockSignals(true);//don't touch anothers checkboxes
373  ui->checkBoxAllSizes->setCheckState(Qt::Unchecked);
374  sizes.insert(GSizes::ALL, false);
375  ui->checkBoxAllSizes->blockSignals(false);
376  }
377  --sizesChecked;
378  }
379 
380  if (data.contains(box))
381  {
382  sizes.insert(static_cast<GSizes>(data.value(box)), box->isChecked());
383  }
384 
385  UpdateDefSize();
386 
387  CheckApplyOk();
388  gradationChanged = true;
389  }
390 }
391 
392 //---------------------------------------------------------------------------------------------------------------------
394 {
395  descriptionChanged = true;
396 }
397 
398 //---------------------------------------------------------------------------------------------------------------------
400 {
401  defaultChanged = true;
402 }
403 
404 //---------------------------------------------------------------------------------------------------------------------
406 {
407  labelDataChanged = true;
408  askSaveLabelData = true;
409 }
410 
411 //---------------------------------------------------------------------------------------------------------------------
413 {
414  ui->checkBoxH50->setChecked(enabled);
415  ui->checkBoxH56->setChecked(enabled);
416  ui->checkBoxH62->setChecked(enabled);
417  ui->checkBoxH68->setChecked(enabled);
418  ui->checkBoxH74->setChecked(enabled);
419  ui->checkBoxH80->setChecked(enabled);
420  ui->checkBoxH86->setChecked(enabled);
421  ui->checkBoxH92->setChecked(enabled);
422  ui->checkBoxH98->setChecked(enabled);
423  ui->checkBoxH104->setChecked(enabled);
424  ui->checkBoxH110->setChecked(enabled);
425  ui->checkBoxH116->setChecked(enabled);
426  ui->checkBoxH122->setChecked(enabled);
427  ui->checkBoxH128->setChecked(enabled);
428  ui->checkBoxH134->setChecked(enabled);
429  ui->checkBoxH140->setChecked(enabled);
430  ui->checkBoxH146->setChecked(enabled);
431  ui->checkBoxH152->setChecked(enabled);
432  ui->checkBoxH158->setChecked(enabled);
433  ui->checkBoxH164->setChecked(enabled);
434  ui->checkBoxH170->setChecked(enabled);
435  ui->checkBoxH176->setChecked(enabled);
436  ui->checkBoxH182->setChecked(enabled);
437  ui->checkBoxH188->setChecked(enabled);
438  ui->checkBoxH194->setChecked(enabled);
439  ui->checkBoxH200->setChecked(enabled);
440 }
441 
442 //---------------------------------------------------------------------------------------------------------------------
444 {
445  ui->checkBoxS22->setChecked(enabled);
446  ui->checkBoxS24->setChecked(enabled);
447  ui->checkBoxS26->setChecked(enabled);
448  ui->checkBoxS28->setChecked(enabled);
449  ui->checkBoxS30->setChecked(enabled);
450  ui->checkBoxS32->setChecked(enabled);
451  ui->checkBoxS34->setChecked(enabled);
452  ui->checkBoxS36->setChecked(enabled);
453  ui->checkBoxS38->setChecked(enabled);
454  ui->checkBoxS40->setChecked(enabled);
455  ui->checkBoxS42->setChecked(enabled);
456  ui->checkBoxS44->setChecked(enabled);
457  ui->checkBoxS46->setChecked(enabled);
458  ui->checkBoxS48->setChecked(enabled);
459  ui->checkBoxS50->setChecked(enabled);
460  ui->checkBoxS52->setChecked(enabled);
461  ui->checkBoxS54->setChecked(enabled);
462  ui->checkBoxS56->setChecked(enabled);
463  ui->checkBoxS58->setChecked(enabled);
464  ui->checkBoxS60->setChecked(enabled);
465  ui->checkBoxS62->setChecked(enabled);
466  ui->checkBoxS64->setChecked(enabled);
467  ui->checkBoxS66->setChecked(enabled);
468  ui->checkBoxS68->setChecked(enabled);
469  ui->checkBoxS70->setChecked(enabled);
470  ui->checkBoxS72->setChecked(enabled);
471 }
472 
473 //---------------------------------------------------------------------------------------------------------------------
475 {
476  Init(ui->checkBoxAllHeights, static_cast<int>(GHeights::ALL), &DialogPatternProperties::SelectAll);
477 
478  Init(ui->checkBoxH50, static_cast<int>(GHeights::H50), &DialogPatternProperties::CheckStateHeight);
479  Init(ui->checkBoxH56, static_cast<int>(GHeights::H56), &DialogPatternProperties::CheckStateHeight);
480  Init(ui->checkBoxH62, static_cast<int>(GHeights::H62), &DialogPatternProperties::CheckStateHeight);
481  Init(ui->checkBoxH68, static_cast<int>(GHeights::H68), &DialogPatternProperties::CheckStateHeight);
482  Init(ui->checkBoxH74, static_cast<int>(GHeights::H74), &DialogPatternProperties::CheckStateHeight);
483  Init(ui->checkBoxH80, static_cast<int>(GHeights::H80), &DialogPatternProperties::CheckStateHeight);
484  Init(ui->checkBoxH86, static_cast<int>(GHeights::H86), &DialogPatternProperties::CheckStateHeight);
485  Init(ui->checkBoxH92, static_cast<int>(GHeights::H92), &DialogPatternProperties::CheckStateHeight);
486  Init(ui->checkBoxH98, static_cast<int>(GHeights::H98), &DialogPatternProperties::CheckStateHeight);
487  Init(ui->checkBoxH104, static_cast<int>(GHeights::H104), &DialogPatternProperties::CheckStateHeight);
488  Init(ui->checkBoxH110, static_cast<int>(GHeights::H110), &DialogPatternProperties::CheckStateHeight);
489  Init(ui->checkBoxH116, static_cast<int>(GHeights::H116), &DialogPatternProperties::CheckStateHeight);
490  Init(ui->checkBoxH122, static_cast<int>(GHeights::H122), &DialogPatternProperties::CheckStateHeight);
491  Init(ui->checkBoxH128, static_cast<int>(GHeights::H128), &DialogPatternProperties::CheckStateHeight);
492  Init(ui->checkBoxH134, static_cast<int>(GHeights::H134), &DialogPatternProperties::CheckStateHeight);
493  Init(ui->checkBoxH140, static_cast<int>(GHeights::H140), &DialogPatternProperties::CheckStateHeight);
494  Init(ui->checkBoxH146, static_cast<int>(GHeights::H146), &DialogPatternProperties::CheckStateHeight);
495  Init(ui->checkBoxH152, static_cast<int>(GHeights::H152), &DialogPatternProperties::CheckStateHeight);
496  Init(ui->checkBoxH158, static_cast<int>(GHeights::H158), &DialogPatternProperties::CheckStateHeight);
497  Init(ui->checkBoxH164, static_cast<int>(GHeights::H164), &DialogPatternProperties::CheckStateHeight);
498  Init(ui->checkBoxH170, static_cast<int>(GHeights::H170), &DialogPatternProperties::CheckStateHeight);
499  Init(ui->checkBoxH176, static_cast<int>(GHeights::H176), &DialogPatternProperties::CheckStateHeight);
500  Init(ui->checkBoxH182, static_cast<int>(GHeights::H182), &DialogPatternProperties::CheckStateHeight);
501  Init(ui->checkBoxH188, static_cast<int>(GHeights::H188), &DialogPatternProperties::CheckStateHeight);
502  Init(ui->checkBoxH194, static_cast<int>(GHeights::H194), &DialogPatternProperties::CheckStateHeight);
503  Init(ui->checkBoxH200, static_cast<int>(GHeights::H200), &DialogPatternProperties::CheckStateHeight);
504 }
505 
506 //---------------------------------------------------------------------------------------------------------------------
508 {
509  Init(ui->checkBoxAllSizes, static_cast<int>(GSizes::ALL), &DialogPatternProperties::SelectAll);
510 
511  Init(ui->checkBoxS22, static_cast<int>(GSizes::S22), &DialogPatternProperties::CheckStateSize);
512  Init(ui->checkBoxS24, static_cast<int>(GSizes::S24), &DialogPatternProperties::CheckStateSize);
513  Init(ui->checkBoxS26, static_cast<int>(GSizes::S26), &DialogPatternProperties::CheckStateSize);
514  Init(ui->checkBoxS28, static_cast<int>(GSizes::S28), &DialogPatternProperties::CheckStateSize);
515  Init(ui->checkBoxS30, static_cast<int>(GSizes::S30), &DialogPatternProperties::CheckStateSize);
516  Init(ui->checkBoxS32, static_cast<int>(GSizes::S32), &DialogPatternProperties::CheckStateSize);
517  Init(ui->checkBoxS34, static_cast<int>(GSizes::S34), &DialogPatternProperties::CheckStateSize);
518  Init(ui->checkBoxS36, static_cast<int>(GSizes::S36), &DialogPatternProperties::CheckStateSize);
519  Init(ui->checkBoxS38, static_cast<int>(GSizes::S38), &DialogPatternProperties::CheckStateSize);
520  Init(ui->checkBoxS40, static_cast<int>(GSizes::S40), &DialogPatternProperties::CheckStateSize);
521  Init(ui->checkBoxS42, static_cast<int>(GSizes::S42), &DialogPatternProperties::CheckStateSize);
522  Init(ui->checkBoxS44, static_cast<int>(GSizes::S44), &DialogPatternProperties::CheckStateSize);
523  Init(ui->checkBoxS46, static_cast<int>(GSizes::S46), &DialogPatternProperties::CheckStateSize);
524  Init(ui->checkBoxS48, static_cast<int>(GSizes::S48), &DialogPatternProperties::CheckStateSize);
525  Init(ui->checkBoxS50, static_cast<int>(GSizes::S50), &DialogPatternProperties::CheckStateSize);
526  Init(ui->checkBoxS52, static_cast<int>(GSizes::S52), &DialogPatternProperties::CheckStateSize);
527  Init(ui->checkBoxS54, static_cast<int>(GSizes::S54), &DialogPatternProperties::CheckStateSize);
528  Init(ui->checkBoxS56, static_cast<int>(GSizes::S56), &DialogPatternProperties::CheckStateSize);
529  Init(ui->checkBoxS58, static_cast<int>(GSizes::S58), &DialogPatternProperties::CheckStateSize);
530  Init(ui->checkBoxS60, static_cast<int>(GSizes::S60), &DialogPatternProperties::CheckStateSize);
531  Init(ui->checkBoxS62, static_cast<int>(GSizes::S62), &DialogPatternProperties::CheckStateSize);
532  Init(ui->checkBoxS64, static_cast<int>(GSizes::S64), &DialogPatternProperties::CheckStateSize);
533  Init(ui->checkBoxS66, static_cast<int>(GSizes::S66), &DialogPatternProperties::CheckStateSize);
534  Init(ui->checkBoxS68, static_cast<int>(GSizes::S68), &DialogPatternProperties::CheckStateSize);
535  Init(ui->checkBoxS70, static_cast<int>(GSizes::S70), &DialogPatternProperties::CheckStateSize);
536  Init(ui->checkBoxS72, static_cast<int>(GSizes::S72), &DialogPatternProperties::CheckStateSize);
537 }
538 
539 //---------------------------------------------------------------------------------------------------------------------
540 void DialogPatternProperties::initComboBoxFormats(QComboBox *box, const QStringList &items,
541  const QString &currentFormat)
542 {
543  SCASSERT(box != nullptr)
544 
545  box->addItems(items);
546  int index = box->findText(currentFormat);
547  if (index != -1)
548  {
549  box->setCurrentIndex(index);
550  }
551  else
552  {
553  box->setCurrentIndex(0);
554  }
555 }
556 
557 //---------------------------------------------------------------------------------------------------------------------
559 {
560  bool enable = !(heightsChecked == 0 || sizesChecked == 0);
561  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
562  ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enable);
563 }
564 
565 //---------------------------------------------------------------------------------------------------------------------
567 {
568  if (descriptionChanged)
569  {
570  doc->SetNotes(ui->plainTextEditTechNotes->document()->toPlainText());
571  doc->SetDescription(ui->plainTextEditDescription->document()->toPlainText());
572 
573  descriptionChanged = false;
574  emit doc->patternChanged(false);
575  }
576 }
577 
578 //---------------------------------------------------------------------------------------------------------------------
580 {
581  if (gradationChanged)
582  {
585  emit UpdateGradation();
586  gradationChanged = false;
587  emit doc->patternChanged(false);
588  }
589 }
590 
591 //---------------------------------------------------------------------------------------------------------------------
593 {
594  if (defaultChanged)
595  {
596  if (ui->radioButtonDefFromM->isChecked())
597  {
598  doc->SetDefCustom(false);
599  }
600  else
601  {
602  doc->SetDefCustom(true);
603  doc->SetDefCustomHeight(ui->comboBoxHeight->currentText().toInt());
604  doc->SetDefCustomSize(ui->comboBoxSize->currentText().toInt());
605  }
606  defaultChanged = false;
607  emit doc->patternChanged(false);
608  }
609 }
610 
611 //---------------------------------------------------------------------------------------------------------------------
613 {
614  if (labelDataChanged)
615  {
616  doc->SetPatternName(ui->lineEditPatternName->text());
617  doc->SetPatternNumber(ui->lineEditPatternNumber->text());
618  doc->SetCompanyName(ui->lineEditCompanyName->text());
619  doc->SetCustomerName(ui->lineEditCustomerName->text());
620  doc->SetLabelDateFormat(ui->comboBoxDateFormat->currentText());
621  doc->SetLabelTimeFormat(ui->comboBoxTimeFormat->currentText());
622 
623  labelDataChanged = false;
624  askSaveLabelData = false;
625  emit doc->patternChanged(false);
626  emit doc->UpdatePatternLabel();
627  }
628 }
629 
630 //---------------------------------------------------------------------------------------------------------------------
632 {
634  {
636  templateDataChanged = false;
637  emit doc->patternChanged(false);
638  emit doc->UpdatePatternLabel();
639  }
640 }
641 
642 //---------------------------------------------------------------------------------------------------------------------
644 {
645  if (securityChanged)
646  {
647  doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked());
648  securityChanged = false;
649  emit doc->patternChanged(false);
650  }
651 }
652 
653 //---------------------------------------------------------------------------------------------------------------------
655 {
656  int index = ui->comboBoxHeight->findText(def);
657  if (index != -1)
658  {
659  ui->comboBoxHeight->setCurrentIndex(index);
660  defaultChanged = true;
661  }
662  else
663  {
664  const int height = static_cast<int>(VContainer::height());
665  index = ui->comboBoxHeight->findText(QString().setNum(height));
666  if (index != -1)
667  {
668  ui->comboBoxHeight->setCurrentIndex(index);
669  defaultChanged = true;
670  }
671  }
672 }
673 
674 //---------------------------------------------------------------------------------------------------------------------
676 {
677  int index = ui->comboBoxSize->findText(def);
678  if (index != -1)
679  {
680  ui->comboBoxSize->setCurrentIndex(index);
681  defaultChanged = true;
682  }
683  else
684  {
685  const int size = static_cast<int>(VContainer::size());
686  index = ui->comboBoxSize->findText(QString().setNum(size));
687  if (index != -1)
688  {
689  ui->comboBoxSize->setCurrentIndex(index);
690  defaultChanged = true;
691  }
692  }
693 }
694 
695 //---------------------------------------------------------------------------------------------------------------------
697 {
698  const QString def = ui->comboBoxHeight->currentText();
699  InitComboBox(ui->comboBoxHeight, heights);
700  SetDefaultHeight(def);
701 }
702 
703 //---------------------------------------------------------------------------------------------------------------------
705 {
706  const QString def = ui->comboBoxSize->currentText();
707  InitComboBox(ui->comboBoxSize, sizes);
708  SetDefaultSize(def);
709 }
710 
711 //---------------------------------------------------------------------------------------------------------------------
712 template<typename Func>
713 void DialogPatternProperties::Init(QCheckBox *check, int val, Func slot)
714 {
715  connect(check, &QCheckBox::stateChanged, this, slot);
716  data.insert(check, val);
717 }
718 
719 //---------------------------------------------------------------------------------------------------------------------
720 template<typename GVal>
722 {
723  if (option.value(GVal::ALL) == false)
724  {
725  QMapIterator<GVal, bool> i(option);
726  while (i.hasNext())
727  {
728  i.next();
729  if (i.value() == false && i.key() != GVal::ALL)
730  {
731  QCheckBox *box = data.key(static_cast<int>(i.key()));
732  if (box != nullptr)
733  {
734  box->setCheckState(Qt::Unchecked);
735  }
736  }
737  }
738  }
739 }
740 
741 //---------------------------------------------------------------------------------------------------------------------
742 template<typename GVal>
743 void DialogPatternProperties::InitComboBox(QComboBox *box, const QMap<GVal, bool> &option)
744 {
745  SCASSERT(box != nullptr)
746 
747  box->clear();
748 
749  QMapIterator<GVal, bool> i(option);
750  while (i.hasNext())
751  {
752  i.next();
753  if (i.value() && i.key() != GVal::ALL)
754  {
755  box->addItem(QString().setNum(static_cast<int>(UnitConvertor(static_cast<int>(i.key()), Unit::Cm,
756  *pattern->GetPatternUnit()))));
757  }
758  }
759 }
760 
761 //---------------------------------------------------------------------------------------------------------------------
763 {
764 // we set an image from file.val
765  QImage image;
766  QByteArray byteArray;
767  byteArray.append(doc->GetImage().toUtf8());
768  QByteArray ba = QByteArray::fromBase64(byteArray);
769  QBuffer buffer(&ba);
770  buffer.open(QIODevice::ReadOnly);
771  QString extension = doc->GetImageExtension();
772  image.load(&buffer, extension.toLatin1().data()); // writes image into ba in 'extension' format
773  return image;
774 }
775 
776 //---------------------------------------------------------------------------------------------------------------------
778 {
779  ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu);
780  ui->imageLabel->setScaledContents(true);
781  connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, [this]()
782  {
783  QMenu menu(this);
784  menu.addAction(deleteAction);
785  menu.addAction(changeImageAction);
786  menu.addAction(saveImageAction);
787  menu.addAction(showImageAction);
788  menu.exec(QCursor::pos());
789  menu.show();
790  });
791 
792  deleteAction = new QAction(tr("Delete image"), this);
793  changeImageAction = new QAction(tr("Change image"), this);
794  saveImageAction = new QAction(tr("Save image to file"), this);
795  showImageAction = new QAction(tr("Show image"), this);
796 
797  connect(deleteAction, &QAction::triggered, this, [this]()
798  {
799  doc->DeleteImage();
800  ui->imageLabel->setText(tr("Change image"));
801  deleteAction->setEnabled(false);
802  saveImageAction->setEnabled(false);
803  showImageAction->setEnabled(false);
804  });
805 
806  connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::ChangeImage);
807  connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage);
808  connect(showImageAction, &QAction::triggered, this, [this]()
809  {
810  QLabel *label = new QLabel(this, Qt::Window);
811  const QImage image = GetImage();
812  label->setPixmap(QPixmap::fromImage(image));
813  label->setGeometry(QRect(QCursor::pos(), image.size()));
814  label->show();
815  });
816 
817  const QImage image = GetImage();
818  if (not image.isNull())
819  {
820  ui->imageLabel->setPixmap(QPixmap::fromImage(image));
821  }
822  else
823  {
824  deleteAction->setEnabled(false);
825  saveImageAction->setEnabled(false);
826  showImageAction->setEnabled(false);
827  }
828 }
829 
830 //---------------------------------------------------------------------------------------------------------------------
832 {
833  const QString filter = tr("Images") + QLatin1String(" (*.png *.jpg *.jpeg *.bmp)");
834  const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), filter, nullptr,
835  QFileDialog::DontUseNativeDialog);
836  QImage image;
837  if (fileName.isEmpty())
838  {
839  return;
840  }
841  else
842  {
843  if (not image.load(fileName))
844  {
845  return;
846  }
847  ui->imageLabel->setPixmap(QPixmap::fromImage(image));
848  QFileInfo f(fileName);
849  QString extension = f.suffix().toUpper();
850 
851  if (extension == QLatin1String("JPEG"))
852  {
853  extension = "JPG";
854  }
855  if (extension == QLatin1String("PNG") || extension == QLatin1String("JPG") || extension == QLatin1String("BMP"))
856  {
857  QByteArray byteArray;
858  QBuffer buffer(&byteArray);
859  buffer.open(QIODevice::WriteOnly);
860  image.save(&buffer, extension.toLatin1().data()); //writes the image in 'extension' format inside the buffer
861  QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());
862 
863  // save our image to file.val
864  doc->SetImage(iconBase64, extension);
865  }
866  deleteAction->setEnabled(true);
867  saveImageAction->setEnabled(true);
868  showImageAction->setEnabled(true);
869  }
870 }
871 
872 //---------------------------------------------------------------------------------------------------------------------
874 {
875  QByteArray byteArray;
876  byteArray.append(doc->GetImage().toUtf8());
877  QByteArray ba = QByteArray::fromBase64(byteArray);
878  const QString extension = QLatin1String(".") + doc->GetImageExtension();
879  QString filter = tr("Images") + QLatin1String(" (*") + extension + QLatin1String(")");
880  QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter,
881  QFileDialog::DontUseNativeDialog);
882  if (not filename.isEmpty())
883  {
884  if (not filename.endsWith(extension.toUpper()))
885  {
886  filename.append(extension);
887  }
888  QFile file(filename);
889  if (file.open(QIODevice::WriteOnly))
890  {
891  file.write(ba);
892  file.close();
893  }
894  }
895 }
896 
897 //---------------------------------------------------------------------------------------------------------------------
899 {
901  {
902  QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Save label data."),
903  tr("Label data were changed. Do you want to save them before editing label template?"),
904  QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
905 
906  if (answer == QMessageBox::Yes)
907  {
908  SaveLabelData();
909  }
910  else
911  {
912  askSaveLabelData = false;
913  }
914  }
915 
917 
919 
920  if (QDialog::Accepted == editor.exec())
921  {
922  templateLines = editor.GetTemplate();
923  templateDataChanged = true;
924  }
925 }
virtual ~DialogPatternProperties() Q_DECL_OVERRIDE
void SetDefaultHeight(const QString &def)
QVector< VLabelTemplateLine > templateLines
DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent=nullptr)
Ui::DialogPatternProperties * ui
void InitComboBox(QComboBox *box, const QMap< GVal, bool > &option)
void initComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat)
void Init(QCheckBox *check, int val, Func slot)
void SetOptions(const QMap< GVal, bool > &option)
QMap< QCheckBox *, int > data
void SetDefaultSize(const QString &def)
QMap< GHeights, bool > heights
void SetTemplate(const QVector< VLabelTemplateLine > &lines)
QVector< VLabelTemplateLine > GetTemplate() const
void SetPatternNumber(const QString &qsNum)
void SetGradationHeights(const QMap< GHeights, bool > &options)
void SetImage(const QString &text, const QString &extension)
QString GetCompanyName() const
QVector< VLabelTemplateLine > getPatternLabelTemplate() const
QString GetLabelDateFormat() const
QString GetPatternName() const
QString GetPatternNumber() const
QString GetImageExtension() const
void SetPatternName(const QString &qsName)
void setPatternLabelTemplate(const QVector< VLabelTemplateLine > &lines)
void patternChanged(bool saved)
patternChanged emit if we have unsaved change.
void SetCustomerName(const QString &qsName)
QString GetDescription() const
void UpdatePatternLabel()
QMap< GHeights, bool > GetGradationHeights() const
QString GetImage() const
QString GetCustomerName() const
QMap< GSizes, bool > GetGradationSizes() const
void SetNotes(const QString &text)
void SetCompanyName(const QString &qsName)
void SetLabelDateFormat(const QString &format)
void SetGradationSizes(const QMap< GSizes, bool > &options)
QString GetLabelTimeFormat() const
QString GetNotes() const
void SetLabelTimeFormat(const QString &format)
void SetDescription(const QString &text)
bool GetOsSeparator() const
QStringList GetUserDefinedTimeFormats() const
static QStringList PredefinedTimeFormats()
static QStringList PredefinedDateFormats()
QStringList GetUserDefinedDateFormats() const
The VContainer class container of all variables.
Definition: vcontainer.h:141
static qreal height()
height return height
Definition: vcontainer.cpp:690
static qreal size()
size return size
Definition: vcontainer.cpp:674
const Unit * GetPatternUnit() const
Definition: vcontainer.cpp:599
The VPattern class working with pattern file.
Definition: vpattern.h:68
void SetDefCustomSize(int value)
Definition: vpattern.cpp:3851
int GetDefCustomSize() const
Definition: vpattern.cpp:3823
int GetDefCustomHeight() const
Definition: vpattern.cpp:3764
bool IsReadOnly() const
Definition: vpattern.cpp:3882
void SetReadOnly(bool rOnly)
Definition: vpattern.cpp:3895
bool IsDefCustom() const
Definition: vpattern.cpp:3710
void SetDefCustom(bool value)
Definition: vpattern.cpp:3731
void SetDefCustomHeight(int value)
Definition: vpattern.cpp:3792
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
Definition: def.cpp:269
static const int heightStep
Definition: def.h:279
#define SCASSERT(cond)
Definition: def.h:317
GHeights
Definition: def.h:280
GSizes
Definition: def.h:287
static const int sizeStep
Definition: def.h:286
static const int sizesCount
static const int heightsCount
#define qApp
Definition: vapplication.h:67