Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #ifndef MUSE_UI_INAVIGATION_H
23 : #define MUSE_UI_INAVIGATION_H
24 :
25 : #include <tuple>
26 : #include <memory>
27 : #include <functional>
28 : #include <QString>
29 : #include <QList>
30 : #include <QVariantMap>
31 :
32 : #include "async/channel.h"
33 : #include "async/notification.h"
34 :
35 : class QWindow;
36 : class QQuickItem;
37 :
38 : namespace muse::ui {
39 : class INavigationSection;
40 : class INavigationPanel;
41 : class INavigationControl;
42 :
43 : class INavigation
44 : {
45 : public:
46 560 : virtual ~INavigation() = default;
47 :
48 : struct Event
49 : {
50 : //! NOTE Please sync with view/NavigationEvent::Type
51 : enum Type {
52 : Undefined = 0,
53 : Left,
54 : Right,
55 : Up,
56 : Down,
57 : Trigger,
58 : Escape,
59 :
60 : // Internal events
61 : AboutActive // sending before activation
62 : };
63 :
64 : Type type = Undefined;
65 : bool accepted = false;
66 : QVariantMap data; // additional data
67 :
68 37 : Event(Type t)
69 37 : : type(t) {}
70 :
71 37 : static std::shared_ptr<Event> make(Type t) { return std::make_shared<Event>(t); }
72 : };
73 : using EventPtr = std::shared_ptr<Event>;
74 :
75 : struct Index
76 : {
77 : int column = -1;
78 : int row = -1;
79 :
80 188 : void setOrder(int n) { column = n; }
81 1120 : int order() const { return column; }
82 :
83 0 : inline bool operator ==(const Index& idx) const { return column == idx.column && row == idx.row; }
84 :
85 0 : std::string to_string() const { return std::string("[") + std::to_string(row) + "," + std::to_string(column) + "]"; }
86 : };
87 :
88 : enum class ActivationType {
89 : None,
90 : ByMouse
91 : };
92 :
93 : virtual QString name() const = 0;
94 :
95 : virtual const Index& index() const = 0;
96 : virtual void setIndex(const Index& index) = 0;
97 : virtual async::Channel<Index> indexChanged() const = 0;
98 :
99 : virtual bool enabled() const = 0;
100 : virtual async::Channel<bool> enabledChanged() const = 0;
101 :
102 : virtual bool active() const = 0;
103 : virtual void setActive(bool arg) = 0;
104 : virtual async::Channel<bool> activeChanged() const = 0;
105 :
106 : virtual QWindow* window() const = 0;
107 : virtual QQuickItem* visualItem() const = 0;
108 :
109 : virtual void onEvent(EventPtr e) = 0;
110 : };
111 :
112 : class INavigationPanel;
113 : class INavigationControl : public INavigation
114 : {
115 : public:
116 372 : virtual ~INavigationControl() = default;
117 :
118 : virtual INavigationPanel* panel() const = 0;
119 :
120 : virtual void trigger() = 0;
121 : virtual async::Notification triggered() const = 0;
122 :
123 : virtual void requestActive(bool enableHighlight = false) = 0;
124 : };
125 :
126 : class INavigationSection;
127 : class INavigationPanel : public INavigation
128 : {
129 : public:
130 124 : virtual ~INavigationPanel() = default;
131 :
132 : //! NOTE Please sync with view/NavigationPanel::Direction
133 : enum class Direction {
134 : Horizontal = 0,
135 : Vertical,
136 : Both
137 : };
138 :
139 : virtual INavigationSection* section() const = 0;
140 : virtual Direction direction() const = 0;
141 : virtual const std::set<INavigationControl*>& controls() const = 0;
142 : virtual async::Notification controlsListChanged() const = 0;
143 : virtual void requestActive(INavigationControl* control = nullptr, bool enableHighlight = false,
144 : INavigation::ActivationType activationType = INavigation::ActivationType::None) = 0;
145 : };
146 :
147 : using OnActiveRequested = std::function<void (INavigationSection* sec, INavigationPanel* panel, INavigationControl* ctrl,
148 : bool enableHighlight, INavigation::ActivationType activationType)>;
149 :
150 : class INavigationSection : public INavigation
151 : {
152 : public:
153 64 : virtual ~INavigationSection() = default;
154 :
155 : //! NOTE Please sync with view/NavigationSection::Type
156 : enum class Type {
157 : Regular = 0,
158 : //! NOTE If activated exclusive section, we shouldn't navigate to another section.
159 : //! Typically exclusive section - this is dialog
160 : Exclusive,
161 : //! NOTE If the type is Ignore, then the section is ignored (not registered),
162 : //! usually it is necessary to remove sections from diagnostics
163 : Ignore
164 : };
165 :
166 : virtual Type type() const = 0;
167 : virtual const std::set<INavigationPanel*>& panels() const = 0;
168 : virtual async::Notification panelsListChanged() const = 0;
169 :
170 : virtual void setOnActiveRequested(const OnActiveRequested& func) = 0;
171 : virtual void requestActive(INavigationPanel* panel = nullptr, INavigationControl* control = nullptr, bool enableHighlight = false,
172 : INavigation::ActivationType activationType = INavigation::ActivationType::None) = 0;
173 : };
174 : }
175 :
176 : #endif // MUSE_UI_INAVIGATION_H
|