MuseScore/libmscore/fingering.cpp

146 lines
4.6 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
2018-03-21 15:34:32 +01:00
// Copyright (C) 2010-2018 Werner Schweer
2012-05-26 14:26:10 +02:00
//
// 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 "fingering.h"
#include "score.h"
#include "staff.h"
2012-05-26 14:26:10 +02:00
#include "undo.h"
2014-04-09 16:09:21 +02:00
#include "xml.h"
#include "chord.h"
#include "part.h"
#include "measure.h"
#include "stem.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
//---------------------------------------------------------
// fingeringStyle
//---------------------------------------------------------
2018-08-01 11:46:07 +02:00
static const ElementStyle fingeringStyle {
};
2018-03-21 14:05:33 +01:00
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Fingering
2018-03-21 15:34:32 +01:00
// Element(Score* = 0, ElementFlags = ElementFlag::NOTHING);
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2018-08-01 11:46:07 +02:00
Fingering::Fingering(Score* s, Tid tid, ElementFlags ef)
: TextBase(s, tid, ef)
2018-03-21 14:05:33 +01:00
{
2018-08-01 11:46:07 +02:00
initElementStyle(&fingeringStyle);
2018-03-21 14:05:33 +01:00
}
Fingering::Fingering(Score* s, ElementFlags ef)
2018-08-01 11:46:07 +02:00
: Fingering(s, Tid::FINGERING, ef)
2012-05-26 14:26:10 +02:00
{
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Fingering::layout()
{
2017-12-27 11:51:00 +01:00
TextBase::layout();
if (autoplace() && note()) {
Chord* chord = note()->chord();
Staff* staff = chord->staff();
Part* part = staff->part();
int n = part->nstaves();
bool voices = chord->measure()->hasVoices(staff->idx());
bool below = voices ? !chord->up() : (n > 1) && (staff->rstaff() == n-1);
bool tight = voices && !chord->beam();
qreal x = 0.0;
qreal y = 0.0;
qreal headWidth = note()->bboxRightPos();
qreal headHeight = note()->headHeight();
qreal fh = headHeight; // TODO: fingering number height
if (chord->notes().size() == 1) {
x = headWidth * .5;
if (below) {
// place fingering below note
y = fh + spatium() * .4;
if (tight) {
y += 0.5 * spatium();
if (chord->stem())
x += 0.5 * spatium();
}
else if (chord->stem() && !chord->up()) {
// on stem side
y += chord->stem()->height();
x -= spatium() * .4;
}
}
else {
// place fingering above note
y = -headHeight - spatium() * .4;
if (tight) {
y -= 0.5 * spatium();
if (chord->stem())
x -= 0.5 * spatium();
}
else if (chord->stem() && chord->up()) {
// on stem side
y -= chord->stem()->height();
x += spatium() * .4;
}
}
}
else {
x -= spatium();
}
setUserOff(QPointF(x, y));
}
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Fingering::draw(QPainter* painter) const
{
2017-12-27 11:51:00 +01:00
TextBase::draw(painter);
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
2016-02-04 17:06:32 +01:00
QString Fingering::accessibleInfo() const
{
QString rez = Element::accessibleInfo();
2018-08-01 11:46:07 +02:00
if (tid() == Tid::STRING_NUMBER)
rez += " " + QObject::tr("String number");
return QString("%1: %2").arg(rez).arg(plainText());
}
2017-01-05 14:53:21 +01:00
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant Fingering::propertyDefault(Pid id) const
2017-01-05 14:53:21 +01:00
{
switch (id) {
2018-03-27 15:36:00 +02:00
case Pid::SUB_STYLE:
2018-08-01 11:46:07 +02:00
return int(Tid::FINGERING);
2017-01-05 14:53:21 +01:00
default:
2017-12-27 11:51:00 +01:00
return TextBase::propertyDefault(id);
2017-01-05 14:53:21 +01:00
}
}
2013-05-13 18:49:17 +02:00
}