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:
|
2014-06-18 20:57:45 +02:00
|
|
|
case P_ID::BEGIN_TEXT_PLACE:
|
|
|
|
case P_ID::CONTINUE_TEXT_PLACE:
|
|
|
|
case P_ID::ANCHOR:
|
|
|
|
case P_ID::BEGIN_HOOK:
|
|
|
|
case P_ID::BEGIN_HOOK_HEIGHT:
|
|
|
|
case P_ID::END_HOOK_HEIGHT:
|
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)
|
|
|
|
{
|
2014-05-30 10:13:29 +02:00
|
|
|
setBeginText("1.", TextStyleType::VOLTA);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2014-05-26 22:55:18 +02:00
|
|
|
setBeginTextPlace(PlaceText::BELOW);
|
|
|
|
setContinueTextPlace(PlaceText::BELOW);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
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);
|
2014-05-26 20:48:27 +02:00
|
|
|
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
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-06-25 22:28:47 +02:00
|
|
|
void Volta::setVoltaType(Type val)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2014-06-25 22:28:47 +02:00
|
|
|
setEndHook(Type::CLOSED == val);
|
2014-06-18 20:57:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// voltaType
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-06-25 22:28:47 +02:00
|
|
|
Volta::Type Volta::voltaType() const
|
2014-06-18 20:57:45 +02:00
|
|
|
{
|
2014-06-25 22:28:47 +02:00
|
|
|
return endHook() ? Type::CLOSED : Type::OPEN;
|
2014-06-18 20:57:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// undoSetVoltaType
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-06-25 22:28:47 +02:00
|
|
|
void Volta::undoSetVoltaType(Type val)
|
2014-06-18 20:57:45 +02:00
|
|
|
{
|
|
|
|
undoChangeProperty(P_ID::VOLTA_TYPE, int(val));
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setText
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::setText(const QString& s)
|
|
|
|
{
|
2014-05-30 10:13:29 +02:00
|
|
|
setBeginText(s, TextStyleType::VOLTA);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// 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
|
|
|
|
2014-07-21 13:24:21 +02:00
|
|
|
e.addSpanner(e.intAttribute("id", -1), this);
|
2013-01-11 18:10:18 +01:00
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
const QStringRef& tag(e.name());
|
2014-06-18 20:57:45 +02:00
|
|
|
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
|
|
|
}
|
2014-07-23 05:03:48 +02:00
|
|
|
else if (tag == "subtype") { // obsolete
|
|
|
|
int st = e.readInt();
|
|
|
|
if (st == 1)
|
|
|
|
setEndHook(true);
|
|
|
|
}
|
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
|
|
|
|
{
|
2014-07-21 13:24:21 +02:00
|
|
|
xml.stag(QString("%1 id=\"%2\"").arg(name()).arg(xml.spannerId(this)));
|
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:
|
2014-06-25 22:28:47 +02:00
|
|
|
setVoltaType(Type(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;
|
|
|
|
}
|
2014-08-12 15:32:32 +02:00
|
|
|
// layout();
|
|
|
|
// score()->addRefresh(pageBoundingRect());
|
|
|
|
score()->setLayoutAll(true);
|
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
|
|
|
|
2014-06-18 20:57:45 +02:00
|
|
|
case P_ID::BEGIN_TEXT_PLACE:
|
|
|
|
case P_ID::CONTINUE_TEXT_PLACE:
|
|
|
|
return int(PlaceText::BELOW);
|
|
|
|
|
|
|
|
case P_ID::ANCHOR:
|
|
|
|
return int(Anchor::MEASURE);
|
|
|
|
|
|
|
|
case P_ID::BEGIN_HOOK:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case P_ID::BEGIN_HOOK_HEIGHT:
|
|
|
|
case P_ID::END_HOOK_HEIGHT:
|
|
|
|
return score()->styleS(StyleIdx::voltaHook).val();
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|