LCOV - code coverage report
Current view: top level - src/engraving/dom - stafftext.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 49.3 % 73 36
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #include "stafftext.h"
      24              : 
      25              : #include "soundflag.h"
      26              : #include "segment.h"
      27              : #include "score.h"
      28              : #include "../editing/addremoveelement.h"
      29              : 
      30              : using namespace mu::engraving;
      31              : 
      32              : static const ElementStyle STAFF_STYLE {
      33              :     { Sid::staffTextPlacement, Pid::PLACEMENT },
      34              :     { Sid::staffTextMinDistance, Pid::MIN_DISTANCE },
      35              : };
      36              : 
      37          615 : StaffText::StaffText(DummyParentOr<Segment> parent, TextStyleType tid)
      38          615 :     : StaffTextBase(ElementType::STAFF_TEXT, parent, tid, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
      39              : {
      40          615 :     initElementStyle(&STAFF_STYLE);
      41          615 :     resetProperty(Pid::MUSIC_SYMBOL_SIZE);
      42          615 : }
      43              : 
      44          208 : StaffText::StaffText(const StaffText& t)
      45          208 :     : StaffTextBase(t)
      46              : {
      47          208 :     if (t.m_soundFlag) {
      48            0 :         setSoundFlag(t.m_soundFlag->clone());
      49              :     }
      50          208 : }
      51              : 
      52            0 : bool StaffText::isEditAllowed(EditData& ed) const
      53              : {
      54            0 :     bool ctrlPressed  = ed.modifiers & ControlModifier;
      55            0 :     bool shiftPressed = ed.modifiers & ShiftModifier;
      56            0 :     bool altPressed = ed.modifiers & AltModifier;
      57            0 :     if (altPressed && !ctrlPressed && !shiftPressed && (ed.key == Key_Left || ed.key == Key_Right)) {
      58            0 :         return false;
      59              :     }
      60              : 
      61            0 :     return TextBase::isEditAllowed(ed);
      62              : }
      63              : 
      64            5 : EngravingItem* StaffText::linkedClone()
      65              : {
      66            5 :     StaffText* clone = static_cast<StaffText*>(StaffTextBase::linkedClone());
      67              : 
      68            5 :     if (clone->m_soundFlag && m_soundFlag) {
      69            0 :         score()->undo(new Link(clone->m_soundFlag, m_soundFlag));
      70              :     }
      71              : 
      72            5 :     return clone;
      73              : }
      74              : 
      75         4262 : PropertyValue StaffText::propertyDefault(Pid id) const
      76              : {
      77         4262 :     switch (id) {
      78          331 :     case Pid::TEXT_STYLE:
      79          331 :         return TextStyleType::STAFF;
      80         3931 :     default:
      81         3931 :         return StaffTextBase::propertyDefault(id);
      82              :     }
      83              : }
      84              : 
      85           59 : void StaffText::scanElements(std::function<void(EngravingItem*)> func)
      86              : {
      87           59 :     if (m_soundFlag) {
      88            0 :         m_soundFlag->scanElements(func);
      89              :     }
      90              : 
      91           59 :     StaffTextBase::scanElements(func);
      92           59 : }
      93              : 
      94            0 : void StaffText::add(EngravingItem* e)
      95              : {
      96            0 :     e->setOwnershipParent(this);
      97            0 :     e->setTrack(track());
      98              : 
      99            0 :     switch (e->type()) {
     100            0 :     case ElementType::SOUND_FLAG:
     101            0 :         setSoundFlag(toSoundFlag(e));
     102            0 :         e->added();
     103            0 :         return;
     104            0 :     default:
     105            0 :         break;
     106              :     }
     107              : 
     108            0 :     StaffTextBase::add(e);
     109              : }
     110              : 
     111            0 : void StaffText::remove(EngravingItem* e)
     112              : {
     113            0 :     switch (e->type()) {
     114            0 :     case ElementType::SOUND_FLAG: {
     115            0 :         if (soundFlag() == e) {
     116            0 :             setSoundFlag(nullptr);
     117            0 :             e->removed();
     118            0 :             return;
     119              :         } else {
     120            0 :             LOGD("StaffText::remove: %s %p there is already another sound flag", e->typeName(), e);
     121              :         }
     122            0 :         break;
     123              :     }
     124            0 :     default:
     125            0 :         break;
     126              :     }
     127              : 
     128            0 :     StaffTextBase::remove(e);
     129              : }
     130              : 
     131          690 : void StaffText::setTrack(track_idx_t idx)
     132              : {
     133          690 :     StaffTextBase::setTrack(idx);
     134              : 
     135          690 :     if (m_soundFlag) {
     136            0 :         m_soundFlag->setTrack(idx);
     137              :     }
     138          690 : }
     139              : 
     140            0 : bool StaffText::hasSoundFlag() const
     141              : {
     142            0 :     return m_soundFlag != nullptr;
     143              : }
     144              : 
     145         1484 : SoundFlag* StaffText::soundFlag() const
     146              : {
     147         1484 :     return m_soundFlag;
     148              : }
     149              : 
     150            9 : void StaffText::setSoundFlag(SoundFlag* flag)
     151              : {
     152            9 :     if (m_soundFlag == flag) {
     153            0 :         return;
     154              :     }
     155              : 
     156            9 :     m_soundFlag = flag;
     157              : 
     158            9 :     if (m_soundFlag) {
     159            9 :         m_soundFlag->setOwnershipParent(this);
     160            9 :         m_soundFlag->setTrack(track());
     161              :     }
     162              : 
     163            9 :     triggerLayout();
     164              : }
        

Generated by: LCOV version 2.0-1