Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework anchor lines drawing #5738

Merged
merged 7 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions libmscore/arpeggio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,37 +290,44 @@ void Arpeggio::editDrag(EditData& ed)
}

//---------------------------------------------------------
// dragAnchor
// dragAnchorLines
//---------------------------------------------------------

QLineF Arpeggio::dragAnchor() const
QVector<QLineF> Arpeggio::dragAnchorLines() const
{
QVector<QLineF> result;

Chord* c = chord();
if (c)
return QLineF(pagePos(), c->upNote()->pagePos());
return QLineF();
result << QLineF(pagePos(), c->upNote()->pagePos());
return QVector<QLineF>();
}

//---------------------------------------------------------
// gripAnchor
// gripAnchorLines
//---------------------------------------------------------

QPointF Arpeggio::gripAnchor(Grip n) const
QVector<QLineF> Arpeggio::gripAnchorLines(Grip grip) const
{
Chord* c = chord();
if (c == 0)
return QPointF();
if (n == Grip::START)
return c->upNote()->pagePos();
else if (n == Grip::END) {
Note* dnote = c->downNote();
QVector<QLineF> result;

Chord* _chord = chord();
if (!_chord)
return result;

QPointF gripPosition = gripsPositions()[static_cast<int>(grip)];

if (grip == Grip::START)
result << QLineF(_chord->upNote()->pagePos(), gripPosition);
else if (grip == Grip::END) {
Note* downNote = _chord->downNote();
int btrack = track() + (_span - 1) * VOICES;
Element* e = c->segment()->element(btrack);
Element* e = _chord->segment()->element(btrack);
if (e && e->isChord())
dnote = toChord(e)->downNote();
return dnote->pagePos();
downNote = toChord(e)->downNote();
result << QLineF(downNote->pagePos(), gripPosition);
}
return QPointF();
return result;
}

//---------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions libmscore/arpeggio.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Arpeggio final : public Element {
void symbolLine2(SymId end, SymId fill);

void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/) override;
QLineF dragAnchor() const override;
QPointF gripAnchor(Grip) const override;
QVector<QLineF> dragAnchorLines() const override;
QVector<QLineF> gripAnchorLines(Grip) const override;
void startEdit(EditData&) override;

public:
Expand Down Expand Up @@ -96,7 +96,7 @@ class Arpeggio final : public Element {
int gripsCount() const override { return 2; }
Grip initialEditModeGrip() const override { return Grip::END; }
Grip defaultGrip() const override { return Grip::START; }
std::vector<QPointF> gripsPositions(const EditData&) const override;
std::vector<QPointF> gripsPositions(const EditData& = EditData()) const override;
};


Expand Down
8 changes: 5 additions & 3 deletions libmscore/articulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,14 @@ bool Articulation::layoutCloseToNote() const
}

//---------------------------------------------------------
// dragAnchor
// dragAnchorLines
//---------------------------------------------------------

QLineF Articulation::dragAnchor() const
QVector<QLineF> Articulation::dragAnchorLines() const
{
return QLineF(canvasPos(), parent()->canvasPos());
QVector<QLineF> result;
result << QLineF(canvasPos(), parent()->canvasPos());
return result;
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/articulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Articulation final : public Element {
void write(XmlWriter& xml) const override;
bool readProperties(XmlReader&) override;

QLineF dragAnchor() const override;
QVector<QLineF> dragAnchorLines() const override;

QVariant getProperty(Pid propertyId) const override;
bool setProperty(Pid propertyId, const QVariant&) override;
Expand Down
14 changes: 3 additions & 11 deletions libmscore/bsymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,12 @@ QRectF BSymbol::drag(EditData& ed)
}

//---------------------------------------------------------
// dragAnchor
// dragAnchorLines
//---------------------------------------------------------

QLineF BSymbol::dragAnchor() const
QVector<QLineF> BSymbol::dragAnchorLines() const
{
if (parent() && parent()->type() == ElementType::SEGMENT) {
System* system = segment()->measure()->system();
qreal y = system->staffCanvasYpage(staffIdx());
QPointF anchor(segment()->canvasPos().x(), y);
return QLineF(canvasPos(), anchor);
}
else {
return QLineF(canvasPos(), parent()->canvasPos());
}
return genericDragAnchorLines();
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/bsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BSymbol : public Element {
QList<Element*>& leafs() { return _leafs; }
virtual QPointF pagePos() const override;
virtual QPointF canvasPos() const override;
virtual QLineF dragAnchor() const override;
QVector<QLineF> dragAnchorLines() const override;
Segment* segment() const { return (Segment*)parent(); }
};

Expand Down
44 changes: 44 additions & 0 deletions libmscore/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,26 @@ bool Element::isPrintable() const
}
}

