Skip to content

Commit

Permalink
Add preview of dynamic on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
ketgg authored and cbjeukendrup committed Jan 10, 2025
1 parent 9389966 commit 3db2be4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/engraving/dom/engravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,10 @@ Color EngravingItem::curColor(bool isVisible, Color normalColor) const
return configuration()->highlightSelectionColor(track() == muse::nidx ? 0 : voice());
}

if (flag(ElementFlag::IS_PREVIEW)) {
return configuration()->formattingColor();
}

bool marked = false;
if (isNote()) {
marked = toNote(this)->mark();
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/engravingitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ enum class ElementFlag {
ENABLED = 0x01000000, // used for segments
EMPTY = 0x02000000,
WRITTEN = 0x04000000,

IS_PREVIEW = 0x08000000, // used for hover preview in dynamics popup
};

typedef muse::Flags<ElementFlag> ElementFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ StyledPopupView {
}
}

mouseArea.onContainsMouseChanged: {
if (modelData.type === DynamicPopupModel.Dynamic) {
mouseArea.containsMouse ? dynamicModel.showPreview(currentPage, index) : dynamicModel.hidePreview()
}
}

onClicked: {
modelData.type === DynamicPopupModel.Dynamic ? dynamicModel.addOrChangeDynamic(currentPage, index) : dynamicModel.addHairpinToDynamic(modelData.type);
}
Expand Down
42 changes: 42 additions & 0 deletions src/notation/view/internal/dynamicpopupmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ void DynamicPopupModel::init()
return;
}

if (toDynamic(m_item)->empty()) {
m_item->setFlag(ElementFlag::IS_PREVIEW, true);
}

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

for (const QList<DynamicPopupModel::PageItem>& page : DYN_POPUP_PAGES) {
Expand Down Expand Up @@ -159,6 +163,10 @@ void DynamicPopupModel::addOrChangeDynamic(int page, int index)
m_item->undoChangeProperty(Pid::DYNAMIC_TYPE, DYN_POPUP_PAGES[page][index].dynType);
endCommand();

if (m_item->flag(ElementFlag::IS_PREVIEW)) {
m_item->setFlag(ElementFlag::IS_PREVIEW, false);
}

INotationInteractionPtr interaction = currentNotation()->interaction();

interaction->flipHairpinsType(toDynamic(m_item));
Expand Down Expand Up @@ -192,3 +200,37 @@ void DynamicPopupModel::addHairpinToDynamic(ItemType itemType)
endCommand();
updateNotation();
}

void DynamicPopupModel::showPreview(int page, int index)
{
IF_ASSERT_FAILED(m_item) {
return;
}

if (!m_item->isDynamic() || !m_item->flag(ElementFlag::IS_PREVIEW)) {
return;
}

beginCommand(TranslatableString("undoableAction", "Show dynamic preview"));
m_item->setProperty(Pid::TEXT, Dynamic::dynamicText(DYN_POPUP_PAGES[page][index].dynType));
m_item->setProperty(Pid::DYNAMIC_TYPE, DYN_POPUP_PAGES[page][index].dynType);
endCommand();
updateNotation();
}

void DynamicPopupModel::hidePreview()
{
IF_ASSERT_FAILED(m_item) {
return;
}

if (!m_item->isDynamic() || !m_item->flag(ElementFlag::IS_PREVIEW)) {
return;
}

beginCommand(TranslatableString("undoableAction", "Hide dynamic preview"));
m_item->setProperty(Pid::TEXT, String());
m_item->setProperty(Pid::DYNAMIC_TYPE, DynamicType::OTHER);
endCommand();
updateNotation();
}
3 changes: 3 additions & 0 deletions src/notation/view/internal/dynamicpopupmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class DynamicPopupModel : public AbstractElementPopupModel
Q_INVOKABLE void addOrChangeDynamic(int page, int index);
Q_INVOKABLE void addHairpinToDynamic(ItemType itemType);

Q_INVOKABLE void showPreview(int page, int index);
Q_INVOKABLE void hidePreview();

QString fontFamily() const;
QVariantList pages() const;

Expand Down

0 comments on commit 3db2be4

Please sign in to comment.