Skip to content

Commit

Permalink
fixes & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Mar 31, 2014
1 parent cebfec6 commit 8f54ce5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 38 deletions.
65 changes: 30 additions & 35 deletions libmscore/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ void SlurSegment::editDrag(const EditData& ed)
ups[GRIP_DRAG].off = QPointF();
setUserOff(userOff() + ed.delta);
}

// if this SlurSegment was automatically adjusted to avoid collision
// lock this edit by resetting SlurSegment to default position
// and incorporating previous adjustment into user offset
QPointF offset = getAutoAdjust();
if (!offset.isNull()) {
setAutoAdjust(0.0, 0.0);
setUserOff(userOff() + offset);
}
}

//---------------------------------------------------------
Expand Down Expand Up @@ -554,29 +563,31 @@ void SlurSegment::layout(const QPointF& p1, const QPointF& p2)
ups[GRIP_END].p = p2;
slurTie()->computeBezier(this);
QRectF bbox = path.boundingRect();

// adjust position to avoid staff line if necessary
qreal sp = spatium();
qreal ld = staff()->lineDistance() * sp;
qreal minDistance = 0.5;
setAutoAdjust(0.0, 0.0);
if (bbox.height() < minDistance * 2 * sp) {
// path is fairly flat
// adjust position to avoid staff line if necessary
Staff* st = staff();
autoAdjustOffset = QPointF();
if (bbox.height() < minDistance * 2 * sp && st) {
// slur/tie is fairly flat
bool up = slurTie()->up();
qreal topY = bbox.top() / ld;
qreal bottomY = bbox.bottom() / ld;
int closestLine = up ? qRound(topY) : qRound(bottomY);
if (closestLine >= 0 && closestLine < staff()->lines()) {
qreal staffY = system()->staff(staffIdx())->y();
qreal ld = st->lineDistance() * sp;
qreal topY = (bbox.top() - staffY) / ld;
qreal bottomY = (bbox.bottom() - staffY) / ld;
int lineY = up ? qRound(topY) : qRound(bottomY);
if (lineY >= 0 && lineY < st->lines() * st->lineDistance()) {
// on staff
if (qAbs(topY - closestLine) < minDistance && qAbs(bottomY - closestLine) < minDistance) {
if (qAbs(topY - lineY) < minDistance && qAbs(bottomY - lineY) < minDistance) {
// too close to line
if (userOff() == QPointF()) {
if (!isNudged()) {
// user has not edited
qreal offY;
if (up)
offY = (closestLine - minDistance) - topY;
offY = (lineY - minDistance) - topY;
else
offY = (closestLine + minDistance) - bottomY;
//qreal offY = (up ? -0.5 : 0.5) * sp;
offY = (lineY + minDistance) - bottomY;
setAutoAdjust(0.0, offY * sp);
bbox = path.boundingRect();
}
Expand All @@ -594,8 +605,11 @@ void SlurSegment::layout(const QPointF& p1, const QPointF& p2)
void SlurSegment::setAutoAdjust(const QPointF& offset)
{
QPointF diff = offset - autoAdjustOffset;
if (diff != QPointF()) {
move(diff);
if (!diff.isNull()) {
path.translate(diff);
shapePath.translate(diff);
for (int i = 0; i < SLUR_GRIPS; ++i)
ups[i].p += diff;
autoAdjustOffset = offset;
}
}
Expand Down Expand Up @@ -1067,25 +1081,6 @@ QVariant SlurSegment::propertyDefault(P_ID id) const
}
}

//---------------------------------------------------------
// startEdit
//---------------------------------------------------------

void SlurSegment::startEdit(MuseScoreView* s, const QPointF& p)
{
QPointF zeroP;
QPointF offset = getAutoAdjust();
if (offset != zeroP) {
// this segment was automatically adjusted to avoid collision
// lock in position by resetting to default position
// and incorporating previous adjustment into user offset
setUserOff(userOff() + offset);
setAutoAdjust(zeroP);
parent()->layout();
}
SpannerSegment::startEdit(s, p);
}

//---------------------------------------------------------
// reset
//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion libmscore/slur.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class SlurSegment : public SpannerSegment {
virtual QPainterPath shape() const { return shapePath; }
virtual void draw(QPainter*) const;

virtual void startEdit(MuseScoreView*, const QPointF&) override;
virtual bool isEditable() const { return true; }
virtual void editDrag(const EditData&);
virtual bool edit(MuseScoreView*, int grip, int key, Qt::KeyboardModifiers, const QString& s);
Expand Down
3 changes: 2 additions & 1 deletion vtest/gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ else
emmentaler-8 bravura-8 emmentaler-9 bravura-9 emmentaler-10 bravura-10\
emmentaler-11 bravura-11 frametext ottava slurs-1\
chord-layout-1 chord-layout-2 chord-layout-3 chord-layout-4 chord-layout-5\
accidental-1 accidental-2 accidental-3 accidental-4 accidental-5 accidental-6"
accidental-1 accidental-2 accidental-3 accidental-4 accidental-5 accidental-6\
tie-1"
fi

MSCORE=../build.debug/mscore/mscore
Expand Down
3 changes: 2 additions & 1 deletion vtest/gen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ set SRC=mmrest-1,bravura-mmrest,mmrest-2,mmrest-4,mmrest-5,mmrest-6,mmrest-7,mmr
emmentaler-6,bravura-6,emmentaler-7,bravura-7, ^
emmentaler-8,bravura-8,emmentaler-9,bravura-9,emmentaler-10,bravura-10, ^
chord-layout-1,chord-layout-2,chord-layout-3,chord-layout-4,chord-layout-5, ^
accidental-1,accidental-2,accidental-3,accidental-4,accidental-5,accidental-6
accidental-1,accidental-2,accidental-3,accidental-4,accidental-5,accidental-6, ^
tie-1

set MSCORE=..\win32install\bin\mscore.exe
set DPI=130
Expand Down
Binary file added vtest/tie-1-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vtest/tie-1.mscz
Binary file not shown.

0 comments on commit 8f54ce5

Please sign in to comment.