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"
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-10-27 14:46:35 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void VoltaSegment::layout()
|
|
|
|
{
|
2013-04-15 19:16:47 +02:00
|
|
|
rypos() = 0.0;
|
2012-11-04 12:50:36 +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::voltaY).val() * spatium();
|
2012-10-27 14:46:35 +02:00
|
|
|
adjustReadPos();
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
2013-05-02 16:12:17 +02:00
|
|
|
// getProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QVariant VoltaSegment::getProperty(P_ID id) const
|
|
|
|
{
|
|
|
|
switch (id) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-05-02 16:12:17 +02:00
|
|
|
return volta()->getProperty(id);
|
|
|
|
default:
|
|
|
|
return TextLineSegment::getProperty(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool VoltaSegment::setProperty(P_ID id, const QVariant& v)
|
|
|
|
{
|
|
|
|
switch (id) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-05-02 16:12:17 +02:00
|
|
|
return volta()->setProperty(id, v);
|
|
|
|
default:
|
|
|
|
return TextLineSegment::setProperty(id, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// propertyDefault
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QVariant VoltaSegment::propertyDefault(P_ID id) const
|
|
|
|
{
|
|
|
|
switch (id) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-05-02 16:12:17 +02:00
|
|
|
return volta()->propertyDefault(id);
|
|
|
|
default:
|
|
|
|
return TextLineSegment::propertyDefault(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 21:15:25 +02:00
|
|
|
//---------------------------------------------------------
|
2013-08-07 13:20:44 +02:00
|
|
|
// propertyStyle
|
2013-08-06 21:15:25 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2013-08-07 13:20:44 +02:00
|
|
|
PropertyStyle VoltaSegment::propertyStyle(P_ID id) const
|
2013-08-06 21:15:25 +02:00
|
|
|
{
|
|
|
|
switch (id) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-08-06 21:15:25 +02:00
|
|
|
return PropertyStyle::NOSTYLE;
|
|
|
|
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
2013-08-07 13:20:44 +02:00
|
|
|
return volta()->propertyStyle(id);
|
2013-08-06 21:15:25 +02:00
|
|
|
|
|
|
|
default:
|
2013-08-07 13:20:44 +02:00
|
|
|
return TextLineSegment::propertyStyle(id);
|
2013-08-06 21:15:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// resetProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void VoltaSegment::resetProperty(P_ID id)
|
|
|
|
{
|
|
|
|
switch (id) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-08-06 21:15:25 +02:00
|
|
|
return;
|
|
|
|
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
2013-08-06 21:15:25 +02:00
|
|
|
return volta()->resetProperty(id);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return TextLineSegment::resetProperty(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// styleChanged
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void VoltaSegment::styleChanged()
|
|
|
|
{
|
|
|
|
volta()->styleChanged();
|
|
|
|
}
|
|
|
|
|
2013-05-02 16:12:17 +02:00
|
|
|
//---------------------------------------------------------
|
2012-05-26 14:26:10 +02:00
|
|
|
// Volta
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Volta::Volta(Score* s)
|
|
|
|
: TextLine(s)
|
|
|
|
{
|
2013-03-05 20:23:59 +01:00
|
|
|
_voltaType = VoltaType::OPEN;
|
2014-03-06 14:53:07 +01:00
|
|
|
setBeginText("1.", TEXT_STYLE_VOLTA);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
setBeginTextPlace(PLACE_BELOW);
|
|
|
|
setContinueTextPlace(PLACE_BELOW);
|
|
|
|
|
|
|
|
setBeginHook(true);
|
2014-05-26 15:31:36 +02:00
|
|
|
Spatium hook(s->styleS(StyleIdx::voltaHook));
|
2012-05-26 14:26:10 +02:00
|
|
|
setBeginHookHeight(hook);
|
|
|
|
setEndHookHeight(hook);
|
|
|
|
setAnchor(ANCHOR_MEASURE);
|
2013-08-06 21:15:25 +02:00
|
|
|
|
2014-05-26 15:31:36 +02:00
|
|
|
setLineWidth(score()->styleS(StyleIdx::voltaLineWidth));
|
2013-08-07 13:20:44 +02:00
|
|
|
lineWidthStyle = PropertyStyle::STYLED;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2013-03-05 20:23:59 +01:00
|
|
|
// setVoltaType
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2013-03-05 20:23:59 +01:00
|
|
|
void Volta::setVoltaType(VoltaType val)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2013-03-05 20:23:59 +01:00
|
|
|
_voltaType = val;
|
|
|
|
switch (val) {
|
|
|
|
case VoltaType::OPEN:
|
2012-05-26 14:26:10 +02:00
|
|
|
setEndHook(false);
|
|
|
|
break;
|
2013-03-05 20:23:59 +01:00
|
|
|
case VoltaType::CLOSED:
|
2012-05-26 14:26:10 +02:00
|
|
|
setEndHook(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::layout()
|
|
|
|
{
|
|
|
|
TextLine::layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setText
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::setText(const QString& s)
|
|
|
|
{
|
2014-03-06 14:53:07 +01:00
|
|
|
setBeginText(s, TEXT_STYLE_VOLTA);
|
2012-05-26 14:26:10 +02:00
|
|
|
foreach(SpannerSegment* seg, spannerSegments())
|
|
|
|
static_cast<VoltaSegment*>(seg)->clearText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// text
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QString Volta::text() const
|
|
|
|
{
|
2014-03-06 14:53:07 +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")
|
2013-03-05 20:23:59 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-08-06 21:15:25 +02:00
|
|
|
else if (tag == "lineWidth") {
|
|
|
|
setLineWidth(Spatium(e.readDouble()));
|
2013-08-07 13:20:44 +02:00
|
|
|
lineWidthStyle = PropertyStyle::UNSTYLED;
|
2013-08-06 21:15:25 +02:00
|
|
|
}
|
2012-05-26 14:26:10 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// write
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::write(Xml& xml) const
|
|
|
|
{
|
|
|
|
xml.stag(QString("%1 id=\"%2\"").arg(name()).arg(id()));
|
2013-03-05 20:23:59 +01:00
|
|
|
xml.tag("subtype", int(_voltaType));
|
2013-08-09 11:42:24 +02:00
|
|
|
TextLine::writeProperties(xml);
|
2012-05-26 14:26:10 +02:00
|
|
|
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
|
|
|
|
{
|
2013-08-06 21:15:25 +02:00
|
|
|
foreach (int ending, endings()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
if (ending == repeat)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:37:31 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// getProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QVariant Volta::getProperty(P_ID propertyId) const
|
|
|
|
{
|
2013-08-06 21:15:25 +02:00
|
|
|
switch (propertyId) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-03-05 20:23:59 +01:00
|
|
|
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());
|
2013-08-06 21:15:25 +02:00
|
|
|
switch (propertyId) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-03-05 20:23:59 +01:00
|
|
|
setVoltaType(VoltaType(val.toInt()));
|
2012-09-17 15:37:31 +02:00
|
|
|
break;
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
2013-08-07 13:20:44 +02:00
|
|
|
lineWidthStyle = PropertyStyle::UNSTYLED;
|
2013-08-06 21:15:25 +02:00
|
|
|
// fall through
|
2012-09-17 15:37:31 +02:00
|
|
|
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) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2012-09-17 15:37:31 +02:00
|
|
|
return 0;
|
2013-08-06 21:15:25 +02:00
|
|
|
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
2014-05-26 15:31:36 +02:00
|
|
|
return score()->styleS(StyleIdx::voltaLineWidth).val();
|
2013-08-06 21:15:25 +02:00
|
|
|
|
2012-09-17 15:37:31 +02:00
|
|
|
default:
|
2012-09-17 18:09:30 +02:00
|
|
|
return TextLine::propertyDefault(propertyId);
|
2012-09-17 15:37:31 +02:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2013-03-05 20:23:59 +01:00
|
|
|
// undoSetVoltaType
|
2012-09-17 15:37:31 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2013-03-05 20:23:59 +01:00
|
|
|
void Volta::undoSetVoltaType(VoltaType val)
|
2012-09-17 15:37:31 +02:00
|
|
|
{
|
2014-05-26 18:18:01 +02:00
|
|
|
score()->undoChangeProperty(this, P_ID::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)
|
|
|
|
{
|
2014-05-26 15:31:36 +02:00
|
|
|
rUserYoffset() += (val - score()->styleS(StyleIdx::voltaY).val()) * spatium();
|
2012-10-27 14:46:35 +02:00
|
|
|
}
|
|
|
|
|
2013-08-06 21:15:25 +02:00
|
|
|
//---------------------------------------------------------
|
2013-08-07 13:20:44 +02:00
|
|
|
// propertyStyle
|
2013-08-06 21:15:25 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2013-08-07 13:20:44 +02:00
|
|
|
PropertyStyle Volta::propertyStyle(P_ID id) const
|
2013-08-06 21:15:25 +02:00
|
|
|
{
|
|
|
|
switch (id) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-08-06 21:15:25 +02:00
|
|
|
return PropertyStyle::NOSTYLE;
|
|
|
|
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
2013-08-07 13:20:44 +02:00
|
|
|
return lineWidthStyle;
|
2013-08-06 21:15:25 +02:00
|
|
|
|
|
|
|
default:
|
2013-08-07 13:20:44 +02:00
|
|
|
return TextLine::propertyStyle(id);
|
2013-08-06 21:15:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// resetProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::resetProperty(P_ID id)
|
|
|
|
{
|
|
|
|
switch (id) {
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::VOLTA_TYPE:
|
2013-08-06 21:15:25 +02:00
|
|
|
return;
|
|
|
|
|
2014-05-26 18:18:01 +02:00
|
|
|
case P_ID::LINE_WIDTH:
|
2014-05-26 15:31:36 +02:00
|
|
|
setLineWidth(score()->styleS(StyleIdx::voltaLineWidth));
|
2013-08-07 13:20:44 +02:00
|
|
|
lineWidthStyle = PropertyStyle::STYLED;
|
2013-08-06 21:15:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return TextLine::resetProperty(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// styleChanged
|
|
|
|
// reset all styled values to actual style
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::styleChanged()
|
|
|
|
{
|
2013-08-07 13:20:44 +02:00
|
|
|
if (lineWidthStyle == PropertyStyle::STYLED)
|
2014-05-26 15:31:36 +02:00
|
|
|
setLineWidth(score()->styleS(StyleIdx::voltaLineWidth));
|
2013-08-06 21:15:25 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 13:19:54 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// reset
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::reset()
|
|
|
|
{
|
|
|
|
if (lineWidthStyle == PropertyStyle::UNSTYLED)
|
2014-05-26 18:18:01 +02:00
|
|
|
score()->undoChangeProperty(this, P_ID::LINE_WIDTH, propertyDefault(P_ID::LINE_WIDTH), PropertyStyle::STYLED);
|
2013-08-09 13:19:54 +02:00
|
|
|
TextLine::reset();
|
|
|
|
}
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|