MuseScore/libmscore/breath.cpp

200 lines
5.3 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 "breath.h"
#include "sym.h"
#include "system.h"
#include "segment.h"
#include "measure.h"
#include "score.h"
2014-04-09 16:09:21 +02:00
#include "xml.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2013-11-06 15:58:05 +01:00
SymId Breath::symList[Breath::breathSymbols] = {
2014-04-18 18:55:33 +02:00
SymId::breathMarkComma,
SymId::breathMarkComma, // TODO-smufl SymId(lcommaSym),
SymId::caesuraCurved,
2013-11-07 16:05:00 +01:00
SymId::caesura
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
// Breath
//---------------------------------------------------------
Breath::Breath(Score* s)
: Element(s)
{
_breathType = 0;
_pause = 0.0;
setFlags(ElementFlag::MOVABLE | ElementFlag::SELECTABLE);
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Breath::layout()
{
2013-11-11 15:11:28 +01:00
setbbox(symBbox(symList[breathType()]));
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Breath::write(Xml& xml) const
{
2014-08-15 17:20:20 +02:00
if (!xml.canWrite(this))
return;
2012-05-26 14:26:10 +02:00
xml.stag("Breath");
xml.tag("subtype", _breathType);
writeProperty(xml, P_ID::PAUSE);
2012-05-26 14:26:10 +02:00
Element::writeProperties(xml);
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Breath::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
2013-01-11 18:10:18 +01:00
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "subtype")
_breathType = e.readInt();
else if (tag == "pause")
_pause = e.readDouble();
2012-05-26 14:26:10 +02:00
else if (!Element::readProperties(e))
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Breath::draw(QPainter* p) const
{
p->setPen(curColor());
2013-11-06 15:58:05 +01:00
drawSymbol(symList[_breathType], p);
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// space
//---------------------------------------------------------
Space Breath::space() const
{
return Space(0.0, spatium() * 1.5);
}
//---------------------------------------------------------
// pagePos
//---------------------------------------------------------
QPointF Breath::pagePos() const
{
if (parent() == 0)
return pos();
System* system = segment()->measure()->system();
qreal yp = y();
if (system)
yp += system->staff(staffIdx())->y() + system->y();
return QPointF(pageX(), yp);
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Breath::getProperty(P_ID propertyId) const
{
switch(propertyId) {
case P_ID::PAUSE:
return _pause;
default:
return Element::getProperty(propertyId);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Breath::setProperty(P_ID propertyId, const QVariant& v)
{
switch(propertyId) {
case P_ID::PAUSE:
setPause(v.toDouble());
score()->addLayoutFlags(LayoutFlag::FIX_TICKS);
break;
default:
if (!Element::setProperty(propertyId, v))
return false;
break;
}
score()->setLayoutAll(true);
setGenerated(false);
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Breath::propertyDefault(P_ID id) const
{
switch(id) {
case P_ID::PAUSE:
return 0.0;
default:
return Element::propertyDefault(id);
}
}
//---------------------------------------------------------
// nextElement
//---------------------------------------------------------
Element* Breath::nextElement()
{
return segment()->firstInNextSegments(staffIdx());
}
//---------------------------------------------------------
// prevElement
//---------------------------------------------------------
Element* Breath::prevElement()
{
return segment()->lastInPrevSegments(staffIdx());
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
QString Breath::accessibleInfo()
{
switch (breathType()) {
case 2:
case 3:
return tr("Caesura");
default:
return tr("Breath");
}
}
2013-05-13 18:49:17 +02:00
}