Fixed some code style errors and checking label position at resizing

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-07-14 02:59:42 +02:00
parent 634d8773de
commit ea9cdd46b2
7 changed files with 28 additions and 18 deletions

View File

@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<pattern> <pattern>
<!--Valentina pattern format.--> <!--Valentina pattern format.-->
<version>0.3.2</version> <version>0.2.4</version>
<unit>cm</unit> <unit>cm</unit>
<author/> <author/>
<description/> <description/>

View File

@ -90,9 +90,13 @@ int VPatternInfoGeometry::GetFontSize() const
void VPatternInfoGeometry::SetFontSize(int iSize) void VPatternInfoGeometry::SetFontSize(int iSize)
{ {
if (iSize >= MIN_FONT_SIZE) if (iSize >= MIN_FONT_SIZE)
{
m_iFontSize = iSize; m_iFontSize = iSize;
}
else else
{
m_iFontSize = MIN_FONT_SIZE; m_iFontSize = MIN_FONT_SIZE;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -152,9 +152,13 @@ int VPatternPieceData::GetFontSize() const
void VPatternPieceData::SetFontSize(int iSize) void VPatternPieceData::SetFontSize(int iSize)
{ {
if (iSize >= MIN_FONT_SIZE) if (iSize >= MIN_FONT_SIZE)
{
m_iFontSize = iSize; m_iFontSize = iSize;
}
else else
{
m_iFontSize = MIN_FONT_SIZE; m_iFontSize = MIN_FONT_SIZE;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -175,7 +175,9 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH)
{ {
// don't allow resize under specific size // don't allow resize under specific size
if (fW < MIN_W || fH < m_iMinH) if (fW < MIN_W || fH < m_iMinH)
{
return; return;
}
m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setTopLeft(QPointF(0, 0));
m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setWidth(fW);
@ -293,17 +295,15 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
{ {
QPointF pt = m_ptStartPos; QPointF pt = m_ptStartPos;
rectBB.setTopLeft(pt); rectBB.setTopLeft(pt);
QSize sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y());
rectBB.setSize(sz); rectBB.setSize(sz);
if (IsContained(rectBB, rotation(), dX, dY) == false) { if (IsContained(rectBB, rotation(), dX, dY) == true)
sz.setWidth(sz.width() + dX); {
sz.setHeight(sz.height() + dY);
}
SetSize(sz.width(), sz.height()); SetSize(sz.width(), sz.height());
Update(); Update();
emit SignalShrink(); emit SignalShrink();
} }
}
else if (m_eMode == mRotate) else if (m_eMode == mRotate)
{ {
if (fabs(m_dAngle) < 0.01) if (fabs(m_dAngle) < 0.01)
@ -429,7 +429,7 @@ bool VTextGraphicsItem::IsBigEnough(qreal fW, qreal fH, int iFontSize)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm)
{ {
QRegExp reg("\\s+"); QRegularExpression reg("\\s+");
QStringList qslWords = qs.split(reg); QStringList qslWords = qs.split(reg);
QStringList qslLines; QStringList qslLines;
QString qsCurrent; QString qsCurrent;
@ -437,7 +437,7 @@ QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QF
{ {
if (qsCurrent.length() > 0) if (qsCurrent.length() > 0)
{ {
qsCurrent += " "; qsCurrent += QLatin1Literal(" ");
} }
if (fm.width(qsCurrent + qslWords[i]) > fW) if (fm.width(qsCurrent + qslWords[i]) > fW)
{ {
@ -460,9 +460,13 @@ double VTextGraphicsItem::GetAngle(QPointF pt) const
double dY = pt.y() - m_ptRotCenter.y(); double dY = pt.y() - m_ptRotCenter.y();
if (fabs(dX) < 1 && fabs(dY) < 1) if (fabs(dX) < 1 && fabs(dY) < 1)
{
return 0; return 0;
}
else else
{
return atan2(dY, dX); return atan2(dY, dX);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -85,7 +85,7 @@ protected:
double GetAngle(QPointF pt) const; double GetAngle(QPointF pt) const;
signals: signals:
void SignalMoved(QPointF ptPos); void SignalMoved(const QPointF& ptPos);
void SignalResized(qreal iTW, int iFontSize); void SignalResized(qreal iTW, int iFontSize);
void SignalRotated(qreal dAng); void SignalRotated(qreal dAng);
void SignalShrink(); void SignalShrink();

View File

@ -134,12 +134,10 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail); connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail);
connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail);
connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail); connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail);
//connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern); connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern);
connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern);
connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern);
//connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo);
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel);
@ -820,7 +818,7 @@ void VToolDetail::UpdatePatternInfo()
/** /**
* @brief SaveMoveDetail saves the move detail operation to the undo stack * @brief SaveMoveDetail saves the move detail operation to the undo stack
*/ */
void VToolDetail::SaveMoveDetail(QPointF ptPos) void VToolDetail::SaveMoveDetail(const QPointF& ptPos)
{ {
VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet; VDetail newDet = oldDet;
@ -879,7 +877,7 @@ void VToolDetail::SaveRotationDetail(qreal dRot)
/** /**
* @brief SaveMovePattern saves the pattern label position * @brief SaveMovePattern saves the pattern label position
*/ */
void VToolDetail::SaveMovePattern(QPointF ptPos) void VToolDetail::SaveMovePattern(const QPointF &ptPos)
{ {
VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet; VDetail newDet = oldDet;

View File

@ -111,10 +111,10 @@ protected:
protected slots: protected slots:
virtual void UpdateLabel(); virtual void UpdateLabel();
virtual void UpdatePatternInfo(); virtual void UpdatePatternInfo();
virtual void SaveMoveDetail(QPointF ptPos); virtual void SaveMoveDetail(const QPointF &ptPos);
virtual void SaveResizeDetail(qreal dLabelW, int iFontSize); virtual void SaveResizeDetail(qreal dLabelW, int iFontSize);
virtual void SaveRotationDetail(qreal dRot); virtual void SaveRotationDetail(qreal dRot);
virtual void SaveMovePattern(QPointF ptPos); virtual void SaveMovePattern(const QPointF& ptPos);
virtual void SaveResizePattern(qreal dLabelW, int iFontSize); virtual void SaveResizePattern(qreal dLabelW, int iFontSize);
virtual void SaveRotationPattern(qreal dRot); virtual void SaveRotationPattern(qreal dRot);