1 //=============================================================================
2 //  MuseScore
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 #include "libmscore/articulation.h"
21 #include "articulationprop.h"
22 #include "libmscore/sym.h"
23 #include "libmscore/score.h"
24 #include "libmscore/chordrest.h"
25 #include "libmscore/system.h"
26 #include "libmscore/measure.h"
27 #include "libmscore/staff.h"
28 #include "libmscore/stafftype.h"
29 #include "libmscore/part.h"
30 #include "libmscore/segment.h"
31 #include "libmscore/undo.h"
32 #include "musescore.h"
33 
34 namespace Ms {
35 
36 //---------------------------------------------------------
37 //   ArticulationProperties
38 //---------------------------------------------------------
39 
ArticulationProperties(Articulation * na,QWidget * parent)40 ArticulationProperties::ArticulationProperties(Articulation* na, QWidget* parent)
41    : QDialog(parent)
42       {
43       setObjectName("ArticulationProperties");
44       setupUi(this);
45       setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
46 
47       articulation = na;
48 
49       ChordRest* cr = articulation->chordRest();
50       if (cr) {
51             Segment* segment       = cr->segment();
52             Part* part             = articulation->staff()->part();
53             Instrument* instrument = part->instrument(segment->tick());
54 
55 //      const QList<NamedEventList>& midiActions() const;
56 //      const QList<MidiArticulation>& articulation() const;
57 //      const QList<Channel>& channel() const;
58 
59             for (const Channel* a : instrument->channel()) {
60                   QString name = a->name();
61                   if (a->name().isEmpty())
62                         name = Channel::DEFAULT_NAME;
63                   channelList->addItem(qApp->translate("InstrumentsXML", name.toUtf8().data()));
64                   channelList->item(channelList->count() - 1)->setData(Qt::UserRole, name);
65                   }
66             for (const NamedEventList& el : instrument->midiActions()) {
67                   midiActionList->addItem(qApp->translate("InstrumentsXML", el.name.toUtf8().data()));
68                   midiActionList->item(midiActionList->count() - 1)->setData(Qt::UserRole, el.name);
69                   }
70             }
71 
72 #if 0
73       for (const NamedEventList& e : instrument->midiActions) {
74             midiActionList->addItem(qApp->translate("InstrumentsXML", e.name.toUtf8().data()));
75             midiActionList->item(midiActionList->count() - 1)->setData(Qt::UserRole, e.name);
76             }
77       articulationChange->setChecked(!articulation->articulationName().isEmpty());
78       midiAction->setChecked(!articulation->midiActionName().isEmpty());
79 
80       if (!articulation->articulationName().isEmpty()) {
81             QList<QListWidgetItem*> wl = articulationList
82                ->findItems(st->articulationName(), Qt::MatchExactly);
83             if (!wl.isEmpty())
84                   articulationList->setCurrentRow(articulationList->row(wl[0]));
85             }
86       if (!articulation->midiActionName().isEmpty()) {
87             QList<QListWidgetItem*> wl = midiActionList
88                ->findItems(st->midiActionName(), Qt::MatchExactly);
89             if (!wl.isEmpty())
90                   midiActionList->setCurrentRow(midiActionList->row(wl[0]));
91             }
92 #endif
93 
94       direction->setCurrentIndex(int(articulation->direction()));
95       anchor->setCurrentIndex(int(articulation->anchor()));
96 
97       connect(this, SIGNAL(accepted()), SLOT(saveValues()));
98 
99       MuseScore::restoreGeometry(this);
100       }
101 
102 //---------------------------------------------------------
103 //   saveValues
104 //---------------------------------------------------------
105 
saveValues()106 void ArticulationProperties::saveValues()
107       {
108 #if 0
109       if (articulationChange->isChecked()) {
110             QListWidgetItem* i = articulationList->currentItem();
111             if (i)
112                   staffText->setChannelName(i->data(Qt::UserRole));
113             }
114       if (midiAction->isChecked()) {
115             QListWidgetItem* i = midiActionList->currentItem();
116             if (i)
117                   staffText->setMidiActionName(i->data(Qt::UserRole));
118             }
119 #endif
120       if (int(articulation->direction()) != direction->currentIndex())
121             articulation->score()->undo(new ChangeProperty(articulation,
122                Pid::DIRECTION, direction->currentIndex()));
123 
124       if (int(articulation->anchor()) != anchor->currentIndex())
125             articulation->score()->undo(new ChangeProperty(articulation,
126                Pid::ARTICULATION_ANCHOR, anchor->currentIndex()));
127       }
128 
129 //---------------------------------------------------------
130 //   hideEvent
131 //---------------------------------------------------------
132 
hideEvent(QHideEvent * event)133 void ArticulationProperties::hideEvent(QHideEvent* event)
134       {
135       MuseScore::saveGeometry(this);
136       QDialog::hideEvent(event);
137       }
138 
139 }
140