2016-12-23 12:05:18 +01:00
|
|
|
//=============================================================================
|
|
|
|
// 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
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2020-05-29 18:47:27 +02:00
|
|
|
StaffLines::StaffLines(Score* s)
|
|
|
|
: Element(s)
|
2016-12-23 12:05:18 +01:00
|
|
|
{
|
|
|
|
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) {
|
2017-01-18 14:16:33 +01:00
|
|
|
if (e->type() == ElementType::PAGE) {
|
2016-12-23 12:05:18 +01:00
|
|
|
p += e->pos();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
e = e->parent();
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void StaffLines::layout()
|
2018-08-20 17:39:15 +02:00
|
|
|
{
|
|
|
|
layoutForWidth(measure()->width());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// layoutForWidth
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void StaffLines::layoutForWidth(qreal w)
|
2016-12-23 12:05:18 +01:00
|
|
|
{
|
2018-11-08 15:45:14 +01:00
|
|
|
const Staff* s = staff();
|
2016-12-23 12:05:18 +01:00
|
|
|
qreal _spatium = spatium();
|
2017-12-15 10:37:37 +01:00
|
|
|
qreal dist = _spatium;
|
2016-12-23 12:05:18 +01:00
|
|
|
setPos(QPointF(0.0, 0.0));
|
|
|
|
int _lines;
|
|
|
|
if (s) {
|
|
|
|
setMag(s->mag(measure()->tick()));
|
|
|
|
setColor(s->color());
|
2018-11-08 15:45:14 +01:00
|
|
|
const StaffType* st = s->staffType(measure()->tick());
|
2016-12-23 12:05:18 +01:00
|
|
|
dist *= st->lineDistance().val();
|
|
|
|
_lines = st->lines();
|
|
|
|
rypos() = st->yoffset().val() * _spatium;
|
2018-09-12 09:22:20 +02:00
|
|
|
// if (_lines == 1)
|
|
|
|
// rypos() = 2 * _spatium;
|
2016-12-23 12:05:18 +01:00
|
|
|
} else {
|
|
|
|
_lines = 5;
|
|
|
|
setColor(MScore::defaultColor);
|
|
|
|
}
|
2018-08-20 17:39:15 +02:00
|
|
|
lw = score()->styleS(Sid::staffLineWidth).val() * _spatium;
|
2016-12-23 12:05:18 +01:00
|
|
|
qreal x1 = pos().x();
|
|
|
|
qreal x2 = x1 + w;
|
|
|
|
qreal y = pos().y();
|
2017-12-15 10:37:37 +01:00
|
|
|
bbox().setRect(x1, -lw * .5 + y, w, (_lines - 1) * dist + lw);
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2018-11-25 12:47:22 +01:00
|
|
|
if (_lines == 1) {
|
|
|
|
qreal extraSize = _spatium;
|
|
|
|
bbox().adjust(0, -extraSize, 0, extraSize);
|
|
|
|
}
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2016-12-23 12:05:18 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|