53 #include "ui_dialogpatternproperties.h"
55 #include <QPushButton>
56 #include <QFileDialog>
59 #include <QMessageBox>
61 #include "../xml/vpattern.h"
62 #include "../vpatterndb/vcontainer.h"
63 #include "../core/vapplication.h"
64 #include "../vtools/dialogs/support/editlabeltemplate_dialog.h"
81 data(
QMap<QCheckBox *, int>()),
82 descriptionChanged(false),
83 gradationChanged(false),
84 defaultChanged(false),
85 securityChanged(false),
86 labelDataChanged(false),
87 askSaveLabelData(false),
88 templateDataChanged(false),
89 deleteAction(nullptr),
90 changeImageAction(nullptr),
91 saveImageAction(nullptr),
92 showImageAction(nullptr),
100 settings->
GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
102 if (
qApp->getFilePath().isEmpty())
104 ui->lineEditPathToFile->setText(tr(
"<Empty>"));
105 ui->lineEditPathToFile->setToolTip(tr(
"File was not saved yet."));
106 ui->pushButtonShowInExplorer->setEnabled(
false);
110 ui->lineEditPathToFile->setText(QDir::toNativeSeparators(
qApp->getFilePath()));
111 ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(
qApp->getFilePath()));
112 ui->pushButtonShowInExplorer->setEnabled(
true);
114 ui->lineEditPathToFile->setCursorPosition(0);
116 connect(
ui->pushButtonShowInExplorer, &QPushButton::clicked,
this, [
this]()
118 ShowInGraphicalShell(qApp->getFilePath());
120 #if defined(Q_OS_MAC)
121 ui->pushButtonShowInExplorer->setText(tr(
"Show in Finder"));
133 connect(
ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked,
this,
136 QPushButton *bCancel =
ui->buttonBox->button(QDialogButtonBox::Cancel);
138 connect(bCancel, &QPushButton::clicked,
this, &DialogPatternProperties::close);
140 ui->tabWidget->setCurrentIndex(0);
143 ui->tabWidget->setTabEnabled(1,
false);
164 connect(
ui->radioButtonDefFromP, &QRadioButton::toggled,
this, [
this]()
166 ui->comboBoxHeight->setEnabled(ui->radioButtonDefFromP->isChecked());
167 ui->comboBoxSize->setEnabled(ui->radioButtonDefFromP->isChecked());
176 connect(
ui->comboBoxHeight,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
178 connect(
ui->comboBoxSize,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
182 ui->checkBoxPatternReadOnly->setChecked(readOnly);
185 connect(
ui->checkBoxPatternReadOnly, &QRadioButton::toggled,
this, [
this](){securityChanged = true;});
189 ui->checkBoxPatternReadOnly->setDisabled(
true);
215 connect(
ui->comboBoxDateFormat,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
217 connect(
ui->comboBoxTimeFormat,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
230 switch (
ui->tabWidget->currentIndex())
270 QCheckBox* box = qobject_cast<QCheckBox*>(sender());
273 if (box ==
ui->checkBoxAllHeights)
275 if (state == Qt::Checked)
279 else if (state == Qt::Unchecked)
284 if (
data.contains(box))
290 if (box ==
ui->checkBoxAllSizes)
292 if (state == Qt::Checked)
296 else if (state == Qt::Unchecked)
301 if (
data.contains(box))
312 QCheckBox* box = qobject_cast<QCheckBox*>(sender());
315 if (state == Qt::Checked)
320 ui->checkBoxAllHeights->blockSignals(
true);
321 ui->checkBoxAllHeights->setCheckState(Qt::Checked);
323 ui->checkBoxAllHeights->blockSignals(
false);
326 else if (state == Qt::Unchecked)
330 ui->checkBoxAllHeights->blockSignals(
true);
331 ui->checkBoxAllHeights->setCheckState(Qt::Unchecked);
333 ui->checkBoxAllHeights->blockSignals(
false);
338 if (
data.contains(box))
353 QCheckBox* box = qobject_cast<QCheckBox*>(sender());
357 if (state == Qt::Checked)
362 ui->checkBoxAllSizes->blockSignals(
true);
363 ui->checkBoxAllSizes->setCheckState(Qt::Checked);
365 ui->checkBoxAllSizes->blockSignals(
false);
368 else if (state == Qt::Unchecked)
372 ui->checkBoxAllSizes->blockSignals(
true);
373 ui->checkBoxAllSizes->setCheckState(Qt::Unchecked);
375 ui->checkBoxAllSizes->blockSignals(
false);
380 if (
data.contains(box))
414 ui->checkBoxH50->setChecked(enabled);
415 ui->checkBoxH56->setChecked(enabled);
416 ui->checkBoxH62->setChecked(enabled);
417 ui->checkBoxH68->setChecked(enabled);
418 ui->checkBoxH74->setChecked(enabled);
419 ui->checkBoxH80->setChecked(enabled);
420 ui->checkBoxH86->setChecked(enabled);
421 ui->checkBoxH92->setChecked(enabled);
422 ui->checkBoxH98->setChecked(enabled);
423 ui->checkBoxH104->setChecked(enabled);
424 ui->checkBoxH110->setChecked(enabled);
425 ui->checkBoxH116->setChecked(enabled);
426 ui->checkBoxH122->setChecked(enabled);
427 ui->checkBoxH128->setChecked(enabled);
428 ui->checkBoxH134->setChecked(enabled);
429 ui->checkBoxH140->setChecked(enabled);
430 ui->checkBoxH146->setChecked(enabled);
431 ui->checkBoxH152->setChecked(enabled);
432 ui->checkBoxH158->setChecked(enabled);
433 ui->checkBoxH164->setChecked(enabled);
434 ui->checkBoxH170->setChecked(enabled);
435 ui->checkBoxH176->setChecked(enabled);
436 ui->checkBoxH182->setChecked(enabled);
437 ui->checkBoxH188->setChecked(enabled);
438 ui->checkBoxH194->setChecked(enabled);
439 ui->checkBoxH200->setChecked(enabled);
445 ui->checkBoxS22->setChecked(enabled);
446 ui->checkBoxS24->setChecked(enabled);
447 ui->checkBoxS26->setChecked(enabled);
448 ui->checkBoxS28->setChecked(enabled);
449 ui->checkBoxS30->setChecked(enabled);
450 ui->checkBoxS32->setChecked(enabled);
451 ui->checkBoxS34->setChecked(enabled);
452 ui->checkBoxS36->setChecked(enabled);
453 ui->checkBoxS38->setChecked(enabled);
454 ui->checkBoxS40->setChecked(enabled);
455 ui->checkBoxS42->setChecked(enabled);
456 ui->checkBoxS44->setChecked(enabled);
457 ui->checkBoxS46->setChecked(enabled);
458 ui->checkBoxS48->setChecked(enabled);
459 ui->checkBoxS50->setChecked(enabled);
460 ui->checkBoxS52->setChecked(enabled);
461 ui->checkBoxS54->setChecked(enabled);
462 ui->checkBoxS56->setChecked(enabled);
463 ui->checkBoxS58->setChecked(enabled);
464 ui->checkBoxS60->setChecked(enabled);
465 ui->checkBoxS62->setChecked(enabled);
466 ui->checkBoxS64->setChecked(enabled);
467 ui->checkBoxS66->setChecked(enabled);
468 ui->checkBoxS68->setChecked(enabled);
469 ui->checkBoxS70->setChecked(enabled);
470 ui->checkBoxS72->setChecked(enabled);
541 const QString ¤tFormat)
545 box->addItems(items);
546 int index = box->findText(currentFormat);
549 box->setCurrentIndex(index);
553 box->setCurrentIndex(0);
561 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
562 ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enable);
570 doc->
SetNotes(
ui->plainTextEditTechNotes->document()->toPlainText());
596 if (
ui->radioButtonDefFromM->isChecked())
656 int index =
ui->comboBoxHeight->findText(def);
659 ui->comboBoxHeight->setCurrentIndex(index);
665 index =
ui->comboBoxHeight->findText(QString().setNum(height));
668 ui->comboBoxHeight->setCurrentIndex(index);
677 int index =
ui->comboBoxSize->findText(def);
680 ui->comboBoxSize->setCurrentIndex(index);
686 index =
ui->comboBoxSize->findText(QString().setNum(size));
689 ui->comboBoxSize->setCurrentIndex(index);
698 const QString def =
ui->comboBoxHeight->currentText();
706 const QString def =
ui->comboBoxSize->currentText();
712 template<
typename Func>
715 connect(check, &QCheckBox::stateChanged,
this, slot);
716 data.insert(check, val);
720 template<
typename GVal>
723 if (option.value(GVal::ALL) ==
false)
725 QMapIterator<GVal, bool> i(option);
729 if (i.value() ==
false && i.key() != GVal::ALL)
731 QCheckBox *box =
data.key(
static_cast<int>(i.key()));
734 box->setCheckState(Qt::Unchecked);
742 template<
typename GVal>
749 QMapIterator<GVal, bool> i(option);
753 if (i.value() && i.key() != GVal::ALL)
766 QByteArray byteArray;
768 QByteArray ba = QByteArray::fromBase64(byteArray);
770 buffer.open(QIODevice::ReadOnly);
772 image.load(&buffer, extension.toLatin1().data());
779 ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu);
780 ui->imageLabel->setScaledContents(
true);
781 connect(
ui->imageLabel, &QWidget::customContextMenuRequested,
this, [
this]()
784 menu.addAction(deleteAction);
785 menu.addAction(changeImageAction);
786 menu.addAction(saveImageAction);
787 menu.addAction(showImageAction);
788 menu.exec(QCursor::pos());
797 connect(
deleteAction, &QAction::triggered,
this, [
this]()
800 ui->imageLabel->setText(tr(
"Change image"));
810 QLabel *label =
new QLabel(
this, Qt::Window);
812 label->setPixmap(QPixmap::fromImage(image));
813 label->setGeometry(QRect(QCursor::pos(), image.size()));
818 if (not image.isNull())
820 ui->imageLabel->setPixmap(QPixmap::fromImage(image));
833 const QString filter = tr(
"Images") + QLatin1String(
" (*.png *.jpg *.jpeg *.bmp)");
834 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Image for pattern"), QString(), filter,
nullptr,
835 QFileDialog::DontUseNativeDialog);
837 if (fileName.isEmpty())
843 if (not image.load(fileName))
847 ui->imageLabel->setPixmap(QPixmap::fromImage(image));
848 QFileInfo f(fileName);
849 QString extension = f.suffix().toUpper();
851 if (extension == QLatin1String(
"JPEG"))
855 if (extension == QLatin1String(
"PNG") || extension == QLatin1String(
"JPG") || extension == QLatin1String(
"BMP"))
857 QByteArray byteArray;
858 QBuffer buffer(&byteArray);
859 buffer.open(QIODevice::WriteOnly);
860 image.save(&buffer, extension.toLatin1().data());
861 QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());
875 QByteArray byteArray;
877 QByteArray ba = QByteArray::fromBase64(byteArray);
879 QString filter = tr(
"Images") + QLatin1String(
" (*") + extension + QLatin1String(
")");
880 QString filename = QFileDialog::getSaveFileName(
this, tr(
"Save File"), tr(
"untitled"), filter, &filter,
881 QFileDialog::DontUseNativeDialog);
882 if (not filename.isEmpty())
884 if (not filename.endsWith(extension.toUpper()))
886 filename.append(extension);
888 QFile file(filename);
889 if (file.open(QIODevice::WriteOnly))
902 QMessageBox::StandardButton answer = QMessageBox::question(
this, tr(
"Save label data."),
903 tr(
"Label data were changed. Do you want to save them before editing label template?"),
904 QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
906 if (answer == QMessageBox::Yes)
920 if (QDialog::Accepted == editor.exec())
virtual ~DialogPatternProperties() Q_DECL_OVERRIDE
void SetDefaultHeight(const QString &def)
QVector< VLabelTemplateLine > templateLines
DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent=nullptr)
Ui::DialogPatternProperties * ui
QAction * showImageAction
void InitComboBox(QComboBox *box, const QMap< GVal, bool > &option)
void SelectAll(int state)
void initComboBoxFormats(QComboBox *box, const QStringList &items, const QString ¤tFormat)
void CheckStateSize(int state)
void CheckStateHeight(int state)
QAction * saveImageAction
void SetHeightsChecked(bool enabled)
void Init(QCheckBox *check, int val, Func slot)
void SetOptions(const QMap< GVal, bool > &option)
QMap< QCheckBox *, int > data
void SetDefaultSize(const QString &def)
QMap< GSizes, bool > sizes
void SetSizesChecked(bool enabled)
QAction * changeImageAction
QMap< GHeights, bool > heights
void SetTemplate(const QVector< VLabelTemplateLine > &lines)
QVector< VLabelTemplateLine > GetTemplate() const
void SetPatternNumber(const QString &qsNum)
void SetGradationHeights(const QMap< GHeights, bool > &options)
void SetImage(const QString &text, const QString &extension)
QString GetCompanyName() const
QVector< VLabelTemplateLine > getPatternLabelTemplate() const
QString GetLabelDateFormat() const
QString GetPatternName() const
QString GetPatternNumber() const
QString GetImageExtension() const
void SetPatternName(const QString &qsName)
void setPatternLabelTemplate(const QVector< VLabelTemplateLine > &lines)
void patternChanged(bool saved)
patternChanged emit if we have unsaved change.
void SetCustomerName(const QString &qsName)
QString GetDescription() const
void UpdatePatternLabel()
QMap< GHeights, bool > GetGradationHeights() const
QString GetCustomerName() const
QMap< GSizes, bool > GetGradationSizes() const
void SetNotes(const QString &text)
void SetCompanyName(const QString &qsName)
void SetLabelDateFormat(const QString &format)
void SetGradationSizes(const QMap< GSizes, bool > &options)
QString GetLabelTimeFormat() const
void SetLabelTimeFormat(const QString &format)
void SetDescription(const QString &text)
bool GetOsSeparator() const
QStringList GetUserDefinedTimeFormats() const
static QStringList PredefinedTimeFormats()
static QStringList PredefinedDateFormats()
QStringList GetUserDefinedDateFormats() const
The VContainer class container of all variables.
static qreal height()
height return height
static qreal size()
size return size
const Unit * GetPatternUnit() const
The VPattern class working with pattern file.
void SetDefCustomSize(int value)
int GetDefCustomSize() const
int GetDefCustomHeight() const
void SetReadOnly(bool rOnly)
void SetDefCustom(bool value)
void SetDefCustomHeight(int value)
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
static const int heightStep
static const int sizeStep
static const int sizesCount
static const int heightsCount