From 8ae0d37faf64b6ceae9e3089dd32e75c917cdaa8 Mon Sep 17 00:00:00 2001 From: re1san Date: Thu, 22 Aug 2024 21:40:45 +0530 Subject: [PATCH] Add adjustedBoundingRect to set a fixed height for bounding rectangle --- src/engraving/dom/dynamic.cpp | 17 +++++++++++++++++ src/engraving/dom/dynamic.h | 2 ++ src/engraving/dom/textbase.cpp | 17 +++++++++++------ .../NotationScene/internal/DynamicPopup.qml | 2 +- src/notation/view/abstractelementpopupmodel.cpp | 12 +++++++++++- .../view/notationviewinputcontroller.cpp | 12 ++++++++++-- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/engraving/dom/dynamic.cpp b/src/engraving/dom/dynamic.cpp index 765cc31ebb4e2..da4c785bb28e5 100644 --- a/src/engraving/dom/dynamic.cpp +++ b/src/engraving/dom/dynamic.cpp @@ -1111,3 +1111,20 @@ std::vector Dynamic::gripsPositions(const EditData&) const return {}; } } + +//--------------------------------------------------------- +// adjustedBoundingRect +//--------------------------------------------------------- + +RectF Dynamic::adjustedBoundingRect() const +{ + RectF r; + double m = spatium(); + + r = canvasBoundingRect(); + r.setWidth(width() + m * 2); + r.setHeight(m * 4.5); + r.translate(-m, -m); + + return r; +} diff --git a/src/engraving/dom/dynamic.h b/src/engraving/dom/dynamic.h index 3db4bc74a4930..1e2bb3419eb1a 100644 --- a/src/engraving/dom/dynamic.h +++ b/src/engraving/dom/dynamic.h @@ -152,6 +152,8 @@ class Dynamic final : public TextBase void findAdjacentHairpins(); + RectF adjustedBoundingRect() const; + private: M_PROPERTY(bool, avoidBarLines, setAvoidBarLines) diff --git a/src/engraving/dom/textbase.cpp b/src/engraving/dom/textbase.cpp index da8761735a1fd..01b3e0a101cf5 100644 --- a/src/engraving/dom/textbase.cpp +++ b/src/engraving/dom/textbase.cpp @@ -1889,10 +1889,9 @@ void TextBase::createBlocks(LayoutData* ldata) const SymId id = SymNames::symIdByName(sym); if (id != SymId::noSym) { CharFormat fmt = *cursor.format(); // save format - - //char32_t code = score()->scoreFont()->symCode(id); - char32_t code = id - == SymId::space ? static_cast(' ') : score()->engravingFonts()->fallbackFont()->symCode(id); + char32_t code = id == SymId::space + ? static_cast(' ') + : score()->engravingFonts()->fallbackFont()->symCode(id); cursor.format()->setFontFamily(u"ScoreText"); insert(&cursor, code, ldata); cursor.setFormat(fmt); // restore format @@ -3323,8 +3322,14 @@ void TextBase::drawEditMode(Painter* p, EditData& ed, double currentViewScaling) p->setPen(Pen(configuration()->formattingColor(), 2.0 / currentViewScaling)); // 2 pixel pen size p->setBrush(BrushStyle::NoBrush); - double m = spatium(); - RectF r = canvasBoundingRect().adjusted(-m, -m, m, m); + RectF r; + + if (ed.element->isDynamic()) { + r = toDynamic(ed.element)->adjustedBoundingRect(); + } else { + double m = spatium(); + r = canvasBoundingRect().adjusted(-m, -m, m, m); + } p->drawRect(r); pen = Pen(configuration()->defaultColor(), 0.0); diff --git a/src/notation/qml/MuseScore/NotationScene/internal/DynamicPopup.qml b/src/notation/qml/MuseScore/NotationScene/internal/DynamicPopup.qml index 3fbcba32123cc..857715c37b59a 100644 --- a/src/notation/qml/MuseScore/NotationScene/internal/DynamicPopup.qml +++ b/src/notation/qml/MuseScore/NotationScene/internal/DynamicPopup.qml @@ -27,7 +27,7 @@ StyledPopupView { function updatePosition() { root.x = root.parent.width / 2 - root.contentWidth / 2 - root.y = root.parent.height + root.y = root.parent.height - root.padding + root.margins } RowLayout { diff --git a/src/notation/view/abstractelementpopupmodel.cpp b/src/notation/view/abstractelementpopupmodel.cpp index 70d19cab7f729..1c6bd398fea77 100644 --- a/src/notation/view/abstractelementpopupmodel.cpp +++ b/src/notation/view/abstractelementpopupmodel.cpp @@ -232,7 +232,17 @@ const mu::engraving::ElementTypeSet& AbstractElementPopupModel::dependentElement void AbstractElementPopupModel::updateItemRect() { - QRectF rect = m_item ? fromLogical(m_item->canvasBoundingRect()).toQRectF() : QRectF(); + QRectF rect; + + if (!m_item) { + rect = QRect(); + } else { + if (m_item->isDynamic()) { + rect = fromLogical(toDynamic(m_item)->adjustedBoundingRect()).toQRectF(); + } else { + rect = fromLogical(m_item->canvasBoundingRect()).toQRectF(); + } + } if (m_itemRect != rect) { m_itemRect = rect; diff --git a/src/notation/view/notationviewinputcontroller.cpp b/src/notation/view/notationviewinputcontroller.cpp index 0964b85b77803..4bcdc6aa3fd3a 100644 --- a/src/notation/view/notationviewinputcontroller.cpp +++ b/src/notation/view/notationviewinputcontroller.cpp @@ -138,7 +138,11 @@ void NotationViewInputController::onNotationChanged() m_view->hideElementPopup(); if (AbstractElementPopupModel::supportsPopup(selectedItem)) { - m_view->showElementPopup(type, selectedItem->canvasBoundingRect()); + if (selectedItem->isDynamic()) { + m_view->showElementPopup(type, toDynamic(selectedItem)->adjustedBoundingRect()); + } else { + m_view->showElementPopup(type, selectedItem->canvasBoundingRect()); + } } }); } @@ -1237,7 +1241,11 @@ void NotationViewInputController::togglePopupForItemIfSupports(const EngravingIt ElementType type = item->type(); if (AbstractElementPopupModel::supportsPopup(item)) { - m_view->toggleElementPopup(type, item->canvasBoundingRect()); + if (item->isDynamic()) { + m_view->toggleElementPopup(type, toDynamic(item)->adjustedBoundingRect()); + } else { + m_view->toggleElementPopup(type, item->canvasBoundingRect()); + } } }