1 //============================================================================= 2 // MuseScore 3 // Music Composition & Notation 4 // 5 // Copyright (C) 2004-2011 Werner Schweer 6 // 7 // This program is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License version 2 9 // as published by the Free Software Foundation and appearing in 10 // the file LICENCE.GPL 11 //============================================================================= 12 13 #ifndef __ACCIDENTAL_H__ 14 #define __ACCIDENTAL_H__ 15 16 /** 17 \file 18 Definition of class Accidental 19 */ 20 21 #include <QString> 22 #include <QList> 23 #include <QVariant> 24 25 #include "config.h" 26 #include "element.h" 27 #include "sym.h" 28 29 namespace Ms { 30 31 class Note; 32 enum class AccidentalVal : signed char; 33 34 //--------------------------------------------------------- 35 // AccidentalRole 36 //--------------------------------------------------------- 37 38 enum class AccidentalRole : char { 39 AUTO, // layout created accidental 40 USER // user created accidental 41 }; 42 43 //--------------------------------------------------------- 44 // AccidentalBracket 45 //--------------------------------------------------------- 46 47 enum class AccidentalBracket : char { 48 NONE, 49 PARENTHESIS, 50 BRACKET, 51 BRACE, 52 }; 53 54 //--------------------------------------------------------- 55 // SymElement 56 //--------------------------------------------------------- 57 58 struct SymElement { 59 SymId sym; 60 qreal x; 61 qreal y; SymElementSymElement62 SymElement(SymId _sym, qreal _x, qreal _y) : sym(_sym), x(_x), y(_y) {} 63 }; 64 65 //--------------------------------------------------------- 66 // @@ Accidental 67 // @P role enum (Accidental.AUTO, .USER) (read only) 68 // @P small bool 69 //--------------------------------------------------------- 70 71 class Accidental final : public Element { 72 QList<SymElement> el; 73 AccidentalType _accidentalType { AccidentalType::NONE }; 74 bool _small { false }; 75 AccidentalBracket _bracket { AccidentalBracket::NONE }; 76 AccidentalRole _role { AccidentalRole::AUTO }; 77 78 public: 79 Accidental(Score* s = 0); 80 clone()81 Accidental* clone() const override { return new Accidental(*this); } type()82 ElementType type() const override { return ElementType::ACCIDENTAL; } 83 84 QString subtypeUserName() const; 85 void setSubtype(const QString& s); setAccidentalType(AccidentalType t)86 void setAccidentalType(AccidentalType t) { _accidentalType = t; } 87 accidentalType()88 AccidentalType accidentalType() const { return _accidentalType; } role()89 AccidentalRole role() const { return _role; } 90 subtype()91 int subtype() const override { return (int)_accidentalType; } subtypeName()92 QString subtypeName() const override { return QString(subtype2name(_accidentalType)); } 93 94 bool acceptDrop(EditData&) const override; 95 Element* drop(EditData&) override; 96 void layout() override; 97 void layoutMultiGlyphAccidental(); 98 void layoutSingleGlyphAccidental(); 99 void draw(QPainter*) const override; isEditable()100 bool isEditable() const override { return true; } startEdit(EditData &)101 void startEdit(EditData&) override { setGenerated(false); } 102 103 SymId symbol() const; note()104 Note* note() const { return (parent() && parent()->isNote()) ? toNote(parent()) : 0; } 105 bracket()106 AccidentalBracket bracket() const { return _bracket; } setBracket(AccidentalBracket val)107 void setBracket(AccidentalBracket val) { _bracket = val; } 108 setRole(AccidentalRole r)109 void setRole(AccidentalRole r) { _role = r; } 110 small()111 bool small() const { return _small; } setSmall(bool val)112 void setSmall(bool val) { _small = val; } 113 114 void undoSetSmall(bool val); 115 116 void read(XmlReader&) override; 117 void write(XmlWriter& xml) const override; 118 119 QVariant getProperty(Pid propertyId) const override; 120 bool setProperty(Pid propertyId, const QVariant&) override; 121 QVariant propertyDefault(Pid propertyId) const override; 122 Pid propertyId(const QStringRef& xmlName) const override; 123 QString propertyUserValue(Pid) const override; 124 125 static AccidentalVal subtype2value(AccidentalType); // return effective pitch offset 126 static SymId subtype2symbol(AccidentalType); 127 static const char* subtype2name(AccidentalType); 128 static AccidentalType value2subtype(AccidentalVal); 129 static AccidentalType name2subtype(const QString&); isMicrotonal(AccidentalType t)130 static bool isMicrotonal(AccidentalType t) { return t > AccidentalType::FLAT3; } 131 132 QString accessibleInfo() const override; 133 }; 134 135 extern AccidentalVal sym2accidentalVal(SymId id); 136 137 } // namespace Ms 138 139 Q_DECLARE_METATYPE(Ms::AccidentalRole); 140 141 142 #endif 143