2013-09-18 21:16:19 +02:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2013 Valentina project All Rights Reserved.
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Valentina.
|
|
|
|
|
**
|
|
|
|
|
** Tox 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.
|
|
|
|
|
**
|
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-08-29 12:31:50 +02:00
|
|
|
|
#include "tablewindow.h"
|
|
|
|
|
#include "ui_tablewindow.h"
|
|
|
|
|
#include "widgets/vtablegraphicsview.h"
|
|
|
|
|
#include "options.h"
|
2013-11-12 13:48:45 +01:00
|
|
|
|
#include <QtSvg>
|
2013-08-29 12:31:50 +02:00
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
TableWindow::TableWindow(QWidget *parent)
|
|
|
|
|
:QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow),
|
2013-08-29 12:31:50 +02:00
|
|
|
|
listDetails(QVector<VItem*>()), outItems(false), collidingItems(false), currentScene(0),
|
|
|
|
|
paper(0), shadowPaper(0), listOutItems(0), listCollidingItems(QList<QGraphicsItem*>()),
|
2013-11-04 21:35:15 +01:00
|
|
|
|
indexDetail(0), sceneRect(QRectF())
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
numberDetal = new QLabel("Залишилось 0 деталей.", this);
|
|
|
|
|
colission = new QLabel("Колізій не знайдено.", this);
|
|
|
|
|
ui->statusBar->addWidget(numberDetal);
|
|
|
|
|
ui->statusBar->addWidget(colission);
|
|
|
|
|
outItems = collidingItems = false;
|
2013-10-28 18:27:31 +01:00
|
|
|
|
//sceneRect = QRectF(0, 0, toPixel(203), toPixel(287));
|
2013-08-29 12:31:50 +02:00
|
|
|
|
sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171));
|
|
|
|
|
currentScene = new QGraphicsScene(sceneRect);
|
|
|
|
|
QBrush *brush = new QBrush();
|
|
|
|
|
brush->setStyle( Qt::SolidPattern );
|
|
|
|
|
brush->setColor( QColor( Qt::gray ) );
|
|
|
|
|
currentScene->setBackgroundBrush( *brush );
|
|
|
|
|
VTableGraphicsView* view = new VTableGraphicsView(currentScene);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
TableWindow::~TableWindow()
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
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));
|
|
|
|
|
currentScene->addItem(shadowPaper);
|
2013-11-04 21:35:15 +01:00
|
|
|
|
paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2));
|
2013-08-29 12:31:50 +02:00
|
|
|
|
paper->setPen(QPen(Qt::black, toPixel(widthMainLine)));
|
|
|
|
|
paper->setBrush(QBrush(Qt::white));
|
|
|
|
|
currentScene->addItem(paper);
|
|
|
|
|
qDebug()<<paper->rect().size().toSize();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::AddDetail()
|
|
|
|
|
{
|
|
|
|
|
if (indexDetail<listDetails.count())
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
currentScene->clearSelection();
|
|
|
|
|
VItem* Detail = listDetails[indexDetail];
|
2013-11-04 21:35:15 +01:00
|
|
|
|
QObject::connect(Detail, SIGNAL(itemOut(int, bool)), this, SLOT(itemOut(int, bool)));
|
|
|
|
|
QObject::connect(Detail, SIGNAL(itemColliding(QList<QGraphicsItem*>, int)), this,
|
|
|
|
|
SLOT(itemColliding(QList<QGraphicsItem*>, int)));
|
2013-08-29 12:31:50 +02:00
|
|
|
|
QObject::connect(this, SIGNAL(LengthChanged()), Detail, SLOT(LengthChanged()));
|
|
|
|
|
Detail->setPen(QPen(Qt::black, toPixel(widthMainLine)));
|
|
|
|
|
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);
|
|
|
|
|
Detail->setParentItem(paper);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
numberDetal->setText(QString("Залишилось %1 деталей.").arg(listDetails.count()-indexDetail));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Отримуємо деталі розрахованої моделі для подальшого укладання.
|
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::ModelChosen(QVector<VItem*> listDetails)
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
this->listDetails = listDetails;
|
|
|
|
|
listOutItems = new QBitArray(this->listDetails.count());
|
|
|
|
|
AddPaper();
|
|
|
|
|
indexDetail = 0;
|
|
|
|
|
AddDetail();
|
|
|
|
|
show();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::closeEvent(QCloseEvent *event)
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
event->ignore();
|
|
|
|
|
StopTable();
|
|
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::StopTable()
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
hide();
|
|
|
|
|
currentScene->clear();
|
|
|
|
|
delete listOutItems;
|
|
|
|
|
listDetails.clear();
|
|
|
|
|
//sceneRect = QRectF(0, 0, 230*resol/25.9, 327*resol/25.9);
|
|
|
|
|
sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171));
|
|
|
|
|
emit closed();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::saveScene()
|
|
|
|
|
{
|
2013-10-14 16:44:33 +02:00
|
|
|
|
QString name = QFileDialog::getSaveFileName(0, tr("Save layout"), "", "Images (*.png);;Svg files (*.svg)");
|
2013-11-04 21:35:15 +01:00
|
|
|
|
if (name.isNull())
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QBrush *brush = new QBrush();
|
|
|
|
|
brush->setColor( QColor( Qt::white ) );
|
|
|
|
|
currentScene->setBackgroundBrush( *brush );
|
2013-10-14 16:44:33 +02:00
|
|
|
|
currentScene->clearSelection(); // Selections would also render to the file
|
2013-08-29 12:31:50 +02:00
|
|
|
|
shadowPaper->setBrush(QBrush(Qt::white));
|
|
|
|
|
shadowPaper->setPen(QPen(Qt::white, 0.1));
|
|
|
|
|
paper->setPen(QPen(Qt::white, 0.1));
|
|
|
|
|
paper->setBrush(QBrush(Qt::white));
|
|
|
|
|
currentScene->setSceneRect(currentScene->itemsBoundingRect());
|
|
|
|
|
|
|
|
|
|
QFileInfo fi(name);
|
2013-11-04 21:35:15 +01:00
|
|
|
|
if (fi.suffix() == "svg")
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
SvgFile(name);
|
2013-11-04 21:35:15 +01:00
|
|
|
|
}
|
|
|
|
|
else if (fi.suffix() == "png")
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
PngFile(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
brush->setColor( QColor( Qt::gray ) );
|
|
|
|
|
brush->setStyle( Qt::SolidPattern );
|
|
|
|
|
currentScene->setBackgroundBrush( *brush );
|
|
|
|
|
paper->setPen(QPen(Qt::black, widthMainLine));
|
|
|
|
|
shadowPaper->setBrush(QBrush(Qt::black));
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::checkNext()
|
|
|
|
|
{
|
|
|
|
|
if (outItems == true && collidingItems == true)
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
colission->setText("Колізій не знайдено.");
|
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-08-29 12:31:50 +02:00
|
|
|
|
colission->setText("Знайдено колізії.");
|
|
|
|
|
ui->actionNext->setDisabled(true);
|
|
|
|
|
ui->actionSave->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
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) );
|
2013-11-04 21:35:15 +01:00
|
|
|
|
if (bitem == 0)
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
qDebug()<<"Не можу привести тип об'єкту";
|
2013-11-04 21:35:15 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
bitem->setPen(QPen(Qt::black, toPixel(widthMainLine)));
|
|
|
|
|
}
|
|
|
|
|
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) );
|
2013-11-04 21:35:15 +01:00
|
|
|
|
if (bitem == 0)
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
qDebug()<<"Не можу привести тип об'єкту";
|
2013-11-04 21:35:15 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
bitem->setPen(QPen(Qt::black, toPixel(widthMainLine)));
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::GetNextDetail()
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
AddDetail();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::AddLength()
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
QRectF rect = currentScene->sceneRect();
|
|
|
|
|
rect.setHeight(rect.height()+toPixel(279));
|
|
|
|
|
currentScene->setSceneRect(rect);
|
|
|
|
|
rect = shadowPaper->rect();
|
|
|
|
|
rect.setHeight(rect.height()+toPixel(279));
|
|
|
|
|
shadowPaper->setRect(rect);
|
|
|
|
|
rect = paper->rect();
|
|
|
|
|
rect.setHeight(rect.height()+toPixel(279));
|
|
|
|
|
paper->setRect(rect);
|
|
|
|
|
ui->actionRemove->setEnabled(true);
|
|
|
|
|
emit LengthChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
void TableWindow::RemoveLength()
|
|
|
|
|
{
|
|
|
|
|
if (sceneRect.height()<=currentScene->sceneRect().height()-100)
|
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
|
QRectF rect = currentScene->sceneRect();
|
|
|
|
|
rect.setHeight(rect.height()-toPixel(279));
|
|
|
|
|
currentScene->setSceneRect(rect);
|
|
|
|
|
rect = shadowPaper->rect();
|
|
|
|
|
rect.setHeight(rect.height()-toPixel(279));
|
|
|
|
|
shadowPaper->setRect(rect);
|
|
|
|
|
rect = paper->rect();
|
|
|
|
|
rect.setHeight(rect.height()-toPixel(279));
|
|
|
|
|
paper->setRect(rect);
|
2013-11-04 21:35:15 +01:00
|
|
|
|
if (sceneRect.height()==currentScene->sceneRect().height())
|
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
qDebug()<<"Додали деталь.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QMainWindow::keyPressEvent ( event );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
//generator.setViewBox(QRect(0, 0, 200, 200));
|
|
|
|
|
generator.setTitle(tr("SVG Generator Example Drawing"));
|
|
|
|
|
generator.setDescription(tr("An SVG drawing created by the SVG Generator "
|
|
|
|
|
"Example provided with Qt."));
|
2013-11-12 13:48:45 +01:00
|
|
|
|
generator.setResolution(PrintDPI);
|
|
|
|
|
qDebug()<<"resolution is" << generator.resolution();
|
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);
|
|
|
|
|
painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
|
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
|
currentScene->render(&painter);
|
|
|
|
|
painter.end();
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
painter.setPen(QPen(Qt::black, toPixel(widthMainLine), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
|
|
|
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
|
|
|
|
currentScene->render(&painter);
|
|
|
|
|
image.save(name);
|
|
|
|
|
}
|