Plugin API: make spatium usage in positioning properties more consistent

See https://musescore.org/en/node/296003 for the relevant discussion
This commit is contained in:
Dmitri Ovodok 2020-01-22 09:30:32 +02:00
parent fe3064d1ba
commit d5f35e4e29
2 changed files with 34 additions and 17 deletions

View file

@ -23,10 +23,8 @@ namespace PluginAPI {
void Element::setOffsetX(qreal offX)
{
offX *= element()->spatium();
QPointF off(element()->offset());
off.rx() += offX;
set(Ms::Pid::OFFSET, off);
const qreal offY = element()->offset().y() / element()->spatium();
set(Ms::Pid::OFFSET, QPointF(offX, offY));
}
//---------------------------------------------------------
@ -35,10 +33,8 @@ void Element::setOffsetX(qreal offX)
void Element::setOffsetY(qreal offY)
{
offY *= element()->spatium();
QPointF off(element()->offset());
off.ry() += offY;
set(Ms::Pid::OFFSET, off);
const qreal offX = element()->offset().x() / element()->spatium();
set(Ms::Pid::OFFSET, QPointF(offX, offY));
}
//---------------------------------------------------------

View file

@ -61,9 +61,19 @@ QVariant ScoreElement::get(Ms::Pid pid) const
if (!e)
return QVariant();
const QVariant val = e->getProperty(pid);
if (propertyType(pid) == P_TYPE::FRACTION) {
const Fraction f(val.value<Fraction>());
return QVariant::fromValue(wrap(f));
switch (propertyType(pid)) {
case P_TYPE::FRACTION: {
const Fraction f(val.value<Fraction>());
return QVariant::fromValue(wrap(f));
}
case P_TYPE::POINT_SP:
case P_TYPE::POINT_SP_MM:
if (e->isElement())
return val.toPointF() / toElement(e)->spatium();
// TODO: handle Staff and other classes?
break;
default:
break;
}
return val;
}
@ -77,13 +87,24 @@ void ScoreElement::set(Ms::Pid pid, QVariant val)
if (!e)
return;
if (propertyType(pid) == P_TYPE::FRACTION) {
FractionWrapper* f = val.value<FractionWrapper*>();
if (!f) {
qWarning("ScoreElement::set: trying to assign value of wrong type to fractional property");
return;
switch (propertyType(pid)) {
case P_TYPE::FRACTION: {
FractionWrapper* f = val.value<FractionWrapper*>();
if (!f) {
qWarning("ScoreElement::set: trying to assign value of wrong type to fractional property");
return;
}
val = QVariant::fromValue(f->fraction());
}
val = QVariant::fromValue(f->fraction());
break;
case P_TYPE::POINT_SP:
case P_TYPE::POINT_SP_MM:
if (e->isElement())
val = val.toPointF() * toElement(e)->spatium();
// TODO: handle Staff and other classes?
break;
default:
break;
}
const PropertyFlags f = e->propertyFlags(pid);