1 //============================================================================= 2 // MuseScore 3 // Music Composition & Notation 4 // 5 // Copyright (C) 2002-2014 Werner Schweer 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 // as published by the Free Software Foundation and appearing in 10 // the file LICENCE.GPL 11 //============================================================================= 12 13 #ifndef __INSTRWIDGET_H__ 14 #define __INSTRWIDGET_H__ 15 16 #include "ui_instrwidget.h" 17 #include "libmscore/clef.h" 18 #include "libmscore/instrtemplate.h" 19 20 class QTreeWidgetItem; 21 22 namespace Ms { 23 24 //class EditInstrument; 25 class InstrumentTemplate; 26 class Instrument; 27 class Part; 28 class Staff; 29 class StaffType; 30 class Score; 31 class InstrumentGenre; 32 class ScoreOrder; 33 class ScoreOrderList; 34 35 enum class ListItemOp : char { KEEP, I_DELETE, ADD, UPDATE }; 36 enum { PART_LIST_ITEM = QTreeWidgetItem::UserType, STAFF_LIST_ITEM }; 37 38 //--------------------------------------------------------- 39 // ScoreOrderListModel 40 //--------------------------------------------------------- 41 42 class ScoreOrderListModel : public QAbstractListModel { 43 private: 44 ScoreOrderList* _scoreOrders; 45 46 public: 47 ScoreOrderListModel(ScoreOrderList* data, QObject* parent=nullptr); 48 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 49 int rowCount(const QModelIndex& parent = QModelIndex()) const; 50 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; 51 void rebuildData(); 52 }; 53 54 //--------------------------------------------------------- 55 // ScoreOrderFilterProxyModel 56 //--------------------------------------------------------- 57 58 class ScoreOrderFilterProxyModel : public QSortFilterProxyModel { 59 private: 60 ScoreOrderList* _scoreOrders; 61 ScoreOrder* _customizedOrder { nullptr }; 62 63 public: 64 ScoreOrderFilterProxyModel(ScoreOrderList* data, QObject* parent=nullptr); 65 void setCustomizedOrder(ScoreOrder* order); 66 67 protected: 68 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 69 }; 70 71 //--------------------------------------------------------- 72 // PartListItem 73 //--------------------------------------------------------- 74 75 class PartListItem : public QTreeWidgetItem { 76 private: 77 QString _name; 78 bool soloist; 79 80 public: 81 ListItemOp op; 82 Part* part; 83 const InstrumentTemplate* it; 84 85 PartListItem(Part* p, QTreeWidget* lv); 86 PartListItem(const InstrumentTemplate* i); 87 PartListItem(const InstrumentTemplate* i, QTreeWidget* lv); 88 PartListItem(const InstrumentTemplate* i, QTreeWidget* lv, QTreeWidgetItem* prv); 89 QString id() const; 90 QString name() const; 91 bool visible() const; 92 void setVisible(bool val); 93 void updateClefs(); 94 void setSoloist(bool soloist); 95 bool isSoloist() const; 96 }; 97 98 //--------------------------------------------------------- 99 // StaffListItem 100 //--------------------------------------------------------- 101 102 class StaffListItem : public QObject, public QTreeWidgetItem { 103 Q_OBJECT 104 int _partIdx; 105 bool _linked; 106 ClefTypeList _defaultClefType; // clef for "normal" stafftype 107 ClefTypeList _clefType; // actual clef 108 QComboBox* _staffTypeCombo { nullptr }; 109 Staff* _staff { 0 }; 110 ListItemOp _op { ListItemOp::KEEP }; 111 static int customStandardIdx; 112 static int customPercussionIdx; 113 static int customTablatureIdx; 114 static constexpr int CUSTOM_STAFF_TYPE_IDX = -1000; 115 116 int staffTypeIdx(int idx) const; 117 118 private slots: 119 void staffTypeChanged(int); 120 121 public: 122 StaffListItem(); 123 StaffListItem(PartListItem* li); 124 partIdx()125 int partIdx() const { return _partIdx; } 126 void setPartIdx(int val); 127 128 void setClefType(const ClefTypeList& val); clefType()129 const ClefTypeList& clefType() const { return _clefType; } 130 setDefaultClefType(const ClefTypeList & val)131 void setDefaultClefType(const ClefTypeList& val) { _defaultClefType = val; } defaultClefType()132 const ClefTypeList& defaultClefType() const { return _defaultClefType; } 133 134 void setLinked(bool val); linked()135 bool linked() const { return _linked; } 136 void setStaffType(const StaffType*); 137 void setStaffType(int); 138 const StaffType* staffType() const; 139 int staffTypeIdx() const; 140 void initStaffTypeCombo(bool forceRecreate = false); 141 staffTypeCombo()142 QComboBox* staffTypeCombo() { return _staffTypeCombo; } 143 staff()144 Staff* staff() const { return _staff; } setStaff(Staff * s)145 void setStaff(Staff* s) { _staff = s; } op()146 ListItemOp op() const { return _op; } setOp(ListItemOp v)147 void setOp(ListItemOp v) { _op = v; } 148 }; 149 150 //--------------------------------------------------------- 151 // InstrumentTemplateListItem 152 //--------------------------------------------------------- 153 154 class InstrumentTemplateListItem : public QTreeWidgetItem { 155 InstrumentTemplate* _instrumentTemplate; 156 QString _group; 157 158 public: 159 InstrumentTemplateListItem(QString group, QTreeWidget* parent); 160 InstrumentTemplateListItem(InstrumentTemplate* i, InstrumentTemplateListItem* parent); 161 InstrumentTemplateListItem(InstrumentTemplate* i, QTreeWidget* parent); 162 instrumentTemplate()163 InstrumentTemplate* instrumentTemplate() const { return _instrumentTemplate; } 164 virtual QString text(int col) const; 165 }; 166 167 168 //--------------------------------------------------------- 169 // InstrumentsWidget 170 //--------------------------------------------------------- 171 172 class InstrumentsWidget : public QWidget, public Ui::InstrumentsWidget { 173 Q_OBJECT 174 175 ScoreOrderListModel* _model; 176 ScoreOrderFilterProxyModel* _filter; 177 int findPrvItem(PartListItem* pli, bool insert, int number=-1); 178 QTreeWidgetItem* movePartItem(int oldPos, int newPos); 179 180 private slots: 181 void on_instrumentList_itemSelectionChanged(); 182 void on_instrumentList_itemActivated(QTreeWidgetItem* item, int); 183 void on_partiturList_itemSelectionChanged(); 184 void on_addButton_clicked(); 185 void on_removeButton_clicked(); 186 void on_upButton_clicked(); 187 void on_downButton_clicked(); 188 StaffListItem* on_addStaffButton_clicked(); 189 void on_addLinkedStaffButton_clicked(); 190 void on_makeSoloistButton_clicked(); 191 void on_scoreOrderComboBox_activated(int index); 192 void on_instrumentSearch_textChanged(const QString &); 193 void on_instrumentGenreFilter_currentIndexChanged(int); 194 void filterInstrumentsByGenre(QTreeWidget *, QString); 195 void sortInstruments(); 196 void updateScoreOrder(); 197 198 protected: 199 virtual void changeEvent(QEvent*); 200 void retranslate(); 201 202 public slots: 203 void buildTemplateList(); 204 205 signals: 206 void completeChanged(bool); 207 208 public: 209 InstrumentsWidget(QWidget* parent = 0); 210 void genPartList(Score*); 211 void updatePartIdx(); 212 void init(); 213 void setMakeSoloistButtonText(); 214 void createInstruments(Score*); 215 void numberInstrumentNames(Score*); 216 void setScoreOrder(ScoreOrder* order); 217 ScoreOrder* getScoreOrder() const; 218 void setBracketsAndBarlines(Score*); 219 bool isScoreOrder(const ScoreOrder* order) const; 220 QTreeWidget* getPartiturList(); 221 }; 222 223 extern void populateInstrumentList(QTreeWidget* instrumentList); 224 extern void populateGenreCombo(QComboBox* combo); 225 226 } // namespace Ms 227 228 extern QList<Ms::InstrumentGenre *> instrumentGenres; 229 230 #endif 231 232