33 #include "ui_export_layout_dialog.h"
34 #include "../options.h"
35 #include "../core/vapplication.h"
36 #include "../vmisc/vsettings.h"
37 #include "../ifc/exception/vexception.h"
38 #include "../vwidgets/export_format_combobox.h"
41 #include <QFileDialog>
42 #include <QMessageBox>
45 #include <QRegularExpression>
56 , m_isInitialized(false)
58 , m_SaveButton(nullptr)
61 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
63 ui->path_LineEdit->setClearButtonEnabled(
true);
64 ui->filename_LineEdit->setClearButtonEnabled(
true);
66 qApp->Seamly2DSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
72 ui->filename_LineEdit->setValidator(
new QRegularExpressionValidator(QRegularExpression(
fileNameRegExp),
this));
77 ui->filename_LineEdit->setText(mask);
83 ui->filename_LineEdit->setText(mask);
87 VException e(tr(
"The base filename does not match a regular expression."));
135 ui->textAsPaths_Checkbox->setVisible(
false);
140 connect(
ui->format_ComboBox,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
142 connect(
ui->browse_PushButton, &QPushButton::clicked,
this, [
this]()
144 const QString dirPath = qApp->Seamly2DSettings()->getLayoutPath();
145 bool usedNotExistedDir = false;
146 QDir directory(dirPath);
147 if (!directory.exists())
149 usedNotExistedDir = directory.mkpath(
".");
152 const QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Select folder"), dirPath,
153 QFileDialog::ShowDirsOnly
154 | QFileDialog::DontResolveSymlinks
155 | QFileDialog::DontUseNativeDialog);
158 dir == ui->path_LineEdit->text() ? pathChanged(dir) : ui->path_LineEdit->setText(dir);
161 if (usedNotExistedDir)
163 QDir directory(dirPath);
164 directory.rmpath(
".");
168 connect(ui->quality_Slider, &QSlider::valueChanged,
this, [
this]()
170 ui->percent_SpinBox->setValue(ui->quality_Slider->value());
172 connect(ui->percent_SpinBox, QOverload<int>::of(&QSpinBox::valueChanged), [=](
int i)
174 ui->quality_Slider->setValue(i);
177 ui->path_LineEdit->setText(
qApp->Seamly2DSettings()->getLayoutPath());
179 initTemplates(ui->templates_ComboBox);
191 int indexCustom = templates_ComboBox->count() -1;
192 templates_ComboBox->removeItem(indexCustom);
202 VException e(tr(
"Tried to use out of range format number."));
206 const int i =
ui->format_ComboBox->findData(
static_cast<int>(
format));
209 VException e(tr(
"Selected not present format."));
212 ui->format_ComboBox->setCurrentIndex(i);
247 ui->binaryDXF_CheckBox->setChecked(binary);
261 ui->binaryDXF_CheckBox->setChecked(
false);
298 return ui->binaryDXF_CheckBox->isChecked();
319 if (cmdDestinationPath.isEmpty())
321 path = QDir::currentPath();
323 else if (QDir(cmdDestinationPath).isAbsolute())
325 path = cmdDestinationPath;
330 if (!dir.cd(cmdDestinationPath))
332 VException e(tr(
"The destination directory doesn't exist or is not readable."));
335 path = dir.absolutePath();
338 qDebug() <<
"Full output path: " <<
path <<
"\n";
339 ui->path_LineEdit->setText(
path);
416 return ui->path_LineEdit->text();
422 return ui->filename_LineEdit->text();
434 return ui->format_ComboBox->currentText();
441 QString infoText = QStringLiteral(
"Do you want to replace it?");
443 if (
ui->exportFiles_ListWidget->count() > 1)
445 text = tr(
"%1 files with basename %2 already exist.")
446 .arg(
ui->exportFiles_ListWidget->count())
448 infoText = tr(
"Do you want to replace them?");
453 for (
int i=0; i <
m_count; ++i)
457 increment = QStringLiteral(
"_0") + QString::number(i+1);
460 const QString name = QString(
"%1/%2%3%4")
466 if (QFile::exists(name))
468 QMessageBox messageBox(
this);
469 messageBox.setWindowTitle(tr(
"Confirm Export"));
470 messageBox.setIcon(QMessageBox::Question);
471 messageBox.setText(text);
472 messageBox.setInformativeText(infoText);
473 messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
474 messageBox.setDefaultButton(QMessageBox::Yes);
475 int result = messageBox.exec();
477 if (result == QMessageBox::No)
495 QPalette palette =
ui->path_LineEdit->palette();
499 if (dir.exists(text))
502 palette.setColor(
ui->path_LineEdit->foregroundRole(), Qt::black);
507 palette.setColor(
ui->path_LineEdit->foregroundRole(), Qt::red);
510 ui->path_LineEdit->setPalette(palette);
516 ui->exportFiles_ListWidget->clear();
521 ui->export_GroupBox->hide();
527 ui->textAsPaths_Checkbox->setEnabled(
true);
528 ui->quality_Slider->setEnabled(
false);
529 ui->paperFormat_GroupBox->setEnabled(
false);
530 ui->margins_GroupBox->setEnabled(
false);
531 ui->export_GroupBox->show();
536 const QString name = QString(
"%1%2")
540 QListWidgetItem *item =
new QListWidgetItem(name);
542 ui->exportFiles_ListWidget->addItem(item);
546 for (
int i=0; i <
m_count; ++i)
548 const QString name = QString(
"%1_0%2%3")
550 .arg(QString::number(i+1))
553 QListWidgetItem *item =
new QListWidgetItem(name);
555 ui->exportFiles_ListWidget->addItem(item);
559 switch(currentFormat)
588 ui->binaryDXF_CheckBox->setEnabled(
true);
591 ui->paperFormat_GroupBox->setEnabled(
true);
592 ui->margins_GroupBox->setEnabled(
true);
595 ui->quality_Slider->setEnabled(
true);
598 ui->quality_Slider->setEnabled(
true);
609 ui->binaryDXF_CheckBox->setEnabled(
false);
617 return ui->textAsPaths_Checkbox->isChecked();
625 ui->textAsPaths_Checkbox->setChecked(textAsPaths);
629 ui->textAsPaths_Checkbox->setChecked(
false);
636 QDialog::showEvent( event );
637 if ( event->spontaneous() )
647 setFixedHeight(size().height());
655 const int index =
ui->format_ComboBox->findData(
static_cast<int>(
format));
658 ui->format_ComboBox->removeItem(index);
659 ui->format_ComboBox->setCurrentToDefault();
674 const Unit unit =
qApp->patternUnit();
679 ui->leftField_DoubleSpinBox->setValue(margins.left());
680 ui->topField_DoubleSpinBox->setValue(margins.top());
681 ui->rightField_DoubleSpinBox->setValue(margins.right());
682 ui->bottomField_DoubleSpinBox->setValue(margins.bottom());
684 ui->percent_SpinBox->setValue(
ui->quality_Slider->value());
690 for (
int i=0; i < max; ++i)
694 if (size == tmplSize)
696 ui->templates_ComboBox->setCurrentIndex(i);
704 ui->portrait_ToolButton->setChecked(
true);
708 ui->landscape_ToolButton->setChecked(
true);
723 const Unit unit =
qApp->patternUnit();
726 QMarginsF margins = QMarginsF(
ui->leftField_DoubleSpinBox->value(),
727 ui->topField_DoubleSpinBox->value(),
728 ui->rightField_DoubleSpinBox->value(),
729 ui->bottomField_DoubleSpinBox->value());
743 if(
ui->portrait_ToolButton->isChecked())
753 if (
qApp->Settings()->useLastExportFormat())
766 QString modeStr = QStringLiteral();
767 if (
qApp->Seamly2DSettings()->useModeType())
773 modeStr = QStringLiteral(
"_block");
778 modeStr = QStringLiteral(
"_pieces");
784 modeStr = QStringLiteral(
"_layout");
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
void setDestinationPath(const QString &cmdDestinationPath)
LayoutExportFormat format() const
void readSettings()
ExportLayoutDialog::readSettings.
void initTemplates(QComboBox *templates)
QString modeString() const
modeString()
QString formatText() const
void pathChanged(const QString &text)
bool isTextAsPaths() const
static QString exportFormatSuffix(LayoutExportFormat format)
QPushButton * m_SaveButton
ExportLayoutDialog(int count, Draw mode=Draw::Layout, const QString &fileName=QString(), QWidget *parent=nullptr)
void setTextAsPaths(bool textAsPaths)
void removeFormatFromList(LayoutExportFormat format)
void setBinaryDXFFormat(bool binary)
Ui::ExportLayoutDialog * ui
void writeSettings() const
ExportLayoutDialog::writeSettings.
void selectFormat(LayoutExportFormat format)
virtual ~ExportLayoutDialog()
bool isBinaryDXFFormat() const
void initTemplates(QComboBox *comboBoxTemplates)
QSizeF getTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
DialogLayoutSettings::TemplateSize.
int getExportQuality() const
void setExportQuality(const int &value)
The VException class parent for all exception. Could be use for abstract exception.
void setTiledPDFOrientation(PageOrientation value)
void setTiledPDFMargins(const QMarginsF &value, const Unit &unit)
VSettings::setTiledPDFMargins sets the setting tiled pdf margins to the given value.
void setTiledPDFPaperHeight(qreal value, const Unit &unit)
VSettings::setTiledPDFPaperHeight sets the tiled pdf paper height.
qreal getTiledPDFPaperWidth(const Unit &unit) const
VSettings::getTiledPDFPaperWidth returns the paper height of tiled pdf in the desired unit.
QMarginsF GetTiledPDFMargins(const Unit &unit) const
VSettings::GetTiledPDFMargins returns the tiled pdf margins in the given unit. When the setting is ca...
qreal getTiledPDFPaperHeight(const Unit &unit) const
VSettings::getTiledPDFPaperHeight returns the paper height of tiled pdf in the desired unit.
PageOrientation getTiledPDFOrientation() const
void setTiledPDFPaperWidth(qreal value, const Unit &unit)
VSettings::setTiledPDFPaperWidth sets the tiled pdf paper width.
const QString fileNameRegExp