From 1a56b2721ac143170464c6030c502f10aa62a9ca Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 15 Aug 2016 15:03:10 +0300 Subject: [PATCH] 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 --- .../valentina/dialogs/dialogsavelayout.cpp | 27 ++-- src/app/valentina/dialogs/dialogsavelayout.h | 2 +- src/app/valentina/dialogs/dialogsavelayout.ui | 152 +++++++++++------- src/app/valentina/mainwindow.cpp | 36 +++++ src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 42 ++++- src/app/valentina/mainwindowsnogui.cpp | 54 +++---- src/app/valentina/mainwindowsnogui.h | 6 +- 8 files changed, 202 insertions(+), 118 deletions(-) diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index c1eae6432..8ffd7f78d 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -91,15 +91,22 @@ DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget * } 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->comboBoxFormat, static_cast(&QComboBox::currentIndexChanged), ShowExample); 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); - 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); @@ -128,12 +135,12 @@ void DialogSaveLayout::SelectFormate(const int formate) //--------------------------------------------------------------------------------------------------------------------- QString DialogSaveLayout::MakeHelpFormatList() { - QString out = "\n"; + QString out("\n"); int cntr = 0; const QVector> availFormats = InitAvailFormats(); 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; } @@ -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) return ui->comboBoxFormat->itemData(ui->comboBoxFormat->currentIndex()).toString(); @@ -198,7 +205,7 @@ void DialogSaveLayout::Save() { 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)) { QMessageBox::StandardButton res = QMessageBox::question(this, tr("Name conflict"), @@ -256,8 +263,7 @@ void DialogSaveLayout::showEvent(QShowEvent *event) } // do your init stuff here - setMaximumSize(size()); - setMinimumSize(size()); + setFixedHeight(size().height()); isInitialized = true;//first show windows are held } @@ -280,7 +286,8 @@ bool DialogSaveLayout::TestPdf() QProcess proc; #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 proc.start(PDFTOPS); // Seek pdftops in standard path #endif diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index 9a3739bb8..af1990831 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -53,7 +53,7 @@ public: QString Path() const; QString FileName() const; - QString Formate() const; + QString Format() const; void SelectFormate(const int formate); static QString MakeHelpFormatList(); void SetDestinationPath(const QString& cmdDestinationPath); diff --git a/src/app/valentina/dialogs/dialogsavelayout.ui b/src/app/valentina/dialogs/dialogsavelayout.ui index 52cfa6a5e..87c190ff1 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.ui +++ b/src/app/valentina/dialogs/dialogsavelayout.ui @@ -6,8 +6,8 @@ 0 0 - 692 - 179 + 748 + 150 @@ -19,17 +19,19 @@ - - - 0 + + + QLayout::SetDefaultConstraint + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - File name: - - - @@ -37,6 +39,42 @@ + + + + + + + 0 + 0 + + + + Destination folder + + + Path to destination folder + + + + + + + + 0 + 0 + + + + Select path to destination folder + + + Browse... + + + + + @@ -44,64 +82,58 @@ - - - - Destination folder - - - Path to destination folder. - - - - - - - - 0 - 0 - - - - Select path to destination folder - - - Browse... - - - - + 0 0 + + + + File name: + + + - - - File base name - - - File base name. - - - - - - - - 130 - 0 - - - - TextLabel - - + + + + + + 0 + 0 + + + + File base name + + + File base name + + + + + + + + 130 + 0 + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index f579bb0c9..3eab696c4 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1702,6 +1702,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); 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(); + ui->toolButtonLayoutExportAs->setEnabled(enabled); ui->actionExportAs->setEnabled(enabled); ui->actionPrintPreview->setEnabled(enabled); ui->actionPrintPreviewTiled->setEnabled(enabled); @@ -3950,6 +3952,40 @@ void MainWindow::CreateMeasurements() 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) { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 581159fae..375ffcda4 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -113,6 +113,7 @@ private slots: void ShowPaper(int index); void Preferences(); void CreateMeasurements(); + void ExportLayoutAs(); void ArrowTool(); void ToolEndLine(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index b724c7cef..ae7bebe5e 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -48,14 +48,14 @@ Tools - 4 + 6 0 0 - 117 + 100 358 @@ -427,7 +427,7 @@ 0 0 - 130 + 100 110 @@ -536,7 +536,7 @@ 0 0 - 130 + 100 248 @@ -798,7 +798,7 @@ 0 0 - 130 + 100 248 @@ -1063,8 +1063,8 @@ 0 0 - 130 - 356 + 100 + 104 @@ -1163,7 +1163,7 @@ 0 0 - 130 + 100 104 @@ -1316,6 +1316,32 @@ + + + + false + + + Export original layout + + + ... + + + + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 6db890d61..0c478f573 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -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) { - QString suf = dialog.Formate(); - suf.replace(".", ""); - + const QString suf = dialog.Format().replace(".", ""); 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); const QString mask = dialog.FileName(); @@ -227,13 +205,19 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); 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(); brush->setColor( QColor( Qt::white ) ); scenes[i]->setBackgroundBrush( *brush ); shadows[i]->setVisible(false); 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)) { case 0: //svg diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 4d5780319..84394802a 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -53,7 +53,6 @@ public: public slots: void ToolLayoutSettings(bool checked); - void ExportLayoutAs(); void SaveAsTiledPDF(); void PrintPreviewOrigin(); void PrintPreviewTiled(); @@ -98,6 +97,8 @@ protected: virtual void PrepareSceneList()=0; QIcon ScenePreview(int i) const; bool LayoutSettings(VLayoutGenerator& lGenerator); + int ContinueIfLayoutStale(); + QString FileName() const; private slots: void PrintPages (QPrinter *printer); void ErrorConsoleMode(const LayoutErrors &state); @@ -135,9 +136,6 @@ private: bool isPagesUniform() const; bool IsPagesFit(const QSizeF &printPaper) const; - QString FileName() const; - - int ContinueIfLayoutStale(); }; #endif // MAINWINDOWSNOGUI_H