LCOV - code coverage report
Current view: top level - src/engraving/dom - barline.h Coverage Total Hit
Test: filtered_coverage.info Lines: 66.7 % 24 16
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              : #pragma once
      24              : 
      25              : #include "engravingitem.h"
      26              : 
      27              : #include "../editing/elementeditdata.h"
      28              : 
      29              : namespace mu::engraving {
      30              : class Factory;
      31              : class Segment;
      32              : class Transaction;
      33              : 
      34              : static constexpr int MIN_BARLINE_FROMTO_DIST        = 2;
      35              : static constexpr int MIN_BARLINE_SPAN_FROMTO        = -2;
      36              : 
      37              : // bar line span for 1-line staves is special: goes from 2sp above the line to 2sp below the line;
      38              : static constexpr int BARLINE_SPAN_1LINESTAFF_FROM   = -4;
      39              : static constexpr int BARLINE_SPAN_1LINESTAFF_TO     = 4;
      40              : 
      41              : // data for some preset bar line span types
      42              : static constexpr int BARLINE_SPAN_TICK1_FROM        = -1;
      43              : static constexpr int BARLINE_SPAN_TICK1_TO          = -7;
      44              : static constexpr int BARLINE_SPAN_TICK2_FROM        = -2;
      45              : static constexpr int BARLINE_SPAN_TICK2_TO          = -6;
      46              : static constexpr int BARLINE_SPAN_SHORT1_FROM       = 2;
      47              : static constexpr int BARLINE_SPAN_SHORT1_TO         = -2;
      48              : static constexpr int BARLINE_SPAN_SHORT2_FROM       = 1;
      49              : static constexpr int BARLINE_SPAN_SHORT2_TO         = -1;
      50              : 
      51              : //---------------------------------------------------------
      52              : //   BarLineTableItem
      53              : //---------------------------------------------------------
      54              : 
      55              : struct BarLineTableItem {
      56              :     BarLineType type;
      57              :     const muse::TranslatableString& userName;
      58              : };
      59              : 
      60              : //---------------------------------------------------------
      61              : //   BarLineEditData
      62              : //---------------------------------------------------------
      63              : 
      64              : class BarLineEditData : public ElementEditData
      65              : {
      66            0 :     OBJECT_ALLOCATOR(engraving, BarLineEditData)
      67              : public:
      68              :     double yoff1 = 0.0;
      69              :     double yoff2 = 0.0;
      70            0 :     virtual EditDataType type() override { return EditDataType::BarLineEditData; }
      71              : };
      72              : 
      73              : //---------------------------------------------------------
      74              : //   @@ BarLine
      75              : //
      76              : //   @P barLineType  enum  (BarLineType.NORMAL, .DOUBLE, .START_REPEAT, .END_REPEAT, .BROKEN, .END, .END_START_REPEAT, .DOTTED)
      77              : //---------------------------------------------------------
      78              : 
      79              : class BarLine final : public EngravingItem
      80              : {
      81        54145 :     OBJECT_ALLOCATOR(engraving, BarLine)
      82         2376 :     DECLARE_CLASSOF(ElementType::BAR_LINE)
      83              : 
      84              : public:
      85              :     ~BarLine() override;
      86              : 
      87              :     BarLine& operator=(const BarLine&) = delete;
      88              : 
      89              :     void setOwnershipParent(DummyParentOr<Segment> parent);
      90              : 
      91          161 :     BarLine* clone() const override { return new BarLine(*this); }
      92              :     PointF canvasPos() const override;      ///< position in canvas coordinates
      93              :     PointF pagePos() const override;        ///< position in page coordinates
      94              : 
      95              :     void scanElements(std::function<void(EngravingItem*)> func) override;
      96              :     void setTrack(track_idx_t t) override;
      97              :     void add(EngravingItem*) override;
      98              :     void remove(EngravingItem*) override;
      99              :     bool acceptDrop(EditData&) const override;
     100              :     EngravingItem* drop(Transaction& tx, EditData&) override;
     101            0 :     bool isEditable() const override { return true; }
     102              : 
     103       487217 :     Segment* segment() const { return toSegment(ownershipParent()); }
     104        12167 :     Measure* measure() const { return ownershipParent() ? toMeasure(ownershipParent()->ownershipParent()) : nullptr; }
     105              : 
     106        89288 :     void setSpanStaff(const bool val) { m_spanStaff = val; }
     107        84262 :     void setSpanFrom(int val) { m_spanFrom = val; }
     108        84261 :     void setSpanTo(int val) { m_spanTo = val; }
     109              :     void setShowTips(bool val);
     110       299259 :     bool spanStaff() const { return m_spanStaff; }
     111       286757 :     int spanFrom() const { return m_spanFrom; }
     112       225116 :     int spanTo() const { return m_spanTo; }
     113              :     bool showTips() const;
     114              : 
     115              :     void startEdit(EditData& ed) override;
     116              :     bool isEditAllowed(EditData&) const override;
     117              :     bool edit(EditData& ed) override;
     118              :     void dragGrip(EditData&) override;
     119              :     void endDragGrip(EditData&) override;
     120              : 
     121       226788 :     const ElementList* el() const { return &m_el; }
     122              : 
     123              :     static String translatedUserTypeName(BarLineType);
     124              : 
     125        89014 :     void setBarLineType(BarLineType i) { m_barLineType = i; }
     126       136764 :     BarLineType barLineType() const { return m_barLineType; }
     127              : 
     128              :     bool isTop() const;
     129              :     bool isBottom() const;
     130              : 
     131            0 :     int subtype() const override { return int(m_barLineType); }
     132              :     TranslatableString subtypeUserName() const override;
     133              : 
     134              :     PropertyValue getProperty(Pid propertyId) const override;
     135              :     bool setProperty(Pid propertyId, const PropertyValue&) override;
     136              :     PropertyValue propertyDefault(Pid propertyId) const override;
     137              :     void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
     138              :     using EngravingObject::undoChangeProperty;
     139              :     EngravingObject* propertyDelegate(Pid) const override;
     140              : 
     141              :     void setPlayCount(int playCount) { m_playCount = playCount; }
     142           13 :     int playCount() const { return m_playCount; }
     143              : 
     144              :     PlayCountText* playCountText() const;
     145              : 
     146              :     EngravingItem* nextSegmentElement() override;
     147              :     EngravingItem* prevSegmentElement() override;
     148              : 
     149              :     String accessibleInfo() const override;
     150              :     String accessibleExtraInfo() const override;
     151              : 
     152              :     void setSelected(bool f) override;
     153            0 :     bool needStartEditingAfterSelecting() const override { return true; }
     154            0 :     int gripsCount() const override { return 1; }
     155            0 :     Grip initialEditModeGrip() const override { return Grip::START; }
     156            0 :     Grip defaultGrip() const override { return Grip::START; }
     157              :     std::vector<PointF> gripsPositions(const EditData&) const override;
     158              : 
     159              :     void styleChanged() override;
     160              : 
     161              :     static const std::vector<BarLineTableItem> barLineTable;
     162              : 
     163              :     void calcY();
     164              : 
     165              :     struct LayoutData : public EngravingItem::LayoutData {
     166              :         double y1 = 0.0;
     167              :         double y2 = 0.0;
     168              :     };
     169              : 
     170       403827 :     DECLARE_LAYOUTDATA_METHODS(BarLine)
     171              : 
     172              : private:
     173              : 
     174              :     friend class Factory;
     175              :     BarLine(DummyParentOr<Segment> parent);
     176              :     BarLine(const BarLine&);
     177              : 
     178              :     bool m_spanStaff = false;         // span barline to next staff if true
     179              :     int m_spanFrom = 0;          // line number on start and end staves
     180              :     int m_spanTo = 0;
     181              :     BarLineType m_barLineType = BarLineType::NORMAL;
     182              : 
     183              :     ElementList m_el;          ///< fermata or other articulations
     184              : 
     185              :     int m_playCount = -1;                 // For use during copy & paste
     186              : };
     187              : } // namespace mu::engraving
        

Generated by: LCOV version 2.0-1