Several changes related to layout export.

Added tool button "Layout export" in section Layout. Should speed up calling
this feature.
Redesign dialog "Layout export". Changes in layout. Now user can change dialog
width.
Fixed bug with path to destination folder. Now the app will check each change
of path. If path after closing the dialog doesn't exist the app will try to
create a path.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-08-15 15:03:10 +03:00
parent db138cd6e7
commit 1a56b2721a
8 changed files with 202 additions and 118 deletions

View File

@ -91,15 +91,22 @@ DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget *
} }
connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save); connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save);
auto ShowExample = [this](){ui->labelExample->setText(tr("Example:") + FileName() + "1" + Formate());}; auto ShowExample = [this]()
{
ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + Format());
};
connect(ui->lineEditFileName, &QLineEdit::textChanged, ShowExample); connect(ui->lineEditFileName, &QLineEdit::textChanged, ShowExample);
connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), ShowExample); connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), ShowExample);
connect(ui->pushButtonBrowse, &QPushButton::clicked, [this]() connect(ui->pushButtonBrowse, &QPushButton::clicked, [this]()
{ {
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder"), QDir::homePath(), const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder"),
qApp->ValentinaSettings()->GetPathLayout(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
ui->lineEditPath->setText(dir); if (not dir.isEmpty())
{// If paths equal the signal will not be called, we will do this manually
dir == ui->lineEditPath->text() ? PathChanged(dir) : ui->lineEditPath->setText(dir);
}
}); });
connect(ui->lineEditPath, &QLineEdit::textChanged, this, &DialogSaveLayout::PathChanged); connect(ui->lineEditPath, &QLineEdit::textChanged, this, &DialogSaveLayout::PathChanged);
@ -128,12 +135,12 @@ void DialogSaveLayout::SelectFormate(const int formate)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogSaveLayout::MakeHelpFormatList() QString DialogSaveLayout::MakeHelpFormatList()
{ {
QString out = "\n"; QString out("\n");
int cntr = 0; int cntr = 0;
const QVector<std::pair<QString, QString>> availFormats = InitAvailFormats(); const QVector<std::pair<QString, QString>> availFormats = InitAvailFormats();
foreach(auto& v, availFormats) foreach(auto& v, availFormats)
{ {
out += "\t"+v.first+" = "+ QString::number(cntr++)+"\n"; out += QLatin1String("\t") + v.first+QLatin1String(" = ") + QString::number(cntr++) + QLatin1String("\n");
} }
return out; return out;
} }
@ -184,7 +191,7 @@ QString DialogSaveLayout::FileName() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogSaveLayout::Formate() const QString DialogSaveLayout::Format() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
return ui->comboBoxFormat->itemData(ui->comboBoxFormat->currentIndex()).toString(); return ui->comboBoxFormat->itemData(ui->comboBoxFormat->currentIndex()).toString();
@ -198,7 +205,7 @@ void DialogSaveLayout::Save()
{ {
for (int i=0; i < count; ++i) for (int i=0; i < count; ++i)
{ {
const QString name = Path()+"/"+FileName()+QString::number(i+1)+Formate(); const QString name = Path()+QLatin1Literal("/")+FileName()+QString::number(i+1)+Format();
if (QFile::exists(name)) if (QFile::exists(name))
{ {
QMessageBox::StandardButton res = QMessageBox::question(this, tr("Name conflict"), QMessageBox::StandardButton res = QMessageBox::question(this, tr("Name conflict"),
@ -256,8 +263,7 @@ void DialogSaveLayout::showEvent(QShowEvent *event)
} }
// do your init stuff here // do your init stuff here
setMaximumSize(size()); setFixedHeight(size().height());
setMinimumSize(size());
isInitialized = true;//first show windows are held isInitialized = true;//first show windows are held
} }
@ -280,7 +286,8 @@ bool DialogSaveLayout::TestPdf()
QProcess proc; QProcess proc;
#if defined(Q_OS_WIN) || defined(Q_OS_OSX) #if defined(Q_OS_WIN) || defined(Q_OS_OSX)
proc.start(qApp->applicationDirPath()+"/"+PDFTOPS); // Seek pdftops in app bundle or near valentin.exe // Seek pdftops in app bundle or near valentin.exe
proc.start(qApp->applicationDirPath() + QLatin1String("/")+ PDFTOPS);
#else #else
proc.start(PDFTOPS); // Seek pdftops in standard path proc.start(PDFTOPS); // Seek pdftops in standard path
#endif #endif

View File

@ -53,7 +53,7 @@ public:
QString Path() const; QString Path() const;
QString FileName() const; QString FileName() const;
QString Formate() const; QString Format() const;
void SelectFormate(const int formate); void SelectFormate(const int formate);
static QString MakeHelpFormatList(); static QString MakeHelpFormatList();
void SetDestinationPath(const QString& cmdDestinationPath); void SetDestinationPath(const QString& cmdDestinationPath);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>692</width> <width>748</width>
<height>179</height> <height>150</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -19,17 +19,19 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QFormLayout" name="formLayout">
<property name="rightMargin"> <property name="sizeConstraint">
<number>0</number> <enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property> </property>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -37,6 +39,42 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineEditPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Destination folder</string>
</property>
<property name="placeholderText">
<string>Path to destination folder</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonBrowse">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Select path to destination folder</string>
</property>
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
@ -44,64 +82,58 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditPath">
<property name="toolTip">
<string>Destination folder</string>
</property>
<property name="placeholderText">
<string>Path to destination folder.</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButtonBrowse">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Select path to destination folder</string>
</property>
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="comboBoxFormat"> <widget class="QComboBox" name="comboBoxFormat">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="lineEditFileName"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="toolTip"> <item>
<string>File base name</string> <widget class="QLineEdit" name="lineEditFileName">
</property> <property name="sizePolicy">
<property name="placeholderText"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<string>File base name.</string> <horstretch>0</horstretch>
</property> <verstretch>0</verstretch>
</widget> </sizepolicy>
</item> </property>
<item row="2" column="2"> <property name="toolTip">
<widget class="QLabel" name="labelExample"> <string>File base name</string>
<property name="minimumSize"> </property>
<size> <property name="placeholderText">
<width>130</width> <string>File base name</string>
<height>0</height> </property>
</size> </widget>
</property> </item>
<property name="text"> <item>
<string notr="true">TextLabel</string> <widget class="QLabel" name="labelExample">
</property> <property name="minimumSize">
</widget> <size>
<width>130</width>
<height>0</height>
</size>
</property>
<property name="text">
<string notr="true">TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>

View File

@ -1702,6 +1702,7 @@ void MainWindow::InitToolButtons()
connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup);
connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation);
connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint);
connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2970,6 +2971,7 @@ void MainWindow::SetLayoutModeActions()
{ {
const bool enabled = not scenes.isEmpty(); const bool enabled = not scenes.isEmpty();
ui->toolButtonLayoutExportAs->setEnabled(enabled);
ui->actionExportAs->setEnabled(enabled); ui->actionExportAs->setEnabled(enabled);
ui->actionPrintPreview->setEnabled(enabled); ui->actionPrintPreview->setEnabled(enabled);
ui->actionPrintPreviewTiled->setEnabled(enabled); ui->actionPrintPreviewTiled->setEnabled(enabled);
@ -3950,6 +3952,40 @@ void MainWindow::CreateMeasurements()
QProcess::startDetached(tape, QStringList(), workingDirectory); QProcess::startDetached(tape, QStringList(), workingDirectory);
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ExportLayoutAs()
{
if (isLayoutStale)
{
if (ContinueIfLayoutStale() == QMessageBox::No)
{
ui->toolButtonLayoutExportAs->setChecked(false);
return;
}
}
try
{
DialogSaveLayout dialog(scenes.size(), FileName(), this);
if (dialog.exec() == QDialog::Rejected)
{
ui->toolButtonLayoutExportAs->setChecked(false);
return;
}
ExportLayout(dialog);
}
catch (const VException &e)
{
ui->toolButtonLayoutExportAs->setChecked(false);
qCritical("%s\n\n%s\n\n%s", qUtf8Printable(tr("Export error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return;
}
ui->toolButtonLayoutExportAs->setChecked(false);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::ToolBarStyle(QToolBar *bar) void MainWindow::ToolBarStyle(QToolBar *bar)
{ {

View File

@ -113,6 +113,7 @@ private slots:
void ShowPaper(int index); void ShowPaper(int index);
void Preferences(); void Preferences();
void CreateMeasurements(); void CreateMeasurements();
void ExportLayoutAs();
void ArrowTool(); void ArrowTool();
void ToolEndLine(bool checked); void ToolEndLine(bool checked);

View File

@ -48,14 +48,14 @@
<string>Tools</string> <string>Tools</string>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>4</number> <number>6</number>
</property> </property>
<widget class="QWidget" name="page"> <widget class="QWidget" name="page">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>117</width> <width>100</width>
<height>358</height> <height>358</height>
</rect> </rect>
</property> </property>
@ -427,7 +427,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>130</width> <width>100</width>
<height>110</height> <height>110</height>
</rect> </rect>
</property> </property>
@ -536,7 +536,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>130</width> <width>100</width>
<height>248</height> <height>248</height>
</rect> </rect>
</property> </property>
@ -798,7 +798,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>130</width> <width>100</width>
<height>248</height> <height>248</height>
</rect> </rect>
</property> </property>
@ -1063,8 +1063,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>130</width> <width>100</width>
<height>356</height> <height>104</height>
</rect> </rect>
</property> </property>
<attribute name="icon"> <attribute name="icon">
@ -1163,7 +1163,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>130</width> <width>100</width>
<height>104</height> <height>104</height>
</rect> </rect>
</property> </property>
@ -1316,6 +1316,32 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QToolButton" name="toolButtonLayoutExportAs">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Export original layout</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset resource="../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/32x32/export_to_picture_document.png</normaloff>:/icon/32x32/export_to_picture_document.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -182,43 +182,21 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ExportLayoutAs()
{
if (isLayoutStale)
{
if (ContinueIfLayoutStale() == QMessageBox::No)
{
return;
}
}
try
{
DialogSaveLayout dialog(scenes.size(), FileName(), this);
if (dialog.exec() == QDialog::Rejected)
{
return;
}
ExportLayout(dialog);
}
catch (const VException &e)
{
qCritical("%s\n\n%s\n\n%s", qUtf8Printable(tr("Export error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return;
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog)
{ {
QString suf = dialog.Formate(); const QString suf = dialog.Format().replace(".", "");
suf.replace(".", "");
const QString path = dialog.Path(); const QString path = dialog.Path();
QDir dir(path);
dir.setPath(path);
if (not dir.exists(path))
{
if (not dir.mkpath(path))
{
qCritical() << tr("Can't create path");
return;
}
}
qApp->ValentinaSettings()->SetPathLayout(path); qApp->ValentinaSettings()->SetPathLayout(path);
const QString mask = dialog.FileName(); const QString mask = dialog.FileName();
@ -227,13 +205,19 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog)
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i)); QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper) if (paper)
{ {
const QString name = path + "/" + mask+QString::number(i+1) + dialog.Formate(); const QString name = path + QLatin1String("/") + mask+QString::number(i+1) + dialog.Format();
QBrush *brush = new QBrush(); QBrush *brush = new QBrush();
brush->setColor( QColor( Qt::white ) ); brush->setColor( QColor( Qt::white ) );
scenes[i]->setBackgroundBrush( *brush ); scenes[i]->setBackgroundBrush( *brush );
shadows[i]->setVisible(false); shadows[i]->setVisible(false);
paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen));
const QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj" << "dxf"; const QStringList suffix = QStringList() << QLatin1String("svg")
<< QLatin1String("png")
<< QLatin1String("pdf")
<< QLatin1String("eps")
<< QLatin1String("ps")
<< QLatin1String("obj")
<< QLatin1String("dxf");
switch (suffix.indexOf(suf)) switch (suffix.indexOf(suf))
{ {
case 0: //svg case 0: //svg

View File

@ -53,7 +53,6 @@ public:
public slots: public slots:
void ToolLayoutSettings(bool checked); void ToolLayoutSettings(bool checked);
void ExportLayoutAs();
void SaveAsTiledPDF(); void SaveAsTiledPDF();
void PrintPreviewOrigin(); void PrintPreviewOrigin();
void PrintPreviewTiled(); void PrintPreviewTiled();
@ -98,6 +97,8 @@ protected:
virtual void PrepareSceneList()=0; virtual void PrepareSceneList()=0;
QIcon ScenePreview(int i) const; QIcon ScenePreview(int i) const;
bool LayoutSettings(VLayoutGenerator& lGenerator); bool LayoutSettings(VLayoutGenerator& lGenerator);
int ContinueIfLayoutStale();
QString FileName() const;
private slots: private slots:
void PrintPages (QPrinter *printer); void PrintPages (QPrinter *printer);
void ErrorConsoleMode(const LayoutErrors &state); void ErrorConsoleMode(const LayoutErrors &state);
@ -135,9 +136,6 @@ private:
bool isPagesUniform() const; bool isPagesUniform() const;
bool IsPagesFit(const QSizeF &printPaper) const; bool IsPagesFit(const QSizeF &printPaper) const;
QString FileName() const;
int ContinueIfLayoutStale();
}; };
#endif // MAINWINDOWSNOGUI_H #endif // MAINWINDOWSNOGUI_H