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 #define RG_MODULE_STRING "[MatrixToolBox]"
19 
20 #include "MatrixToolBox.h"
21 #include "MatrixTool.h"
22 #include "MatrixWidget.h"
23 #include "MatrixPainter.h"
24 #include "MatrixEraser.h"
25 #include "MatrixSelector.h"
26 #include "MatrixMover.h"
27 #include "MatrixResizer.h"
28 #include "MatrixScene.h"
29 #include "MatrixVelocity.h"
30 #include "misc/Debug.h"
31 
32 #include <QString>
33 #include <QMessageBox>
34 
35 namespace Rosegarden
36 {
37 
MatrixToolBox(MatrixWidget * parent)38 MatrixToolBox::MatrixToolBox(MatrixWidget *parent) :
39     BaseToolBox(parent),
40     m_widget(parent),
41     m_scene(nullptr)
42 {
43 }
44 
~MatrixToolBox()45 MatrixToolBox::~MatrixToolBox()
46 {
47     RG_DEBUG << "MatrixToolBox::~MatrixToolBox()";
48 }
49 
50 BaseTool *
createTool(QString toolName)51 MatrixToolBox::createTool(QString toolName)
52 {
53     MatrixTool *tool = nullptr;
54 
55     QString toolNamelc = toolName.toLower();
56 
57     if (toolNamelc == MatrixPainter::ToolName())
58 
59         tool = new MatrixPainter(m_widget);
60 
61     else if (toolNamelc == MatrixEraser::ToolName())
62 
63         tool = new MatrixEraser(m_widget);
64 
65     else if (toolNamelc == MatrixSelector::ToolName())
66 
67         tool = new MatrixSelector(m_widget);
68 
69     else if (toolNamelc == MatrixMover::ToolName())
70 
71         tool = new MatrixMover(m_widget);
72 
73     else if (toolNamelc == MatrixResizer::ToolName())
74 
75         tool = new MatrixResizer(m_widget);
76 
77     else if (toolNamelc == MatrixVelocity::ToolName())
78 
79         tool = new MatrixVelocity(m_widget);
80 
81     else {
82         QMessageBox::critical(nullptr, tr("Rosegarden"), QString("MatrixToolBox::createTool : unrecognised toolname %1 (%2)")
83                            .arg(toolName).arg(toolNamelc));
84         return nullptr;
85     }
86 
87     m_tools.insert(toolName, tool);
88 
89     if (m_scene) {
90         tool->setScene(m_scene);
91         connect(m_scene, &MatrixScene::eventRemoved,
92                 tool, &MatrixTool::handleEventRemoved);
93     }
94 
95     return tool;
96 }
97 
98 void
setScene(MatrixScene * scene)99 MatrixToolBox::setScene(MatrixScene *scene)
100 {
101     m_scene = scene;
102 
103     for (QHash<QString, BaseTool *>::iterator i = m_tools.begin();
104          i != m_tools.end(); ++i) {
105         MatrixTool *nt = dynamic_cast<MatrixTool *>(*i);
106         if (nt) {
107             nt->setScene(scene);
108             connect(scene, &MatrixScene::eventRemoved,
109                     nt, &MatrixTool::handleEventRemoved);
110         }
111     }
112 }
113 
114 }
115