2015-05-12 14:42:19 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file mainwindowsnogui.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 12 5, 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 "mainwindowsnogui.h"
|
2015-06-15 15:10:55 +02:00
|
|
|
#include "core/vapplication.h"
|
2015-08-27 17:55:17 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vobj/vobjpaintdevice.h"
|
2015-09-07 21:47:02 +02:00
|
|
|
#include "../vdxf/vdxfpaintdevice.h"
|
2015-08-25 19:53:03 +02:00
|
|
|
#include "dialogs/dialoglayoutsettings.h"
|
|
|
|
|
2015-08-27 18:03:43 +02:00
|
|
|
#include "../vlayout/vlayoutgenerator.h"
|
|
|
|
#include "dialogs/dialoglayoutprogress.h"
|
|
|
|
#include "dialogs/dialogsavelayout.h"
|
|
|
|
#include "../vlayout/vposter.h"
|
2015-05-12 14:42:19 +02:00
|
|
|
|
2015-05-14 14:27:04 +02:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
2015-05-12 14:42:19 +02:00
|
|
|
#include <QGraphicsScene>
|
2015-05-14 14:27:04 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QProcess>
|
2015-05-12 17:15:10 +02:00
|
|
|
#include <QToolButton>
|
2015-05-14 14:27:04 +02:00
|
|
|
#include <QtSvg>
|
|
|
|
#include <QPrinter>
|
|
|
|
#include <QPrintPreviewDialog>
|
|
|
|
#include <QPrintDialog>
|
2015-05-31 12:00:16 +02:00
|
|
|
#include <QPrinterInfo>
|
2015-05-14 14:27:04 +02:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
# define PDFTOPS "pdftops.exe"
|
|
|
|
#else
|
|
|
|
# define PDFTOPS "pdftops"
|
|
|
|
#endif
|
2015-05-12 14:42:19 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
|
|
|
|
: QMainWindow(parent), listDetails(QVector<VLayoutDetail>()), currentScene(nullptr), tempSceneLayout(nullptr),
|
2015-06-11 19:36:17 +02:00
|
|
|
pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList<QGraphicsItem *>()),
|
|
|
|
shadows(QList<QGraphicsItem *>()), scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()),
|
|
|
|
undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()),
|
|
|
|
isLayoutStale(true), isTiled(false)
|
2015-05-12 14:42:19 +02:00
|
|
|
{
|
|
|
|
InitTempLayoutScene();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MainWindowsNoGUI::~MainWindowsNoGUI()
|
|
|
|
{
|
|
|
|
delete tempSceneLayout;
|
|
|
|
delete pattern;
|
|
|
|
}
|
|
|
|
|
2015-05-12 17:15:10 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
|
|
|
|
{
|
2015-05-12 19:59:36 +02:00
|
|
|
QToolButton *tButton = qobject_cast< QToolButton * >(this->sender());
|
|
|
|
SCASSERT(tButton != nullptr)
|
|
|
|
|
2015-05-12 17:15:10 +02:00
|
|
|
if (checked)
|
|
|
|
{
|
2015-08-25 19:53:03 +02:00
|
|
|
VLayoutGenerator lGenerator;
|
|
|
|
|
2015-05-12 17:15:10 +02:00
|
|
|
|
|
|
|
DialogLayoutSettings layout(&lGenerator, this);
|
|
|
|
if (layout.exec() == QDialog::Rejected)
|
|
|
|
{
|
2015-05-12 19:59:36 +02:00
|
|
|
tButton->setChecked(false);
|
2015-05-12 17:15:10 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-08-25 19:53:03 +02:00
|
|
|
LayoutSettings(lGenerator);
|
|
|
|
tButton->setChecked(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tButton->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
2015-05-12 17:15:10 +02:00
|
|
|
|
2015-08-25 19:53:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-11 11:06:14 +02:00
|
|
|
bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
|
2015-08-25 19:53:03 +02:00
|
|
|
{
|
|
|
|
lGenerator.SetDetails(listDetails);
|
|
|
|
DialogLayoutProgress progress(listDetails.count(), this);
|
|
|
|
if (VApplication::CheckGUI())
|
|
|
|
{
|
2015-05-12 17:15:10 +02:00
|
|
|
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
|
|
|
|
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
|
|
|
|
connect(&lGenerator, &VLayoutGenerator::Error, &progress, &DialogLayoutProgress::Error);
|
|
|
|
connect(&lGenerator, &VLayoutGenerator::Finished, &progress, &DialogLayoutProgress::Finished);
|
|
|
|
connect(&progress, &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
|
2015-08-25 19:53:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
connect(&lGenerator, &VLayoutGenerator::Error, this, &MainWindowsNoGUI::ErrorConsoleMode);
|
|
|
|
}
|
|
|
|
lGenerator.Generate();
|
2015-05-12 17:15:10 +02:00
|
|
|
|
2015-08-25 19:53:03 +02:00
|
|
|
switch (lGenerator.State())
|
|
|
|
{
|
|
|
|
case LayoutErrors::NoError:
|
|
|
|
CleanLayout();
|
|
|
|
papers = lGenerator.GetPapersItems();// Blank sheets
|
|
|
|
details = lGenerator.GetAllDetails();// All details
|
|
|
|
if (lGenerator.IsUnitePages())
|
|
|
|
{
|
|
|
|
UnitePages();
|
|
|
|
}
|
|
|
|
CreateShadows();
|
|
|
|
CreateScenes();
|
|
|
|
PrepareSceneList();
|
|
|
|
isLayoutStale = false;
|
|
|
|
break;
|
|
|
|
case LayoutErrors::ProcessStoped:
|
|
|
|
case LayoutErrors::PrepareLayoutError:
|
|
|
|
case LayoutErrors::EmptyPaperError:
|
2015-10-11 11:06:14 +02:00
|
|
|
return false;
|
2015-08-25 19:53:03 +02:00
|
|
|
default:
|
|
|
|
break;
|
2015-05-12 17:15:10 +02:00
|
|
|
|
|
|
|
}
|
2015-10-11 11:06:14 +02:00
|
|
|
return true;
|
2015-08-25 19:53:03 +02:00
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
|
|
|
|
{
|
|
|
|
switch (state)
|
2015-05-12 17:15:10 +02:00
|
|
|
{
|
2015-08-25 19:53:03 +02:00
|
|
|
case LayoutErrors::NoError:
|
|
|
|
return;
|
|
|
|
case LayoutErrors::PrepareLayoutError:
|
2015-10-01 16:59:01 +02:00
|
|
|
qCritical() << tr("Couldn't prepare data for creation layout");
|
2015-08-25 19:53:03 +02:00
|
|
|
break;
|
|
|
|
case LayoutErrors::ProcessStoped:
|
|
|
|
break;
|
|
|
|
case LayoutErrors::EmptyPaperError:
|
2015-10-01 16:59:01 +02:00
|
|
|
qCritical() << tr("Several workpieces left not arranged, but none of them match for paper");
|
2015-08-25 19:53:03 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-12 17:15:10 +02:00
|
|
|
}
|
2015-09-28 20:54:41 +02:00
|
|
|
|
2015-10-11 11:06:14 +02:00
|
|
|
qApp->exit(V_EX_DATAERR);
|
2015-05-12 17:15:10 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 14:27:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::ExportLayoutAs()
|
|
|
|
{
|
|
|
|
if (isLayoutStale)
|
|
|
|
{
|
|
|
|
if (ContinueIfLayoutStale() == QMessageBox::No)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 11:06:14 +02:00
|
|
|
try
|
2015-05-14 14:27:04 +02:00
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
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()));
|
2015-05-14 14:27:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-08-25 19:53:03 +02:00
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog)
|
|
|
|
{
|
|
|
|
|
2015-05-14 14:27:04 +02:00
|
|
|
QString suf = dialog.Formate();
|
|
|
|
suf.replace(".", "");
|
|
|
|
|
|
|
|
const QString path = dialog.Path();
|
2015-07-24 14:06:53 +02:00
|
|
|
qApp->ValentinaSettings()->SetPathLayout(path);
|
2015-05-14 14:27:04 +02:00
|
|
|
const QString mask = dialog.FileName();
|
|
|
|
|
|
|
|
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);
|
2015-05-20 19:21:36 +02:00
|
|
|
paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen));
|
2015-09-07 21:47:02 +02:00
|
|
|
const QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj" << "dxf";
|
2015-05-14 14:27:04 +02:00
|
|
|
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;
|
2015-09-07 21:47:02 +02:00
|
|
|
case 6: //dxf
|
|
|
|
DxfFile(name, i);
|
|
|
|
break;
|
2015-05-14 14:27:04 +02:00
|
|
|
default:
|
|
|
|
qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO;
|
|
|
|
break;
|
|
|
|
}
|
2015-05-20 19:21:36 +02:00
|
|
|
paper->setPen(QPen(Qt::black, 1));
|
2015-05-14 14:27:04 +02:00
|
|
|
brush->setColor( QColor( Qt::gray ) );
|
|
|
|
brush->setStyle( Qt::SolidPattern );
|
|
|
|
scenes[i]->setBackgroundBrush( *brush );
|
|
|
|
shadows[i]->setVisible(true);
|
|
|
|
delete brush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::SaveAsPDF()
|
|
|
|
{
|
|
|
|
if (not isPagesUniform())
|
|
|
|
{
|
|
|
|
qCritical()<<tr("For saving multypage document all sheet should have the same size. Use export "
|
|
|
|
"function instead.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isTiled = false;
|
|
|
|
SaveLayoutAs();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::SaveAsTiledPDF()
|
|
|
|
{
|
|
|
|
isTiled = true;
|
|
|
|
SaveLayoutAs();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::PrintPages(QPrinter *printer)
|
|
|
|
{
|
|
|
|
if (printer == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<QImage> images = AllSheets();
|
|
|
|
|
|
|
|
QVector<QImage> poster;
|
|
|
|
if (isTiled)
|
|
|
|
{
|
|
|
|
VPoster posterazor(printer);
|
|
|
|
for (int i=0; i < images.size(); i++)
|
|
|
|
{
|
|
|
|
poster += posterazor.Generate(images.at(i), i+1, images.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
poster = images;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainter painter;
|
|
|
|
if (not painter.begin(printer))
|
|
|
|
{ // failed to open file
|
|
|
|
qWarning("failed to open file, is it writable?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter.
|
|
|
|
int firstPage = printer->fromPage() - 1;
|
|
|
|
if (firstPage >= poster.size())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (firstPage == -1)
|
|
|
|
{
|
|
|
|
firstPage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lastPage = printer->toPage() - 1;
|
|
|
|
if (lastPage == -1 || lastPage >= poster.size())
|
|
|
|
{
|
|
|
|
lastPage = poster.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int numPages = lastPage - firstPage + 1;
|
|
|
|
int copyCount = 1;
|
|
|
|
if (not printer->supportsMultipleCopies())
|
|
|
|
{
|
|
|
|
copyCount = printer->copyCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < copyCount; ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < numPages; ++j)
|
|
|
|
{
|
|
|
|
if (i != 0 || j != 0)
|
|
|
|
{
|
|
|
|
if (not printer->newPage())
|
|
|
|
{
|
|
|
|
qWarning("failed in flushing page to disk, disk full?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int index;
|
|
|
|
if (printer->pageOrder() == QPrinter::FirstPageFirst)
|
|
|
|
{
|
|
|
|
index = firstPage + j;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index = lastPage - j;
|
|
|
|
}
|
|
|
|
painter.drawImage(QPointF(), poster.at(index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::PrintPreviewOrigin()
|
|
|
|
{
|
|
|
|
if (not isPagesUniform())
|
|
|
|
{
|
|
|
|
qCritical()<<tr("For previewing multypage document all sheet should have the same size.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isTiled = false;
|
|
|
|
PrintPreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::PrintPreviewTiled()
|
|
|
|
{
|
|
|
|
isTiled = true;
|
|
|
|
PrintPreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::PrintOrigin()
|
|
|
|
{
|
|
|
|
if (not isPagesUniform())
|
|
|
|
{
|
|
|
|
qCritical()<<tr("For printing multypages document all sheet should have the same size.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isTiled = false;
|
|
|
|
LayoutPrint();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::PrintTiled()
|
|
|
|
{
|
|
|
|
isTiled = false;
|
|
|
|
LayoutPrint();
|
|
|
|
}
|
|
|
|
|
2015-05-12 14:42:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash<quint32, VDetail> *details)
|
|
|
|
{
|
|
|
|
SCASSERT(details != nullptr)
|
2015-08-25 19:53:03 +02:00
|
|
|
if (details->count() == 0)
|
2015-05-12 14:42:19 +02:00
|
|
|
{
|
|
|
|
listDetails.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
listDetails.clear();
|
|
|
|
QHashIterator<quint32, VDetail> idetail(*details);
|
|
|
|
while (idetail.hasNext())
|
|
|
|
{
|
|
|
|
idetail.next();
|
|
|
|
VLayoutDetail det = VLayoutDetail();
|
|
|
|
det.SetCountourPoints(idetail.value().ContourPoints(pattern));
|
|
|
|
det.SetSeamAllowencePoints(idetail.value().SeamAllowancePoints(pattern),
|
|
|
|
idetail.value().getSeamAllowance());
|
|
|
|
det.setName(idetail.value().getName());
|
|
|
|
det.setWidth(qApp->toPixel(idetail.value().getWidth()));
|
|
|
|
|
|
|
|
listDetails.append(det);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::InitTempLayoutScene()
|
|
|
|
{
|
2015-05-12 17:15:10 +02:00
|
|
|
tempSceneLayout = new QGraphicsScene();
|
2015-05-12 14:42:19 +02:00
|
|
|
tempSceneLayout->setBackgroundBrush( QBrush(QColor(Qt::gray), Qt::SolidPattern) );
|
|
|
|
}
|
2015-05-12 17:15:10 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QIcon MainWindowsNoGUI::ScenePreview(int i) const
|
|
|
|
{
|
|
|
|
QImage image;
|
|
|
|
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
|
|
|
|
image = QImage(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_RGB32);
|
|
|
|
|
|
|
|
if (not image.isNull())
|
|
|
|
{
|
|
|
|
image.fill(Qt::white);
|
|
|
|
QPainter painter(&image);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
2015-06-15 11:32:27 +02:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine,
|
|
|
|
Qt::RoundCap, Qt::RoundJoin));
|
2015-05-12 17:15:10 +02:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
scenes.at(i)->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning()<<"Cannot create image. Size too big";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = QImage(QSize(101, 146), QImage::Format_RGB32);
|
|
|
|
image.fill(Qt::white);
|
|
|
|
}
|
|
|
|
return QIcon(QBitmap::fromImage(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::CreateShadows()
|
|
|
|
{
|
|
|
|
for (int i=0; i< papers.size(); ++i)
|
|
|
|
{
|
|
|
|
qreal x1=0, y1=0, x2=0, y2=0;
|
|
|
|
QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
item->rect().getCoords(&x1, &y1, &x2, &y2);
|
|
|
|
QGraphicsRectItem *shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4));
|
|
|
|
shadowPaper->setBrush(QBrush(Qt::black));
|
|
|
|
shadows.append(shadowPaper);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shadows.append(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::CreateScenes()
|
|
|
|
{
|
|
|
|
for (int i=0; i<papers.size(); ++i)
|
|
|
|
{
|
|
|
|
QGraphicsScene *scene = new QGraphicsScene();
|
|
|
|
scene->setBackgroundBrush(QBrush(QColor(Qt::gray), Qt::SolidPattern));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2015-05-14 14:27:04 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SvgFile save layout to svg file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
|
|
|
void MainWindowsNoGUI::SvgFile(const QString &name, int i) const
|
|
|
|
{
|
|
|
|
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(doc->GetDescription());
|
2015-06-11 19:36:17 +02:00
|
|
|
generator.setResolution(static_cast<int>(PrintDPI));
|
2015-05-14 14:27:04 +02:00
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&generator);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
2015-06-15 11:32:27 +02:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*pattern->GetPatternUnit())), Qt::SolidLine,
|
|
|
|
Qt::RoundCap, Qt::RoundJoin));
|
2015-05-14 14:27:04 +02:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
2015-05-20 19:16:37 +02:00
|
|
|
scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio);
|
2015-05-14 14:27:04 +02:00
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief PngFile save layout to png file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
|
|
|
void MainWindowsNoGUI::PngFile(const QString &name, int i) const
|
|
|
|
{
|
|
|
|
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
|
2015-05-20 19:16:37 +02:00
|
|
|
QImage image(r.size().toSize(), QImage::Format_ARGB32);
|
2015-05-14 14:27:04 +02:00
|
|
|
image.fill(Qt::transparent); // Start all pixels transparent
|
|
|
|
QPainter painter(&image);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
2015-06-15 11:32:27 +02:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine,
|
|
|
|
Qt::RoundCap, Qt::RoundJoin));
|
2015-05-14 14:27:04 +02:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
2015-05-20 19:16:37 +02:00
|
|
|
scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio);
|
2015-05-14 14:27:04 +02:00
|
|
|
image.save(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief PdfFile save layout to pdf file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
|
|
|
void MainWindowsNoGUI::PdfFile(const QString &name, int i) const
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
QPrinter printer;
|
|
|
|
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
|
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
|
|
|
printer.setOutputFileName(name);
|
|
|
|
printer.setDocName(FileName());
|
|
|
|
const QRectF r = paper->rect();
|
2015-06-11 19:36:17 +02:00
|
|
|
printer.setResolution(static_cast<int>(PrintDPI));
|
2015-05-14 14:27:04 +02:00
|
|
|
// Set orientation
|
|
|
|
if (paper->rect().height()>= paper->rect().width())
|
|
|
|
{
|
|
|
|
printer.setOrientation(QPrinter::Portrait);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printer.setOrientation(QPrinter::Landscape);
|
|
|
|
}
|
2015-06-11 19:36:17 +02:00
|
|
|
printer.setPaperSize ( QSizeF(FromPixel(r.width(), Unit::Mm), FromPixel(r.height(), Unit::Mm)),
|
2015-05-14 14:27:04 +02:00
|
|
|
QPrinter::Millimeter );
|
|
|
|
QPainter painter;
|
|
|
|
if (painter.begin( &printer ) == false)
|
|
|
|
{ // failed to open file
|
2015-10-01 16:59:01 +02:00
|
|
|
qCritical("%s", qUtf8Printable(tr("Can't open printer %1").arg(name)));
|
2015-05-14 14:27:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
2015-06-15 11:32:27 +02:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine,
|
|
|
|
Qt::RoundCap, Qt::RoundJoin));
|
2015-05-14 14:27:04 +02:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
2015-05-20 19:16:37 +02:00
|
|
|
scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio);
|
2015-05-14 14:27:04 +02:00
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief EpsFile save layout to eps file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
|
|
|
void MainWindowsNoGUI::EpsFile(const QString &name, int i) const
|
|
|
|
{
|
|
|
|
QTemporaryFile tmp;
|
|
|
|
if (tmp.open())
|
|
|
|
{
|
|
|
|
PdfFile(tmp.fileName(), i);
|
|
|
|
QStringList params = QStringList() << "-eps" << tmp.fileName() << name;
|
|
|
|
PdfToPs(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief PsFile save layout to ps file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
|
|
|
void MainWindowsNoGUI::PsFile(const QString &name, int i) const
|
|
|
|
{
|
|
|
|
QTemporaryFile tmp;
|
|
|
|
if (tmp.open())
|
|
|
|
{
|
|
|
|
PdfFile(tmp.fileName(), i);
|
|
|
|
QStringList params = QStringList() << tmp.fileName() << name;
|
|
|
|
PdfToPs(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format.
|
|
|
|
* @param params string with parameter for tool. Parameters have format: "-eps input_file out_file". Use -eps when
|
|
|
|
* need create eps file.
|
|
|
|
*/
|
|
|
|
void MainWindowsNoGUI::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
|
|
|
|
|
|
|
|
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 MainWindowsNoGUI::ObjFile(const QString &name, int i) const
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
VObjPaintDevice generator;
|
|
|
|
generator.setFileName(name);
|
|
|
|
generator.setSize(paper->rect().size().toSize());
|
2015-06-11 19:36:17 +02:00
|
|
|
generator.setResolution(static_cast<int>(PrintDPI));
|
2015-05-14 14:27:04 +02:00
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&generator);
|
2015-05-20 19:16:37 +02:00
|
|
|
scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio);
|
2015-05-14 14:27:04 +02:00
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::DxfFile(const QString &name, int i) const
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
VDxfPaintDevice generator;
|
|
|
|
generator.setFileName(name);
|
|
|
|
generator.setSize(paper->rect().size().toSize());
|
|
|
|
generator.setResolution(static_cast<int>(PrintDPI));
|
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&generator);
|
|
|
|
scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio);
|
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-14 14:27:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QImage> MainWindowsNoGUI::AllSheets()
|
|
|
|
{
|
|
|
|
QVector<QImage> images;
|
|
|
|
for (int i=0; i < scenes.size(); ++i)
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
// Hide shadow and paper border
|
|
|
|
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));// border
|
|
|
|
|
|
|
|
// Render png
|
|
|
|
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_RGB32);
|
|
|
|
image.fill(Qt::white);
|
|
|
|
QPainter painter(&image);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
2015-06-15 11:32:27 +02:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine,
|
|
|
|
Qt::RoundCap, Qt::RoundJoin));
|
2015-05-14 14:27:04 +02:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
scenes.at(i)->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
images.append(image);
|
|
|
|
|
|
|
|
// Resore
|
2015-06-15 11:32:27 +02:00
|
|
|
paper->setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit()))));
|
2015-05-14 14:27:04 +02:00
|
|
|
brush->setColor( QColor( Qt::gray ) );
|
|
|
|
brush->setStyle( Qt::SolidPattern );
|
|
|
|
scenes[i]->setBackgroundBrush( *brush );
|
|
|
|
shadows[i]->setVisible(true);
|
|
|
|
delete brush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return images;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::SaveLayoutAs()
|
|
|
|
{
|
|
|
|
if (isLayoutStale)
|
|
|
|
{
|
|
|
|
if (ContinueIfLayoutStale() == QMessageBox::No)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QPrinter printer;
|
|
|
|
SetPrinterSettings(&printer);
|
|
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Print to pdf"),
|
2015-07-24 14:06:53 +02:00
|
|
|
qApp->ValentinaSettings()->GetPathLayout()+"/"+FileName()+".pdf",
|
2015-05-14 14:27:04 +02:00
|
|
|
tr("PDF file (*.pdf)"));
|
|
|
|
if (not fileName.isEmpty())
|
|
|
|
{
|
|
|
|
QFileInfo f( fileName );
|
|
|
|
if(f.suffix().isEmpty())
|
|
|
|
{
|
|
|
|
fileName.append(".pdf");
|
|
|
|
}
|
2015-07-24 14:06:53 +02:00
|
|
|
qApp->ValentinaSettings()->SetPathLayout(f.absolutePath());
|
2015-05-14 14:27:04 +02:00
|
|
|
|
|
|
|
printer.setOutputFileName(fileName);
|
2015-06-11 19:36:17 +02:00
|
|
|
printer.setResolution(static_cast<int>(PrintDPI));
|
2015-05-14 14:27:04 +02:00
|
|
|
PrintPages( &printer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::PrintPreview()
|
|
|
|
{
|
|
|
|
if (isLayoutStale)
|
|
|
|
{
|
|
|
|
if (ContinueIfLayoutStale() == QMessageBox::No)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QPrinterInfo def = QPrinterInfo::defaultPrinter();
|
|
|
|
|
|
|
|
//if there is no default printer set the print preview won't show
|
|
|
|
if(def.isNull() || def.printerName().isEmpty())
|
|
|
|
{
|
|
|
|
if(QPrinterInfo::availablePrinters().isEmpty())
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")),
|
|
|
|
qUtf8Printable(tr("Cannot proceed because there are no available printers in your system.")));
|
2015-05-14 14:27:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
def = QPrinterInfo::availablePrinters().first();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPrinter printer(def, QPrinter::ScreenResolution);
|
2015-06-11 19:36:17 +02:00
|
|
|
printer.setResolution(static_cast<int>(PrintDPI));
|
2015-05-14 14:27:04 +02:00
|
|
|
SetPrinterSettings(&printer);
|
|
|
|
// display print preview dialog
|
|
|
|
QPrintPreviewDialog preview(&printer);
|
|
|
|
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages);
|
|
|
|
preview.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::LayoutPrint()
|
|
|
|
{
|
|
|
|
if (isLayoutStale)
|
|
|
|
{
|
|
|
|
if (ContinueIfLayoutStale() == QMessageBox::No)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// display print dialog and if accepted print
|
|
|
|
QPrinter printer(QPrinter::HighResolution);
|
|
|
|
SetPrinterSettings(&printer);
|
|
|
|
QPrintDialog dialog( &printer, this );
|
|
|
|
// If only user couldn't change page margins we could use method setMinMax();
|
|
|
|
dialog.setOption(QPrintDialog::PrintCurrentPage, false);
|
|
|
|
if ( dialog.exec() == QDialog::Accepted )
|
|
|
|
{
|
2015-06-11 19:36:17 +02:00
|
|
|
printer.setResolution(static_cast<int>(PrintDPI));
|
2015-05-14 14:27:04 +02:00
|
|
|
PrintPages( &printer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
|
|
|
|
{
|
|
|
|
SCASSERT(printer != nullptr)
|
2015-08-25 19:53:03 +02:00
|
|
|
printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
2015-05-14 14:27:04 +02:00
|
|
|
|
|
|
|
// Set orientation
|
|
|
|
if (papers.size() > 0)
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
|
|
|
|
SCASSERT(paper != nullptr)
|
2015-08-25 19:53:03 +02:00
|
|
|
if (paper->rect().height()>= paper->rect().width())
|
2015-05-14 14:27:04 +02:00
|
|
|
{
|
|
|
|
printer->setOrientation(QPrinter::Portrait);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printer->setOrientation(QPrinter::Landscape);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not isTiled && papers.size() > 0)
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
|
|
|
|
SCASSERT(paper != nullptr)
|
2015-08-25 19:53:03 +02:00
|
|
|
printer->setPaperSize ( QSizeF(FromPixel(paper->rect().width(), Unit::Mm),
|
|
|
|
FromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter );
|
2015-05-14 14:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
printer->setDocName(FileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool MainWindowsNoGUI::isPagesUniform() const
|
|
|
|
{
|
|
|
|
if (papers.size() < 2)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
|
|
|
|
SCASSERT(paper != nullptr)
|
2015-08-25 19:53:03 +02:00
|
|
|
for (int i=1; i < papers.size(); ++i)
|
2015-05-14 14:27:04 +02:00
|
|
|
{
|
|
|
|
QGraphicsRectItem *p = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
SCASSERT(p != nullptr)
|
2015-08-25 19:53:03 +02:00
|
|
|
if (paper->rect() != p->rect())
|
2015-05-14 14:27:04 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString MainWindowsNoGUI::FileName() const
|
|
|
|
{
|
|
|
|
QString fileName;
|
|
|
|
curFile.isEmpty() ? fileName = tr("unnamed") : fileName = curFile;
|
|
|
|
return QFileInfo(fileName).baseName();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int MainWindowsNoGUI::ContinueIfLayoutStale()
|
|
|
|
{
|
|
|
|
QMessageBox msgBox(this);
|
|
|
|
msgBox.setIcon(QMessageBox::Question);
|
|
|
|
msgBox.setWindowTitle(tr("The layout is stale."));
|
|
|
|
msgBox.setText(tr("The layout was not updated since last pattern modification. Do you want to continue?"));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::No);
|
|
|
|
QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
|
QGridLayout* layout = static_cast<QGridLayout*>(msgBox.layout());
|
|
|
|
SCASSERT(layout != nullptr);
|
|
|
|
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
|
|
|
|
msgBox.exec();
|
|
|
|
return msgBox.result();
|
|
|
|
}
|
2015-05-18 13:26:37 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::UnitePages()
|
|
|
|
{
|
|
|
|
if (papers.size() < 2)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QGraphicsItem *> nPapers;
|
|
|
|
QList<QList<QGraphicsItem *> > nDetails;
|
|
|
|
qreal length = 0;
|
|
|
|
int j = 0; // papers count
|
|
|
|
|
|
|
|
for (int i = 0; i < papers.size(); ++i)
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
SCASSERT(paper != nullptr)
|
2015-08-25 19:53:03 +02:00
|
|
|
if (length + paper->rect().height() <= QIMAGE_MAX)
|
2015-05-18 13:26:37 +02:00
|
|
|
{
|
|
|
|
UniteDetails(j, nDetails, length, i);
|
|
|
|
length += paper->rect().height();
|
|
|
|
UnitePapers(j, nPapers, paper->rect().width(), length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length = 0; // Strat new paper
|
|
|
|
++j;// New paper
|
|
|
|
UniteDetails(j, nDetails, length, i);
|
|
|
|
length += paper->rect().height();
|
|
|
|
UnitePapers(j, nPapers, paper->rect().width(), length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qDeleteAll (papers);
|
|
|
|
papers.clear();
|
|
|
|
papers = nPapers;
|
|
|
|
|
|
|
|
details.clear();
|
|
|
|
details = nDetails;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<QGraphicsItem *> MainWindowsNoGUI::MoveDetails(qreal length, const QList<QGraphicsItem *> &details)
|
|
|
|
{
|
|
|
|
if (qFuzzyCompare(length+1, 0+1))
|
|
|
|
{
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < details.size(); ++i)
|
|
|
|
{
|
|
|
|
details.at(i)->moveBy(0, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::UnitePapers(int j, QList<QGraphicsItem *> &nPapers, qreal width, qreal length)
|
|
|
|
{
|
|
|
|
if ((j == 0 && nPapers.isEmpty()) || j >= nPapers.size())
|
|
|
|
{//First or new paper in list
|
|
|
|
QGraphicsRectItem *paper = new QGraphicsRectItem(0, 0, width, length);
|
|
|
|
paper->setPen(QPen(Qt::black, 1));
|
|
|
|
paper->setBrush(QBrush(Qt::white));
|
|
|
|
nPapers.insert(j, paper);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{// Avoid memory leak
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(nPapers.at(j));
|
|
|
|
paper->setRect(0, 0, width, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MainWindowsNoGUI::UniteDetails(int j, QList<QList<QGraphicsItem *> > &nDetails, qreal length, int i)
|
|
|
|
{
|
|
|
|
if ((j == 0 && nDetails.isEmpty()) || j >= nDetails.size())
|
|
|
|
{//First or new details in paper
|
|
|
|
nDetails.insert(j, MoveDetails(length, details.at(i)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nDetails[j].append(MoveDetails(length, details.at(i)));
|
|
|
|
}
|
|
|
|
}
|