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::appshell {
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(muse::uicomponents::MenuItem * currentWorkspaceItem READ currentWorkspaceItem CONSTANT)
53 : Q_PROPERTY(muse::uicomponents::MenuItem * concertPitchItem READ concertPitchItem CONSTANT)
54 : Q_PROPERTY(muse::uicomponents::MenuItem * currentViewMode READ currentViewMode NOTIFY currentViewModeChanged)
55 : Q_PROPERTY(bool zoomEnabled READ zoomEnabled NOTIFY zoomEnabledChanged)
56 : Q_PROPERTY(QVariantList availableViewModeList READ availableViewModeList_property NOTIFY availableViewModeListChanged)
57 : Q_PROPERTY(QVariantList availableZoomList READ availableZoomList_property NOTIFY availableZoomListChanged)
58 : Q_PROPERTY(int currentZoomPercentage READ currentZoomPercentage WRITE setCurrentZoomPercentage NOTIFY currentZoomPercentageChanged)
59 :
60 : QML_ELEMENT
61 :
62 : muse::GlobalInject<muse::workspace::IWorkspaceConfiguration> workspaceConfiguration;
63 : muse::GlobalInject<notation::INotationConfiguration> notationConfiguration;
64 : muse::GlobalInject<muse::IGlobalConfiguration> globalConfiguration;
65 : muse::GlobalInject<muse::rcommand::ICommandsRegister> commandsRegister;
66 : muse::ContextInject<project::IProjectSession> context = { this };
67 : muse::ContextInject<muse::rcommand::ICommandsState> commandsState = { this };
68 : muse::ContextInject<muse::rcommand::ICommandDispatcher> dispatcher = { this };
69 :
70 : public:
71 : explicit NotationStatusBarModel(QObject* parent = nullptr);
72 :
73 : QString accessibilityInfo() const;
74 : muse::uicomponents::MenuItem* currentWorkspaceItem();
75 : muse::uicomponents::MenuItem* concertPitchItem();
76 : muse::uicomponents::MenuItem* currentViewMode();
77 : bool zoomEnabled() const;
78 : int currentZoomPercentage() const;
79 :
80 : Q_INVOKABLE void toggleConcertPitch();
81 : Q_INVOKABLE void setCurrentViewMode(const QString& modeCode);
82 :
83 : Q_INVOKABLE int minZoomPercentage() const;
84 : Q_INVOKABLE int maxZoomPercentage() const;
85 : Q_INVOKABLE void setCurrentZoom(const QString& zoomId);
86 : Q_INVOKABLE void zoomIn();
87 : Q_INVOKABLE void zoomOut();
88 :
89 : Q_INVOKABLE void handleMenuItem(const QString& itemId);
90 : Q_INVOKABLE void handleWorkspacesMenuItem(const QString& itemId);
91 :
92 : public slots:
93 : void setCurrentZoomPercentage(int zoomPercentage);
94 :
95 : signals:
96 : void accessibilityInfoChanged();
97 : void currentWorkspaceActionChanged();
98 : void concertPitchActionChanged();
99 : void currentViewModeChanged();
100 : void availableViewModeListChanged();
101 : void zoomEnabledChanged();
102 : void availableZoomListChanged();
103 : void currentZoomPercentageChanged();
104 :
105 : private:
106 : void classBegin() override;
107 0 : void componentComplete() override {}
108 : void init();
109 :
110 : void setNotation(const notation::INotationPtr& notation);
111 :
112 : notation::INotationPtr notation() const;
113 : notation::INotationAccessibilityPtr accessibility() const;
114 :
115 : void initAvailableViewModeList();
116 : void initAvailableZoomList();
117 :
118 : muse::uicomponents::MenuItem* makeMenuItem(const muse::rcommand::Command& command);
119 :
120 : void updateConcertPitchItem();
121 : void updateCurrentWorkspaceItem();
122 :
123 : void dispatch(const muse::rcommand::Command& command, const muse::rcommand::Params& params = {});
124 :
125 : notation::ZoomType currentZoomType() const;
126 :
127 : QList<int> possibleZoomPercentageList() const;
128 :
129 : QVariantList availableViewModeList_property();
130 : QVariantList availableZoomList_property();
131 :
132 : QVariantList menuItemListToVariantList(const muse::uicomponents::MenuItemList& list) const;
133 :
134 : notation::INotationPtr m_notation = nullptr;
135 :
136 : muse::uicomponents::MenuItem* m_currentWorkspaceItem = nullptr;
137 : muse::uicomponents::MenuItem* m_concertPitchItem = nullptr;
138 : muse::uicomponents::MenuItemList m_availableViewModeList;
139 : muse::uicomponents::MenuItemList m_availableZoomList;
140 :
141 : std::shared_ptr<muse::uicomponents::AbstractMenuModel> m_workspacesMenuModel;
142 : };
143 : }
|