Skip to content

Commit

Permalink
symbols properties
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoMigros committed Feb 14, 2024
1 parent 80f4c56 commit b2b7f0d
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 27 deletions.
Binary file modified fonts/mscore/MusescoreIcon.ttf
Binary file not shown.
4 changes: 4 additions & 0 deletions src/engraving/dom/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::STRINGTUNINGS_PRESET, true, "preset", P_TYPE::STRING, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "strings preset") },
{ Pid::STRINGTUNINGS_VISIBLE_STRINGS, true, "visibleStrings",P_TYPE::INT_VEC, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "visible strings") },

{ Pid::SCORE_FONT, true, "scoreFont", P_TYPE::STRING, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "score font") },
{ Pid::SYMBOLS_SIZE, false, "symbolsSize", P_TYPE::REAL, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "symbols size") },
{ Pid::SYMBOL_ANGLE, false, "symbolAngle", P_TYPE::REAL, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "symbol angle") },

{ Pid::END, false, "++end++", P_TYPE::INT, PropertyGroup::NONE, DUMMY_QT_TR_NOOP("propertyName", "<invalid property>") }
};
/* *INDENT-ON* */
Expand Down
4 changes: 4 additions & 0 deletions src/engraving/dom/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ enum class Pid {
STRINGTUNINGS_PRESET,
STRINGTUNINGS_VISIBLE_STRINGS,

SCORE_FONT,
SYMBOLS_SIZE,
SYMBOL_ANGLE,

END
};

Expand Down
53 changes: 51 additions & 2 deletions src/engraving/dom/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "symbol.h"

#include "score.h"

#include "draw/fontmetrics.h"
#include "iengravingfont.h"

Expand Down Expand Up @@ -54,8 +56,10 @@ Symbol::Symbol(EngravingItem* parent, ElementFlags f)
Symbol::Symbol(const Symbol& s)
: BSymbol(s)
{
m_sym = s.m_sym;
m_scoreFont = s.m_scoreFont;
m_sym = s.m_sym;
m_scoreFont = s.m_scoreFont;
m_symbolsSize = s.m_symbolsSize;
m_symAngle = s.m_symAngle;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -84,6 +88,16 @@ PropertyValue Symbol::getProperty(Pid propertyId) const
switch (propertyId) {
case Pid::SYMBOL:
return PropertyValue::fromValue(m_sym);
case Pid::SCORE_FONT:
if (m_scoreFont) {
return PropertyValue::fromValue(String::fromStdString(m_scoreFont->name()));
} else {
return PropertyValue::fromValue(String(u""));
}
case Pid::SYMBOLS_SIZE:
return PropertyValue::fromValue(m_symbolsSize);
case Pid::SYMBOL_ANGLE:
return PropertyValue::fromValue(m_symAngle);
default:
break;
}
Expand All @@ -100,12 +114,47 @@ bool Symbol::setProperty(Pid propertyId, const PropertyValue& v)
case Pid::SYMBOL:
m_sym = v.value<SymId>();
break;
case Pid::SCORE_FONT:
m_scoreFont = engravingFonts()->fontByName(v.value<String>().toStdString());
break;
case Pid::SYMBOLS_SIZE:
m_symbolsSize = v.toDouble();
break;
case Pid::SYMBOL_ANGLE:
m_symAngle = v.toDouble();
break;
default:
break;
}
triggerLayout();
return BSymbol::setProperty(propertyId, v);
}

//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------

PropertyValue Symbol::propertyDefault(Pid propertyId) const
{
switch (propertyId) {
case Pid::SYMBOL:
return SymId::accidentalSharp;
case Pid::SYMBOL_ANGLE:
return 0.0;
case Pid::SYMBOLS_SIZE:
return 1.0;
case Pid::SCORE_FONT:
if (m_scoreFont) {
return style().styleSt(Sid::MusicalSymbolFont);
} else {
return String(u"");
}
default:
break;
}
return EngravingItem::propertyDefault(propertyId);
}

//---------------------------------------------------------
// FSymbol
//---------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/dom/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,24 @@ class Symbol : public BSymbol
void setSym(SymId s, const std::shared_ptr<IEngravingFont>& sf = nullptr) { m_sym = s; m_scoreFont = sf; }
SymId sym() const { return m_sym; }
const std::shared_ptr<IEngravingFont>& scoreFont() const { return m_scoreFont; }
double symbolsSize() const { return m_symbolsSize; }
double symAngle() const { return m_symAngle; }
mu::AsciiStringView symName() const;

