LCOV - code coverage report
Current view: top level - src/engraving/dom - soundflag.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 18.5 % 119 22
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) 2024 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 "soundflag.h"
      24              : 
      25              : #include <climits>
      26              : 
      27              : #include "iengravingconfiguration.h" // IWYU pragma: keep
      28              : 
      29              : #include "../editing/editsoundflag.h"
      30              : #include "linkedobjects.h"
      31              : #include "mscore.h"
      32              : #include "score.h"
      33              : 
      34              : using namespace muse::draw;
      35              : using namespace mu::engraving;
      36              : 
      37            9 : SoundFlag::SoundFlag(DummyParentOr<EngravingItem> parent)
      38            9 :     : EngravingItem(ElementType::SOUND_FLAG, parent)
      39              : {
      40            9 :     String fontFamily = configuration()->iconsFontFamily();
      41            9 :     m_iconFontValid = !fontFamily.empty();
      42            9 :     m_iconFont = Font(fontFamily, Font::Type::Icon);
      43            9 :     m_iconFont.setPointSizeF(UI_ICONS_DEFAULT_FONT_SIZE);
      44              : 
      45              :     //! draw on top of all elements
      46            9 :     setZ(INT_MAX);
      47            9 : }
      48              : 
      49            0 : SoundFlag* SoundFlag::clone() const
      50              : {
      51            0 :     return new SoundFlag(*this);
      52              : }
      53              : 
      54            0 : bool SoundFlag::isEditable() const
      55              : {
      56            0 :     return false;
      57              : }
      58              : 
      59            0 : void SoundFlag::setSelected(bool f)
      60              : {
      61            0 :     EngravingItem* parent = ownershipParentItem();
      62            0 :     if (parent) {
      63            0 :         parent->setSelected(f);
      64              :     }
      65              : 
      66            0 :     EngravingItem::setSelected(f);
      67            0 : }
      68              : 
      69            0 : PropertyValue SoundFlag::getProperty(Pid id) const
      70              : {
      71            0 :     switch (id) {
      72            0 :     case Pid::PLAY:
      73            0 :         return m_play;
      74            0 :     case Pid::VISIBLE:
      75              :     case Pid::AUTOPLACE:
      76              :     case Pid::SMALL:
      77            0 :         return PropertyValue();
      78            0 :     case Pid::APPLY_TO_ALL_STAVES:
      79            0 :         return m_applyToAllStaves;
      80            0 :     default:
      81            0 :         return EngravingItem::getProperty(id);
      82              :     }
      83              : }
      84              : 
      85            0 : bool SoundFlag::setProperty(Pid id, const PropertyValue& value)
      86              : {
      87            0 :     switch (id) {
      88            0 :     case Pid::PLAY:
      89            0 :         m_play = value.toBool();
      90            0 :         return true;
      91            0 :     case Pid::VISIBLE:
      92              :     case Pid::AUTOPLACE:
      93              :     case Pid::SMALL:
      94            0 :         return false;
      95            0 :     case Pid::APPLY_TO_ALL_STAVES:
      96            0 :         m_applyToAllStaves = value.toBool();
      97            0 :         return true;
      98            0 :     default:
      99            0 :         return EngravingItem::setProperty(id, value);
     100              :     }
     101              : }
     102              : 
     103            0 : PropertyValue SoundFlag::propertyDefault(Pid id) const
     104              : {
     105            0 :     switch (id) {
     106            0 :     case Pid::PLAY:
     107            0 :         return true;
     108            0 :     case Pid::VISIBLE:
     109              :     case Pid::AUTOPLACE:
     110              :     case Pid::SMALL:
     111            0 :         return PropertyValue();
     112            0 :     case Pid::APPLY_TO_ALL_STAVES:
     113            0 :         return true;
     114            0 :     default:
     115            0 :         return EngravingItem::propertyDefault(id);
     116              :     }
     117              : }
     118              : 
     119           49 : const SoundFlag::PresetCodes& SoundFlag::soundPresets() const
     120              : {
     121           49 :     return m_soundPresets;
     122              : }
     123              : 
     124            0 : void SoundFlag::setSoundPresets(const PresetCodes& soundPresets)
     125              : {
     126            0 :     m_soundPresets = soundPresets;
     127            0 : }
     128              : 
     129           98 : const SoundFlag::PlayingTechniqueCode& SoundFlag::playingTechnique() const
     130              : {
     131           98 :     return m_playingTechnique;
     132              : }
     133              : 
     134            9 : void SoundFlag::setPlayingTechnique(const PlayingTechniqueCode& technique)
     135              : {
     136            9 :     m_playingTechnique = technique;
     137            9 : }
     138              : 
     139            9 : bool SoundFlag::play() const
     140              : {
     141            9 :     return m_play;
     142              : }
     143              : 
     144            0 : void mu::engraving::SoundFlag::setPlay(bool play)
     145              : {
     146            0 :     m_play = play;
     147            0 : }
     148              : 
     149           16 : bool SoundFlag::applyToAllStaves() const
     150              : {
     151           16 :     return m_applyToAllStaves;
     152              : }
     153              : 
     154            3 : void SoundFlag::setApplyToAllStaves(bool apply)
     155              : {
     156            3 :     m_applyToAllStaves = apply;
     157            3 : }
     158              : 
     159            0 : void SoundFlag::clear()
     160              : {
     161            0 :     if (m_soundPresets.empty() && m_playingTechnique.empty()) {
     162            0 :         return;
     163              :     }
     164              : 
     165            0 :     m_soundPresets.clear();
     166            0 :     m_playingTechnique.clear();
     167              : 
     168            0 :     triggerLayout();
     169              : }
     170              : 
     171            0 : bool SoundFlag::shouldHide() const
     172              : {
     173            0 :     if (!m_iconFontValid) {
     174            0 :         return true;
     175              :     }
     176              : 
     177            0 :     if (const Score* score = this->score()) {
     178            0 :         if (!score->showSoundFlags()) {
     179            0 :             return true;
     180              :         }
     181              : 
     182            0 :         if (score->printing()) {
     183            0 :             return true;
     184              :         }
     185              :     }
     186              : 
     187            0 :     if (!m_soundPresets.empty() || !m_playingTechnique.empty()) {
     188            0 :         return false;
     189              :     }
     190              : 
     191            0 :     if (selected()) {
     192            0 :         return false;
     193              :     }
     194              : 
     195            0 :     const EngravingItem* parent = ownershipParentItem();
     196            0 :     if (parent && parent->selected() && score()->selection().isSingle()) {
     197            0 :         return false;
     198              :     }
     199              : 
     200            0 :     return true;
     201              : }
     202              : 
     203            0 : void SoundFlag::undoChangeSoundFlag(const PresetCodes& presets, const PlayingTechniqueCode& technique)
     204              : {
     205            0 :     if (m_soundPresets == presets && m_playingTechnique == technique) {
     206            0 :         return;
     207              :     }
     208              : 
     209            0 :     score()->undo(new ChangeSoundFlag(this, presets, technique));
     210            0 :     triggerLayout();
     211              : 
     212            0 :     const LinkedObjects* links = this->links();
     213            0 :     if (!links) {
     214            0 :         return;
     215              :     }
     216              : 
     217            0 :     for (EngravingObject* obj : *links) {
     218            0 :         if (obj->isSoundFlag()) {
     219            0 :             SoundFlag* linkedSoundFlag = toSoundFlag(obj);
     220            0 :             score()->undo(new ChangeSoundFlag(linkedSoundFlag, presets, technique));
     221            0 :             linkedSoundFlag->triggerLayout();
     222              :         }
     223              :     }
     224              : }
     225              : 
     226            0 : char16_t SoundFlag::iconCode() const
     227              : {
     228            0 :     return 0xEF4E;
     229              : }
     230              : 
     231            0 : Font SoundFlag::iconFont() const
     232              : {
     233            0 :     Font font = m_iconFont;
     234            0 :     font.setPointSizeF(UI_ICONS_DEFAULT_FONT_SIZE * magS());
     235            0 :     return font;
     236            0 : }
     237              : 
     238            0 : Color SoundFlag::iconBackgroundColor() const
     239              : {
     240            0 :     Color color = curColor(true, {});
     241            0 :     if (!selected()) {
     242            0 :         color = Color("#CFD5DD");
     243            0 :         color.setAlpha(128);
     244              :     }
     245              : 
     246            0 :     return color;
     247            0 : }
        

Generated by: LCOV version 2.0-1