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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2016 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 "stafflines.h"
#include "system.h"
#include "measure.h"
#include "score.h"
#include "stafftype.h"
#include "staff.h"
// Anatomy of StaffLines:
//
// step - The possible vertical positions of a note are counted as steps.
// The top staff line is step position zero.
// lines - number of visible staff lines
// lineDistance - The distance between lines, measured in step units. A standard five line
// staff has a line distance of two steps.
// stepDistance - The distance between steps measured in scaled spatium/2 units. A standard five
// line staff has a step distance of 0.5 which results in a line distance of
// one spatium. The spatium unit is scaled by staff size.
// yoffset - vertical offset to align with other staves of different height
// stepOffset - This value changes the staff line step numbering.
//
namespace Ms {
//---------------------------------------------------------
// StaffLines
//---------------------------------------------------------
StaffLines::StaffLines(Score* s)
: Element(s)
{
setSelectable(false);
}
//---------------------------------------------------------
// pagePos
//---------------------------------------------------------
QPointF StaffLines::pagePos() const
{
System* system = measure()->system();
return QPointF(measure()->x() + system->x(), system->staff(staffIdx())->y() + system->y());
}
//---------------------------------------------------------
// canvasPos
//---------------------------------------------------------
QPointF StaffLines::canvasPos() const
{
QPointF p(pagePos());
Element* e = parent();
while (e) {
if (e->type() == ElementType::PAGE) {
p += e->pos();
break;
}
e = e->parent();
}
return p;
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void StaffLines::layout()
{
layoutForWidth(measure()->width());
}
//---------------------------------------------------------
// layoutForWidth
//---------------------------------------------------------
void StaffLines::layoutForWidth(qreal w)
{
const Staff* s = staff();
qreal _spatium = spatium();
qreal dist = _spatium;
setPos(QPointF(0.0, 0.0));
int _lines;
if (s) {
setMag(s->mag(measure()->tick()));
setColor(s->color());
const StaffType* st = s->staffType(measure()->tick());
dist *= st->lineDistance().val();
_lines = st->lines();
rypos() = st->yoffset().val() * _spatium;
// if (_lines == 1)
// rypos() = 2 * _spatium;
}
else {
_lines = 5;
setColor(MScore::defaultColor);
}
lw = score()->styleS(Sid::staffLineWidth).val() * _spatium;
qreal x1 = pos().x();
qreal x2 = x1 + w;
qreal y = pos().y();
bbox().setRect(x1, -lw * .5 + y, w, (_lines-1) * dist + lw);
if (_lines == 1) {
qreal extraSize = _spatium;
bbox().adjust(0, -extraSize, 0, extraSize);
}
lines.clear();
for (int i = 0; i < _lines; ++i) {
lines.push_back(QLineF(x1, y, x2, y));
y += dist;
}
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void StaffLines::draw(QPainter* painter) const
{
painter->setPen(QPen(curColor(), lw, Qt::SolidLine, Qt::FlatCap));
painter->drawLines(lines);
}
//---------------------------------------------------------
// y1
//---------------------------------------------------------
qreal StaffLines::y1() const
{
System* system = measure()->system();
/* if (system == 0 || staffIdx() >= system->staves()->size())
return 0.0;
*/
return system->staff(staffIdx())->y() + ipos().y();
}
}
|