String accessibleInfo() const override;

PropertyValue getProperty(Pid) const override;
bool setProperty(Pid, const PropertyValue&) override;
PropertyValue propertyDefault(Pid) const override;

double baseLine() const override { return 0.0; }
virtual Segment* segment() const { return (Segment*)explicitParent(); }

protected:
SymId m_sym = SymId::noSym;
std::shared_ptr<IEngravingFont> m_scoreFont = nullptr;
double m_symbolsSize = 1.0;
double m_symAngle = 0.0;
};

//---------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/engraving/iengravingfont.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class IEngravingFont
virtual PointF smuflAnchor(SymId symId, SmuflAnchorId anchorId, double mag) const = 0;

// Draw
virtual void draw(SymId id, draw::Painter* p, double mag, const PointF& pos) const = 0;
virtual void draw(SymId id, draw::Painter* p, const SizeF& mag, const PointF& pos) const = 0;
virtual void draw(const SymIdList& ids, draw::Painter* p, double mag, const PointF& pos) const = 0;
virtual void draw(const SymIdList& ids, draw::Painter* p, const SizeF& mag, const PointF& pos) const = 0;
virtual void draw(SymId id, draw::Painter* p, double mag, const PointF& pos, const double angle = 0) const = 0;
virtual void draw(SymId id, draw::Painter* p, const SizeF& mag, const PointF& pos, const double angle = 0) const = 0;
virtual void draw(const SymIdList& ids, draw::Painter* p, double mag, const PointF& pos, const double angle = 0) const = 0;
virtual void draw(const SymIdList& ids, draw::Painter* p, const SizeF& mag, const PointF& pos, const double angle = 0) const = 0;
};

