From 5e3daf416c3817e9b4da85494c947360a1e250ce Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 3 Jul 2016 10:17:59 +0200 Subject: [PATCH] Fixed initial positioning of the labels --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 6 ++--- src/libs/vtools/tools/vtooldetail.cpp | 30 +++++++++++++++++---- src/libs/vtools/tools/vtooldetail.h | 12 ++++----- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 68c76a973..025ba13af 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -42,7 +42,7 @@ #define MIN_W 120 #define MIN_H 60 #define MIN_FONT_SIZE 12 -#define MAX_FONT_SIZE 48 +#define MAX_FONT_SIZE 128 #define SPACING 2 #define TOP_Z 2 @@ -50,8 +50,6 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) : QGraphicsObject(pParent) { - setFlag(QGraphicsItem::ItemIsMovable, true); - setFlag(QGraphicsItem::ItemIsSelectable, true); m_eMode = mNormal; m_bReleased = false; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); @@ -172,12 +170,14 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) if (fW < MIN_W || fH < m_iMinH) return; + m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setHeight(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()); + prepareGeometryChange(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 2c6a4cf3d..756248ec8 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -134,15 +134,15 @@ 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(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); patternInfo = new VTextGraphicsItem(this); 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); + //connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); + connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo); UpdateLabel(); @@ -712,7 +712,17 @@ void VToolDetail::UpdateLabel() 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->Update(); dataLabel->show(); @@ -775,7 +785,17 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = qslDate.last(); 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->Update(); } diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 969805f7f..d7086d5c2 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -121,15 +121,15 @@ protected slots: private: Q_DISABLE_COPY(VToolDetail) /** @brief dialog dialog options. */ - DialogTool *dialog; + DialogTool *dialog; /** @brief sceneDetails pointer to the scene. */ - VMainGraphicsScene *sceneDetails; - QString drawName; + VMainGraphicsScene *sceneDetails; + QString drawName; - VNoBrushScalePathItem *seamAllowance; - VTextGraphicsItem* dataLabel; - VTextGraphicsItem* patternInfo; + VNoBrushScalePathItem *seamAllowance; + VTextGraphicsItem *dataLabel; + VTextGraphicsItem *patternInfo; VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr);