Saving the layout paper sheets.

--HG--
branch : feature
This commit is contained in:
dismine 2015-01-23 12:07:58 +02:00
parent 0b85380f20
commit 4a9e69d32f
10 changed files with 601 additions and 202 deletions

View 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);
}

View 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

View 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>

View file

@ -43,7 +43,8 @@ HEADERS += \
$$PWD/app/dialogundo.h \ $$PWD/app/dialogundo.h \
$$PWD/tools/dialogcurveintersectaxis.h \ $$PWD/tools/dialogcurveintersectaxis.h \
$$PWD/app/dialoglayoutsettings.h \ $$PWD/app/dialoglayoutsettings.h \
$$PWD/app/dialoglayoutprogress.h $$PWD/app/dialoglayoutprogress.h \
dialogs/app/dialogsavelayout.h
SOURCES += \ SOURCES += \
$$PWD/tools/dialogtriangle.cpp \ $$PWD/tools/dialogtriangle.cpp \
@ -85,7 +86,8 @@ SOURCES += \
$$PWD/app/dialogundo.cpp \ $$PWD/app/dialogundo.cpp \
$$PWD/tools/dialogcurveintersectaxis.cpp \ $$PWD/tools/dialogcurveintersectaxis.cpp \
$$PWD/app/dialoglayoutsettings.cpp \ $$PWD/app/dialoglayoutsettings.cpp \
$$PWD/app/dialoglayoutprogress.cpp $$PWD/app/dialoglayoutprogress.cpp \
dialogs/app/dialogsavelayout.cpp
FORMS += \ FORMS += \
$$PWD/tools/dialogtriangle.ui \ $$PWD/tools/dialogtriangle.ui \
@ -121,4 +123,5 @@ FORMS += \
$$PWD/app/dialogundo.ui \ $$PWD/app/dialogundo.ui \
$$PWD/tools/dialogcurveintersectaxis.ui \ $$PWD/tools/dialogcurveintersectaxis.ui \
$$PWD/app/dialoglayoutsettings.ui \ $$PWD/app/dialoglayoutsettings.ui \
$$PWD/app/dialoglayoutprogress.ui $$PWD/app/dialoglayoutprogress.ui \
dialogs/app/dialogsavelayout.ui

View file

