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

Add option to scale frames with spatium, or independently #23852

Merged
merged 6 commits into from
Aug 12, 2024
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
38 changes: 28 additions & 10 deletions src/engraving/dom/box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Box::Box(const ElementType& type, System* parent)

void HBox::computeMinWidth()
{
setWidth(point(boxWidth()) + topGap() + bottomGap()); // top/bottom is really left/right
setWidth(point(boxWidth() + topGap() + bottomGap())); // top/bottom is really left/right
}

bool Box::isEditAllowed(EditData&) const
Expand Down Expand Up @@ -94,8 +94,9 @@ void Box::startEditDrag(EditData& ed)

void Box::editDrag(EditData& ed)
{
const double sp = sizeIsSpatiumDependent() ? spatium() : style().defaultSpatium();
if (isVBox()) {
m_boxHeight += Spatium(ed.delta.y() / spatium());
m_boxHeight += Spatium(ed.delta.y() / sp);
if (ed.vRaster) {
double vRaster = 1.0 / MScore::vRaster();
int n = lrint(m_boxHeight.val() / vRaster);
Expand All @@ -105,7 +106,7 @@ void Box::editDrag(EditData& ed)
system()->setHeight(height());
triggerLayout();
} else {
m_boxWidth += Spatium(ed.delta.x() / spatium());
m_boxWidth += Spatium(ed.delta.x() / sp);
if (ed.hRaster) {
double hRaster = 1.0 / MScore::hRaster();
int n = lrint(m_boxWidth.val() / hRaster);
Expand Down Expand Up @@ -151,6 +152,12 @@ void Box::add(EngravingItem* e)
MeasureBase::add(e);
}

double Box::point(const Spatium val) const
{
const double sp = sizeIsSpatiumDependent() ? spatium() : style().defaultSpatium();
return val.val() * sp;
}

RectF Box::contentRect() const
{
RectF result;
Expand Down Expand Up @@ -207,10 +214,10 @@ bool Box::setProperty(Pid propertyId, const PropertyValue& v)
m_boxWidth = v.value<Spatium>();
break;
case Pid::TOP_GAP:
m_topGap = v.value<Millimetre>();
m_topGap = v.value<Spatium>();
break;
case Pid::BOTTOM_GAP:
m_bottomGap = v.value<Millimetre>();
m_bottomGap = v.value<Spatium>();
break;
case Pid::LEFT_MARGIN:
m_leftMargin = v.toDouble();
Expand Down Expand Up @@ -246,9 +253,9 @@ PropertyValue Box::propertyDefault(Pid id) const
return Spatium(0.0);

case Pid::TOP_GAP:
return isHBox() ? Millimetre(0.0) : style().styleMM(Sid::systemFrameDistance);
return isHBox() ? Spatium(0.0) : style().styleS(Sid::systemFrameDistance);
case Pid::BOTTOM_GAP:
return isHBox() ? Millimetre(0.0) : style().styleMM(Sid::frameSystemDistance);
return isHBox() ? Spatium(0.0) : style().styleS(Sid::frameSystemDistance);

case Pid::LEFT_MARGIN:
case Pid::RIGHT_MARGIN:
Expand All @@ -257,11 +264,18 @@ PropertyValue Box::propertyDefault(Pid id) const
return 0.0;
case Pid::BOX_AUTOSIZE:
return true;
case Pid::SIZE_SPATIUM_DEPENDENT:
return !isTitleFrame();
default:
return MeasureBase::propertyDefault(id);
}
}

bool Box::isTitleFrame() const
{
return this == score()->first() && type() == ElementType::VBOX;
}

//---------------------------------------------------------
// copyValues
//---------------------------------------------------------
Expand All @@ -278,6 +292,8 @@ void Box::copyValues(Box* origin)
m_topMargin = origin->topMargin() * factor;
m_leftMargin = origin->leftMargin() * factor;
m_rightMargin = origin->rightMargin() * factor;

setSizeIsSpatiumDependent(origin->sizeIsSpatiumDependent());
}

//---------------------------------------------------------
Expand Down Expand Up @@ -426,7 +442,7 @@ void Box::manageExclusionFromParts(bool exclude)
toEngravingItem(sectionBreak)->manageExclusionFromParts(true);
}

