MuseScore/libmscore/ledgerline.cpp

131 lines
3.7 KiB
C++
Raw Normal View History

//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2013 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 "ledgerline.h"
#include "chord.h"
#include "measure.h"
#include "staff.h"
#include "system.h"
#include "score.h"
2017-12-27 11:51:00 +01:00
#include "xml.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
//---------------------------------------------------------
// LedgerLine
//---------------------------------------------------------
LedgerLine::LedgerLine(Score* s)
2017-12-27 11:51:00 +01:00
: Element(s)
{
setSelectable(false);
_next = 0;
}
//---------------------------------------------------------
// pagePos
//---------------------------------------------------------
QPointF LedgerLine::pagePos() const
{
System* system = chord()->measure()->system();
qreal yp = y() + system->staff(staffIdx())->y() + system->y();
return QPointF(pageX(), yp);
}
//---------------------------------------------------------
// measureXPos
//---------------------------------------------------------
qreal LedgerLine::measureXPos() const
{
qreal xp = x(); // chord relative
xp += chord()->x(); // segment relative
xp += chord()->segment()->x(); // measure relative
return xp;
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void LedgerLine::layout()
{
2018-03-27 15:36:00 +02:00
setLineWidth(score()->styleP(Sid::ledgerLineWidth) * chord()->mag());
if (staff())
setColor(staff()->color());
2017-12-27 11:51:00 +01:00
qreal w2 = _width * .5;
if (vertical)
bbox().setRect(-w2, -w2, _width, _len + _width);
else
bbox().setRect(-w2, -w2, _len + _width, _width);
}
2012-10-19 01:17:15 +02:00
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void LedgerLine::draw(QPainter* painter) const
{
2016-09-03 17:45:59 +02:00
if (chord()->crossMeasure() == CrossMeasure::SECOND)
2012-10-19 01:17:15 +02:00
return;
2017-12-27 11:51:00 +01:00
painter->setPen(QPen(curColor(), _width));
if (vertical)
painter->drawLine(QLineF(0.0, 0.0, 0.0, _len));
else
painter->drawLine(QLineF(0.0, 0.0, _len, 0.0));
}
//---------------------------------------------------------
// spatiumChanged
//---------------------------------------------------------
void LedgerLine::spatiumChanged(qreal oldValue, qreal newValue)
{
_width = (_width / oldValue) * newValue;
_len = (_len / oldValue) * newValue;
layout();
}
//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------
void LedgerLine::writeProperties(XmlWriter& xml) const
{
xml.tag("lineWidth", _width / spatium());
xml.tag("lineLen", _len / spatium());
if (!vertical)
xml.tag("vertical", vertical);
}
//---------------------------------------------------------
// readProperties
//---------------------------------------------------------
bool LedgerLine::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (tag == "lineWidth")
_width = e.readDouble() * spatium();
else if (tag == "lineLen")
_len = e.readDouble() * spatium();
else if (tag == "vertical")
vertical = e.readInt();
else
return false;
return true;
2012-10-19 01:17:15 +02:00
}
2013-05-13 18:49:17 +02:00
}