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.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <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"
|
2013-11-12 13:48:45 +01:00
|
|
|
#include <QtSvg>
|
2014-01-09 12:39:58 +01:00
|
|
|
#include <QPrinter>
|
2014-03-19 19:27:11 +01:00
|
|
|
#include "widgets/vapplication.h"
|
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(QWidget *parent)
|
2014-02-26 10:22:05 +01:00
|
|
|
:QMainWindow(parent), numberDetal(nullptr), colission(nullptr), ui(new Ui::TableWindow),
|
|
|
|
listDetails(QVector<VItem*>()), outItems(false), collidingItems(false), tableScene(nullptr),
|
|
|
|
paper(nullptr), shadowPaper(nullptr), listOutItems(nullptr), listCollidingItems(QList<QGraphicsItem*>()),
|
2014-02-19 14:50:43 +01:00
|
|
|
indexDetail(0), sceneRect(QRectF()), fileName(QString()), description(QString())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->setupUi(this);
|
2013-12-30 12:54:38 +01:00
|
|
|
numberDetal = new QLabel(tr("0 details left."), this);
|
2013-12-21 15:21:40 +01:00
|
|
|
colission = new QLabel(tr("Collisions not found."), this);
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->statusBar->addWidget(numberDetal);
|
|
|
|
ui->statusBar->addWidget(colission);
|
|
|
|
outItems = collidingItems = false;
|
2014-03-19 19:27:11 +01:00
|
|
|
//sceneRect = QRectF(0, 0, qApp->toPixel(203), qApp->toPixel(287));
|
|
|
|
sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171));
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene = new QGraphicsScene(sceneRect);
|
|
|
|
QBrush brush;
|
|
|
|
brush.setStyle( Qt::SolidPattern );
|
|
|
|
brush.setColor( QColor( Qt::gray ) );
|
|
|
|
tableScene->setBackgroundBrush( brush );
|
|
|
|
VTableGraphicsView* view = new VTableGraphicsView(tableScene);
|
2013-11-04 21:35:15 +01:00
|
|
|
view->fitInView(view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->horizontalLayout->addWidget(view);
|
|
|
|
connect(ui->actionTurn, &QAction::triggered, view, &VTableGraphicsView::rotateItems);
|
|
|
|
connect(ui->actionMirror, &QAction::triggered, view, &VTableGraphicsView::MirrorItem);
|
|
|
|
connect(ui->actionZoomIn, &QAction::triggered, view, &VTableGraphicsView::ZoomIn);
|
|
|
|
connect(ui->actionZoomOut, &QAction::triggered, view, &VTableGraphicsView::ZoomOut);
|
|
|
|
connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable);
|
|
|
|
connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene);
|
|
|
|
connect(ui->actionNext, &QAction::triggered, this, &TableWindow::GetNextDetail);
|
|
|
|
connect(ui->actionAdd, &QAction::triggered, this, &TableWindow::AddLength);
|
|
|
|
connect(ui->actionRemove, &QAction::triggered, this, &TableWindow::RemoveLength);
|
|
|
|
connect(view, &VTableGraphicsView::itemChect, this, &TableWindow::itemChect);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
TableWindow::~TableWindow()
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
delete tableScene;
|
2013-08-29 12:31:50 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::AddPaper()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
qreal x1, y1, x2, y2;
|
|
|
|
sceneRect.getCoords(&x1, &y1, &x2, &y2);
|
2013-11-04 21:35:15 +01:00
|
|
|
shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4));
|
2013-08-29 12:31:50 +02:00
|
|
|
shadowPaper->setBrush(QBrush(Qt::black));
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->addItem(shadowPaper);
|
2013-11-04 21:35:15 +01:00
|
|
|
paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2));
|
2014-03-26 05:39:07 +01:00
|
|
|
paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
2013-08-29 12:31:50 +02:00
|
|
|
paper->setBrush(QBrush(Qt::white));
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->addItem(paper);
|
2013-08-29 12:31:50 +02:00
|
|
|
qDebug()<<paper->rect().size().toSize();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::AddDetail()
|
|
|
|
{
|
|
|
|
if (indexDetail<listDetails.count())
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->clearSelection();
|
2013-08-29 12:31:50 +02:00
|
|
|
VItem* Detail = listDetails[indexDetail];
|
2014-02-28 14:12:39 +01:00
|
|
|
Q_CHECK_PTR(Detail);
|
|
|
|
connect(Detail, &VItem::itemOut, this, &TableWindow::itemOut);
|
|
|
|
connect(Detail, &VItem::itemColliding, this, &TableWindow::itemColliding);
|
|
|
|
connect(this, &TableWindow::LengthChanged, Detail, &VItem::LengthChanged);
|
2013-11-13 15:07:40 +01:00
|
|
|
Detail->setPen(QPen(Qt::black, 1));
|
2013-08-29 12:31:50 +02:00
|
|
|
Detail->setBrush(QBrush(Qt::white));
|
|
|
|
Detail->setPos(paper->boundingRect().center());
|
|
|
|
Detail->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
Detail->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
Detail->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
2013-11-13 15:07:40 +01:00
|
|
|
Detail->setPaper(paper);
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->addItem(Detail);
|
2013-08-29 12:31:50 +02:00
|
|
|
Detail->setSelected(true);
|
|
|
|
indexDetail++;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (indexDetail==listDetails.count())
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->actionSave->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
2013-12-30 12:54:38 +01:00
|
|
|
numberDetal->setText(QString(tr("%1 details left.")).arg(listDetails.count()-indexDetail));
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
*/
|
2014-02-19 14:50:43 +01:00
|
|
|
void TableWindow::ModelChosen(QVector<VItem*> 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;
|
|
|
|
listOutItems = new QBitArray(this->listDetails.count());
|
|
|
|
AddPaper();
|
|
|
|
indexDetail = 0;
|
|
|
|
AddDetail();
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::StopTable()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
hide();
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->clear();
|
2013-08-29 12:31:50 +02:00
|
|
|
delete listOutItems;
|
|
|
|
listDetails.clear();
|
|
|
|
//sceneRect = QRectF(0, 0, 230*resol/25.9, 327*resol/25.9);
|
2014-03-19 19:27:11 +01:00
|
|
|
sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171));
|
2013-08-29 12:31:50 +02:00
|
|
|
emit closed();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::saveScene()
|
|
|
|
{
|
2014-01-09 12:39:58 +01:00
|
|
|
QMap<QString, QString> extByMessage;
|
|
|
|
extByMessage[ tr("Svg files (*.svg)") ] = ".svg";
|
|
|
|
extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
|
|
|
|
extByMessage[ tr("Images (*.png)") ] = ".png";
|
2014-02-17 23:57:51 +01:00
|
|
|
extByMessage[ tr("PS files (*.ps)") ] = ".ps";
|
|
|
|
extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
|
2014-01-09 12:39:58 +01:00
|
|
|
|
|
|
|
QString saveMessage;
|
|
|
|
QMapIterator<QString, QString> i(extByMessage);
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
saveMessage += i.key();
|
|
|
|
if (i.hasNext())
|
2014-01-27 17:01:24 +01:00
|
|
|
{
|
2014-01-09 12:39:58 +01:00
|
|
|
saveMessage += ";;";
|
2014-01-27 17:01:24 +01:00
|
|
|
}
|
2014-01-09 12:39:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString sf;
|
|
|
|
// the save function
|
2014-02-19 17:26:03 +01:00
|
|
|
QString dir = QDir::homePath()+"/"+fileName;
|
2014-01-16 23:32:20 +01:00
|
|
|
QString name = QFileDialog::getSaveFileName(this, tr("Save layout"), dir, saveMessage, &sf);
|
2014-01-09 12:39:58 +01:00
|
|
|
|
|
|
|
if (name.isEmpty())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:39:58 +01:00
|
|
|
// what if the users did not specify a suffix...?
|
|
|
|
QFileInfo f( name );
|
2014-02-17 23:57:51 +01:00
|
|
|
if (f.suffix().isEmpty() && f.suffix() != "svg" && f.suffix() != "png" && f.suffix() != "pdf"
|
|
|
|
&& f.suffix() != "eps" && f.suffix() != "ps")
|
2014-01-09 12:39:58 +01:00
|
|
|
{
|
|
|
|
name += extByMessage[sf];
|
|
|
|
}
|
|
|
|
|
2013-08-29 12:31:50 +02:00
|
|
|
QBrush *brush = new QBrush();
|
|
|
|
brush->setColor( QColor( Qt::white ) );
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->setBackgroundBrush( *brush );
|
|
|
|
tableScene->clearSelection(); // Selections would also render to the file, so need delete them
|
2013-11-13 15:07:40 +01:00
|
|
|
shadowPaper->setVisible(false);
|
2014-03-19 19:27:11 +01:00
|
|
|
paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));
|
2014-01-09 12:39:58 +01:00
|
|
|
QFileInfo fi( name );
|
2014-02-18 20:14:12 +01:00
|
|
|
QStringList suffix;
|
|
|
|
suffix << "svg" << "png" << "pdf" << "eps" << "ps";
|
2014-02-18 21:42:06 +01:00
|
|
|
switch (suffix.indexOf(fi.suffix()))
|
|
|
|
{
|
2014-05-01 13:33:40 +02:00
|
|
|
case 0: //svg
|
|
|
|
paper->setVisible(false);
|
|
|
|
SvgFile(name);
|
|
|
|
paper->setVisible(true);
|
|
|
|
break;
|
|
|
|
case 1: //png
|
|
|
|
PngFile(name);
|
|
|
|
break;
|
|
|
|
case 2: //pdf
|
|
|
|
PdfFile(name);
|
|
|
|
break;
|
|
|
|
case 3: //eps
|
|
|
|
EpsFile(name);
|
|
|
|
break;
|
|
|
|
case 4: //ps
|
|
|
|
PsFile(name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug() << "Bad file suffix"<<Q_FUNC_INFO;
|
|
|
|
break;
|
2014-02-17 23:57:51 +01:00
|
|
|
}
|
2014-03-26 05:39:07 +01:00
|
|
|
paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
2013-08-29 12:31:50 +02:00
|
|
|
brush->setColor( QColor( Qt::gray ) );
|
|
|
|
brush->setStyle( Qt::SolidPattern );
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->setBackgroundBrush( *brush );
|
2013-11-13 15:07:40 +01:00
|
|
|
shadowPaper->setVisible(true);
|
|
|
|
delete brush;
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::itemChect(bool flag)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->actionTurn->setDisabled(flag);
|
|
|
|
ui->actionMirror->setDisabled(flag);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::checkNext()
|
|
|
|
{
|
|
|
|
if (outItems == true && collidingItems == true)
|
|
|
|
{
|
2013-12-21 15:21:40 +01:00
|
|
|
colission->setText(tr("Collisions not found."));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (indexDetail==listDetails.count())
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->actionSave->setEnabled(true);
|
|
|
|
ui->actionNext->setDisabled(true);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->actionNext->setDisabled(false);
|
|
|
|
ui->actionSave->setEnabled(false);
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 15:21:40 +01:00
|
|
|
colission->setText(tr("Collisions found."));
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->actionNext->setDisabled(true);
|
|
|
|
ui->actionSave->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::itemOut(int number, bool flag)
|
|
|
|
{
|
|
|
|
listOutItems->setBit(number, flag);
|
|
|
|
for ( int i = 0; i < listOutItems->count(); ++i )
|
|
|
|
{
|
|
|
|
if (listOutItems->at(i)==true)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
outItems=false;
|
|
|
|
qDebug()<<"itemOut::outItems="<<outItems<<"&& collidingItems"<<collidingItems;
|
|
|
|
checkNext();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outItems=true;
|
|
|
|
checkNext();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::itemColliding(QList<QGraphicsItem *> list, int number)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
//qDebug()<<"number="<<number;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (number==0)
|
|
|
|
{
|
|
|
|
if (listCollidingItems.isEmpty()==false)
|
|
|
|
{
|
|
|
|
if (listCollidingItems.contains(list.at(0))==true)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
listCollidingItems.removeAt(listCollidingItems.indexOf(list.at(0)));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (listCollidingItems.size()>1)
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < listCollidingItems.count(); ++i )
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> lis = listCollidingItems.at(i)->collidingItems();
|
|
|
|
if (lis.size()-2 <= 0)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
VItem * bitem = qgraphicsitem_cast<VItem *> ( listCollidingItems.at(i) );
|
2014-01-30 14:47:41 +01:00
|
|
|
Q_CHECK_PTR(bitem);
|
2014-03-26 05:39:07 +01:00
|
|
|
bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
2013-08-29 12:31:50 +02:00
|
|
|
listCollidingItems.removeAt(i);
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else if (listCollidingItems.size()==1)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
VItem * bitem = qgraphicsitem_cast<VItem *> ( listCollidingItems.at(0) );
|
2014-01-30 14:47:41 +01:00
|
|
|
Q_CHECK_PTR(bitem);
|
2014-03-26 05:39:07 +01:00
|
|
|
bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
2013-08-29 12:31:50 +02:00
|
|
|
listCollidingItems.clear();
|
|
|
|
collidingItems = true;
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
collidingItems = true;
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
collidingItems = true;
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else if (number==1)
|
|
|
|
{
|
|
|
|
if (list.contains(paper)==true)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
list.removeAt(list.indexOf(paper));
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (list.contains(shadowPaper)==true)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
list.removeAt(list.indexOf(shadowPaper));
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
for ( int i = 0; i < list.count(); ++i )
|
|
|
|
{
|
|
|
|
if (listCollidingItems.contains(list.at(i))==false)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
listCollidingItems.append(list.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
collidingItems = false;
|
|
|
|
}
|
|
|
|
qDebug()<<"itemColliding::outItems="<<outItems<<"&& collidingItems"<<collidingItems;
|
|
|
|
checkNext();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::GetNextDetail()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
AddDetail();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::AddLength()
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
QRectF rect = tableScene->sceneRect();
|
2014-03-19 19:27:11 +01:00
|
|
|
rect.setHeight(rect.height()+qApp->toPixel(279));
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->setSceneRect(rect);
|
2013-08-29 12:31:50 +02:00
|
|
|
rect = shadowPaper->rect();
|
2014-03-19 19:27:11 +01:00
|
|
|
rect.setHeight(rect.height()+qApp->toPixel(279));
|
2013-08-29 12:31:50 +02:00
|
|
|
shadowPaper->setRect(rect);
|
|
|
|
rect = paper->rect();
|
2014-03-19 19:27:11 +01:00
|
|
|
rect.setHeight(rect.height()+qApp->toPixel(279));
|
2013-08-29 12:31:50 +02:00
|
|
|
paper->setRect(rect);
|
|
|
|
ui->actionRemove->setEnabled(true);
|
|
|
|
emit LengthChanged();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::RemoveLength()
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
if (sceneRect.height() <= tableScene->sceneRect().height() - 100)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
QRectF rect = tableScene->sceneRect();
|
2014-03-19 19:27:11 +01:00
|
|
|
rect.setHeight(rect.height()-qApp->toPixel(279));
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->setSceneRect(rect);
|
2013-08-29 12:31:50 +02:00
|
|
|
rect = shadowPaper->rect();
|
2014-03-19 19:27:11 +01:00
|
|
|
rect.setHeight(rect.height()-qApp->toPixel(279));
|
2013-08-29 12:31:50 +02:00
|
|
|
shadowPaper->setRect(rect);
|
|
|
|
rect = paper->rect();
|
2014-03-19 19:27:11 +01:00
|
|
|
rect.setHeight(rect.height()-qApp->toPixel(279));
|
2013-08-29 12:31:50 +02:00
|
|
|
paper->setRect(rect);
|
2013-12-30 19:59:33 +01:00
|
|
|
if (fabs(sceneRect.height() - tableScene->sceneRect().height()) < 0.01)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->actionRemove->setDisabled(true);
|
|
|
|
}
|
|
|
|
emit LengthChanged();
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ui->actionRemove->setDisabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::keyPressEvent ( QKeyEvent * event )
|
|
|
|
{
|
|
|
|
if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return )
|
|
|
|
{
|
|
|
|
if (ui->actionNext->isEnabled() == true )
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
AddDetail();
|
2013-12-21 15:21:40 +01:00
|
|
|
qDebug()<<"Added detail.";
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
QMainWindow::keyPressEvent ( event );
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::SvgFile(const QString &name) const
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QSvgGenerator generator;
|
|
|
|
generator.setFileName(name);
|
|
|
|
generator.setSize(paper->rect().size().toSize());
|
2014-02-28 13:17:41 +01:00
|
|
|
generator.setViewBox(paper->rect());
|
2014-02-19 14:50:43 +01:00
|
|
|
generator.setTitle("Valentina pattern");
|
|
|
|
generator.setDescription(description);
|
2014-03-19 19:27:11 +01:00
|
|
|
generator.setResolution(static_cast<int>(qApp->PrintDPI));
|
2013-08-29 12:31:50 +02:00
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&generator);
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
2014-03-26 05:39:07 +01:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
2013-08-29 12:31:50 +02:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->render(&painter);
|
2013-08-29 12:31:50 +02:00
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void TableWindow::PngFile(const QString &name) const
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QRectF r = paper->rect();
|
|
|
|
qreal x=0, y=0, w=0, h=0;
|
2013-11-04 21:35:15 +01:00
|
|
|
r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents
|
|
|
|
// Create the image with the exact size of the shrunk scene
|
|
|
|
QImage image(QSize(static_cast<qint32>(w), static_cast<qint32>(h)), QImage::Format_ARGB32);
|
2013-08-29 12:31:50 +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);
|
2014-03-26 05:39:07 +01:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
2013-08-29 12:31:50 +02:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
2013-12-30 19:59:33 +01:00
|
|
|
tableScene->render(&painter);
|
2013-08-29 12:31:50 +02:00
|
|
|
image.save(name);
|
|
|
|
}
|
2014-01-09 12:39:58 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-09 12:39:58 +01:00
|
|
|
void TableWindow::PdfFile(const QString &name) const
|
|
|
|
{
|
|
|
|
QPrinter printer;
|
|
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
|
|
|
printer.setOutputFileName(name);
|
|
|
|
QRectF r = paper->rect();
|
|
|
|
qreal x=0, y=0, w=0, h=0;
|
|
|
|
r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents
|
2014-03-19 19:27:11 +01:00
|
|
|
printer.setResolution(static_cast<int>(qApp->PrintDPI));
|
|
|
|
printer.setPaperSize ( QSizeF(qApp->fromPixel(w), qApp->fromPixel(h)), QPrinter::Millimeter );
|
2014-01-09 12:39:58 +01:00
|
|
|
QPainter painter;
|
2014-01-27 17:01:24 +01:00
|
|
|
if (painter.begin( &printer ) == false)
|
|
|
|
{ // failed to open file
|
|
|
|
qCritical("Can't open printer %s", qPrintable(name));
|
2014-01-09 12:39:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
2014-03-26 05:39:07 +01:00
|
|
|
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
2014-01-09 12:39:58 +01:00
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
tableScene->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
}
|
2014-02-17 23:57:51 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-17 23:57:51 +01:00
|
|
|
void TableWindow::EpsFile(const QString &name) const
|
|
|
|
{
|
|
|
|
QTemporaryFile tmp;
|
2014-02-18 21:20:58 +01:00
|
|
|
if (tmp.open())
|
|
|
|
{
|
2014-02-17 23:57:51 +01:00
|
|
|
PdfFile(tmp.fileName());
|
|
|
|
|
2014-02-18 21:20:58 +01:00
|
|
|
QStringList params;
|
2014-02-17 23:57:51 +01:00
|
|
|
params << "-eps" << tmp.fileName() << name;
|
2014-02-18 21:20:58 +01:00
|
|
|
|
2014-03-14 19:47:50 +01:00
|
|
|
PdfToPs(params);
|
2014-02-26 10:51:37 +01:00
|
|
|
}
|
2014-02-17 23:57:51 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-17 23:57:51 +01:00
|
|
|
void TableWindow::PsFile(const QString &name) const
|
|
|
|
{
|
|
|
|
QTemporaryFile tmp;
|
2014-02-18 21:20:58 +01:00
|
|
|
if (tmp.open())
|
|
|
|
{
|
2014-02-17 23:57:51 +01:00
|
|
|
PdfFile(tmp.fileName());
|
|
|
|
|
2014-02-18 21:20:58 +01:00
|
|
|
QStringList params;
|
|
|
|
params << tmp.fileName() << name;
|
|
|
|
|
2014-03-14 19:47:50 +01:00
|
|
|
PdfToPs(params);
|
2014-02-18 21:20:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-14 19:47:50 +01:00
|
|
|
void TableWindow::PdfToPs(const QStringList ¶ms) const
|
2014-03-06 16:35:24 +01:00
|
|
|
{
|
2014-02-18 20:14:12 +01:00
|
|
|
#ifndef QT_NO_CURSOR
|
2014-02-18 21:20:58 +01:00
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2014-02-18 20:14:12 +01:00
|
|
|
#endif
|
2014-02-18 21:20:58 +01:00
|
|
|
QProcess proc;
|
2014-02-21 15:58:07 +01:00
|
|
|
#ifdef Q_OS_WIN
|
2014-02-28 13:30:23 +01:00
|
|
|
proc.start("pdftops.exe", params);
|
2014-02-17 23:57:51 +01:00
|
|
|
#else
|
2014-02-28 13:30:23 +01:00
|
|
|
proc.start("pdftops", params);
|
2014-02-18 20:14:12 +01:00
|
|
|
#endif
|
2014-02-18 21:20:58 +01:00
|
|
|
proc.waitForFinished(15000);
|
2014-02-18 20:14:12 +01:00
|
|
|
#ifndef QT_NO_CURSOR
|
2014-02-18 21:20:58 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
2014-02-18 20:14:12 +01:00
|
|
|
#endif
|
2014-02-18 21:20:58 +01:00
|
|
|
|
2014-03-14 19:47:50 +01:00
|
|
|
QFile f(params.last());
|
2014-02-26 10:51:37 +01:00
|
|
|
if (f.exists() == false)
|
2014-02-18 21:20:58 +01:00
|
|
|
{
|
2014-03-14 19:47:50 +01:00
|
|
|
QString msg = QString(tr("Creating file '%1' failed! %2")).arg(params.last()).arg(proc.errorString());
|
2014-02-28 13:30:23 +01:00
|
|
|
QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default);
|
2014-02-18 21:20:58 +01:00
|
|
|
msgBox.exec();
|
|
|
|
}
|
2014-02-17 23:57:51 +01:00
|
|
|
}
|