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"
66 #include <QMessageBox>
67 #include <QFileDialog>
75 , m_placeholdersMenu(new QMenu(this))
80 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
82 ui->lineEditLine->setClearButtonEnabled(
true);
97 connect(
ui->spinBoxFontSize,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
this,
115 if (
ui->listWidgetEdit->count() > 0)
117 const QListWidgetItem *line =
ui->listWidgetEdit->currentItem();
120 ui->lineEditLine->blockSignals(
true);
121 ui->lineEditLine->setText(line->text());
122 ui->lineEditLine->blockSignals(
false);
124 const QFont lineFont = line->font();
126 ui->toolButtonBold->blockSignals(
true);
127 ui->toolButtonBold->setChecked(lineFont.bold());
128 ui->toolButtonBold->blockSignals(
false);
130 ui->toolButtonItalic->blockSignals(
true);
131 ui->toolButtonItalic->setChecked(lineFont.italic());
132 ui->toolButtonItalic->blockSignals(
false);
134 ui->toolButtonTextLeft->blockSignals(
true);
135 ui->toolButtonTextCenter->blockSignals(
true);
136 ui->toolButtonTextRight->blockSignals(
true);
138 const int lineAlignment = line->textAlignment();
140 if (lineAlignment == 0 || lineAlignment & Qt::AlignLeft)
142 ui->toolButtonTextLeft->setChecked(
true);
143 ui->toolButtonTextCenter->setChecked(
false);
144 ui->toolButtonTextRight->setChecked(
false);
146 else if (lineAlignment & Qt::AlignHCenter)
148 ui->toolButtonTextLeft->setChecked(
false);
149 ui->toolButtonTextCenter->setChecked(
true);
150 ui->toolButtonTextRight->setChecked(
false);
152 else if (lineAlignment & Qt::AlignRight)
154 ui->toolButtonTextLeft->setChecked(
false);
155 ui->toolButtonTextCenter->setChecked(
false);
156 ui->toolButtonTextRight->setChecked(
true);
159 ui->toolButtonTextLeft->blockSignals(
false);
160 ui->toolButtonTextCenter->blockSignals(
false);
161 ui->toolButtonTextRight->blockSignals(
false);
163 ui->spinBoxFontSize->blockSignals(
true);
164 ui->spinBoxFontSize->setValue(line->data(Qt::UserRole).toInt());
165 ui->spinBoxFontSize->blockSignals(
false);
175 int row =
ui->listWidgetEdit->currentRow();
176 ui->listWidgetEdit->insertItem(++row,
new QListWidgetItem(tr(
"<empty>")));
177 ui->listWidgetEdit->setCurrentRow(row);
183 ui->listWidgetEdit->blockSignals(
true);
184 QListWidgetItem *curLine =
ui->listWidgetEdit->takeItem(
ui->listWidgetEdit->currentRow());
189 ui->listWidgetEdit->blockSignals(
false);
196 QListWidgetItem *curLine =
ui->listWidgetEdit->currentItem();
199 curLine->setText(text);
206 QListWidgetItem *curLine =
ui->listWidgetEdit->currentItem();
209 QFont lineFont = curLine->font();
211 QToolButton *button = qobject_cast<QToolButton *>(sender());
214 if (button ==
ui->toolButtonBold)
216 lineFont.setBold(checked);
218 else if (button ==
ui->toolButtonItalic)
220 lineFont.setItalic(checked);
224 curLine->setFont(lineFont);
231 QListWidgetItem *curLine =
ui->listWidgetEdit->currentItem();
234 QToolButton *button = qobject_cast<QToolButton *>(sender());
237 ui->toolButtonTextLeft->blockSignals(
true);
238 ui->toolButtonTextCenter->blockSignals(
true);
239 ui->toolButtonTextRight->blockSignals(
true);
241 if (button ==
ui->toolButtonTextLeft)
245 curLine->setTextAlignment(Qt::AlignLeft);
247 ui->toolButtonTextCenter->setChecked(
false);
248 ui->toolButtonTextRight->setChecked(
false);
252 button->setChecked(
true);
255 else if (button ==
ui->toolButtonTextCenter)
259 curLine->setTextAlignment(Qt::AlignHCenter);
261 ui->toolButtonTextLeft->setChecked(
false);
262 ui->toolButtonTextRight->setChecked(
false);
266 button->setChecked(
true);
269 else if (button ==
ui->toolButtonTextRight)
273 curLine->setTextAlignment(Qt::AlignRight);
275 ui->toolButtonTextCenter->setChecked(
false);
276 ui->toolButtonTextRight->setChecked(
false);
280 button->setChecked(
true);
284 ui->toolButtonTextLeft->blockSignals(
false);
285 ui->toolButtonTextCenter->blockSignals(
false);
286 ui->toolButtonTextRight->blockSignals(
false);
294 if (
ui->listWidgetEdit->count() > 0)
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)
306 ui->listWidgetEdit->blockSignals(
true);
307 ui->listWidgetEdit->clear();
308 ui->listWidgetEdit->blockSignals(
false);
315 QString filters(tr(
"Label template") + QLatin1String(
"(*.xml)"));
316 QString dir =
qApp->Settings()->GetPathLabelTemplate();
318 bool usedNotExistedDir =
false;
320 if (not directory.exists())
322 usedNotExistedDir = directory.mkpath(
".");
325 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Export label template"),
326 dir + QLatin1String(
"/") + tr(
"template") + QLatin1String(
".xml"),
327 filters,
nullptr, QFileDialog::DontUseNativeDialog);
329 auto RemoveTempDir = [usedNotExistedDir, dir]()
331 if (usedNotExistedDir)
334 directory.rmpath(
".");
338 if (fileName.isEmpty())
344 QFileInfo f( fileName );
345 if (f.suffix().isEmpty() && f.suffix() != QLatin1String(
"xml"))
347 fileName += QLatin1String(
".xml");
355 const bool result = ltemplate.
SaveDocument(fileName, error);
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);
373 if (
ui->listWidgetEdit->count() > 0)
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)
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())
402 qCritical(
"%s\n\n%s\n\n%s", qUtf8Printable(tr(
"File error.")), qUtf8Printable(e.
ErrorMessage()),
410 QAction *action = qobject_cast<QAction *>(sender());
413 ui->lineEditLine->insert(action->data().toString());
414 ui->lineEditLine->setFocus();
421 if (index ==
ui->tabWidget->indexOf(
ui->tabPreview))
423 ui->toolButtonNewLabel->setDisabled(
true);
424 ui->toolButtonImportLabel->setDisabled(
true);
429 ui->toolButtonNewLabel->setEnabled(
ui->listWidgetEdit->count() > 0);
430 ui->toolButtonImportLabel->setEnabled(
true);
437 QListWidgetItem *curLine =
ui->listWidgetEdit->currentItem();
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);
450 const bool enabled =
ui->listWidgetEdit->count() > 0;
454 ui->lineEditLine->blockSignals(
true);
455 ui->lineEditLine->clear();
456 ui->lineEditLine->blockSignals(
false);
459 ui->toolButtonAdd->setEnabled(
true);
460 ui->toolButtonImportLabel->setEnabled(
true);
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);
482 auto value = i.value();
484 action->setData(per +
qApp->TrVars()->PlaceholderToUser(i.key()) + per);
494 QLocale locale(
qApp->Settings()->GetLocale());
509 const QString patternFilePath = QFileInfo(
qApp->getFilePath()).baseName();
512 const QString measurementsFilePath = QFileInfo(
m_doc->
MPath()).baseName();
558 line.replace(QChar(
'%')+i.key()+QChar(
'%'), i.value().second);
569 for (
int i=0; i<
ui->listWidgetEdit->count(); ++i)
571 const QListWidgetItem *lineItem =
ui->listWidgetEdit->item(i);
575 line.
line =
qApp->TrVars()->PlaceholderFromUserText(lineItem->text());
576 line.
alignment = lineItem->textAlignment();
579 const QFont font = lineItem->font();
580 line.
bold = font.bold();
581 line.
italic = font.italic();
593 ui->listWidgetEdit->blockSignals(
true);
594 ui->listWidgetEdit->clear();
598 for (
int i=0; i<lines.size(); ++i)
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);
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);
610 ui->listWidgetEdit->insertItem(++row, item);
613 ui->listWidgetEdit->blockSignals(
false);
615 if (
ui->listWidgetEdit->count() > 0)
617 ui->listWidgetEdit->setCurrentRow(0);
642 ui->listWidgetPreview->clear();
646 for (
int i=0; i<lines.size(); ++i)
649 item->setTextAlignment(lines.at(i).alignment);
650 item->setData(Qt::UserRole, lines.at(i).fontSizeIncrement);
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);
658 ui->listWidgetPreview->insertItem(++row, item);
661 if (
ui->listWidgetPreview->count() > 0)
663 ui->listWidgetPreview->setCurrentRow(0);
void SaveTextFormating(bool checked)
void SetTemplate(const QVector< VLabelTemplateLine > &lines)
QVector< VLabelTemplateLine > GetTemplate() const
Ui::EditLabelTemplateDialog * ui
void SetPiece(const VPiece &piece)
void InitPreviewLines(const QVector< VLabelTemplateLine > &lines)
void TabChanged(int index)
QMap< QString, QPair< QString, QString > > m_placeholders
void InitPlaceholdersMenu()
void SaveFontStyle(bool checked)
virtual ~EditLabelTemplateDialog()
QMenu * m_placeholdersMenu
void SaveLineText(const QString &text)
QString ReplacePlaceholders(QString line) const
EditLabelTemplateDialog(VAbstractPattern *doc, QWidget *parent=nullptr)
void SaveAdditionalFontSize(int i)
QString GetCompanyName() const
QString GetLabelDateFormat() const
QString GetPatternName() const
QString GetPatternNumber() const
QString GetCustomerName() const
QString GetLabelTimeFormat() const
static qreal height()
height return height
static qreal size()
size return size
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.
virtual QString ErrorMessage() const
ErrorMessage return main error message.
virtual QString DetailedInformation() const
DetailedInformation return detailed information about error.
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
QString GetRotationWay() const
QString GetAnnotation() const
QString GetLetter() const
QString GetFoldPosition() const
VPieceLabelData & GetPatternPieceData()
Returns full access to the pattern piece data object.
const QString pl_customer
const QString pl_pFoldPosition
const QString pl_pQuantity
const QString pl_mFileName
const QString pl_patternName
const QString pl_pAnnotation
const QString pl_patternNumber
const QString pl_pFileName
const QString pl_mInterfacing
const QString pl_pOrientation
const QString pl_pRotation
const QString pl_mInterlining