MuseScore/libmscore/pedal.cpp
2014-05-28 16:17:40 +02:00

306 lines
9.2 KiB
C++

//=============================================================================
// 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 "pedal.h"
#include "textline.h"
#include "sym.h"
#include "xml.h"
#include "system.h"
#include "measure.h"
#include "chordrest.h"
#include "score.h"
namespace Ms {
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void PedalSegment::layout()
{
TextLineSegment::layout1();
if (parent()) // for palette
rypos() += score()->styleS(StyleIdx::pedalY).val() * spatium();
adjustReadPos();
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool PedalSegment::setProperty(P_ID id, const QVariant& v)
{
switch (id) {
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
return pedal()->setProperty(id, v);
default:
return TextLineSegment::setProperty(id, v);
}
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant PedalSegment::propertyDefault(P_ID id) const
{
switch (id) {
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
return pedal()->propertyDefault(id);
default:
return TextLineSegment::propertyDefault(id);
}
}
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle PedalSegment::propertyStyle(P_ID id) const
{
switch (id) {
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
return pedal()->propertyStyle(id);
default:
return TextLineSegment::propertyStyle(id);
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void PedalSegment::resetProperty(P_ID id)
{
switch (id) {
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
return pedal()->resetProperty(id);
default:
return TextLineSegment::resetProperty(id);
}
}
//---------------------------------------------------------
// styleChanged
//---------------------------------------------------------
void PedalSegment::styleChanged()
{
pedal()->styleChanged();
}
//---------------------------------------------------------
// Pedal
//---------------------------------------------------------
Pedal::Pedal(Score* s)
: TextLine(s)
{
setBeginHookHeight(Spatium(-1.2));
setEndHookHeight(Spatium(-1.2));
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
lineWidthStyle = PropertyStyle::STYLED;
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
lineStyleStyle = PropertyStyle::STYLED;
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void Pedal::read(XmlReader& e)
{
if (score()->mscVersion() >= 110) {
// setBeginSymbol(SymId::noSym);
setEndHook(false);
}
setId(e.intAttribute("id", -1));
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "subtype") // obsolete
e.skipCurrentElement();
else if (tag == "lineWidth") {
setLineWidth(Spatium(e.readDouble()));
lineWidthStyle = PropertyStyle::UNSTYLED;
}
else if (tag == "lineStyle") {
setLineStyle(Qt::PenStyle(e.readInt()));
lineStyleStyle = PropertyStyle::UNSTYLED;
}
else if (!TextLine::readProperties(e))
e.unknown();
}
}
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
LineSegment* Pedal::createLineSegment()
{
return new PedalSegment(score());
}
//---------------------------------------------------------
// setYoff
//---------------------------------------------------------
void Pedal::setYoff(qreal val)
{
rUserYoffset() += (val - score()->styleS(StyleIdx::pedalY).val()) * spatium();
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Pedal::setProperty(P_ID propertyId, const QVariant& val)
{
switch (propertyId) {
case P_ID::LINE_WIDTH:
lineWidthStyle = PropertyStyle::UNSTYLED;
TextLine::setProperty(propertyId, val);
break;
case P_ID::LINE_STYLE:
lineStyleStyle = PropertyStyle::UNSTYLED;
TextLine::setProperty(propertyId, val);
break;
default:
if (!TextLine::setProperty(propertyId, val))
return false;
break;
}
score()->setLayoutAll(true);
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Pedal::propertyDefault(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::LINE_WIDTH:
return score()->styleS(StyleIdx::pedalLineWidth).val();
case P_ID::LINE_STYLE:
return int(score()->styleI(StyleIdx::pedalLineStyle));
default:
return TextLine::propertyDefault(propertyId);
}
}
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle Pedal::propertyStyle(P_ID id) const
{
switch (id) {
case P_ID::LINE_WIDTH:
return lineWidthStyle;
case P_ID::LINE_STYLE:
return lineStyleStyle;
default:
return TextLine::propertyStyle(id);
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void Pedal::resetProperty(P_ID id)
{
switch (id) {
case P_ID::LINE_WIDTH:
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
lineWidthStyle = PropertyStyle::STYLED;
break;
case P_ID::LINE_STYLE:
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
lineStyleStyle = PropertyStyle::STYLED;
break;
default:
return TextLine::resetProperty(id);
}
}
//---------------------------------------------------------
// styleChanged
// reset all styled values to actual style
//---------------------------------------------------------
void Pedal::styleChanged()
{
if (lineWidthStyle == PropertyStyle::STYLED)
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
if (lineStyleStyle == PropertyStyle::STYLED)
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
}
//---------------------------------------------------------
// linePos
// return System() coordinates
//---------------------------------------------------------
QPointF Pedal::linePos(GripLine grip, System** sys)
{
qreal x;
qreal nhw = score()->noteHeadWidth();
System* s;
if (grip == GripLine::START) {
ChordRest* c = static_cast<ChordRest*>(startElement());
s = c->segment()->system();
x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
if (beginHook() && beginHookType() == HookType::HOOK_45)
x += nhw * .5;
}
else {
ChordRest* c = static_cast<ChordRest*>(endElement());
if (c) {
s = c->segment()->system();
x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
}
else {
int t = tick2();
Measure* m = score()->tick2measure(t);
s = m->system();
x = m->tick2pos(t);
}
if (endHook() && endHookType() == HookType::HOOK_45)
x += nhw * .5;
else
x += nhw;
}
*sys = s;
return QPointF(x, s->staffYpage(staffIdx()) - s->pos().y());
}
}