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 PaperSize 50000
#define toPixel(mm) ((mm / 25.4) * PrintDPI) #define toPixel(mm) ((mm / 25.4) * PrintDPI)
#define toMM(pix) ((pix / PrintDPI) * 25.4) #define toMM(pix) ((pix / PrintDPI) * 25.4)
#define widthMainLine toPixel(1.2) #define widthMainLine 1.2
#define widthHairLine widthMainLine/3 #define widthHairLine widthMainLine/3
namespace Scene namespace Scene

View file

@ -72,7 +72,7 @@ void TableWindow::AddPaper()
shadowPaper->setBrush(QBrush(Qt::black)); shadowPaper->setBrush(QBrush(Qt::black));
currentScene->addItem(shadowPaper); currentScene->addItem(shadowPaper);
paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2)); 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)); paper->setBrush(QBrush(Qt::white));
currentScene->addItem(paper); currentScene->addItem(paper);
qDebug()<<paper->rect().size().toSize(); qDebug()<<paper->rect().size().toSize();
@ -88,13 +88,14 @@ void TableWindow::AddDetail()
QObject::connect(Detail, SIGNAL(itemColliding(QList<QGraphicsItem*>, int)), this, QObject::connect(Detail, SIGNAL(itemColliding(QList<QGraphicsItem*>, int)), this,
SLOT(itemColliding(QList<QGraphicsItem*>, int))); SLOT(itemColliding(QList<QGraphicsItem*>, int)));
QObject::connect(this, SIGNAL(LengthChanged()), Detail, SLOT(LengthChanged())); 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->setBrush(QBrush(Qt::white));
Detail->setPos(paper->boundingRect().center()); Detail->setPos(paper->boundingRect().center());
Detail->setFlag(QGraphicsItem::ItemIsMovable, true); Detail->setFlag(QGraphicsItem::ItemIsMovable, true);
Detail->setFlag(QGraphicsItem::ItemIsSelectable, true); Detail->setFlag(QGraphicsItem::ItemIsSelectable, true);
Detail->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); Detail->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
Detail->setParentItem(paper); Detail->setPaper(paper);
currentScene->addItem(Detail);
Detail->setSelected(true); Detail->setSelected(true);
indexDetail++; indexDetail++;
if (indexDetail==listDetails.count()) if (indexDetail==listDetails.count())
@ -160,27 +161,26 @@ void TableWindow::saveScene()
brush->setColor( QColor( Qt::white ) ); brush->setColor( QColor( Qt::white ) );
currentScene->setBackgroundBrush( *brush ); currentScene->setBackgroundBrush( *brush );
currentScene->clearSelection(); // Selections would also render to the file currentScene->clearSelection(); // Selections would also render to the file
shadowPaper->setBrush(QBrush(Qt::white)); shadowPaper->setVisible(false);
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); QFileInfo fi(name);
if (fi.suffix() == "svg") if (fi.suffix() == "svg")
{ {
paper->setVisible(false);
SvgFile(name); SvgFile(name);
paper->setVisible(true);
} }
else if (fi.suffix() == "png") else if (fi.suffix() == "png")
{ {
paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));
PngFile(name); PngFile(name);
paper->setPen(QPen(Qt::black, widthMainLine));
} }
brush->setColor( QColor( Qt::gray ) ); brush->setColor( QColor( Qt::gray ) );
brush->setStyle( Qt::SolidPattern ); brush->setStyle( Qt::SolidPattern );
currentScene->setBackgroundBrush( *brush ); currentScene->setBackgroundBrush( *brush );
paper->setPen(QPen(Qt::black, widthMainLine)); shadowPaper->setVisible(true);
shadowPaper->setBrush(QBrush(Qt::black)); delete brush;
} }
void TableWindow::itemChect(bool flag) void TableWindow::itemChect(bool flag)
@ -254,7 +254,7 @@ void TableWindow::itemColliding(QList<QGraphicsItem *> list, int number)
} }
else else
{ {
bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); bitem->setPen(QPen(Qt::black, widthMainLine));
} }
listCollidingItems.removeAt(i); listCollidingItems.removeAt(i);
} }
@ -269,7 +269,7 @@ void TableWindow::itemColliding(QList<QGraphicsItem *> list, int number)
} }
else else
{ {
bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); bitem->setPen(QPen(Qt::black, widthMainLine));
} }
listCollidingItems.clear(); listCollidingItems.clear();
collidingItems = true; collidingItems = true;
@ -372,7 +372,6 @@ void TableWindow::SvgFile(const QString &name) const
QSvgGenerator generator; QSvgGenerator generator;
generator.setFileName(name); generator.setFileName(name);
generator.setSize(paper->rect().size().toSize()); generator.setSize(paper->rect().size().toSize());
//generator.setViewBox(QRect(0, 0, 200, 200));
generator.setTitle(tr("SVG Generator Example Drawing")); generator.setTitle(tr("SVG Generator Example Drawing"));
generator.setDescription(tr("An SVG drawing created by the SVG Generator " generator.setDescription(tr("An SVG drawing created by the SVG Generator "
"Example provided with Qt.")); "Example provided with Qt."));
@ -382,7 +381,7 @@ void TableWindow::SvgFile(const QString &name) const
painter.begin(&generator); painter.begin(&generator);
painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true); 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 ) ); painter.setBrush ( QBrush ( Qt::NoBrush ) );
currentScene->render(&painter); currentScene->render(&painter);
painter.end(); painter.end();
@ -399,7 +398,7 @@ void TableWindow::PngFile(const QString &name) const
QPainter painter(&image); QPainter painter(&image);
painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true); 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 ) ); painter.setBrush ( QBrush ( Qt::NoBrush ) );
currentScene->render(&painter); currentScene->render(&painter);
image.save(name); image.save(name);

