Saving the layout paper sheets.
--HG-- branch : feature
This commit is contained in:
parent
0b85380f20
commit
4a9e69d32f
151
src/app/dialogs/app/dialogsavelayout.cpp
Normal file
151
src/app/dialogs/app/dialogsavelayout.cpp
Normal file
|
@ -0,0 +1,151 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file dialogsavelayout.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 22 1, 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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "dialogsavelayout.h"
|
||||
#include "ui_dialogsavelayout.h"
|
||||
#include "../options.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogSaveLayout::DialogSaveLayout(const QMap<QString, QString> &formates, int count, QWidget *parent)
|
||||
:QDialog(parent), ui(new Ui::DialogSaveLAyout), count(count)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||
SCASSERT(bOk != nullptr);
|
||||
bOk->setEnabled(false);
|
||||
|
||||
QRegExpValidator *validator = new QRegExpValidator(QRegExp("^[\\w\\-. ]+$"), this);
|
||||
ui->lineEditMask->setValidator(validator);
|
||||
|
||||
QMap<QString, QString>::const_iterator i = formates.constBegin();
|
||||
while (i != formates.constEnd())
|
||||
{
|
||||
ui->comboBoxFormat->addItem(i.key(), QVariant(i.value()));
|
||||
++i;
|
||||
}
|
||||
|
||||
connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save);
|
||||
connect(ui->lineEditMask, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample);
|
||||
connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&DialogSaveLayout::ShowExample);
|
||||
connect(ui->pushButtonBrowse, &QPushButton::clicked, this, &DialogSaveLayout::Browse);
|
||||
connect(ui->lineEditPath, &QLineEdit::textChanged, this, &DialogSaveLayout::PathChanged);
|
||||
|
||||
ui->comboBoxFormat->setCurrentIndex(4);//svg
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogSaveLayout::~DialogSaveLayout()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString DialogSaveLayout::Path() const
|
||||
{
|
||||
return ui->lineEditPath->text();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString DialogSaveLayout::Mask() const
|
||||
{
|
||||
return ui->lineEditMask->text();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString DialogSaveLayout::Formate() const
|
||||
{
|
||||
return ui->comboBoxFormat->currentData().toString();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogSaveLayout::Save()
|
||||
{
|
||||
for (int i=0; i < count; ++i)
|
||||
{
|
||||
const QString name = Path()+"/"+Mask()+QString::number(i+1)+Formate();
|
||||
if (QFile::exists(name))
|
||||
{
|
||||
QMessageBox::StandardButton res = QMessageBox::question(this, tr("Name conflict"),
|
||||
tr("Folder already contain file with name %1. Rewrite all conflict file names?")
|
||||
.arg(name), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
|
||||
if (res == QMessageBox::No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogSaveLayout::ShowExample()
|
||||
{
|
||||
ui->labelExample->setText(tr("Example:") + Mask() + "1" + Formate());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogSaveLayout::Browse()
|
||||
{
|
||||
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder"), QDir::homePath(),
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
ui->lineEditPath->setText(dir);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogSaveLayout::PathChanged(const QString &text)
|
||||
{
|
||||
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||
SCASSERT(bOk != nullptr);
|
||||
|
||||
QPalette palette = ui->lineEditPath->palette();
|
||||
|
||||
QDir dir(text);
|
||||
dir.setPath(text);
|
||||
if (dir.exists(text))
|
||||
{
|
||||
bOk->setEnabled(true);
|
||||
palette.setColor(ui->lineEditPath->foregroundRole(), Qt::black);
|
||||
}
|
||||
else
|
||||
{
|
||||
bOk->setEnabled(false);
|
||||
palette.setColor(ui->lineEditPath->foregroundRole(), Qt::red);
|
||||
}
|
||||
|
||||
ui->lineEditPath->setPalette(palette);
|
||||
}
|
63
src/app/dialogs/app/dialogsavelayout.h
Normal file
63
src/app/dialogs/app/dialogsavelayout.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file dialogsavelayout.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 22 1, 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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef DIALOGSAVELAYOUT_H
|
||||
#define DIALOGSAVELAYOUT_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class DialogSaveLAyout;
|
||||
}
|
||||
|
||||
class DialogSaveLayout : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DialogSaveLayout(const QMap<QString, QString> &formates, int count, QWidget *parent = 0);
|
||||
~DialogSaveLayout();
|
||||
|
||||
QString Path() const;
|
||||
QString Mask() const;
|
||||
QString Formate() const;
|
||||
|
||||
public slots:
|
||||
void Save();
|
||||
void ShowExample();
|
||||
void Browse();
|
||||
void PathChanged(const QString &text);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogSaveLayout)
|
||||
Ui::DialogSaveLAyout *ui;
|
||||
int count;
|
||||
};
|
||||
|
||||
#endif // DIALOGSAVELAYOUT_H
|
140
src/app/dialogs/app/dialogsavelayout.ui
Normal file
140
src/app/dialogs/app/dialogsavelayout.ui
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogSaveLAyout</class>
|
||||
<widget class="QDialog" name="DialogSaveLAyout">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>692</width>
|
||||
<height>179</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>692</width>
|
||||
<height>179</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Mask:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Path:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>File format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEditPath"/>
|
||||
</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="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBoxFormat">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEditMask"/>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="labelExample">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>DialogSaveLAyout</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>DialogSaveLAyout</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -43,7 +43,8 @@ HEADERS += \
|
|||
$$PWD/app/dialogundo.h \
|
||||
$$PWD/tools/dialogcurveintersectaxis.h \
|
||||
$$PWD/app/dialoglayoutsettings.h \
|
||||
$$PWD/app/dialoglayoutprogress.h
|
||||
$$PWD/app/dialoglayoutprogress.h \
|
||||
dialogs/app/dialogsavelayout.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/tools/dialogtriangle.cpp \
|
||||
|
@ -85,7 +86,8 @@ SOURCES += \
|
|||
$$PWD/app/dialogundo.cpp \
|
||||
$$PWD/tools/dialogcurveintersectaxis.cpp \
|
||||
$$PWD/app/dialoglayoutsettings.cpp \
|
||||
$$PWD/app/dialoglayoutprogress.cpp
|
||||
$$PWD/app/dialoglayoutprogress.cpp \
|
||||
dialogs/app/dialogsavelayout.cpp
|
||||
|
||||
FORMS += \
|
||||
$$PWD/tools/dialogtriangle.ui \
|
||||
|
@ -121,4 +123,5 @@ FORMS += \
|
|||
$$PWD/app/dialogundo.ui \
|
||||
$$PWD/tools/dialogcurveintersectaxis.ui \
|
||||
$$PWD/app/dialoglayoutsettings.ui \
|
||||
$$PWD/app/dialoglayoutprogress.ui
|
||||
$$PWD/app/dialoglayoutprogress.ui \
|
||||
dialogs/app/dialogsavelayout.ui
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "../dialogs/app/dialoglayoutsettings.h"
|
||||
#include "../../libs/vlayout/vlayoutgenerator.h"
|
||||
#include "../dialogs/app/dialoglayoutprogress.h"
|
||||
#include "../dialogs/app/dialogsavelayout.h"
|
||||
|
||||
#include <QtSvg>
|
||||
#include <QPrinter>
|
||||
|
@ -54,7 +55,8 @@
|
|||
TableWindow::TableWindow(QWidget *parent)
|
||||
:QMainWindow(parent), ui(new Ui::TableWindow),
|
||||
listDetails(QVector<VLayoutDetail>()), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()),
|
||||
scenes(QList<QGraphicsScene *>()), fileName(QString()), description(QString()), tempScene(nullptr)
|
||||
scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()),fileName(QString()),
|
||||
description(QString()), tempScene(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
tempScene = new QGraphicsScene(QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)));
|
||||
|
@ -69,7 +71,7 @@ TableWindow::TableWindow(QWidget *parent)
|
|||
connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn);
|
||||
connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut);
|
||||
connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable);
|
||||
//connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene);
|
||||
connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene);
|
||||
connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout);
|
||||
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper);
|
||||
}
|
||||
|
@ -161,97 +163,68 @@ void TableWindow::StopTable()
|
|||
*/
|
||||
void TableWindow::saveScene()
|
||||
{
|
||||
// QMap<QString, QString> extByMessage;
|
||||
// extByMessage[ tr("Svg files (*.svg)") ] = ".svg";
|
||||
// extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
|
||||
// extByMessage[ tr("Images (*.png)") ] = ".png";
|
||||
// extByMessage[ tr("Wavefront OBJ (*.obj)") ] = ".obj";
|
||||
QMap<QString, QString> extByMessage = InitFormates();
|
||||
DialogSaveLayout dialog(extByMessage, scenes.size(), this);
|
||||
|
||||
// QProcess proc;
|
||||
// proc.start(PDFTOPS);
|
||||
// if (proc.waitForFinished(15000))
|
||||
// {
|
||||
// extByMessage[ tr("PS files (*.ps)") ] = ".ps";
|
||||
// extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qWarning()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
|
||||
// }
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// QString saveMessage;
|
||||
// QMapIterator<QString, QString> i(extByMessage);
|
||||
// while (i.hasNext())
|
||||
// {
|
||||
// i.next();
|
||||
// saveMessage += i.key();
|
||||
// if (i.hasNext())
|
||||
// {
|
||||
// saveMessage += ";;";
|
||||
// }
|
||||
// }
|
||||
QString suf = dialog.Formate();
|
||||
suf.replace(".", "");
|
||||
|
||||
// QString sf;
|
||||
// // the save function
|
||||
// QString dir = QDir::homePath()+"/"+fileName;
|
||||
// QString name = QFileDialog::getSaveFileName(this, tr("Save layout"), dir, saveMessage, &sf);
|
||||
QString path = dialog.Path();
|
||||
QString mask = dialog.Mask();
|
||||
|
||||
// if (name.isEmpty())
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // what if the user did not specify a suffix...?
|
||||
// QString suf = extByMessage.value(sf);
|
||||
// suf.replace(".", "");
|
||||
// QFileInfo f( name );
|
||||
// if (f.suffix().isEmpty() || f.suffix() != suf)
|
||||
// {
|
||||
// name += extByMessage.value(sf);
|
||||
// }
|
||||
|
||||
// QBrush *brush = new QBrush();
|
||||
// brush->setColor( QColor( Qt::white ) );
|
||||
// tableScene->setBackgroundBrush( *brush );
|
||||
// tableScene->clearSelection(); // Selections would also render to the file, so need delete them
|
||||
// shadowPaper->setVisible(false);
|
||||
// paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));
|
||||
// QFileInfo fi( name );
|
||||
// QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj";
|
||||
// switch (suffix.indexOf(fi.suffix()))
|
||||
// {
|
||||
// case 0: //svg
|
||||
// paper->setVisible(false);
|
||||
// SvgFile(name);
|
||||
// paper->setVisible(true);
|
||||
// break;
|
||||
// case 1: //png
|
||||
// PngFile(name);
|
||||
// break;
|
||||
// case 2: //pdf
|
||||
// PdfFile(name);
|
||||
// break;
|
||||
// case 3: //eps
|
||||
// EpsFile(name);
|
||||
// break;
|
||||
// case 4: //ps
|
||||
// PsFile(name);
|
||||
// break;
|
||||
// case 5: //obj
|
||||
// paper->setVisible(false);
|
||||
// ObjFile(name);
|
||||
// paper->setVisible(true);
|
||||
// break;
|
||||
// default:
|
||||
// qDebug() << "Can't recognize file suffix. File file "<<name<<Q_FUNC_INFO;
|
||||
// break;
|
||||
// }
|
||||
// paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
||||
// brush->setColor( QColor( Qt::gray ) );
|
||||
// brush->setStyle( Qt::SolidPattern );
|
||||
// tableScene->setBackgroundBrush( *brush );
|
||||
// shadowPaper->setVisible(true);
|
||||
// delete brush;
|
||||
for (int i=0; i < scenes.size(); ++i)
|
||||
{
|
||||
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
||||
if (paper)
|
||||
{
|
||||
const QString name = path + "/" + mask+QString::number(i+1) + dialog.Formate();
|
||||
QBrush *brush = new QBrush();
|
||||
brush->setColor( QColor( Qt::white ) );
|
||||
scenes[i]->setBackgroundBrush( *brush );
|
||||
shadows[i]->setVisible(false);
|
||||
paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));
|
||||
QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj";
|
||||
switch (suffix.indexOf(suf))
|
||||
{
|
||||
case 0: //svg
|
||||
paper->setVisible(false);
|
||||
SvgFile(name, i);
|
||||
paper->setVisible(true);
|
||||
break;
|
||||
case 1: //png
|
||||
PngFile(name, i);
|
||||
break;
|
||||
case 2: //pdf
|
||||
PdfFile(name, i);
|
||||
break;
|
||||
case 3: //eps
|
||||
EpsFile(name, i);
|
||||
break;
|
||||
case 4: //ps
|
||||
PsFile(name, i);
|
||||
break;
|
||||
case 5: //obj
|
||||
paper->setVisible(false);
|
||||
ObjFile(name, i);
|
||||
paper->setVisible(true);
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO;
|
||||
break;
|
||||
}
|
||||
paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
||||
brush->setColor( QColor( Qt::gray ) );
|
||||
brush->setStyle( Qt::SolidPattern );
|
||||
scenes[i]->setBackgroundBrush( *brush );
|
||||
shadows[i]->setVisible(true);
|
||||
delete brush;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -303,10 +276,10 @@ void TableWindow::Layout()
|
|||
{
|
||||
case LayoutErrors::NoError:
|
||||
ClearLayout();
|
||||
papers = lGenerator.GetItems();
|
||||
papers = lGenerator.GetPapersItems();
|
||||
details = lGenerator.GetAllDetails();
|
||||
CreateShadows();
|
||||
CreateScenes();
|
||||
// Create previews
|
||||
PrepareSceneList();
|
||||
break;
|
||||
case LayoutErrors::ProcessStoped:
|
||||
|
@ -326,23 +299,28 @@ void TableWindow::Layout()
|
|||
* @brief SvgFile save layout to svg file.
|
||||
* @param name name layout file.
|
||||
*/
|
||||
void TableWindow::SvgFile(const QString &name) const
|
||||
void TableWindow::SvgFile(const QString &name, int i) const
|
||||
{
|
||||
// QSvgGenerator generator;
|
||||
// generator.setFileName(name);
|
||||
// generator.setSize(paper->rect().size().toSize());
|
||||
// generator.setViewBox(paper->rect());
|
||||
// generator.setTitle("Valentina pattern");
|
||||
// generator.setDescription(description);
|
||||
// generator.setResolution(static_cast<int>(qApp->PrintDPI));
|
||||
// QPainter painter;
|
||||
// painter.begin(&generator);
|
||||
// painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
||||
// painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
// painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||
// tableScene->render(&painter);
|
||||
// painter.end();
|
||||
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
||||
if (paper)
|
||||
{
|
||||
QSvgGenerator generator;
|
||||
generator.setFileName(name);
|
||||
generator.setSize(paper->rect().size().toSize());
|
||||
generator.setViewBox(paper->rect());
|
||||
generator.setTitle("Valentina. Pattern layout");
|
||||
generator.setDescription(description);
|
||||
generator.setResolution(static_cast<int>(qApp->PrintDPI));
|
||||
QPainter painter;
|
||||
painter.begin(&generator);
|
||||
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap,
|
||||
Qt::RoundJoin));
|
||||
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||
scenes.at(i)->render(&painter);
|
||||
painter.end();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -350,21 +328,24 @@ void TableWindow::SvgFile(const QString &name) const
|
|||
* @brief PngFile save layout to png file.
|
||||
* @param name name layout file.
|
||||
*/
|
||||
void TableWindow::PngFile(const QString &name) const
|
||||
void TableWindow::PngFile(const QString &name, int i) const
|
||||
{
|
||||
// QRectF r = paper->rect();
|
||||
// qreal x=0, y=0, w=0, h=0;
|
||||
// r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents
|
||||
// // Create the image with the exact size of the shrunk scene
|
||||
// QImage image(QSize(static_cast<qint32>(w), static_cast<qint32>(h)), QImage::Format_ARGB32);
|
||||
// image.fill(Qt::transparent); // Start all pixels transparent
|
||||
// QPainter painter(&image);
|
||||
// painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
||||
// painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
// painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||
// tableScene->render(&painter);
|
||||
// image.save(name);
|
||||
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
||||
if (paper)
|
||||
{
|
||||
const QRectF r = paper->rect();
|
||||
// Create the image with the exact size of the shrunk scene
|
||||
QImage image(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_ARGB32);
|
||||
image.fill(Qt::transparent); // Start all pixels transparent
|
||||
QPainter painter(&image);
|
||||
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
|
||||
Qt::RoundJoin));
|
||||
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||
scenes.at(i)->render(&painter);
|
||||
image.save(name);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -372,28 +353,32 @@ void TableWindow::PngFile(const QString &name) const
|
|||
* @brief PdfFile save layout to pdf file.
|
||||
* @param name name layout file.
|
||||
*/
|
||||
void TableWindow::PdfFile(const QString &name) const
|
||||
void TableWindow::PdfFile(const QString &name, int i) const
|
||||
{
|
||||
// QPrinter printer;
|
||||
// printer.setOutputFormat(QPrinter::PdfFormat);
|
||||
// printer.setOutputFileName(name);
|
||||
// QRectF r = paper->rect();
|
||||
// qreal x=0, y=0, w=0, h=0;
|
||||
// r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents
|
||||
// printer.setResolution(static_cast<int>(qApp->PrintDPI));
|
||||
// printer.setPaperSize ( QSizeF(qApp->fromPixel(w, Unit::Mm), qApp->fromPixel(h, Unit::Mm)), QPrinter::Millimeter );
|
||||
// QPainter painter;
|
||||
// if (painter.begin( &printer ) == false)
|
||||
// { // failed to open file
|
||||
// qCritical("Can't open printer %s", qPrintable(name));
|
||||
// return;
|
||||
// }
|
||||
// painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
||||
// painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
// painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||
// tableScene->render(&painter);
|
||||
// painter.end();
|
||||
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
||||
if (paper)
|
||||
{
|
||||
QPrinter printer;
|
||||
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||
printer.setOutputFileName(name);
|
||||
const QRectF r = paper->rect();
|
||||
printer.setResolution(static_cast<int>(qApp->PrintDPI));
|
||||
printer.setPaperSize ( QSizeF(qApp->fromPixel(r.width(), Unit::Mm), qApp->fromPixel(r.height(), Unit::Mm)),
|
||||
QPrinter::Millimeter );
|
||||
QPainter painter;
|
||||
if (painter.begin( &printer ) == false)
|
||||
{ // failed to open file
|
||||
qCritical("Can't open printer %s", qPrintable(name));
|
||||
return;
|
||||
}
|
||||
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
|
||||
Qt::RoundJoin));
|
||||
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||
scenes.at(i)->render(&painter);
|
||||
painter.end();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -401,15 +386,15 @@ void TableWindow::PdfFile(const QString &name) const
|
|||
* @brief EpsFile save layout to eps file.
|
||||
* @param name name layout file.
|
||||
*/
|
||||
void TableWindow::EpsFile(const QString &name) const
|
||||
void TableWindow::EpsFile(const QString &name, int i) const
|
||||
{
|
||||
// QTemporaryFile tmp;
|
||||
// if (tmp.open())
|
||||
// {
|
||||
// PdfFile(tmp.fileName());
|
||||
// QStringList params = QStringList() << "-eps" << tmp.fileName() << name;
|
||||
// PdfToPs(params);
|
||||
// }
|
||||
QTemporaryFile tmp;
|
||||
if (tmp.open())
|
||||
{
|
||||
PdfFile(tmp.fileName(), i);
|
||||
QStringList params = QStringList() << "-eps" << tmp.fileName() << name;
|
||||
PdfToPs(params);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -417,15 +402,15 @@ void TableWindow::EpsFile(const QString &name) const
|
|||
* @brief PsFile save layout to ps file.
|
||||
* @param name name layout file.
|
||||
*/
|
||||
void TableWindow::PsFile(const QString &name) const
|
||||
void TableWindow::PsFile(const QString &name, int i) const
|
||||
{
|
||||
// QTemporaryFile tmp;
|
||||
// if (tmp.open())
|
||||
// {
|
||||
// PdfFile(tmp.fileName());
|
||||
// QStringList params = QStringList() << tmp.fileName() << name;
|
||||
// PdfToPs(params);
|
||||
// }
|
||||
QTemporaryFile tmp;
|
||||
if (tmp.open())
|
||||
{
|
||||
PdfFile(tmp.fileName(), i);
|
||||
QStringList params = QStringList() << tmp.fileName() << name;
|
||||
PdfToPs(params);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -436,36 +421,40 @@ void TableWindow::PsFile(const QString &name) const
|
|||
*/
|
||||
void TableWindow::PdfToPs(const QStringList ¶ms) const
|
||||
{
|
||||
//#ifndef QT_NO_CURSOR
|
||||
// QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
//#endif
|
||||
// QProcess proc;
|
||||
// proc.start(PDFTOPS, params);
|
||||
// proc.waitForFinished(15000);
|
||||
//#ifndef QT_NO_CURSOR
|
||||
// QApplication::restoreOverrideCursor();
|
||||
//#endif
|
||||
#ifndef QT_NO_CURSOR
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
#endif
|
||||
QProcess proc;
|
||||
proc.start(PDFTOPS, params);
|
||||
proc.waitForFinished(15000);
|
||||
#ifndef QT_NO_CURSOR
|
||||
QApplication::restoreOverrideCursor();
|
||||
#endif
|
||||
|
||||
// QFile f(params.last());
|
||||
// if (f.exists() == false)
|
||||
// {
|
||||
// QString msg = QString(tr("Creating file '%1' failed! %2")).arg(params.last()).arg(proc.errorString());
|
||||
// QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default);
|
||||
// msgBox.exec();
|
||||
// }
|
||||
QFile f(params.last());
|
||||
if (f.exists() == false)
|
||||
{
|
||||
QString msg = QString(tr("Creating file '%1' failed! %2")).arg(params.last()).arg(proc.errorString());
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default);
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TableWindow::ObjFile(const QString &name) const
|
||||
void TableWindow::ObjFile(const QString &name, int i) const
|
||||
{
|
||||
// VObjPaintDevice generator;
|
||||
// generator.setFileName(name);
|
||||
// generator.setSize(paper->rect().size().toSize());
|
||||
// generator.setResolution(static_cast<int>(qApp->PrintDPI));
|
||||
// QPainter painter;
|
||||
// painter.begin(&generator);
|
||||
// tableScene->render(&painter);
|
||||
// painter.end();
|
||||
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
||||
if (paper)
|
||||
{
|
||||
VObjPaintDevice generator;
|
||||
generator.setFileName(name);
|
||||
generator.setSize(paper->rect().size().toSize());
|
||||
generator.setResolution(static_cast<int>(qApp->PrintDPI));
|
||||
QPainter painter;
|
||||
painter.begin(&generator);
|
||||
scenes.at(i)->render(&painter);
|
||||
painter.end();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -512,6 +501,13 @@ void TableWindow::CreateScenes()
|
|||
scene->setBackgroundBrush(brush);
|
||||
scene->addItem(shadows.at(i));
|
||||
scene->addItem(papers.at(i));
|
||||
|
||||
QList<QGraphicsItem *> paperDetails = details.at(i);
|
||||
for (int i=0; i < paperDetails.size(); ++i)
|
||||
{
|
||||
scene->addItem(paperDetails.at(i));
|
||||
}
|
||||
|
||||
scenes.append(scene);
|
||||
}
|
||||
}
|
||||
|
@ -559,3 +555,26 @@ QIcon TableWindow::ScenePreview(int i) const
|
|||
}
|
||||
return QIcon(QBitmap::fromImage(image));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<QString, QString> TableWindow::InitFormates() const
|
||||
{
|
||||
QMap<QString, QString> extByMessage;
|
||||
extByMessage[ tr("Svg files (*.svg)") ] = ".svg";
|
||||
extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
|
||||
extByMessage[ tr("Images (*.png)") ] = ".png";
|
||||
extByMessage[ tr("Wavefront OBJ (*.obj)") ] = ".obj";
|
||||
|
||||
QProcess proc;
|
||||
proc.start(PDFTOPS);
|
||||
if (proc.waitForFinished(15000))
|
||||
{
|
||||
extByMessage[ tr("PS files (*.ps)") ] = ".ps";
|
||||
extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
|
||||
}
|
||||
return extByMessage;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace Ui
|
|||
}
|
||||
|
||||
class QGraphicsScene;
|
||||
class QGraphicsRectItem;
|
||||
|
||||
/**
|
||||
* @brief TableWindow class layout window.
|
||||
|
@ -80,6 +81,7 @@ private:
|
|||
QList<QGraphicsItem *> papers;
|
||||
QList<QGraphicsItem *> shadows;
|
||||
QList<QGraphicsScene *> scenes;
|
||||
QList<QList<QGraphicsItem *> > details;
|
||||
|
||||
/** @brief fileName keep name of pattern file. */
|
||||
QString fileName;
|
||||
|
@ -89,19 +91,20 @@ private:
|
|||
|
||||
QGraphicsScene* tempScene;
|
||||
|
||||
void SvgFile(const QString &name)const;
|
||||
void PngFile(const QString &name)const;
|
||||
void PdfFile(const QString &name)const;
|
||||
void EpsFile(const QString &name)const;
|
||||
void PsFile(const QString &name)const;
|
||||
void SvgFile(const QString &name, int i)const;
|
||||
void PngFile(const QString &name, int i)const;
|
||||
void PdfFile(const QString &name, int i)const;
|
||||
void EpsFile(const QString &name, int i)const;
|
||||
void PsFile(const QString &name, int i)const;
|
||||
void PdfToPs(const QStringList ¶ms)const;
|
||||
void ObjFile(const QString &name)const;
|
||||
void ObjFile(const QString &name, int i)const;
|
||||
|
||||
void ClearLayout();
|
||||
void CreateShadows();
|
||||
void CreateScenes();
|
||||
void PrepareSceneList();
|
||||
QIcon ScenePreview(int i) const;
|
||||
QMap<QString, QString> InitFormates() const;
|
||||
};
|
||||
|
||||
#endif // TABLEWINDOW_H
|
||||
|
|
|
@ -155,12 +155,23 @@ LayoutErrors VLayoutGenerator::State() const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QList<QGraphicsItem *> VLayoutGenerator::GetItems() const
|
||||
QList<QGraphicsItem *> VLayoutGenerator::GetPapersItems() const
|
||||
{
|
||||
QList<QGraphicsItem *> list;
|
||||
for (int i=0; i < papers.count(); ++i)
|
||||
{
|
||||
list.append(papers.at(i).GetItem());
|
||||
list.append(papers.at(i).GetPaperItem());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QList<QList<QGraphicsItem *> > VLayoutGenerator::GetAllDetails() const
|
||||
{
|
||||
QList<QList<QGraphicsItem *> > list;
|
||||
for (int i=0; i < papers.count(); ++i)
|
||||
{
|
||||
list.append(papers.at(i).GetDetails());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ public:
|
|||
|
||||
LayoutErrors State() const;
|
||||
|
||||
QList<QGraphicsItem *> GetItems() const;
|
||||
QList<QGraphicsItem *> GetPapersItems() const;
|
||||
QList<QList<QGraphicsItem *>> GetAllDetails() const;
|
||||
|
||||
bool GetRotate() const;
|
||||
void SetRotate(bool value);
|
||||
|
|
|
@ -270,16 +270,22 @@ void VLayoutPaper::SaveCandidate(VBestSquare &bestResult, const VLayoutDetail &d
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsItem *VLayoutPaper::GetItem() const
|
||||
QGraphicsRectItem *VLayoutPaper::GetPaperItem() const
|
||||
{
|
||||
QGraphicsRectItem *paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(),
|
||||
d->globalContour.GetHeight()));
|
||||
paper->setPen(QPen(Qt::black, 1));
|
||||
paper->setBrush(QBrush(Qt::white));
|
||||
for (int i=0; i < d->details.count(); ++i)
|
||||
{
|
||||
QGraphicsItem *item = d->details.at(i).GetItem();
|
||||
item->setParentItem(paper);
|
||||
}
|
||||
return paper;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QList<QGraphicsItem *> VLayoutPaper::GetDetails() const
|
||||
{
|
||||
QList<QGraphicsItem *> list;
|
||||
for (int i=0; i < d->details.count(); ++i)
|
||||
{
|
||||
list.append(d->details.at(i).GetItem());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ class VLayoutPaperData;
|
|||
class VLayoutDetail;
|
||||
class QGraphicsItem;
|
||||
class VBestSquare;
|
||||
class QGraphicsRectItem;
|
||||
|
||||
class VLayoutPaper
|
||||
{
|
||||
|
@ -68,7 +69,8 @@ public:
|
|||
|
||||
bool ArrangeDetail(const VLayoutDetail &detail, bool &stop);
|
||||
int Count() const;
|
||||
QGraphicsItem *GetItem() const;
|
||||
QGraphicsRectItem *GetPaperItem() const;
|
||||
QList<QGraphicsItem *> GetDetails() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<VLayoutPaperData> d;
|
||||
|
|
Loading…
Reference in New Issue
Block a user