MuseScore/libmscore/hairpin.cpp

851 lines
30 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "hairpin.h"
#include "style.h"
#include "xml.h"
#include "utils.h"
#include "score.h"
#include "measure.h"
#include "segment.h"
#include "system.h"
#include "undo.h"
#include "staff.h"
#include "mscore.h"
#include "chord.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
Spatium Hairpin::editHairpinHeight;
//---------------------------------------------------------
// lookupDynamic
2016-07-20 12:45:34 +02:00
// return autoplace Dynamic at chord e position
//---------------------------------------------------------
Dynamic* lookupDynamic(Element* e)
{
Dynamic* d = 0;
Segment* s = 0;
if (e && e->isChord())
s = toChord(e)->segment();
if (s) {
for (Element* ee : s->annotations()) {
if (ee->isDynamic() && ee->track() == e->track() && ee->placeBelow()) {
d = toDynamic(ee);
break;
}
}
}
if (d) {
if (!d->autoplace())
d = 0;
}
return d;
}
//---------------------------------------------------------
// moveDynamic
//---------------------------------------------------------
2016-08-02 17:00:49 +02:00
static void moveDynamic(Dynamic* d, qreal y)
{
2016-07-19 14:36:09 +02:00
if (d && d->autoplace()) {
int staffIdx = d->staffIdx();
Shape& ss = d->segment()->staffShape(staffIdx);
Shape& ms = d->measure()->staffShape(staffIdx);
QPointF spos = d->segment()->pos();
2016-08-02 17:00:49 +02:00
d->rUserYoffset() = y;
2016-07-19 14:36:09 +02:00
ss.add(d->shape());
ms.add(d->shape().translated(spos));
}
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void HairpinSegment::layout()
{
Dynamic* sd = 0;
Dynamic* ed = 0;
2016-07-20 12:45:34 +02:00
qreal _spatium = spatium();
2016-07-25 12:29:24 +02:00
if (autoplace()) {
setUserOff(QPointF());
setUserOff2(QPointF());
}
if (isSingleType() || isBeginType()) {
sd = lookupDynamic(hairpin()->startElement());
if (sd) {
if (autoplace()) {
2016-07-25 12:29:24 +02:00
qreal dx = sd->bbox().right() + sd->pos().x()
+ sd->segment()->pos().x() + sd->measure()->pos().x();
// hardcoded distance between Dynamic and Hairpin: 0.5sp
qreal dist = dx - pos().x() + score()->styleP(StyleIdx::autoplaceHairpinDynamicsDistance);
rUserXoffset() = dist;
rUserXoffset2() = -dist;
2016-07-20 12:45:34 +02:00
}
else
sd->doAutoplace();
2016-07-20 12:45:34 +02:00
}
}
if (isSingleType() || isEndType()) {
ed = lookupDynamic(hairpin()->endElement());
if (ed) {
if (autoplace()) {
2016-07-25 12:29:24 +02:00
rUserXoffset2() -= ed->bbox().width();
qreal dx = ed->bbox().left() + ed->pos().x()
+ ed->segment()->pos().x() + ed->measure()->pos().x();
// hardcoded distance between Hairpin and Dynamic: 0.5sp
ed->rUserXoffset() = pos2().x() + pos().x() - dx + score()->styleP(StyleIdx::autoplaceHairpinDynamicsDistance);
2016-07-20 12:45:34 +02:00
}
else
ed->doAutoplace();
2016-07-20 12:45:34 +02:00
}
}
2012-05-26 14:26:10 +02:00
Hairpin::Type type = hairpin()->hairpinType();
if (type == Hairpin::Type::DECRESC_LINE || type == Hairpin::Type::CRESC_LINE) {
twoLines = false;
TextLineSegment::layout();
2016-08-02 17:00:49 +02:00
drawCircledTip = false;
if (parent())
rypos() += score()->styleP(StyleIdx::hairpinY);
2012-05-26 14:26:10 +02:00
}
else {
delete _text;
delete _endText;
2016-07-20 12:45:34 +02:00
_text = 0;
_endText = 0;
QTransform t;
2016-07-20 12:45:34 +02:00
qreal h1 = hairpin()->hairpinHeight().val() * spatium() * .5;
qreal h2 = hairpin()->hairpinContHeight().val() * spatium() * .5;
qreal len;
qreal x = pos2().x();
if (x < _spatium) // minimum size of hairpin
x = _spatium;
qreal y = pos2().y();
len = sqrt(x * x + y * y);
t.rotateRadians(asin(y/len));
drawCircledTip = hairpin()->hairpinCircledTip();
circledTipRadius = drawCircledTip ? 0.6 * _spatium * .5 : 0.0;
QLine l1, l2;
twoLines = true;
switch (type) {
case Hairpin::Type::CRESC_HAIRPIN: {
switch (spannerSegmentType()) {
2016-07-20 12:45:34 +02:00
case SpannerSegmentType::SINGLE:
case SpannerSegmentType::BEGIN:
l1.setLine(circledTipRadius * 2.0, 0.0, len, h1);
l2.setLine(circledTipRadius * 2.0, 0.0, len, -h1);
circledTip.setX(circledTipRadius );
circledTip.setY(0.0);
break;
case SpannerSegmentType::MIDDLE:
2016-07-20 12:45:34 +02:00
case SpannerSegmentType::END:
drawCircledTip = false;
l1.setLine(.0, h2, len, h1);
l2.setLine(.0, -h2, len, -h1);
break;
}
}
2012-05-26 14:26:10 +02:00
break;
case Hairpin::Type::DECRESC_HAIRPIN: {
switch(spannerSegmentType()) {
case SpannerSegmentType::SINGLE:
case SpannerSegmentType::END:
2016-07-20 12:45:34 +02:00
l1.setLine(0.0, h1, len - circledTipRadius * 2, 0.0);
l2.setLine(0.0, -h1, len - circledTipRadius * 2, 0.0);
circledTip.setX(len - circledTipRadius);
circledTip.setY(0.0);
break;
case SpannerSegmentType::BEGIN:
case SpannerSegmentType::MIDDLE:
drawCircledTip = false;
l1.setLine(.0, h1, len, + h2);
l2.setLine(.0, -h1, len, - h2);
break;
}
}
break;
default:
2012-05-26 14:26:10 +02:00
break;
}
// Do Coord rotation
l1 = t.map(l1);
l2 = t.map(l2);
if (drawCircledTip )
circledTip = t.map(circledTip);
2016-07-20 12:45:34 +02:00
points[0] = l1.p1();
points[1] = l1.p2();
points[2] = l2.p1();
points[3] = l2.p2();
npoints = 4;
QRectF r = QRectF(l1.p1(), l1.p2()).normalized() | QRectF(l2.p1(), l2.p2()).normalized();
2016-07-19 14:36:09 +02:00
qreal w = score()->styleP(StyleIdx::hairpinLineWidth);
setbbox(r.adjusted(-w*.5, -w*.5, w, w));
if (parent())
rypos() += score()->styleP(StyleIdx::hairpinY);
2012-05-26 14:26:10 +02:00
}
if (autoplace() && parent()) {
qreal minDistance = spatium() * .7;
Shape s1 = shape().translated(pos());
qreal d = system()->bottomDistance(staffIdx(), s1);
2016-07-19 14:36:09 +02:00
2016-07-25 12:29:24 +02:00
qreal ymax = pos().y();
2016-07-19 14:36:09 +02:00
if (d > -minDistance)
2016-08-02 17:00:49 +02:00
ymax += d + minDistance;
2016-07-19 14:36:09 +02:00
2016-08-02 17:00:49 +02:00
qreal sdy;
2016-07-19 14:36:09 +02:00
if (sd) {
2016-08-02 17:00:49 +02:00
sdy = -sd->bbox().top() * .4;
2016-07-19 14:36:09 +02:00
sd->doAutoplace();
2016-08-02 17:00:49 +02:00
if (sd->pos().y() - sdy > ymax)
ymax = sd->pos().y() - sdy;
2016-07-19 14:36:09 +02:00
}
2016-08-02 17:00:49 +02:00
qreal edy;
2016-07-19 14:36:09 +02:00
if (ed) {
2016-08-02 17:00:49 +02:00
edy = -ed->bbox().top() * .4;
2016-07-19 14:36:09 +02:00
ed->doAutoplace();
2016-08-02 17:00:49 +02:00
if (ed->pos().y() - edy > ymax)
ymax = ed->pos().y() - edy;
}
2016-07-25 12:29:24 +02:00
rUserYoffset() = ymax - pos().y();
if (sd)
2016-08-02 17:00:49 +02:00
moveDynamic(sd, ymax - sd->ipos().y() + sdy);
2016-07-25 12:29:24 +02:00
if (ed)
2016-08-02 17:00:49 +02:00
moveDynamic(ed, ymax - ed->ipos().y() + edy);
}
else
adjustReadPos();
2012-05-26 14:26:10 +02:00
}
2016-07-20 12:45:34 +02:00
//---------------------------------------------------------
// shape
//---------------------------------------------------------
Shape HairpinSegment::shape() const
{
switch (hairpin()->hairpinType()) {
case Hairpin::Type::CRESC_HAIRPIN:
case Hairpin::Type::DECRESC_HAIRPIN:
return Shape(bbox());
case Hairpin::Type::DECRESC_LINE:
case Hairpin::Type::CRESC_LINE:
default:
return TextLineSegment::shape();
}
}
2013-07-26 15:26:18 +02:00
//---------------------------------------------------------
// updateGrips
//---------------------------------------------------------
void HairpinSegment::updateGrips(Grip* defaultGrip, QVector<QRectF>& grip) const
2013-07-26 15:26:18 +02:00
{
*defaultGrip = Grip::END;
2014-03-16 14:57:32 +01:00
2013-07-26 15:26:18 +02:00
QPointF pp(pagePos());
qreal _spatium = spatium();
qreal x = pos2().x();
if (x < _spatium) // minimum size of hairpin
x = _spatium;
qreal y = pos2().y();
QPointF p(x, y);
2014-02-26 21:28:00 +01:00
// Calc QPointF for Grip Aperture
QTransform doRotation;
QPointF gripLineAperturePoint;
qreal h1 = hairpin()->hairpinHeight().val() * spatium() * .5;
qreal len = sqrt( x * x + y * y );
doRotation.rotateRadians( asin(y/len) );
qreal lineApertureX;
qreal offsetX = 10; // Horizontal offset for x Grip
if(len < offsetX * 3 ) // For small hairpin, offset = 30% of len
offsetX = len/3; // else offset is fixed to 10
2014-02-26 21:28:00 +01:00
if (hairpin()->hairpinType() == Hairpin::Type::CRESC_HAIRPIN)
2014-02-26 21:28:00 +01:00
lineApertureX = len - offsetX; // End of CRESCENDO - Offset
else
2014-02-26 21:28:00 +01:00
lineApertureX = offsetX; // Begin of DECRESCENDO + Offset
qreal lineApertureH = ( len - offsetX ) * h1/len; // Vertical position for y grip
gripLineAperturePoint.setX( lineApertureX );
gripLineAperturePoint.setY( lineApertureH );
gripLineAperturePoint = doRotation.map( gripLineAperturePoint );
// End calc position grip aperture
grip[int(Grip::START)].translate( pp );
grip[int(Grip::END)].translate( p + pp );
grip[int(Grip::MIDDLE)].translate( p * .5 + pp );
grip[int(Grip::APERTURE)].translate( gripLineAperturePoint + pp );
2014-02-26 21:28:00 +01:00
}
2014-02-26 21:28:00 +01:00
//---------------------------------------------------------
// editDrag
//---------------------------------------------------------
void HairpinSegment::editDrag(const EditData& ed)
{
if (ed.curGrip == Grip::APERTURE) {
qreal newHeight = hairpin()->hairpinHeight().val() + ed.delta.y()/spatium()/.5;
if (newHeight < 0.5)
newHeight = 0.5;
hairpin()->setHairpinHeight(Spatium(newHeight));
triggerLayout();
}
LineSegment::editDrag(ed);
2013-07-26 15:26:18 +02:00
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void HairpinSegment::draw(QPainter* painter) const
{
TextLineSegment::draw(painter);
2013-05-02 16:12:17 +02:00
QColor color;
if (selected() && !(score() && score()->printing()))
color = (track() > -1) ? MScore::selectColor[voice()] : MScore::selectColor[0];
else if (!hairpin()->visible()) // || !hairpin()->lineVisible()
2013-05-02 16:12:17 +02:00
color = Qt::gray;
else
color = hairpin()->lineColor();
QPen pen(color, point(hairpin()->lineWidth()), hairpin()->lineStyle());
2012-05-26 14:26:10 +02:00
painter->setPen(pen);
if (drawCircledTip) {
2015-08-23 22:08:14 +02:00
painter->setBrush(Qt::NoBrush);
painter->drawEllipse( circledTip,circledTipRadius,circledTipRadius );
}
2012-05-26 14:26:10 +02:00
}
2013-03-27 17:52:26 +01:00
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant HairpinSegment::getProperty(P_ID id) const
{
2013-05-02 16:12:17 +02:00
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CIRCLEDTIP:
case P_ID::HAIRPIN_TYPE:
case P_ID::VELO_CHANGE:
case P_ID::DYNAMIC_RANGE:
case P_ID::DIAGONAL:
case P_ID::HAIRPIN_HEIGHT:
case P_ID::HAIRPIN_CONT_HEIGHT:
2013-05-02 16:12:17 +02:00
return hairpin()->getProperty(id);
default:
return TextLineSegment::getProperty(id);
2013-05-02 16:12:17 +02:00
}
2013-03-27 17:52:26 +01:00
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool HairpinSegment::setProperty(P_ID id, const QVariant& v)
{
2013-05-02 16:12:17 +02:00
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CIRCLEDTIP:
case P_ID::HAIRPIN_TYPE:
case P_ID::VELO_CHANGE:
case P_ID::DYNAMIC_RANGE:
case P_ID::DIAGONAL:
case P_ID::LINE_WIDTH:
case P_ID::HAIRPIN_HEIGHT:
case P_ID::HAIRPIN_CONT_HEIGHT:
2013-05-02 16:12:17 +02:00
return hairpin()->setProperty(id, v);
default:
return TextLineSegment::setProperty(id, v);
2013-05-02 16:12:17 +02:00
}
2013-03-27 17:52:26 +01:00
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant HairpinSegment::propertyDefault(P_ID id) const
{
2013-05-02 16:12:17 +02:00
switch (id) {
case P_ID::TEXT_STYLE_TYPE:
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CIRCLEDTIP:
case P_ID::HAIRPIN_TYPE:
case P_ID::VELO_CHANGE:
case P_ID::DYNAMIC_RANGE:
case P_ID::DIAGONAL:
case P_ID::HAIRPIN_HEIGHT:
case P_ID::HAIRPIN_CONT_HEIGHT:
2013-05-02 16:12:17 +02:00
return hairpin()->propertyDefault(id);
default:
return TextLineSegment::propertyDefault(id);
2013-05-02 16:12:17 +02:00
}
2013-03-27 17:52:26 +01:00
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle HairpinSegment::propertyStyle(P_ID id) const
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
case P_ID::HAIRPIN_HEIGHT:
case P_ID::HAIRPIN_CONT_HEIGHT:
2013-08-09 11:42:24 +02:00
return hairpin()->propertyStyle(id);
default:
return TextLineSegment::propertyStyle(id);
2013-08-09 11:42:24 +02:00
}
}
2016-07-20 12:45:34 +02:00
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
StyleIdx HairpinSegment::getPropertyStyle(P_ID id) const
{
switch (id) {
case P_ID::LINE_WIDTH:
case P_ID::HAIRPIN_HEIGHT:
case P_ID::HAIRPIN_CONT_HEIGHT:
return hairpin()->getPropertyStyle(id);
default:
break;
}
return TextLineSegment::getPropertyStyle(id);
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void HairpinSegment::resetProperty(P_ID id)
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
case P_ID::HAIRPIN_HEIGHT:
case P_ID::HAIRPIN_CONT_HEIGHT:
2013-08-09 11:42:24 +02:00
return hairpin()->resetProperty(id);
default:
return TextLineSegment::resetProperty(id);
2013-08-09 11:42:24 +02:00
}
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Hairpin
//---------------------------------------------------------
Hairpin::Hairpin(Score* s)
2015-08-23 22:08:14 +02:00
: TextLine(s)
2012-05-26 14:26:10 +02:00
{
_hairpinType = Type::CRESC_HAIRPIN;
_hairpinCircledTip = false;
_veloChange = 0;
_dynRange = Dynamic::Range::PART;
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::hairpinLineWidth));
2013-08-13 14:26:40 +02:00
lineWidthStyle = PropertyStyle::STYLED;
2014-05-26 15:31:36 +02:00
_hairpinHeight = score()->styleS(StyleIdx::hairpinHeight);
2013-08-13 14:26:40 +02:00
hairpinHeightStyle = PropertyStyle::STYLED;
2014-05-26 15:31:36 +02:00
_hairpinContHeight = score()->styleS(StyleIdx::hairpinContHeight);
2013-08-13 14:26:40 +02:00
hairpinContHeightStyle = PropertyStyle::STYLED;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// setHairpinType
//---------------------------------------------------------
void Hairpin::setHairpinType(Type val)
{
if (_hairpinType == val)
return;
_hairpinType = val;
switch (_hairpinType) {
case Type::CRESC_HAIRPIN:
case Type::DECRESC_HAIRPIN:
setBeginText("");
setContinueText("");
setLineStyle(Qt::SolidLine);
break;
case Type::CRESC_LINE:
setBeginText("cresc.");
setContinueText("(cresc.)");
setLineStyle(Qt::CustomDashLine);
break;
case Type::DECRESC_LINE:
setBeginText("dim.");
setContinueText("(dim.)");
setLineStyle(Qt::CustomDashLine);
break;
};
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// layout
// compute segments from tick() to _tick2
//---------------------------------------------------------
void Hairpin::layout()
{
setPos(0.0, 0.0);
2015-08-23 22:08:14 +02:00
TextLine::layout();
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
LineSegment* Hairpin::createLineSegment()
{
return new HairpinSegment(score());
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Hairpin::write(Xml& xml) const
{
2014-08-13 15:42:40 +02:00
if (!xml.canWrite(this))
return;
2014-07-21 13:24:21 +02:00
int id = xml.spannerId(this);
xml.stag(QString("%1 id=\"%2\"").arg(name()).arg(id));
2014-05-21 15:45:01 +02:00
xml.tag("subtype", int(_hairpinType));
writeProperty(xml, P_ID::VELO_CHANGE);
2014-05-26 18:18:01 +02:00
writeProperty(xml, P_ID::HAIRPIN_CIRCLEDTIP);
writeProperty(xml, P_ID::DYNAMIC_RANGE);
writeProperty(xml, P_ID::PLACEMENT);
writeProperty(xml, P_ID::HAIRPIN_HEIGHT);
writeProperty(xml, P_ID::HAIRPIN_CONT_HEIGHT);
2015-08-23 22:08:14 +02:00
TextLine::writeProperties(xml);
2012-05-26 14:26:10 +02:00
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Hairpin::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
foreach(SpannerSegment* seg, spannerSegments())
delete seg;
spannerSegments().clear();
2013-01-11 18:10:18 +01:00
2014-07-21 13:24:21 +02:00
int id = e.intAttribute("id", -1);
e.addSpanner(id, this);
2013-01-11 18:10:18 +01:00
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
2012-05-26 14:26:10 +02:00
if (tag == "subtype")
setHairpinType(Type(e.readInt()));
2013-08-09 11:42:24 +02:00
else if (tag == "lineWidth") {
setLineWidth(Spatium(e.readDouble()));
lineWidthStyle = PropertyStyle::UNSTYLED;
}
2013-08-13 14:26:40 +02:00
else if (tag == "hairpinHeight") {
setHairpinHeight(Spatium(e.readDouble()));
hairpinHeightStyle = PropertyStyle::UNSTYLED;
}
else if (tag == "hairpinContHeight") {
setHairpinContHeight(Spatium(e.readDouble()));
hairpinContHeightStyle = PropertyStyle::UNSTYLED;
}
else if (tag == "hairpinCircledTip")
_hairpinCircledTip = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "veloChange")
2013-01-11 18:10:18 +01:00
_veloChange = e.readInt();
else if (tag == "dynType")
_dynRange = Dynamic::Range(e.readInt());
2016-07-25 12:29:24 +02:00
else if (tag == "useTextLine") { // obsolete
e.readInt();
if (hairpinType() == Type::CRESC_HAIRPIN)
setHairpinType(Type::CRESC_LINE);
else if (hairpinType() == Type::DECRESC_HAIRPIN)
setHairpinType(Type::DECRESC_LINE);
}
2015-08-23 22:08:14 +02:00
else if (!TextLine::readProperties(e))
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// undoSetHairpinType
//---------------------------------------------------------
void Hairpin::undoSetHairpinType(Type val)
{
2016-06-09 09:26:13 +02:00
undoChangeProperty(P_ID::HAIRPIN_TYPE, int(val));
}
//---------------------------------------------------------
// undoSetVeloChange
//---------------------------------------------------------
void Hairpin::undoSetVeloChange(int val)
{
2016-06-09 09:26:13 +02:00
undoChangeProperty(P_ID::VELO_CHANGE, val);
}
//---------------------------------------------------------
// undoSetDynType
//---------------------------------------------------------
void Hairpin::undoSetDynRange(Dynamic::Range val)
{
2016-06-09 09:26:13 +02:00
undoChangeProperty(P_ID::DYNAMIC_RANGE, int(val));
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
2012-08-10 17:01:35 +02:00
QVariant Hairpin::getProperty(P_ID id) const
2012-05-26 14:26:10 +02:00
{
2013-05-02 16:12:17 +02:00
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CIRCLEDTIP:
return _hairpinCircledTip;
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_TYPE:
2014-05-21 15:45:01 +02:00
return int(_hairpinType);
2014-05-26 18:18:01 +02:00
case P_ID::VELO_CHANGE:
return _veloChange;
2014-05-26 18:18:01 +02:00
case P_ID::DYNAMIC_RANGE:
return int(_dynRange);
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_HEIGHT:
2016-03-05 15:31:26 +01:00
return _hairpinHeight;
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CONT_HEIGHT:
2016-03-05 15:31:26 +01:00
return _hairpinContHeight;
default:
2015-08-23 22:08:14 +02:00
return TextLine::getProperty(id);
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
2012-08-10 17:01:35 +02:00
bool Hairpin::setProperty(P_ID id, const QVariant& v)
2012-05-26 14:26:10 +02:00
{
2013-05-02 16:12:17 +02:00
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CIRCLEDTIP:
_hairpinCircledTip = v.toBool();
break;
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_TYPE:
setHairpinType(Type(v.toInt()));
setGenerated(false);
break;
2014-05-26 18:18:01 +02:00
case P_ID::VELO_CHANGE:
_veloChange = v.toInt();
break;
2014-05-26 18:18:01 +02:00
case P_ID::DYNAMIC_RANGE:
_dynRange = Dynamic::Range(v.toInt());
break;
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2013-08-09 11:42:24 +02:00
lineWidthStyle = PropertyStyle::UNSTYLED;
2015-08-23 22:08:14 +02:00
TextLine::setProperty(id, v);
2013-08-09 11:42:24 +02:00
break;
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_HEIGHT:
hairpinHeightStyle = PropertyStyle::UNSTYLED;
2016-03-05 15:31:26 +01:00
_hairpinHeight = v.value<Spatium>();
2013-08-13 14:26:40 +02:00
break;
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CONT_HEIGHT:
2013-08-13 14:26:40 +02:00
hairpinContHeightStyle = PropertyStyle::UNSTYLED;
2016-03-05 15:31:26 +01:00
_hairpinContHeight = v.value<Spatium>();
2013-08-13 14:26:40 +02:00
break;
default:
2015-08-23 22:08:14 +02:00
return TextLine::setProperty(id, v);
2012-05-26 14:26:10 +02:00
}
triggerLayout();
return true;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Hairpin::propertyDefault(P_ID id) const
{
2013-05-02 16:12:17 +02:00
switch (id) {
case P_ID::TEXT_STYLE_TYPE: return int(TextStyleType::HAIRPIN);
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CIRCLEDTIP: return false;
//no default case P_ID::HAIRPIN_TYPE: return int(Type::CRESC_HAIRPIN);
case P_ID::VELO_CHANGE: return 0;
case P_ID::DYNAMIC_RANGE: return int(Dynamic::Range::PART);
2016-03-05 15:31:26 +01:00
case P_ID::LINE_WIDTH: return score()->style(StyleIdx::hairpinLineWidth);
case P_ID::HAIRPIN_HEIGHT: return score()->style(StyleIdx::hairpinHeight);
case P_ID::HAIRPIN_CONT_HEIGHT: return score()->style(StyleIdx::hairpinContHeight);
case P_ID::LINE_STYLE:
if (_hairpinType == Type::CRESC_HAIRPIN || _hairpinType == Type::DECRESC_HAIRPIN)
return int(Qt::SolidLine);
return int(Qt::CustomDashLine);
2013-08-13 14:26:40 +02:00
default:
2015-08-23 22:08:14 +02:00
return TextLine::propertyDefault(id);
}
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle Hairpin::propertyStyle(P_ID id) const
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH: return lineWidthStyle;
case P_ID::HAIRPIN_HEIGHT: return hairpinHeightStyle;
case P_ID::HAIRPIN_CONT_HEIGHT: return hairpinContHeightStyle;
2013-08-13 14:26:40 +02:00
default:
2015-08-23 22:08:14 +02:00
return TextLine::propertyStyle(id);
2013-08-09 11:42:24 +02:00
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void Hairpin::resetProperty(P_ID id)
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2016-03-05 15:31:26 +01:00
setProperty(id, propertyDefault(id));
2013-08-09 11:42:24 +02:00
lineWidthStyle = PropertyStyle::STYLED;
break;
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_HEIGHT:
2016-03-05 15:31:26 +01:00
setProperty(id, propertyDefault(id));
2013-08-13 14:26:40 +02:00
hairpinHeightStyle = PropertyStyle::STYLED;
break;
2014-05-26 18:18:01 +02:00
case P_ID::HAIRPIN_CONT_HEIGHT:
2016-03-05 15:31:26 +01:00
setLineWidth(score()->styleS(StyleIdx::hairpinLineWidth));
2013-08-13 14:26:40 +02:00
hairpinContHeightStyle = PropertyStyle::STYLED;
break;
2013-08-09 11:42:24 +02:00
default:
2015-08-23 22:08:14 +02:00
return TextLine::resetProperty(id);
2013-08-09 11:42:24 +02:00
}
triggerLayout();
2013-08-09 11:42:24 +02:00
}
2016-07-20 12:45:34 +02:00
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
StyleIdx Hairpin::getPropertyStyle(P_ID id) const
{
switch (id) {
case P_ID::LINE_WIDTH:
return StyleIdx::hairpinLineWidth;
case P_ID::HAIRPIN_HEIGHT:
return StyleIdx::hairpinHeight;
case P_ID::HAIRPIN_CONT_HEIGHT:
return StyleIdx::hairpinContHeight;
default:
break;
}
return StyleIdx::NOSTYLE;
}
2013-03-27 17:52:26 +01:00
//---------------------------------------------------------
// setYoff
//---------------------------------------------------------
void Hairpin::setYoff(qreal val)
{
2014-05-26 15:31:36 +02:00
rUserYoffset() += (val - score()->styleS(StyleIdx::hairpinY).val()) * spatium();
2013-03-27 17:52:26 +01:00
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// styleChanged
// reset all styled values to actual style
//---------------------------------------------------------
void Hairpin::styleChanged()
{
if (lineWidthStyle == PropertyStyle::STYLED)
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::hairpinLineWidth));
2013-08-13 14:26:40 +02:00
if (hairpinHeightStyle == PropertyStyle::STYLED)
2014-05-26 15:31:36 +02:00
setHairpinHeight(score()->styleS(StyleIdx::hairpinHeight));
2013-08-13 14:26:40 +02:00
if (hairpinContHeightStyle == PropertyStyle::STYLED)
2014-05-26 15:31:36 +02:00
setHairpinContHeight(score()->styleS(StyleIdx::hairpinContHeight));
2013-08-09 11:42:24 +02:00
}
2013-08-09 13:19:54 +02:00
//---------------------------------------------------------
// reset
//---------------------------------------------------------
void Hairpin::reset()
{
if (lineWidthStyle == PropertyStyle::UNSTYLED)
2016-06-09 09:26:13 +02:00
undoChangeProperty(P_ID::LINE_WIDTH, propertyDefault(P_ID::LINE_WIDTH), PropertyStyle::STYLED);
2013-08-13 14:26:40 +02:00
if (hairpinHeightStyle == PropertyStyle::UNSTYLED)
2016-06-09 09:26:13 +02:00
undoChangeProperty(P_ID::HAIRPIN_HEIGHT, propertyDefault(P_ID::HAIRPIN_HEIGHT), PropertyStyle::STYLED);
2013-08-13 14:26:40 +02:00
if (hairpinContHeightStyle == PropertyStyle::UNSTYLED)
2016-06-09 09:26:13 +02:00
undoChangeProperty(P_ID::HAIRPIN_CONT_HEIGHT, propertyDefault(P_ID::HAIRPIN_CONT_HEIGHT), PropertyStyle::STYLED);
2015-08-23 22:08:14 +02:00
TextLine::reset();
2013-08-09 13:19:54 +02:00
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
2016-02-04 17:06:32 +01:00
QString Hairpin::accessibleInfo() const
{
2015-08-23 22:08:14 +02:00
QString rez = TextLine::accessibleInfo();
switch (hairpinType()) {
case Type::CRESC_HAIRPIN:
rez += ": " + tr("Crescendo");
break;
case Type::DECRESC_HAIRPIN:
2015-08-23 22:08:14 +02:00
rez += ": " + tr("Decrescendo");
break;
default:
rez += ": " + tr("Custom");
}
return rez;
}
//---------------------------------------------------------
// startEdit
//---------------------------------------------------------
void Hairpin::startEdit(MuseScoreView* view, const QPointF& p)
{
editHairpinHeight = _hairpinHeight;
2015-08-23 22:08:14 +02:00
TextLine::startEdit(view, p);
}
//---------------------------------------------------------
// endEdit
//---------------------------------------------------------
void Hairpin::endEdit()
{
if (editHairpinHeight != _hairpinHeight)
2016-03-05 15:31:26 +01:00
score()->undoPropertyChanged(this, P_ID::HAIRPIN_HEIGHT, editHairpinHeight);
2015-08-23 22:08:14 +02:00
TextLine::endEdit();
}
2013-05-13 18:49:17 +02:00
}