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 #include "NotationTool.h"
19 #include "misc/Debug.h"
20 
21 #include "NotationWidget.h"
22 
23 #include "misc/Strings.h"
24 
25 #include <QMenu>
26 
27 
28 namespace Rosegarden
29 {
30 
31 NotationTool::NotationTool(QString rcFileName, QString menuName,
compare(QTreeWidgetItem *,int,bool) const32                            NotationWidget *widget) :
33     BaseTool(menuName, widget),
34     m_widget(widget),
35     m_scene(nullptr),
36     m_rcFileName(rcFileName)
37 {
38 }
39 
40 NotationTool::NotationTool(NotationWidget *widget) :
41     BaseTool("", widget),
42     m_widget(widget)
43 {
44 }
45 
46 NotationTool::~NotationTool()
47 {
48     NOTATION_DEBUG << "NotationTool::~NotationTool()";
49 //    delete m_menu;
50 }
51 
52 void
53 NotationTool::ready()
54 {
55     m_widget->setCursor(Qt::ArrowCursor);
56 //!!!    m_widget->setHeightTracking(false);
57 }
58 
59 void
60 NotationTool::stow()
61 {
62 }
63 
64 void
65 NotationTool::handleLeftButtonPress(const NotationMouseEvent *) { }
66 
67 void
68 NotationTool::handleMidButtonPress(const NotationMouseEvent *) { }
69 
70 void
71 NotationTool::handleRightButtonPress(const NotationMouseEvent *)
72 {
73     showMenu();
74 }
75 
76 void
77 NotationTool::handleMouseRelease(const NotationMouseEvent *) { }
78 
79 void
80 NotationTool::handleMouseDoubleClick(const NotationMouseEvent *) { }
81 
82 FollowMode
83 NotationTool::handleMouseMove(const NotationMouseEvent *)
84 {
85     return NO_FOLLOW;
86 }
87 
88 void
89 NotationTool::handleWheelTurned(int, const NotationMouseEvent *) { }
90 
91 void
92 NotationTool::invokeInParentView(QString actionName)
93 {
94     QAction *a = findActionInParentView(actionName);
95     if (!a) {
96         RG_WARNING << "NotationTool::invokeInParentView: No action \"" << actionName
97                   << "\" found in parent view";
98     } else {
99         a->trigger();
100     }
101 }
102 
103 QAction *
104 NotationTool::findActionInParentView(QString actionName)
105 {
106     if (!m_widget) return nullptr;
107     QWidget *w = m_widget;
108     ActionFileClient *c = nullptr;
109     while (w && !(c = dynamic_cast<ActionFileClient *>(w))) {
110         w = w->parentWidget();
111     }
112     if (!c) {
113         RG_WARNING << "NotationTool::findActionInParentView: Can't find ActionFileClient in parent widget hierarchy";
114         return nullptr;
115     }
116     QAction *a = c->findAction(actionName);
117     return a;
118 }
119 
120 void
121 NotationTool::createMenu()
122 {
123     NOTATION_DEBUG << "NotationTool::createMenu() " << m_rcFileName << " - " << m_menuName;
124 
125     if (!createMenusAndToolbars(m_rcFileName)) {
126         RG_WARNING << "NotationTool::createMenu(" << m_rcFileName << "): menu creation failed";
127         m_menu = nullptr;
128         return;
129     }
130 
131     QMenu *menu = findMenu(m_menuName);
132     if (!menu) {
133         RG_WARNING << "NotationTool::createMenu(" << m_rcFileName
134                    << "): menu name "
135                    << m_menuName << "not created by RC file";
136         return;
137     }
138 
139     m_menu = menu;
140 }
141 
142 }
143 
144 
145