Skip to content

Commit

Permalink
Fix #292900: Expose Element.pos X/Y values to plugins.
Browse files Browse the repository at this point in the history
Expose Element.pos X/Y values so that plugin's can accurately
position things like STAFF_TEXT on the score. One example is
to position a tin whistle finger hole pattern directly under
a grace note. Another is to place note names properly using
MuseScore's shipped notename.qml plugin.
  • Loading branch information
DLLarson committed Aug 3, 2019
1 parent 9be19d2 commit 6e46f20
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions mscore/plugin/api/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ extern Element* wrap(Ms::Element* se, Ownership own = Ownership::SCORE);
class Element : public Ms::PluginAPI::ScoreElement {
Q_OBJECT

/**
* Parent element for this element.
* \since 3.3
*/
Q_PROPERTY(Ms::PluginAPI::Element* parent READ parent)
/**
* X-axis offset from a reference position in spatium units.
* \see Element::offset
Expand All @@ -84,10 +89,29 @@ class Element : public Ms::PluginAPI::ScoreElement {
*/
Q_PROPERTY(qreal offsetY READ offsetY WRITE setOffsetY)
/**
* Parent element for this element.
* \since 3.3
* Reference position of this element relative to its parent element.
*
* This is an offset from the parent object that is determined by the
* autoplace feature. It includes any other offsets applied to the
* element. You can use this value to accurately position other elements
* related to the same parent.
*
* This value is in spatium units for compatiblity with Element.offsetX.
* \since MuseScore 3.3
*/
Q_PROPERTY(Ms::PluginAPI::Element* parent READ parent)
Q_PROPERTY(qreal posX READ posX)
/**
* Reference position of this element relative to its parent element.
*
* This is an offset from the parent object that is determined by the
* autoplace feature. It includes any other offsets applied to the
* element. You can use this value to accurately position other elements
* related to the same parent.
*
* This value is in spatium units for compatiblity with Element.offsetY.
* \since MuseScore 3.3
*/
Q_PROPERTY(qreal posY READ posY)

API_PROPERTY( subtype, SUBTYPE )
API_PROPERTY_READ_ONLY_T( bool, selected, SELECTED )
Expand Down Expand Up @@ -326,6 +350,9 @@ class Element : public Ms::PluginAPI::ScoreElement {
void setOffsetX(qreal offX);
void setOffsetY(qreal offY);

qreal posX() const { return element()->pos().x() / element()->spatium(); }
qreal posY() const { return element()->pos().y() / element()->spatium(); }

Ms::PluginAPI::Element* parent() const { return wrap(element()->parent()); }

public:
Expand Down

0 comments on commit 6e46f20

Please sign in to comment.