Fixed initial positioning of the labels

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-07-03 10:17:59 +02:00
parent 74a49662f6
commit 5e3daf416c
3 changed files with 34 additions and 14 deletions

View file

@ -42,7 +42,7 @@
#define MIN_W 120 #define MIN_W 120
#define MIN_H 60 #define MIN_H 60
#define MIN_FONT_SIZE 12 #define MIN_FONT_SIZE 12
#define MAX_FONT_SIZE 48 #define MAX_FONT_SIZE 128
#define SPACING 2 #define SPACING 2
#define TOP_Z 2 #define TOP_Z 2
@ -50,8 +50,6 @@
VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent)
: QGraphicsObject(pParent) : QGraphicsObject(pParent)
{ {
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
m_eMode = mNormal; m_eMode = mNormal;
m_bReleased = false; m_bReleased = false;
m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setTopLeft(QPointF(0, 0));
@ -172,12 +170,14 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH)
if (fW < MIN_W || fH < m_iMinH) if (fW < MIN_W || fH < m_iMinH)
return; return;
m_rectBoundingBox.setTopLeft(QPointF(0, 0));
m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setWidth(fW);
m_rectBoundingBox.setHeight(fH); m_rectBoundingBox.setHeight(fH);
m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE)); m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE));
m_rectResize.setWidth(RESIZE_SQUARE); m_rectResize.setWidth(RESIZE_SQUARE);
m_rectResize.setHeight(RESIZE_SQUARE); m_rectResize.setHeight(RESIZE_SQUARE);
setTransformOriginPoint(m_rectBoundingBox.center()); setTransformOriginPoint(m_rectBoundingBox.center());
prepareGeometryChange();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -134,15 +134,15 @@ 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(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
patternInfo = new VTextGraphicsItem(this); patternInfo = new VTextGraphicsItem(this);
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(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);
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo);
UpdateLabel(); UpdateLabel();
@ -712,7 +712,17 @@ void VToolDetail::UpdateLabel()
dataLabel->AddLine(tl); dataLabel->AddLine(tl);
} }
dataLabel->setPos(data.GetPos()); QPointF pt;
// check if center is inside
if (boundingRect().contains(data.GetPos() + QPointF(data.GetLabelWidth()/2, data.GetLabelHeight()/2)) == false)
{
pt = boundingRect().topLeft();
}
else
{
pt = data.GetPos();
}
dataLabel->setPos(pt);
dataLabel->setRotation(data.GetRotation()); dataLabel->setRotation(data.GetRotation());
dataLabel->Update(); dataLabel->Update();
dataLabel->show(); dataLabel->show();
@ -775,7 +785,17 @@ void VToolDetail::UpdatePatternInfo()
tl.m_qsText = qslDate.last(); tl.m_qsText = qslDate.last();
patternInfo->AddLine(tl); patternInfo->AddLine(tl);
patternInfo->setPos(geom.GetPos()); // check if center is inside
QPointF pt;
if (boundingRect().contains(geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2)) == false)
{
pt = boundingRect().topLeft();
}
else
{
pt = geom.GetPos();
}
patternInfo->setPos(pt);
patternInfo->setRotation(geom.GetRotation()); patternInfo->setRotation(geom.GetRotation());
patternInfo->Update(); patternInfo->Update();
} }

View file

@ -121,15 +121,15 @@ protected slots:
private: private:
Q_DISABLE_COPY(VToolDetail) Q_DISABLE_COPY(VToolDetail)
/** @brief dialog dialog options. */ /** @brief dialog dialog options. */
DialogTool *dialog; DialogTool *dialog;
/** @brief sceneDetails pointer to the scene. */ /** @brief sceneDetails pointer to the scene. */
VMainGraphicsScene *sceneDetails; VMainGraphicsScene *sceneDetails;
QString drawName; QString drawName;
VNoBrushScalePathItem *seamAllowance; VNoBrushScalePathItem *seamAllowance;
VTextGraphicsItem* dataLabel; VTextGraphicsItem *dataLabel;
VTextGraphicsItem* patternInfo; VTextGraphicsItem *patternInfo;
VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr);