250 lines
7.3 KiB
C++
250 lines
7.3 KiB
C++
//=============================================================================
|
|
// MuseScore
|
|
// Music Composition & Notation
|
|
//
|
|
// Copyright (C) 2002-2011 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 "score.h"
|
|
#include "textline.h"
|
|
#include "staff.h"
|
|
#include "system.h"
|
|
|
|
namespace Ms {
|
|
|
|
//---------------------------------------------------------
|
|
// TextLineSegment
|
|
//---------------------------------------------------------
|
|
|
|
TextLineSegment::TextLineSegment(Score* s)
|
|
: TextLineBaseSegment(s)
|
|
{
|
|
setPlacement(Placement::ABOVE);
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// layout
|
|
//---------------------------------------------------------
|
|
|
|
void TextLineSegment::layout()
|
|
{
|
|
if (autoplace())
|
|
setUserOff(QPointF());
|
|
|
|
TextLineBaseSegment::layout();
|
|
if (parent()) {
|
|
if (textLine()->placeBelow()) {
|
|
qreal sh = staff() ? staff()->height() : 0.0;
|
|
rypos() = sh + score()->styleP(StyleIdx::textLinePosBelow) * mag();
|
|
}
|
|
else
|
|
rypos() = score()->styleP(StyleIdx::textLinePosAbove) * mag();
|
|
if (autoplace()) {
|
|
qreal minDistance = spatium() * .7;
|
|
Shape s1 = shape().translated(pos());
|
|
if (textLine()->placeAbove()) {
|
|
qreal d = system()->topDistance(staffIdx(), s1);
|
|
if (d > -minDistance)
|
|
rUserYoffset() = -d - minDistance;
|
|
}
|
|
else {
|
|
qreal d = system()->bottomDistance(staffIdx(), s1);
|
|
if (d > -minDistance)
|
|
rUserYoffset() = d + minDistance;
|
|
}
|
|
}
|
|
else
|
|
adjustReadPos();
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// getProperty
|
|
//---------------------------------------------------------
|
|
|
|
QVariant TextLineSegment::getProperty(P_ID id) const
|
|
{
|
|
switch (id) {
|
|
case P_ID::PLACEMENT:
|
|
return textLine()->getProperty(id);
|
|
default:
|
|
return TextLineBaseSegment::getProperty(id);
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// setProperty
|
|
//---------------------------------------------------------
|
|
|
|
bool TextLineSegment::setProperty(P_ID id, const QVariant& v)
|
|
{
|
|
switch (id) {
|
|
case P_ID::PLACEMENT:
|
|
return textLine()->setProperty(id, v);
|
|
default:
|
|
return TextLineBaseSegment::setProperty(id, v);
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// propertyDefault
|
|
//---------------------------------------------------------
|
|
|
|
QVariant TextLineSegment::propertyDefault(P_ID id) const
|
|
{
|
|
switch (id) {
|
|
case P_ID::PLACEMENT:
|
|
return textLine()->propertyDefault(id);
|
|
default:
|
|
return TextLineBaseSegment::propertyDefault(id);
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// propertyStyle
|
|
//---------------------------------------------------------
|
|
|
|
PropertyFlags TextLineSegment::propertyFlags(P_ID id) const
|
|
{
|
|
switch (id) {
|
|
case P_ID::PLACEMENT:
|
|
return textLine()->propertyFlags(id);
|
|
|
|
default:
|
|
return TextLineBaseSegment::propertyFlags(id);
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// resetProperty
|
|
//---------------------------------------------------------
|
|
|
|
void TextLineSegment::resetProperty(P_ID id)
|
|
{
|
|
switch (id) {
|
|
case P_ID::PLACEMENT:
|
|
return textLine()->resetProperty(id);
|
|
|
|
default:
|
|
return TextLineBaseSegment::resetProperty(id);
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// styleChanged
|
|
//---------------------------------------------------------
|
|
|
|
void TextLineSegment::styleChanged()
|
|
{
|
|
textLine()->styleChanged();
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// TextLine
|
|
//---------------------------------------------------------
|
|
|
|
TextLine::TextLine(Score* s)
|
|
: TextLineBase(s)
|
|
{
|
|
setPlacement(Placement::ABOVE);
|
|
}
|
|
|
|
TextLine::TextLine(const TextLine& tl)
|
|
: TextLineBase(tl)
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// styleChanged
|
|
// reset all styled values to actual style
|
|
//---------------------------------------------------------
|
|
|
|
void TextLine::styleChanged()
|
|
{
|
|
TextLineBase::styleChanged();
|
|
triggerLayout();
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// reset
|
|
//---------------------------------------------------------
|
|
|
|
void TextLine::reset()
|
|
{
|
|
TextLineBase::reset();
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// createLineSegment
|
|
//---------------------------------------------------------
|
|
|
|
LineSegment* TextLine::createLineSegment()
|
|
{
|
|
TextLineSegment* seg = new TextLineSegment(score());
|
|
// note-anchored line segments are relative to system not to staff
|
|
if (anchor() == Spanner::Anchor::NOTE)
|
|
seg->setFlag(ElementFlag::ON_STAFF, false);
|
|
return seg;
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// getProperty
|
|
//---------------------------------------------------------
|
|
|
|
QVariant TextLine::getProperty(P_ID propertyId) const
|
|
{
|
|
switch (propertyId) {
|
|
default:
|
|
break;
|
|
}
|
|
return TextLineBase::getProperty(propertyId);
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// setProperty
|
|
//---------------------------------------------------------
|
|
|
|
bool TextLine::setProperty(P_ID propertyId, const QVariant& val)
|
|
{
|
|
switch (propertyId) {
|
|
case P_ID::PLACEMENT:
|
|
if (val != getProperty(propertyId)) {
|
|
// reverse hooks
|
|
setBeginHookHeight(-beginHookHeight());
|
|
setEndHookHeight(-endHookHeight());
|
|
}
|
|
TextLineBase::setProperty(propertyId, val);
|
|
break;
|
|
|
|
default:
|
|
if (!TextLineBase::setProperty(propertyId, val))
|
|
return false;
|
|
break;
|
|
}
|
|
score()->setLayoutAll();
|
|
return true;
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// propertyDefault
|
|
//---------------------------------------------------------
|
|
|
|
QVariant TextLine::propertyDefault(P_ID propertyId) const
|
|
{
|
|
switch (propertyId) {
|
|
case P_ID::PLACEMENT:
|
|
return int(Placement::ABOVE);
|
|
default:
|
|
return TextLineBase::propertyDefault(propertyId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} // namespace Ms
|
|
|