diff --git a/src/engraving/dom/edit.cpp b/src/engraving/dom/edit.cpp index 58cef305b3cb1..6fe204bec38d8 100644 --- a/src/engraving/dom/edit.cpp +++ b/src/engraving/dom/edit.cpp @@ -3980,11 +3980,7 @@ void Score::cmdDeleteSelection() FretDiagram* fretDiagram = toFretDiagram(e); Harmony* harmony = fretDiagram->harmony(); if (harmony) { - for (EngravingObject* o: fretDiagram->linkList()) { - FretDiagram* linkedDiagram = toFretDiagram(o); - Harmony* linkedHarmony = linkedDiagram->harmony(); - undo(new FretLinkHarmony(linkedDiagram, linkedHarmony, true /* unlink */)); - } + undoChangeParent(harmony, fretDiagram->segment(), track2staff(fretDiagram->track())); elSelectedAfterDeletion = harmony; } } else if (e->isHarmony()) { @@ -6987,21 +6983,7 @@ void Score::undoAddElement(EngravingItem* element, bool addToLinkedStaves, bool ne->setTrack(linkedTrack); ne->setParent(seg); - // make harmony child of fret diagram if possible - if (ne->isHarmony()) { - for (EngravingItem* segel : segment->annotations()) { - if (segel && segel->isFretDiagram() && segel->track() == linkedTrack && !toFretDiagram(segel)->harmony()) { - segel->add(ne); - break; - } - } - } else if (ne->isFretDiagram()) { - // update track of child harmony - FretDiagram* fd = toFretDiagram(ne); - if (fd->harmony()) { - fd->harmony()->setTrack(linkedTrack); - } - } else if (ne->isStringTunings()) { + if (ne->isStringTunings()) { StringTunings* stringTunings = toStringTunings(ne); if (stringTunings->stringData()->isNull()) { const StringData* stringData = stringTunings->part()->stringData(tick, staff->idx()); diff --git a/src/engraving/dom/fret.cpp b/src/engraving/dom/fret.cpp index 8d221228cd747..1b5df32551674 100644 --- a/src/engraving/dom/fret.cpp +++ b/src/engraving/dom/fret.cpp @@ -804,21 +804,6 @@ std::vector FretDiagram::patternHarmonies(const String& pattern) return muse::value(s_diagramPatternToHarmoniesMap, pattern); } -void FretDiagram::applyAlignmentToHarmony() -{ - if (m_harmony->propertyFlags(Pid::OFFSET) == PropertyFlags::STYLED) { - m_harmony->resetProperty(Pid::OFFSET); - } - - m_harmony->setProperty(Pid::ALIGN, Align(AlignH::HCENTER, AlignV::BASELINE)); - m_harmony->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED); -} - -void FretDiagram::resetHarmonyAlignment() -{ - m_harmony->resetProperty(Pid::ALIGN); -} - //--------------------------------------------------------- // clear //--------------------------------------------------------- @@ -946,38 +931,6 @@ void FretDiagram::setHarmony(String harmonyText) triggerLayout(); } -void FretDiagram::linkHarmony(Harmony* harmony) -{ - m_harmony = harmony; - - setParent(harmony->explicitParent()); - harmony->setParent(this); - - //! on the same lavel as diagram - m_harmony->setZ(z()); - - if (Segment* segment = this->segment()) { - segment->removeAnnotation(harmony); - } - - m_harmony->setTrack(track()); - - applyAlignmentToHarmony(); -} - -void FretDiagram::unlinkHarmony() -{ - m_harmony->setTrack(track()); - - resetHarmonyAlignment(); - - m_harmony->setZ(-1); - - segment()->add(m_harmony); - - m_harmony = nullptr; -} - //--------------------------------------------------------- // add //--------------------------------------------------------- @@ -990,9 +943,6 @@ void FretDiagram::add(EngravingItem* e) m_harmony->setTrack(track()); - //! on the same lavel as diagram - m_harmony->setZ(z()); - if (m_harmony->harmonyName().empty()) { if (s_diagramPatternToHarmoniesMap.empty()) { readHarmonyToDiagramFile(HARMONY_TO_DIAGRAM_FILE_PATH); @@ -1007,7 +957,9 @@ void FretDiagram::add(EngravingItem* e) } } - applyAlignmentToHarmony(); + m_harmony->resetProperty(Pid::OFFSET); + m_harmony->setProperty(Pid::ALIGN, Align(AlignH::HCENTER, AlignV::BASELINE)); + m_harmony->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED); e->added(); } else { @@ -1355,7 +1307,7 @@ FretDiagram* FretDiagram::makeFromHarmonyOrFretDiagram(const EngravingItem* harm fretDiagram->updateDiagram(harmony->plainText()); - fretDiagram->linkHarmony(harmony); + fretDiagram->add(harmony); } else if (harmonyOrFretDiagram->isHarmony() && harmonyOrFretDiagram->parentItem()->isFretDiagram()) { fretDiagram = toFretDiagram(harmonyOrFretDiagram->parentItem())->clone(); } else if (harmonyOrFretDiagram->isFretDiagram()) { diff --git a/src/engraving/dom/fret.h b/src/engraving/dom/fret.h index 033bfb513f3a9..aa1378796b30e 100644 --- a/src/engraving/dom/fret.h +++ b/src/engraving/dom/fret.h @@ -209,8 +209,6 @@ class FretDiagram final : public EngravingItem String harmonyText() const; Harmony* harmony() const { return m_harmony; } void setHarmony(String harmonyText); - void linkHarmony(Harmony* harmony); - void unlinkHarmony(); std::vector dot(int s, int f = 0) const; FretItem::Marker marker(int s) const; @@ -302,9 +300,6 @@ class FretDiagram final : public EngravingItem static void applyDiagramPattern(FretDiagram* diagram, const String& pattern); - void applyAlignmentToHarmony(); - void resetHarmonyAlignment(); - int m_strings = 0; int m_frets = 0; int m_fretOffset = 0; diff --git a/src/engraving/dom/undo.cpp b/src/engraving/dom/undo.cpp index 8dbe469b6b1f5..886e8239d2185 100644 --- a/src/engraving/dom/undo.cpp +++ b/src/engraving/dom/undo.cpp @@ -3557,31 +3557,6 @@ void ChangeTieJumpPointActive::flip(EditData*) m_active = oldActive; } -FretLinkHarmony::FretLinkHarmony(FretDiagram* diagram, Harmony* harmony, bool unlink) -{ - m_fretDiagram = diagram; - m_harmony = harmony; - m_unlink = unlink; -} - -void FretLinkHarmony::undo(EditData*) -{ - if (m_unlink) { - m_fretDiagram->linkHarmony(m_harmony); - } else { - m_fretDiagram->unlinkHarmony(); - } -} - -void FretLinkHarmony::redo(EditData*) -{ - if (m_unlink) { - m_fretDiagram->unlinkHarmony(); - } else { - m_fretDiagram->linkHarmony(m_harmony); - } -} - RemoveFretDiagramFromFretBox::RemoveFretDiagramFromFretBox(FretDiagram* f) : m_fretDiagram(f) { diff --git a/src/engraving/dom/undo.h b/src/engraving/dom/undo.h index b250d8aa62872..a352a9fcc3fb7 100644 --- a/src/engraving/dom/undo.h +++ b/src/engraving/dom/undo.h @@ -159,7 +159,6 @@ enum class CommandType : signed char { FretMarker, FretBarre, FretClear, - FretLinkHarmony, RemoveFretDiagramFromFretBox, // Harmony @@ -1806,25 +1805,6 @@ class FretClear : public UndoCommand UNDO_CHANGED_OBJECTS({ diagram }) }; -class FretLinkHarmony : public UndoCommand -{ - OBJECT_ALLOCATOR(engraving, FretLinkHarmony) - - FretDiagram* m_fretDiagram = nullptr; - Harmony* m_harmony = nullptr; - bool m_unlink = false; - - void undo(EditData*) override; - void redo(EditData*) override; - -public: - FretLinkHarmony(FretDiagram*, Harmony*, bool unlink = false); - - UNDO_TYPE(CommandType::FretLinkHarmony) - UNDO_NAME("FretLinkHarmony") - UNDO_CHANGED_OBJECTS({ m_fretDiagram }) -}; - class RemoveFretDiagramFromFretBox : public UndoCommand { OBJECT_ALLOCATOR(engraving, RemoveFretDiagramFromFretBox) diff --git a/src/engraving/types/types.h b/src/engraving/types/types.h index e05f866461448..9fcc88087cace 100644 --- a/src/engraving/types/types.h +++ b/src/engraving/types/types.h @@ -128,8 +128,8 @@ enum class ElementType : unsigned char { REHEARSAL_MARK, INSTRUMENT_CHANGE, STAFFTYPE_CHANGE, - HARMONY, FRET_DIAGRAM, + HARMONY, HARP_DIAGRAM, BEND, TREMOLOBAR, diff --git a/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.cpp b/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.cpp index c8b44cdee9a1b..31d2fe7c380ac 100644 --- a/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.cpp +++ b/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.cpp @@ -55,12 +55,15 @@ void FretFrameChordsSettingsModel::requestElements() m_chordListModel->setFBox(fretBox()); m_chordListModel->load(); + + updateHasInvisibleChords(); } void FretFrameChordsSettingsModel::loadProperties() { loadProperties({ Pid::FRET_FRAME_DIAGRAMS_ORDER }); m_chordListModel->load(); + updateHasInvisibleChords(); } void FretFrameChordsSettingsModel::resetProperties() @@ -81,6 +84,7 @@ void FretFrameChordsSettingsModel::onNotationChanged(const engraving::PropertyId const engraving::StyleIdSet&) { loadProperties(changedPropertyIdSet); + updateHasInvisibleChords(); } void FretFrameChordsSettingsModel::loadProperties(const engraving::PropertyIdSet& propertyIdSet) @@ -90,6 +94,26 @@ void FretFrameChordsSettingsModel::loadProperties(const engraving::PropertyIdSet } } +void FretFrameChordsSettingsModel::updateHasInvisibleChords() +{ + bool hasInvisibleChords = false; + + const FBox* fbox = fretBox(); + if (fbox) { + for (EngravingItem* item : fbox->el()) { + if (!item->visible()) { + hasInvisibleChords = true; + break; + } + } + } + + if (hasInvisibleChords != m_hasInvisibleChords) { + m_hasInvisibleChords = hasInvisibleChords; + emit hasInvisibleChordsChanged(m_hasInvisibleChords); + } +} + FretFrameChordListModel* FretFrameChordsSettingsModel::chordListModel() const { return m_chordListModel.get(); @@ -99,3 +123,27 @@ PropertyItem* FretFrameChordsSettingsModel::listOrder() const { return m_listOrder; } + +bool FretFrameChordsSettingsModel::hasInvisibleChords() const +{ + return m_hasInvisibleChords; +} + +void FretFrameChordsSettingsModel::resetList() +{ + beginCommand(TranslatableString("undoableAction", "Reset Fret Diagram Legend chords list")); + + FBox* fbox = fretBox(); + if (fbox) { + fbox->undoResetProperty(Pid::FRET_FRAME_DIAGRAMS_ORDER); + + for (EngravingItem* item : fbox->el()) { + item->undoResetProperty(Pid::VISIBLE); + } + } + + updateNotation(); + endCommand(); + + loadProperties(); +} diff --git a/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.h b/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.h index e8ff2b6f1c54e..287de07a4c922 100644 --- a/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.h +++ b/src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.h @@ -43,6 +43,8 @@ class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse: Q_PROPERTY(PropertyItem * listOrder READ listOrder CONSTANT) + Q_PROPERTY(bool hasInvisibleChords READ hasInvisibleChords NOTIFY hasInvisibleChordsChanged) + muse::Inject globalContext = { this }; public: @@ -51,6 +53,12 @@ class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse: FretFrameChordListModel* chordListModel() const; PropertyItem* listOrder() const; + bool hasInvisibleChords() const; + + Q_INVOKABLE void resetList(); + +signals: + void hasInvisibleChordsChanged(bool hasInvisible); private: engraving::FBox* fretBox() const; @@ -64,8 +72,11 @@ class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse: void loadProperties(const mu::engraving::PropertyIdSet& propertyIdSet); + void updateHasInvisibleChords(); + std::shared_ptr m_chordListModel; PropertyItem* m_listOrder = nullptr; + bool m_hasInvisibleChords = false; }; } diff --git a/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsControlPanel.qml b/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsControlPanel.qml index 43a0bcfb21168..3eab908742331 100644 --- a/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsControlPanel.qml +++ b/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsControlPanel.qml @@ -40,6 +40,7 @@ RowLayout { property bool isMovingUpAvailable: false property bool isMovingDownAvailable: false + property bool hasInvisibleChords: false height: childrenRect.height @@ -47,6 +48,7 @@ RowLayout { signal moveSelectionUpRequested() signal moveSelectionDownRequested() + signal resetListRequested(); FlatButton { id: upBotton @@ -92,10 +94,10 @@ RowLayout { navigation.row: downButton.navigation.row + 1 navigation.accessible.name: qsTrc("inspector", "Reset chord list") - enabled: root.listOrderItem.isModified + enabled: root.listOrderItem.isModified || root.hasInvisibleChords onClicked: { - root.listOrderItem.resetToDefault() + root.resetListRequested() } } } diff --git a/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsTab.qml b/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsTab.qml index 9680589bb62a1..5a1f2bf56ad9d 100644 --- a/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsTab.qml +++ b/src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsTab.qml @@ -55,6 +55,7 @@ FocusableItem { anchors.rightMargin: root.sideMargin listOrderItem: root.model ? root.model.listOrder : null + hasInvisibleChords: root.model ? root.model.hasInvisibleChords : null isMovingUpAvailable: view.model ? view.model.isMovingUpAvailable : false isMovingDownAvailable: view.model ? view.model.isMovingDownAvailable : false @@ -73,6 +74,10 @@ FocusableItem { view.model.moveSelectionDown() Qt.callLater(view.positionViewAtSelectedItems) } + + onResetListRequested: { + root.model.resetList() + } } FretFrameChordsView { diff --git a/src/notation/internal/notationinteraction.cpp b/src/notation/internal/notationinteraction.cpp index 403f65236dd37..f8e51c60b003b 100644 --- a/src/notation/internal/notationinteraction.cpp +++ b/src/notation/internal/notationinteraction.cpp @@ -7856,11 +7856,11 @@ void NotationInteraction::addFretboardDiagram() diagram->setTrack(element->track()); Harmony* harmony = toHarmony(element); - diagram->updateDiagram(harmony->harmonyName()); - score->undo(new FretLinkHarmony(diagram, harmony)); + diagram->setParent(harmony->parent()); score->undoAddElement(diagram); + score->undoChangeParent(harmony, diagram, track2staff(element->track())); lastAddedDiagram = diagram; }