MuseScore/libmscore/layoutbreak.cpp

273 lines
8.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 "layoutbreak.h"
#include "score.h"
#include "mscore.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 {
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// LayoutBreak
//---------------------------------------------------------
LayoutBreak::LayoutBreak(Score* score)
: Element(score)
{
_layoutBreakType = Type(propertyDefault(P_ID::LAYOUT_BREAK).toInt());
2014-05-26 15:31:36 +02:00
_pause = score->styleD(StyleIdx::SectionPause);
2012-05-26 14:26:10 +02:00
_startWithLongNames = true;
_startWithMeasureOne = true;
2013-05-15 14:37:24 +02:00
lw = spatium() * 0.3;
setFlag(ElementFlag::HAS_TAG, true);
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void LayoutBreak::write(Xml& xml) const
{
xml.stag(name());
Element::writeProperties(xml);
2014-05-26 18:18:01 +02:00
writeProperty(xml, P_ID::LAYOUT_BREAK);
writeProperty(xml, P_ID::PAUSE);
2012-05-26 14:26:10 +02:00
if (!_startWithLongNames)
xml.tag("startWithLongNames", _startWithLongNames);
if (!_startWithMeasureOne)
xml.tag("startWithMeasureOne", _startWithMeasureOne);
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void LayoutBreak::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());
2012-08-10 17:01:35 +02:00
if (tag == "subtype")
2014-05-26 18:18:01 +02:00
setProperty(P_ID::LAYOUT_BREAK, Ms::getProperty(P_ID::LAYOUT_BREAK, e));
2012-08-10 17:01:35 +02:00
else if (tag == "pause")
2013-01-11 18:10:18 +01:00
_pause = e.readDouble();
2012-05-26 14:26:10 +02:00
else if (tag == "startWithLongNames")
2013-01-11 18:10:18 +01:00
_startWithLongNames = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "startWithMeasureOne")
2013-01-11 18:10:18 +01:00
_startWithMeasureOne = e.readInt();
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
}
layout0();
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void LayoutBreak::draw(QPainter* painter) const
{
if (score()->printing() || !score()->showUnprintable())
return;
2013-05-15 11:41:46 +02:00
QPainterPathStroker stroker;
stroker.setWidth(lw/2);
stroker.setJoinStyle(Qt::MiterJoin);
stroker.setCapStyle(Qt::SquareCap);
QVector<qreal> dashes ;
dashes.append(1);
dashes.append(3);
stroker.setDashPattern(dashes);
QPainterPath stroke = stroker.createStroke(path);
painter->fillPath(stroke, selected() ? MScore::selectColor[0] : MScore::layoutBreakColor);
2012-05-26 14:26:10 +02:00
painter->setPen(QPen(selected() ? MScore::selectColor[0] : MScore::layoutBreakColor,
2013-05-15 11:41:46 +02:00
lw, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
2012-05-26 14:26:10 +02:00
painter->setBrush(Qt::NoBrush);
2013-05-15 11:41:46 +02:00
painter->drawPath(path2);
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// layout0
//---------------------------------------------------------
void LayoutBreak::layout0()
{
qreal _spatium = spatium();
path = QPainterPath();
2013-05-15 11:41:46 +02:00
path2 = QPainterPath();
2013-05-15 15:31:29 +02:00
qreal h = _spatium * 2.5;
qreal w = _spatium * 2.5;
2013-05-15 11:41:46 +02:00
QRectF rect(0.0, 0.0, w, h);
path.addRect(rect);
2012-05-26 14:26:10 +02:00
switch(layoutBreakType()) {
case Type::LINE:
2013-05-15 11:41:46 +02:00
path2.moveTo(w * .8, h * .3);
path2.lineTo(w * .8, h * .6);
path2.lineTo(w * .3, h * .6);
path2.moveTo(w * .4, h * .5);
path2.lineTo(w * .25, h * .6);
path2.lineTo(w * .4, h * .7);
path2.lineTo(w * .4, h * .5);
2012-05-26 14:26:10 +02:00
break;
case Type::PAGE:
2013-05-15 11:41:46 +02:00
path2.moveTo(w*.25, h*.2);
path2.lineTo(w*.60, h*.2);
path2.lineTo(w*.75, h*.35);
path2.lineTo(w*.75, h*.8);
path2.lineTo(w*.25, h*.8);
path2.lineTo(w*.25, h*.2);
2013-05-15 15:31:29 +02:00
path2.moveTo(w*.55, h*.21); // 0.01 to avoid overlap
2013-05-15 11:41:46 +02:00
path2.lineTo(w*.55, h*.40);
2013-05-15 15:31:29 +02:00
path2.lineTo(w*.74, h*.40);
2012-05-26 14:26:10 +02:00
break;
case Type::SECTION:
2013-05-15 11:41:46 +02:00
path2.moveTo(w*.25, h*.2);
path2.lineTo(w*.75, h*.2);
path2.lineTo(w*.75, h*.8);
path2.lineTo(w*.25, h*.8);
2013-05-15 15:31:29 +02:00
path2.moveTo(w*.55, h*.21); // 0.01 to avoid overlap
path2.lineTo(w*.55, h*.79);
2012-05-26 14:26:10 +02:00
break;
default:
qDebug("unknown layout break symbol");
2012-05-26 14:26:10 +02:00
break;
}
QRectF bb(0, 0, w, h);
bb.adjust(-lw, -lw, lw, lw);
setbbox(bb);
}
//---------------------------------------------------------
// setLayoutBreakType
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
void LayoutBreak::setLayoutBreakType(Type val)
2012-05-26 14:26:10 +02:00
{
_layoutBreakType = val;
2012-05-26 14:26:10 +02:00
layout0();
}
//---------------------------------------------------------
// spatiumChanged
//---------------------------------------------------------
void LayoutBreak::spatiumChanged(qreal, qreal)
{
lw = spatium() * 0.3;
layout0();
}
//---------------------------------------------------------
// acceptDrop
//---------------------------------------------------------
2014-08-13 21:01:21 +02:00
bool LayoutBreak::acceptDrop(const DropData& data) const
2012-05-26 14:26:10 +02:00
{
2014-08-13 21:01:21 +02:00
return data.element->type() == Element::Type::LAYOUT_BREAK
&& static_cast<LayoutBreak*>(data.element)->layoutBreakType() != layoutBreakType();
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// drop
//---------------------------------------------------------
Element* LayoutBreak::drop(const DropData& data)
{
Element* e = data.element;
score()->undoChangeElement(this, e);
return e;
}
2012-08-10 17:01:35 +02:00
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant LayoutBreak::getProperty(P_ID propertyId) const
{
switch(propertyId) {
2014-05-26 18:18:01 +02:00
case P_ID::LAYOUT_BREAK:
return int(_layoutBreakType);
2014-05-26 18:18:01 +02:00
case P_ID::PAUSE:
2012-08-10 17:01:35 +02:00
return _pause;
default:
return Element::getProperty(propertyId);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool LayoutBreak::setProperty(P_ID propertyId, const QVariant& v)
{
switch(propertyId) {
2014-05-26 18:18:01 +02:00
case P_ID::LAYOUT_BREAK:
setLayoutBreakType(Type(v.toInt()));
2012-08-10 17:01:35 +02:00
break;
2014-05-26 18:18:01 +02:00
case P_ID::PAUSE:
2012-08-10 17:01:35 +02:00
setPause(v.toDouble());
score()->addLayoutFlags(LayoutFlag::FIX_TICKS);
2012-08-10 17:01:35 +02:00
break;
default:
if (!Element::setProperty(propertyId, v))
return false;
break;
}
score()->setLayoutAll(true);
setGenerated(false);
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant LayoutBreak::propertyDefault(P_ID id) const
{
switch(id) {
2014-05-26 18:18:01 +02:00
case P_ID::LAYOUT_BREAK:
2012-08-10 17:01:35 +02:00
return QVariant(); // LAYOUT_BREAK_LINE;
2014-05-26 18:18:01 +02:00
case P_ID::PAUSE:
2014-05-26 15:31:36 +02:00
return 0.0; // score()->styleD(StyleIdx::SectionPause);
2012-08-10 17:01:35 +02:00
default:
return Element::propertyDefault(id);
}
}
2013-10-05 23:13:33 +02:00
//---------------------------------------------------------
// undoLayoutBreakType
//---------------------------------------------------------
void LayoutBreak::undoSetLayoutBreakType(Type t)
2013-10-05 23:13:33 +02:00
{
2014-05-26 18:18:01 +02:00
undoChangeProperty(P_ID::LAYOUT_BREAK, int(t));
2013-10-05 23:13:33 +02:00
}
2013-05-13 18:49:17 +02:00
}