diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 48c038cd5..68c76a973 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,7 @@ #define MIN_FONT_SIZE 12 #define MAX_FONT_SIZE 48 #define SPACING 2 +#define TOP_Z 2 //--------------------------------------------------------------------------------------------------------------------- VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) @@ -55,7 +57,7 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_iMinH = MIN_H; SetSize(MIN_W, m_iMinH); - setZValue(2); + setZValue(TOP_Z); } //--------------------------------------------------------------------------------------------------------------------- @@ -137,11 +139,10 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Reset() { - qDebug() << "RESET" << m_eMode << m_liLines.count(); m_eMode = mNormal; m_bReleased = false; Update(); - setZValue(2); + setZValue(TOP_Z); } //--------------------------------------------------------------------------------------------------------------------- @@ -206,6 +207,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) m_ptStartPos = pos(); m_ptStart = pME->scenePos(); m_szStart = m_rectBoundingBox.size(); + m_ptRotCenter = mapToScene(m_rectBoundingBox.center()); m_dAngle = GetAngle(pME->scenePos()); m_dRotation = rotation(); if (m_eMode != mRotate) @@ -219,9 +221,8 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) m_eMode = mMove; } } - setZValue(3); + setZValue(TOP_Z + 1); UpdateBox(); - qDebug() << "PRESS" << m_eMode << m_liLines.count(); } } @@ -262,8 +263,6 @@ 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 << m_liLines.count(); - if (m_eMode == mMove || m_eMode == mResize) { // when released in mMove or mResize mode if (bShort == true) @@ -299,7 +298,6 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } } m_bReleased = true; - qDebug() << "RELEASE finished" << m_eMode << m_liLines.count(); } } @@ -382,8 +380,8 @@ QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QF //--------------------------------------------------------------------------------------------------------------------- double VTextGraphicsItem::GetAngle(QPointF pt) const { - double dX = pt.x() - m_ptStart.x(); - double dY = pt.y() - m_ptStart.y(); + double dX = pt.x() - m_ptRotCenter.x(); + double dY = pt.y() - m_ptRotCenter.y(); if (fabs(dX) < 1 && fabs(dY) < 1) return 0; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 54d3725cb..7f01e987c 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -92,6 +92,7 @@ private: bool m_bReleased; QPointF m_ptStartPos; QPointF m_ptStart; + QPointF m_ptRotCenter; QSizeF m_szStart; double m_dRotation; double m_dAngle; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 8686e633b..2c6a4cf3d 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -81,8 +81,7 @@ const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath"); VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent) :VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene), - drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)), - dataLabel(new VTextGraphicsItem(this)), patternInfo(new VTextGraphicsItem(this)) + drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)) { VDetail detail = data->GetDetail(id); for (int i = 0; i< detail.CountNode(); ++i) @@ -119,8 +118,6 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - qDebug() << "VToolDetail" << patternInfo; - connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolDetail::ResetChildren); if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) @@ -133,11 +130,13 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 } setAcceptHoverEvents(true); + dataLabel = new VTextGraphicsItem(this); 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); + 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);