Rotation bugs fixed

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-07-01 01:45:16 +02:00
parent 9a64ddf6a3
commit 6effc2b5cd
13 changed files with 147 additions and 18 deletions

View File

@ -678,11 +678,10 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
detail.GetPatternPieceData().SetLabelWidth(dLW);
qreal dLH = element.attribute(VToolDetail::AttrHeight, "0").toDouble();
detail.GetPatternPieceData().SetLabelHeight(dLH);
qDebug() << "HEIGHT" <<
detail.GetPatternPieceData().GetPos() <<
detail.GetPatternPieceData().GetLabelHeight();
int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt();
detail.GetPatternPieceData().SetFontSize(iFS);
qreal dRot = element.attribute(VToolDetail::AttrRotation, "0").toDouble();
detail.GetPatternPieceData().SetRotation(dRot);
QDomNodeList nodeListMCP = element.childNodes();
for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP)

View File

@ -26,6 +26,7 @@
<xs:element name="labelPosition" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="labelSize" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="fontSize" type="xs:unsignedInt" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="rotation" type="xs:double" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="gradation" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
@ -360,6 +361,7 @@
<xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="width" type="xs:double"></xs:attribute>
<xs:attribute name="height" type="xs:double"></xs:attribute>
<xs:attribute name="rotation" type="xs:double"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="node" maxOccurs="unbounded">

View File

@ -68,8 +68,9 @@ const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer");
const QString VAbstractPattern::TagCompanyName = QStringLiteral("company");
const QString VAbstractPattern::TagCreationDate = QStringLiteral("created");
const QString VAbstractPattern::TagLabelPos = QStringLiteral("labelPosition");
const QString VAbstractPattern::TagLabelSize = QStringLiteral("labelSize");
const QString VAbstractPattern::TagLabelSize = QStringLiteral("labelSize");
const QString VAbstractPattern::TagLabelFont = QStringLiteral("fontSize");
const QString VAbstractPattern::TagLabelRot = QStringLiteral("rotation");
const QString VAbstractPattern::AttrName = QStringLiteral("name");
const QString VAbstractPattern::AttrVisible = QStringLiteral("visible");
@ -1157,6 +1158,27 @@ void VAbstractPattern::SetFontSize(int iFS)
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VAbstractPattern::GetRotation() const
{
bool bOK;
qreal dRot = UniqueTagText(TagLabelRot).toDouble(&bOK);
if (bOK == false)
{
dRot = 0;
}
return dRot;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetRotation(qreal dRot)
{
CheckTagExists(TagLabelRot);
setTagText(TagLabelRot, QString::number(dRot, 'f', 3));
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetImage() const
{
@ -1283,7 +1305,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes
<< TagGradation << TagPatternName << TagPatternNum << TagCompanyName
<< TagCustomerName << TagCreationDate << TagLabelPos << TagLabelSize
<< TagLabelFont;
<< TagLabelFont << TagLabelRot;
switch (tags.indexOf(tag))
{
case 0: //TagUnit
@ -1365,6 +1387,12 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
break;
}
case 14:
{
element = createElement(TagLabelRot);
break;
}
default:
{
return QDomElement();

View File

@ -123,6 +123,8 @@ public:
void SetLabelSize(QSizeF sz);
int GetFontSize() const;
void SetFontSize(int iFS);
qreal GetRotation() const;
void SetRotation(qreal dRot);
QString GetImage() const;
QString GetImageExtension() const;
@ -182,6 +184,7 @@ public:
static const QString TagLabelPos;
static const QString TagLabelSize;
static const QString TagLabelFont;
static const QString TagLabelRot;
static const QString AttrName;
static const QString AttrVisible;

View File

@ -35,6 +35,7 @@ VPatternPieceData::VPatternPieceData() :
m_iFontSize = MIN_FONT_SIZE;
// 0 means unknown width
m_dLabelWidth = 0;
m_dRotation = 0;
}
//---------------------------------------------------------------------------------------------------------------------
@ -169,4 +170,16 @@ void VPatternPieceData::SetFontSize(int iSize)
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPatternPieceData::GetRotation() const
{
return m_dRotation;
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternPieceData::SetRotation(qreal dRot)
{
m_dRotation = dRot;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -93,6 +93,8 @@ public:
void SetLabelHeight(qreal dLabelH);
int GetFontSize() const;
void SetFontSize(int iSize);
qreal GetRotation() const;
void SetRotation(qreal dRot);
private:
/** @brief Pattern piece name
@ -116,6 +118,9 @@ private:
/** @brief Label font size
*/
int m_iFontSize;
/** @brief Label rotation
*/
qreal m_dRotation;
};
#endif // VPATTERNPIECEDATA_H

View File

@ -36,6 +36,8 @@
#define RESIZE_SQUARE 30
#define ROTATE_CIRCLE 20
#define ROTATE_RECT 60
#define ROTATE_ARC 50
#define MIN_W 120
#define MIN_H 60
#define MIN_FONT_SIZE 12
@ -71,6 +73,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
{
Q_UNUSED(widget);
painter->fillRect(option->rect, QColor(251, 251, 175));
painter->setRenderHints(QPainter::Antialiasing);
// draw text lines
int iY = 0;
@ -117,6 +120,16 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
ROTATE_CIRCLE,
ROTATE_CIRCLE
);
painter->setPen(QPen(Qt::black, 3));
painter->setBrush(Qt::NoBrush);
int iTop = ROTATE_RECT - ROTATE_ARC;
int iLeft = ROTATE_RECT - ROTATE_ARC;
int iRight = m_rectBoundingBox.width() - ROTATE_RECT;
int iBottom = m_rectBoundingBox.height() - ROTATE_RECT;
painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16);
painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16);
painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16);
painter->drawArc(iRight, iBottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16);
}
}
}
@ -124,7 +137,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::Reset()
{
return;
qDebug() << "RESET" << m_eMode << m_liLines.count();
m_eMode = mNormal;
m_bReleased = false;
Update();
@ -163,6 +176,7 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH)
m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE));
m_rectResize.setWidth(RESIZE_SQUARE);
m_rectResize.setHeight(RESIZE_SQUARE);
setTransformOriginPoint(m_rectBoundingBox.center());
}
//---------------------------------------------------------------------------------------------------------------------
@ -172,6 +186,12 @@ void VTextGraphicsItem::Update()
UpdateBox();
}
//---------------------------------------------------------------------------------------------------------------------
int VTextGraphicsItem::GetFontSize() const
{
return m_font.pixelSize();
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VTextGraphicsItem::boundingRect() const
{
@ -183,7 +203,6 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
{
if (pME->button() == Qt::LeftButton)
{
qDebug() << "PRESS" << m_eMode;
m_ptStartPos = pos();
m_ptStart = pME->scenePos();
m_szStart = m_rectBoundingBox.size();
@ -202,7 +221,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
}
setZValue(3);
UpdateBox();
qDebug() << "PRESS finished" << m_eMode;
qDebug() << "PRESS" << m_eMode << m_liLines.count();
}
}
@ -212,7 +231,6 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
QPointF ptDiff = pME->scenePos() - m_ptStart;
if (m_eMode == mMove)
{
//moveBy(ptDiff.x(), ptDiff.y());
setPos(m_ptStartPos + ptDiff);
UpdateBox();
}
@ -231,6 +249,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
}
double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI;
setRotation(m_dRotation + dAng);
emit SignalRotated(rotation());
Update();
}
}
@ -243,7 +262,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y());
bool bShort = (dDist < 2);
qDebug() << "RELEASE" << m_eMode << dDist;
qDebug() << "RELEASE" << m_eMode << dDist << m_liLines.count();
if (m_eMode == mMove || m_eMode == mResize)
{ // when released in mMove or mResize mode
@ -280,6 +299,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
}
}
m_bReleased = true;
qDebug() << "RELEASE finished" << m_eMode << m_liLines.count();
}
}

