Skip to content

Commit

Permalink
Merge pull request #5986 from dmitrio95/plugins-pagenumber-pagepos
Browse files Browse the repository at this point in the history
fix #301561: Plugin API: restore pagenumber and pagePos properties from MuseScore 2.X
  • Loading branch information
anatoly-os authored Apr 26, 2020
2 parents 97720a2 + 15a3051 commit ac5b40e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mscore/plugin/api/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ void Chord::addInternal(Ms::Chord* chord, Ms::Element* s)
chord->score()->undoAddElement(s);
}

//---------------------------------------------------------
// Page::pagenumber
//---------------------------------------------------------

int Page::pagenumber() const
{
return page()->no();
}

//---------------------------------------------------------
// Chord::remove
//---------------------------------------------------------
Expand Down Expand Up @@ -259,6 +268,8 @@ Element* wrap(Ms::Element* e, Ownership own)
return wrap<Segment>(toSegment(e), own);
case ElementType::MEASURE:
return wrap<Measure>(toMeasure(e), own);
case ElementType::PAGE:
return wrap<Page>(toPage(e), own);
default:
break;
}
Expand Down
40 changes: 40 additions & 0 deletions mscore/plugin/api/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "libmscore/measure.h"
#include "libmscore/note.h"
#include "libmscore/notedot.h"
#include "libmscore/page.h"
#include "libmscore/segment.h"
#include "libmscore/accidental.h"
#include "libmscore/musescoreCore.h"
Expand Down Expand Up @@ -114,6 +115,11 @@ class Element : public Ms::PluginAPI::ScoreElement {
* \since MuseScore 3.3
*/
Q_PROPERTY(qreal posY READ posY)
/**
* Position of this element in page coordinates, in spatium units.
* \since MuseScore 3.5
*/
Q_PROPERTY(QPointF pagePos READ pagePos)

/**
* Bounding box of this element.
Expand Down Expand Up @@ -369,6 +375,8 @@ class Element : public Ms::PluginAPI::ScoreElement {
qreal posX() const { return element()->pos().x() / element()->spatium(); }
qreal posY() const { return element()->pos().y() / element()->spatium(); }

QPointF pagePos() const { return element()->pagePos() / element()->spatium(); }

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

QRectF bbox() const;
Expand Down Expand Up @@ -671,6 +679,38 @@ class Measure : public Element {
/// \endcond
};

//---------------------------------------------------------
// Page
//---------------------------------------------------------

class Page : public Element {
Q_OBJECT
/**
* \brief Page number, counting from 0.
* Number of this page in the score counting from 0, i.e.
* for the first page its \p pagenumber value will be equal to 0.
* User-visible page number can be calculated as
* \code
* page.pagenumber + 1 + score.pageNumberOffset
* \endcode
* where \p score is the relevant \ref Score object.
* \since MuseScore 3.5
* \see Score::pageNumberOffset
*/
Q_PROPERTY(int pagenumber READ pagenumber)

public:
/// \cond MS_INTERNAL
Page(Ms::Page* p = nullptr, Ownership own = Ownership::SCORE)
: Element(p, own) {}

Ms::Page* page() { return toPage(e); }
const Ms::Page* page() const { return toPage(e); }

int pagenumber() const;
/// \endcond
};

#undef API_PROPERTY
#undef API_PROPERTY_T
#undef API_PROPERTY_READ_ONLY
Expand Down
12 changes: 12 additions & 0 deletions mscore/plugin/api/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ class Score : public Ms::PluginAPI::ScoreElement {
Q_PROPERTY(QString mscoreRevision READ mscoreRevision)
/** Current selections for the score. \since MuseScore 3.3 */
Q_PROPERTY(Ms::PluginAPI::Selection* selection READ selection)
/**
* Page numbering offset. The user-visible number of the given \p page is defined as
* \code
* page.pagenumber + 1 + score.pageNumberOffset
* \endcode
* \since MuseScore 3.5
* \see Page::pagenumber
*/
Q_PROPERTY(int pageNumberOffset READ pageNumberOffset WRITE setPageNumberOffset)

public:
/// \cond MS_INTERNAL
Expand All @@ -106,6 +115,9 @@ class Score : public Ms::PluginAPI::ScoreElement {
QString title() { return score()->metaTag("workTitle"); }
Ms::PluginAPI::Selection* selection() { return selectionWrap(&score()->selection()); }

int pageNumberOffset() const { return score()->pageNumberOffset(); }
void setPageNumberOffset(int offset) { score()->undoChangePageNumberOffset(offset); }

/// \endcond

/// Returns as a string the metatag named \p tag
Expand Down

0 comments on commit ac5b40e

Please sign in to comment.