//---------------------------------------------------------
// findAncestor
//---------------------------------------------------------

Element* Element::findAncestor(ElementType t)
{
Element* e = this;
while (e && e->type() != t)
e = e->parent();
return e;
}

const Element* Element::findAncestor(ElementType t) const
{
const Element* e = this;
while (e && e->type() != t)
e = e->parent();
return e;
}

//---------------------------------------------------------
// findMeasure
//---------------------------------------------------------
Expand Down Expand Up @@ -2003,6 +2023,30 @@ void Element::endDrag(EditData& ed)
}
}

//---------------------------------------------------------
// genericDragAnchorLines
//---------------------------------------------------------

QVector<QLineF> Element::genericDragAnchorLines() const
{
qreal xp = 0.0;
for (Element* e = parent(); e; e = e->parent())
xp += e->x();
qreal yp;
if (parent()->isSegment()) {
System* system = toSegment(parent())->measure()->system();
const int stIdx = staffIdx();
yp = system->staffCanvasYpage(stIdx);
if (placement() == Placement::BELOW)
yp += system->staff(stIdx)->bbox().height();
}
else
yp = parent()->canvasPos().y();
QPointF p1(xp, yp);
QLineF anchorLine(p1, canvasPos());
return { anchorLine };
}

//---------------------------------------------------------
// updateGrips
//---------------------------------------------------------
Expand Down
25 changes: 21 additions & 4 deletions libmscore/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class EditData {
Element* element { 0 };
Element* dropElement { 0 };

EditData(MuseScoreView* v) : view(v) {}
EditData(MuseScoreView* v = nullptr) : view(v) {}
void clearData();

ElementEditData* getData(const Element*) const;
Expand Down Expand Up @@ -193,6 +193,10 @@ class Element : public ScoreElement {

Element* parent() const { return _parent; }
void setParent(Element* e) { _parent = e; }

Element* findAncestor(ElementType t);
const Element* findAncestor(ElementType t) const;

Measure* findMeasure();
const Measure* findMeasure() const;
MeasureBase* findMeasureBase();
Expand Down Expand Up @@ -291,7 +295,18 @@ class Element : public ScoreElement {
virtual void startDrag(EditData&);
virtual QRectF drag(EditData&);
virtual void endDrag(EditData&);
virtual QLineF dragAnchor() const { return QLineF(); }
/** Returns anchor lines displayed while dragging element in page coordinates. */
virtual QVector<QLineF> dragAnchorLines() const { return QVector<QLineF>(); }
/**
* A generic \ref dragAnchorLines() implementation which can be used in
* dragAnchorLines() overrides in descendants. It is not made its default
* implementation in Element class since showing anchor lines is not
* desirable for most element types.
* TODO: maybe Annotation class could be extracted which would be a base
* class of various annotation types and which would have this
* dragAnchorLines() implementation by default.
*/
QVector<QLineF> genericDragAnchorLines() const;

virtual bool isEditable() const { return !flag(ElementFlag::GENERATED); }

Expand All @@ -308,13 +323,15 @@ class Element : public ScoreElement {
void updateGrips(EditData&) const;
virtual bool nextGrip(EditData&) const;
virtual bool prevGrip(EditData&) const;
virtual QPointF gripAnchor(Grip) const { return QPointF(); }
/** Returns anchor lines displayed while dragging element's grip in page coordinates. */
virtual QVector<QLineF> gripAnchorLines(Grip) const { return QVector<QLineF>(); }

virtual EditBehavior normalModeEditBehavior() const { return EditBehavior::SelectOnly; }
virtual int gripsCount() const { return 0; }
virtual Grip initialEditModeGrip() const { return Grip::NO_GRIP; }
virtual Grip defaultGrip() const { return Grip::NO_GRIP; }
virtual std::vector<QPointF> gripsPositions(const EditData&) const { return std::vector<QPointF>(); }
/** Returns grips positions in page coordinates. */
virtual std::vector<QPointF> gripsPositions(const EditData& = EditData()) const { return std::vector<QPointF>(); }

int track() const { return _track; }
virtual void setTrack(int val) { _track = val; }
Expand Down
8 changes: 5 additions & 3 deletions libmscore/fermata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,14 @@ void Fermata::layout()
}

//---------------------------------------------------------
// dragAnchor
// dragAnchorLines
//---------------------------------------------------------

QLineF Fermata::dragAnchor() const
QVector<QLineF> Fermata::dragAnchorLines() const
{
return QLineF(canvasPos(), parent()->canvasPos());
QVector<QLineF> result;
result << QLineF(canvasPos(), parent()->canvasPos());
return result;
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/fermata.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Fermata final : public Element {
void write(XmlWriter& xml) const override;
bool readProperties(XmlReader&) override;

QLineF dragAnchor() const override;
QVector<QLineF> dragAnchorLines() const override;

QVariant getProperty(Pid propertyId) const override;
bool setProperty(Pid propertyId, const QVariant&) override;
Expand Down
17 changes: 3 additions & 14 deletions libmscore/fret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,12 @@ QPointF FretDiagram::pagePos() const
}

//---------------------------------------------------------
// dragAnchor
// dragAnchorLines
//---------------------------------------------------------

QLineF FretDiagram::dragAnchor() const
QVector<QLineF> FretDiagram::dragAnchorLines() const
{
qreal xp = 0.0;
for (Element* e = parent(); e; e = e->parent())
xp += e->x();
qreal yp;
if (parent()->isSegment()) {
System* system = toSegment(parent())->measure()->system();
yp = system->staffCanvasYpage(staffIdx());
}
else
yp = parent()->canvasPos().y();
QPointF p1(xp, yp);
return QLineF(p1, canvasPos());
return genericDragAnchorLines();
#if 0 // TODOxx
if (parent()->isSegment()) {
Segment* s = toSegment(parent());
Expand Down
2 changes: 1 addition & 1 deletion libmscore/fret.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class FretDiagram final : public Element {
void writeOld(XmlWriter& xml) const;
void read(XmlReader&) override;
void readNew(XmlReader&);
QLineF dragAnchor() const override;
QVector<QLineF> dragAnchorLines() const override;
QPointF pagePos() const override;

// read / write MusicXML
Expand Down
2 changes: 1 addition & 1 deletion libmscore/hairpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class HairpinSegment final : public TextLineBaseSegment {
Shape shape() const override;

int gripsCount() const override { return 4; }
std::vector<QPointF> gripsPositions(const EditData&) const override;
std::vector<QPointF> gripsPositions(const EditData& = EditData()) const override;
};

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Image final : public BSymbol {
bool isEditable() const override { return true; }
void startEditDrag(EditData&) override;
void editDrag(EditData& ed) override;
QPointF gripAnchor(Grip) const override { return QPointF(); }
QVector<QLineF> gripAnchorLines(Grip) const override { return QVector<QLineF>(); }

public:
Image(Score* = 0);
Expand Down
Loading