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 <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()),
|
2015-11-09 12:58:45 +01:00
|
|
|
isLayoutStale(true), margins(), paperSize(), 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);
|
2015-12-09 12:31:33 +01:00
|
|
|
if (VApplication::IsGUIMode())
|
2015-08-25 19:53:03 +02:00
|
|
|
{
|
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();
|
2015-11-09 12:33:36 +01:00
|
|
|
margins = lGenerator.GetFields();
|
2015-11-09 12:58:45 +01:00
|
|
|
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
|
2015-08-25 19:53:03 +02:00
|
|
|
isLayoutStale = false;
|
2015-12-09 12:31:33 +01:00
|
|
|
if (VApplication::IsGUIMode())
|
2015-12-03 09:56:19 +01:00
|
|
|
{
|
|
|
|
QApplication::alert(this);
|
|
|
|
}
|
2015-08-25 19:53:03 +02:00
|
|
|
break;
|
|
|
|
case LayoutErrors::ProcessStoped:
|
|
|
|
case LayoutErrors::PrepareLayoutError:
|
|
|
|
case LayoutErrors::EmptyPaperError:
|
2015-12-09 12:31:33 +01:00
|
|
|
if (VApplication::IsGUIMode())
|
2015-12-03 09:56:19 +01:00
|
|
|
{
|
|
|
|
QApplication::alert(this);
|
|
|
|
}
|
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;
|
|
|
|
}
|
2015-11-09 12:33:36 +01:00
|
|
|
painter.drawImage(QPointF(margins.left(), margins.top()), poster.at(index));
|
2015-05-14 14:27:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2015-10-28 15:22:36 +01:00
|
|
|
const VDetail &d = idetail.value();
|
|
|
|
det.SetCountourPoints(d.ContourPoints(pattern));
|
2015-11-15 18:06:25 +01:00
|
|
|
det.SetSeamAllowencePoints(d.SeamAllowancePoints(pattern), d.getSeamAllowance(), d.getClosed());
|
2015-10-28 15:22:36 +01:00
|
|
|
det.setName(d.getName());
|
|
|
|
det.setWidth(qApp->toPixel(d.getWidth()));
|
2015-05-12 14:42:19 +02:00
|
|
|
|
|
|
|
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 ) );
|
2015-10-23 07:27:47 +02:00
|
|
|
scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio);
|
2015-05-12 17:15:10 +02:00
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-11-04 16:22:49 +01:00
|
|
|
QVector<QImage> MainWindowsNoGUI::AllSheets() const
|
2015-05-14 14:27:04 +02:00
|
|
|
{
|
|
|
|
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 ) );
|
2015-10-23 07:27:47 +02:00
|
|
|
scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio);
|
2015-05-14 14:27:04 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 12:33:36 +01:00
|
|
|
QSharedPointer<QPrinter> printer = DefaultPrinter();
|
|
|
|
if (printer.isNull())
|
2015-05-14 14:27:04 +02:00
|
|
|
{
|
2015-11-09 12:33:36 +01:00
|
|
|
qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")),
|
|
|
|
qUtf8Printable(tr("Cannot proceed because there are no available printers in your system.")));
|
|
|
|
return;
|
2015-05-14 14:27:04 +02:00
|
|
|
}
|
|
|
|
|
2015-11-09 12:58:45 +01:00
|
|
|
SetPrinterSettings(printer.data(), false);
|
2015-05-14 14:27:04 +02:00
|
|
|
// display print preview dialog
|
2015-11-09 12:33:36 +01:00
|
|
|
QPrintPreviewDialog preview(printer.data());
|
2015-05-14 14:27:04 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-11-09 12:58:45 +01:00
|
|
|
void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, bool prepareForPrinting)
|
2015-05-14 14:27:04 +02:00
|
|
|
{
|
|
|
|
SCASSERT(printer != nullptr)
|
2015-11-04 16:22:49 +01: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-11-04 16:22:49 +01: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)
|
|
|
|
{
|
2015-11-09 13:29:37 +01:00
|
|
|
const QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm));
|
|
|
|
const QPrinter::PageSize pSZ = FindTemplate(size);
|
|
|
|
if (pSZ == QPrinter::Custom)
|
|
|
|
{
|
|
|
|
printer->setPaperSize (size, QPrinter::Millimeter );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printer->setPaperSize (pSZ);
|
|
|
|
}
|
2015-05-14 14:27:04 +02:00
|
|
|
}
|
|
|
|
|
2015-11-09 12:33:36 +01:00
|
|
|
{
|
|
|
|
const qreal left = FromPixel(margins.left(), Unit::Mm);
|
|
|
|
const qreal top = FromPixel(margins.top(), Unit::Mm);
|
|
|
|
const qreal right = FromPixel(margins.right(), Unit::Mm);
|
|
|
|
const qreal bottom = FromPixel(margins.bottom(), Unit::Mm);
|
|
|
|
printer->setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
|
|
|
|
}
|
|
|
|
|
2015-11-09 12:58:45 +01:00
|
|
|
if (prepareForPrinting)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName());
|
|
|
|
#else
|
|
|
|
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf"));
|
|
|
|
#endif
|
|
|
|
}
|
2015-05-14 14:27:04 +02:00
|
|
|
printer->setDocName(FileName());
|
2015-11-04 16:22:49 +01:00
|
|
|
|
|
|
|
IsLayoutGrayscale() ? printer->setColorMode(QPrinter::GrayScale) : printer->setColorMode(QPrinter::Color);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool MainWindowsNoGUI::IsLayoutGrayscale() const
|
|
|
|
{
|
|
|
|
const QVector<QImage> images = AllSheets();
|
|
|
|
|
|
|
|
for(int i=0; i < images.size(); ++i)
|
|
|
|
{
|
|
|
|
if (not images.at(i).isGrayscale())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-05-14 14:27:04 +02:00
|
|
|
}
|
|
|
|
|
2015-11-09 13:29:37 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPrinter::PaperSize MainWindowsNoGUI::FindTemplate(const QSizeF &size) const
|
|
|
|
{
|
|
|
|
if (size == QSizeF(841, 1189))
|
|
|
|
{
|
|
|
|
return QPrinter::A0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == QSizeF(594, 841))
|
|
|
|
{
|
|
|
|
return QPrinter::A1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == QSizeF(420, 594))
|
|
|
|
{
|
|
|
|
return QPrinter::A2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == QSizeF(297, 420))
|
|
|
|
{
|
|
|
|
return QPrinter::A3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == QSizeF(210, 297))
|
|
|
|
{
|
|
|
|
return QPrinter::A4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == QSizeF(215.9, 355.6))
|
|
|
|
{
|
|
|
|
return QPrinter::Legal;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == QSizeF(215.9, 279.4))
|
|
|
|
{
|
|
|
|
return QPrinter::Letter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QPrinter::Custom;
|
|
|
|
}
|
|
|
|
|
2015-05-14 14:27:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool MainWindowsNoGUI::isPagesUniform() const
|
|
|
|
{
|
|
|
|
if (papers.size() < 2)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
|
|
|
|
SCASSERT(paper != nullptr)
|
2015-11-04 16:22:49 +01: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-11-04 16:22:49 +01: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));
|
2015-10-28 15:22:36 +01:00
|
|
|
SCASSERT(paper != nullptr);
|
|
|
|
const QRectF rec = paper->rect();
|
|
|
|
if (length + rec.height() <= QIMAGE_MAX)
|
2015-05-18 13:26:37 +02:00
|
|
|
{
|
|
|
|
UniteDetails(j, nDetails, length, i);
|
2015-10-28 15:22:36 +01:00
|
|
|
length += rec.height();
|
|
|
|
UnitePapers(j, nPapers, rec.width(), length);
|
2015-05-18 13:26:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length = 0; // Strat new paper
|
|
|
|
++j;// New paper
|
|
|
|
UniteDetails(j, nDetails, length, i);
|
2015-10-28 15:22:36 +01:00
|
|
|
length += rec.height();
|
|
|
|
UnitePapers(j, nPapers, rec.width(), length);
|
2015-05-18 13:26:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
}
|