Fixed text properties application

This commit is contained in:
Stephan Roos
2026-02-27 20:08:01 +02:00
parent 38a00c5edf
commit c42154efc3

View File

@ -173,9 +173,7 @@ MuseScore {
//------------------------------------------------- //-------------------------------------------------
for (var i = 0; i < holeCount; i++) { for (var i = 0; i < holeCount; i++) {
var symbol var symbol
if (binaryString[i] === "2") if (binaryString[i] === "2")
symbol = "●" symbol = "●"
else if (binaryString[i] === "1") else if (binaryString[i] === "1")
@ -183,23 +181,30 @@ MuseScore {
else else
symbol = "○" symbol = "○"
var token = new RegExp("\\$" + (i+1) + "(?!\\d)", "g") // Use global replace to replace all occurrences
var token = "$" + (i+1)
while (output.indexOf(token) !== -1) {
output = output.replace(token, symbol) output = output.replace(token, symbol)
} }
}
//------------------------------------------------- //-------------------------------------------------
// Replace plus placeholder ($+) // Replace plus placeholder ($+)
//------------------------------------------------- //-------------------------------------------------
var plusSymbol = (plusBit === "1") ? "+" : " " var plusSymbol = (plusBit === "1") ? "+" : " "
output = output.replace(/\$\+/g, plusSymbol) while (output.indexOf("$+") !== -1) {
output = output.replace("$+", plusSymbol)
}
//------------------------------------------------- //-------------------------------------------------
// Final validation // Final validation
//------------------------------------------------- //-------------------------------------------------
if (/\$\d+|\$\+/.test(output)) if (output.indexOf("$") !== -1) {
return "Regex Validation Error" console.log("Warning: Unreplaced placeholders in:", output)
return output // Return anyway with what we have
}
return output return output
} }
@ -209,11 +214,12 @@ MuseScore {
//--------------------------------------------------------- //---------------------------------------------------------
function formatText(text) { function formatText(text) {
console.log("Formatting text - setting fontSize to:", userFontSize)
text.fontSize = userFontSize text.fontSize = userFontSize
text.placement = Placement.BELOW text.placement = Placement.BELOW
text.autoplace = false text.autoplace = false
text.offsetY = userOffsetY text.offsetY = userOffsetY
text.lineSpacing = userLineSpacing text.lineSpacing = userLineSpacing // Multiply by 10 for better range
if (userJustification === 0) if (userJustification === 0)
text.align = Align.LEFT text.align = Align.LEFT
@ -233,11 +239,19 @@ MuseScore {
return false return false
} }
console.log("=== Applying Fingerings ===")
console.log("userFontSize:", userFontSize)
console.log("userFormatString:", userFormatString)
console.log("userJustification:", userJustification)
console.log("userOffsetY:", userOffsetY)
console.log("userLineSpacing:", userLineSpacing)
curScore.startCmd() curScore.startCmd()
var cursor = curScore.newCursor() var cursor = curScore.newCursor()
cursor.rewind(0) cursor.rewind(0)
var count = 0
while (cursor.segment) { while (cursor.segment) {
if (cursor.element && cursor.element.type === Element.CHORD) { if (cursor.element && cursor.element.type === Element.CHORD) {
var chord = cursor.element var chord = cursor.element
@ -248,21 +262,33 @@ MuseScore {
if (!fingeringDict[noteName]) { //note not in fingering dictionary if (!fingeringDict[noteName]) { //note not in fingering dictionary
text.text = "☒" text.text = "☒"
console.log("Note not in dictionary:", noteName)
} else { } else {
var diagram = buildFingeringText(fingeringDict[noteName], userFormatString) var diagram = buildFingeringText(fingeringDict[noteName], userFormatString)
text.text = diagram text.text = diagram
console.log("Note:", noteName, "Diagram:", diagram.replace(/\n/g, "\\n"))
} }
cursor.add(text) cursor.add(text)
formatText(text) formatText(text)
// Verify the text object has the properties set
console.log("Text fontSize after format:", text.fontSize)
console.log("Text offsetY after format:", text.offsetY)
console.log("Text lineSpacing after format:", text.lineSpacing)
count++
} }
cursor.next() cursor.next()
} }
curScore.endCmd() curScore.endCmd()
console.log("Applied fingerings to", count, "notes")
console.log("=== Done ===")
return true return true
} }
function getFirstNoteName() { function getFirstNoteName() {
for (var note in fingeringDict) { for (var note in fingeringDict) {
return note // Returns the first key in the dictionary return note // Returns the first key in the dictionary
@ -287,8 +313,16 @@ MuseScore {
function setUserFontSize(size) { function setUserFontSize(size) {
var oldSize = userFontSize var oldSize = userFontSize
getHistory().add( getHistory().add(
function() { userFontSize = oldSize }, function() {
function() { userFontSize = size; fontSizeSpin.value = size }, userFontSize = oldSize
fontSizeField.text = oldSize
previewLabel.font.pointSize = oldSize
},
function() {
userFontSize = size
fontSizeField.text = size
previewLabel.font.pointSize = size
},
"font size" "font size"
) )
} }
@ -305,8 +339,14 @@ MuseScore {
function setUserOffsetY(offset) { function setUserOffsetY(offset) {
var oldOffset = userOffsetY var oldOffset = userOffsetY
getHistory().add( getHistory().add(
function() { userOffsetY = oldOffset; offsetSpin.value = oldOffset * 10 }, function() {
function() { userOffsetY = offset; offsetSpin.value = offset * 10 }, userOffsetY = oldOffset
offsetField.text = oldOffset.toFixed(1)
},
function() {
userOffsetY = offset
offsetField.text = offset.toFixed(1)
},
"vertical offset" "vertical offset"
) )
} }
@ -314,8 +354,14 @@ MuseScore {
function setUserLineSpacing(spacing) { function setUserLineSpacing(spacing) {
var oldSpacing = userLineSpacing var oldSpacing = userLineSpacing
getHistory().add( getHistory().add(
function() { userLineSpacing = oldSpacing; spacingSpin.value = oldSpacing * 10 }, function() {
function() { userLineSpacing = spacing; spacingSpin.value = spacing * 10 }, userLineSpacing = oldSpacing
spacingField.text = oldSpacing.toFixed(1)
},
function() {
userLineSpacing = spacing
spacingField.text = spacing.toFixed(1)
},
"line spacing" "line spacing"
) )
} }
@ -345,10 +391,10 @@ MuseScore {
getHistory().end() getHistory().end()
} }
function fontSizeChanged() { function fontSizeChanged(size) {
getHistory().begin() getHistory().begin()
setModified(true) setModified(true)
setUserFontSize(fontSizeSpin.value) setUserFontSize(size)
updatePreview() updatePreview()
getHistory().end() getHistory().end()
} }
@ -414,6 +460,7 @@ MuseScore {
// Set up system palette for color management // Set up system palette for color management
SystemPalette { id: sysPal } SystemPalette { id: sysPal }
// TOP ROW - Text Formatting Options
// TOP ROW - Text Formatting Options // TOP ROW - Text Formatting Options
GroupBox { GroupBox {
title: "Text Formatting" title: "Text Formatting"
@ -449,7 +496,7 @@ MuseScore {
color: sysPal.text color: sysPal.text
selectionColor: sysPal.highlight selectionColor: sysPal.highlight
selectedTextColor: sysPal.highlightedText selectedTextColor: sysPal.highlightedText
validator: IntValidator { bottom: 6; top: 72 } validator: IntValidator { bottom: 1; top: 72 }
background: Rectangle { background: Rectangle {
color: sysPal.window color: sysPal.window
border.color: sysPal.mid border.color: sysPal.mid
@ -458,7 +505,7 @@ MuseScore {
// Handle Enter key press // Handle Enter key press
onAccepted: { onAccepted: {
var newValue = parseInt(text) var newValue = parseInt(text)
if (!isNaN(newValue) && newValue >= 6 && newValue <= 72) { if (!isNaN(newValue) && newValue >= 1 && newValue <= 72) {
if (newValue !== userFontSize) { if (newValue !== userFontSize) {
fontSizeChanged(newValue) fontSizeChanged(newValue)
} }
@ -471,7 +518,7 @@ MuseScore {
onActiveFocusChanged: { onActiveFocusChanged: {
if (!activeFocus) { if (!activeFocus) {
var newValue = parseInt(text) var newValue = parseInt(text)
if (!isNaN(newValue) && newValue >= 6 && newValue <= 72) { if (!isNaN(newValue) && newValue >= 1 && newValue <= 72) {
if (newValue !== userFontSize) { if (newValue !== userFontSize) {
fontSizeChanged(newValue) fontSizeChanged(newValue)
} }
@ -484,12 +531,13 @@ MuseScore {
// Update preview in real-time as user types // Update preview in real-time as user types
onTextChanged: { onTextChanged: {
var newValue = parseInt(text) var newValue = parseInt(text)
if (!isNaN(newValue) && newValue >= 6 && newValue <= 72) { if (!isNaN(newValue) && newValue >= 1 && newValue <= 72) {
// Temporarily update preview without committing to history // Temporarily update preview without committing to history
previewLabel.font.pointSize = newValue previewLabel.font.pointSize = newValue
} }
} }
} }
Label { Label {
text: "Justification:" text: "Justification:"
color: sysPal.windowText color: sysPal.windowText
@ -500,7 +548,10 @@ MuseScore {
Layout.preferredWidth: 120 Layout.preferredWidth: 120
model: ["Left", "Center", "Right"] model: ["Left", "Center", "Right"]
currentIndex: userJustification currentIndex: userJustification
onActivated: justificationChanged() onActivated: {
justificationChanged()
updatePreview()
}
contentItem: Text { contentItem: Text {
text: justCombo.displayText text: justCombo.displayText
color: sysPal.windowText color: sysPal.windowText
@ -536,9 +587,10 @@ MuseScore {
onAccepted: { onAccepted: {
var newValue = parseFloat(text) var newValue = parseFloat(text)
if (!isNaN(newValue) && newValue >= -20.0 && newValue <= 20.0) { if (!isNaN(newValue) && newValue >= -200.0 && newValue <= 200.0) {
if (newValue !== userOffsetY) { if (newValue !== userOffsetY) {
offsetYChanged(newValue) offsetYChanged(newValue)
updatePreview()
} }
} else { } else {
text = userOffsetY.toFixed(1) text = userOffsetY.toFixed(1)
@ -548,17 +600,16 @@ MuseScore {
onActiveFocusChanged: { onActiveFocusChanged: {
if (!activeFocus) { if (!activeFocus) {
var newValue = parseFloat(text) var newValue = parseFloat(text)
if (!isNaN(newValue) && newValue >= -20.0 && newValue <= 20.0) { if (!isNaN(newValue) && newValue >= -200.0 && newValue <= 200.0) {
if (newValue !== userOffsetY) { if (newValue !== userOffsetY) {
offsetYChanged(newValue) offsetYChanged(newValue)
updatePreview()
} }
} else { } else {
text = userOffsetY.toFixed(1) text = userOffsetY.toFixed(1)
} }
} }
} }
// Offset doesn't affect preview content, so no onTextChanged needed
} }
Label { Label {
@ -574,7 +625,7 @@ MuseScore {
color: sysPal.text color: sysPal.text
selectionColor: sysPal.highlight selectionColor: sysPal.highlight
selectedTextColor: sysPal.highlightedText selectedTextColor: sysPal.highlightedText
validator: DoubleValidator { bottom: 0.5; top: 3.0; decimals: 1 } validator: DoubleValidator { bottom: 0; top: 6; decimals: 1 }
background: Rectangle { background: Rectangle {
color: sysPal.window color: sysPal.window
border.color: sysPal.mid border.color: sysPal.mid
@ -582,9 +633,10 @@ MuseScore {
onAccepted: { onAccepted: {
var newValue = parseFloat(text) var newValue = parseFloat(text)
if (!isNaN(newValue) && newValue >= 0.5 && newValue <= 3.0) { if (!isNaN(newValue) && newValue >= 0 && newValue <= 6) {
if (newValue !== userLineSpacing) { if (newValue !== userLineSpacing) {
lineSpacingChanged(newValue) lineSpacingChanged(newValue)
updatePreview()
} }
} else { } else {
text = userLineSpacing.toFixed(1) text = userLineSpacing.toFixed(1)
@ -594,17 +646,16 @@ MuseScore {
onActiveFocusChanged: { onActiveFocusChanged: {
if (!activeFocus) { if (!activeFocus) {
var newValue = parseFloat(text) var newValue = parseFloat(text)
if (!isNaN(newValue) && newValue >= 0.5 && newValue <= 3.0) { if (!isNaN(newValue) && newValue >= 0 && newValue <= 6.0) {
if (newValue !== userLineSpacing) { if (newValue !== userLineSpacing) {
lineSpacingChanged(newValue) lineSpacingChanged(newValue)
updatePreview()
} }
} else { } else {
text = userLineSpacing.toFixed(1) text = userLineSpacing.toFixed(1)
} }
} }
} }
// Line spacing doesn't affect preview content, so no onTextChanged needed
} }
} }
} }
@ -807,6 +858,8 @@ MuseScore {
color: sysPal.windowText color: sysPal.windowText
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
width: parent.width width: parent.width
lineHeight: userLineSpacing
lineHeightMode: Text.ProportionalHeight
} }
} }
} }