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 "engraving/style/style.h"
26 :
27 : namespace mu::engraving {
28 : class Score;
29 : }
30 :
31 : namespace mu::engraving::apiv1 {
32 : //---------------------------------------------------------
33 : // MStyle
34 : /// Provides an access to score style settings.
35 : /// Style settings for a score can be obtained by
36 : /// querying the \ref Score.style property.
37 : ///
38 : /// Usage example:
39 : /// \code
40 : /// var style = curScore.style;
41 : /// var genClef = style.value("genClef"); // retrieves style setting on clefs generation, true by default
42 : /// style.setValue("genClef", false); // disables generating clefs for this score
43 : /// \endcode
44 : /// \since MuseScore 3.5
45 : /// \see \ref Sid
46 : //---------------------------------------------------------
47 :
48 : /** APIDOC
49 : * Provides an access to score style settings.
50 : * Style settings for a score can be obtained by
51 : * querying the `Score.style` property.
52 : * @class Style
53 : * @memberof Engraving
54 : * @hideconstructor
55 : * @example
56 : * let style = curScore.style;
57 : * let genClef = style.value("genClef"); // retrieves style setting on clefs generation, true by default
58 : * style.setValue("genClef", false); // disables generating clefs for this score
59 : */
60 : class MStyle : public QObject
61 : {
62 : Q_OBJECT
63 :
64 : public:
65 0 : MStyle(mu::engraving::MStyle* style, mu::engraving::Score* score)
66 0 : : QObject(), m_style(style), m_score(score) {}
67 :
68 : /** APIDOC
69 : * Get the value of style by key.
70 : * Key should be one of `Sid` values.
71 : * @method
72 : * @param {Engraving.Sid} key Key
73 : * @return {Variant} Value. Type of the returned value depends on type of the corresponding style setting.
74 : */
75 : Q_INVOKABLE QVariant value(const QString& key) const;
76 :
77 : /** APIDOC
78 : * Sets the value of style setting named `key` to `value`.
79 : * Key should be one of `Sid` values.
80 : * @method
81 : * @param {Engraving.Sid} key Key
82 : * @param {Variant} value Value
83 : */
84 : Q_INVOKABLE void setValue(const QString& key, QVariant value);
85 :
86 : /** APIDOC
87 : * Resets the value of style setting named `key` to its default.
88 : * Key should be one of `Sid` values.
89 : * @method
90 : * @param {Engraving.Sid} key Key
91 : * @since 4.7
92 : */
93 : Q_INVOKABLE void resetValue(const QString& key);
94 :
95 : private:
96 :
97 : static engraving::Sid keyToSid(const QString& key);
98 :
99 : mu::engraving::MStyle* m_style = nullptr;
100 : mu::engraving::Score* m_score = nullptr;
101 : };
102 :
103 : extern MStyle* styleWrap(mu::engraving::MStyle*, mu::engraving::Score*);
104 : }
|