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 :
23 : #pragma once
24 :
25 : #include "api/apiobject.h"
26 : #include "async/asyncable.h"
27 :
28 : #include "modularity/ioc.h"
29 : #include "interactive/iinteractive.h"
30 : #include "interactive/iplatforminteractive.h"
31 :
32 : namespace muse::interactive {
33 : class InteractiveApi : public api::ApiObject, public async::Asyncable
34 : {
35 : Q_OBJECT
36 :
37 : GlobalInject<IPlatformInteractive> platformInteractive;
38 : ContextInject<IInteractive> interactive = { this };
39 :
40 : public:
41 : explicit InteractiveApi(api::IApiEngine* e);
42 :
43 : /** APIDOC
44 : * Question buttons
45 : * @global
46 : * @enum
47 : */
48 : enum ButtonCode {
49 : Ok = int(IInteractive::Button::Ok),
50 : Continue = int(IInteractive::Button::Continue),
51 : RestoreDefaults = int(IInteractive::Button::RestoreDefaults),
52 : Reset = int(IInteractive::Button::Reset),
53 : Apply = int(IInteractive::Button::Apply),
54 : Help = int(IInteractive::Button::Help),
55 : Discard = int(IInteractive::Button::Discard),
56 : Cancel = int(IInteractive::Button::Cancel),
57 : Close = int(IInteractive::Button::Close),
58 : Ignore = int(IInteractive::Button::Ignore),
59 : Retry = int(IInteractive::Button::Retry),
60 : Abort = int(IInteractive::Button::Abort),
61 : NoToAll = int(IInteractive::Button::NoToAll),
62 : No = int(IInteractive::Button::No),
63 : YesToAll = int(IInteractive::Button::YesToAll),
64 : Yes = int(IInteractive::Button::Yes),
65 : Open = int(IInteractive::Button::Open),
66 : DontSave = int(IInteractive::Button::DontSave),
67 : SaveAll = int(IInteractive::Button::SaveAll),
68 : Save = int(IInteractive::Button::Save),
69 : Next = int(IInteractive::Button::Next),
70 : Back = int(IInteractive::Button::Back),
71 : Select = int(IInteractive::Button::Select),
72 : Clear = int(IInteractive::Button::Clear),
73 : Done = int(IInteractive::Button::Done),
74 : };
75 0 : Q_ENUM(ButtonCode);
76 :
77 : Q_INVOKABLE QJSValue info(const QString& contentTitle, const QString& text);
78 : Q_INVOKABLE QJSValue warning(const QString& contentTitle, const QString& text);
79 : Q_INVOKABLE QJSValue error(const QString& contentTitle, const QString& text);
80 :
81 : Q_INVOKABLE QJSValue question(const QString& contentTitle, const QString& text, const QJSValueList& buttons);
82 :
83 : Q_INVOKABLE void openUrl(const QString& url);
84 :
85 : private:
86 : std::vector<muse::IInteractive::Button> buttons(const QJSValueList& buttons) const;
87 : };
88 : }
|