LCOV - code coverage report
Current view: top level - src/engraving/dom - mmrest.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 86.9 % 61 53
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 "mmrest.h"
      24              : 
      25              : #include "measure.h"
      26              : #include "part.h"
      27              : #include "score.h"
      28              : #include "system.h"
      29              : 
      30              : using namespace mu::engraving;
      31              : 
      32              : //---------------------------------------------------------
      33              : //    MMRest
      34              : //--------------------------------------------------------
      35              : 
      36          107 : MMRest::MMRest(DummyParentOr<Segment> s)
      37          107 :     : Rest(ElementType::MMREST, s)
      38              : {
      39          107 :     m_numberVisible = true;
      40          107 :     setPlacement(PlacementV::ABOVE);
      41          107 : }
      42              : 
      43            0 : MMRest::MMRest(const MMRest& r, bool link)
      44            0 :     : Rest(r, link)
      45              : {
      46            0 :     m_numberVisible = r.m_numberVisible;
      47            0 : }
      48              : 
      49          537 : bool MMRest::shouldShowNumberByDefault() const
      50              : {
      51          537 :     bool shouldShow = isOldStyle() && ldata()->number == 1 ? style().styleB(Sid::singleMeasureMMRestShowNumber) : true;
      52              : 
      53          537 :     const Part* itemPart = part();
      54          537 :     const System* system = measure()->system();
      55          561 :     bool isTopStaffOfPartAndCenteringIsActive = itemPart->nstaves() > 1 && staff() == itemPart->staves().front()
      56           12 :                                                 && (system && system->nextVisibleStaff(staffIdx()) != muse::nidx)
      57          561 :                                                 && style().styleB(Sid::mmRestBetweenStaves);
      58              : 
      59          537 :     return shouldShow && !isTopStaffOfPartAndCenteringIsActive;
      60              : }
      61              : 
      62          537 : bool MMRest::showNumber() const
      63              : {
      64          537 :     return shouldShowNumberByDefault() && m_numberVisible;
      65              : }
      66              : 
      67         1430 : bool MMRest::isOldStyle() const
      68              : {
      69         1430 :     int number = ldata()->number;
      70         1430 :     return (style().styleB(Sid::oldStyleMultiMeasureRests) && number <= style().styleI(Sid::mmRestOldStyleMaxMeasures))
      71         1430 :            || (number == 1 && style().styleB(Sid::singleMeasureMMRestUseNormalRest));
      72              : }
      73              : 
      74         1058 : RectF MMRest::numberRect() const
      75              : {
      76         1058 :     return symBbox(ldata()->numberSym);
      77              : }
      78              : 
      79          529 : PointF MMRest::numberPos() const
      80              : {
      81          529 :     RectF numBBox = numberRect();
      82          529 :     double x = 0.5 * (ldata()->restWidth - numBBox.width());
      83          529 :     double y = -pos().y() + yNumberPos() - 0.5 * numBBox.height();
      84          529 :     return PointF(x, y);
      85              : }
      86              : 
      87          529 : double MMRest::yNumberPos() const
      88              : {
      89          529 :     return ldata()->yNumberPos + absoluteFromSpatium(m_numberOffset);
      90              : }
      91              : 
      92              : //---------------------------------------------------------
      93              : //   propertyDefault
      94              : //---------------------------------------------------------
      95              : 
      96          451 : PropertyValue MMRest::propertyDefault(Pid propertyId) const
      97              : {
      98          451 :     switch (propertyId) {
      99           34 :     case Pid::MMREST_NUMBER_OFFSET:
     100           34 :         return 0.0_sp;
     101           34 :     case Pid::MMREST_NUMBER_VISIBLE:
     102           34 :         return true;
     103          383 :     default:
     104          383 :         return Rest::propertyDefault(propertyId);
     105              :     }
     106              : }
     107              : 
     108              : //---------------------------------------------------------
     109              : //   getProperty
     110              : //---------------------------------------------------------
     111              : 
     112          456 : PropertyValue MMRest::getProperty(Pid propertyId) const
     113              : {
     114          456 :     switch (propertyId) {
     115           38 :     case Pid::MMREST_NUMBER_OFFSET:
     116           38 :         return m_numberOffset;
     117           34 :     case Pid::MMREST_NUMBER_VISIBLE:
     118           34 :         return m_numberVisible;
     119          384 :     default:
     120          384 :         return Rest::getProperty(propertyId);
     121              :     }
     122              : }
     123              : 
     124              : //---------------------------------------------------------
     125              : //   setProperty
     126              : //---------------------------------------------------------
     127              : 
     128           28 : bool MMRest::setProperty(Pid propertyId, const PropertyValue& v)
     129              : {
     130           28 :     switch (propertyId) {
     131            2 :     case Pid::MMREST_NUMBER_OFFSET:
     132            2 :         m_numberOffset = v.value<Spatium>();
     133            2 :         triggerLayout();
     134            2 :         break;
     135            0 :     case Pid::MMREST_NUMBER_VISIBLE:
     136            0 :         m_numberVisible = v.toBool();
     137            0 :         triggerLayout();
     138            0 :         break;
     139           26 :     default:
     140           26 :         return Rest::setProperty(propertyId, v);
     141              :     }
     142            2 :     return true;
     143              : }
        

Generated by: LCOV version 2.0-1