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"
|
2016-07-10 12:00:57 +02:00
|
|
|
#include "system.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2018-08-01 11:46:07 +02:00
|
|
|
static const ElementStyle voltaStyle {
|
|
|
|
{ Sid::voltaFontFace, Pid::BEGIN_FONT_FACE },
|
|
|
|
{ Sid::voltaFontFace, Pid::CONTINUE_FONT_FACE },
|
|
|
|
{ Sid::voltaFontFace, Pid::END_FONT_FACE },
|
|
|
|
{ Sid::voltaFontSize, Pid::BEGIN_FONT_SIZE },
|
|
|
|
{ Sid::voltaFontSize, Pid::CONTINUE_FONT_SIZE },
|
|
|
|
{ Sid::voltaFontSize, Pid::END_FONT_SIZE },
|
|
|
|
{ Sid::voltaFontBold, Pid::BEGIN_FONT_BOLD },
|
|
|
|
{ Sid::voltaFontBold, Pid::CONTINUE_FONT_BOLD },
|
|
|
|
{ Sid::voltaFontBold, Pid::END_FONT_BOLD },
|
|
|
|
{ Sid::voltaFontItalic, Pid::BEGIN_FONT_ITALIC },
|
|
|
|
{ Sid::voltaFontItalic, Pid::CONTINUE_FONT_ITALIC },
|
|
|
|
{ Sid::voltaFontItalic, Pid::END_FONT_ITALIC },
|
|
|
|
{ Sid::voltaFontUnderline, Pid::BEGIN_FONT_UNDERLINE },
|
|
|
|
{ Sid::voltaFontUnderline, Pid::CONTINUE_FONT_UNDERLINE },
|
|
|
|
{ Sid::voltaFontUnderline, Pid::END_FONT_UNDERLINE },
|
|
|
|
{ Sid::voltaAlign, Pid::BEGIN_TEXT_ALIGN },
|
|
|
|
{ Sid::voltaAlign, Pid::CONTINUE_TEXT_ALIGN },
|
|
|
|
{ Sid::voltaAlign, Pid::END_TEXT_ALIGN },
|
|
|
|
{ Sid::voltaOffset, Pid::BEGIN_TEXT_OFFSET },
|
|
|
|
{ Sid::voltaOffset, Pid::CONTINUE_TEXT_OFFSET },
|
|
|
|
{ Sid::voltaOffset, Pid::END_TEXT_OFFSET },
|
|
|
|
{ Sid::voltaLineWidth, Pid::LINE_WIDTH },
|
|
|
|
{ Sid::voltaLineStyle, Pid::LINE_STYLE },
|
|
|
|
{ Sid::voltaHook, Pid::BEGIN_HOOK_HEIGHT },
|
|
|
|
{ Sid::voltaHook, Pid::END_HOOK_HEIGHT },
|
|
|
|
};
|
|
|
|
|
2012-10-27 14:46:35 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void VoltaSegment::layout()
|
|
|
|
{
|
2016-08-30 14:03:26 +02:00
|
|
|
TextLineBaseSegment::layout();
|
2018-09-11 18:10:57 +02:00
|
|
|
autoplaceSpannerSegment(spatium() * .7, Sid::voltaY, Sid::voltaY);
|
2012-10-27 14:46:35 +02:00
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
2018-07-24 15:48:24 +02:00
|
|
|
// propertyDelegate
|
2013-05-02 16:12:17 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-07-24 15:48:24 +02:00
|
|
|
Element* VoltaSegment::propertyDelegate(Pid pid)
|
2013-05-02 16:12:17 +02:00
|
|
|
{
|
2018-07-24 15:48:24 +02:00
|
|
|
if (pid == Pid::BEGIN_HOOK_TYPE || pid == Pid::END_HOOK_TYPE || pid == Pid::VOLTA_ENDING)
|
|
|
|
return spanner();
|
|
|
|
return TextLineBaseSegment::propertyDelegate(pid);
|
2013-08-06 21:15:25 +02:00
|
|
|
}
|
|
|
|
|
2013-05-02 16:12:17 +02:00
|
|
|
//---------------------------------------------------------
|
2012-05-26 14:26:10 +02:00
|
|
|
// Volta
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Volta::Volta(Score* s)
|
2018-08-01 11:46:07 +02:00
|
|
|
: TextLineBase(s, ElementFlag::SYSTEM)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2018-08-01 11:46:07 +02:00
|
|
|
initElementStyle(&voltaStyle);
|
2018-03-27 14:40:34 +02:00
|
|
|
|
2014-05-26 22:55:18 +02:00
|
|
|
setBeginTextPlace(PlaceText::BELOW);
|
|
|
|
setContinueTextPlace(PlaceText::BELOW);
|
2018-03-27 14:40:34 +02:00
|
|
|
setLineVisible(true);
|
2018-03-27 15:36:00 +02:00
|
|
|
resetProperty(Pid::BEGIN_TEXT);
|
|
|
|
resetProperty(Pid::CONTINUE_TEXT);
|
|
|
|
resetProperty(Pid::END_TEXT);
|
|
|
|
resetProperty(Pid::BEGIN_TEXT_PLACE);
|
|
|
|
resetProperty(Pid::CONTINUE_TEXT_PLACE);
|
|
|
|
resetProperty(Pid::END_TEXT_PLACE);
|
|
|
|
resetProperty(Pid::BEGIN_HOOK_TYPE);
|
|
|
|
resetProperty(Pid::END_HOOK_TYPE);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2014-05-26 20:48:27 +02:00
|
|
|
setAnchor(Anchor::MEASURE);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setText
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Volta::setText(const QString& s)
|
|
|
|
{
|
2017-02-07 18:48:23 +01:00
|
|
|
setBeginText(s);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// text
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QString Volta::text() const
|
|
|
|
{
|
2017-02-07 18:48:23 +01:00
|
|
|
return beginText();
|
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
|
|
|
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
const QStringRef& tag(e.name());
|
2017-02-07 18:48:23 +01:00
|
|
|
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();
|
2016-07-10 12:00:57 +02:00
|
|
|
for (const QString& l : sl) {
|
2012-05-26 14:26:10 +02:00
|
|
|
int i = l.simplified().toInt();
|
|
|
|
_endings.append(i);
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 14:03:26 +02:00
|
|
|
else if (!TextLineBase::readProperties(e))
|
2013-01-11 18:10:18 +01:00
|
|
|
e.unknown();
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// write
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-11-19 11:51:21 +01:00
|
|
|
void Volta::write(XmlWriter& xml) const
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2018-05-23 23:27:23 +02:00
|
|
|
xml.stag(name());
|
2016-08-30 14:03:26 +02:00
|
|
|
TextLineBase::writeProperties(xml);
|
2012-05-26 14:26:10 +02:00
|
|
|
QString s;
|
2016-07-10 12:00:57 +02:00
|
|
|
for (int i : _endings) {
|
2012-05-26 14:26:10 +02:00
|
|
|
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
|
|
|
|
{
|
2016-07-10 12:00:57 +02:00
|
|
|
for (int ending : endings()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
if (ending == repeat)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-27 16:12:08 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// lastEnding
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
int Volta::lastEnding() const
|
|
|
|
{
|
|
|
|
if (_endings.isEmpty())
|
|
|
|
return 0;
|
|
|
|
return _endings.last();
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:37:31 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// getProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
QVariant Volta::getProperty(Pid propertyId) const
|
2012-09-17 15:37:31 +02:00
|
|
|
{
|
2013-08-06 21:15:25 +02:00
|
|
|
switch (propertyId) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::VOLTA_ENDING:
|
2014-09-25 11:34:26 +02:00
|
|
|
return QVariant::fromValue(endings());
|
2012-09-17 15:37:31 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-08-30 14:03:26 +02:00
|
|
|
return TextLineBase::getProperty(propertyId);
|
2012-09-17 15:37:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
bool Volta::setProperty(Pid propertyId, const QVariant& val)
|
2012-09-17 15:37:31 +02:00
|
|
|
{
|
2013-08-06 21:15:25 +02:00
|
|
|
switch (propertyId) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::VOLTA_ENDING:
|
2014-09-25 11:34:26 +02:00
|
|
|
setEndings(val.value<QList<int>>());
|
|
|
|
break;
|
2012-09-17 15:37:31 +02:00
|
|
|
default:
|
2016-08-30 14:03:26 +02:00
|
|
|
if (!TextLineBase::setProperty(propertyId, val))
|
2012-09-17 15:37:31 +02:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-14 10:32:34 +02:00
|
|
|
triggerLayout();
|
2012-09-17 15:37:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// propertyDefault
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
QVariant Volta::propertyDefault(Pid propertyId) const
|
2012-09-17 15:37:31 +02:00
|
|
|
{
|
2016-06-14 10:32:34 +02:00
|
|
|
switch (propertyId) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::VOLTA_ENDING:
|
2014-09-25 11:34:26 +02:00
|
|
|
return QVariant::fromValue(QList<int>());
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::ANCHOR:
|
2014-06-18 20:57:45 +02:00
|
|
|
return int(Anchor::MEASURE);
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::BEGIN_HOOK_TYPE:
|
2017-02-07 18:48:23 +01:00
|
|
|
return int(HookType::HOOK_90);
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::END_HOOK_TYPE:
|
2018-03-27 14:40:34 +02:00
|
|
|
return int(HookType::NONE);
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::BEGIN_TEXT:
|
|
|
|
case Pid::CONTINUE_TEXT:
|
|
|
|
case Pid::END_TEXT:
|
2018-03-27 14:40:34 +02:00
|
|
|
return "";
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::LINE_VISIBLE:
|
2018-03-27 14:40:34 +02:00
|
|
|
return true;
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::BEGIN_TEXT_PLACE:
|
|
|
|
case Pid::CONTINUE_TEXT_PLACE:
|
|
|
|
case Pid::END_TEXT_PLACE:
|
2018-03-27 14:40:34 +02:00
|
|
|
return int(PlaceText::ABOVE);
|
2014-06-18 20:57:45 +02:00
|
|
|
|
2012-09-17 15:37:31 +02:00
|
|
|
default:
|
2016-08-30 14:03:26 +02:00
|
|
|
return TextLineBase::propertyDefault(propertyId);
|
2012-09-17 15:37:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 14:46:35 +02:00
|
|
|
//---------------------------------------------------------
|
2017-02-07 18:48:23 +01:00
|
|
|
// accessibleInfo
|
2013-08-06 21:15:25 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2017-02-07 18:48:23 +01:00
|
|
|
QString Volta::accessibleInfo() const
|
2013-08-06 21:15:25 +02:00
|
|
|
{
|
2017-02-07 18:48:23 +01:00
|
|
|
return QString("%1: %2").arg(Element::accessibleInfo()).arg(text());
|
2013-08-06 21:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2017-02-07 18:48:23 +01:00
|
|
|
// setVoltaType
|
|
|
|
// deprecated
|
2013-08-09 13:19:54 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2017-02-07 18:48:23 +01:00
|
|
|
void Volta::setVoltaType(Type val)
|
2013-08-09 13:19:54 +02:00
|
|
|
{
|
2017-02-07 18:48:23 +01:00
|
|
|
setEndHookType(Type::CLOSED == val ? HookType::HOOK_90 : HookType::NONE);
|
2013-08-09 13:19:54 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 14:13:37 +02:00
|
|
|
//---------------------------------------------------------
|
2017-02-07 18:48:23 +01:00
|
|
|
// voltaType
|
|
|
|
// deprecated
|
2014-07-10 14:13:37 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2017-02-07 18:48:23 +01:00
|
|
|
Volta::Type Volta::voltaType() const
|
2014-08-23 04:07:31 +02:00
|
|
|
{
|
2017-02-07 18:48:23 +01:00
|
|
|
return endHookType() != HookType::NONE ? Type::CLOSED : Type::OPEN;
|
2014-07-10 14:13:37 +02:00
|
|
|
}
|
2014-08-23 04:07:31 +02:00
|
|
|
|
2016-07-09 17:07:12 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|