From 63f9f621983ff324b3159fc9bd8f3d8103294cfb Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 13 Nov 2013 16:07:40 +0200 Subject: [PATCH] Wrong define of widthMainLine. In SVG file don't show paper only details. In png file paper stayed. --HG-- branch : develop --- options.h | 2 +- tablewindow.cpp | 31 +++++++++++++++---------------- widgets/vitem.cpp | 13 +++++++++++-- widgets/vitem.h | 9 +++++++-- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/options.h b/options.h index bf2fbad48..8891d0d72 100644 --- a/options.h +++ b/options.h @@ -28,7 +28,7 @@ #define PaperSize 50000 #define toPixel(mm) ((mm / 25.4) * PrintDPI) #define toMM(pix) ((pix / PrintDPI) * 25.4) -#define widthMainLine toPixel(1.2) +#define widthMainLine 1.2 #define widthHairLine widthMainLine/3 namespace Scene diff --git a/tablewindow.cpp b/tablewindow.cpp index 655f6593d..69b22e5eb 100644 --- a/tablewindow.cpp +++ b/tablewindow.cpp @@ -72,7 +72,7 @@ void TableWindow::AddPaper() shadowPaper->setBrush(QBrush(Qt::black)); currentScene->addItem(shadowPaper); paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2)); - paper->setPen(QPen(Qt::black, toPixel(widthMainLine))); + paper->setPen(QPen(Qt::black, widthMainLine)); paper->setBrush(QBrush(Qt::white)); currentScene->addItem(paper); qDebug()<rect().size().toSize(); @@ -88,13 +88,14 @@ void TableWindow::AddDetail() QObject::connect(Detail, SIGNAL(itemColliding(QList, int)), this, SLOT(itemColliding(QList, int))); QObject::connect(this, SIGNAL(LengthChanged()), Detail, SLOT(LengthChanged())); - Detail->setPen(QPen(Qt::black, toPixel(widthMainLine))); + 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->setParentItem(paper); + Detail->setPaper(paper); + currentScene->addItem(Detail); Detail->setSelected(true); indexDetail++; if (indexDetail==listDetails.count()) @@ -160,27 +161,26 @@ void TableWindow::saveScene() brush->setColor( QColor( Qt::white ) ); currentScene->setBackgroundBrush( *brush ); currentScene->clearSelection(); // Selections would also render to the file - 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()); - + shadowPaper->setVisible(false); QFileInfo fi(name); if (fi.suffix() == "svg") { + paper->setVisible(false); SvgFile(name); + paper->setVisible(true); } else if (fi.suffix() == "png") { + paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); PngFile(name); + paper->setPen(QPen(Qt::black, widthMainLine)); } brush->setColor( QColor( Qt::gray ) ); brush->setStyle( Qt::SolidPattern ); currentScene->setBackgroundBrush( *brush ); - paper->setPen(QPen(Qt::black, widthMainLine)); - shadowPaper->setBrush(QBrush(Qt::black)); + shadowPaper->setVisible(true); + delete brush; } void TableWindow::itemChect(bool flag) @@ -254,7 +254,7 @@ void TableWindow::itemColliding(QList list, int number) } else { - bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + bitem->setPen(QPen(Qt::black, widthMainLine)); } listCollidingItems.removeAt(i); } @@ -269,7 +269,7 @@ void TableWindow::itemColliding(QList list, int number) } else { - bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + bitem->setPen(QPen(Qt::black, widthMainLine)); } listCollidingItems.clear(); collidingItems = true; @@ -372,7 +372,6 @@ void TableWindow::SvgFile(const QString &name) const 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.")); @@ -382,7 +381,7 @@ void TableWindow::SvgFile(const QString &name) const 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.setPen(QPen(Qt::black, 1.2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); currentScene->render(&painter); painter.end(); @@ -399,7 +398,7 @@ void TableWindow::PngFile(const QString &name) const 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.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); currentScene->render(&painter); image.save(name); diff --git a/widgets/vitem.cpp b/widgets/vitem.cpp index 963a693da..bfc184409 100644 --- a/widgets/vitem.cpp +++ b/widgets/vitem.cpp @@ -20,15 +20,24 @@ ****************************************************************************/ #include "vitem.h" +#include VItem::VItem (const QPainterPath & path, int numInList, QGraphicsItem * parent ) - :QGraphicsPathItem ( path, parent ), numInOutList(numInList) + :QGraphicsPathItem ( path, parent ), numInOutList(numInList), paper(0) { } void VItem::checkItemChange() { - QRectF rect = parentItem()->sceneBoundingRect(); + QRectF rect; + if(paper == 0){ + qDebug()<<"Don't set paper for detail!!!!"; + rect = this->scene()->sceneRect(); + } + else + { + rect = paper->sceneBoundingRect(); + } QRectF myrect = sceneBoundingRect(); if ( rect.contains( myrect )==true ) { diff --git a/widgets/vitem.h b/widgets/vitem.h index cff2136c8..868848ba7 100644 --- a/widgets/vitem.h +++ b/widgets/vitem.h @@ -36,14 +36,15 @@ public: * @brief VItem конструктор за замовчуванням *Конструктор генерує пусту деталь з номером в списку, що дорівнює 0. */ - VItem ():numInOutList(0){} + VItem ():numInOutList(0), paper(0){} /** * @brief VItem конструктор * @param numInList номер в списку деталей, що передається у вікно де *укладаються деталі. * @param parent батьківський об'єкт на сцені для даного. За замовчуванням немає. */ - VItem (int numInList, QGraphicsItem * parent = 0):QGraphicsPathItem (parent), numInOutList(numInList){} + VItem (int numInList, QGraphicsItem * parent = 0):QGraphicsPathItem (parent), numInOutList(numInList), + paper(0){} /** * @brief VItem конструктор * @param path зображення що буде показуватися на сцені - об’єкт класу QPainterPath. @@ -57,6 +58,8 @@ public: * @param angle кут в градусах на який повертається деталь. */ void Rotate ( qreal angle ); + QGraphicsRectItem *getPaper() const {return paper;} + void setPaper(QGraphicsRectItem *value) {paper = value;} public slots: /** * @brief LengthChanged слот який обробляє сигнал зміни довжини листа. @@ -82,11 +85,13 @@ protected: */ void checkItemChange (); private: + Q_DISABLE_COPY(VItem) /** * @brief numInOutList для зберігання інформації про колізії від кожної деталі необхідно знати її *номер. */ qint32 numInOutList; + QGraphicsRectItem* paper; signals: /** * @brief itemOut сигнал виходу за межі листа. Посилається у будь-якому випадку.