MuseScore/libmscore/volta.cpp

245 lines
7 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 "volta.h"
#include "style.h"
#include "xml.h"
#include "score.h"
#include "text.h"
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void VoltaSegment::layout()
{
2013-04-15 19:16:47 +02:00
rypos() = 0.0;
TextLineSegment::layout1();
2012-11-08 12:59:30 +01:00
if (parent()) // for palette
rypos() += score()->styleS(ST_voltaY).val() * spatium();
2012-10-27 14:46:35 +02:00
adjustReadPos();
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Volta
//---------------------------------------------------------
Volta::Volta(Score* s)
: TextLine(s)
{
_voltaType = VoltaType::OPEN;
2012-05-26 14:26:10 +02:00
setBeginText("1.", s->textStyle(TEXT_STYLE_VOLTA));
setBeginTextPlace(PLACE_BELOW);
setContinueTextPlace(PLACE_BELOW);
setBeginHook(true);
Spatium hook(s->styleS(ST_voltaHook));
setBeginHookHeight(hook);
setEndHookHeight(hook);
setAnchor(ANCHOR_MEASURE);
}
//---------------------------------------------------------
// setVoltaType
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
void Volta::setVoltaType(VoltaType val)
2012-05-26 14:26:10 +02:00
{
_voltaType = val;
switch (val) {
case VoltaType::OPEN:
2012-05-26 14:26:10 +02:00
setEndHook(false);
break;
case VoltaType::CLOSED:
2012-05-26 14:26:10 +02:00
setEndHook(true);
break;
}
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Volta::layout()
{
setLineWidth(score()->styleS(ST_voltaLineWidth));
Spatium hook(score()->styleS(ST_voltaHook));
setBeginHookHeight(hook);
setEndHookHeight(hook);
TextLine::layout();
}
//---------------------------------------------------------
// setText
//---------------------------------------------------------
void Volta::setText(const QString& s)
{
setBeginText(s, score()->textStyle(TEXT_STYLE_VOLTA));
foreach(SpannerSegment* seg, spannerSegments())
static_cast<VoltaSegment*>(seg)->clearText();
}
//---------------------------------------------------------
// text
//---------------------------------------------------------
QString Volta::text() const
{
2013-02-26 15:50:36 +01:00
return beginText()->text();
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Volta::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
2013-01-11 18:10:18 +01:00
qDeleteAll(spannerSegments());
2012-05-26 14:26:10 +02:00
spannerSegments().clear();
2013-01-11 18:10:18 +01:00
setId(e.intAttribute("id", -1));
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
2012-05-26 14:26:10 +02:00
if (tag == "subtype")
setVoltaType(VoltaType(e.readInt()));
2012-05-26 14:26:10 +02:00
else if (tag == "text") // obsolete
2013-01-11 18:10:18 +01:00
setText(e.readElementText());
2012-05-26 14:26:10 +02:00
else if (tag == "endings") {
2013-01-11 18:10:18 +01:00
QString s = e.readElementText();
2012-05-26 14:26:10 +02:00
QStringList sl = s.split(",", QString::SkipEmptyParts);
_endings.clear();
foreach(const QString& l, sl) {
int i = l.simplified().toInt();
_endings.append(i);
}
}
else if (!TextLine::readProperties(e))
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Volta::write(Xml& xml) const
{
Volta proto(score());
proto.setVoltaType(voltaType());
2012-05-26 14:26:10 +02:00
xml.stag(QString("%1 id=\"%2\"").arg(name()).arg(id()));
xml.tag("subtype", int(_voltaType));
2012-05-26 14:26:10 +02:00
TextLine::writeProperties(xml, &proto);
QString s;
foreach(int i, _endings) {
if (!s.isEmpty())
s += ", ";
s += QString("%1").arg(i);
}
xml.tag("endings", s);
xml.etag();
}
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
LineSegment* Volta::createLineSegment()
{
return new VoltaSegment(score());
}
//---------------------------------------------------------
// hasEnding
//---------------------------------------------------------
bool Volta::hasEnding(int repeat) const
{
foreach(int ending, endings()) {
if (ending == repeat)
return true;
}
return false;
}
2012-09-17 15:37:31 +02:00
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Volta::getProperty(P_ID propertyId) const
{
switch(propertyId) {
case P_VOLTA_TYPE:
return int(voltaType());
2012-09-17 15:37:31 +02:00
default:
break;
}
return TextLine::getProperty(propertyId);
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Volta::setProperty(P_ID propertyId, const QVariant& val)
{
2012-09-17 17:35:49 +02:00
score()->addRefresh(pageBoundingRect());
2012-09-17 15:37:31 +02:00
switch(propertyId) {
case P_VOLTA_TYPE:
setVoltaType(VoltaType(val.toInt()));
2012-09-17 15:37:31 +02:00
break;
default:
2012-09-17 18:09:30 +02:00
if (!TextLine::setProperty(propertyId, val))
2012-09-17 15:37:31 +02:00
return false;
break;
}
2012-09-17 16:34:07 +02:00
layout();
score()->addRefresh(pageBoundingRect());
2012-09-17 15:37:31 +02:00
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Volta::propertyDefault(P_ID propertyId) const
{
switch(propertyId) {
case P_VOLTA_TYPE:
return 0;
default:
2012-09-17 18:09:30 +02:00
return TextLine::propertyDefault(propertyId);
2012-09-17 15:37:31 +02:00
}
return QVariant();
}
//---------------------------------------------------------
// undoSetVoltaType
2012-09-17 15:37:31 +02:00
//---------------------------------------------------------
void Volta::undoSetVoltaType(VoltaType val)
2012-09-17 15:37:31 +02:00
{
score()->undoChangeProperty(this, P_VOLTA_TYPE, int(val));
2012-09-17 15:37:31 +02:00
}
2012-09-17 16:34:07 +02:00
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
// setYoff
//---------------------------------------------------------
void Volta::setYoff(qreal val)
{
rUserYoffset() += (val - score()->styleS(ST_voltaY).val()) * spatium();
}