bool titleFrame = this == score()->first() && type() == ElementType::VBOX;
bool titleFrame = isTitleFrame();
if (exclude) {
const std::list<EngravingObject*> links = linkList();
for (EngravingObject* linkedObject : links) {
Expand Down Expand Up @@ -469,6 +485,7 @@ void Box::manageExclusionFromParts(bool exclude)
options.cloneBoxToAllParts = false;
MeasureBase* newFrame = score->insertBox(type(), newMB, options);
newFrame->setExcludeFromOtherParts(false);
// newFrame->setSizeIsSpatiumDependent(!titleFrame);

for (EngravingItem* item : el()) {
// Don't add instrument name from current part
Expand All @@ -485,7 +502,7 @@ void Box::manageExclusionFromParts(bool exclude)
toTBox(newFrame)->resetText(newText);
}

if (!score->isMaster() && newFrame == score->first() && newFrame->type() == ElementType::VBOX) {
if (!score->isMaster() && titleFrame) {
// Title frame - add part name
String partLabel = score->name();
if (!partLabel.empty()) {
Expand Down Expand Up @@ -638,9 +655,10 @@ PropertyValue VBox::propertyDefault(Pid id) const

void VBox::startEditDrag(EditData& ed)
{
const double sp = sizeIsSpatiumDependent() ? spatium() : style().defaultSpatium();
if (isAutoSizeEnabled()) {
setAutoSizeEnabled(false);
setBoxHeight(Spatium(height() / spatium()));
setBoxHeight(Spatium(height() / sp));
}
Box::startEditDrag(ed);
}
Expand Down
14 changes: 8 additions & 6 deletions src/engraving/dom/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Box : public MeasureBase
virtual bool acceptDrop(EditData&) const override;
virtual EngravingItem* drop(EditData&) override;
virtual void add(EngravingItem* e) override;
virtual double point(const Spatium val) const override;

RectF contentRect() const;
Spatium boxWidth() const { return m_boxWidth; }
Expand All @@ -64,13 +65,14 @@ class Box : public MeasureBase
void setRightMargin(double val) { m_rightMargin = val; }
void setTopMargin(double val) { m_topMargin = val; }
void setBottomMargin(double val) { m_bottomMargin = val; }
Millimetre topGap() const { return m_topGap; }
void setTopGap(Millimetre val) { m_topGap = val; }
Millimetre bottomGap() const { return m_bottomGap; }
void setBottomGap(Millimetre val) { m_bottomGap = val; }
Spatium topGap() const { return m_topGap; }
void setTopGap(Spatium val) { m_topGap = val; }
Spatium bottomGap() const { return m_bottomGap; }
void setBottomGap(Spatium val) { m_bottomGap = val; }
bool isAutoSizeEnabled() const { return m_isAutoSizeEnabled; }
void setAutoSizeEnabled(const bool val) { m_isAutoSizeEnabled = val; }
void copyValues(Box* origin);
bool isTitleFrame() const;

PropertyValue getProperty(Pid propertyId) const override;
bool setProperty(Pid propertyId, const PropertyValue&) override;
Expand All @@ -91,9 +93,9 @@ class Box : public MeasureBase
private:
Spatium m_boxWidth; // only valid for HBox
Spatium m_boxHeight; // only valid for VBox
Millimetre m_topGap; // distance from previous system (left border for hbox)
Spatium m_topGap; // distance from previous system (left border for hbox)
// initialized with Sid::systemFrameDistance
Millimetre m_bottomGap; // distance to next system (right border for hbox)
Spatium m_bottomGap; // distance to next system (right border for hbox)
// initialized with Sid::frameSystemDistance
double m_leftMargin = 0.0;
double m_rightMargin = 0.0; // inner margins in metric mm
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4124,6 +4124,7 @@ MeasureBase* Score::insertBox(ElementType type, MeasureBase* beforeMeasure, cons
}

Fraction tick;
bool isTitleFrame = type == ElementType::VBOX && beforeMeasure == beforeMeasure->score()->first();
if (beforeMeasure) {
if (beforeMeasure->isMeasure()) {
Measure* m = toMeasure(beforeMeasure);
Expand All @@ -4149,6 +4150,7 @@ MeasureBase* Score::insertBox(ElementType type, MeasureBase* beforeMeasure, cons
newMeasureBase->setTick(tick);
newMeasureBase->setNext(beforeMeasure);
newMeasureBase->setPrev(beforeMeasure ? beforeMeasure->prev() : last());
newMeasureBase->setSizeIsSpatiumDependent(!isTitleFrame);

undo(new InsertMeasures(newMeasureBase, newMeasureBase));

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/engravingitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class EngravingItem : public EngravingObject

bool isPrintable() const;
bool isPlayable() const;
double point(const Spatium sp) const { return sp.val() * spatium(); }
virtual double point(const Spatium sp) const { return sp.val() * spatium(); }

bool systemFlag() const { return flag(ElementFlag::SYSTEM); }
void setSystemFlag(bool v) const { setFlag(ElementFlag::SYSTEM, v); }
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/dom/excerpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,11 @@ static MeasureBase* cloneMeasure(MeasureBase* mb, Score* score, const Score* osc
if (mb->isHBox()) {
nmb = Factory::createHBox(score->dummy()->system());
} else if (mb->isVBox()) {
nmb = Factory::createVBox(score->dummy()->system());
if (toBox(mb)->isTitleFrame()) {
nmb = Factory::createTitleVBox(score->dummy()->system());
} else {
nmb = Factory::createVBox(score->dummy()->system());
}
} else if (mb->isTBox()) {
nmb = Factory::createTBox(score->dummy()->system());
Text* text = toTBox(mb)->text();
Expand Down
10 changes: 10 additions & 0 deletions src/engraving/dom/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,16 @@ VBox* Factory::createVBox(const ElementType& type, System * parent, bool isAcces
return b;
}

VBox* Factory::createTitleVBox(System* parent, bool isAccessibleEnabled)
{
VBox* b = new VBox(ElementType::VBOX, parent);
b->setAccessibleEnabled(isAccessibleEnabled);
b->setSizeIsSpatiumDependent(false);
b->setTick(Fraction(0, 1));

return b;
}

CREATE_ITEM_IMPL(HBox, ElementType::HBOX, System, isAccessibleEnabled)

CREATE_ITEM_IMPL(TBox, ElementType::TBOX, System, isAccessibleEnabled)
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class Factory

static VBox* createVBox(const ElementType& type, System* parent, bool isAccessibleEnabled = true);

static VBox* createTitleVBox(System* parent, bool isAccessibleEnabled = true);

static HBox* createHBox(System* parent, bool isAccessibleEnabled = true);

static TBox* createTBox(System* parent, bool isAccessibleEnabled = true);
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::BOX_HEIGHT, false, "height", P_TYPE::SPATIUM, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "height") },
{ Pid::BOX_WIDTH, false, "width", P_TYPE::SPATIUM, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "width") },
{ Pid::BOX_AUTOSIZE, false, "boxAutoSize", P_TYPE::BOOL, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "autosize frame") },
{ Pid::TOP_GAP, false, "topGap", P_TYPE::MILLIMETRE, PropertyGroup::POSITION, DUMMY_QT_TR_NOOP("propertyName", "top gap") },
{ Pid::BOTTOM_GAP, false, "bottomGap", P_TYPE::MILLIMETRE, PropertyGroup::POSITION, DUMMY_QT_TR_NOOP("propertyName", "bottom gap") },
{ Pid::TOP_GAP, false, "topGap", P_TYPE::SPATIUM, PropertyGroup::POSITION, DUMMY_QT_TR_NOOP("propertyName", "top gap") },
{ Pid::BOTTOM_GAP, false, "bottomGap", P_TYPE::SPATIUM, PropertyGroup::POSITION, DUMMY_QT_TR_NOOP("propertyName", "bottom gap") },
{ Pid::LEFT_MARGIN, false, "leftMargin", P_TYPE::REAL, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "left padding") },
{ Pid::RIGHT_MARGIN, false, "rightMargin", P_TYPE::REAL, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "right padding") },
{ Pid::TOP_MARGIN, false, "topMargin", P_TYPE::REAL, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "top padding") },
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@ double System::minTop() const

double System::minBottom() const
{
if (vbox()) {
return vbox()->bottomGap();
if (const Box* vb = vbox()) {
return vb->point(vb->bottomGap());
}
staff_idx_t si = lastVisibleSysStaff();
SysStaff* s = si == muse::nidx ? nullptr : staff(si);
Expand Down
7 changes: 4 additions & 3 deletions src/engraving/rendering/dev/scorehorizontalviewlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ void ScoreHorizontalViewLayout::collectLinearSystem(LayoutContext& ctx)
MeasureLayout::layoutStaffLines(m, ctx);
} else if (ctx.state().curMeasure()->isHBox()) {
MeasureBase* curM = ctx.mutState().curMeasure();
curM->setPos(pos + PointF(toHBox(curM)->topGap(), 0.0));
TLayout::layoutBaseMeasureBase(curM, curM->mutldata(), ctx);
ww = curM->width();
HBox* curHBox = toHBox(curM);
curHBox->setPos(pos + PointF(curHBox->point(curHBox->topGap()), 0.0));
TLayout::layoutBaseMeasureBase(curHBox, curHBox->mutldata(), ctx);
ww = curHBox->width();
}
pos.rx() += ww;

Expand Down
22 changes: 13 additions & 9 deletions src/engraving/rendering/dev/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,10 @@ System* SystemLayout::collectSystem(LayoutContext& ctx)
createBrackets = false;
}
} else if (mb->isHBox()) {
mb->setPos(pos + PointF(toHBox(mb)->topGap(), 0.0));
TLayout::layoutMeasureBase(mb, ctx);
createBrackets = toHBox(mb)->createSystemHeader();
HBox* curHBox = toHBox(mb);
curHBox->setPos(pos + PointF(curHBox->point(curHBox->topGap()), 0.0));
TLayout::layoutMeasureBase(curHBox, ctx);
createBrackets = curHBox->createSystemHeader();
} else if (mb->isVBox()) {
mb->setPos(pos);
}
Expand Down Expand Up @@ -2716,12 +2717,15 @@ double SystemLayout::minDistance(const System* top, const System* bottom, const
const LayoutConfiguration& conf = ctx.conf();
const DomAccessor& dom = ctx.dom();

if (top->vbox() && !bottom->vbox()) {
return std::max(double(top->vbox()->bottomGap()), bottom->minTop());
} else if (!top->vbox() && bottom->vbox()) {
return std::max(double(bottom->vbox()->topGap()), top->minBottom());
} else if (top->vbox() && bottom->vbox()) {
return double(bottom->vbox()->topGap() + top->vbox()->bottomGap());
const Box* topVBox = top->vbox();
const Box* bottomVBox = bottom->vbox();

if (topVBox && !bottomVBox) {
return std::max(topVBox->point(topVBox->bottomGap()), bottom->minTop());
} else if (!topVBox && bottomVBox) {
return std::max(bottomVBox->point(bottomVBox->topGap()), top->minBottom());
} else if (topVBox && bottomVBox) {
return bottomVBox->point(bottomVBox->topGap()) + topVBox->point(topVBox->bottomGap());
}

if (top->staves().empty() || bottom->staves().empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/dev/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ void TLayout::layoutVBox(const VBox* item, VBox::LayoutData* ldata, const Layout
if (boxAutoSize && MScore::noImages) {
// adjustLayoutWithoutImages
double calculatedVBoxHeight = 0;
const int padding = ctx.conf().spatium();
const int padding = item->sizeIsSpatiumDependent() ? ctx.conf().spatium() : ctx.conf().style().defaultSpatium();
ElementList elist = item->el();
for (EngravingItem* e : elist) {
if (e->isText()) {
Expand Down
7 changes: 4 additions & 3 deletions src/engraving/rendering/stable/scorehorizontalviewlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ void ScoreHorizontalViewLayout::collectLinearSystem(LayoutContext& ctx)
MeasureLayout::layoutStaffLines(m, ctx);
} else if (ctx.state().curMeasure()->isHBox()) {
MeasureBase* curM = ctx.mutState().curMeasure();
curM->setPos(pos + PointF(toHBox(curM)->topGap(), 0.0));
TLayout::layoutBaseMeasureBase(curM, curM->mutldata(), ctx);
ww = curM->width();
HBox* curHBox = toHBox(curM);
curHBox->setPos(pos + PointF(curHBox->point(curHBox->topGap()), 0.0));
TLayout::layoutBaseMeasureBase(curHBox, curHBox->mutldata(), ctx);
ww = curHBox->width();
}
pos.rx() += ww;

Expand Down
17 changes: 10 additions & 7 deletions src/engraving/rendering/stable/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ System* SystemLayout::collectSystem(LayoutContext& ctx)
createBrackets = false;
}
} else if (mb->isHBox()) {
mb->setPos(pos + PointF(toHBox(mb)->topGap(), 0.0));
mb->setPos(pos + PointF(toHBox(mb)->topGap().val(), 0.0));
TLayout::layoutMeasureBase(mb, ctx);
createBrackets = toHBox(mb)->createSystemHeader();
} else if (mb->isVBox()) {
Expand Down Expand Up @@ -2525,12 +2525,15 @@ void SystemLayout::setInstrumentNames(System* system, LayoutContext& ctx, bool l
double SystemLayout::minDistance(const System* top, const System* bottom, LayoutContext& ctx)
{
TRACEFUNC;
if (top->vbox() && !bottom->vbox()) {
return std::max(double(top->vbox()->bottomGap()), bottom->minTop());
} else if (!top->vbox() && bottom->vbox()) {
return std::max(double(bottom->vbox()->topGap()), top->minBottom());
} else if (top->vbox() && bottom->vbox()) {
return double(bottom->vbox()->topGap() + top->vbox()->bottomGap());
const Box* topVBox = top->vbox();
const Box* bottomVBox = bottom->vbox();

if (topVBox && !bottomVBox) {
return std::max(topVBox->point(topVBox->bottomGap()), bottom->minTop());
} else if (!topVBox && bottomVBox) {
return std::max(bottomVBox->point(bottomVBox->topGap()), top->minBottom());
} else if (topVBox && bottomVBox) {
return bottomVBox->point(bottomVBox->topGap()) + topVBox->point(topVBox->bottomGap());
}

if (top->staves().empty() || bottom->staves().empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/read114/read114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3058,7 +3058,7 @@ Err Read114::readScore(Score* score, XmlReader& e, ReadInOutData* out)
for (MeasureBase* mb = masterScore->first(); mb; mb = mb->next()) {
if (mb->isVBox()) {
VBox* b = toVBox(mb);
Millimetre y = masterScore->style().styleMM(Sid::staffUpperBorder);
Spatium y = masterScore->style().styleS(Sid::staffUpperBorder);
b->setBottomGap(y);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/rw/read206/read206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3075,7 +3075,7 @@ static void readStaffContent206(Score* score, XmlReader& e, ReadContext& ctx)

if (tag == "Measure") {
if (lastReadBox) {
lastReadBox->setBottomGap(lastReadBox->bottomGap() + lastReadBox->propertyDefault(Pid::BOTTOM_GAP).value<Millimetre>());
lastReadBox->setBottomGap(lastReadBox->bottomGap() + lastReadBox->propertyDefault(Pid::BOTTOM_GAP).value<Spatium>());
lastReadBox = nullptr;
}
readMeasureLast = true;
Expand Down Expand Up @@ -3120,10 +3120,10 @@ static void readStaffContent206(Score* score, XmlReader& e, ReadContext& ctx)
// If it's the first box, and comes before any measures, reset to
// 301 default.
if (!readMeasureLast && !lastReadBox) {
b->setTopGap(b->propertyDefault(Pid::TOP_GAP).value<Millimetre>());
b->setTopGap(b->propertyDefault(Pid::TOP_GAP).value<Spatium>());
b->setPropertyFlags(Pid::TOP_GAP, PropertyFlags::STYLED);
} else if (readMeasureLast) {
b->setTopGap(b->topGap() + b->propertyDefault(Pid::TOP_GAP).value<Millimetre>());
b->setTopGap(b->topGap() + b->propertyDefault(Pid::TOP_GAP).value<Spatium>());
}

lastReadBox = b;
Expand Down
Loading