Skip to content

Commit

Permalink
[engraving] reemoved engravingitem old interface
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Sep 1, 2023
1 parent 0233b76 commit 1ed130f
Show file tree
Hide file tree
Showing 80 changed files with 621 additions and 637 deletions.
2 changes: 1 addition & 1 deletion src/diagnostics/view/engraving/engravingelementsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ QVariantMap EngravingElementsModel::makeData(const mu::engraving::EngravingObjec
info += "\n";
if (el->isEngravingItem()) {
const mu::engraving::EngravingItem* item = mu::engraving::toEngravingItem(el);
info += "pagePos: " + formatPoint(item->pagePos()) + ", bbox: " + formatRect(item->bbox());
info += "pagePos: " + formatPoint(item->pagePos()) + ", bbox: " + formatRect(item->layoutData()->bbox);
}

QVariantMap d;
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/accidental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void Accidental::computeMag()
if (isSmall()) {
m *= style().styleD(Sid::smallNoteMag);
}
setMag(m);
mutLayoutData()->setMag(m);
}

//---------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/engraving/libmscore/arpeggio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ void Arpeggio::setHeight(double h)

std::vector<PointF> Arpeggio::gripsPositions(const EditData&) const
{
const LayoutData* ldata = layoutData();
const PointF pp(pagePos());
PointF p1(bbox().width() / 2, bbox().top());
PointF p2(bbox().width() / 2, bbox().bottom());
PointF p1(ldata->bbox.width() / 2, ldata->bbox.top());
PointF p2(ldata->bbox.width() / 2, ldata->bbox.bottom());
return { p1 + pp, p2 + pp };
}

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void BarLine::endEditDrag(EditData& ed)
Shape BarLine::shape() const
{
Shape shape;
shape.add(bbox(), this);
shape.add(layoutData()->bbox, this);
return shape;
}

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/libmscore/box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void Box::editDrag(EditData& ed)
int n = lrint(_boxHeight.val() / vRaster);
_boxHeight = Spatium(vRaster * n);
}
bbox().setRect(0.0, 0.0, system()->width(), point(boxHeight()));
mutLayoutData()->bbox.setRect(0.0, 0.0, system()->width(), point(boxHeight()));
system()->setHeight(height());
triggerLayout();
} else {
Expand Down Expand Up @@ -155,7 +155,7 @@ RectF Box::contentRect() const
RectF result;

for (const EngravingItem* element : el()) {
result = result.united(element->bbox());
result = result.united(element->layoutData()->bbox);
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ void Chord::setSlash(bool flag, bool stemless)
// for drum staves, no offset, but use normal head
if (!staffType->isDrumStaff()) {
// undoChangeProperty(Pid::OFFSET, PointF(0.0, y));
movePosY(y);
mutLayoutData()->movePosY(y);
} else {
head = NoteHeadGroup::HEAD_NORMAL;
}
Expand Down Expand Up @@ -2824,7 +2824,7 @@ Shape Chord::shape() const
shape.add(l->shape().translate(l->pos()));
}
if (m_beamlet && m_stem) {
double xPos = m_beamlet->line.p1().x() - m_stem->xpos();
double xPos = m_beamlet->line.p1().x() - m_stem->layoutData()->pos.x();
if (m_beamlet->isBefore && !m_up) {
xPos -= m_stem->width();
} else if (!m_beamlet->isBefore && m_up) {
Expand Down Expand Up @@ -2960,7 +2960,7 @@ void GraceNotesGroup::setPos(double x, double y)
EngravingItem::setPos(x, y);
for (unsigned i = 0; i < this->size(); ++i) {
Chord* chord = this->at(i);
chord->movePos(PointF(x, y));
chord->mutLayoutData()->movePos(PointF(x, y));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,8 @@ Shape ChordRest::shape() const
rmargin = std::max(rmargin, styleP(Sid::lyricsDashMinLength));
}
// for horizontal spacing we only need the lyrics width:
x1 = std::min(x1, l->bbox().x() - lmargin + l->pos().x());
x2 = std::max(x2, l->bbox().x() + l->bbox().width() + rmargin + l->pos().x());
x1 = std::min(x1, l->layoutData()->bbox.x() - lmargin + l->pos().x());
x2 = std::max(x2, l->layoutData()->bbox.x() + l->layoutData()->bbox.width() + rmargin + l->pos().x());
if (l->ticks() == Fraction::fromTicks(Lyrics::TEMP_MELISMA_TICKS)) {
x2 += spatium();
}
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ Note* Score::setGraceNote(Chord* ch, int pitch, NoteType type, int len)
chord->setDurationType(d);
chord->setTicks(d.fraction());
chord->setNoteType(type);
chord->setMag(ch->staff()->staffMag(chord->tick()) * style().styleD(Sid::graceNoteMag));
chord->mutLayoutData()->setMag(ch->staff()->staffMag(chord->tick()) * style().styleD(Sid::graceNoteMag));

undoAddElement(chord);
select(note, SelectType::SINGLE, 0);
Expand Down
66 changes: 34 additions & 32 deletions src/engraving/libmscore/dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,34 +266,34 @@ double Dynamic::customTextOffset() const
// Move Dynamic up or down to avoid collisions with other elements.
//-------------------------------------------------------------------

void Dynamic::doAutoplace()
{
Segment* s = segment();
if (!(s && autoplace())) {
return;
}

double minDistance = style().styleS(Sid::dynamicsMinDistance).val() * spatium();
RectF r = bbox().translated(pos() + s->pos() + s->measure()->pos());
double yOff = offset().y() - propertyDefault(Pid::OFFSET).value<PointF>().y();
r.translate(0.0, -yOff);

Skyline& sl = s->measure()->system()->staff(staffIdx())->skyline();
SkylineLine sk(!placeAbove());
sk.add(r);

if (placeAbove()) {
double d = sk.minDistance(sl.north());
if (d > -minDistance) {
movePosY(-(d + minDistance));
}
} else {
double d = sl.south().minDistance(sk);
if (d > -minDistance) {
movePosY(d + minDistance);
}
}
}
//void Dynamic::doAutoplace()
//{
// Segment* s = segment();
// if (!(s && autoplace())) {
// return;
// }

// double minDistance = style().styleS(Sid::dynamicsMinDistance).val() * spatium();
// RectF r = bbox().translated(pos() + s->pos() + s->measure()->pos());
// double yOff = offset().y() - propertyDefault(Pid::OFFSET).value<PointF>().y();
// r.translate(0.0, -yOff);

// Skyline& sl = s->measure()->system()->staff(staffIdx())->skyline();
// SkylineLine sk(!placeAbove());
// sk.add(r);

// if (placeAbove()) {
// double d = sk.minDistance(sl.north());
// if (d > -minDistance) {
// movePosY(-(d + minDistance));
// }
// } else {
// double d = sl.south().minDistance(sk);
// if (d > -minDistance) {
// movePosY(d + minDistance);
// }
// }
//}

//--------------------------------------------------------------------------
// manageBarlineCollisions
Expand Down Expand Up @@ -354,10 +354,11 @@ void Dynamic::manageBarlineCollisions()
if (leftBarLineSegment) {
EngravingItem* e = leftBarLineSegment->elementAt(barLineStaff * VOICES);
if (e) {
double leftMargin = bbox().translated(pagePos() - offset()).left() - e->bbox().translated(e->pagePos()).right()
double leftMargin = layoutData()->bbox.translated(pagePos() - offset()).left()
- e->layoutData()->bbox.translated(e->pagePos()).right()
- minBarLineDistance;
if (leftMargin < 0) {
movePosX(-leftMargin);
mutLayoutData()->movePosX(-leftMargin);
return;
}
}
Expand All @@ -374,10 +375,11 @@ void Dynamic::manageBarlineCollisions()
if (rightBarLineSegment) {
EngravingItem* e = rightBarLineSegment->elementAt(barLineStaff * VOICES);
if (e) {
double rightMargin = e->bbox().translated(e->pagePos()).left() - bbox().translated(pagePos() - offset()).right()
double rightMargin = e->layoutData()->bbox.translated(e->pagePos()).left()
- layoutData()->bbox.translated(pagePos() - offset()).right()
- minBarLineDistance;
if (rightMargin < 0) {
movePosX(rightMargin);
mutLayoutData()->movePosX(rightMargin);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Dynamic final : public TextBase

String accessibleInfo() const override;
String screenReaderInfo() const override;
void doAutoplace();
// void doAutoplace();
void manageBarlineCollisions();

static String dynamicText(DynamicType t);
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ ChordRest* Score::addClone(ChordRest* cr, const Fraction& tick, const TDuration&
} else {
newcr = toChordRest(cr->clone());
}
newcr->setPosX(0.0);
newcr->mutLayoutData()->setPosX(0.0);
newcr->setDurationType(d);
newcr->setTicks(d.fraction());
newcr->setTuplet(cr->tuplet());
Expand Down
25 changes: 3 additions & 22 deletions src/engraving/libmscore/engravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,12 +931,13 @@ void Compound::clear()

void EngravingItem::dump() const
{
const LayoutData* ldata = layoutData();
LOGD("---EngravingItem: %s, pos(%4.2f,%4.2f)"
"\n bbox(%g,%g,%g,%g)"
"\n abox(%g,%g,%g,%g)"
"\n parent: %p",
typeName(), ipos().x(), ipos().y(),
bbox().x(), bbox().y(), bbox().width(), bbox().height(),
typeName(), ldata->pos.x(), ldata->pos.y(),
ldata->bbox.x(), ldata->bbox.y(), ldata->bbox.width(), ldata->bbox.height(),
abbox().x(), abbox().y(), abbox().width(), abbox().height(),
explicitParent());
}
Expand Down Expand Up @@ -2178,26 +2179,6 @@ EngravingItem::LayoutData* EngravingItem::mutLayoutData()
return m_layoutData;
}

const mu::RectF& EngravingItem::bbox() const
{
if (!layoutData()) {
//LOGD() << "no layout data, will be returned dummy";
static mu::RectF dummy;
return dummy;
}
return layoutData()->bbox;
}

const PointF& EngravingItem::ipos() const
{
if (!layoutData()) {
//LOGD() << "no layout data, will be returned dummy";
static mu::PointF dummy;
return dummy;
}
return layoutData()->pos;
}

double EngravingItem::mag() const
{
if (!layoutData()) {
Expand Down
40 changes: 13 additions & 27 deletions src/engraving/libmscore/engravingitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,8 @@ class EngravingItem : public EngravingObject

bool isNudged() const { return !m_offset.isNull(); }

mu::RectF abbox() const { return bbox().translated(pagePos()); }
mu::RectF pageBoundingRect() const { return bbox().translated(pagePos()); }
mu::RectF canvasBoundingRect() const { return bbox().translated(canvasPos()); }
virtual void setbbox(const mu::RectF& r) { mutLayoutData()->bbox = r; }
virtual void addbbox(const mu::RectF& r) { mutLayoutData()->bbox.unite(r); }
bool contains(const PointF& p) const;
bool intersects(const mu::RectF& r) const;
virtual Shape shape() const { return Shape(bbox(), this); }
virtual double baseLine() const { return -height(); }

virtual mu::RectF hitBBox() const { return layoutData()->bbox; }
virtual Shape hitShape() const { return shape(); }
Expand Down Expand Up @@ -526,37 +519,30 @@ class EngravingItem : public EngravingObject
const LayoutData* layoutData() const;
LayoutData* mutLayoutData();

const mu::RectF& bbox() const;
const PointF& ipos() const;
virtual double mag() const;
virtual Shape shape() const { return Shape(layoutData()->bbox, this); }
virtual double baseLine() const { return -height(); }

//! --- Old Interface ---
bool skipDraw() const { return layoutData() && layoutData()->isSkipDraw; }
void setSkipDraw(bool val) { mutLayoutData()->isSkipDraw = val; }
mu::RectF abbox() const { return layoutData()->bbox.translated(pagePos()); }
mu::RectF pageBoundingRect() const { return layoutData()->bbox.translated(pagePos()); }
mu::RectF canvasBoundingRect() const { return layoutData()->bbox.translated(canvasPos()); }

mu::RectF& bbox() { return mutLayoutData()->bbox; }
virtual double height() const { return bbox().height(); }
//! --- Old Interface ---
virtual void setbbox(const mu::RectF& r) { mutLayoutData()->bbox = r; }
virtual void addbbox(const mu::RectF& r) { mutLayoutData()->bbox.unite(r); }
virtual double height() const { return layoutData()->bbox.height(); }
virtual void setHeight(double v) { mutLayoutData()->bbox.setHeight(v); }
virtual double width() const { return bbox().width(); }
virtual double width() const { return layoutData()->bbox.width(); }
virtual void setWidth(double v) { mutLayoutData()->bbox.setWidth(v); }

double xpos() { return ipos().x(); }
double ypos() { return ipos().y(); }
virtual const PointF pos() const { return ipos() + m_offset; }
virtual double x() const { return ipos().x() + m_offset.x(); }
virtual double y() const { return ipos().y() + m_offset.y(); }
virtual const PointF pos() const { return layoutData()->pos + m_offset; }
virtual double x() const { return layoutData()->pos.x() + m_offset.x(); }
virtual double y() const { return layoutData()->pos.y() + m_offset.y(); }
virtual void setPos(double x, double y) { doSetPos(x, y); }
virtual void setPos(const PointF& p) { doSetPos(p.x(), p.y()); }
void setPosX(double x) { mutLayoutData()->setPosX(x); }
void setPosY(double y) { mutLayoutData()->setPosY(y); }
void movePos(const PointF& p) { mutLayoutData()->movePos(p); }
void movePosX(double x) { mutLayoutData()->movePosX(x); }
void movePosY(double y) { mutLayoutData()->movePosY(y); }

virtual void move(const PointF& s) { mutLayoutData()->pos += s; }

void setMag(double val) { mutLayoutData()->mag = val; }

void setOffsetChanged(bool val, bool absolute = true, const PointF& diff = PointF());
//! ---------------------

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/libmscore/figuredbass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@ double FiguredBass::additionalContLineX(double pagePosY) const
&& fbi->prefix() == FiguredBassItem::Modifier::NONE
&& fbi->suffix() == FiguredBassItem::Modifier::NONE
&& fbi->parenth4() == FiguredBassItem::Parenthesis::NONE
&& std::abs(pgPos.y() + fbi->ipos().y() - pagePosY) < 0.05) {
return pgPos.x() + fbi->ipos().x();
&& std::abs(pgPos.y() + fbi->layoutData()->pos.y() - pagePosY) < 0.05) {
return pgPos.x() + fbi->layoutData()->pos.x();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/libmscore/fret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ void FretDiagram::init(StringData* stringData, Chord* chord)
double FretDiagram::centerX() const
{
// Keep in sync with how bbox is calculated in layout().
return (bbox().right() - layoutData()->markerSize * .5) * .5;
return (layoutData()->bbox.right() - layoutData()->markerSize * .5) * .5;
}

double FretDiagram::rightX() const
{
// Keep in sync with how bbox is calculated in layout().
return bbox().right() - layoutData()->markerSize * .5;
return layoutData()->bbox.right() - layoutData()->markerSize * .5;
}

//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/libmscore/fretcircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ RectF FretCircle::ellipseRect() const
auto notes = m_chord->notes();
Note* up = m_chord->upNote();
Note* down = m_chord->downNote();
RectF elRect = up->bbox();
RectF elRect = up->layoutData()->bbox;

double maxWidth = 0;
double initialX = up->x();
double initialWidth = up->width();

for (const Note* note : notes) {
elRect |= note->bbox();
elRect |= note->layoutData()->bbox;
maxWidth = std::max(note->width(), maxWidth);
}

Expand Down
9 changes: 2 additions & 7 deletions src/engraving/libmscore/glissando.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ NICE-TO-HAVE TODO:
#include <cmath>
#include <algorithm>

#include "draw/fontmetrics.h"
#include "draw/types/pen.h"
#include "style/style.h"

#include "types/typesconv.h"
#include "iengravingfont.h"

#include "chord.h"
#include "measure.h"
Expand Down Expand Up @@ -168,8 +163,8 @@ void Glissando::addLineAttachPoints()
if (!frontSeg || !backSeg || !startNote || !endNote) {
return;
}
double startX = frontSeg->ipos().x();
double endX = backSeg->pos2().x() + backSeg->ipos().x(); // because pos2 is relative to ipos
double startX = frontSeg->layoutData()->pos.x();
double endX = backSeg->pos2().x() + backSeg->layoutData()->pos.x(); // because pos2 is relative to ipos
// Here we don't pass y() because its value is unreliable during the first stages of layout.
// The y() is irrelevant anyway for horizontal spacing.
startNote->addLineAttachPoint(PointF(startX, 0.0), this);
Expand Down
Loading

0 comments on commit 1ed130f

Please sign in to comment.