Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-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 :
23 : #pragma once
24 :
25 : #include <QObject>
26 : #include <QQmlParserStatus>
27 : #include <qqmlintegration.h>
28 :
29 : #include "async/asyncable.h"
30 :
31 : #include "uicomponents/qml/Muse/UiComponents/menuitem.h"
32 : #include "uicomponents/qml/Muse/UiComponents/abstractmenumodel.h"
33 :
34 : #include "modularity/ioc.h"
35 : #include "rcommand/icommanddispatcher.h"
36 : #include "rcommand/icommandsregister.h"
37 : #include "rcommand/icommandsstate.h"
38 : #include "workspace/iworkspaceconfiguration.h"
39 : #include "notation/inotationconfiguration.h"
40 : #include "project/iprojectsession.h"
41 : #include "global/iglobalconfiguration.h"
42 :
43 : #include "rcommand/commandtypes.h"
44 :
45 : namespace mu::notation {
46 : class NotationStatusBarModel : public QObject, public QQmlParserStatus, public muse::Contextable, public muse::async::Asyncable
47 : {
48 : Q_OBJECT
49 : Q_INTERFACES(QQmlParserStatus)
50 :
51 : Q_PROPERTY(QString accessibilityInfo READ accessibilityInfo NOTIFY accessibilityInfoChanged)
52 : Q_PROPERTY(bool isWorkspaceAvailable READ isWorkspaceAvailable CONSTANT)
53 : Q_PROPERTY(muse::uicomponents::MenuItem * currentWorkspaceItem READ currentWorkspaceItem CONSTANT)
54 : Q_PROPERTY(muse::uicomponents::MenuItem * concertPitchItem READ concertPitchItem CONSTANT)
55 : Q_PROPERTY(muse::uicomponents::MenuItem * currentViewMode READ currentViewMode NOTIFY currentViewModeChanged)
56 : Q_PROPERTY(bool zoomEnabled READ zoomEnabled NOTIFY zoomEnabledChanged)
57 : Q_PROPERTY(QVariantList availableViewModeList READ availableViewModeList_property NOTIFY availableViewModeListChanged)
58 : Q_PROPERTY(QVariantList availableZoomList READ availableZoomList_property NOTIFY availableZoomListChanged)
59 : Q_PROPERTY(int currentZoomPercentage READ currentZoomPercentage WRITE setCurrentZoomPercentage NOTIFY currentZoomPercentageChanged)
60 :
61 : QML_ELEMENT
62 :
63 : muse::GlobalInject<muse::workspace::IWorkspaceConfiguration> workspaceConfiguration;
64 : muse::GlobalInject<INotationConfiguration> notationConfiguration;
65 : muse::GlobalInject<muse::IGlobalConfiguration> globalConfiguration;
66 : muse::GlobalInject<muse::rcommand::ICommandsRegister> commandsRegister;
67 : muse::ContextInject<project::IProjectSession> context = { this };
68 : muse::ContextInject<muse::rcommand::ICommandsState> commandsState = { this };
69 : muse::ContextInject<muse::rcommand::ICommandDispatcher> dispatcher = { this };
70 :
71 : public:
72 : explicit NotationStatusBarModel(QObject* parent = nullptr);
73 :
74 : QString accessibilityInfo() const;
75 : bool isWorkspaceAvailable() const;
76 : muse::uicomponents::MenuItem* currentWorkspaceItem();
77 : muse::uicomponents::MenuItem* concertPitchItem();
78 : muse::uicomponents::MenuItem* currentViewMode();
79 : bool zoomEnabled() const;
80 : int currentZoomPercentage() const;
81 :
82 : Q_INVOKABLE void toggleConcertPitch();
83 : Q_INVOKABLE void setCurrentViewMode(const QString& modeCode);
84 :
85 : Q_INVOKABLE int minZoomPercentage() const;
86 : Q_INVOKABLE int maxZoomPercentage() const;
87 : Q_INVOKABLE void setCurrentZoom(const QString& zoomId);
88 : Q_INVOKABLE void zoomIn();
89 : Q_INVOKABLE void zoomOut();
90 :
91 : Q_INVOKABLE void handleMenuItem(const QString& itemId);
92 : Q_INVOKABLE void handleWorkspacesMenuItem(const QString& itemId);
93 :
94 : public slots:
95 : void setCurrentZoomPercentage(int zoomPercentage);
96 :
97 : signals:
98 : void accessibilityInfoChanged();
99 : void currentWorkspaceActionChanged();
100 : void concertPitchActionChanged();
101 : void currentViewModeChanged();
102 : void availableViewModeListChanged();
103 : void zoomEnabledChanged();
104 : void availableZoomListChanged();
105 : void currentZoomPercentageChanged();
106 :
107 : private:
108 : void classBegin() override;
109 0 : void componentComplete() override {}
110 : void init();
111 :
112 : void setNotation(const notation::INotationPtr& notation);
113 :
114 : notation::INotationPtr notation() const;
115 : notation::INotationAccessibilityPtr accessibility() const;
116 :
117 : void initAvailableViewModeList();
118 : void initAvailableZoomList();
119 :
120 : muse::uicomponents::MenuItem* makeMenuItem(const muse::rcommand::Command& command);
121 :
122 : void updateConcertPitchItem();
123 : void updateCurrentWorkspaceItem();
124 :
125 : void dispatch(const muse::rcommand::Command& command, const muse::rcommand::Params& params = {});
126 :
127 : notation::ZoomType currentZoomType() const;
128 :
129 : QList<int> possibleZoomPercentageList() const;
130 :
131 : QVariantList availableViewModeList_property();
132 : QVariantList availableZoomList_property();
133 :
134 : QVariantList menuItemListToVariantList(const muse::uicomponents::MenuItemList& list) const;
135 :
136 : notation::INotationPtr m_notation = nullptr;
137 :
138 : muse::uicomponents::MenuItem* m_currentWorkspaceItem = nullptr;
139 : muse::uicomponents::MenuItem* m_concertPitchItem = nullptr;
140 : muse::uicomponents::MenuItemList m_availableViewModeList;
141 : muse::uicomponents::MenuItemList m_availableZoomList;
142 :
143 : std::shared_ptr<muse::uicomponents::AbstractMenuModel> m_workspacesMenuModel;
144 : };
145 : }
|