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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2013 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 "marker.h"
#include "score.h"
#include "sym.h"
#include "xml.h"
#include "measure.h"
namespace Ms {
//must be in sync with Marker::Type enum
const MarkerTypeItem markerTypeTable[] = {
{ Marker::Type::SEGNO , QT_TRANSLATE_NOOP("markerType", "Segno") },
{ Marker::Type::VARSEGNO, QT_TRANSLATE_NOOP("markerType", "Segno variation")},
{ Marker::Type::CODA , QT_TRANSLATE_NOOP("markerType", "Coda") },
{ Marker::Type::VARCODA , QT_TRANSLATE_NOOP("markerType", "Varied coda") },
{ Marker::Type::CODETTA , QT_TRANSLATE_NOOP("markerType", "Codetta") },
{ Marker::Type::FINE , QT_TRANSLATE_NOOP("markerType", "Fine") },
{ Marker::Type::TOCODA , QT_TRANSLATE_NOOP("markerType", "To Coda") },
{ Marker::Type::USER , QT_TRANSLATE_NOOP("markerType", "Custom") }
};
int markerTypeTableSize()
{
return sizeof(markerTypeTable)/sizeof(MarkerTypeItem) - 1; //-1 for the user defined
}
//---------------------------------------------------------
// Marker
//---------------------------------------------------------
Marker::Marker(Score* s)
: Text(s)
{
_markerType = Type::FINE;
setFlags(ElementFlag::MOVABLE | ElementFlag::SELECTABLE | ElementFlag::ON_STAFF);
setTextStyleType(TextStyleType::REPEAT_LEFT);
setLayoutToParentWidth(true);
}
//---------------------------------------------------------
// setMarkerType
//---------------------------------------------------------
void Marker::setMarkerType(Type t)
{
_markerType = t;
const char* txt = 0;
switch (t) {
case Type::SEGNO:
txt = "<sym>segno</sym>";
setLabel("segno");
break;
case Type::VARSEGNO:
txt = "<sym>segnoSerpent1</sym>";
setLabel("varsegno");
break;
case Type::CODA:
txt = "<sym>coda</sym>";
setLabel("codab");
break;
case Type::VARCODA:
txt = "<sym>codaSquare</sym>";
setLabel("varcoda");
break;
case Type::CODETTA:
txt = "<sym>coda</sym><sym>coda</sym>";
setLabel("codetta");
break;
case Type::FINE:
txt = "Fine";
setTextStyleType(TextStyleType::REPEAT_RIGHT);
setLabel("fine");
break;
case Type::TOCODA:
txt = "To Coda";
setTextStyleType(TextStyleType::REPEAT_RIGHT);
setLabel("coda");
break;
case Type::USER:
break;
default:
qDebug("unknown marker type %hhd", t);
break;
}
if (isEmpty() && txt)
setXmlText(txt);
}
QString Marker::markerTypeUserName()
{
return qApp->translate("markerType", markerTypeTable[static_cast<int>(_markerType)].name.toUtf8().constData());
}
//---------------------------------------------------------
// styleChanged
//---------------------------------------------------------
void Marker::styleChanged()
{
setMarkerType(_markerType);
}
//---------------------------------------------------------
// adjustReadPos
//---------------------------------------------------------
void Marker::adjustReadPos()
{
if (!readPos().isNull()) {
QPointF uo;
/*
if (score()->mscVersion() <= 114) {
// rebase from Measure to Segment
uo = userOff();
uo.rx() -= segment()->pos().x();
// 1.2 is always HCENTER aligned
if ((textStyle().align() & AlignmentFlags::HMASK) == 0) // AlignmentFlags::LEFT
uo.rx() -= bbox().width() * .5;
}
else
*/
uo = readPos() - ipos();
setUserOff(uo);
setReadPos(QPointF());
}
}
//---------------------------------------------------------
// markerType
//---------------------------------------------------------
Marker::Type Marker::markerType(const QString& s) const
{
if (s == "segno")
return Type::SEGNO;
else if (s == "varsegno")
return Type::VARSEGNO;
else if (s == "codab")
return Type::CODA;
else if (s == "varcoda")
return Type::VARCODA;
else if (s == "codetta")
return Type::CODETTA;
else if (s == "fine")
return Type::FINE;
else if (s == "coda")
return Type::TOCODA;
else
return Type::USER;
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Marker::layout()
{
setPos(textStyle().offset(spatium()));
Text::layout1();
// although normally laid out to parent (measure) width,
// force to center over barline if left-aligned
if (layoutToParentWidth() && !(textStyle().align() & (AlignmentFlags::RIGHT|AlignmentFlags::HCENTER)))
rxpos() -= width() * 0.5;
adjustReadPos();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void Marker::read(XmlReader& e)
{
Type mt = Type::SEGNO;
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "label") {
QString s(e.readElementText());
setLabel(s);
mt = markerType(s);
}
else if (!Text::readProperties(e))
e.unknown();
}
// REPEAT is obsolete, but was previously used for both left and right aligned text
if (textStyleType() == TextStyleType::REPEAT)
setTextStyleType(TextStyleType::REPEAT_LEFT);
setMarkerType(mt);
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Marker::write(Xml& xml) const
{
xml.stag(name());
Text::writeProperties(xml);
xml.tag("label", _label);
xml.etag();
}
//---------------------------------------------------------
// undoSetLabel
//---------------------------------------------------------
void Marker::undoSetLabel(const QString& s)
{
score()->undoChangeProperty(this, P_ID::LABEL, s);
}
//---------------------------------------------------------
// undoSetMarkerType
//---------------------------------------------------------
void Marker::undoSetMarkerType(Type t)
{
score()->undoChangeProperty(this, P_ID::MARKER_TYPE, int(t));
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Marker::getProperty(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::LABEL:
return label();
case P_ID::MARKER_TYPE:
return int(markerType());
default:
break;
}
return Text::getProperty(propertyId);
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Marker::setProperty(P_ID propertyId, const QVariant& v)
{
switch (propertyId) {
case P_ID::LABEL:
setLabel(v.toString());
break;
case P_ID::MARKER_TYPE:
setMarkerType(Type(v.toInt()));
break;
default:
if (!Text::setProperty(propertyId, v))
return false;
break;
}
score()->setLayoutAll(true);
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Marker::propertyDefault(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::LABEL:
return QString();
case P_ID::MARKER_TYPE:
return int(Type::FINE);
default:
break;
}
return Text::propertyDefault(propertyId);
}
//---------------------------------------------------------
// nextElement
//---------------------------------------------------------
Element* Marker::nextElement()
{
Segment* seg;
if (markerType() == Marker::Type::FINE) {
seg = measure()->last();
return seg->firstElement(staffIdx());
}
Measure* prevMeasure = measure()->prevMeasureMM();
if (prevMeasure) {
seg = prevMeasure->last();
return seg->firstElement(staffIdx());
}
return Element::nextElement();
}
//---------------------------------------------------------
// prevElement
//---------------------------------------------------------
Element* Marker::prevElement()
{
//it's the same barline
return nextElement();
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
QString Marker::accessibleInfo()
{
return QString("%1: %2").arg(Element::accessibleInfo()).arg(markerTypeUserName());
}
}
|