View File

@ -63,6 +63,7 @@ public:
void Reset();
int GetFontSize() const;
QRectF boundingRect() const;
void AddLine(const TextLine& tl);
void Clear();

View File

@ -57,6 +57,7 @@ const QString VToolDetail::AttrHeight = QStringLiteral("height");
const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType");
const QString VToolDetail::AttrReverse = QStringLiteral("reverse");
const QString VToolDetail::AttrFont = QStringLiteral("fontSize");
const QString VToolDetail::AttrRotation = QStringLiteral("rotation");
const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour");
const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling");
@ -118,7 +119,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove);
connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChildren);
connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolDetail::ResetChildren);
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
{
AddToFile();
@ -131,10 +132,12 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail);
connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail);
connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail);
connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern);
connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern);
connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern);
connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo);
@ -356,6 +359,7 @@ void VToolDetail::AddToFile()
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
doc->SetAttribute(domData, AttrRotation, data.GetRotation());
for (int i = 0; i < data.GetMCPCount(); ++i)
{
@ -404,6 +408,7 @@ void VToolDetail::RefreshDataInFile()
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
doc->SetAttribute(domData, AttrRotation, data.GetRotation());
for (int i = 0; i < data.GetMCPCount(); ++i)
{
@ -650,11 +655,10 @@ void VToolDetail::UpdateLabel()
{
const VDetail detail = VAbstractTool::data.GetDetail(id);
qDebug() << "Update label";
const VPatternPieceData& data = detail.GetPatternPieceData();
if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0)
{
dataLabel->Reset();
//dataLabel->Reset();
QString qsText = "Cut %1 of %2%3";
QStringList qslPlace;
@ -688,6 +692,7 @@ void VToolDetail::UpdateLabel()
}
dataLabel->setPos(data.GetPos());
dataLabel->setRotation(data.GetRotation());
dataLabel->Update();
dataLabel->show();
}
@ -703,7 +708,7 @@ void VToolDetail::UpdateLabel()
*/
void VToolDetail::UpdatePatternInfo()
{
patternInfo->Reset();
//patternInfo->Reset();
QFont fnt = qApp->font();
int iFS = doc->GetFontSize();
if (iFS < MIN_FONT_SIZE)
@ -748,6 +753,7 @@ void VToolDetail::UpdatePatternInfo()
patternInfo->AddLine(tl);
patternInfo->setPos(doc->GetLabelPosition());
patternInfo->setRotation(doc->GetRotation());
patternInfo->Update();
}
@ -761,6 +767,11 @@ void VToolDetail::SaveMoveDetail(QPointF ptPos)
VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet;
newDet.GetPatternPieceData().SetPos(ptPos);
newDet.GetPatternPieceData().SetLabelWidth(dataLabel->boundingRect().width());
newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height());
newDet.GetPatternPieceData().SetFontSize(dataLabel->GetFontSize());
newDet.GetPatternPieceData().SetRotation(dataLabel->rotation());
SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
moveCommand->setText(tr("move pattern piece label"));
connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
@ -778,12 +789,35 @@ void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize)
newDet.GetPatternPieceData().SetLabelWidth(dLabelW);
newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height());
newDet.GetPatternPieceData().SetFontSize(iFontSize);
newDet.GetPatternPieceData().SetRotation(dataLabel->rotation());
SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
resizeCommand->setText(tr("resize pattern piece label"));
connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(resizeCommand);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveRotationDetail saves the rotation detail label operation to the undo stack
*/
void VToolDetail::SaveRotationDetail(qreal dRot)
{
qDebug() << "SAVEROTATION" << dRot;
VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet;
newDet.GetPatternPieceData().SetPos(dataLabel->pos());
newDet.GetPatternPieceData().SetLabelWidth(dataLabel->boundingRect().width());
newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height());
newDet.GetPatternPieceData().SetFontSize(dataLabel->GetFontSize());
newDet.GetPatternPieceData().SetRotation(dRot);
SaveDetailOptions* rotateCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
rotateCommand->setText(tr("rotate pattern piece label"));
connect(rotateCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(rotateCommand);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveMovePattern saves the pattern label position
@ -804,6 +838,13 @@ void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize)
doc->SetFontSize(iFontSize);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDetail::SaveRotationPattern(qreal dRot)
{
doc->SetRotation(dRot);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief AddNode add node to the file.
@ -953,10 +994,17 @@ void VToolDetail::AllowSelecting(bool enabled)
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDetail::ResetChildren()
void VToolDetail::ResetChildren(QGraphicsItem *pItem)
{
dataLabel->Reset();
patternInfo->Reset();
VTextGraphicsItem* pVGI = dynamic_cast<VTextGraphicsItem*>(pItem);
if (pVGI != dataLabel)
{
dataLabel->Reset();
}
if (pVGI != patternInfo)
{
patternInfo->Reset();
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -73,6 +73,7 @@ public:
static const QString AttrNodeType;
static const QString AttrReverse;
static const QString AttrFont;
static const QString AttrRotation;
static const QString NodeTypeContour;
static const QString NodeTypeModeling;
static const QString NodeArc;
@ -92,7 +93,7 @@ public slots:
void EnableToolMove(bool move);
virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE;
virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE;
virtual void ResetChildren();
virtual void ResetChildren(QGraphicsItem* pItem);
virtual void UpdateAll();
protected:
virtual void AddToFile () Q_DECL_OVERRIDE;
@ -112,8 +113,10 @@ protected slots:
virtual void UpdatePatternInfo();
virtual void SaveMoveDetail(QPointF ptPos);
virtual void SaveResizeDetail(qreal dLabelW, int iFontSize);
virtual void SaveRotationDetail(qreal dRot);
virtual void SaveMovePattern(QPointF ptPos);
virtual void SaveResizePattern(qreal dLabelW, int iFontSize);
virtual void SaveRotationPattern(qreal dRot);
private:
Q_DISABLE_COPY(VToolDetail)

View File

@ -142,6 +142,8 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet
doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth());
doc->SetAttribute(domData, VToolDetail::AttrHeight, data.GetLabelHeight());
doc->SetAttribute(domData, VToolDetail::AttrFont, data.GetFontSize());
doc->SetAttribute(domData, VToolDetail::AttrRotation, data.GetRotation());
for (int i = 0; i < data.GetMCPCount(); ++i)
{
MaterialCutPlacement mcp = data.GetMCP(i);

View File

@ -80,6 +80,10 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
QGraphicsScene::mousePressEvent(event);
QTransform t;
QGraphicsItem* pItem = itemAt(event->scenePos(), t);
emit ItemClicked(pItem);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -93,6 +93,7 @@ signals:
void MouseLeftPressed();
void MouseLeftReleased();
void ItemClicked(QGraphicsItem* pItem);
/**
* @brief ChoosedObject send option choosed object.