Wrong define of widthMainLine. In SVG file don't show paper only details. In

png file paper stayed.

--HG--
branch : develop
This commit is contained in:
dismine 2013-11-13 16:07:40 +02:00
parent fab9fa4bfb
commit 63f9f62198
4 changed files with 34 additions and 21 deletions

View File

@ -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

View File

@ -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()<<paper->rect().size().toSize();
@ -88,13 +88,14 @@ void TableWindow::AddDetail()
QObject::connect(Detail, SIGNAL(itemColliding(QList<QGraphicsItem*>, int)), this,
SLOT(itemColliding(QList<QGraphicsItem*>, 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<QGraphicsItem *> 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<QGraphicsItem *> 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);

View File

@ -20,15 +20,24 @@
****************************************************************************/
#include "vitem.h"
#include <QGraphicsScene>
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 )
{

View File

@ -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 сигнал виходу за межі листа. Посилається у будь-якому випадку.