-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add: Accessibility Panel - Score Style Preset option #23048
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
install(FILES | ||
16mm_MSN.mss | ||
18mm_MSN.mss | ||
20mm_MSN.mss | ||
22mm_MSN.mss | ||
25mm_MSN.mss | ||
DESTINATION ${Mscore_SHARE_NAME}${Mscore_INSTALL_NAME}styles/MSN | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
* MuseScore-Studio-CLA-applies | ||
* | ||
* MuseScore Studio | ||
* Music Composition & Notation | ||
* | ||
* Copyright (C) 2021 MuseScore Limited | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#include "scoreaccessibilitysettingsmodel.h" | ||
|
||
#include "translation.h" | ||
#include "log.h" | ||
#include "engraving/types/typesconv.h" | ||
#include "framework/global/defer.h" | ||
|
||
using namespace mu::inspector; | ||
using namespace mu::engraving; | ||
|
||
ScoreAccessibilitySettingsModel::ScoreAccessibilitySettingsModel(QObject* parent, IElementRepositoryService* repository) | ||
: AbstractInspectorModel(parent, repository) | ||
{ | ||
setSectionType(InspectorSectionType::SECTION_SCORE_ACCESSIBILITY); | ||
setTitle(muse::qtrc("inspector", "Accessibility")); | ||
|
||
globalContext()->currentNotation()->style()->styleChanged().onNotify(this, [this]() { | ||
if (!m_ignoreStyleChange && !m_scoreStylePresetEdited) { | ||
m_scoreStylePresetEdited = true; | ||
globalContext()->currentNotation()->elements()->msScore()->score()->style().setPresetEdited(true); | ||
emit possibleScoreStylePresetsChanged(); | ||
emit scoreStylePresetIndexChanged(); | ||
} | ||
}); | ||
} | ||
|
||
void ScoreAccessibilitySettingsModel::createProperties() | ||
{ | ||
// Placeholder | ||
} | ||
|
||
void ScoreAccessibilitySettingsModel::requestElements() | ||
{ | ||
// Placeholder | ||
} | ||
|
||
void ScoreAccessibilitySettingsModel::loadProperties() | ||
{ | ||
// Placeholder | ||
} | ||
|
||
void ScoreAccessibilitySettingsModel::resetProperties() | ||
{ | ||
// Placeholder | ||
} | ||
|
||
muse::io::path_t ScoreAccessibilitySettingsModel::getStyleFilePath(ScoreStylePreset preset) const | ||
{ | ||
muse::io::path_t basePath = globalConfiguration()->appDataPath() + "styles/MSN/"; | ||
switch (preset) { | ||
case ScoreStylePreset::DEFAULT: | ||
return engravingConfiguration()->defaultStyleFilePath(); | ||
case ScoreStylePreset::MSN_16MM: | ||
return basePath + "16mm_MSN.mss"; | ||
case ScoreStylePreset::MSN_18MM: | ||
return basePath + "18mm_MSN.mss"; | ||
case ScoreStylePreset::MSN_20MM: | ||
return basePath + "20mm_MSN.mss"; | ||
case ScoreStylePreset::MSN_22MM: | ||
return basePath + "22mm_MSN.mss"; | ||
case ScoreStylePreset::MSN_25MM: | ||
return basePath + "25mm_MSN.mss"; | ||
default: | ||
return muse::io::path_t(); | ||
} | ||
} | ||
|
||
QVariantList ScoreAccessibilitySettingsModel::possibleScoreStylePresets() const | ||
{ | ||
QVariantList presets; | ||
|
||
QString text = "text"; | ||
QString value = "value"; | ||
QString preset = "preset"; | ||
QString edited = "edited"; | ||
|
||
for (int i = 0; i < static_cast<int>(ScoreStylePreset::MAX_PRESET); ++i) { | ||
ScoreStylePreset presetEnum = static_cast<ScoreStylePreset>(i); | ||
QString presetName = TConv::translatedUserName(presetEnum); | ||
|
||
presets.append(QVariantMap { | ||
{ text, presetName }, | ||
{ | ||
value, | ||
QVariantMap { | ||
{ preset, i }, | ||
{ edited, false } | ||
} | ||
} | ||
}); | ||
|
||
if (i == static_cast<int>(m_scoreStylePreset) && m_scoreStylePresetEdited) { | ||
QString editedPresetName = muse::qtrc("inspector", "%1 (edited)").arg(presetName); | ||
presets.append(QVariantMap { | ||
{ text, editedPresetName }, | ||
{ | ||
value, | ||
QVariantMap { | ||
{ preset, i }, | ||
{ edited, true } | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return presets; | ||
} | ||
|
||
void ScoreAccessibilitySettingsModel::setScoreStylePresetIndex(int index) | ||
{ | ||
int oldIndex = scoreStylePresetIndex(); | ||
|
||
if (index == oldIndex) { | ||
return; | ||
} | ||
|
||
if (m_scoreStylePresetEdited && index > oldIndex) { | ||
--index; | ||
} | ||
shoogle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
auto selectedPreset = static_cast<ScoreStylePreset>(index); | ||
|
||
bool presetChanged = (selectedPreset != m_scoreStylePreset); | ||
bool editedChanged = (m_scoreStylePresetEdited != false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bool editedChanged = m_scoreStylePresetEdited; // because index != oldIndex |
||
|
||
MStyle& style = globalContext()->currentNotation()->elements()->msScore()->score()->style(); | ||
|
||
if (presetChanged) { | ||
loadStyle(selectedPreset); | ||
m_scoreStylePreset = selectedPreset; | ||
style.setPreset(selectedPreset); | ||
|
||
emit scoreStylePresetIndexChanged(); | ||
} | ||
|
||
if (editedChanged) { | ||
m_scoreStylePresetEdited = false; | ||
style.setPresetEdited(false); | ||
|
||
emit possibleScoreStylePresetsChanged(); | ||
emit scoreStylePresetIndexChanged(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You emit Emitting will cause connected slots to fire (i.e. it will make something happen in the UI), which could potentially be costly in terms of performance. You don't want to emit things more often than you need to. Normally, it would be better to add a separate conditional block at the end of the function: if (presetChanged || editedChanged) {
emit scoreStylePresetIndexChanged();
} Except in this case you already know that emit scoreStylePresetIndexChanged(); That should be the final line of this function. |
||
} | ||
} | ||
|
||
void ScoreAccessibilitySettingsModel::loadStyle(ScoreStylePreset preset) | ||
{ | ||
muse::io::path_t filePath = getStyleFilePath(preset); | ||
m_ignoreStyleChange = true; | ||
DEFER { | ||
m_ignoreStyleChange = false; | ||
}; | ||
|
||
if (preset == ScoreStylePreset::DEFAULT && filePath.empty()) { | ||
StyleIdSet emptySet; | ||
globalContext()->currentNotation()->style()->resetAllStyleValues(emptySet); | ||
return; | ||
} | ||
|
||
IF_ASSERT_FAILED(!filePath.empty()) { | ||
return; | ||
} | ||
|
||
LOGI() << "Loading style from filePath: " << filePath; | ||
globalContext()->currentNotation()->style()->loadStyle(filePath, true); | ||
} | ||
|
||
int ScoreAccessibilitySettingsModel::scoreStylePresetIndex() const | ||
{ | ||
return static_cast<int>(m_scoreStylePreset) + (m_scoreStylePresetEdited ? 1 : 0); | ||
} | ||
|
||
void ScoreAccessibilitySettingsModel::updateScoreStylePreset() | ||
{ | ||
MStyle style = globalContext()->currentNotation()->elements()->msScore()->score()->style(); | ||
ScoreStylePreset stylePreset = style.preset(); | ||
bool stylePresetEdited = style.presetEdited(); | ||
bool indexChanged = false; | ||
|
||
if (m_scoreStylePreset != stylePreset) { | ||
m_scoreStylePreset = stylePreset; | ||
shoogle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
indexChanged = true; | ||
} | ||
|
||
if (m_scoreStylePresetEdited != stylePresetEdited) { | ||
m_scoreStylePresetEdited = stylePresetEdited; | ||
shoogle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
emit possibleScoreStylePresetsChanged(); | ||
indexChanged = true; | ||
} | ||
|
||
if (indexChanged) { | ||
emit scoreStylePresetIndexChanged(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the type name is mentioned elsewhere on the line, you can also do:
auto m_preset = ScoreStylePreset::DEFAULT;
But writing it explicitly is fine too.