Skip to content
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

Consistent system left alignment #9277

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 80 additions & 40 deletions src/engraving/libmscore/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,53 +254,40 @@ void System::adjustStavesNumber(int nstaves)
}

//---------------------------------------------------------
// layoutSystem
/// Layout the System
// systemNamesWidth
//---------------------------------------------------------

void System::layoutSystem(const LayoutContext& ctx, qreal xo1, const bool isFirstSystem, bool firstSystemIndent)
qreal System::systemNamesWidth()
{
if (_staves.empty()) { // ignore vbox
return;
}

static const Spatium instrumentNameOffset(1.0); // TODO: make style value

int nstaves = _staves.size();
qreal instrumentNameOffset = score()->styleP(Sid::instrumentNameOffset);

//---------------------------------------------------
// find x position of staves
//---------------------------------------------------
qreal xoff2 = 0.0; // x offset for instrument name
qreal namesWidth = 0.0;

for (const Part* p : score()->parts()) {
if (firstVisibleSysStaffOfPart(p) < 0) {
continue;
}
for (int staffIdx = firstSysStaffOfPart(p); staffIdx <= lastSysStaffOfPart(p); ++staffIdx) {
for (const Part* part : score()->parts()) {
for (int staffIdx = firstSysStaffOfPart(part); staffIdx <= lastSysStaffOfPart(part); ++staffIdx) {
SysStaff* staff = this->staff(staffIdx);
if (!staff) {
continue;
}

for (InstrumentName* t : qAsConst(staff->instrumentNames)) {
t->layout();
qreal w = t->width() + point(instrumentNameOffset);
if (w > xoff2) {
xoff2 = w;
}
for (InstrumentName* name : qAsConst(staff->instrumentNames)) {
name->layout();
qreal width = name->width() + instrumentNameOffset;
namesWidth = qMax(namesWidth, width);
}
}
}

if (isFirstSystem && firstSystemIndent) {
xoff2 = qMax(xoff2, styleP(Sid::firstSystemIndentationValue) * mag());
}
return namesWidth;
}

//---------------------------------------------------
// create brackets
//---------------------------------------------------
//---------------------------------------------------------
// layoutBrackets
//---------------------------------------------------------

qreal System::layoutBrackets(const LayoutContext& ctx)
{
int nstaves = _staves.size();
int columns = getBracketsColumnsCount();

#if (!defined (_MSCVER) && !defined (_MSC_VER))
Expand Down Expand Up @@ -336,17 +323,70 @@ void System::layoutSystem(const LayoutContext& ctx, qreal xo1, const bool isFirs
delete b;
}

//---------------------------------------------------
// layout SysStaff and StaffLines
//---------------------------------------------------

_leftMargin = xoff2;
qreal totalBracketWidth = 0.0;

qreal bd = score()->styleP(Sid::bracketDistance);
if (!_brackets.empty()) {
for (int w : bracketWidth) {
_leftMargin += w + bd;
totalBracketWidth += w + bd;
}
}

return totalBracketWidth;
}

//---------------------------------------------------------
// totalBracketOffset
//---------------------------------------------------------

qreal System::totalBracketOffset(const LayoutContext& ctx)
{
bool hideEmptyStaves = score()->styleB(Sid::hideEmptyStaves);
score()->setStyleValue(Sid::hideEmptyStaves, false);

qreal offset = layoutBrackets(ctx);

score()->setStyleValue(Sid::hideEmptyStaves, hideEmptyStaves);
return offset;
}

//---------------------------------------------------------
// layoutSystem
/// Layout the System
//---------------------------------------------------------

void System::layoutSystem(const LayoutContext& ctx, qreal xo1, const bool isFirstSystem, bool firstSystemIndent)
{
if (_staves.empty()) { // ignore vbox
return;
}

qreal instrumentNameOffset = score()->styleP(Sid::instrumentNameOffset);

int nstaves = _staves.size();

//---------------------------------------------------
// find x position of staves
//---------------------------------------------------
qreal maxNamesWidth = systemNamesWidth();

if (isFirstSystem && firstSystemIndent) {
maxNamesWidth = qMax(maxNamesWidth, styleP(Sid::firstSystemIndentationValue) * mag());
}

qreal maxBracketsWidth = totalBracketOffset(ctx);
qreal bracketsWidth = layoutBrackets(ctx);
qreal bracketWidthDifference = maxBracketsWidth - bracketsWidth;
qreal nameOffset = 0.0;
if (maxNamesWidth == 0.0) {
if (score()->styleB(Sid::alignSystemToMargin)) {
_leftMargin = bracketWidthDifference;
} else {
_leftMargin = maxBracketsWidth;
}
} else {
_leftMargin = maxNamesWidth + bracketWidthDifference + instrumentNameOffset;
nameOffset = _leftMargin - bracketsWidth - instrumentNameOffset;
}

int nVisible = 0;
Expand Down Expand Up @@ -386,14 +426,14 @@ void System::layoutSystem(const LayoutContext& ctx, qreal xo1, const bool isFirs
for (InstrumentName* t : qAsConst(s->instrumentNames)) {
switch (int(t->align()) & int(Align::HMASK)) {
case int(Align::LEFT):
t->rxpos() = 0;
t->rxpos() = t->width() - maxNamesWidth + nameOffset + xo1;
break;
case int(Align::HCENTER):
t->rxpos() = (xoff2 - point(instrumentNameOffset) + xo1) * .5;
t->rxpos() = (t->width() - maxNamesWidth) / 2 + nameOffset + xo1;
break;
case int(Align::RIGHT):
default:
t->rxpos() = xoff2 - point(instrumentNameOffset) + xo1;
t->rxpos() = nameOffset + xo1;
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/libmscore/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class System final : public EngravingItem
Bracket* createBracket(const mu::engraving::LayoutContext& ctx, Ms::BracketItem* bi, int column, int staffIdx, QList<Ms::Bracket*>& bl,
Measure* measure);

qreal systemNamesWidth();
qreal layoutBrackets(const mu::engraving::LayoutContext& ctx);
qreal totalBracketOffset(const mu::engraving::LayoutContext& ctx);

public:

~System();
Expand Down Expand Up @@ -154,7 +158,7 @@ class System final : public EngravingItem

Page* page() const { return (Page*)parent(); }

void layoutSystem(const mu::engraving::LayoutContext& ctx, qreal, const bool isFirstSystem = false, bool firstSystemIndent = false);
void layoutSystem(const mu::engraving::LayoutContext& ctx, qreal xo1, const bool isFirstSystem = false, bool firstSystemIndent = false);
Nick-Mazuk marked this conversation as resolved.
Show resolved Hide resolved

void setMeasureHeight(qreal height);
void layoutBracketsVertical();
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/style/styledef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ const std::array<StyleDef::StyleValue, size_t(Sid::STYLES)> StyleDef::styleValue
{ Sid::staffUpperBorder, "staffUpperBorder", Spatium(7.0) },
{ Sid::staffLowerBorder, "staffLowerBorder", Spatium(7.0) },
{ Sid::staffDistance, "staffDistance", Spatium(6.5) },
{ Sid::instrumentNameOffset, "instrumentNameOffset", Spatium(1.0) },
{ Sid::akkoladeDistance, "akkoladeDistance", Spatium(6.5) },
{ Sid::minSystemDistance, "minSystemDistance", Spatium(8.5) },
{ Sid::maxSystemDistance, "maxSystemDistance", Spatium(15.0) },
{ Sid::alignSystemToMargin, "alignSystemToMargin", true },

{ Sid::enableVerticalSpread, "enableVerticalSpread", false },
{ Sid::spreadSystem, "spreadSystem", 2.5 },
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/style/styledef.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ enum class Sid {
staffUpperBorder,
staffLowerBorder,
staffDistance,
instrumentNameOffset,
akkoladeDistance,
minSystemDistance,
maxSystemDistance,
alignSystemToMargin,

enableVerticalSpread,
spreadSystem,
Expand Down