[trunk] Staff text for other (non-first) staves is placed relatively to first stave

• Jan 23, 2012 - 00:25
S4 - Minor

Setup: rev. 5241; compiled with latest Qt SDK (Qt lib 4.7.4) under Ubuntu 11.10


1) Open or create any score with more than 1 stave
2) Create a staff text (Ctrl-T) for any stave except the first
3) Type some text
4) Exit the text editor (for instance clicking elsewhere)

Result: the newly added staff text is displayed over the first stave.

Expected result: the newly added staff text should be displayed over the stave to which it has been added.





The issue only affects STYLED staff text: unstyled staff text is positioned correctly.

Sample: A very short sample score is attached: it only contains two staff texts, one styled and one unstyled, both attached to the bottom stave; the first is displayed above the top stave, the second is displayed above the bottom stave.

Analysis: I think the issue is in function void Text::layout() (file text.cpp, lines 179 and foll.).

If the staff text is NOT STYLED, line 251 is (sooner or later) executed:
    rypos() += s ? s->measure()->system()->staff(staffIdx())->y() : 0.0;
which positions the text vertically according the stave it belongs to.

If the staff text is STYLED, no similar code is executed and the text is not positioned correctly.

The patch: The attached patch is actually a hack: it simply copies lines 249-253 into the styled case of function void Text::layout().

The result is correct, but the patch is probably too simplistic. Anyway, I opened a few scores, even reasonably complex, and I could not notice any side effect.

As MuseScore text layout is a rather complex matter, a more experienced look is probably required.



Status (old) patch (code needs review) fixed

(modified) patch applied to r5248.
I also changed the anchor position of staff text (red dashed line when dragging).