Skip to content

Commit

Permalink
Select an existing dynamic instead of opening a new empty popup at th…
Browse files Browse the repository at this point in the history
…e end of hairpin drag
  • Loading branch information
ketgg committed Aug 5, 2024
1 parent b3e53a8 commit 1e6a203
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ TextBase* Score::addText(TextStyleType type, EngravingItem* destinationElement)
}
textBox = Factory::createDynamic(dummy()->segment());
chordRest->undoAddAnnotation(textBox);
textBox->setFlag(ElementFlag::IS_PREVIEW, true);
break;
}
case TextStyleType::INSTRUMENT_CHANGE: {
Expand Down
36 changes: 26 additions & 10 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4427,19 +4427,35 @@ void NotationInteraction::toggleDynamicPopup()
return;
}

EngravingItem* selectedElement = selection()->element();
EngravingItem* el = selection()->element();

if (selectedElement->isHairpinSegment()) {
HairpinSegment* hairpinSeg = toHairpinSegment(selectedElement);
Grip curGrip = m_editData.curGrip;
ChordRest* cr = curGrip == Grip::START ? hairpinSeg->spanner()->startCR()
: curGrip == Grip::END ? hairpinSeg->spanner()->endCR()
: nullptr;
if (cr) {
addTextToItem(TextStyleType::DYNAMICS, cr);
if (el->isHairpinSegment()) {
HairpinSegment* hairpinSeg = toHairpinSegment(el);

switch (m_editData.curGrip) {
case Grip::START: {
EngravingItem* startDynOrExp = hairpinSeg->findElementToSnapBefore();
if (startDynOrExp != nullptr) {
select({ startDynOrExp }); // If there is already a dynamic select it instead of opening an empty popup
} else {
addTextToItem(TextStyleType::DYNAMICS, hairpinSeg->spanner()->startCR());
}
}
return;
case Grip::END: {
EngravingItem* endDynOrExp = hairpinSeg->findElementToSnapAfter();
if (endDynOrExp != nullptr) {
select({ endDynOrExp }); // If there is already a dynamic select it instead of opening an empty popup
} else {
addTextToItem(TextStyleType::DYNAMICS, hairpinSeg->spanner()->endCR());
}
}
return;
default:
return;
}
} else {
addTextToItem(TextStyleType::DYNAMICS, selection()->element());
addTextToItem(TextStyleType::DYNAMICS, el);
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/notation/view/internal/dynamicpopupmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ void DynamicPopupModel::init()
return;
}

// If popup opened on clicking an already existing dynamic then dont't show the preview on hover
if (!toDynamic(m_item)->empty()) {
m_item->setFlag(ElementFlag::IS_PREVIEW, false);
} else {
m_item->setFlag(ElementFlag::IS_PREVIEW, true);
}

IEngravingFontPtr engravingFont = m_item->score()->engravingFont();

for (const QList<DynamicPopupModel::PageItem>& page : DYN_POPUP_PAGES) {
Expand Down

0 comments on commit 1e6a203

Please sign in to comment.