1 /* This file is part of the KDE project
2  * Copyright 2007 Marijn Kruisselbrink <mkruisselbrink@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #include "CreateChordCommand.h"
20 
21 #include "../core/VoiceBar.h"
22 #include "../core/Chord.h"
23 #include "../MusicShape.h"
24 
25 #include <klocalizedstring.h>
26 
27 using namespace MusicCore;
28 
29 
CreateChordCommand(MusicShape * shape,VoiceBar * voiceBar,Staff * staff,Duration duration,int before,int pitch,int accidentals)30 CreateChordCommand::CreateChordCommand(MusicShape* shape, VoiceBar* voiceBar, Staff* staff, Duration duration, int before, int pitch, int accidentals)
31     : m_shape(shape), m_voiceBar(voiceBar), m_before(before)
32 {
33     setText(kundo2_i18n("Add chord"));
34     m_chord = new Chord(staff, duration);
35     m_chord->addNote(staff, pitch, accidentals);
36 }
37 
CreateChordCommand(MusicShape * shape,VoiceBar * voiceBar,Staff * staff,Duration duration,int before)38 CreateChordCommand::CreateChordCommand(MusicShape* shape, VoiceBar* voiceBar, Staff* staff, Duration duration, int before)
39     : m_shape(shape), m_voiceBar(voiceBar), m_before(before)
40 {
41     setText(kundo2_i18n("Add rest"));
42     m_chord = new Chord(staff, duration);
43 }
44 
redo()45 void CreateChordCommand::redo()
46 {
47     m_voiceBar->insertElement(m_chord, m_before);
48     m_shape->engrave();
49     m_shape->update();
50 
51 }
52 
undo()53 void CreateChordCommand::undo()
54 {
55     m_voiceBar->removeElement(m_chord, false);
56     m_shape->engrave();
57     m_shape->update();
58 }
59