MuseScore  3.4
Music composition and notation
palettemodel_list.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2019 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __PALETTEMODEL_H__
21 #define __PALETTEMODEL_H__
22 
23 #include "libmscore/element.h"
24 
25 namespace Ms {
26 
27 //---------------------------------------------------------
28 // PaletteCell
29 //---------------------------------------------------------
30 
31 struct PaletteCell {
32  std::unique_ptr<Element> element;
33  QString name; // used for tool tip
34  QString tag;
35 
36  bool drawStaff { false };
37  double x { 0.0 }; // TODO: remove?
38  double y { 0.0 }; // TODO: remove?
39  double xoffset { 0.0 };
40  double yoffset { 0.0 }; // in spatium units of "gscore"
41  qreal mag { 1.0 };
42  bool readOnly { false };
43 
44  PaletteCell() = default;
45  PaletteCell(std::unique_ptr<Element> e, const QString& _name, QString _tag = QString(), qreal _mag = 1.0)
46  : element(std::move(e)), name(_name), tag(_tag), mag(_mag) {}
47  // TODO: drawStaff/needsStaff (see palette.cpp)
48 
49  };
50 
51 //---------------------------------------------------------
52 // PaletteCellIconEngine
53 //---------------------------------------------------------
54 
55 class PaletteCellIconEngine : public QIconEngine {
57 
58  public:
59  PaletteCellIconEngine(const PaletteCell* cell) : _cell(cell) {}
60 
61  QIconEngine* clone() const override { return new PaletteCellIconEngine(_cell); }
62 
63 // QList<QSize> availableSizes(QIcon::Mode /*mode*/, QIcon::State /*state*/) const override { return { QSize(64, 64) }; }
64 
65  void paint(QPainter* painter, const QRect& rect, QIcon::Mode mode, QIcon::State state) override;
66  };
67 
68 //---------------------------------------------------------
69 // PaletteModel
70 //---------------------------------------------------------
71 
72 class PaletteModel : public QAbstractListModel {
73  Q_OBJECT
74 
75  std::vector<std::unique_ptr<PaletteCell>> cells; // unique_ptr to avoid moving PaletteCell objects; needed for PaletteCellIconEngine
76 
77  public:
78  PaletteModel(QObject* parent = nullptr) : QAbstractListModel(parent) {}
79  PaletteModel(std::vector<std::unique_ptr<PaletteCell>> c, QObject* parent = nullptr)
80  : QAbstractListModel(parent), cells(std::move(c)) {}
81 
82  void insert(int idx, Element* e, const QString& name, QString tag = QString(), qreal mag = 1.0);
83  void append(Element* e, const QString& name, QString tag = QString(), qreal mag = 1.0);
84 
85  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
86  QVariant data(const QModelIndex& index, int role) const override;
87 // QVariant headerData(int section, Qt::Orientation orientation, int role) const override // TODO: headerData: palette name?
88 
89  Qt::ItemFlags flags(const QModelIndex &index) const override;
90 
91  QMimeData* mimeData(const QModelIndexList& indexes) const override;
92  QStringList mimeTypes() const override;
93 
94  static constexpr int paletteElementRole = Qt::UserRole;
95  };
96 
97 } // namespace Ms
98 
99 Q_DECLARE_METATYPE(const Ms::PaletteCell*);
100 
101 #endif
const PaletteCell * _cell
Definition: palettemodel_list.h:56
double y
Definition: palettemodel_list.h:38
qreal mag
Definition: palettemodel_list.h:41
PaletteModel(std::vector< std::unique_ptr< PaletteCell >> c, QObject *parent=nullptr)
Definition: palettemodel_list.h:79
QString name
Definition: palettemodel_list.h:33
Base class of score layout elements.
Definition: element.h:158
double x
Definition: palettemodel_list.h:37
std::vector< std::unique_ptr< PaletteCell > > cells
Definition: palettemodel_list.h:75
QString tag
Definition: palettemodel_list.h:34
std::unique_ptr< Element > element
Definition: palettemodel_list.h:32
Definition: palettemodel_list.h:72
bool drawStaff
Definition: palettemodel_list.h:36
PaletteCell(std::unique_ptr< Element > e, const QString &_name, QString _tag=QString(), qreal _mag=1.0)
Definition: palettemodel_list.h:45
PaletteCellIconEngine(const PaletteCell *cell)
Definition: palettemodel_list.h:59
Definition: palettemodel_list.h:31
double yoffset
Definition: palettemodel_list.h:40
double xoffset
Definition: palettemodel_list.h:39
Definition: palettemodel_list.h:55
Definition: aeolus.cpp:26
bool readOnly
Definition: palettemodel_list.h:42
QIconEngine * clone() const override
Definition: palettemodel_list.h:61
QByteArray mimeData() const
Definition: palettetree.cpp:350
PaletteModel(QObject *parent=nullptr)
Definition: palettemodel_list.h:78
PaletteCell()=default