LCOV - code coverage report
Current view: top level - src/palette/internal - palette.h Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 26 0
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              : #ifndef MU_PALETTE_PALETTE_H
      23              : #define MU_PALETTE_PALETTE_H
      24              : 
      25              : #include <functional>
      26              : 
      27              : #include "palettecell.h"
      28              : 
      29              : #include "modularity/ioc.h"
      30              : #include "../ipaletteconfiguration.h"
      31              : #include "interactive/iinteractive.h"
      32              : #include "engraving/rendering/isinglerenderer.h"
      33              : #include "engraving/ipalettescoreprovider.h"
      34              : #include "engraving/dom/engravingitem.h"
      35              : 
      36              : #include "types/translatablestring.h"
      37              : 
      38              : namespace mu::engraving {
      39              : enum class ActionIconType : signed char;
      40              : class XmlWriter;
      41              : class XMLReader;
      42              : }
      43              : 
      44              : namespace mu::palette {
      45              : class Palette;
      46              : using PalettePtr = std::shared_ptr<Palette>;
      47              : 
      48              : class Palette : public QObject, public muse::Contextable
      49              : {
      50              :     Q_GADGET
      51              : 
      52              :     muse::GlobalInject<IPaletteConfiguration> configuration;
      53              :     muse::GlobalInject<engraving::rendering::ISingleRenderer> engravingRender;
      54              :     muse::ContextInject<muse::IInteractive> interactive = { this };
      55              :     muse::ContextInject<engraving::IPaletteScoreProvider> paletteScoreProvider = { this };
      56              : 
      57              : public:
      58              :     enum class Type {
      59              :         Unknown = 0,
      60              :         Clef,
      61              :         KeySig,
      62              :         TimeSig,
      63              :         Bracket,
      64              :         Accidental,
      65              :         Articulation,
      66              :         Ornament,
      67              :         Breath,
      68              :         GraceNote,
      69              :         NoteHead,
      70              :         Line,
      71              :         BarLine,
      72              :         Arpeggio,
      73              :         Tremolo,
      74              :         Text,
      75              :         Tempo,
      76              :         Dynamic,
      77              :         Fingering,
      78              :         Repeat,
      79              :         FretboardDiagram,
      80              :         Accordion,
      81              :         BagpipeEmbellishment,
      82              :         Layout,
      83              :         Beam,
      84              :         Guitar,
      85              :         Keyboard,
      86              :         Pitch,
      87              :         Harp,
      88              :         StringTunings,
      89              :         Playback,
      90              :         Handbells,
      91              :         Custom
      92              :     };
      93            0 :     Q_ENUM(Type)
      94              : 
      95              :     explicit Palette(const muse::modularity::ContextPtr& iocCtx, Type t = Type::Custom, QObject* parent = nullptr);
      96              :     ~Palette();
      97              : 
      98              :     QString id() const;
      99              : 
     100            0 :     const QString& name() const { return m_name; }
     101            0 :     void setName(const QString& str) { m_name = str; }
     102              : 
     103              :     QString translatedName() const;
     104              :     void retranslate();
     105              : 
     106            0 :     Type type() const { return m_type; }
     107            0 :     void setType(Type t) { m_type = t; }
     108              : 
     109              :     Type contentType() const;
     110              : 
     111              :     // TODO: Remove QString overload
     112              :     PaletteCellPtr insertElement(size_t idx, engraving::ElementPtr element, const QString& name, qreal mag = 1.0,
     113              :                                  const QPointF& offset = QPointF(), const QString& tag = "");
     114              :     PaletteCellPtr insertElement(size_t idx, engraving::ElementPtr element, const muse::TranslatableString& name, qreal mag = 1.0,
     115              :                                  const QPointF& offset = QPointF(), const QString& tag = "");
     116              :     PaletteCellPtr insertActionIcon(size_t idx, engraving::ActionIconType type, double mag = 1.0);
     117              :     // TODO: Remove QString overload
     118              :     PaletteCellPtr appendElement(engraving::ElementPtr element, const QString& name, qreal mag = 1.0,
     119              :                                  const QPointF& offset = QPointF(), const QString& tag = "");
     120              :     PaletteCellPtr appendElement(engraving::ElementPtr element, const muse::TranslatableString& name, qreal mag = 1.0,
     121              :                                  const QPointF& offset = QPointF(), const QString& tag = "");
     122              :     PaletteCellPtr appendActionIcon(engraving::ActionIconType type, double mag = 1.0);
     123              : 
     124              :     bool insertCell(size_t idx, PaletteCellPtr cell);
     125              :     bool insertCells(size_t idx, std::vector<PaletteCellPtr> cells);
     126              :     bool removeCell(PaletteCellPtr cell);
     127              :     bool removeCells(std::vector<PaletteCellPtr> cells);
     128              : 
     129            0 :     const std::vector<PaletteCellPtr>& cells() const { return m_cells; }
     130            0 :     int cellsCount() const { return int(m_cells.size()); }
     131              :     bool empty() const { return m_cells.empty(); }
     132              : 
     133            0 :     PaletteCellPtr cellAt(int idx) { return m_cells.at(idx); }
     134            0 :     PaletteCellConstPtr cellAt(int idx) const { return m_cells.at(idx); }
     135              :     PaletteCellPtr cellAt(size_t idx) { return m_cells.at(idx); }
     136              :     PaletteCellConstPtr cellAt(size_t idx) const { return m_cells.at(idx); }
     137              : 
     138              :     int indexOfCell(const PaletteCell& cell, bool matchName = true) const;
     139              : 
     140              :     PaletteCellPtr takeCell(size_t idx);
     141              :     std::vector<PaletteCellPtr> takeCells(size_t idx, size_t count);
     142            0 :     void clear() { m_cells.clear(); }
     143              : 
     144            0 :     qreal yOffset() const { return m_yOffset; }
     145            0 :     void setYOffset(qreal val) { m_yOffset = val; }
     146              : 
     147            0 :     qreal mag() const { return m_mag; }
     148            0 :     void setMag(qreal val) { m_mag = val; }
     149              : 
     150            0 :     bool drawGrid() const { return m_drawGrid; }
     151            0 :     void setDrawGrid(bool val) { m_drawGrid = val; }
     152              : 
     153            0 :     QSize gridSize() const { return m_gridSize; }
     154            0 :     void setGridSize(QSize s) { m_gridSize = s; }
     155            0 :     void setGridSize(int w, int h) { m_gridSize = QSize(w, h); }
     156              : 
     157              :     QSize scaledGridSize() const;
     158              : 
     159            0 :     bool isVisible() const { return m_isVisible; }
     160            0 :     void setVisible(bool val) { m_isVisible = val; }
     161              : 
     162            0 :     bool isCustom() const { return m_type == Type::Custom; }
     163              : 
     164            0 :     bool isEditable() const { return m_isEditable; }
     165            0 :     void setEditable(bool val) { m_isEditable = val; }
     166              : 
     167            0 :     bool isExpanded() const { return m_isExpanded; }
     168            0 :     void setExpanded(bool val) { m_isExpanded = val; }
     169              : 
     170              :     bool read(engraving::XmlReader&, bool pasteMode);
     171              :     void write(engraving::XmlWriter&, bool pasteMode) const;
     172              :     static PalettePtr fromMimeData(const QByteArray& data, const muse::modularity::ContextPtr& iocCtx);
     173              :     QByteArray toMimeData() const;
     174              : 
     175              :     bool readFromFile(const QString& path);
     176              :     bool writeToFile(const QString& path) const;
     177              : 
     178              :     static constexpr const char* mimeDataFormat = "application/musescore/palette";
     179              : 
     180              : private:
     181              :     void showWritingPaletteError(const QString& path) const;
     182              : 
     183              :     Type guessType() const;
     184              : 
     185              :     std::function<void(PaletteCellPtr)> cellHandlerByPaletteType(const Type& type) const;
     186              : 
     187              :     QString m_id;
     188              :     QString m_name;
     189              :     Type m_type;
     190              : 
     191              :     std::vector<PaletteCellPtr> m_cells;
     192              : 
     193              :     qreal m_yOffset = 0.0; // in spatium units of "gscore"
     194              :     qreal m_mag = 1.0;
     195              :     QSize m_gridSize = QSize(64, 64);
     196              :     bool m_drawGrid = false;
     197              : 
     198              :     bool m_isVisible = true;
     199              :     bool m_isEditable = true;
     200              :     bool m_isExpanded = false;
     201              : };
     202              : }
     203              : 
     204              : #endif // MU_PALETTE_PALETTE_H
        

Generated by: LCOV version 2.0-1