MuseScore/libmscore/rehearsalmark.cpp

98 lines
3.8 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 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 "rehearsalmark.h"
2017-02-08 13:27:35 +01:00
#include "measure.h"
2017-06-02 11:59:32 +02:00
#include "system.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2018-08-01 11:46:07 +02:00
//---------------------------------------------------------
// rehearsalMarkStyle
//---------------------------------------------------------
static const ElementStyle rehearsalMarkStyle {
{ Sid::rehearsalMarkFontFace, Pid::FONT_FACE },
{ Sid::rehearsalMarkFontSize, Pid::FONT_SIZE },
{ Sid::rehearsalMarkFontBold, Pid::FONT_BOLD },
{ Sid::rehearsalMarkFontItalic, Pid::FONT_ITALIC },
{ Sid::rehearsalMarkFontUnderline, Pid::FONT_UNDERLINE },
{ Sid::rehearsalMarkAlign, Pid::ALIGN },
{ Sid::rehearsalMarkFrameType, Pid::FRAME_TYPE },
{ Sid::rehearsalMarkFramePadding, Pid::FRAME_PADDING },
{ Sid::rehearsalMarkFrameWidth, Pid::FRAME_WIDTH },
{ Sid::rehearsalMarkFrameRound, Pid::FRAME_ROUND },
{ Sid::rehearsalMarkFrameFgColor, Pid::FRAME_FG_COLOR },
{ Sid::rehearsalMarkFrameBgColor, Pid::FRAME_BG_COLOR },
{ Sid::rehearsalMarkPlacement, Pid::PLACEMENT },
};
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// RehearsalMark
//---------------------------------------------------------
RehearsalMark::RehearsalMark(Score* s)
2018-08-01 11:46:07 +02:00
: TextBase(s, Tid::REHEARSAL_MARK)
2012-05-26 14:26:10 +02:00
{
2018-08-01 11:46:07 +02:00
initElementStyle(&rehearsalMarkStyle);
2017-12-27 11:51:00 +01:00
setSystemFlag(true);
2012-05-26 14:26:10 +02:00
}
2016-06-03 16:51:17 +02:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void RehearsalMark::layout()
{
2018-03-27 15:36:00 +02:00
qreal y = placeAbove() ? styleP(Sid::rehearsalMarkPosAbove) : styleP(Sid::rehearsalMarkPosBelow) + staff()->height();
2017-02-08 18:11:51 +01:00
setPos(QPointF(0.0, y));
2017-12-27 11:51:00 +01:00
TextBase::layout1();
Segment* s = segment();
2016-06-09 09:26:13 +02:00
if (s) {
if (!s->rtick()) {
// first CR of measure, decide whether to align to barline
2017-01-05 11:23:47 +01:00
if (!s->prev() && align() & Align::CENTER) {
2016-06-09 09:26:13 +02:00
// measure with no clef / keysig / timesig
rxpos() -= s->x();
}
2017-01-05 11:23:47 +01:00
else if (align() & Align::RIGHT) {
2016-06-09 09:26:13 +02:00
// measure with clef / keysig / timesig, rehearsal mark right aligned
// align left edge of rehearsal to barline if that is further to left
qreal leftX = bbox().x();
qreal barlineX = -s->x();
rxpos() += qMin(leftX, barlineX) + width();
}
}
2018-03-27 15:36:00 +02:00
autoplaceSegmentElement(styleP(Sid::rehearsalMarkMinDistance));
}
}
2017-01-16 20:51:12 +01:00
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant RehearsalMark::propertyDefault(Pid id) const
2017-01-16 20:51:12 +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::REHEARSAL_MARK);
2018-03-27 15:36:00 +02:00
case Pid::PLACEMENT:
return score()->styleV(Sid::rehearsalMarkPlacement);
2017-01-16 20:51:12 +01:00
default:
2017-12-27 11:51:00 +01:00
return TextBase::propertyDefault(id);
2017-01-16 20:51:12 +01:00
}
}
2016-06-09 09:26:13 +02:00
} // namespace Ms
2013-05-13 18:49:17 +02:00