using IEngravingFontPtr = std::shared_ptr<IEngravingFont>;
Expand Down
25 changes: 16 additions & 9 deletions src/engraving/internal/engravingfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,17 +744,17 @@ PointF EngravingFont::smuflAnchor(SymId symId, SmuflAnchorId anchorId, double ma
// Draw
// =============================================

void EngravingFont::draw(SymId id, Painter* painter, const SizeF& mag, const PointF& pos) const
void EngravingFont::draw(SymId id, Painter* painter, const SizeF& mag, const PointF& pos, const double angle) const
{
const Sym& sym = this->sym(id);
if (sym.isCompound()) { // is this a compound symbol?
draw(sym.subSymbolIds, painter, mag, pos);
draw(sym.subSymbolIds, painter, mag, pos, angle);
return;
}

if (!sym.isValid()) {
if (MScore::useFallbackFont && !engravingFonts()->isFallbackFont(this)) {
engravingFonts()->fallbackFont()->draw(id, painter, mag, pos);
engravingFonts()->fallbackFont()->draw(id, painter, mag, pos, angle);
} else {
LOGE() << "invalid sym: " << static_cast<size_t>(id);
}
Expand All @@ -767,29 +767,36 @@ void EngravingFont::draw(SymId id, Painter* painter, const SizeF& mag, const Poi
m_font.setPointSizeF(size);
painter->scale(mag.width(), mag.height());
painter->setFont(m_font);
if (angle != 0) {
const double _width = sym.bbox.width() / 2;
const double _height = sym.bbox.height() / 2;
painter->translate(_width, -_height);
painter->rotate(angle);
painter->translate(-_width, _height);
}
painter->drawSymbol(PointF(pos.x() / mag.width(), pos.y() / mag.height()), symCode(id));
painter->restore();
}

void EngravingFont::draw(SymId id, Painter* painter, double mag, const PointF& pos) const
void EngravingFont::draw(SymId id, Painter* painter, double mag, const PointF& pos, const double angle) const
{
draw(id, painter, SizeF(mag, mag), pos);
draw(id, painter, SizeF(mag, mag), pos, angle);
}

void EngravingFont::draw(const SymIdList& ids, Painter* painter, double mag, const PointF& startPos) const
void EngravingFont::draw(const SymIdList& ids, Painter* painter, double mag, const PointF& startPos, const double angle) const
{
PointF pos(startPos);
for (SymId id : ids) {
draw(id, painter, mag, pos);
draw(id, painter, mag, pos, angle);
pos.setX(pos.x() + advance(id, mag));
}
}

void EngravingFont::draw(const SymIdList& ids, Painter* painter, const SizeF& mag, const PointF& startPos) const
void EngravingFont::draw(const SymIdList& ids, Painter* painter, const SizeF& mag, const PointF& startPos, const double angle) const
{
PointF pos(startPos);
for (SymId id : ids) {
draw(id, painter, mag, pos);
draw(id, painter, mag, pos, angle);
pos.setX(pos.x() + advance(id, mag.width()));
}
}
8 changes: 4 additions & 4 deletions src/engraving/internal/engravingfont.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ class EngravingFont : public IEngravingFont
PointF smuflAnchor(SymId symId, SmuflAnchorId anchorId, double mag) const override;

// Draw
void draw(SymId id, draw::Painter* p, double mag, const PointF& pos) const override;
void draw(SymId id, draw::Painter* p, const SizeF& mag, const PointF& pos) const override;
void draw(SymId id, draw::Painter* p, double mag, const PointF& pos, const double angle = 0) const override;
void draw(SymId id, draw::Painter* p, const SizeF& mag, const PointF& pos, const double angle = 0) const override;

void draw(const SymIdList& ids, draw::Painter* p, double mag, const PointF& pos) const override;
void draw(const SymIdList& ids, draw::Painter* p, const SizeF& mag, const PointF& pos) const override;
void draw(const SymIdList& ids, draw::Painter* p, double mag, const PointF& pos, const double angle = 0) const override;
void draw(const SymIdList& ids, draw::Painter* p, const SizeF& mag, const PointF& pos, const double angle = 0) const override;

void ensureLoad();

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/dev/tdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,7 @@ void TDraw::draw(const Symbol* item, Painter* painter)
if (!item->isNoteDot() || !tabStaff) {
painter->setPen(item->curColor());
if (item->scoreFont()) {
item->scoreFont()->draw(item->sym(), painter, item->magS(), PointF());
item->scoreFont()->draw(item->sym(), painter, item->magS() * item->symbolsSize(), PointF(), item->symAngle());
} else {
item->drawSymbol(item->sym(), painter);
}
Expand Down
4 changes: 3 additions & 1 deletion src/engraving/rendering/dev/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5458,7 +5458,9 @@ void TLayout::layoutSymbol(const Symbol* item, Symbol::LayoutData* ldata, const
} else if (item->staff()) {
ldata->setMag(item->staff()->staffMag(item->tick()));
}
ldata->setBbox(item->scoreFont() ? item->scoreFont()->bbox(item->sym(), item->magS()) : item->symBbox(item->sym()));
ldata->setBbox(item->scoreFont()
? item->scoreFont()->bbox(item->sym(), item->magS() * item->symbolsSize())
: item->symBbox(item->sym()));
double w = ldata->bbox().width();
PointF p;
if (item->align() == AlignV::BOTTOM) {
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/rw/read410/tread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,6 +2462,8 @@ void TRead::read(Symbol* sym, XmlReader& e, ReadContext& ctx)
sym->setSym(symId);
} else if (tag == "font") {
fontName = e.readText();
} else if (readProperty(sym, tag, e, ctx, Pid::SYMBOLS_SIZE)) {
} else if (readProperty(sym, tag, e, ctx, Pid::SYMBOL_ANGLE)) {
} else if (tag == "Symbol") {
Symbol* s = new Symbol(sym);
TRead::read(s, e, ctx);
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/rw/write/twrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,8 @@ void TWrite::write(const Symbol* item, XmlWriter& xml, WriteContext& ctx)
xml.tag("name", SymNames::nameForSymId(item->sym()));
if (item->scoreFont()) {
xml.tag("font", item->scoreFont()->name());
writeProperty(item, xml, Pid::SYMBOLS_SIZE);
writeProperty(item, xml, Pid::SYMBOL_ANGLE);
}
writeProperties(static_cast<const BSymbol*>(item), xml, ctx);
xml.endElement();
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/view/iconcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ class IconCode
TIE_CHORD_OUTSIDE = 0xF466,
TIE_CHORD_INSIDE = 0xF467,

TRIANGLE_SYMBOL = 0xF46D,

NONE = 0xFFFF
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Item {
property real maxValue: 999
property real minValue: -999
property alias validator: textInputField.validator
property bool wrap: false

property alias measureUnitsSymbol: textInputField.measureUnitsSymbol
property alias hint: textInputField.hint
Expand All @@ -47,10 +48,10 @@ Item {

readonly property int spacing: 8

property bool canIncrease: root.currentValue < root.maxValue
property bool canIncrease: wrap || root.currentValue < root.maxValue
property var onIncrement: null

property bool canDecrease: root.currentValue > root.minValue
property bool canDecrease: wrap || root.currentValue > root.minValue
property var onDecrement: null

signal valueEdited(var newValue)
Expand All @@ -67,7 +68,11 @@ Item {
newValue = onIncrement()
} else {
var value = root.isIndeterminate ? 0.0 : currentValue
newValue = Math.min(value + step, root.maxValue)
if (value + step >= root.maxValue) {
newValue = wrap ? root.minValue + (value + step - root.maxValue) : root.maxValue
} else {
newValue = value + step
}

if (newValue === value) {
return
Expand All @@ -86,7 +91,11 @@ Item {
newValue = onDecrement()
} else {
var value = root.isIndeterminate ? 0.0 : currentValue
newValue = Math.max(value - step, root.minValue)
if (value - step < root.minValue) {
newValue = wrap ? root.maxValue + (value - step + root.minValue) : root.minValue
} else {
newValue = value - step
}

if (newValue === value) {
return
Expand Down
2 changes: 2 additions & 0 deletions src/inspector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/models/notation/staffs/staffsettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/stafftype/stafftypesettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/notation/stafftype/stafftypesettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/symbols/symbolsettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/notation/symbols/symbolsettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/tempos/temposettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/notation/tempos/temposettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/timesignatures/timesignaturesettingsmodel.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/inspector/models/abstractinspectormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ static const QMap<mu::engraving::ElementType, InspectorModelType> NOTATION_ELEME
{ mu::engraving::ElementType::REST, InspectorModelType::TYPE_REST },
{ mu::engraving::ElementType::DYNAMIC, InspectorModelType::TYPE_DYNAMIC },
{ mu::engraving::ElementType::EXPRESSION, InspectorModelType::TYPE_EXPRESSION },
{ mu::engraving::ElementType::STRING_TUNINGS, InspectorModelType::TYPE_STRING_TUNINGS }
{ mu::engraving::ElementType::STRING_TUNINGS, InspectorModelType::TYPE_STRING_TUNINGS },
{ mu::engraving::ElementType::SYMBOL, InspectorModelType::TYPE_SYMBOL },
};

static QMap<mu::engraving::HairpinType, InspectorModelType> HAIRPIN_ELEMENT_MODEL_TYPES = {
Expand Down
1 change: 1 addition & 0 deletions src/inspector/models/abstractinspectormodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class AbstractInspectorModel : public QObject, public async::Asyncable
TYPE_REST,
TYPE_REST_BEAM,
TYPE_STRING_TUNINGS,
TYPE_SYMBOL,
};
Q_ENUM(InspectorModelType)

Expand Down
3 changes: 3 additions & 0 deletions src/inspector/models/inspectormodelcreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include "notation/dynamics/dynamicsettingsmodel.h"
#include "notation/expressions/expressionsettingsmodel.h"
#include "notation/stringtunings/stringtuningssettingsmodel.h"
#include "notation/symbols/symbolsettingsmodel.h"

using namespace mu::inspector;

Expand Down Expand Up @@ -195,6 +196,8 @@ AbstractInspectorModel* InspectorModelCreator::newInspectorModel(InspectorModelT
return new ExpressionSettingsModel(parent, repository);
case InspectorModelType::TYPE_STRING_TUNINGS:
return new StringTuningsSettingsModel(parent, repository);
case InspectorModelType::TYPE_SYMBOL:
return new SymbolSettingsModel(parent, repository);
case InspectorModelType::TYPE_BREATH:
case InspectorModelType::TYPE_ARPEGGIO:
case InspectorModelType::TYPE_UNDEFINED:
Expand Down
Loading

0 comments on commit b2b7f0d

Please sign in to comment.