From 92ec78e6b35817a422b58a2e6838d64037f54eae Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 15 Aug 2016 17:19:21 +0200 Subject: [PATCH] Made sure that labels stay inside the detail after changing size or height --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 2 ++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 17 +++++++++++++++++ src/libs/vtools/tools/vtooldetail.cpp | 12 ++++++++---- src/libs/vwidgets/vmaingraphicsscene.h | 2 ++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 3eab696c4..dda3a33a3 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -2805,6 +2805,7 @@ void MainWindow::ChangedSize(const QString & text) if (UpdateMeasurements(AbsoluteMPath(curFile, doc->MPath()), text.toInt(), static_cast(pattern->height()))) { doc->LiteParseTree(Document::LiteParse); + emit sceneDetails->DimensionsChanged(); } else { @@ -2833,6 +2834,7 @@ void MainWindow::ChangedHeight(const QString &text) if (UpdateMeasurements(AbsoluteMPath(curFile, doc->MPath()), static_cast(pattern->size()), text.toInt())) { doc->LiteParseTree(Document::LiteParse); + emit sceneDetails->DimensionsChanged(); } else { diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 54b9c6566..75d3b8b01 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -230,6 +230,23 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) return; } + if (fW > parentItem()->boundingRect().width()) + { + fW = parentItem()->boundingRect().width(); + } + if (fW < MIN_W) + { + fW = MIN_W; + } + if (fH > parentItem()->boundingRect().height()) + { + fH = parentItem()->boundingRect().height(); + } + if (fH < m_iMinH) + { + fH = m_iMinH; + } + m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setHeight(fH); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 8e3d23882..fc31d3272 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -206,6 +206,10 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo); + + connect(sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolDetail::UpdateLabel); + connect(sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolDetail::UpdatePatternInfo); + UpdateLabel(); UpdatePatternInfo(); } @@ -770,8 +774,8 @@ void VToolDetail::UpdateLabel() QPointF pt = data.GetPos(); QRectF rectBB; rectBB.setTopLeft(pt); - rectBB.setWidth(data.GetLabelWidth()); - rectBB.setHeight(data.GetLabelHeight()); + rectBB.setWidth(dataLabel->boundingRect().width()); + rectBB.setHeight(dataLabel->boundingRect().height()); qreal dX; qreal dY; if (dataLabel->IsContained(rectBB, data.GetRotation(), dX, dY) == false) @@ -816,8 +820,8 @@ void VToolDetail::UpdatePatternInfo() QPointF pt = geom.GetPos(); QRectF rectBB; rectBB.setTopLeft(pt); - rectBB.setWidth(geom.GetLabelWidth()); - rectBB.setHeight(geom.GetLabelHeight()); + rectBB.setWidth(patternInfo->boundingRect().width()); + rectBB.setHeight(patternInfo->boundingRect().height()); qreal dX; qreal dY; if (patternInfo->IsContained(rectBB, geom.GetRotation(), dX, dY) == false) diff --git a/src/libs/vwidgets/vmaingraphicsscene.h b/src/libs/vwidgets/vmaingraphicsscene.h index a81172270..320604be6 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.h +++ b/src/libs/vwidgets/vmaingraphicsscene.h @@ -146,6 +146,8 @@ signals: void EnableNodePointItemHover(bool enabled); void EnableDetailItemHover(bool enabled); void EnableLineItemHover(bool enabled); + void DimensionsChanged(); + private: /** @brief horScrollBar value horizontal scroll bar. */ qint32 horScrollBar;