Skip to content

Commit

Permalink
adjust glissando bbox to hold text and wavy glissando
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioBL committed Jan 23, 2015
1 parent a78eec8 commit e20bd7b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
63 changes: 62 additions & 1 deletion libmscore/glissando.cpp
Expand Up @@ -368,5 +368,66 @@ QVariant Glissando::propertyDefault(P_ID propertyId) const
return Element::propertyDefault(propertyId);
}

}
//---------------------------------------------------------
// bbox
// used for canvasBoundingRect during dragging
//---------------------------------------------------------

const QRectF& Glissando::bbox() const
{
qreal _spatium = spatium();
qreal w = line.dx();
qreal h = line.dy();
qreal l = sqrt(w * w + h * h);
qreal wi = asin( -h / l);
if (glissandoType() == Type::WAVY) {
QRectF b = symBbox(SymId::wiggleTrill);
qreal wsym = symWidth(SymId::wiggleTrill);
int n = (int)(l / wsym); // always round down (truncate) to avoid overlap
qreal x = (l - n*wsym) * 0.5; // centre line in available space
b.setWidth(b.width()+wsym*(n-1));
b.translate(x,b.height()*.5);
qreal x1 = b.left()*cos(wi)+b.top()*sin(wi);
qreal x2 = b.left()*cos(wi)+b.bottom()*sin(wi);
qreal y1 = -(b.left()*sin(wi)-b.top()*cos(wi));
qreal y2 = -(b.right()*sin(wi)-b.top()*cos(wi));
qreal x3 = b.right()*cos(wi)+b.top()*sin(wi);
qreal x4 = b.right()*cos(wi)+b.bottom()*sin(wi);
qreal y3 = -(b.left()*sin(wi)-b.bottom()*cos(wi));
qreal y4 = -(b.right()*sin(wi)-b.bottom()*cos(wi));
QPointF pTL(fmin(x1,x2),fmin(y1,y2));
QPointF pBR(fmax(x3,x4),fmax(y3,y4));
b = QRectF(pTL,pBR);
b.translate(line.p1());
Element::addbbox(b.normalized());
}
if (_showText) {
const TextStyle& st = score()->textStyle(TextStyleType::GLISSANDO);
QFont f = st.fontPx(_spatium);
QRectF r = QFontMetricsF(f).boundingRect(_text);
// if text longer than available space, skip it
if (r.width() < l) {
qreal yOffset = r.height() + r.y(); // find text descender height
// raise text slightly above line and slightly more with WAVY than with STRAIGHT
yOffset += _spatium * (glissandoType() == Type::WAVY ? 0.75 : 0.05);
qreal x = (l - r.width()) * 0.5;
r.translate(x,-yOffset);
qreal x1 = r.left()*cos(wi)+r.top()*sin(wi);
qreal x2 = r.left()*cos(wi)+r.bottom()*sin(wi);
qreal y1 = -(r.left()*sin(wi)-r.top()*cos(wi));
qreal y2 = -(r.right()*sin(wi)-r.top()*cos(wi));
qreal x3 = r.right()*cos(wi)+r.top()*sin(wi);
qreal x4 = r.right()*cos(wi)+r.bottom()*sin(wi);
qreal y3 = -(r.left()*sin(wi)-r.bottom()*cos(wi));
qreal y4 = -(r.right()*sin(wi)-r.bottom()*cos(wi));
QPointF pTL(fmin(x1,x2),fmin(y1,y2));
QPointF pBR(fmax(x3,x4),fmax(y3,y4));
r = QRectF(pTL,pBR);
r.translate(line.p1());
Element::addbbox(r.normalized());
}
}
return Element::bbox();
}

}
1 change: 1 addition & 0 deletions libmscore/glissando.h
Expand Up @@ -61,6 +61,7 @@ class Glissando : public Element {
virtual void read(XmlReader&) override;

void setSize(const QSizeF&); // used for palette
virtual const QRectF& bbox() const override;

QString text() const { return _text; }
void setText(const QString& t) { _text = t; }
Expand Down

0 comments on commit e20bd7b

Please sign in to comment.