2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file tablewindow.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-29 12:31:50 +02:00
|
|
|
#include "tablewindow.h"
|
|
|
|
#include "ui_tablewindow.h"
|
|
|
|
#include "widgets/vtablegraphicsview.h"
|
2014-09-25 17:44:06 +02:00
|
|
|
#include "core/vapplication.h"
|
2015-01-26 15:08:09 +01:00
|
|
|
#include "core/vsettings.h"
|
2014-12-12 15:08:31 +01:00
|
|
|
#include "../../libs/vobj/vobjpaintdevice.h"
|
2015-01-14 15:14:51 +01:00
|
|
|
#include "../dialogs/app/dialoglayoutsettings.h"
|
2015-01-15 14:10:05 +01:00
|
|
|
#include "../../libs/vlayout/vlayoutgenerator.h"
|
|
|
|
#include "../dialogs/app/dialoglayoutprogress.h"
|
2015-01-23 11:07:58 +01:00
|
|
|
#include "../dialogs/app/dialogsavelayout.h"
|
2015-04-11 16:30:49 +02:00
|
|
|
#include "../../libs/vlayout/vposter.h"
|
2015-01-15 14:10:05 +01:00
|
|
|
|
|
|
|
#include <QtSvg>
|
|
|
|
#include <QPrinter>
|
|
|
|
#include <QGraphicsScene>
|
2015-04-11 16:30:49 +02:00
|
|
|
#include <QPrintPreviewDialog>
|
2015-04-11 17:16:30 +02:00
|
|
|
#include <QPrintDialog>
|
2015-04-16 12:04:46 +02:00
|
|
|
#include <QtPrintSupport>
|
2015-01-15 14:10:05 +01:00
|
|
|
#include <QtCore/qmath.h>
|
2013-08-29 12:31:50 +02:00
|
|
|
|
2014-07-23 13:09:19 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
# define PDFTOPS "pdftops.exe"
|
|
|
|
#else
|
|
|
|
# define PDFTOPS "pdftops"
|
|
|
|
#endif
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief TableWindow constructor.
|
|
|
|
* @param parent parent widget.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
TableWindow::TableWindow(QWidget *parent)
|
2015-01-15 14:10:05 +01:00
|
|
|
:QMainWindow(parent), ui(new Ui::TableWindow),
|
|
|
|
listDetails(QVector<VLayoutDetail>()), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()),
|
2015-03-02 18:11:43 +01:00
|
|
|
scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()), fileName(QString()),
|
2015-01-23 11:07:58 +01:00
|
|
|
description(QString()), tempScene(nullptr)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->setupUi(this);
|
2015-02-10 20:27:11 +01:00
|
|
|
|
|
|
|
qApp->getSettings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
|
|
|
|
|
2015-01-15 14:10:05 +01:00
|
|
|
tempScene = new QGraphicsScene(QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)));
|
2013-12-30 19:59:33 +01:00
|
|
|
QBrush brush;
|
|
|
|
brush.setStyle( Qt::SolidPattern );
|
|
|
|
brush.setColor( QColor( Qt::gray ) );
|
2015-01-15 14:10:05 +01:00
|
|
|
tempScene->setBackgroundBrush( brush );
|
2014-08-12 13:44:21 +02:00
|
|
|
|
2015-01-15 14:10:05 +01:00
|
|
|
ui->view->setScene(tempScene);
|
2014-08-12 13:44:21 +02:00
|
|
|
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
ui->horizontalLayout->addWidget(ui->view);
|
2015-01-17 14:14:28 +01:00
|
|
|
connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn);
|
|
|
|
connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut);
|
2013-08-29 12:31:50 +02:00
|
|
|
connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable);
|
2015-01-26 14:38:51 +01:00
|
|
|
connect(ui->actionSave, &QAction::triggered, this, &TableWindow::SaveLayout);
|
2015-01-14 15:14:51 +01:00
|
|
|
connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout);
|
2015-01-15 14:10:05 +01:00
|
|
|
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper);
|
2015-04-11 16:30:49 +02:00
|
|
|
connect(ui->actionPrint_pre_view, &QAction::triggered, this, &TableWindow::PrintPreview);
|
2015-04-11 17:16:30 +02:00
|
|
|
connect(ui->action_Print, &QAction::triggered, this, &TableWindow::LayoutPrint);
|
2015-04-11 17:33:43 +02:00
|
|
|
connect(ui->actionSave_to_p_df, &QAction::triggered, this, &TableWindow::PrintToPdf);
|
2015-04-11 20:20:37 +02:00
|
|
|
|
|
|
|
ReadSettings();
|
2015-04-29 14:43:33 +02:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
// On Mac deafault icon size is 32x32.
|
|
|
|
ui->toolBar->setIconSize(QSize(24, 24));
|
|
|
|
#endif
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
TableWindow::~TableWindow()
|
|
|
|
{
|
2015-01-15 14:10:05 +01:00
|
|
|
ClearLayout();
|
2013-08-29 12:31:50 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief ModelChosen show window when user want create new layout.
|
|
|
|
* @param listDetails list of details.
|
|
|
|
* @param description pattern description.
|
|
|
|
*/
|
2013-08-29 12:31:50 +02:00
|
|
|
/*
|
2013-12-21 15:21:40 +01:00
|
|
|
* Get details for creation layout.
|
2013-08-29 12:31:50 +02:00
|
|
|
*/
|
2015-01-07 17:54:43 +01:00
|
|
|
void TableWindow::ModelChosen(QVector<VLayoutDetail> listDetails, const QString &fileName, const QString &description)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-19 14:50:43 +01:00
|
|
|
this->description = description;
|
|
|
|
|
2014-02-28 14:06:14 +01:00
|
|
|
QString file;
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
{
|
|
|
|
file = tr("untitled");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file = fileName;
|
|
|
|
}
|
|
|
|
QFileInfo fi( file );
|
2014-02-19 14:50:43 +01:00
|
|
|
this->fileName = fi.baseName();
|
|
|
|
|
2013-08-29 12:31:50 +02:00
|
|
|
this->listDetails = listDetails;
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief closeEvent handle after close window.
|
|
|
|
* @param event close event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
event->ignore();
|
|
|
|
StopTable();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief moveToCenter move screen to the center of window.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::moveToCenter()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QRect rect = frameGeometry();
|
|
|
|
rect.moveCenter(QDesktopWidget().availableGeometry().center());
|
|
|
|
move(rect.topLeft());
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief showEvent handle after show window.
|
|
|
|
* @param event show event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::showEvent ( QShowEvent * event )
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QMainWindow::showEvent(event);
|
|
|
|
moveToCenter();
|
2014-08-12 13:44:21 +02:00
|
|
|
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief StopTable stop creation layout.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::StopTable()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
hide();
|
2015-01-15 14:10:05 +01:00
|
|
|
ClearLayout();
|
2013-08-29 12:31:50 +02:00
|
|
|
emit closed();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief saveScene save created layout.
|
|
|
|
*/
|
2015-01-26 14:38:51 +01:00
|
|
|
void TableWindow::SaveLayout()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
QMap<QString, QString> extByMessage = InitFormates();
|
2015-01-23 12:40:17 +01:00
|
|
|
DialogSaveLayout dialog(extByMessage, scenes.size(), fileName, this);
|
2015-01-23 11:07:58 +01:00
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString suf = dialog.Formate();
|
|
|
|
suf.replace(".", "");
|
|
|
|
|
2015-01-26 15:08:09 +01:00
|
|
|
const QString path = dialog.Path();
|
|
|
|
qApp->getSettings()->SetPathLayout(path);
|
|
|
|
const QString mask = dialog.FileName();
|
2015-01-23 11:07:58 +01:00
|
|
|
|
|
|
|
for (int i=0; i < scenes.size(); ++i)
|
|
|
|
{
|
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
const QString name = path + "/" + mask+QString::number(i+1) + dialog.Formate();
|
|
|
|
QBrush *brush = new QBrush();
|
|
|
|
brush->setColor( QColor( Qt::white ) );
|
|
|
|
scenes[i]->setBackgroundBrush( *brush );
|
|
|
|
shadows[i]->setVisible(false);
|
|
|
|
paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));
|
|
|
|
QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj";
|
|
|
|
switch (suffix.indexOf(suf))
|
|
|
|
{
|
|
|
|
case 0: //svg
|
|
|
|
paper->setVisible(false);
|
|
|
|
SvgFile(name, i);
|
|
|
|
paper->setVisible(true);
|
|
|
|
break;
|
|
|
|
case 1: //png
|
|
|
|
PngFile(name, i);
|
|
|
|
break;
|
|
|
|
case 2: //pdf
|
|
|
|
PdfFile(name, i);
|
|
|
|
break;
|
|
|
|
case 3: //eps
|
|
|
|
EpsFile(name, i);
|
|
|
|
break;
|
|
|
|
case 4: //ps
|
|
|
|
PsFile(name, i);
|
|
|
|
break;
|
|
|
|
case 5: //obj
|
|
|
|
paper->setVisible(false);
|
|
|
|
ObjFile(name, i);
|
|
|
|
paper->setVisible(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
|
|
|
brush->setColor( QColor( Qt::gray ) );
|
|
|
|
brush->setStyle( Qt::SolidPattern );
|
|
|
|
scenes[i]->setBackgroundBrush( *brush );
|
|
|
|
shadows[i]->setVisible(true);
|
|
|
|
delete brush;
|
|
|
|
}
|
|
|
|
}
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2015-01-17 14:14:28 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-15 14:10:05 +01:00
|
|
|
void TableWindow::ShowPaper(int index)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-15 14:10:05 +01:00
|
|
|
if (index < 0 || index > scenes.size())
|
|
|
|
{
|
|
|
|
ui->view->setScene(tempScene);
|
2015-04-11 16:30:49 +02:00
|
|
|
EnableActions(false);
|
2015-01-15 14:10:05 +01:00
|
|
|
}
|
2015-01-17 14:14:28 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->view->setScene(scenes.at(index));
|
|
|
|
}
|
2015-01-15 14:10:05 +01:00
|
|
|
|
2015-01-17 14:14:28 +01:00
|
|
|
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2015-04-11 16:30:49 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::PrintPreview()
|
|
|
|
{
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Print error"),
|
|
|
|
tr("Cannot proceed because there are no available printers in your system."),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
def = QPrinterInfo::availablePrinters().first();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPrinter printer(def, QPrinter::ScreenResolution);
|
|
|
|
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
|
2015-04-11 17:16:30 +02:00
|
|
|
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
|
|
|
printer.setDocName(fileName);
|
2015-04-11 16:30:49 +02:00
|
|
|
|
2015-04-11 17:16:30 +02:00
|
|
|
// display print preview dialog
|
2015-04-11 16:30:49 +02:00
|
|
|
QPrintPreviewDialog preview(&printer);
|
|
|
|
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &TableWindow::Print);
|
|
|
|
preview.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::Print(QPrinter *printer)
|
|
|
|
{
|
|
|
|
if (printer == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<QImage> images = AllSheets();
|
|
|
|
|
|
|
|
VPoster posterazor(printer);
|
|
|
|
QVector<QImage> poster;
|
|
|
|
for (int i=0; i < images.size(); i++)
|
|
|
|
{
|
|
|
|
poster += posterazor.Generate(images.at(i), i+1, images.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainter painter;
|
|
|
|
if (not painter.begin(printer))
|
|
|
|
{ // failed to open file
|
|
|
|
qWarning("failed to open file, is it writable?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-19 11:33:30 +02:00
|
|
|
// Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter.
|
|
|
|
int firstPage = printer->fromPage() - 1;
|
|
|
|
if (firstPage >= poster.size())
|
2015-04-11 16:30:49 +02:00
|
|
|
{
|
2015-04-19 11:33:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (firstPage == -1)
|
|
|
|
{
|
|
|
|
firstPage = 0;
|
|
|
|
}
|
2015-04-11 16:30:49 +02:00
|
|
|
|
2015-04-19 11:33:30 +02:00
|
|
|
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)
|
2015-04-11 16:30:49 +02:00
|
|
|
{
|
2015-04-19 11:33:30 +02:00
|
|
|
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
|
2015-04-11 16:30:49 +02:00
|
|
|
{
|
2015-04-19 11:33:30 +02:00
|
|
|
index = lastPage - j;
|
2015-04-11 16:30:49 +02:00
|
|
|
}
|
2015-04-19 11:33:30 +02:00
|
|
|
painter.drawImage(QPointF(), poster.at(index));
|
2015-04-11 16:30:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
|
2015-04-11 17:16:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::LayoutPrint()
|
|
|
|
{
|
|
|
|
// display print dialog and if accepted print
|
2015-04-19 11:33:30 +02:00
|
|
|
QPrinter printer(QPrinter::HighResolution);
|
2015-04-11 17:16:30 +02:00
|
|
|
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
|
|
|
printer.setDocName(fileName);
|
|
|
|
QPrintDialog dialog( &printer, this );
|
2015-04-19 12:16:16 +02:00
|
|
|
// If only user couldn't change page margins we could use method setMinMax();
|
|
|
|
dialog.setOption(QPrintDialog::PrintCurrentPage, false);
|
2015-04-11 17:16:30 +02:00
|
|
|
if ( dialog.exec() == QDialog::Accepted )
|
|
|
|
{
|
|
|
|
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
|
|
|
|
Print( &printer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-11 17:33:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::PrintToPdf()
|
|
|
|
{
|
|
|
|
QPrinter printer;
|
|
|
|
printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
|
|
|
|
printer.setDocName(fileName);
|
|
|
|
|
2015-04-19 12:40:44 +02:00
|
|
|
QPageSetupDialog dialog(&printer, this);
|
|
|
|
if ( dialog.exec() == QDialog::Accepted )
|
2015-04-11 17:33:43 +02:00
|
|
|
{
|
2015-04-19 12:40:44 +02:00
|
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
2015-04-19 16:41:46 +02:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Print to pdf"),
|
|
|
|
QDir::homePath()+"/"+this->fileName+".pdf",
|
|
|
|
tr("PDF file (*.pdf)"));
|
2015-04-19 12:40:44 +02:00
|
|
|
if (not fileName.isEmpty())
|
|
|
|
{
|
2015-04-19 13:04:15 +02:00
|
|
|
if(QFileInfo(fileName).suffix().isEmpty())
|
|
|
|
{
|
|
|
|
fileName.append(".pdf");
|
|
|
|
}
|
|
|
|
|
2015-04-19 12:40:44 +02:00
|
|
|
printer.setOutputFileName(fileName);
|
|
|
|
printer.setResolution(static_cast<int>(VApplication::PrintDPI));
|
|
|
|
Print( &printer );
|
|
|
|
}
|
2015-04-11 17:33:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-15 14:10:05 +01:00
|
|
|
void TableWindow::Layout()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-05-02 18:21:47 +02:00
|
|
|
VLayoutGenerator lGenerator(this);
|
|
|
|
lGenerator.SetDetails(listDetails);
|
|
|
|
|
|
|
|
DialogLayoutSettings layout(&lGenerator, this);
|
2015-01-15 14:10:05 +01:00
|
|
|
if (layout.exec() == QDialog::Rejected)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-15 14:10:05 +01:00
|
|
|
return;
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2015-01-17 14:14:28 +01:00
|
|
|
DialogLayoutProgress progress(listDetails.count(), this);
|
2013-08-29 12:31:50 +02:00
|
|
|
|
2015-01-15 14:10:05 +01: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);
|
2013-08-29 12:31:50 +02:00
|
|
|
|
2015-01-15 14:10:05 +01:00
|
|
|
lGenerator.Generate();
|
2015-01-14 15:14:51 +01:00
|
|
|
|
2015-01-17 14:14:28 +01:00
|
|
|
switch (lGenerator.State())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-17 14:14:28 +01:00
|
|
|
case LayoutErrors::NoError:
|
|
|
|
ClearLayout();
|
2015-04-11 16:30:49 +02:00
|
|
|
papers = lGenerator.GetPapersItems();// Blank sheets
|
|
|
|
details = lGenerator.GetAllDetails();// All details
|
2015-01-17 14:14:28 +01:00
|
|
|
CreateShadows();
|
|
|
|
CreateScenes();
|
|
|
|
PrepareSceneList();
|
|
|
|
break;
|
|
|
|
case LayoutErrors::ProcessStoped:
|
|
|
|
break;
|
|
|
|
case LayoutErrors::PrepareLayoutError:
|
|
|
|
case LayoutErrors::PaperSizeError:
|
|
|
|
case LayoutErrors::EmptyPaperError:
|
|
|
|
ClearLayout();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief SvgFile save layout to svg file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
2015-01-23 11:07:58 +01:00
|
|
|
void TableWindow::SvgFile(const QString &name, int i) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
QSvgGenerator generator;
|
|
|
|
generator.setFileName(name);
|
|
|
|
generator.setSize(paper->rect().size().toSize());
|
|
|
|
generator.setViewBox(paper->rect());
|
|
|
|
generator.setTitle("Valentina. Pattern layout");
|
|
|
|
generator.setDescription(description);
|
|
|
|
generator.setResolution(static_cast<int>(qApp->PrintDPI));
|
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&generator);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin));
|
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
scenes.at(i)->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
}
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief PngFile save layout to png file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
2015-01-23 11:07:58 +01:00
|
|
|
void TableWindow::PngFile(const QString &name, int i) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
const QRectF r = paper->rect();
|
|
|
|
// Create the image with the exact size of the shrunk scene
|
|
|
|
QImage image(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_ARGB32);
|
|
|
|
image.fill(Qt::transparent); // Start all pixels transparent
|
|
|
|
QPainter painter(&image);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin));
|
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
2015-04-19 12:54:42 +02:00
|
|
|
scenes.at(i)->render(&painter, r, r);
|
2015-01-23 11:07:58 +01:00
|
|
|
image.save(name);
|
|
|
|
}
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
2014-01-09 12:39:58 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief PdfFile save layout to pdf file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
2015-01-23 11:07:58 +01:00
|
|
|
void TableWindow::PdfFile(const QString &name, int i) const
|
2014-01-09 12:39:58 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
QPrinter printer;
|
|
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
|
|
|
printer.setOutputFileName(name);
|
|
|
|
const QRectF r = paper->rect();
|
|
|
|
printer.setResolution(static_cast<int>(qApp->PrintDPI));
|
|
|
|
printer.setPaperSize ( QSizeF(qApp->fromPixel(r.width(), Unit::Mm), qApp->fromPixel(r.height(), Unit::Mm)),
|
|
|
|
QPrinter::Millimeter );
|
|
|
|
QPainter painter;
|
|
|
|
if (painter.begin( &printer ) == false)
|
|
|
|
{ // failed to open file
|
|
|
|
qCritical("Can't open printer %s", qPrintable(name));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin));
|
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
scenes.at(i)->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
}
|
2014-01-09 12:39:58 +01:00
|
|
|
}
|
2014-02-17 23:57:51 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief EpsFile save layout to eps file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
2015-01-23 11:07:58 +01:00
|
|
|
void TableWindow::EpsFile(const QString &name, int i) const
|
2014-02-17 23:57:51 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
QTemporaryFile tmp;
|
|
|
|
if (tmp.open())
|
|
|
|
{
|
|
|
|
PdfFile(tmp.fileName(), i);
|
|
|
|
QStringList params = QStringList() << "-eps" << tmp.fileName() << name;
|
|
|
|
PdfToPs(params);
|
|
|
|
}
|
2014-02-17 23:57:51 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief PsFile save layout to ps file.
|
|
|
|
* @param name name layout file.
|
|
|
|
*/
|
2015-01-23 11:07:58 +01:00
|
|
|
void TableWindow::PsFile(const QString &name, int i) const
|
2014-02-17 23:57:51 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
QTemporaryFile tmp;
|
|
|
|
if (tmp.open())
|
|
|
|
{
|
|
|
|
PdfFile(tmp.fileName(), i);
|
|
|
|
QStringList params = QStringList() << tmp.fileName() << name;
|
|
|
|
PdfToPs(params);
|
|
|
|
}
|
2014-02-18 21:20:58 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2014-03-14 19:47:50 +01:00
|
|
|
void TableWindow::PdfToPs(const QStringList ¶ms) const
|
2014-03-06 16:35:24 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
#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();
|
|
|
|
}
|
2015-01-15 14:10:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-23 11:07:58 +01:00
|
|
|
void TableWindow::ObjFile(const QString &name, int i) const
|
2015-01-15 14:10:05 +01:00
|
|
|
{
|
2015-01-23 11:07:58 +01:00
|
|
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
|
|
|
if (paper)
|
|
|
|
{
|
|
|
|
VObjPaintDevice generator;
|
|
|
|
generator.setFileName(name);
|
|
|
|
generator.setSize(paper->rect().size().toSize());
|
|
|
|
generator.setResolution(static_cast<int>(qApp->PrintDPI));
|
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&generator);
|
|
|
|
scenes.at(i)->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
}
|
2015-01-15 14:10:05 +01:00
|
|
|
}
|
|
|
|
|
2015-04-11 16:30:49 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QImage> TableWindow::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);
|
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin));
|
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
scenes.at(i)->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
images.append(image);
|
|
|
|
|
|
|
|
// Resore
|
|
|
|
paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
|
|
|
brush->setColor( QColor( Qt::gray ) );
|
|
|
|
brush->setStyle( Qt::SolidPattern );
|
|
|
|
scenes[i]->setBackgroundBrush( *brush );
|
|
|
|
shadows[i]->setVisible(true);
|
|
|
|
delete brush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return images;
|
|
|
|
}
|
|
|
|
|
2015-01-15 14:10:05 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::ClearLayout()
|
|
|
|
{
|
|
|
|
qDeleteAll (scenes);
|
|
|
|
scenes.clear();
|
|
|
|
shadows.clear();
|
|
|
|
papers.clear();
|
2015-01-17 14:14:28 +01:00
|
|
|
ui->listWidget->clear();
|
2015-04-11 16:30:49 +02:00
|
|
|
EnableActions(false);
|
2015-01-15 14:10:05 +01:00
|
|
|
}
|
2014-02-18 21:20:58 +01:00
|
|
|
|
2015-01-15 14:10:05 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::CreateShadows()
|
|
|
|
{
|
|
|
|
for (int i=0; i< papers.size(); ++i)
|
2014-02-18 21:20:58 +01:00
|
|
|
{
|
2015-01-15 14:10:05 +01:00
|
|
|
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);
|
|
|
|
}
|
2014-02-18 21:20:58 +01:00
|
|
|
}
|
2014-02-17 23:57:51 +01:00
|
|
|
}
|
2014-12-12 15:08:31 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-15 14:10:05 +01:00
|
|
|
void TableWindow::CreateScenes()
|
|
|
|
{
|
|
|
|
QBrush brush;
|
|
|
|
brush.setStyle( Qt::SolidPattern );
|
|
|
|
brush.setColor( QColor( Qt::gray ) );
|
|
|
|
|
|
|
|
for (int i=0; i<papers.size(); ++i)
|
|
|
|
{
|
|
|
|
QGraphicsScene *scene = new QGraphicsScene();
|
|
|
|
scene->setBackgroundBrush(brush);
|
|
|
|
scene->addItem(shadows.at(i));
|
|
|
|
scene->addItem(papers.at(i));
|
2015-01-23 11:07:58 +01:00
|
|
|
|
|
|
|
QList<QGraphicsItem *> paperDetails = details.at(i);
|
|
|
|
for (int i=0; i < paperDetails.size(); ++i)
|
|
|
|
{
|
|
|
|
scene->addItem(paperDetails.at(i));
|
|
|
|
}
|
|
|
|
|
2015-01-15 14:10:05 +01:00
|
|
|
scenes.append(scene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::PrepareSceneList()
|
2014-12-12 15:08:31 +01:00
|
|
|
{
|
2015-01-17 14:14:28 +01:00
|
|
|
for (int i=1; i<=scenes.size(); ++i)
|
2015-01-15 14:10:05 +01:00
|
|
|
{
|
2015-01-22 17:22:37 +01:00
|
|
|
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1), QString::number(i));
|
2015-01-15 14:10:05 +01:00
|
|
|
ui->listWidget->addItem(item);
|
|
|
|
}
|
2015-01-17 14:14:28 +01:00
|
|
|
|
2015-05-02 18:21:47 +02:00
|
|
|
if (not scenes.isEmpty())
|
2015-01-17 14:14:28 +01:00
|
|
|
{
|
|
|
|
ui->listWidget->setCurrentRow(0);
|
2015-04-11 16:30:49 +02:00
|
|
|
EnableActions(true);
|
2015-01-17 14:14:28 +01:00
|
|
|
}
|
2014-12-12 15:08:31 +01:00
|
|
|
}
|
2015-01-22 17:22:37 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QIcon TableWindow::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);
|
2015-05-06 14:03:45 +02:00
|
|
|
|
|
|
|
if (not image.isNull())
|
|
|
|
{
|
|
|
|
image.fill(Qt::white);
|
|
|
|
QPainter painter(&image);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin));
|
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
scenes.at(i)->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning()<<"Cannot create image. Size too big";
|
|
|
|
}
|
2015-01-22 17:22:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = QImage(QSize(101, 146), QImage::Format_RGB32);
|
|
|
|
image.fill(Qt::white);
|
|
|
|
}
|
|
|
|
return QIcon(QBitmap::fromImage(image));
|
|
|
|
}
|
2015-01-23 11:07:58 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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;
|
2015-03-16 15:49:51 +01:00
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
|
|
|
proc.start(qApp->applicationDirPath()+"/"+PDFTOPS); // Seek pdftops in app bundle or near valentin.exe
|
|
|
|
#else
|
|
|
|
proc.start(PDFTOPS); // Seek pdftops in standard path
|
|
|
|
#endif
|
2015-01-23 11:07:58 +01:00
|
|
|
if (proc.waitForFinished(15000))
|
|
|
|
{
|
|
|
|
extByMessage[ tr("PS files (*.ps)") ] = ".ps";
|
|
|
|
extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-16 15:49:51 +01:00
|
|
|
qDebug()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
|
2015-01-23 11:07:58 +01:00
|
|
|
}
|
|
|
|
return extByMessage;
|
|
|
|
}
|
2015-04-11 16:30:49 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::EnableActions(bool enable)
|
|
|
|
{
|
|
|
|
ui->actionSave->setEnabled(enable);
|
|
|
|
ui->actionSave_to_p_df->setEnabled(enable);
|
|
|
|
ui->actionPrint_pre_view->setEnabled(enable);
|
|
|
|
ui->action_Print->setEnabled(enable);
|
|
|
|
}
|
2015-04-11 20:20:37 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::ToolBarStyle(QToolBar *bar)
|
|
|
|
{
|
|
|
|
if (qApp->getSettings()->GetToolBarStyle())
|
|
|
|
{
|
|
|
|
bar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::ReadSettings()
|
|
|
|
{
|
|
|
|
// Text under tool buton icon
|
|
|
|
ToolBarStyles();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TableWindow::ToolBarStyles()
|
|
|
|
{
|
|
|
|
ToolBarStyle(ui->toolBar);
|
|
|
|
ToolBarStyle(ui->toolBar_2);
|
|
|
|
}
|