Seamly2D
Code documentation
editlabeltemplate_dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file editlabeltemplate_dialog.cpp
3  ** @author Douglas S Caskey
4  ** @date Dec 26, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. if not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 
26 /************************************************************************
27  **
28  ** @file dialogeditlabel.cpp
29  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
30  ** @date 11 8, 2017
31  **
32  ** @brief
33  ** @copyright
34  ** This source code is part of the Valentina project, a pattern making
35  ** program, whose allow create and modeling patterns of clothing.
36  ** Copyright (C) 2017 Valentina project
37  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
38  **
39  ** Valentina is free software: you can redistribute it and/or modify
40  ** it under the terms of the GNU General Public License as published by
41  ** the Free Software Foundation, either version 3 of the License, or
42  ** (at your option) any later version.
43  **
44  ** Valentina is distributed in the hope that it will be useful,
45  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
46  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47  ** GNU General Public License for more details.
48  **
49  ** You should have received a copy of the GNU General Public License
50  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
51  **
52  *************************************************************************/
53 
55 #include "ui_editlabeltemplate_dialog.h"
56 #include "../vmisc/vabstractapplication.h"
57 #include "../vformat/vlabeltemplate.h"
58 #include "../ifc/xml/vlabeltemplateconverter.h"
59 #include "../ifc/xml/vabstractpattern.h"
60 #include "../ifc/exception/vexception.h"
61 #include "../vpatterndb/vcontainer.h"
62 #include "../vpatterndb/vpiece.h"
63 #include "../vpatterndb/floatItemData/vpiecelabeldata.h"
64 
65 #include <QDir>
66 #include <QMessageBox>
67 #include <QFileDialog>
68 #include <QMenu>
69 #include <QDate>
70 
71 //---------------------------------------------------------------------------------------------------------------------
73  : QDialog(parent)
74  , ui(new Ui::EditLabelTemplateDialog)
75  , m_placeholdersMenu(new QMenu(this))
76  , m_doc(doc)
77  , m_placeholders()
78 {
79  ui->setupUi(this);
80  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
81 
82  ui->lineEditLine->setClearButtonEnabled(true);
83 
84  connect(ui->toolButtonAdd, &QToolButton::clicked, this, &EditLabelTemplateDialog::AddLine);
85  connect(ui->toolButtonRemove, &QToolButton::clicked, this, &EditLabelTemplateDialog::RemoveLine);
86  connect(ui->lineEditLine, &QLineEdit::textEdited, this, &EditLabelTemplateDialog::SaveLineText);
87  connect(ui->toolButtonBold, &QToolButton::toggled, this, &EditLabelTemplateDialog::SaveFontStyle);
88  connect(ui->toolButtonItalic, &QToolButton::toggled, this, &EditLabelTemplateDialog::SaveFontStyle);
89  connect(ui->toolButtonTextLeft, &QToolButton::toggled, this, &EditLabelTemplateDialog::SaveTextFormating);
90  connect(ui->toolButtonTextCenter, &QToolButton::toggled, this, &EditLabelTemplateDialog::SaveTextFormating);
91  connect(ui->toolButtonTextRight, &QToolButton::toggled, this, &EditLabelTemplateDialog::SaveTextFormating);
92  connect(ui->listWidgetEdit, &QListWidget::itemSelectionChanged, this, &EditLabelTemplateDialog::ShowLineDetails);
93  connect(ui->tabWidget, &QTabWidget::currentChanged, this, &EditLabelTemplateDialog::TabChanged);
94  connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &EditLabelTemplateDialog::NewTemplate);
95  connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &EditLabelTemplateDialog::ExportTemplate);
96  connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &EditLabelTemplateDialog::ImportTemplate);
97  connect(ui->spinBoxFontSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
99 
102 
103  ui->pushButtonInsert->setMenu(m_placeholdersMenu);
104 }
105 
106 //---------------------------------------------------------------------------------------------------------------------
108 {
109  delete ui;
110 }
111 
112 //---------------------------------------------------------------------------------------------------------------------
114 {
115  if (ui->listWidgetEdit->count() > 0)
116  {
117  const QListWidgetItem *line = ui->listWidgetEdit->currentItem();
118  if (line)
119  {
120  ui->lineEditLine->blockSignals(true);
121  ui->lineEditLine->setText(line->text());
122  ui->lineEditLine->blockSignals(false);
123 
124  const QFont lineFont = line->font();
125 
126  ui->toolButtonBold->blockSignals(true);
127  ui->toolButtonBold->setChecked(lineFont.bold());
128  ui->toolButtonBold->blockSignals(false);
129 
130  ui->toolButtonItalic->blockSignals(true);
131  ui->toolButtonItalic->setChecked(lineFont.italic());
132  ui->toolButtonItalic->blockSignals(false);
133 
134  ui->toolButtonTextLeft->blockSignals(true);
135  ui->toolButtonTextCenter->blockSignals(true);
136  ui->toolButtonTextRight->blockSignals(true);
137 
138  const int lineAlignment = line->textAlignment();
139 
140  if (lineAlignment == 0 || lineAlignment & Qt::AlignLeft)
141  {
142  ui->toolButtonTextLeft->setChecked(true);
143  ui->toolButtonTextCenter->setChecked(false);
144  ui->toolButtonTextRight->setChecked(false);
145  }
146  else if (lineAlignment & Qt::AlignHCenter)
147  {
148  ui->toolButtonTextLeft->setChecked(false);
149  ui->toolButtonTextCenter->setChecked(true);
150  ui->toolButtonTextRight->setChecked(false);
151  }
152  else if (lineAlignment & Qt::AlignRight)
153  {
154  ui->toolButtonTextLeft->setChecked(false);
155  ui->toolButtonTextCenter->setChecked(false);
156  ui->toolButtonTextRight->setChecked(true);
157  }
158 
159  ui->toolButtonTextLeft->blockSignals(false);
160  ui->toolButtonTextCenter->blockSignals(false);
161  ui->toolButtonTextRight->blockSignals(false);
162 
163  ui->spinBoxFontSize->blockSignals(true);
164  ui->spinBoxFontSize->setValue(line->data(Qt::UserRole).toInt());
165  ui->spinBoxFontSize->blockSignals(false);
166  }
167  }
168 
169  SetupControls();
170 }
171 
172 //---------------------------------------------------------------------------------------------------------------------
174 {
175  int row = ui->listWidgetEdit->currentRow();
176  ui->listWidgetEdit->insertItem(++row, new QListWidgetItem(tr("<empty>")));
177  ui->listWidgetEdit->setCurrentRow(row);
178 }
179 
180 //---------------------------------------------------------------------------------------------------------------------
182 {
183  ui->listWidgetEdit->blockSignals(true);
184  QListWidgetItem *curLine = ui->listWidgetEdit->takeItem(ui->listWidgetEdit->currentRow());
185  if (curLine)
186  {
187  delete curLine;
188  }
189  ui->listWidgetEdit->blockSignals(false);
190  ShowLineDetails();
191 }
192 
193 //---------------------------------------------------------------------------------------------------------------------
194 void EditLabelTemplateDialog::SaveLineText(const QString &text)
195 {
196  QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
197  if (curLine)
198  {
199  curLine->setText(text);
200  }
201 }
202 
203 //---------------------------------------------------------------------------------------------------------------------
205 {
206  QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
207  if (curLine)
208  {
209  QFont lineFont = curLine->font();
210 
211  QToolButton *button = qobject_cast<QToolButton *>(sender());
212  if (button)
213  {
214  if (button == ui->toolButtonBold)
215  {
216  lineFont.setBold(checked);
217  }
218  else if (button == ui->toolButtonItalic)
219  {
220  lineFont.setItalic(checked);
221  }
222  }
223 
224  curLine->setFont(lineFont);
225  }
226 }
227 
228 //---------------------------------------------------------------------------------------------------------------------
230 {
231  QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
232  if (curLine)
233  {
234  QToolButton *button = qobject_cast<QToolButton *>(sender());
235  if (button)
236  {
237  ui->toolButtonTextLeft->blockSignals(true);
238  ui->toolButtonTextCenter->blockSignals(true);
239  ui->toolButtonTextRight->blockSignals(true);
240 
241  if (button == ui->toolButtonTextLeft)
242  {
243  if (checked)
244  {
245  curLine->setTextAlignment(Qt::AlignLeft);
246 
247  ui->toolButtonTextCenter->setChecked(false);
248  ui->toolButtonTextRight->setChecked(false);
249  }
250  else
251  {
252  button->setChecked(true);
253  }
254  }
255  else if (button == ui->toolButtonTextCenter)
256  {
257  if (checked)
258  {
259  curLine->setTextAlignment(Qt::AlignHCenter);
260 
261  ui->toolButtonTextLeft->setChecked(false);
262  ui->toolButtonTextRight->setChecked(false);
263  }
264  else
265  {
266  button->setChecked(true);
267  }
268  }
269  else if (button == ui->toolButtonTextRight)
270  {
271  if (checked)
272  {
273  curLine->setTextAlignment(Qt::AlignRight);
274 
275  ui->toolButtonTextCenter->setChecked(false);
276  ui->toolButtonTextRight->setChecked(false);
277  }
278  else
279  {
280  button->setChecked(true);
281  }
282  }
283 
284  ui->toolButtonTextLeft->blockSignals(false);
285  ui->toolButtonTextCenter->blockSignals(false);
286  ui->toolButtonTextRight->blockSignals(false);
287  }
288  }
289 }
290 
291 //---------------------------------------------------------------------------------------------------------------------
293 {
294  if (ui->listWidgetEdit->count() > 0)
295  {
296  const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Create new template"),
297  tr("Creating new template will overwrite the current, do "
298  "you want to continue?"),
299  QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
300  if (answer == QMessageBox::No)
301  {
302  return;
303  }
304  }
305 
306  ui->listWidgetEdit->blockSignals(true);
307  ui->listWidgetEdit->clear();
308  ui->listWidgetEdit->blockSignals(false);
309  ShowLineDetails();
310 }
311 
312 //---------------------------------------------------------------------------------------------------------------------
314 {
315  QString filters(tr("Label template") + QLatin1String("(*.xml)"));
316  QString dir = qApp->Settings()->GetPathLabelTemplate();
317 
318  bool usedNotExistedDir = false;
319  QDir directory(dir);
320  if (not directory.exists())
321  {
322  usedNotExistedDir = directory.mkpath(".");
323  }
324 
325  QString fileName = QFileDialog::getSaveFileName(this, tr("Export label template"),
326  dir + QLatin1String("/") + tr("template") + QLatin1String(".xml"),
327  filters, nullptr, QFileDialog::DontUseNativeDialog);
328 
329  auto RemoveTempDir = [usedNotExistedDir, dir]()
330  {
331  if (usedNotExistedDir)
332  {
333  QDir directory(dir);
334  directory.rmpath(".");
335  }
336  };
337 
338  if (fileName.isEmpty())
339  {
340  RemoveTempDir();
341  return;
342  }
343 
344  QFileInfo f( fileName );
345  if (f.suffix().isEmpty() && f.suffix() != QLatin1String("xml"))
346  {
347  fileName += QLatin1String(".xml");
348  }
349 
350  VLabelTemplate ltemplate;
351  ltemplate.CreateEmptyTemplate();
352  ltemplate.AddLines(GetTemplate());
353 
354  QString error;
355  const bool result = ltemplate.SaveDocument(fileName, error);
356  if (result == false)
357  {
358  QMessageBox messageBox(this);
359  messageBox.setIcon(QMessageBox::Warning);
360  messageBox.setInformativeText(tr("Could not save file"));
361  messageBox.setDefaultButton(QMessageBox::Ok);
362  messageBox.setDetailedText(error);
363  messageBox.setStandardButtons(QMessageBox::Ok);
364  messageBox.exec();
365  }
366 
367  RemoveTempDir();
368 }
369 
370 //---------------------------------------------------------------------------------------------------------------------
372 {
373  if (ui->listWidgetEdit->count() > 0)
374  {
375  const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Import template"),
376  tr("Import template will overwrite the current, do "
377  "you want to continue?"),
378  QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
379  if (answer == QMessageBox::No)
380  {
381  return;
382  }
383  }
384 
385  QString filter(tr("Label template") + QLatin1String("(*.xml)"));
386  const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"),
387  qApp->Settings()->GetPathLabelTemplate(), filter, nullptr,
388  QFileDialog::DontUseNativeDialog);
389  if (fileName.isEmpty())
390  {
391  return;
392  }
393 
394  try
395  {
396  VLabelTemplate ltemplate;
397  ltemplate.setXMLContent(VLabelTemplateConverter(fileName).Convert());
398  SetTemplate(ltemplate.ReadLines());
399  }
400  catch (VException &e)
401  {
402  qCritical("%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), qUtf8Printable(e.ErrorMessage()),
403  qUtf8Printable(e.DetailedInformation()));
404  }
405 }
406 
407 //---------------------------------------------------------------------------------------------------------------------
409 {
410  QAction *action = qobject_cast<QAction *>(sender());
411  if (action)
412  {
413  ui->lineEditLine->insert(action->data().toString());
414  ui->lineEditLine->setFocus();
415  }
416 }
417 
418 //---------------------------------------------------------------------------------------------------------------------
420 {
421  if (index == ui->tabWidget->indexOf(ui->tabPreview))
422  {
423  ui->toolButtonNewLabel->setDisabled(true);
424  ui->toolButtonImportLabel->setDisabled(true);
426  }
427  else
428  {
429  ui->toolButtonNewLabel->setEnabled(ui->listWidgetEdit->count() > 0);
430  ui->toolButtonImportLabel->setEnabled(true);
431  }
432 }
433 
434 //---------------------------------------------------------------------------------------------------------------------
436 {
437  QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
438  if (curLine)
439  {
440  QFont lineFont = curLine->font();
441  lineFont.setPointSize(lineFont.pointSize() - curLine->data(Qt::UserRole).toInt() + i);
442  curLine->setFont(lineFont);
443  curLine->setData(Qt::UserRole, i);
444  }
445 }
446 
447 //---------------------------------------------------------------------------------------------------------------------
449 {
450  const bool enabled = ui->listWidgetEdit->count() > 0;
451 
452  if (not enabled)
453  {
454  ui->lineEditLine->blockSignals(true);
455  ui->lineEditLine->clear();
456  ui->lineEditLine->blockSignals(false);
457  }
458 
459  ui->toolButtonAdd->setEnabled(true);
460  ui->toolButtonImportLabel->setEnabled(true);
461 
462  ui->toolButtonRemove->setEnabled(enabled);
463  ui->toolButtonBold->setEnabled(enabled);
464  ui->toolButtonItalic->setEnabled(enabled);
465  ui->toolButtonTextLeft->setEnabled(enabled);
466  ui->toolButtonTextCenter->setEnabled(enabled);
467  ui->toolButtonTextRight->setEnabled(enabled);
468  ui->pushButtonInsert->setEnabled(enabled);
469  ui->toolButtonNewLabel->setEnabled(enabled);
470  ui->toolButtonExportLabel->setEnabled(enabled);
471  ui->lineEditLine->setEnabled(enabled);
472  ui->spinBoxFontSize->setEnabled(enabled);
473 }
474 
475 //---------------------------------------------------------------------------------------------------------------------
477 {
478  QChar per('%');
479  auto i = m_placeholders.constBegin();
480  while (i != m_placeholders.constEnd())
481  {
482  auto value = i.value();
483  QAction *action = m_placeholdersMenu->addAction(value.first);
484  action->setData(per + qApp->TrVars()->PlaceholderToUser(i.key()) + per);
485  connect(action, &QAction::triggered, this, &EditLabelTemplateDialog::InsertPlaceholder);
486  ++i;
487  }
488 }
489 
490 //---------------------------------------------------------------------------------------------------------------------
492 {
493  // Pattern tags
494  QLocale locale(qApp->Settings()->GetLocale());
495 
496  const QString date = locale.toString(QDate::currentDate(), m_doc->GetLabelDateFormat());
497  m_placeholders.insert(pl_date, qMakePair(tr("Date"), date));
498 
499  const QString time = locale.toString(QTime::currentTime(), m_doc->GetLabelTimeFormat());
500  m_placeholders.insert(pl_time, qMakePair(tr("Time"), time));
501 
502  m_placeholders.insert(pl_patternName, qMakePair(tr("Pattern name"), m_doc->GetPatternName()));
503  m_placeholders.insert(pl_patternNumber, qMakePair(tr("Pattern number"), m_doc->GetPatternNumber()));
504  m_placeholders.insert(pl_author, qMakePair(tr("Company name or designer name"),
505  m_doc->GetCompanyName()));
506  m_placeholders.insert(pl_customer, qMakePair(tr("Customer name"), m_doc->GetCustomerName()));
507  m_placeholders.insert(pl_pExt, qMakePair(tr("Pattern extension"), QString("val")));
508 
509  const QString patternFilePath = QFileInfo(qApp->getFilePath()).baseName();
510  m_placeholders.insert(pl_pFileName, qMakePair(tr("Pattern file name"), patternFilePath));
511 
512  const QString measurementsFilePath = QFileInfo(m_doc->MPath()).baseName();
513  m_placeholders.insert(pl_mFileName, qMakePair(tr("Measurments file name"), measurementsFilePath));
514 
515  QString curSize;
516  QString curHeight;
517  QString mExt;
518  if (qApp->patternType() == MeasurementsType::Multisize)
519  {
520  curSize = QString::number(VContainer::size());
521  curHeight = QString::number(VContainer::height());
522  mExt = "vst";
523  }
524  else if (qApp->patternType() == MeasurementsType::Individual)
525  {
526  curSize = QString::number(VContainer::size());
527  curHeight = QString::number(VContainer::height());
528  mExt = "vit";
529  }
530 
531  m_placeholders.insert(pl_size, qMakePair(tr("Size"), curSize));
532  m_placeholders.insert(pl_height, qMakePair(tr("Height"), curHeight));
533  m_placeholders.insert(pl_mExt, qMakePair(tr("Measurments extension"), mExt));
534 
535  // Piece tags
536  m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString("")));
537  m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString("")));
538  m_placeholders.insert(pl_pOrientation, qMakePair(tr("Piece orientation"), QString("")));
539  m_placeholders.insert(pl_pRotation, qMakePair(tr("Piece rotation"), QString("")));
540  m_placeholders.insert(pl_pTilt, qMakePair(tr("Piece tilt"), QString("")));
541  m_placeholders.insert(pl_pFoldPosition, qMakePair(tr("Piece fold position"), QString("")));
542  m_placeholders.insert(pl_pName, qMakePair(tr("Piece name"), QString("")));
543  m_placeholders.insert(pl_pQuantity, qMakePair(tr("Quantity"), QString("")));
544  m_placeholders.insert(pl_mFabric, qMakePair(tr("Material: Fabric"), tr("Fabric")));
545  m_placeholders.insert(pl_mLining, qMakePair(tr("Material: Lining"), tr("Lining")));
546  m_placeholders.insert(pl_mInterfacing, qMakePair(tr("Material: Interfacing"), tr("Interfacing")));
547  m_placeholders.insert(pl_mInterlining, qMakePair(tr("Material: Interlining"), tr("Interlining")));
548  m_placeholders.insert(pl_wCut, qMakePair(tr("Word: Cut"), tr("Cut")));
549  m_placeholders.insert(pl_wOnFold, qMakePair(tr("Word: on fold"), QString("")));// By default should be empty
550 }
551 
552 //---------------------------------------------------------------------------------------------------------------------
554 {
555  auto i = m_placeholders.constBegin();
556  while (i != m_placeholders.constEnd())
557  {
558  line.replace(QChar('%')+i.key()+QChar('%'), i.value().second);
559  ++i;
560  }
561  return line;
562 }
563 
564 //---------------------------------------------------------------------------------------------------------------------
566 {
568 
569  for (int i=0; i<ui->listWidgetEdit->count(); ++i)
570  {
571  const QListWidgetItem *lineItem = ui->listWidgetEdit->item(i);
572  if (lineItem)
573  {
574  VLabelTemplateLine line;
575  line.line = qApp->TrVars()->PlaceholderFromUserText(lineItem->text());
576  line.alignment = lineItem->textAlignment();
577  line.fontSizeIncrement = lineItem->data(Qt::UserRole).toInt();
578 
579  const QFont font = lineItem->font();
580  line.bold = font.bold();
581  line.italic = font.italic();
582 
583  lines.append(line);
584  }
585  }
586 
587  return lines;
588 }
589 
590 //---------------------------------------------------------------------------------------------------------------------
592 {
593  ui->listWidgetEdit->blockSignals(true);
594  ui->listWidgetEdit->clear();
595 
596  int row = -1;
597 
598  for (int i=0; i<lines.size(); ++i)
599  {
600  QListWidgetItem *item = new QListWidgetItem(qApp->TrVars()->PlaceholderToUserText(lines.at(i).line));
601  item->setTextAlignment(lines.at(i).alignment);
602  item->setData(Qt::UserRole, lines.at(i).fontSizeIncrement);
603 
604  QFont font = item->font();
605  font.setBold(lines.at(i).bold);
606  font.setItalic(lines.at(i).italic);
607  font.setPointSize(font.pointSize() + lines.at(i).fontSizeIncrement);
608  item->setFont(font);
609 
610  ui->listWidgetEdit->insertItem(++row, item);
611  }
612 
613  ui->listWidgetEdit->blockSignals(false);
614 
615  if (ui->listWidgetEdit->count() > 0)
616  {
617  ui->listWidgetEdit->setCurrentRow(0);
618  }
619 }
620 
621 //---------------------------------------------------------------------------------------------------------------------
623 {
624  const VPieceLabelData& pieceData = piece.GetPatternPieceData();
625  m_placeholders[pl_pLetter].second = pieceData.GetLetter();
626  m_placeholders[pl_pAnnotation].second = pieceData.GetAnnotation();
627  m_placeholders[pl_pOrientation].second = pieceData.GetOrientation();
628  m_placeholders[pl_pRotation].second = pieceData.GetRotationWay();
629  m_placeholders[pl_pTilt].second = pieceData.GetTilt();
630  m_placeholders[pl_pFoldPosition].second = pieceData.GetFoldPosition();
631  m_placeholders[pl_pName].second = piece.GetName();
632  m_placeholders[pl_pQuantity].second = QString::number(pieceData.GetQuantity());
633  if (pieceData.IsOnFold())
634  {
635  m_placeholders[pl_wOnFold].second = tr("on fold");
636  }
637 }
638 
639 //---------------------------------------------------------------------------------------------------------------------
641 {
642  ui->listWidgetPreview->clear();
643 
644  int row = -1;
645 
646  for (int i=0; i<lines.size(); ++i)
647  {
648  QListWidgetItem *item = new QListWidgetItem(ReplacePlaceholders(lines.at(i).line));
649  item->setTextAlignment(lines.at(i).alignment);
650  item->setData(Qt::UserRole, lines.at(i).fontSizeIncrement);
651 
652  QFont font = item->font();
653  font.setBold(lines.at(i).bold);
654  font.setItalic(lines.at(i).italic);
655  font.setPointSize(font.pointSize() + lines.at(i).fontSizeIncrement);
656  item->setFont(font);
657 
658  ui->listWidgetPreview->insertItem(++row, item);
659  }
660 
661  if (ui->listWidgetPreview->count() > 0)
662  {
663  ui->listWidgetPreview->setCurrentRow(0);
664  }
665 }
void SetTemplate(const QVector< VLabelTemplateLine > &lines)
QVector< VLabelTemplateLine > GetTemplate() const
Ui::EditLabelTemplateDialog * ui
void SetPiece(const VPiece &piece)
void InitPreviewLines(const QVector< VLabelTemplateLine > &lines)
QMap< QString, QPair< QString, QString > > m_placeholders
void SaveLineText(const QString &text)
QString ReplacePlaceholders(QString line) const
EditLabelTemplateDialog(VAbstractPattern *doc, QWidget *parent=nullptr)
QString GetCompanyName() const
QString GetLabelDateFormat() const
QString MPath() const
QString GetPatternName() const
QString GetPatternNumber() const
QString GetCustomerName() const
QString GetLabelTimeFormat() const
QString GetName() const
static qreal height()
height return height
Definition: vcontainer.cpp:690
static qreal size()
size return size
Definition: vcontainer.cpp:674
virtual void setXMLContent(const QString &fileName)
virtual bool SaveDocument(const QString &fileName, QString &error)
The VException class parent for all exception. Could be use for abstract exception.
Definition: vexception.h:66
virtual QString ErrorMessage() const
ErrorMessage return main error message.
Definition: vexception.cpp:97
virtual QString DetailedInformation() const
DetailedInformation return detailed information about error.
Definition: vexception.cpp:134
void AddLines(const QVector< VLabelTemplateLine > &lines)
void CreateEmptyTemplate()
QVector< VLabelTemplateLine > ReadLines() const
The VPieceLabelData class holds some information about a single piece like letter,...
QString GetOrientation() const
bool IsOnFold() const
int GetQuantity() const
QString GetRotationWay() const
QString GetAnnotation() const
QString GetTilt() const
QString GetLetter() const
QString GetFoldPosition() const
Definition: vpiece.h:88
VPieceLabelData & GetPatternPieceData()
Returns full access to the pattern piece data object.
Definition: vpiece.cpp:532
const QString pl_size
Definition: def.cpp:137
const QString pl_customer
Definition: def.cpp:144
const QString pl_pExt
Definition: def.cpp:145
const QString pl_mExt
Definition: def.cpp:148
const QString pl_pFoldPosition
Definition: def.cpp:154
const QString pl_wCut
Definition: def.cpp:161
const QString pl_author
Definition: def.cpp:143
const QString pl_time
Definition: def.cpp:140
const QString pl_pQuantity
Definition: def.cpp:156
const QString pl_mFileName
Definition: def.cpp:147
const QString pl_patternName
Definition: def.cpp:141
const QString pl_pAnnotation
Definition: def.cpp:150
const QString pl_pName
Definition: def.cpp:155
const QString pl_wOnFold
Definition: def.cpp:162
const QString pl_patternNumber
Definition: def.cpp:142
const QString pl_mLining
Definition: def.cpp:158
const QString pl_pFileName
Definition: def.cpp:146
const QString pl_date
Definition: def.cpp:139
const QString pl_mInterfacing
Definition: def.cpp:159
const QString pl_mFabric
Definition: def.cpp:157
const QString pl_pOrientation
Definition: def.cpp:151
const QString pl_pRotation
Definition: def.cpp:152
const QString pl_mInterlining
Definition: def.cpp:160
const QString pl_pTilt
Definition: def.cpp:153
const QString pl_height
Definition: def.cpp:138
const QString pl_pLetter
Definition: def.cpp:149
QString line
Definition: ifcdef.h:281
int fontSizeIncrement
Definition: ifcdef.h:285
#define qApp
Definition: vapplication.h:67