MuseScore/libmscore/pedal.cpp

269 lines
7.8 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 "pedal.h"
#include "textline.h"
#include "sym.h"
2014-04-09 16:09:21 +02:00
#include "xml.h"
2012-05-26 14:26:10 +02:00
#include "score.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void PedalSegment::layout()
{
2012-11-07 16:47:42 +01:00
TextLineSegment::layout1();
2012-11-08 12:59:30 +01:00
if (parent()) // for palette
2014-05-26 15:31:36 +02:00
rypos() += score()->styleS(StyleIdx::pedalY).val() * spatium();
2012-10-27 14:46:35 +02:00
adjustReadPos();
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool PedalSegment::setProperty(P_ID id, const QVariant& v)
{
switch (id) {
case P_LINE_WIDTH:
case P_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_LINE_WIDTH:
case P_LINE_STYLE:
return pedal()->propertyDefault(id);
default:
return TextLineSegment::propertyDefault(id);
}
}
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle PedalSegment::propertyStyle(P_ID id) const
{
switch (id) {
case P_LINE_WIDTH:
case P_LINE_STYLE:
return pedal()->propertyStyle(id);
default:
return TextLineSegment::propertyStyle(id);
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void PedalSegment::resetProperty(P_ID id)
{
switch (id) {
case P_LINE_WIDTH:
case P_LINE_STYLE:
return pedal()->resetProperty(id);
default:
return TextLineSegment::resetProperty(id);
}
}
//---------------------------------------------------------
// styleChanged
//---------------------------------------------------------
void PedalSegment::styleChanged()
{
pedal()->styleChanged();
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Pedal
//---------------------------------------------------------
Pedal::Pedal(Score* s)
: TextLine(s)
{
2014-03-16 14:57:32 +01:00
setBeginText("<sym>keyboardPedalPed</sym>");
2012-05-26 14:26:10 +02:00
setEndHook(true);
setBeginHookHeight(Spatium(-1.2));
setEndHookHeight(Spatium(-1.2));
2013-08-09 11:42:24 +02:00
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
2013-08-09 11:42:24 +02:00
lineWidthStyle = PropertyStyle::STYLED;
2014-05-26 15:31:36 +02:00
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
2013-08-09 11:42:24 +02:00
lineStyleStyle = PropertyStyle::STYLED;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Pedal::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
if (score()->mscVersion() >= 110) {
// setBeginSymbol(SymId::noSym);
2012-05-26 14:26:10 +02:00
setEndHook(false);
}
setId(e.intAttribute("id", -1));
while (e.readNextStartElement()) {
2013-08-09 11:42:24 +02:00
const QStringRef& tag(e.name());
if (tag == "subtype") // obsolete
e.skipCurrentElement();
2013-08-09 11:42:24 +02:00
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();
}
2012-05-26 14:26:10 +02:00
}
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
LineSegment* Pedal::createLineSegment()
{
return new PedalSegment(score());
}
//---------------------------------------------------------
// setYoff
//---------------------------------------------------------
void Pedal::setYoff(qreal val)
{
2014-05-26 15:31:36 +02:00
rUserYoffset() += (val - score()->styleS(StyleIdx::pedalY).val()) * spatium();
2012-10-27 14:46:35 +02:00
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Pedal::setProperty(P_ID propertyId, const QVariant& val)
{
switch (propertyId) {
case P_LINE_WIDTH:
lineWidthStyle = PropertyStyle::UNSTYLED;
TextLine::setProperty(propertyId, val);
break;
case P_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_LINE_WIDTH:
2014-05-26 15:31:36 +02:00
return score()->styleS(StyleIdx::pedalLineWidth).val();
2013-08-09 11:42:24 +02:00
case P_LINE_STYLE:
2014-05-26 15:31:36 +02:00
return int(score()->styleI(StyleIdx::pedalLineStyle));
2013-08-09 11:42:24 +02:00
default:
return TextLine::propertyDefault(propertyId);
}
}
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle Pedal::propertyStyle(P_ID id) const
{
switch (id) {
case P_LINE_WIDTH:
return lineWidthStyle;
case P_LINE_STYLE:
return lineStyleStyle;
default:
return TextLine::propertyStyle(id);
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void Pedal::resetProperty(P_ID id)
{
switch (id) {
case P_LINE_WIDTH:
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
2013-08-09 11:42:24 +02:00
lineWidthStyle = PropertyStyle::STYLED;
break;
case P_LINE_STYLE:
2014-05-26 15:31:36 +02:00
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
2013-08-09 11:42:24 +02:00
lineStyleStyle = PropertyStyle::STYLED;
break;
default:
return TextLine::resetProperty(id);
}
}
//---------------------------------------------------------
// styleChanged
// reset all styled values to actual style
//---------------------------------------------------------
void Pedal::styleChanged()
{
if (lineWidthStyle == PropertyStyle::STYLED)
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
2013-08-09 11:42:24 +02:00
if (lineStyleStyle == PropertyStyle::STYLED)
2014-05-26 15:31:36 +02:00
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
2013-08-09 11:42:24 +02:00
}
2013-05-13 18:49:17 +02:00
}