@ -34,6 +34,7 @@
#include "../dialogs/app/dialoglayoutsettings.h" #include "../dialogs/app/dialoglayoutsettings.h"
#include "../../libs/vlayout/vlayoutgenerator.h" #include "../../libs/vlayout/vlayoutgenerator.h"
#include "../dialogs/app/dialoglayoutprogress.h" #include "../dialogs/app/dialoglayoutprogress.h"
#include "../dialogs/app/dialogsavelayout.h"
#include <QtSvg> #include <QtSvg>
#include <QPrinter> #include <QPrinter>
@ -54,7 +55,8 @@
TableWindow::TableWindow(QWidget *parent) TableWindow::TableWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::TableWindow), :QMainWindow(parent), ui(new Ui::TableWindow),
listDetails(QVector<VLayoutDetail>()), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()), 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); ui->setupUi(this);
tempScene = new QGraphicsScene(QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm))); 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->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn);
connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut); connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut);
connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable); 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->actionLayout, &QAction::triggered, this, &TableWindow::Layout);
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper);
} }
@ -161,97 +163,68 @@ void TableWindow::StopTable()
*/ */
void TableWindow::saveScene() void TableWindow::saveScene()
{ {
// QMap<QString, QString> extByMessage; QMap<QString, QString> extByMessage = InitFormates();
// extByMessage[ tr("Svg files (*.svg)") ] = ".svg"; DialogSaveLayout dialog(extByMessage, scenes.size(), this);
// extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
// extByMessage[ tr("Images (*.png)") ] = ".png";
// extByMessage[ tr("Wavefront OBJ (*.obj)") ] = ".obj";
// QProcess proc; if (dialog.exec() == QDialog::Rejected)
// proc.start(PDFTOPS); {
// if (proc.waitForFinished(15000)) return;
// { }
// extByMessage[ tr("PS files (*.ps)") ] = ".ps";
// extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
// }
// else
// {
// qWarning()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
// }
// QString saveMessage; QString suf = dialog.Formate();
// QMapIterator<QString, QString> i(extByMessage); suf.replace(".", "");
// while (i.hasNext())
// {
// i.next();
// saveMessage += i.key();
// if (i.hasNext())
// {
// saveMessage += ";;";
// }
// }
// QString sf; QString path = dialog.Path();
// // the save function QString mask = dialog.Mask();
// QString dir = QDir::homePath()+"/"+fileName;
// QString name = QFileDialog::getSaveFileName(this, tr("Save layout"), dir, saveMessage, &sf);
// if (name.isEmpty()) for (int i=0; i < scenes.size(); ++i)
// { {
// return; QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
// } if (paper)
{
// // what if the user did not specify a suffix...? const QString name = path + "/" + mask+QString::number(i+1) + dialog.Formate();
// QString suf = extByMessage.value(sf); QBrush *brush = new QBrush();
// suf.replace(".", ""); brush->setColor( QColor( Qt::white ) );
// QFileInfo f( name ); scenes[i]->setBackgroundBrush( *brush );
// if (f.suffix().isEmpty() || f.suffix() != suf) shadows[i]->setVisible(false);
// { paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));
// name += extByMessage.value(sf); QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj";
// } switch (suffix.indexOf(suf))
{
// QBrush *brush = new QBrush(); case 0: //svg
// brush->setColor( QColor( Qt::white ) ); paper->setVisible(false);
// tableScene->setBackgroundBrush( *brush ); SvgFile(name, i);
// tableScene->clearSelection(); // Selections would also render to the file, so need delete them paper->setVisible(true);
// shadowPaper->setVisible(false); break;
// paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); case 1: //png
// QFileInfo fi( name ); PngFile(name, i);
// QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj"; break;
// switch (suffix.indexOf(fi.suffix())) case 2: //pdf
// { PdfFile(name, i);
// case 0: //svg break;
// paper->setVisible(false); case 3: //eps
// SvgFile(name); EpsFile(name, i);
// paper->setVisible(true); break;
// break; case 4: //ps
// case 1: //png PsFile(name, i);
// PngFile(name); break;
// break; case 5: //obj
// case 2: //pdf paper->setVisible(false);
// PdfFile(name); ObjFile(name, i);
// break; paper->setVisible(true);
// case 3: //eps break;
// EpsFile(name); default:
// break; qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO;
// case 4: //ps break;
// PsFile(name); }
// break; paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
// case 5: //obj brush->setColor( QColor( Qt::gray ) );
// paper->setVisible(false); brush->setStyle( Qt::SolidPattern );
// ObjFile(name); scenes[i]->setBackgroundBrush( *brush );
// paper->setVisible(true); shadows[i]->setVisible(true);
// break; delete brush;
// 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;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -303,10 +276,10 @@ void TableWindow::Layout()
{ {
case LayoutErrors::NoError: case LayoutErrors::NoError:
ClearLayout(); ClearLayout();
papers = lGenerator.GetItems(); papers = lGenerator.GetPapersItems();
details = lGenerator.GetAllDetails();
CreateShadows(); CreateShadows();
CreateScenes(); CreateScenes();
// Create previews
PrepareSceneList(); PrepareSceneList();
break; break;
case LayoutErrors::ProcessStoped: case LayoutErrors::ProcessStoped:
@ -326,23 +299,28 @@ void TableWindow::Layout()
* @brief SvgFile save layout to svg file. * @brief SvgFile save layout to svg file.
* @param name name layout file. * @param name name layout file.
*/ */
void TableWindow::SvgFile(const QString &name) const void TableWindow::SvgFile(const QString &name, int i) const
{ {
// QSvgGenerator generator; QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
// generator.setFileName(name); if (paper)
// generator.setSize(paper->rect().size().toSize()); {
// generator.setViewBox(paper->rect()); QSvgGenerator generator;
// generator.setTitle("Valentina pattern"); generator.setFileName(name);
// generator.setDescription(description); generator.setSize(paper->rect().size().toSize());
// generator.setResolution(static_cast<int>(qApp->PrintDPI)); generator.setViewBox(paper->rect());
// QPainter painter; generator.setTitle("Valentina. Pattern layout");
// painter.begin(&generator); generator.setDescription(description);
// painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); generator.setResolution(static_cast<int>(qApp->PrintDPI));
// painter.setRenderHint(QPainter::Antialiasing, true); QPainter painter;
// painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.begin(&generator);
// painter.setBrush ( QBrush ( Qt::NoBrush ) ); painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
// tableScene->render(&painter); painter.setRenderHint(QPainter::Antialiasing, true);
// painter.end(); 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. * @brief PngFile save layout to png file.
* @param name name layout 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(); QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
// qreal x=0, y=0, w=0, h=0; if (paper)
// 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 const QRectF r = paper->rect();
// QImage image(QSize(static_cast<qint32>(w), static_cast<qint32>(h)), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
// image.fill(Qt::transparent); // Start all pixels transparent QImage image(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_ARGB32);
// QPainter painter(&image); image.fill(Qt::transparent); // Start all pixels transparent
// painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); QPainter painter(&image);
// painter.setRenderHint(QPainter::Antialiasing, true); painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
// painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setRenderHint(QPainter::Antialiasing, true);
// painter.setBrush ( QBrush ( Qt::NoBrush ) ); painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
// tableScene->render(&painter); Qt::RoundJoin));
// image.save(name); 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. * @brief PdfFile save layout to pdf file.
* @param name name layout file. * @param name name layout file.
*/ */
void TableWindow::PdfFile(const QString &name) const void TableWindow::PdfFile(const QString &name, int i) const
{ {
// QPrinter printer; QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
// printer.setOutputFormat(QPrinter::PdfFormat); if (paper)
// printer.setOutputFileName(name); {
// QRectF r = paper->rect(); QPrinter printer;
// qreal x=0, y=0, w=0, h=0; printer.setOutputFormat(QPrinter::PdfFormat);
// r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents printer.setOutputFileName(name);
// printer.setResolution(static_cast<int>(qApp->PrintDPI)); const QRectF r = paper->rect();
// printer.setPaperSize ( QSizeF(qApp->fromPixel(w, Unit::Mm), qApp->fromPixel(h, Unit::Mm)), QPrinter::Millimeter ); printer.setResolution(static_cast<int>(qApp->PrintDPI));
// QPainter painter; printer.setPaperSize ( QSizeF(qApp->fromPixel(r.width(), Unit::Mm), qApp->fromPixel(r.height(), Unit::Mm)),
// if (painter.begin( &printer ) == false) QPrinter::Millimeter );
// { // failed to open file QPainter painter;
// qCritical("Can't open printer %s", qPrintable(name)); if (painter.begin( &printer ) == false)
// return; { // failed to open file
// } qCritical("Can't open printer %s", qPrintable(name));
// painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); return;
// painter.setRenderHint(QPainter::Antialiasing, true); }
// painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
// painter.setBrush ( QBrush ( Qt::NoBrush ) ); painter.setRenderHint(QPainter::Antialiasing, true);
// tableScene->render(&painter); painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
// painter.end(); 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. * @brief EpsFile save layout to eps file.
* @param name name layout file. * @param name name layout file.
*/ */
void TableWindow::EpsFile(const QString &name) const void TableWindow::EpsFile(const QString &name, int i) const
{ {
// QTemporaryFile tmp; QTemporaryFile tmp;
// if (tmp.open()) if (tmp.open())
// { {
// PdfFile(tmp.fileName()); PdfFile(tmp.fileName(), i);
// QStringList params = QStringList() << "-eps" << tmp.fileName() << name; QStringList params = QStringList() << "-eps" << tmp.fileName() << name;
// PdfToPs(params); PdfToPs(params);
// } }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -417,15 +402,15 @@ void TableWindow::EpsFile(const QString &name) const
* @brief PsFile save layout to ps file. * @brief PsFile save layout to ps file.
* @param name name layout file. * @param name name layout file.
*/ */
void TableWindow::PsFile(const QString &name) const void TableWindow::PsFile(const QString &name, int i) const
{ {
// QTemporaryFile tmp; QTemporaryFile tmp;
// if (tmp.open()) if (tmp.open())
// { {
// PdfFile(tmp.fileName()); PdfFile(tmp.fileName(), i);
// QStringList params = QStringList() << tmp.fileName() << name; QStringList params = QStringList() << tmp.fileName() << name;
// PdfToPs(params); PdfToPs(params);
// } }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -436,36 +421,40 @@ void TableWindow::PsFile(const QString &name) const
*/ */
void TableWindow::PdfToPs(const QStringList &params) const void TableWindow::PdfToPs(const QStringList &params) const
{ {
//#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
// QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
//#endif #endif
// QProcess proc; QProcess proc;
// proc.start(PDFTOPS, params); proc.start(PDFTOPS, params);
// proc.waitForFinished(15000); proc.waitForFinished(15000);
//#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
// QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
//#endif #endif
// QFile f(params.last()); QFile f(params.last());
// if (f.exists() == false) if (f.exists() == false)
// { {
// QString msg = QString(tr("Creating file '%1' failed! %2")).arg(params.last()).arg(proc.errorString()); 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); QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default);
// msgBox.exec(); msgBox.exec();
// } }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TableWindow::ObjFile(const QString &name) const void TableWindow::ObjFile(const QString &name, int i) const
{ {
// VObjPaintDevice generator; QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
// generator.setFileName(name); if (paper)
// generator.setSize(paper->rect().size().toSize()); {
// generator.setResolution(static_cast<int>(qApp->PrintDPI)); VObjPaintDevice generator;
// QPainter painter; generator.setFileName(name);
// painter.begin(&generator); generator.setSize(paper->rect().size().toSize());
// tableScene->render(&painter); generator.setResolution(static_cast<int>(qApp->PrintDPI));
// painter.end(); QPainter painter;
painter.begin(&generator);
scenes.at(i)->render(&painter);
painter.end();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -512,6 +501,13 @@ void TableWindow::CreateScenes()
scene->setBackgroundBrush(brush); scene->setBackgroundBrush(brush);
scene->addItem(shadows.at(i)); scene->addItem(shadows.at(i));
scene->addItem(papers.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); scenes.append(scene);
} }
} }
@ -559,3 +555,26 @@ QIcon TableWindow::ScenePreview(int i) const
} }
return QIcon(QBitmap::fromImage(image)); 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;
}

View file

@ -41,6 +41,7 @@ namespace Ui
} }
class QGraphicsScene; class QGraphicsScene;
class QGraphicsRectItem;
/** /**
* @brief TableWindow class layout window. * @brief TableWindow class layout window.
@ -80,6 +81,7 @@ private:
QList<QGraphicsItem *> papers; QList<QGraphicsItem *> papers;
QList<QGraphicsItem *> shadows; QList<QGraphicsItem *> shadows;
QList<QGraphicsScene *> scenes; QList<QGraphicsScene *> scenes;
QList<QList<QGraphicsItem *> > details;
/** @brief fileName keep name of pattern file. */ /** @brief fileName keep name of pattern file. */
QString fileName; QString fileName;
@ -89,19 +91,20 @@ private:
QGraphicsScene* tempScene; QGraphicsScene* tempScene;
void SvgFile(const QString &name)const; void SvgFile(const QString &name, int i)const;
void PngFile(const QString &name)const; void PngFile(const QString &name, int i)const;
void PdfFile(const QString &name)const; void PdfFile(const QString &name, int i)const;
void EpsFile(const QString &name)const; void EpsFile(const QString &name, int i)const;
void PsFile(const QString &name)const; void PsFile(const QString &name, int i)const;
void PdfToPs(const QStringList &params)const; void PdfToPs(const QStringList &params)const;
void ObjFile(const QString &name)const; void ObjFile(const QString &name, int i)const;
void ClearLayout(); void ClearLayout();
void CreateShadows(); void CreateShadows();
void CreateScenes(); void CreateScenes();
void PrepareSceneList(); void PrepareSceneList();
QIcon ScenePreview(int i) const; QIcon ScenePreview(int i) const;
QMap<QString, QString> InitFormates() const;
}; };
#endif // TABLEWINDOW_H #endif // TABLEWINDOW_H

View file

@ -155,12 +155,23 @@ LayoutErrors VLayoutGenerator::State() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QList<QGraphicsItem *> VLayoutGenerator::GetItems() const QList<QGraphicsItem *> VLayoutGenerator::GetPapersItems() const
{ {
QList<QGraphicsItem *> list; QList<QGraphicsItem *> list;
for (int i=0; i < papers.count(); ++i) 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; return list;
} }

View file

@ -64,7 +64,8 @@ public:
LayoutErrors State() const; LayoutErrors State() const;
QList<QGraphicsItem *> GetItems() const; QList<QGraphicsItem *> GetPapersItems() const;
QList<QList<QGraphicsItem *>> GetAllDetails() const;
bool GetRotate() const; bool GetRotate() const;
void SetRotate(bool value); void SetRotate(bool value);

View file

@ -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(), QGraphicsRectItem *paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(),
d->globalContour.GetHeight())); d->globalContour.GetHeight()));
paper->setPen(QPen(Qt::black, 1)); paper->setPen(QPen(Qt::black, 1));
paper->setBrush(QBrush(Qt::white)); 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; 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;
}

View file

@ -36,6 +36,7 @@ class VLayoutPaperData;
class VLayoutDetail; class VLayoutDetail;
class QGraphicsItem; class QGraphicsItem;
class VBestSquare; class VBestSquare;
class QGraphicsRectItem;
class VLayoutPaper class VLayoutPaper
{ {
@ -68,7 +69,8 @@ public:
bool ArrangeDetail(const VLayoutDetail &detail, bool &stop); bool ArrangeDetail(const VLayoutDetail &detail, bool &stop);
int Count() const; int Count() const;
QGraphicsItem *GetItem() const; QGraphicsRectItem *GetPaperItem() const;
QList<QGraphicsItem *> GetDetails() const;
private: private:
QSharedDataPointer<VLayoutPaperData> d; QSharedDataPointer<VLayoutPaperData> d;