Skip to content

Commit

Permalink
Add adjustedBoundingRect to set a fixed height for bounding rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
ketgg authored and cbjeukendrup committed Jan 9, 2025
1 parent 60240db commit 8ae0d37
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/engraving/dom/dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,3 +1111,20 @@ std::vector<PointF> 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;
}
2 changes: 2 additions & 0 deletions src/engraving/dom/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class Dynamic final : public TextBase

void findAdjacentHairpins();

RectF adjustedBoundingRect() const;

private:

M_PROPERTY(bool, avoidBarLines, setAvoidBarLines)
Expand Down
17 changes: 11 additions & 6 deletions src/engraving/dom/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char32_t>(' ') : score()->engravingFonts()->fallbackFont()->symCode(id);
char32_t code = id == SymId::space
? static_cast<char32_t>(' ')
: score()->engravingFonts()->fallbackFont()->symCode(id);
cursor.format()->setFontFamily(u"ScoreText");
insert(&cursor, code, ldata);
cursor.setFormat(fmt); // restore format
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion src/notation/view/abstractelementpopupmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/notation/view/notationviewinputcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
});
}
Expand Down Expand Up @@ -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());
}
}
}

Expand Down

0 comments on commit 8ae0d37

Please sign in to comment.