View file

@ -20,15 +20,24 @@
****************************************************************************/ ****************************************************************************/
#include "vitem.h" #include "vitem.h"
#include <QGraphicsScene>
VItem::VItem (const QPainterPath & path, int numInList, QGraphicsItem * parent ) VItem::VItem (const QPainterPath & path, int numInList, QGraphicsItem * parent )
:QGraphicsPathItem ( path, parent ), numInOutList(numInList) :QGraphicsPathItem ( path, parent ), numInOutList(numInList), paper(0)
{ {
} }
void VItem::checkItemChange() 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(); QRectF myrect = sceneBoundingRect();
if ( rect.contains( myrect )==true ) if ( rect.contains( myrect )==true )
{ {

View file

@ -36,14 +36,15 @@ public:
* @brief VItem конструктор за замовчуванням * @brief VItem конструктор за замовчуванням
*Конструктор генерує пусту деталь з номером в списку, що дорівнює 0. *Конструктор генерує пусту деталь з номером в списку, що дорівнює 0.
*/ */
VItem ():numInOutList(0){} VItem ():numInOutList(0), paper(0){}
/** /**
* @brief VItem конструктор * @brief VItem конструктор
* @param numInList номер в списку деталей, що передається у вікно де * @param numInList номер в списку деталей, що передається у вікно де
*укладаються деталі. *укладаються деталі.
* @param parent батьківський об'єкт на сцені для даного. За замовчуванням немає. * @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 конструктор * @brief VItem конструктор
* @param path зображення що буде показуватися на сцені - обєкт класу QPainterPath. * @param path зображення що буде показуватися на сцені - обєкт класу QPainterPath.
@ -57,6 +58,8 @@ public:
* @param angle кут в градусах на який повертається деталь. * @param angle кут в градусах на який повертається деталь.
*/ */
void Rotate ( qreal angle ); void Rotate ( qreal angle );
QGraphicsRectItem *getPaper() const {return paper;}
void setPaper(QGraphicsRectItem *value) {paper = value;}
public slots: public slots:
/** /**
* @brief LengthChanged слот який обробляє сигнал зміни довжини листа. * @brief LengthChanged слот який обробляє сигнал зміни довжини листа.
@ -82,11 +85,13 @@ protected:
*/ */
void checkItemChange (); void checkItemChange ();
private: private:
Q_DISABLE_COPY(VItem)
/** /**
* @brief numInOutList для зберігання інформації про колізії від кожної деталі необхідно знати її * @brief numInOutList для зберігання інформації про колізії від кожної деталі необхідно знати її
*номер. *номер.
*/ */
qint32 numInOutList; qint32 numInOutList;
QGraphicsRectItem* paper;
signals: signals:
/** /**
* @brief itemOut сигнал виходу за межі листа. Посилається у будь-якому випадку. * @brief itemOut сигнал виходу за межі листа. Посилається у будь-якому випадку.