MuseScore/libmscore/volta.cpp

412 lines
12 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"
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 {
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void VoltaSegment::layout()
{
2016-07-10 12:00:57 +02:00
if (autoplace())
setUserOff(QPointF());
TextLineBaseSegment::layout();
2016-07-10 12:00:57 +02:00
if (!parent())
return;
rypos() = score()->styleP(StyleIdx::voltaY) * mag();
if (autoplace()) {
qreal minDistance = spatium() * .7;
Shape s1 = shape().translated(pos());
qreal d = system()->topDistance(staffIdx(), s1);
if (d > -minDistance)
rUserYoffset() = -d - minDistance;
}
else
adjustReadPos();
2012-10-27 14:46:35 +02:00
}
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-09-25 11:34:26 +02:00
case P_ID::VOLTA_ENDING:
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
2017-02-07 18:48:23 +01:00
case P_ID::BEGIN_TEXT_OFFSET:
2013-05-02 16:12:17 +02:00
return volta()->getProperty(id);
default:
return TextLineBaseSegment::getProperty(id);
2013-05-02 16:12:17 +02:00
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool VoltaSegment::setProperty(P_ID id, const QVariant& v)
{
switch (id) {
2014-09-25 11:34:26 +02:00
case P_ID::VOLTA_ENDING:
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
2017-02-07 18:48:23 +01:00
case P_ID::BEGIN_TEXT_OFFSET:
2013-05-02 16:12:17 +02:00
return volta()->setProperty(id, v);
default:
return TextLineBaseSegment::setProperty(id, v);
2013-05-02 16:12:17 +02:00
}
}
//---------------------------------------------------------
// 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::LINE_STYLE:
2014-06-18 20:57:45 +02:00
case P_ID::BEGIN_TEXT_PLACE:
case P_ID::CONTINUE_TEXT_PLACE:
case P_ID::ANCHOR:
2017-02-07 18:48:23 +01:00
// case P_ID::BEGIN_HOOK:
2014-06-18 20:57:45 +02:00
case P_ID::BEGIN_HOOK_HEIGHT:
case P_ID::END_HOOK_HEIGHT:
2014-09-25 11:34:26 +02:00
case P_ID::VOLTA_ENDING:
2017-02-07 18:48:23 +01:00
case P_ID::BEGIN_TEXT_OFFSET:
2017-12-07 14:45:03 +01:00
case P_ID::BEGIN_FONT_BOLD:
2013-05-02 16:12:17 +02:00
return volta()->propertyDefault(id);
default:
return TextLineBaseSegment::propertyDefault(id);
2013-05-02 16:12:17 +02:00
}
}
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
// getPropertyStyle
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
StyleIdx VoltaSegment::getPropertyStyle(P_ID id) const
{
switch (id) {
2017-02-07 18:48:23 +01:00
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
case P_ID::BEGIN_FONT_FACE:
case P_ID::BEGIN_FONT_SIZE:
case P_ID::BEGIN_FONT_BOLD:
case P_ID::BEGIN_FONT_ITALIC:
case P_ID::BEGIN_FONT_UNDERLINE:
case P_ID::BEGIN_TEXT_ALIGN:
case P_ID::BEGIN_TEXT_OFFSET:
return volta()->getPropertyStyle(id);
default:
return TextLineBaseSegment::getPropertyStyle(id);
}
}
2017-02-07 18:48:23 +01:00
//---------------------------------------------------------
// propertyFlags
//---------------------------------------------------------
PropertyFlags& VoltaSegment::propertyFlags(P_ID id)
2017-02-07 18:48:23 +01:00
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2017-02-07 18:48:23 +01:00
case P_ID::LINE_STYLE:
case P_ID::LINE_COLOR:
2017-01-16 20:51:12 +01:00
return volta()->propertyFlags(id);
default:
2017-01-16 20:51:12 +01:00
return TextLineBaseSegment::propertyFlags(id);
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void VoltaSegment::resetProperty(P_ID id)
{
switch (id) {
2014-09-25 11:34:26 +02:00
case P_ID::VOLTA_ENDING:
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
return volta()->resetProperty(id);
default:
return TextLineBaseSegment::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)
: TextLineBase(s)
2012-05-26 14:26:10 +02:00
{
2017-12-27 16:09:12 +01:00
init();
setBeginTextPlace(PlaceText::BELOW);
setContinueTextPlace(PlaceText::BELOW);
2012-05-26 14:26:10 +02:00
2017-02-07 18:48:23 +01:00
setBeginHookType(HookType::HOOK_90);
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
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());
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);
}
}
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
{
2014-07-21 13:24:21 +02:00
xml.stag(QString("%1 id=\"%2\"").arg(name()).arg(xml.spannerId(this)));
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;
}
2012-09-17 15:37:31 +02:00
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Volta::getProperty(P_ID propertyId) const
{
switch (propertyId) {
2014-09-25 11:34:26 +02:00
case P_ID::VOLTA_ENDING:
return QVariant::fromValue(endings());
2012-09-17 15:37:31 +02:00
default:
break;
}
return TextLineBase::getProperty(propertyId);
2012-09-17 15:37:31 +02:00
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Volta::setProperty(P_ID propertyId, const QVariant& val)
{
switch (propertyId) {
2014-09-25 11:34:26 +02:00
case P_ID::VOLTA_ENDING:
setEndings(val.value<QList<int>>());
break;
2012-09-17 15:37:31 +02:00
default:
if (!TextLineBase::setProperty(propertyId, val))
2012-09-17 15:37:31 +02:00
return false;
break;
}
triggerLayout();
2012-09-17 15:37:31 +02:00
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Volta::propertyDefault(P_ID propertyId) const
{
switch (propertyId) {
2017-02-07 18:48:23 +01:00
case P_ID::LINE_WIDTH:
return score()->styleV(StyleIdx::voltaLineWidth);
case P_ID::LINE_STYLE:
2017-12-07 14:45:03 +01:00
return score()->styleV(StyleIdx::voltaLineStyle);
case P_ID::BEGIN_FONT_BOLD:
return score()->styleV(StyleIdx::voltaFontBold);
case P_ID::BEGIN_FONT_SIZE:
return score()->styleV(StyleIdx::voltaFontSize);
2014-09-25 11:34:26 +02:00
case P_ID::VOLTA_ENDING:
return QVariant::fromValue(QList<int>());
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);
2017-02-07 18:48:23 +01:00
case P_ID::BEGIN_HOOK_TYPE:
return int(HookType::HOOK_90);
case P_ID::BEGIN_TEXT_OFFSET:
return QPointF(0.5, 1.9);
case P_ID::BEGIN_TEXT_ALIGN:
2017-02-23 11:41:53 +01:00
return QVariant::fromValue(Align::BASELINE);
2014-06-18 20:57:45 +02:00
case P_ID::BEGIN_HOOK_HEIGHT:
case P_ID::END_HOOK_HEIGHT:
2017-01-05 11:23:47 +01:00
return score()->styleV(StyleIdx::voltaHook);
2014-06-18 20:57:45 +02:00
2012-09-17 15:37:31 +02:00
default:
return TextLineBase::propertyDefault(propertyId);
2012-09-17 15:37:31 +02:00
}
return QVariant();
}
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
// accessibleInfo
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
QString Volta::accessibleInfo() const
{
2017-02-07 18:48:23 +01:00
return QString("%1: %2").arg(Element::accessibleInfo()).arg(text());
}
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
// getPropertyStyle
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
StyleIdx Volta::getPropertyStyle(P_ID id) const
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2017-02-07 18:48:23 +01:00
return StyleIdx::voltaLineWidth;
case P_ID::LINE_STYLE:
2017-02-07 18:48:23 +01:00
return StyleIdx::voltaLineStyle;
case P_ID::BEGIN_FONT_FACE:
return StyleIdx::voltaFontFace;
case P_ID::BEGIN_FONT_SIZE:
return StyleIdx::voltaFontSize;
case P_ID::BEGIN_FONT_BOLD:
return StyleIdx::voltaFontBold;
case P_ID::BEGIN_FONT_ITALIC:
return StyleIdx::voltaFontItalic;
case P_ID::BEGIN_FONT_UNDERLINE:
return StyleIdx::voltaFontUnderline;
case P_ID::BEGIN_TEXT_ALIGN:
return StyleIdx::voltaAlign;
case P_ID::BEGIN_TEXT_OFFSET:
return StyleIdx::voltaOffset;
default:
2017-02-07 18:48:23 +01:00
break;
}
2017-02-07 18:48:23 +01:00
return TextLineBase::getPropertyStyle(id);
}
//---------------------------------------------------------
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
}
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
// voltaType
// deprecated
//---------------------------------------------------------
2017-02-07 18:48:23 +01:00
Volta::Type Volta::voltaType() const
{
2017-02-07 18:48:23 +01:00
return endHookType() != HookType::NONE ? Type::CLOSED : Type::OPEN;
}
2013-05-13 18:49:17 +02:00
}