1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Rosegarden
5 A MIDI and audio sequencer and musical notation editor.
6 Copyright 2000-2021 the Rosegarden development team.
7
8 Other copyrights also apply to some parts of this work. Please
9 see the AUTHORS file and individual file headers for details.
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18
19 #include "SegmentToolBox.h"
20
21 #include "CompositionView.h"
22 #include "document/RosegardenDocument.h"
23 #include "gui/general/BaseToolBox.h"
24 #include "SegmentTool.h"
25 #include "SegmentSelector.h"
26 #include "SegmentEraser.h"
27 #include "SegmentJoiner.h"
28 #include "SegmentMover.h"
29 #include "SegmentPencil.h"
30 #include "SegmentResizer.h"
31 #include "SegmentSplitter.h"
32 #include <QString>
33 #include <QMessageBox>
34
35 namespace Rosegarden
36 {
37
SegmentToolBox(CompositionView * parent,RosegardenDocument * doc)38 SegmentToolBox::SegmentToolBox(CompositionView* parent, RosegardenDocument* doc)
39 : BaseToolBox(parent),
40 m_canvas(parent),
41 m_doc(doc)
42 {}
43
createTool(QString toolName)44 SegmentTool* SegmentToolBox::createTool(QString toolName)
45 {
46 SegmentTool* tool = nullptr;
47
48 QString toolNamelc = toolName.toLower();
49
50 if (toolNamelc == SegmentPencil::ToolName())
51
52 tool = new SegmentPencil(m_canvas, m_doc);
53
54 else if (toolNamelc == SegmentEraser::ToolName())
55
56 tool = new SegmentEraser(m_canvas, m_doc);
57
58 else if (toolNamelc == SegmentMover::ToolName())
59
60 tool = new SegmentMover(m_canvas, m_doc);
61
62 else if (toolNamelc == SegmentResizer::ToolName())
63
64 tool = new SegmentResizer(m_canvas, m_doc);
65
66 else if (toolNamelc == SegmentSelector::ToolName())
67
68 tool = new SegmentSelector(m_canvas, m_doc);
69
70 else if (toolNamelc == SegmentSplitter::ToolName())
71
72 tool = new SegmentSplitter(m_canvas, m_doc);
73
74 else if (toolNamelc == SegmentJoiner::ToolName())
75
76 tool = new SegmentJoiner(m_canvas, m_doc);
77
78 else {
79 QMessageBox::critical(nullptr, tr("Rosegarden"), QString("SegmentToolBox::createTool : unrecognised toolname %1 (%2)")
80 .arg(toolName).arg(toolNamelc));
81 return nullptr;
82 }
83
84 m_tools.insert(toolName, tool);
85
86 return tool;
87 }
88
getTool(QString toolName)89 SegmentTool* SegmentToolBox::getTool(QString toolName)
90 {
91 return dynamic_cast<SegmentTool*>(BaseToolBox::getTool(toolName));
92 }
93
94 }
95