From 79325fe91f371703d6c555e04a77ed90d8884805 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 15 Jan 2015 15:10:05 +0200 Subject: [PATCH] Changes for table widows. All prepare for begin testing. --HG-- branch : feature --- src/app/tablewindow.cpp | 758 ++++++++++---------------- src/app/tablewindow.h | 91 +--- src/app/tablewindow.ui | 55 +- src/libs/vlayout/vlayoutgenerator.cpp | 1 + 4 files changed, 367 insertions(+), 538 deletions(-) diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp index c48726fae..78371a773 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/tablewindow.cpp @@ -29,12 +29,16 @@ #include "tablewindow.h" #include "ui_tablewindow.h" #include "widgets/vtablegraphicsview.h" -#include -#include #include "core/vapplication.h" -#include #include "../../libs/vobj/vobjpaintdevice.h" #include "../dialogs/app/dialoglayoutsettings.h" +#include "../../libs/vlayout/vlayoutgenerator.h" +#include "../dialogs/app/dialoglayoutprogress.h" + +#include +#include +#include +#include #ifdef Q_OS_WIN # define PDFTOPS "pdftops.exe" @@ -48,98 +52,36 @@ * @param parent parent widget. */ TableWindow::TableWindow(QWidget *parent) - :QMainWindow(parent), numberDetal(nullptr), colission(nullptr), ui(new Ui::TableWindow), - listDetails(QVector()), outItems(false), collidingItems(false), tableScene(nullptr), - paper(nullptr), shadowPaper(nullptr), listOutItems(nullptr), listCollidingItems(QList()), - indexDetail(0), sceneRect(QRectF()), fileName(QString()), description(QString()) + :QMainWindow(parent), ui(new Ui::TableWindow), + listDetails(QVector()), papers(QList()), shadows(QList()), + scenes(QList()), fileName(QString()), description(QString()), paperHeight(0), paperWidth(0), + shift(0), layoutWidth(0), group(Cases::CaseDesc), tempScene(nullptr) { ui->setupUi(this); - numberDetal = new QLabel(tr("0 details left."), this); - colission = new QLabel(tr("Collisions not found."), this); - ui->statusBar->addWidget(numberDetal); - ui->statusBar->addWidget(colission); - outItems = collidingItems = false; - sceneRect = QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)); - tableScene = new QGraphicsScene(sceneRect); + tempScene = new QGraphicsScene(QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm))); QBrush brush; brush.setStyle( Qt::SolidPattern ); brush.setColor( QColor( Qt::gray ) ); - tableScene->setBackgroundBrush( brush ); + tempScene->setBackgroundBrush( brush ); - ui->view->setScene(tableScene); + ui->view->setScene(tempScene); ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio); ui->horizontalLayout->addWidget(ui->view); - connect(tableScene, &QGraphicsScene::selectionChanged, ui->view, &VTableGraphicsView::selectionChanged); - connect(ui->actionTurn, &QAction::triggered, ui->view, &VTableGraphicsView::rotateItems); - connect(ui->actionMirror, &QAction::triggered, ui->view, &VTableGraphicsView::MirrorItem); - connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn); - connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut); + //connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn); + //connect(ui->actionZoomOut, &QAction::triggered, ui->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(ui->view, &VTableGraphicsView::itemChect, this, &TableWindow::itemChect); + //connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene); connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &TableWindow::ShowPaper); } //--------------------------------------------------------------------------------------------------------------------- TableWindow::~TableWindow() { - delete tableScene; + ClearLayout(); delete ui; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddPaper add to the scene paper and shadow. - */ -void TableWindow::AddPaper() -{ - qreal x1, y1, x2, y2; - sceneRect.getCoords(&x1, &y1, &x2, &y2); - shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4)); - shadowPaper->setBrush(QBrush(Qt::black)); - tableScene->addItem(shadowPaper); - paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2)); - paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); - paper->setBrush(QBrush(Qt::white)); - tableScene->addItem(paper); - qDebug()<rect().size().toSize(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddDetail show on scene next detail. - */ -void TableWindow::AddDetail() -{ -// if (indexDetailclearSelection(); -// VItem* Detail = listDetails[indexDetail]; -// SCASSERT(Detail != nullptr); -// connect(Detail, &VItem::itemOut, this, &TableWindow::itemOut); -// connect(Detail, &VItem::itemColliding, this, &TableWindow::itemColliding); -// connect(this, &TableWindow::LengthChanged, Detail, &VItem::LengthChanged); -// Detail->setPen(QPen(Qt::black, 1)); -// 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->setPaper(paper); -// tableScene->addItem(Detail); -// Detail->setSelected(true); -// indexDetail++; -// if (indexDetail==listDetails.count()) -// { -// ui->actionSave->setEnabled(true); -// } -// } -// numberDetal->setText(QString(tr("%1 details left.")).arg(listDetails.count()-indexDetail)); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief ModelChosen show window when user want create new layout. @@ -166,10 +108,6 @@ void TableWindow::ModelChosen(QVector listDetails, const QString this->fileName = fi.baseName(); this->listDetails = listDetails; - listOutItems = new QBitArray(this->listDetails.count()); - AddPaper(); - indexDetail = 0; - AddDetail(); show(); } @@ -214,11 +152,7 @@ void TableWindow::showEvent ( QShowEvent * event ) void TableWindow::StopTable() { hide(); - tableScene->clear(); - delete listOutItems; - listDetails.clear(); - sceneRect = QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)); - tableScene->setSceneRect(sceneRect); + ClearLayout(); emit closed(); } @@ -228,313 +162,160 @@ void TableWindow::StopTable() */ void TableWindow::saveScene() { - QMap extByMessage; - extByMessage[ tr("Svg files (*.svg)") ] = ".svg"; - extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf"; - extByMessage[ tr("Images (*.png)") ] = ".png"; - extByMessage[ tr("Wavefront OBJ (*.obj)") ] = ".obj"; +// QMap 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; - proc.start(PDFTOPS); - if (proc.waitForFinished(15000)) - { - extByMessage[ tr("PS files (*.ps)") ] = ".ps"; - extByMessage[ tr("EPS files (*.eps)") ] = ".eps"; - } - else - { - qWarning()< i(extByMessage); - while (i.hasNext()) - { - i.next(); - saveMessage += i.key(); - if (i.hasNext()) - { - saveMessage += ";;"; - } - } - - QString sf; - // the save function - QString dir = QDir::homePath()+"/"+fileName; - QString name = QFileDialog::getSaveFileName(this, tr("Save layout"), dir, saveMessage, &sf); - - if (name.isEmpty()) - { - return; - } - - // what if the user did not specify a suffix...? - QString suf = extByMessage.value(sf); - suf.replace(".", ""); - QFileInfo f( name ); - if (f.suffix().isEmpty() || f.suffix() != suf) - { - name += extByMessage.value(sf); - } - - QBrush *brush = new QBrush(); - brush->setColor( QColor( Qt::white ) ); - tableScene->setBackgroundBrush( *brush ); - tableScene->clearSelection(); // Selections would also render to the file, so need delete them - shadowPaper->setVisible(false); - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); - QFileInfo fi( name ); - QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj"; - switch (suffix.indexOf(fi.suffix())) - { - 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; - case 5: //obj - paper->setVisible(false); - ObjFile(name); - paper->setVisible(true); - break; - default: - qDebug() << "Can't recognize file suffix. File file "<setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); - brush->setColor( QColor( Qt::gray ) ); - brush->setStyle( Qt::SolidPattern ); - tableScene->setBackgroundBrush( *brush ); - shadowPaper->setVisible(true); - delete brush; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief itemChect turn off rotation button if don't selected detail. - * @param flag true - enable button. - */ -void TableWindow::itemChect(bool flag) -{ - ui->actionTurn->setDisabled(flag); - ui->actionMirror->setDisabled(flag); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief checkNext disable next detail button if exist colission or out details. - */ -void TableWindow::checkNext() -{ - if (outItems == true && collidingItems == true) - { - colission->setText(tr("Collisions not found.")); - if (indexDetail==listDetails.count()) - { - ui->actionSave->setEnabled(true); - ui->actionNext->setDisabled(true); - } - else - { - ui->actionNext->setDisabled(false); - ui->actionSave->setEnabled(false); - } - } - else - { - colission->setText(tr("Collisions found.")); - ui->actionNext->setDisabled(true); - ui->actionSave->setEnabled(false); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief itemOut handled if detail moved out paper sheet. - * @param number Number detail in list. - * @param flag set state of detail. True if detail moved out paper sheet. - */ -void TableWindow::itemOut(int number, bool flag) -{ - listOutItems->setBit(number, flag); - for ( int i = 0; i < listOutItems->count(); ++i ) - { - if (listOutItems->at(i)==true) - { - outItems=false; - qDebug()<<"itemOut::outItems="< list, int number) -{ - //qDebug()<<"number="< i(extByMessage); +// while (i.hasNext()) +// { +// i.next(); +// saveMessage += i.key(); +// if (i.hasNext()) // { -// if (listCollidingItems.contains(list.at(0))==true) -// { -// listCollidingItems.removeAt(listCollidingItems.indexOf(list.at(0))); -// if (listCollidingItems.size()>1) -// { -// for ( int i = 0; i < listCollidingItems.count(); ++i ) -// { -// QList lis = listCollidingItems.at(i)->collidingItems(); -// if (lis.size()-2 <= 0) -// { -// VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(i) ); -// SCASSERT(bitem != nullptr); -// bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); -// listCollidingItems.removeAt(i); -// } -// } -// } -// else if (listCollidingItems.size()==1) -// { -// VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(0) ); -// SCASSERT(bitem != nullptr); -// bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); -// listCollidingItems.clear(); -// collidingItems = true; -// } -// } -// else -// { -// collidingItems = true; -// } -// } -// else -// { -// collidingItems = true; +// saveMessage += ";;"; // } // } -// else if (number==1) + +// QString sf; +// // the save function +// QString dir = QDir::homePath()+"/"+fileName; +// QString name = QFileDialog::getSaveFileName(this, tr("Save layout"), dir, saveMessage, &sf); + +// if (name.isEmpty()) // { -// if (list.contains(paper)==true) -// { -// list.removeAt(list.indexOf(paper)); -// } -// if (list.contains(shadowPaper)==true) -// { -// list.removeAt(list.indexOf(shadowPaper)); -// } -// for ( int i = 0; i < list.count(); ++i ) -// { -// if (listCollidingItems.contains(list.at(i))==false) -// { -// listCollidingItems.append(list.at(i)); -// } -// } -// collidingItems = false; +// return; // } -// qDebug()<<"itemColliding::outItems="<setColor( QColor( Qt::white ) ); +// tableScene->setBackgroundBrush( *brush ); +// tableScene->clearSelection(); // Selections would also render to the file, so need delete them +// shadowPaper->setVisible(false); +// paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); +// QFileInfo fi( name ); +// QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj"; +// switch (suffix.indexOf(fi.suffix())) +// { +// 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; +// case 5: //obj +// paper->setVisible(false); +// ObjFile(name); +// paper->setVisible(true); +// break; +// default: +// qDebug() << "Can't recognize file suffix. File file "<setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); +// brush->setColor( QColor( Qt::gray ) ); +// brush->setStyle( Qt::SolidPattern ); +// tableScene->setBackgroundBrush( *brush ); +// shadowPaper->setVisible(true); +// delete brush; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetNextDetail put next detail on table. - */ -void TableWindow::GetNextDetail() +void TableWindow::ShowPaper(int index) { - AddDetail(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddLength Add length paper sheet.Збільшує довжину листа на певне значення за один раз. - */ -void TableWindow::AddLength() -{ - QRectF rect = tableScene->sceneRect(); - rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm)); - tableScene->setSceneRect(rect); - rect = shadowPaper->rect(); - rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm)); - shadowPaper->setRect(rect); - rect = paper->rect(); - rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm)); - paper->setRect(rect); - ui->actionRemove->setEnabled(true); - emit LengthChanged(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RemoveLength reduce the length of paper sheet. You can reduce to the minimal value only. - */ -void TableWindow::RemoveLength() -{ - if (sceneRect.height() <= tableScene->sceneRect().height() - 100) + if (index < 0 || index > scenes.size()) { - QRectF rect = tableScene->sceneRect(); - rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm)); - tableScene->setSceneRect(rect); - rect = shadowPaper->rect(); - rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm)); - shadowPaper->setRect(rect); - rect = paper->rect(); - rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm)); - paper->setRect(rect); - if (fabs(sceneRect.height() - tableScene->sceneRect().height()) < 0.01) - { - ui->actionRemove->setDisabled(true); - } - emit LengthChanged(); - } - else - { - ui->actionRemove->setDisabled(true); + ui->view->setScene(tempScene); } + + ui->view->setScene(scenes.at(index)); } //--------------------------------------------------------------------------------------------------------------------- void TableWindow::Layout() { DialogLayoutSettings layout(this); - layout.exec(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief keyPressEvent handle key press events. - * @param event key event. - */ -void TableWindow::keyPressEvent ( QKeyEvent * event ) -{ - if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return ) + if (paperHeight != 0) { - if (ui->actionNext->isEnabled() == true ) - { - AddDetail(); - qDebug()<<"Added detail."; - } + layout.SetPaperHeight(paperHeight); + layout.SetPaperWidth(paperWidth); + layout.SetLayoutWidth(layoutWidth); + layout.SetShift(shift); + layout.SetGroup(group); + } + + if (layout.exec() == QDialog::Rejected) + { + return; + } + + paperHeight = layout.GetPaperHeight(); + paperWidth = layout.GetPaperWidth(); + shift = layout.GetShift(); + layoutWidth = layout.GetLayoutWidth(); + group = layout.GetGroup(); + + VLayoutGenerator lGenerator(this); + lGenerator.SetDetails(listDetails); + lGenerator.SetLayoutWidth(layoutWidth); + lGenerator.SetCaseType(group); + lGenerator.SetPaperHeight(paperHeight); + lGenerator.SetPaperWidth(paperWidth); + lGenerator.SetShift(shift); + + DialogLayoutProgress progress(lGenerator.DetailsCount(), this); + + 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); + + lGenerator.Generate(); + + if (lGenerator.State() == LayoutErrors::NoError) + { + ClearLayout(); + papers = lGenerator.GetItems(); + CreateShadows(); + CreateScenes(); + // Create previews + PrepareSceneList(); } - QMainWindow::keyPressEvent ( event ); } //--------------------------------------------------------------------------------------------------------------------- @@ -544,21 +325,21 @@ void TableWindow::keyPressEvent ( QKeyEvent * event ) */ void TableWindow::SvgFile(const QString &name) const { - QSvgGenerator generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setViewBox(paper->rect()); - generator.setTitle("Valentina pattern"); - generator.setDescription(description); - generator.setResolution(static_cast(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 ) ); - tableScene->render(&painter); - painter.end(); +// QSvgGenerator generator; +// generator.setFileName(name); +// generator.setSize(paper->rect().size().toSize()); +// generator.setViewBox(paper->rect()); +// generator.setTitle("Valentina pattern"); +// generator.setDescription(description); +// generator.setResolution(static_cast(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 ) ); +// tableScene->render(&painter); +// painter.end(); } //--------------------------------------------------------------------------------------------------------------------- @@ -568,19 +349,19 @@ void TableWindow::SvgFile(const QString &name) const */ void TableWindow::PngFile(const QString &name) const { - 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 - // Create the image with the exact size of the shrunk scene - QImage image(QSize(static_cast(w), static_cast(h)), 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 ) ); - tableScene->render(&painter); - image.save(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 +// // Create the image with the exact size of the shrunk scene +// QImage image(QSize(static_cast(w), static_cast(h)), 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 ) ); +// tableScene->render(&painter); +// image.save(name); } //--------------------------------------------------------------------------------------------------------------------- @@ -590,26 +371,26 @@ void TableWindow::PngFile(const QString &name) const */ 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 - printer.setResolution(static_cast(qApp->PrintDPI)); - printer.setPaperSize ( QSizeF(qApp->fromPixel(w, Unit::Mm), qApp->fromPixel(h, 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 ) ); - tableScene->render(&painter); - painter.end(); +// 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 +// printer.setResolution(static_cast(qApp->PrintDPI)); +// printer.setPaperSize ( QSizeF(qApp->fromPixel(w, Unit::Mm), qApp->fromPixel(h, 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 ) ); +// tableScene->render(&painter); +// painter.end(); } //--------------------------------------------------------------------------------------------------------------------- @@ -619,13 +400,13 @@ void TableWindow::PdfFile(const QString &name) const */ void TableWindow::EpsFile(const QString &name) const { - QTemporaryFile tmp; - if (tmp.open()) - { - PdfFile(tmp.fileName()); - QStringList params = QStringList() << "-eps" << tmp.fileName() << name; - PdfToPs(params); - } +// QTemporaryFile tmp; +// if (tmp.open()) +// { +// PdfFile(tmp.fileName()); +// QStringList params = QStringList() << "-eps" << tmp.fileName() << name; +// PdfToPs(params); +// } } //--------------------------------------------------------------------------------------------------------------------- @@ -635,13 +416,13 @@ void TableWindow::EpsFile(const QString &name) const */ void TableWindow::PsFile(const QString &name) const { - QTemporaryFile tmp; - if (tmp.open()) - { - PdfFile(tmp.fileName()); - QStringList params = QStringList() << tmp.fileName() << name; - PdfToPs(params); - } +// QTemporaryFile tmp; +// if (tmp.open()) +// { +// PdfFile(tmp.fileName()); +// QStringList params = QStringList() << tmp.fileName() << name; +// PdfToPs(params); +// } } //--------------------------------------------------------------------------------------------------------------------- @@ -652,34 +433,93 @@ void TableWindow::PsFile(const QString &name) const */ void TableWindow::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 +//#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(); - } +// 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 TableWindow::ObjFile(const QString &name) const { - VObjPaintDevice generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setResolution(static_cast(qApp->PrintDPI)); - QPainter painter; - painter.begin(&generator); - tableScene->render(&painter); - painter.end(); +// VObjPaintDevice generator; +// generator.setFileName(name); +// generator.setSize(paper->rect().size().toSize()); +// generator.setResolution(static_cast(qApp->PrintDPI)); +// QPainter painter; +// painter.begin(&generator); +// tableScene->render(&painter); +// painter.end(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TableWindow::ClearLayout() +{ + qDeleteAll (scenes); + scenes.clear(); + listDetails.clear(); + shadows.clear(); + papers.clear(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TableWindow::CreateShadows() +{ + for (int i=0; i< papers.size(); ++i) + { + qreal x1=0, y1=0, x2=0, y2=0; + QGraphicsRectItem *item = qgraphicsitem_cast(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 TableWindow::CreateScenes() +{ + QBrush brush; + brush.setStyle( Qt::SolidPattern ); + brush.setColor( QColor( Qt::gray ) ); + + for (int i=0; isetBackgroundBrush(brush); + scene->addItem(shadows.at(i)); + scene->addItem(papers.at(i)); + scenes.append(scene); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TableWindow::PrepareSceneList() +{ + const QIcon ico("://icon/64x64/icon64x64.png"); + for (int i=0; ilistWidget->addItem(item); + } } diff --git a/src/app/tablewindow.h b/src/app/tablewindow.h index effc1fb48..071561ba8 100644 --- a/src/app/tablewindow.h +++ b/src/app/tablewindow.h @@ -33,12 +33,15 @@ #include #include "../../libs/vlayout/vlayoutdetail.h" +#include "../../libs/vlayout/vbank.h" namespace Ui { class TableWindow; } +class QGraphicsScene; + /** * @brief TableWindow class layout window. */ @@ -46,87 +49,37 @@ class TableWindow : public QMainWindow { Q_OBJECT public: - /** @brief numberDetal show count details, what need placed. */ - QLabel* numberDetal; - - /** @brief colission show if exist colissions. */ - QLabel* colission; - explicit TableWindow(QWidget *parent = nullptr); ~TableWindow(); -public slots: +public slots: void ModelChosen(QVector listDetails, const QString &fileName, const QString &description); - - void StopTable(); - - void saveScene(); - - void GetNextDetail(); - - void itemChect(bool flag); - - void itemOut(int number, bool flag); - - void itemColliding(QList list, int number); - - void AddLength(); - - void RemoveLength(); void Layout(); + void StopTable(); + void saveScene(); + void ShowPaper(int index); + signals: - /** - * @brief closed emit if window is closing. - */ + /** @brief closed emit if window is closing. */ void closed(); - /** - * @brief LengthChanged emit if changing length of paper sheet. - */ - void LengthChanged(); + protected: - void closeEvent(QCloseEvent *event); - void moveToCenter(); - void showEvent ( QShowEvent * event ); - void keyPressEvent ( QKeyEvent * event ); private: Q_DISABLE_COPY(TableWindow) /** @brief ui keeps information about user interface */ Ui::TableWindow* ui; /** @brief listDetails list of details. */ - QVector listDetails; + QVector listDetails; - /** @brief outItems true if we have details out paper sheet. */ - bool outItems; - - /** @brief collidingItems true if we have colission details. */ - bool collidingItems; - - /** @brief currentScene pointer to scene. */ - QGraphicsScene* tableScene; - - /** @brief paper paper sheet. */ - QGraphicsRectItem* paper; - - /** @brief shadowPaper paper sheet shadow. */ - QGraphicsRectItem* shadowPaper; - - /** @brief listOutItems list state out each detail. */ - QBitArray* listOutItems; - - /** @brief listCollidingItems list colissed details. */ - QList listCollidingItems; - - /** @brief indexDetail index next detail in list what will be shown. */ - qint32 indexDetail; - - /** @brief sceneRect minimal size of a paper. */ - QRectF sceneRect; + QList papers; + QList shadows; + QList scenes; /** @brief fileName keep name of pattern file. */ QString fileName; @@ -134,9 +87,14 @@ private: /** @brief description pattern description */ QString description; - void checkNext(); - void AddPaper(); - void AddDetail(); + int paperHeight; + int paperWidth; + unsigned int shift; + qreal layoutWidth; + Cases group; + + QGraphicsScene* tempScene; + void SvgFile(const QString &name)const; void PngFile(const QString &name)const; void PdfFile(const QString &name)const; @@ -144,6 +102,11 @@ private: void PsFile(const QString &name)const; void PdfToPs(const QStringList ¶ms)const; void ObjFile(const QString &name)const; + + void ClearLayout(); + void CreateShadows(); + void CreateScenes(); + void PrepareSceneList(); }; #endif // TABLEWINDOW_H diff --git a/src/app/tablewindow.ui b/src/app/tablewindow.ui index 327eebf44..03c642d21 100644 --- a/src/app/tablewindow.ui +++ b/src/app/tablewindow.ui @@ -22,21 +22,6 @@ - - QLayout::SetMinAndMaxSize - - - 9 - - - 9 - - - 9 - - - 9 - @@ -73,6 +58,46 @@ + + + QDockWidget::DockWidgetMovable + + + Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea + + + Pages + + + 1 + + + + + + + + 200 + 200 + + + + QListView::Static + + + QListView::TopToBottom + + + true + + + QListView::IconMode + + + + + + false diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index f9f20712a..45c161c98 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -135,6 +135,7 @@ void VLayoutGenerator::Generate() emit Error(state); return; } + emit Finished(); } //---------------------------------------------------------------------------------------------------------------------