diff --git a/dist/OBS_debian/debian.valentina.dirs b/dist/OBS_debian/debian.valentina.dirs index 4d8be8137..bd0bdc98e 100644 --- a/dist/OBS_debian/debian.valentina.dirs +++ b/dist/OBS_debian/debian.valentina.dirs @@ -2,6 +2,7 @@ /usr/share/valentina/translations /usr/share/valentina/tables/multisize /usr/share/valentina/tables/templates +/usr/share/valentina/labels /usr/share/mime/packages /usr/share/applications diff --git a/dist/OBS_debian/debian.valentina.install b/dist/OBS_debian/debian.valentina.install index d0f0eebc6..c2c52fea9 100644 --- a/dist/OBS_debian/debian.valentina.install +++ b/dist/OBS_debian/debian.valentina.install @@ -4,5 +4,6 @@ usr/share/valentina/* usr/share/valentina/translations/* usr/share/valentina/tables/multisize/* usr/share/valentina/tables/templates/* +usr/share/valentina/labels/* usr/share/pixmaps/* usr/share/applications/* diff --git a/dist/OBS_debian/debian.valentina.sharedmimeinfo b/dist/OBS_debian/debian.valentina.sharedmimeinfo index 00f1b4197..41bb06377 100644 --- a/dist/OBS_debian/debian.valentina.sharedmimeinfo +++ b/dist/OBS_debian/debian.valentina.sharedmimeinfo @@ -76,8 +76,8 @@ Valentina pattern Valentina pattern Valentina pattern - OValentina pattern - OValentina pattern + Valentina pattern + Valentina pattern Valentina pattern Valentina pattern Valentina pattern @@ -170,8 +170,8 @@ Valentina individual measurments Valentina individual measurments Valentina individual measurments - OValentina individual measurments - OValentina individual measurments + Valentina individual measurments + Valentina individual measurments Valentina individual measurments Valentina individual measurments Valentina individual measurments @@ -264,8 +264,8 @@ Valentina standard measurments Valentina standard measurments Valentina standard measurments - OValentina standard measurments - OValentina standard measurments + Valentina standard measurments + Valentina standard measurments Valentina standard measurments Valentina standard measurments Valentina standard measurments diff --git a/dist/debian/valentina.dirs b/dist/debian/valentina.dirs index 4d8be8137..bd0bdc98e 100644 --- a/dist/debian/valentina.dirs +++ b/dist/debian/valentina.dirs @@ -2,6 +2,7 @@ /usr/share/valentina/translations /usr/share/valentina/tables/multisize /usr/share/valentina/tables/templates +/usr/share/valentina/labels /usr/share/mime/packages /usr/share/applications diff --git a/dist/debian/valentina.install b/dist/debian/valentina.install index d0f0eebc6..c2c52fea9 100644 --- a/dist/debian/valentina.install +++ b/dist/debian/valentina.install @@ -4,5 +4,6 @@ usr/share/valentina/* usr/share/valentina/translations/* usr/share/valentina/tables/multisize/* usr/share/valentina/tables/templates/* +usr/share/valentina/labels/* usr/share/pixmaps/* usr/share/applications/* diff --git a/dist/debian/valentina.sharedmimeinfo b/dist/debian/valentina.sharedmimeinfo index 00f1b4197..41bb06377 100644 --- a/dist/debian/valentina.sharedmimeinfo +++ b/dist/debian/valentina.sharedmimeinfo @@ -76,8 +76,8 @@ Valentina pattern Valentina pattern Valentina pattern - OValentina pattern - OValentina pattern + Valentina pattern + Valentina pattern Valentina pattern Valentina pattern Valentina pattern @@ -170,8 +170,8 @@ Valentina individual measurments Valentina individual measurments Valentina individual measurments - OValentina individual measurments - OValentina individual measurments + Valentina individual measurments + Valentina individual measurments Valentina individual measurments Valentina individual measurments Valentina individual measurments @@ -264,8 +264,8 @@ Valentina standard measurments Valentina standard measurments Valentina standard measurments - OValentina standard measurments - OValentina standard measurments + Valentina standard measurments + Valentina standard measurments Valentina standard measurments Valentina standard measurments Valentina standard measurments diff --git a/dist/rpm/valentina.spec b/dist/rpm/valentina.spec index 707fa70e2..2bfe1fcaa 100644 --- a/dist/rpm/valentina.spec +++ b/dist/rpm/valentina.spec @@ -154,6 +154,8 @@ fi %{_datadir}/%{name}/tables/multisize/*.vst %dir %{_datadir}/%{name}/tables/templates %{_datadir}/%{name}/tables/templates/*.vit +%dir %{_datadir}/%{name}/labels +%{_datadir}/%{name}/labels/*.xml %clean rm -f dist/debian/%{name}.1.gz dist/debian/tape.1.gz dist/debian/%{name}.xml dist/debian/%{name} diff --git a/dist/win/inno/valentina.iss b/dist/win/inno/valentina.iss index 420ddf34a..88e8cec89 100644 --- a/dist/win/inno/valentina.iss +++ b/dist/win/inno/valentina.iss @@ -213,6 +213,7 @@ Source: ".\valentina\iconengines\*"; DestDir: "{app}\iconengines"; Flags: recurs Source: ".\valentina\platforms\*"; DestDir: "{app}\platforms"; Flags: recursesubdirs createallsubdirs Source: ".\valentina\printsupport\*"; DestDir: "{app}\printsupport"; Flags: recursesubdirs createallsubdirs Source: ".\valentina\tables\*"; DestDir: "{app}\tables"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: ".\valentina\labels\*"; DestDir: "{app}\labels"; Flags: ignoreversion recursesubdirs createallsubdirs Source: ".\valentina\*.exe"; DestDir: "{app}"; Flags: ignoreversion Source: ".\valentina\*.dll"; DestDir: "{app}" Source: ".\valentina\*.txt"; DestDir: "{app}"; Flags: ignoreversion diff --git a/src/app/share/labels/def_pattern_label.xml b/src/app/share/labels/def_pattern_label.xml new file mode 100644 index 000000000..a3d78f539 --- /dev/null +++ b/src/app/share/labels/def_pattern_label.xml @@ -0,0 +1,11 @@ + + diff --git a/src/app/share/labels/def_piece_label.xml b/src/app/share/labels/def_piece_label.xml new file mode 100644 index 000000000..a80afc06c --- /dev/null +++ b/src/app/share/labels/def_piece_label.xml @@ -0,0 +1,9 @@ + + diff --git a/src/app/tables.pri b/src/app/tables.pri index e5e059b62..c085206f8 100644 --- a/src/app/tables.pri +++ b/src/app/tables.pri @@ -6,4 +6,9 @@ INSTALL_STANDARD_TEMPLATES += \ $$PWD/share/tables/templates/template_all_measurements.vit \ $$PWD/share/tables/templates/t_Aldrich_Women.vit +# Keep path to all label templates we provide right now +INSTALL_LABEL_TEMPLATES += $$PWD/share/labels/def_pattern_label.xml \ + $$PWD/share/labels/def_piece_label.xml + copyToDestdir($$INSTALL_MULTISIZE_MEASUREMENTS, $$shell_path($${OUT_PWD}/$$DESTDIR/tables/multisize)) +copyToDestdir($$INSTALL_LABEL_TEMPLATES, $$shell_path($${OUT_PWD}/$$DESTDIR/labels)) diff --git a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp index 9e0926409..c1cb7ff4d 100644 --- a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp @@ -63,6 +63,7 @@ void PreferencesPathPage::Apply() settings->SetPathPattern(ui->pathTable->item(2, 1)->text()); settings->SetPathLayout(ui->pathTable->item(3, 1)->text()); settings->SetPathTemplate(ui->pathTable->item(4, 1)->text()); + settings->SetPathLabelTemplate(ui->pathTable->item(5, 1)->text()); } //--------------------------------------------------------------------------------------------------------------------- @@ -91,6 +92,9 @@ void PreferencesPathPage::DefaultPath() case 4: // templates path = VCommonSettings::GetDefPathTemplate(); break; + case 5: // label templates + path = VSettings::GetDefPathLabelTemplate(); + break; default: break; } @@ -125,6 +129,9 @@ void PreferencesPathPage::EditPath() case 4: // templates path = qApp->ValentinaSettings()->GetPathTemplate(); break; + case 5: // label templates + path = qApp->ValentinaSettings()->GetPathLabelTemplate(); + break; default: break; } @@ -164,7 +171,7 @@ void PreferencesPathPage::EditPath() //--------------------------------------------------------------------------------------------------------------------- void PreferencesPathPage::InitTable() { - ui->pathTable->setRowCount(5); + ui->pathTable->setRowCount(6); ui->pathTable->setColumnCount(2); const VSettings *settings = qApp->ValentinaSettings(); @@ -204,6 +211,13 @@ void PreferencesPathPage::InitTable() ui->pathTable->setItem(4, 1, item); } + { + ui->pathTable->setItem(5, 0, new QTableWidgetItem(tr("My label templates"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathLabelTemplate()); + item->setToolTip(settings->GetPathLabelTemplate()); + ui->pathTable->setItem(5, 1, item); + } + ui->pathTable->verticalHeader()->setDefaultSectionSize(20); ui->pathTable->resizeColumnsToContents(); ui->pathTable->resizeRowsToContents(); diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp index 2b3f5e632..fcfc633cc 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp @@ -30,8 +30,27 @@ #include "ui_preferencespatternpage.h" #include "../../core/vapplication.h" #include "../ifc/xml/vabstractpattern.h" +#include "../dialogdatetimeformats.h" #include +#include +#include + +namespace +{ +QStringList ComboBoxAllStrings(QComboBox *combo) +{ + SCASSERT(combo != nullptr) + + QStringList itemsInComboBox; + for (int index = 0; index < combo->count(); ++index) + { + itemsInComboBox << combo->itemText(index); + } + + return itemsInComboBox; +} +} //--------------------------------------------------------------------------------------------------------------------- PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) @@ -39,20 +58,11 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) ui(new Ui::PreferencesPatternPage) { ui->setupUi(this); - ui->userName->setText(qApp->ValentinaSettings()->GetUser()); ui->graphOutputCheck->setChecked(qApp->ValentinaSettings()->GetGraphicalOutput()); ui->undoCount->setValue(qApp->ValentinaSettings()->GetUndoCount()); - connect(ui->userMaterialClearButton, &QPushButton::clicked, this, [this]() - { - VSettings* pSet = qApp->ValentinaSettings(); - pSet->ClearUserDefinedMaterial(); - pSet->sync(); - QString qsMsg = tr("All user defined materials have been deleted!"); - QMessageBox::information(this, QCoreApplication::applicationName(), qsMsg); - }); - InitDefaultSeamAllowance(); + InitLabelDateTimeFormats(); ui->forbidFlippingCheck->setChecked(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping()); ui->doublePassmarkCheck->setChecked(qApp->ValentinaSettings()->IsDoublePassmark()); @@ -70,7 +80,6 @@ PreferencesPatternPage::~PreferencesPatternPage() void PreferencesPatternPage::Apply() { VSettings *settings = qApp->ValentinaSettings(); - settings->SetUser(ui->userName->text()); // Scene antialiasing settings->SetGraphicalOutput(ui->graphOutputCheck->isChecked()); @@ -86,13 +95,19 @@ void PreferencesPatternPage::Apply() settings->SetForbidWorkpieceFlipping(ui->forbidFlippingCheck->isChecked()); settings->SetHideMainPath(ui->checkBoxHideMainPath->isChecked()); - qApp->ValentinaSettings()->SetLabelFont(ui->fontComboBoxLabelFont->currentFont()); + settings->SetLabelFont(ui->fontComboBoxLabelFont->currentFont()); if (settings->IsDoublePassmark() != ui->doublePassmarkCheck->isChecked()) { settings->SetDoublePassmark(ui->doublePassmarkCheck->isChecked()); qApp->getCurrentDocument()->LiteParseTree(Document::LiteParse); } + + settings->SetLabelDateFormat(ui->comboBoxDateFormats->currentText()); + settings->SetLabelTimeFormat(ui->comboBoxTimeFormats->currentText()); + + settings->SetUserDefinedDateFormats(ComboBoxAllStrings(ui->comboBoxDateFormats)); + settings->SetUserDefinedTimeFormats(ComboBoxAllStrings(ui->comboBoxTimeFormats)); } //--------------------------------------------------------------------------------------------------------------------- @@ -101,3 +116,81 @@ void PreferencesPatternPage::InitDefaultSeamAllowance() ui->defaultSeamAllowance->setValue(qApp->ValentinaSettings()->GetDefaultSeamAllowance()); ui->defaultSeamAllowance->setSuffix(UnitsToStr(StrToUnits(qApp->ValentinaSettings()->GetUnit()), true)); } + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesPatternPage::EditDateTimeFormats() +{ + VSettings *settings = qApp->ValentinaSettings(); + + QPushButton *button = qobject_cast(sender()); + if (button == ui->pushButtonEditDateFormats) + { + CallDateTimeFormatEditor(QDate::currentDate(), settings->PredefinedDateFormats(), + settings->GetUserDefinedDateFormats(), ui->comboBoxDateFormats); + } + else if (button == ui->pushButtonEditTimeFormats) + { + CallDateTimeFormatEditor(QTime::currentTime(), settings->PredefinedTimeFormats(), + settings->GetUserDefinedTimeFormats(), ui->comboBoxTimeFormats); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesPatternPage::InitLabelDateTimeFormats() +{ + VSettings *settings = qApp->ValentinaSettings(); + + InitComboBoxFormats(ui->comboBoxDateFormats, + VSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(), + settings->GetLabelDateFormat()); + InitComboBoxFormats(ui->comboBoxTimeFormats, + VSettings::PredefinedTimeFormats() + settings->GetUserDefinedTimeFormats(), + settings->GetLabelTimeFormat()); + + connect(ui->pushButtonEditDateFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats); + connect(ui->pushButtonEditTimeFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PreferencesPatternPage::InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString ¤tFormat) +{ + SCASSERT(box != nullptr) + + box->addItems(items); + int index = box->findText(currentFormat); + if (index != -1) + { + box->setCurrentIndex(index); + } + else + { + box->setCurrentIndex(0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void PreferencesPatternPage::CallDateTimeFormatEditor(const T &type, const QStringList &predefinedFormats, + const QStringList &userDefinedFormats, QComboBox *box) +{ + SCASSERT(box != nullptr) + + DialogDateTimeFormats dialog(type, predefinedFormats, userDefinedFormats); + + if (QDialog::Accepted == dialog.exec()) + { + const QString currentFormat = box->currentText(); + box->clear(); + box->addItems(dialog.GetFormats()); + + int index = box->findText(currentFormat); + if (index != -1) + { + box->setCurrentIndex(index); + } + else + { + box->setCurrentIndex(0); + } + } +} diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.h b/src/app/valentina/dialogs/configpages/preferencespatternpage.h index 7d82c316d..c13ec1baa 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.h +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.h @@ -36,6 +36,8 @@ namespace Ui class PreferencesPatternPage; } +class QComboBox; + class PreferencesPatternPage : public QWidget { Q_OBJECT @@ -47,9 +49,19 @@ public: void Apply(); void InitDefaultSeamAllowance(); +private slots: + void EditDateTimeFormats(); + private: Q_DISABLE_COPY(PreferencesPatternPage) Ui::PreferencesPatternPage *ui; + + void InitLabelDateTimeFormats(); + void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString ¤tFormat); + + template + void CallDateTimeFormatEditor(const T &type, const QStringList &predefinedFormats, + const QStringList &userDefinedFormats, QComboBox *box); }; #endif // PREFERENCESPATTERNPAGE_H diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.ui b/src/app/valentina/dialogs/configpages/preferencespatternpage.ui index 461ef356a..957a4ce9e 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.ui +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.ui @@ -7,36 +7,13 @@ 0 0 381 - 444 + 705 Pattern - - - - User - - - - - - User name: - - - - - - - true - - - - - - @@ -75,28 +52,6 @@ - - - - User defined materials - - - - - - - 0 - 0 - - - - Delete all - - - - - - @@ -182,6 +137,60 @@ + + + + Label data/time format + + + + QFormLayout::ExpandingFieldsGrow + + + + + Date: + + + + + + + + + + + + Edit formats + + + + + + + + + Time: + + + + + + + + + + + + Edit formats + + + + + + + + diff --git a/src/app/valentina/dialogs/dialogdatetimeformats.cpp b/src/app/valentina/dialogs/dialogdatetimeformats.cpp new file mode 100644 index 000000000..3cdd9b2e2 --- /dev/null +++ b/src/app/valentina/dialogs/dialogdatetimeformats.cpp @@ -0,0 +1,218 @@ +/************************************************************************ + ** + ** @file dialogdatetimeformats.cpp + ** @author Roman Telezhynskyi + ** @date 19 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogdatetimeformats.h" +#include "ui_dialogdatetimeformats.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogDateTimeFormats::DialogDateTimeFormats(const QDate &date, const QStringList &predefinedFormats, + const QStringList &userDefinedFormats, QWidget *parent) + : QDialog(parent), + ui(new Ui::DialogDateTimeFormats), + m_dateMode(true), + m_date(date), + m_time(), + m_predefined(predefinedFormats) +{ + ui->setupUi(this); + + Init(predefinedFormats, userDefinedFormats); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogDateTimeFormats::DialogDateTimeFormats(const QTime &time, const QStringList &predefinedFormats, + const QStringList &userDefinedFormats, QWidget *parent) + : QDialog(parent), + ui(new Ui::DialogDateTimeFormats), + m_dateMode(false), + m_date(), + m_time(time), + m_predefined(predefinedFormats) +{ + ui->setupUi(this); + + Init(predefinedFormats, userDefinedFormats); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogDateTimeFormats::~DialogDateTimeFormats() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList DialogDateTimeFormats::GetFormats() const +{ + QStringList formats; + + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *lineItem = ui->listWidget->item(i)) + { + const QString format = lineItem->data(Qt::UserRole).toString(); + if (not format.isEmpty()) + { + formats.append(lineItem->data(Qt::UserRole).toString()); + } + } + } + + return formats; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDateTimeFormats::AddLine() +{ + int row = ui->listWidget->count(); + ui->listWidget->insertItem(++row, new QListWidgetItem(tr(""))); + ui->listWidget->setCurrentRow(row); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDateTimeFormats::RemoveLine() +{ + ui->listWidget->blockSignals(true); + if (QListWidgetItem *curLine = ui->listWidget->currentItem()) + { + if (not m_predefined.contains(curLine->data(Qt::UserRole).toString())) + { + delete ui->listWidget->takeItem(ui->listWidget->currentRow()); + } + } + ui->listWidget->blockSignals(false); + ShowFormatDetails(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDateTimeFormats::SaveFormat(const QString &text) +{ + if (QListWidgetItem *curLine = ui->listWidget->currentItem()) + { + if (not GetFormats().contains(text)) + { + const QString preview = m_dateMode ? m_date.toString(text) : m_time.toString(text); + curLine->setText(preview); + curLine->setData(Qt::UserRole, text); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDateTimeFormats::ShowFormatDetails() +{ + if (ui->listWidget->count() > 0) + { + if (const QListWidgetItem *line = ui->listWidget->currentItem()) + { + ui->lineEditFormat->blockSignals(true); + ui->lineEditFormat->setText(line->data(Qt::UserRole).toString()); + ui->lineEditFormat->blockSignals(false); + } + } + + SetupControls(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDateTimeFormats::Init(const QStringList &predefined, const QStringList &userDefined) +{ + SetFormatLines(predefined, userDefined); + + ui->lineEditFormat->setClearButtonEnabled(true); + + connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogDateTimeFormats::RemoveLine); + connect(ui->toolButtonAdd, &QToolButton::clicked, this, &DialogDateTimeFormats::AddLine); + connect(ui->lineEditFormat, &QLineEdit::textEdited, this, &DialogDateTimeFormats::SaveFormat); + connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogDateTimeFormats::ShowFormatDetails); + + ui->listWidget->setCurrentRow(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDateTimeFormats::SetFormatLines(const QStringList &predefined, const QStringList &userDefined) +{ + ui->listWidget->blockSignals(true); + ui->listWidget->clear(); + + int row = -1; + + for (int i=0; ilistWidget->insertItem(++row, AddListLine(predefined.at(i))); + } + + for (int i=0; ilistWidget->insertItem(++row, AddListLine(userDefined.at(i))); + } + + ui->listWidget->blockSignals(false); + + if (ui->listWidget->count() > 0) + { + ui->listWidget->setCurrentRow(0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDateTimeFormats::SetupControls() +{ + const bool enabled = ui->listWidget->count() > 0; + + if (not enabled) + { + ui->lineEditFormat->blockSignals(true); + ui->lineEditFormat->clear(); + ui->lineEditFormat->blockSignals(false); + } + + ui->toolButtonAdd->setEnabled(true); + + ui->lineEditFormat->setEnabled(enabled); + + const QListWidgetItem *line = ui->listWidget->currentItem(); + if (line != nullptr && m_predefined.contains(line->data(Qt::UserRole).toString())) + { + ui->toolButtonRemove->setEnabled(false); + ui->lineEditFormat->setReadOnly(true); + } + else + { + ui->toolButtonRemove->setEnabled(enabled); + ui->lineEditFormat->setReadOnly(false); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QListWidgetItem *DialogDateTimeFormats::AddListLine(const QString &format) +{ + const QString preview = m_dateMode ? m_date.toString(format) : m_time.toString(format); + QListWidgetItem *item = new QListWidgetItem(preview); + item->setData(Qt::UserRole, format); + return item; +} diff --git a/src/app/valentina/dialogs/dialogdatetimeformats.h b/src/app/valentina/dialogs/dialogdatetimeformats.h new file mode 100644 index 000000000..46706fd0e --- /dev/null +++ b/src/app/valentina/dialogs/dialogdatetimeformats.h @@ -0,0 +1,79 @@ +/************************************************************************ + ** + ** @file dialogdatetimeformats.h + ** @author Roman Telezhynskyi + ** @date 19 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGDATETIMEFORMATS_H +#define DIALOGDATETIMEFORMATS_H + +#include +#include +#include + +namespace Ui +{ + class DialogDateTimeFormats; +} + +class QListWidgetItem; + +class DialogDateTimeFormats : public QDialog +{ + Q_OBJECT + +public: + DialogDateTimeFormats(const QDate &date, const QStringList &predefinedFormats, + const QStringList &userDefinedFormats, QWidget *parent = nullptr); + DialogDateTimeFormats(const QTime &time, const QStringList &predefinedFormats, + const QStringList &userDefinedFormats, QWidget *parent = nullptr); + virtual ~DialogDateTimeFormats(); + + QStringList GetFormats() const; + +private slots: + void AddLine(); + void RemoveLine(); + void SaveFormat(const QString &text); + void ShowFormatDetails(); + +private: + Q_DISABLE_COPY(DialogDateTimeFormats) + Ui::DialogDateTimeFormats *ui; + bool m_dateMode; + QDate m_date; + QTime m_time; + QStringList m_predefined; + + void Init(const QStringList &predefined, const QStringList &userDefined); + void SetFormatLines(const QStringList &predefined, const QStringList &userDefined); + void SetupControls(); + + bool IsPredefined() const; + + QListWidgetItem *AddListLine(const QString &format); +}; + +#endif // DIALOGDATETIMEFORMATS_H diff --git a/src/app/valentina/dialogs/dialogdatetimeformats.ui b/src/app/valentina/dialogs/dialogdatetimeformats.ui new file mode 100644 index 000000000..6fa90abf0 --- /dev/null +++ b/src/app/valentina/dialogs/dialogdatetimeformats.ui @@ -0,0 +1,125 @@ + + + DialogDateTimeFormats + + + + 0 + 0 + 393 + 381 + + + + Label date time editor + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + + + Format: + + + + + + + false + + + + + + Insert a format + + + + + + + false + + + Add + + + + .. + + + + + + + false + + + Remove + + + + .. + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogDateTimeFormats + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogDateTimeFormats + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 11078857d..94f82808d 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -33,9 +33,12 @@ #include #include #include +#include + #include "../xml/vpattern.h" #include "../vpatterndb/vcontainer.h" #include "../core/vapplication.h" +#include "../vtools/dialogs/support/dialogeditlabel.h" // calc how many combinations we have static const int heightsCount = (static_cast(GHeights::H200) - @@ -43,8 +46,7 @@ static const int heightsCount = (static_cast(GHeights::H200) - static const int sizesCount = (static_cast(GSizes::S72) - (static_cast(GSizes::S22) - sizeStep))/sizeStep; //--------------------------------------------------------------------------------------------------------------------- -DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPattern *doc, VContainer *pattern, - QWidget *parent) +DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent) : QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), @@ -58,22 +60,23 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte gradationChanged(false), defaultChanged(false), securityChanged(false), - generalInfoChanged(false), + labelDataChanged(false), + askSaveLabelData(false), + templateDataChanged(false), deleteAction(nullptr), changeImageAction(nullptr), saveImageAction(nullptr), showImageAction(nullptr), - m_filePath(filePath) + templateLines() { ui->setupUi(this); - ui->lineEditAuthor->setClearButtonEnabled(true); - SCASSERT(doc != nullptr) - qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + VSettings *settings = qApp->ValentinaSettings(); + settings->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); - if (m_filePath.isEmpty()) + if (qApp->GetPPath().isEmpty()) { ui->lineEditPathToFile->setText(tr("")); ui->lineEditPathToFile->setToolTip(tr("File was not saved yet.")); @@ -81,23 +84,20 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte } else { - ui->lineEditPathToFile->setText(QDir::toNativeSeparators(m_filePath)); - ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(m_filePath)); + ui->lineEditPathToFile->setText(QDir::toNativeSeparators(qApp->GetPPath())); + ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(qApp->GetPPath())); ui->pushButtonShowInExplorer->setEnabled(true); } ui->lineEditPathToFile->setCursorPosition(0); connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, this, [this]() { - ShowInGraphicalShell(m_filePath); + ShowInGraphicalShell(qApp->GetPPath()); }); #if defined(Q_OS_MAC) ui->pushButtonShowInExplorer->setText(tr("Show in Finder")); #endif //defined(Q_OS_MAC) - ui->lineEditAuthor->setText(doc->GetAuthor()); - connect(ui->lineEditAuthor, &QLineEdit::editingFinished, this, &DialogPatternProperties::DescEdited); - ui->plainTextEditDescription->setPlainText(doc->GetDescription()); connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited); @@ -175,32 +175,24 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte ui->lineEditPatternNumber->setText(doc->GetPatternNumber()); ui->lineEditCompanyName->setText(doc->GetCompanyName()); ui->lineEditCustomerName->setText(doc->GetCustomerName()); - ui->checkBoxShowDate->setText(ui->checkBoxShowDate->text() - .arg(QDate::currentDate().toString(Qt::SystemLocaleLongDate))); - ui->lineEditSize->setText(doc->GetPatternSize()); - const QString plSize = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_size) + QLatin1String("%"); - const QString plHeight = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_height) + QLatin1String("%"); - ui->lineEditSize->setToolTip(tr("Use %1 and %2 to insert pattern size and height").arg(plSize, plHeight)); + connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); + connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); + connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); + connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); + connect(ui->pushButtonEditPatternLabel, &QPushButton::clicked, this, &DialogPatternProperties::EditLabel); - ui->checkBoxShowDate->setChecked(doc->IsDateVisible()); - if (doc->MPath().isEmpty() == true) - { - ui->checkBoxShowMeasurements->setChecked(false); - ui->checkBoxShowMeasurements->setEnabled(false); - } - else - { - ui->checkBoxShowMeasurements->setChecked(doc->IsMeasurementsVisible()); - } + InitComboBoxFormats(ui->comboBoxDateFormat, + VSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(), + doc->GetLabelDateFormat()); + InitComboBoxFormats(ui->comboBoxTimeFormat, + VSettings::PredefinedTimeFormats() + settings->GetUserDefinedTimeFormats(), + doc->GetLabelTimeFormat()); - connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); - connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); - connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); - connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); - connect(ui->lineEditSize, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); - connect(ui->checkBoxShowDate, &QCheckBox::stateChanged, this, &DialogPatternProperties::GeneralInfoChanged); - connect(ui->checkBoxShowMeasurements, &QCheckBox::stateChanged, this, &DialogPatternProperties::GeneralInfoChanged); + connect(ui->comboBoxDateFormat, static_cast(&QComboBox::currentIndexChanged), + this, &DialogPatternProperties::LabelDataChanged); + connect(ui->comboBoxTimeFormat, static_cast(&QComboBox::currentIndexChanged), + this, &DialogPatternProperties::LabelDataChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -216,27 +208,18 @@ void DialogPatternProperties::Apply() { case 0: SaveDescription(); - descriptionChanged = false; - emit doc->patternChanged(false); break; case 1: SaveGradation(); - gradationChanged = false; SaveDefValues(); - defaultChanged = false; - emit doc->patternChanged(false); break; case 2: - doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked()); - securityChanged = false; - emit doc->patternChanged(false); + SaveReadOnlyState(); break; case 3: - SaveGeneralInfo(); - generalInfoChanged = false; - emit doc->patternChanged(false); + SaveLabelData(); + SaveTemplateData(); break; - default: break; } @@ -245,40 +228,12 @@ void DialogPatternProperties::Apply() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::Ok() { - if (descriptionChanged) - { - SaveDescription(); - descriptionChanged = false; - emit doc->patternChanged(false); - } - - if (gradationChanged) - { - SaveGradation(); - gradationChanged = false; - emit doc->patternChanged(false); - } - - if (defaultChanged) - { - SaveDefValues(); - defaultChanged = false; - emit doc->patternChanged(false); - } - - if (securityChanged) - { - doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked()); - securityChanged = false; - emit doc->patternChanged(false); - } - - if (generalInfoChanged == true) - { - SaveGeneralInfo(); - generalInfoChanged = false; - emit doc->patternChanged(false); - } + SaveDescription(); + SaveGradation(); + SaveDefValues(); + SaveReadOnlyState(); + SaveLabelData(); + SaveTemplateData(); close(); } @@ -421,9 +376,10 @@ void DialogPatternProperties::DefValueChanged() } //--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::GeneralInfoChanged() +void DialogPatternProperties::LabelDataChanged() { - generalInfoChanged = true; + labelDataChanged = true; + askSaveLabelData = true; } //--------------------------------------------------------------------------------------------------------------------- @@ -554,6 +510,24 @@ void DialogPatternProperties::InitSizes() Init(ui->checkBoxS72, static_cast(GSizes::S72), &DialogPatternProperties::CheckStateSize); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::InitComboBoxFormats(QComboBox *box, const QStringList &items, + const QString ¤tFormat) +{ + SCASSERT(box != nullptr) + + box->addItems(items); + int index = box->findText(currentFormat); + if (index != -1) + { + box->setCurrentIndex(index); + } + else + { + box->setCurrentIndex(0); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::CheckApplyOk() { @@ -565,45 +539,90 @@ void DialogPatternProperties::CheckApplyOk() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SaveDescription() { - doc->SetNotes(ui->plainTextEditTechNotes->document()->toPlainText()); - doc->SetDescription(ui->plainTextEditDescription->document()->toPlainText()); - doc->SetAuthor(ui->lineEditAuthor->text()); + if (descriptionChanged) + { + doc->SetNotes(ui->plainTextEditTechNotes->document()->toPlainText()); + doc->SetDescription(ui->plainTextEditDescription->document()->toPlainText()); + + descriptionChanged = false; + emit doc->patternChanged(false); + emit doc->UpdatePatternLabel(); + } } //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SaveGradation() { - doc->SetGradationHeights(heights); - doc->SetGradationSizes(sizes); - emit UpdateGradation(); + if (gradationChanged) + { + doc->SetGradationHeights(heights); + doc->SetGradationSizes(sizes); + emit UpdateGradation(); + gradationChanged = false; + emit doc->patternChanged(false); + } } //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SaveDefValues() { - if (ui->radioButtonDefFromM->isChecked()) + if (defaultChanged) { - doc->SetDefCustom(false); + if (ui->radioButtonDefFromM->isChecked()) + { + doc->SetDefCustom(false); + } + else + { + doc->SetDefCustom(true); + doc->SetDefCustomHeight(ui->comboBoxHeight->currentText().toInt()); + doc->SetDefCustomSize(ui->comboBoxSize->currentText().toInt()); + } + defaultChanged = false; + emit doc->patternChanged(false); } - else - { - doc->SetDefCustom(true); - doc->SetDefCustomHeight(ui->comboBoxHeight->currentText().toInt()); - doc->SetDefCustomSize(ui->comboBoxSize->currentText().toInt()); - } - defaultChanged = false; } //--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::SaveGeneralInfo() +void DialogPatternProperties::SaveLabelData() { - doc->SetPatternName(ui->lineEditPatternName->text()); - doc->SetPatternNumber(ui->lineEditPatternNumber->text()); - doc->SetCompanyName(ui->lineEditCompanyName->text()); - doc->SetCustomerName(ui->lineEditCustomerName->text()); - doc->SetPatternSize(ui->lineEditSize->text()); - doc->SetDateVisible(ui->checkBoxShowDate->isChecked()); - doc->SetMesurementsVisible(ui->checkBoxShowMeasurements->isChecked()); + if (labelDataChanged) + { + doc->SetPatternName(ui->lineEditPatternName->text()); + doc->SetPatternNumber(ui->lineEditPatternNumber->text()); + doc->SetCompanyName(ui->lineEditCompanyName->text()); + doc->SetCustomerName(ui->lineEditCustomerName->text()); + doc->SetLabelDateFormat(ui->comboBoxDateFormat->currentText()); + doc->SetLabelTimeFormat(ui->comboBoxTimeFormat->currentText()); + + labelDataChanged = false; + askSaveLabelData = false; + emit doc->patternChanged(false); + emit doc->UpdatePatternLabel(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SaveTemplateData() +{ + if (templateDataChanged) + { + doc->SetPatternLabelTemplate(templateLines); + templateDataChanged = false; + emit doc->patternChanged(false); + emit doc->UpdatePatternLabel(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SaveReadOnlyState() +{ + if (securityChanged) + { + doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked()); + securityChanged = false; + emit doc->patternChanged(false); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -849,3 +868,33 @@ void DialogPatternProperties::SaveImage() } } } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::EditLabel() +{ + if (labelDataChanged && askSaveLabelData) + { + QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Save label data."), + tr("Label data were changed. Do you want to save them before editing label template?"), + QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); + + if (answer == QMessageBox::Yes) + { + SaveLabelData(); + } + else + { + askSaveLabelData = false; + } + } + + DialogEditLabel editor(doc); + + templateDataChanged ? editor.SetTemplate(templateLines) : editor.SetTemplate(doc->GetPatternLabelTemplate()); + + if (QDialog::Accepted == editor.exec()) + { + templateLines = editor.GetTemplate(); + templateDataChanged = true; + } +} diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index ecdfae10d..86df10310 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -33,6 +33,8 @@ #include "../options.h" #include +#include "../vformat/vlabeltemplate.h" + class VPattern; class VContainer; class QCheckBox; @@ -46,14 +48,13 @@ class DialogPatternProperties : public QDialog { Q_OBJECT public: - explicit DialogPatternProperties(const QString &filePath, VPattern *doc, VContainer *pattern, - QWidget *parent = nullptr); + explicit DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent = nullptr); virtual ~DialogPatternProperties() Q_DECL_OVERRIDE; signals: void UpdateGradation(); private slots: void DefValueChanged(); - void GeneralInfoChanged(); + void LabelDataChanged(); void Apply(); void Ok(); void SelectAll(int state); @@ -62,6 +63,7 @@ private slots: void DescEdited(); void ChangeImage(); void SaveImage(); + void EditLabel(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; @@ -76,12 +78,15 @@ private: bool gradationChanged; bool defaultChanged; bool securityChanged; - bool generalInfoChanged; + bool labelDataChanged; + bool askSaveLabelData; + bool templateDataChanged; QAction *deleteAction; QAction *changeImageAction; QAction *saveImageAction; QAction *showImageAction; - const QString &m_filePath; + + QVector templateLines; void SetHeightsChecked(bool enabled); void SetSizesChecked(bool enabled); @@ -93,11 +98,14 @@ private: void SetOptions(const QMap &option); template void InitComboBox(QComboBox *box, const QMap &option); + void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString ¤tFormat); void CheckApplyOk(); void SaveDescription(); void SaveGradation(); void SaveDefValues(); - void SaveGeneralInfo(); + void SaveLabelData(); + void SaveTemplateData(); + void SaveReadOnlyState(); void SetDefaultHeight(const QString &def); void SetDefaultSize(const QString &def); diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index eb98d5f2f..05fa7479f 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -6,7 +6,7 @@ 0 0 - 727 + 655 532 @@ -21,11 +21,11 @@ - 1 + 0 - Description + Pattern @@ -80,20 +80,6 @@ - - - - - - Author name - - - - - - - - @@ -183,7 +169,7 @@ - For technical notes. + For technical notes @@ -1205,95 +1191,135 @@ - General info + Label data - + - - - + + + - Pattern name: + Label template: - - - - 30 + + + + Edit pattern label - - - - - Pattern number: + Edit template - - - - 30 + + + + Qt::Horizontal - - - - - - Company/Designer name: + + + 40 + 20 + - - - - - - 30 - - - - - - - Customer name: - - - - - - - 30 - - - - - - - Pattern size: - - - - - - - 40 - - + - - - Show date of layout creation (%1) + + + + 0 + 1 + - - - - - - Show measurements file + + Label data + + + QFormLayout::ExpandingFieldsGrow + + + + + Pattern name: + + + + + + + 30 + + + + + + + Pattern number: + + + + + + + 30 + + + + + + + Company/Designer name: + + + + + + + 30 + + + + + + + Customer name: + + + + + + + 30 + + + + + + + Date format: + + + + + + + + + + Time format: + + + + + + + diff --git a/src/app/valentina/dialogs/dialogs.pri b/src/app/valentina/dialogs/dialogs.pri index 8599a928e..155d4041e 100644 --- a/src/app/valentina/dialogs/dialogs.pri +++ b/src/app/valentina/dialogs/dialogs.pri @@ -16,7 +16,8 @@ HEADERS += \ $$PWD/dialogpreferences.h \ $$PWD/configpages/preferencesconfigurationpage.h \ $$PWD/configpages/preferencespatternpage.h \ - $$PWD/configpages/preferencespathpage.h + $$PWD/configpages/preferencespathpage.h \ + $$PWD/dialogdatetimeformats.h SOURCES += \ $$PWD/dialogincrements.cpp \ @@ -32,7 +33,8 @@ SOURCES += \ $$PWD/dialogpreferences.cpp \ $$PWD/configpages/preferencesconfigurationpage.cpp \ $$PWD/configpages/preferencespatternpage.cpp \ - $$PWD/configpages/preferencespathpage.cpp + $$PWD/configpages/preferencespathpage.cpp \ + $$PWD/dialogdatetimeformats.cpp FORMS += \ $$PWD/dialogincrements.ui \ @@ -48,4 +50,5 @@ FORMS += \ $$PWD/dialogpreferences.ui \ $$PWD/configpages/preferencesconfigurationpage.ui \ $$PWD/configpages/preferencespatternpage.ui \ - $$PWD/configpages/preferencespathpage.ui + $$PWD/configpages/preferencespathpage.ui \ + $$PWD/dialogdatetimeformats.ui diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index a7e5984d2..e431ca71c 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -62,7 +62,9 @@ #include "../vtools/undocommands/addgroup.h" #include "dialogs/vwidgetdetails.h" #include "../vpatterndb/vpiecepath.h" +#include "../vpatterndb/measurements.h" #include "../qmuparser/qmuparsererror.h" +#include "../vtools/dialogs/support/dialogeditlabel.h" #include #include @@ -451,12 +453,6 @@ bool MainWindow::LoadMeasurements(const QString &path) return false; } - if (m->Type() == MeasurementsType::Multisize) - { - VContainer::SetSize(UnitConvertor(m->BaseSize(), m->MUnit(), *m->GetData()->GetPatternUnit())); - VContainer::SetHeight(UnitConvertor(m->BaseHeight(), m->MUnit(), *m->GetData()->GetPatternUnit())); - } - try { qApp->setPatternType(m->Type()); @@ -474,6 +470,18 @@ bool MainWindow::LoadMeasurements(const QString &path) } return false; } + + if (m->Type() == MeasurementsType::Multisize) + { + VContainer::SetSize(UnitConvertor(m->BaseSize(), m->MUnit(), *m->GetData()->GetPatternUnit())); + VContainer::SetHeight(UnitConvertor(m->BaseHeight(), m->MUnit(), *m->GetData()->GetPatternUnit())); + } + else if (m->Type() == MeasurementsType::Individual) + { + VContainer::SetSize(*pattern->DataVariables()->value(size_M)->GetValue()); + VContainer::SetHeight(*pattern->DataVariables()->value(height_M)->GetValue()); + } + return true; } @@ -497,12 +505,6 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) return false; } - if (m->Type() == MeasurementsType::Multisize) - { - VContainer::SetSize(size); - VContainer::SetHeight(height); - } - try { pattern->ClearVariables(VarType::Measurement); @@ -518,6 +520,18 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) } return false; } + + if (m->Type() == MeasurementsType::Multisize) + { + VContainer::SetSize(size); + VContainer::SetHeight(height); + } + else if (m->Type() == MeasurementsType::Individual) + { + VContainer::SetSize(*pattern->DataVariables()->value(size_M)->GetValue()); + VContainer::SetHeight(*pattern->DataVariables()->value(height_M)->GetValue()); + } + return true; } @@ -1519,10 +1533,10 @@ void MainWindow::LoadIndividual() { if (not doc->MPath().isEmpty()) { - watcher->removePath(AbsoluteMPath(curFile, doc->MPath())); + watcher->removePath(AbsoluteMPath(qApp->GetPPath(), doc->MPath())); } ui->actionUnloadMeasurements->setEnabled(true); - doc->SetPath(RelativeMPath(curFile, mPath)); + doc->SetMPath(RelativeMPath(qApp->GetPPath(), mPath)); watcher->addPath(mPath); PatternChangesWereSaved(false); ui->actionEditCurrent->setEnabled(true); @@ -1568,10 +1582,10 @@ void MainWindow::LoadMultisize() { if (not doc->MPath().isEmpty()) { - watcher->removePath(AbsoluteMPath(curFile, doc->MPath())); + watcher->removePath(AbsoluteMPath(qApp->GetPPath(), doc->MPath())); } ui->actionUnloadMeasurements->setEnabled(true); - doc->SetPath(RelativeMPath(curFile, mPath)); + doc->SetMPath(RelativeMPath(qApp->GetPPath(), mPath)); watcher->addPath(mPath); PatternChangesWereSaved(false); ui->actionEditCurrent->setEnabled(true); @@ -1607,8 +1621,13 @@ void MainWindow::UnloadMeasurements() if (doc->ListMeasurements().isEmpty()) { - watcher->removePath(AbsoluteMPath(curFile, doc->MPath())); - doc->SetPath(QString()); + watcher->removePath(AbsoluteMPath(qApp->GetPPath(), doc->MPath())); + if (qApp->patternType() == MeasurementsType::Multisize) + { + ToolBarOption(); + } + qApp->setPatternType(MeasurementsType::Unknown); + doc->SetMPath(QString()); PatternChangesWereSaved(false); ui->actionEditCurrent->setEnabled(false); ui->actionUnloadMeasurements->setDisabled(true); @@ -1628,7 +1647,7 @@ void MainWindow::ShowMeasurements() { if (not doc->MPath().isEmpty()) { - const QString absoluteMPath = AbsoluteMPath(curFile, doc->MPath()); + const QString absoluteMPath = AbsoluteMPath(qApp->GetPPath(), doc->MPath()); QStringList arguments; if (qApp->patternType() == MeasurementsType::Multisize) @@ -1700,7 +1719,7 @@ void MainWindow::SyncMeasurements() { if (mChanges) { - const QString path = AbsoluteMPath(curFile, doc->MPath()); + const QString path = AbsoluteMPath(qApp->GetPPath(), doc->MPath()); if(UpdateMeasurements(path, static_cast(VContainer::size()), static_cast(VContainer::height()))) { if (not watcher->files().contains(path)) @@ -2530,7 +2549,14 @@ bool MainWindow::SaveAs() { QString filters(tr("Pattern files") + QLatin1String("(*.val)")); QString dir; - curFile.isEmpty() ? dir = qApp->ValentinaSettings()->GetPathPattern() : dir = QFileInfo(curFile).absolutePath(); + if (qApp->GetPPath().isEmpty()) + { + dir = qApp->ValentinaSettings()->GetPathPattern(); + } + else + { + dir = QFileInfo(qApp->GetPPath()).absolutePath(); + } bool usedNotExistedDir = false; QDir directory(dir); @@ -2632,7 +2658,7 @@ bool MainWindow::SaveAs() */ bool MainWindow::Save() { - if (curFile.isEmpty() || patternReadOnly) + if (qApp->GetPPath().isEmpty() || patternReadOnly) { return SaveAs(); } @@ -2646,7 +2672,7 @@ bool MainWindow::Save() #ifdef Q_OS_WIN32 qt_ntfs_permission_lookup++; // turn checking on #endif /*Q_OS_WIN32*/ - const bool isFileWritable = QFileInfo(curFile).isWritable(); + const bool isFileWritable = QFileInfo(qApp->GetPPath()).isWritable(); #ifdef Q_OS_WIN32 qt_ntfs_permission_lookup--; // turn it off again #endif /*Q_OS_WIN32*/ @@ -2665,8 +2691,8 @@ bool MainWindow::Save() #ifdef Q_OS_WIN32 qt_ntfs_permission_lookup++; // turn checking on #endif /*Q_OS_WIN32*/ - bool changed = QFile::setPermissions(curFile, - QFileInfo(curFile).permissions() | QFileDevice::WriteUser); + bool changed = QFile::setPermissions(qApp->GetPPath(), + QFileInfo(qApp->GetPPath()).permissions() | QFileDevice::WriteUser); #ifdef Q_OS_WIN32 qt_ntfs_permission_lookup--; // turn it off again #endif /*Q_OS_WIN32*/ @@ -2675,7 +2701,7 @@ bool MainWindow::Save() { QMessageBox messageBox(this); messageBox.setIcon(QMessageBox::Warning); - messageBox.setText(tr("Cannot set permissions for %1 to writable.").arg(curFile)); + messageBox.setText(tr("Cannot set permissions for %1 to writable.").arg(qApp->GetPPath())); messageBox.setInformativeText(tr("Could not save the file.")); messageBox.setDefaultButton(QMessageBox::Ok); messageBox.setStandardButtons(QMessageBox::Ok); @@ -2690,10 +2716,10 @@ bool MainWindow::Save() } QString error; - bool result = SavePattern(curFile, error); + bool result = SavePattern(qApp->GetPPath(), error); if (result) { - QFile::remove(curFile + autosavePrefix); + QFile::remove(qApp->GetPPath() + autosavePrefix); m_curFileFormatVersion = VPatternConverter::PatternMaxVer; m_curFileFormatVersionStr = VPatternConverter::PatternMaxVerStr; } @@ -2754,9 +2780,9 @@ void MainWindow::Clear() qCDebug(vMainWindow, "Returned to Draw mode."); pattern->Clear(); qCDebug(vMainWindow, "Clearing pattern."); - if (not curFile.isEmpty() && not doc->MPath().isEmpty()) + if (not qApp->GetPPath().isEmpty() && not doc->MPath().isEmpty()) { - watcher->removePath(AbsoluteMPath(curFile, doc->MPath())); + watcher->removePath(AbsoluteMPath(qApp->GetPPath(), doc->MPath())); } doc->clear(); setCurrentFile(QString()); @@ -2807,16 +2833,16 @@ void MainWindow::FileClosedCorrect() //File was closed correct. QStringList restoreFiles = qApp->ValentinaSettings()->GetRestoreFileList(); - restoreFiles.removeAll(curFile); + restoreFiles.removeAll(qApp->GetPPath()); qApp->ValentinaSettings()->SetRestoreFileList(restoreFiles); // Remove autosave file - QFile autofile(curFile + autosavePrefix); + QFile autofile(qApp->GetPPath() + autosavePrefix); if (autofile.exists()) { autofile.remove(); } - qCDebug(vMainWindow, "File %s closed correct.", qUtf8Printable(curFile)); + qCDebug(vMainWindow, "File %s closed correct.", qUtf8Printable(qApp->GetPPath())); } //--------------------------------------------------------------------------------------------------------------------- @@ -3161,7 +3187,8 @@ void MainWindow::PatternChangesWereSaved(bool saved) void MainWindow::ChangedSize(const QString & text) { const int size = static_cast(VContainer::size()); - if (UpdateMeasurements(AbsoluteMPath(curFile, doc->MPath()), text.toInt(), static_cast(VContainer::height()))) + if (UpdateMeasurements(AbsoluteMPath(qApp->GetPPath(), doc->MPath()), text.toInt(), + static_cast(VContainer::height()))) { doc->LiteParseTree(Document::LiteParse); emit sceneDetails->DimensionsChanged(); @@ -3190,7 +3217,8 @@ void MainWindow::ChangedSize(const QString & text) void MainWindow::ChangedHeight(const QString &text) { const int height = static_cast(VContainer::height()); - if (UpdateMeasurements(AbsoluteMPath(curFile, doc->MPath()), static_cast(VContainer::size()), text.toInt())) + if (UpdateMeasurements(AbsoluteMPath(qApp->GetPPath(), doc->MPath()), static_cast(VContainer::size()), + text.toInt())) { doc->LiteParseTree(Document::LiteParse); emit sceneDetails->DimensionsChanged(); @@ -3374,10 +3402,10 @@ bool MainWindow::SavePattern(const QString &fileName, QString &error) qCDebug(vMainWindow, "Saving pattern file %s.", qUtf8Printable(fileName)); QFileInfo tempInfo(fileName); - const QString mPath = AbsoluteMPath(curFile, doc->MPath()); - if (not mPath.isEmpty() && curFile != fileName) + const QString mPath = AbsoluteMPath(qApp->GetPPath(), doc->MPath()); + if (not mPath.isEmpty() && qApp->GetPPath() != fileName) { - doc->SetPath(RelativeMPath(fileName, mPath)); + doc->SetMPath(RelativeMPath(fileName, mPath)); } const bool result = doc->SaveDocument(fileName, error); @@ -3393,7 +3421,7 @@ bool MainWindow::SavePattern(const QString &fileName, QString &error) } else { - doc->SetPath(mPath); + doc->SetMPath(mPath); qCDebug(vMainWindow, "Could not save file %s. %s.", qUtf8Printable(fileName), qUtf8Printable(error)); } return result; @@ -3407,9 +3435,9 @@ void MainWindow::AutoSavePattern() { qCDebug(vMainWindow, "Autosaving pattern."); - if (curFile.isEmpty() == false && this->isWindowModified() == true) + if (qApp->GetPPath().isEmpty() == false && this->isWindowModified() == true) { - QString autofile = curFile + autosavePrefix; + QString autofile = qApp->GetPPath() + autosavePrefix; QString error; SavePattern(autofile, error); } @@ -3424,10 +3452,11 @@ void MainWindow::AutoSavePattern() void MainWindow::setCurrentFile(const QString &fileName) { qCDebug(vMainWindow, "Set current name to \"%s\"", qUtf8Printable(fileName)); - curFile = fileName; + qApp->SetPPath(fileName); + emit doc->UpdatePatternLabel(); qApp->getUndoStack()->setClean(); - if (not curFile.isEmpty() && VApplication::IsGUIMode()) + if (not qApp->GetPPath().isEmpty() && VApplication::IsGUIMode()) { qCDebug(vMainWindow, "Updating recent file list."); VSettings *settings = qApp->ValentinaSettings(); @@ -3512,7 +3541,7 @@ bool MainWindow::MaybeSave() messageBox->setEscapeButton(QMessageBox::Cancel); messageBox->setButtonText(QMessageBox::Yes, - curFile.isEmpty() || patternReadOnly ? tr("Save...") : tr("Save")); + qApp->GetPPath().isEmpty() || patternReadOnly ? tr("Save...") : tr("Save")); messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); messageBox->setWindowModality(Qt::ApplicationModal); @@ -3849,7 +3878,7 @@ void MainWindow::InitDocksContain() //--------------------------------------------------------------------------------------------------------------------- bool MainWindow::OpenNewValentina(const QString &fileName) const { - if (this->isWindowModified() || curFile.isEmpty() == false) + if (this->isWindowModified() || qApp->GetPPath().isEmpty() == false) { VApplication::NewValentina(fileName); return true; @@ -3972,7 +4001,7 @@ void MainWindow::CreateActions() connect(ui->actionPattern_properties, &QAction::triggered, this, [this]() { - DialogPatternProperties proper(curFile, doc, pattern, this); + DialogPatternProperties proper(doc, pattern, this); connect(&proper, &DialogPatternProperties::UpdateGradation, this, [this]() { UpdateHeightsList(VMeasurement::ListHeights(doc->GetGradationHeights(), qApp->patternUnit())); @@ -4042,6 +4071,12 @@ void MainWindow::CreateActions() connect(ui->actionSyncMeasurements, &QAction::triggered, this, &MainWindow::SyncMeasurements); connect(ui->actionUnloadMeasurements, &QAction::triggered, this, &MainWindow::UnloadMeasurements); + + connect(ui->actionLabelTemplateEditor, &QAction::triggered, this, [this]() + { + DialogEditLabel editor(doc); + editor.exec(); + }); } //--------------------------------------------------------------------------------------------------------------------- @@ -4191,7 +4226,7 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu doc->setXMLContent(converter.Convert()); if (!customMeasureFile.isEmpty()) { - doc->SetPath(RelativeMPath(fileName, customMeasureFile)); + doc->SetMPath(RelativeMPath(fileName, customMeasureFile)); } qApp->setPatternUnit(doc->MUnit()); const QString path = AbsoluteMPath(fileName, doc->MPath()); @@ -4663,9 +4698,9 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS CheckRequiredMeasurements(m.data()); - doc->SetPath(RelativeMPath(patternPath, mPath)); - PatternChangesWereSaved(false); qApp->setPatternType(patternType); + doc->SetMPath(RelativeMPath(patternPath, mPath)); + PatternChangesWereSaved(false); return mPath; } } @@ -4813,7 +4848,7 @@ bool MainWindow::SetSize(const QString &text) { if (not VApplication::IsGUIMode()) { - if (this->isWindowModified() || not curFile.isEmpty()) + if (this->isWindowModified() || not qApp->GetPPath().isEmpty()) { if (qApp->patternType() == MeasurementsType::Multisize) { @@ -4856,7 +4891,7 @@ bool MainWindow::SetHeight(const QString &text) { if (not VApplication::IsGUIMode()) { - if (this->isWindowModified() || not curFile.isEmpty()) + if (this->isWindowModified() || not qApp->GetPPath().isEmpty()) { if (qApp->patternType() == MeasurementsType::Multisize) { @@ -4969,9 +5004,9 @@ void MainWindow::ProcessCMD() QString MainWindow::GetPatternFileName() { QString shownName = tr("untitled.val"); - if(not curFile.isEmpty()) + if(not qApp->GetPPath().isEmpty()) { - shownName = StrippedName(curFile); + shownName = StrippedName(qApp->GetPPath()); } shownName += QLatin1String("[*]"); return shownName; @@ -4987,7 +5022,7 @@ QString MainWindow::GetMeasurementFileName() else { QString shownName(" ["); - shownName += StrippedName(AbsoluteMPath(curFile, doc->MPath())); + shownName += StrippedName(AbsoluteMPath(qApp->GetPPath(), doc->MPath())); if(mChanges) { @@ -5003,12 +5038,12 @@ QString MainWindow::GetMeasurementFileName() void MainWindow::UpdateWindowTitle() { bool isFileWritable = true; - if (not curFile.isEmpty()) + if (not qApp->GetPPath().isEmpty()) { #ifdef Q_OS_WIN32 qt_ntfs_permission_lookup++; // turn checking on #endif /*Q_OS_WIN32*/ - isFileWritable = QFileInfo(curFile).isWritable(); + isFileWritable = QFileInfo(qApp->GetPPath()).isWritable(); #ifdef Q_OS_WIN32 qt_ntfs_permission_lookup--; // turn it off again #endif /*Q_OS_WIN32*/ @@ -5023,7 +5058,7 @@ void MainWindow::UpdateWindowTitle() setWindowTitle(GetPatternFileName()+GetMeasurementFileName() + QLatin1String(" (") + tr("read only") + QLatin1String(")")); } - setWindowFilePath(curFile); + setWindowFilePath(qApp->GetPPath()); #if defined(Q_OS_MAC) static QIcon fileIcon = QIcon(QCoreApplication::applicationDirPath() + diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 10c90405b..38422502b 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -55,8 +55,8 @@ 0 0 - 126 - 351 + 127 + 358 @@ -402,7 +402,7 @@ 0 0 140 - 108 + 110 @@ -511,7 +511,7 @@ 0 0 140 - 243 + 248 @@ -773,7 +773,7 @@ 0 0 140 - 243 + 248 @@ -1038,7 +1038,7 @@ 0 0 140 - 102 + 104 @@ -1121,7 +1121,7 @@ 0 0 140 - 326 + 328 @@ -1325,7 +1325,7 @@ 0 0 140 - 192 + 196 @@ -1535,7 +1535,7 @@ 0 0 140 - 326 + 328 @@ -1635,7 +1635,7 @@ 0 0 1100 - 19 + 25 @@ -1664,6 +1664,8 @@ + + @@ -2668,6 +2670,11 @@ QAction::NoRole + + + Label template editor + + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index c917a3ee7..8b05e458f 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -101,7 +101,6 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) redoAction(nullptr), actionDockWidgetToolOptions(nullptr), actionDockWidgetGroups(nullptr), - curFile(), isNoScaling(false), isLayoutStale(true), ignorePrinterFields(false), @@ -1512,7 +1511,7 @@ void MainWindowsNoGUI::ExportScene(const DialogSaveLayout &dialog, const QListGetPPath().isEmpty() ? fileName = tr("unnamed") : fileName = qApp->GetPPath(); return QFileInfo(fileName).baseName(); } diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index fcc5e4029..3c23bf983 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -82,9 +82,6 @@ protected: QAction *actionDockWidgetToolOptions; QAction *actionDockWidgetGroups; - /** @brief fileName name current pattern file. */ - QString curFile; - bool isNoScaling; bool isLayoutStale; bool ignorePrinterFields; diff --git a/src/app/valentina/valentina.pro b/src/app/valentina/valentina.pro index 9e013e879..fb4e6342a 100644 --- a/src/app/valentina/valentina.pro +++ b/src/app/valentina/valentina.pro @@ -167,6 +167,10 @@ unix{ templates.path = /usr/share/$${TARGET}/tables/templates/ templates.files = $$INSTALL_STANDARD_TEMPLATES + # Path to label templates after installation + label.path = /usr/share/$${TARGET}/labels/ + label.files = $$INSTALL_LABEL_TEMPLATES + INSTALLS += \ target \ tape \ @@ -174,7 +178,8 @@ unix{ pixmaps \ translations \ multisize \ - templates + templates \ + label } macx{ # Some macx stuff @@ -234,6 +239,10 @@ unix{ templates.path = $$RESOURCES_DIR/tables/templates/ templates.files = $$INSTALL_STANDARD_TEMPLATES + # Path to label templates after installation + label.path = /usr/share/$${TARGET}/labels/ + label.files = $$INSTALL_LABEL_TEMPLATES + icns_resources.path = $$RESOURCES_DIR/ icns_resources.files += $$PWD/../../../dist/macx/i-measurements.icns icns_resources.files += $$PWD/../../../dist/macx/s-measurements.icns @@ -246,6 +255,7 @@ unix{ QMAKE_BUNDLE_DATA += \ templates \ multisize \ + label \ libraries \ tape \ xpdf \ @@ -316,6 +326,10 @@ win32:*g++* { package_templates.files += $$INSTALL_STANDARD_TEMPLATES INSTALLS += package_templates + package_labels.path = $${OUT_PWD}/../../../package/valentina/labels + package_labels.files += $$INSTALL_LABEL_TEMPLATES + INSTALLS += package_labels + package_translations.path = $${OUT_PWD}/../../../package/valentina/translations package_translations.files += \ $$INSTALL_TRANSLATIONS \ # Valentina diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 733ee5cb7..0edf3d62b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -106,7 +106,6 @@ void VPattern::CreateEmptyFile() unit.appendChild(newNodeText); patternElement.appendChild(unit); - patternElement.appendChild(createElement(TagAuthor)); patternElement.appendChild(createElement(TagDescription)); patternElement.appendChild(createElement(TagNotes)); @@ -149,10 +148,10 @@ void VPattern::Parse(const Document &parse) SCASSERT(sceneDraw != nullptr) SCASSERT(sceneDetail != nullptr) - QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes + QStringList tags = QStringList() << TagDraw << TagIncrements << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagSize << TagShowDate << TagShowMeasurements; + << TagPatternLabel; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -188,50 +187,41 @@ void VPattern::Parse(const Document &parse) qCDebug(vXML, "Tag increments."); ParseIncrementsElement(domElement); break; - case 2: // TagAuthor - qCDebug(vXML, "Tag author."); - break; - case 3: // TagDescription + case 2: // TagDescription qCDebug(vXML, "Tag description."); break; - case 4: // TagNotes + case 3: // TagNotes qCDebug(vXML, "Tag notes."); break; - case 5: // TagMeasurements + case 4: // TagMeasurements qCDebug(vXML, "Tag measurements."); break; - case 6: // TagVersion + case 5: // TagVersion qCDebug(vXML, "Tag version."); break; - case 7: // TagGradation + case 6: // TagGradation qCDebug(vXML, "Tag gradation."); break; - case 8: // TagImage + case 7: // TagImage qCDebug(vXML, "Tag image."); break; - case 9: // TagUnit + case 8: // TagUnit qCDebug(vXML, "Tag unit."); break; - case 10: // TagPatternName + case 9: // TagPatternName qCDebug(vXML, "Pattern name."); break; - case 11: // TagPatternNumber + case 10: // TagPatternNumber qCDebug(vXML, "Pattern number."); break; - case 12: // TagCompanyName + case 11: // TagCompanyName qCDebug(vXML, "Company name."); break; - case 13: // TagCustomerName + case 12: // TagCustomerName qCDebug(vXML, "Customer name."); break; - case 14: // TagSize - qCDebug(vXML, "Size"); - break; - case 15: - qCDebug(vXML, "Show creation date"); - break; - case 16: - qCDebug(vXML, "Show measurements"); + case 13: // TagPatternLabel + qCDebug(vXML, "Pattern label."); break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); @@ -903,16 +893,14 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) { VPieceLabelData &ppData = detail.GetPatternPieceData(); ppData.SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); - try - { - QString qsLetter = GetParametrString(domElement, AttrLetter, ""); - ppData.SetLetter(qsLetter); - } - catch(const VExceptionEmptyParameter &e) - { - Q_UNUSED(e) - ppData.SetLetter(""); - } + ppData.SetLetter(GetParametrEmptyString(domElement, AttrLetter)); + ppData.SetAnnotation(GetParametrEmptyString(domElement, AttrAnnotation)); + ppData.SetOrientation(GetParametrEmptyString(domElement, AttrOrientation)); + ppData.SetRotation(GetParametrEmptyString(domElement, AttrRotation)); + ppData.SetTilt(GetParametrEmptyString(domElement, AttrTilt)); + ppData.SetFoldPosition(GetParametrEmptyString(domElement, AttrFoldPosition)); + ppData.SetQuantity(static_cast(GetParametrUInt(domElement, AttrQuantity, "1"))); + ppData.SetOnFold(GetParametrBool(domElement, AttrOnFold, falseStr)); ppData.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); ppData.SetLabelWidth(GetParametrString(domElement, AttrWidth, "1")); ppData.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); @@ -921,21 +909,7 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) ppData.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); ppData.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); ppData.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); - - QDomNodeList nodeListMCP = domElement.childNodes(); - for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP) - { - MaterialCutPlacement mcp; - QDomElement domMCP = nodeListMCP.at(iMCP).toElement(); - mcp.m_eMaterial = MaterialType(GetParametrUInt(domMCP, AttrMaterial, 0)); - if (mcp.m_eMaterial == MaterialType::mtUserDefined) - { - mcp.m_qsMaterialUserDef = GetParametrString(domMCP, AttrUserDefined, ""); - } - mcp.m_iCutNumber = static_cast(GetParametrUInt(domMCP, AttrCutNumber, 0)); - mcp.m_ePlacement = PlacementType(GetParametrUInt(domMCP, AttrPlacement, 0)); - ppData.Append(mcp); - } + ppData.SetLabelTemplate(GetLabelTemplate(domElement)); } //--------------------------------------------------------------------------------------------------------------------- @@ -3393,21 +3367,6 @@ void VPattern::ParseIncrementsElement(const QDomNode &node) } } -//--------------------------------------------------------------------------------------------------------------------- -QString VPattern::GetAuthor() const -{ - return UniqueTagText(TagAuthor, qApp->ValentinaSettings()->GetUser()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPattern::SetAuthor(const QString &text) -{ - CheckTagExists(TagAuthor); - setTagText(TagAuthor, text); - modified = true; - emit patternChanged(false); -} - //--------------------------------------------------------------------------------------------------------------------- void VPattern::AddEmptyIncrement(const QString &name) { diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 2ce56e4e6..c0daab674 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -66,9 +66,6 @@ public: QRectF ActiveDrawBoundingRect() const; - QString GetAuthor() const; - void SetAuthor(const QString &text); - void AddEmptyIncrement(const QString &name); void AddEmptyIncrementAfter(const QString &after, const QString &name); void RemoveIncrement(const QString &name); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 9b0b8e565..e5ae62094 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -213,4 +213,18 @@ extern const QString currentSeamAllowance; extern const QStringList builInVariables; +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +struct VLabelTemplateLine +{ + QString line; + bool bold; + bool italic; + int alignment; + int fontSizeIncrement; +}; + +QT_WARNING_POP + #endif // IFCDEF_H diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index b585907db..78bfb02d4 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -34,6 +34,7 @@ schema/pattern/v0.4.8.xsd schema/pattern/v0.5.0.xsd schema/pattern/v0.5.1.xsd + schema/pattern/v0.6.0.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd @@ -45,5 +46,6 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd + schema/label_template/v1.0.0.xsd diff --git a/src/libs/ifc/schema/label_template/v1.0.0.xsd b/src/libs/ifc/schema/label_template/v1.0.0.xsd new file mode 100644 index 000000000..894be390d --- /dev/null +++ b/src/libs/ifc/schema/label_template/v1.0.0.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/schema/pattern/v0.6.0.xsd b/src/libs/ifc/schema/pattern/v0.6.0.xsd new file mode 100644 index 000000000..9cb509919 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.6.0.xsd @@ -0,0 +1,937 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index c1092679a..cb35f9a39 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -51,6 +51,7 @@ #include "vpatternconverter.h" #include "vdomdocument.h" #include "vtoolrecord.h" +#include "../vmisc/vabstractapplication.h" class QDomElement; @@ -59,7 +60,6 @@ const QString VAbstractPattern::TagCalculation = QStringLiteral("calculatio const QString VAbstractPattern::TagModeling = QStringLiteral("modeling"); const QString VAbstractPattern::TagDetails = QStringLiteral("details"); const QString VAbstractPattern::TagDetail = QStringLiteral("detail"); -const QString VAbstractPattern::TagAuthor = QStringLiteral("author"); const QString VAbstractPattern::TagDescription = QStringLiteral("description"); const QString VAbstractPattern::TagNotes = QStringLiteral("notes"); const QString VAbstractPattern::TagImage = QStringLiteral("image"); @@ -82,14 +82,11 @@ const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagData = QStringLiteral("data"); const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo"); -const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName"); const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); -const QString VAbstractPattern::TagSize = QStringLiteral("size"); -const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate"); -const QString VAbstractPattern::TagShowMeasurements = QStringLiteral("showMeasurements"); +const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel"); const QString VAbstractPattern::TagGrainline = QStringLiteral("grainline"); const QString VAbstractPattern::TagPath = QStringLiteral("path"); const QString VAbstractPattern::TagNodes = QStringLiteral("nodes"); @@ -101,10 +98,15 @@ const QString VAbstractPattern::AttrObject = QStringLiteral("object") const QString VAbstractPattern::AttrTool = QStringLiteral("tool"); const QString VAbstractPattern::AttrType = QStringLiteral("type"); const QString VAbstractPattern::AttrLetter = QStringLiteral("letter"); -const QString VAbstractPattern::AttrMaterial = QStringLiteral("material"); -const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); -const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); -const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); +const QString VAbstractPattern::AttrAnnotation = QStringLiteral("annotation"); +const QString VAbstractPattern::AttrOrientation = QStringLiteral("orientation"); +const QString VAbstractPattern::AttrRotation = QStringLiteral("rotation"); +const QString VAbstractPattern::AttrTilt = QStringLiteral("tilt"); +const QString VAbstractPattern::AttrFoldPosition = QStringLiteral("foldPosition"); +const QString VAbstractPattern::AttrQuantity = QStringLiteral("quantity"); +const QString VAbstractPattern::AttrOnFold = QStringLiteral("onFold"); +const QString VAbstractPattern::AttrDateFormat = QStringLiteral("dateFormat"); +const QString VAbstractPattern::AttrTimeFormat = QStringLiteral("timeFormat"); const QString VAbstractPattern::AttrArrows = QStringLiteral("arrows"); const QString VAbstractPattern::AttrNodeReverse = QStringLiteral("reverse"); const QString VAbstractPattern::AttrNodeExcluded = QStringLiteral("excluded"); @@ -119,7 +121,6 @@ const QString VAbstractPattern::AttrPath = QStringLiteral("path"); const QString VAbstractPattern::AttrEnd = QStringLiteral("end"); const QString VAbstractPattern::AttrIncludeAs = QStringLiteral("includeAs"); const QString VAbstractPattern::AttrWidth = QStringLiteral("width"); -const QString VAbstractPattern::AttrRotation = QStringLiteral("rotation"); const QString VAbstractPattern::AttrAll = QStringLiteral("all"); @@ -193,6 +194,8 @@ const QString VAbstractPattern::NodeSpline = QStringLiteral("NodeSpline"); const QString VAbstractPattern::NodeSplinePath = QStringLiteral("NodeSplinePath"); QHash VAbstractPattern::tools = QHash(); +QVector VAbstractPattern::patternLabelLines = QVector(); +bool VAbstractPattern::patternLabelWasChanged = false; namespace { @@ -790,11 +793,12 @@ QString VAbstractPattern::MPath() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetPath(const QString &path) +void VAbstractPattern::SetMPath(const QString &path) { if (setTagText(TagMeasurements, path)) { emit patternChanged(false); + emit UpdatePatternLabel(); } else { @@ -1330,48 +1334,94 @@ void VAbstractPattern::SetCustomerName(const QString& qsName) } //--------------------------------------------------------------------------------------------------------------------- -QString VAbstractPattern::GetPatternSize() const +QString VAbstractPattern::GetLabelDateFormat() const { - return UniqueTagText(TagSize); + QString globalLabelDateFormat = qApp->Settings()->GetLabelDateFormat(); + + const QDomNodeList list = elementsByTagName(TagPatternLabel); + if (list.isEmpty()) + { + return globalLabelDateFormat; + } + + QDomElement tag = list.at(0).toElement(); + return GetParametrString(tag, AttrDateFormat, globalLabelDateFormat); } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetPatternSize(const QString& qsSize) +void VAbstractPattern::SetLabelDateFormat(const QString &format) { - CheckTagExists(TagSize); - setTagText(TagSize, qsSize); + QDomElement tag = CheckTagExists(TagPatternLabel); + SetAttribute(tag, AttrDateFormat, format); + patternLabelWasChanged = true; modified = true; emit patternChanged(false); } //--------------------------------------------------------------------------------------------------------------------- -bool VAbstractPattern::IsDateVisible() const +QString VAbstractPattern::GetLabelTimeFormat() const { - return UniqueTagText(TagShowDate) != falseStr; + QString globalLabelTimeFormat = qApp->Settings()->GetLabelTimeFormat(); + + const QDomNodeList list = elementsByTagName(TagPatternLabel); + if (list.isEmpty()) + { + return globalLabelTimeFormat; + } + + QDomElement tag = list.at(0).toElement(); + return GetParametrString(tag, AttrTimeFormat, globalLabelTimeFormat); } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetDateVisible(bool bVisible) +void VAbstractPattern::SetLabelTimeFormat(const QString &format) { - CheckTagExists(TagShowDate); - setTagText(TagShowDate, bVisible == true? trueStr : falseStr); + QDomElement tag = CheckTagExists(TagPatternLabel); + SetAttribute(tag, AttrTimeFormat, format); + patternLabelWasChanged = true; modified = true; emit patternChanged(false); } //--------------------------------------------------------------------------------------------------------------------- -bool VAbstractPattern::IsMeasurementsVisible() const +void VAbstractPattern::SetPatternLabelTemplate(const QVector &lines) { - return UniqueTagText(TagShowMeasurements) == trueStr; + QDomElement tag = CheckTagExists(TagPatternLabel); + RemoveAllChildren(tag); + SetLabelTemplate(tag, lines); + patternLabelLines = lines; + patternLabelWasChanged = true; + modified = true; + emit patternChanged(false); } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetMesurementsVisible(bool bVisible) +QVector VAbstractPattern::GetPatternLabelTemplate() const { - CheckTagExists(TagShowMeasurements); - setTagText(TagShowMeasurements, bVisible == true? trueStr : falseStr); - modified = true; - emit patternChanged(false); + if (patternLabelLines.isEmpty()) + { + const QDomNodeList list = elementsByTagName(TagPatternLabel); + if (list.isEmpty()) + { + return QVector(); + } + + patternLabelLines = GetLabelTemplate(list.at(0).toElement()); + } + + return patternLabelLines; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetPatternWasChanged(bool changed) +{ + patternLabelWasChanged = changed; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractPattern::GetPatternWasChanged() const +{ + return patternLabelWasChanged; } //--------------------------------------------------------------------------------------------------------------------- @@ -1514,24 +1564,21 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) QDomElement element; if (list.isEmpty()) { - const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes + const QStringList tags = QStringList() << TagUnit << TagImage << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagSize << TagShowDate << TagShowMeasurements; + << TagCustomerName << TagPatternLabel; switch (tags.indexOf(tag)) { case 1: //TagImage element = createElement(TagImage); break; - case 2: //TagAuthor - element = createElement(TagAuthor); - break; - case 3: //TagDescription + case 2: //TagDescription element = createElement(TagDescription); break; - case 4: //TagNotes + case 3: //TagNotes element = createElement(TagNotes); break; - case 5: //TagGradation + case 4: //TagGradation { element = createElement(TagGradation); @@ -1544,27 +1591,21 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element.appendChild(sizes); break; } - case 6: // TagPatternName + case 5: // TagPatternName element = createElement(TagPatternName); break; - case 7: // TagPatternNum + case 6: // TagPatternNum element = createElement(TagPatternNum); break; - case 8: // TagCompanyName + case 7: // TagCompanyName element = createElement(TagCompanyName); break; - case 9: // TagCustomerName + case 8: // TagCustomerName element = createElement(TagCustomerName); break; - case 10: // TagSize - element = createElement(TagSize); - break; - case 11: // TagShowDate - element = createElement(TagShowDate); - break; - case 12: // TagShowMeasurements - element = createElement(TagShowMeasurements); - break; + case 9: // TagPatternLabel + element = createElement(TagPatternLabel); + break; case 0: //TagUnit (Mandatory tag) default: return QDomElement(); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index b7b285052..7afa88722 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -121,7 +121,7 @@ public: QVector getLocalHistory() const; QString MPath() const; - void SetPath(const QString &path); + void SetMPath(const QString &path); quint32 SiblingNodeId(const quint32 &nodeId) const; @@ -141,18 +141,27 @@ public: QString GetPatternName() const; void SetPatternName(const QString& qsName); + QString GetCompanyName() const; void SetCompanyName(const QString& qsName); + QString GetPatternNumber() const; void SetPatternNumber(const QString &qsNum); + QString GetCustomerName() const; void SetCustomerName(const QString& qsName); - QString GetPatternSize() const; - void SetPatternSize(const QString &qsSize); - bool IsDateVisible() const; - void SetDateVisible(bool bVisible); - bool IsMeasurementsVisible() const; - void SetMesurementsVisible(bool bVisible); + + QString GetLabelDateFormat() const; + void SetLabelDateFormat(const QString &format); + + QString GetLabelTimeFormat() const; + void SetLabelTimeFormat(const QString &format); + + void SetPatternLabelTemplate(const QVector &lines); + QVector GetPatternLabelTemplate() const; + + void SetPatternWasChanged(bool changed); + bool GetPatternWasChanged() const; QString GetImage() const; QString GetImageExtension() const; @@ -181,7 +190,6 @@ public: static const QString TagModeling; static const QString TagDetails; static const QString TagDetail; - static const QString TagAuthor; static const QString TagDescription; static const QString TagImage; static const QString TagNotes; @@ -204,14 +212,11 @@ public: static const QString TagSizes; static const QString TagData; static const QString TagPatternInfo; - static const QString TagMCP; static const QString TagPatternName; static const QString TagPatternNum; static const QString TagCompanyName; static const QString TagCustomerName; - static const QString TagSize; - static const QString TagShowDate; - static const QString TagShowMeasurements; + static const QString TagPatternLabel; static const QString TagGrainline; static const QString TagPath; static const QString TagNodes; @@ -223,10 +228,15 @@ public: static const QString AttrTool; static const QString AttrType; static const QString AttrLetter; - static const QString AttrMaterial; - static const QString AttrUserDefined; - static const QString AttrCutNumber; - static const QString AttrPlacement; + static const QString AttrAnnotation; + static const QString AttrOrientation; + static const QString AttrRotation; + static const QString AttrTilt; + static const QString AttrFoldPosition; + static const QString AttrQuantity; + static const QString AttrOnFold; + static const QString AttrDateFormat; + static const QString AttrTimeFormat; static const QString AttrArrows; static const QString AttrNodeReverse; static const QString AttrNodeExcluded; @@ -241,7 +251,6 @@ public: static const QString AttrEnd; static const QString AttrIncludeAs; static const QString AttrWidth; - static const QString AttrRotation; static const QString AttrAll; @@ -341,6 +350,7 @@ signals: * @brief patternChanged emit if we have unsaved change. */ void patternChanged(bool saved); + void UpdatePatternLabel(); /** * @brief ShowTool highlight tool. * @param id tool id. @@ -383,6 +393,9 @@ protected: /** @brief tools list with pointer on tools. */ static QHash tools; + /** @brief patternLabelLines list to speed up reading a template by many pieces. */ + static QVector patternLabelLines; + static bool patternLabelWasChanged; static void ToolExists(const quint32 &id); static VPiecePath ParsePathNodes(const QDomElement &domElement); diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 7199346df..408b986fc 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -178,9 +178,16 @@ void MessageHandler::handleMessage(QtMsgType type, const QString &description, c Q_LOGGING_CATEGORY(vXML, "v.xml") -const QString VDomDocument::AttrId = QStringLiteral("id"); +const QString VDomDocument::AttrId = QStringLiteral("id"); +const QString VDomDocument::AttrText = QStringLiteral("text"); +const QString VDomDocument::AttrBold = QStringLiteral("bold"); +const QString VDomDocument::AttrItalic = QStringLiteral("italic"); +const QString VDomDocument::AttrAlignment = QStringLiteral("alignment"); +const QString VDomDocument::AttrFSIncrement = QStringLiteral("sfIncrement"); + const QString VDomDocument::TagVersion = QStringLiteral("version"); const QString VDomDocument::TagUnit = QStringLiteral("unit"); +const QString VDomDocument::TagLine = QStringLiteral("line"); //--------------------------------------------------------------------------------------------------------------------- VDomDocument::VDomDocument() @@ -446,6 +453,21 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt return parameter; } +//--------------------------------------------------------------------------------------------------------------------- +QString VDomDocument::GetParametrEmptyString(const QDomElement &domElement, const QString &name) +{ + QString result; + try + { + result = GetParametrString(domElement, name, ""); + } + catch(const VExceptionEmptyParameter &) + { + // do nothing + } + return result; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Returns the double value of the given attribute. @@ -899,3 +921,55 @@ bool VDomDocument::SafeCopy(const QString &source, const QString &destination, Q return result; } + +//--------------------------------------------------------------------------------------------------------------------- +QVector VDomDocument::GetLabelTemplate(const QDomElement &element) const +{ + // We use implicit conversion. That's why check if values are still the same as excpected. + Q_STATIC_ASSERT(Qt::AlignLeft == 1); + Q_STATIC_ASSERT(Qt::AlignRight == 2); + Q_STATIC_ASSERT(Qt::AlignHCenter == 4); + + QVector lines; + + if (not element.isNull()) + { + QDomElement tagLine = element.firstChildElement(); + while (tagLine.isNull() == false) + { + if (tagLine.tagName() == TagLine) + { + VLabelTemplateLine line; + line.line = GetParametrString(tagLine, AttrText, tr("")); + line.bold = GetParametrBool(tagLine, AttrBold, falseStr); + line.italic = GetParametrBool(tagLine, AttrItalic, falseStr); + line.alignment = GetParametrUInt(tagLine, AttrAlignment, "0"); + line.fontSizeIncrement = GetParametrUInt(tagLine, AttrFSIncrement, "0"); + lines.append(line); + } + tagLine = tagLine.nextSiblingElement(TagLine); + } + } + + return lines; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDomDocument::SetLabelTemplate(QDomElement &element, const QVector &lines) +{ + if (not element.isNull()) + { + for (int i=0; i < lines.size(); ++i) + { + QDomElement tagLine = createElement(TagLine); + + SetAttribute(tagLine, AttrText, lines.at(i).line); + SetAttribute(tagLine, AttrBold, lines.at(i).bold); + SetAttribute(tagLine, AttrItalic, lines.at(i).italic); + SetAttribute(tagLine, AttrAlignment, lines.at(i).alignment); + SetAttribute(tagLine, AttrFSIncrement, lines.at(i).fontSizeIncrement); + + element.appendChild(tagLine); + } + } +} diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index b2e0dafc5..b2a401e4a 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -83,8 +83,15 @@ class VDomDocument : public QDomDocument Q_DECLARE_TR_FUNCTIONS(VDomDocument) public: static const QString AttrId; + static const QString AttrText; + static const QString AttrBold; + static const QString AttrItalic; + static const QString AttrAlignment; + static const QString AttrFSIncrement; + static const QString TagVersion; static const QString TagUnit; + static const QString TagLine; VDomDocument(); virtual ~VDomDocument() Q_DECL_EQ_DEFAULT; @@ -101,6 +108,7 @@ public: static QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue = QString()); + static QString GetParametrEmptyString(const QDomElement& domElement, const QString &name); static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue); static quint32 GetParametrId(const QDomElement& domElement); @@ -122,6 +130,9 @@ public: static bool SafeCopy(const QString &source, const QString &destination, QString &error); + QVector GetLabelTemplate(const QDomElement &element) const; + void SetLabelTemplate(QDomElement &element, const QVector &lines); + protected: bool setTagText(const QString &tag, const QString &text); bool setTagText(const QDomElement &domElement, const QString &text); diff --git a/src/libs/ifc/xml/vlabeltemplateconverter.cpp b/src/libs/ifc/xml/vlabeltemplateconverter.cpp new file mode 100644 index 000000000..4b7319828 --- /dev/null +++ b/src/libs/ifc/xml/vlabeltemplateconverter.cpp @@ -0,0 +1,109 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vlabeltemplateconverter.h" + +/* + * Version rules: + * 1. Version have three parts "major.minor.patch"; + * 2. major part only for stable releases; + * 3. minor - 10 or more patch changes, or one big change; + * 4. patch - little change. + */ + +const QString VLabelTemplateConverter::LabelTemplateMinVerStr = QStringLiteral("1.0.0"); +const QString VLabelTemplateConverter::LabelTemplateMaxVerStr = QStringLiteral("1.0.0"); +const QString VLabelTemplateConverter::CurrentSchema = QStringLiteral("://schema/label_template/v1.0.0.xsd"); + +//VLabelTemplateConverter::LabelTemplateMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! +//VLabelTemplateConverter::LabelTemplateMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! + +//--------------------------------------------------------------------------------------------------------------------- +VLabelTemplateConverter::VLabelTemplateConverter(const QString &fileName) + : VAbstractConverter(fileName) +{ + ValidateInputFile(CurrentSchema); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VLabelTemplateConverter::MinVer() const +{ + return LabelTemplateMinVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VLabelTemplateConverter::MaxVer() const +{ + return LabelTemplateMaxVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VLabelTemplateConverter::MinVerStr() const +{ + return LabelTemplateMinVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VLabelTemplateConverter::MaxVerStr() const +{ + return LabelTemplateMaxVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VLabelTemplateConverter::XSDSchema(int ver) const +{ + switch (ver) + { + case (0x010000): + return CurrentSchema; + default: + InvalidVersion(ver); + break; + } + return QString();//unreachable code +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLabelTemplateConverter::ApplyPatches() +{ + switch (m_ver) + { + case (0x010000): + break; + default: + InvalidVersion(m_ver); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLabelTemplateConverter::DowngradeToCurrentMaxVersion() +{ + SetVersion(LabelTemplateMaxVerStr); + Save(); +} diff --git a/src/libs/ifc/xml/vlabeltemplateconverter.h b/src/libs/ifc/xml/vlabeltemplateconverter.h new file mode 100644 index 000000000..13669199b --- /dev/null +++ b/src/libs/ifc/xml/vlabeltemplateconverter.h @@ -0,0 +1,63 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VLABELTEMPLATECONVERTER_H +#define VLABELTEMPLATECONVERTER_H + +#include "vabstractconverter.h" + +class VLabelTemplateConverter : public VAbstractConverter +{ +public: + explicit VLabelTemplateConverter(const QString &fileName); + virtual ~VLabelTemplateConverter() Q_DECL_EQ_DEFAULT; + + static const QString LabelTemplateMaxVerStr; + static const QString CurrentSchema; + static Q_DECL_CONSTEXPR const int LabelTemplateMinVer = CONVERTER_VERSION_CHECK(1, 0, 0); + static Q_DECL_CONSTEXPR const int LabelTemplateMaxVer = CONVERTER_VERSION_CHECK(1, 0, 0); + +protected: + virtual int MinVer() const Q_DECL_OVERRIDE; + virtual int MaxVer() const Q_DECL_OVERRIDE; + + virtual QString MinVerStr() const Q_DECL_OVERRIDE; + virtual QString MaxVerStr() const Q_DECL_OVERRIDE; + + virtual QString XSDSchema(int ver) const Q_DECL_OVERRIDE; + virtual void ApplyPatches() Q_DECL_OVERRIDE; + virtual void DowngradeToCurrentMaxVersion() Q_DECL_OVERRIDE; + + virtual bool IsReadOnly() const Q_DECL_OVERRIDE {return false;} + +private: + Q_DISABLE_COPY(VLabelTemplateConverter) + static const QString LabelTemplateMinVerStr; +}; + +#endif // VLABELTEMPLATECONVERTER_H diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 25bbe6e8c..d4e15a3f9 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.5.1"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.5.1.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.6.0"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.6.0.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -135,6 +135,30 @@ static const QString strNodeType = QStringLiteral("nodeType"); static const QString strDet = QStringLiteral("det"); static const QString strTypeObject = QStringLiteral("typeObject"); static const QString strReadOnly = QStringLiteral("readOnly"); +static const QString strPatternLabel = QStringLiteral("patternLabel"); +static const QString strImage = QStringLiteral("image"); +static const QString strAuthor = QStringLiteral("author"); +static const QString strDescription = QStringLiteral("description"); +static const QString strNotes = QStringLiteral("notes"); +static const QString strGradation = QStringLiteral("gradation"); +static const QString strPatternName = QStringLiteral("patternName"); +static const QString strPatternNum = QStringLiteral("patternNumber"); +static const QString strCompanyName = QStringLiteral("company"); +static const QString strCustomerName = QStringLiteral("customer"); +static const QString strLine = QStringLiteral("line"); +static const QString strText = QStringLiteral("text"); +static const QString strBold = QStringLiteral("bold"); +static const QString strItalic = QStringLiteral("italic"); +static const QString strAlignment = QStringLiteral("alignment"); +static const QString strFSIncrement = QStringLiteral("sfIncrement"); +static const QString strShowDate = QStringLiteral("showDate"); +static const QString strShowMeasurements = QStringLiteral("showMeasurements"); +static const QString strSize = QStringLiteral("size"); +static const QString strMCP = QStringLiteral("mcp"); +static const QString strLetter = QStringLiteral("letter"); +static const QString strMaterial = QStringLiteral("material"); +static const QString strUserDefined = QStringLiteral("userDef"); +static const QString strPlacement = QStringLiteral("placement"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -215,6 +239,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000500): return QStringLiteral("://schema/pattern/v0.5.0.xsd"); case (0x000501): + return QStringLiteral("://schema/pattern/v0.5.1.xsd"); + case (0x000600): return CurrentSchema; default: InvalidVersion(ver); @@ -361,6 +387,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000501), m_convertedFileName); V_FALLTHROUGH case (0x000501): + ToV0_6_0(); + ValidateXML(XSDSchema(0x000600), m_convertedFileName); + V_FALLTHROUGH + case (0x000600): break; default: InvalidVersion(m_ver); @@ -379,7 +409,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 5, 1), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 6, 0), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -768,6 +798,20 @@ void VPatternConverter::ToV0_5_1() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_6_0() +{ + // TODO. Delete if minimal supported version is 0.6.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.6.0")); + QDomElement label = AddTagPatternLabelV0_5_1(); + PortPatternLabeltoV0_6_0(label); + PortPieceLabelstoV0_6_0(); + RemoveUnusedTagsV0_6_0(); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { @@ -2040,6 +2084,214 @@ void VPatternConverter::LabelTagToV0_4_4(const QString &tagName) } } +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VPatternConverter::AddTagPatternLabelV0_5_1() +{ + // TODO. Delete if minimal supported version is 0.6.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0), + "Time to refactor the code."); + + const QDomNodeList list = elementsByTagName(strPatternLabel); + if (list.isEmpty()) + { + const QStringList tags = QStringList() << strUnit + << strImage + << strAuthor + << strDescription + << strNotes + << strGradation + << strPatternName + << strPatternNum + << strCompanyName + << strCustomerName + << strPatternLabel; + + QDomElement element = createElement(strPatternLabel); + QDomElement pattern = documentElement(); + for (int i = tags.indexOf(element.tagName())-1; i >= 0; --i) + { + const QDomNodeList list = elementsByTagName(tags.at(i)); + if (not list.isEmpty()) + { + pattern.insertAfter(element, list.at(0)); + break; + } + } + return element; + } + return list.at(0).toElement(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::PortPatternLabeltoV0_6_0(QDomElement &label) +{ + // TODO. Delete if minimal supported version is 0.6.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0), + "Time to refactor the code."); + + if (not UniqueTagText(strCompanyName).isEmpty()) + { + AddLabelTemplateLineV0_6_0(label, "%author%", true, false, 0, 4); + } + else + { + const QString author = UniqueTagText(strAuthor); + if (not author.isEmpty()) + { + AddLabelTemplateLineV0_6_0(label, author, true, false, 0, 4); + } + } + + if (not UniqueTagText(strPatternName).isEmpty()) + { + AddLabelTemplateLineV0_6_0(label, "%patternName%", false, false, 0, 2); + } + + if (not UniqueTagText(strPatternNum).isEmpty()) + { + AddLabelTemplateLineV0_6_0(label, "%patternNumber%", false, false, 0, 0); + } + + if (not UniqueTagText(strCustomerName).isEmpty()) + { + AddLabelTemplateLineV0_6_0(label, "%customer%", false, true, 0, 0); + } + + const QString sizeField = UniqueTagText(strSize); + if (not sizeField.isEmpty()) + { + AddLabelTemplateLineV0_6_0(label, sizeField, false, false, 0, 0); + } + + if (UniqueTagText(strShowMeasurements) == trueStr) + { + AddLabelTemplateLineV0_6_0(label, "%mFileName%.%mExt%", false, false, 0, 0); + } + + if (UniqueTagText(strShowDate) == trueStr) + { + AddLabelTemplateLineV0_6_0(label, "%date%", false, true, 0, 0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::AddLabelTemplateLineV0_6_0(QDomElement &label, const QString &text, bool bold, bool italic, + int alignment, int fontSizeIncrement) +{ + // TODO. Delete if minimal supported version is 0.6.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0), + "Time to refactor the code."); + + QDomElement tagLine = createElement(strLine); + + SetAttribute(tagLine, strText, text); + SetAttribute(tagLine, strBold, bold); + SetAttribute(tagLine, strItalic, italic); + SetAttribute(tagLine, strAlignment, alignment); + SetAttribute(tagLine, strFSIncrement, fontSizeIncrement); + + label.appendChild(tagLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::PortPieceLabelstoV0_6_0() +{ + // TODO. Delete if minimal supported version is 0.6.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0), + "Time to refactor the code."); + + const QDomNodeList nodeList = elementsByTagName(strData); + for (int i = 0; i < nodeList.size(); ++i) + { + QDomElement dataTag = nodeList.at(i).toElement(); + QDomNodeList nodeListMCP = dataTag.childNodes(); + const int count = nodeListMCP.count(); + try + { + if (not GetParametrString(dataTag, strLetter, "").isEmpty()) + { + AddLabelTemplateLineV0_6_0(dataTag, "%pLetter%", true, false, Qt::AlignHCenter, 6); + } + } + catch(const VExceptionEmptyParameter &) + {} + + AddLabelTemplateLineV0_6_0(dataTag, "%pName%", true, false, Qt::AlignHCenter, 2); + + for (int iMCP = 0; iMCP < count; ++iMCP) + { + QDomElement domMCP = nodeListMCP.at(iMCP).toElement(); + + QString line; + + const int material = GetParametrUInt(domMCP, strMaterial, "0"); + switch(material) + { + case 0: + line.append("%mFabric%"); + break; + case 1: + line.append("%mLining%"); + break; + case 2: + line.append("%mInterfacing%"); + break; + case 3: + line.append("%mInterlining%"); + break; + case 4: + default: + line.append(GetParametrString(domMCP, strUserDefined, "User material")); + break; + } + + line.append(", %wCut% %pQuantity%"); + if (GetParametrUInt(domMCP, strPlacement, "0") == 1) + { + line.append(" %wOnFold%"); + } + + AddLabelTemplateLineV0_6_0(dataTag, line, false, false, Qt::AlignHCenter, 0); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::RemoveUnusedTagsV0_6_0() +{ + // TODO. Delete if minimal supported version is 0.6.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0), + "Time to refactor the code."); + + RemoveUniqueTagV0_6_0(strAuthor); + RemoveUniqueTagV0_6_0(strSize); + RemoveUniqueTagV0_6_0(strShowDate); + RemoveUniqueTagV0_6_0(strShowMeasurements); + + const QDomNodeList nodeList = elementsByTagName(strMCP); + for (int i = 0; i < nodeList.size(); ++i) + { + nodeList.at(i).parentNode().removeChild(nodeList.at(i)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::RemoveUniqueTagV0_6_0(const QString &tag) +{ + // TODO. Delete if minimal supported version is 0.6.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 0), + "Time to refactor the code."); + + const QDomNodeList nodeList = elementsByTagName(tag); + if (nodeList.isEmpty()) + { + return; + } + + QDomElement pattern = documentElement(); + pattern.removeChild(nodeList.at(0)); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnionDetailsToV0_4_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 449f75c18..0cc38b39f 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 5, 1); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 6, 0); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -105,6 +105,7 @@ private: void ToV0_4_8(); void ToV0_5_0(); void ToV0_5_1(); + void ToV0_6_0(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); @@ -147,6 +148,14 @@ private: QDomElement GetUnionChildrenNodesV0_4_0(const QDomElement &detail); void LabelTagToV0_4_4(const QString &tagName); + + QDomElement AddTagPatternLabelV0_5_1(); + void PortPatternLabeltoV0_6_0(QDomElement &label); + void AddLabelTemplateLineV0_6_0(QDomElement &label, const QString &text, bool bold, bool italic, int alignment, + int fontSizeIncrement); + void PortPieceLabelstoV0_6_0(); + void RemoveUnusedTagsV0_6_0(); + void RemoveUniqueTagV0_6_0(const QString &tag); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/xml.pri b/src/libs/ifc/xml/xml.pri index 0925a57b0..d5d333e23 100644 --- a/src/libs/ifc/xml/xml.pri +++ b/src/libs/ifc/xml/xml.pri @@ -9,7 +9,8 @@ HEADERS += \ $$PWD/vabstractpattern.h \ $$PWD/vvstconverter.h \ $$PWD//vvitconverter.h \ - $$PWD//vabstractmconverter.h + $$PWD//vabstractmconverter.h \ + $$PWD/vlabeltemplateconverter.h SOURCES += \ $$PWD/vabstractconverter.cpp \ @@ -19,4 +20,5 @@ SOURCES += \ $$PWD/vabstractpattern.cpp \ $$PWD/vvstconverter.cpp \ $$PWD//vvitconverter.cpp \ - $$PWD//vabstractmconverter.cpp + $$PWD//vabstractmconverter.cpp \ + $$PWD/vlabeltemplateconverter.cpp diff --git a/src/libs/vformat/vformat.pri b/src/libs/vformat/vformat.pri index 5afe5834a..2d8f8f3ad 100644 --- a/src/libs/vformat/vformat.pri +++ b/src/libs/vformat/vformat.pri @@ -2,10 +2,12 @@ # This need for corect working file translations.pro SOURCES += \ - $$PWD/vmeasurements.cpp + $$PWD/vmeasurements.cpp \ + $$PWD/vlabeltemplate.cpp *msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ $$PWD/vmeasurements.h \ - $$PWD/stable.h + $$PWD/stable.h \ + $$PWD/vlabeltemplate.h diff --git a/src/libs/vformat/vlabeltemplate.cpp b/src/libs/vformat/vlabeltemplate.cpp new file mode 100644 index 000000000..78f6ba385 --- /dev/null +++ b/src/libs/vformat/vlabeltemplate.cpp @@ -0,0 +1,80 @@ +/************************************************************************ + ** + ** @file vlabeltemplate.cpp + ** @author Roman Telezhynskyi + ** @date 10 8, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vlabeltemplate.h" +#include "../ifc/xml/vlabeltemplateconverter.h" + +const QString VLabelTemplate::TagTemplate = QStringLiteral("template"); +const QString VLabelTemplate::TagLines = QStringLiteral("lines"); + +//--------------------------------------------------------------------------------------------------------------------- +VLabelTemplate::VLabelTemplate() + : VDomDocument() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VLabelTemplate::CreateEmptyTemplate() +{ + clear(); + QDomElement templateElement = this->createElement(TagTemplate); + + QDomElement version = createElement(TagVersion); + QDomText newNodeText = createTextNode(VLabelTemplateConverter::LabelTemplateMaxVerStr); + version.appendChild(newNodeText); + templateElement.appendChild(version); + + templateElement.appendChild(createElement(TagLines)); + + this->appendChild(templateElement); + insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLabelTemplate::AddLines(const QVector &lines) +{ + const QDomNodeList listLines = elementsByTagName(TagLines); + if (listLines.size() == 0) + { + return; + } + + QDomElement tag = listLines.at(0).toElement(); + VDomDocument::SetLabelTemplate(tag, lines); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VLabelTemplate::ReadLines() const +{ + const QDomNodeList listLines = elementsByTagName(TagLines); + if (listLines.size() == 0) + { + return QVector(); + } + + return VDomDocument::GetLabelTemplate(listLines.at(0).toElement()); +} diff --git a/src/libs/vformat/vlabeltemplate.h b/src/libs/vformat/vlabeltemplate.h new file mode 100644 index 000000000..dd091479e --- /dev/null +++ b/src/libs/vformat/vlabeltemplate.h @@ -0,0 +1,51 @@ +/************************************************************************ + ** + ** @file vlabeltemplate.h + ** @author Roman Telezhynskyi + ** @date 10 8, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VLABELTEMPLATE_H +#define VLABELTEMPLATE_H + +#include "../ifc/xml/vdomdocument.h" + +class VLabelTemplate : public VDomDocument +{ +public: + VLabelTemplate(); + virtual ~VLabelTemplate() Q_DECL_EQ_DEFAULT; + + static const QString TagTemplate; + static const QString TagLines; + + void CreateEmptyTemplate(); + + void AddLines(const QVector &lines); + QVector ReadLines() const; +private: + Q_DISABLE_COPY(VLabelTemplate) +}; + +#endif // VLABELTEMPLATE_H diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 65b6c713f..9b66429d3 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -400,8 +400,7 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern if (geom.IsVisible() == true) { VAbstractPattern* pDoc = qApp->getCurrentDocument(); - det.SetPatternInfo(pDoc, geom, qApp->Settings()->GetLabelFont(), VContainer::size(), VContainer::height(), - pattern); + det.SetPatternInfo(pDoc, geom, qApp->Settings()->GetLabelFont(), pattern); } const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry(); @@ -544,8 +543,8 @@ QStringList VLayoutPiece::GetPatternText() const } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font, - qreal dSize, qreal dHeight, const VContainer *pattern) +void VLayoutPiece::SetPatternInfo(VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font, + const VContainer *pattern) { QPointF ptPos; qreal labelWidth = 0; @@ -578,7 +577,7 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLa d->m_tmPattern.SetFont(font); d->m_tmPattern.SetFontSize(geom.GetFontSize()); - d->m_tmPattern.Update(pDoc, dSize, dHeight); + d->m_tmPattern.Update(pDoc); // generate lines of text d->m_tmPattern.SetFontSize(geom.GetFontSize()); @@ -1026,8 +1025,8 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector GetGrainline() const; diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index a6e219e8b..c5e21c952 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -38,6 +38,7 @@ #include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vmath.h" +#include "../vpatterndb/vcontainer.h" #include "vtextmanager.h" //--------------------------------------------------------------------------------------------------------------------- @@ -47,11 +48,134 @@ TextLine::TextLine() : m_qsText(), m_iFontSize(MIN_FONT_SIZE), - m_eFontWeight(QFont::Normal), - m_eStyle(QFont::StyleNormal), + bold(false), + italic(false), m_eAlign(Qt::AlignCenter) {} +QList VTextManager::m_patternLabelLines = QList(); + +namespace +{ + +//--------------------------------------------------------------------------------------------------------------------- +QMap PreparePlaceholders(const VAbstractPattern *doc) +{ + SCASSERT(doc != nullptr) + + QMap placeholders; + + // Pattern tags + QLocale locale(qApp->Settings()->GetLocale()); + + const QString date = locale.toString(QDate::currentDate(), doc->GetLabelDateFormat()); + placeholders.insert(pl_date, date); + + const QString time = locale.toString(QTime::currentTime(), doc->GetLabelTimeFormat()); + placeholders.insert(pl_time, time); + + placeholders.insert(pl_patternName, doc->GetPatternName()); + placeholders.insert(pl_patternNumber, doc->GetPatternNumber()); + placeholders.insert(pl_author, doc->GetCompanyName()); + placeholders.insert(pl_customer, doc->GetCustomerName()); + placeholders.insert(pl_pExt, QString("val")); + placeholders.insert(pl_pFileName, QFileInfo(qApp->GetPPath()).baseName()); + placeholders.insert(pl_mFileName, QFileInfo(doc->MPath()).baseName()); + + QString curSize; + QString curHeight; + QString mExt; + if (qApp->patternType() == MeasurementsType::Multisize) + { + curSize = QString::number(VContainer::size()); + curHeight = QString::number(VContainer::height()); + mExt = "vst"; + } + else if (qApp->patternType() == MeasurementsType::Individual) + { + curSize = QString::number(VContainer::size()); + curHeight = QString::number(VContainer::height()); + mExt = "vit"; + } + + placeholders.insert(pl_size, curSize); + placeholders.insert(pl_height, curHeight); + placeholders.insert(pl_mExt, mExt); + + // Piece tags + placeholders.insert(pl_pLetter, ""); + placeholders.insert(pl_pAnnotation, ""); + placeholders.insert(pl_pOrientation, ""); + placeholders.insert(pl_pRotation, ""); + placeholders.insert(pl_pTilt, ""); + placeholders.insert(pl_pFoldPosition, ""); + placeholders.insert(pl_pName, ""); + placeholders.insert(pl_pQuantity, ""); + placeholders.insert(pl_wOnFold, ""); + placeholders.insert(pl_mFabric, QObject::tr("Fabric")); + placeholders.insert(pl_mLining, QObject::tr("Lining")); + placeholders.insert(pl_mInterfacing, QObject::tr("Interfacing")); + placeholders.insert(pl_mInterlining, QObject::tr("Interlining")); + placeholders.insert(pl_wCut, QObject::tr("Cut")); + + return placeholders; +} + +//--------------------------------------------------------------------------------------------------------------------- +void InitPiecePlaceholders(QMap &placeholders, const QString &name, const VPieceLabelData& data) +{ + placeholders[pl_pLetter] = data.GetLetter(); + placeholders[pl_pAnnotation] = data.GetAnnotation(); + placeholders[pl_pOrientation] = data.GetOrientation(); + placeholders[pl_pRotation] = data.GetRotation(); + placeholders[pl_pTilt] = data.GetTilt(); + placeholders[pl_pFoldPosition] = data.GetFoldPosition(); + placeholders[pl_pName] = name; + placeholders[pl_pQuantity] = QString::number(data.GetQuantity()); + + if (data.IsOnFold()) + { + placeholders[pl_wOnFold] = QObject::tr("on fold"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString ReplacePlaceholders(const QMap &placeholders, QString line) +{ + QChar per('%'); + auto i = placeholders.constBegin(); + while (i != placeholders.constEnd()) + { + line.replace(per+i.key()+per, i.value()); + ++i; + } + return line; +} + +//--------------------------------------------------------------------------------------------------------------------- +QList PrepareLines(const QVector &lines) +{ + QList textLines; + + for (int i=0; i < lines.size(); ++i) + { + if (not lines.at(i).line.isEmpty()) + { + TextLine tl; + tl.m_qsText = lines.at(i).line; + tl.m_eAlign = static_cast(lines.at(i).alignment); + tl.m_iFontSize = lines.at(i).fontSizeIncrement; + tl.bold = lines.at(i).bold; + tl.italic = lines.at(i).italic; + + textLines << tl; + } + } + + return textLines; +} +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VTextManager::VTextManager constructor @@ -60,13 +184,6 @@ VTextManager::VTextManager() : m_font(), m_liLines() {} -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VTextManager::~VTextManager destructor - */ -VTextManager::~VTextManager() -{} - //--------------------------------------------------------------------------------------------------------------------- VTextManager::VTextManager(const VTextManager &text) : m_font(text.GetFont()), m_liLines(text.GetAllSourceLines()) @@ -130,25 +247,6 @@ QList VTextManager::GetAllSourceLines() const return m_liLines; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddSourceLine add new text line to the list - * @param tl text line object to be added - */ -void VTextManager::AddSourceLine(const TextLine& tl) -{ - m_liLines << tl; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ClearSourceLines deletes the list of texts - */ -void VTextManager::ClearSourceLines() -{ - m_liLines.clear(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VTextManager::GetSourceLinesCount returns the number of input text lines @@ -202,8 +300,8 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) const TextLine& tl = GetSourceLine(i); fnt = m_font; fnt.setPixelSize(iFS + tl.m_iFontSize); - fnt.setWeight(tl.m_eFontWeight); - fnt.setStyle(tl.m_eStyle); + fnt.setBold(tl.bold); + fnt.setItalic(tl.italic); QFontMetrics fm(fnt); const int iTW = fm.width(tl.m_qsText); if (iTW > iMaxLen) @@ -215,8 +313,8 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) if (iMaxLen > fW) { QFont fnt = m_font; - fnt.setWeight(maxLine.m_eFontWeight); - fnt.setStyle(maxLine.m_eStyle); + fnt.setBold(maxLine.bold); + fnt.setItalic(maxLine.italic); int lineLength = 0; do @@ -240,58 +338,19 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) */ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data) { - ClearSourceLines(); - TextLine tl; - // all text must be centered and normal style! - tl.m_eAlign = Qt::AlignCenter; - tl.m_eStyle = QFont::StyleNormal; + m_liLines.clear(); - // letter - tl.m_qsText = data.GetLetter(); - if (tl.m_qsText.isEmpty() == false) + QMap placeholders = PreparePlaceholders(qApp->getCurrentDocument()); + InitPiecePlaceholders(placeholders, qsName, data); + + QVector lines = data.GetLabelTemplate(); + + for (int i=0; i 0)//Not gonna happen because min value is 1 now, but decided to left - { - QString qsMat; - if (mcp.m_eMaterial == MaterialType::mtUserDefined) - { - qsMat = mcp.m_qsMaterialUserDef; - } - else - { - qsMat = qslMaterials[int(mcp.m_eMaterial)]; - } - tl.m_qsText = qsText.arg(qsMat).arg(mcp.m_iCutNumber). - arg(qslPlace[int(mcp.m_ePlacement)]); - AddSourceLine(tl); - } + lines[i].line = ReplacePlaceholders(placeholders, lines.at(i).line); } + + m_liLines = PrepareLines(lines); } //--------------------------------------------------------------------------------------------------------------------- @@ -299,89 +358,28 @@ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data) * @brief VTextManager::Update updates the text lines with pattern info * @param pDoc pointer to the abstract pattern object */ -void VTextManager::Update(const VAbstractPattern *pDoc, qreal dSize, qreal dHeight) +void VTextManager::Update(VAbstractPattern *pDoc) { - ClearSourceLines(); - TextLine tl; - // all information must be centered - tl.m_eAlign = Qt::AlignCenter; + m_liLines.clear(); - // Company name - tl.m_qsText = pDoc->GetCompanyName(); - if (tl.m_qsText.isEmpty() == false) + if (m_patternLabelLines.isEmpty() || pDoc->GetPatternWasChanged()) { - tl.m_eFontWeight = QFont::DemiBold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 4; - AddSourceLine(tl); - } - // Pattern name - tl.m_qsText = pDoc->GetPatternName(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 2; - AddSourceLine(tl); - } - // Pattern number - tl.m_qsText = pDoc->GetPatternNumber(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - AddSourceLine(tl); - } - // Customer name - tl.m_qsText = pDoc->GetCustomerName(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleItalic; - tl.m_iFontSize = 0; - AddSourceLine(tl); - } - // Size - tl.m_qsText = pDoc->GetPatternSize(); - if (tl.m_qsText.isEmpty() == false) - { - // Such describing placeholders will help avoid mistake of localization. - // Translators very often remove '%'. - QString placeholder = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_size) + QLatin1String("%"); - tl.m_qsText.replace(placeholder, QString::number(dSize)); + QVector lines = pDoc->GetPatternLabelTemplate(); + if (lines.isEmpty() && m_patternLabelLines.isEmpty()) + { + return; // Nothing to parse + } - placeholder = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_height) + QLatin1String("%"); - tl.m_qsText.replace(placeholder, QString::number(dHeight)); + const QMap placeholders = PreparePlaceholders(pDoc); - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - AddSourceLine(tl); - } - // Measurements - tl.m_qsText = QFileInfo(pDoc->MPath()).fileName(); - if (tl.m_qsText.isEmpty() == false && pDoc->IsMeasurementsVisible() == true) - { - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - AddSourceLine(tl); - } - // Date - QDate date; - if (pDoc->IsDateVisible() == true) - { - date = QDate::currentDate(); - } - if (date.isValid() == true) - { - QLocale locale(qApp->Settings()->GetLocale()); - tl.m_qsText = locale.toString(date, "dd MMMM yyyy"); - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - AddSourceLine(tl); + for (int i=0; iSetPatternWasChanged(false); + m_patternLabelLines = PrepareLines(lines); } + + m_liLines = m_patternLabelLines; } - diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index bb631f381..1acaad8fb 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -51,8 +51,8 @@ struct TextLine { QString m_qsText; int m_iFontSize; // 0 means default - QFont::Weight m_eFontWeight; - QFont::Style m_eStyle; + bool bold; + bool italic; Qt::Alignment m_eAlign; TextLine(); @@ -67,7 +67,7 @@ class VTextManager Q_DECLARE_TR_FUNCTIONS(VTextManager) public: VTextManager(); - virtual ~VTextManager(); + virtual ~VTextManager() = default; VTextManager(const VTextManager &text); VTextManager &operator=(const VTextManager &text); @@ -80,17 +80,17 @@ public: void FitFontSize(qreal fW, qreal fH); QList GetAllSourceLines() const; - void AddSourceLine(const TextLine& tl); - void ClearSourceLines(); int GetSourceLinesCount() const; const TextLine& GetSourceLine(int i) const; void Update(const QString& qsName, const VPieceLabelData& data); - void Update(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight); + void Update(VAbstractPattern* pDoc); private: QFont m_font; QList m_liLines; + + static QList m_patternLabelLines; }; #endif // VTEXTMANAGER_H diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 4bb1adb3d..e8f06e69e 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -109,8 +109,59 @@ const QStringList builInPostfixOperators = QStringList() << cm_Oprt << mm_Oprt << in_Oprt; -const QString pl_size = QStringLiteral("size"); -const QString pl_height = QStringLiteral("height"); +const QString pl_size = QStringLiteral("size"); +const QString pl_height = QStringLiteral("height"); +const QString pl_date = QStringLiteral("date"); +const QString pl_time = QStringLiteral("time"); +const QString pl_patternName = QStringLiteral("patternName"); +const QString pl_patternNumber = QStringLiteral("patternNumber"); +const QString pl_author = QStringLiteral("author"); +const QString pl_customer = QStringLiteral("customer"); +const QString pl_pExt = QStringLiteral("pExt"); +const QString pl_pFileName = QStringLiteral("pFileName"); +const QString pl_mFileName = QStringLiteral("mFileName"); +const QString pl_mExt = QStringLiteral("mExt"); +const QString pl_pLetter = QStringLiteral("pLetter"); +const QString pl_pAnnotation = QStringLiteral("pAnnotation"); +const QString pl_pOrientation = QStringLiteral("pOrientation"); +const QString pl_pRotation = QStringLiteral("pRotation"); +const QString pl_pTilt = QStringLiteral("pTilt"); +const QString pl_pFoldPosition = QStringLiteral("pFoldPosition"); +const QString pl_pName = QStringLiteral("pName"); +const QString pl_pQuantity = QStringLiteral("pQuantity"); +const QString pl_mFabric = QStringLiteral("mFabric"); +const QString pl_mLining = QStringLiteral("mLining"); +const QString pl_mInterfacing = QStringLiteral("mInterfacing"); +const QString pl_mInterlining = QStringLiteral("mInterlining"); +const QString pl_wCut = QStringLiteral("wCut"); +const QString pl_wOnFold = QStringLiteral("wOnFold"); + +const QStringList labelTemplatePlaceholders = QStringList() << pl_size + << pl_height + << pl_date + << pl_time + << pl_patternName + << pl_patternNumber + << pl_author + << pl_customer + << pl_pExt + << pl_pFileName + << pl_mFileName + << pl_mExt + << pl_pLetter + << pl_pAnnotation + << pl_pOrientation + << pl_pRotation + << pl_pTilt + << pl_pFoldPosition + << pl_pName + << pl_pQuantity + << pl_mFabric + << pl_mLining + << pl_mInterfacing + << pl_mInterlining + << pl_wCut + << pl_wOnFold; const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png"); const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png"); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 23cff43ea..e39b6dcca 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -353,6 +353,32 @@ extern const QStringList builInPostfixOperators; // Placeholders extern const QString pl_size; extern const QString pl_height; +extern const QString pl_date; +extern const QString pl_time; +extern const QString pl_patternName; +extern const QString pl_patternNumber; +extern const QString pl_author; +extern const QString pl_customer; +extern const QString pl_pExt; +extern const QString pl_pFileName; +extern const QString pl_mFileName; +extern const QString pl_mExt; +extern const QString pl_pLetter; +extern const QString pl_pAnnotation; +extern const QString pl_pOrientation; +extern const QString pl_pRotation; +extern const QString pl_pTilt; +extern const QString pl_pFoldPosition; +extern const QString pl_pName; +extern const QString pl_pQuantity; +extern const QString pl_mFabric; +extern const QString pl_mLining; +extern const QString pl_mInterfacing; +extern const QString pl_mInterlining; +extern const QString pl_wCut; +extern const QString pl_wOnFold; + +extern const QStringList labelTemplatePlaceholders; extern const QString cursorArrowOpenHand; extern const QString cursorArrowCloseHand; diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-center.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-center.png new file mode 100755 index 000000000..1196e53fc Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-center.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-left.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-left.png new file mode 100755 index 000000000..7fbdb0ff3 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-left.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-right.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-right.png new file mode 100755 index 000000000..2411b1fd0 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-justify-right.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-text-bold.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-text-bold.png new file mode 100755 index 000000000..f0d0f9725 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-text-bold.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-text-italic.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-text-italic.png new file mode 100755 index 000000000..fba9d06df Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/format-text-italic.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-center.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-center.png new file mode 100755 index 000000000..fceb6f99b Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-center.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-left.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-left.png new file mode 100755 index 000000000..ea8d27706 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-left.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-right.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-right.png new file mode 100755 index 000000000..66ff89675 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-justify-right.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-text-bold.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-text-bold.png new file mode 100755 index 000000000..341110cb2 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-text-bold.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-text-italic.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-text-italic.png new file mode 100755 index 000000000..acf4a9936 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/format-text-italic.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-center.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-center.png new file mode 100755 index 000000000..8665c960c Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-center.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-left.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-left.png new file mode 100755 index 000000000..9b6874828 Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-left.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-right.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-right.png new file mode 100755 index 000000000..a31a3ed9c Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-justify-right.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-text-bold.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-text-bold.png new file mode 100755 index 000000000..f9417f8de Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-text-bold.png differ diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-text-italic.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-text-italic.png new file mode 100755 index 000000000..9bfb2251d Binary files /dev/null and b/src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/format-text-italic.png differ diff --git a/src/libs/vmisc/share/resources/theme.qrc b/src/libs/vmisc/share/resources/theme.qrc index bbca2edc7..a0753b552 100644 --- a/src/libs/vmisc/share/resources/theme.qrc +++ b/src/libs/vmisc/share/resources/theme.qrc @@ -84,5 +84,20 @@ icons/win.icon.theme/16x16/actions/help-about.png icons/win.icon.theme/24x24/actions/help-about.png icons/win.icon.theme/32x32/actions/help-about.png + icons/win.icon.theme/16x16/actions/format-justify-center.png + icons/win.icon.theme/16x16/actions/format-justify-left.png + icons/win.icon.theme/16x16/actions/format-justify-right.png + icons/win.icon.theme/16x16/actions/format-text-bold.png + icons/win.icon.theme/16x16/actions/format-text-italic.png + icons/win.icon.theme/24x24/actions/format-justify-left.png + icons/win.icon.theme/24x24/actions/format-justify-right.png + icons/win.icon.theme/24x24/actions/format-justify-center.png + icons/win.icon.theme/24x24/actions/format-text-bold.png + icons/win.icon.theme/24x24/actions/format-text-italic.png + icons/win.icon.theme/32x32/actions/format-justify-center.png + icons/win.icon.theme/32x32/actions/format-justify-left.png + icons/win.icon.theme/32x32/actions/format-justify-right.png + icons/win.icon.theme/32x32/actions/format-text-bold.png + icons/win.icon.theme/32x32/actions/format-text-italic.png diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index 8ad3b3cf0..0321cf8fd 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -54,6 +54,7 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv) pmsTranslator(nullptr), _patternUnit(Unit::Cm), _patternType(MeasurementsType::Unknown), + patternFilePath(), currentScene(nullptr), sceneView(nullptr), doc(nullptr), diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index 75701e48e..857a143be 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -105,6 +105,9 @@ public: virtual bool IsAppInGUIMode()const =0; + QString GetPPath() const; + void SetPPath(const QString &value); + protected: QUndoStack *undoStack; @@ -131,7 +134,7 @@ private: Q_DISABLE_COPY(VAbstractApplication) Unit _patternUnit; MeasurementsType _patternType; - + QString patternFilePath; QGraphicsScene **currentScene; VMainGraphicsView *sceneView; @@ -147,6 +150,18 @@ private: void ClearTranslation(); }; +//--------------------------------------------------------------------------------------------------------------------- +inline QString VAbstractApplication::GetPPath() const +{ + return patternFilePath; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractApplication::SetPPath(const QString &value) +{ + patternFilePath = value; +} + //--------------------------------------------------------------------------------------------------------------------- template diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 4a38fef82..f8b9f959a 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -45,9 +45,12 @@ #include "../vmisc/vmath.h" #include "../vpatterndb/pmsystems.h" +namespace +{ const QString settingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements"); -const QString settingPathsMultisizeMeasurements = QStringLiteral("paths/standard_measurements"); +const QString settingPathsMultisizeMeasurements = QStringLiteral("paths/standard_measurements"); const QString settingPathsTemplates = QStringLiteral("paths/templates"); +const QString settingPathsLabelTemplate = QStringLiteral("paths/labels"); const QString settingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator"); const QString settingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state"); @@ -60,13 +63,12 @@ const QString settingConfigurationConfirmItemDeletion = QStringLiteral("confi const QString settingConfigurationConfirmFormatRewriting = QStringLiteral("configuration/confirm_format_rewriting"); const QString settingConfigurationToolBarStyle = QStringLiteral("configuration/tool_bar_style"); -const QString settingPatternUser = QStringLiteral("pattern/user"); const QString settingPatternUndo = QStringLiteral("pattern/undo"); const QString settingPatternForbidFlipping = QStringLiteral("pattern/forbidFlipping"); const QString settingPatternHideMainPath = QStringLiteral("pattern/hideMainPath"); const QString settingDoublePassmark = QStringLiteral("pattern/doublePassmark"); const QString settingPatternDefaultSeamAllowance = QStringLiteral("pattern/defaultSeamAllowance"); -const QString settingLabelFont = QStringLiteral("pattern/labelFont"); +const QString settingPatternLabelFont = QStringLiteral("pattern/labelFont"); const QString settingGeneralRecentFileList = QStringLiteral("recentFileList"); const QString settingGeneralRestoreFileList = QStringLiteral("restoreFileList"); @@ -79,12 +81,27 @@ const QString settingIncrementsDialogSize = QStringLiteral("toolIncrement const QString settingFormulaWizardDialogSize = QStringLiteral("formulaWizardDialogSize"); const QString settingLatestSkippedVersion = QStringLiteral("lastestSkippedVersion"); const QString settingDateOfLastRemind = QStringLiteral("dateOfLastRemind"); -const QString settingUserDefinedMaterials = QStringLiteral("configuration/userDefinedMaterials"); const QString settingCSVWithHeader = QStringLiteral("csv/withHeader"); const QString settingCSVCodec = QStringLiteral("csv/withCodec"); const QString settingCSVSeparator = QStringLiteral("csv/withSeparator"); +const QString settingLabelDateFormat = QStringLiteral("label/dateFormat"); +const QString settingLabelUserDateFormats = QStringLiteral("label/userDateFormats"); +const QString settingLabelTimeFormat = QStringLiteral("label/timeFormat"); +const QString settingLabelUserTimeFormats = QStringLiteral("label/userTimeFormats"); + +//--------------------------------------------------------------------------------------------------------------------- +QStringList ClearFormats(const QStringList &predefinedFormats, QStringList formats) +{ + for (int i = 0; i < predefinedFormats.size(); ++i) + { + formats.removeAll(predefinedFormats.at(i)); + } + return formats; +} +} + static const QString commonIniFilename = QStringLiteral("common"); #if !defined(Q_OS_WIN) @@ -314,6 +331,24 @@ void VCommonSettings::SetPathTemplate(const QString &value) settings.sync(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VCommonSettings::GetDefPathLabelTemplate() +{ + return QDir::homePath() + QLatin1String("/valentina/") + tr("label templates"); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VCommonSettings::GetPathLabelTemplate() const +{ + return value(settingPathsLabelTemplate, GetDefPathLabelTemplate()).toString(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetPathLabelTemplate(const QString &value) +{ + setValue(settingPathsLabelTemplate, value); +} + //--------------------------------------------------------------------------------------------------------------------- bool VCommonSettings::GetOsSeparator() const { @@ -443,24 +478,6 @@ void VCommonSettings::SetToolBarStyle(const bool &value) setValue(settingConfigurationToolBarStyle, value); } -//--------------------------------------------------------------------------------------------------------------------- -QString VCommonSettings::GetUser() const -{ - QString user; -#ifdef Q_OS_WIN - user = value(settingPatternUser, QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); -#else - user = value(settingPatternUser, QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); -#endif - return user; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VCommonSettings::SetUser(const QString &value) -{ - setValue(settingPatternUser, value); -} - //--------------------------------------------------------------------------------------------------------------------- int VCommonSettings::GetUndoCount() const { @@ -630,27 +647,6 @@ void VCommonSettings::SetDateOfLastRemind(const QDate &date) settings.sync(); } -//--------------------------------------------------------------------------------------------------------------------- -QStringList VCommonSettings::GetUserDefinedMaterials() const -{ - return value(settingUserDefinedMaterials).toStringList(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VCommonSettings::AddUserDefinedMaterial(QString qsMaterial) -{ - QStringList qsl = GetUserDefinedMaterials(); - qsl << qsMaterial; - setValue(settingUserDefinedMaterials, qsl); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VCommonSettings::ClearUserDefinedMaterial() -{ - QStringList qsl; - setValue(settingUserDefinedMaterials, qsl); -} - //--------------------------------------------------------------------------------------------------------------------- bool VCommonSettings::GetForbidWorkpieceFlipping() const { @@ -828,11 +824,115 @@ double VCommonSettings::GetDefaultSeamAllowance() //--------------------------------------------------------------------------------------------------------------------- QFont VCommonSettings::GetLabelFont() const { - return qvariant_cast(value(settingLabelFont, QApplication::font())); + return qvariant_cast(value(settingPatternLabelFont, QApplication::font())); } //--------------------------------------------------------------------------------------------------------------------- void VCommonSettings::SetLabelFont(const QFont &f) { - setValue(settingLabelFont, f); + setValue(settingPatternLabelFont, f); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VCommonSettings::GetLabelDateFormat() const +{ + const QString format = value(settingLabelDateFormat, VCommonSettings::PredefinedDateFormats().first()).toString(); + const QStringList allFormats = VCommonSettings::PredefinedDateFormats() + GetUserDefinedDateFormats(); + + if (allFormats.contains(format)) + { + return format; + } + else + { + return VCommonSettings::PredefinedDateFormats().first(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetLabelDateFormat(const QString &format) +{ + setValue(settingLabelDateFormat, format); +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VCommonSettings::PredefinedDateFormats() +{ + QStringList formats = QStringList() << "MM-dd-yyyy" + << "d/M/yy" + << "ddddMMMM dd, yyyy" + << "dd/MM/yy" + << "dd/MM/yyyy" + << "MMM d, yy" + << "MMM d, yyyy" + << "d. MMM. yyyy" + << "MMMM d, yyyy" + << "d. MMMM yyyy" + << "ddd, MMM d, yy" + << "ddd dd/MMM yy" + << "ddd, MMMM d, yyyy" + << "ddddMMMM d, yyyy" + << "MM-dd" + << "yy-MM-dd" + << "yyyy-MM-dd" + << "MM/yy" + << "MMM dd" + << "MMMM"; + return formats; +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VCommonSettings::GetUserDefinedDateFormats() const +{ + return value(settingLabelUserDateFormats, QStringList()).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetUserDefinedDateFormats(const QStringList &formats) +{ + setValue(settingLabelUserDateFormats, ClearFormats(VCommonSettings::PredefinedDateFormats(), formats)); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VCommonSettings::GetLabelTimeFormat() const +{ + const QString format = value(settingLabelTimeFormat, VCommonSettings::PredefinedTimeFormats().first()).toString(); + const QStringList allFormats = VCommonSettings::PredefinedTimeFormats() + GetUserDefinedTimeFormats(); + + if (allFormats.contains(format)) + { + return format; + } + else + { + return VCommonSettings::PredefinedTimeFormats().first(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetLabelTimeFormat(const QString &format) +{ + setValue(settingLabelTimeFormat, format); +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VCommonSettings::PredefinedTimeFormats() +{ + QStringList formats = QStringList() << "hh:mm:ss" + << "hh:mm:ss AP" + << "hh:mm" + << "hh:mm AP"; + return formats; +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VCommonSettings::GetUserDefinedTimeFormats() const +{ + return value(settingLabelUserTimeFormats, QStringList()).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetUserDefinedTimeFormats(const QStringList &formats) +{ + setValue(settingLabelUserTimeFormats, ClearFormats(VCommonSettings::PredefinedTimeFormats(), formats)); } diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index fb2c79bba..6f16ebbb6 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -66,6 +66,10 @@ public: QString GetPathTemplate() const; void SetPathTemplate(const QString &value); + static QString GetDefPathLabelTemplate(); + QString GetPathLabelTemplate() const; + void SetPathLabelTemplate(const QString &value); + bool GetOsSeparator() const; void SetOsSeparator(const bool &value); @@ -96,9 +100,6 @@ public: bool GetToolBarStyle() const; void SetToolBarStyle(const bool &value); - QString GetUser() const; - void SetUser(const QString &value); - int GetUndoCount() const; void SetUndoCount(const int &value); @@ -135,10 +136,6 @@ public: QDate GetDateOfLastRemind() const; void SetDateOfLastRemind(const QDate &date); - QStringList GetUserDefinedMaterials() const; - void AddUserDefinedMaterial(QString qsMaterial); - void ClearUserDefinedMaterial(); - bool GetForbidWorkpieceFlipping() const; void SetForbidWorkpieceFlipping(bool value); @@ -170,6 +167,20 @@ public: static const QString unixStandardSharePath; #endif + QString GetLabelDateFormat() const; + void SetLabelDateFormat(const QString &format); + + static QStringList PredefinedDateFormats(); + QStringList GetUserDefinedDateFormats() const; + void SetUserDefinedDateFormats(const QStringList &formats); + + QString GetLabelTimeFormat() const; + void SetLabelTimeFormat(const QString &format); + + static QStringList PredefinedTimeFormats(); + QStringList GetUserDefinedTimeFormats() const; + void SetUserDefinedTimeFormats(const QStringList &formats); + private: Q_DISABLE_COPY(VCommonSettings) }; diff --git a/src/libs/vpatterndb/floatItemData/floatitemdef.h b/src/libs/vpatterndb/floatItemData/floatitemdef.h index 6807a3379..d66890a86 100644 --- a/src/libs/vpatterndb/floatItemData/floatitemdef.h +++ b/src/libs/vpatterndb/floatItemData/floatitemdef.h @@ -40,40 +40,5 @@ enum class ArrowType : char atRear }; -enum class MaterialType : char -{ - mtFabric = 0, - mtLining = 1, - mtInterfacing = 2, - mtInterlining = 3, - mtUserDefined = 4 -}; - -enum class PlacementType : char -{ - ptNone = 0, - ptCutOnFold = 1 -}; - -/** - * @brief The MaterialCutPlacement struct used to hold a material, cut number and placement 3-tuple - */ -struct MaterialCutPlacement -{ - MaterialType m_eMaterial; - QString m_qsMaterialUserDef; - int m_iCutNumber; - PlacementType m_ePlacement; - - MaterialCutPlacement() - : m_eMaterial(MaterialType::mtFabric), - m_qsMaterialUserDef(), - m_iCutNumber(0), - m_ePlacement(PlacementType::ptNone) - {} -}; - -typedef QList MCPContainer; - #endif // FLOATITEMDEF_H diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp index 06d641933..6b5da058d 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp @@ -59,65 +59,119 @@ VPieceLabelData &VPieceLabelData::operator=(const VPieceLabelData &data) VPieceLabelData::~VPieceLabelData() {} -//--------------------------------------------------------------------------------------------------------------------- -void VPieceLabelData::Append(const MaterialCutPlacement& rMCP) -{ - d->m_conMCP.append(rMCP); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceLabelData::Insert(int i, const MaterialCutPlacement& rMCP) -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i <= GetMCPCount()); - d->m_conMCP.insert(i, rMCP); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceLabelData::Set(int i, const MaterialCutPlacement& rMCP) -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i < GetMCPCount()); - d->m_conMCP[i] = rMCP; -} - -//--------------------------------------------------------------------------------------------------------------------- -int VPieceLabelData::GetMCPCount() const -{ - return d->m_conMCP.count(); -} - -//--------------------------------------------------------------------------------------------------------------------- -const MaterialCutPlacement& VPieceLabelData::GetMCP(int i) const -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i < GetMCPCount()); - return d->m_conMCP.at(i); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceLabelData::RemoveMCP(int i) -{ - Q_ASSERT(i >= 0); - Q_ASSERT(i < GetMCPCount()); - d->m_conMCP.removeAt(i); -} - //--------------------------------------------------------------------------------------------------------------------- void VPieceLabelData::Clear() { d->m_qsLetter.clear(); - d->m_conMCP.clear(); } //--------------------------------------------------------------------------------------------------------------------- -const QString& VPieceLabelData::GetLetter() const +QString VPieceLabelData::GetLetter() const { return d->m_qsLetter; } //--------------------------------------------------------------------------------------------------------------------- -void VPieceLabelData::SetLetter(QString qsLetter) +void VPieceLabelData::SetLetter(const QString &qsLetter) { d->m_qsLetter = qsLetter.left(3); } + +//--------------------------------------------------------------------------------------------------------------------- +QString VPieceLabelData::GetAnnotation() const +{ + return d->m_annotation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetAnnotation(const QString &val) +{ + d->m_annotation = val; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPieceLabelData::GetOrientation() const +{ + return d->m_orientation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetOrientation(const QString &val) +{ + d->m_orientation = val; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPieceLabelData::GetRotation() const +{ + return d->m_rotation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetRotation(const QString &val) +{ + d->m_rotation = val; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPieceLabelData::GetTilt() const +{ + return d->m_tilt; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetTilt(const QString &val) +{ + d->m_tilt = val; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPieceLabelData::GetFoldPosition() const +{ + return d->m_foldPosition; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetFoldPosition(const QString &val) +{ + d->m_foldPosition = val; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPieceLabelData::GetQuantity() const +{ + return d->m_quantity; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetQuantity(int val) +{ + if (val >= 1) + { + d->m_quantity = val; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPieceLabelData::IsOnFold() const +{ + return d->m_onFold; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetOnFold(bool onFold) +{ + d->m_onFold = onFold; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPieceLabelData::GetLabelTemplate() const +{ + return d->m_lines; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetLabelTemplate(const QVector &lines) +{ + d->m_lines = lines; +} diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h index 5831c2626..087184d30 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h @@ -35,6 +35,7 @@ #include "floatitemdef.h" class VPieceLabelDataPrivate; +class VLabelTemplateLine; /** * @brief The VPieceLabelData class holds some information about a single @@ -56,18 +57,35 @@ public: void Swap(VPieceLabelData &data) Q_DECL_NOTHROW { VPatternLabelData::Swap(data); std::swap(d, data.d); } - // methods, which operate on MaterialCutPlacement container - void Append(const MaterialCutPlacement& rMCP); - void Insert(int i, const MaterialCutPlacement& rMCP); - void Set(int i, const MaterialCutPlacement& rMCP); - int GetMCPCount() const; - const MaterialCutPlacement& GetMCP(int i) const; - void RemoveMCP(int i); - void Clear(); + void Clear(); // methods, which operate on other members - const QString& GetLetter() const; - void SetLetter(QString qsLetter); + QString GetLetter() const; + void SetLetter(const QString &qsLetter); + + QString GetAnnotation() const; + void SetAnnotation(const QString &val); + + QString GetOrientation() const; + void SetOrientation(const QString &val); + + QString GetRotation() const; + void SetRotation(const QString &val); + + QString GetTilt() const; + void SetTilt(const QString &val); + + QString GetFoldPosition() const; + void SetFoldPosition(const QString &val); + + int GetQuantity() const; + void SetQuantity(int val); + + bool IsOnFold() const; + void SetOnFold(bool onFold); + + QVector GetLabelTemplate() const; + void SetLabelTemplate(const QVector &lines); private: QSharedDataPointer d; diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h index d2ea60154..23ff02908 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h @@ -31,9 +31,11 @@ #include #include +#include #include "../vmisc/diagnostic.h" #include "floatitemdef.h" +#include "../ifc/ifcdef.h" QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -44,21 +46,43 @@ class VPieceLabelDataPrivate : public QSharedData public: VPieceLabelDataPrivate() : m_qsLetter(), - m_conMCP() + m_annotation(), + m_orientation(), + m_rotation(), + m_tilt(), + m_foldPosition(), + m_quantity(1), + m_onFold(false), + m_lines() {} VPieceLabelDataPrivate(const VPieceLabelDataPrivate &data) : QSharedData(data), m_qsLetter(data.m_qsLetter), - m_conMCP(data.m_conMCP) + m_annotation(data.m_annotation), + m_orientation(data.m_orientation), + m_rotation(data.m_rotation), + m_tilt(data.m_tilt), + m_foldPosition(data.m_foldPosition), + m_quantity(data.m_quantity), + m_onFold(data.m_onFold), + m_lines(data.m_lines) {} ~VPieceLabelDataPrivate() Q_DECL_EQ_DEFAULT; /** @brief m_qsLetter Detail letter (should be no more than 3 characters) */ - QString m_qsLetter; - /** @brief m_conMCP List of material, cut, placement tuples */ - MCPContainer m_conMCP; + QString m_qsLetter; + QString m_annotation; + QString m_orientation; + QString m_rotation; + QString m_tilt; + QString m_foldPosition; + + int m_quantity; + bool m_onFold; + + QVector m_lines; private: VPieceLabelDataPrivate &operator=(const VPieceLabelDataPrivate &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vpatterndb/measurements.cpp b/src/libs/vpatterndb/measurements.cpp index 26a696fe4..45f70bfc5 100644 --- a/src/libs/vpatterndb/measurements.cpp +++ b/src/libs/vpatterndb/measurements.cpp @@ -96,7 +96,11 @@ const QString highhipCirc_M = QStringLiteral("highhip_circ"); / const QString hipCirc_M = QStringLiteral("hip_circ"); // G09 const QString neckArcF_M = QStringLiteral("neck_arc_f"); // G10 const QString highbustArcF_M = QStringLiteral("highbust_arc_f"); // G11 + +// size and bust_arc_f are synonyms +const QString size_M = QStringLiteral("size"); // G12 const QString bustArcF_M = QStringLiteral("bust_arc_f"); // G12 + const QString lowbustArcF_M = QStringLiteral("lowbust_arc_f"); // G13 const QString ribArcF_M = QStringLiteral("rib_arc_f"); // G14 const QString waistArcF_M = QStringLiteral("waist_arc_f"); // G15 @@ -400,6 +404,7 @@ QStringList ListGroupG() << neckArcF_M // G10 << highbustArcF_M // G11 << bustArcF_M // G12 + << size_M // G12 << lowbustArcF_M // G13 << ribArcF_M // G14 << waistArcF_M // G15 @@ -794,47 +799,48 @@ QString MapDiagrams(const VTranslateMeasurements *trM, const QString &number) case 9: // G10 case 10: // G11 case 11: // G12 - case 12: // G13 - case 13: // G14 - case 14: // G15 - case 15: // G16 - case 16: // G17 + case 12: // G12 + case 13: // G13 + case 14: // G14 + case 15: // G15 + case 16: // G16 + case 17: // G17 return QStringLiteral("Gp2"); - case 17: // G18 - case 18: // G19 - case 19: // G20 - case 20: // G21 - case 21: // G22 - case 22: // G23 - case 23: // G24 - case 24: // G25 + case 18: // G18 + case 19: // G19 + case 20: // G20 + case 21: // G21 + case 22: // G22 + case 23: // G23 + case 24: // G24 + case 25: // G25 return QStringLiteral("Gp3"); - case 25: // G26 - case 26: // G27 - case 27: // G28 - case 28: // G29 - case 29: // G30 - case 30: // G31 - case 31: // G32 - case 32: // G33 + case 26: // G26 + case 27: // G27 + case 28: // G28 + case 29: // G29 + case 30: // G30 + case 31: // G31 + case 32: // G32 + case 33: // G33 return QStringLiteral("Gp4"); - case 33: // G34 - case 34: // G35 - case 35: // G36 - case 36: // G37 - case 37: // G38 - case 38: // G39 - case 39: // G40 - case 40: // G41 + case 34: // G34 + case 35: // G35 + case 36: // G36 + case 37: // G37 + case 38: // G38 + case 39: // G39 + case 40: // G40 + case 41: // G41 return QStringLiteral("Gp5"); - case 41: // G42 + case 42: // G42 return QStringLiteral("Gp6"); - case 42: // G43 - case 43: // G44 + case 43: // G43 + case 44: // G44 return QStringLiteral("Gp7"); - case 44: // G45 + case 45: // G45 return QStringLiteral("Gp8"); - case 45: // G46 + case 46: // G46 return QStringLiteral("Gp9"); default: break; diff --git a/src/libs/vpatterndb/measurements.h b/src/libs/vpatterndb/measurements.h index e63875104..8d034b923 100644 --- a/src/libs/vpatterndb/measurements.h +++ b/src/libs/vpatterndb/measurements.h @@ -98,7 +98,11 @@ extern const QString highhipCirc_M; // G08 extern const QString hipCirc_M; // G09 extern const QString neckArcF_M; // G10 extern const QString highbustArcF_M; // G11 + +// size and bust_arc_f are synonyms +extern const QString size_M; // G12 extern const QString bustArcF_M; // G12 + extern const QString lowbustArcF_M; // G13 extern const QString ribArcF_M; // G14 extern const QString waistArcF_M; // G15 diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 3b75520f8..11f116c79 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -610,18 +610,6 @@ const VTranslateVars *VContainer::GetTrVars() const return d->trVars; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VariableExist check if exist variable this same name. - * @param name name of row - * @return true if contains - */ -// cppcheck-suppress unusedFunction -bool VContainer::VariableExist(const QString &name) -{ - return d->variables.contains(name); -} - //--------------------------------------------------------------------------------------------------------------------- template const QMap > VContainer::DataVar(const VarType &type) const diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 4311e92f0..6f5e882a6 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -178,8 +178,6 @@ public: static qreal height(); static qreal *rheight(); - bool VariableExist(const QString& name); - void RemoveIncrement(const QString& name); const QHash > *DataGObjects() const; diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 9a2cc340c..3f3c99f94 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -104,11 +104,11 @@ public: QVector MissingInternalPaths(const VPiece &det) const; QVector MissingPins(const VPiece &det) const; - void SetPatternPieceData(const VPieceLabelData &data); + void SetPatternPieceData(const VPieceLabelData &data); VPieceLabelData& GetPatternPieceData(); const VPieceLabelData& GetPatternPieceData() const; - void SetPatternInfo(const VPatternLabelData &info); + void SetPatternInfo(const VPatternLabelData &info); VPatternLabelData& GetPatternInfo(); const VPatternLabelData& GetPatternInfo() const; diff --git a/src/libs/vpatterndb/vtranslatemeasurements.cpp b/src/libs/vpatterndb/vtranslatemeasurements.cpp index f1bc8b6ef..44dead041 100644 --- a/src/libs/vpatterndb/vtranslatemeasurements.cpp +++ b/src/libs/vpatterndb/vtranslatemeasurements.cpp @@ -669,6 +669,13 @@ void VTranslateMeasurements::InitGroupG() "Full measurement description."); InitMeasurement(bustArcF_M, m, g, d, "G12"); //================================================================================================================= + m = translate("VTranslateMeasurements", "size", + "Name in a formula. Don't use math symbols and space in name!!!!"); + g = translate("VTranslateMeasurements", "Size", "Full measurement name."); + d = translate("VTranslateMeasurements", "Same as bust_arc_f.", + "Full measurement description."); + InitMeasurement(size_M, m, g, d, "G12"); + //================================================================================================================= m = translate("VTranslateMeasurements", "lowbust_arc_f", "Name in a formula. Don't use math symbols and space in name!!!!"); g = translate("VTranslateMeasurements", "Lowbust arc, front", "Full measurement name."); diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index 22810a645..a672e7e18 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -457,8 +457,32 @@ void VTranslateVars::InitPostfixOperators() //--------------------------------------------------------------------------------------------------------------------- void VTranslateVars::InitPlaceholder() { - placeholders.insert(pl_size, translate("VTranslateVars", "size", "placeholder")); - placeholders.insert(pl_height, translate("VTranslateVars", "height", "placeholder")); + placeholders.insert(pl_size, translate("VTranslateVars", "size", "placeholder")); + placeholders.insert(pl_height, translate("VTranslateVars", "height", "placeholder")); + placeholders.insert(pl_date, translate("VTranslateVars", "date", "placeholder")); + placeholders.insert(pl_time, translate("VTranslateVars", "time", "placeholder")); + placeholders.insert(pl_patternName, translate("VTranslateVars", "patternName", "placeholder")); + placeholders.insert(pl_patternNumber, translate("VTranslateVars", "patternNumber", "placeholder")); + placeholders.insert(pl_author, translate("VTranslateVars", "author", "placeholder")); + placeholders.insert(pl_customer, translate("VTranslateVars", "customer", "placeholder")); + placeholders.insert(pl_pExt, translate("VTranslateVars", "pExt", "placeholder")); + placeholders.insert(pl_pFileName, translate("VTranslateVars", "pFileName", "placeholder")); + placeholders.insert(pl_mFileName, translate("VTranslateVars", "mFileName", "placeholder")); + placeholders.insert(pl_mExt, translate("VTranslateVars", "mExt", "placeholder")); + placeholders.insert(pl_pLetter, translate("VTranslateVars", "pLetter", "placeholder")); + placeholders.insert(pl_pAnnotation, translate("VTranslateVars", "pAnnotation", "placeholder")); + placeholders.insert(pl_pOrientation, translate("VTranslateVars", "pOrientation", "placeholder")); + placeholders.insert(pl_pRotation, translate("VTranslateVars", "pRotation", "placeholder")); + placeholders.insert(pl_pTilt, translate("VTranslateVars", "pTilt", "placeholder")); + placeholders.insert(pl_pFoldPosition, translate("VTranslateVars", "pFoldPosition", "placeholder")); + placeholders.insert(pl_pName, translate("VTranslateVars", "pName", "placeholder")); + placeholders.insert(pl_pQuantity, translate("VTranslateVars", "pQuantity", "placeholder")); + placeholders.insert(pl_mFabric, translate("VTranslateVars", "mFabric", "placeholder")); + placeholders.insert(pl_mLining, translate("VTranslateVars", "mLining", "placeholder")); + placeholders.insert(pl_mInterfacing, translate("VTranslateVars", "mInterfacing", "placeholder")); + placeholders.insert(pl_mInterlining, translate("VTranslateVars", "mInterlining", "placeholder")); + placeholders.insert(pl_wCut, translate("VTranslateVars", "wCut", "placeholder")); + placeholders.insert(pl_wOnFold, translate("VTranslateVars", "wOnFold", "placeholder")); } #undef translate @@ -673,6 +697,44 @@ QString VTranslateVars::PlaceholderToUser(const QString &var) const return var; } +//--------------------------------------------------------------------------------------------------------------------- +QString VTranslateVars::PlaceholderToUserText(QString text) const +{ + QChar per('%'); + auto i = placeholders.constBegin(); + while (i != placeholders.constEnd()) + { + const QString translated = per + i.value().translate() + per; + const QString original = per + i.key() + per; + + if (translated != original) + { + text.replace(original, translated); + } + ++i; + } + return text; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VTranslateVars::PlaceholderFromUserText(QString text) const +{ + QChar per('%'); + auto i = placeholders.constBegin(); + while (i != placeholders.constEnd()) + { + const QString translated = per + i.value().translate() + per; + const QString original = per + i.key() + per; + + if (translated != original) + { + text.replace(translated, original); + } + ++i; + } + return text; +} + //--------------------------------------------------------------------------------------------------------------------- QString VTranslateVars::VarToUser(const QString &var) const { diff --git a/src/libs/vpatterndb/vtranslatevars.h b/src/libs/vpatterndb/vtranslatevars.h index a8a8213d9..1ac8a7c68 100644 --- a/src/libs/vpatterndb/vtranslatevars.h +++ b/src/libs/vpatterndb/vtranslatevars.h @@ -48,6 +48,9 @@ public: QString InternalVarToUser(const QString &var) const; QString PlaceholderToUser(const QString &var) const; + QString PlaceholderToUserText(QString text) const; + QString PlaceholderFromUserText(QString text) const; + QString VarToUser(const QString &var) const; QString VarFromUser(const QString &var) const; diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 8678e3bfb..5d2fad588 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -45,7 +45,8 @@ HEADERS += \ $$PWD/tools/piece/dialogseamallowance.h \ $$PWD/tools/piece/dialogpiecepath.h \ $$PWD/tools/dialogpin.h \ - $$PWD/tools/dialoginsertnode.h + $$PWD/tools/dialoginsertnode.h \ + $$PWD/support/dialogeditlabel.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -90,7 +91,8 @@ SOURCES += \ $$PWD/tools/piece/dialogseamallowance.cpp \ $$PWD/tools/piece/dialogpiecepath.cpp \ $$PWD/tools/dialogpin.cpp \ - $$PWD/tools/dialoginsertnode.cpp + $$PWD/tools/dialoginsertnode.cpp \ + $$PWD/support/dialogeditlabel.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -139,4 +141,5 @@ FORMS += \ $$PWD/tools/piece/tabs/tabgrainline.ui \ $$PWD/tools/piece/tabs/tabpins.ui \ $$PWD/tools/dialoginsertnode.ui \ - $$PWD/tools/piece/tabs/tabpassmarks.ui + $$PWD/tools/piece/tabs/tabpassmarks.ui \ + $$PWD/support/dialogeditlabel.ui diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp new file mode 100644 index 000000000..c59ad9733 --- /dev/null +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -0,0 +1,639 @@ +/************************************************************************ + ** + ** @file dialogeditlabel.cpp + ** @author Roman Telezhynskyi + ** @date 11 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogeditlabel.h" +#include "ui_dialogeditlabel.h" +#include "../vmisc/vabstractapplication.h" +#include "../vformat/vlabeltemplate.h" +#include "../ifc/xml/vlabeltemplateconverter.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../ifc/exception/vexception.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vpiece.h" +#include "../vpatterndb/floatItemData/vpiecelabeldata.h" + +#include +#include +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogEditLabel::DialogEditLabel(VAbstractPattern *doc, QWidget *parent) + : QDialog(parent), + ui(new Ui::DialogEditLabel), + m_placeholdersMenu(new QMenu(this)), + m_doc(doc), + m_placeholders() +{ + ui->setupUi(this); + + ui->lineEditLine->setClearButtonEnabled(true); + + connect(ui->toolButtonAdd, &QToolButton::clicked, this, &DialogEditLabel::AddLine); + connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogEditLabel::RemoveLine); + connect(ui->lineEditLine, &QLineEdit::textEdited, this, &DialogEditLabel::SaveLineText); + connect(ui->toolButtonBold, &QToolButton::toggled, this, &DialogEditLabel::SaveFontStyle); + connect(ui->toolButtonItalic, &QToolButton::toggled, this, &DialogEditLabel::SaveFontStyle); + connect(ui->toolButtonTextLeft, &QToolButton::toggled, this, &DialogEditLabel::SaveTextFormating); + connect(ui->toolButtonTextCenter, &QToolButton::toggled, this, &DialogEditLabel::SaveTextFormating); + connect(ui->toolButtonTextRight, &QToolButton::toggled, this, &DialogEditLabel::SaveTextFormating); + connect(ui->listWidgetEdit, &QListWidget::itemSelectionChanged, this, &DialogEditLabel::ShowLineDetails); + connect(ui->tabWidget, &QTabWidget::currentChanged, this, &DialogEditLabel::TabChanged); + connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate); + connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate); + connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &DialogEditLabel::ImportTemplate); + connect(ui->spinBoxFontSize, static_cast(&QSpinBox::valueChanged), this, + &DialogEditLabel::SaveAdditionalFontSize); + + InitPlaceholders(); + InitPlaceholdersMenu(); + + ui->pushButtonInsert->setMenu(m_placeholdersMenu); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogEditLabel::~DialogEditLabel() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::ShowLineDetails() +{ + if (ui->listWidgetEdit->count() > 0) + { + const QListWidgetItem *line = ui->listWidgetEdit->currentItem(); + if (line) + { + ui->lineEditLine->blockSignals(true); + ui->lineEditLine->setText(line->text()); + ui->lineEditLine->blockSignals(false); + + const QFont lineFont = line->font(); + + ui->toolButtonBold->blockSignals(true); + ui->toolButtonBold->setChecked(lineFont.bold()); + ui->toolButtonBold->blockSignals(false); + + ui->toolButtonItalic->blockSignals(true); + ui->toolButtonItalic->setChecked(lineFont.italic()); + ui->toolButtonItalic->blockSignals(false); + + ui->toolButtonTextLeft->blockSignals(true); + ui->toolButtonTextCenter->blockSignals(true); + ui->toolButtonTextRight->blockSignals(true); + + const int lineAlignment = line->textAlignment(); + + if (lineAlignment == 0 || lineAlignment & Qt::AlignLeft) + { + ui->toolButtonTextLeft->setChecked(true); + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else if (lineAlignment & Qt::AlignHCenter) + { + ui->toolButtonTextLeft->setChecked(false); + ui->toolButtonTextCenter->setChecked(true); + ui->toolButtonTextRight->setChecked(false); + } + else if (lineAlignment & Qt::AlignRight) + { + ui->toolButtonTextLeft->setChecked(false); + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(true); + } + + ui->toolButtonTextLeft->blockSignals(false); + ui->toolButtonTextCenter->blockSignals(false); + ui->toolButtonTextRight->blockSignals(false); + + ui->spinBoxFontSize->blockSignals(true); + ui->spinBoxFontSize->setValue(line->data(Qt::UserRole).toInt()); + ui->spinBoxFontSize->blockSignals(false); + } + } + + SetupControls(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::AddLine() +{ + int row = ui->listWidgetEdit->currentRow(); + ui->listWidgetEdit->insertItem(++row, new QListWidgetItem(tr(""))); + ui->listWidgetEdit->setCurrentRow(row); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::RemoveLine() +{ + ui->listWidgetEdit->blockSignals(true); + QListWidgetItem *curLine = ui->listWidgetEdit->takeItem(ui->listWidgetEdit->currentRow()); + if (curLine) + { + delete curLine; + } + ui->listWidgetEdit->blockSignals(false); + ShowLineDetails(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SaveLineText(const QString &text) +{ + QListWidgetItem *curLine = ui->listWidgetEdit->currentItem(); + if (curLine) + { + curLine->setText(text); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SaveFontStyle(bool checked) +{ + QListWidgetItem *curLine = ui->listWidgetEdit->currentItem(); + if (curLine) + { + QFont lineFont = curLine->font(); + + QToolButton *button = qobject_cast(sender()); + if (button) + { + if (button == ui->toolButtonBold) + { + lineFont.setBold(checked); + } + else if (button == ui->toolButtonItalic) + { + lineFont.setItalic(checked); + } + } + + curLine->setFont(lineFont); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SaveTextFormating(bool checked) +{ + QListWidgetItem *curLine = ui->listWidgetEdit->currentItem(); + if (curLine) + { + QToolButton *button = qobject_cast(sender()); + if (button) + { + ui->toolButtonTextLeft->blockSignals(true); + ui->toolButtonTextCenter->blockSignals(true); + ui->toolButtonTextRight->blockSignals(true); + + if (button == ui->toolButtonTextLeft) + { + if (checked) + { + curLine->setTextAlignment(Qt::AlignLeft); + + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else + { + button->setChecked(true); + } + } + else if (button == ui->toolButtonTextCenter) + { + if (checked) + { + curLine->setTextAlignment(Qt::AlignHCenter); + + ui->toolButtonTextLeft->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else + { + button->setChecked(true); + } + } + else if (button == ui->toolButtonTextRight) + { + if (checked) + { + curLine->setTextAlignment(Qt::AlignRight); + + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else + { + button->setChecked(true); + } + } + + ui->toolButtonTextLeft->blockSignals(false); + ui->toolButtonTextCenter->blockSignals(false); + ui->toolButtonTextRight->blockSignals(false); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::NewTemplate() +{ + if (ui->listWidgetEdit->count() > 0) + { + const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Create new template"), + tr("Creating new template will overwrite the current, do " + "you want to continue?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (answer == QMessageBox::No) + { + return; + } + } + + ui->listWidgetEdit->blockSignals(true); + ui->listWidgetEdit->clear(); + ui->listWidgetEdit->blockSignals(false); + ShowLineDetails(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::ExportTemplate() +{ + QString filters(tr("Label template") + QLatin1String("(*.xml)")); + QString dir = qApp->Settings()->GetPathLabelTemplate(); + + bool usedNotExistedDir = false; + QDir directory(dir); + if (not directory.exists()) + { + usedNotExistedDir = directory.mkpath("."); + } + + QString fileName = QFileDialog::getSaveFileName(this, tr("Export label template"), + dir + QLatin1String("/") + tr("template") + QLatin1String(".xml"), + filters, nullptr, QFileDialog::DontUseNativeDialog); + + auto RemoveTempDir = [usedNotExistedDir, dir]() + { + if (usedNotExistedDir) + { + QDir directory(dir); + directory.rmpath("."); + } + }; + + if (fileName.isEmpty()) + { + RemoveTempDir(); + return; + } + + QFileInfo f( fileName ); + if (f.suffix().isEmpty() && f.suffix() != QLatin1String("xml")) + { + fileName += QLatin1String(".xml"); + } + + VLabelTemplate ltemplate; + ltemplate.CreateEmptyTemplate(); + ltemplate.AddLines(GetTemplate()); + + QString error; + const bool result = ltemplate.SaveDocument(fileName, error); + if (result == false) + { + QMessageBox messageBox(this); + messageBox.setIcon(QMessageBox::Warning); + messageBox.setInformativeText(tr("Could not save file")); + messageBox.setDefaultButton(QMessageBox::Ok); + messageBox.setDetailedText(error); + messageBox.setStandardButtons(QMessageBox::Ok); + messageBox.exec(); + } + + RemoveTempDir(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::ImportTemplate() +{ + if (ui->listWidgetEdit->count() > 0) + { + const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Import template"), + tr("Import template will overwrite the current, do " + "you want to continue?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (answer == QMessageBox::No) + { + return; + } + } + + QString filter(tr("Label template") + QLatin1String("(*.xml)")); + const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), + qApp->Settings()->GetPathLabelTemplate(), filter, nullptr, + QFileDialog::DontUseNativeDialog); + if (fileName.isEmpty()) + { + return; + } + + try + { + VLabelTemplate ltemplate; + ltemplate.setXMLContent(VLabelTemplateConverter(fileName).Convert()); + SetTemplate(ltemplate.ReadLines()); + } + catch (VException &e) + { + qCritical("%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), qUtf8Printable(e.ErrorMessage()), + qUtf8Printable(e.DetailedInformation())); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::InsertPlaceholder() +{ + QAction *action = qobject_cast(sender()); + if (action) + { + ui->lineEditLine->insert(action->data().toString()); + ui->lineEditLine->setFocus(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::TabChanged(int index) +{ + if (index == ui->tabWidget->indexOf(ui->tabPreview)) + { + ui->toolButtonNewLabel->setDisabled(true); + ui->toolButtonImportLabel->setDisabled(true); + InitPreviewLines(GetTemplate()); + } + else + { + ui->toolButtonNewLabel->setEnabled(ui->listWidgetEdit->count() > 0); + ui->toolButtonImportLabel->setEnabled(true); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SaveAdditionalFontSize(int i) +{ + QListWidgetItem *curLine = ui->listWidgetEdit->currentItem(); + if (curLine) + { + QFont lineFont = curLine->font(); + lineFont.setPointSize(lineFont.pointSize() - curLine->data(Qt::UserRole).toInt() + i); + curLine->setFont(lineFont); + curLine->setData(Qt::UserRole, i); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SetupControls() +{ + const bool enabled = ui->listWidgetEdit->count() > 0; + + if (not enabled) + { + ui->lineEditLine->blockSignals(true); + ui->lineEditLine->clear(); + ui->lineEditLine->blockSignals(false); + } + + ui->toolButtonAdd->setEnabled(true); + ui->toolButtonImportLabel->setEnabled(true); + + ui->toolButtonRemove->setEnabled(enabled); + ui->toolButtonBold->setEnabled(enabled); + ui->toolButtonItalic->setEnabled(enabled); + ui->toolButtonTextLeft->setEnabled(enabled); + ui->toolButtonTextCenter->setEnabled(enabled); + ui->toolButtonTextRight->setEnabled(enabled); + ui->pushButtonInsert->setEnabled(enabled); + ui->toolButtonNewLabel->setEnabled(enabled); + ui->toolButtonExportLabel->setEnabled(enabled); + ui->lineEditLine->setEnabled(enabled); + ui->spinBoxFontSize->setEnabled(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::InitPlaceholdersMenu() +{ + QChar per('%'); + auto i = m_placeholders.constBegin(); + while (i != m_placeholders.constEnd()) + { + auto value = i.value(); + QAction *action = m_placeholdersMenu->addAction(value.first); + action->setData(per + qApp->TrVars()->PlaceholderToUser(i.key()) + per); + connect(action, &QAction::triggered, this, &DialogEditLabel::InsertPlaceholder); + ++i; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::InitPlaceholders() +{ + // Pattern tags + QLocale locale(qApp->Settings()->GetLocale()); + + const QString date = locale.toString(QDate::currentDate(), m_doc->GetLabelDateFormat()); + m_placeholders.insert(pl_date, qMakePair(tr("Date"), date)); + + const QString time = locale.toString(QTime::currentTime(), m_doc->GetLabelTimeFormat()); + m_placeholders.insert(pl_time, qMakePair(tr("Time"), time)); + + m_placeholders.insert(pl_patternName, qMakePair(tr("Pattern name"), m_doc->GetPatternName())); + m_placeholders.insert(pl_patternNumber, qMakePair(tr("Pattern number"), m_doc->GetPatternNumber())); + m_placeholders.insert(pl_author, qMakePair(tr("Company name or designer name"), + m_doc->GetCompanyName())); + m_placeholders.insert(pl_customer, qMakePair(tr("Customer name"), m_doc->GetCustomerName())); + m_placeholders.insert(pl_pExt, qMakePair(tr("Pattern extension"), QString("val"))); + + const QString patternFilePath = QFileInfo(qApp->GetPPath()).baseName(); + m_placeholders.insert(pl_pFileName, qMakePair(tr("Pattern file name"), patternFilePath)); + + const QString measurementsFilePath = QFileInfo(m_doc->MPath()).baseName(); + m_placeholders.insert(pl_mFileName, qMakePair(tr("Measurments file name"), measurementsFilePath)); + + QString curSize; + QString curHeight; + QString mExt; + if (qApp->patternType() == MeasurementsType::Multisize) + { + curSize = QString::number(VContainer::size()); + curHeight = QString::number(VContainer::height()); + mExt = "vst"; + } + else if (qApp->patternType() == MeasurementsType::Individual) + { + curSize = QString::number(VContainer::size()); + curHeight = QString::number(VContainer::height()); + mExt = "vit"; + } + + m_placeholders.insert(pl_size, qMakePair(tr("Size"), curSize)); + m_placeholders.insert(pl_height, qMakePair(tr("Height"), curHeight)); + m_placeholders.insert(pl_mExt, qMakePair(tr("Measurments extension"), mExt)); + + // Piece tags + m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString(""))); + m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString(""))); + m_placeholders.insert(pl_pOrientation, qMakePair(tr("Piece orientation"), QString(""))); + m_placeholders.insert(pl_pRotation, qMakePair(tr("Piece rotation"), QString(""))); + m_placeholders.insert(pl_pTilt, qMakePair(tr("Piece tilt"), QString(""))); + m_placeholders.insert(pl_pFoldPosition, qMakePair(tr("Piece fold position"), QString(""))); + m_placeholders.insert(pl_pName, qMakePair(tr("Piece name"), QString(""))); + m_placeholders.insert(pl_pQuantity, qMakePair(tr("Quantity"), QString(""))); + m_placeholders.insert(pl_mFabric, qMakePair(tr("Material: Fabric"), tr("Fabric"))); + m_placeholders.insert(pl_mLining, qMakePair(tr("Material: Lining"), tr("Lining"))); + m_placeholders.insert(pl_mInterfacing, qMakePair(tr("Material: Interfacing"), tr("Interfacing"))); + m_placeholders.insert(pl_mInterlining, qMakePair(tr("Material: Interlining"), tr("Interlining"))); + m_placeholders.insert(pl_wCut, qMakePair(tr("Word: Cut"), tr("Cut"))); + m_placeholders.insert(pl_wOnFold, qMakePair(tr("Word: on fold"), QString("")));// By default should be empty +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogEditLabel::ReplacePlaceholders(QString line) const +{ + auto i = m_placeholders.constBegin(); + while (i != m_placeholders.constEnd()) + { + line.replace(QChar('%')+i.key()+QChar('%'), i.value().second); + ++i; + } + return line; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogEditLabel::GetTemplate() const +{ + QVector lines; + + for (int i=0; ilistWidgetEdit->count(); ++i) + { + const QListWidgetItem *lineItem = ui->listWidgetEdit->item(i); + if (lineItem) + { + VLabelTemplateLine line; + line.line = qApp->TrVars()->PlaceholderFromUserText(lineItem->text()); + line.alignment = lineItem->textAlignment(); + line.fontSizeIncrement = lineItem->data(Qt::UserRole).toInt(); + + const QFont font = lineItem->font(); + line.bold = font.bold(); + line.italic = font.italic(); + + lines.append(line); + } + } + + return lines; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SetTemplate(const QVector &lines) +{ + ui->listWidgetEdit->blockSignals(true); + ui->listWidgetEdit->clear(); + + int row = -1; + + for (int i=0; iTrVars()->PlaceholderToUserText(lines.at(i).line)); + item->setTextAlignment(lines.at(i).alignment); + item->setData(Qt::UserRole, lines.at(i).fontSizeIncrement); + + QFont font = item->font(); + font.setBold(lines.at(i).bold); + font.setItalic(lines.at(i).italic); + font.setPointSize(font.pointSize() + lines.at(i).fontSizeIncrement); + item->setFont(font); + + ui->listWidgetEdit->insertItem(++row, item); + } + + ui->listWidgetEdit->blockSignals(false); + + if (ui->listWidgetEdit->count() > 0) + { + ui->listWidgetEdit->setCurrentRow(0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SetPiece(const VPiece &piece) +{ + const VPieceLabelData& pieceData = piece.GetPatternPieceData(); + m_placeholders[pl_pLetter].second = pieceData.GetLetter(); + m_placeholders[pl_pAnnotation].second = pieceData.GetAnnotation(); + m_placeholders[pl_pOrientation].second = pieceData.GetOrientation(); + m_placeholders[pl_pRotation].second = pieceData.GetRotation(); + m_placeholders[pl_pTilt].second = pieceData.GetTilt(); + m_placeholders[pl_pFoldPosition].second = pieceData.GetFoldPosition(); + m_placeholders[pl_pName].second = piece.GetName(); + m_placeholders[pl_pQuantity].second = QString::number(pieceData.GetQuantity()); + if (pieceData.IsOnFold()) + { + m_placeholders[pl_wOnFold].second = tr("on fold"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::InitPreviewLines(const QVector &lines) +{ + ui->listWidgetPreview->clear(); + + int row = -1; + + for (int i=0; isetTextAlignment(lines.at(i).alignment); + item->setData(Qt::UserRole, lines.at(i).fontSizeIncrement); + + QFont font = item->font(); + font.setBold(lines.at(i).bold); + font.setItalic(lines.at(i).italic); + font.setPointSize(font.pointSize() + lines.at(i).fontSizeIncrement); + item->setFont(font); + + ui->listWidgetPreview->insertItem(++row, item); + } + + if (ui->listWidgetPreview->count() > 0) + { + ui->listWidgetPreview->setCurrentRow(0); + } +} diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.h b/src/libs/vtools/dialogs/support/dialogeditlabel.h new file mode 100644 index 000000000..d2df21aa3 --- /dev/null +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.h @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @file dialogeditlabel.h + ** @author Roman Telezhynskyi + ** @date 11 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGEDITLABEL_H +#define DIALOGEDITLABEL_H + +#include +#include + +namespace Ui +{ + class DialogEditLabel; +} + +class VLabelTemplateLine; +class QMenu; +class VAbstractPattern; +class VPiece; + +class DialogEditLabel : public QDialog +{ + Q_OBJECT + +public: + explicit DialogEditLabel(VAbstractPattern *doc, QWidget *parent = nullptr); + virtual ~DialogEditLabel(); + + QVector GetTemplate() const; + void SetTemplate(const QVector &lines); + + void SetPiece(const VPiece &piece); + +private slots: + void ShowLineDetails(); + void AddLine(); + void RemoveLine(); + void SaveLineText(const QString &text); + void SaveFontStyle(bool checked); + void SaveTextFormating(bool checked); + void NewTemplate(); + void ExportTemplate(); + void ImportTemplate(); + void InsertPlaceholder(); + void TabChanged(int index); + void SaveAdditionalFontSize(int i); + +private: + Q_DISABLE_COPY(DialogEditLabel) + Ui::DialogEditLabel *ui; + QMenu *m_placeholdersMenu; + VAbstractPattern *m_doc; + + QMap> m_placeholders; + + void SetupControls(); + void InitPlaceholdersMenu(); + void InitPlaceholders(); + + QString ReplacePlaceholders(QString line) const; + + void InitPreviewLines(const QVector &lines); +}; + +#endif // DIALOGEDITLABEL_H diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.ui b/src/libs/vtools/dialogs/support/dialogeditlabel.ui new file mode 100644 index 000000000..f03281469 --- /dev/null +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.ui @@ -0,0 +1,408 @@ + + + DialogEditLabel + + + Qt::ApplicationModal + + + + 0 + 0 + 437 + 464 + + + + Edit label template + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + true + + + + + + + + false + + + Clear current and begin new label + + + ... + + + + .. + + + + 24 + 24 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Import from label template + + + ... + + + + .. + + + + 24 + 24 + + + + + + + + false + + + Export label as template + + + ... + + + + .. + + + + 24 + 24 + + + + + + + + + + 0 + + + + Edit + + + + + + + 0 + 1 + + + + QAbstractItemView::InternalMove + + + + + + + + + 6 + + + + + false + + + Bold + + + ... + + + + .. + + + true + + + + + + + false + + + Italic + + + ... + + + + .. + + + true + + + + + + + false + + + Aligns with the left edge + + + ... + + + + .. + + + true + + + + + + + false + + + Centers horizontally in the available space + + + ... + + + + .. + + + true + + + + + + + false + + + Aligns with the right edge + + + ... + + + + .. + + + true + + + + + + + false + + + Additional font size. Use to make a line bigger. + + + 25 + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + ... + + + + ../../../../app/valentina/dialogs../../../../app/valentina/dialogs + + + + + + + false + + + ... + + + + ../../../../app/valentina/dialogs../../../../app/valentina/dialogs + + + + + + + + + Text: + + + + + + + + + false + + + Line of text + + + false + + + + + + + false + + + Insert placeholders + + + Insert... + + + + + + + + + + + + Preview + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + VLineEdit + QLineEdit +
vlineedit.h
+
+
+ + + + + + buttonBox + accepted() + DialogEditLabel + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogEditLabel + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 38074d721..cdfb3186a 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -42,6 +42,7 @@ #include "dialogpiecepath.h" #include "../../../undocommands/savepiecepathoptions.h" #include "../../support/dialogeditwrongformula.h" +#include "../../support/dialogeditlabel.h" #include "../../../tools/vtoolseamallowance.h" #include @@ -103,9 +104,6 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & m_my(0), m_dialog(), m_visPins(), - m_qslMaterials(), - m_qslPlacements(), - m_conMCP(), m_oldData(), m_oldGeom(), m_oldGrainline(), @@ -123,7 +121,8 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & m_timerWidth(nullptr), m_timerWidthBefore(nullptr), m_timerWidthAfter(nullptr), - m_saWidth(0) + m_saWidth(0), + m_templateLines() { ui->setupUi(this); @@ -245,19 +244,19 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) m_mx = piece.GetMx(); m_my = piece.GetMy(); - uiTabLabels->lineEditLetter->setText(piece.GetPatternPieceData().GetLetter()); - - m_conMCP.clear(); - for (int i = 0; i < piece.GetPatternPieceData().GetMCPCount(); ++i) - { - m_conMCP << piece.GetPatternPieceData().GetMCP(i); - } - - UpdateList(); + m_oldData = piece.GetPatternPieceData(); + uiTabLabels->lineEditLetter->setText(m_oldData.GetLetter()); + uiTabLabels->lineEditAnnotation->setText(m_oldData.GetAnnotation()); + uiTabLabels->lineEditOrientation->setText(m_oldData.GetOrientation()); + uiTabLabels->lineEditRotation->setText(m_oldData.GetRotation()); + uiTabLabels->lineEditTilt->setText(m_oldData.GetTilt()); + uiTabLabels->lineEditFoldPosition->setText(m_oldData.GetFoldPosition()); + uiTabLabels->spinBoxQuantity->setValue(m_oldData.GetQuantity()); + uiTabLabels->checkBoxFold->setChecked(m_oldData.IsOnFold()); + m_templateLines = m_oldData.GetLabelTemplate(); uiTabGrainline->comboBoxArrow->setCurrentIndex(int(piece.GetGrainlineGeometry().GetArrowType())); - m_oldData = piece.GetPatternPieceData(); uiTabLabels->groupBoxDetailLabel->setChecked(m_oldData.IsVisible()); ChangeCurrentData(uiTabLabels->comboBoxDLCenterPin, m_oldData.CenterPin()); ChangeCurrentData(uiTabLabels->comboBoxDLTopLeftPin, m_oldData.TopLeftPin()); @@ -459,105 +458,6 @@ void DialogSeamAllowance::resizeEvent(QResizeEvent *event) DialogTool::resizeEvent(event); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::UpdateList() -{ - uiTabLabels->listWidgetMCP->clear(); - for (int i = 0; i < m_conMCP.count(); ++i) - { - MaterialCutPlacement mcp = m_conMCP.at(i); - QString qsText = tr("Cut %1 of %2%3").arg(mcp.m_iCutNumber); - if (mcp.m_eMaterial < MaterialType::mtUserDefined) - { - qsText = qsText.arg(m_qslMaterials[int(mcp.m_eMaterial)]); - } - else - { - qsText = qsText.arg(mcp.m_qsMaterialUserDef); - } - if (mcp.m_ePlacement == PlacementType::ptCutOnFold) - { - qsText = qsText.arg(QLatin1String(" ") + tr("on Fold")); - } - else - { - qsText = qsText.arg(""); - } - - uiTabLabels->listWidgetMCP->addItem(qsText); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::AddUpdate() -{ - MaterialCutPlacement mcp; - QStringList qslUserMaterials = qApp->Settings()->GetUserDefinedMaterials(); - - const int i = uiTabLabels->comboBoxMaterial->currentData().toInt(); - QString qsMat = uiTabLabels->comboBoxMaterial->currentText(); - if (i < m_qslMaterials.count() && qsMat == m_qslMaterials[i]) - { - mcp.m_eMaterial = MaterialType(i); - mcp.m_qsMaterialUserDef.clear(); - } - else - { - mcp.m_eMaterial = MaterialType::mtUserDefined; - mcp.m_qsMaterialUserDef = qsMat; - // check if we have new user defined material - bool bFound = false; - for (int i = 0; i < qslUserMaterials.count() && bFound == false; ++i) - { - if (mcp.m_qsMaterialUserDef == qslUserMaterials[i]) - { - bFound = true; - } - } - if (bFound == false) - { - qApp->Settings()->AddUserDefinedMaterial(mcp.m_qsMaterialUserDef); - qApp->Settings()->sync(); - uiTabLabels->comboBoxMaterial->addItem(mcp.m_qsMaterialUserDef, int(MaterialType::mtUserDefined)); - } - } - - mcp.m_iCutNumber = uiTabLabels->spinBoxCutNumber->value(); - mcp.m_ePlacement = PlacementType(uiTabLabels->comboBoxPlacement->currentIndex()); - - if (m_bAddMode == true) - { - m_conMCP << mcp; - } - else - { - int iR = uiTabLabels->listWidgetMCP->currentRow(); - SCASSERT(iR >= 0) - m_conMCP[iR] = mcp; - SetAddMode(); - } - UpdateList(); - ClearFields(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::Cancel() -{ - ClearFields(); - SetAddMode(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::Remove() -{ - int iR = uiTabLabels->listWidgetMCP->currentRow(); - SCASSERT(iR >= 0) - m_conMCP.removeAt(iR); - UpdateList(); - ClearFields(); - SetAddMode(); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::NameDetailChanged() { @@ -584,12 +484,6 @@ void DialogSeamAllowance::NameDetailChanged() CheckState(); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::MaterialChanged() -{ - uiTabLabels->pushButtonAdd->setEnabled(uiTabLabels->comboBoxMaterial->currentText().isEmpty() == false); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos) { @@ -1529,53 +1423,6 @@ void DialogSeamAllowance::UpdatePatternLabelValues() CheckState(); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetAddMode() -{ - uiTabLabels->pushButtonAdd->setText(tr("Add")); - uiTabLabels->pushButtonCancel->hide(); - uiTabLabels->pushButtonRemove->hide(); - uiTabLabels->listWidgetMCP->setCurrentRow(-1); - m_bAddMode = true; -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetEditMode() -{ - int iR = uiTabLabels->listWidgetMCP->currentRow(); - // this method can be called by clicking on item or by update. In the latter case there is nothing else to do! - if (iR < 0 || iR >= m_conMCP.count()) - { - return; - } - - uiTabLabels->pushButtonAdd->setText(tr("Update")); - uiTabLabels->pushButtonCancel->show(); - uiTabLabels->pushButtonRemove->show(); - - MaterialCutPlacement mcp = m_conMCP.at(iR); - if (mcp.m_eMaterial == MaterialType::mtUserDefined) - { - int iRow = qApp->Settings()->GetUserDefinedMaterials().indexOf(mcp.m_qsMaterialUserDef); - if (iRow >= 0) - { - uiTabLabels->comboBoxMaterial->setCurrentIndex(iRow + m_qslMaterials.count()); - } - else - { - uiTabLabels->comboBoxMaterial->setCurrentText(mcp.m_qsMaterialUserDef); - } - } - else - { - uiTabLabels->comboBoxMaterial->setCurrentIndex(int(mcp.m_eMaterial)); - } - uiTabLabels->spinBoxCutNumber->setValue(mcp.m_iCutNumber); - uiTabLabels->comboBoxPlacement->setCurrentIndex(int(mcp.m_ePlacement)); - - m_bAddMode = false; -} - //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::EnabledGrainline() { @@ -2099,6 +1946,19 @@ void DialogSeamAllowance::PatternPinPointChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EditLabel() +{ + DialogEditLabel editor(qApp->getCurrentDocument()); + editor.SetTemplate(m_templateLines); + editor.SetPiece(GetPiece()); + + if (QDialog::Accepted == editor.exec()) + { + m_templateLines = editor.GetTemplate(); + } +} + //--------------------------------------------------------------------------------------------------------------------- VPiece DialogSeamAllowance::CreatePiece() const { @@ -2116,12 +1976,14 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.SetMy(m_my); piece.SetFormulaSAWidth(GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidth), m_saWidth); piece.GetPatternPieceData().SetLetter(uiTabLabels->lineEditLetter->text()); - - for (int i = 0; i < m_conMCP.count(); ++i) - { - piece.GetPatternPieceData().Append(m_conMCP[i]); - } - + piece.GetPatternPieceData().SetAnnotation(uiTabLabels->lineEditAnnotation->text()); + piece.GetPatternPieceData().SetOrientation(uiTabLabels->lineEditOrientation->text()); + piece.GetPatternPieceData().SetRotation(uiTabLabels->lineEditRotation->text()); + piece.GetPatternPieceData().SetTilt(uiTabLabels->lineEditTilt->text()); + piece.GetPatternPieceData().SetFoldPosition(uiTabLabels->lineEditFoldPosition->text()); + piece.GetPatternPieceData().SetQuantity(uiTabLabels->spinBoxQuantity->value()); + piece.GetPatternPieceData().SetOnFold(uiTabLabels->checkBoxFold->isChecked()); + piece.GetPatternPieceData().SetLabelTemplate(m_templateLines); piece.GetPatternPieceData().SetPos(m_oldData.GetPos()); piece.GetPatternPieceData().SetLabelWidth(GetFormulaFromUser(uiTabLabels->lineEditDLWidthFormula)); piece.GetPatternPieceData().SetLabelHeight(GetFormulaFromUser(uiTabLabels->lineEditDLHeightFormula)); @@ -2646,35 +2508,14 @@ void DialogSeamAllowance::InitPatternPieceDataTab() { uiTabLabels->lineEditName->setClearButtonEnabled(true); uiTabLabels->lineEditLetter->setClearButtonEnabled(true); + uiTabLabels->lineEditAnnotation->setClearButtonEnabled(true); + uiTabLabels->lineEditOrientation->setClearButtonEnabled(true); + uiTabLabels->lineEditRotation->setClearButtonEnabled(true); + uiTabLabels->lineEditTilt->setClearButtonEnabled(true); + uiTabLabels->lineEditFoldPosition->setClearButtonEnabled(true); connect(uiTabLabels->lineEditName, &QLineEdit::textChanged, this, &DialogSeamAllowance::NameDetailChanged); - - m_qslMaterials << QApplication::translate("Detail", "Fabric", nullptr) - << QApplication::translate("Detail", "Lining", nullptr) - << QApplication::translate("Detail", "Interfacing", nullptr) - << QApplication::translate("Detail", "Interlining", nullptr); - - for (int i = 0; i < m_qslMaterials.count(); ++i) - { - uiTabLabels->comboBoxMaterial->addItem(m_qslMaterials[i], i); - } - - const QStringList qsl = qApp->Settings()->GetUserDefinedMaterials(); - for (int i = 0; i < qsl.count(); ++i) - { - uiTabLabels->comboBoxMaterial->addItem(qsl.at(i), int(MaterialType::mtUserDefined)); - } - - m_qslPlacements << tr("None") << tr("Cut on fold"); - uiTabLabels->comboBoxPlacement->addItems(m_qslPlacements); - - connect(uiTabLabels->pushButtonAdd, &QPushButton::clicked, this, &DialogSeamAllowance::AddUpdate); - connect(uiTabLabels->pushButtonCancel, &QPushButton::clicked, this, &DialogSeamAllowance::Cancel); - connect(uiTabLabels->pushButtonRemove, &QPushButton::clicked, this, &DialogSeamAllowance::Remove); - connect(uiTabLabels->listWidgetMCP, &QListWidget::itemClicked, this, &DialogSeamAllowance::SetEditMode); - connect(uiTabLabels->comboBoxMaterial, &QComboBox::currentTextChanged, this, &DialogSeamAllowance::MaterialChanged); - - SetAddMode(); + connect(uiTabLabels->pushButtonEditPieceLabel, &QPushButton::clicked, this, &DialogSeamAllowance::EditLabel); } //--------------------------------------------------------------------------------------------------------------------- @@ -2880,14 +2721,6 @@ void DialogSeamAllowance::UpdateCurrentInternalPathRecord() item->setText(GetPathName(path)); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::ClearFields() -{ - uiTabLabels->comboBoxMaterial->setCurrentIndex(0); - uiTabLabels->spinBoxCutNumber->setValue(0); - uiTabLabels->comboBoxPlacement->setCurrentIndex(0); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::SetGrainlineAngle(QString angleFormula) { diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h index 570511782..383379535 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h @@ -75,15 +75,8 @@ protected: virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE; virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; -protected slots: - void UpdateList(); - void AddUpdate(); - void Cancel(); - void Remove(); - private slots: void NameDetailChanged(); - void MaterialChanged(); void ShowMainPathContextMenu(const QPoint &pos); void ShowCustomSAContextMenu(const QPoint &pos); void ShowInternalPathsContextMenu(const QPoint &pos); @@ -111,9 +104,6 @@ private slots: void UpdateDetailLabelValues(); void UpdatePatternLabelValues(); - void SetAddMode(); - void SetEditMode(); - void EditGrainlineFormula(); void EditDLFormula(); void EditPLFormula(); @@ -156,6 +146,8 @@ private slots: void DetailPinPointChanged(); void PatternPinPointChanged(); + void EditLabel(); + private: Q_DISABLE_COPY(DialogSeamAllowance) @@ -190,14 +182,9 @@ private: QPointer m_dialog; QPointer m_visPins; - QStringList m_qslMaterials; - QStringList m_qslPlacements; - // temporary container for Material/Cut/Placement 3-tuples - MCPContainer m_conMCP; - - VPieceLabelData m_oldData; + VPieceLabelData m_oldData; VPatternLabelData m_oldGeom; - VGrainlineData m_oldGrainline; + VGrainlineData m_oldGrainline; int m_iRotBaseHeight; int m_iLenBaseHeight; int m_DLWidthBaseHeight; @@ -215,6 +202,8 @@ private: QTimer *m_timerWidthAfter; qreal m_saWidth; + QVector m_templateLines; + VPiece CreatePiece() const; void NewMainPathItem(const VPieceNode &node); @@ -227,7 +216,6 @@ private: bool MainPathIsClockwise() const; void UpdateCurrentCustomSARecord(); void UpdateCurrentInternalPathRecord(); - void ClearFields(); QListWidgetItem *GetItemById(quint32 id); diff --git a/src/libs/vtools/dialogs/tools/piece/tabs/tablabels.ui b/src/libs/vtools/dialogs/tools/piece/tabs/tablabels.ui index 543012c83..3b247040d 100644 --- a/src/libs/vtools/dialogs/tools/piece/tabs/tablabels.ui +++ b/src/libs/vtools/dialogs/tools/piece/tabs/tablabels.ui @@ -6,8 +6,8 @@ 0 0 - 566 - 596 + 579 + 500 @@ -28,8 +28,8 @@ 0 0 - 546 - 576 + 559 + 480 @@ -44,158 +44,205 @@
- - - Qt::Horizontal + + + + + Label template: + + + + + + + Edit pattern label + + + Edit template + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Label data - - - - - - QFormLayout::ExpandingFieldsGrow - - - - - Letter: - - - - - - - 3 - - - Letter of pattern piece - - - - - - - Name of detail: - - - - - - - Detail - - - 30 - - - Name can't be empty - - - - - - - - - Material/Cut number/Placement - - - - - - Cut number: - - - - - - - Material type: - - - - - - - You can choose one of the predefined materials or enter a new one - - - true - - - - - - - 1 - - - 1000 - - - - - - - Placement: - - - - - - - - - - Add - - - - - - - Cancel - - - - - - - Remove - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 180 - 0 - + + + QFormLayout::ExpandingFieldsGrow - - Qt::ClickFocus - - + + + + Letter: + + + + + + + 3 + + + Letter of pattern piece + + + + + + + Name of detail: + + + + + + + Detail + + + 30 + + + Name can't be empty + + + + + + + Quantity: + + + + + + + 1 + + + 9999 + + + 1 + + + + + + + Placement: + + + + + + + on fold + + + + + + + Annotation: + + + + + + + A text field to add comments in + + + + + + + Orientation: + + + + + + + "Left"/"Right"/"Undefined" + + + + + + + Rotation: + + + + + + + "1-Way"/"2-Way"/"4-Way"/"Any" + + + + + + + Tilt: + + + + + + + "CW X"/"CCW X" + + + + + + + Fold position: + + + + + + + "Up/Down"/"Left/Right" + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 6ea8ba99e..69c1b9368 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -302,7 +302,14 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPieceLabelData& data = piece.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr); + doc->SetAttribute(domData, VAbstractPattern::AttrAnnotation, data.GetAnnotation()); + doc->SetAttribute(domData, VAbstractPattern::AttrOrientation, data.GetOrientation()); + doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation()); + doc->SetAttribute(domData, VAbstractPattern::AttrTilt, data.GetTilt()); + doc->SetAttribute(domData, VAbstractPattern::AttrFoldPosition, data.GetFoldPosition()); + doc->SetAttribute(domData, VAbstractPattern::AttrQuantity, data.GetQuantity()); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible()); + doc->SetAttribute(domData, VAbstractPattern::AttrOnFold, data.IsOnFold()); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, VAbstractPattern::AttrWidth, data.GetLabelWidth()); @@ -337,19 +344,8 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement domData.removeAttribute(AttrBottomRightPin); } - for (int i = 0; i < data.GetMCPCount(); ++i) - { - const MaterialCutPlacement mcp = data.GetMCP(i); - QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); - doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); - if (mcp.m_eMaterial == MaterialType::mtUserDefined) - { - doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); - } - doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); - doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); - domData.appendChild(domMCP); - } + doc->SetLabelTemplate(domData, data.GetLabelTemplate()); + domElement.appendChild(domData); } @@ -358,7 +354,7 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE { QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternLabelData& geom = piece.GetPatternInfo(); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true ? trueStr : falseStr); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible()); doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, VAbstractPattern::AttrWidth, geom.GetLabelWidth()); @@ -402,7 +398,7 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle // grainline QDomElement domData = doc->createElement(VAbstractPattern::TagGrainline); const VGrainlineData& glGeom = piece.GetGrainlineGeometry(); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible() == true ? trueStr : falseStr); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible()); doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x()); doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); @@ -578,7 +574,7 @@ void VToolSeamAllowance::UpdatePatternInfo() if (PrepareLabelData(geom, m_patternInfo, pos, labelAngle)) { - m_patternInfo->UpdateData(doc, VContainer::size(), VContainer::height()); + m_patternInfo->UpdateData(doc); UpdateLabelItem(m_patternInfo, pos, labelAngle); } } @@ -1151,7 +1147,7 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, connect(m_grainLine, &VGrainlineItem::SignalResized, this, &VToolSeamAllowance::SaveResizeGrainline); connect(m_grainLine, &VGrainlineItem::SignalRotated, this, &VToolSeamAllowance::SaveRotateGrainline); - connect(doc, &VAbstractPattern::patternChanged, this, &VToolSeamAllowance::UpdatePatternInfo); + connect(doc, &VAbstractPattern::UpdatePatternLabel, this, &VToolSeamAllowance::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateDetailLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateGrainline); diff --git a/src/libs/vwidgets/vlineedit.cpp b/src/libs/vwidgets/vlineedit.cpp new file mode 100644 index 000000000..392fa657a --- /dev/null +++ b/src/libs/vwidgets/vlineedit.cpp @@ -0,0 +1,76 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vlineedit.h" + +//--------------------------------------------------------------------------------------------------------------------- +VLineEdit::VLineEdit(QWidget *parent) + : QLineEdit(parent), + m_selectOnMousePress(false) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VLineEdit::VLineEdit(const QString &contents, QWidget *parent) + : QLineEdit(contents, parent), + m_selectOnMousePress(false) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VLineEdit::focusInEvent(QFocusEvent *e) +{ + QLineEdit::focusInEvent(e); + selectAll(); + m_selectOnMousePress = true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLineEdit::focusOutEvent(QFocusEvent *e) +{ + const int start = selectionStart(); + const int selectionLength = selectedText().length(); + const bool wasTextSelected = hasSelectedText(); + + QLineEdit::focusOutEvent(e); + + if (wasTextSelected) + { + setSelection(start, selectionLength); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLineEdit::mousePressEvent(QMouseEvent *e) +{ + QLineEdit::mousePressEvent(e); + if(m_selectOnMousePress) + { + selectAll(); + m_selectOnMousePress = false; + } +} + diff --git a/src/libs/vwidgets/vlineedit.h b/src/libs/vwidgets/vlineedit.h new file mode 100644 index 000000000..9b9561608 --- /dev/null +++ b/src/libs/vwidgets/vlineedit.h @@ -0,0 +1,50 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 8, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VLINEEDIT_H +#define VLINEEDIT_H + +#include + +class VLineEdit : public QLineEdit +{ + Q_OBJECT +public: + VLineEdit(QWidget * parent = nullptr); + VLineEdit(const QString &contents, QWidget *parent = nullptr); + +protected: + virtual void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE; + virtual void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE; + virtual void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VLineEdit) + bool m_selectOnMousePress; +}; + +#endif // VLINEEDIT_H diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index cd916d53f..ce28ee4d6 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -164,8 +164,8 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem const TextLine& tl = m_tm.GetSourceLine(i); fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize); - fnt.setWeight(tl.m_eFontWeight); - fnt.setStyle(tl.m_eStyle); + fnt.setBold(tl.bold); + fnt.setItalic(tl.italic); QString qsText = tl.m_qsText; QFontMetrics fm(fnt); @@ -235,25 +235,6 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VTextGraphicsItem::AddLine adds a line of text to the label list. - * @param tl line of text to add - */ -void VTextGraphicsItem::AddLine(const TextLine& tl) -{ - m_tm.AddSourceLine(tl); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VTextGraphicsItem::Clear deletes all the label texts - */ -void VTextGraphicsItem::Clear() -{ - m_tm.ClearSourceLines(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VTextGraphicsItem::SetSize Tries to set the label size to (fW, fH). If any of those is too small, the label @@ -362,9 +343,9 @@ void VTextGraphicsItem::UpdateData(const QString &qsName, const VPieceLabelData * @brief VTextGraphicsItem::UpdateData Updates the pattern label * @param pDoc pointer to the pattern object */ -void VTextGraphicsItem::UpdateData(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight) +void VTextGraphicsItem::UpdateData(VAbstractPattern* pDoc) { - m_tm.Update(pDoc, dSize, dHeight); + m_tm.Update(pDoc); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vtextgraphicsitem.h b/src/libs/vwidgets/vtextgraphicsitem.h index f59ce5388..0b321ca07 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.h +++ b/src/libs/vwidgets/vtextgraphicsitem.h @@ -63,12 +63,10 @@ public: void SetFont(const QFont& fnt); int GetFontSize() const; - void AddLine(const TextLine& tl); - void Clear(); void SetSize(qreal fW, qreal fH); bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const; void UpdateData(const QString& qsName, const VPieceLabelData& data); - void UpdateData(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight); + void UpdateData(VAbstractPattern* pDoc); int GetTextLines() const; protected: diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 400730a4a..f77837b0d 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -21,7 +21,8 @@ SOURCES += \ $$PWD/vcurvepathitem.cpp \ $$PWD/global.cpp \ $$PWD/vscenepoint.cpp \ - $$PWD/scalesceneitems.cpp + $$PWD/scalesceneitems.cpp \ + $$PWD/vlineedit.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -46,4 +47,5 @@ HEADERS += \ $$PWD/vcurvepathitem.h \ $$PWD/global.h \ $$PWD/vscenepoint.h \ - $$PWD/scalesceneitems.h + $$PWD/scalesceneitems.h \ + $$PWD/vlineedit.h diff --git a/src/test/TranslationsTest/tst_buitinregexp.cpp b/src/test/TranslationsTest/tst_buitinregexp.cpp index 5411f6f46..96fa4da51 100644 --- a/src/test/TranslationsTest/tst_buitinregexp.cpp +++ b/src/test/TranslationsTest/tst_buitinregexp.cpp @@ -224,6 +224,22 @@ void TST_BuitInRegExp::TestCheckInternalVaribleRegExp() } } +//--------------------------------------------------------------------------------------------------------------------- +void TST_BuitInRegExp::TestTemplatePlaceholders() +{ + QSet originals; + QSet translations; + + for (int i = 0; i < labelTemplatePlaceholders.size(); ++i) + { + originals.insert(labelTemplatePlaceholders.at(i)); + translations.insert(m_trMs->PlaceholderToUser(labelTemplatePlaceholders.at(i))); + } + + QCOMPARE(originals.size(), labelTemplatePlaceholders.size()); // All tags are unique + QCOMPARE(translations.size(), labelTemplatePlaceholders.size()); // All translated tags are unique +} + //--------------------------------------------------------------------------------------------------------------------- void TST_BuitInRegExp::cleanupTestCase() { diff --git a/src/test/TranslationsTest/tst_buitinregexp.h b/src/test/TranslationsTest/tst_buitinregexp.h index 7626d0001..1f99eeffa 100644 --- a/src/test/TranslationsTest/tst_buitinregexp.h +++ b/src/test/TranslationsTest/tst_buitinregexp.h @@ -61,6 +61,7 @@ private slots: void TestCheckUnderlineExists(); void TestCheckInternalVaribleRegExp_data(); void TestCheckInternalVaribleRegExp(); + void TestTemplatePlaceholders(); void cleanupTestCase(); private: diff --git a/src/test/ValentinaTest/tst_nameregexp.cpp b/src/test/ValentinaTest/tst_nameregexp.cpp index 01f589a98..9c6de7eee 100644 --- a/src/test/ValentinaTest/tst_nameregexp.cpp +++ b/src/test/ValentinaTest/tst_nameregexp.cpp @@ -250,7 +250,11 @@ void TST_NameRegExp::TestCorrectOrderMeasurement_data() QTest::newRow("G09") << hipCirc_M << "hip_circ"; QTest::newRow("G10") << neckArcF_M << "neck_arc_f"; QTest::newRow("G11") << highbustArcF_M << "highbust_arc_f"; + + // size and bust_arc_f are synonyms QTest::newRow("G12") << bustArcF_M << "bust_arc_f"; + QTest::newRow("G12") << size_M << "size"; + QTest::newRow("G13") << lowbustArcF_M << "lowbust_arc_f"; QTest::newRow("G14") << ribArcF_M << "rib_arc_f"; QTest::newRow("G15") << waistArcF_M << "waist_arc_f";