1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
//=============================================================================
// 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"
#include "xml.h"
namespace Ms {
//---------------------------------------------------------
// LedgerLine
//---------------------------------------------------------
LedgerLine::LedgerLine(Score* s)
: 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()
{
setLineWidth(score()->styleP(Sid::ledgerLineWidth) * chord()->mag());
if (staff())
setColor(staff()->color());
qreal w2 = _width * .5;
if (vertical)
bbox().setRect(-w2, -w2, _width, _len + _width);
else
bbox().setRect(-w2, -w2, _len + _width, _width);
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void LedgerLine::draw(QPainter* painter) const
{
if (chord()->crossMeasure() == CrossMeasure::SECOND)
return;
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;
}
}
|