MuseScore/libmscore/layoutbreak.cpp

320 lines
9.9 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 {
2019-11-15 05:36:19 +01:00
//---------------------------------------------------------
// sectionBreakStyle
//---------------------------------------------------------
static const ElementStyle sectionBreakStyle {
{ Sid::SectionPause, Pid::PAUSE }
};
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// LayoutBreak
//---------------------------------------------------------
LayoutBreak::LayoutBreak(Score* score)
2018-08-01 11:46:07 +02:00
: Element(score, ElementFlag::SYSTEM | ElementFlag::HAS_TAG)
2012-05-26 14:26:10 +02:00
{
_pause = 0.;
_startWithLongNames = false;
_startWithMeasureOne = false;
_layoutBreakType = Type(propertyDefault(Pid::LAYOUT_BREAK).toInt());
2019-11-15 05:36:19 +01:00
initElementStyle(&sectionBreakStyle);
resetProperty(Pid::PAUSE);
resetProperty(Pid::START_WITH_LONG_NAMES);
resetProperty(Pid::START_WITH_MEASURE_ONE);
lw = spatium() * 0.3;
2012-05-26 14:26:10 +02:00
}
LayoutBreak::LayoutBreak(const LayoutBreak& lb)
: Element(lb)
{
2016-03-30 22:33:04 +02:00
_layoutBreakType = lb._layoutBreakType;
lw = lb.lw;
_pause = lb._pause;
_startWithLongNames = lb._startWithLongNames;
_startWithMeasureOne = lb._startWithMeasureOne;
layout0();
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// write
//---------------------------------------------------------
2016-11-19 11:51:21 +01:00
void LayoutBreak::write(XmlWriter& xml) const
2012-05-26 14:26:10 +02:00
{
xml.stag(this);
2012-05-26 14:26:10 +02:00
Element::writeProperties(xml);
for (auto id : { Pid::LAYOUT_BREAK, Pid::PAUSE, Pid::START_WITH_LONG_NAMES, Pid::START_WITH_MEASURE_ONE })
writeProperty(xml, id);
2012-05-26 14:26:10 +02:00
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")
2018-10-26 10:41:07 +02:00
readProperty(e, Pid::LAYOUT_BREAK);
2012-08-10 17:01:35 +02:00
else if (tag == "pause")
readProperty(e, Pid::PAUSE);
2012-05-26 14:26:10 +02:00
else if (tag == "startWithLongNames")
readProperty(e, Pid::START_WITH_LONG_NAMES);
2012-05-26 14:26:10 +02:00
else if (tag == "startWithMeasureOne")
readProperty(e, Pid::START_WITH_MEASURE_ONE);
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;
2013-05-15 11:41:46 +02:00
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;
case Type::NOBREAK:
path2.moveTo(w * .1, h * .5);
path2.lineTo(w * .9, h * .5);
path2.moveTo(w * .7, h * .3);
path2.lineTo(w * .5, h * .5);
path2.lineTo(w * .7, h * .7);
path2.lineTo(w * .7, h * .3);
path2.moveTo(w * .3, h * .3);
path2.lineTo(w * .5, h * .5);
path2.lineTo(w * .3, h * .7);
path2.lineTo(w * .3, h * .3);
break;
2012-05-26 14:26:10 +02:00
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
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
bool LayoutBreak::acceptDrop(EditData& data) const
2012-05-26 14:26:10 +02:00
{
return data.dropElement->type() == ElementType::LAYOUT_BREAK
&& toLayoutBreak(data.dropElement)->layoutBreakType() != layoutBreakType();
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// drop
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
Element* LayoutBreak::drop(EditData& data)
2012-05-26 14:26:10 +02:00
{
Element* e = data.dropElement;
2012-05-26 14:26:10 +02:00
score()->undoChangeElement(this, e);
return e;
}
2012-08-10 17:01:35 +02:00
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant LayoutBreak::getProperty(Pid propertyId) const
2012-08-10 17:01:35 +02:00
{
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::LAYOUT_BREAK:
return int(_layoutBreakType);
2018-03-27 15:36:00 +02:00
case Pid::PAUSE:
2012-08-10 17:01:35 +02:00
return _pause;
case Pid::START_WITH_LONG_NAMES:
return _startWithLongNames;
case Pid::START_WITH_MEASURE_ONE:
return _startWithMeasureOne;
2012-08-10 17:01:35 +02:00
default:
return Element::getProperty(propertyId);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
bool LayoutBreak::setProperty(Pid propertyId, const QVariant& v)
2012-08-10 17:01:35 +02:00
{
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::LAYOUT_BREAK:
setLayoutBreakType(Type(v.toInt()));
2012-08-10 17:01:35 +02:00
break;
2018-03-27 15:36:00 +02:00
case Pid::PAUSE:
2012-08-10 17:01:35 +02:00
setPause(v.toDouble());
break;
case Pid::START_WITH_LONG_NAMES:
setStartWithLongNames(v.toBool());
break;
case Pid::START_WITH_MEASURE_ONE:
setStartWithMeasureOne(v.toBool());
break;
2012-08-10 17:01:35 +02:00
default:
if (!Element::setProperty(propertyId, v))
return false;
break;
}
2019-10-24 15:49:23 +02:00
triggerLayoutAll();
2012-08-10 17:01:35 +02:00
setGenerated(false);
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant LayoutBreak::propertyDefault(Pid id) const
2012-08-10 17:01:35 +02:00
{
switch (id) {
2018-03-27 15:36:00 +02:00
case Pid::LAYOUT_BREAK:
2012-08-10 17:01:35 +02:00
return QVariant(); // LAYOUT_BREAK_LINE;
2018-03-27 15:36:00 +02:00
case Pid::PAUSE:
return score()->styleD(Sid::SectionPause);
case Pid::START_WITH_LONG_NAMES:
return true;
case Pid::START_WITH_MEASURE_ONE:
return true;
2012-08-10 17:01:35 +02:00
default:
return Element::propertyDefault(id);
}
}
//---------------------------------------------------------
// propertyId
//---------------------------------------------------------
Pid LayoutBreak::propertyId(const QStringRef& name) const
{
if (name == propertyName(Pid::LAYOUT_BREAK))
return Pid::LAYOUT_BREAK;
return Element::propertyId(name);
}
2013-05-13 18:49:17 +02:00
}