MuseScore  3.4
Music composition and notation
palette.h
Go to the documentation of this file.
1 //=============================================================================
2 // MusE Score
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2002-2011 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 __PALETTE_H__
21 #define __PALETTE_H__
22 
23 #include "palette/palettetree.h"
24 #include "ui_paletteProperties.h"
25 #include "libmscore/sym.h"
26 
27 namespace Ms {
28 
29 class Element;
30 class Sym;
31 class XmlWriter;
32 class XmlReader;
33 class Palette;
34 
35 //---------------------------------------------------------
36 // PaletteProperties
37 //---------------------------------------------------------
38 
39 class PaletteProperties : public QDialog, private Ui::PaletteProperties {
40  Q_OBJECT
41 
43  virtual void accept();
44  virtual void hideEvent(QHideEvent*);
45  public:
46  PaletteProperties(Palette* p, QWidget* parent = 0);
47  };
48 
49 //---------------------------------------------------------
50 // PaletteScrollArea
51 //---------------------------------------------------------
52 
53 class PaletteScrollArea : public QScrollArea {
54  Q_OBJECT
56 
57  virtual void resizeEvent(QResizeEvent*);
58 
59  protected:
60  virtual void keyPressEvent(QKeyEvent* event) override;
61 
62  public:
63  PaletteScrollArea(Palette* w, QWidget* parent = 0);
64  bool restrictHeight() const { return _restrictHeight; }
65  void setRestrictHeight(bool val) { _restrictHeight = val; }
66  };
67 
68 //---------------------------------------------------------
69 // Palette
70 //---------------------------------------------------------
71 
72 class Palette : public QWidget {
73  Q_OBJECT
74 
75  QString _name;
76  QList<PaletteCell*> cells;
77  QList<PaletteCell*> dragCells; // used for filter & backup
78 
79  int hgrid;
80  int vgrid;
82  int pressedIndex = -1;
83  int dragIdx;
86 
87  qreal extraMag;
88  bool _drawGrid;
90  bool _disableElementsApply { false };
91  bool _readOnly;
93  qreal _yOffset; // in spatium units of "gscore"
94  bool filterActive { false }; // bool if filter is active
95 
97  bool _showContextMenu { true };
98 
99  virtual void paintEvent(QPaintEvent*) override;
100  virtual void mousePressEvent(QMouseEvent*) override;
101  void mouseReleaseEvent(QMouseEvent* event) override;
102  virtual void mouseMoveEvent(QMouseEvent*) override;
103  virtual void leaveEvent(QEvent*) override;
104  virtual bool event(QEvent*) override;
105  virtual void resizeEvent(QResizeEvent*) override;
106 
107  virtual void dragEnterEvent(QDragEnterEvent*) override;
108  virtual void dragMoveEvent(QDragMoveEvent*) override;
109  virtual void dropEvent(QDropEvent*) override;
110  virtual void contextMenuEvent(QContextMenuEvent*) override;
111 
112  int idx2(const QPoint&) const;
113  QRect idxRect(int) const;
114 
115  const QList<PaletteCell*>* ccp() const { return filterActive ? &dragCells : &cells; }
116  QPixmap pixmap(int cellIdx) const;
117 
118 
119  private slots:
120  void actionToggled(bool val);
121 
122  signals:
123  void boxClicked(int);
124  void changed();
125  void displayMore(const QString& paletteName);
126 
127  public:
128  Palette(QWidget* parent = 0);
129  Palette(std::unique_ptr<PalettePanel>, QWidget* parent = nullptr);
130  virtual ~Palette();
131 
132  void nextPaletteElement();
133  void prevPaletteElement();
134  void applyPaletteElement();
135  static bool applyPaletteElement(Element* element, Qt::KeyboardModifiers modifiers = 0);
136  PaletteCell* append(Element*, const QString& name, QString tag = QString(),
137  qreal mag = 1.0);
138  PaletteCell* add(int idx, Element*, const QString& name,
139  const QString tag = QString(), qreal mag = 1.0);
140 
141  void emitChanged() { emit changed(); }
142  void setGrid(int, int);
143  Element* element(int idx);
144  void setDrawGrid(bool val) { _drawGrid = val; }
145  bool drawGrid() const { return _drawGrid; }
146  bool read(const QString& path); // TODO: remove/reuse PalettePanel code
147  void write(const QString& path); // TODO: remove/reuse PalettePanel code
148  void read(XmlReader&);
149  void write(XmlWriter&) const;
150  void clear();
151  void setSelectable(bool val) { _selectable = val; }
152  bool selectable() const { return _selectable; }
153  int getSelectedIdx() const { return selectedIdx; }
154  void setSelected(int idx) { selectedIdx = idx; }
155  bool readOnly() const { return _readOnly; }
156  void setReadOnly(bool val);
157  bool disableElementsApply() const { return _disableElementsApply; }
158  void setDisableElementsApply(bool val) { _disableElementsApply = val; }
159 
160  bool systemPalette() const { return _systemPalette; }
161  void setSystemPalette(bool val);
162 
163  void setMag(qreal val);
164  qreal mag() const { return extraMag; }
165  void setYOffset(qreal val) { _yOffset = val; }
166  qreal yOffset() const { return _yOffset; }
167  int columns() const;
168  int rows() const;
169  int size() const { return filterActive ? dragCells.size() : cells.size(); }
170  PaletteCell* cellAt(int index) const { return ccp()->value(index); }
171  void setCellReadOnly(int c, bool v) { cells[c]->readOnly = v; }
172  QString name() const { return _name; }
173  void setName(const QString& s) { _name = s; }
174  int gridWidth() const { return hgrid; }
175  int gridHeight() const { return vgrid; }
176  bool moreElements() const { return _moreElements; }
177  void setMoreElements(bool val);
178  bool filter(const QString& text);
179  void setShowContextMenu(bool val) { _showContextMenu = val; }
180 
181  static qreal guiMag();
182  int gridWidthM() const { return hgrid * guiMag(); }
183  int gridHeightM() const { return vgrid * guiMag(); }
184 
185  int getCurrentIdx() { return currentIdx; }
186  void setCurrentIdx(int i) { currentIdx = i; }
187  bool isFilterActive() { return filterActive == true; }
188  QList<PaletteCell*> getDragCells() { return dragCells; }
189  virtual int heightForWidth(int) const;
190  virtual QSize sizeHint() const;
191  int idx(const QPoint&) const;
192  };
193 
194 
195 } // namespace Ms
196 #endif
QString _name
Definition: palette.h:75
qreal yOffset() const
Definition: palette.h:166
PaletteCell * cellAt(int index) const
Definition: palette.h:170
PaletteProperties(Palette *p, QWidget *parent=0)
Definition: palette.cpp:1701
int getSelectedIdx() const
Definition: palette.h:153
bool selectable() const
Definition: palette.h:152
Definition: xml.h:67
QList< PaletteCell * > cells
Definition: palette.h:76
int selectedIdx
Definition: palette.h:84
bool _restrictHeight
Definition: palette.h:55
bool systemPalette() const
Definition: palette.h:160
void setDrawGrid(bool val)
Definition: palette.h:144
bool disableElementsApply() const
Definition: palette.h:157
int gridWidth() const
Definition: palette.h:174
Definition: palette.h:53
void setYOffset(qreal val)
Definition: palette.h:165
int size() const
Definition: palette.h:169
int hgrid
Definition: palette.h:79
Base class of score layout elements.
Definition: element.h:158
bool _drawGrid
Definition: palette.h:88
QString name() const
Definition: palette.h:172
bool moreElements() const
Definition: palette.h:176
int gridWidthM() const
Definition: palette.h:182
QPoint dragStartPosition
Definition: palette.h:85
void setCurrentIdx(int i)
Definition: palette.h:186
bool restrictHeight() const
Definition: palette.h:64
bool isFilterActive()
Definition: palette.h:187
bool readOnly() const
Definition: palette.h:155
int vgrid
Definition: palette.h:80
Definition: palettemodel_list.h:31
int gridHeightM() const
Definition: palette.h:183
int getCurrentIdx()
Definition: palette.h:185
void setSelectable(bool val)
Definition: palette.h:151
void setName(const QString &s)
Definition: palette.h:173
bool _readOnly
Definition: palette.h:91
Definition: aeolus.cpp:26
qreal extraMag
Definition: palette.h:87
int gridHeight() const
Definition: palette.h:175
bool _selectable
Definition: palette.h:89
Definition: xml.h:218
void setCellReadOnly(int c, bool v)
Definition: palette.h:171
void setRestrictHeight(bool val)
Definition: palette.h:65
bool _systemPalette
Definition: palette.h:92
QList< PaletteCell * > getDragCells()
Definition: palette.h:188
Definition: xmlwriter.h:26
virtual void accept()
Definition: palette.cpp:1724
void emitChanged()
Definition: palette.h:141
qreal _yOffset
Definition: palette.h:93
const QList< PaletteCell * > * ccp() const
Definition: palette.h:115
Definition: xmlreader.h:28
Definition: palette.h:72
virtual void hideEvent(QHideEvent *)
Definition: palette.cpp:1739
void setSelected(int idx)
Definition: palette.h:154
void setShowContextMenu(bool val)
Definition: palette.h:179
int currentIdx
Definition: palette.h:81
int dragIdx
Definition: palette.h:83
Definition: palette.h:39
bool _moreElements
Definition: palette.h:96
QList< PaletteCell * > dragCells
Definition: palette.h:77
void setDisableElementsApply(bool val)
Definition: palette.h:158
qreal mag() const
Definition: palette.h:164
Palette * palette
Definition: palette.h:42
bool drawGrid() const
Definition: palette.h:145